暂无描述

index.js 1.8MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032
  1. import { c as createCommonjsModule, a as commonjsGlobal, u as unwrapExports, s as styleInject, j as _slicedToArray, b as _inherits$c, d as _createClass, e as _classCallCheck$h, f as _possibleConstructorReturn$c, h as _getPrototypeOf, _ as _defineProperty$1, k as _assertThisInitialized } from '../style-inject.es-b888177c.js';
  2. import React, { useState, useMemo } from 'react';
  3. import reactDom from 'react-dom';
  4. import server from 'react-dom/server';
  5. /*
  6. object-assign
  7. (c) Sindre Sorhus
  8. @license MIT
  9. */
  10. /* eslint-disable no-unused-vars */
  11. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  12. var hasOwnProperty = Object.prototype.hasOwnProperty;
  13. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  14. function toObject(val) {
  15. if (val === null || val === undefined) {
  16. throw new TypeError('Object.assign cannot be called with null or undefined');
  17. }
  18. return Object(val);
  19. }
  20. function shouldUseNative() {
  21. try {
  22. if (!Object.assign) {
  23. return false;
  24. }
  25. // Detect buggy property enumeration order in older V8 versions.
  26. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  27. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  28. test1[5] = 'de';
  29. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  30. return false;
  31. }
  32. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  33. var test2 = {};
  34. for (var i = 0; i < 10; i++) {
  35. test2['_' + String.fromCharCode(i)] = i;
  36. }
  37. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  38. return test2[n];
  39. });
  40. if (order2.join('') !== '0123456789') {
  41. return false;
  42. }
  43. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  44. var test3 = {};
  45. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  46. test3[letter] = letter;
  47. });
  48. if (Object.keys(Object.assign({}, test3)).join('') !==
  49. 'abcdefghijklmnopqrst') {
  50. return false;
  51. }
  52. return true;
  53. } catch (err) {
  54. // We don't expect any of the above to throw, but better to be safe.
  55. return false;
  56. }
  57. }
  58. var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
  59. var from;
  60. var to = toObject(target);
  61. var symbols;
  62. for (var s = 1; s < arguments.length; s++) {
  63. from = Object(arguments[s]);
  64. for (var key in from) {
  65. if (hasOwnProperty.call(from, key)) {
  66. to[key] = from[key];
  67. }
  68. }
  69. if (getOwnPropertySymbols) {
  70. symbols = getOwnPropertySymbols(from);
  71. for (var i = 0; i < symbols.length; i++) {
  72. if (propIsEnumerable.call(from, symbols[i])) {
  73. to[symbols[i]] = from[symbols[i]];
  74. }
  75. }
  76. }
  77. }
  78. return to;
  79. };
  80. var immutable = createCommonjsModule(function (module, exports) {
  81. /**
  82. * Copyright (c) 2014-2015, Facebook, Inc.
  83. * All rights reserved.
  84. *
  85. * This source code is licensed under the BSD-style license found in the
  86. * LICENSE file in the root directory of this source tree. An additional grant
  87. * of patent rights can be found in the PATENTS file in the same directory.
  88. */
  89. (function (global, factory) {
  90. module.exports = factory() ;
  91. }(commonjsGlobal, function () {var SLICE$0 = Array.prototype.slice;
  92. function createClass(ctor, superClass) {
  93. if (superClass) {
  94. ctor.prototype = Object.create(superClass.prototype);
  95. }
  96. ctor.prototype.constructor = ctor;
  97. }
  98. function Iterable(value) {
  99. return isIterable(value) ? value : Seq(value);
  100. }
  101. createClass(KeyedIterable, Iterable);
  102. function KeyedIterable(value) {
  103. return isKeyed(value) ? value : KeyedSeq(value);
  104. }
  105. createClass(IndexedIterable, Iterable);
  106. function IndexedIterable(value) {
  107. return isIndexed(value) ? value : IndexedSeq(value);
  108. }
  109. createClass(SetIterable, Iterable);
  110. function SetIterable(value) {
  111. return isIterable(value) && !isAssociative(value) ? value : SetSeq(value);
  112. }
  113. function isIterable(maybeIterable) {
  114. return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]);
  115. }
  116. function isKeyed(maybeKeyed) {
  117. return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
  118. }
  119. function isIndexed(maybeIndexed) {
  120. return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
  121. }
  122. function isAssociative(maybeAssociative) {
  123. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  124. }
  125. function isOrdered(maybeOrdered) {
  126. return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
  127. }
  128. Iterable.isIterable = isIterable;
  129. Iterable.isKeyed = isKeyed;
  130. Iterable.isIndexed = isIndexed;
  131. Iterable.isAssociative = isAssociative;
  132. Iterable.isOrdered = isOrdered;
  133. Iterable.Keyed = KeyedIterable;
  134. Iterable.Indexed = IndexedIterable;
  135. Iterable.Set = SetIterable;
  136. var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  137. var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  138. var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  139. var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  140. // Used for setting prototype methods that IE8 chokes on.
  141. var DELETE = 'delete';
  142. // Constants describing the size of trie nodes.
  143. var SHIFT = 5; // Resulted in best performance after ______?
  144. var SIZE = 1 << SHIFT;
  145. var MASK = SIZE - 1;
  146. // A consistent shared value representing "not set" which equals nothing other
  147. // than itself, and nothing that could be provided externally.
  148. var NOT_SET = {};
  149. // Boolean references, Rough equivalent of `bool &`.
  150. var CHANGE_LENGTH = { value: false };
  151. var DID_ALTER = { value: false };
  152. function MakeRef(ref) {
  153. ref.value = false;
  154. return ref;
  155. }
  156. function SetRef(ref) {
  157. ref && (ref.value = true);
  158. }
  159. // A function which returns a value representing an "owner" for transient writes
  160. // to tries. The return value will only ever equal itself, and will not equal
  161. // the return of any subsequent call of this function.
  162. function OwnerID() {}
  163. // http://jsperf.com/copy-array-inline
  164. function arrCopy(arr, offset) {
  165. offset = offset || 0;
  166. var len = Math.max(0, arr.length - offset);
  167. var newArr = new Array(len);
  168. for (var ii = 0; ii < len; ii++) {
  169. newArr[ii] = arr[ii + offset];
  170. }
  171. return newArr;
  172. }
  173. function ensureSize(iter) {
  174. if (iter.size === undefined) {
  175. iter.size = iter.__iterate(returnTrue);
  176. }
  177. return iter.size;
  178. }
  179. function wrapIndex(iter, index) {
  180. // This implements "is array index" which the ECMAString spec defines as:
  181. //
  182. // A String property name P is an array index if and only if
  183. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  184. // to 2^32−1.
  185. //
  186. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  187. if (typeof index !== 'number') {
  188. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  189. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  190. return NaN;
  191. }
  192. index = uint32Index;
  193. }
  194. return index < 0 ? ensureSize(iter) + index : index;
  195. }
  196. function returnTrue() {
  197. return true;
  198. }
  199. function wholeSlice(begin, end, size) {
  200. return (begin === 0 || (size !== undefined && begin <= -size)) &&
  201. (end === undefined || (size !== undefined && end >= size));
  202. }
  203. function resolveBegin(begin, size) {
  204. return resolveIndex(begin, size, 0);
  205. }
  206. function resolveEnd(end, size) {
  207. return resolveIndex(end, size, size);
  208. }
  209. function resolveIndex(index, size, defaultIndex) {
  210. return index === undefined ?
  211. defaultIndex :
  212. index < 0 ?
  213. Math.max(0, size + index) :
  214. size === undefined ?
  215. index :
  216. Math.min(size, index);
  217. }
  218. /* global Symbol */
  219. var ITERATE_KEYS = 0;
  220. var ITERATE_VALUES = 1;
  221. var ITERATE_ENTRIES = 2;
  222. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  223. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  224. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  225. function Iterator(next) {
  226. this.next = next;
  227. }
  228. Iterator.prototype.toString = function() {
  229. return '[Iterator]';
  230. };
  231. Iterator.KEYS = ITERATE_KEYS;
  232. Iterator.VALUES = ITERATE_VALUES;
  233. Iterator.ENTRIES = ITERATE_ENTRIES;
  234. Iterator.prototype.inspect =
  235. Iterator.prototype.toSource = function () { return this.toString(); };
  236. Iterator.prototype[ITERATOR_SYMBOL] = function () {
  237. return this;
  238. };
  239. function iteratorValue(type, k, v, iteratorResult) {
  240. var value = type === 0 ? k : type === 1 ? v : [k, v];
  241. iteratorResult ? (iteratorResult.value = value) : (iteratorResult = {
  242. value: value, done: false
  243. });
  244. return iteratorResult;
  245. }
  246. function iteratorDone() {
  247. return { value: undefined, done: true };
  248. }
  249. function hasIterator(maybeIterable) {
  250. return !!getIteratorFn(maybeIterable);
  251. }
  252. function isIterator(maybeIterator) {
  253. return maybeIterator && typeof maybeIterator.next === 'function';
  254. }
  255. function getIterator(iterable) {
  256. var iteratorFn = getIteratorFn(iterable);
  257. return iteratorFn && iteratorFn.call(iterable);
  258. }
  259. function getIteratorFn(iterable) {
  260. var iteratorFn = iterable && (
  261. (REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  262. iterable[FAUX_ITERATOR_SYMBOL]
  263. );
  264. if (typeof iteratorFn === 'function') {
  265. return iteratorFn;
  266. }
  267. }
  268. function isArrayLike(value) {
  269. return value && typeof value.length === 'number';
  270. }
  271. createClass(Seq, Iterable);
  272. function Seq(value) {
  273. return value === null || value === undefined ? emptySequence() :
  274. isIterable(value) ? value.toSeq() : seqFromValue(value);
  275. }
  276. Seq.of = function(/*...values*/) {
  277. return Seq(arguments);
  278. };
  279. Seq.prototype.toSeq = function() {
  280. return this;
  281. };
  282. Seq.prototype.toString = function() {
  283. return this.__toString('Seq {', '}');
  284. };
  285. Seq.prototype.cacheResult = function() {
  286. if (!this._cache && this.__iterateUncached) {
  287. this._cache = this.entrySeq().toArray();
  288. this.size = this._cache.length;
  289. }
  290. return this;
  291. };
  292. // abstract __iterateUncached(fn, reverse)
  293. Seq.prototype.__iterate = function(fn, reverse) {
  294. return seqIterate(this, fn, reverse, true);
  295. };
  296. // abstract __iteratorUncached(type, reverse)
  297. Seq.prototype.__iterator = function(type, reverse) {
  298. return seqIterator(this, type, reverse, true);
  299. };
  300. createClass(KeyedSeq, Seq);
  301. function KeyedSeq(value) {
  302. return value === null || value === undefined ?
  303. emptySequence().toKeyedSeq() :
  304. isIterable(value) ?
  305. (isKeyed(value) ? value.toSeq() : value.fromEntrySeq()) :
  306. keyedSeqFromValue(value);
  307. }
  308. KeyedSeq.prototype.toKeyedSeq = function() {
  309. return this;
  310. };
  311. createClass(IndexedSeq, Seq);
  312. function IndexedSeq(value) {
  313. return value === null || value === undefined ? emptySequence() :
  314. !isIterable(value) ? indexedSeqFromValue(value) :
  315. isKeyed(value) ? value.entrySeq() : value.toIndexedSeq();
  316. }
  317. IndexedSeq.of = function(/*...values*/) {
  318. return IndexedSeq(arguments);
  319. };
  320. IndexedSeq.prototype.toIndexedSeq = function() {
  321. return this;
  322. };
  323. IndexedSeq.prototype.toString = function() {
  324. return this.__toString('Seq [', ']');
  325. };
  326. IndexedSeq.prototype.__iterate = function(fn, reverse) {
  327. return seqIterate(this, fn, reverse, false);
  328. };
  329. IndexedSeq.prototype.__iterator = function(type, reverse) {
  330. return seqIterator(this, type, reverse, false);
  331. };
  332. createClass(SetSeq, Seq);
  333. function SetSeq(value) {
  334. return (
  335. value === null || value === undefined ? emptySequence() :
  336. !isIterable(value) ? indexedSeqFromValue(value) :
  337. isKeyed(value) ? value.entrySeq() : value
  338. ).toSetSeq();
  339. }
  340. SetSeq.of = function(/*...values*/) {
  341. return SetSeq(arguments);
  342. };
  343. SetSeq.prototype.toSetSeq = function() {
  344. return this;
  345. };
  346. Seq.isSeq = isSeq;
  347. Seq.Keyed = KeyedSeq;
  348. Seq.Set = SetSeq;
  349. Seq.Indexed = IndexedSeq;
  350. var IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
  351. Seq.prototype[IS_SEQ_SENTINEL] = true;
  352. createClass(ArraySeq, IndexedSeq);
  353. function ArraySeq(array) {
  354. this._array = array;
  355. this.size = array.length;
  356. }
  357. ArraySeq.prototype.get = function(index, notSetValue) {
  358. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  359. };
  360. ArraySeq.prototype.__iterate = function(fn, reverse) {
  361. var array = this._array;
  362. var maxIndex = array.length - 1;
  363. for (var ii = 0; ii <= maxIndex; ii++) {
  364. if (fn(array[reverse ? maxIndex - ii : ii], ii, this) === false) {
  365. return ii + 1;
  366. }
  367. }
  368. return ii;
  369. };
  370. ArraySeq.prototype.__iterator = function(type, reverse) {
  371. var array = this._array;
  372. var maxIndex = array.length - 1;
  373. var ii = 0;
  374. return new Iterator(function()
  375. {return ii > maxIndex ?
  376. iteratorDone() :
  377. iteratorValue(type, ii, array[reverse ? maxIndex - ii++ : ii++])}
  378. );
  379. };
  380. createClass(ObjectSeq, KeyedSeq);
  381. function ObjectSeq(object) {
  382. var keys = Object.keys(object);
  383. this._object = object;
  384. this._keys = keys;
  385. this.size = keys.length;
  386. }
  387. ObjectSeq.prototype.get = function(key, notSetValue) {
  388. if (notSetValue !== undefined && !this.has(key)) {
  389. return notSetValue;
  390. }
  391. return this._object[key];
  392. };
  393. ObjectSeq.prototype.has = function(key) {
  394. return this._object.hasOwnProperty(key);
  395. };
  396. ObjectSeq.prototype.__iterate = function(fn, reverse) {
  397. var object = this._object;
  398. var keys = this._keys;
  399. var maxIndex = keys.length - 1;
  400. for (var ii = 0; ii <= maxIndex; ii++) {
  401. var key = keys[reverse ? maxIndex - ii : ii];
  402. if (fn(object[key], key, this) === false) {
  403. return ii + 1;
  404. }
  405. }
  406. return ii;
  407. };
  408. ObjectSeq.prototype.__iterator = function(type, reverse) {
  409. var object = this._object;
  410. var keys = this._keys;
  411. var maxIndex = keys.length - 1;
  412. var ii = 0;
  413. return new Iterator(function() {
  414. var key = keys[reverse ? maxIndex - ii : ii];
  415. return ii++ > maxIndex ?
  416. iteratorDone() :
  417. iteratorValue(type, key, object[key]);
  418. });
  419. };
  420. ObjectSeq.prototype[IS_ORDERED_SENTINEL] = true;
  421. createClass(IterableSeq, IndexedSeq);
  422. function IterableSeq(iterable) {
  423. this._iterable = iterable;
  424. this.size = iterable.length || iterable.size;
  425. }
  426. IterableSeq.prototype.__iterateUncached = function(fn, reverse) {
  427. if (reverse) {
  428. return this.cacheResult().__iterate(fn, reverse);
  429. }
  430. var iterable = this._iterable;
  431. var iterator = getIterator(iterable);
  432. var iterations = 0;
  433. if (isIterator(iterator)) {
  434. var step;
  435. while (!(step = iterator.next()).done) {
  436. if (fn(step.value, iterations++, this) === false) {
  437. break;
  438. }
  439. }
  440. }
  441. return iterations;
  442. };
  443. IterableSeq.prototype.__iteratorUncached = function(type, reverse) {
  444. if (reverse) {
  445. return this.cacheResult().__iterator(type, reverse);
  446. }
  447. var iterable = this._iterable;
  448. var iterator = getIterator(iterable);
  449. if (!isIterator(iterator)) {
  450. return new Iterator(iteratorDone);
  451. }
  452. var iterations = 0;
  453. return new Iterator(function() {
  454. var step = iterator.next();
  455. return step.done ? step : iteratorValue(type, iterations++, step.value);
  456. });
  457. };
  458. createClass(IteratorSeq, IndexedSeq);
  459. function IteratorSeq(iterator) {
  460. this._iterator = iterator;
  461. this._iteratorCache = [];
  462. }
  463. IteratorSeq.prototype.__iterateUncached = function(fn, reverse) {
  464. if (reverse) {
  465. return this.cacheResult().__iterate(fn, reverse);
  466. }
  467. var iterator = this._iterator;
  468. var cache = this._iteratorCache;
  469. var iterations = 0;
  470. while (iterations < cache.length) {
  471. if (fn(cache[iterations], iterations++, this) === false) {
  472. return iterations;
  473. }
  474. }
  475. var step;
  476. while (!(step = iterator.next()).done) {
  477. var val = step.value;
  478. cache[iterations] = val;
  479. if (fn(val, iterations++, this) === false) {
  480. break;
  481. }
  482. }
  483. return iterations;
  484. };
  485. IteratorSeq.prototype.__iteratorUncached = function(type, reverse) {
  486. if (reverse) {
  487. return this.cacheResult().__iterator(type, reverse);
  488. }
  489. var iterator = this._iterator;
  490. var cache = this._iteratorCache;
  491. var iterations = 0;
  492. return new Iterator(function() {
  493. if (iterations >= cache.length) {
  494. var step = iterator.next();
  495. if (step.done) {
  496. return step;
  497. }
  498. cache[iterations] = step.value;
  499. }
  500. return iteratorValue(type, iterations, cache[iterations++]);
  501. });
  502. };
  503. // # pragma Helper functions
  504. function isSeq(maybeSeq) {
  505. return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]);
  506. }
  507. var EMPTY_SEQ;
  508. function emptySequence() {
  509. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  510. }
  511. function keyedSeqFromValue(value) {
  512. var seq =
  513. Array.isArray(value) ? new ArraySeq(value).fromEntrySeq() :
  514. isIterator(value) ? new IteratorSeq(value).fromEntrySeq() :
  515. hasIterator(value) ? new IterableSeq(value).fromEntrySeq() :
  516. typeof value === 'object' ? new ObjectSeq(value) :
  517. undefined;
  518. if (!seq) {
  519. throw new TypeError(
  520. 'Expected Array or iterable object of [k, v] entries, '+
  521. 'or keyed object: ' + value
  522. );
  523. }
  524. return seq;
  525. }
  526. function indexedSeqFromValue(value) {
  527. var seq = maybeIndexedSeqFromValue(value);
  528. if (!seq) {
  529. throw new TypeError(
  530. 'Expected Array or iterable object of values: ' + value
  531. );
  532. }
  533. return seq;
  534. }
  535. function seqFromValue(value) {
  536. var seq = maybeIndexedSeqFromValue(value) ||
  537. (typeof value === 'object' && new ObjectSeq(value));
  538. if (!seq) {
  539. throw new TypeError(
  540. 'Expected Array or iterable object of values, or keyed object: ' + value
  541. );
  542. }
  543. return seq;
  544. }
  545. function maybeIndexedSeqFromValue(value) {
  546. return (
  547. isArrayLike(value) ? new ArraySeq(value) :
  548. isIterator(value) ? new IteratorSeq(value) :
  549. hasIterator(value) ? new IterableSeq(value) :
  550. undefined
  551. );
  552. }
  553. function seqIterate(seq, fn, reverse, useKeys) {
  554. var cache = seq._cache;
  555. if (cache) {
  556. var maxIndex = cache.length - 1;
  557. for (var ii = 0; ii <= maxIndex; ii++) {
  558. var entry = cache[reverse ? maxIndex - ii : ii];
  559. if (fn(entry[1], useKeys ? entry[0] : ii, seq) === false) {
  560. return ii + 1;
  561. }
  562. }
  563. return ii;
  564. }
  565. return seq.__iterateUncached(fn, reverse);
  566. }
  567. function seqIterator(seq, type, reverse, useKeys) {
  568. var cache = seq._cache;
  569. if (cache) {
  570. var maxIndex = cache.length - 1;
  571. var ii = 0;
  572. return new Iterator(function() {
  573. var entry = cache[reverse ? maxIndex - ii : ii];
  574. return ii++ > maxIndex ?
  575. iteratorDone() :
  576. iteratorValue(type, useKeys ? entry[0] : ii - 1, entry[1]);
  577. });
  578. }
  579. return seq.__iteratorUncached(type, reverse);
  580. }
  581. function fromJS(json, converter) {
  582. return converter ?
  583. fromJSWith(converter, json, '', {'': json}) :
  584. fromJSDefault(json);
  585. }
  586. function fromJSWith(converter, json, key, parentJSON) {
  587. if (Array.isArray(json)) {
  588. return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  589. }
  590. if (isPlainObj(json)) {
  591. return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  592. }
  593. return json;
  594. }
  595. function fromJSDefault(json) {
  596. if (Array.isArray(json)) {
  597. return IndexedSeq(json).map(fromJSDefault).toList();
  598. }
  599. if (isPlainObj(json)) {
  600. return KeyedSeq(json).map(fromJSDefault).toMap();
  601. }
  602. return json;
  603. }
  604. function isPlainObj(value) {
  605. return value && (value.constructor === Object || value.constructor === undefined);
  606. }
  607. /**
  608. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  609. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  610. *
  611. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  612. * value, which is different from the algorithm described by
  613. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  614. *
  615. * This is extended further to allow Objects to describe the values they
  616. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  617. *
  618. * Note: because of this extension, the key equality of Immutable.Map and the
  619. * value equality of Immutable.Set will differ from ES6 Map and Set.
  620. *
  621. * ### Defining custom values
  622. *
  623. * The easiest way to describe the value an object represents is by implementing
  624. * `valueOf`. For example, `Date` represents a value by returning a unix
  625. * timestamp for `valueOf`:
  626. *
  627. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  628. * var date2 = new Date(1234567890000);
  629. * date1.valueOf(); // 1234567890000
  630. * assert( date1 !== date2 );
  631. * assert( Immutable.is( date1, date2 ) );
  632. *
  633. * Note: overriding `valueOf` may have other implications if you use this object
  634. * where JavaScript expects a primitive, such as implicit string coercion.
  635. *
  636. * For more complex types, especially collections, implementing `valueOf` may
  637. * not be performant. An alternative is to implement `equals` and `hashCode`.
  638. *
  639. * `equals` takes another object, presumably of similar type, and returns true
  640. * if the it is equal. Equality is symmetrical, so the same result should be
  641. * returned if this and the argument are flipped.
  642. *
  643. * assert( a.equals(b) === b.equals(a) );
  644. *
  645. * `hashCode` returns a 32bit integer number representing the object which will
  646. * be used to determine how to store the value object in a Map or Set. You must
  647. * provide both or neither methods, one must not exist without the other.
  648. *
  649. * Also, an important relationship between these methods must be upheld: if two
  650. * values are equal, they *must* return the same hashCode. If the values are not
  651. * equal, they might have the same hashCode; this is called a hash collision,
  652. * and while undesirable for performance reasons, it is acceptable.
  653. *
  654. * if (a.equals(b)) {
  655. * assert( a.hashCode() === b.hashCode() );
  656. * }
  657. *
  658. * All Immutable collections implement `equals` and `hashCode`.
  659. *
  660. */
  661. function is(valueA, valueB) {
  662. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  663. return true;
  664. }
  665. if (!valueA || !valueB) {
  666. return false;
  667. }
  668. if (typeof valueA.valueOf === 'function' &&
  669. typeof valueB.valueOf === 'function') {
  670. valueA = valueA.valueOf();
  671. valueB = valueB.valueOf();
  672. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  673. return true;
  674. }
  675. if (!valueA || !valueB) {
  676. return false;
  677. }
  678. }
  679. if (typeof valueA.equals === 'function' &&
  680. typeof valueB.equals === 'function' &&
  681. valueA.equals(valueB)) {
  682. return true;
  683. }
  684. return false;
  685. }
  686. function deepEqual(a, b) {
  687. if (a === b) {
  688. return true;
  689. }
  690. if (
  691. !isIterable(b) ||
  692. a.size !== undefined && b.size !== undefined && a.size !== b.size ||
  693. a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
  694. isKeyed(a) !== isKeyed(b) ||
  695. isIndexed(a) !== isIndexed(b) ||
  696. isOrdered(a) !== isOrdered(b)
  697. ) {
  698. return false;
  699. }
  700. if (a.size === 0 && b.size === 0) {
  701. return true;
  702. }
  703. var notAssociative = !isAssociative(a);
  704. if (isOrdered(a)) {
  705. var entries = a.entries();
  706. return b.every(function(v, k) {
  707. var entry = entries.next().value;
  708. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  709. }) && entries.next().done;
  710. }
  711. var flipped = false;
  712. if (a.size === undefined) {
  713. if (b.size === undefined) {
  714. if (typeof a.cacheResult === 'function') {
  715. a.cacheResult();
  716. }
  717. } else {
  718. flipped = true;
  719. var _ = a;
  720. a = b;
  721. b = _;
  722. }
  723. }
  724. var allEqual = true;
  725. var bSize = b.__iterate(function(v, k) {
  726. if (notAssociative ? !a.has(v) :
  727. flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
  728. allEqual = false;
  729. return false;
  730. }
  731. });
  732. return allEqual && a.size === bSize;
  733. }
  734. createClass(Repeat, IndexedSeq);
  735. function Repeat(value, times) {
  736. if (!(this instanceof Repeat)) {
  737. return new Repeat(value, times);
  738. }
  739. this._value = value;
  740. this.size = times === undefined ? Infinity : Math.max(0, times);
  741. if (this.size === 0) {
  742. if (EMPTY_REPEAT) {
  743. return EMPTY_REPEAT;
  744. }
  745. EMPTY_REPEAT = this;
  746. }
  747. }
  748. Repeat.prototype.toString = function() {
  749. if (this.size === 0) {
  750. return 'Repeat []';
  751. }
  752. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  753. };
  754. Repeat.prototype.get = function(index, notSetValue) {
  755. return this.has(index) ? this._value : notSetValue;
  756. };
  757. Repeat.prototype.includes = function(searchValue) {
  758. return is(this._value, searchValue);
  759. };
  760. Repeat.prototype.slice = function(begin, end) {
  761. var size = this.size;
  762. return wholeSlice(begin, end, size) ? this :
  763. new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
  764. };
  765. Repeat.prototype.reverse = function() {
  766. return this;
  767. };
  768. Repeat.prototype.indexOf = function(searchValue) {
  769. if (is(this._value, searchValue)) {
  770. return 0;
  771. }
  772. return -1;
  773. };
  774. Repeat.prototype.lastIndexOf = function(searchValue) {
  775. if (is(this._value, searchValue)) {
  776. return this.size;
  777. }
  778. return -1;
  779. };
  780. Repeat.prototype.__iterate = function(fn, reverse) {
  781. for (var ii = 0; ii < this.size; ii++) {
  782. if (fn(this._value, ii, this) === false) {
  783. return ii + 1;
  784. }
  785. }
  786. return ii;
  787. };
  788. Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
  789. var ii = 0;
  790. return new Iterator(function()
  791. {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
  792. );
  793. };
  794. Repeat.prototype.equals = function(other) {
  795. return other instanceof Repeat ?
  796. is(this._value, other._value) :
  797. deepEqual(other);
  798. };
  799. var EMPTY_REPEAT;
  800. function invariant(condition, error) {
  801. if (!condition) throw new Error(error);
  802. }
  803. createClass(Range, IndexedSeq);
  804. function Range(start, end, step) {
  805. if (!(this instanceof Range)) {
  806. return new Range(start, end, step);
  807. }
  808. invariant(step !== 0, 'Cannot step a Range by 0');
  809. start = start || 0;
  810. if (end === undefined) {
  811. end = Infinity;
  812. }
  813. step = step === undefined ? 1 : Math.abs(step);
  814. if (end < start) {
  815. step = -step;
  816. }
  817. this._start = start;
  818. this._end = end;
  819. this._step = step;
  820. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  821. if (this.size === 0) {
  822. if (EMPTY_RANGE) {
  823. return EMPTY_RANGE;
  824. }
  825. EMPTY_RANGE = this;
  826. }
  827. }
  828. Range.prototype.toString = function() {
  829. if (this.size === 0) {
  830. return 'Range []';
  831. }
  832. return 'Range [ ' +
  833. this._start + '...' + this._end +
  834. (this._step > 1 ? ' by ' + this._step : '') +
  835. ' ]';
  836. };
  837. Range.prototype.get = function(index, notSetValue) {
  838. return this.has(index) ?
  839. this._start + wrapIndex(this, index) * this._step :
  840. notSetValue;
  841. };
  842. Range.prototype.includes = function(searchValue) {
  843. var possibleIndex = (searchValue - this._start) / this._step;
  844. return possibleIndex >= 0 &&
  845. possibleIndex < this.size &&
  846. possibleIndex === Math.floor(possibleIndex);
  847. };
  848. Range.prototype.slice = function(begin, end) {
  849. if (wholeSlice(begin, end, this.size)) {
  850. return this;
  851. }
  852. begin = resolveBegin(begin, this.size);
  853. end = resolveEnd(end, this.size);
  854. if (end <= begin) {
  855. return new Range(0, 0);
  856. }
  857. return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
  858. };
  859. Range.prototype.indexOf = function(searchValue) {
  860. var offsetValue = searchValue - this._start;
  861. if (offsetValue % this._step === 0) {
  862. var index = offsetValue / this._step;
  863. if (index >= 0 && index < this.size) {
  864. return index
  865. }
  866. }
  867. return -1;
  868. };
  869. Range.prototype.lastIndexOf = function(searchValue) {
  870. return this.indexOf(searchValue);
  871. };
  872. Range.prototype.__iterate = function(fn, reverse) {
  873. var maxIndex = this.size - 1;
  874. var step = this._step;
  875. var value = reverse ? this._start + maxIndex * step : this._start;
  876. for (var ii = 0; ii <= maxIndex; ii++) {
  877. if (fn(value, ii, this) === false) {
  878. return ii + 1;
  879. }
  880. value += reverse ? -step : step;
  881. }
  882. return ii;
  883. };
  884. Range.prototype.__iterator = function(type, reverse) {
  885. var maxIndex = this.size - 1;
  886. var step = this._step;
  887. var value = reverse ? this._start + maxIndex * step : this._start;
  888. var ii = 0;
  889. return new Iterator(function() {
  890. var v = value;
  891. value += reverse ? -step : step;
  892. return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
  893. });
  894. };
  895. Range.prototype.equals = function(other) {
  896. return other instanceof Range ?
  897. this._start === other._start &&
  898. this._end === other._end &&
  899. this._step === other._step :
  900. deepEqual(this, other);
  901. };
  902. var EMPTY_RANGE;
  903. createClass(Collection, Iterable);
  904. function Collection() {
  905. throw TypeError('Abstract');
  906. }
  907. createClass(KeyedCollection, Collection);function KeyedCollection() {}
  908. createClass(IndexedCollection, Collection);function IndexedCollection() {}
  909. createClass(SetCollection, Collection);function SetCollection() {}
  910. Collection.Keyed = KeyedCollection;
  911. Collection.Indexed = IndexedCollection;
  912. Collection.Set = SetCollection;
  913. var imul =
  914. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
  915. Math.imul :
  916. function imul(a, b) {
  917. a = a | 0; // int
  918. b = b | 0; // int
  919. var c = a & 0xffff;
  920. var d = b & 0xffff;
  921. // Shift by 0 fixes the sign on the high part.
  922. return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int
  923. };
  924. // v8 has an optimization for storing 31-bit signed numbers.
  925. // Values which have either 00 or 11 as the high order bits qualify.
  926. // This function drops the highest order bit in a signed number, maintaining
  927. // the sign bit.
  928. function smi(i32) {
  929. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
  930. }
  931. function hash(o) {
  932. if (o === false || o === null || o === undefined) {
  933. return 0;
  934. }
  935. if (typeof o.valueOf === 'function') {
  936. o = o.valueOf();
  937. if (o === false || o === null || o === undefined) {
  938. return 0;
  939. }
  940. }
  941. if (o === true) {
  942. return 1;
  943. }
  944. var type = typeof o;
  945. if (type === 'number') {
  946. var h = o | 0;
  947. if (h !== o) {
  948. h ^= o * 0xFFFFFFFF;
  949. }
  950. while (o > 0xFFFFFFFF) {
  951. o /= 0xFFFFFFFF;
  952. h ^= o;
  953. }
  954. return smi(h);
  955. }
  956. if (type === 'string') {
  957. return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
  958. }
  959. if (typeof o.hashCode === 'function') {
  960. return o.hashCode();
  961. }
  962. if (type === 'object') {
  963. return hashJSObj(o);
  964. }
  965. if (typeof o.toString === 'function') {
  966. return hashString(o.toString());
  967. }
  968. throw new Error('Value type ' + type + ' cannot be hashed.');
  969. }
  970. function cachedHashString(string) {
  971. var hash = stringHashCache[string];
  972. if (hash === undefined) {
  973. hash = hashString(string);
  974. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  975. STRING_HASH_CACHE_SIZE = 0;
  976. stringHashCache = {};
  977. }
  978. STRING_HASH_CACHE_SIZE++;
  979. stringHashCache[string] = hash;
  980. }
  981. return hash;
  982. }
  983. // http://jsperf.com/hashing-strings
  984. function hashString(string) {
  985. // This is the hash from JVM
  986. // The hash code for a string is computed as
  987. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  988. // where s[i] is the ith character of the string and n is the length of
  989. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  990. // (exclusive) by dropping high bits.
  991. var hash = 0;
  992. for (var ii = 0; ii < string.length; ii++) {
  993. hash = 31 * hash + string.charCodeAt(ii) | 0;
  994. }
  995. return smi(hash);
  996. }
  997. function hashJSObj(obj) {
  998. var hash;
  999. if (usingWeakMap) {
  1000. hash = weakMap.get(obj);
  1001. if (hash !== undefined) {
  1002. return hash;
  1003. }
  1004. }
  1005. hash = obj[UID_HASH_KEY];
  1006. if (hash !== undefined) {
  1007. return hash;
  1008. }
  1009. if (!canDefineProperty) {
  1010. hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  1011. if (hash !== undefined) {
  1012. return hash;
  1013. }
  1014. hash = getIENodeHash(obj);
  1015. if (hash !== undefined) {
  1016. return hash;
  1017. }
  1018. }
  1019. hash = ++objHashUID;
  1020. if (objHashUID & 0x40000000) {
  1021. objHashUID = 0;
  1022. }
  1023. if (usingWeakMap) {
  1024. weakMap.set(obj, hash);
  1025. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  1026. throw new Error('Non-extensible objects are not allowed as keys.');
  1027. } else if (canDefineProperty) {
  1028. Object.defineProperty(obj, UID_HASH_KEY, {
  1029. 'enumerable': false,
  1030. 'configurable': false,
  1031. 'writable': false,
  1032. 'value': hash
  1033. });
  1034. } else if (obj.propertyIsEnumerable !== undefined &&
  1035. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
  1036. // Since we can't define a non-enumerable property on the object
  1037. // we'll hijack one of the less-used non-enumerable properties to
  1038. // save our hash on it. Since this is a function it will not show up in
  1039. // `JSON.stringify` which is what we want.
  1040. obj.propertyIsEnumerable = function() {
  1041. return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
  1042. };
  1043. obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
  1044. } else if (obj.nodeType !== undefined) {
  1045. // At this point we couldn't get the IE `uniqueID` to use as a hash
  1046. // and we couldn't use a non-enumerable property to exploit the
  1047. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  1048. // itself.
  1049. obj[UID_HASH_KEY] = hash;
  1050. } else {
  1051. throw new Error('Unable to set a non-enumerable property on object.');
  1052. }
  1053. return hash;
  1054. }
  1055. // Get references to ES5 object methods.
  1056. var isExtensible = Object.isExtensible;
  1057. // True if Object.defineProperty works as expected. IE8 fails this test.
  1058. var canDefineProperty = (function() {
  1059. try {
  1060. Object.defineProperty({}, '@', {});
  1061. return true;
  1062. } catch (e) {
  1063. return false;
  1064. }
  1065. }());
  1066. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  1067. // and avoid memory leaks from the IE cloneNode bug.
  1068. function getIENodeHash(node) {
  1069. if (node && node.nodeType > 0) {
  1070. switch (node.nodeType) {
  1071. case 1: // Element
  1072. return node.uniqueID;
  1073. case 9: // Document
  1074. return node.documentElement && node.documentElement.uniqueID;
  1075. }
  1076. }
  1077. }
  1078. // If possible, use a WeakMap.
  1079. var usingWeakMap = typeof WeakMap === 'function';
  1080. var weakMap;
  1081. if (usingWeakMap) {
  1082. weakMap = new WeakMap();
  1083. }
  1084. var objHashUID = 0;
  1085. var UID_HASH_KEY = '__immutablehash__';
  1086. if (typeof Symbol === 'function') {
  1087. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  1088. }
  1089. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  1090. var STRING_HASH_CACHE_MAX_SIZE = 255;
  1091. var STRING_HASH_CACHE_SIZE = 0;
  1092. var stringHashCache = {};
  1093. function assertNotInfinite(size) {
  1094. invariant(
  1095. size !== Infinity,
  1096. 'Cannot perform this action with an infinite size.'
  1097. );
  1098. }
  1099. createClass(Map, KeyedCollection);
  1100. // @pragma Construction
  1101. function Map(value) {
  1102. return value === null || value === undefined ? emptyMap() :
  1103. isMap(value) && !isOrdered(value) ? value :
  1104. emptyMap().withMutations(function(map ) {
  1105. var iter = KeyedIterable(value);
  1106. assertNotInfinite(iter.size);
  1107. iter.forEach(function(v, k) {return map.set(k, v)});
  1108. });
  1109. }
  1110. Map.prototype.toString = function() {
  1111. return this.__toString('Map {', '}');
  1112. };
  1113. // @pragma Access
  1114. Map.prototype.get = function(k, notSetValue) {
  1115. return this._root ?
  1116. this._root.get(0, undefined, k, notSetValue) :
  1117. notSetValue;
  1118. };
  1119. // @pragma Modification
  1120. Map.prototype.set = function(k, v) {
  1121. return updateMap(this, k, v);
  1122. };
  1123. Map.prototype.setIn = function(keyPath, v) {
  1124. return this.updateIn(keyPath, NOT_SET, function() {return v});
  1125. };
  1126. Map.prototype.remove = function(k) {
  1127. return updateMap(this, k, NOT_SET);
  1128. };
  1129. Map.prototype.deleteIn = function(keyPath) {
  1130. return this.updateIn(keyPath, function() {return NOT_SET});
  1131. };
  1132. Map.prototype.update = function(k, notSetValue, updater) {
  1133. return arguments.length === 1 ?
  1134. k(this) :
  1135. this.updateIn([k], notSetValue, updater);
  1136. };
  1137. Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
  1138. if (!updater) {
  1139. updater = notSetValue;
  1140. notSetValue = undefined;
  1141. }
  1142. var updatedValue = updateInDeepMap(
  1143. this,
  1144. forceIterator(keyPath),
  1145. notSetValue,
  1146. updater
  1147. );
  1148. return updatedValue === NOT_SET ? undefined : updatedValue;
  1149. };
  1150. Map.prototype.clear = function() {
  1151. if (this.size === 0) {
  1152. return this;
  1153. }
  1154. if (this.__ownerID) {
  1155. this.size = 0;
  1156. this._root = null;
  1157. this.__hash = undefined;
  1158. this.__altered = true;
  1159. return this;
  1160. }
  1161. return emptyMap();
  1162. };
  1163. // @pragma Composition
  1164. Map.prototype.merge = function(/*...iters*/) {
  1165. return mergeIntoMapWith(this, undefined, arguments);
  1166. };
  1167. Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1168. return mergeIntoMapWith(this, merger, iters);
  1169. };
  1170. Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  1171. return this.updateIn(
  1172. keyPath,
  1173. emptyMap(),
  1174. function(m ) {return typeof m.merge === 'function' ?
  1175. m.merge.apply(m, iters) :
  1176. iters[iters.length - 1]}
  1177. );
  1178. };
  1179. Map.prototype.mergeDeep = function(/*...iters*/) {
  1180. return mergeIntoMapWith(this, deepMerger, arguments);
  1181. };
  1182. Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1183. return mergeIntoMapWith(this, deepMergerWith(merger), iters);
  1184. };
  1185. Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  1186. return this.updateIn(
  1187. keyPath,
  1188. emptyMap(),
  1189. function(m ) {return typeof m.mergeDeep === 'function' ?
  1190. m.mergeDeep.apply(m, iters) :
  1191. iters[iters.length - 1]}
  1192. );
  1193. };
  1194. Map.prototype.sort = function(comparator) {
  1195. // Late binding
  1196. return OrderedMap(sortFactory(this, comparator));
  1197. };
  1198. Map.prototype.sortBy = function(mapper, comparator) {
  1199. // Late binding
  1200. return OrderedMap(sortFactory(this, comparator, mapper));
  1201. };
  1202. // @pragma Mutability
  1203. Map.prototype.withMutations = function(fn) {
  1204. var mutable = this.asMutable();
  1205. fn(mutable);
  1206. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  1207. };
  1208. Map.prototype.asMutable = function() {
  1209. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  1210. };
  1211. Map.prototype.asImmutable = function() {
  1212. return this.__ensureOwner();
  1213. };
  1214. Map.prototype.wasAltered = function() {
  1215. return this.__altered;
  1216. };
  1217. Map.prototype.__iterator = function(type, reverse) {
  1218. return new MapIterator(this, type, reverse);
  1219. };
  1220. Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  1221. var iterations = 0;
  1222. this._root && this._root.iterate(function(entry ) {
  1223. iterations++;
  1224. return fn(entry[1], entry[0], this$0);
  1225. }, reverse);
  1226. return iterations;
  1227. };
  1228. Map.prototype.__ensureOwner = function(ownerID) {
  1229. if (ownerID === this.__ownerID) {
  1230. return this;
  1231. }
  1232. if (!ownerID) {
  1233. this.__ownerID = ownerID;
  1234. this.__altered = false;
  1235. return this;
  1236. }
  1237. return makeMap(this.size, this._root, ownerID, this.__hash);
  1238. };
  1239. function isMap(maybeMap) {
  1240. return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
  1241. }
  1242. Map.isMap = isMap;
  1243. var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
  1244. var MapPrototype = Map.prototype;
  1245. MapPrototype[IS_MAP_SENTINEL] = true;
  1246. MapPrototype[DELETE] = MapPrototype.remove;
  1247. MapPrototype.removeIn = MapPrototype.deleteIn;
  1248. // #pragma Trie Nodes
  1249. function ArrayMapNode(ownerID, entries) {
  1250. this.ownerID = ownerID;
  1251. this.entries = entries;
  1252. }
  1253. ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1254. var entries = this.entries;
  1255. for (var ii = 0, len = entries.length; ii < len; ii++) {
  1256. if (is(key, entries[ii][0])) {
  1257. return entries[ii][1];
  1258. }
  1259. }
  1260. return notSetValue;
  1261. };
  1262. ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1263. var removed = value === NOT_SET;
  1264. var entries = this.entries;
  1265. var idx = 0;
  1266. for (var len = entries.length; idx < len; idx++) {
  1267. if (is(key, entries[idx][0])) {
  1268. break;
  1269. }
  1270. }
  1271. var exists = idx < len;
  1272. if (exists ? entries[idx][1] === value : removed) {
  1273. return this;
  1274. }
  1275. SetRef(didAlter);
  1276. (removed || !exists) && SetRef(didChangeSize);
  1277. if (removed && entries.length === 1) {
  1278. return; // undefined
  1279. }
  1280. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  1281. return createNodes(ownerID, entries, key, value);
  1282. }
  1283. var isEditable = ownerID && ownerID === this.ownerID;
  1284. var newEntries = isEditable ? entries : arrCopy(entries);
  1285. if (exists) {
  1286. if (removed) {
  1287. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  1288. } else {
  1289. newEntries[idx] = [key, value];
  1290. }
  1291. } else {
  1292. newEntries.push([key, value]);
  1293. }
  1294. if (isEditable) {
  1295. this.entries = newEntries;
  1296. return this;
  1297. }
  1298. return new ArrayMapNode(ownerID, newEntries);
  1299. };
  1300. function BitmapIndexedNode(ownerID, bitmap, nodes) {
  1301. this.ownerID = ownerID;
  1302. this.bitmap = bitmap;
  1303. this.nodes = nodes;
  1304. }
  1305. BitmapIndexedNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1306. if (keyHash === undefined) {
  1307. keyHash = hash(key);
  1308. }
  1309. var bit = (1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK));
  1310. var bitmap = this.bitmap;
  1311. return (bitmap & bit) === 0 ? notSetValue :
  1312. this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue);
  1313. };
  1314. BitmapIndexedNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1315. if (keyHash === undefined) {
  1316. keyHash = hash(key);
  1317. }
  1318. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1319. var bit = 1 << keyHashFrag;
  1320. var bitmap = this.bitmap;
  1321. var exists = (bitmap & bit) !== 0;
  1322. if (!exists && value === NOT_SET) {
  1323. return this;
  1324. }
  1325. var idx = popCount(bitmap & (bit - 1));
  1326. var nodes = this.nodes;
  1327. var node = exists ? nodes[idx] : undefined;
  1328. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  1329. if (newNode === node) {
  1330. return this;
  1331. }
  1332. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  1333. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  1334. }
  1335. if (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) {
  1336. return nodes[idx ^ 1];
  1337. }
  1338. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  1339. return newNode;
  1340. }
  1341. var isEditable = ownerID && ownerID === this.ownerID;
  1342. var newBitmap = exists ? newNode ? bitmap : bitmap ^ bit : bitmap | bit;
  1343. var newNodes = exists ? newNode ?
  1344. setIn(nodes, idx, newNode, isEditable) :
  1345. spliceOut(nodes, idx, isEditable) :
  1346. spliceIn(nodes, idx, newNode, isEditable);
  1347. if (isEditable) {
  1348. this.bitmap = newBitmap;
  1349. this.nodes = newNodes;
  1350. return this;
  1351. }
  1352. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  1353. };
  1354. function HashArrayMapNode(ownerID, count, nodes) {
  1355. this.ownerID = ownerID;
  1356. this.count = count;
  1357. this.nodes = nodes;
  1358. }
  1359. HashArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1360. if (keyHash === undefined) {
  1361. keyHash = hash(key);
  1362. }
  1363. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1364. var node = this.nodes[idx];
  1365. return node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue;
  1366. };
  1367. HashArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1368. if (keyHash === undefined) {
  1369. keyHash = hash(key);
  1370. }
  1371. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1372. var removed = value === NOT_SET;
  1373. var nodes = this.nodes;
  1374. var node = nodes[idx];
  1375. if (removed && !node) {
  1376. return this;
  1377. }
  1378. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  1379. if (newNode === node) {
  1380. return this;
  1381. }
  1382. var newCount = this.count;
  1383. if (!node) {
  1384. newCount++;
  1385. } else if (!newNode) {
  1386. newCount--;
  1387. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  1388. return packNodes(ownerID, nodes, newCount, idx);
  1389. }
  1390. }
  1391. var isEditable = ownerID && ownerID === this.ownerID;
  1392. var newNodes = setIn(nodes, idx, newNode, isEditable);
  1393. if (isEditable) {
  1394. this.count = newCount;
  1395. this.nodes = newNodes;
  1396. return this;
  1397. }
  1398. return new HashArrayMapNode(ownerID, newCount, newNodes);
  1399. };
  1400. function HashCollisionNode(ownerID, keyHash, entries) {
  1401. this.ownerID = ownerID;
  1402. this.keyHash = keyHash;
  1403. this.entries = entries;
  1404. }
  1405. HashCollisionNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1406. var entries = this.entries;
  1407. for (var ii = 0, len = entries.length; ii < len; ii++) {
  1408. if (is(key, entries[ii][0])) {
  1409. return entries[ii][1];
  1410. }
  1411. }
  1412. return notSetValue;
  1413. };
  1414. HashCollisionNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1415. if (keyHash === undefined) {
  1416. keyHash = hash(key);
  1417. }
  1418. var removed = value === NOT_SET;
  1419. if (keyHash !== this.keyHash) {
  1420. if (removed) {
  1421. return this;
  1422. }
  1423. SetRef(didAlter);
  1424. SetRef(didChangeSize);
  1425. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  1426. }
  1427. var entries = this.entries;
  1428. var idx = 0;
  1429. for (var len = entries.length; idx < len; idx++) {
  1430. if (is(key, entries[idx][0])) {
  1431. break;
  1432. }
  1433. }
  1434. var exists = idx < len;
  1435. if (exists ? entries[idx][1] === value : removed) {
  1436. return this;
  1437. }
  1438. SetRef(didAlter);
  1439. (removed || !exists) && SetRef(didChangeSize);
  1440. if (removed && len === 2) {
  1441. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  1442. }
  1443. var isEditable = ownerID && ownerID === this.ownerID;
  1444. var newEntries = isEditable ? entries : arrCopy(entries);
  1445. if (exists) {
  1446. if (removed) {
  1447. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  1448. } else {
  1449. newEntries[idx] = [key, value];
  1450. }
  1451. } else {
  1452. newEntries.push([key, value]);
  1453. }
  1454. if (isEditable) {
  1455. this.entries = newEntries;
  1456. return this;
  1457. }
  1458. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  1459. };
  1460. function ValueNode(ownerID, keyHash, entry) {
  1461. this.ownerID = ownerID;
  1462. this.keyHash = keyHash;
  1463. this.entry = entry;
  1464. }
  1465. ValueNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1466. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  1467. };
  1468. ValueNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1469. var removed = value === NOT_SET;
  1470. var keyMatch = is(key, this.entry[0]);
  1471. if (keyMatch ? value === this.entry[1] : removed) {
  1472. return this;
  1473. }
  1474. SetRef(didAlter);
  1475. if (removed) {
  1476. SetRef(didChangeSize);
  1477. return; // undefined
  1478. }
  1479. if (keyMatch) {
  1480. if (ownerID && ownerID === this.ownerID) {
  1481. this.entry[1] = value;
  1482. return this;
  1483. }
  1484. return new ValueNode(ownerID, this.keyHash, [key, value]);
  1485. }
  1486. SetRef(didChangeSize);
  1487. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  1488. };
  1489. // #pragma Iterators
  1490. ArrayMapNode.prototype.iterate =
  1491. HashCollisionNode.prototype.iterate = function (fn, reverse) {
  1492. var entries = this.entries;
  1493. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  1494. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  1495. return false;
  1496. }
  1497. }
  1498. };
  1499. BitmapIndexedNode.prototype.iterate =
  1500. HashArrayMapNode.prototype.iterate = function (fn, reverse) {
  1501. var nodes = this.nodes;
  1502. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  1503. var node = nodes[reverse ? maxIndex - ii : ii];
  1504. if (node && node.iterate(fn, reverse) === false) {
  1505. return false;
  1506. }
  1507. }
  1508. };
  1509. ValueNode.prototype.iterate = function (fn, reverse) {
  1510. return fn(this.entry);
  1511. };
  1512. createClass(MapIterator, Iterator);
  1513. function MapIterator(map, type, reverse) {
  1514. this._type = type;
  1515. this._reverse = reverse;
  1516. this._stack = map._root && mapIteratorFrame(map._root);
  1517. }
  1518. MapIterator.prototype.next = function() {
  1519. var type = this._type;
  1520. var stack = this._stack;
  1521. while (stack) {
  1522. var node = stack.node;
  1523. var index = stack.index++;
  1524. var maxIndex;
  1525. if (node.entry) {
  1526. if (index === 0) {
  1527. return mapIteratorValue(type, node.entry);
  1528. }
  1529. } else if (node.entries) {
  1530. maxIndex = node.entries.length - 1;
  1531. if (index <= maxIndex) {
  1532. return mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index]);
  1533. }
  1534. } else {
  1535. maxIndex = node.nodes.length - 1;
  1536. if (index <= maxIndex) {
  1537. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  1538. if (subNode) {
  1539. if (subNode.entry) {
  1540. return mapIteratorValue(type, subNode.entry);
  1541. }
  1542. stack = this._stack = mapIteratorFrame(subNode, stack);
  1543. }
  1544. continue;
  1545. }
  1546. }
  1547. stack = this._stack = this._stack.__prev;
  1548. }
  1549. return iteratorDone();
  1550. };
  1551. function mapIteratorValue(type, entry) {
  1552. return iteratorValue(type, entry[0], entry[1]);
  1553. }
  1554. function mapIteratorFrame(node, prev) {
  1555. return {
  1556. node: node,
  1557. index: 0,
  1558. __prev: prev
  1559. };
  1560. }
  1561. function makeMap(size, root, ownerID, hash) {
  1562. var map = Object.create(MapPrototype);
  1563. map.size = size;
  1564. map._root = root;
  1565. map.__ownerID = ownerID;
  1566. map.__hash = hash;
  1567. map.__altered = false;
  1568. return map;
  1569. }
  1570. var EMPTY_MAP;
  1571. function emptyMap() {
  1572. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  1573. }
  1574. function updateMap(map, k, v) {
  1575. var newRoot;
  1576. var newSize;
  1577. if (!map._root) {
  1578. if (v === NOT_SET) {
  1579. return map;
  1580. }
  1581. newSize = 1;
  1582. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  1583. } else {
  1584. var didChangeSize = MakeRef(CHANGE_LENGTH);
  1585. var didAlter = MakeRef(DID_ALTER);
  1586. newRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter);
  1587. if (!didAlter.value) {
  1588. return map;
  1589. }
  1590. newSize = map.size + (didChangeSize.value ? v === NOT_SET ? -1 : 1 : 0);
  1591. }
  1592. if (map.__ownerID) {
  1593. map.size = newSize;
  1594. map._root = newRoot;
  1595. map.__hash = undefined;
  1596. map.__altered = true;
  1597. return map;
  1598. }
  1599. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  1600. }
  1601. function updateNode(node, ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1602. if (!node) {
  1603. if (value === NOT_SET) {
  1604. return node;
  1605. }
  1606. SetRef(didAlter);
  1607. SetRef(didChangeSize);
  1608. return new ValueNode(ownerID, keyHash, [key, value]);
  1609. }
  1610. return node.update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter);
  1611. }
  1612. function isLeafNode(node) {
  1613. return node.constructor === ValueNode || node.constructor === HashCollisionNode;
  1614. }
  1615. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  1616. if (node.keyHash === keyHash) {
  1617. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  1618. }
  1619. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  1620. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1621. var newNode;
  1622. var nodes = idx1 === idx2 ?
  1623. [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)] :
  1624. ((newNode = new ValueNode(ownerID, keyHash, entry)), idx1 < idx2 ? [node, newNode] : [newNode, node]);
  1625. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  1626. }
  1627. function createNodes(ownerID, entries, key, value) {
  1628. if (!ownerID) {
  1629. ownerID = new OwnerID();
  1630. }
  1631. var node = new ValueNode(ownerID, hash(key), [key, value]);
  1632. for (var ii = 0; ii < entries.length; ii++) {
  1633. var entry = entries[ii];
  1634. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  1635. }
  1636. return node;
  1637. }
  1638. function packNodes(ownerID, nodes, count, excluding) {
  1639. var bitmap = 0;
  1640. var packedII = 0;
  1641. var packedNodes = new Array(count);
  1642. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  1643. var node = nodes[ii];
  1644. if (node !== undefined && ii !== excluding) {
  1645. bitmap |= bit;
  1646. packedNodes[packedII++] = node;
  1647. }
  1648. }
  1649. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  1650. }
  1651. function expandNodes(ownerID, nodes, bitmap, including, node) {
  1652. var count = 0;
  1653. var expandedNodes = new Array(SIZE);
  1654. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  1655. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  1656. }
  1657. expandedNodes[including] = node;
  1658. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  1659. }
  1660. function mergeIntoMapWith(map, merger, iterables) {
  1661. var iters = [];
  1662. for (var ii = 0; ii < iterables.length; ii++) {
  1663. var value = iterables[ii];
  1664. var iter = KeyedIterable(value);
  1665. if (!isIterable(value)) {
  1666. iter = iter.map(function(v ) {return fromJS(v)});
  1667. }
  1668. iters.push(iter);
  1669. }
  1670. return mergeIntoCollectionWith(map, merger, iters);
  1671. }
  1672. function deepMerger(existing, value, key) {
  1673. return existing && existing.mergeDeep && isIterable(value) ?
  1674. existing.mergeDeep(value) :
  1675. is(existing, value) ? existing : value;
  1676. }
  1677. function deepMergerWith(merger) {
  1678. return function(existing, value, key) {
  1679. if (existing && existing.mergeDeepWith && isIterable(value)) {
  1680. return existing.mergeDeepWith(merger, value);
  1681. }
  1682. var nextValue = merger(existing, value, key);
  1683. return is(existing, nextValue) ? existing : nextValue;
  1684. };
  1685. }
  1686. function mergeIntoCollectionWith(collection, merger, iters) {
  1687. iters = iters.filter(function(x ) {return x.size !== 0});
  1688. if (iters.length === 0) {
  1689. return collection;
  1690. }
  1691. if (collection.size === 0 && !collection.__ownerID && iters.length === 1) {
  1692. return collection.constructor(iters[0]);
  1693. }
  1694. return collection.withMutations(function(collection ) {
  1695. var mergeIntoMap = merger ?
  1696. function(value, key) {
  1697. collection.update(key, NOT_SET, function(existing )
  1698. {return existing === NOT_SET ? value : merger(existing, value, key)}
  1699. );
  1700. } :
  1701. function(value, key) {
  1702. collection.set(key, value);
  1703. };
  1704. for (var ii = 0; ii < iters.length; ii++) {
  1705. iters[ii].forEach(mergeIntoMap);
  1706. }
  1707. });
  1708. }
  1709. function updateInDeepMap(existing, keyPathIter, notSetValue, updater) {
  1710. var isNotSet = existing === NOT_SET;
  1711. var step = keyPathIter.next();
  1712. if (step.done) {
  1713. var existingValue = isNotSet ? notSetValue : existing;
  1714. var newValue = updater(existingValue);
  1715. return newValue === existingValue ? existing : newValue;
  1716. }
  1717. invariant(
  1718. isNotSet || (existing && existing.set),
  1719. 'invalid keyPath'
  1720. );
  1721. var key = step.value;
  1722. var nextExisting = isNotSet ? NOT_SET : existing.get(key, NOT_SET);
  1723. var nextUpdated = updateInDeepMap(
  1724. nextExisting,
  1725. keyPathIter,
  1726. notSetValue,
  1727. updater
  1728. );
  1729. return nextUpdated === nextExisting ? existing :
  1730. nextUpdated === NOT_SET ? existing.remove(key) :
  1731. (isNotSet ? emptyMap() : existing).set(key, nextUpdated);
  1732. }
  1733. function popCount(x) {
  1734. x = x - ((x >> 1) & 0x55555555);
  1735. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  1736. x = (x + (x >> 4)) & 0x0f0f0f0f;
  1737. x = x + (x >> 8);
  1738. x = x + (x >> 16);
  1739. return x & 0x7f;
  1740. }
  1741. function setIn(array, idx, val, canEdit) {
  1742. var newArray = canEdit ? array : arrCopy(array);
  1743. newArray[idx] = val;
  1744. return newArray;
  1745. }
  1746. function spliceIn(array, idx, val, canEdit) {
  1747. var newLen = array.length + 1;
  1748. if (canEdit && idx + 1 === newLen) {
  1749. array[idx] = val;
  1750. return array;
  1751. }
  1752. var newArray = new Array(newLen);
  1753. var after = 0;
  1754. for (var ii = 0; ii < newLen; ii++) {
  1755. if (ii === idx) {
  1756. newArray[ii] = val;
  1757. after = -1;
  1758. } else {
  1759. newArray[ii] = array[ii + after];
  1760. }
  1761. }
  1762. return newArray;
  1763. }
  1764. function spliceOut(array, idx, canEdit) {
  1765. var newLen = array.length - 1;
  1766. if (canEdit && idx === newLen) {
  1767. array.pop();
  1768. return array;
  1769. }
  1770. var newArray = new Array(newLen);
  1771. var after = 0;
  1772. for (var ii = 0; ii < newLen; ii++) {
  1773. if (ii === idx) {
  1774. after = 1;
  1775. }
  1776. newArray[ii] = array[ii + after];
  1777. }
  1778. return newArray;
  1779. }
  1780. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  1781. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  1782. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  1783. createClass(List, IndexedCollection);
  1784. // @pragma Construction
  1785. function List(value) {
  1786. var empty = emptyList();
  1787. if (value === null || value === undefined) {
  1788. return empty;
  1789. }
  1790. if (isList(value)) {
  1791. return value;
  1792. }
  1793. var iter = IndexedIterable(value);
  1794. var size = iter.size;
  1795. if (size === 0) {
  1796. return empty;
  1797. }
  1798. assertNotInfinite(size);
  1799. if (size > 0 && size < SIZE) {
  1800. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  1801. }
  1802. return empty.withMutations(function(list ) {
  1803. list.setSize(size);
  1804. iter.forEach(function(v, i) {return list.set(i, v)});
  1805. });
  1806. }
  1807. List.of = function(/*...values*/) {
  1808. return this(arguments);
  1809. };
  1810. List.prototype.toString = function() {
  1811. return this.__toString('List [', ']');
  1812. };
  1813. // @pragma Access
  1814. List.prototype.get = function(index, notSetValue) {
  1815. index = wrapIndex(this, index);
  1816. if (index >= 0 && index < this.size) {
  1817. index += this._origin;
  1818. var node = listNodeFor(this, index);
  1819. return node && node.array[index & MASK];
  1820. }
  1821. return notSetValue;
  1822. };
  1823. // @pragma Modification
  1824. List.prototype.set = function(index, value) {
  1825. return updateList(this, index, value);
  1826. };
  1827. List.prototype.remove = function(index) {
  1828. return !this.has(index) ? this :
  1829. index === 0 ? this.shift() :
  1830. index === this.size - 1 ? this.pop() :
  1831. this.splice(index, 1);
  1832. };
  1833. List.prototype.insert = function(index, value) {
  1834. return this.splice(index, 0, value);
  1835. };
  1836. List.prototype.clear = function() {
  1837. if (this.size === 0) {
  1838. return this;
  1839. }
  1840. if (this.__ownerID) {
  1841. this.size = this._origin = this._capacity = 0;
  1842. this._level = SHIFT;
  1843. this._root = this._tail = null;
  1844. this.__hash = undefined;
  1845. this.__altered = true;
  1846. return this;
  1847. }
  1848. return emptyList();
  1849. };
  1850. List.prototype.push = function(/*...values*/) {
  1851. var values = arguments;
  1852. var oldSize = this.size;
  1853. return this.withMutations(function(list ) {
  1854. setListBounds(list, 0, oldSize + values.length);
  1855. for (var ii = 0; ii < values.length; ii++) {
  1856. list.set(oldSize + ii, values[ii]);
  1857. }
  1858. });
  1859. };
  1860. List.prototype.pop = function() {
  1861. return setListBounds(this, 0, -1);
  1862. };
  1863. List.prototype.unshift = function(/*...values*/) {
  1864. var values = arguments;
  1865. return this.withMutations(function(list ) {
  1866. setListBounds(list, -values.length);
  1867. for (var ii = 0; ii < values.length; ii++) {
  1868. list.set(ii, values[ii]);
  1869. }
  1870. });
  1871. };
  1872. List.prototype.shift = function() {
  1873. return setListBounds(this, 1);
  1874. };
  1875. // @pragma Composition
  1876. List.prototype.merge = function(/*...iters*/) {
  1877. return mergeIntoListWith(this, undefined, arguments);
  1878. };
  1879. List.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1880. return mergeIntoListWith(this, merger, iters);
  1881. };
  1882. List.prototype.mergeDeep = function(/*...iters*/) {
  1883. return mergeIntoListWith(this, deepMerger, arguments);
  1884. };
  1885. List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1886. return mergeIntoListWith(this, deepMergerWith(merger), iters);
  1887. };
  1888. List.prototype.setSize = function(size) {
  1889. return setListBounds(this, 0, size);
  1890. };
  1891. // @pragma Iteration
  1892. List.prototype.slice = function(begin, end) {
  1893. var size = this.size;
  1894. if (wholeSlice(begin, end, size)) {
  1895. return this;
  1896. }
  1897. return setListBounds(
  1898. this,
  1899. resolveBegin(begin, size),
  1900. resolveEnd(end, size)
  1901. );
  1902. };
  1903. List.prototype.__iterator = function(type, reverse) {
  1904. var index = 0;
  1905. var values = iterateList(this, reverse);
  1906. return new Iterator(function() {
  1907. var value = values();
  1908. return value === DONE ?
  1909. iteratorDone() :
  1910. iteratorValue(type, index++, value);
  1911. });
  1912. };
  1913. List.prototype.__iterate = function(fn, reverse) {
  1914. var index = 0;
  1915. var values = iterateList(this, reverse);
  1916. var value;
  1917. while ((value = values()) !== DONE) {
  1918. if (fn(value, index++, this) === false) {
  1919. break;
  1920. }
  1921. }
  1922. return index;
  1923. };
  1924. List.prototype.__ensureOwner = function(ownerID) {
  1925. if (ownerID === this.__ownerID) {
  1926. return this;
  1927. }
  1928. if (!ownerID) {
  1929. this.__ownerID = ownerID;
  1930. return this;
  1931. }
  1932. return makeList(this._origin, this._capacity, this._level, this._root, this._tail, ownerID, this.__hash);
  1933. };
  1934. function isList(maybeList) {
  1935. return !!(maybeList && maybeList[IS_LIST_SENTINEL]);
  1936. }
  1937. List.isList = isList;
  1938. var IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
  1939. var ListPrototype = List.prototype;
  1940. ListPrototype[IS_LIST_SENTINEL] = true;
  1941. ListPrototype[DELETE] = ListPrototype.remove;
  1942. ListPrototype.setIn = MapPrototype.setIn;
  1943. ListPrototype.deleteIn =
  1944. ListPrototype.removeIn = MapPrototype.removeIn;
  1945. ListPrototype.update = MapPrototype.update;
  1946. ListPrototype.updateIn = MapPrototype.updateIn;
  1947. ListPrototype.mergeIn = MapPrototype.mergeIn;
  1948. ListPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  1949. ListPrototype.withMutations = MapPrototype.withMutations;
  1950. ListPrototype.asMutable = MapPrototype.asMutable;
  1951. ListPrototype.asImmutable = MapPrototype.asImmutable;
  1952. ListPrototype.wasAltered = MapPrototype.wasAltered;
  1953. function VNode(array, ownerID) {
  1954. this.array = array;
  1955. this.ownerID = ownerID;
  1956. }
  1957. // TODO: seems like these methods are very similar
  1958. VNode.prototype.removeBefore = function(ownerID, level, index) {
  1959. if (index === level ? 1 << level : this.array.length === 0) {
  1960. return this;
  1961. }
  1962. var originIndex = (index >>> level) & MASK;
  1963. if (originIndex >= this.array.length) {
  1964. return new VNode([], ownerID);
  1965. }
  1966. var removingFirst = originIndex === 0;
  1967. var newChild;
  1968. if (level > 0) {
  1969. var oldChild = this.array[originIndex];
  1970. newChild = oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  1971. if (newChild === oldChild && removingFirst) {
  1972. return this;
  1973. }
  1974. }
  1975. if (removingFirst && !newChild) {
  1976. return this;
  1977. }
  1978. var editable = editableVNode(this, ownerID);
  1979. if (!removingFirst) {
  1980. for (var ii = 0; ii < originIndex; ii++) {
  1981. editable.array[ii] = undefined;
  1982. }
  1983. }
  1984. if (newChild) {
  1985. editable.array[originIndex] = newChild;
  1986. }
  1987. return editable;
  1988. };
  1989. VNode.prototype.removeAfter = function(ownerID, level, index) {
  1990. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  1991. return this;
  1992. }
  1993. var sizeIndex = ((index - 1) >>> level) & MASK;
  1994. if (sizeIndex >= this.array.length) {
  1995. return this;
  1996. }
  1997. var newChild;
  1998. if (level > 0) {
  1999. var oldChild = this.array[sizeIndex];
  2000. newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  2001. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  2002. return this;
  2003. }
  2004. }
  2005. var editable = editableVNode(this, ownerID);
  2006. editable.array.splice(sizeIndex + 1);
  2007. if (newChild) {
  2008. editable.array[sizeIndex] = newChild;
  2009. }
  2010. return editable;
  2011. };
  2012. var DONE = {};
  2013. function iterateList(list, reverse) {
  2014. var left = list._origin;
  2015. var right = list._capacity;
  2016. var tailPos = getTailOffset(right);
  2017. var tail = list._tail;
  2018. return iterateNodeOrLeaf(list._root, list._level, 0);
  2019. function iterateNodeOrLeaf(node, level, offset) {
  2020. return level === 0 ?
  2021. iterateLeaf(node, offset) :
  2022. iterateNode(node, level, offset);
  2023. }
  2024. function iterateLeaf(node, offset) {
  2025. var array = offset === tailPos ? tail && tail.array : node && node.array;
  2026. var from = offset > left ? 0 : left - offset;
  2027. var to = right - offset;
  2028. if (to > SIZE) {
  2029. to = SIZE;
  2030. }
  2031. return function() {
  2032. if (from === to) {
  2033. return DONE;
  2034. }
  2035. var idx = reverse ? --to : from++;
  2036. return array && array[idx];
  2037. };
  2038. }
  2039. function iterateNode(node, level, offset) {
  2040. var values;
  2041. var array = node && node.array;
  2042. var from = offset > left ? 0 : (left - offset) >> level;
  2043. var to = ((right - offset) >> level) + 1;
  2044. if (to > SIZE) {
  2045. to = SIZE;
  2046. }
  2047. return function() {
  2048. do {
  2049. if (values) {
  2050. var value = values();
  2051. if (value !== DONE) {
  2052. return value;
  2053. }
  2054. values = null;
  2055. }
  2056. if (from === to) {
  2057. return DONE;
  2058. }
  2059. var idx = reverse ? --to : from++;
  2060. values = iterateNodeOrLeaf(
  2061. array && array[idx], level - SHIFT, offset + (idx << level)
  2062. );
  2063. } while (true);
  2064. };
  2065. }
  2066. }
  2067. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  2068. var list = Object.create(ListPrototype);
  2069. list.size = capacity - origin;
  2070. list._origin = origin;
  2071. list._capacity = capacity;
  2072. list._level = level;
  2073. list._root = root;
  2074. list._tail = tail;
  2075. list.__ownerID = ownerID;
  2076. list.__hash = hash;
  2077. list.__altered = false;
  2078. return list;
  2079. }
  2080. var EMPTY_LIST;
  2081. function emptyList() {
  2082. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  2083. }
  2084. function updateList(list, index, value) {
  2085. index = wrapIndex(list, index);
  2086. if (index !== index) {
  2087. return list;
  2088. }
  2089. if (index >= list.size || index < 0) {
  2090. return list.withMutations(function(list ) {
  2091. index < 0 ?
  2092. setListBounds(list, index).set(0, value) :
  2093. setListBounds(list, 0, index + 1).set(index, value);
  2094. });
  2095. }
  2096. index += list._origin;
  2097. var newTail = list._tail;
  2098. var newRoot = list._root;
  2099. var didAlter = MakeRef(DID_ALTER);
  2100. if (index >= getTailOffset(list._capacity)) {
  2101. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  2102. } else {
  2103. newRoot = updateVNode(newRoot, list.__ownerID, list._level, index, value, didAlter);
  2104. }
  2105. if (!didAlter.value) {
  2106. return list;
  2107. }
  2108. if (list.__ownerID) {
  2109. list._root = newRoot;
  2110. list._tail = newTail;
  2111. list.__hash = undefined;
  2112. list.__altered = true;
  2113. return list;
  2114. }
  2115. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  2116. }
  2117. function updateVNode(node, ownerID, level, index, value, didAlter) {
  2118. var idx = (index >>> level) & MASK;
  2119. var nodeHas = node && idx < node.array.length;
  2120. if (!nodeHas && value === undefined) {
  2121. return node;
  2122. }
  2123. var newNode;
  2124. if (level > 0) {
  2125. var lowerNode = node && node.array[idx];
  2126. var newLowerNode = updateVNode(lowerNode, ownerID, level - SHIFT, index, value, didAlter);
  2127. if (newLowerNode === lowerNode) {
  2128. return node;
  2129. }
  2130. newNode = editableVNode(node, ownerID);
  2131. newNode.array[idx] = newLowerNode;
  2132. return newNode;
  2133. }
  2134. if (nodeHas && node.array[idx] === value) {
  2135. return node;
  2136. }
  2137. SetRef(didAlter);
  2138. newNode = editableVNode(node, ownerID);
  2139. if (value === undefined && idx === newNode.array.length - 1) {
  2140. newNode.array.pop();
  2141. } else {
  2142. newNode.array[idx] = value;
  2143. }
  2144. return newNode;
  2145. }
  2146. function editableVNode(node, ownerID) {
  2147. if (ownerID && node && ownerID === node.ownerID) {
  2148. return node;
  2149. }
  2150. return new VNode(node ? node.array.slice() : [], ownerID);
  2151. }
  2152. function listNodeFor(list, rawIndex) {
  2153. if (rawIndex >= getTailOffset(list._capacity)) {
  2154. return list._tail;
  2155. }
  2156. if (rawIndex < 1 << (list._level + SHIFT)) {
  2157. var node = list._root;
  2158. var level = list._level;
  2159. while (node && level > 0) {
  2160. node = node.array[(rawIndex >>> level) & MASK];
  2161. level -= SHIFT;
  2162. }
  2163. return node;
  2164. }
  2165. }
  2166. function setListBounds(list, begin, end) {
  2167. // Sanitize begin & end using this shorthand for ToInt32(argument)
  2168. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  2169. if (begin !== undefined) {
  2170. begin = begin | 0;
  2171. }
  2172. if (end !== undefined) {
  2173. end = end | 0;
  2174. }
  2175. var owner = list.__ownerID || new OwnerID();
  2176. var oldOrigin = list._origin;
  2177. var oldCapacity = list._capacity;
  2178. var newOrigin = oldOrigin + begin;
  2179. var newCapacity = end === undefined ? oldCapacity : end < 0 ? oldCapacity + end : oldOrigin + end;
  2180. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  2181. return list;
  2182. }
  2183. // If it's going to end after it starts, it's empty.
  2184. if (newOrigin >= newCapacity) {
  2185. return list.clear();
  2186. }
  2187. var newLevel = list._level;
  2188. var newRoot = list._root;
  2189. // New origin might need creating a higher root.
  2190. var offsetShift = 0;
  2191. while (newOrigin + offsetShift < 0) {
  2192. newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner);
  2193. newLevel += SHIFT;
  2194. offsetShift += 1 << newLevel;
  2195. }
  2196. if (offsetShift) {
  2197. newOrigin += offsetShift;
  2198. oldOrigin += offsetShift;
  2199. newCapacity += offsetShift;
  2200. oldCapacity += offsetShift;
  2201. }
  2202. var oldTailOffset = getTailOffset(oldCapacity);
  2203. var newTailOffset = getTailOffset(newCapacity);
  2204. // New size might need creating a higher root.
  2205. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  2206. newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner);
  2207. newLevel += SHIFT;
  2208. }
  2209. // Locate or create the new tail.
  2210. var oldTail = list._tail;
  2211. var newTail = newTailOffset < oldTailOffset ?
  2212. listNodeFor(list, newCapacity - 1) :
  2213. newTailOffset > oldTailOffset ? new VNode([], owner) : oldTail;
  2214. // Merge Tail into tree.
  2215. if (oldTail && newTailOffset > oldTailOffset && newOrigin < oldCapacity && oldTail.array.length) {
  2216. newRoot = editableVNode(newRoot, owner);
  2217. var node = newRoot;
  2218. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  2219. var idx = (oldTailOffset >>> level) & MASK;
  2220. node = node.array[idx] = editableVNode(node.array[idx], owner);
  2221. }
  2222. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  2223. }
  2224. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  2225. if (newCapacity < oldCapacity) {
  2226. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  2227. }
  2228. // If the new origin is within the tail, then we do not need a root.
  2229. if (newOrigin >= newTailOffset) {
  2230. newOrigin -= newTailOffset;
  2231. newCapacity -= newTailOffset;
  2232. newLevel = SHIFT;
  2233. newRoot = null;
  2234. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  2235. // Otherwise, if the root has been trimmed, garbage collect.
  2236. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  2237. offsetShift = 0;
  2238. // Identify the new top root node of the subtree of the old root.
  2239. while (newRoot) {
  2240. var beginIndex = (newOrigin >>> newLevel) & MASK;
  2241. if (beginIndex !== (newTailOffset >>> newLevel) & MASK) {
  2242. break;
  2243. }
  2244. if (beginIndex) {
  2245. offsetShift += (1 << newLevel) * beginIndex;
  2246. }
  2247. newLevel -= SHIFT;
  2248. newRoot = newRoot.array[beginIndex];
  2249. }
  2250. // Trim the new sides of the new root.
  2251. if (newRoot && newOrigin > oldOrigin) {
  2252. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  2253. }
  2254. if (newRoot && newTailOffset < oldTailOffset) {
  2255. newRoot = newRoot.removeAfter(owner, newLevel, newTailOffset - offsetShift);
  2256. }
  2257. if (offsetShift) {
  2258. newOrigin -= offsetShift;
  2259. newCapacity -= offsetShift;
  2260. }
  2261. }
  2262. if (list.__ownerID) {
  2263. list.size = newCapacity - newOrigin;
  2264. list._origin = newOrigin;
  2265. list._capacity = newCapacity;
  2266. list._level = newLevel;
  2267. list._root = newRoot;
  2268. list._tail = newTail;
  2269. list.__hash = undefined;
  2270. list.__altered = true;
  2271. return list;
  2272. }
  2273. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  2274. }
  2275. function mergeIntoListWith(list, merger, iterables) {
  2276. var iters = [];
  2277. var maxSize = 0;
  2278. for (var ii = 0; ii < iterables.length; ii++) {
  2279. var value = iterables[ii];
  2280. var iter = IndexedIterable(value);
  2281. if (iter.size > maxSize) {
  2282. maxSize = iter.size;
  2283. }
  2284. if (!isIterable(value)) {
  2285. iter = iter.map(function(v ) {return fromJS(v)});
  2286. }
  2287. iters.push(iter);
  2288. }
  2289. if (maxSize > list.size) {
  2290. list = list.setSize(maxSize);
  2291. }
  2292. return mergeIntoCollectionWith(list, merger, iters);
  2293. }
  2294. function getTailOffset(size) {
  2295. return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
  2296. }
  2297. createClass(OrderedMap, Map);
  2298. // @pragma Construction
  2299. function OrderedMap(value) {
  2300. return value === null || value === undefined ? emptyOrderedMap() :
  2301. isOrderedMap(value) ? value :
  2302. emptyOrderedMap().withMutations(function(map ) {
  2303. var iter = KeyedIterable(value);
  2304. assertNotInfinite(iter.size);
  2305. iter.forEach(function(v, k) {return map.set(k, v)});
  2306. });
  2307. }
  2308. OrderedMap.of = function(/*...values*/) {
  2309. return this(arguments);
  2310. };
  2311. OrderedMap.prototype.toString = function() {
  2312. return this.__toString('OrderedMap {', '}');
  2313. };
  2314. // @pragma Access
  2315. OrderedMap.prototype.get = function(k, notSetValue) {
  2316. var index = this._map.get(k);
  2317. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  2318. };
  2319. // @pragma Modification
  2320. OrderedMap.prototype.clear = function() {
  2321. if (this.size === 0) {
  2322. return this;
  2323. }
  2324. if (this.__ownerID) {
  2325. this.size = 0;
  2326. this._map.clear();
  2327. this._list.clear();
  2328. return this;
  2329. }
  2330. return emptyOrderedMap();
  2331. };
  2332. OrderedMap.prototype.set = function(k, v) {
  2333. return updateOrderedMap(this, k, v);
  2334. };
  2335. OrderedMap.prototype.remove = function(k) {
  2336. return updateOrderedMap(this, k, NOT_SET);
  2337. };
  2338. OrderedMap.prototype.wasAltered = function() {
  2339. return this._map.wasAltered() || this._list.wasAltered();
  2340. };
  2341. OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2342. return this._list.__iterate(
  2343. function(entry ) {return entry && fn(entry[1], entry[0], this$0)},
  2344. reverse
  2345. );
  2346. };
  2347. OrderedMap.prototype.__iterator = function(type, reverse) {
  2348. return this._list.fromEntrySeq().__iterator(type, reverse);
  2349. };
  2350. OrderedMap.prototype.__ensureOwner = function(ownerID) {
  2351. if (ownerID === this.__ownerID) {
  2352. return this;
  2353. }
  2354. var newMap = this._map.__ensureOwner(ownerID);
  2355. var newList = this._list.__ensureOwner(ownerID);
  2356. if (!ownerID) {
  2357. this.__ownerID = ownerID;
  2358. this._map = newMap;
  2359. this._list = newList;
  2360. return this;
  2361. }
  2362. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  2363. };
  2364. function isOrderedMap(maybeOrderedMap) {
  2365. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  2366. }
  2367. OrderedMap.isOrderedMap = isOrderedMap;
  2368. OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
  2369. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  2370. function makeOrderedMap(map, list, ownerID, hash) {
  2371. var omap = Object.create(OrderedMap.prototype);
  2372. omap.size = map ? map.size : 0;
  2373. omap._map = map;
  2374. omap._list = list;
  2375. omap.__ownerID = ownerID;
  2376. omap.__hash = hash;
  2377. return omap;
  2378. }
  2379. var EMPTY_ORDERED_MAP;
  2380. function emptyOrderedMap() {
  2381. return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()));
  2382. }
  2383. function updateOrderedMap(omap, k, v) {
  2384. var map = omap._map;
  2385. var list = omap._list;
  2386. var i = map.get(k);
  2387. var has = i !== undefined;
  2388. var newMap;
  2389. var newList;
  2390. if (v === NOT_SET) { // removed
  2391. if (!has) {
  2392. return omap;
  2393. }
  2394. if (list.size >= SIZE && list.size >= map.size * 2) {
  2395. newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx});
  2396. newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap();
  2397. if (omap.__ownerID) {
  2398. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  2399. }
  2400. } else {
  2401. newMap = map.remove(k);
  2402. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  2403. }
  2404. } else {
  2405. if (has) {
  2406. if (v === list.get(i)[1]) {
  2407. return omap;
  2408. }
  2409. newMap = map;
  2410. newList = list.set(i, [k, v]);
  2411. } else {
  2412. newMap = map.set(k, list.size);
  2413. newList = list.set(list.size, [k, v]);
  2414. }
  2415. }
  2416. if (omap.__ownerID) {
  2417. omap.size = newMap.size;
  2418. omap._map = newMap;
  2419. omap._list = newList;
  2420. omap.__hash = undefined;
  2421. return omap;
  2422. }
  2423. return makeOrderedMap(newMap, newList);
  2424. }
  2425. createClass(ToKeyedSequence, KeyedSeq);
  2426. function ToKeyedSequence(indexed, useKeys) {
  2427. this._iter = indexed;
  2428. this._useKeys = useKeys;
  2429. this.size = indexed.size;
  2430. }
  2431. ToKeyedSequence.prototype.get = function(key, notSetValue) {
  2432. return this._iter.get(key, notSetValue);
  2433. };
  2434. ToKeyedSequence.prototype.has = function(key) {
  2435. return this._iter.has(key);
  2436. };
  2437. ToKeyedSequence.prototype.valueSeq = function() {
  2438. return this._iter.valueSeq();
  2439. };
  2440. ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
  2441. var reversedSequence = reverseFactory(this, true);
  2442. if (!this._useKeys) {
  2443. reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
  2444. }
  2445. return reversedSequence;
  2446. };
  2447. ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
  2448. var mappedSequence = mapFactory(this, mapper, context);
  2449. if (!this._useKeys) {
  2450. mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
  2451. }
  2452. return mappedSequence;
  2453. };
  2454. ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2455. var ii;
  2456. return this._iter.__iterate(
  2457. this._useKeys ?
  2458. function(v, k) {return fn(v, k, this$0)} :
  2459. ((ii = reverse ? resolveSize(this) : 0),
  2460. function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
  2461. reverse
  2462. );
  2463. };
  2464. ToKeyedSequence.prototype.__iterator = function(type, reverse) {
  2465. if (this._useKeys) {
  2466. return this._iter.__iterator(type, reverse);
  2467. }
  2468. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2469. var ii = reverse ? resolveSize(this) : 0;
  2470. return new Iterator(function() {
  2471. var step = iterator.next();
  2472. return step.done ? step :
  2473. iteratorValue(type, reverse ? --ii : ii++, step.value, step);
  2474. });
  2475. };
  2476. ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
  2477. createClass(ToIndexedSequence, IndexedSeq);
  2478. function ToIndexedSequence(iter) {
  2479. this._iter = iter;
  2480. this.size = iter.size;
  2481. }
  2482. ToIndexedSequence.prototype.includes = function(value) {
  2483. return this._iter.includes(value);
  2484. };
  2485. ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2486. var iterations = 0;
  2487. return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
  2488. };
  2489. ToIndexedSequence.prototype.__iterator = function(type, reverse) {
  2490. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2491. var iterations = 0;
  2492. return new Iterator(function() {
  2493. var step = iterator.next();
  2494. return step.done ? step :
  2495. iteratorValue(type, iterations++, step.value, step)
  2496. });
  2497. };
  2498. createClass(ToSetSequence, SetSeq);
  2499. function ToSetSequence(iter) {
  2500. this._iter = iter;
  2501. this.size = iter.size;
  2502. }
  2503. ToSetSequence.prototype.has = function(key) {
  2504. return this._iter.includes(key);
  2505. };
  2506. ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2507. return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
  2508. };
  2509. ToSetSequence.prototype.__iterator = function(type, reverse) {
  2510. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2511. return new Iterator(function() {
  2512. var step = iterator.next();
  2513. return step.done ? step :
  2514. iteratorValue(type, step.value, step.value, step);
  2515. });
  2516. };
  2517. createClass(FromEntriesSequence, KeyedSeq);
  2518. function FromEntriesSequence(entries) {
  2519. this._iter = entries;
  2520. this.size = entries.size;
  2521. }
  2522. FromEntriesSequence.prototype.entrySeq = function() {
  2523. return this._iter.toSeq();
  2524. };
  2525. FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2526. return this._iter.__iterate(function(entry ) {
  2527. // Check if entry exists first so array access doesn't throw for holes
  2528. // in the parent iteration.
  2529. if (entry) {
  2530. validateEntry(entry);
  2531. var indexedIterable = isIterable(entry);
  2532. return fn(
  2533. indexedIterable ? entry.get(1) : entry[1],
  2534. indexedIterable ? entry.get(0) : entry[0],
  2535. this$0
  2536. );
  2537. }
  2538. }, reverse);
  2539. };
  2540. FromEntriesSequence.prototype.__iterator = function(type, reverse) {
  2541. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2542. return new Iterator(function() {
  2543. while (true) {
  2544. var step = iterator.next();
  2545. if (step.done) {
  2546. return step;
  2547. }
  2548. var entry = step.value;
  2549. // Check if entry exists first so array access doesn't throw for holes
  2550. // in the parent iteration.
  2551. if (entry) {
  2552. validateEntry(entry);
  2553. var indexedIterable = isIterable(entry);
  2554. return iteratorValue(
  2555. type,
  2556. indexedIterable ? entry.get(0) : entry[0],
  2557. indexedIterable ? entry.get(1) : entry[1],
  2558. step
  2559. );
  2560. }
  2561. }
  2562. });
  2563. };
  2564. ToIndexedSequence.prototype.cacheResult =
  2565. ToKeyedSequence.prototype.cacheResult =
  2566. ToSetSequence.prototype.cacheResult =
  2567. FromEntriesSequence.prototype.cacheResult =
  2568. cacheResultThrough;
  2569. function flipFactory(iterable) {
  2570. var flipSequence = makeSequence(iterable);
  2571. flipSequence._iter = iterable;
  2572. flipSequence.size = iterable.size;
  2573. flipSequence.flip = function() {return iterable};
  2574. flipSequence.reverse = function () {
  2575. var reversedSequence = iterable.reverse.apply(this); // super.reverse()
  2576. reversedSequence.flip = function() {return iterable.reverse()};
  2577. return reversedSequence;
  2578. };
  2579. flipSequence.has = function(key ) {return iterable.includes(key)};
  2580. flipSequence.includes = function(key ) {return iterable.has(key)};
  2581. flipSequence.cacheResult = cacheResultThrough;
  2582. flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2583. return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
  2584. };
  2585. flipSequence.__iteratorUncached = function(type, reverse) {
  2586. if (type === ITERATE_ENTRIES) {
  2587. var iterator = iterable.__iterator(type, reverse);
  2588. return new Iterator(function() {
  2589. var step = iterator.next();
  2590. if (!step.done) {
  2591. var k = step.value[0];
  2592. step.value[0] = step.value[1];
  2593. step.value[1] = k;
  2594. }
  2595. return step;
  2596. });
  2597. }
  2598. return iterable.__iterator(
  2599. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  2600. reverse
  2601. );
  2602. };
  2603. return flipSequence;
  2604. }
  2605. function mapFactory(iterable, mapper, context) {
  2606. var mappedSequence = makeSequence(iterable);
  2607. mappedSequence.size = iterable.size;
  2608. mappedSequence.has = function(key ) {return iterable.has(key)};
  2609. mappedSequence.get = function(key, notSetValue) {
  2610. var v = iterable.get(key, NOT_SET);
  2611. return v === NOT_SET ?
  2612. notSetValue :
  2613. mapper.call(context, v, key, iterable);
  2614. };
  2615. mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2616. return iterable.__iterate(
  2617. function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
  2618. reverse
  2619. );
  2620. };
  2621. mappedSequence.__iteratorUncached = function (type, reverse) {
  2622. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2623. return new Iterator(function() {
  2624. var step = iterator.next();
  2625. if (step.done) {
  2626. return step;
  2627. }
  2628. var entry = step.value;
  2629. var key = entry[0];
  2630. return iteratorValue(
  2631. type,
  2632. key,
  2633. mapper.call(context, entry[1], key, iterable),
  2634. step
  2635. );
  2636. });
  2637. };
  2638. return mappedSequence;
  2639. }
  2640. function reverseFactory(iterable, useKeys) {
  2641. var reversedSequence = makeSequence(iterable);
  2642. reversedSequence._iter = iterable;
  2643. reversedSequence.size = iterable.size;
  2644. reversedSequence.reverse = function() {return iterable};
  2645. if (iterable.flip) {
  2646. reversedSequence.flip = function () {
  2647. var flipSequence = flipFactory(iterable);
  2648. flipSequence.reverse = function() {return iterable.flip()};
  2649. return flipSequence;
  2650. };
  2651. }
  2652. reversedSequence.get = function(key, notSetValue)
  2653. {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
  2654. reversedSequence.has = function(key )
  2655. {return iterable.has(useKeys ? key : -1 - key)};
  2656. reversedSequence.includes = function(value ) {return iterable.includes(value)};
  2657. reversedSequence.cacheResult = cacheResultThrough;
  2658. reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
  2659. return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
  2660. };
  2661. reversedSequence.__iterator =
  2662. function(type, reverse) {return iterable.__iterator(type, !reverse)};
  2663. return reversedSequence;
  2664. }
  2665. function filterFactory(iterable, predicate, context, useKeys) {
  2666. var filterSequence = makeSequence(iterable);
  2667. if (useKeys) {
  2668. filterSequence.has = function(key ) {
  2669. var v = iterable.get(key, NOT_SET);
  2670. return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
  2671. };
  2672. filterSequence.get = function(key, notSetValue) {
  2673. var v = iterable.get(key, NOT_SET);
  2674. return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
  2675. v : notSetValue;
  2676. };
  2677. }
  2678. filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2679. var iterations = 0;
  2680. iterable.__iterate(function(v, k, c) {
  2681. if (predicate.call(context, v, k, c)) {
  2682. iterations++;
  2683. return fn(v, useKeys ? k : iterations - 1, this$0);
  2684. }
  2685. }, reverse);
  2686. return iterations;
  2687. };
  2688. filterSequence.__iteratorUncached = function (type, reverse) {
  2689. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2690. var iterations = 0;
  2691. return new Iterator(function() {
  2692. while (true) {
  2693. var step = iterator.next();
  2694. if (step.done) {
  2695. return step;
  2696. }
  2697. var entry = step.value;
  2698. var key = entry[0];
  2699. var value = entry[1];
  2700. if (predicate.call(context, value, key, iterable)) {
  2701. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  2702. }
  2703. }
  2704. });
  2705. };
  2706. return filterSequence;
  2707. }
  2708. function countByFactory(iterable, grouper, context) {
  2709. var groups = Map().asMutable();
  2710. iterable.__iterate(function(v, k) {
  2711. groups.update(
  2712. grouper.call(context, v, k, iterable),
  2713. 0,
  2714. function(a ) {return a + 1}
  2715. );
  2716. });
  2717. return groups.asImmutable();
  2718. }
  2719. function groupByFactory(iterable, grouper, context) {
  2720. var isKeyedIter = isKeyed(iterable);
  2721. var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable();
  2722. iterable.__iterate(function(v, k) {
  2723. groups.update(
  2724. grouper.call(context, v, k, iterable),
  2725. function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
  2726. );
  2727. });
  2728. var coerce = iterableClass(iterable);
  2729. return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
  2730. }
  2731. function sliceFactory(iterable, begin, end, useKeys) {
  2732. var originalSize = iterable.size;
  2733. // Sanitize begin & end using this shorthand for ToInt32(argument)
  2734. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  2735. if (begin !== undefined) {
  2736. begin = begin | 0;
  2737. }
  2738. if (end !== undefined) {
  2739. end = end | 0;
  2740. }
  2741. if (wholeSlice(begin, end, originalSize)) {
  2742. return iterable;
  2743. }
  2744. var resolvedBegin = resolveBegin(begin, originalSize);
  2745. var resolvedEnd = resolveEnd(end, originalSize);
  2746. // begin or end will be NaN if they were provided as negative numbers and
  2747. // this iterable's size is unknown. In that case, cache first so there is
  2748. // a known size and these do not resolve to NaN.
  2749. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  2750. return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
  2751. }
  2752. // Note: resolvedEnd is undefined when the original sequence's length is
  2753. // unknown and this slice did not supply an end and should contain all
  2754. // elements after resolvedBegin.
  2755. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  2756. var resolvedSize = resolvedEnd - resolvedBegin;
  2757. var sliceSize;
  2758. if (resolvedSize === resolvedSize) {
  2759. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  2760. }
  2761. var sliceSeq = makeSequence(iterable);
  2762. // If iterable.size is undefined, the size of the realized sliceSeq is
  2763. // unknown at this point unless the number of items to slice is 0
  2764. sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
  2765. if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
  2766. sliceSeq.get = function (index, notSetValue) {
  2767. index = wrapIndex(this, index);
  2768. return index >= 0 && index < sliceSize ?
  2769. iterable.get(index + resolvedBegin, notSetValue) :
  2770. notSetValue;
  2771. };
  2772. }
  2773. sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
  2774. if (sliceSize === 0) {
  2775. return 0;
  2776. }
  2777. if (reverse) {
  2778. return this.cacheResult().__iterate(fn, reverse);
  2779. }
  2780. var skipped = 0;
  2781. var isSkipping = true;
  2782. var iterations = 0;
  2783. iterable.__iterate(function(v, k) {
  2784. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  2785. iterations++;
  2786. return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
  2787. iterations !== sliceSize;
  2788. }
  2789. });
  2790. return iterations;
  2791. };
  2792. sliceSeq.__iteratorUncached = function(type, reverse) {
  2793. if (sliceSize !== 0 && reverse) {
  2794. return this.cacheResult().__iterator(type, reverse);
  2795. }
  2796. // Don't bother instantiating parent iterator if taking 0.
  2797. var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
  2798. var skipped = 0;
  2799. var iterations = 0;
  2800. return new Iterator(function() {
  2801. while (skipped++ < resolvedBegin) {
  2802. iterator.next();
  2803. }
  2804. if (++iterations > sliceSize) {
  2805. return iteratorDone();
  2806. }
  2807. var step = iterator.next();
  2808. if (useKeys || type === ITERATE_VALUES) {
  2809. return step;
  2810. } else if (type === ITERATE_KEYS) {
  2811. return iteratorValue(type, iterations - 1, undefined, step);
  2812. } else {
  2813. return iteratorValue(type, iterations - 1, step.value[1], step);
  2814. }
  2815. });
  2816. };
  2817. return sliceSeq;
  2818. }
  2819. function takeWhileFactory(iterable, predicate, context) {
  2820. var takeSequence = makeSequence(iterable);
  2821. takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  2822. if (reverse) {
  2823. return this.cacheResult().__iterate(fn, reverse);
  2824. }
  2825. var iterations = 0;
  2826. iterable.__iterate(function(v, k, c)
  2827. {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
  2828. );
  2829. return iterations;
  2830. };
  2831. takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  2832. if (reverse) {
  2833. return this.cacheResult().__iterator(type, reverse);
  2834. }
  2835. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2836. var iterating = true;
  2837. return new Iterator(function() {
  2838. if (!iterating) {
  2839. return iteratorDone();
  2840. }
  2841. var step = iterator.next();
  2842. if (step.done) {
  2843. return step;
  2844. }
  2845. var entry = step.value;
  2846. var k = entry[0];
  2847. var v = entry[1];
  2848. if (!predicate.call(context, v, k, this$0)) {
  2849. iterating = false;
  2850. return iteratorDone();
  2851. }
  2852. return type === ITERATE_ENTRIES ? step :
  2853. iteratorValue(type, k, v, step);
  2854. });
  2855. };
  2856. return takeSequence;
  2857. }
  2858. function skipWhileFactory(iterable, predicate, context, useKeys) {
  2859. var skipSequence = makeSequence(iterable);
  2860. skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2861. if (reverse) {
  2862. return this.cacheResult().__iterate(fn, reverse);
  2863. }
  2864. var isSkipping = true;
  2865. var iterations = 0;
  2866. iterable.__iterate(function(v, k, c) {
  2867. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  2868. iterations++;
  2869. return fn(v, useKeys ? k : iterations - 1, this$0);
  2870. }
  2871. });
  2872. return iterations;
  2873. };
  2874. skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  2875. if (reverse) {
  2876. return this.cacheResult().__iterator(type, reverse);
  2877. }
  2878. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2879. var skipping = true;
  2880. var iterations = 0;
  2881. return new Iterator(function() {
  2882. var step, k, v;
  2883. do {
  2884. step = iterator.next();
  2885. if (step.done) {
  2886. if (useKeys || type === ITERATE_VALUES) {
  2887. return step;
  2888. } else if (type === ITERATE_KEYS) {
  2889. return iteratorValue(type, iterations++, undefined, step);
  2890. } else {
  2891. return iteratorValue(type, iterations++, step.value[1], step);
  2892. }
  2893. }
  2894. var entry = step.value;
  2895. k = entry[0];
  2896. v = entry[1];
  2897. skipping && (skipping = predicate.call(context, v, k, this$0));
  2898. } while (skipping);
  2899. return type === ITERATE_ENTRIES ? step :
  2900. iteratorValue(type, k, v, step);
  2901. });
  2902. };
  2903. return skipSequence;
  2904. }
  2905. function concatFactory(iterable, values) {
  2906. var isKeyedIterable = isKeyed(iterable);
  2907. var iters = [iterable].concat(values).map(function(v ) {
  2908. if (!isIterable(v)) {
  2909. v = isKeyedIterable ?
  2910. keyedSeqFromValue(v) :
  2911. indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  2912. } else if (isKeyedIterable) {
  2913. v = KeyedIterable(v);
  2914. }
  2915. return v;
  2916. }).filter(function(v ) {return v.size !== 0});
  2917. if (iters.length === 0) {
  2918. return iterable;
  2919. }
  2920. if (iters.length === 1) {
  2921. var singleton = iters[0];
  2922. if (singleton === iterable ||
  2923. isKeyedIterable && isKeyed(singleton) ||
  2924. isIndexed(iterable) && isIndexed(singleton)) {
  2925. return singleton;
  2926. }
  2927. }
  2928. var concatSeq = new ArraySeq(iters);
  2929. if (isKeyedIterable) {
  2930. concatSeq = concatSeq.toKeyedSeq();
  2931. } else if (!isIndexed(iterable)) {
  2932. concatSeq = concatSeq.toSetSeq();
  2933. }
  2934. concatSeq = concatSeq.flatten(true);
  2935. concatSeq.size = iters.reduce(
  2936. function(sum, seq) {
  2937. if (sum !== undefined) {
  2938. var size = seq.size;
  2939. if (size !== undefined) {
  2940. return sum + size;
  2941. }
  2942. }
  2943. },
  2944. 0
  2945. );
  2946. return concatSeq;
  2947. }
  2948. function flattenFactory(iterable, depth, useKeys) {
  2949. var flatSequence = makeSequence(iterable);
  2950. flatSequence.__iterateUncached = function(fn, reverse) {
  2951. var iterations = 0;
  2952. var stopped = false;
  2953. function flatDeep(iter, currentDepth) {var this$0 = this;
  2954. iter.__iterate(function(v, k) {
  2955. if ((!depth || currentDepth < depth) && isIterable(v)) {
  2956. flatDeep(v, currentDepth + 1);
  2957. } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
  2958. stopped = true;
  2959. }
  2960. return !stopped;
  2961. }, reverse);
  2962. }
  2963. flatDeep(iterable, 0);
  2964. return iterations;
  2965. };
  2966. flatSequence.__iteratorUncached = function(type, reverse) {
  2967. var iterator = iterable.__iterator(type, reverse);
  2968. var stack = [];
  2969. var iterations = 0;
  2970. return new Iterator(function() {
  2971. while (iterator) {
  2972. var step = iterator.next();
  2973. if (step.done !== false) {
  2974. iterator = stack.pop();
  2975. continue;
  2976. }
  2977. var v = step.value;
  2978. if (type === ITERATE_ENTRIES) {
  2979. v = v[1];
  2980. }
  2981. if ((!depth || stack.length < depth) && isIterable(v)) {
  2982. stack.push(iterator);
  2983. iterator = v.__iterator(type, reverse);
  2984. } else {
  2985. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  2986. }
  2987. }
  2988. return iteratorDone();
  2989. });
  2990. };
  2991. return flatSequence;
  2992. }
  2993. function flatMapFactory(iterable, mapper, context) {
  2994. var coerce = iterableClass(iterable);
  2995. return iterable.toSeq().map(
  2996. function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
  2997. ).flatten(true);
  2998. }
  2999. function interposeFactory(iterable, separator) {
  3000. var interposedSequence = makeSequence(iterable);
  3001. interposedSequence.size = iterable.size && iterable.size * 2 -1;
  3002. interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  3003. var iterations = 0;
  3004. iterable.__iterate(function(v, k)
  3005. {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
  3006. fn(v, iterations++, this$0) !== false},
  3007. reverse
  3008. );
  3009. return iterations;
  3010. };
  3011. interposedSequence.__iteratorUncached = function(type, reverse) {
  3012. var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
  3013. var iterations = 0;
  3014. var step;
  3015. return new Iterator(function() {
  3016. if (!step || iterations % 2) {
  3017. step = iterator.next();
  3018. if (step.done) {
  3019. return step;
  3020. }
  3021. }
  3022. return iterations % 2 ?
  3023. iteratorValue(type, iterations++, separator) :
  3024. iteratorValue(type, iterations++, step.value, step);
  3025. });
  3026. };
  3027. return interposedSequence;
  3028. }
  3029. function sortFactory(iterable, comparator, mapper) {
  3030. if (!comparator) {
  3031. comparator = defaultComparator;
  3032. }
  3033. var isKeyedIterable = isKeyed(iterable);
  3034. var index = 0;
  3035. var entries = iterable.toSeq().map(
  3036. function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
  3037. ).toArray();
  3038. entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
  3039. isKeyedIterable ?
  3040. function(v, i) { entries[i].length = 2; } :
  3041. function(v, i) { entries[i] = v[1]; }
  3042. );
  3043. return isKeyedIterable ? KeyedSeq(entries) :
  3044. isIndexed(iterable) ? IndexedSeq(entries) :
  3045. SetSeq(entries);
  3046. }
  3047. function maxFactory(iterable, comparator, mapper) {
  3048. if (!comparator) {
  3049. comparator = defaultComparator;
  3050. }
  3051. if (mapper) {
  3052. var entry = iterable.toSeq()
  3053. .map(function(v, k) {return [v, mapper(v, k, iterable)]})
  3054. .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
  3055. return entry && entry[0];
  3056. } else {
  3057. return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
  3058. }
  3059. }
  3060. function maxCompare(comparator, a, b) {
  3061. var comp = comparator(b, a);
  3062. // b is considered the new max if the comparator declares them equal, but
  3063. // they are not equal and b is in fact a nullish value.
  3064. return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
  3065. }
  3066. function zipWithFactory(keyIter, zipper, iters) {
  3067. var zipSequence = makeSequence(keyIter);
  3068. zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
  3069. // Note: this a generic base implementation of __iterate in terms of
  3070. // __iterator which may be more generically useful in the future.
  3071. zipSequence.__iterate = function(fn, reverse) {
  3072. /* generic:
  3073. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  3074. var step;
  3075. var iterations = 0;
  3076. while (!(step = iterator.next()).done) {
  3077. iterations++;
  3078. if (fn(step.value[1], step.value[0], this) === false) {
  3079. break;
  3080. }
  3081. }
  3082. return iterations;
  3083. */
  3084. // indexed:
  3085. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  3086. var step;
  3087. var iterations = 0;
  3088. while (!(step = iterator.next()).done) {
  3089. if (fn(step.value, iterations++, this) === false) {
  3090. break;
  3091. }
  3092. }
  3093. return iterations;
  3094. };
  3095. zipSequence.__iteratorUncached = function(type, reverse) {
  3096. var iterators = iters.map(function(i )
  3097. {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
  3098. );
  3099. var iterations = 0;
  3100. var isDone = false;
  3101. return new Iterator(function() {
  3102. var steps;
  3103. if (!isDone) {
  3104. steps = iterators.map(function(i ) {return i.next()});
  3105. isDone = steps.some(function(s ) {return s.done});
  3106. }
  3107. if (isDone) {
  3108. return iteratorDone();
  3109. }
  3110. return iteratorValue(
  3111. type,
  3112. iterations++,
  3113. zipper.apply(null, steps.map(function(s ) {return s.value}))
  3114. );
  3115. });
  3116. };
  3117. return zipSequence
  3118. }
  3119. // #pragma Helper Functions
  3120. function reify(iter, seq) {
  3121. return isSeq(iter) ? seq : iter.constructor(seq);
  3122. }
  3123. function validateEntry(entry) {
  3124. if (entry !== Object(entry)) {
  3125. throw new TypeError('Expected [K, V] tuple: ' + entry);
  3126. }
  3127. }
  3128. function resolveSize(iter) {
  3129. assertNotInfinite(iter.size);
  3130. return ensureSize(iter);
  3131. }
  3132. function iterableClass(iterable) {
  3133. return isKeyed(iterable) ? KeyedIterable :
  3134. isIndexed(iterable) ? IndexedIterable :
  3135. SetIterable;
  3136. }
  3137. function makeSequence(iterable) {
  3138. return Object.create(
  3139. (
  3140. isKeyed(iterable) ? KeyedSeq :
  3141. isIndexed(iterable) ? IndexedSeq :
  3142. SetSeq
  3143. ).prototype
  3144. );
  3145. }
  3146. function cacheResultThrough() {
  3147. if (this._iter.cacheResult) {
  3148. this._iter.cacheResult();
  3149. this.size = this._iter.size;
  3150. return this;
  3151. } else {
  3152. return Seq.prototype.cacheResult.call(this);
  3153. }
  3154. }
  3155. function defaultComparator(a, b) {
  3156. return a > b ? 1 : a < b ? -1 : 0;
  3157. }
  3158. function forceIterator(keyPath) {
  3159. var iter = getIterator(keyPath);
  3160. if (!iter) {
  3161. // Array might not be iterable in this environment, so we need a fallback
  3162. // to our wrapped type.
  3163. if (!isArrayLike(keyPath)) {
  3164. throw new TypeError('Expected iterable or array-like: ' + keyPath);
  3165. }
  3166. iter = getIterator(Iterable(keyPath));
  3167. }
  3168. return iter;
  3169. }
  3170. createClass(Record, KeyedCollection);
  3171. function Record(defaultValues, name) {
  3172. var hasInitialized;
  3173. var RecordType = function Record(values) {
  3174. if (values instanceof RecordType) {
  3175. return values;
  3176. }
  3177. if (!(this instanceof RecordType)) {
  3178. return new RecordType(values);
  3179. }
  3180. if (!hasInitialized) {
  3181. hasInitialized = true;
  3182. var keys = Object.keys(defaultValues);
  3183. setProps(RecordTypePrototype, keys);
  3184. RecordTypePrototype.size = keys.length;
  3185. RecordTypePrototype._name = name;
  3186. RecordTypePrototype._keys = keys;
  3187. RecordTypePrototype._defaultValues = defaultValues;
  3188. }
  3189. this._map = Map(values);
  3190. };
  3191. var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
  3192. RecordTypePrototype.constructor = RecordType;
  3193. return RecordType;
  3194. }
  3195. Record.prototype.toString = function() {
  3196. return this.__toString(recordName(this) + ' {', '}');
  3197. };
  3198. // @pragma Access
  3199. Record.prototype.has = function(k) {
  3200. return this._defaultValues.hasOwnProperty(k);
  3201. };
  3202. Record.prototype.get = function(k, notSetValue) {
  3203. if (!this.has(k)) {
  3204. return notSetValue;
  3205. }
  3206. var defaultVal = this._defaultValues[k];
  3207. return this._map ? this._map.get(k, defaultVal) : defaultVal;
  3208. };
  3209. // @pragma Modification
  3210. Record.prototype.clear = function() {
  3211. if (this.__ownerID) {
  3212. this._map && this._map.clear();
  3213. return this;
  3214. }
  3215. var RecordType = this.constructor;
  3216. return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap()));
  3217. };
  3218. Record.prototype.set = function(k, v) {
  3219. if (!this.has(k)) {
  3220. throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
  3221. }
  3222. var newMap = this._map && this._map.set(k, v);
  3223. if (this.__ownerID || newMap === this._map) {
  3224. return this;
  3225. }
  3226. return makeRecord(this, newMap);
  3227. };
  3228. Record.prototype.remove = function(k) {
  3229. if (!this.has(k)) {
  3230. return this;
  3231. }
  3232. var newMap = this._map && this._map.remove(k);
  3233. if (this.__ownerID || newMap === this._map) {
  3234. return this;
  3235. }
  3236. return makeRecord(this, newMap);
  3237. };
  3238. Record.prototype.wasAltered = function() {
  3239. return this._map.wasAltered();
  3240. };
  3241. Record.prototype.__iterator = function(type, reverse) {var this$0 = this;
  3242. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse);
  3243. };
  3244. Record.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  3245. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse);
  3246. };
  3247. Record.prototype.__ensureOwner = function(ownerID) {
  3248. if (ownerID === this.__ownerID) {
  3249. return this;
  3250. }
  3251. var newMap = this._map && this._map.__ensureOwner(ownerID);
  3252. if (!ownerID) {
  3253. this.__ownerID = ownerID;
  3254. this._map = newMap;
  3255. return this;
  3256. }
  3257. return makeRecord(this, newMap, ownerID);
  3258. };
  3259. var RecordPrototype = Record.prototype;
  3260. RecordPrototype[DELETE] = RecordPrototype.remove;
  3261. RecordPrototype.deleteIn =
  3262. RecordPrototype.removeIn = MapPrototype.removeIn;
  3263. RecordPrototype.merge = MapPrototype.merge;
  3264. RecordPrototype.mergeWith = MapPrototype.mergeWith;
  3265. RecordPrototype.mergeIn = MapPrototype.mergeIn;
  3266. RecordPrototype.mergeDeep = MapPrototype.mergeDeep;
  3267. RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith;
  3268. RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  3269. RecordPrototype.setIn = MapPrototype.setIn;
  3270. RecordPrototype.update = MapPrototype.update;
  3271. RecordPrototype.updateIn = MapPrototype.updateIn;
  3272. RecordPrototype.withMutations = MapPrototype.withMutations;
  3273. RecordPrototype.asMutable = MapPrototype.asMutable;
  3274. RecordPrototype.asImmutable = MapPrototype.asImmutable;
  3275. function makeRecord(likeRecord, map, ownerID) {
  3276. var record = Object.create(Object.getPrototypeOf(likeRecord));
  3277. record._map = map;
  3278. record.__ownerID = ownerID;
  3279. return record;
  3280. }
  3281. function recordName(record) {
  3282. return record._name || record.constructor.name || 'Record';
  3283. }
  3284. function setProps(prototype, names) {
  3285. try {
  3286. names.forEach(setProp.bind(undefined, prototype));
  3287. } catch (error) {
  3288. // Object.defineProperty failed. Probably IE8.
  3289. }
  3290. }
  3291. function setProp(prototype, name) {
  3292. Object.defineProperty(prototype, name, {
  3293. get: function() {
  3294. return this.get(name);
  3295. },
  3296. set: function(value) {
  3297. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  3298. this.set(name, value);
  3299. }
  3300. });
  3301. }
  3302. createClass(Set, SetCollection);
  3303. // @pragma Construction
  3304. function Set(value) {
  3305. return value === null || value === undefined ? emptySet() :
  3306. isSet(value) && !isOrdered(value) ? value :
  3307. emptySet().withMutations(function(set ) {
  3308. var iter = SetIterable(value);
  3309. assertNotInfinite(iter.size);
  3310. iter.forEach(function(v ) {return set.add(v)});
  3311. });
  3312. }
  3313. Set.of = function(/*...values*/) {
  3314. return this(arguments);
  3315. };
  3316. Set.fromKeys = function(value) {
  3317. return this(KeyedIterable(value).keySeq());
  3318. };
  3319. Set.prototype.toString = function() {
  3320. return this.__toString('Set {', '}');
  3321. };
  3322. // @pragma Access
  3323. Set.prototype.has = function(value) {
  3324. return this._map.has(value);
  3325. };
  3326. // @pragma Modification
  3327. Set.prototype.add = function(value) {
  3328. return updateSet(this, this._map.set(value, true));
  3329. };
  3330. Set.prototype.remove = function(value) {
  3331. return updateSet(this, this._map.remove(value));
  3332. };
  3333. Set.prototype.clear = function() {
  3334. return updateSet(this, this._map.clear());
  3335. };
  3336. // @pragma Composition
  3337. Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
  3338. iters = iters.filter(function(x ) {return x.size !== 0});
  3339. if (iters.length === 0) {
  3340. return this;
  3341. }
  3342. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  3343. return this.constructor(iters[0]);
  3344. }
  3345. return this.withMutations(function(set ) {
  3346. for (var ii = 0; ii < iters.length; ii++) {
  3347. SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)});
  3348. }
  3349. });
  3350. };
  3351. Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
  3352. if (iters.length === 0) {
  3353. return this;
  3354. }
  3355. iters = iters.map(function(iter ) {return SetIterable(iter)});
  3356. var originalSet = this;
  3357. return this.withMutations(function(set ) {
  3358. originalSet.forEach(function(value ) {
  3359. if (!iters.every(function(iter ) {return iter.includes(value)})) {
  3360. set.remove(value);
  3361. }
  3362. });
  3363. });
  3364. };
  3365. Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
  3366. if (iters.length === 0) {
  3367. return this;
  3368. }
  3369. iters = iters.map(function(iter ) {return SetIterable(iter)});
  3370. var originalSet = this;
  3371. return this.withMutations(function(set ) {
  3372. originalSet.forEach(function(value ) {
  3373. if (iters.some(function(iter ) {return iter.includes(value)})) {
  3374. set.remove(value);
  3375. }
  3376. });
  3377. });
  3378. };
  3379. Set.prototype.merge = function() {
  3380. return this.union.apply(this, arguments);
  3381. };
  3382. Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  3383. return this.union.apply(this, iters);
  3384. };
  3385. Set.prototype.sort = function(comparator) {
  3386. // Late binding
  3387. return OrderedSet(sortFactory(this, comparator));
  3388. };
  3389. Set.prototype.sortBy = function(mapper, comparator) {
  3390. // Late binding
  3391. return OrderedSet(sortFactory(this, comparator, mapper));
  3392. };
  3393. Set.prototype.wasAltered = function() {
  3394. return this._map.wasAltered();
  3395. };
  3396. Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  3397. return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
  3398. };
  3399. Set.prototype.__iterator = function(type, reverse) {
  3400. return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
  3401. };
  3402. Set.prototype.__ensureOwner = function(ownerID) {
  3403. if (ownerID === this.__ownerID) {
  3404. return this;
  3405. }
  3406. var newMap = this._map.__ensureOwner(ownerID);
  3407. if (!ownerID) {
  3408. this.__ownerID = ownerID;
  3409. this._map = newMap;
  3410. return this;
  3411. }
  3412. return this.__make(newMap, ownerID);
  3413. };
  3414. function isSet(maybeSet) {
  3415. return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
  3416. }
  3417. Set.isSet = isSet;
  3418. var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
  3419. var SetPrototype = Set.prototype;
  3420. SetPrototype[IS_SET_SENTINEL] = true;
  3421. SetPrototype[DELETE] = SetPrototype.remove;
  3422. SetPrototype.mergeDeep = SetPrototype.merge;
  3423. SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
  3424. SetPrototype.withMutations = MapPrototype.withMutations;
  3425. SetPrototype.asMutable = MapPrototype.asMutable;
  3426. SetPrototype.asImmutable = MapPrototype.asImmutable;
  3427. SetPrototype.__empty = emptySet;
  3428. SetPrototype.__make = makeSet;
  3429. function updateSet(set, newMap) {
  3430. if (set.__ownerID) {
  3431. set.size = newMap.size;
  3432. set._map = newMap;
  3433. return set;
  3434. }
  3435. return newMap === set._map ? set :
  3436. newMap.size === 0 ? set.__empty() :
  3437. set.__make(newMap);
  3438. }
  3439. function makeSet(map, ownerID) {
  3440. var set = Object.create(SetPrototype);
  3441. set.size = map ? map.size : 0;
  3442. set._map = map;
  3443. set.__ownerID = ownerID;
  3444. return set;
  3445. }
  3446. var EMPTY_SET;
  3447. function emptySet() {
  3448. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  3449. }
  3450. createClass(OrderedSet, Set);
  3451. // @pragma Construction
  3452. function OrderedSet(value) {
  3453. return value === null || value === undefined ? emptyOrderedSet() :
  3454. isOrderedSet(value) ? value :
  3455. emptyOrderedSet().withMutations(function(set ) {
  3456. var iter = SetIterable(value);
  3457. assertNotInfinite(iter.size);
  3458. iter.forEach(function(v ) {return set.add(v)});
  3459. });
  3460. }
  3461. OrderedSet.of = function(/*...values*/) {
  3462. return this(arguments);
  3463. };
  3464. OrderedSet.fromKeys = function(value) {
  3465. return this(KeyedIterable(value).keySeq());
  3466. };
  3467. OrderedSet.prototype.toString = function() {
  3468. return this.__toString('OrderedSet {', '}');
  3469. };
  3470. function isOrderedSet(maybeOrderedSet) {
  3471. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  3472. }
  3473. OrderedSet.isOrderedSet = isOrderedSet;
  3474. var OrderedSetPrototype = OrderedSet.prototype;
  3475. OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
  3476. OrderedSetPrototype.__empty = emptyOrderedSet;
  3477. OrderedSetPrototype.__make = makeOrderedSet;
  3478. function makeOrderedSet(map, ownerID) {
  3479. var set = Object.create(OrderedSetPrototype);
  3480. set.size = map ? map.size : 0;
  3481. set._map = map;
  3482. set.__ownerID = ownerID;
  3483. return set;
  3484. }
  3485. var EMPTY_ORDERED_SET;
  3486. function emptyOrderedSet() {
  3487. return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
  3488. }
  3489. createClass(Stack, IndexedCollection);
  3490. // @pragma Construction
  3491. function Stack(value) {
  3492. return value === null || value === undefined ? emptyStack() :
  3493. isStack(value) ? value :
  3494. emptyStack().unshiftAll(value);
  3495. }
  3496. Stack.of = function(/*...values*/) {
  3497. return this(arguments);
  3498. };
  3499. Stack.prototype.toString = function() {
  3500. return this.__toString('Stack [', ']');
  3501. };
  3502. // @pragma Access
  3503. Stack.prototype.get = function(index, notSetValue) {
  3504. var head = this._head;
  3505. index = wrapIndex(this, index);
  3506. while (head && index--) {
  3507. head = head.next;
  3508. }
  3509. return head ? head.value : notSetValue;
  3510. };
  3511. Stack.prototype.peek = function() {
  3512. return this._head && this._head.value;
  3513. };
  3514. // @pragma Modification
  3515. Stack.prototype.push = function(/*...values*/) {
  3516. if (arguments.length === 0) {
  3517. return this;
  3518. }
  3519. var newSize = this.size + arguments.length;
  3520. var head = this._head;
  3521. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  3522. head = {
  3523. value: arguments[ii],
  3524. next: head
  3525. };
  3526. }
  3527. if (this.__ownerID) {
  3528. this.size = newSize;
  3529. this._head = head;
  3530. this.__hash = undefined;
  3531. this.__altered = true;
  3532. return this;
  3533. }
  3534. return makeStack(newSize, head);
  3535. };
  3536. Stack.prototype.pushAll = function(iter) {
  3537. iter = IndexedIterable(iter);
  3538. if (iter.size === 0) {
  3539. return this;
  3540. }
  3541. assertNotInfinite(iter.size);
  3542. var newSize = this.size;
  3543. var head = this._head;
  3544. iter.reverse().forEach(function(value ) {
  3545. newSize++;
  3546. head = {
  3547. value: value,
  3548. next: head
  3549. };
  3550. });
  3551. if (this.__ownerID) {
  3552. this.size = newSize;
  3553. this._head = head;
  3554. this.__hash = undefined;
  3555. this.__altered = true;
  3556. return this;
  3557. }
  3558. return makeStack(newSize, head);
  3559. };
  3560. Stack.prototype.pop = function() {
  3561. return this.slice(1);
  3562. };
  3563. Stack.prototype.unshift = function(/*...values*/) {
  3564. return this.push.apply(this, arguments);
  3565. };
  3566. Stack.prototype.unshiftAll = function(iter) {
  3567. return this.pushAll(iter);
  3568. };
  3569. Stack.prototype.shift = function() {
  3570. return this.pop.apply(this, arguments);
  3571. };
  3572. Stack.prototype.clear = function() {
  3573. if (this.size === 0) {
  3574. return this;
  3575. }
  3576. if (this.__ownerID) {
  3577. this.size = 0;
  3578. this._head = undefined;
  3579. this.__hash = undefined;
  3580. this.__altered = true;
  3581. return this;
  3582. }
  3583. return emptyStack();
  3584. };
  3585. Stack.prototype.slice = function(begin, end) {
  3586. if (wholeSlice(begin, end, this.size)) {
  3587. return this;
  3588. }
  3589. var resolvedBegin = resolveBegin(begin, this.size);
  3590. var resolvedEnd = resolveEnd(end, this.size);
  3591. if (resolvedEnd !== this.size) {
  3592. // super.slice(begin, end);
  3593. return IndexedCollection.prototype.slice.call(this, begin, end);
  3594. }
  3595. var newSize = this.size - resolvedBegin;
  3596. var head = this._head;
  3597. while (resolvedBegin--) {
  3598. head = head.next;
  3599. }
  3600. if (this.__ownerID) {
  3601. this.size = newSize;
  3602. this._head = head;
  3603. this.__hash = undefined;
  3604. this.__altered = true;
  3605. return this;
  3606. }
  3607. return makeStack(newSize, head);
  3608. };
  3609. // @pragma Mutability
  3610. Stack.prototype.__ensureOwner = function(ownerID) {
  3611. if (ownerID === this.__ownerID) {
  3612. return this;
  3613. }
  3614. if (!ownerID) {
  3615. this.__ownerID = ownerID;
  3616. this.__altered = false;
  3617. return this;
  3618. }
  3619. return makeStack(this.size, this._head, ownerID, this.__hash);
  3620. };
  3621. // @pragma Iteration
  3622. Stack.prototype.__iterate = function(fn, reverse) {
  3623. if (reverse) {
  3624. return this.reverse().__iterate(fn);
  3625. }
  3626. var iterations = 0;
  3627. var node = this._head;
  3628. while (node) {
  3629. if (fn(node.value, iterations++, this) === false) {
  3630. break;
  3631. }
  3632. node = node.next;
  3633. }
  3634. return iterations;
  3635. };
  3636. Stack.prototype.__iterator = function(type, reverse) {
  3637. if (reverse) {
  3638. return this.reverse().__iterator(type);
  3639. }
  3640. var iterations = 0;
  3641. var node = this._head;
  3642. return new Iterator(function() {
  3643. if (node) {
  3644. var value = node.value;
  3645. node = node.next;
  3646. return iteratorValue(type, iterations++, value);
  3647. }
  3648. return iteratorDone();
  3649. });
  3650. };
  3651. function isStack(maybeStack) {
  3652. return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
  3653. }
  3654. Stack.isStack = isStack;
  3655. var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
  3656. var StackPrototype = Stack.prototype;
  3657. StackPrototype[IS_STACK_SENTINEL] = true;
  3658. StackPrototype.withMutations = MapPrototype.withMutations;
  3659. StackPrototype.asMutable = MapPrototype.asMutable;
  3660. StackPrototype.asImmutable = MapPrototype.asImmutable;
  3661. StackPrototype.wasAltered = MapPrototype.wasAltered;
  3662. function makeStack(size, head, ownerID, hash) {
  3663. var map = Object.create(StackPrototype);
  3664. map.size = size;
  3665. map._head = head;
  3666. map.__ownerID = ownerID;
  3667. map.__hash = hash;
  3668. map.__altered = false;
  3669. return map;
  3670. }
  3671. var EMPTY_STACK;
  3672. function emptyStack() {
  3673. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  3674. }
  3675. /**
  3676. * Contributes additional methods to a constructor
  3677. */
  3678. function mixin(ctor, methods) {
  3679. var keyCopier = function(key ) { ctor.prototype[key] = methods[key]; };
  3680. Object.keys(methods).forEach(keyCopier);
  3681. Object.getOwnPropertySymbols &&
  3682. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  3683. return ctor;
  3684. }
  3685. Iterable.Iterator = Iterator;
  3686. mixin(Iterable, {
  3687. // ### Conversion to other types
  3688. toArray: function() {
  3689. assertNotInfinite(this.size);
  3690. var array = new Array(this.size || 0);
  3691. this.valueSeq().__iterate(function(v, i) { array[i] = v; });
  3692. return array;
  3693. },
  3694. toIndexedSeq: function() {
  3695. return new ToIndexedSequence(this);
  3696. },
  3697. toJS: function() {
  3698. return this.toSeq().map(
  3699. function(value ) {return value && typeof value.toJS === 'function' ? value.toJS() : value}
  3700. ).__toJS();
  3701. },
  3702. toJSON: function() {
  3703. return this.toSeq().map(
  3704. function(value ) {return value && typeof value.toJSON === 'function' ? value.toJSON() : value}
  3705. ).__toJS();
  3706. },
  3707. toKeyedSeq: function() {
  3708. return new ToKeyedSequence(this, true);
  3709. },
  3710. toMap: function() {
  3711. // Use Late Binding here to solve the circular dependency.
  3712. return Map(this.toKeyedSeq());
  3713. },
  3714. toObject: function() {
  3715. assertNotInfinite(this.size);
  3716. var object = {};
  3717. this.__iterate(function(v, k) { object[k] = v; });
  3718. return object;
  3719. },
  3720. toOrderedMap: function() {
  3721. // Use Late Binding here to solve the circular dependency.
  3722. return OrderedMap(this.toKeyedSeq());
  3723. },
  3724. toOrderedSet: function() {
  3725. // Use Late Binding here to solve the circular dependency.
  3726. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  3727. },
  3728. toSet: function() {
  3729. // Use Late Binding here to solve the circular dependency.
  3730. return Set(isKeyed(this) ? this.valueSeq() : this);
  3731. },
  3732. toSetSeq: function() {
  3733. return new ToSetSequence(this);
  3734. },
  3735. toSeq: function() {
  3736. return isIndexed(this) ? this.toIndexedSeq() :
  3737. isKeyed(this) ? this.toKeyedSeq() :
  3738. this.toSetSeq();
  3739. },
  3740. toStack: function() {
  3741. // Use Late Binding here to solve the circular dependency.
  3742. return Stack(isKeyed(this) ? this.valueSeq() : this);
  3743. },
  3744. toList: function() {
  3745. // Use Late Binding here to solve the circular dependency.
  3746. return List(isKeyed(this) ? this.valueSeq() : this);
  3747. },
  3748. // ### Common JavaScript methods and properties
  3749. toString: function() {
  3750. return '[Iterable]';
  3751. },
  3752. __toString: function(head, tail) {
  3753. if (this.size === 0) {
  3754. return head + tail;
  3755. }
  3756. return head + ' ' + this.toSeq().map(this.__toStringMapper).join(', ') + ' ' + tail;
  3757. },
  3758. // ### ES6 Collection methods (ES6 Array and Map)
  3759. concat: function() {var values = SLICE$0.call(arguments, 0);
  3760. return reify(this, concatFactory(this, values));
  3761. },
  3762. includes: function(searchValue) {
  3763. return this.some(function(value ) {return is(value, searchValue)});
  3764. },
  3765. entries: function() {
  3766. return this.__iterator(ITERATE_ENTRIES);
  3767. },
  3768. every: function(predicate, context) {
  3769. assertNotInfinite(this.size);
  3770. var returnValue = true;
  3771. this.__iterate(function(v, k, c) {
  3772. if (!predicate.call(context, v, k, c)) {
  3773. returnValue = false;
  3774. return false;
  3775. }
  3776. });
  3777. return returnValue;
  3778. },
  3779. filter: function(predicate, context) {
  3780. return reify(this, filterFactory(this, predicate, context, true));
  3781. },
  3782. find: function(predicate, context, notSetValue) {
  3783. var entry = this.findEntry(predicate, context);
  3784. return entry ? entry[1] : notSetValue;
  3785. },
  3786. findEntry: function(predicate, context) {
  3787. var found;
  3788. this.__iterate(function(v, k, c) {
  3789. if (predicate.call(context, v, k, c)) {
  3790. found = [k, v];
  3791. return false;
  3792. }
  3793. });
  3794. return found;
  3795. },
  3796. findLastEntry: function(predicate, context) {
  3797. return this.toSeq().reverse().findEntry(predicate, context);
  3798. },
  3799. forEach: function(sideEffect, context) {
  3800. assertNotInfinite(this.size);
  3801. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  3802. },
  3803. join: function(separator) {
  3804. assertNotInfinite(this.size);
  3805. separator = separator !== undefined ? '' + separator : ',';
  3806. var joined = '';
  3807. var isFirst = true;
  3808. this.__iterate(function(v ) {
  3809. isFirst ? (isFirst = false) : (joined += separator);
  3810. joined += v !== null && v !== undefined ? v.toString() : '';
  3811. });
  3812. return joined;
  3813. },
  3814. keys: function() {
  3815. return this.__iterator(ITERATE_KEYS);
  3816. },
  3817. map: function(mapper, context) {
  3818. return reify(this, mapFactory(this, mapper, context));
  3819. },
  3820. reduce: function(reducer, initialReduction, context) {
  3821. assertNotInfinite(this.size);
  3822. var reduction;
  3823. var useFirst;
  3824. if (arguments.length < 2) {
  3825. useFirst = true;
  3826. } else {
  3827. reduction = initialReduction;
  3828. }
  3829. this.__iterate(function(v, k, c) {
  3830. if (useFirst) {
  3831. useFirst = false;
  3832. reduction = v;
  3833. } else {
  3834. reduction = reducer.call(context, reduction, v, k, c);
  3835. }
  3836. });
  3837. return reduction;
  3838. },
  3839. reduceRight: function(reducer, initialReduction, context) {
  3840. var reversed = this.toKeyedSeq().reverse();
  3841. return reversed.reduce.apply(reversed, arguments);
  3842. },
  3843. reverse: function() {
  3844. return reify(this, reverseFactory(this, true));
  3845. },
  3846. slice: function(begin, end) {
  3847. return reify(this, sliceFactory(this, begin, end, true));
  3848. },
  3849. some: function(predicate, context) {
  3850. return !this.every(not(predicate), context);
  3851. },
  3852. sort: function(comparator) {
  3853. return reify(this, sortFactory(this, comparator));
  3854. },
  3855. values: function() {
  3856. return this.__iterator(ITERATE_VALUES);
  3857. },
  3858. // ### More sequential methods
  3859. butLast: function() {
  3860. return this.slice(0, -1);
  3861. },
  3862. isEmpty: function() {
  3863. return this.size !== undefined ? this.size === 0 : !this.some(function() {return true});
  3864. },
  3865. count: function(predicate, context) {
  3866. return ensureSize(
  3867. predicate ? this.toSeq().filter(predicate, context) : this
  3868. );
  3869. },
  3870. countBy: function(grouper, context) {
  3871. return countByFactory(this, grouper, context);
  3872. },
  3873. equals: function(other) {
  3874. return deepEqual(this, other);
  3875. },
  3876. entrySeq: function() {
  3877. var iterable = this;
  3878. if (iterable._cache) {
  3879. // We cache as an entries array, so we can just return the cache!
  3880. return new ArraySeq(iterable._cache);
  3881. }
  3882. var entriesSequence = iterable.toSeq().map(entryMapper).toIndexedSeq();
  3883. entriesSequence.fromEntrySeq = function() {return iterable.toSeq()};
  3884. return entriesSequence;
  3885. },
  3886. filterNot: function(predicate, context) {
  3887. return this.filter(not(predicate), context);
  3888. },
  3889. findLast: function(predicate, context, notSetValue) {
  3890. return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
  3891. },
  3892. first: function() {
  3893. return this.find(returnTrue);
  3894. },
  3895. flatMap: function(mapper, context) {
  3896. return reify(this, flatMapFactory(this, mapper, context));
  3897. },
  3898. flatten: function(depth) {
  3899. return reify(this, flattenFactory(this, depth, true));
  3900. },
  3901. fromEntrySeq: function() {
  3902. return new FromEntriesSequence(this);
  3903. },
  3904. get: function(searchKey, notSetValue) {
  3905. return this.find(function(_, key) {return is(key, searchKey)}, undefined, notSetValue);
  3906. },
  3907. getIn: function(searchKeyPath, notSetValue) {
  3908. var nested = this;
  3909. // Note: in an ES6 environment, we would prefer:
  3910. // for (var key of searchKeyPath) {
  3911. var iter = forceIterator(searchKeyPath);
  3912. var step;
  3913. while (!(step = iter.next()).done) {
  3914. var key = step.value;
  3915. nested = nested && nested.get ? nested.get(key, NOT_SET) : NOT_SET;
  3916. if (nested === NOT_SET) {
  3917. return notSetValue;
  3918. }
  3919. }
  3920. return nested;
  3921. },
  3922. groupBy: function(grouper, context) {
  3923. return groupByFactory(this, grouper, context);
  3924. },
  3925. has: function(searchKey) {
  3926. return this.get(searchKey, NOT_SET) !== NOT_SET;
  3927. },
  3928. hasIn: function(searchKeyPath) {
  3929. return this.getIn(searchKeyPath, NOT_SET) !== NOT_SET;
  3930. },
  3931. isSubset: function(iter) {
  3932. iter = typeof iter.includes === 'function' ? iter : Iterable(iter);
  3933. return this.every(function(value ) {return iter.includes(value)});
  3934. },
  3935. isSuperset: function(iter) {
  3936. iter = typeof iter.isSubset === 'function' ? iter : Iterable(iter);
  3937. return iter.isSubset(this);
  3938. },
  3939. keySeq: function() {
  3940. return this.toSeq().map(keyMapper).toIndexedSeq();
  3941. },
  3942. last: function() {
  3943. return this.toSeq().reverse().first();
  3944. },
  3945. max: function(comparator) {
  3946. return maxFactory(this, comparator);
  3947. },
  3948. maxBy: function(mapper, comparator) {
  3949. return maxFactory(this, comparator, mapper);
  3950. },
  3951. min: function(comparator) {
  3952. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator);
  3953. },
  3954. minBy: function(mapper, comparator) {
  3955. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator, mapper);
  3956. },
  3957. rest: function() {
  3958. return this.slice(1);
  3959. },
  3960. skip: function(amount) {
  3961. return this.slice(Math.max(0, amount));
  3962. },
  3963. skipLast: function(amount) {
  3964. return reify(this, this.toSeq().reverse().skip(amount).reverse());
  3965. },
  3966. skipWhile: function(predicate, context) {
  3967. return reify(this, skipWhileFactory(this, predicate, context, true));
  3968. },
  3969. skipUntil: function(predicate, context) {
  3970. return this.skipWhile(not(predicate), context);
  3971. },
  3972. sortBy: function(mapper, comparator) {
  3973. return reify(this, sortFactory(this, comparator, mapper));
  3974. },
  3975. take: function(amount) {
  3976. return this.slice(0, Math.max(0, amount));
  3977. },
  3978. takeLast: function(amount) {
  3979. return reify(this, this.toSeq().reverse().take(amount).reverse());
  3980. },
  3981. takeWhile: function(predicate, context) {
  3982. return reify(this, takeWhileFactory(this, predicate, context));
  3983. },
  3984. takeUntil: function(predicate, context) {
  3985. return this.takeWhile(not(predicate), context);
  3986. },
  3987. valueSeq: function() {
  3988. return this.toIndexedSeq();
  3989. },
  3990. // ### Hashable Object
  3991. hashCode: function() {
  3992. return this.__hash || (this.__hash = hashIterable(this));
  3993. }
  3994. // ### Internal
  3995. // abstract __iterate(fn, reverse)
  3996. // abstract __iterator(type, reverse)
  3997. });
  3998. // var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  3999. // var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  4000. // var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  4001. // var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  4002. var IterablePrototype = Iterable.prototype;
  4003. IterablePrototype[IS_ITERABLE_SENTINEL] = true;
  4004. IterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.values;
  4005. IterablePrototype.__toJS = IterablePrototype.toArray;
  4006. IterablePrototype.__toStringMapper = quoteString;
  4007. IterablePrototype.inspect =
  4008. IterablePrototype.toSource = function() { return this.toString(); };
  4009. IterablePrototype.chain = IterablePrototype.flatMap;
  4010. IterablePrototype.contains = IterablePrototype.includes;
  4011. // Temporary warning about using length
  4012. (function () {
  4013. try {
  4014. Object.defineProperty(IterablePrototype, 'length', {
  4015. get: function () {
  4016. if (!Iterable.noLengthWarning) {
  4017. var stack;
  4018. try {
  4019. throw new Error();
  4020. } catch (error) {
  4021. stack = error.stack;
  4022. }
  4023. if (stack.indexOf('_wrapObject') === -1) {
  4024. console && console.warn && console.warn(
  4025. 'iterable.length has been deprecated, '+
  4026. 'use iterable.size or iterable.count(). '+
  4027. 'This warning will become a silent error in a future version. ' +
  4028. stack
  4029. );
  4030. return this.size;
  4031. }
  4032. }
  4033. }
  4034. });
  4035. } catch (e) {}
  4036. })();
  4037. mixin(KeyedIterable, {
  4038. // ### More sequential methods
  4039. flip: function() {
  4040. return reify(this, flipFactory(this));
  4041. },
  4042. findKey: function(predicate, context) {
  4043. var entry = this.findEntry(predicate, context);
  4044. return entry && entry[0];
  4045. },
  4046. findLastKey: function(predicate, context) {
  4047. return this.toSeq().reverse().findKey(predicate, context);
  4048. },
  4049. keyOf: function(searchValue) {
  4050. return this.findKey(function(value ) {return is(value, searchValue)});
  4051. },
  4052. lastKeyOf: function(searchValue) {
  4053. return this.findLastKey(function(value ) {return is(value, searchValue)});
  4054. },
  4055. mapEntries: function(mapper, context) {var this$0 = this;
  4056. var iterations = 0;
  4057. return reify(this,
  4058. this.toSeq().map(
  4059. function(v, k) {return mapper.call(context, [k, v], iterations++, this$0)}
  4060. ).fromEntrySeq()
  4061. );
  4062. },
  4063. mapKeys: function(mapper, context) {var this$0 = this;
  4064. return reify(this,
  4065. this.toSeq().flip().map(
  4066. function(k, v) {return mapper.call(context, k, v, this$0)}
  4067. ).flip()
  4068. );
  4069. }
  4070. });
  4071. var KeyedIterablePrototype = KeyedIterable.prototype;
  4072. KeyedIterablePrototype[IS_KEYED_SENTINEL] = true;
  4073. KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries;
  4074. KeyedIterablePrototype.__toJS = IterablePrototype.toObject;
  4075. KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)};
  4076. mixin(IndexedIterable, {
  4077. // ### Conversion to other types
  4078. toKeyedSeq: function() {
  4079. return new ToKeyedSequence(this, false);
  4080. },
  4081. // ### ES6 Collection methods (ES6 Array and Map)
  4082. filter: function(predicate, context) {
  4083. return reify(this, filterFactory(this, predicate, context, false));
  4084. },
  4085. findIndex: function(predicate, context) {
  4086. var entry = this.findEntry(predicate, context);
  4087. return entry ? entry[0] : -1;
  4088. },
  4089. indexOf: function(searchValue) {
  4090. var key = this.toKeyedSeq().keyOf(searchValue);
  4091. return key === undefined ? -1 : key;
  4092. },
  4093. lastIndexOf: function(searchValue) {
  4094. var key = this.toKeyedSeq().reverse().keyOf(searchValue);
  4095. return key === undefined ? -1 : key;
  4096. // var index =
  4097. // return this.toSeq().reverse().indexOf(searchValue);
  4098. },
  4099. reverse: function() {
  4100. return reify(this, reverseFactory(this, false));
  4101. },
  4102. slice: function(begin, end) {
  4103. return reify(this, sliceFactory(this, begin, end, false));
  4104. },
  4105. splice: function(index, removeNum /*, ...values*/) {
  4106. var numArgs = arguments.length;
  4107. removeNum = Math.max(removeNum | 0, 0);
  4108. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  4109. return this;
  4110. }
  4111. // If index is negative, it should resolve relative to the size of the
  4112. // collection. However size may be expensive to compute if not cached, so
  4113. // only call count() if the number is in fact negative.
  4114. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  4115. var spliced = this.slice(0, index);
  4116. return reify(
  4117. this,
  4118. numArgs === 1 ?
  4119. spliced :
  4120. spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  4121. );
  4122. },
  4123. // ### More collection methods
  4124. findLastIndex: function(predicate, context) {
  4125. var key = this.toKeyedSeq().findLastKey(predicate, context);
  4126. return key === undefined ? -1 : key;
  4127. },
  4128. first: function() {
  4129. return this.get(0);
  4130. },
  4131. flatten: function(depth) {
  4132. return reify(this, flattenFactory(this, depth, false));
  4133. },
  4134. get: function(index, notSetValue) {
  4135. index = wrapIndex(this, index);
  4136. return (index < 0 || (this.size === Infinity ||
  4137. (this.size !== undefined && index > this.size))) ?
  4138. notSetValue :
  4139. this.find(function(_, key) {return key === index}, undefined, notSetValue);
  4140. },
  4141. has: function(index) {
  4142. index = wrapIndex(this, index);
  4143. return index >= 0 && (this.size !== undefined ?
  4144. this.size === Infinity || index < this.size :
  4145. this.indexOf(index) !== -1
  4146. );
  4147. },
  4148. interpose: function(separator) {
  4149. return reify(this, interposeFactory(this, separator));
  4150. },
  4151. interleave: function(/*...iterables*/) {
  4152. var iterables = [this].concat(arrCopy(arguments));
  4153. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, iterables);
  4154. var interleaved = zipped.flatten(true);
  4155. if (zipped.size) {
  4156. interleaved.size = zipped.size * iterables.length;
  4157. }
  4158. return reify(this, interleaved);
  4159. },
  4160. last: function() {
  4161. return this.get(-1);
  4162. },
  4163. skipWhile: function(predicate, context) {
  4164. return reify(this, skipWhileFactory(this, predicate, context, false));
  4165. },
  4166. zip: function(/*, ...iterables */) {
  4167. var iterables = [this].concat(arrCopy(arguments));
  4168. return reify(this, zipWithFactory(this, defaultZipper, iterables));
  4169. },
  4170. zipWith: function(zipper/*, ...iterables */) {
  4171. var iterables = arrCopy(arguments);
  4172. iterables[0] = this;
  4173. return reify(this, zipWithFactory(this, zipper, iterables));
  4174. }
  4175. });
  4176. IndexedIterable.prototype[IS_INDEXED_SENTINEL] = true;
  4177. IndexedIterable.prototype[IS_ORDERED_SENTINEL] = true;
  4178. mixin(SetIterable, {
  4179. // ### ES6 Collection methods (ES6 Array and Map)
  4180. get: function(value, notSetValue) {
  4181. return this.has(value) ? value : notSetValue;
  4182. },
  4183. includes: function(value) {
  4184. return this.has(value);
  4185. },
  4186. // ### More sequential methods
  4187. keySeq: function() {
  4188. return this.valueSeq();
  4189. }
  4190. });
  4191. SetIterable.prototype.has = IterablePrototype.includes;
  4192. // Mixin subclasses
  4193. mixin(KeyedSeq, KeyedIterable.prototype);
  4194. mixin(IndexedSeq, IndexedIterable.prototype);
  4195. mixin(SetSeq, SetIterable.prototype);
  4196. mixin(KeyedCollection, KeyedIterable.prototype);
  4197. mixin(IndexedCollection, IndexedIterable.prototype);
  4198. mixin(SetCollection, SetIterable.prototype);
  4199. // #pragma Helper functions
  4200. function keyMapper(v, k) {
  4201. return k;
  4202. }
  4203. function entryMapper(v, k) {
  4204. return [k, v];
  4205. }
  4206. function not(predicate) {
  4207. return function() {
  4208. return !predicate.apply(this, arguments);
  4209. }
  4210. }
  4211. function neg(predicate) {
  4212. return function() {
  4213. return -predicate.apply(this, arguments);
  4214. }
  4215. }
  4216. function quoteString(value) {
  4217. return typeof value === 'string' ? JSON.stringify(value) : value;
  4218. }
  4219. function defaultZipper() {
  4220. return arrCopy(arguments);
  4221. }
  4222. function defaultNegComparator(a, b) {
  4223. return a < b ? 1 : a > b ? -1 : 0;
  4224. }
  4225. function hashIterable(iterable) {
  4226. if (iterable.size === Infinity) {
  4227. return 0;
  4228. }
  4229. var ordered = isOrdered(iterable);
  4230. var keyed = isKeyed(iterable);
  4231. var h = ordered ? 1 : 0;
  4232. var size = iterable.__iterate(
  4233. keyed ?
  4234. ordered ?
  4235. function(v, k) { h = 31 * h + hashMerge(hash(v), hash(k)) | 0; } :
  4236. function(v, k) { h = h + hashMerge(hash(v), hash(k)) | 0; } :
  4237. ordered ?
  4238. function(v ) { h = 31 * h + hash(v) | 0; } :
  4239. function(v ) { h = h + hash(v) | 0; }
  4240. );
  4241. return murmurHashOfSize(size, h);
  4242. }
  4243. function murmurHashOfSize(size, h) {
  4244. h = imul(h, 0xCC9E2D51);
  4245. h = imul(h << 15 | h >>> -15, 0x1B873593);
  4246. h = imul(h << 13 | h >>> -13, 5);
  4247. h = (h + 0xE6546B64 | 0) ^ size;
  4248. h = imul(h ^ h >>> 16, 0x85EBCA6B);
  4249. h = imul(h ^ h >>> 13, 0xC2B2AE35);
  4250. h = smi(h ^ h >>> 16);
  4251. return h;
  4252. }
  4253. function hashMerge(a, b) {
  4254. return a ^ b + 0x9E3779B9 + (a << 6) + (a >> 2) | 0; // int
  4255. }
  4256. var Immutable = {
  4257. Iterable: Iterable,
  4258. Seq: Seq,
  4259. Collection: Collection,
  4260. Map: Map,
  4261. OrderedMap: OrderedMap,
  4262. List: List,
  4263. Stack: Stack,
  4264. Set: Set,
  4265. OrderedSet: OrderedSet,
  4266. Record: Record,
  4267. Range: Range,
  4268. Repeat: Repeat,
  4269. is: is,
  4270. fromJS: fromJS
  4271. };
  4272. return Immutable;
  4273. }));
  4274. });
  4275. var OrderedMap = immutable.OrderedMap;
  4276. var BlockMapBuilder = {
  4277. createFromArray: function createFromArray(blocks) {
  4278. return OrderedMap(blocks.map(function (block) {
  4279. return [block.getKey(), block];
  4280. }));
  4281. }
  4282. };
  4283. var BlockMapBuilder_1 = BlockMapBuilder;
  4284. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4285. 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; }
  4286. 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; }
  4287. var Map$1 = immutable.Map,
  4288. OrderedSet = immutable.OrderedSet,
  4289. Record = immutable.Record;
  4290. // Immutable.map is typed such that the value for every key in the map
  4291. // must be the same type
  4292. var EMPTY_SET = OrderedSet();
  4293. var defaultRecord = {
  4294. style: EMPTY_SET,
  4295. entity: null
  4296. };
  4297. var CharacterMetadataRecord = Record(defaultRecord);
  4298. var CharacterMetadata = function (_CharacterMetadataRec) {
  4299. _inherits(CharacterMetadata, _CharacterMetadataRec);
  4300. function CharacterMetadata() {
  4301. _classCallCheck(this, CharacterMetadata);
  4302. return _possibleConstructorReturn(this, _CharacterMetadataRec.apply(this, arguments));
  4303. }
  4304. CharacterMetadata.prototype.getStyle = function getStyle() {
  4305. return this.get('style');
  4306. };
  4307. CharacterMetadata.prototype.getEntity = function getEntity() {
  4308. return this.get('entity');
  4309. };
  4310. CharacterMetadata.prototype.hasStyle = function hasStyle(style) {
  4311. return this.getStyle().includes(style);
  4312. };
  4313. CharacterMetadata.applyStyle = function applyStyle(record, style) {
  4314. var withStyle = record.set('style', record.getStyle().add(style));
  4315. return CharacterMetadata.create(withStyle);
  4316. };
  4317. CharacterMetadata.removeStyle = function removeStyle(record, style) {
  4318. var withoutStyle = record.set('style', record.getStyle().remove(style));
  4319. return CharacterMetadata.create(withoutStyle);
  4320. };
  4321. CharacterMetadata.applyEntity = function applyEntity(record, entityKey) {
  4322. var withEntity = record.getEntity() === entityKey ? record : record.set('entity', entityKey);
  4323. return CharacterMetadata.create(withEntity);
  4324. };
  4325. /**
  4326. * Use this function instead of the `CharacterMetadata` constructor.
  4327. * Since most content generally uses only a very small number of
  4328. * style/entity permutations, we can reuse these objects as often as
  4329. * possible.
  4330. */
  4331. CharacterMetadata.create = function create(config) {
  4332. if (!config) {
  4333. return EMPTY;
  4334. }
  4335. var defaultConfig = {
  4336. style: EMPTY_SET,
  4337. entity: null
  4338. };
  4339. // Fill in unspecified properties, if necessary.
  4340. var configMap = Map$1(defaultConfig).merge(config);
  4341. var existing = pool.get(configMap);
  4342. if (existing) {
  4343. return existing;
  4344. }
  4345. var newCharacter = new CharacterMetadata(configMap);
  4346. pool = pool.set(configMap, newCharacter);
  4347. return newCharacter;
  4348. };
  4349. return CharacterMetadata;
  4350. }(CharacterMetadataRecord);
  4351. var EMPTY = new CharacterMetadata();
  4352. var pool = Map$1([[Map$1(defaultRecord), EMPTY]]);
  4353. CharacterMetadata.EMPTY = EMPTY;
  4354. var CharacterMetadata_1 = CharacterMetadata;
  4355. /**
  4356. * Copyright (c) 2013-present, Facebook, Inc.
  4357. * All rights reserved.
  4358. *
  4359. * This source code is licensed under the BSD-style license found in the
  4360. * LICENSE file in the root directory of this source tree. An additional grant
  4361. * of patent rights can be found in the PATENTS file in the same directory.
  4362. *
  4363. * @providesModule findRangesImmutable
  4364. * @format
  4365. *
  4366. */
  4367. /**
  4368. * Search through an array to find contiguous stretches of elements that
  4369. * match a specified filter function.
  4370. *
  4371. * When ranges are found, execute a specified `found` function to supply
  4372. * the values to the caller.
  4373. */
  4374. function findRangesImmutable(haystack, areEqualFn, filterFn, foundFn) {
  4375. if (!haystack.size) {
  4376. return;
  4377. }
  4378. var cursor = 0;
  4379. haystack.reduce(function (value, nextValue, nextIndex) {
  4380. if (!areEqualFn(value, nextValue)) {
  4381. if (filterFn(value)) {
  4382. foundFn(cursor, nextIndex);
  4383. }
  4384. cursor = nextIndex;
  4385. }
  4386. return nextValue;
  4387. });
  4388. filterFn(haystack.last()) && foundFn(cursor, haystack.count());
  4389. }
  4390. var findRangesImmutable_1 = findRangesImmutable;
  4391. function _classCallCheck$1(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4392. 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; }
  4393. 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; }
  4394. var List = immutable.List,
  4395. Map$2 = immutable.Map,
  4396. OrderedSet$1 = immutable.OrderedSet,
  4397. Record$1 = immutable.Record,
  4398. Repeat = immutable.Repeat;
  4399. var EMPTY_SET$1 = OrderedSet$1();
  4400. var defaultRecord$1 = {
  4401. key: '',
  4402. type: 'unstyled',
  4403. text: '',
  4404. characterList: List(),
  4405. depth: 0,
  4406. data: Map$2()
  4407. };
  4408. var ContentBlockRecord = Record$1(defaultRecord$1);
  4409. var decorateCharacterList = function decorateCharacterList(config) {
  4410. if (!config) {
  4411. return config;
  4412. }
  4413. var characterList = config.characterList,
  4414. text = config.text;
  4415. if (text && !characterList) {
  4416. config.characterList = List(Repeat(CharacterMetadata_1.EMPTY, text.length));
  4417. }
  4418. return config;
  4419. };
  4420. var ContentBlock = function (_ContentBlockRecord) {
  4421. _inherits$1(ContentBlock, _ContentBlockRecord);
  4422. function ContentBlock(config) {
  4423. _classCallCheck$1(this, ContentBlock);
  4424. return _possibleConstructorReturn$1(this, _ContentBlockRecord.call(this, decorateCharacterList(config)));
  4425. }
  4426. ContentBlock.prototype.getKey = function getKey() {
  4427. return this.get('key');
  4428. };
  4429. ContentBlock.prototype.getType = function getType() {
  4430. return this.get('type');
  4431. };
  4432. ContentBlock.prototype.getText = function getText() {
  4433. return this.get('text');
  4434. };
  4435. ContentBlock.prototype.getCharacterList = function getCharacterList() {
  4436. return this.get('characterList');
  4437. };
  4438. ContentBlock.prototype.getLength = function getLength() {
  4439. return this.getText().length;
  4440. };
  4441. ContentBlock.prototype.getDepth = function getDepth() {
  4442. return this.get('depth');
  4443. };
  4444. ContentBlock.prototype.getData = function getData() {
  4445. return this.get('data');
  4446. };
  4447. ContentBlock.prototype.getInlineStyleAt = function getInlineStyleAt(offset) {
  4448. var character = this.getCharacterList().get(offset);
  4449. return character ? character.getStyle() : EMPTY_SET$1;
  4450. };
  4451. ContentBlock.prototype.getEntityAt = function getEntityAt(offset) {
  4452. var character = this.getCharacterList().get(offset);
  4453. return character ? character.getEntity() : null;
  4454. };
  4455. /**
  4456. * Execute a callback for every contiguous range of styles within the block.
  4457. */
  4458. ContentBlock.prototype.findStyleRanges = function findStyleRanges(filterFn, callback) {
  4459. findRangesImmutable_1(this.getCharacterList(), haveEqualStyle, filterFn, callback);
  4460. };
  4461. /**
  4462. * Execute a callback for every contiguous range of entities within the block.
  4463. */
  4464. ContentBlock.prototype.findEntityRanges = function findEntityRanges(filterFn, callback) {
  4465. findRangesImmutable_1(this.getCharacterList(), haveEqualEntity, filterFn, callback);
  4466. };
  4467. return ContentBlock;
  4468. }(ContentBlockRecord);
  4469. function haveEqualStyle(charA, charB) {
  4470. return charA.getStyle() === charB.getStyle();
  4471. }
  4472. function haveEqualEntity(charA, charB) {
  4473. return charA.getEntity() === charB.getEntity();
  4474. }
  4475. var ContentBlock_1 = ContentBlock;
  4476. function _classCallCheck$2(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4477. 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; }
  4478. 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; }
  4479. var List$1 = immutable.List,
  4480. Map$3 = immutable.Map,
  4481. OrderedSet$2 = immutable.OrderedSet,
  4482. Record$2 = immutable.Record,
  4483. Repeat$1 = immutable.Repeat;
  4484. var EMPTY_SET$2 = OrderedSet$2();
  4485. var defaultRecord$2 = {
  4486. parent: null,
  4487. characterList: List$1(),
  4488. data: Map$3(),
  4489. depth: 0,
  4490. key: '',
  4491. text: '',
  4492. type: 'unstyled',
  4493. children: List$1(),
  4494. prevSibling: null,
  4495. nextSibling: null
  4496. };
  4497. var haveEqualStyle$1 = function haveEqualStyle(charA, charB) {
  4498. return charA.getStyle() === charB.getStyle();
  4499. };
  4500. var haveEqualEntity$1 = function haveEqualEntity(charA, charB) {
  4501. return charA.getEntity() === charB.getEntity();
  4502. };
  4503. var decorateCharacterList$1 = function decorateCharacterList(config) {
  4504. if (!config) {
  4505. return config;
  4506. }
  4507. var characterList = config.characterList,
  4508. text = config.text;
  4509. if (text && !characterList) {
  4510. config.characterList = List$1(Repeat$1(CharacterMetadata_1.EMPTY, text.length));
  4511. }
  4512. return config;
  4513. };
  4514. var ContentBlockNode = function (_Record) {
  4515. _inherits$2(ContentBlockNode, _Record);
  4516. function ContentBlockNode() {
  4517. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultRecord$2;
  4518. _classCallCheck$2(this, ContentBlockNode);
  4519. return _possibleConstructorReturn$2(this, _Record.call(this, decorateCharacterList$1(props)));
  4520. }
  4521. ContentBlockNode.prototype.getKey = function getKey() {
  4522. return this.get('key');
  4523. };
  4524. ContentBlockNode.prototype.getType = function getType() {
  4525. return this.get('type');
  4526. };
  4527. ContentBlockNode.prototype.getText = function getText() {
  4528. return this.get('text');
  4529. };
  4530. ContentBlockNode.prototype.getCharacterList = function getCharacterList() {
  4531. return this.get('characterList');
  4532. };
  4533. ContentBlockNode.prototype.getLength = function getLength() {
  4534. return this.getText().length;
  4535. };
  4536. ContentBlockNode.prototype.getDepth = function getDepth() {
  4537. return this.get('depth');
  4538. };
  4539. ContentBlockNode.prototype.getData = function getData() {
  4540. return this.get('data');
  4541. };
  4542. ContentBlockNode.prototype.getInlineStyleAt = function getInlineStyleAt(offset) {
  4543. var character = this.getCharacterList().get(offset);
  4544. return character ? character.getStyle() : EMPTY_SET$2;
  4545. };
  4546. ContentBlockNode.prototype.getEntityAt = function getEntityAt(offset) {
  4547. var character = this.getCharacterList().get(offset);
  4548. return character ? character.getEntity() : null;
  4549. };
  4550. ContentBlockNode.prototype.getChildKeys = function getChildKeys() {
  4551. return this.get('children');
  4552. };
  4553. ContentBlockNode.prototype.getParentKey = function getParentKey() {
  4554. return this.get('parent');
  4555. };
  4556. ContentBlockNode.prototype.getPrevSiblingKey = function getPrevSiblingKey() {
  4557. return this.get('prevSibling');
  4558. };
  4559. ContentBlockNode.prototype.getNextSiblingKey = function getNextSiblingKey() {
  4560. return this.get('nextSibling');
  4561. };
  4562. ContentBlockNode.prototype.findStyleRanges = function findStyleRanges(filterFn, callback) {
  4563. findRangesImmutable_1(this.getCharacterList(), haveEqualStyle$1, filterFn, callback);
  4564. };
  4565. ContentBlockNode.prototype.findEntityRanges = function findEntityRanges(filterFn, callback) {
  4566. findRangesImmutable_1(this.getCharacterList(), haveEqualEntity$1, filterFn, callback);
  4567. };
  4568. return ContentBlockNode;
  4569. }(Record$2(defaultRecord$2));
  4570. var ContentBlockNode_1 = ContentBlockNode;
  4571. /**
  4572. * Copyright 2013-present, Facebook, Inc.
  4573. * All rights reserved.
  4574. *
  4575. * This source code is licensed under the BSD-style license found in the
  4576. * LICENSE file in the root directory of this source tree. An additional grant
  4577. * of patent rights can be found in the PATENTS file in the same directory.
  4578. *
  4579. * @providesModule DraftFeatureFlags-core
  4580. * @format
  4581. *
  4582. */
  4583. var DraftFeatureFlags = {
  4584. draft_killswitch_allow_nontextnodes: false,
  4585. draft_segmented_entities_behavior: false,
  4586. draft_handlebeforeinput_composed_text: false,
  4587. draft_tree_data_support: false
  4588. };
  4589. var DraftFeatureFlagsCore = DraftFeatureFlags;
  4590. var DraftFeatureFlags_1 = DraftFeatureFlagsCore;
  4591. var Map$4 = immutable.Map;
  4592. var ContentStateInlineStyle = {
  4593. add: function add(contentState, selectionState, inlineStyle) {
  4594. return modifyInlineStyle(contentState, selectionState, inlineStyle, true);
  4595. },
  4596. remove: function remove(contentState, selectionState, inlineStyle) {
  4597. return modifyInlineStyle(contentState, selectionState, inlineStyle, false);
  4598. }
  4599. };
  4600. function modifyInlineStyle(contentState, selectionState, inlineStyle, addOrRemove) {
  4601. var blockMap = contentState.getBlockMap();
  4602. var startKey = selectionState.getStartKey();
  4603. var startOffset = selectionState.getStartOffset();
  4604. var endKey = selectionState.getEndKey();
  4605. var endOffset = selectionState.getEndOffset();
  4606. var newBlocks = blockMap.skipUntil(function (_, k) {
  4607. return k === startKey;
  4608. }).takeUntil(function (_, k) {
  4609. return k === endKey;
  4610. }).concat(Map$4([[endKey, blockMap.get(endKey)]])).map(function (block, blockKey) {
  4611. var sliceStart;
  4612. var sliceEnd;
  4613. if (startKey === endKey) {
  4614. sliceStart = startOffset;
  4615. sliceEnd = endOffset;
  4616. } else {
  4617. sliceStart = blockKey === startKey ? startOffset : 0;
  4618. sliceEnd = blockKey === endKey ? endOffset : block.getLength();
  4619. }
  4620. var chars = block.getCharacterList();
  4621. var current;
  4622. while (sliceStart < sliceEnd) {
  4623. current = chars.get(sliceStart);
  4624. chars = chars.set(sliceStart, addOrRemove ? CharacterMetadata_1.applyStyle(current, inlineStyle) : CharacterMetadata_1.removeStyle(current, inlineStyle));
  4625. sliceStart++;
  4626. }
  4627. return block.set('characterList', chars);
  4628. });
  4629. return contentState.merge({
  4630. blockMap: blockMap.merge(newBlocks),
  4631. selectionBefore: selectionState,
  4632. selectionAfter: selectionState
  4633. });
  4634. }
  4635. var ContentStateInlineStyle_1 = ContentStateInlineStyle;
  4636. function applyEntityToContentBlock(contentBlock, start, end, entityKey) {
  4637. var characterList = contentBlock.getCharacterList();
  4638. while (start < end) {
  4639. characterList = characterList.set(start, CharacterMetadata_1.applyEntity(characterList.get(start), entityKey));
  4640. start++;
  4641. }
  4642. return contentBlock.set('characterList', characterList);
  4643. }
  4644. var applyEntityToContentBlock_1 = applyEntityToContentBlock;
  4645. function applyEntityToContentState(contentState, selectionState, entityKey) {
  4646. var blockMap = contentState.getBlockMap();
  4647. var startKey = selectionState.getStartKey();
  4648. var startOffset = selectionState.getStartOffset();
  4649. var endKey = selectionState.getEndKey();
  4650. var endOffset = selectionState.getEndOffset();
  4651. var newBlocks = blockMap.skipUntil(function (_, k) {
  4652. return k === startKey;
  4653. }).takeUntil(function (_, k) {
  4654. return k === endKey;
  4655. }).toOrderedMap().merge(immutable.OrderedMap([[endKey, blockMap.get(endKey)]])).map(function (block, blockKey) {
  4656. var sliceStart = blockKey === startKey ? startOffset : 0;
  4657. var sliceEnd = blockKey === endKey ? endOffset : block.getLength();
  4658. return applyEntityToContentBlock_1(block, sliceStart, sliceEnd, entityKey);
  4659. });
  4660. return contentState.merge({
  4661. blockMap: blockMap.merge(newBlocks),
  4662. selectionBefore: selectionState,
  4663. selectionAfter: selectionState
  4664. });
  4665. }
  4666. var applyEntityToContentState_1 = applyEntityToContentState;
  4667. /**
  4668. * Copyright (c) 2013-present, Facebook, Inc.
  4669. * All rights reserved.
  4670. *
  4671. * This source code is licensed under the BSD-style license found in the
  4672. * LICENSE file in the root directory of this source tree. An additional grant
  4673. * of patent rights can be found in the PATENTS file in the same directory.
  4674. *
  4675. * @providesModule DraftEntitySegments
  4676. * @format
  4677. *
  4678. */
  4679. /**
  4680. * Identify the range to delete from a segmented entity.
  4681. *
  4682. * Rules:
  4683. *
  4684. * Example: 'John F. Kennedy'
  4685. *
  4686. * - Deletion from within any non-whitespace (i.e. ['John', 'F.', 'Kennedy'])
  4687. * will return the range of that text.
  4688. *
  4689. * 'John F. Kennedy' -> 'John F.'
  4690. * ^
  4691. *
  4692. * - Forward deletion of whitespace will remove the following section:
  4693. *
  4694. * 'John F. Kennedy' -> 'John Kennedy'
  4695. * ^
  4696. *
  4697. * - Backward deletion of whitespace will remove the previous section:
  4698. *
  4699. * 'John F. Kennedy' -> 'F. Kennedy'
  4700. * ^
  4701. */
  4702. var DraftEntitySegments = {
  4703. getRemovalRange: function getRemovalRange(selectionStart, selectionEnd, text, entityStart, direction) {
  4704. var segments = text.split(' ');
  4705. segments = segments.map(function ( /*string*/segment, /*number*/ii) {
  4706. if (direction === 'forward') {
  4707. if (ii > 0) {
  4708. return ' ' + segment;
  4709. }
  4710. } else if (ii < segments.length - 1) {
  4711. return segment + ' ';
  4712. }
  4713. return segment;
  4714. });
  4715. var segmentStart = entityStart;
  4716. var segmentEnd;
  4717. var segment;
  4718. var removalStart = null;
  4719. var removalEnd = null;
  4720. for (var jj = 0; jj < segments.length; jj++) {
  4721. segment = segments[jj];
  4722. segmentEnd = segmentStart + segment.length;
  4723. // Our selection overlaps this segment.
  4724. if (selectionStart < segmentEnd && segmentStart < selectionEnd) {
  4725. if (removalStart !== null) {
  4726. removalEnd = segmentEnd;
  4727. } else {
  4728. removalStart = segmentStart;
  4729. removalEnd = segmentEnd;
  4730. }
  4731. } else if (removalStart !== null) {
  4732. break;
  4733. }
  4734. segmentStart = segmentEnd;
  4735. }
  4736. var entityEnd = entityStart + text.length;
  4737. var atStart = removalStart === entityStart;
  4738. var atEnd = removalEnd === entityEnd;
  4739. if (!atStart && atEnd || atStart && !atEnd) {
  4740. if (direction === 'forward') {
  4741. if (removalEnd !== entityEnd) {
  4742. removalEnd++;
  4743. }
  4744. } else if (removalStart !== entityStart) {
  4745. removalStart--;
  4746. }
  4747. }
  4748. return {
  4749. start: removalStart,
  4750. end: removalEnd
  4751. };
  4752. }
  4753. };
  4754. var DraftEntitySegments_1 = DraftEntitySegments;
  4755. /**
  4756. * Copyright (c) 2013-present, Facebook, Inc.
  4757. *
  4758. * This source code is licensed under the MIT license found in the
  4759. * LICENSE file in the root directory of this source tree.
  4760. *
  4761. */
  4762. /**
  4763. * Use invariant() to assert state which your program assumes to be true.
  4764. *
  4765. * Provide sprintf-style format (only %s is supported) and arguments
  4766. * to provide information about what broke and what you were
  4767. * expecting.
  4768. *
  4769. * The invariant message will be stripped in production, but the invariant
  4770. * will remain to ensure logic does not differ in production.
  4771. */
  4772. var validateFormat = function validateFormat(format) {};
  4773. if (process.env.NODE_ENV !== 'production') {
  4774. validateFormat = function validateFormat(format) {
  4775. if (format === undefined) {
  4776. throw new Error('invariant requires an error message argument');
  4777. }
  4778. };
  4779. }
  4780. function invariant(condition, format, a, b, c, d, e, f) {
  4781. validateFormat(format);
  4782. if (!condition) {
  4783. var error;
  4784. if (format === undefined) {
  4785. error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
  4786. } else {
  4787. var args = [a, b, c, d, e, f];
  4788. var argIndex = 0;
  4789. error = new Error(format.replace(/%s/g, function () {
  4790. return args[argIndex++];
  4791. }));
  4792. error.name = 'Invariant Violation';
  4793. }
  4794. error.framesToPop = 1; // we don't care about invariant's own frame
  4795. throw error;
  4796. }
  4797. }
  4798. var invariant_1 = invariant;
  4799. /**
  4800. * Obtain the start and end positions of the range that has the
  4801. * specified entity applied to it.
  4802. *
  4803. * Entity keys are applied only to contiguous stretches of text, so this
  4804. * method searches for the first instance of the entity key and returns
  4805. * the subsequent range.
  4806. */
  4807. function getRangesForDraftEntity(block, key) {
  4808. var ranges = [];
  4809. block.findEntityRanges(function (c) {
  4810. return c.getEntity() === key;
  4811. }, function (start, end) {
  4812. ranges.push({ start: start, end: end });
  4813. });
  4814. !!!ranges.length ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Entity key not found in this range.') : invariant_1(false) : void 0;
  4815. return ranges;
  4816. }
  4817. var getRangesForDraftEntity_1 = getRangesForDraftEntity;
  4818. /**
  4819. * Given a SelectionState and a removal direction, determine the entire range
  4820. * that should be removed from a ContentState. This is based on any entities
  4821. * within the target, with their `mutability` values taken into account.
  4822. *
  4823. * For instance, if we are attempting to remove part of an "immutable" entity
  4824. * range, the entire entity must be removed. The returned `SelectionState`
  4825. * will be adjusted accordingly.
  4826. */
  4827. function getCharacterRemovalRange(entityMap, startBlock, endBlock, selectionState, direction) {
  4828. var start = selectionState.getStartOffset();
  4829. var end = selectionState.getEndOffset();
  4830. var startEntityKey = startBlock.getEntityAt(start);
  4831. var endEntityKey = endBlock.getEntityAt(end - 1);
  4832. if (!startEntityKey && !endEntityKey) {
  4833. return selectionState;
  4834. }
  4835. var newSelectionState = selectionState;
  4836. if (startEntityKey && startEntityKey === endEntityKey) {
  4837. newSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, true, true);
  4838. } else if (startEntityKey && endEntityKey) {
  4839. var startSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, false, true);
  4840. var endSelectionState = getEntityRemovalRange(entityMap, endBlock, newSelectionState, direction, endEntityKey, false, false);
  4841. newSelectionState = newSelectionState.merge({
  4842. anchorOffset: startSelectionState.getAnchorOffset(),
  4843. focusOffset: endSelectionState.getFocusOffset(),
  4844. isBackward: false
  4845. });
  4846. } else if (startEntityKey) {
  4847. var _startSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, false, true);
  4848. newSelectionState = newSelectionState.merge({
  4849. anchorOffset: _startSelectionState.getStartOffset(),
  4850. isBackward: false
  4851. });
  4852. } else if (endEntityKey) {
  4853. var _endSelectionState = getEntityRemovalRange(entityMap, endBlock, newSelectionState, direction, endEntityKey, false, false);
  4854. newSelectionState = newSelectionState.merge({
  4855. focusOffset: _endSelectionState.getEndOffset(),
  4856. isBackward: false
  4857. });
  4858. }
  4859. return newSelectionState;
  4860. }
  4861. function getEntityRemovalRange(entityMap, block, selectionState, direction, entityKey, isEntireSelectionWithinEntity, isEntityAtStart) {
  4862. var start = selectionState.getStartOffset();
  4863. var end = selectionState.getEndOffset();
  4864. var entity = entityMap.__get(entityKey);
  4865. var mutability = entity.getMutability();
  4866. var sideToConsider = isEntityAtStart ? start : end;
  4867. // `MUTABLE` entities can just have the specified range of text removed
  4868. // directly. No adjustments are needed.
  4869. if (mutability === 'MUTABLE') {
  4870. return selectionState;
  4871. }
  4872. // Find the entity range that overlaps with our removal range.
  4873. var entityRanges = getRangesForDraftEntity_1(block, entityKey).filter(function (range) {
  4874. return sideToConsider <= range.end && sideToConsider >= range.start;
  4875. });
  4876. !(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;
  4877. var entityRange = entityRanges[0];
  4878. // For `IMMUTABLE` entity types, we will remove the entire entity range.
  4879. if (mutability === 'IMMUTABLE') {
  4880. return selectionState.merge({
  4881. anchorOffset: entityRange.start,
  4882. focusOffset: entityRange.end,
  4883. isBackward: false
  4884. });
  4885. }
  4886. // For `SEGMENTED` entity types, determine the appropriate segment to
  4887. // remove.
  4888. if (!isEntireSelectionWithinEntity) {
  4889. if (isEntityAtStart) {
  4890. end = entityRange.end;
  4891. } else {
  4892. start = entityRange.start;
  4893. }
  4894. }
  4895. var removalRange = DraftEntitySegments_1.getRemovalRange(start, end, block.getText().slice(entityRange.start, entityRange.end), entityRange.start, direction);
  4896. return selectionState.merge({
  4897. anchorOffset: removalRange.start,
  4898. focusOffset: removalRange.end,
  4899. isBackward: false
  4900. });
  4901. }
  4902. var getCharacterRemovalRange_1 = getCharacterRemovalRange;
  4903. /**
  4904. * Copyright (c) 2013-present, Facebook, Inc.
  4905. * All rights reserved.
  4906. *
  4907. * This source code is licensed under the BSD-style license found in the
  4908. * LICENSE file in the root directory of this source tree. An additional grant
  4909. * of patent rights can be found in the PATENTS file in the same directory.
  4910. *
  4911. * @providesModule generateRandomKey
  4912. * @format
  4913. *
  4914. */
  4915. var seenKeys = {};
  4916. var MULTIPLIER = Math.pow(2, 24);
  4917. function generateRandomKey() {
  4918. var key = void 0;
  4919. while (key === undefined || seenKeys.hasOwnProperty(key) || !isNaN(+key)) {
  4920. key = Math.floor(Math.random() * MULTIPLIER).toString(32);
  4921. }
  4922. seenKeys[key] = true;
  4923. return key;
  4924. }
  4925. var generateRandomKey_1 = generateRandomKey;
  4926. var OrderedMap$1 = immutable.OrderedMap;
  4927. var randomizeContentBlockNodeKeys = function randomizeContentBlockNodeKeys(blockMap) {
  4928. var newKeysRef = {};
  4929. // we keep track of root blocks in order to update subsequent sibling links
  4930. var lastRootBlock = void 0;
  4931. return OrderedMap$1(blockMap.withMutations(function (blockMapState) {
  4932. blockMapState.forEach(function (block, index) {
  4933. var oldKey = block.getKey();
  4934. var nextKey = block.getNextSiblingKey();
  4935. var prevKey = block.getPrevSiblingKey();
  4936. var childrenKeys = block.getChildKeys();
  4937. var parentKey = block.getParentKey();
  4938. // new key that we will use to build linking
  4939. var key = generateRandomKey_1();
  4940. // we will add it here to re-use it later
  4941. newKeysRef[oldKey] = key;
  4942. if (nextKey) {
  4943. var nextBlock = blockMapState.get(nextKey);
  4944. if (nextBlock) {
  4945. blockMapState.setIn([nextKey, 'prevSibling'], key);
  4946. } else {
  4947. // this can happen when generating random keys for fragments
  4948. blockMapState.setIn([oldKey, 'nextSibling'], null);
  4949. }
  4950. }
  4951. if (prevKey) {
  4952. var prevBlock = blockMapState.get(prevKey);
  4953. if (prevBlock) {
  4954. blockMapState.setIn([prevKey, 'nextSibling'], key);
  4955. } else {
  4956. // this can happen when generating random keys for fragments
  4957. blockMapState.setIn([oldKey, 'prevSibling'], null);
  4958. }
  4959. }
  4960. if (parentKey && blockMapState.get(parentKey)) {
  4961. var parentBlock = blockMapState.get(parentKey);
  4962. var parentChildrenList = parentBlock.getChildKeys();
  4963. blockMapState.setIn([parentKey, 'children'], parentChildrenList.set(parentChildrenList.indexOf(block.getKey()), key));
  4964. } else {
  4965. // blocks will then be treated as root block nodes
  4966. blockMapState.setIn([oldKey, 'parent'], null);
  4967. if (lastRootBlock) {
  4968. blockMapState.setIn([lastRootBlock.getKey(), 'nextSibling'], key);
  4969. blockMapState.setIn([oldKey, 'prevSibling'], newKeysRef[lastRootBlock.getKey()]);
  4970. }
  4971. lastRootBlock = blockMapState.get(oldKey);
  4972. }
  4973. childrenKeys.forEach(function (childKey) {
  4974. var childBlock = blockMapState.get(childKey);
  4975. if (childBlock) {
  4976. blockMapState.setIn([childKey, 'parent'], key);
  4977. } else {
  4978. blockMapState.setIn([oldKey, 'children'], block.getChildKeys().filter(function (child) {
  4979. return child !== childKey;
  4980. }));
  4981. }
  4982. });
  4983. });
  4984. }).toArray().map(function (block) {
  4985. return [newKeysRef[block.getKey()], block.set('key', newKeysRef[block.getKey()])];
  4986. }));
  4987. };
  4988. var randomizeContentBlockKeys = function randomizeContentBlockKeys(blockMap) {
  4989. return OrderedMap$1(blockMap.toArray().map(function (block) {
  4990. var key = generateRandomKey_1();
  4991. return [key, block.set('key', key)];
  4992. }));
  4993. };
  4994. var randomizeBlockMapKeys = function randomizeBlockMapKeys(blockMap) {
  4995. var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode_1;
  4996. if (!isTreeBasedBlockMap) {
  4997. return randomizeContentBlockKeys(blockMap);
  4998. }
  4999. return randomizeContentBlockNodeKeys(blockMap);
  5000. };
  5001. var randomizeBlockMapKeys_1 = randomizeBlockMapKeys;
  5002. function removeEntitiesAtEdges(contentState, selectionState) {
  5003. var blockMap = contentState.getBlockMap();
  5004. var entityMap = contentState.getEntityMap();
  5005. var updatedBlocks = {};
  5006. var startKey = selectionState.getStartKey();
  5007. var startOffset = selectionState.getStartOffset();
  5008. var startBlock = blockMap.get(startKey);
  5009. var updatedStart = removeForBlock(entityMap, startBlock, startOffset);
  5010. if (updatedStart !== startBlock) {
  5011. updatedBlocks[startKey] = updatedStart;
  5012. }
  5013. var endKey = selectionState.getEndKey();
  5014. var endOffset = selectionState.getEndOffset();
  5015. var endBlock = blockMap.get(endKey);
  5016. if (startKey === endKey) {
  5017. endBlock = updatedStart;
  5018. }
  5019. var updatedEnd = removeForBlock(entityMap, endBlock, endOffset);
  5020. if (updatedEnd !== endBlock) {
  5021. updatedBlocks[endKey] = updatedEnd;
  5022. }
  5023. if (!Object.keys(updatedBlocks).length) {
  5024. return contentState.set('selectionAfter', selectionState);
  5025. }
  5026. return contentState.merge({
  5027. blockMap: blockMap.merge(updatedBlocks),
  5028. selectionAfter: selectionState
  5029. });
  5030. }
  5031. function getRemovalRange(characters, key, offset) {
  5032. var removalRange;
  5033. findRangesImmutable_1(characters, function (a, b) {
  5034. return a.getEntity() === b.getEntity();
  5035. }, function (element) {
  5036. return element.getEntity() === key;
  5037. }, function (start, end) {
  5038. if (start <= offset && end >= offset) {
  5039. removalRange = { start: start, end: end };
  5040. }
  5041. });
  5042. !(typeof removalRange === 'object') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Removal range must exist within character list.') : invariant_1(false) : void 0;
  5043. return removalRange;
  5044. }
  5045. function removeForBlock(entityMap, block, offset) {
  5046. var chars = block.getCharacterList();
  5047. var charBefore = offset > 0 ? chars.get(offset - 1) : undefined;
  5048. var charAfter = offset < chars.count() ? chars.get(offset) : undefined;
  5049. var entityBeforeCursor = charBefore ? charBefore.getEntity() : undefined;
  5050. var entityAfterCursor = charAfter ? charAfter.getEntity() : undefined;
  5051. if (entityAfterCursor && entityAfterCursor === entityBeforeCursor) {
  5052. var entity = entityMap.__get(entityAfterCursor);
  5053. if (entity.getMutability() !== 'MUTABLE') {
  5054. var _getRemovalRange = getRemovalRange(chars, entityAfterCursor, offset),
  5055. start = _getRemovalRange.start,
  5056. end = _getRemovalRange.end;
  5057. var current;
  5058. while (start < end) {
  5059. current = chars.get(start);
  5060. chars = chars.set(start, CharacterMetadata_1.applyEntity(current, null));
  5061. start++;
  5062. }
  5063. return block.set('characterList', chars);
  5064. }
  5065. }
  5066. return block;
  5067. }
  5068. var removeEntitiesAtEdges_1 = removeEntitiesAtEdges;
  5069. var getContentStateFragment = function getContentStateFragment(contentState, selectionState) {
  5070. var startKey = selectionState.getStartKey();
  5071. var startOffset = selectionState.getStartOffset();
  5072. var endKey = selectionState.getEndKey();
  5073. var endOffset = selectionState.getEndOffset();
  5074. // Edge entities should be stripped to ensure that we don't preserve
  5075. // invalid partial entities when the fragment is reused. We do, however,
  5076. // preserve entities that are entirely within the selection range.
  5077. var contentWithoutEdgeEntities = removeEntitiesAtEdges_1(contentState, selectionState);
  5078. var blockMap = contentWithoutEdgeEntities.getBlockMap();
  5079. var blockKeys = blockMap.keySeq();
  5080. var startIndex = blockKeys.indexOf(startKey);
  5081. var endIndex = blockKeys.indexOf(endKey) + 1;
  5082. return randomizeBlockMapKeys_1(blockMap.slice(startIndex, endIndex).map(function (block, blockKey) {
  5083. var text = block.getText();
  5084. var chars = block.getCharacterList();
  5085. if (startKey === endKey) {
  5086. return block.merge({
  5087. text: text.slice(startOffset, endOffset),
  5088. characterList: chars.slice(startOffset, endOffset)
  5089. });
  5090. }
  5091. if (blockKey === startKey) {
  5092. return block.merge({
  5093. text: text.slice(startOffset),
  5094. characterList: chars.slice(startOffset)
  5095. });
  5096. }
  5097. if (blockKey === endKey) {
  5098. return block.merge({
  5099. text: text.slice(0, endOffset),
  5100. characterList: chars.slice(0, endOffset)
  5101. });
  5102. }
  5103. return block;
  5104. }));
  5105. };
  5106. var getContentStateFragment_1 = getContentStateFragment;
  5107. /**
  5108. * Copyright (c) 2013-present, Facebook, Inc.
  5109. * All rights reserved.
  5110. *
  5111. * This source code is licensed under the BSD-style license found in the
  5112. * LICENSE file in the root directory of this source tree. An additional grant
  5113. * of patent rights can be found in the PATENTS file in the same directory.
  5114. *
  5115. * @providesModule insertIntoList
  5116. * @format
  5117. *
  5118. */
  5119. /**
  5120. * Maintain persistence for target list when appending and prepending.
  5121. */
  5122. function insertIntoList(targetList, toInsert, offset) {
  5123. if (offset === targetList.count()) {
  5124. toInsert.forEach(function (c) {
  5125. targetList = targetList.push(c);
  5126. });
  5127. } else if (offset === 0) {
  5128. toInsert.reverse().forEach(function (c) {
  5129. targetList = targetList.unshift(c);
  5130. });
  5131. } else {
  5132. var head = targetList.slice(0, offset);
  5133. var tail = targetList.slice(offset);
  5134. targetList = head.concat(toInsert, tail).toList();
  5135. }
  5136. return targetList;
  5137. }
  5138. var insertIntoList_1 = insertIntoList;
  5139. var List$2 = immutable.List;
  5140. var updateExistingBlock = function updateExistingBlock(contentState, selectionState, blockMap, fragmentBlock, targetKey, targetOffset) {
  5141. var targetBlock = blockMap.get(targetKey);
  5142. var text = targetBlock.getText();
  5143. var chars = targetBlock.getCharacterList();
  5144. var finalKey = targetKey;
  5145. var finalOffset = targetOffset + fragmentBlock.getText().length;
  5146. var newBlock = targetBlock.merge({
  5147. text: text.slice(0, targetOffset) + fragmentBlock.getText() + text.slice(targetOffset),
  5148. characterList: insertIntoList_1(chars, fragmentBlock.getCharacterList(), targetOffset),
  5149. data: fragmentBlock.getData()
  5150. });
  5151. return contentState.merge({
  5152. blockMap: blockMap.set(targetKey, newBlock),
  5153. selectionBefore: selectionState,
  5154. selectionAfter: selectionState.merge({
  5155. anchorKey: finalKey,
  5156. anchorOffset: finalOffset,
  5157. focusKey: finalKey,
  5158. focusOffset: finalOffset,
  5159. isBackward: false
  5160. })
  5161. });
  5162. };
  5163. /**
  5164. * Appends text/characterList from the fragment first block to
  5165. * target block.
  5166. */
  5167. var updateHead = function updateHead(block, targetOffset, fragment) {
  5168. var text = block.getText();
  5169. var chars = block.getCharacterList();
  5170. // Modify head portion of block.
  5171. var headText = text.slice(0, targetOffset);
  5172. var headCharacters = chars.slice(0, targetOffset);
  5173. var appendToHead = fragment.first();
  5174. return block.merge({
  5175. text: headText + appendToHead.getText(),
  5176. characterList: headCharacters.concat(appendToHead.getCharacterList()),
  5177. type: headText ? block.getType() : appendToHead.getType(),
  5178. data: appendToHead.getData()
  5179. });
  5180. };
  5181. /**
  5182. * Appends offset text/characterList from the target block to the last
  5183. * fragment block.
  5184. */
  5185. var updateTail = function updateTail(block, targetOffset, fragment) {
  5186. // Modify tail portion of block.
  5187. var text = block.getText();
  5188. var chars = block.getCharacterList();
  5189. // Modify head portion of block.
  5190. var blockSize = text.length;
  5191. var tailText = text.slice(targetOffset, blockSize);
  5192. var tailCharacters = chars.slice(targetOffset, blockSize);
  5193. var prependToTail = fragment.last();
  5194. return prependToTail.merge({
  5195. text: prependToTail.getText() + tailText,
  5196. characterList: prependToTail.getCharacterList().concat(tailCharacters),
  5197. data: prependToTail.getData()
  5198. });
  5199. };
  5200. var getRootBlocks = function getRootBlocks(block, blockMap) {
  5201. var headKey = block.getKey();
  5202. var rootBlock = block;
  5203. var rootBlocks = [];
  5204. // sometimes the fragment head block will not be part of the blockMap itself this can happen when
  5205. // the fragment head is used to update the target block, however when this does not happen we need
  5206. // to make sure that we include it on the rootBlocks since the first block of a fragment is always a
  5207. // fragment root block
  5208. if (blockMap.get(headKey)) {
  5209. rootBlocks.push(headKey);
  5210. }
  5211. while (rootBlock && rootBlock.getNextSiblingKey()) {
  5212. var lastSiblingKey = rootBlock.getNextSiblingKey();
  5213. if (!lastSiblingKey) {
  5214. break;
  5215. }
  5216. rootBlocks.push(lastSiblingKey);
  5217. rootBlock = blockMap.get(lastSiblingKey);
  5218. }
  5219. return rootBlocks;
  5220. };
  5221. var updateBlockMapLinks = function updateBlockMapLinks(blockMap, originalBlockMap, targetBlock, fragmentHeadBlock) {
  5222. return blockMap.withMutations(function (blockMapState) {
  5223. var targetKey = targetBlock.getKey();
  5224. var headKey = fragmentHeadBlock.getKey();
  5225. var targetNextKey = targetBlock.getNextSiblingKey();
  5226. var targetParentKey = targetBlock.getParentKey();
  5227. var fragmentRootBlocks = getRootBlocks(fragmentHeadBlock, blockMap);
  5228. var lastRootFragmentBlockKey = fragmentRootBlocks[fragmentRootBlocks.length - 1];
  5229. if (blockMapState.get(headKey)) {
  5230. // update the fragment head when it is part of the blockMap otherwise
  5231. blockMapState.setIn([targetKey, 'nextSibling'], headKey);
  5232. blockMapState.setIn([headKey, 'prevSibling'], targetKey);
  5233. } else {
  5234. // update the target block that had the fragment head contents merged into it
  5235. blockMapState.setIn([targetKey, 'nextSibling'], fragmentHeadBlock.getNextSiblingKey());
  5236. blockMapState.setIn([fragmentHeadBlock.getNextSiblingKey(), 'prevSibling'], targetKey);
  5237. }
  5238. // update the last root block fragment
  5239. blockMapState.setIn([lastRootFragmentBlockKey, 'nextSibling'], targetNextKey);
  5240. // update the original target next block
  5241. if (targetNextKey) {
  5242. blockMapState.setIn([targetNextKey, 'prevSibling'], lastRootFragmentBlockKey);
  5243. }
  5244. // update fragment parent links
  5245. fragmentRootBlocks.forEach(function (blockKey) {
  5246. return blockMapState.setIn([blockKey, 'parent'], targetParentKey);
  5247. });
  5248. // update targetBlock parent child links
  5249. if (targetParentKey) {
  5250. var targetParent = blockMap.get(targetParentKey);
  5251. var originalTargetParentChildKeys = targetParent.getChildKeys();
  5252. var targetBlockIndex = originalTargetParentChildKeys.indexOf(targetKey);
  5253. var insertionIndex = targetBlockIndex + 1;
  5254. var newChildrenKeysArray = originalTargetParentChildKeys.toArray();
  5255. // insert fragment children
  5256. newChildrenKeysArray.splice.apply(newChildrenKeysArray, [insertionIndex, 0].concat(fragmentRootBlocks));
  5257. blockMapState.setIn([targetParentKey, 'children'], List$2(newChildrenKeysArray));
  5258. }
  5259. });
  5260. };
  5261. var insertFragment = function insertFragment(contentState, selectionState, blockMap, fragment, targetKey, targetOffset) {
  5262. var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode_1;
  5263. var newBlockArr = [];
  5264. var fragmentSize = fragment.size;
  5265. var target = blockMap.get(targetKey);
  5266. var head = fragment.first();
  5267. var tail = fragment.last();
  5268. var finalOffset = tail.getLength();
  5269. var finalKey = tail.getKey();
  5270. var shouldNotUpdateFromFragmentBlock = isTreeBasedBlockMap && (!target.getChildKeys().isEmpty() || !head.getChildKeys().isEmpty());
  5271. blockMap.forEach(function (block, blockKey) {
  5272. if (blockKey !== targetKey) {
  5273. newBlockArr.push(block);
  5274. return;
  5275. }
  5276. if (shouldNotUpdateFromFragmentBlock) {
  5277. newBlockArr.push(block);
  5278. } else {
  5279. newBlockArr.push(updateHead(block, targetOffset, fragment));
  5280. }
  5281. // Insert fragment blocks after the head and before the tail.
  5282. fragment
  5283. // when we are updating the target block with the head fragment block we skip the first fragment
  5284. // head since its contents have already been merged with the target block otherwise we include
  5285. // the whole fragment
  5286. .slice(shouldNotUpdateFromFragmentBlock ? 0 : 1, fragmentSize - 1).forEach(function (fragmentBlock) {
  5287. return newBlockArr.push(fragmentBlock);
  5288. });
  5289. // update tail
  5290. newBlockArr.push(updateTail(block, targetOffset, fragment));
  5291. });
  5292. var updatedBlockMap = BlockMapBuilder_1.createFromArray(newBlockArr);
  5293. if (isTreeBasedBlockMap) {
  5294. updatedBlockMap = updateBlockMapLinks(updatedBlockMap, blockMap, target, head);
  5295. }
  5296. return contentState.merge({
  5297. blockMap: updatedBlockMap,
  5298. selectionBefore: selectionState,
  5299. selectionAfter: selectionState.merge({
  5300. anchorKey: finalKey,
  5301. anchorOffset: finalOffset,
  5302. focusKey: finalKey,
  5303. focusOffset: finalOffset,
  5304. isBackward: false
  5305. })
  5306. });
  5307. };
  5308. var insertFragmentIntoContentState = function insertFragmentIntoContentState(contentState, selectionState, fragmentBlockMap) {
  5309. !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;
  5310. var blockMap = contentState.getBlockMap();
  5311. var fragment = randomizeBlockMapKeys_1(fragmentBlockMap);
  5312. var targetKey = selectionState.getStartKey();
  5313. var targetOffset = selectionState.getStartOffset();
  5314. var targetBlock = blockMap.get(targetKey);
  5315. if (targetBlock instanceof ContentBlockNode_1) {
  5316. !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;
  5317. }
  5318. // When we insert a fragment with a single block we simply update the target block
  5319. // with the contents of the inserted fragment block
  5320. if (fragment.size === 1) {
  5321. return updateExistingBlock(contentState, selectionState, blockMap, fragment.first(), targetKey, targetOffset);
  5322. }
  5323. return insertFragment(contentState, selectionState, blockMap, fragment, targetKey, targetOffset);
  5324. };
  5325. var insertFragmentIntoContentState_1 = insertFragmentIntoContentState;
  5326. var Repeat$2 = immutable.Repeat;
  5327. function insertTextIntoContentState(contentState, selectionState, text, characterMetadata) {
  5328. !selectionState.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`insertText` should only be called with a collapsed range.') : invariant_1(false) : void 0;
  5329. var len = text.length;
  5330. if (!len) {
  5331. return contentState;
  5332. }
  5333. var blockMap = contentState.getBlockMap();
  5334. var key = selectionState.getStartKey();
  5335. var offset = selectionState.getStartOffset();
  5336. var block = blockMap.get(key);
  5337. var blockText = block.getText();
  5338. var newBlock = block.merge({
  5339. text: blockText.slice(0, offset) + text + blockText.slice(offset, block.getLength()),
  5340. characterList: insertIntoList_1(block.getCharacterList(), Repeat$2(characterMetadata, len).toList(), offset)
  5341. });
  5342. var newOffset = offset + len;
  5343. return contentState.merge({
  5344. blockMap: blockMap.set(key, newBlock),
  5345. selectionAfter: selectionState.merge({
  5346. anchorOffset: newOffset,
  5347. focusOffset: newOffset
  5348. })
  5349. });
  5350. }
  5351. var insertTextIntoContentState_1 = insertTextIntoContentState;
  5352. var Map$5 = immutable.Map;
  5353. function modifyBlockForContentState(contentState, selectionState, operation) {
  5354. var startKey = selectionState.getStartKey();
  5355. var endKey = selectionState.getEndKey();
  5356. var blockMap = contentState.getBlockMap();
  5357. var newBlocks = blockMap.toSeq().skipUntil(function (_, k) {
  5358. return k === startKey;
  5359. }).takeUntil(function (_, k) {
  5360. return k === endKey;
  5361. }).concat(Map$5([[endKey, blockMap.get(endKey)]])).map(operation);
  5362. return contentState.merge({
  5363. blockMap: blockMap.merge(newBlocks),
  5364. selectionBefore: selectionState,
  5365. selectionAfter: selectionState
  5366. });
  5367. }
  5368. var modifyBlockForContentState_1 = modifyBlockForContentState;
  5369. /**
  5370. * Copyright (c) 2013-present, Facebook, Inc.
  5371. * All rights reserved.
  5372. *
  5373. * This source code is licensed under the BSD-style license found in the
  5374. * LICENSE file in the root directory of this source tree. An additional grant
  5375. * of patent rights can be found in the PATENTS file in the same directory.
  5376. *
  5377. * @providesModule getNextDelimiterBlockKey
  5378. * @format
  5379. *
  5380. *
  5381. * This is unstable and not part of the public API and should not be used by
  5382. * production systems. This file may be update/removed without notice.
  5383. */
  5384. var getNextDelimiterBlockKey = function getNextDelimiterBlockKey(block, blockMap) {
  5385. var isExperimentalTreeBlock = block instanceof ContentBlockNode_1;
  5386. if (!isExperimentalTreeBlock) {
  5387. return null;
  5388. }
  5389. var nextSiblingKey = block.getNextSiblingKey();
  5390. if (nextSiblingKey) {
  5391. return nextSiblingKey;
  5392. }
  5393. var parent = block.getParentKey();
  5394. if (!parent) {
  5395. return null;
  5396. }
  5397. var nextNonDescendantBlock = blockMap.get(parent);
  5398. while (nextNonDescendantBlock && !nextNonDescendantBlock.getNextSiblingKey()) {
  5399. var parentKey = nextNonDescendantBlock.getParentKey();
  5400. nextNonDescendantBlock = parentKey ? blockMap.get(parentKey) : null;
  5401. }
  5402. if (!nextNonDescendantBlock) {
  5403. return null;
  5404. }
  5405. return nextNonDescendantBlock.getNextSiblingKey();
  5406. };
  5407. var getNextDelimiterBlockKey_1 = getNextDelimiterBlockKey;
  5408. var List$3 = immutable.List,
  5409. Map$6 = immutable.Map;
  5410. var transformBlock = function transformBlock(key, blockMap, func) {
  5411. if (!key) {
  5412. return;
  5413. }
  5414. var block = blockMap.get(key);
  5415. if (!block) {
  5416. return;
  5417. }
  5418. blockMap.set(key, func(block));
  5419. };
  5420. /**
  5421. * Ancestors needs to be preserved when there are non selected
  5422. * children to make sure we do not leave any orphans behind
  5423. */
  5424. var getAncestorsKeys = function getAncestorsKeys(blockKey, blockMap) {
  5425. var parents = [];
  5426. if (!blockKey) {
  5427. return parents;
  5428. }
  5429. var blockNode = blockMap.get(blockKey);
  5430. while (blockNode && blockNode.getParentKey()) {
  5431. var parentKey = blockNode.getParentKey();
  5432. if (parentKey) {
  5433. parents.push(parentKey);
  5434. }
  5435. blockNode = parentKey ? blockMap.get(parentKey) : null;
  5436. }
  5437. return parents;
  5438. };
  5439. /**
  5440. * Get all next delimiter keys until we hit a root delimiter and return
  5441. * an array of key references
  5442. */
  5443. var getNextDelimitersBlockKeys = function getNextDelimitersBlockKeys(block, blockMap) {
  5444. var nextDelimiters = [];
  5445. if (!block) {
  5446. return nextDelimiters;
  5447. }
  5448. var nextDelimiter = getNextDelimiterBlockKey_1(block, blockMap);
  5449. while (nextDelimiter && blockMap.get(nextDelimiter)) {
  5450. var _block = blockMap.get(nextDelimiter);
  5451. nextDelimiters.push(nextDelimiter);
  5452. // we do not need to keep checking all root node siblings, just the first occurance
  5453. nextDelimiter = _block.getParentKey() ? getNextDelimiterBlockKey_1(_block, blockMap) : null;
  5454. }
  5455. return nextDelimiters;
  5456. };
  5457. var getNextValidSibling = function getNextValidSibling(block, blockMap, originalBlockMap) {
  5458. if (!block) {
  5459. return null;
  5460. }
  5461. // note that we need to make sure we refer to the original block since this
  5462. // function is called within a withMutations
  5463. var nextValidSiblingKey = originalBlockMap.get(block.getKey()).getNextSiblingKey();
  5464. while (nextValidSiblingKey && !blockMap.get(nextValidSiblingKey)) {
  5465. nextValidSiblingKey = originalBlockMap.get(nextValidSiblingKey).getNextSiblingKey() || null;
  5466. }
  5467. return nextValidSiblingKey;
  5468. };
  5469. var getPrevValidSibling = function getPrevValidSibling(block, blockMap, originalBlockMap) {
  5470. if (!block) {
  5471. return null;
  5472. }
  5473. // note that we need to make sure we refer to the original block since this
  5474. // function is called within a withMutations
  5475. var prevValidSiblingKey = originalBlockMap.get(block.getKey()).getPrevSiblingKey();
  5476. while (prevValidSiblingKey && !blockMap.get(prevValidSiblingKey)) {
  5477. prevValidSiblingKey = originalBlockMap.get(prevValidSiblingKey).getPrevSiblingKey() || null;
  5478. }
  5479. return prevValidSiblingKey;
  5480. };
  5481. var updateBlockMapLinks$1 = function updateBlockMapLinks(blockMap, startBlock, endBlock, originalBlockMap) {
  5482. return blockMap.withMutations(function (blocks) {
  5483. // update start block if its retained
  5484. transformBlock(startBlock.getKey(), blocks, function (block) {
  5485. return block.merge({
  5486. nextSibling: getNextValidSibling(startBlock, blocks, originalBlockMap),
  5487. prevSibling: getPrevValidSibling(startBlock, blocks, originalBlockMap)
  5488. });
  5489. });
  5490. // update endblock if its retained
  5491. transformBlock(endBlock.getKey(), blocks, function (block) {
  5492. return block.merge({
  5493. nextSibling: getNextValidSibling(endBlock, blocks, originalBlockMap),
  5494. prevSibling: getPrevValidSibling(endBlock, blocks, originalBlockMap)
  5495. });
  5496. });
  5497. // update start block parent ancestors
  5498. getAncestorsKeys(startBlock.getKey(), originalBlockMap).forEach(function (parentKey) {
  5499. return transformBlock(parentKey, blocks, function (block) {
  5500. return block.merge({
  5501. children: block.getChildKeys().filter(function (key) {
  5502. return blocks.get(key);
  5503. }),
  5504. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  5505. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  5506. });
  5507. });
  5508. });
  5509. // update start block next - can only happen if startBlock == endBlock
  5510. transformBlock(startBlock.getNextSiblingKey(), blocks, function (block) {
  5511. return block.merge({
  5512. prevSibling: startBlock.getPrevSiblingKey()
  5513. });
  5514. });
  5515. // update start block prev
  5516. transformBlock(startBlock.getPrevSiblingKey(), blocks, function (block) {
  5517. return block.merge({
  5518. nextSibling: getNextValidSibling(startBlock, blocks, originalBlockMap)
  5519. });
  5520. });
  5521. // update end block next
  5522. transformBlock(endBlock.getNextSiblingKey(), blocks, function (block) {
  5523. return block.merge({
  5524. prevSibling: getPrevValidSibling(endBlock, blocks, originalBlockMap)
  5525. });
  5526. });
  5527. // update end block prev
  5528. transformBlock(endBlock.getPrevSiblingKey(), blocks, function (block) {
  5529. return block.merge({
  5530. nextSibling: endBlock.getNextSiblingKey()
  5531. });
  5532. });
  5533. // update end block parent ancestors
  5534. getAncestorsKeys(endBlock.getKey(), originalBlockMap).forEach(function (parentKey) {
  5535. transformBlock(parentKey, blocks, function (block) {
  5536. return block.merge({
  5537. children: block.getChildKeys().filter(function (key) {
  5538. return blocks.get(key);
  5539. }),
  5540. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  5541. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  5542. });
  5543. });
  5544. });
  5545. // update next delimiters all the way to a root delimiter
  5546. getNextDelimitersBlockKeys(endBlock, originalBlockMap).forEach(function (delimiterKey) {
  5547. return transformBlock(delimiterKey, blocks, function (block) {
  5548. return block.merge({
  5549. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  5550. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  5551. });
  5552. });
  5553. });
  5554. });
  5555. };
  5556. var removeRangeFromContentState = function removeRangeFromContentState(contentState, selectionState) {
  5557. if (selectionState.isCollapsed()) {
  5558. return contentState;
  5559. }
  5560. var blockMap = contentState.getBlockMap();
  5561. var startKey = selectionState.getStartKey();
  5562. var startOffset = selectionState.getStartOffset();
  5563. var endKey = selectionState.getEndKey();
  5564. var endOffset = selectionState.getEndOffset();
  5565. var startBlock = blockMap.get(startKey);
  5566. var endBlock = blockMap.get(endKey);
  5567. // we assume that ContentBlockNode and ContentBlocks are not mixed together
  5568. var isExperimentalTreeBlock = startBlock instanceof ContentBlockNode_1;
  5569. // used to retain blocks that should not be deleted to avoid orphan children
  5570. var parentAncestors = [];
  5571. if (isExperimentalTreeBlock) {
  5572. var endBlockchildrenKeys = endBlock.getChildKeys();
  5573. var endBlockAncestors = getAncestorsKeys(endKey, blockMap);
  5574. // endBlock has unselected sibblings so we can not remove its ancestors parents
  5575. if (endBlock.getNextSiblingKey()) {
  5576. parentAncestors = parentAncestors.concat(endBlockAncestors);
  5577. }
  5578. // endBlock has children so can not remove this block or any of its ancestors
  5579. if (!endBlockchildrenKeys.isEmpty()) {
  5580. parentAncestors = parentAncestors.concat(endBlockAncestors.concat([endKey]));
  5581. }
  5582. // we need to retain all ancestors of the next delimiter block
  5583. parentAncestors = parentAncestors.concat(getAncestorsKeys(getNextDelimiterBlockKey_1(endBlock, blockMap), blockMap));
  5584. }
  5585. var characterList = void 0;
  5586. if (startBlock === endBlock) {
  5587. characterList = removeFromList(startBlock.getCharacterList(), startOffset, endOffset);
  5588. } else {
  5589. characterList = startBlock.getCharacterList().slice(0, startOffset).concat(endBlock.getCharacterList().slice(endOffset));
  5590. }
  5591. var modifiedStart = startBlock.merge({
  5592. text: startBlock.getText().slice(0, startOffset) + endBlock.getText().slice(endOffset),
  5593. characterList: characterList
  5594. });
  5595. var newBlocks = blockMap.toSeq().skipUntil(function (_, k) {
  5596. return k === startKey;
  5597. }).takeUntil(function (_, k) {
  5598. return k === endKey;
  5599. }).filter(function (_, k) {
  5600. return parentAncestors.indexOf(k) === -1;
  5601. }).concat(Map$6([[endKey, null]])).map(function (_, k) {
  5602. return k === startKey ? modifiedStart : null;
  5603. });
  5604. var updatedBlockMap = blockMap.merge(newBlocks).filter(function (block) {
  5605. return !!block;
  5606. });
  5607. if (isExperimentalTreeBlock) {
  5608. updatedBlockMap = updateBlockMapLinks$1(updatedBlockMap, startBlock, endBlock, blockMap);
  5609. }
  5610. return contentState.merge({
  5611. blockMap: updatedBlockMap,
  5612. selectionBefore: selectionState,
  5613. selectionAfter: selectionState.merge({
  5614. anchorKey: startKey,
  5615. anchorOffset: startOffset,
  5616. focusKey: startKey,
  5617. focusOffset: startOffset,
  5618. isBackward: false
  5619. })
  5620. });
  5621. };
  5622. /**
  5623. * Maintain persistence for target list when removing characters on the
  5624. * head and tail of the character list.
  5625. */
  5626. var removeFromList = function removeFromList(targetList, startOffset, endOffset) {
  5627. if (startOffset === 0) {
  5628. while (startOffset < endOffset) {
  5629. targetList = targetList.shift();
  5630. startOffset++;
  5631. }
  5632. } else if (endOffset === targetList.count()) {
  5633. while (endOffset > startOffset) {
  5634. targetList = targetList.pop();
  5635. endOffset--;
  5636. }
  5637. } else {
  5638. var head = targetList.slice(0, startOffset);
  5639. var tail = targetList.slice(endOffset);
  5640. targetList = head.concat(tail).toList();
  5641. }
  5642. return targetList;
  5643. };
  5644. var removeRangeFromContentState_1 = removeRangeFromContentState;
  5645. var List$4 = immutable.List,
  5646. Map$7 = immutable.Map;
  5647. var transformBlock$1 = function transformBlock(key, blockMap, func) {
  5648. if (!key) {
  5649. return;
  5650. }
  5651. var block = blockMap.get(key);
  5652. if (!block) {
  5653. return;
  5654. }
  5655. blockMap.set(key, func(block));
  5656. };
  5657. var updateBlockMapLinks$2 = function updateBlockMapLinks(blockMap, originalBlock, belowBlock) {
  5658. return blockMap.withMutations(function (blocks) {
  5659. var originalBlockKey = originalBlock.getKey();
  5660. var belowBlockKey = belowBlock.getKey();
  5661. // update block parent
  5662. transformBlock$1(originalBlock.getParentKey(), blocks, function (block) {
  5663. var parentChildrenList = block.getChildKeys();
  5664. var insertionIndex = parentChildrenList.indexOf(originalBlockKey) + 1;
  5665. var newChildrenArray = parentChildrenList.toArray();
  5666. newChildrenArray.splice(insertionIndex, 0, belowBlockKey);
  5667. return block.merge({
  5668. children: List$4(newChildrenArray)
  5669. });
  5670. });
  5671. // update original next block
  5672. transformBlock$1(originalBlock.getNextSiblingKey(), blocks, function (block) {
  5673. return block.merge({
  5674. prevSibling: belowBlockKey
  5675. });
  5676. });
  5677. // update original block
  5678. transformBlock$1(originalBlockKey, blocks, function (block) {
  5679. return block.merge({
  5680. nextSibling: belowBlockKey
  5681. });
  5682. });
  5683. // update below block
  5684. transformBlock$1(belowBlockKey, blocks, function (block) {
  5685. return block.merge({
  5686. prevSibling: originalBlockKey
  5687. });
  5688. });
  5689. });
  5690. };
  5691. var splitBlockInContentState = function splitBlockInContentState(contentState, selectionState) {
  5692. !selectionState.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Selection range must be collapsed.') : invariant_1(false) : void 0;
  5693. var key = selectionState.getAnchorKey();
  5694. var offset = selectionState.getAnchorOffset();
  5695. var blockMap = contentState.getBlockMap();
  5696. var blockToSplit = blockMap.get(key);
  5697. var text = blockToSplit.getText();
  5698. var chars = blockToSplit.getCharacterList();
  5699. var keyBelow = generateRandomKey_1();
  5700. var isExperimentalTreeBlock = blockToSplit instanceof ContentBlockNode_1;
  5701. var blockAbove = blockToSplit.merge({
  5702. text: text.slice(0, offset),
  5703. characterList: chars.slice(0, offset)
  5704. });
  5705. var blockBelow = blockAbove.merge({
  5706. key: keyBelow,
  5707. text: text.slice(offset),
  5708. characterList: chars.slice(offset),
  5709. data: Map$7()
  5710. });
  5711. var blocksBefore = blockMap.toSeq().takeUntil(function (v) {
  5712. return v === blockToSplit;
  5713. });
  5714. var blocksAfter = blockMap.toSeq().skipUntil(function (v) {
  5715. return v === blockToSplit;
  5716. }).rest();
  5717. var newBlocks = blocksBefore.concat([[key, blockAbove], [keyBelow, blockBelow]], blocksAfter).toOrderedMap();
  5718. if (isExperimentalTreeBlock) {
  5719. !blockToSplit.getChildKeys().isEmpty() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'ContentBlockNode must not have children') : invariant_1(false) : void 0;
  5720. newBlocks = updateBlockMapLinks$2(newBlocks, blockAbove, blockBelow);
  5721. }
  5722. return contentState.merge({
  5723. blockMap: newBlocks,
  5724. selectionBefore: selectionState,
  5725. selectionAfter: selectionState.merge({
  5726. anchorKey: keyBelow,
  5727. anchorOffset: 0,
  5728. focusKey: keyBelow,
  5729. focusOffset: 0,
  5730. isBackward: false
  5731. })
  5732. });
  5733. };
  5734. var splitBlockInContentState_1 = splitBlockInContentState;
  5735. var OrderedSet$3 = immutable.OrderedSet;
  5736. /**
  5737. * `DraftModifier` provides a set of convenience methods that apply
  5738. * modifications to a `ContentState` object based on a target `SelectionState`.
  5739. *
  5740. * Any change to a `ContentState` should be decomposable into a series of
  5741. * transaction functions that apply the required changes and return output
  5742. * `ContentState` objects.
  5743. *
  5744. * These functions encapsulate some of the most common transaction sequences.
  5745. */
  5746. var DraftModifier = {
  5747. replaceText: function replaceText(contentState, rangeToReplace, text, inlineStyle, entityKey) {
  5748. var withoutEntities = removeEntitiesAtEdges_1(contentState, rangeToReplace);
  5749. var withoutText = removeRangeFromContentState_1(withoutEntities, rangeToReplace);
  5750. var character = CharacterMetadata_1.create({
  5751. style: inlineStyle || OrderedSet$3(),
  5752. entity: entityKey || null
  5753. });
  5754. return insertTextIntoContentState_1(withoutText, withoutText.getSelectionAfter(), text, character);
  5755. },
  5756. insertText: function insertText(contentState, targetRange, text, inlineStyle, entityKey) {
  5757. !targetRange.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Target range must be collapsed for `insertText`.') : invariant_1(false) : void 0;
  5758. return DraftModifier.replaceText(contentState, targetRange, text, inlineStyle, entityKey);
  5759. },
  5760. moveText: function moveText(contentState, removalRange, targetRange) {
  5761. var movedFragment = getContentStateFragment_1(contentState, removalRange);
  5762. var afterRemoval = DraftModifier.removeRange(contentState, removalRange, 'backward');
  5763. return DraftModifier.replaceWithFragment(afterRemoval, targetRange, movedFragment);
  5764. },
  5765. replaceWithFragment: function replaceWithFragment(contentState, targetRange, fragment) {
  5766. var withoutEntities = removeEntitiesAtEdges_1(contentState, targetRange);
  5767. var withoutText = removeRangeFromContentState_1(withoutEntities, targetRange);
  5768. return insertFragmentIntoContentState_1(withoutText, withoutText.getSelectionAfter(), fragment);
  5769. },
  5770. removeRange: function removeRange(contentState, rangeToRemove, removalDirection) {
  5771. var startKey = void 0,
  5772. endKey = void 0,
  5773. startBlock = void 0,
  5774. endBlock = void 0;
  5775. if (rangeToRemove.getIsBackward()) {
  5776. rangeToRemove = rangeToRemove.merge({
  5777. anchorKey: rangeToRemove.getFocusKey(),
  5778. anchorOffset: rangeToRemove.getFocusOffset(),
  5779. focusKey: rangeToRemove.getAnchorKey(),
  5780. focusOffset: rangeToRemove.getAnchorOffset(),
  5781. isBackward: false
  5782. });
  5783. }
  5784. startKey = rangeToRemove.getAnchorKey();
  5785. endKey = rangeToRemove.getFocusKey();
  5786. startBlock = contentState.getBlockForKey(startKey);
  5787. endBlock = contentState.getBlockForKey(endKey);
  5788. var startOffset = rangeToRemove.getStartOffset();
  5789. var endOffset = rangeToRemove.getEndOffset();
  5790. var startEntityKey = startBlock.getEntityAt(startOffset);
  5791. var endEntityKey = endBlock.getEntityAt(endOffset - 1);
  5792. // Check whether the selection state overlaps with a single entity.
  5793. // If so, try to remove the appropriate substring of the entity text.
  5794. if (startKey === endKey) {
  5795. if (startEntityKey && startEntityKey === endEntityKey) {
  5796. var _adjustedRemovalRange = getCharacterRemovalRange_1(contentState.getEntityMap(), startBlock, endBlock, rangeToRemove, removalDirection);
  5797. return removeRangeFromContentState_1(contentState, _adjustedRemovalRange);
  5798. }
  5799. }
  5800. var adjustedRemovalRange = rangeToRemove;
  5801. var withoutEntities = removeEntitiesAtEdges_1(contentState, adjustedRemovalRange);
  5802. return removeRangeFromContentState_1(withoutEntities, adjustedRemovalRange);
  5803. },
  5804. splitBlock: function splitBlock(contentState, selectionState) {
  5805. var withoutEntities = removeEntitiesAtEdges_1(contentState, selectionState);
  5806. var withoutText = removeRangeFromContentState_1(withoutEntities, selectionState);
  5807. return splitBlockInContentState_1(withoutText, withoutText.getSelectionAfter());
  5808. },
  5809. applyInlineStyle: function applyInlineStyle(contentState, selectionState, inlineStyle) {
  5810. return ContentStateInlineStyle_1.add(contentState, selectionState, inlineStyle);
  5811. },
  5812. removeInlineStyle: function removeInlineStyle(contentState, selectionState, inlineStyle) {
  5813. return ContentStateInlineStyle_1.remove(contentState, selectionState, inlineStyle);
  5814. },
  5815. setBlockType: function setBlockType(contentState, selectionState, blockType) {
  5816. return modifyBlockForContentState_1(contentState, selectionState, function (block) {
  5817. return block.merge({ type: blockType, depth: 0 });
  5818. });
  5819. },
  5820. setBlockData: function setBlockData(contentState, selectionState, blockData) {
  5821. return modifyBlockForContentState_1(contentState, selectionState, function (block) {
  5822. return block.merge({ data: blockData });
  5823. });
  5824. },
  5825. mergeBlockData: function mergeBlockData(contentState, selectionState, blockData) {
  5826. return modifyBlockForContentState_1(contentState, selectionState, function (block) {
  5827. return block.merge({ data: block.getData().merge(blockData) });
  5828. });
  5829. },
  5830. applyEntity: function applyEntity(contentState, selectionState, entityKey) {
  5831. var withoutEntities = removeEntitiesAtEdges_1(contentState, selectionState);
  5832. return applyEntityToContentState_1(withoutEntities, selectionState, entityKey);
  5833. }
  5834. };
  5835. var DraftModifier_1 = DraftModifier;
  5836. /**
  5837. * Copyright (c) 2013-present, Facebook, Inc.
  5838. *
  5839. * This source code is licensed under the MIT license found in the
  5840. * LICENSE file in the root directory of this source tree.
  5841. *
  5842. *
  5843. */
  5844. function makeEmptyFunction(arg) {
  5845. return function () {
  5846. return arg;
  5847. };
  5848. }
  5849. /**
  5850. * This function accepts and discards inputs; it has no side effects. This is
  5851. * primarily useful idiomatically for overridable function endpoints which
  5852. * always need to be callable, since JS lacks a null-call idiom ala Cocoa.
  5853. */
  5854. var emptyFunction = function emptyFunction() {};
  5855. emptyFunction.thatReturns = makeEmptyFunction;
  5856. emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
  5857. emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
  5858. emptyFunction.thatReturnsNull = makeEmptyFunction(null);
  5859. emptyFunction.thatReturnsThis = function () {
  5860. return this;
  5861. };
  5862. emptyFunction.thatReturnsArgument = function (arg) {
  5863. return arg;
  5864. };
  5865. var emptyFunction_1 = emptyFunction;
  5866. var List$5 = immutable.List,
  5867. Repeat$3 = immutable.Repeat,
  5868. Record$3 = immutable.Record;
  5869. var returnTrue = emptyFunction_1.thatReturnsTrue;
  5870. var FINGERPRINT_DELIMITER = '-';
  5871. var defaultLeafRange = {
  5872. start: null,
  5873. end: null
  5874. };
  5875. var LeafRange = Record$3(defaultLeafRange);
  5876. var defaultDecoratorRange = {
  5877. start: null,
  5878. end: null,
  5879. decoratorKey: null,
  5880. leaves: null
  5881. };
  5882. var DecoratorRange = Record$3(defaultDecoratorRange);
  5883. var BlockTree = {
  5884. /**
  5885. * Generate a block tree for a given ContentBlock/decorator pair.
  5886. */
  5887. generate: function generate(contentState, block, decorator) {
  5888. var textLength = block.getLength();
  5889. if (!textLength) {
  5890. return List$5.of(new DecoratorRange({
  5891. start: 0,
  5892. end: 0,
  5893. decoratorKey: null,
  5894. leaves: List$5.of(new LeafRange({ start: 0, end: 0 }))
  5895. }));
  5896. }
  5897. var leafSets = [];
  5898. var decorations = decorator ? decorator.getDecorations(block, contentState) : List$5(Repeat$3(null, textLength));
  5899. var chars = block.getCharacterList();
  5900. findRangesImmutable_1(decorations, areEqual, returnTrue, function (start, end) {
  5901. leafSets.push(new DecoratorRange({
  5902. start: start,
  5903. end: end,
  5904. decoratorKey: decorations.get(start),
  5905. leaves: generateLeaves(chars.slice(start, end).toList(), start)
  5906. }));
  5907. });
  5908. return List$5(leafSets);
  5909. },
  5910. /**
  5911. * Create a string representation of the given tree map. This allows us
  5912. * to rapidly determine whether a tree has undergone a significant
  5913. * structural change.
  5914. */
  5915. getFingerprint: function getFingerprint(tree) {
  5916. return tree.map(function (leafSet) {
  5917. var decoratorKey = leafSet.get('decoratorKey');
  5918. var fingerprintString = decoratorKey !== null ? decoratorKey + '.' + (leafSet.get('end') - leafSet.get('start')) : '';
  5919. return '' + fingerprintString + '.' + leafSet.get('leaves').size;
  5920. }).join(FINGERPRINT_DELIMITER);
  5921. }
  5922. };
  5923. /**
  5924. * Generate LeafRange records for a given character list.
  5925. */
  5926. function generateLeaves(characters, offset) {
  5927. var leaves = [];
  5928. var inlineStyles = characters.map(function (c) {
  5929. return c.getStyle();
  5930. }).toList();
  5931. findRangesImmutable_1(inlineStyles, areEqual, returnTrue, function (start, end) {
  5932. leaves.push(new LeafRange({
  5933. start: start + offset,
  5934. end: end + offset
  5935. }));
  5936. });
  5937. return List$5(leaves);
  5938. }
  5939. function areEqual(a, b) {
  5940. return a === b;
  5941. }
  5942. var BlockTree_1 = BlockTree;
  5943. function _classCallCheck$3(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5944. 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; }
  5945. 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; }
  5946. var Record$4 = immutable.Record;
  5947. var DraftEntityInstanceRecord = Record$4({
  5948. type: 'TOKEN',
  5949. mutability: 'IMMUTABLE',
  5950. data: Object
  5951. });
  5952. /**
  5953. * An instance of a document entity, consisting of a `type` and relevant
  5954. * `data`, metadata about the entity.
  5955. *
  5956. * For instance, a "link" entity might provide a URI, and a "mention"
  5957. * entity might provide the mentioned user's ID. These pieces of data
  5958. * may be used when rendering the entity as part of a ContentBlock DOM
  5959. * representation. For a link, the data would be used as an href for
  5960. * the rendered anchor. For a mention, the ID could be used to retrieve
  5961. * a hovercard.
  5962. */
  5963. var DraftEntityInstance = function (_DraftEntityInstanceR) {
  5964. _inherits$3(DraftEntityInstance, _DraftEntityInstanceR);
  5965. function DraftEntityInstance() {
  5966. _classCallCheck$3(this, DraftEntityInstance);
  5967. return _possibleConstructorReturn$3(this, _DraftEntityInstanceR.apply(this, arguments));
  5968. }
  5969. DraftEntityInstance.prototype.getType = function getType() {
  5970. return this.get('type');
  5971. };
  5972. DraftEntityInstance.prototype.getMutability = function getMutability() {
  5973. return this.get('mutability');
  5974. };
  5975. DraftEntityInstance.prototype.getData = function getData() {
  5976. return this.get('data');
  5977. };
  5978. return DraftEntityInstance;
  5979. }(DraftEntityInstanceRecord);
  5980. var DraftEntityInstance_1 = DraftEntityInstance;
  5981. 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; };
  5982. /**
  5983. * Copyright (c) 2013-present, Facebook, Inc.
  5984. * All rights reserved.
  5985. *
  5986. * This source code is licensed under the BSD-style license found in the
  5987. * LICENSE file in the root directory of this source tree. An additional grant
  5988. * of patent rights can be found in the PATENTS file in the same directory.
  5989. *
  5990. * @providesModule DraftEntity
  5991. * @format
  5992. *
  5993. */
  5994. var Map$8 = immutable.Map;
  5995. var instances = Map$8();
  5996. var instanceKey = 0;
  5997. /**
  5998. * Temporary utility for generating the warnings
  5999. */
  6000. function logWarning(oldMethodCall, newMethodCall) {
  6001. console.warn('WARNING: ' + oldMethodCall + ' will be deprecated soon!\nPlease use "' + newMethodCall + '" instead.');
  6002. }
  6003. /**
  6004. * A "document entity" is an object containing metadata associated with a
  6005. * piece of text in a ContentBlock.
  6006. *
  6007. * For example, a `link` entity might include a `uri` property. When a
  6008. * ContentBlock is rendered in the browser, text that refers to that link
  6009. * entity may be rendered as an anchor, with the `uri` as the href value.
  6010. *
  6011. * In a ContentBlock, every position in the text may correspond to zero
  6012. * or one entities. This correspondence is tracked using a key string,
  6013. * generated via DraftEntity.create() and used to obtain entity metadata
  6014. * via DraftEntity.get().
  6015. */
  6016. var DraftEntity = {
  6017. /**
  6018. * WARNING: This method will be deprecated soon!
  6019. * Please use 'contentState.getLastCreatedEntityKey' instead.
  6020. * ---
  6021. * Get the random key string from whatever entity was last created.
  6022. * We need this to support the new API, as part of transitioning to put Entity
  6023. * storage in contentState.
  6024. */
  6025. getLastCreatedEntityKey: function getLastCreatedEntityKey() {
  6026. logWarning('DraftEntity.getLastCreatedEntityKey', 'contentState.getLastCreatedEntityKey');
  6027. return DraftEntity.__getLastCreatedEntityKey();
  6028. },
  6029. /**
  6030. * WARNING: This method will be deprecated soon!
  6031. * Please use 'contentState.createEntity' instead.
  6032. * ---
  6033. * Create a DraftEntityInstance and store it for later retrieval.
  6034. *
  6035. * A random key string will be generated and returned. This key may
  6036. * be used to track the entity's usage in a ContentBlock, and for
  6037. * retrieving data about the entity at render time.
  6038. */
  6039. create: function create(type, mutability, data) {
  6040. logWarning('DraftEntity.create', 'contentState.createEntity');
  6041. return DraftEntity.__create(type, mutability, data);
  6042. },
  6043. /**
  6044. * WARNING: This method will be deprecated soon!
  6045. * Please use 'contentState.addEntity' instead.
  6046. * ---
  6047. * Add an existing DraftEntityInstance to the DraftEntity map. This is
  6048. * useful when restoring instances from the server.
  6049. */
  6050. add: function add(instance) {
  6051. logWarning('DraftEntity.add', 'contentState.addEntity');
  6052. return DraftEntity.__add(instance);
  6053. },
  6054. /**
  6055. * WARNING: This method will be deprecated soon!
  6056. * Please use 'contentState.getEntity' instead.
  6057. * ---
  6058. * Retrieve the entity corresponding to the supplied key string.
  6059. */
  6060. get: function get(key) {
  6061. logWarning('DraftEntity.get', 'contentState.getEntity');
  6062. return DraftEntity.__get(key);
  6063. },
  6064. /**
  6065. * WARNING: This method will be deprecated soon!
  6066. * Please use 'contentState.mergeEntityData' instead.
  6067. * ---
  6068. * Entity instances are immutable. If you need to update the data for an
  6069. * instance, this method will merge your data updates and return a new
  6070. * instance.
  6071. */
  6072. mergeData: function mergeData(key, toMerge) {
  6073. logWarning('DraftEntity.mergeData', 'contentState.mergeEntityData');
  6074. return DraftEntity.__mergeData(key, toMerge);
  6075. },
  6076. /**
  6077. * WARNING: This method will be deprecated soon!
  6078. * Please use 'contentState.replaceEntityData' instead.
  6079. * ---
  6080. * Completely replace the data for a given instance.
  6081. */
  6082. replaceData: function replaceData(key, newData) {
  6083. logWarning('DraftEntity.replaceData', 'contentState.replaceEntityData');
  6084. return DraftEntity.__replaceData(key, newData);
  6085. },
  6086. // ***********************************WARNING******************************
  6087. // --- the above public API will be deprecated in the next version of Draft!
  6088. // The methods below this line are private - don't call them directly.
  6089. /**
  6090. * Get the random key string from whatever entity was last created.
  6091. * We need this to support the new API, as part of transitioning to put Entity
  6092. * storage in contentState.
  6093. */
  6094. __getLastCreatedEntityKey: function __getLastCreatedEntityKey() {
  6095. return '' + instanceKey;
  6096. },
  6097. /**
  6098. * Create a DraftEntityInstance and store it for later retrieval.
  6099. *
  6100. * A random key string will be generated and returned. This key may
  6101. * be used to track the entity's usage in a ContentBlock, and for
  6102. * retrieving data about the entity at render time.
  6103. */
  6104. __create: function __create(type, mutability, data) {
  6105. return DraftEntity.__add(new DraftEntityInstance_1({ type: type, mutability: mutability, data: data || {} }));
  6106. },
  6107. /**
  6108. * Add an existing DraftEntityInstance to the DraftEntity map. This is
  6109. * useful when restoring instances from the server.
  6110. */
  6111. __add: function __add(instance) {
  6112. var key = '' + ++instanceKey;
  6113. instances = instances.set(key, instance);
  6114. return key;
  6115. },
  6116. /**
  6117. * Retrieve the entity corresponding to the supplied key string.
  6118. */
  6119. __get: function __get(key) {
  6120. var instance = instances.get(key);
  6121. !!!instance ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Unknown DraftEntity key: %s.', key) : invariant_1(false) : void 0;
  6122. return instance;
  6123. },
  6124. /**
  6125. * Entity instances are immutable. If you need to update the data for an
  6126. * instance, this method will merge your data updates and return a new
  6127. * instance.
  6128. */
  6129. __mergeData: function __mergeData(key, toMerge) {
  6130. var instance = DraftEntity.__get(key);
  6131. var newData = _extends({}, instance.getData(), toMerge);
  6132. var newInstance = instance.set('data', newData);
  6133. instances = instances.set(key, newInstance);
  6134. return newInstance;
  6135. },
  6136. /**
  6137. * Completely replace the data for a given instance.
  6138. */
  6139. __replaceData: function __replaceData(key, newData) {
  6140. var instance = DraftEntity.__get(key);
  6141. var newInstance = instance.set('data', newData);
  6142. instances = instances.set(key, newInstance);
  6143. return newInstance;
  6144. }
  6145. };
  6146. var DraftEntity_1 = DraftEntity;
  6147. function _classCallCheck$4(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6148. 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; }
  6149. 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; }
  6150. var Record$5 = immutable.Record;
  6151. var defaultRecord$3 = {
  6152. anchorKey: '',
  6153. anchorOffset: 0,
  6154. focusKey: '',
  6155. focusOffset: 0,
  6156. isBackward: false,
  6157. hasFocus: false
  6158. };
  6159. var SelectionStateRecord = Record$5(defaultRecord$3);
  6160. var SelectionState = function (_SelectionStateRecord) {
  6161. _inherits$4(SelectionState, _SelectionStateRecord);
  6162. function SelectionState() {
  6163. _classCallCheck$4(this, SelectionState);
  6164. return _possibleConstructorReturn$4(this, _SelectionStateRecord.apply(this, arguments));
  6165. }
  6166. SelectionState.prototype.serialize = function serialize() {
  6167. return 'Anchor: ' + this.getAnchorKey() + ':' + this.getAnchorOffset() + ', ' + 'Focus: ' + this.getFocusKey() + ':' + this.getFocusOffset() + ', ' + 'Is Backward: ' + String(this.getIsBackward()) + ', ' + 'Has Focus: ' + String(this.getHasFocus());
  6168. };
  6169. SelectionState.prototype.getAnchorKey = function getAnchorKey() {
  6170. return this.get('anchorKey');
  6171. };
  6172. SelectionState.prototype.getAnchorOffset = function getAnchorOffset() {
  6173. return this.get('anchorOffset');
  6174. };
  6175. SelectionState.prototype.getFocusKey = function getFocusKey() {
  6176. return this.get('focusKey');
  6177. };
  6178. SelectionState.prototype.getFocusOffset = function getFocusOffset() {
  6179. return this.get('focusOffset');
  6180. };
  6181. SelectionState.prototype.getIsBackward = function getIsBackward() {
  6182. return this.get('isBackward');
  6183. };
  6184. SelectionState.prototype.getHasFocus = function getHasFocus() {
  6185. return this.get('hasFocus');
  6186. };
  6187. /**
  6188. * Return whether the specified range overlaps with an edge of the
  6189. * SelectionState.
  6190. */
  6191. SelectionState.prototype.hasEdgeWithin = function hasEdgeWithin(blockKey, start, end) {
  6192. var anchorKey = this.getAnchorKey();
  6193. var focusKey = this.getFocusKey();
  6194. if (anchorKey === focusKey && anchorKey === blockKey) {
  6195. var selectionStart = this.getStartOffset();
  6196. var selectionEnd = this.getEndOffset();
  6197. return start <= selectionEnd && selectionStart <= end;
  6198. }
  6199. if (blockKey !== anchorKey && blockKey !== focusKey) {
  6200. return false;
  6201. }
  6202. var offsetToCheck = blockKey === anchorKey ? this.getAnchorOffset() : this.getFocusOffset();
  6203. return start <= offsetToCheck && end >= offsetToCheck;
  6204. };
  6205. SelectionState.prototype.isCollapsed = function isCollapsed() {
  6206. return this.getAnchorKey() === this.getFocusKey() && this.getAnchorOffset() === this.getFocusOffset();
  6207. };
  6208. SelectionState.prototype.getStartKey = function getStartKey() {
  6209. return this.getIsBackward() ? this.getFocusKey() : this.getAnchorKey();
  6210. };
  6211. SelectionState.prototype.getStartOffset = function getStartOffset() {
  6212. return this.getIsBackward() ? this.getFocusOffset() : this.getAnchorOffset();
  6213. };
  6214. SelectionState.prototype.getEndKey = function getEndKey() {
  6215. return this.getIsBackward() ? this.getAnchorKey() : this.getFocusKey();
  6216. };
  6217. SelectionState.prototype.getEndOffset = function getEndOffset() {
  6218. return this.getIsBackward() ? this.getAnchorOffset() : this.getFocusOffset();
  6219. };
  6220. SelectionState.createEmpty = function createEmpty(key) {
  6221. return new SelectionState({
  6222. anchorKey: key,
  6223. anchorOffset: 0,
  6224. focusKey: key,
  6225. focusOffset: 0,
  6226. isBackward: false,
  6227. hasFocus: false
  6228. });
  6229. };
  6230. return SelectionState;
  6231. }(SelectionStateRecord);
  6232. var SelectionState_1 = SelectionState;
  6233. /**
  6234. * Copyright (c) 2013-present, Facebook, Inc.
  6235. * All rights reserved.
  6236. *
  6237. * This source code is licensed under the BSD-style license found in the
  6238. * LICENSE file in the root directory of this source tree. An additional grant
  6239. * of patent rights can be found in the PATENTS file in the same directory.
  6240. *
  6241. * @providesModule sanitizeDraftText
  6242. * @format
  6243. *
  6244. */
  6245. var REGEX_BLOCK_DELIMITER = new RegExp('\r', 'g');
  6246. function sanitizeDraftText(input) {
  6247. return input.replace(REGEX_BLOCK_DELIMITER, '');
  6248. }
  6249. var sanitizeDraftText_1 = sanitizeDraftText;
  6250. function _classCallCheck$5(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6251. 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; }
  6252. 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; }
  6253. var List$6 = immutable.List,
  6254. Record$6 = immutable.Record,
  6255. Repeat$4 = immutable.Repeat;
  6256. var defaultRecord$4 = {
  6257. entityMap: null,
  6258. blockMap: null,
  6259. selectionBefore: null,
  6260. selectionAfter: null
  6261. };
  6262. var ContentBlockNodeRecord = ContentBlock_1;
  6263. var ContentStateRecord = Record$6(defaultRecord$4);
  6264. var ContentState = function (_ContentStateRecord) {
  6265. _inherits$5(ContentState, _ContentStateRecord);
  6266. function ContentState() {
  6267. _classCallCheck$5(this, ContentState);
  6268. return _possibleConstructorReturn$5(this, _ContentStateRecord.apply(this, arguments));
  6269. }
  6270. ContentState.prototype.getEntityMap = function getEntityMap() {
  6271. // TODO: update this when we fully remove DraftEntity
  6272. return DraftEntity_1;
  6273. };
  6274. ContentState.prototype.getBlockMap = function getBlockMap() {
  6275. return this.get('blockMap');
  6276. };
  6277. ContentState.prototype.getSelectionBefore = function getSelectionBefore() {
  6278. return this.get('selectionBefore');
  6279. };
  6280. ContentState.prototype.getSelectionAfter = function getSelectionAfter() {
  6281. return this.get('selectionAfter');
  6282. };
  6283. ContentState.prototype.getBlockForKey = function getBlockForKey(key) {
  6284. var block = this.getBlockMap().get(key);
  6285. return block;
  6286. };
  6287. ContentState.prototype.getKeyBefore = function getKeyBefore(key) {
  6288. return this.getBlockMap().reverse().keySeq().skipUntil(function (v) {
  6289. return v === key;
  6290. }).skip(1).first();
  6291. };
  6292. ContentState.prototype.getKeyAfter = function getKeyAfter(key) {
  6293. return this.getBlockMap().keySeq().skipUntil(function (v) {
  6294. return v === key;
  6295. }).skip(1).first();
  6296. };
  6297. ContentState.prototype.getBlockAfter = function getBlockAfter(key) {
  6298. return this.getBlockMap().skipUntil(function (_, k) {
  6299. return k === key;
  6300. }).skip(1).first();
  6301. };
  6302. ContentState.prototype.getBlockBefore = function getBlockBefore(key) {
  6303. return this.getBlockMap().reverse().skipUntil(function (_, k) {
  6304. return k === key;
  6305. }).skip(1).first();
  6306. };
  6307. ContentState.prototype.getBlocksAsArray = function getBlocksAsArray() {
  6308. return this.getBlockMap().toArray();
  6309. };
  6310. ContentState.prototype.getFirstBlock = function getFirstBlock() {
  6311. return this.getBlockMap().first();
  6312. };
  6313. ContentState.prototype.getLastBlock = function getLastBlock() {
  6314. return this.getBlockMap().last();
  6315. };
  6316. ContentState.prototype.getPlainText = function getPlainText(delimiter) {
  6317. return this.getBlockMap().map(function (block) {
  6318. return block ? block.getText() : '';
  6319. }).join(delimiter || '\n');
  6320. };
  6321. ContentState.prototype.getLastCreatedEntityKey = function getLastCreatedEntityKey() {
  6322. // TODO: update this when we fully remove DraftEntity
  6323. return DraftEntity_1.__getLastCreatedEntityKey();
  6324. };
  6325. ContentState.prototype.hasText = function hasText() {
  6326. var blockMap = this.getBlockMap();
  6327. return blockMap.size > 1 || blockMap.first().getLength() > 0;
  6328. };
  6329. ContentState.prototype.createEntity = function createEntity(type, mutability, data) {
  6330. // TODO: update this when we fully remove DraftEntity
  6331. DraftEntity_1.__create(type, mutability, data);
  6332. return this;
  6333. };
  6334. ContentState.prototype.mergeEntityData = function mergeEntityData(key, toMerge) {
  6335. // TODO: update this when we fully remove DraftEntity
  6336. DraftEntity_1.__mergeData(key, toMerge);
  6337. return this;
  6338. };
  6339. ContentState.prototype.replaceEntityData = function replaceEntityData(key, newData) {
  6340. // TODO: update this when we fully remove DraftEntity
  6341. DraftEntity_1.__replaceData(key, newData);
  6342. return this;
  6343. };
  6344. ContentState.prototype.addEntity = function addEntity(instance) {
  6345. // TODO: update this when we fully remove DraftEntity
  6346. DraftEntity_1.__add(instance);
  6347. return this;
  6348. };
  6349. ContentState.prototype.getEntity = function getEntity(key) {
  6350. // TODO: update this when we fully remove DraftEntity
  6351. return DraftEntity_1.__get(key);
  6352. };
  6353. ContentState.createFromBlockArray = function createFromBlockArray(
  6354. // TODO: update flow type when we completely deprecate the old entity API
  6355. blocks, entityMap) {
  6356. // TODO: remove this when we completely deprecate the old entity API
  6357. var theBlocks = Array.isArray(blocks) ? blocks : blocks.contentBlocks;
  6358. var blockMap = BlockMapBuilder_1.createFromArray(theBlocks);
  6359. var selectionState = blockMap.isEmpty() ? new SelectionState_1() : SelectionState_1.createEmpty(blockMap.first().getKey());
  6360. return new ContentState({
  6361. blockMap: blockMap,
  6362. entityMap: entityMap || DraftEntity_1,
  6363. selectionBefore: selectionState,
  6364. selectionAfter: selectionState
  6365. });
  6366. };
  6367. ContentState.createFromText = function createFromText(text) {
  6368. var delimiter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : /\r\n?|\n/g;
  6369. var strings = text.split(delimiter);
  6370. var blocks = strings.map(function (block) {
  6371. block = sanitizeDraftText_1(block);
  6372. return new ContentBlockNodeRecord({
  6373. key: generateRandomKey_1(),
  6374. text: block,
  6375. type: 'unstyled',
  6376. characterList: List$6(Repeat$4(CharacterMetadata_1.EMPTY, block.length))
  6377. });
  6378. });
  6379. return ContentState.createFromBlockArray(blocks);
  6380. };
  6381. return ContentState;
  6382. }(ContentStateRecord);
  6383. var ContentState_1 = ContentState;
  6384. var NEUTRAL = 'NEUTRAL'; // No strong direction
  6385. var LTR = 'LTR'; // Left-to-Right direction
  6386. var RTL = 'RTL'; // Right-to-Left direction
  6387. var globalDir = null;
  6388. // == Helpers ==
  6389. /**
  6390. * Check if a directionality value is a Strong one
  6391. */
  6392. function isStrong(dir) {
  6393. return dir === LTR || dir === RTL;
  6394. }
  6395. /**
  6396. * Get string value to be used for `dir` HTML attribute or `direction` CSS
  6397. * property.
  6398. */
  6399. function getHTMLDir(dir) {
  6400. !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;
  6401. return dir === LTR ? 'ltr' : 'rtl';
  6402. }
  6403. /**
  6404. * Get string value to be used for `dir` HTML attribute or `direction` CSS
  6405. * property, but returns null if `dir` has same value as `otherDir`.
  6406. * `null`.
  6407. */
  6408. function getHTMLDirIfDifferent(dir, otherDir) {
  6409. !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;
  6410. !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;
  6411. return dir === otherDir ? null : getHTMLDir(dir);
  6412. }
  6413. // == Global Direction ==
  6414. /**
  6415. * Set the global direction.
  6416. */
  6417. function setGlobalDir(dir) {
  6418. globalDir = dir;
  6419. }
  6420. /**
  6421. * Initialize the global direction
  6422. */
  6423. function initGlobalDir() {
  6424. setGlobalDir(LTR);
  6425. }
  6426. /**
  6427. * Get the global direction
  6428. */
  6429. function getGlobalDir() {
  6430. if (!globalDir) {
  6431. this.initGlobalDir();
  6432. }
  6433. !globalDir ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Global direction not set.') : invariant_1(false) : void 0;
  6434. return globalDir;
  6435. }
  6436. var UnicodeBidiDirection = {
  6437. // Values
  6438. NEUTRAL: NEUTRAL,
  6439. LTR: LTR,
  6440. RTL: RTL,
  6441. // Helpers
  6442. isStrong: isStrong,
  6443. getHTMLDir: getHTMLDir,
  6444. getHTMLDirIfDifferent: getHTMLDirIfDifferent,
  6445. // Global Direction
  6446. setGlobalDir: setGlobalDir,
  6447. initGlobalDir: initGlobalDir,
  6448. getGlobalDir: getGlobalDir
  6449. };
  6450. var UnicodeBidiDirection_1 = UnicodeBidiDirection;
  6451. /**
  6452. * RegExp ranges of characters with a *Strong* Bidi_Class value.
  6453. *
  6454. * Data is based on DerivedBidiClass.txt in UCD version 7.0.0.
  6455. *
  6456. * NOTE: For performance reasons, we only support Unicode's
  6457. * Basic Multilingual Plane (BMP) for now.
  6458. */
  6459. var RANGE_BY_BIDI_TYPE = {
  6460. 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',
  6461. 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',
  6462. 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'
  6463. };
  6464. var REGEX_STRONG = new RegExp('[' + RANGE_BY_BIDI_TYPE.L + RANGE_BY_BIDI_TYPE.R + RANGE_BY_BIDI_TYPE.AL + ']');
  6465. var REGEX_RTL = new RegExp('[' + RANGE_BY_BIDI_TYPE.R + RANGE_BY_BIDI_TYPE.AL + ']');
  6466. /**
  6467. * Returns the first strong character (has Bidi_Class value of L, R, or AL).
  6468. *
  6469. * @param str A text block; e.g. paragraph, table cell, tag
  6470. * @return A character with strong bidi direction, or null if not found
  6471. */
  6472. function firstStrongChar(str) {
  6473. var match = REGEX_STRONG.exec(str);
  6474. return match == null ? null : match[0];
  6475. }
  6476. /**
  6477. * Returns the direction of a block of text, based on the direction of its
  6478. * first strong character (has Bidi_Class value of L, R, or AL).
  6479. *
  6480. * @param str A text block; e.g. paragraph, table cell, tag
  6481. * @return The resolved direction
  6482. */
  6483. function firstStrongCharDir(str) {
  6484. var strongChar = firstStrongChar(str);
  6485. if (strongChar == null) {
  6486. return UnicodeBidiDirection_1.NEUTRAL;
  6487. }
  6488. return REGEX_RTL.exec(strongChar) ? UnicodeBidiDirection_1.RTL : UnicodeBidiDirection_1.LTR;
  6489. }
  6490. /**
  6491. * Returns the direction of a block of text, based on the direction of its
  6492. * first strong character (has Bidi_Class value of L, R, or AL), or a fallback
  6493. * direction, if no strong character is found.
  6494. *
  6495. * This function is supposed to be used in respect to Higher-Level Protocol
  6496. * rule HL1. (http://www.unicode.org/reports/tr9/#HL1)
  6497. *
  6498. * @param str A text block; e.g. paragraph, table cell, tag
  6499. * @param fallback Fallback direction, used if no strong direction detected
  6500. * for the block (default = NEUTRAL)
  6501. * @return The resolved direction
  6502. */
  6503. function resolveBlockDir(str, fallback) {
  6504. fallback = fallback || UnicodeBidiDirection_1.NEUTRAL;
  6505. if (!str.length) {
  6506. return fallback;
  6507. }
  6508. var blockDir = firstStrongCharDir(str);
  6509. return blockDir === UnicodeBidiDirection_1.NEUTRAL ? fallback : blockDir;
  6510. }
  6511. /**
  6512. * Returns the direction of a block of text, based on the direction of its
  6513. * first strong character (has Bidi_Class value of L, R, or AL), or a fallback
  6514. * direction, if no strong character is found.
  6515. *
  6516. * NOTE: This function is similar to resolveBlockDir(), but uses the global
  6517. * direction as the fallback, so it *always* returns a Strong direction,
  6518. * making it useful for integration in places that you need to make the final
  6519. * decision, like setting some CSS class.
  6520. *
  6521. * This function is supposed to be used in respect to Higher-Level Protocol
  6522. * rule HL1. (http://www.unicode.org/reports/tr9/#HL1)
  6523. *
  6524. * @param str A text block; e.g. paragraph, table cell
  6525. * @param strongFallback Fallback direction, used if no strong direction
  6526. * detected for the block (default = global direction)
  6527. * @return The resolved Strong direction
  6528. */
  6529. function getDirection(str, strongFallback) {
  6530. if (!strongFallback) {
  6531. strongFallback = UnicodeBidiDirection_1.getGlobalDir();
  6532. }
  6533. !UnicodeBidiDirection_1.isStrong(strongFallback) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Fallback direction must be a strong direction') : invariant_1(false) : void 0;
  6534. return resolveBlockDir(str, strongFallback);
  6535. }
  6536. /**
  6537. * Returns true if getDirection(arguments...) returns LTR.
  6538. *
  6539. * @param str A text block; e.g. paragraph, table cell
  6540. * @param strongFallback Fallback direction, used if no strong direction
  6541. * detected for the block (default = global direction)
  6542. * @return True if the resolved direction is LTR
  6543. */
  6544. function isDirectionLTR(str, strongFallback) {
  6545. return getDirection(str, strongFallback) === UnicodeBidiDirection_1.LTR;
  6546. }
  6547. /**
  6548. * Returns true if getDirection(arguments...) returns RTL.
  6549. *
  6550. * @param str A text block; e.g. paragraph, table cell
  6551. * @param strongFallback Fallback direction, used if no strong direction
  6552. * detected for the block (default = global direction)
  6553. * @return True if the resolved direction is RTL
  6554. */
  6555. function isDirectionRTL(str, strongFallback) {
  6556. return getDirection(str, strongFallback) === UnicodeBidiDirection_1.RTL;
  6557. }
  6558. var UnicodeBidi = {
  6559. firstStrongChar: firstStrongChar,
  6560. firstStrongCharDir: firstStrongCharDir,
  6561. resolveBlockDir: resolveBlockDir,
  6562. getDirection: getDirection,
  6563. isDirectionLTR: isDirectionLTR,
  6564. isDirectionRTL: isDirectionRTL
  6565. };
  6566. var UnicodeBidi_1 = UnicodeBidi;
  6567. function _classCallCheck$6(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6568. var UnicodeBidiService = function () {
  6569. /**
  6570. * Stateful class for paragraph direction detection
  6571. *
  6572. * @param defaultDir Default direction of the service
  6573. */
  6574. function UnicodeBidiService(defaultDir) {
  6575. _classCallCheck$6(this, UnicodeBidiService);
  6576. if (!defaultDir) {
  6577. defaultDir = UnicodeBidiDirection_1.getGlobalDir();
  6578. } else {
  6579. !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;
  6580. }
  6581. this._defaultDir = defaultDir;
  6582. this.reset();
  6583. }
  6584. /**
  6585. * Reset the internal state
  6586. *
  6587. * Instead of creating a new instance, you can just reset() your instance
  6588. * everytime you start a new loop.
  6589. */
  6590. UnicodeBidiService.prototype.reset = function reset() {
  6591. this._lastDir = this._defaultDir;
  6592. };
  6593. /**
  6594. * Returns the direction of a block of text, and remembers it as the
  6595. * fall-back direction for the next paragraph.
  6596. *
  6597. * @param str A text block, e.g. paragraph, table cell, tag
  6598. * @return The resolved direction
  6599. */
  6600. UnicodeBidiService.prototype.getDirection = function getDirection(str) {
  6601. this._lastDir = UnicodeBidi_1.getDirection(str, this._lastDir);
  6602. return this._lastDir;
  6603. };
  6604. return UnicodeBidiService;
  6605. }();
  6606. var UnicodeBidiService_1 = UnicodeBidiService;
  6607. /**
  6608. * Copyright (c) 2013-present, Facebook, Inc.
  6609. *
  6610. * This source code is licensed under the MIT license found in the
  6611. * LICENSE file in the root directory of this source tree.
  6612. *
  6613. *
  6614. */
  6615. var nullthrows = function nullthrows(x) {
  6616. if (x != null) {
  6617. return x;
  6618. }
  6619. throw new Error("Got unexpected null or undefined");
  6620. };
  6621. var nullthrows_1 = nullthrows;
  6622. var OrderedMap$2 = immutable.OrderedMap;
  6623. var bidiService;
  6624. var EditorBidiService = {
  6625. getDirectionMap: function getDirectionMap(content, prevBidiMap) {
  6626. if (!bidiService) {
  6627. bidiService = new UnicodeBidiService_1();
  6628. } else {
  6629. bidiService.reset();
  6630. }
  6631. var blockMap = content.getBlockMap();
  6632. var nextBidi = blockMap.valueSeq().map(function (block) {
  6633. return nullthrows_1(bidiService).getDirection(block.getText());
  6634. });
  6635. var bidiMap = OrderedMap$2(blockMap.keySeq().zip(nextBidi));
  6636. if (prevBidiMap != null && immutable.is(prevBidiMap, bidiMap)) {
  6637. return prevBidiMap;
  6638. }
  6639. return bidiMap;
  6640. }
  6641. };
  6642. var EditorBidiService_1 = EditorBidiService;
  6643. 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; };
  6644. function _classCallCheck$7(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6645. var OrderedSet$4 = immutable.OrderedSet,
  6646. Record$7 = immutable.Record,
  6647. Stack = immutable.Stack;
  6648. var defaultRecord$5 = {
  6649. allowUndo: true,
  6650. currentContent: null,
  6651. decorator: null,
  6652. directionMap: null,
  6653. forceSelection: false,
  6654. inCompositionMode: false,
  6655. inlineStyleOverride: null,
  6656. lastChangeType: null,
  6657. nativelyRenderedContent: null,
  6658. redoStack: Stack(),
  6659. selection: null,
  6660. treeMap: null,
  6661. undoStack: Stack()
  6662. };
  6663. var EditorStateRecord = Record$7(defaultRecord$5);
  6664. var EditorState = function () {
  6665. EditorState.createEmpty = function createEmpty(decorator) {
  6666. return EditorState.createWithContent(ContentState_1.createFromText(''), decorator);
  6667. };
  6668. EditorState.createWithContent = function createWithContent(contentState, decorator) {
  6669. var firstKey = contentState.getBlockMap().first().getKey();
  6670. return EditorState.create({
  6671. currentContent: contentState,
  6672. undoStack: Stack(),
  6673. redoStack: Stack(),
  6674. decorator: decorator || null,
  6675. selection: SelectionState_1.createEmpty(firstKey)
  6676. });
  6677. };
  6678. EditorState.create = function create(config) {
  6679. var currentContent = config.currentContent,
  6680. decorator = config.decorator;
  6681. var recordConfig = _extends$1({}, config, {
  6682. treeMap: generateNewTreeMap(currentContent, decorator),
  6683. directionMap: EditorBidiService_1.getDirectionMap(currentContent)
  6684. });
  6685. return new EditorState(new EditorStateRecord(recordConfig));
  6686. };
  6687. EditorState.set = function set(editorState, put) {
  6688. var map = editorState.getImmutable().withMutations(function (state) {
  6689. var existingDecorator = state.get('decorator');
  6690. var decorator = existingDecorator;
  6691. if (put.decorator === null) {
  6692. decorator = null;
  6693. } else if (put.decorator) {
  6694. decorator = put.decorator;
  6695. }
  6696. var newContent = put.currentContent || editorState.getCurrentContent();
  6697. if (decorator !== existingDecorator) {
  6698. var treeMap = state.get('treeMap');
  6699. var newTreeMap;
  6700. if (decorator && existingDecorator) {
  6701. newTreeMap = regenerateTreeForNewDecorator(newContent, newContent.getBlockMap(), treeMap, decorator, existingDecorator);
  6702. } else {
  6703. newTreeMap = generateNewTreeMap(newContent, decorator);
  6704. }
  6705. state.merge({
  6706. decorator: decorator,
  6707. treeMap: newTreeMap,
  6708. nativelyRenderedContent: null
  6709. });
  6710. return;
  6711. }
  6712. var existingContent = editorState.getCurrentContent();
  6713. if (newContent !== existingContent) {
  6714. state.set('treeMap', regenerateTreeForNewBlocks(editorState, newContent.getBlockMap(), newContent.getEntityMap(), decorator));
  6715. }
  6716. state.merge(put);
  6717. });
  6718. return new EditorState(map);
  6719. };
  6720. EditorState.prototype.toJS = function toJS() {
  6721. return this.getImmutable().toJS();
  6722. };
  6723. EditorState.prototype.getAllowUndo = function getAllowUndo() {
  6724. return this.getImmutable().get('allowUndo');
  6725. };
  6726. EditorState.prototype.getCurrentContent = function getCurrentContent() {
  6727. return this.getImmutable().get('currentContent');
  6728. };
  6729. EditorState.prototype.getUndoStack = function getUndoStack() {
  6730. return this.getImmutable().get('undoStack');
  6731. };
  6732. EditorState.prototype.getRedoStack = function getRedoStack() {
  6733. return this.getImmutable().get('redoStack');
  6734. };
  6735. EditorState.prototype.getSelection = function getSelection() {
  6736. return this.getImmutable().get('selection');
  6737. };
  6738. EditorState.prototype.getDecorator = function getDecorator() {
  6739. return this.getImmutable().get('decorator');
  6740. };
  6741. EditorState.prototype.isInCompositionMode = function isInCompositionMode() {
  6742. return this.getImmutable().get('inCompositionMode');
  6743. };
  6744. EditorState.prototype.mustForceSelection = function mustForceSelection() {
  6745. return this.getImmutable().get('forceSelection');
  6746. };
  6747. EditorState.prototype.getNativelyRenderedContent = function getNativelyRenderedContent() {
  6748. return this.getImmutable().get('nativelyRenderedContent');
  6749. };
  6750. EditorState.prototype.getLastChangeType = function getLastChangeType() {
  6751. return this.getImmutable().get('lastChangeType');
  6752. };
  6753. /**
  6754. * While editing, the user may apply inline style commands with a collapsed
  6755. * cursor, intending to type text that adopts the specified style. In this
  6756. * case, we track the specified style as an "override" that takes precedence
  6757. * over the inline style of the text adjacent to the cursor.
  6758. *
  6759. * If null, there is no override in place.
  6760. */
  6761. EditorState.prototype.getInlineStyleOverride = function getInlineStyleOverride() {
  6762. return this.getImmutable().get('inlineStyleOverride');
  6763. };
  6764. EditorState.setInlineStyleOverride = function setInlineStyleOverride(editorState, inlineStyleOverride) {
  6765. return EditorState.set(editorState, { inlineStyleOverride: inlineStyleOverride });
  6766. };
  6767. /**
  6768. * Get the appropriate inline style for the editor state. If an
  6769. * override is in place, use it. Otherwise, the current style is
  6770. * based on the location of the selection state.
  6771. */
  6772. EditorState.prototype.getCurrentInlineStyle = function getCurrentInlineStyle() {
  6773. var override = this.getInlineStyleOverride();
  6774. if (override != null) {
  6775. return override;
  6776. }
  6777. var content = this.getCurrentContent();
  6778. var selection = this.getSelection();
  6779. if (selection.isCollapsed()) {
  6780. return getInlineStyleForCollapsedSelection(content, selection);
  6781. }
  6782. return getInlineStyleForNonCollapsedSelection(content, selection);
  6783. };
  6784. EditorState.prototype.getBlockTree = function getBlockTree(blockKey) {
  6785. return this.getImmutable().getIn(['treeMap', blockKey]);
  6786. };
  6787. EditorState.prototype.isSelectionAtStartOfContent = function isSelectionAtStartOfContent() {
  6788. var firstKey = this.getCurrentContent().getBlockMap().first().getKey();
  6789. return this.getSelection().hasEdgeWithin(firstKey, 0, 0);
  6790. };
  6791. EditorState.prototype.isSelectionAtEndOfContent = function isSelectionAtEndOfContent() {
  6792. var content = this.getCurrentContent();
  6793. var blockMap = content.getBlockMap();
  6794. var last = blockMap.last();
  6795. var end = last.getLength();
  6796. return this.getSelection().hasEdgeWithin(last.getKey(), end, end);
  6797. };
  6798. EditorState.prototype.getDirectionMap = function getDirectionMap() {
  6799. return this.getImmutable().get('directionMap');
  6800. };
  6801. /**
  6802. * Incorporate native DOM selection changes into the EditorState. This
  6803. * method can be used when we simply want to accept whatever the DOM
  6804. * has given us to represent selection, and we do not need to re-render
  6805. * the editor.
  6806. *
  6807. * To forcibly move the DOM selection, see `EditorState.forceSelection`.
  6808. */
  6809. EditorState.acceptSelection = function acceptSelection(editorState, selection) {
  6810. return updateSelection(editorState, selection, false);
  6811. };
  6812. /**
  6813. * At times, we need to force the DOM selection to be where we
  6814. * need it to be. This can occur when the anchor or focus nodes
  6815. * are non-text nodes, for instance. In this case, we want to trigger
  6816. * a re-render of the editor, which in turn forces selection into
  6817. * the correct place in the DOM. The `forceSelection` method
  6818. * accomplishes this.
  6819. *
  6820. * This method should be used in cases where you need to explicitly
  6821. * move the DOM selection from one place to another without a change
  6822. * in ContentState.
  6823. */
  6824. EditorState.forceSelection = function forceSelection(editorState, selection) {
  6825. if (!selection.getHasFocus()) {
  6826. selection = selection.set('hasFocus', true);
  6827. }
  6828. return updateSelection(editorState, selection, true);
  6829. };
  6830. /**
  6831. * Move selection to the end of the editor without forcing focus.
  6832. */
  6833. EditorState.moveSelectionToEnd = function moveSelectionToEnd(editorState) {
  6834. var content = editorState.getCurrentContent();
  6835. var lastBlock = content.getLastBlock();
  6836. var lastKey = lastBlock.getKey();
  6837. var length = lastBlock.getLength();
  6838. return EditorState.acceptSelection(editorState, new SelectionState_1({
  6839. anchorKey: lastKey,
  6840. anchorOffset: length,
  6841. focusKey: lastKey,
  6842. focusOffset: length,
  6843. isBackward: false
  6844. }));
  6845. };
  6846. /**
  6847. * Force focus to the end of the editor. This is useful in scenarios
  6848. * where we want to programmatically focus the input and it makes sense
  6849. * to allow the user to continue working seamlessly.
  6850. */
  6851. EditorState.moveFocusToEnd = function moveFocusToEnd(editorState) {
  6852. var afterSelectionMove = EditorState.moveSelectionToEnd(editorState);
  6853. return EditorState.forceSelection(afterSelectionMove, afterSelectionMove.getSelection());
  6854. };
  6855. /**
  6856. * Push the current ContentState onto the undo stack if it should be
  6857. * considered a boundary state, and set the provided ContentState as the
  6858. * new current content.
  6859. */
  6860. EditorState.push = function push(editorState, contentState, changeType) {
  6861. if (editorState.getCurrentContent() === contentState) {
  6862. return editorState;
  6863. }
  6864. var forceSelection = changeType !== 'insert-characters';
  6865. var directionMap = EditorBidiService_1.getDirectionMap(contentState, editorState.getDirectionMap());
  6866. if (!editorState.getAllowUndo()) {
  6867. return EditorState.set(editorState, {
  6868. currentContent: contentState,
  6869. directionMap: directionMap,
  6870. lastChangeType: changeType,
  6871. selection: contentState.getSelectionAfter(),
  6872. forceSelection: forceSelection,
  6873. inlineStyleOverride: null
  6874. });
  6875. }
  6876. var selection = editorState.getSelection();
  6877. var currentContent = editorState.getCurrentContent();
  6878. var undoStack = editorState.getUndoStack();
  6879. var newContent = contentState;
  6880. if (selection !== currentContent.getSelectionAfter() || mustBecomeBoundary(editorState, changeType)) {
  6881. undoStack = undoStack.push(currentContent);
  6882. newContent = newContent.set('selectionBefore', selection);
  6883. } else if (changeType === 'insert-characters' || changeType === 'backspace-character' || changeType === 'delete-character') {
  6884. // Preserve the previous selection.
  6885. newContent = newContent.set('selectionBefore', currentContent.getSelectionBefore());
  6886. }
  6887. var inlineStyleOverride = editorState.getInlineStyleOverride();
  6888. // Don't discard inline style overrides for the following change types:
  6889. var overrideChangeTypes = ['adjust-depth', 'change-block-type', 'split-block'];
  6890. if (overrideChangeTypes.indexOf(changeType) === -1) {
  6891. inlineStyleOverride = null;
  6892. }
  6893. var editorStateChanges = {
  6894. currentContent: newContent,
  6895. directionMap: directionMap,
  6896. undoStack: undoStack,
  6897. redoStack: Stack(),
  6898. lastChangeType: changeType,
  6899. selection: contentState.getSelectionAfter(),
  6900. forceSelection: forceSelection,
  6901. inlineStyleOverride: inlineStyleOverride
  6902. };
  6903. return EditorState.set(editorState, editorStateChanges);
  6904. };
  6905. /**
  6906. * Make the top ContentState in the undo stack the new current content and
  6907. * push the current content onto the redo stack.
  6908. */
  6909. EditorState.undo = function undo(editorState) {
  6910. if (!editorState.getAllowUndo()) {
  6911. return editorState;
  6912. }
  6913. var undoStack = editorState.getUndoStack();
  6914. var newCurrentContent = undoStack.peek();
  6915. if (!newCurrentContent) {
  6916. return editorState;
  6917. }
  6918. var currentContent = editorState.getCurrentContent();
  6919. var directionMap = EditorBidiService_1.getDirectionMap(newCurrentContent, editorState.getDirectionMap());
  6920. return EditorState.set(editorState, {
  6921. currentContent: newCurrentContent,
  6922. directionMap: directionMap,
  6923. undoStack: undoStack.shift(),
  6924. redoStack: editorState.getRedoStack().push(currentContent),
  6925. forceSelection: true,
  6926. inlineStyleOverride: null,
  6927. lastChangeType: 'undo',
  6928. nativelyRenderedContent: null,
  6929. selection: currentContent.getSelectionBefore()
  6930. });
  6931. };
  6932. /**
  6933. * Make the top ContentState in the redo stack the new current content and
  6934. * push the current content onto the undo stack.
  6935. */
  6936. EditorState.redo = function redo(editorState) {
  6937. if (!editorState.getAllowUndo()) {
  6938. return editorState;
  6939. }
  6940. var redoStack = editorState.getRedoStack();
  6941. var newCurrentContent = redoStack.peek();
  6942. if (!newCurrentContent) {
  6943. return editorState;
  6944. }
  6945. var currentContent = editorState.getCurrentContent();
  6946. var directionMap = EditorBidiService_1.getDirectionMap(newCurrentContent, editorState.getDirectionMap());
  6947. return EditorState.set(editorState, {
  6948. currentContent: newCurrentContent,
  6949. directionMap: directionMap,
  6950. undoStack: editorState.getUndoStack().push(currentContent),
  6951. redoStack: redoStack.shift(),
  6952. forceSelection: true,
  6953. inlineStyleOverride: null,
  6954. lastChangeType: 'redo',
  6955. nativelyRenderedContent: null,
  6956. selection: newCurrentContent.getSelectionAfter()
  6957. });
  6958. };
  6959. /**
  6960. * Not for public consumption.
  6961. */
  6962. function EditorState(immutable) {
  6963. _classCallCheck$7(this, EditorState);
  6964. this._immutable = immutable;
  6965. }
  6966. /**
  6967. * Not for public consumption.
  6968. */
  6969. EditorState.prototype.getImmutable = function getImmutable() {
  6970. return this._immutable;
  6971. };
  6972. return EditorState;
  6973. }();
  6974. /**
  6975. * Set the supplied SelectionState as the new current selection, and set
  6976. * the `force` flag to trigger manual selection placement by the view.
  6977. */
  6978. function updateSelection(editorState, selection, forceSelection) {
  6979. return EditorState.set(editorState, {
  6980. selection: selection,
  6981. forceSelection: forceSelection,
  6982. nativelyRenderedContent: null,
  6983. inlineStyleOverride: null
  6984. });
  6985. }
  6986. /**
  6987. * Regenerate the entire tree map for a given ContentState and decorator.
  6988. * Returns an OrderedMap that maps all available ContentBlock objects.
  6989. */
  6990. function generateNewTreeMap(contentState, decorator) {
  6991. return contentState.getBlockMap().map(function (block) {
  6992. return BlockTree_1.generate(contentState, block, decorator);
  6993. }).toOrderedMap();
  6994. }
  6995. /**
  6996. * Regenerate tree map objects for all ContentBlocks that have changed
  6997. * between the current editorState and newContent. Returns an OrderedMap
  6998. * with only changed regenerated tree map objects.
  6999. */
  7000. function regenerateTreeForNewBlocks(editorState, newBlockMap, newEntityMap, decorator) {
  7001. var contentState = editorState.getCurrentContent().set('entityMap', newEntityMap);
  7002. var prevBlockMap = contentState.getBlockMap();
  7003. var prevTreeMap = editorState.getImmutable().get('treeMap');
  7004. return prevTreeMap.merge(newBlockMap.toSeq().filter(function (block, key) {
  7005. return block !== prevBlockMap.get(key);
  7006. }).map(function (block) {
  7007. return BlockTree_1.generate(contentState, block, decorator);
  7008. }));
  7009. }
  7010. /**
  7011. * Generate tree map objects for a new decorator object, preserving any
  7012. * decorations that are unchanged from the previous decorator.
  7013. *
  7014. * Note that in order for this to perform optimally, decoration Lists for
  7015. * decorators should be preserved when possible to allow for direct immutable
  7016. * List comparison.
  7017. */
  7018. function regenerateTreeForNewDecorator(content, blockMap, previousTreeMap, decorator, existingDecorator) {
  7019. return previousTreeMap.merge(blockMap.toSeq().filter(function (block) {
  7020. return decorator.getDecorations(block, content) !== existingDecorator.getDecorations(block, content);
  7021. }).map(function (block) {
  7022. return BlockTree_1.generate(content, block, decorator);
  7023. }));
  7024. }
  7025. /**
  7026. * Return whether a change should be considered a boundary state, given
  7027. * the previous change type. Allows us to discard potential boundary states
  7028. * during standard typing or deletion behavior.
  7029. */
  7030. function mustBecomeBoundary(editorState, changeType) {
  7031. var lastChangeType = editorState.getLastChangeType();
  7032. return changeType !== lastChangeType || changeType !== 'insert-characters' && changeType !== 'backspace-character' && changeType !== 'delete-character';
  7033. }
  7034. function getInlineStyleForCollapsedSelection(content, selection) {
  7035. var startKey = selection.getStartKey();
  7036. var startOffset = selection.getStartOffset();
  7037. var startBlock = content.getBlockForKey(startKey);
  7038. // If the cursor is not at the start of the block, look backward to
  7039. // preserve the style of the preceding character.
  7040. if (startOffset > 0) {
  7041. return startBlock.getInlineStyleAt(startOffset - 1);
  7042. }
  7043. // The caret is at position zero in this block. If the block has any
  7044. // text at all, use the style of the first character.
  7045. if (startBlock.getLength()) {
  7046. return startBlock.getInlineStyleAt(0);
  7047. }
  7048. // Otherwise, look upward in the document to find the closest character.
  7049. return lookUpwardForInlineStyle(content, startKey);
  7050. }
  7051. function getInlineStyleForNonCollapsedSelection(content, selection) {
  7052. var startKey = selection.getStartKey();
  7053. var startOffset = selection.getStartOffset();
  7054. var startBlock = content.getBlockForKey(startKey);
  7055. // If there is a character just inside the selection, use its style.
  7056. if (startOffset < startBlock.getLength()) {
  7057. return startBlock.getInlineStyleAt(startOffset);
  7058. }
  7059. // Check if the selection at the end of a non-empty block. Use the last
  7060. // style in the block.
  7061. if (startOffset > 0) {
  7062. return startBlock.getInlineStyleAt(startOffset - 1);
  7063. }
  7064. // Otherwise, look upward in the document to find the closest character.
  7065. return lookUpwardForInlineStyle(content, startKey);
  7066. }
  7067. function lookUpwardForInlineStyle(content, fromKey) {
  7068. var lastNonEmpty = content.getBlockMap().reverse().skipUntil(function (_, k) {
  7069. return k === fromKey;
  7070. }).skip(1).skipUntil(function (block, _) {
  7071. return block.getLength();
  7072. }).first();
  7073. if (lastNonEmpty) return lastNonEmpty.getInlineStyleAt(lastNonEmpty.getLength() - 1);
  7074. return OrderedSet$4();
  7075. }
  7076. var EditorState_1 = EditorState;
  7077. var OrderedMap$3 = immutable.OrderedMap,
  7078. List$7 = immutable.List;
  7079. var transformBlock$2 = function transformBlock(key, blockMap, func) {
  7080. if (!key) {
  7081. return;
  7082. }
  7083. var block = blockMap.get(key);
  7084. if (!block) {
  7085. return;
  7086. }
  7087. blockMap.set(key, func(block));
  7088. };
  7089. var updateBlockMapLinks$3 = function updateBlockMapLinks(blockMap, originalBlockToBeMoved, originalTargetBlock, insertionMode, isExperimentalTreeBlock) {
  7090. if (!isExperimentalTreeBlock) {
  7091. return blockMap;
  7092. }
  7093. // possible values of 'insertionMode' are: 'after', 'before'
  7094. var isInsertedAfterTarget = insertionMode === 'after';
  7095. var originalBlockKey = originalBlockToBeMoved.getKey();
  7096. var originalTargetKey = originalTargetBlock.getKey();
  7097. var originalParentKey = originalBlockToBeMoved.getParentKey();
  7098. var originalNextSiblingKey = originalBlockToBeMoved.getNextSiblingKey();
  7099. var originalPrevSiblingKey = originalBlockToBeMoved.getPrevSiblingKey();
  7100. var newParentKey = originalTargetBlock.getParentKey();
  7101. var newNextSiblingKey = isInsertedAfterTarget ? originalTargetBlock.getNextSiblingKey() : originalTargetKey;
  7102. var newPrevSiblingKey = isInsertedAfterTarget ? originalTargetKey : originalTargetBlock.getPrevSiblingKey();
  7103. return blockMap.withMutations(function (blocks) {
  7104. // update old parent
  7105. transformBlock$2(originalParentKey, blocks, function (block) {
  7106. var parentChildrenList = block.getChildKeys();
  7107. return block.merge({
  7108. children: parentChildrenList['delete'](parentChildrenList.indexOf(originalBlockKey))
  7109. });
  7110. });
  7111. // update old prev
  7112. transformBlock$2(originalPrevSiblingKey, blocks, function (block) {
  7113. return block.merge({
  7114. nextSibling: originalNextSiblingKey
  7115. });
  7116. });
  7117. // update old next
  7118. transformBlock$2(originalNextSiblingKey, blocks, function (block) {
  7119. return block.merge({
  7120. prevSibling: originalPrevSiblingKey
  7121. });
  7122. });
  7123. // update new next
  7124. transformBlock$2(newNextSiblingKey, blocks, function (block) {
  7125. return block.merge({
  7126. prevSibling: originalBlockKey
  7127. });
  7128. });
  7129. // update new prev
  7130. transformBlock$2(newPrevSiblingKey, blocks, function (block) {
  7131. return block.merge({
  7132. nextSibling: originalBlockKey
  7133. });
  7134. });
  7135. // update new parent
  7136. transformBlock$2(newParentKey, blocks, function (block) {
  7137. var newParentChildrenList = block.getChildKeys();
  7138. var targetBlockIndex = newParentChildrenList.indexOf(originalTargetKey);
  7139. var insertionIndex = isInsertedAfterTarget ? targetBlockIndex + 1 : targetBlockIndex !== 0 ? targetBlockIndex - 1 : 0;
  7140. var newChildrenArray = newParentChildrenList.toArray();
  7141. newChildrenArray.splice(insertionIndex, 0, originalBlockKey);
  7142. return block.merge({
  7143. children: List$7(newChildrenArray)
  7144. });
  7145. });
  7146. // update block
  7147. transformBlock$2(originalBlockKey, blocks, function (block) {
  7148. return block.merge({
  7149. nextSibling: newNextSiblingKey,
  7150. prevSibling: newPrevSiblingKey,
  7151. parent: newParentKey
  7152. });
  7153. });
  7154. });
  7155. };
  7156. var moveBlockInContentState = function moveBlockInContentState(contentState, blockToBeMoved, targetBlock, insertionMode) {
  7157. !(insertionMode !== 'replace') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Replacing blocks is not supported.') : invariant_1(false) : void 0;
  7158. var targetKey = targetBlock.getKey();
  7159. var blockKey = blockToBeMoved.getKey();
  7160. !(blockKey !== targetKey) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Block cannot be moved next to itself.') : invariant_1(false) : void 0;
  7161. var blockMap = contentState.getBlockMap();
  7162. var isExperimentalTreeBlock = blockToBeMoved instanceof ContentBlockNode_1;
  7163. var blocksToBeMoved = [blockToBeMoved];
  7164. var blockMapWithoutBlocksToBeMoved = blockMap['delete'](blockKey);
  7165. if (isExperimentalTreeBlock) {
  7166. blocksToBeMoved = [];
  7167. blockMapWithoutBlocksToBeMoved = blockMap.withMutations(function (blocks) {
  7168. var nextSiblingKey = blockToBeMoved.getNextSiblingKey();
  7169. var nextDelimiterBlockKey = getNextDelimiterBlockKey_1(blockToBeMoved, blocks);
  7170. blocks.toSeq().skipUntil(function (block) {
  7171. return block.getKey() === blockKey;
  7172. }).takeWhile(function (block) {
  7173. var key = block.getKey();
  7174. var isBlockToBeMoved = key === blockKey;
  7175. var hasNextSiblingAndIsNotNextSibling = nextSiblingKey && key !== nextSiblingKey;
  7176. var doesNotHaveNextSiblingAndIsNotDelimiter = !nextSiblingKey && block.getParentKey() && (!nextDelimiterBlockKey || key !== nextDelimiterBlockKey);
  7177. return !!(isBlockToBeMoved || hasNextSiblingAndIsNotNextSibling || doesNotHaveNextSiblingAndIsNotDelimiter);
  7178. }).forEach(function (block) {
  7179. blocksToBeMoved.push(block);
  7180. blocks['delete'](block.getKey());
  7181. });
  7182. });
  7183. }
  7184. var blocksBefore = blockMapWithoutBlocksToBeMoved.toSeq().takeUntil(function (v) {
  7185. return v === targetBlock;
  7186. });
  7187. var blocksAfter = blockMapWithoutBlocksToBeMoved.toSeq().skipUntil(function (v) {
  7188. return v === targetBlock;
  7189. }).skip(1);
  7190. var slicedBlocks = blocksToBeMoved.map(function (block) {
  7191. return [block.getKey(), block];
  7192. });
  7193. var newBlocks = OrderedMap$3();
  7194. if (insertionMode === 'before') {
  7195. var blockBefore = contentState.getBlockBefore(targetKey);
  7196. !(!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;
  7197. newBlocks = blocksBefore.concat([].concat(slicedBlocks, [[targetKey, targetBlock]]), blocksAfter).toOrderedMap();
  7198. } else if (insertionMode === 'after') {
  7199. var blockAfter = contentState.getBlockAfter(targetKey);
  7200. !(!blockAfter || blockAfter.getKey() !== blockKey) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Block cannot be moved next to itself.') : invariant_1(false) : void 0;
  7201. newBlocks = blocksBefore.concat([[targetKey, targetBlock]].concat(slicedBlocks), blocksAfter).toOrderedMap();
  7202. }
  7203. return contentState.merge({
  7204. blockMap: updateBlockMapLinks$3(newBlocks, blockToBeMoved, targetBlock, insertionMode, isExperimentalTreeBlock),
  7205. selectionBefore: contentState.getSelectionAfter(),
  7206. selectionAfter: contentState.getSelectionAfter().merge({
  7207. anchorKey: blockKey,
  7208. focusKey: blockKey
  7209. })
  7210. });
  7211. };
  7212. var moveBlockInContentState_1 = moveBlockInContentState;
  7213. var ContentBlockRecord$1 = ContentBlock_1;
  7214. var List$8 = immutable.List,
  7215. Repeat$5 = immutable.Repeat;
  7216. var AtomicBlockUtils = {
  7217. insertAtomicBlock: function insertAtomicBlock(editorState, entityKey, character) {
  7218. var contentState = editorState.getCurrentContent();
  7219. var selectionState = editorState.getSelection();
  7220. var afterRemoval = DraftModifier_1.removeRange(contentState, selectionState, 'backward');
  7221. var targetSelection = afterRemoval.getSelectionAfter();
  7222. var afterSplit = DraftModifier_1.splitBlock(afterRemoval, targetSelection);
  7223. var insertionTarget = afterSplit.getSelectionAfter();
  7224. var asAtomicBlock = DraftModifier_1.setBlockType(afterSplit, insertionTarget, 'atomic');
  7225. var charData = CharacterMetadata_1.create({ entity: entityKey });
  7226. var atomicBlockConfig = {
  7227. key: generateRandomKey_1(),
  7228. type: 'atomic',
  7229. text: character,
  7230. characterList: List$8(Repeat$5(charData, character.length))
  7231. };
  7232. var atomicDividerBlockConfig = {
  7233. key: generateRandomKey_1(),
  7234. type: 'unstyled'
  7235. };
  7236. var fragmentArray = [new ContentBlockRecord$1(atomicBlockConfig), new ContentBlockRecord$1(atomicDividerBlockConfig)];
  7237. var fragment = BlockMapBuilder_1.createFromArray(fragmentArray);
  7238. var withAtomicBlock = DraftModifier_1.replaceWithFragment(asAtomicBlock, insertionTarget, fragment);
  7239. var newContent = withAtomicBlock.merge({
  7240. selectionBefore: selectionState,
  7241. selectionAfter: withAtomicBlock.getSelectionAfter().set('hasFocus', true)
  7242. });
  7243. return EditorState_1.push(editorState, newContent, 'insert-fragment');
  7244. },
  7245. moveAtomicBlock: function moveAtomicBlock(editorState, atomicBlock, targetRange, insertionMode) {
  7246. var contentState = editorState.getCurrentContent();
  7247. var selectionState = editorState.getSelection();
  7248. var withMovedAtomicBlock = void 0;
  7249. if (insertionMode === 'before' || insertionMode === 'after') {
  7250. var targetBlock = contentState.getBlockForKey(insertionMode === 'before' ? targetRange.getStartKey() : targetRange.getEndKey());
  7251. withMovedAtomicBlock = moveBlockInContentState_1(contentState, atomicBlock, targetBlock, insertionMode);
  7252. } else {
  7253. var afterRemoval = DraftModifier_1.removeRange(contentState, targetRange, 'backward');
  7254. var selectionAfterRemoval = afterRemoval.getSelectionAfter();
  7255. var _targetBlock = afterRemoval.getBlockForKey(selectionAfterRemoval.getFocusKey());
  7256. if (selectionAfterRemoval.getStartOffset() === 0) {
  7257. withMovedAtomicBlock = moveBlockInContentState_1(afterRemoval, atomicBlock, _targetBlock, 'before');
  7258. } else if (selectionAfterRemoval.getEndOffset() === _targetBlock.getLength()) {
  7259. withMovedAtomicBlock = moveBlockInContentState_1(afterRemoval, atomicBlock, _targetBlock, 'after');
  7260. } else {
  7261. var afterSplit = DraftModifier_1.splitBlock(afterRemoval, selectionAfterRemoval);
  7262. var selectionAfterSplit = afterSplit.getSelectionAfter();
  7263. var _targetBlock2 = afterSplit.getBlockForKey(selectionAfterSplit.getFocusKey());
  7264. withMovedAtomicBlock = moveBlockInContentState_1(afterSplit, atomicBlock, _targetBlock2, 'before');
  7265. }
  7266. }
  7267. var newContent = withMovedAtomicBlock.merge({
  7268. selectionBefore: selectionState,
  7269. selectionAfter: withMovedAtomicBlock.getSelectionAfter().set('hasFocus', true)
  7270. });
  7271. return EditorState_1.push(editorState, newContent, 'move-block');
  7272. }
  7273. };
  7274. var AtomicBlockUtils_1 = AtomicBlockUtils;
  7275. function _classCallCheck$8(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7276. var List$9 = immutable.List;
  7277. var DELIMITER = '.';
  7278. /**
  7279. * A CompositeDraftDecorator traverses through a list of DraftDecorator
  7280. * instances to identify sections of a ContentBlock that should be rendered
  7281. * in a "decorated" manner. For example, hashtags, mentions, and links may
  7282. * be intended to stand out visually, be rendered as anchors, etc.
  7283. *
  7284. * The list of decorators supplied to the constructor will be used in the
  7285. * order they are provided. This allows the caller to specify a priority for
  7286. * string matching, in case of match collisions among decorators.
  7287. *
  7288. * For instance, I may have a link with a `#` in its text. Though this section
  7289. * of text may match our hashtag decorator, it should not be treated as a
  7290. * hashtag. I should therefore list my link DraftDecorator
  7291. * before my hashtag DraftDecorator when constructing this composite
  7292. * decorator instance.
  7293. *
  7294. * Thus, when a collision like this is encountered, the earlier match is
  7295. * preserved and the new match is discarded.
  7296. */
  7297. var CompositeDraftDecorator = function () {
  7298. function CompositeDraftDecorator(decorators) {
  7299. _classCallCheck$8(this, CompositeDraftDecorator);
  7300. // Copy the decorator array, since we use this array order to determine
  7301. // precedence of decoration matching. If the array is mutated externally,
  7302. // we don't want to be affected here.
  7303. this._decorators = decorators.slice();
  7304. }
  7305. CompositeDraftDecorator.prototype.getDecorations = function getDecorations(block, contentState) {
  7306. var decorations = Array(block.getText().length).fill(null);
  7307. this._decorators.forEach(function ( /*object*/decorator, /*number*/ii) {
  7308. var counter = 0;
  7309. var strategy = decorator.strategy;
  7310. var callback = function callback( /*number*/start, /*number*/end) {
  7311. // Find out if any of our matching range is already occupied
  7312. // by another decorator. If so, discard the match. Otherwise, store
  7313. // the component key for rendering.
  7314. if (canOccupySlice(decorations, start, end)) {
  7315. occupySlice(decorations, start, end, ii + DELIMITER + counter);
  7316. counter++;
  7317. }
  7318. };
  7319. strategy(block, callback, contentState);
  7320. });
  7321. return List$9(decorations);
  7322. };
  7323. CompositeDraftDecorator.prototype.getComponentForKey = function getComponentForKey(key) {
  7324. var componentKey = parseInt(key.split(DELIMITER)[0], 10);
  7325. return this._decorators[componentKey].component;
  7326. };
  7327. CompositeDraftDecorator.prototype.getPropsForKey = function getPropsForKey(key) {
  7328. var componentKey = parseInt(key.split(DELIMITER)[0], 10);
  7329. return this._decorators[componentKey].props;
  7330. };
  7331. return CompositeDraftDecorator;
  7332. }();
  7333. /**
  7334. * Determine whether we can occupy the specified slice of the decorations
  7335. * array.
  7336. */
  7337. function canOccupySlice(decorations, start, end) {
  7338. for (var ii = start; ii < end; ii++) {
  7339. if (decorations[ii] != null) {
  7340. return false;
  7341. }
  7342. }
  7343. return true;
  7344. }
  7345. /**
  7346. * Splice the specified component into our decoration array at the desired
  7347. * range.
  7348. */
  7349. function occupySlice(targetArr, start, end, componentKey) {
  7350. for (var ii = start; ii < end; ii++) {
  7351. targetArr[ii] = componentKey;
  7352. }
  7353. }
  7354. var CompositeDraftDecorator_1 = CompositeDraftDecorator;
  7355. /**
  7356. * Copyright (c) 2013-present, Facebook, Inc.
  7357. *
  7358. * This source code is licensed under the MIT license found in the
  7359. * LICENSE file in the root directory of this source tree.
  7360. *
  7361. */
  7362. /**
  7363. * This function is used to mark string literals representing CSS class names
  7364. * so that they can be transformed statically. This allows for modularization
  7365. * and minification of CSS class names.
  7366. *
  7367. * In static_upstream, this function is actually implemented, but it should
  7368. * eventually be replaced with something more descriptive, and the transform
  7369. * that is used in the main stack should be ported for use elsewhere.
  7370. *
  7371. * @param string|object className to modularize, or an object of key/values.
  7372. * In the object case, the values are conditions that
  7373. * determine if the className keys should be included.
  7374. * @param [string ...] Variable list of classNames in the string case.
  7375. * @return string Renderable space-separated CSS className.
  7376. */
  7377. function cx(classNames) {
  7378. if (typeof classNames == 'object') {
  7379. return Object.keys(classNames).filter(function (className) {
  7380. return classNames[className];
  7381. }).map(replace).join(' ');
  7382. }
  7383. return Array.prototype.map.call(arguments, replace).join(' ');
  7384. }
  7385. function replace(str) {
  7386. return str.replace(/\//g, '-');
  7387. }
  7388. var cx_1 = cx;
  7389. var Map$9 = immutable.Map;
  7390. var UL_WRAP = React.createElement('ul', { className: cx_1('public/DraftStyleDefault/ul') });
  7391. var OL_WRAP = React.createElement('ol', { className: cx_1('public/DraftStyleDefault/ol') });
  7392. var PRE_WRAP = React.createElement('pre', { className: cx_1('public/DraftStyleDefault/pre') });
  7393. var DefaultDraftBlockRenderMap = Map$9({
  7394. 'header-one': {
  7395. element: 'h1'
  7396. },
  7397. 'header-two': {
  7398. element: 'h2'
  7399. },
  7400. 'header-three': {
  7401. element: 'h3'
  7402. },
  7403. 'header-four': {
  7404. element: 'h4'
  7405. },
  7406. 'header-five': {
  7407. element: 'h5'
  7408. },
  7409. 'header-six': {
  7410. element: 'h6'
  7411. },
  7412. 'unordered-list-item': {
  7413. element: 'li',
  7414. wrapper: UL_WRAP
  7415. },
  7416. 'ordered-list-item': {
  7417. element: 'li',
  7418. wrapper: OL_WRAP
  7419. },
  7420. blockquote: {
  7421. element: 'blockquote'
  7422. },
  7423. atomic: {
  7424. element: 'figure'
  7425. },
  7426. 'code-block': {
  7427. element: 'pre',
  7428. wrapper: PRE_WRAP
  7429. },
  7430. unstyled: {
  7431. element: 'div',
  7432. aliasedElements: ['p']
  7433. }
  7434. });
  7435. var DefaultDraftBlockRenderMap_1 = DefaultDraftBlockRenderMap;
  7436. /**
  7437. * Copyright (c) 2013-present, Facebook, Inc.
  7438. * All rights reserved.
  7439. *
  7440. * This source code is licensed under the BSD-style license found in the
  7441. * LICENSE file in the root directory of this source tree. An additional grant
  7442. * of patent rights can be found in the PATENTS file in the same directory.
  7443. *
  7444. * @providesModule DefaultDraftInlineStyle
  7445. * @format
  7446. *
  7447. */
  7448. var DefaultDraftInlineStyle = {
  7449. BOLD: {
  7450. fontWeight: 'bold'
  7451. },
  7452. CODE: {
  7453. fontFamily: 'monospace',
  7454. wordWrap: 'break-word'
  7455. },
  7456. ITALIC: {
  7457. fontStyle: 'italic'
  7458. },
  7459. STRIKETHROUGH: {
  7460. textDecoration: 'line-through'
  7461. },
  7462. UNDERLINE: {
  7463. textDecoration: 'underline'
  7464. }
  7465. };
  7466. /**
  7467. * Copyright (c) 2013-present, Facebook, Inc.
  7468. *
  7469. * This source code is licensed under the MIT license found in the
  7470. * LICENSE file in the root directory of this source tree.
  7471. *
  7472. */
  7473. var Keys = {
  7474. BACKSPACE: 8,
  7475. TAB: 9,
  7476. RETURN: 13,
  7477. ALT: 18,
  7478. ESC: 27,
  7479. SPACE: 32,
  7480. PAGE_UP: 33,
  7481. PAGE_DOWN: 34,
  7482. END: 35,
  7483. HOME: 36,
  7484. LEFT: 37,
  7485. UP: 38,
  7486. RIGHT: 39,
  7487. DOWN: 40,
  7488. DELETE: 46,
  7489. COMMA: 188,
  7490. PERIOD: 190,
  7491. A: 65,
  7492. Z: 90,
  7493. ZERO: 48,
  7494. NUMPAD_0: 96,
  7495. NUMPAD_9: 105
  7496. };
  7497. /**
  7498. * Copyright (c) 2013-present, Facebook, Inc.
  7499. * All rights reserved.
  7500. *
  7501. * This source code is licensed under the BSD-style license found in the
  7502. * LICENSE file in the root directory of this source tree. An additional grant
  7503. * of patent rights can be found in the PATENTS file in the same directory.
  7504. *
  7505. * @providesModule getEntityKeyForSelection
  7506. * @format
  7507. *
  7508. */
  7509. /**
  7510. * Return the entity key that should be used when inserting text for the
  7511. * specified target selection, only if the entity is `MUTABLE`. `IMMUTABLE`
  7512. * and `SEGMENTED` entities should not be used for insertion behavior.
  7513. */
  7514. function getEntityKeyForSelection(contentState, targetSelection) {
  7515. var entityKey;
  7516. if (targetSelection.isCollapsed()) {
  7517. var key = targetSelection.getAnchorKey();
  7518. var offset = targetSelection.getAnchorOffset();
  7519. if (offset > 0) {
  7520. entityKey = contentState.getBlockForKey(key).getEntityAt(offset - 1);
  7521. if (entityKey !== contentState.getBlockForKey(key).getEntityAt(offset)) {
  7522. return null;
  7523. }
  7524. return filterKey(contentState.getEntityMap(), entityKey);
  7525. }
  7526. return null;
  7527. }
  7528. var startKey = targetSelection.getStartKey();
  7529. var startOffset = targetSelection.getStartOffset();
  7530. var startBlock = contentState.getBlockForKey(startKey);
  7531. entityKey = startOffset === startBlock.getLength() ? null : startBlock.getEntityAt(startOffset);
  7532. return filterKey(contentState.getEntityMap(), entityKey);
  7533. }
  7534. /**
  7535. * Determine whether an entity key corresponds to a `MUTABLE` entity. If so,
  7536. * return it. If not, return null.
  7537. */
  7538. function filterKey(entityMap, entityKey) {
  7539. if (entityKey) {
  7540. var entity = entityMap.__get(entityKey);
  7541. return entity.getMutability() === 'MUTABLE' ? entityKey : null;
  7542. }
  7543. return null;
  7544. }
  7545. var getEntityKeyForSelection_1 = getEntityKeyForSelection;
  7546. /**
  7547. * Copyright (c) 2013-present, Facebook, Inc.
  7548. * All rights reserved.
  7549. *
  7550. * This source code is licensed under the BSD-style license found in the
  7551. * LICENSE file in the root directory of this source tree. An additional grant
  7552. * of patent rights can be found in the PATENTS file in the same directory.
  7553. *
  7554. * @providesModule isEventHandled
  7555. * @format
  7556. *
  7557. */
  7558. /**
  7559. * Utility method for determining whether or not the value returned
  7560. * from a handler indicates that it was handled.
  7561. */
  7562. function isEventHandled(value) {
  7563. return value === 'handled' || value === true;
  7564. }
  7565. var isEventHandled_1 = isEventHandled;
  7566. /**
  7567. * Copyright (c) 2013-present, Facebook, Inc.
  7568. * All rights reserved.
  7569. *
  7570. * This source code is licensed under the BSD-style license found in the
  7571. * LICENSE file in the root directory of this source tree. An additional grant
  7572. * of patent rights can be found in the PATENTS file in the same directory.
  7573. *
  7574. * @providesModule isSelectionAtLeafStart
  7575. * @format
  7576. *
  7577. */
  7578. function isSelectionAtLeafStart(editorState) {
  7579. var selection = editorState.getSelection();
  7580. var anchorKey = selection.getAnchorKey();
  7581. var blockTree = editorState.getBlockTree(anchorKey);
  7582. var offset = selection.getStartOffset();
  7583. var isAtStart = false;
  7584. blockTree.some(function (leafSet) {
  7585. if (offset === leafSet.get('start')) {
  7586. isAtStart = true;
  7587. return true;
  7588. }
  7589. if (offset < leafSet.get('end')) {
  7590. return leafSet.get('leaves').some(function (leaf) {
  7591. var leafStart = leaf.get('start');
  7592. if (offset === leafStart) {
  7593. isAtStart = true;
  7594. return true;
  7595. }
  7596. return false;
  7597. });
  7598. }
  7599. return false;
  7600. });
  7601. return isAtStart;
  7602. }
  7603. var isSelectionAtLeafStart_1 = isSelectionAtLeafStart;
  7604. /**
  7605. * Millisecond delay to allow `compositionstart` to fire again upon
  7606. * `compositionend`.
  7607. *
  7608. * This is used for Korean input to ensure that typing can continue without
  7609. * the editor trying to render too quickly. More specifically, Safari 7.1+
  7610. * triggers `compositionstart` a little slower than Chrome/FF, which
  7611. * leads to composed characters being resolved and re-render occurring
  7612. * sooner than we want.
  7613. */
  7614. var RESOLVE_DELAY = 20;
  7615. /**
  7616. * A handful of variables used to track the current composition and its
  7617. * resolution status. These exist at the module level because it is not
  7618. * possible to have compositions occurring in multiple editors simultaneously,
  7619. * and it simplifies state management with respect to the DraftEditor component.
  7620. */
  7621. var resolved = false;
  7622. var stillComposing = false;
  7623. var textInputData = '';
  7624. var DraftEditorCompositionHandler = {
  7625. onBeforeInput: function onBeforeInput(editor, e) {
  7626. textInputData = (textInputData || '') + e.data;
  7627. },
  7628. /**
  7629. * A `compositionstart` event has fired while we're still in composition
  7630. * mode. Continue the current composition session to prevent a re-render.
  7631. */
  7632. onCompositionStart: function onCompositionStart(editor) {
  7633. stillComposing = true;
  7634. },
  7635. /**
  7636. * Attempt to end the current composition session.
  7637. *
  7638. * Defer handling because browser will still insert the chars into active
  7639. * element after `compositionend`. If a `compositionstart` event fires
  7640. * before `resolveComposition` executes, our composition session will
  7641. * continue.
  7642. *
  7643. * The `resolved` flag is useful because certain IME interfaces fire the
  7644. * `compositionend` event multiple times, thus queueing up multiple attempts
  7645. * at handling the composition. Since handling the same composition event
  7646. * twice could break the DOM, we only use the first event. Example: Arabic
  7647. * Google Input Tools on Windows 8.1 fires `compositionend` three times.
  7648. */
  7649. onCompositionEnd: function onCompositionEnd(editor) {
  7650. resolved = false;
  7651. stillComposing = false;
  7652. setTimeout(function () {
  7653. if (!resolved) {
  7654. DraftEditorCompositionHandler.resolveComposition(editor);
  7655. }
  7656. }, RESOLVE_DELAY);
  7657. },
  7658. /**
  7659. * In Safari, keydown events may fire when committing compositions. If
  7660. * the arrow keys are used to commit, prevent default so that the cursor
  7661. * doesn't move, otherwise it will jump back noticeably on re-render.
  7662. */
  7663. onKeyDown: function onKeyDown(editor, e) {
  7664. if (!stillComposing) {
  7665. // If a keydown event is received after compositionend but before the
  7666. // 20ms timer expires (ex: type option-E then backspace, or type A then
  7667. // backspace in 2-Set Korean), we should immediately resolve the
  7668. // composition and reinterpret the key press in edit mode.
  7669. DraftEditorCompositionHandler.resolveComposition(editor);
  7670. editor._onKeyDown(e);
  7671. return;
  7672. }
  7673. if (e.which === Keys.RIGHT || e.which === Keys.LEFT) {
  7674. e.preventDefault();
  7675. }
  7676. },
  7677. /**
  7678. * Keypress events may fire when committing compositions. In Firefox,
  7679. * pressing RETURN commits the composition and inserts extra newline
  7680. * characters that we do not want. `preventDefault` allows the composition
  7681. * to be committed while preventing the extra characters.
  7682. */
  7683. onKeyPress: function onKeyPress(editor, e) {
  7684. if (e.which === Keys.RETURN) {
  7685. e.preventDefault();
  7686. }
  7687. },
  7688. /**
  7689. * Attempt to insert composed characters into the document.
  7690. *
  7691. * If we are still in a composition session, do nothing. Otherwise, insert
  7692. * the characters into the document and terminate the composition session.
  7693. *
  7694. * If no characters were composed -- for instance, the user
  7695. * deleted all composed characters and committed nothing new --
  7696. * force a re-render. We also re-render when the composition occurs
  7697. * at the beginning of a leaf, to ensure that if the browser has
  7698. * created a new text node for the composition, we will discard it.
  7699. *
  7700. * Resetting innerHTML will move focus to the beginning of the editor,
  7701. * so we update to force it back to the correct place.
  7702. */
  7703. resolveComposition: function resolveComposition(editor) {
  7704. if (stillComposing) {
  7705. return;
  7706. }
  7707. resolved = true;
  7708. var composedChars = textInputData;
  7709. textInputData = '';
  7710. var editorState = EditorState_1.set(editor._latestEditorState, {
  7711. inCompositionMode: false
  7712. });
  7713. var currentStyle = editorState.getCurrentInlineStyle();
  7714. var entityKey = getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection());
  7715. var mustReset = !composedChars || isSelectionAtLeafStart_1(editorState) || currentStyle.size > 0 || entityKey !== null;
  7716. if (mustReset) {
  7717. editor.restoreEditorDOM();
  7718. }
  7719. editor.exitCurrentMode();
  7720. if (composedChars) {
  7721. // If characters have been composed, re-rendering with the update
  7722. // is sufficient to reset the editor.
  7723. var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), composedChars, currentStyle, entityKey);
  7724. editor.update(EditorState_1.push(editorState, contentState, 'insert-characters'));
  7725. return;
  7726. }
  7727. if (mustReset) {
  7728. editor.update(EditorState_1.set(editorState, {
  7729. nativelyRenderedContent: null,
  7730. forceSelection: true
  7731. }));
  7732. }
  7733. }
  7734. };
  7735. var DraftEditorCompositionHandler_1 = DraftEditorCompositionHandler;
  7736. var uaParser = createCommonjsModule(function (module, exports) {
  7737. /*!
  7738. * UAParser.js v0.7.21
  7739. * Lightweight JavaScript-based User-Agent string parser
  7740. * https://github.com/faisalman/ua-parser-js
  7741. *
  7742. * Copyright © 2012-2019 Faisal Salman <f@faisalman.com>
  7743. * Licensed under MIT License
  7744. */
  7745. (function (window, undefined$1) {
  7746. //////////////
  7747. // Constants
  7748. /////////////
  7749. var LIBVERSION = '0.7.21',
  7750. EMPTY = '',
  7751. UNKNOWN = '?',
  7752. FUNC_TYPE = 'function',
  7753. OBJ_TYPE = 'object',
  7754. STR_TYPE = 'string',
  7755. MAJOR = 'major', // deprecated
  7756. MODEL = 'model',
  7757. NAME = 'name',
  7758. TYPE = 'type',
  7759. VENDOR = 'vendor',
  7760. VERSION = 'version',
  7761. ARCHITECTURE= 'architecture',
  7762. CONSOLE = 'console',
  7763. MOBILE = 'mobile',
  7764. TABLET = 'tablet',
  7765. SMARTTV = 'smarttv',
  7766. WEARABLE = 'wearable',
  7767. EMBEDDED = 'embedded';
  7768. ///////////
  7769. // Helper
  7770. //////////
  7771. var util = {
  7772. extend : function (regexes, extensions) {
  7773. var mergedRegexes = {};
  7774. for (var i in regexes) {
  7775. if (extensions[i] && extensions[i].length % 2 === 0) {
  7776. mergedRegexes[i] = extensions[i].concat(regexes[i]);
  7777. } else {
  7778. mergedRegexes[i] = regexes[i];
  7779. }
  7780. }
  7781. return mergedRegexes;
  7782. },
  7783. has : function (str1, str2) {
  7784. if (typeof str1 === "string") {
  7785. return str2.toLowerCase().indexOf(str1.toLowerCase()) !== -1;
  7786. } else {
  7787. return false;
  7788. }
  7789. },
  7790. lowerize : function (str) {
  7791. return str.toLowerCase();
  7792. },
  7793. major : function (version) {
  7794. return typeof(version) === STR_TYPE ? version.replace(/[^\d\.]/g,'').split(".")[0] : undefined$1;
  7795. },
  7796. trim : function (str) {
  7797. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  7798. }
  7799. };
  7800. ///////////////
  7801. // Map helper
  7802. //////////////
  7803. var mapper = {
  7804. rgx : function (ua, arrays) {
  7805. var i = 0, j, k, p, q, matches, match;
  7806. // loop through all regexes maps
  7807. while (i < arrays.length && !matches) {
  7808. var regex = arrays[i], // even sequence (0,2,4,..)
  7809. props = arrays[i + 1]; // odd sequence (1,3,5,..)
  7810. j = k = 0;
  7811. // try matching uastring with regexes
  7812. while (j < regex.length && !matches) {
  7813. matches = regex[j++].exec(ua);
  7814. if (!!matches) {
  7815. for (p = 0; p < props.length; p++) {
  7816. match = matches[++k];
  7817. q = props[p];
  7818. // check if given property is actually array
  7819. if (typeof q === OBJ_TYPE && q.length > 0) {
  7820. if (q.length == 2) {
  7821. if (typeof q[1] == FUNC_TYPE) {
  7822. // assign modified match
  7823. this[q[0]] = q[1].call(this, match);
  7824. } else {
  7825. // assign given value, ignore regex match
  7826. this[q[0]] = q[1];
  7827. }
  7828. } else if (q.length == 3) {
  7829. // check whether function or regex
  7830. if (typeof q[1] === FUNC_TYPE && !(q[1].exec && q[1].test)) {
  7831. // call function (usually string mapper)
  7832. this[q[0]] = match ? q[1].call(this, match, q[2]) : undefined$1;
  7833. } else {
  7834. // sanitize match using given regex
  7835. this[q[0]] = match ? match.replace(q[1], q[2]) : undefined$1;
  7836. }
  7837. } else if (q.length == 4) {
  7838. this[q[0]] = match ? q[3].call(this, match.replace(q[1], q[2])) : undefined$1;
  7839. }
  7840. } else {
  7841. this[q] = match ? match : undefined$1;
  7842. }
  7843. }
  7844. }
  7845. }
  7846. i += 2;
  7847. }
  7848. },
  7849. str : function (str, map) {
  7850. for (var i in map) {
  7851. // check if array
  7852. if (typeof map[i] === OBJ_TYPE && map[i].length > 0) {
  7853. for (var j = 0; j < map[i].length; j++) {
  7854. if (util.has(map[i][j], str)) {
  7855. return (i === UNKNOWN) ? undefined$1 : i;
  7856. }
  7857. }
  7858. } else if (util.has(map[i], str)) {
  7859. return (i === UNKNOWN) ? undefined$1 : i;
  7860. }
  7861. }
  7862. return str;
  7863. }
  7864. };
  7865. ///////////////
  7866. // String map
  7867. //////////////
  7868. var maps = {
  7869. browser : {
  7870. oldsafari : {
  7871. version : {
  7872. '1.0' : '/8',
  7873. '1.2' : '/1',
  7874. '1.3' : '/3',
  7875. '2.0' : '/412',
  7876. '2.0.2' : '/416',
  7877. '2.0.3' : '/417',
  7878. '2.0.4' : '/419',
  7879. '?' : '/'
  7880. }
  7881. }
  7882. },
  7883. device : {
  7884. amazon : {
  7885. model : {
  7886. 'Fire Phone' : ['SD', 'KF']
  7887. }
  7888. },
  7889. sprint : {
  7890. model : {
  7891. 'Evo Shift 4G' : '7373KT'
  7892. },
  7893. vendor : {
  7894. 'HTC' : 'APA',
  7895. 'Sprint' : 'Sprint'
  7896. }
  7897. }
  7898. },
  7899. os : {
  7900. windows : {
  7901. version : {
  7902. 'ME' : '4.90',
  7903. 'NT 3.11' : 'NT3.51',
  7904. 'NT 4.0' : 'NT4.0',
  7905. '2000' : 'NT 5.0',
  7906. 'XP' : ['NT 5.1', 'NT 5.2'],
  7907. 'Vista' : 'NT 6.0',
  7908. '7' : 'NT 6.1',
  7909. '8' : 'NT 6.2',
  7910. '8.1' : 'NT 6.3',
  7911. '10' : ['NT 6.4', 'NT 10.0'],
  7912. 'RT' : 'ARM'
  7913. }
  7914. }
  7915. }
  7916. };
  7917. //////////////
  7918. // Regex map
  7919. /////////////
  7920. var regexes = {
  7921. browser : [[
  7922. // Presto based
  7923. /(opera\smini)\/([\w\.-]+)/i, // Opera Mini
  7924. /(opera\s[mobiletab]+).+version\/([\w\.-]+)/i, // Opera Mobi/Tablet
  7925. /(opera).+version\/([\w\.]+)/i, // Opera > 9.80
  7926. /(opera)[\/\s]+([\w\.]+)/i // Opera < 9.80
  7927. ], [NAME, VERSION], [
  7928. /(opios)[\/\s]+([\w\.]+)/i // Opera mini on iphone >= 8.0
  7929. ], [[NAME, 'Opera Mini'], VERSION], [
  7930. /\s(opr)\/([\w\.]+)/i // Opera Webkit
  7931. ], [[NAME, 'Opera'], VERSION], [
  7932. // Mixed
  7933. /(kindle)\/([\w\.]+)/i, // Kindle
  7934. /(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?([\w\.]*)/i,
  7935. // Lunascape/Maxthon/Netfront/Jasmine/Blazer
  7936. // Trident based
  7937. /(avant\s|iemobile|slim)(?:browser)?[\/\s]?([\w\.]*)/i,
  7938. // Avant/IEMobile/SlimBrowser
  7939. /(bidubrowser|baidubrowser)[\/\s]?([\w\.]+)/i, // Baidu Browser
  7940. /(?:ms|\()(ie)\s([\w\.]+)/i, // Internet Explorer
  7941. // Webkit/KHTML based
  7942. /(rekonq)\/([\w\.]*)/i, // Rekonq
  7943. /(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt|iron|vivaldi|iridium|phantomjs|bowser|quark|qupzilla|falkon)\/([\w\.-]+)/i
  7944. // Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt/Iron/Iridium/PhantomJS/Bowser/QupZilla/Falkon
  7945. ], [NAME, VERSION], [
  7946. /(konqueror)\/([\w\.]+)/i // Konqueror
  7947. ], [[NAME, 'Konqueror'], VERSION], [
  7948. /(trident).+rv[:\s]([\w\.]+).+like\sgecko/i // IE11
  7949. ], [[NAME, 'IE'], VERSION], [
  7950. /(edge|edgios|edga|edg)\/((\d+)?[\w\.]+)/i // Microsoft Edge
  7951. ], [[NAME, 'Edge'], VERSION], [
  7952. /(yabrowser)\/([\w\.]+)/i // Yandex
  7953. ], [[NAME, 'Yandex'], VERSION], [
  7954. /(Avast)\/([\w\.]+)/i // Avast Secure Browser
  7955. ], [[NAME, 'Avast Secure Browser'], VERSION], [
  7956. /(AVG)\/([\w\.]+)/i // AVG Secure Browser
  7957. ], [[NAME, 'AVG Secure Browser'], VERSION], [
  7958. /(puffin)\/([\w\.]+)/i // Puffin
  7959. ], [[NAME, 'Puffin'], VERSION], [
  7960. /(focus)\/([\w\.]+)/i // Firefox Focus
  7961. ], [[NAME, 'Firefox Focus'], VERSION], [
  7962. /(opt)\/([\w\.]+)/i // Opera Touch
  7963. ], [[NAME, 'Opera Touch'], VERSION], [
  7964. /((?:[\s\/])uc?\s?browser|(?:juc.+)ucweb)[\/\s]?([\w\.]+)/i // UCBrowser
  7965. ], [[NAME, 'UCBrowser'], VERSION], [
  7966. /(comodo_dragon)\/([\w\.]+)/i // Comodo Dragon
  7967. ], [[NAME, /_/g, ' '], VERSION], [
  7968. /(windowswechat qbcore)\/([\w\.]+)/i // WeChat Desktop for Windows Built-in Browser
  7969. ], [[NAME, 'WeChat(Win) Desktop'], VERSION], [
  7970. /(micromessenger)\/([\w\.]+)/i // WeChat
  7971. ], [[NAME, 'WeChat'], VERSION], [
  7972. /(brave)\/([\w\.]+)/i // Brave browser
  7973. ], [[NAME, 'Brave'], VERSION], [
  7974. /(qqbrowserlite)\/([\w\.]+)/i // QQBrowserLite
  7975. ], [NAME, VERSION], [
  7976. /(QQ)\/([\d\.]+)/i // QQ, aka ShouQ
  7977. ], [NAME, VERSION], [
  7978. /m?(qqbrowser)[\/\s]?([\w\.]+)/i // QQBrowser
  7979. ], [NAME, VERSION], [
  7980. /(baiduboxapp)[\/\s]?([\w\.]+)/i // Baidu App
  7981. ], [NAME, VERSION], [
  7982. /(2345Explorer)[\/\s]?([\w\.]+)/i // 2345 Browser
  7983. ], [NAME, VERSION], [
  7984. /(MetaSr)[\/\s]?([\w\.]+)/i // SouGouBrowser
  7985. ], [NAME], [
  7986. /(LBBROWSER)/i // LieBao Browser
  7987. ], [NAME], [
  7988. /xiaomi\/miuibrowser\/([\w\.]+)/i // MIUI Browser
  7989. ], [VERSION, [NAME, 'MIUI Browser']], [
  7990. /;fbav\/([\w\.]+);/i // Facebook App for iOS & Android
  7991. ], [VERSION, [NAME, 'Facebook']], [
  7992. /safari\s(line)\/([\w\.]+)/i, // Line App for iOS
  7993. /android.+(line)\/([\w\.]+)\/iab/i // Line App for Android
  7994. ], [NAME, VERSION], [
  7995. /headlesschrome(?:\/([\w\.]+)|\s)/i // Chrome Headless
  7996. ], [VERSION, [NAME, 'Chrome Headless']], [
  7997. /\swv\).+(chrome)\/([\w\.]+)/i // Chrome WebView
  7998. ], [[NAME, /(.+)/, '$1 WebView'], VERSION], [
  7999. /((?:oculus|samsung)browser)\/([\w\.]+)/i
  8000. ], [[NAME, /(.+(?:g|us))(.+)/, '$1 $2'], VERSION], [ // Oculus / Samsung Browser
  8001. /android.+version\/([\w\.]+)\s+(?:mobile\s?safari|safari)*/i // Android Browser
  8002. ], [VERSION, [NAME, 'Android Browser']], [
  8003. /(sailfishbrowser)\/([\w\.]+)/i // Sailfish Browser
  8004. ], [[NAME, 'Sailfish Browser'], VERSION], [
  8005. /(chrome|omniweb|arora|[tizenoka]{5}\s?browser)\/v?([\w\.]+)/i
  8006. // Chrome/OmniWeb/Arora/Tizen/Nokia
  8007. ], [NAME, VERSION], [
  8008. /(dolfin)\/([\w\.]+)/i // Dolphin
  8009. ], [[NAME, 'Dolphin'], VERSION], [
  8010. /(qihu|qhbrowser|qihoobrowser|360browser)/i // 360
  8011. ], [[NAME, '360 Browser']], [
  8012. /((?:android.+)crmo|crios)\/([\w\.]+)/i // Chrome for Android/iOS
  8013. ], [[NAME, 'Chrome'], VERSION], [
  8014. /(coast)\/([\w\.]+)/i // Opera Coast
  8015. ], [[NAME, 'Opera Coast'], VERSION], [
  8016. /fxios\/([\w\.-]+)/i // Firefox for iOS
  8017. ], [VERSION, [NAME, 'Firefox']], [
  8018. /version\/([\w\.]+).+?mobile\/\w+\s(safari)/i // Mobile Safari
  8019. ], [VERSION, [NAME, 'Mobile Safari']], [
  8020. /version\/([\w\.]+).+?(mobile\s?safari|safari)/i // Safari & Safari Mobile
  8021. ], [VERSION, NAME], [
  8022. /webkit.+?(gsa)\/([\w\.]+).+?(mobile\s?safari|safari)(\/[\w\.]+)/i // Google Search Appliance on iOS
  8023. ], [[NAME, 'GSA'], VERSION], [
  8024. /webkit.+?(mobile\s?safari|safari)(\/[\w\.]+)/i // Safari < 3.0
  8025. ], [NAME, [VERSION, mapper.str, maps.browser.oldsafari.version]], [
  8026. /(webkit|khtml)\/([\w\.]+)/i
  8027. ], [NAME, VERSION], [
  8028. // Gecko based
  8029. /(navigator|netscape)\/([\w\.-]+)/i // Netscape
  8030. ], [[NAME, 'Netscape'], VERSION], [
  8031. /(swiftfox)/i, // Swiftfox
  8032. /(icedragon|iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo|conkeror)[\/\s]?([\w\.\+]+)/i,
  8033. // IceDragon/Iceweasel/Camino/Chimera/Fennec/Maemo/Minimo/Conkeror
  8034. /(firefox|seamonkey|k-meleon|icecat|iceape|firebird|phoenix|palemoon|basilisk|waterfox)\/([\w\.-]+)$/i,
  8035. // Firefox/SeaMonkey/K-Meleon/IceCat/IceApe/Firebird/Phoenix
  8036. /(mozilla)\/([\w\.]+).+rv\:.+gecko\/\d+/i, // Mozilla
  8037. // Other
  8038. /(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|sleipnir)[\/\s]?([\w\.]+)/i,
  8039. // Polaris/Lynx/Dillo/iCab/Doris/Amaya/w3m/NetSurf/Sleipnir
  8040. /(links)\s\(([\w\.]+)/i, // Links
  8041. /(gobrowser)\/?([\w\.]*)/i, // GoBrowser
  8042. /(ice\s?browser)\/v?([\w\._]+)/i, // ICE Browser
  8043. /(mosaic)[\/\s]([\w\.]+)/i // Mosaic
  8044. ], [NAME, VERSION]
  8045. ],
  8046. cpu : [[
  8047. /(?:(amd|x(?:(?:86|64)[_-])?|wow|win)64)[;\)]/i // AMD64
  8048. ], [[ARCHITECTURE, 'amd64']], [
  8049. /(ia32(?=;))/i // IA32 (quicktime)
  8050. ], [[ARCHITECTURE, util.lowerize]], [
  8051. /((?:i[346]|x)86)[;\)]/i // IA32
  8052. ], [[ARCHITECTURE, 'ia32']], [
  8053. // PocketPC mistakenly identified as PowerPC
  8054. /windows\s(ce|mobile);\sppc;/i
  8055. ], [[ARCHITECTURE, 'arm']], [
  8056. /((?:ppc|powerpc)(?:64)?)(?:\smac|;|\))/i // PowerPC
  8057. ], [[ARCHITECTURE, /ower/, '', util.lowerize]], [
  8058. /(sun4\w)[;\)]/i // SPARC
  8059. ], [[ARCHITECTURE, 'sparc']], [
  8060. /((?:avr32|ia64(?=;))|68k(?=\))|arm(?:64|(?=v\d+[;l]))|(?=atmel\s)avr|(?:irix|mips|sparc)(?:64)?(?=;)|pa-risc)/i
  8061. // IA64, 68K, ARM/64, AVR/32, IRIX/64, MIPS/64, SPARC/64, PA-RISC
  8062. ], [[ARCHITECTURE, util.lowerize]]
  8063. ],
  8064. device : [[
  8065. /\((ipad|playbook);[\w\s\),;-]+(rim|apple)/i // iPad/PlayBook
  8066. ], [MODEL, VENDOR, [TYPE, TABLET]], [
  8067. /applecoremedia\/[\w\.]+ \((ipad)/ // iPad
  8068. ], [MODEL, [VENDOR, 'Apple'], [TYPE, TABLET]], [
  8069. /(apple\s{0,1}tv)/i // Apple TV
  8070. ], [[MODEL, 'Apple TV'], [VENDOR, 'Apple'], [TYPE, SMARTTV]], [
  8071. /(archos)\s(gamepad2?)/i, // Archos
  8072. /(hp).+(touchpad)/i, // HP TouchPad
  8073. /(hp).+(tablet)/i, // HP Tablet
  8074. /(kindle)\/([\w\.]+)/i, // Kindle
  8075. /\s(nook)[\w\s]+build\/(\w+)/i, // Nook
  8076. /(dell)\s(strea[kpr\s\d]*[\dko])/i // Dell Streak
  8077. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8078. /(kf[A-z]+)\sbuild\/.+silk\//i // Kindle Fire HD
  8079. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, TABLET]], [
  8080. /(sd|kf)[0349hijorstuw]+\sbuild\/.+silk\//i // Fire Phone
  8081. ], [[MODEL, mapper.str, maps.device.amazon.model], [VENDOR, 'Amazon'], [TYPE, MOBILE]], [
  8082. /android.+aft([bms])\sbuild/i // Fire TV
  8083. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, SMARTTV]], [
  8084. /\((ip[honed|\s\w*]+);.+(apple)/i // iPod/iPhone
  8085. ], [MODEL, VENDOR, [TYPE, MOBILE]], [
  8086. /\((ip[honed|\s\w*]+);/i // iPod/iPhone
  8087. ], [MODEL, [VENDOR, 'Apple'], [TYPE, MOBILE]], [
  8088. /(blackberry)[\s-]?(\w+)/i, // BlackBerry
  8089. /(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|meizu|motorola|polytron)[\s_-]?([\w-]*)/i,
  8090. // BenQ/Palm/Sony-Ericsson/Acer/Asus/Dell/Meizu/Motorola/Polytron
  8091. /(hp)\s([\w\s]+\w)/i, // HP iPAQ
  8092. /(asus)-?(\w+)/i // Asus
  8093. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8094. /\(bb10;\s(\w+)/i // BlackBerry 10
  8095. ], [MODEL, [VENDOR, 'BlackBerry'], [TYPE, MOBILE]], [
  8096. // Asus Tablets
  8097. /android.+(transfo[prime\s]{4,10}\s\w+|eeepc|slider\s\w+|nexus 7|padfone|p00c)/i
  8098. ], [MODEL, [VENDOR, 'Asus'], [TYPE, TABLET]], [
  8099. /(sony)\s(tablet\s[ps])\sbuild\//i, // Sony
  8100. /(sony)?(?:sgp.+)\sbuild\//i
  8101. ], [[VENDOR, 'Sony'], [MODEL, 'Xperia Tablet'], [TYPE, TABLET]], [
  8102. /android.+\s([c-g]\d{4}|so[-l]\w+)(?=\sbuild\/|\).+chrome\/(?![1-6]{0,1}\d\.))/i
  8103. ], [MODEL, [VENDOR, 'Sony'], [TYPE, MOBILE]], [
  8104. /\s(ouya)\s/i, // Ouya
  8105. /(nintendo)\s([wids3u]+)/i // Nintendo
  8106. ], [VENDOR, MODEL, [TYPE, CONSOLE]], [
  8107. /android.+;\s(shield)\sbuild/i // Nvidia
  8108. ], [MODEL, [VENDOR, 'Nvidia'], [TYPE, CONSOLE]], [
  8109. /(playstation\s[34portablevi]+)/i // Playstation
  8110. ], [MODEL, [VENDOR, 'Sony'], [TYPE, CONSOLE]], [
  8111. /(sprint\s(\w+))/i // Sprint Phones
  8112. ], [[VENDOR, mapper.str, maps.device.sprint.vendor], [MODEL, mapper.str, maps.device.sprint.model], [TYPE, MOBILE]], [
  8113. /(htc)[;_\s-]+([\w\s]+(?=\)|\sbuild)|\w+)/i, // HTC
  8114. /(zte)-(\w*)/i, // ZTE
  8115. /(alcatel|geeksphone|nexian|panasonic|(?=;\s)sony)[_\s-]?([\w-]*)/i
  8116. // Alcatel/GeeksPhone/Nexian/Panasonic/Sony
  8117. ], [VENDOR, [MODEL, /_/g, ' '], [TYPE, MOBILE]], [
  8118. /(nexus\s9)/i // HTC Nexus 9
  8119. ], [MODEL, [VENDOR, 'HTC'], [TYPE, TABLET]], [
  8120. /d\/huawei([\w\s-]+)[;\)]/i,
  8121. /(nexus\s6p|vog-l29|ane-lx1|eml-l29)/i // Huawei
  8122. ], [MODEL, [VENDOR, 'Huawei'], [TYPE, MOBILE]], [
  8123. /android.+(bah2?-a?[lw]\d{2})/i // Huawei MediaPad
  8124. ], [MODEL, [VENDOR, 'Huawei'], [TYPE, TABLET]], [
  8125. /(microsoft);\s(lumia[\s\w]+)/i // Microsoft Lumia
  8126. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8127. /[\s\(;](xbox(?:\sone)?)[\s\);]/i // Microsoft Xbox
  8128. ], [MODEL, [VENDOR, 'Microsoft'], [TYPE, CONSOLE]], [
  8129. /(kin\.[onetw]{3})/i // Microsoft Kin
  8130. ], [[MODEL, /\./g, ' '], [VENDOR, 'Microsoft'], [TYPE, MOBILE]], [
  8131. // Motorola
  8132. /\s(milestone|droid(?:[2-4x]|\s(?:bionic|x2|pro|razr))?:?(\s4g)?)[\w\s]+build\//i,
  8133. /mot[\s-]?(\w*)/i,
  8134. /(XT\d{3,4}) build\//i,
  8135. /(nexus\s6)/i
  8136. ], [MODEL, [VENDOR, 'Motorola'], [TYPE, MOBILE]], [
  8137. /android.+\s(mz60\d|xoom[\s2]{0,2})\sbuild\//i
  8138. ], [MODEL, [VENDOR, 'Motorola'], [TYPE, TABLET]], [
  8139. /hbbtv\/\d+\.\d+\.\d+\s+\([\w\s]*;\s*(\w[^;]*);([^;]*)/i // HbbTV devices
  8140. ], [[VENDOR, util.trim], [MODEL, util.trim], [TYPE, SMARTTV]], [
  8141. /hbbtv.+maple;(\d+)/i
  8142. ], [[MODEL, /^/, 'SmartTV'], [VENDOR, 'Samsung'], [TYPE, SMARTTV]], [
  8143. /\(dtv[\);].+(aquos)/i // Sharp
  8144. ], [MODEL, [VENDOR, 'Sharp'], [TYPE, SMARTTV]], [
  8145. /android.+((sch-i[89]0\d|shw-m380s|gt-p\d{4}|gt-n\d+|sgh-t8[56]9|nexus 10))/i,
  8146. /((SM-T\w+))/i
  8147. ], [[VENDOR, 'Samsung'], MODEL, [TYPE, TABLET]], [ // Samsung
  8148. /smart-tv.+(samsung)/i
  8149. ], [VENDOR, [TYPE, SMARTTV], MODEL], [
  8150. /((s[cgp]h-\w+|gt-\w+|galaxy\snexus|sm-\w[\w\d]+))/i,
  8151. /(sam[sung]*)[\s-]*(\w+-?[\w-]*)/i,
  8152. /sec-((sgh\w+))/i
  8153. ], [[VENDOR, 'Samsung'], MODEL, [TYPE, MOBILE]], [
  8154. /sie-(\w*)/i // Siemens
  8155. ], [MODEL, [VENDOR, 'Siemens'], [TYPE, MOBILE]], [
  8156. /(maemo|nokia).*(n900|lumia\s\d+)/i, // Nokia
  8157. /(nokia)[\s_-]?([\w-]*)/i
  8158. ], [[VENDOR, 'Nokia'], MODEL, [TYPE, MOBILE]], [
  8159. /android[x\d\.\s;]+\s([ab][1-7]\-?[0178a]\d\d?)/i // Acer
  8160. ], [MODEL, [VENDOR, 'Acer'], [TYPE, TABLET]], [
  8161. /android.+([vl]k\-?\d{3})\s+build/i // LG Tablet
  8162. ], [MODEL, [VENDOR, 'LG'], [TYPE, TABLET]], [
  8163. /android\s3\.[\s\w;-]{10}(lg?)-([06cv9]{3,4})/i // LG Tablet
  8164. ], [[VENDOR, 'LG'], MODEL, [TYPE, TABLET]], [
  8165. /(lg) netcast\.tv/i // LG SmartTV
  8166. ], [VENDOR, MODEL, [TYPE, SMARTTV]], [
  8167. /(nexus\s[45])/i, // LG
  8168. /lg[e;\s\/-]+(\w*)/i,
  8169. /android.+lg(\-?[\d\w]+)\s+build/i
  8170. ], [MODEL, [VENDOR, 'LG'], [TYPE, MOBILE]], [
  8171. /(lenovo)\s?(s(?:5000|6000)(?:[\w-]+)|tab(?:[\s\w]+))/i // Lenovo tablets
  8172. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8173. /android.+(ideatab[a-z0-9\-\s]+)/i // Lenovo
  8174. ], [MODEL, [VENDOR, 'Lenovo'], [TYPE, TABLET]], [
  8175. /(lenovo)[_\s-]?([\w-]+)/i
  8176. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8177. /linux;.+((jolla));/i // Jolla
  8178. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8179. /((pebble))app\/[\d\.]+\s/i // Pebble
  8180. ], [VENDOR, MODEL, [TYPE, WEARABLE]], [
  8181. /android.+;\s(oppo)\s?([\w\s]+)\sbuild/i // OPPO
  8182. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8183. /crkey/i // Google Chromecast
  8184. ], [[MODEL, 'Chromecast'], [VENDOR, 'Google'], [TYPE, SMARTTV]], [
  8185. /android.+;\s(glass)\s\d/i // Google Glass
  8186. ], [MODEL, [VENDOR, 'Google'], [TYPE, WEARABLE]], [
  8187. /android.+;\s(pixel c)[\s)]/i // Google Pixel C
  8188. ], [MODEL, [VENDOR, 'Google'], [TYPE, TABLET]], [
  8189. /android.+;\s(pixel( [23])?( xl)?)[\s)]/i // Google Pixel
  8190. ], [MODEL, [VENDOR, 'Google'], [TYPE, MOBILE]], [
  8191. /android.+;\s(\w+)\s+build\/hm\1/i, // Xiaomi Hongmi 'numeric' models
  8192. /android.+(hm[\s\-_]*note?[\s_]*(?:\d\w)?)\s+build/i, // Xiaomi Hongmi
  8193. /android.+(mi[\s\-_]*(?:a\d|one|one[\s_]plus|note lte)?[\s_]*(?:\d?\w?)[\s_]*(?:plus)?)\s+build/i,
  8194. // Xiaomi Mi
  8195. /android.+(redmi[\s\-_]*(?:note)?(?:[\s_]*[\w\s]+))\s+build/i // Redmi Phones
  8196. ], [[MODEL, /_/g, ' '], [VENDOR, 'Xiaomi'], [TYPE, MOBILE]], [
  8197. /android.+(mi[\s\-_]*(?:pad)(?:[\s_]*[\w\s]+))\s+build/i // Mi Pad tablets
  8198. ],[[MODEL, /_/g, ' '], [VENDOR, 'Xiaomi'], [TYPE, TABLET]], [
  8199. /android.+;\s(m[1-5]\snote)\sbuild/i // Meizu
  8200. ], [MODEL, [VENDOR, 'Meizu'], [TYPE, MOBILE]], [
  8201. /(mz)-([\w-]{2,})/i
  8202. ], [[VENDOR, 'Meizu'], MODEL, [TYPE, MOBILE]], [
  8203. /android.+a000(1)\s+build/i, // OnePlus
  8204. /android.+oneplus\s(a\d{4})[\s)]/i
  8205. ], [MODEL, [VENDOR, 'OnePlus'], [TYPE, MOBILE]], [
  8206. /android.+[;\/]\s*(RCT[\d\w]+)\s+build/i // RCA Tablets
  8207. ], [MODEL, [VENDOR, 'RCA'], [TYPE, TABLET]], [
  8208. /android.+[;\/\s]+(Venue[\d\s]{2,7})\s+build/i // Dell Venue Tablets
  8209. ], [MODEL, [VENDOR, 'Dell'], [TYPE, TABLET]], [
  8210. /android.+[;\/]\s*(Q[T|M][\d\w]+)\s+build/i // Verizon Tablet
  8211. ], [MODEL, [VENDOR, 'Verizon'], [TYPE, TABLET]], [
  8212. /android.+[;\/]\s+(Barnes[&\s]+Noble\s+|BN[RT])(V?.*)\s+build/i // Barnes & Noble Tablet
  8213. ], [[VENDOR, 'Barnes & Noble'], MODEL, [TYPE, TABLET]], [
  8214. /android.+[;\/]\s+(TM\d{3}.*\b)\s+build/i // Barnes & Noble Tablet
  8215. ], [MODEL, [VENDOR, 'NuVision'], [TYPE, TABLET]], [
  8216. /android.+;\s(k88)\sbuild/i // ZTE K Series Tablet
  8217. ], [MODEL, [VENDOR, 'ZTE'], [TYPE, TABLET]], [
  8218. /android.+[;\/]\s*(gen\d{3})\s+build.*49h/i // Swiss GEN Mobile
  8219. ], [MODEL, [VENDOR, 'Swiss'], [TYPE, MOBILE]], [
  8220. /android.+[;\/]\s*(zur\d{3})\s+build/i // Swiss ZUR Tablet
  8221. ], [MODEL, [VENDOR, 'Swiss'], [TYPE, TABLET]], [
  8222. /android.+[;\/]\s*((Zeki)?TB.*\b)\s+build/i // Zeki Tablets
  8223. ], [MODEL, [VENDOR, 'Zeki'], [TYPE, TABLET]], [
  8224. /(android).+[;\/]\s+([YR]\d{2})\s+build/i,
  8225. /android.+[;\/]\s+(Dragon[\-\s]+Touch\s+|DT)(\w{5})\sbuild/i // Dragon Touch Tablet
  8226. ], [[VENDOR, 'Dragon Touch'], MODEL, [TYPE, TABLET]], [
  8227. /android.+[;\/]\s*(NS-?\w{0,9})\sbuild/i // Insignia Tablets
  8228. ], [MODEL, [VENDOR, 'Insignia'], [TYPE, TABLET]], [
  8229. /android.+[;\/]\s*((NX|Next)-?\w{0,9})\s+build/i // NextBook Tablets
  8230. ], [MODEL, [VENDOR, 'NextBook'], [TYPE, TABLET]], [
  8231. /android.+[;\/]\s*(Xtreme\_)?(V(1[045]|2[015]|30|40|60|7[05]|90))\s+build/i
  8232. ], [[VENDOR, 'Voice'], MODEL, [TYPE, MOBILE]], [ // Voice Xtreme Phones
  8233. /android.+[;\/]\s*(LVTEL\-)?(V1[12])\s+build/i // LvTel Phones
  8234. ], [[VENDOR, 'LvTel'], MODEL, [TYPE, MOBILE]], [
  8235. /android.+;\s(PH-1)\s/i
  8236. ], [MODEL, [VENDOR, 'Essential'], [TYPE, MOBILE]], [ // Essential PH-1
  8237. /android.+[;\/]\s*(V(100MD|700NA|7011|917G).*\b)\s+build/i // Envizen Tablets
  8238. ], [MODEL, [VENDOR, 'Envizen'], [TYPE, TABLET]], [
  8239. /android.+[;\/]\s*(Le[\s\-]+Pan)[\s\-]+(\w{1,9})\s+build/i // Le Pan Tablets
  8240. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8241. /android.+[;\/]\s*(Trio[\s\-]*.*)\s+build/i // MachSpeed Tablets
  8242. ], [MODEL, [VENDOR, 'MachSpeed'], [TYPE, TABLET]], [
  8243. /android.+[;\/]\s*(Trinity)[\-\s]*(T\d{3})\s+build/i // Trinity Tablets
  8244. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8245. /android.+[;\/]\s*TU_(1491)\s+build/i // Rotor Tablets
  8246. ], [MODEL, [VENDOR, 'Rotor'], [TYPE, TABLET]], [
  8247. /android.+(KS(.+))\s+build/i // Amazon Kindle Tablets
  8248. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, TABLET]], [
  8249. /android.+(Gigaset)[\s\-]+(Q\w{1,9})\s+build/i // Gigaset Tablets
  8250. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8251. /\s(tablet|tab)[;\/]/i, // Unidentifiable Tablet
  8252. /\s(mobile)(?:[;\/]|\ssafari)/i // Unidentifiable Mobile
  8253. ], [[TYPE, util.lowerize], VENDOR, MODEL], [
  8254. /[\s\/\(](smart-?tv)[;\)]/i // SmartTV
  8255. ], [[TYPE, SMARTTV]], [
  8256. /(android[\w\.\s\-]{0,9});.+build/i // Generic Android Device
  8257. ], [MODEL, [VENDOR, 'Generic']]
  8258. ],
  8259. engine : [[
  8260. /windows.+\sedge\/([\w\.]+)/i // EdgeHTML
  8261. ], [VERSION, [NAME, 'EdgeHTML']], [
  8262. /webkit\/537\.36.+chrome\/(?!27)([\w\.]+)/i // Blink
  8263. ], [VERSION, [NAME, 'Blink']], [
  8264. /(presto)\/([\w\.]+)/i, // Presto
  8265. /(webkit|trident|netfront|netsurf|amaya|lynx|w3m|goanna)\/([\w\.]+)/i,
  8266. // WebKit/Trident/NetFront/NetSurf/Amaya/Lynx/w3m/Goanna
  8267. /(khtml|tasman|links)[\/\s]\(?([\w\.]+)/i, // KHTML/Tasman/Links
  8268. /(icab)[\/\s]([23]\.[\d\.]+)/i // iCab
  8269. ], [NAME, VERSION], [
  8270. /rv\:([\w\.]{1,9}).+(gecko)/i // Gecko
  8271. ], [VERSION, NAME]
  8272. ],
  8273. os : [[
  8274. // Windows based
  8275. /microsoft\s(windows)\s(vista|xp)/i // Windows (iTunes)
  8276. ], [NAME, VERSION], [
  8277. /(windows)\snt\s6\.2;\s(arm)/i, // Windows RT
  8278. /(windows\sphone(?:\sos)*)[\s\/]?([\d\.\s\w]*)/i, // Windows Phone
  8279. /(windows\smobile|windows)[\s\/]?([ntce\d\.\s]+\w)/i
  8280. ], [NAME, [VERSION, mapper.str, maps.os.windows.version]], [
  8281. /(win(?=3|9|n)|win\s9x\s)([nt\d\.]+)/i
  8282. ], [[NAME, 'Windows'], [VERSION, mapper.str, maps.os.windows.version]], [
  8283. // Mobile/Embedded OS
  8284. /\((bb)(10);/i // BlackBerry 10
  8285. ], [[NAME, 'BlackBerry'], VERSION], [
  8286. /(blackberry)\w*\/?([\w\.]*)/i, // Blackberry
  8287. /(tizen|kaios)[\/\s]([\w\.]+)/i, // Tizen/KaiOS
  8288. /(android|webos|palm\sos|qnx|bada|rim\stablet\sos|meego|sailfish|contiki)[\/\s-]?([\w\.]*)/i
  8289. // Android/WebOS/Palm/QNX/Bada/RIM/MeeGo/Contiki/Sailfish OS
  8290. ], [NAME, VERSION], [
  8291. /(symbian\s?os|symbos|s60(?=;))[\/\s-]?([\w\.]*)/i // Symbian
  8292. ], [[NAME, 'Symbian'], VERSION], [
  8293. /\((series40);/i // Series 40
  8294. ], [NAME], [
  8295. /mozilla.+\(mobile;.+gecko.+firefox/i // Firefox OS
  8296. ], [[NAME, 'Firefox OS'], VERSION], [
  8297. // Console
  8298. /(nintendo|playstation)\s([wids34portablevu]+)/i, // Nintendo/Playstation
  8299. // GNU/Linux based
  8300. /(mint)[\/\s\(]?(\w*)/i, // Mint
  8301. /(mageia|vectorlinux)[;\s]/i, // Mageia/VectorLinux
  8302. /(joli|[kxln]?ubuntu|debian|suse|opensuse|gentoo|(?=\s)arch|slackware|fedora|mandriva|centos|pclinuxos|redhat|zenwalk|linpus)[\/\s-]?(?!chrom)([\w\.-]*)/i,
  8303. // Joli/Ubuntu/Debian/SUSE/Gentoo/Arch/Slackware
  8304. // Fedora/Mandriva/CentOS/PCLinuxOS/RedHat/Zenwalk/Linpus
  8305. /(hurd|linux)\s?([\w\.]*)/i, // Hurd/Linux
  8306. /(gnu)\s?([\w\.]*)/i // GNU
  8307. ], [NAME, VERSION], [
  8308. /(cros)\s[\w]+\s([\w\.]+\w)/i // Chromium OS
  8309. ], [[NAME, 'Chromium OS'], VERSION],[
  8310. // Solaris
  8311. /(sunos)\s?([\w\.\d]*)/i // Solaris
  8312. ], [[NAME, 'Solaris'], VERSION], [
  8313. // BSD based
  8314. /\s([frentopc-]{0,4}bsd|dragonfly)\s?([\w\.]*)/i // FreeBSD/NetBSD/OpenBSD/PC-BSD/DragonFly
  8315. ], [NAME, VERSION],[
  8316. /(haiku)\s(\w+)/i // Haiku
  8317. ], [NAME, VERSION],[
  8318. /cfnetwork\/.+darwin/i,
  8319. /ip[honead]{2,4}(?:.*os\s([\w]+)\slike\smac|;\sopera)/i // iOS
  8320. ], [[VERSION, /_/g, '.'], [NAME, 'iOS']], [
  8321. /(mac\sos\sx)\s?([\w\s\.]*)/i,
  8322. /(macintosh|mac(?=_powerpc)\s)/i // Mac OS
  8323. ], [[NAME, 'Mac OS'], [VERSION, /_/g, '.']], [
  8324. // Other
  8325. /((?:open)?solaris)[\/\s-]?([\w\.]*)/i, // Solaris
  8326. /(aix)\s((\d)(?=\.|\)|\s)[\w\.])*/i, // AIX
  8327. /(plan\s9|minix|beos|os\/2|amigaos|morphos|risc\sos|openvms|fuchsia)/i,
  8328. // Plan9/Minix/BeOS/OS2/AmigaOS/MorphOS/RISCOS/OpenVMS/Fuchsia
  8329. /(unix)\s?([\w\.]*)/i // UNIX
  8330. ], [NAME, VERSION]
  8331. ]
  8332. };
  8333. /////////////////
  8334. // Constructor
  8335. ////////////////
  8336. var UAParser = function (uastring, extensions) {
  8337. if (typeof uastring === 'object') {
  8338. extensions = uastring;
  8339. uastring = undefined$1;
  8340. }
  8341. if (!(this instanceof UAParser)) {
  8342. return new UAParser(uastring, extensions).getResult();
  8343. }
  8344. var ua = uastring || ((window && window.navigator && window.navigator.userAgent) ? window.navigator.userAgent : EMPTY);
  8345. var rgxmap = extensions ? util.extend(regexes, extensions) : regexes;
  8346. this.getBrowser = function () {
  8347. var browser = { name: undefined$1, version: undefined$1 };
  8348. mapper.rgx.call(browser, ua, rgxmap.browser);
  8349. browser.major = util.major(browser.version); // deprecated
  8350. return browser;
  8351. };
  8352. this.getCPU = function () {
  8353. var cpu = { architecture: undefined$1 };
  8354. mapper.rgx.call(cpu, ua, rgxmap.cpu);
  8355. return cpu;
  8356. };
  8357. this.getDevice = function () {
  8358. var device = { vendor: undefined$1, model: undefined$1, type: undefined$1 };
  8359. mapper.rgx.call(device, ua, rgxmap.device);
  8360. return device;
  8361. };
  8362. this.getEngine = function () {
  8363. var engine = { name: undefined$1, version: undefined$1 };
  8364. mapper.rgx.call(engine, ua, rgxmap.engine);
  8365. return engine;
  8366. };
  8367. this.getOS = function () {
  8368. var os = { name: undefined$1, version: undefined$1 };
  8369. mapper.rgx.call(os, ua, rgxmap.os);
  8370. return os;
  8371. };
  8372. this.getResult = function () {
  8373. return {
  8374. ua : this.getUA(),
  8375. browser : this.getBrowser(),
  8376. engine : this.getEngine(),
  8377. os : this.getOS(),
  8378. device : this.getDevice(),
  8379. cpu : this.getCPU()
  8380. };
  8381. };
  8382. this.getUA = function () {
  8383. return ua;
  8384. };
  8385. this.setUA = function (uastring) {
  8386. ua = uastring;
  8387. return this;
  8388. };
  8389. return this;
  8390. };
  8391. UAParser.VERSION = LIBVERSION;
  8392. UAParser.BROWSER = {
  8393. NAME : NAME,
  8394. MAJOR : MAJOR, // deprecated
  8395. VERSION : VERSION
  8396. };
  8397. UAParser.CPU = {
  8398. ARCHITECTURE : ARCHITECTURE
  8399. };
  8400. UAParser.DEVICE = {
  8401. MODEL : MODEL,
  8402. VENDOR : VENDOR,
  8403. TYPE : TYPE,
  8404. CONSOLE : CONSOLE,
  8405. MOBILE : MOBILE,
  8406. SMARTTV : SMARTTV,
  8407. TABLET : TABLET,
  8408. WEARABLE: WEARABLE,
  8409. EMBEDDED: EMBEDDED
  8410. };
  8411. UAParser.ENGINE = {
  8412. NAME : NAME,
  8413. VERSION : VERSION
  8414. };
  8415. UAParser.OS = {
  8416. NAME : NAME,
  8417. VERSION : VERSION
  8418. };
  8419. ///////////
  8420. // Export
  8421. //////////
  8422. // check js environment
  8423. {
  8424. // nodejs env
  8425. if ( module.exports) {
  8426. exports = module.exports = UAParser;
  8427. }
  8428. exports.UAParser = UAParser;
  8429. }
  8430. // jQuery/Zepto specific (optional)
  8431. // Note:
  8432. // In AMD env the global scope should be kept clean, but jQuery is an exception.
  8433. // jQuery always exports to global scope, unless jQuery.noConflict(true) is used,
  8434. // and we should catch that.
  8435. var $ = window && (window.jQuery || window.Zepto);
  8436. if ($ && !$.ua) {
  8437. var parser = new UAParser();
  8438. $.ua = parser.getResult();
  8439. $.ua.get = function () {
  8440. return parser.getUA();
  8441. };
  8442. $.ua.set = function (uastring) {
  8443. parser.setUA(uastring);
  8444. var result = parser.getResult();
  8445. for (var prop in result) {
  8446. $.ua[prop] = result[prop];
  8447. }
  8448. };
  8449. }
  8450. })(typeof window === 'object' ? window : commonjsGlobal);
  8451. });
  8452. var uaParser_1 = uaParser.UAParser;
  8453. var UNKNOWN = 'Unknown';
  8454. var PLATFORM_MAP = {
  8455. 'Mac OS': 'Mac OS X'
  8456. };
  8457. /**
  8458. * Convert from UAParser platform name to what we expect.
  8459. */
  8460. function convertPlatformName(name) {
  8461. return PLATFORM_MAP[name] || name;
  8462. }
  8463. /**
  8464. * Get the version number in parts. This is very naive. We actually get major
  8465. * version as a part of UAParser already, which is generally good enough, but
  8466. * let's get the minor just in case.
  8467. */
  8468. function getBrowserVersion(version) {
  8469. if (!version) {
  8470. return {
  8471. major: '',
  8472. minor: ''
  8473. };
  8474. }
  8475. var parts = version.split('.');
  8476. return {
  8477. major: parts[0],
  8478. minor: parts[1]
  8479. };
  8480. }
  8481. /**
  8482. * Get the UA data fom UAParser and then convert it to the format we're
  8483. * expecting for our APIS.
  8484. */
  8485. var parser = new uaParser();
  8486. var results = parser.getResult();
  8487. // Do some conversion first.
  8488. var browserVersionData = getBrowserVersion(results.browser.version);
  8489. var uaData = {
  8490. browserArchitecture: results.cpu.architecture || UNKNOWN,
  8491. browserFullVersion: results.browser.version || UNKNOWN,
  8492. browserMinorVersion: browserVersionData.minor || UNKNOWN,
  8493. browserName: results.browser.name || UNKNOWN,
  8494. browserVersion: results.browser.major || UNKNOWN,
  8495. deviceName: results.device.model || UNKNOWN,
  8496. engineName: results.engine.name || UNKNOWN,
  8497. engineVersion: results.engine.version || UNKNOWN,
  8498. platformArchitecture: results.cpu.architecture || UNKNOWN,
  8499. platformName: convertPlatformName(results.os.name) || UNKNOWN,
  8500. platformVersion: results.os.version || UNKNOWN,
  8501. platformFullVersion: results.os.version || UNKNOWN
  8502. };
  8503. var UserAgentData = uaData;
  8504. var componentRegex = /\./;
  8505. var orRegex = /\|\|/;
  8506. var rangeRegex = /\s+\-\s+/;
  8507. var modifierRegex = /^(<=|<|=|>=|~>|~|>|)?\s*(.+)/;
  8508. var numericRegex = /^(\d*)(.*)/;
  8509. /**
  8510. * Splits input `range` on "||" and returns true if any subrange matches
  8511. * `version`.
  8512. *
  8513. * @param {string} range
  8514. * @param {string} version
  8515. * @returns {boolean}
  8516. */
  8517. function checkOrExpression(range, version) {
  8518. var expressions = range.split(orRegex);
  8519. if (expressions.length > 1) {
  8520. return expressions.some(function (range) {
  8521. return VersionRange.contains(range, version);
  8522. });
  8523. } else {
  8524. range = expressions[0].trim();
  8525. return checkRangeExpression(range, version);
  8526. }
  8527. }
  8528. /**
  8529. * Splits input `range` on " - " (the surrounding whitespace is required) and
  8530. * returns true if version falls between the two operands.
  8531. *
  8532. * @param {string} range
  8533. * @param {string} version
  8534. * @returns {boolean}
  8535. */
  8536. function checkRangeExpression(range, version) {
  8537. var expressions = range.split(rangeRegex);
  8538. !(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;
  8539. if (expressions.length === 1) {
  8540. return checkSimpleExpression(expressions[0], version);
  8541. } else {
  8542. var startVersion = expressions[0],
  8543. endVersion = expressions[1];
  8544. !(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;
  8545. return checkSimpleExpression('>=' + startVersion, version) && checkSimpleExpression('<=' + endVersion, version);
  8546. }
  8547. }
  8548. /**
  8549. * Checks if `range` matches `version`. `range` should be a "simple" range (ie.
  8550. * not a compound range using the " - " or "||" operators).
  8551. *
  8552. * @param {string} range
  8553. * @param {string} version
  8554. * @returns {boolean}
  8555. */
  8556. function checkSimpleExpression(range, version) {
  8557. range = range.trim();
  8558. if (range === '') {
  8559. return true;
  8560. }
  8561. var versionComponents = version.split(componentRegex);
  8562. var _getModifierAndCompon = getModifierAndComponents(range),
  8563. modifier = _getModifierAndCompon.modifier,
  8564. rangeComponents = _getModifierAndCompon.rangeComponents;
  8565. switch (modifier) {
  8566. case '<':
  8567. return checkLessThan(versionComponents, rangeComponents);
  8568. case '<=':
  8569. return checkLessThanOrEqual(versionComponents, rangeComponents);
  8570. case '>=':
  8571. return checkGreaterThanOrEqual(versionComponents, rangeComponents);
  8572. case '>':
  8573. return checkGreaterThan(versionComponents, rangeComponents);
  8574. case '~':
  8575. case '~>':
  8576. return checkApproximateVersion(versionComponents, rangeComponents);
  8577. default:
  8578. return checkEqual(versionComponents, rangeComponents);
  8579. }
  8580. }
  8581. /**
  8582. * Checks whether `a` is less than `b`.
  8583. *
  8584. * @param {array<string>} a
  8585. * @param {array<string>} b
  8586. * @returns {boolean}
  8587. */
  8588. function checkLessThan(a, b) {
  8589. return compareComponents(a, b) === -1;
  8590. }
  8591. /**
  8592. * Checks whether `a` is less than or equal to `b`.
  8593. *
  8594. * @param {array<string>} a
  8595. * @param {array<string>} b
  8596. * @returns {boolean}
  8597. */
  8598. function checkLessThanOrEqual(a, b) {
  8599. var result = compareComponents(a, b);
  8600. return result === -1 || result === 0;
  8601. }
  8602. /**
  8603. * Checks whether `a` is equal to `b`.
  8604. *
  8605. * @param {array<string>} a
  8606. * @param {array<string>} b
  8607. * @returns {boolean}
  8608. */
  8609. function checkEqual(a, b) {
  8610. return compareComponents(a, b) === 0;
  8611. }
  8612. /**
  8613. * Checks whether `a` is greater than or equal to `b`.
  8614. *
  8615. * @param {array<string>} a
  8616. * @param {array<string>} b
  8617. * @returns {boolean}
  8618. */
  8619. function checkGreaterThanOrEqual(a, b) {
  8620. var result = compareComponents(a, b);
  8621. return result === 1 || result === 0;
  8622. }
  8623. /**
  8624. * Checks whether `a` is greater than `b`.
  8625. *
  8626. * @param {array<string>} a
  8627. * @param {array<string>} b
  8628. * @returns {boolean}
  8629. */
  8630. function checkGreaterThan(a, b) {
  8631. return compareComponents(a, b) === 1;
  8632. }
  8633. /**
  8634. * Checks whether `a` is "reasonably close" to `b` (as described in
  8635. * https://www.npmjs.org/doc/misc/semver.html). For example, if `b` is "1.3.1"
  8636. * then "reasonably close" is defined as ">= 1.3.1 and < 1.4".
  8637. *
  8638. * @param {array<string>} a
  8639. * @param {array<string>} b
  8640. * @returns {boolean}
  8641. */
  8642. function checkApproximateVersion(a, b) {
  8643. var lowerBound = b.slice();
  8644. var upperBound = b.slice();
  8645. if (upperBound.length > 1) {
  8646. upperBound.pop();
  8647. }
  8648. var lastIndex = upperBound.length - 1;
  8649. var numeric = parseInt(upperBound[lastIndex], 10);
  8650. if (isNumber(numeric)) {
  8651. upperBound[lastIndex] = numeric + 1 + '';
  8652. }
  8653. return checkGreaterThanOrEqual(a, lowerBound) && checkLessThan(a, upperBound);
  8654. }
  8655. /**
  8656. * Extracts the optional modifier (<, <=, =, >=, >, ~, ~>) and version
  8657. * components from `range`.
  8658. *
  8659. * For example, given `range` ">= 1.2.3" returns an object with a `modifier` of
  8660. * `">="` and `components` of `[1, 2, 3]`.
  8661. *
  8662. * @param {string} range
  8663. * @returns {object}
  8664. */
  8665. function getModifierAndComponents(range) {
  8666. var rangeComponents = range.split(componentRegex);
  8667. var matches = rangeComponents[0].match(modifierRegex);
  8668. !matches ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'expected regex to match but it did not') : invariant_1(false) : void 0;
  8669. return {
  8670. modifier: matches[1],
  8671. rangeComponents: [matches[2]].concat(rangeComponents.slice(1))
  8672. };
  8673. }
  8674. /**
  8675. * Determines if `number` is a number.
  8676. *
  8677. * @param {mixed} number
  8678. * @returns {boolean}
  8679. */
  8680. function isNumber(number) {
  8681. return !isNaN(number) && isFinite(number);
  8682. }
  8683. /**
  8684. * Tests whether `range` is a "simple" version number without any modifiers
  8685. * (">", "~" etc).
  8686. *
  8687. * @param {string} range
  8688. * @returns {boolean}
  8689. */
  8690. function isSimpleVersion(range) {
  8691. return !getModifierAndComponents(range).modifier;
  8692. }
  8693. /**
  8694. * Zero-pads array `array` until it is at least `length` long.
  8695. *
  8696. * @param {array} array
  8697. * @param {number} length
  8698. */
  8699. function zeroPad(array, length) {
  8700. for (var i = array.length; i < length; i++) {
  8701. array[i] = '0';
  8702. }
  8703. }
  8704. /**
  8705. * Normalizes `a` and `b` in preparation for comparison by doing the following:
  8706. *
  8707. * - zero-pads `a` and `b`
  8708. * - marks any "x", "X" or "*" component in `b` as equivalent by zero-ing it out
  8709. * in both `a` and `b`
  8710. * - marks any final "*" component in `b` as a greedy wildcard by zero-ing it
  8711. * and all of its successors in `a`
  8712. *
  8713. * @param {array<string>} a
  8714. * @param {array<string>} b
  8715. * @returns {array<array<string>>}
  8716. */
  8717. function normalizeVersions(a, b) {
  8718. a = a.slice();
  8719. b = b.slice();
  8720. zeroPad(a, b.length);
  8721. // mark "x" and "*" components as equal
  8722. for (var i = 0; i < b.length; i++) {
  8723. var matches = b[i].match(/^[x*]$/i);
  8724. if (matches) {
  8725. b[i] = a[i] = '0';
  8726. // final "*" greedily zeros all remaining components
  8727. if (matches[0] === '*' && i === b.length - 1) {
  8728. for (var j = i; j < a.length; j++) {
  8729. a[j] = '0';
  8730. }
  8731. }
  8732. }
  8733. }
  8734. zeroPad(b, a.length);
  8735. return [a, b];
  8736. }
  8737. /**
  8738. * Returns the numerical -- not the lexicographical -- ordering of `a` and `b`.
  8739. *
  8740. * For example, `10-alpha` is greater than `2-beta`.
  8741. *
  8742. * @param {string} a
  8743. * @param {string} b
  8744. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  8745. * or greater than `b`, respectively
  8746. */
  8747. function compareNumeric(a, b) {
  8748. var aPrefix = a.match(numericRegex)[1];
  8749. var bPrefix = b.match(numericRegex)[1];
  8750. var aNumeric = parseInt(aPrefix, 10);
  8751. var bNumeric = parseInt(bPrefix, 10);
  8752. if (isNumber(aNumeric) && isNumber(bNumeric) && aNumeric !== bNumeric) {
  8753. return compare(aNumeric, bNumeric);
  8754. } else {
  8755. return compare(a, b);
  8756. }
  8757. }
  8758. /**
  8759. * Returns the ordering of `a` and `b`.
  8760. *
  8761. * @param {string|number} a
  8762. * @param {string|number} b
  8763. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  8764. * or greater than `b`, respectively
  8765. */
  8766. function compare(a, b) {
  8767. !(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;
  8768. if (a > b) {
  8769. return 1;
  8770. } else if (a < b) {
  8771. return -1;
  8772. } else {
  8773. return 0;
  8774. }
  8775. }
  8776. /**
  8777. * Compares arrays of version components.
  8778. *
  8779. * @param {array<string>} a
  8780. * @param {array<string>} b
  8781. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  8782. * or greater than `b`, respectively
  8783. */
  8784. function compareComponents(a, b) {
  8785. var _normalizeVersions = normalizeVersions(a, b),
  8786. aNormalized = _normalizeVersions[0],
  8787. bNormalized = _normalizeVersions[1];
  8788. for (var i = 0; i < bNormalized.length; i++) {
  8789. var result = compareNumeric(aNormalized[i], bNormalized[i]);
  8790. if (result) {
  8791. return result;
  8792. }
  8793. }
  8794. return 0;
  8795. }
  8796. var VersionRange = {
  8797. /**
  8798. * Checks whether `version` satisfies the `range` specification.
  8799. *
  8800. * We support a subset of the expressions defined in
  8801. * https://www.npmjs.org/doc/misc/semver.html:
  8802. *
  8803. * version Must match version exactly
  8804. * =version Same as just version
  8805. * >version Must be greater than version
  8806. * >=version Must be greater than or equal to version
  8807. * <version Must be less than version
  8808. * <=version Must be less than or equal to version
  8809. * ~version Must be at least version, but less than the next significant
  8810. * revision above version:
  8811. * "~1.2.3" is equivalent to ">= 1.2.3 and < 1.3"
  8812. * ~>version Equivalent to ~version
  8813. * 1.2.x Must match "1.2.x", where "x" is a wildcard that matches
  8814. * anything
  8815. * 1.2.* Similar to "1.2.x", but "*" in the trailing position is a
  8816. * "greedy" wildcard, so will match any number of additional
  8817. * components:
  8818. * "1.2.*" will match "1.2.1", "1.2.1.1", "1.2.1.1.1" etc
  8819. * * Any version
  8820. * "" (Empty string) Same as *
  8821. * v1 - v2 Equivalent to ">= v1 and <= v2"
  8822. * r1 || r2 Passes if either r1 or r2 are satisfied
  8823. *
  8824. * @param {string} range
  8825. * @param {string} version
  8826. * @returns {boolean}
  8827. */
  8828. contains: function contains(range, version) {
  8829. return checkOrExpression(range.trim(), version.trim());
  8830. }
  8831. };
  8832. var VersionRange_1 = VersionRange;
  8833. /**
  8834. * Copyright (c) 2013-present, Facebook, Inc.
  8835. *
  8836. * This source code is licensed under the MIT license found in the
  8837. * LICENSE file in the root directory of this source tree.
  8838. *
  8839. */
  8840. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  8841. /**
  8842. * Executes the provided `callback` once for each enumerable own property in the
  8843. * object and constructs a new object from the results. The `callback` is
  8844. * invoked with three arguments:
  8845. *
  8846. * - the property value
  8847. * - the property name
  8848. * - the object being traversed
  8849. *
  8850. * Properties that are added after the call to `mapObject` will not be visited
  8851. * by `callback`. If the values of existing properties are changed, the value
  8852. * passed to `callback` will be the value at the time `mapObject` visits them.
  8853. * Properties that are deleted before being visited are not visited.
  8854. *
  8855. * @grep function objectMap()
  8856. * @grep function objMap()
  8857. *
  8858. * @param {?object} object
  8859. * @param {function} callback
  8860. * @param {*} context
  8861. * @return {?object}
  8862. */
  8863. function mapObject(object, callback, context) {
  8864. if (!object) {
  8865. return null;
  8866. }
  8867. var result = {};
  8868. for (var name in object) {
  8869. if (hasOwnProperty$1.call(object, name)) {
  8870. result[name] = callback.call(context, object[name], name, object);
  8871. }
  8872. }
  8873. return result;
  8874. }
  8875. var mapObject_1 = mapObject;
  8876. /**
  8877. * Copyright (c) 2013-present, Facebook, Inc.
  8878. *
  8879. * This source code is licensed under the MIT license found in the
  8880. * LICENSE file in the root directory of this source tree.
  8881. *
  8882. *
  8883. * @typechecks static-only
  8884. */
  8885. /**
  8886. * Memoizes the return value of a function that accepts one string argument.
  8887. */
  8888. function memoizeStringOnly(callback) {
  8889. var cache = {};
  8890. return function (string) {
  8891. if (!cache.hasOwnProperty(string)) {
  8892. cache[string] = callback.call(this, string);
  8893. }
  8894. return cache[string];
  8895. };
  8896. }
  8897. var memoizeStringOnly_1 = memoizeStringOnly;
  8898. /**
  8899. * Checks to see whether `name` and `version` satisfy `query`.
  8900. *
  8901. * @param {string} name Name of the browser, device, engine or platform
  8902. * @param {?string} version Version of the browser, engine or platform
  8903. * @param {string} query Query of form "Name [range expression]"
  8904. * @param {?function} normalizer Optional pre-processor for range expression
  8905. * @return {boolean}
  8906. */
  8907. function compare$1(name, version, query, normalizer) {
  8908. // check for exact match with no version
  8909. if (name === query) {
  8910. return true;
  8911. }
  8912. // check for non-matching names
  8913. if (!query.startsWith(name)) {
  8914. return false;
  8915. }
  8916. // full comparison with version
  8917. var range = query.slice(name.length);
  8918. if (version) {
  8919. range = normalizer ? normalizer(range) : range;
  8920. return VersionRange_1.contains(range, version);
  8921. }
  8922. return false;
  8923. }
  8924. /**
  8925. * Normalizes `version` by stripping any "NT" prefix, but only on the Windows
  8926. * platform.
  8927. *
  8928. * Mimics the stripping performed by the `UserAgentWindowsPlatform` PHP class.
  8929. *
  8930. * @param {string} version
  8931. * @return {string}
  8932. */
  8933. function normalizePlatformVersion(version) {
  8934. if (UserAgentData.platformName === 'Windows') {
  8935. return version.replace(/^\s*NT/, '');
  8936. }
  8937. return version;
  8938. }
  8939. /**
  8940. * Provides client-side access to the authoritative PHP-generated User Agent
  8941. * information supplied by the server.
  8942. */
  8943. var UserAgent = {
  8944. /**
  8945. * Check if the User Agent browser matches `query`.
  8946. *
  8947. * `query` should be a string like "Chrome" or "Chrome > 33".
  8948. *
  8949. * Valid browser names include:
  8950. *
  8951. * - ACCESS NetFront
  8952. * - AOL
  8953. * - Amazon Silk
  8954. * - Android
  8955. * - BlackBerry
  8956. * - BlackBerry PlayBook
  8957. * - Chrome
  8958. * - Chrome for iOS
  8959. * - Chrome frame
  8960. * - Facebook PHP SDK
  8961. * - Facebook for iOS
  8962. * - Firefox
  8963. * - IE
  8964. * - IE Mobile
  8965. * - Mobile Safari
  8966. * - Motorola Internet Browser
  8967. * - Nokia
  8968. * - Openwave Mobile Browser
  8969. * - Opera
  8970. * - Opera Mini
  8971. * - Opera Mobile
  8972. * - Safari
  8973. * - UIWebView
  8974. * - Unknown
  8975. * - webOS
  8976. * - etc...
  8977. *
  8978. * An authoritative list can be found in the PHP `BrowserDetector` class and
  8979. * related classes in the same file (see calls to `new UserAgentBrowser` here:
  8980. * https://fburl.com/50728104).
  8981. *
  8982. * @note Function results are memoized
  8983. *
  8984. * @param {string} query Query of the form "Name [range expression]"
  8985. * @return {boolean}
  8986. */
  8987. isBrowser: function isBrowser(query) {
  8988. return compare$1(UserAgentData.browserName, UserAgentData.browserFullVersion, query);
  8989. },
  8990. /**
  8991. * Check if the User Agent browser uses a 32 or 64 bit architecture.
  8992. *
  8993. * @note Function results are memoized
  8994. *
  8995. * @param {string} query Query of the form "32" or "64".
  8996. * @return {boolean}
  8997. */
  8998. isBrowserArchitecture: function isBrowserArchitecture(query) {
  8999. return compare$1(UserAgentData.browserArchitecture, null, query);
  9000. },
  9001. /**
  9002. * Check if the User Agent device matches `query`.
  9003. *
  9004. * `query` should be a string like "iPhone" or "iPad".
  9005. *
  9006. * Valid device names include:
  9007. *
  9008. * - Kindle
  9009. * - Kindle Fire
  9010. * - Unknown
  9011. * - iPad
  9012. * - iPhone
  9013. * - iPod
  9014. * - etc...
  9015. *
  9016. * An authoritative list can be found in the PHP `DeviceDetector` class and
  9017. * related classes in the same file (see calls to `new UserAgentDevice` here:
  9018. * https://fburl.com/50728332).
  9019. *
  9020. * @note Function results are memoized
  9021. *
  9022. * @param {string} query Query of the form "Name"
  9023. * @return {boolean}
  9024. */
  9025. isDevice: function isDevice(query) {
  9026. return compare$1(UserAgentData.deviceName, null, query);
  9027. },
  9028. /**
  9029. * Check if the User Agent rendering engine matches `query`.
  9030. *
  9031. * `query` should be a string like "WebKit" or "WebKit >= 537".
  9032. *
  9033. * Valid engine names include:
  9034. *
  9035. * - Gecko
  9036. * - Presto
  9037. * - Trident
  9038. * - WebKit
  9039. * - etc...
  9040. *
  9041. * An authoritative list can be found in the PHP `RenderingEngineDetector`
  9042. * class related classes in the same file (see calls to `new
  9043. * UserAgentRenderingEngine` here: https://fburl.com/50728617).
  9044. *
  9045. * @note Function results are memoized
  9046. *
  9047. * @param {string} query Query of the form "Name [range expression]"
  9048. * @return {boolean}
  9049. */
  9050. isEngine: function isEngine(query) {
  9051. return compare$1(UserAgentData.engineName, UserAgentData.engineVersion, query);
  9052. },
  9053. /**
  9054. * Check if the User Agent platform matches `query`.
  9055. *
  9056. * `query` should be a string like "Windows" or "iOS 5 - 6".
  9057. *
  9058. * Valid platform names include:
  9059. *
  9060. * - Android
  9061. * - BlackBerry OS
  9062. * - Java ME
  9063. * - Linux
  9064. * - Mac OS X
  9065. * - Mac OS X Calendar
  9066. * - Mac OS X Internet Account
  9067. * - Symbian
  9068. * - SymbianOS
  9069. * - Windows
  9070. * - Windows Mobile
  9071. * - Windows Phone
  9072. * - iOS
  9073. * - iOS Facebook Integration Account
  9074. * - iOS Facebook Social Sharing UI
  9075. * - webOS
  9076. * - Chrome OS
  9077. * - etc...
  9078. *
  9079. * An authoritative list can be found in the PHP `PlatformDetector` class and
  9080. * related classes in the same file (see calls to `new UserAgentPlatform`
  9081. * here: https://fburl.com/50729226).
  9082. *
  9083. * @note Function results are memoized
  9084. *
  9085. * @param {string} query Query of the form "Name [range expression]"
  9086. * @return {boolean}
  9087. */
  9088. isPlatform: function isPlatform(query) {
  9089. return compare$1(UserAgentData.platformName, UserAgentData.platformFullVersion, query, normalizePlatformVersion);
  9090. },
  9091. /**
  9092. * Check if the User Agent platform is a 32 or 64 bit architecture.
  9093. *
  9094. * @note Function results are memoized
  9095. *
  9096. * @param {string} query Query of the form "32" or "64".
  9097. * @return {boolean}
  9098. */
  9099. isPlatformArchitecture: function isPlatformArchitecture(query) {
  9100. return compare$1(UserAgentData.platformArchitecture, null, query);
  9101. }
  9102. };
  9103. var UserAgent_1 = mapObject_1(UserAgent, memoizeStringOnly_1);
  9104. function _classCallCheck$9(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9105. 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; }
  9106. 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; }
  9107. // In IE, spans with <br> tags render as two newlines. By rendering a span
  9108. // with only a newline character, we can be sure to render a single line.
  9109. var useNewlineChar = UserAgent_1.isBrowser('IE <= 11');
  9110. /**
  9111. * Check whether the node should be considered a newline.
  9112. */
  9113. function isNewline(node) {
  9114. return useNewlineChar ? node.textContent === '\n' : node.tagName === 'BR';
  9115. }
  9116. /**
  9117. * Placeholder elements for empty text content.
  9118. *
  9119. * What is this `data-text` attribute, anyway? It turns out that we need to
  9120. * put an attribute on the lowest-level text node in order to preserve correct
  9121. * spellcheck handling. If the <span> is naked, Chrome and Safari may do
  9122. * bizarre things to do the DOM -- split text nodes, create extra spans, etc.
  9123. * If the <span> has an attribute, this appears not to happen.
  9124. * See http://jsfiddle.net/9khdavod/ for the failure case, and
  9125. * http://jsfiddle.net/7pg143f7/ for the fixed case.
  9126. */
  9127. var NEWLINE_A = useNewlineChar ? React.createElement(
  9128. 'span',
  9129. { key: 'A', 'data-text': 'true' },
  9130. '\n'
  9131. ) : React.createElement('br', { key: 'A', 'data-text': 'true' });
  9132. var NEWLINE_B = useNewlineChar ? React.createElement(
  9133. 'span',
  9134. { key: 'B', 'data-text': 'true' },
  9135. '\n'
  9136. ) : React.createElement('br', { key: 'B', 'data-text': 'true' });
  9137. /**
  9138. * The lowest-level component in a `DraftEditor`, the text node component
  9139. * replaces the default React text node implementation. This allows us to
  9140. * perform custom handling of newline behavior and avoid re-rendering text
  9141. * nodes with DOM state that already matches the expectations of our immutable
  9142. * editor state.
  9143. */
  9144. var DraftEditorTextNode = function (_React$Component) {
  9145. _inherits$6(DraftEditorTextNode, _React$Component);
  9146. function DraftEditorTextNode(props) {
  9147. _classCallCheck$9(this, DraftEditorTextNode);
  9148. // By flipping this flag, we also keep flipping keys which forces
  9149. // React to remount this node every time it rerenders.
  9150. var _this = _possibleConstructorReturn$6(this, _React$Component.call(this, props));
  9151. _this._forceFlag = false;
  9152. return _this;
  9153. }
  9154. DraftEditorTextNode.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  9155. var node = reactDom.findDOMNode(this);
  9156. var shouldBeNewline = nextProps.children === '';
  9157. !(node instanceof Element) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'node is not an Element') : invariant_1(false) : void 0;
  9158. if (shouldBeNewline) {
  9159. return !isNewline(node);
  9160. }
  9161. return node.textContent !== nextProps.children;
  9162. };
  9163. DraftEditorTextNode.prototype.componentDidMount = function componentDidMount() {
  9164. this._forceFlag = !this._forceFlag;
  9165. };
  9166. DraftEditorTextNode.prototype.componentDidUpdate = function componentDidUpdate() {
  9167. this._forceFlag = !this._forceFlag;
  9168. };
  9169. DraftEditorTextNode.prototype.render = function render() {
  9170. if (this.props.children === '') {
  9171. return this._forceFlag ? NEWLINE_A : NEWLINE_B;
  9172. }
  9173. return React.createElement(
  9174. 'span',
  9175. { key: this._forceFlag ? 'A' : 'B', 'data-text': 'true' },
  9176. this.props.children
  9177. );
  9178. };
  9179. return DraftEditorTextNode;
  9180. }(React.Component);
  9181. var DraftEditorTextNode_react = DraftEditorTextNode;
  9182. /**
  9183. * Copyright (c) 2013-present, Facebook, Inc.
  9184. * All rights reserved.
  9185. *
  9186. * This source code is licensed under the BSD-style license found in the
  9187. * LICENSE file in the root directory of this source tree. An additional grant
  9188. * of patent rights can be found in the PATENTS file in the same directory.
  9189. *
  9190. * @providesModule DraftJsDebugLogging
  9191. */
  9192. var DraftJsDebugLogging = {
  9193. logSelectionStateFailure: function logSelectionStateFailure() {
  9194. return null;
  9195. }
  9196. };
  9197. /**
  9198. * Copyright (c) 2013-present, Facebook, Inc.
  9199. *
  9200. * This source code is licensed under the MIT license found in the
  9201. * LICENSE file in the root directory of this source tree.
  9202. *
  9203. * @typechecks
  9204. */
  9205. /**
  9206. * @param {*} object The object to check.
  9207. * @return {boolean} Whether or not the object is a DOM node.
  9208. */
  9209. function isNode(object) {
  9210. var doc = object ? object.ownerDocument || object : document;
  9211. var defaultView = doc.defaultView || window;
  9212. return !!(object && (typeof defaultView.Node === 'function' ? object instanceof defaultView.Node : typeof object === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string'));
  9213. }
  9214. var isNode_1 = isNode;
  9215. /**
  9216. * Copyright (c) 2013-present, Facebook, Inc.
  9217. *
  9218. * This source code is licensed under the MIT license found in the
  9219. * LICENSE file in the root directory of this source tree.
  9220. *
  9221. * @typechecks
  9222. */
  9223. /**
  9224. * @param {*} object The object to check.
  9225. * @return {boolean} Whether or not the object is a DOM text node.
  9226. */
  9227. function isTextNode(object) {
  9228. return isNode_1(object) && object.nodeType == 3;
  9229. }
  9230. var isTextNode_1 = isTextNode;
  9231. /**
  9232. * Copyright (c) 2013-present, Facebook, Inc.
  9233. *
  9234. * This source code is licensed under the MIT license found in the
  9235. * LICENSE file in the root directory of this source tree.
  9236. *
  9237. *
  9238. */
  9239. /*eslint-disable no-bitwise */
  9240. /**
  9241. * Checks if a given DOM node contains or is another DOM node.
  9242. */
  9243. function containsNode(outerNode, innerNode) {
  9244. if (!outerNode || !innerNode) {
  9245. return false;
  9246. } else if (outerNode === innerNode) {
  9247. return true;
  9248. } else if (isTextNode_1(outerNode)) {
  9249. return false;
  9250. } else if (isTextNode_1(innerNode)) {
  9251. return containsNode(outerNode, innerNode.parentNode);
  9252. } else if ('contains' in outerNode) {
  9253. return outerNode.contains(innerNode);
  9254. } else if (outerNode.compareDocumentPosition) {
  9255. return !!(outerNode.compareDocumentPosition(innerNode) & 16);
  9256. } else {
  9257. return false;
  9258. }
  9259. }
  9260. var containsNode_1 = containsNode;
  9261. /**
  9262. * Copyright (c) 2013-present, Facebook, Inc.
  9263. *
  9264. * This source code is licensed under the MIT license found in the
  9265. * LICENSE file in the root directory of this source tree.
  9266. *
  9267. * @typechecks
  9268. */
  9269. /* eslint-disable fb-www/typeof-undefined */
  9270. /**
  9271. * Same as document.activeElement but wraps in a try-catch block. In IE it is
  9272. * not safe to call document.activeElement if there is nothing focused.
  9273. *
  9274. * The activeElement will be null only if the document or document body is not
  9275. * yet defined.
  9276. *
  9277. * @param {?DOMDocument} doc Defaults to current document.
  9278. * @return {?DOMElement}
  9279. */
  9280. function getActiveElement(doc) /*?DOMElement*/{
  9281. doc = doc || (typeof document !== 'undefined' ? document : undefined);
  9282. if (typeof doc === 'undefined') {
  9283. return null;
  9284. }
  9285. try {
  9286. return doc.activeElement || doc.body;
  9287. } catch (e) {
  9288. return doc.body;
  9289. }
  9290. }
  9291. var getActiveElement_1 = getActiveElement;
  9292. function getAnonymizedDOM(node, getNodeLabels) {
  9293. if (!node) {
  9294. return '[empty]';
  9295. }
  9296. var anonymized = anonymizeTextWithin(node, getNodeLabels);
  9297. if (anonymized.nodeType === Node.TEXT_NODE) {
  9298. return anonymized.textContent;
  9299. }
  9300. !(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;
  9301. return anonymized.outerHTML;
  9302. }
  9303. function anonymizeTextWithin(node, getNodeLabels) {
  9304. var labels = getNodeLabels !== undefined ? getNodeLabels(node) : [];
  9305. if (node.nodeType === Node.TEXT_NODE) {
  9306. var length = node.textContent.length;
  9307. return document.createTextNode('[text ' + length + (labels.length ? ' | ' + labels.join(', ') : '') + ']');
  9308. }
  9309. var clone = node.cloneNode();
  9310. if (clone.nodeType === 1 && labels.length) {
  9311. clone.setAttribute('data-labels', labels.join(', '));
  9312. }
  9313. var childNodes = node.childNodes;
  9314. for (var ii = 0; ii < childNodes.length; ii++) {
  9315. clone.appendChild(anonymizeTextWithin(childNodes[ii], getNodeLabels));
  9316. }
  9317. return clone;
  9318. }
  9319. function getAnonymizedEditorDOM(node, getNodeLabels) {
  9320. // grabbing the DOM content of the Draft editor
  9321. var currentNode = node;
  9322. while (currentNode) {
  9323. if (currentNode instanceof Element && currentNode.hasAttribute('contenteditable')) {
  9324. // found the Draft editor container
  9325. return getAnonymizedDOM(currentNode, getNodeLabels);
  9326. } else {
  9327. currentNode = currentNode.parentNode;
  9328. }
  9329. }
  9330. return 'Could not find contentEditable parent of node';
  9331. }
  9332. function getNodeLength(node) {
  9333. return node.nodeValue === null ? node.childNodes.length : node.nodeValue.length;
  9334. }
  9335. /**
  9336. * In modern non-IE browsers, we can support both forward and backward
  9337. * selections.
  9338. *
  9339. * Note: IE10+ supports the Selection object, but it does not support
  9340. * the `extend` method, which means that even in modern IE, it's not possible
  9341. * to programatically create a backward selection. Thus, for all IE
  9342. * versions, we use the old IE API to create our selections.
  9343. */
  9344. function setDraftEditorSelection(selectionState, node, blockKey, nodeStart, nodeEnd) {
  9345. // It's possible that the editor has been removed from the DOM but
  9346. // our selection code doesn't know it yet. Forcing selection in
  9347. // this case may lead to errors, so just bail now.
  9348. if (!containsNode_1(document.documentElement, node)) {
  9349. return;
  9350. }
  9351. var selection = commonjsGlobal.getSelection();
  9352. var anchorKey = selectionState.getAnchorKey();
  9353. var anchorOffset = selectionState.getAnchorOffset();
  9354. var focusKey = selectionState.getFocusKey();
  9355. var focusOffset = selectionState.getFocusOffset();
  9356. var isBackward = selectionState.getIsBackward();
  9357. // IE doesn't support backward selection. Swap key/offset pairs.
  9358. if (!selection.extend && isBackward) {
  9359. var tempKey = anchorKey;
  9360. var tempOffset = anchorOffset;
  9361. anchorKey = focusKey;
  9362. anchorOffset = focusOffset;
  9363. focusKey = tempKey;
  9364. focusOffset = tempOffset;
  9365. isBackward = false;
  9366. }
  9367. var hasAnchor = anchorKey === blockKey && nodeStart <= anchorOffset && nodeEnd >= anchorOffset;
  9368. var hasFocus = focusKey === blockKey && nodeStart <= focusOffset && nodeEnd >= focusOffset;
  9369. // If the selection is entirely bound within this node, set the selection
  9370. // and be done.
  9371. if (hasAnchor && hasFocus) {
  9372. selection.removeAllRanges();
  9373. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  9374. addFocusToSelection(selection, node, focusOffset - nodeStart, selectionState);
  9375. return;
  9376. }
  9377. if (!isBackward) {
  9378. // If the anchor is within this node, set the range start.
  9379. if (hasAnchor) {
  9380. selection.removeAllRanges();
  9381. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  9382. }
  9383. // If the focus is within this node, we can assume that we have
  9384. // already set the appropriate start range on the selection, and
  9385. // can simply extend the selection.
  9386. if (hasFocus) {
  9387. addFocusToSelection(selection, node, focusOffset - nodeStart, selectionState);
  9388. }
  9389. } else {
  9390. // If this node has the focus, set the selection range to be a
  9391. // collapsed range beginning here. Later, when we encounter the anchor,
  9392. // we'll use this information to extend the selection.
  9393. if (hasFocus) {
  9394. selection.removeAllRanges();
  9395. addPointToSelection(selection, node, focusOffset - nodeStart, selectionState);
  9396. }
  9397. // If this node has the anchor, we may assume that the correct
  9398. // focus information is already stored on the selection object.
  9399. // We keep track of it, reset the selection range, and extend it
  9400. // back to the focus point.
  9401. if (hasAnchor) {
  9402. var storedFocusNode = selection.focusNode;
  9403. var storedFocusOffset = selection.focusOffset;
  9404. selection.removeAllRanges();
  9405. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  9406. addFocusToSelection(selection, storedFocusNode, storedFocusOffset, selectionState);
  9407. }
  9408. }
  9409. }
  9410. /**
  9411. * Extend selection towards focus point.
  9412. */
  9413. function addFocusToSelection(selection, node, offset, selectionState) {
  9414. var activeElement = getActiveElement_1();
  9415. if (selection.extend && containsNode_1(activeElement, node)) {
  9416. // If `extend` is called while another element has focus, an error is
  9417. // thrown. We therefore disable `extend` if the active element is somewhere
  9418. // other than the node we are selecting. This should only occur in Firefox,
  9419. // since it is the only browser to support multiple selections.
  9420. // See https://bugzilla.mozilla.org/show_bug.cgi?id=921444.
  9421. // logging to catch bug that is being reported in t16250795
  9422. if (offset > getNodeLength(node)) {
  9423. // the call to 'selection.extend' is about to throw
  9424. DraftJsDebugLogging.logSelectionStateFailure({
  9425. anonymizedDom: getAnonymizedEditorDOM(node),
  9426. extraParams: JSON.stringify({ offset: offset }),
  9427. selectionState: JSON.stringify(selectionState.toJS())
  9428. });
  9429. }
  9430. // logging to catch bug that is being reported in t18110632
  9431. var nodeWasFocus = node === selection.focusNode;
  9432. try {
  9433. selection.extend(node, offset);
  9434. } catch (e) {
  9435. DraftJsDebugLogging.logSelectionStateFailure({
  9436. anonymizedDom: getAnonymizedEditorDOM(node, function (n) {
  9437. var labels = [];
  9438. if (n === activeElement) {
  9439. labels.push('active element');
  9440. }
  9441. if (n === selection.anchorNode) {
  9442. labels.push('selection anchor node');
  9443. }
  9444. if (n === selection.focusNode) {
  9445. labels.push('selection focus node');
  9446. }
  9447. return labels;
  9448. }),
  9449. extraParams: JSON.stringify({
  9450. activeElementName: activeElement ? activeElement.nodeName : null,
  9451. nodeIsFocus: node === selection.focusNode,
  9452. nodeWasFocus: nodeWasFocus,
  9453. selectionRangeCount: selection.rangeCount,
  9454. selectionAnchorNodeName: selection.anchorNode ? selection.anchorNode.nodeName : null,
  9455. selectionAnchorOffset: selection.anchorOffset,
  9456. selectionFocusNodeName: selection.focusNode ? selection.focusNode.nodeName : null,
  9457. selectionFocusOffset: selection.focusOffset,
  9458. message: e ? '' + e : null,
  9459. offset: offset
  9460. }, null, 2),
  9461. selectionState: JSON.stringify(selectionState.toJS(), null, 2)
  9462. });
  9463. // allow the error to be thrown -
  9464. // better than continuing in a broken state
  9465. throw e;
  9466. }
  9467. } else {
  9468. // IE doesn't support extend. This will mean no backward selection.
  9469. // Extract the existing selection range and add focus to it.
  9470. // Additionally, clone the selection range. IE11 throws an
  9471. // InvalidStateError when attempting to access selection properties
  9472. // after the range is detached.
  9473. var range = selection.getRangeAt(0);
  9474. range.setEnd(node, offset);
  9475. selection.addRange(range.cloneRange());
  9476. }
  9477. }
  9478. function addPointToSelection(selection, node, offset, selectionState) {
  9479. var range = document.createRange();
  9480. // logging to catch bug that is being reported in t16250795
  9481. if (offset > getNodeLength(node)) {
  9482. // in this case we know that the call to 'range.setStart' is about to throw
  9483. DraftJsDebugLogging.logSelectionStateFailure({
  9484. anonymizedDom: getAnonymizedEditorDOM(node),
  9485. extraParams: JSON.stringify({ offset: offset }),
  9486. selectionState: JSON.stringify(selectionState.toJS())
  9487. });
  9488. }
  9489. range.setStart(node, offset);
  9490. selection.addRange(range);
  9491. }
  9492. var setDraftEditorSelection_1 = setDraftEditorSelection;
  9493. function _classCallCheck$a(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9494. 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; }
  9495. 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; }
  9496. /**
  9497. * All leaf nodes in the editor are spans with single text nodes. Leaf
  9498. * elements are styled based on the merging of an optional custom style map
  9499. * and a default style map.
  9500. *
  9501. * `DraftEditorLeaf` also provides a wrapper for calling into the imperative
  9502. * DOM Selection API. In this way, top-level components can declaratively
  9503. * maintain the selection state.
  9504. */
  9505. var DraftEditorLeaf = function (_React$Component) {
  9506. _inherits$7(DraftEditorLeaf, _React$Component);
  9507. function DraftEditorLeaf() {
  9508. _classCallCheck$a(this, DraftEditorLeaf);
  9509. return _possibleConstructorReturn$7(this, _React$Component.apply(this, arguments));
  9510. }
  9511. DraftEditorLeaf.prototype._setSelection = function _setSelection() {
  9512. var selection = this.props.selection;
  9513. // If selection state is irrelevant to the parent block, no-op.
  9514. if (selection == null || !selection.getHasFocus()) {
  9515. return;
  9516. }
  9517. var _props = this.props,
  9518. block = _props.block,
  9519. start = _props.start,
  9520. text = _props.text;
  9521. var blockKey = block.getKey();
  9522. var end = start + text.length;
  9523. if (!selection.hasEdgeWithin(blockKey, start, end)) {
  9524. return;
  9525. }
  9526. // Determine the appropriate target node for selection. If the child
  9527. // is not a text node, it is a <br /> spacer. In this case, use the
  9528. // <span> itself as the selection target.
  9529. var node = reactDom.findDOMNode(this);
  9530. !node ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing node') : invariant_1(false) : void 0;
  9531. var child = node.firstChild;
  9532. !child ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing child') : invariant_1(false) : void 0;
  9533. var targetNode = void 0;
  9534. if (child.nodeType === Node.TEXT_NODE) {
  9535. targetNode = child;
  9536. } else if (child.tagName === 'BR') {
  9537. targetNode = node;
  9538. } else {
  9539. targetNode = child.firstChild;
  9540. !targetNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing targetNode') : invariant_1(false) : void 0;
  9541. }
  9542. setDraftEditorSelection_1(selection, targetNode, blockKey, start, end);
  9543. };
  9544. /**
  9545. * By making individual leaf instances aware of their context within
  9546. * the text of the editor, we can set our selection range more
  9547. * easily than we could in the non-React world.
  9548. *
  9549. * Note that this depends on our maintaining tight control over the
  9550. * DOM structure of the DraftEditor component. If leaves had multiple
  9551. * text nodes, this would be harder.
  9552. */
  9553. DraftEditorLeaf.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  9554. var leafNode = reactDom.findDOMNode(this.leaf);
  9555. !leafNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing leafNode') : invariant_1(false) : void 0;
  9556. return leafNode.textContent !== nextProps.text || nextProps.styleSet !== this.props.styleSet || nextProps.forceSelection;
  9557. };
  9558. DraftEditorLeaf.prototype.componentDidUpdate = function componentDidUpdate() {
  9559. this._setSelection();
  9560. };
  9561. DraftEditorLeaf.prototype.componentDidMount = function componentDidMount() {
  9562. this._setSelection();
  9563. };
  9564. DraftEditorLeaf.prototype.render = function render() {
  9565. var _this2 = this;
  9566. var block = this.props.block;
  9567. var text = this.props.text;
  9568. // If the leaf is at the end of its block and ends in a soft newline, append
  9569. // an extra line feed character. Browsers collapse trailing newline
  9570. // characters, which leaves the cursor in the wrong place after a
  9571. // shift+enter. The extra character repairs this.
  9572. if (text.endsWith('\n') && this.props.isLast) {
  9573. text += '\n';
  9574. }
  9575. var _props2 = this.props,
  9576. customStyleMap = _props2.customStyleMap,
  9577. customStyleFn = _props2.customStyleFn,
  9578. offsetKey = _props2.offsetKey,
  9579. styleSet = _props2.styleSet;
  9580. var styleObj = styleSet.reduce(function (map, styleName) {
  9581. var mergedStyles = {};
  9582. var style = customStyleMap[styleName];
  9583. if (style !== undefined && map.textDecoration !== style.textDecoration) {
  9584. // .trim() is necessary for IE9/10/11 and Edge
  9585. mergedStyles.textDecoration = [map.textDecoration, style.textDecoration].join(' ').trim();
  9586. }
  9587. return objectAssign(map, style, mergedStyles);
  9588. }, {});
  9589. if (customStyleFn) {
  9590. var newStyles = customStyleFn(styleSet, block);
  9591. styleObj = objectAssign(styleObj, newStyles);
  9592. }
  9593. return React.createElement(
  9594. 'span',
  9595. {
  9596. 'data-offset-key': offsetKey,
  9597. ref: function ref(_ref) {
  9598. return _this2.leaf = _ref;
  9599. },
  9600. style: styleObj },
  9601. React.createElement(
  9602. DraftEditorTextNode_react,
  9603. null,
  9604. text
  9605. )
  9606. );
  9607. };
  9608. return DraftEditorLeaf;
  9609. }(React.Component);
  9610. var DraftEditorLeaf_react = DraftEditorLeaf;
  9611. /**
  9612. * Copyright (c) 2013-present, Facebook, Inc.
  9613. * All rights reserved.
  9614. *
  9615. * This source code is licensed under the BSD-style license found in the
  9616. * LICENSE file in the root directory of this source tree. An additional grant
  9617. * of patent rights can be found in the PATENTS file in the same directory.
  9618. *
  9619. * @providesModule DraftOffsetKey
  9620. * @format
  9621. *
  9622. */
  9623. var KEY_DELIMITER = '-';
  9624. var DraftOffsetKey = {
  9625. encode: function encode(blockKey, decoratorKey, leafKey) {
  9626. return blockKey + KEY_DELIMITER + decoratorKey + KEY_DELIMITER + leafKey;
  9627. },
  9628. decode: function decode(offsetKey) {
  9629. var _offsetKey$split = offsetKey.split(KEY_DELIMITER),
  9630. blockKey = _offsetKey$split[0],
  9631. decoratorKey = _offsetKey$split[1],
  9632. leafKey = _offsetKey$split[2];
  9633. return {
  9634. blockKey: blockKey,
  9635. decoratorKey: parseInt(decoratorKey, 10),
  9636. leafKey: parseInt(leafKey, 10)
  9637. };
  9638. }
  9639. };
  9640. var DraftOffsetKey_1 = DraftOffsetKey;
  9641. /**
  9642. * Copyright (c) 2013-present, Facebook, Inc.
  9643. *
  9644. * This source code is licensed under the MIT license found in the
  9645. * LICENSE file in the root directory of this source tree.
  9646. *
  9647. */
  9648. /**
  9649. * @param {DOMElement} element
  9650. * @param {DOMDocument} doc
  9651. * @return {boolean}
  9652. */
  9653. function _isViewportScrollElement(element, doc) {
  9654. return !!doc && (element === doc.documentElement || element === doc.body);
  9655. }
  9656. /**
  9657. * Scroll Module. This class contains 4 simple static functions
  9658. * to be used to access Element.scrollTop/scrollLeft properties.
  9659. * To solve the inconsistencies between browsers when either
  9660. * document.body or document.documentElement is supplied,
  9661. * below logic will be used to alleviate the issue:
  9662. *
  9663. * 1. If 'element' is either 'document.body' or 'document.documentElement,
  9664. * get whichever element's 'scroll{Top,Left}' is larger.
  9665. * 2. If 'element' is either 'document.body' or 'document.documentElement',
  9666. * set the 'scroll{Top,Left}' on both elements.
  9667. */
  9668. var Scroll = {
  9669. /**
  9670. * @param {DOMElement} element
  9671. * @return {number}
  9672. */
  9673. getTop: function getTop(element) {
  9674. var doc = element.ownerDocument;
  9675. return _isViewportScrollElement(element, doc) ?
  9676. // In practice, they will either both have the same value,
  9677. // or one will be zero and the other will be the scroll position
  9678. // of the viewport. So we can use `X || Y` instead of `Math.max(X, Y)`
  9679. doc.body.scrollTop || doc.documentElement.scrollTop : element.scrollTop;
  9680. },
  9681. /**
  9682. * @param {DOMElement} element
  9683. * @param {number} newTop
  9684. */
  9685. setTop: function setTop(element, newTop) {
  9686. var doc = element.ownerDocument;
  9687. if (_isViewportScrollElement(element, doc)) {
  9688. doc.body.scrollTop = doc.documentElement.scrollTop = newTop;
  9689. } else {
  9690. element.scrollTop = newTop;
  9691. }
  9692. },
  9693. /**
  9694. * @param {DOMElement} element
  9695. * @return {number}
  9696. */
  9697. getLeft: function getLeft(element) {
  9698. var doc = element.ownerDocument;
  9699. return _isViewportScrollElement(element, doc) ? doc.body.scrollLeft || doc.documentElement.scrollLeft : element.scrollLeft;
  9700. },
  9701. /**
  9702. * @param {DOMElement} element
  9703. * @param {number} newLeft
  9704. */
  9705. setLeft: function setLeft(element, newLeft) {
  9706. var doc = element.ownerDocument;
  9707. if (_isViewportScrollElement(element, doc)) {
  9708. doc.body.scrollLeft = doc.documentElement.scrollLeft = newLeft;
  9709. } else {
  9710. element.scrollLeft = newLeft;
  9711. }
  9712. }
  9713. };
  9714. var Scroll_1 = Scroll;
  9715. /**
  9716. * Copyright (c) 2013-present, Facebook, Inc.
  9717. *
  9718. * This source code is licensed under the MIT license found in the
  9719. * LICENSE file in the root directory of this source tree.
  9720. *
  9721. * @typechecks
  9722. */
  9723. var _hyphenPattern = /-(.)/g;
  9724. /**
  9725. * Camelcases a hyphenated string, for example:
  9726. *
  9727. * > camelize('background-color')
  9728. * < "backgroundColor"
  9729. *
  9730. * @param {string} string
  9731. * @return {string}
  9732. */
  9733. function camelize(string) {
  9734. return string.replace(_hyphenPattern, function (_, character) {
  9735. return character.toUpperCase();
  9736. });
  9737. }
  9738. var camelize_1 = camelize;
  9739. /**
  9740. * Copyright (c) 2013-present, Facebook, Inc.
  9741. *
  9742. * This source code is licensed under the MIT license found in the
  9743. * LICENSE file in the root directory of this source tree.
  9744. *
  9745. * @typechecks
  9746. */
  9747. var _uppercasePattern = /([A-Z])/g;
  9748. /**
  9749. * Hyphenates a camelcased string, for example:
  9750. *
  9751. * > hyphenate('backgroundColor')
  9752. * < "background-color"
  9753. *
  9754. * For CSS style names, use `hyphenateStyleName` instead which works properly
  9755. * with all vendor prefixes, including `ms`.
  9756. *
  9757. * @param {string} string
  9758. * @return {string}
  9759. */
  9760. function hyphenate(string) {
  9761. return string.replace(_uppercasePattern, '-$1').toLowerCase();
  9762. }
  9763. var hyphenate_1 = hyphenate;
  9764. /**
  9765. * Copyright (c) 2013-present, Facebook, Inc.
  9766. *
  9767. * This source code is licensed under the MIT license found in the
  9768. * LICENSE file in the root directory of this source tree.
  9769. *
  9770. * @typechecks
  9771. */
  9772. function asString(value) /*?string*/{
  9773. return value == null ? value : String(value);
  9774. }
  9775. function getStyleProperty( /*DOMNode*/node, /*string*/name) /*?string*/{
  9776. var computedStyle = void 0;
  9777. // W3C Standard
  9778. if (window.getComputedStyle) {
  9779. // In certain cases such as within an iframe in FF3, this returns null.
  9780. computedStyle = window.getComputedStyle(node, null);
  9781. if (computedStyle) {
  9782. return asString(computedStyle.getPropertyValue(hyphenate_1(name)));
  9783. }
  9784. }
  9785. // Safari
  9786. if (document.defaultView && document.defaultView.getComputedStyle) {
  9787. computedStyle = document.defaultView.getComputedStyle(node, null);
  9788. // A Safari bug causes this to return null for `display: none` elements.
  9789. if (computedStyle) {
  9790. return asString(computedStyle.getPropertyValue(hyphenate_1(name)));
  9791. }
  9792. if (name === 'display') {
  9793. return 'none';
  9794. }
  9795. }
  9796. // Internet Explorer
  9797. if (node.currentStyle) {
  9798. if (name === 'float') {
  9799. return asString(node.currentStyle.cssFloat || node.currentStyle.styleFloat);
  9800. }
  9801. return asString(node.currentStyle[camelize_1(name)]);
  9802. }
  9803. return asString(node.style && node.style[camelize_1(name)]);
  9804. }
  9805. var getStyleProperty_1 = getStyleProperty;
  9806. /**
  9807. * Copyright (c) 2013-present, Facebook, Inc.
  9808. *
  9809. * This source code is licensed under the MIT license found in the
  9810. * LICENSE file in the root directory of this source tree.
  9811. *
  9812. * @typechecks
  9813. */
  9814. /**
  9815. * @param {DOMNode} element [description]
  9816. * @param {string} name Overflow style property name.
  9817. * @return {boolean} True if the supplied ndoe is scrollable.
  9818. */
  9819. function _isNodeScrollable(element, name) {
  9820. var overflow = Style.get(element, name);
  9821. return overflow === 'auto' || overflow === 'scroll';
  9822. }
  9823. /**
  9824. * Utilities for querying and mutating style properties.
  9825. */
  9826. var Style = {
  9827. /**
  9828. * Gets the style property for the supplied node. This will return either the
  9829. * computed style, if available, or the declared style.
  9830. *
  9831. * @param {DOMNode} node
  9832. * @param {string} name Style property name.
  9833. * @return {?string} Style property value.
  9834. */
  9835. get: getStyleProperty_1,
  9836. /**
  9837. * Determines the nearest ancestor of a node that is scrollable.
  9838. *
  9839. * NOTE: This can be expensive if used repeatedly or on a node nested deeply.
  9840. *
  9841. * @param {?DOMNode} node Node from which to start searching.
  9842. * @return {?DOMWindow|DOMElement} Scroll parent of the supplied node.
  9843. */
  9844. getScrollParent: function getScrollParent(node) {
  9845. if (!node) {
  9846. return null;
  9847. }
  9848. var ownerDocument = node.ownerDocument;
  9849. while (node && node !== ownerDocument.body) {
  9850. if (_isNodeScrollable(node, 'overflow') || _isNodeScrollable(node, 'overflowY') || _isNodeScrollable(node, 'overflowX')) {
  9851. return node;
  9852. }
  9853. node = node.parentNode;
  9854. }
  9855. return ownerDocument.defaultView || ownerDocument.parentWindow;
  9856. }
  9857. };
  9858. var Style_1 = Style;
  9859. /**
  9860. * Copyright (c) 2013-present, Facebook, Inc.
  9861. *
  9862. * This source code is licensed under the MIT license found in the
  9863. * LICENSE file in the root directory of this source tree.
  9864. *
  9865. * @typechecks
  9866. */
  9867. /**
  9868. * Gets an element's bounding rect in pixels relative to the viewport.
  9869. *
  9870. * @param {DOMElement} elem
  9871. * @return {object}
  9872. */
  9873. function getElementRect(elem) {
  9874. var docElem = elem.ownerDocument.documentElement;
  9875. // FF 2, Safari 3 and Opera 9.5- do not support getBoundingClientRect().
  9876. // IE9- will throw if the element is not in the document.
  9877. if (!('getBoundingClientRect' in elem) || !containsNode_1(docElem, elem)) {
  9878. return {
  9879. left: 0,
  9880. right: 0,
  9881. top: 0,
  9882. bottom: 0
  9883. };
  9884. }
  9885. // Subtracts clientTop/Left because IE8- added a 2px border to the
  9886. // <html> element (see http://fburl.com/1493213). IE 7 in
  9887. // Quicksmode does not report clientLeft/clientTop so there
  9888. // will be an unaccounted offset of 2px when in quirksmode
  9889. var rect = elem.getBoundingClientRect();
  9890. return {
  9891. left: Math.round(rect.left) - docElem.clientLeft,
  9892. right: Math.round(rect.right) - docElem.clientLeft,
  9893. top: Math.round(rect.top) - docElem.clientTop,
  9894. bottom: Math.round(rect.bottom) - docElem.clientTop
  9895. };
  9896. }
  9897. var getElementRect_1 = getElementRect;
  9898. /**
  9899. * Copyright (c) 2013-present, Facebook, Inc.
  9900. *
  9901. * This source code is licensed under the MIT license found in the
  9902. * LICENSE file in the root directory of this source tree.
  9903. *
  9904. * @typechecks
  9905. */
  9906. /**
  9907. * Gets an element's position in pixels relative to the viewport. The returned
  9908. * object represents the position of the element's top left corner.
  9909. *
  9910. * @param {DOMElement} element
  9911. * @return {object}
  9912. */
  9913. function getElementPosition(element) {
  9914. var rect = getElementRect_1(element);
  9915. return {
  9916. x: rect.left,
  9917. y: rect.top,
  9918. width: rect.right - rect.left,
  9919. height: rect.bottom - rect.top
  9920. };
  9921. }
  9922. var getElementPosition_1 = getElementPosition;
  9923. /**
  9924. * Copyright (c) 2013-present, Facebook, Inc.
  9925. *
  9926. * This source code is licensed under the MIT license found in the
  9927. * LICENSE file in the root directory of this source tree.
  9928. *
  9929. * @typechecks
  9930. */
  9931. var isWebkit = typeof navigator !== 'undefined' && navigator.userAgent.indexOf('AppleWebKit') > -1;
  9932. /**
  9933. * Gets the element with the document scroll properties such as `scrollLeft` and
  9934. * `scrollHeight`. This may differ across different browsers.
  9935. *
  9936. * NOTE: The return value can be null if the DOM is not yet ready.
  9937. *
  9938. * @param {?DOMDocument} doc Defaults to current document.
  9939. * @return {?DOMElement}
  9940. */
  9941. function getDocumentScrollElement(doc) {
  9942. doc = doc || document;
  9943. if (doc.scrollingElement) {
  9944. return doc.scrollingElement;
  9945. }
  9946. return !isWebkit && doc.compatMode === 'CSS1Compat' ? doc.documentElement : doc.body;
  9947. }
  9948. var getDocumentScrollElement_1 = getDocumentScrollElement;
  9949. /**
  9950. * Copyright (c) 2013-present, Facebook, Inc.
  9951. *
  9952. * This source code is licensed under the MIT license found in the
  9953. * LICENSE file in the root directory of this source tree.
  9954. *
  9955. * @typechecks
  9956. */
  9957. /**
  9958. * Gets the scroll position of the supplied element or window.
  9959. *
  9960. * The return values are unbounded, unlike `getScrollPosition`. This means they
  9961. * may be negative or exceed the element boundaries (which is possible using
  9962. * inertial scrolling).
  9963. *
  9964. * @param {DOMWindow|DOMElement} scrollable
  9965. * @return {object} Map with `x` and `y` keys.
  9966. */
  9967. function getUnboundedScrollPosition(scrollable) {
  9968. if (scrollable.Window && scrollable instanceof scrollable.Window) {
  9969. return {
  9970. x: scrollable.pageXOffset || scrollable.document.documentElement.scrollLeft,
  9971. y: scrollable.pageYOffset || scrollable.document.documentElement.scrollTop
  9972. };
  9973. }
  9974. return {
  9975. x: scrollable.scrollLeft,
  9976. y: scrollable.scrollTop
  9977. };
  9978. }
  9979. var getUnboundedScrollPosition_1 = getUnboundedScrollPosition;
  9980. /**
  9981. * Gets the scroll position of the supplied element or window.
  9982. *
  9983. * The return values are bounded. This means that if the scroll position is
  9984. * negative or exceeds the element boundaries (which is possible using inertial
  9985. * scrolling), you will get zero or the maximum scroll position, respectively.
  9986. *
  9987. * If you need the unbound scroll position, use `getUnboundedScrollPosition`.
  9988. *
  9989. * @param {DOMWindow|DOMElement} scrollable
  9990. * @return {object} Map with `x` and `y` keys.
  9991. */
  9992. function getScrollPosition(scrollable) {
  9993. var documentScrollElement = getDocumentScrollElement_1(scrollable.ownerDocument || scrollable.document);
  9994. if (scrollable.Window && scrollable instanceof scrollable.Window) {
  9995. scrollable = documentScrollElement;
  9996. }
  9997. var scrollPosition = getUnboundedScrollPosition_1(scrollable);
  9998. var viewport = scrollable === documentScrollElement ? scrollable.ownerDocument.documentElement : scrollable;
  9999. var xMax = scrollable.scrollWidth - viewport.clientWidth;
  10000. var yMax = scrollable.scrollHeight - viewport.clientHeight;
  10001. scrollPosition.x = Math.max(0, Math.min(scrollPosition.x, xMax));
  10002. scrollPosition.y = Math.max(0, Math.min(scrollPosition.y, yMax));
  10003. return scrollPosition;
  10004. }
  10005. var getScrollPosition_1 = getScrollPosition;
  10006. function getViewportWidth() {
  10007. var width = void 0;
  10008. if (document.documentElement) {
  10009. width = document.documentElement.clientWidth;
  10010. }
  10011. if (!width && document.body) {
  10012. width = document.body.clientWidth;
  10013. }
  10014. return width || 0;
  10015. } /**
  10016. * Copyright (c) 2013-present, Facebook, Inc.
  10017. *
  10018. * This source code is licensed under the MIT license found in the
  10019. * LICENSE file in the root directory of this source tree.
  10020. *
  10021. *
  10022. * @typechecks
  10023. */
  10024. function getViewportHeight() {
  10025. var height = void 0;
  10026. if (document.documentElement) {
  10027. height = document.documentElement.clientHeight;
  10028. }
  10029. if (!height && document.body) {
  10030. height = document.body.clientHeight;
  10031. }
  10032. return height || 0;
  10033. }
  10034. /**
  10035. * Gets the viewport dimensions including any scrollbars.
  10036. */
  10037. function getViewportDimensions() {
  10038. return {
  10039. width: window.innerWidth || getViewportWidth(),
  10040. height: window.innerHeight || getViewportHeight()
  10041. };
  10042. }
  10043. /**
  10044. * Gets the viewport dimensions excluding any scrollbars.
  10045. */
  10046. getViewportDimensions.withoutScrollbars = function () {
  10047. return {
  10048. width: getViewportWidth(),
  10049. height: getViewportHeight()
  10050. };
  10051. };
  10052. var getViewportDimensions_1 = getViewportDimensions;
  10053. 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; };
  10054. function _classCallCheck$b(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10055. 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; }
  10056. 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; }
  10057. var SCROLL_BUFFER = 10;
  10058. /**
  10059. * Return whether a block overlaps with either edge of the `SelectionState`.
  10060. */
  10061. var isBlockOnSelectionEdge = function isBlockOnSelectionEdge(selection, key) {
  10062. return selection.getAnchorKey() === key || selection.getFocusKey() === key;
  10063. };
  10064. /**
  10065. * The default block renderer for a `DraftEditor` component.
  10066. *
  10067. * A `DraftEditorBlock` is able to render a given `ContentBlock` to its
  10068. * appropriate decorator and inline style components.
  10069. */
  10070. var DraftEditorBlock = function (_React$Component) {
  10071. _inherits$8(DraftEditorBlock, _React$Component);
  10072. function DraftEditorBlock() {
  10073. _classCallCheck$b(this, DraftEditorBlock);
  10074. return _possibleConstructorReturn$8(this, _React$Component.apply(this, arguments));
  10075. }
  10076. DraftEditorBlock.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  10077. return this.props.block !== nextProps.block || this.props.tree !== nextProps.tree || this.props.direction !== nextProps.direction || isBlockOnSelectionEdge(nextProps.selection, nextProps.block.getKey()) && nextProps.forceSelection;
  10078. };
  10079. /**
  10080. * When a block is mounted and overlaps the selection state, we need to make
  10081. * sure that the cursor is visible to match native behavior. This may not
  10082. * be the case if the user has pressed `RETURN` or pasted some content, since
  10083. * programatically creating these new blocks and setting the DOM selection
  10084. * will miss out on the browser natively scrolling to that position.
  10085. *
  10086. * To replicate native behavior, if the block overlaps the selection state
  10087. * on mount, force the scroll position. Check the scroll state of the scroll
  10088. * parent, and adjust it to align the entire block to the bottom of the
  10089. * scroll parent.
  10090. */
  10091. DraftEditorBlock.prototype.componentDidMount = function componentDidMount() {
  10092. var selection = this.props.selection;
  10093. var endKey = selection.getEndKey();
  10094. if (!selection.getHasFocus() || endKey !== this.props.block.getKey()) {
  10095. return;
  10096. }
  10097. var blockNode = reactDom.findDOMNode(this);
  10098. var scrollParent = Style_1.getScrollParent(blockNode);
  10099. var scrollPosition = getScrollPosition_1(scrollParent);
  10100. var scrollDelta = void 0;
  10101. if (scrollParent === window) {
  10102. var nodePosition = getElementPosition_1(blockNode);
  10103. var nodeBottom = nodePosition.y + nodePosition.height;
  10104. var viewportHeight = getViewportDimensions_1().height;
  10105. scrollDelta = nodeBottom - viewportHeight;
  10106. if (scrollDelta > 0) {
  10107. window.scrollTo(scrollPosition.x, scrollPosition.y + scrollDelta + SCROLL_BUFFER);
  10108. }
  10109. } else {
  10110. !(blockNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'blockNode is not an HTMLElement') : invariant_1(false) : void 0;
  10111. var blockBottom = blockNode.offsetHeight + blockNode.offsetTop;
  10112. var scrollBottom = scrollParent.offsetHeight + scrollPosition.y;
  10113. scrollDelta = blockBottom - scrollBottom;
  10114. if (scrollDelta > 0) {
  10115. Scroll_1.setTop(scrollParent, Scroll_1.getTop(scrollParent) + scrollDelta + SCROLL_BUFFER);
  10116. }
  10117. }
  10118. };
  10119. DraftEditorBlock.prototype._renderChildren = function _renderChildren() {
  10120. var _this2 = this;
  10121. var block = this.props.block;
  10122. var blockKey = block.getKey();
  10123. var text = block.getText();
  10124. var lastLeafSet = this.props.tree.size - 1;
  10125. var hasSelection = isBlockOnSelectionEdge(this.props.selection, blockKey);
  10126. return this.props.tree.map(function (leafSet, ii) {
  10127. var leavesForLeafSet = leafSet.get('leaves');
  10128. var lastLeaf = leavesForLeafSet.size - 1;
  10129. var leaves = leavesForLeafSet.map(function (leaf, jj) {
  10130. var offsetKey = DraftOffsetKey_1.encode(blockKey, ii, jj);
  10131. var start = leaf.get('start');
  10132. var end = leaf.get('end');
  10133. return React.createElement(DraftEditorLeaf_react, {
  10134. key: offsetKey,
  10135. offsetKey: offsetKey,
  10136. block: block,
  10137. start: start,
  10138. selection: hasSelection ? _this2.props.selection : null,
  10139. forceSelection: _this2.props.forceSelection,
  10140. text: text.slice(start, end),
  10141. styleSet: block.getInlineStyleAt(start),
  10142. customStyleMap: _this2.props.customStyleMap,
  10143. customStyleFn: _this2.props.customStyleFn,
  10144. isLast: ii === lastLeafSet && jj === lastLeaf
  10145. });
  10146. }).toArray();
  10147. var decoratorKey = leafSet.get('decoratorKey');
  10148. if (decoratorKey == null) {
  10149. return leaves;
  10150. }
  10151. if (!_this2.props.decorator) {
  10152. return leaves;
  10153. }
  10154. var decorator = nullthrows_1(_this2.props.decorator);
  10155. var DecoratorComponent = decorator.getComponentForKey(decoratorKey);
  10156. if (!DecoratorComponent) {
  10157. return leaves;
  10158. }
  10159. var decoratorProps = decorator.getPropsForKey(decoratorKey);
  10160. var decoratorOffsetKey = DraftOffsetKey_1.encode(blockKey, ii, 0);
  10161. var decoratedText = text.slice(leavesForLeafSet.first().get('start'), leavesForLeafSet.last().get('end'));
  10162. // Resetting dir to the same value on a child node makes Chrome/Firefox
  10163. // confused on cursor movement. See http://jsfiddle.net/d157kLck/3/
  10164. var dir = UnicodeBidiDirection_1.getHTMLDirIfDifferent(UnicodeBidi_1.getDirection(decoratedText), _this2.props.direction);
  10165. return React.createElement(
  10166. DecoratorComponent,
  10167. _extends$2({}, decoratorProps, {
  10168. contentState: _this2.props.contentState,
  10169. decoratedText: decoratedText,
  10170. dir: dir,
  10171. key: decoratorOffsetKey,
  10172. entityKey: block.getEntityAt(leafSet.get('start')),
  10173. offsetKey: decoratorOffsetKey }),
  10174. leaves
  10175. );
  10176. }).toArray();
  10177. };
  10178. DraftEditorBlock.prototype.render = function render() {
  10179. var _props = this.props,
  10180. direction = _props.direction,
  10181. offsetKey = _props.offsetKey;
  10182. var className = cx_1({
  10183. 'public/DraftStyleDefault/block': true,
  10184. 'public/DraftStyleDefault/ltr': direction === 'LTR',
  10185. 'public/DraftStyleDefault/rtl': direction === 'RTL'
  10186. });
  10187. return React.createElement(
  10188. 'div',
  10189. { 'data-offset-key': offsetKey, className: className },
  10190. this._renderChildren()
  10191. );
  10192. };
  10193. return DraftEditorBlock;
  10194. }(React.Component);
  10195. var DraftEditorBlock_react = DraftEditorBlock;
  10196. /**
  10197. * Copyright (c) 2013-present, Facebook, Inc.
  10198. *
  10199. * This source code is licensed under the MIT license found in the
  10200. * LICENSE file in the root directory of this source tree.
  10201. *
  10202. * @typechecks static-only
  10203. */
  10204. /**
  10205. * Combines multiple className strings into one.
  10206. * http://jsperf.com/joinclasses-args-vs-array
  10207. *
  10208. * @param {...?string} className
  10209. * @return {string}
  10210. */
  10211. function joinClasses(className /*, ... */) {
  10212. if (!className) {
  10213. className = '';
  10214. }
  10215. var nextClass = void 0;
  10216. var argLength = arguments.length;
  10217. if (argLength > 1) {
  10218. for (var ii = 1; ii < argLength; ii++) {
  10219. nextClass = arguments[ii];
  10220. if (nextClass) {
  10221. className = (className ? className + ' ' : '') + nextClass;
  10222. }
  10223. }
  10224. }
  10225. return className;
  10226. }
  10227. var joinClasses_1 = joinClasses;
  10228. 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; };
  10229. function _classCallCheck$c(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10230. 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; }
  10231. 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; }
  10232. /**
  10233. * Provide default styling for list items. This way, lists will be styled with
  10234. * proper counters and indentation even if the caller does not specify
  10235. * their own styling at all. If more than five levels of nesting are needed,
  10236. * the necessary CSS classes can be provided via `blockStyleFn` configuration.
  10237. */
  10238. var getListItemClasses = function getListItemClasses(type, depth, shouldResetCount, direction) {
  10239. return cx_1({
  10240. 'public/DraftStyleDefault/unorderedListItem': type === 'unordered-list-item',
  10241. 'public/DraftStyleDefault/orderedListItem': type === 'ordered-list-item',
  10242. 'public/DraftStyleDefault/reset': shouldResetCount,
  10243. 'public/DraftStyleDefault/depth0': depth === 0,
  10244. 'public/DraftStyleDefault/depth1': depth === 1,
  10245. 'public/DraftStyleDefault/depth2': depth === 2,
  10246. 'public/DraftStyleDefault/depth3': depth === 3,
  10247. 'public/DraftStyleDefault/depth4': depth === 4,
  10248. 'public/DraftStyleDefault/listLTR': direction === 'LTR',
  10249. 'public/DraftStyleDefault/listRTL': direction === 'RTL'
  10250. });
  10251. };
  10252. /**
  10253. * `DraftEditorContents` is the container component for all block components
  10254. * rendered for a `DraftEditor`. It is optimized to aggressively avoid
  10255. * re-rendering blocks whenever possible.
  10256. *
  10257. * This component is separate from `DraftEditor` because certain props
  10258. * (for instance, ARIA props) must be allowed to update without affecting
  10259. * the contents of the editor.
  10260. */
  10261. var DraftEditorContents = function (_React$Component) {
  10262. _inherits$9(DraftEditorContents, _React$Component);
  10263. function DraftEditorContents() {
  10264. _classCallCheck$c(this, DraftEditorContents);
  10265. return _possibleConstructorReturn$9(this, _React$Component.apply(this, arguments));
  10266. }
  10267. DraftEditorContents.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  10268. var prevEditorState = this.props.editorState;
  10269. var nextEditorState = nextProps.editorState;
  10270. var prevDirectionMap = prevEditorState.getDirectionMap();
  10271. var nextDirectionMap = nextEditorState.getDirectionMap();
  10272. // Text direction has changed for one or more blocks. We must re-render.
  10273. if (prevDirectionMap !== nextDirectionMap) {
  10274. return true;
  10275. }
  10276. var didHaveFocus = prevEditorState.getSelection().getHasFocus();
  10277. var nowHasFocus = nextEditorState.getSelection().getHasFocus();
  10278. if (didHaveFocus !== nowHasFocus) {
  10279. return true;
  10280. }
  10281. var nextNativeContent = nextEditorState.getNativelyRenderedContent();
  10282. var wasComposing = prevEditorState.isInCompositionMode();
  10283. var nowComposing = nextEditorState.isInCompositionMode();
  10284. // If the state is unchanged or we're currently rendering a natively
  10285. // rendered state, there's nothing new to be done.
  10286. if (prevEditorState === nextEditorState || nextNativeContent !== null && nextEditorState.getCurrentContent() === nextNativeContent || wasComposing && nowComposing) {
  10287. return false;
  10288. }
  10289. var prevContent = prevEditorState.getCurrentContent();
  10290. var nextContent = nextEditorState.getCurrentContent();
  10291. var prevDecorator = prevEditorState.getDecorator();
  10292. var nextDecorator = nextEditorState.getDecorator();
  10293. return wasComposing !== nowComposing || prevContent !== nextContent || prevDecorator !== nextDecorator || nextEditorState.mustForceSelection();
  10294. };
  10295. DraftEditorContents.prototype.render = function render() {
  10296. var _props = this.props,
  10297. blockRenderMap = _props.blockRenderMap,
  10298. blockRendererFn = _props.blockRendererFn,
  10299. blockStyleFn = _props.blockStyleFn,
  10300. customStyleMap = _props.customStyleMap,
  10301. customStyleFn = _props.customStyleFn,
  10302. editorState = _props.editorState,
  10303. editorKey = _props.editorKey,
  10304. textDirectionality = _props.textDirectionality;
  10305. var content = editorState.getCurrentContent();
  10306. var selection = editorState.getSelection();
  10307. var forceSelection = editorState.mustForceSelection();
  10308. var decorator = editorState.getDecorator();
  10309. var directionMap = nullthrows_1(editorState.getDirectionMap());
  10310. var blocksAsArray = content.getBlocksAsArray();
  10311. var processedBlocks = [];
  10312. var currentDepth = null;
  10313. var lastWrapperTemplate = null;
  10314. for (var ii = 0; ii < blocksAsArray.length; ii++) {
  10315. var _block = blocksAsArray[ii];
  10316. var key = _block.getKey();
  10317. var blockType = _block.getType();
  10318. var customRenderer = blockRendererFn(_block);
  10319. var CustomComponent = void 0,
  10320. customProps = void 0,
  10321. customEditable = void 0;
  10322. if (customRenderer) {
  10323. CustomComponent = customRenderer.component;
  10324. customProps = customRenderer.props;
  10325. customEditable = customRenderer.editable;
  10326. }
  10327. var direction = textDirectionality ? textDirectionality : directionMap.get(key);
  10328. var offsetKey = DraftOffsetKey_1.encode(key, 0, 0);
  10329. var componentProps = {
  10330. contentState: content,
  10331. block: _block,
  10332. blockProps: customProps,
  10333. blockStyleFn: blockStyleFn,
  10334. customStyleMap: customStyleMap,
  10335. customStyleFn: customStyleFn,
  10336. decorator: decorator,
  10337. direction: direction,
  10338. forceSelection: forceSelection,
  10339. key: key,
  10340. offsetKey: offsetKey,
  10341. selection: selection,
  10342. tree: editorState.getBlockTree(key)
  10343. };
  10344. var configForType = blockRenderMap.get(blockType) || blockRenderMap.get('unstyled');
  10345. var wrapperTemplate = configForType.wrapper;
  10346. var Element = configForType.element || blockRenderMap.get('unstyled').element;
  10347. var depth = _block.getDepth();
  10348. var className = '';
  10349. if (blockStyleFn) {
  10350. className = blockStyleFn(_block);
  10351. }
  10352. // List items are special snowflakes, since we handle nesting and
  10353. // counters manually.
  10354. if (Element === 'li') {
  10355. var shouldResetCount = lastWrapperTemplate !== wrapperTemplate || currentDepth === null || depth > currentDepth;
  10356. className = joinClasses_1(className, getListItemClasses(blockType, depth, shouldResetCount, direction));
  10357. }
  10358. var Component = CustomComponent || DraftEditorBlock_react;
  10359. var childProps = {
  10360. className: className,
  10361. 'data-block': true,
  10362. 'data-editor': editorKey,
  10363. 'data-offset-key': offsetKey,
  10364. key: key
  10365. };
  10366. if (customEditable !== undefined) {
  10367. childProps = _extends$3({}, childProps, {
  10368. contentEditable: customEditable,
  10369. suppressContentEditableWarning: true
  10370. });
  10371. }
  10372. var child = React.createElement(Element, childProps, React.createElement(Component, componentProps));
  10373. processedBlocks.push({
  10374. block: child,
  10375. wrapperTemplate: wrapperTemplate,
  10376. key: key,
  10377. offsetKey: offsetKey
  10378. });
  10379. if (wrapperTemplate) {
  10380. currentDepth = _block.getDepth();
  10381. } else {
  10382. currentDepth = null;
  10383. }
  10384. lastWrapperTemplate = wrapperTemplate;
  10385. }
  10386. // Group contiguous runs of blocks that have the same wrapperTemplate
  10387. var outputBlocks = [];
  10388. for (var _ii = 0; _ii < processedBlocks.length;) {
  10389. var info = processedBlocks[_ii];
  10390. if (info.wrapperTemplate) {
  10391. var blocks = [];
  10392. do {
  10393. blocks.push(processedBlocks[_ii].block);
  10394. _ii++;
  10395. } while (_ii < processedBlocks.length && processedBlocks[_ii].wrapperTemplate === info.wrapperTemplate);
  10396. var wrapperElement = React.cloneElement(info.wrapperTemplate, {
  10397. key: info.key + '-wrap',
  10398. 'data-offset-key': info.offsetKey
  10399. }, blocks);
  10400. outputBlocks.push(wrapperElement);
  10401. } else {
  10402. outputBlocks.push(info.block);
  10403. _ii++;
  10404. }
  10405. }
  10406. return React.createElement(
  10407. 'div',
  10408. { 'data-contents': 'true' },
  10409. outputBlocks
  10410. );
  10411. };
  10412. return DraftEditorContents;
  10413. }(React.Component);
  10414. var DraftEditorContentsCore_react = DraftEditorContents;
  10415. var DraftEditorContents_react = DraftEditorContentsCore_react;
  10416. /**
  10417. * Copyright (c) 2013-present, Facebook, Inc.
  10418. *
  10419. * This source code is licensed under the MIT license found in the
  10420. * LICENSE file in the root directory of this source tree.
  10421. *
  10422. */
  10423. var PhotosMimeType = {
  10424. isImage: function isImage(mimeString) {
  10425. return getParts(mimeString)[0] === 'image';
  10426. },
  10427. isJpeg: function isJpeg(mimeString) {
  10428. var parts = getParts(mimeString);
  10429. return PhotosMimeType.isImage(mimeString) && (
  10430. // see http://fburl.com/10972194
  10431. parts[1] === 'jpeg' || parts[1] === 'pjpeg');
  10432. }
  10433. };
  10434. function getParts(mimeString) {
  10435. return mimeString.split('/');
  10436. }
  10437. var PhotosMimeType_1 = PhotosMimeType;
  10438. /**
  10439. * Copyright (c) 2013-present, Facebook, Inc.
  10440. *
  10441. * This source code is licensed under the MIT license found in the
  10442. * LICENSE file in the root directory of this source tree.
  10443. *
  10444. * @typechecks
  10445. */
  10446. /**
  10447. * Convert array-like objects to arrays.
  10448. *
  10449. * This API assumes the caller knows the contents of the data type. For less
  10450. * well defined inputs use createArrayFromMixed.
  10451. *
  10452. * @param {object|function|filelist} obj
  10453. * @return {array}
  10454. */
  10455. function toArray(obj) {
  10456. var length = obj.length;
  10457. // Some browsers builtin objects can report typeof 'function' (e.g. NodeList
  10458. // in old versions of Safari).
  10459. !(!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;
  10460. !(typeof length === 'number') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'toArray: Object needs a length property') : invariant_1(false) : void 0;
  10461. !(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;
  10462. !(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;
  10463. // Old IE doesn't give collections access to hasOwnProperty. Assume inputs
  10464. // without method will throw during the slice call and skip straight to the
  10465. // fallback.
  10466. if (obj.hasOwnProperty) {
  10467. try {
  10468. return Array.prototype.slice.call(obj);
  10469. } catch (e) {
  10470. // IE < 9 does not support Array#slice on collections objects
  10471. }
  10472. }
  10473. // Fall back to copying key by key. This assumes all keys have a value,
  10474. // so will not preserve sparsely populated inputs.
  10475. var ret = Array(length);
  10476. for (var ii = 0; ii < length; ii++) {
  10477. ret[ii] = obj[ii];
  10478. }
  10479. return ret;
  10480. }
  10481. /**
  10482. * Perform a heuristic test to determine if an object is "array-like".
  10483. *
  10484. * A monk asked Joshu, a Zen master, "Has a dog Buddha nature?"
  10485. * Joshu replied: "Mu."
  10486. *
  10487. * This function determines if its argument has "array nature": it returns
  10488. * true if the argument is an actual array, an `arguments' object, or an
  10489. * HTMLCollection (e.g. node.childNodes or node.getElementsByTagName()).
  10490. *
  10491. * It will return false for other array-like objects like Filelist.
  10492. *
  10493. * @param {*} obj
  10494. * @return {boolean}
  10495. */
  10496. function hasArrayNature(obj) {
  10497. return (
  10498. // not null/false
  10499. !!obj && (
  10500. // arrays are objects, NodeLists are functions in Safari
  10501. typeof obj == 'object' || typeof obj == 'function') &&
  10502. // quacks like an array
  10503. 'length' in obj &&
  10504. // not window
  10505. !('setInterval' in obj) &&
  10506. // no DOM node should be considered an array-like
  10507. // a 'select' element has 'length' and 'item' properties on IE8
  10508. typeof obj.nodeType != 'number' && (
  10509. // a real array
  10510. Array.isArray(obj) ||
  10511. // arguments
  10512. 'callee' in obj ||
  10513. // HTMLCollection/NodeList
  10514. 'item' in obj)
  10515. );
  10516. }
  10517. /**
  10518. * Ensure that the argument is an array by wrapping it in an array if it is not.
  10519. * Creates a copy of the argument if it is already an array.
  10520. *
  10521. * This is mostly useful idiomatically:
  10522. *
  10523. * var createArrayFromMixed = require('createArrayFromMixed');
  10524. *
  10525. * function takesOneOrMoreThings(things) {
  10526. * things = createArrayFromMixed(things);
  10527. * ...
  10528. * }
  10529. *
  10530. * This allows you to treat `things' as an array, but accept scalars in the API.
  10531. *
  10532. * If you need to convert an array-like object, like `arguments`, into an array
  10533. * use toArray instead.
  10534. *
  10535. * @param {*} obj
  10536. * @return {array}
  10537. */
  10538. function createArrayFromMixed(obj) {
  10539. if (!hasArrayNature(obj)) {
  10540. return [obj];
  10541. } else if (Array.isArray(obj)) {
  10542. return obj.slice();
  10543. } else {
  10544. return toArray(obj);
  10545. }
  10546. }
  10547. var createArrayFromMixed_1 = createArrayFromMixed;
  10548. function _classCallCheck$d(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10549. /**
  10550. * Copyright (c) 2013-present, Facebook, Inc.
  10551. *
  10552. * This source code is licensed under the MIT license found in the
  10553. * LICENSE file in the root directory of this source tree.
  10554. *
  10555. * @typechecks
  10556. */
  10557. var CR_LF_REGEX = new RegExp('\r\n', 'g');
  10558. var LF_ONLY = '\n';
  10559. var RICH_TEXT_TYPES = {
  10560. 'text/rtf': 1,
  10561. 'text/html': 1
  10562. };
  10563. /**
  10564. * If DataTransferItem is a file then return the Blob of data.
  10565. *
  10566. * @param {object} item
  10567. * @return {?blob}
  10568. */
  10569. function getFileFromDataTransfer(item) {
  10570. if (item.kind == 'file') {
  10571. return item.getAsFile();
  10572. }
  10573. }
  10574. var DataTransfer$1 = function () {
  10575. /**
  10576. * @param {object} data
  10577. */
  10578. function DataTransfer(data) {
  10579. _classCallCheck$d(this, DataTransfer);
  10580. this.data = data;
  10581. // Types could be DOMStringList or array
  10582. this.types = data.types ? createArrayFromMixed_1(data.types) : [];
  10583. }
  10584. /**
  10585. * Is this likely to be a rich text data transfer?
  10586. *
  10587. * @return {boolean}
  10588. */
  10589. DataTransfer.prototype.isRichText = function isRichText() {
  10590. // If HTML is available, treat this data as rich text. This way, we avoid
  10591. // using a pasted image if it is packaged with HTML -- this may occur with
  10592. // pastes from MS Word, for example. However this is only rich text if
  10593. // there's accompanying text.
  10594. if (this.getHTML() && this.getText()) {
  10595. return true;
  10596. }
  10597. // When an image is copied from a preview window, you end up with two
  10598. // DataTransferItems one of which is a file's metadata as text. Skip those.
  10599. if (this.isImage()) {
  10600. return false;
  10601. }
  10602. return this.types.some(function (type) {
  10603. return RICH_TEXT_TYPES[type];
  10604. });
  10605. };
  10606. /**
  10607. * Get raw text.
  10608. *
  10609. * @return {?string}
  10610. */
  10611. DataTransfer.prototype.getText = function getText() {
  10612. var text;
  10613. if (this.data.getData) {
  10614. if (!this.types.length) {
  10615. text = this.data.getData('Text');
  10616. } else if (this.types.indexOf('text/plain') != -1) {
  10617. text = this.data.getData('text/plain');
  10618. }
  10619. }
  10620. return text ? text.replace(CR_LF_REGEX, LF_ONLY) : null;
  10621. };
  10622. /**
  10623. * Get HTML paste data
  10624. *
  10625. * @return {?string}
  10626. */
  10627. DataTransfer.prototype.getHTML = function getHTML() {
  10628. if (this.data.getData) {
  10629. if (!this.types.length) {
  10630. return this.data.getData('Text');
  10631. } else if (this.types.indexOf('text/html') != -1) {
  10632. return this.data.getData('text/html');
  10633. }
  10634. }
  10635. };
  10636. /**
  10637. * Is this a link data transfer?
  10638. *
  10639. * @return {boolean}
  10640. */
  10641. DataTransfer.prototype.isLink = function isLink() {
  10642. return this.types.some(function (type) {
  10643. return type.indexOf('Url') != -1 || type.indexOf('text/uri-list') != -1 || type.indexOf('text/x-moz-url');
  10644. });
  10645. };
  10646. /**
  10647. * Get a link url.
  10648. *
  10649. * @return {?string}
  10650. */
  10651. DataTransfer.prototype.getLink = function getLink() {
  10652. if (this.data.getData) {
  10653. if (this.types.indexOf('text/x-moz-url') != -1) {
  10654. var url = this.data.getData('text/x-moz-url').split('\n');
  10655. return url[0];
  10656. }
  10657. return this.types.indexOf('text/uri-list') != -1 ? this.data.getData('text/uri-list') : this.data.getData('url');
  10658. }
  10659. return null;
  10660. };
  10661. /**
  10662. * Is this an image data transfer?
  10663. *
  10664. * @return {boolean}
  10665. */
  10666. DataTransfer.prototype.isImage = function isImage() {
  10667. var isImage = this.types.some(function (type) {
  10668. // Firefox will have a type of application/x-moz-file for images during
  10669. // dragging
  10670. return type.indexOf('application/x-moz-file') != -1;
  10671. });
  10672. if (isImage) {
  10673. return true;
  10674. }
  10675. var items = this.getFiles();
  10676. for (var i = 0; i < items.length; i++) {
  10677. var type = items[i].type;
  10678. if (!PhotosMimeType_1.isImage(type)) {
  10679. return false;
  10680. }
  10681. }
  10682. return true;
  10683. };
  10684. DataTransfer.prototype.getCount = function getCount() {
  10685. if (this.data.hasOwnProperty('items')) {
  10686. return this.data.items.length;
  10687. } else if (this.data.hasOwnProperty('mozItemCount')) {
  10688. return this.data.mozItemCount;
  10689. } else if (this.data.files) {
  10690. return this.data.files.length;
  10691. }
  10692. return null;
  10693. };
  10694. /**
  10695. * Get files.
  10696. *
  10697. * @return {array}
  10698. */
  10699. DataTransfer.prototype.getFiles = function getFiles() {
  10700. if (this.data.items) {
  10701. // createArrayFromMixed doesn't properly handle DataTransferItemLists.
  10702. return Array.prototype.slice.call(this.data.items).map(getFileFromDataTransfer).filter(emptyFunction_1.thatReturnsArgument);
  10703. } else if (this.data.files) {
  10704. return Array.prototype.slice.call(this.data.files);
  10705. } else {
  10706. return [];
  10707. }
  10708. };
  10709. /**
  10710. * Are there any files to fetch?
  10711. *
  10712. * @return {boolean}
  10713. */
  10714. DataTransfer.prototype.hasFiles = function hasFiles() {
  10715. return this.getFiles().length > 0;
  10716. };
  10717. return DataTransfer;
  10718. }();
  10719. var DataTransfer_1 = DataTransfer$1;
  10720. /**
  10721. * Copyright (c) 2013-present, Facebook, Inc.
  10722. * All rights reserved.
  10723. *
  10724. * This source code is licensed under the BSD-style license found in the
  10725. * LICENSE file in the root directory of this source tree. An additional grant
  10726. * of patent rights can be found in the PATENTS file in the same directory.
  10727. *
  10728. * @providesModule getSelectionOffsetKeyForNode
  10729. * @format
  10730. *
  10731. */
  10732. /**
  10733. * Get offset key from a node or it's child nodes. Return the first offset key
  10734. * found on the DOM tree of given node.
  10735. */
  10736. function getSelectionOffsetKeyForNode(node) {
  10737. if (node instanceof Element) {
  10738. var offsetKey = node.getAttribute('data-offset-key');
  10739. if (offsetKey) {
  10740. return offsetKey;
  10741. }
  10742. for (var ii = 0; ii < node.childNodes.length; ii++) {
  10743. var childOffsetKey = getSelectionOffsetKeyForNode(node.childNodes[ii]);
  10744. if (childOffsetKey) {
  10745. return childOffsetKey;
  10746. }
  10747. }
  10748. }
  10749. return null;
  10750. }
  10751. var getSelectionOffsetKeyForNode_1 = getSelectionOffsetKeyForNode;
  10752. /**
  10753. * Get the key from the node's nearest offset-aware ancestor.
  10754. */
  10755. function findAncestorOffsetKey(node) {
  10756. var searchNode = node;
  10757. while (searchNode && searchNode !== document.documentElement) {
  10758. var key = getSelectionOffsetKeyForNode_1(searchNode);
  10759. if (key != null) {
  10760. return key;
  10761. }
  10762. searchNode = searchNode.parentNode;
  10763. }
  10764. return null;
  10765. }
  10766. var findAncestorOffsetKey_1 = findAncestorOffsetKey;
  10767. var TEXT_CLIPPING_REGEX = /\.textClipping$/;
  10768. var TEXT_TYPES = {
  10769. 'text/plain': true,
  10770. 'text/html': true,
  10771. 'text/rtf': true
  10772. };
  10773. // Somewhat arbitrary upper bound on text size. Let's not lock up the browser.
  10774. var TEXT_SIZE_UPPER_BOUND = 5000;
  10775. /**
  10776. * Extract the text content from a file list.
  10777. */
  10778. function getTextContentFromFiles(files, callback) {
  10779. var readCount = 0;
  10780. var results = [];
  10781. files.forEach(function ( /*blob*/file) {
  10782. readFile(file, function ( /*string*/text) {
  10783. readCount++;
  10784. text && results.push(text.slice(0, TEXT_SIZE_UPPER_BOUND));
  10785. if (readCount == files.length) {
  10786. callback(results.join('\r'));
  10787. }
  10788. });
  10789. });
  10790. }
  10791. /**
  10792. * todo isaac: Do work to turn html/rtf into a content fragment.
  10793. */
  10794. function readFile(file, callback) {
  10795. if (!commonjsGlobal.FileReader || file.type && !(file.type in TEXT_TYPES)) {
  10796. callback('');
  10797. return;
  10798. }
  10799. if (file.type === '') {
  10800. var contents = '';
  10801. // Special-case text clippings, which have an empty type but include
  10802. // `.textClipping` in the file name. `readAsText` results in an empty
  10803. // string for text clippings, so we force the file name to serve
  10804. // as the text value for the file.
  10805. if (TEXT_CLIPPING_REGEX.test(file.name)) {
  10806. contents = file.name.replace(TEXT_CLIPPING_REGEX, '');
  10807. }
  10808. callback(contents);
  10809. return;
  10810. }
  10811. var reader = new FileReader();
  10812. reader.onload = function () {
  10813. var result = reader.result;
  10814. !(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;
  10815. callback(result);
  10816. };
  10817. reader.onerror = function () {
  10818. callback('');
  10819. };
  10820. reader.readAsText(file);
  10821. }
  10822. var getTextContentFromFiles_1 = getTextContentFromFiles;
  10823. function getUpdatedSelectionState(editorState, anchorKey, anchorOffset, focusKey, focusOffset) {
  10824. var selection = nullthrows_1(editorState.getSelection());
  10825. if (process.env.NODE_ENV !== 'production') {
  10826. if (!anchorKey || !focusKey) {
  10827. /*eslint-disable no-console */
  10828. console.warn('Invalid selection state.', arguments, editorState.toJS());
  10829. /*eslint-enable no-console */
  10830. return selection;
  10831. }
  10832. }
  10833. var anchorPath = DraftOffsetKey_1.decode(anchorKey);
  10834. var anchorBlockKey = anchorPath.blockKey;
  10835. var anchorLeaf = editorState.getBlockTree(anchorBlockKey).getIn([anchorPath.decoratorKey, 'leaves', anchorPath.leafKey]);
  10836. var focusPath = DraftOffsetKey_1.decode(focusKey);
  10837. var focusBlockKey = focusPath.blockKey;
  10838. var focusLeaf = editorState.getBlockTree(focusBlockKey).getIn([focusPath.decoratorKey, 'leaves', focusPath.leafKey]);
  10839. var anchorLeafStart = anchorLeaf.get('start');
  10840. var focusLeafStart = focusLeaf.get('start');
  10841. var anchorBlockOffset = anchorLeaf ? anchorLeafStart + anchorOffset : null;
  10842. var focusBlockOffset = focusLeaf ? focusLeafStart + focusOffset : null;
  10843. var areEqual = selection.getAnchorKey() === anchorBlockKey && selection.getAnchorOffset() === anchorBlockOffset && selection.getFocusKey() === focusBlockKey && selection.getFocusOffset() === focusBlockOffset;
  10844. if (areEqual) {
  10845. return selection;
  10846. }
  10847. var isBackward = false;
  10848. if (anchorBlockKey === focusBlockKey) {
  10849. var anchorLeafEnd = anchorLeaf.get('end');
  10850. var focusLeafEnd = focusLeaf.get('end');
  10851. if (focusLeafStart === anchorLeafStart && focusLeafEnd === anchorLeafEnd) {
  10852. isBackward = focusOffset < anchorOffset;
  10853. } else {
  10854. isBackward = focusLeafStart < anchorLeafStart;
  10855. }
  10856. } else {
  10857. var startKey = editorState.getCurrentContent().getBlockMap().keySeq().skipUntil(function (v) {
  10858. return v === anchorBlockKey || v === focusBlockKey;
  10859. }).first();
  10860. isBackward = startKey === focusBlockKey;
  10861. }
  10862. return selection.merge({
  10863. anchorKey: anchorBlockKey,
  10864. anchorOffset: anchorBlockOffset,
  10865. focusKey: focusBlockKey,
  10866. focusOffset: focusBlockOffset,
  10867. isBackward: isBackward
  10868. });
  10869. }
  10870. var getUpdatedSelectionState_1 = getUpdatedSelectionState;
  10871. /**
  10872. * Get a SelectionState for the supplied mouse event.
  10873. */
  10874. function getSelectionForEvent(event, editorState) {
  10875. var node = null;
  10876. var offset = null;
  10877. if (typeof document.caretRangeFromPoint === 'function') {
  10878. var dropRange = document.caretRangeFromPoint(event.x, event.y);
  10879. node = dropRange.startContainer;
  10880. offset = dropRange.startOffset;
  10881. } else if (event.rangeParent) {
  10882. node = event.rangeParent;
  10883. offset = event.rangeOffset;
  10884. } else {
  10885. return null;
  10886. }
  10887. node = nullthrows_1(node);
  10888. offset = nullthrows_1(offset);
  10889. var offsetKey = nullthrows_1(findAncestorOffsetKey_1(node));
  10890. return getUpdatedSelectionState_1(editorState, offsetKey, offset, offsetKey, offset);
  10891. }
  10892. var DraftEditorDragHandler = {
  10893. /**
  10894. * Drag originating from input terminated.
  10895. */
  10896. onDragEnd: function onDragEnd(editor) {
  10897. editor.exitCurrentMode();
  10898. },
  10899. /**
  10900. * Handle data being dropped.
  10901. */
  10902. onDrop: function onDrop(editor, e) {
  10903. var data = new DataTransfer_1(e.nativeEvent.dataTransfer);
  10904. var editorState = editor._latestEditorState;
  10905. var dropSelection = getSelectionForEvent(e.nativeEvent, editorState);
  10906. e.preventDefault();
  10907. editor.exitCurrentMode();
  10908. if (dropSelection == null) {
  10909. return;
  10910. }
  10911. var files = data.getFiles();
  10912. if (files.length > 0) {
  10913. if (editor.props.handleDroppedFiles && isEventHandled_1(editor.props.handleDroppedFiles(dropSelection, files))) {
  10914. return;
  10915. }
  10916. getTextContentFromFiles_1(files, function (fileText) {
  10917. fileText && editor.update(insertTextAtSelection(editorState, dropSelection, fileText));
  10918. });
  10919. return;
  10920. }
  10921. var dragType = editor._internalDrag ? 'internal' : 'external';
  10922. if (editor.props.handleDrop && isEventHandled_1(editor.props.handleDrop(dropSelection, data, dragType))) {
  10923. return;
  10924. }
  10925. if (editor._internalDrag) {
  10926. editor.update(moveText(editorState, dropSelection));
  10927. return;
  10928. }
  10929. editor.update(insertTextAtSelection(editorState, dropSelection, data.getText()));
  10930. }
  10931. };
  10932. function moveText(editorState, targetSelection) {
  10933. var newContentState = DraftModifier_1.moveText(editorState.getCurrentContent(), editorState.getSelection(), targetSelection);
  10934. return EditorState_1.push(editorState, newContentState, 'insert-fragment');
  10935. }
  10936. /**
  10937. * Insert text at a specified selection.
  10938. */
  10939. function insertTextAtSelection(editorState, selection, text) {
  10940. var newContentState = DraftModifier_1.insertText(editorState.getCurrentContent(), selection, text, editorState.getCurrentInlineStyle());
  10941. return EditorState_1.push(editorState, newContentState, 'insert-fragment');
  10942. }
  10943. var DraftEditorDragHandler_1 = DraftEditorDragHandler;
  10944. (function (global, undefined$1) {
  10945. if (global.setImmediate) {
  10946. return;
  10947. }
  10948. var nextHandle = 1; // Spec says greater than zero
  10949. var tasksByHandle = {};
  10950. var currentlyRunningATask = false;
  10951. var doc = global.document;
  10952. var registerImmediate;
  10953. function setImmediate(callback) {
  10954. // Callback can either be a function or a string
  10955. if (typeof callback !== "function") {
  10956. callback = new Function("" + callback);
  10957. }
  10958. // Copy function arguments
  10959. var args = new Array(arguments.length - 1);
  10960. for (var i = 0; i < args.length; i++) {
  10961. args[i] = arguments[i + 1];
  10962. }
  10963. // Store and register the task
  10964. var task = { callback: callback, args: args };
  10965. tasksByHandle[nextHandle] = task;
  10966. registerImmediate(nextHandle);
  10967. return nextHandle++;
  10968. }
  10969. function clearImmediate(handle) {
  10970. delete tasksByHandle[handle];
  10971. }
  10972. function run(task) {
  10973. var callback = task.callback;
  10974. var args = task.args;
  10975. switch (args.length) {
  10976. case 0:
  10977. callback();
  10978. break;
  10979. case 1:
  10980. callback(args[0]);
  10981. break;
  10982. case 2:
  10983. callback(args[0], args[1]);
  10984. break;
  10985. case 3:
  10986. callback(args[0], args[1], args[2]);
  10987. break;
  10988. default:
  10989. callback.apply(undefined$1, args);
  10990. break;
  10991. }
  10992. }
  10993. function runIfPresent(handle) {
  10994. // From the spec: "Wait until any invocations of this algorithm started before this one have completed."
  10995. // So if we're currently running a task, we'll need to delay this invocation.
  10996. if (currentlyRunningATask) {
  10997. // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a
  10998. // "too much recursion" error.
  10999. setTimeout(runIfPresent, 0, handle);
  11000. } else {
  11001. var task = tasksByHandle[handle];
  11002. if (task) {
  11003. currentlyRunningATask = true;
  11004. try {
  11005. run(task);
  11006. } finally {
  11007. clearImmediate(handle);
  11008. currentlyRunningATask = false;
  11009. }
  11010. }
  11011. }
  11012. }
  11013. function installNextTickImplementation() {
  11014. registerImmediate = function(handle) {
  11015. process.nextTick(function () { runIfPresent(handle); });
  11016. };
  11017. }
  11018. function canUsePostMessage() {
  11019. // The test against `importScripts` prevents this implementation from being installed inside a web worker,
  11020. // where `global.postMessage` means something completely different and can't be used for this purpose.
  11021. if (global.postMessage && !global.importScripts) {
  11022. var postMessageIsAsynchronous = true;
  11023. var oldOnMessage = global.onmessage;
  11024. global.onmessage = function() {
  11025. postMessageIsAsynchronous = false;
  11026. };
  11027. global.postMessage("", "*");
  11028. global.onmessage = oldOnMessage;
  11029. return postMessageIsAsynchronous;
  11030. }
  11031. }
  11032. function installPostMessageImplementation() {
  11033. // Installs an event handler on `global` for the `message` event: see
  11034. // * https://developer.mozilla.org/en/DOM/window.postMessage
  11035. // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
  11036. var messagePrefix = "setImmediate$" + Math.random() + "$";
  11037. var onGlobalMessage = function(event) {
  11038. if (event.source === global &&
  11039. typeof event.data === "string" &&
  11040. event.data.indexOf(messagePrefix) === 0) {
  11041. runIfPresent(+event.data.slice(messagePrefix.length));
  11042. }
  11043. };
  11044. if (global.addEventListener) {
  11045. global.addEventListener("message", onGlobalMessage, false);
  11046. } else {
  11047. global.attachEvent("onmessage", onGlobalMessage);
  11048. }
  11049. registerImmediate = function(handle) {
  11050. global.postMessage(messagePrefix + handle, "*");
  11051. };
  11052. }
  11053. function installMessageChannelImplementation() {
  11054. var channel = new MessageChannel();
  11055. channel.port1.onmessage = function(event) {
  11056. var handle = event.data;
  11057. runIfPresent(handle);
  11058. };
  11059. registerImmediate = function(handle) {
  11060. channel.port2.postMessage(handle);
  11061. };
  11062. }
  11063. function installReadyStateChangeImplementation() {
  11064. var html = doc.documentElement;
  11065. registerImmediate = function(handle) {
  11066. // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
  11067. // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
  11068. var script = doc.createElement("script");
  11069. script.onreadystatechange = function () {
  11070. runIfPresent(handle);
  11071. script.onreadystatechange = null;
  11072. html.removeChild(script);
  11073. script = null;
  11074. };
  11075. html.appendChild(script);
  11076. };
  11077. }
  11078. function installSetTimeoutImplementation() {
  11079. registerImmediate = function(handle) {
  11080. setTimeout(runIfPresent, 0, handle);
  11081. };
  11082. }
  11083. // If supported, we should attach to the prototype of global, since that is where setTimeout et al. live.
  11084. var attachTo = Object.getPrototypeOf && Object.getPrototypeOf(global);
  11085. attachTo = attachTo && attachTo.setTimeout ? attachTo : global;
  11086. // Don't get fooled by e.g. browserify environments.
  11087. if ({}.toString.call(global.process) === "[object process]") {
  11088. // For Node.js before 0.9
  11089. installNextTickImplementation();
  11090. } else if (canUsePostMessage()) {
  11091. // For non-IE10 modern browsers
  11092. installPostMessageImplementation();
  11093. } else if (global.MessageChannel) {
  11094. // For web workers, where supported
  11095. installMessageChannelImplementation();
  11096. } else if (doc && "onreadystatechange" in doc.createElement("script")) {
  11097. // For IE 6–8
  11098. installReadyStateChangeImplementation();
  11099. } else {
  11100. // For older browsers
  11101. installSetTimeoutImplementation();
  11102. }
  11103. attachTo.setImmediate = setImmediate;
  11104. attachTo.clearImmediate = clearImmediate;
  11105. }(typeof self === "undefined" ? typeof commonjsGlobal === "undefined" ? commonjsGlobal : commonjsGlobal : self));
  11106. // setimmediate adds setImmediate to the global. We want to make sure we export
  11107. // the actual function.
  11108. var setImmediate = commonjsGlobal.setImmediate;
  11109. // When nothing is focused, Firefox regards two characters, `'` and `/`, as
  11110. // commands that should open and focus the "quickfind" search bar. This should
  11111. // *never* happen while a contenteditable is focused, but as of v28, it
  11112. // sometimes does, even when the keypress event target is the contenteditable.
  11113. // This breaks the input. Special case these characters to ensure that when
  11114. // they are typed, we prevent default on the event to make sure not to
  11115. // trigger quickfind.
  11116. var FF_QUICKFIND_CHAR = "'";
  11117. var FF_QUICKFIND_LINK_CHAR = '/';
  11118. var isFirefox = UserAgent_1.isBrowser('Firefox');
  11119. function mustPreventDefaultForCharacter(character) {
  11120. return isFirefox && (character == FF_QUICKFIND_CHAR || character == FF_QUICKFIND_LINK_CHAR);
  11121. }
  11122. /**
  11123. * Replace the current selection with the specified text string, with the
  11124. * inline style and entity key applied to the newly inserted text.
  11125. */
  11126. function replaceText(editorState, text, inlineStyle, entityKey) {
  11127. var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), text, inlineStyle, entityKey);
  11128. return EditorState_1.push(editorState, contentState, 'insert-characters');
  11129. }
  11130. /**
  11131. * When `onBeforeInput` executes, the browser is attempting to insert a
  11132. * character into the editor. Apply this character data to the document,
  11133. * allowing native insertion if possible.
  11134. *
  11135. * Native insertion is encouraged in order to limit re-rendering and to
  11136. * preserve spellcheck highlighting, which disappears or flashes if re-render
  11137. * occurs on the relevant text nodes.
  11138. */
  11139. function editOnBeforeInput(editor, e) {
  11140. if (editor._pendingStateFromBeforeInput !== undefined) {
  11141. editor.update(editor._pendingStateFromBeforeInput);
  11142. editor._pendingStateFromBeforeInput = undefined;
  11143. }
  11144. var editorState = editor._latestEditorState;
  11145. var chars = e.data;
  11146. // In some cases (ex: IE ideographic space insertion) no character data
  11147. // is provided. There's nothing to do when this happens.
  11148. if (!chars) {
  11149. return;
  11150. }
  11151. // Allow the top-level component to handle the insertion manually. This is
  11152. // useful when triggering interesting behaviors for a character insertion,
  11153. // Simple examples: replacing a raw text ':)' with a smile emoji or image
  11154. // decorator, or setting a block to be a list item after typing '- ' at the
  11155. // start of the block.
  11156. if (editor.props.handleBeforeInput && isEventHandled_1(editor.props.handleBeforeInput(chars, editorState))) {
  11157. e.preventDefault();
  11158. return;
  11159. }
  11160. // If selection is collapsed, conditionally allow native behavior. This
  11161. // reduces re-renders and preserves spellcheck highlighting. If the selection
  11162. // is not collapsed, we will re-render.
  11163. var selection = editorState.getSelection();
  11164. var selectionStart = selection.getStartOffset();
  11165. var selectionEnd = selection.getEndOffset();
  11166. var anchorKey = selection.getAnchorKey();
  11167. if (!selection.isCollapsed()) {
  11168. e.preventDefault();
  11169. // If the currently selected text matches what the user is trying to
  11170. // replace it with, let's just update the `SelectionState`. If not, update
  11171. // the `ContentState` with the new text.
  11172. var currentlySelectedChars = editorState.getCurrentContent().getPlainText().slice(selectionStart, selectionEnd);
  11173. if (chars === currentlySelectedChars) {
  11174. editor.update(EditorState_1.forceSelection(editorState, selection.merge({
  11175. focusOffset: selectionEnd
  11176. })));
  11177. } else {
  11178. editor.update(replaceText(editorState, chars, editorState.getCurrentInlineStyle(), getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())));
  11179. }
  11180. return;
  11181. }
  11182. var newEditorState = replaceText(editorState, chars, editorState.getCurrentInlineStyle(), getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection()));
  11183. // Bunch of different cases follow where we need to prevent native insertion.
  11184. var mustPreventNative = false;
  11185. if (!mustPreventNative) {
  11186. // Browsers tend to insert text in weird places in the DOM when typing at
  11187. // the start of a leaf, so we'll handle it ourselves.
  11188. mustPreventNative = isSelectionAtLeafStart_1(editor._latestCommittedEditorState);
  11189. }
  11190. if (!mustPreventNative) {
  11191. // Chrome will also split up a node into two pieces if it contains a Tab
  11192. // char, for no explicable reason. Seemingly caused by this commit:
  11193. // https://chromium.googlesource.com/chromium/src/+/013ac5eaf3%5E%21/
  11194. var nativeSelection = commonjsGlobal.getSelection();
  11195. // Selection is necessarily collapsed at this point due to earlier check.
  11196. if (nativeSelection.anchorNode && nativeSelection.anchorNode.nodeType === Node.TEXT_NODE) {
  11197. // See isTabHTMLSpanElement in chromium EditingUtilities.cpp.
  11198. var parentNode = nativeSelection.anchorNode.parentNode;
  11199. mustPreventNative = parentNode.nodeName === 'SPAN' && parentNode.firstChild.nodeType === Node.TEXT_NODE && parentNode.firstChild.nodeValue.indexOf('\t') !== -1;
  11200. }
  11201. }
  11202. if (!mustPreventNative) {
  11203. // Check the old and new "fingerprints" of the current block to determine
  11204. // whether this insertion requires any addition or removal of text nodes,
  11205. // in which case we would prevent the native character insertion.
  11206. var originalFingerprint = BlockTree_1.getFingerprint(editorState.getBlockTree(anchorKey));
  11207. var newFingerprint = BlockTree_1.getFingerprint(newEditorState.getBlockTree(anchorKey));
  11208. mustPreventNative = originalFingerprint !== newFingerprint;
  11209. }
  11210. if (!mustPreventNative) {
  11211. mustPreventNative = mustPreventDefaultForCharacter(chars);
  11212. }
  11213. if (!mustPreventNative) {
  11214. mustPreventNative = nullthrows_1(newEditorState.getDirectionMap()).get(anchorKey) !== nullthrows_1(editorState.getDirectionMap()).get(anchorKey);
  11215. }
  11216. if (mustPreventNative) {
  11217. e.preventDefault();
  11218. editor.update(newEditorState);
  11219. return;
  11220. }
  11221. // We made it all the way! Let the browser do its thing and insert the char.
  11222. newEditorState = EditorState_1.set(newEditorState, {
  11223. nativelyRenderedContent: newEditorState.getCurrentContent()
  11224. });
  11225. // The native event is allowed to occur. To allow user onChange handlers to
  11226. // change the inserted text, we wait until the text is actually inserted
  11227. // before we actually update our state. That way when we rerender, the text
  11228. // we see in the DOM will already have been inserted properly.
  11229. editor._pendingStateFromBeforeInput = newEditorState;
  11230. setImmediate(function () {
  11231. if (editor._pendingStateFromBeforeInput !== undefined) {
  11232. editor.update(editor._pendingStateFromBeforeInput);
  11233. editor._pendingStateFromBeforeInput = undefined;
  11234. }
  11235. });
  11236. }
  11237. var editOnBeforeInput_1 = editOnBeforeInput;
  11238. function editOnBlur(editor, e) {
  11239. // In a contentEditable element, when you select a range and then click
  11240. // another active element, this does trigger a `blur` event but will not
  11241. // remove the DOM selection from the contenteditable.
  11242. // This is consistent across all browsers, but we prefer that the editor
  11243. // behave like a textarea, where a `blur` event clears the DOM selection.
  11244. // We therefore force the issue to be certain, checking whether the active
  11245. // element is `body` to force it when blurring occurs within the window (as
  11246. // opposed to clicking to another tab or window).
  11247. if (getActiveElement_1() === document.body) {
  11248. var _selection = commonjsGlobal.getSelection();
  11249. var editorNode = editor.editor;
  11250. if (_selection.rangeCount === 1 && containsNode_1(editorNode, _selection.anchorNode) && containsNode_1(editorNode, _selection.focusNode)) {
  11251. _selection.removeAllRanges();
  11252. }
  11253. }
  11254. var editorState = editor._latestEditorState;
  11255. var currentSelection = editorState.getSelection();
  11256. if (!currentSelection.getHasFocus()) {
  11257. return;
  11258. }
  11259. var selection = currentSelection.set('hasFocus', false);
  11260. editor.props.onBlur && editor.props.onBlur(e);
  11261. editor.update(EditorState_1.acceptSelection(editorState, selection));
  11262. }
  11263. var editOnBlur_1 = editOnBlur;
  11264. /**
  11265. * The user has begun using an IME input system. Switching to `composite` mode
  11266. * allows handling composition input and disables other edit behavior.
  11267. */
  11268. function editOnCompositionStart(editor, e) {
  11269. editor.setMode('composite');
  11270. editor.update(EditorState_1.set(editor._latestEditorState, { inCompositionMode: true }));
  11271. // Allow composition handler to interpret the compositionstart event
  11272. editor._onCompositionStart(e);
  11273. }
  11274. var editOnCompositionStart_1 = editOnCompositionStart;
  11275. function getFragmentFromSelection(editorState) {
  11276. var selectionState = editorState.getSelection();
  11277. if (selectionState.isCollapsed()) {
  11278. return null;
  11279. }
  11280. return getContentStateFragment_1(editorState.getCurrentContent(), selectionState);
  11281. }
  11282. var getFragmentFromSelection_1 = getFragmentFromSelection;
  11283. /**
  11284. * If we have a selection, create a ContentState fragment and store
  11285. * it in our internal clipboard. Subsequent paste events will use this
  11286. * fragment if no external clipboard data is supplied.
  11287. */
  11288. function editOnCopy(editor, e) {
  11289. var editorState = editor._latestEditorState;
  11290. var selection = editorState.getSelection();
  11291. // No selection, so there's nothing to copy.
  11292. if (selection.isCollapsed()) {
  11293. e.preventDefault();
  11294. return;
  11295. }
  11296. editor.setClipboard(getFragmentFromSelection_1(editor._latestEditorState));
  11297. }
  11298. var editOnCopy_1 = editOnCopy;
  11299. /**
  11300. * On `cut` events, native behavior is allowed to occur so that the system
  11301. * clipboard is set properly. This means that we need to take steps to recover
  11302. * the editor DOM state after the `cut` has occurred in order to maintain
  11303. * control of the component.
  11304. *
  11305. * In addition, we can keep a copy of the removed fragment, including all
  11306. * styles and entities, for use as an internal paste.
  11307. */
  11308. function editOnCut(editor, e) {
  11309. var editorState = editor._latestEditorState;
  11310. var selection = editorState.getSelection();
  11311. var element = e.target;
  11312. var scrollPosition = void 0;
  11313. // No selection, so there's nothing to cut.
  11314. if (selection.isCollapsed()) {
  11315. e.preventDefault();
  11316. return;
  11317. }
  11318. // Track the current scroll position so that it can be forced back in place
  11319. // after the editor regains control of the DOM.
  11320. if (element instanceof Node) {
  11321. scrollPosition = getScrollPosition_1(Style_1.getScrollParent(element));
  11322. }
  11323. var fragment = getFragmentFromSelection_1(editorState);
  11324. editor.setClipboard(fragment);
  11325. // Set `cut` mode to disable all event handling temporarily.
  11326. editor.setMode('cut');
  11327. // Let native `cut` behavior occur, then recover control.
  11328. setTimeout(function () {
  11329. editor.restoreEditorDOM(scrollPosition);
  11330. editor.exitCurrentMode();
  11331. editor.update(removeFragment(editorState));
  11332. }, 0);
  11333. }
  11334. function removeFragment(editorState) {
  11335. var newContent = DraftModifier_1.removeRange(editorState.getCurrentContent(), editorState.getSelection(), 'forward');
  11336. return EditorState_1.push(editorState, newContent, 'remove-range');
  11337. }
  11338. var editOnCut_1 = editOnCut;
  11339. /**
  11340. * Copyright (c) 2013-present, Facebook, Inc.
  11341. * All rights reserved.
  11342. *
  11343. * This source code is licensed under the BSD-style license found in the
  11344. * LICENSE file in the root directory of this source tree. An additional grant
  11345. * of patent rights can be found in the PATENTS file in the same directory.
  11346. *
  11347. * @providesModule editOnDragOver
  11348. * @format
  11349. *
  11350. */
  11351. /**
  11352. * Drag behavior has begun from outside the editor element.
  11353. */
  11354. function editOnDragOver(editor, e) {
  11355. editor._internalDrag = false;
  11356. editor.setMode('drag');
  11357. e.preventDefault();
  11358. }
  11359. var editOnDragOver_1 = editOnDragOver;
  11360. /**
  11361. * Copyright (c) 2013-present, Facebook, Inc.
  11362. * All rights reserved.
  11363. *
  11364. * This source code is licensed under the BSD-style license found in the
  11365. * LICENSE file in the root directory of this source tree. An additional grant
  11366. * of patent rights can be found in the PATENTS file in the same directory.
  11367. *
  11368. * @providesModule editOnDragStart
  11369. * @format
  11370. *
  11371. */
  11372. /**
  11373. * A `dragstart` event has begun within the text editor component.
  11374. */
  11375. function editOnDragStart(editor) {
  11376. editor._internalDrag = true;
  11377. editor.setMode('drag');
  11378. }
  11379. var editOnDragStart_1 = editOnDragStart;
  11380. function editOnFocus(editor, e) {
  11381. var editorState = editor._latestEditorState;
  11382. var currentSelection = editorState.getSelection();
  11383. if (currentSelection.getHasFocus()) {
  11384. return;
  11385. }
  11386. var selection = currentSelection.set('hasFocus', true);
  11387. editor.props.onFocus && editor.props.onFocus(e);
  11388. // When the tab containing this text editor is hidden and the user does a
  11389. // find-in-page in a _different_ tab, Chrome on Mac likes to forget what the
  11390. // selection was right after sending this focus event and (if you let it)
  11391. // moves the cursor back to the beginning of the editor, so we force the
  11392. // selection here instead of simply accepting it in order to preserve the
  11393. // old cursor position. See https://crbug.com/540004.
  11394. // But it looks like this is fixed in Chrome 60.0.3081.0.
  11395. // Other browsers also don't have this bug, so we prefer to acceptSelection
  11396. // when possible, to ensure that unfocusing and refocusing a Draft editor
  11397. // doesn't preserve the selection, matching how textareas work.
  11398. if (UserAgent_1.isBrowser('Chrome < 60.0.3081.0')) {
  11399. editor.update(EditorState_1.forceSelection(editorState, selection));
  11400. } else {
  11401. editor.update(EditorState_1.acceptSelection(editorState, selection));
  11402. }
  11403. }
  11404. var editOnFocus_1 = editOnFocus;
  11405. var isGecko = UserAgent_1.isEngine('Gecko');
  11406. var DOUBLE_NEWLINE = '\n\n';
  11407. /**
  11408. * This function is intended to handle spellcheck and autocorrect changes,
  11409. * which occur in the DOM natively without any opportunity to observe or
  11410. * interpret the changes before they occur.
  11411. *
  11412. * The `input` event fires in contentEditable elements reliably for non-IE
  11413. * browsers, immediately after changes occur to the editor DOM. Since our other
  11414. * handlers override or otherwise handle cover other varieties of text input,
  11415. * the DOM state should match the model in all controlled input cases. Thus,
  11416. * when an `input` change leads to a DOM/model mismatch, the change should be
  11417. * due to a spellcheck change, and we can incorporate it into our model.
  11418. */
  11419. function editOnInput(editor) {
  11420. if (editor._pendingStateFromBeforeInput !== undefined) {
  11421. editor.update(editor._pendingStateFromBeforeInput);
  11422. editor._pendingStateFromBeforeInput = undefined;
  11423. }
  11424. var domSelection = commonjsGlobal.getSelection();
  11425. var anchorNode = domSelection.anchorNode,
  11426. isCollapsed = domSelection.isCollapsed;
  11427. var isNotTextNode = anchorNode.nodeType !== Node.TEXT_NODE;
  11428. var isNotTextOrElementNode = anchorNode.nodeType !== Node.TEXT_NODE && anchorNode.nodeType !== Node.ELEMENT_NODE;
  11429. {
  11430. if (isNotTextOrElementNode) {
  11431. // TODO: (t16149272) figure out context for this change
  11432. return;
  11433. }
  11434. }
  11435. if (anchorNode.nodeType === Node.TEXT_NODE && (anchorNode.previousSibling !== null || anchorNode.nextSibling !== null)) {
  11436. // When typing at the beginning of a visual line, Chrome splits the text
  11437. // nodes into two. Why? No one knows. This commit is suspicious:
  11438. // https://chromium.googlesource.com/chromium/src/+/a3b600981286b135632371477f902214c55a1724
  11439. // To work around, we'll merge the sibling text nodes back into this one.
  11440. var span = anchorNode.parentNode;
  11441. anchorNode.nodeValue = span.textContent;
  11442. for (var child = span.firstChild; child !== null; child = child.nextSibling) {
  11443. if (child !== anchorNode) {
  11444. span.removeChild(child);
  11445. }
  11446. }
  11447. }
  11448. var domText = anchorNode.textContent;
  11449. var editorState = editor._latestEditorState;
  11450. var offsetKey = nullthrows_1(findAncestorOffsetKey_1(anchorNode));
  11451. var _DraftOffsetKey$decod = DraftOffsetKey_1.decode(offsetKey),
  11452. blockKey = _DraftOffsetKey$decod.blockKey,
  11453. decoratorKey = _DraftOffsetKey$decod.decoratorKey,
  11454. leafKey = _DraftOffsetKey$decod.leafKey;
  11455. var _editorState$getBlock = editorState.getBlockTree(blockKey).getIn([decoratorKey, 'leaves', leafKey]),
  11456. start = _editorState$getBlock.start,
  11457. end = _editorState$getBlock.end;
  11458. var content = editorState.getCurrentContent();
  11459. var block = content.getBlockForKey(blockKey);
  11460. var modelText = block.getText().slice(start, end);
  11461. // Special-case soft newlines here. If the DOM text ends in a soft newline,
  11462. // we will have manually inserted an extra soft newline in DraftEditorLeaf.
  11463. // We want to remove this extra newline for the purpose of our comparison
  11464. // of DOM and model text.
  11465. if (domText.endsWith(DOUBLE_NEWLINE)) {
  11466. domText = domText.slice(0, -1);
  11467. }
  11468. // No change -- the DOM is up to date. Nothing to do here.
  11469. if (domText === modelText) {
  11470. // This can be buggy for some Android keyboards because they don't fire
  11471. // standard onkeydown/pressed events and only fired editOnInput
  11472. // so domText is already changed by the browser and ends up being equal
  11473. // to modelText unexpectedly
  11474. return;
  11475. }
  11476. var selection = editorState.getSelection();
  11477. // We'll replace the entire leaf with the text content of the target.
  11478. var targetRange = selection.merge({
  11479. anchorOffset: start,
  11480. focusOffset: end,
  11481. isBackward: false
  11482. });
  11483. var entityKey = block.getEntityAt(start);
  11484. var entity = entityKey && content.getEntity(entityKey);
  11485. var entityType = entity && entity.getMutability();
  11486. var preserveEntity = entityType === 'MUTABLE';
  11487. // Immutable or segmented entities cannot properly be handled by the
  11488. // default browser undo, so we have to use a different change type to
  11489. // force using our internal undo method instead of falling through to the
  11490. // native browser undo.
  11491. var changeType = preserveEntity ? 'spellcheck-change' : 'apply-entity';
  11492. var newContent = DraftModifier_1.replaceText(content, targetRange, domText, block.getInlineStyleAt(start), preserveEntity ? block.getEntityAt(start) : null);
  11493. var anchorOffset, focusOffset, startOffset, endOffset;
  11494. if (isGecko) {
  11495. // Firefox selection does not change while the context menu is open, so
  11496. // we preserve the anchor and focus values of the DOM selection.
  11497. anchorOffset = domSelection.anchorOffset;
  11498. focusOffset = domSelection.focusOffset;
  11499. startOffset = start + Math.min(anchorOffset, focusOffset);
  11500. endOffset = startOffset + Math.abs(anchorOffset - focusOffset);
  11501. anchorOffset = startOffset;
  11502. focusOffset = endOffset;
  11503. } else {
  11504. // Browsers other than Firefox may adjust DOM selection while the context
  11505. // menu is open, and Safari autocorrect is prone to providing an inaccurate
  11506. // DOM selection. Don't trust it. Instead, use our existing SelectionState
  11507. // and adjust it based on the number of characters changed during the
  11508. // mutation.
  11509. var charDelta = domText.length - modelText.length;
  11510. startOffset = selection.getStartOffset();
  11511. endOffset = selection.getEndOffset();
  11512. anchorOffset = isCollapsed ? endOffset + charDelta : startOffset;
  11513. focusOffset = endOffset + charDelta;
  11514. }
  11515. // Segmented entities are completely or partially removed when their
  11516. // text content changes. For this case we do not want any text to be selected
  11517. // after the change, so we are not merging the selection.
  11518. var contentWithAdjustedDOMSelection = newContent.merge({
  11519. selectionBefore: content.getSelectionAfter(),
  11520. selectionAfter: selection.merge({ anchorOffset: anchorOffset, focusOffset: focusOffset })
  11521. });
  11522. editor.update(EditorState_1.push(editorState, contentWithAdjustedDOMSelection, changeType));
  11523. }
  11524. var editOnInput_1 = editOnInput;
  11525. var isOSX = UserAgent_1.isPlatform('Mac OS X');
  11526. var KeyBindingUtil = {
  11527. /**
  11528. * Check whether the ctrlKey modifier is *not* being used in conjunction with
  11529. * the altKey modifier. If they are combined, the result is an `altGraph`
  11530. * key modifier, which should not be handled by this set of key bindings.
  11531. */
  11532. isCtrlKeyCommand: function isCtrlKeyCommand(e) {
  11533. return !!e.ctrlKey && !e.altKey;
  11534. },
  11535. isOptionKeyCommand: function isOptionKeyCommand(e) {
  11536. return isOSX && e.altKey;
  11537. },
  11538. hasCommandModifier: function hasCommandModifier(e) {
  11539. return isOSX ? !!e.metaKey && !e.altKey : KeyBindingUtil.isCtrlKeyCommand(e);
  11540. }
  11541. };
  11542. var KeyBindingUtil_1 = KeyBindingUtil;
  11543. var clipboard = null;
  11544. /**
  11545. * Some systems offer a "secondary" clipboard to allow quick internal cut
  11546. * and paste behavior. For instance, Ctrl+K (cut) and Ctrl+Y (paste).
  11547. */
  11548. var SecondaryClipboard = {
  11549. cut: function cut(editorState) {
  11550. var content = editorState.getCurrentContent();
  11551. var selection = editorState.getSelection();
  11552. var targetRange = null;
  11553. if (selection.isCollapsed()) {
  11554. var anchorKey = selection.getAnchorKey();
  11555. var blockEnd = content.getBlockForKey(anchorKey).getLength();
  11556. if (blockEnd === selection.getAnchorOffset()) {
  11557. return editorState;
  11558. }
  11559. targetRange = selection.set('focusOffset', blockEnd);
  11560. } else {
  11561. targetRange = selection;
  11562. }
  11563. targetRange = nullthrows_1(targetRange);
  11564. clipboard = getContentStateFragment_1(content, targetRange);
  11565. var afterRemoval = DraftModifier_1.removeRange(content, targetRange, 'forward');
  11566. if (afterRemoval === content) {
  11567. return editorState;
  11568. }
  11569. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  11570. },
  11571. paste: function paste(editorState) {
  11572. if (!clipboard) {
  11573. return editorState;
  11574. }
  11575. var newContent = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), clipboard);
  11576. return EditorState_1.push(editorState, newContent, 'insert-fragment');
  11577. }
  11578. };
  11579. var SecondaryClipboard_1 = SecondaryClipboard;
  11580. // These two ranges are consecutive so anything in [HIGH_START, LOW_END] is a
  11581. // surrogate code unit.
  11582. var SURROGATE_HIGH_START = 0xD800;
  11583. var SURROGATE_HIGH_END = 0xDBFF;
  11584. var SURROGATE_LOW_START = 0xDC00;
  11585. var SURROGATE_LOW_END = 0xDFFF;
  11586. var SURROGATE_UNITS_REGEX = /[\uD800-\uDFFF]/;
  11587. /**
  11588. * @param {number} codeUnit A Unicode code-unit, in range [0, 0x10FFFF]
  11589. * @return {boolean} Whether code-unit is in a surrogate (hi/low) range
  11590. */
  11591. function isCodeUnitInSurrogateRange(codeUnit) {
  11592. return SURROGATE_HIGH_START <= codeUnit && codeUnit <= SURROGATE_LOW_END;
  11593. }
  11594. /**
  11595. * Returns whether the two characters starting at `index` form a surrogate pair.
  11596. * For example, given the string s = "\uD83D\uDE0A", (s, 0) returns true and
  11597. * (s, 1) returns false.
  11598. *
  11599. * @param {string} str
  11600. * @param {number} index
  11601. * @return {boolean}
  11602. */
  11603. function isSurrogatePair(str, index) {
  11604. !(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;
  11605. if (index + 1 === str.length) {
  11606. return false;
  11607. }
  11608. var first = str.charCodeAt(index);
  11609. var second = str.charCodeAt(index + 1);
  11610. return SURROGATE_HIGH_START <= first && first <= SURROGATE_HIGH_END && SURROGATE_LOW_START <= second && second <= SURROGATE_LOW_END;
  11611. }
  11612. /**
  11613. * @param {string} str Non-empty string
  11614. * @return {boolean} True if the input includes any surrogate code units
  11615. */
  11616. function hasSurrogateUnit(str) {
  11617. return SURROGATE_UNITS_REGEX.test(str);
  11618. }
  11619. /**
  11620. * Return the length of the original Unicode character at given position in the
  11621. * String by looking into the UTF-16 code unit; that is equal to 1 for any
  11622. * non-surrogate characters in BMP ([U+0000..U+D7FF] and [U+E000, U+FFFF]); and
  11623. * returns 2 for the hi/low surrogates ([U+D800..U+DFFF]), which are in fact
  11624. * representing non-BMP characters ([U+10000..U+10FFFF]).
  11625. *
  11626. * Examples:
  11627. * - '\u0020' => 1
  11628. * - '\u3020' => 1
  11629. * - '\uD835' => 2
  11630. * - '\uD835\uDDEF' => 2
  11631. * - '\uDDEF' => 2
  11632. *
  11633. * @param {string} str Non-empty string
  11634. * @param {number} pos Position in the string to look for one code unit
  11635. * @return {number} Number 1 or 2
  11636. */
  11637. function getUTF16Length(str, pos) {
  11638. return 1 + isCodeUnitInSurrogateRange(str.charCodeAt(pos));
  11639. }
  11640. /**
  11641. * Fully Unicode-enabled replacement for String#length
  11642. *
  11643. * @param {string} str Valid Unicode string
  11644. * @return {number} The number of Unicode characters in the string
  11645. */
  11646. function strlen(str) {
  11647. // Call the native functions if there's no surrogate char
  11648. if (!hasSurrogateUnit(str)) {
  11649. return str.length;
  11650. }
  11651. var len = 0;
  11652. for (var pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
  11653. len++;
  11654. }
  11655. return len;
  11656. }
  11657. /**
  11658. * Fully Unicode-enabled replacement for String#substr()
  11659. *
  11660. * @param {string} str Valid Unicode string
  11661. * @param {number} start Location in Unicode sequence to begin extracting
  11662. * @param {?number} length The number of Unicode characters to extract
  11663. * (default: to the end of the string)
  11664. * @return {string} Extracted sub-string
  11665. */
  11666. function substr(str, start, length) {
  11667. start = start || 0;
  11668. length = length === undefined ? Infinity : length || 0;
  11669. // Call the native functions if there's no surrogate char
  11670. if (!hasSurrogateUnit(str)) {
  11671. return str.substr(start, length);
  11672. }
  11673. // Obvious cases
  11674. var size = str.length;
  11675. if (size <= 0 || start > size || length <= 0) {
  11676. return '';
  11677. }
  11678. // Find the actual starting position
  11679. var posA = 0;
  11680. if (start > 0) {
  11681. for (; start > 0 && posA < size; start--) {
  11682. posA += getUTF16Length(str, posA);
  11683. }
  11684. if (posA >= size) {
  11685. return '';
  11686. }
  11687. } else if (start < 0) {
  11688. for (posA = size; start < 0 && 0 < posA; start++) {
  11689. posA -= getUTF16Length(str, posA - 1);
  11690. }
  11691. if (posA < 0) {
  11692. posA = 0;
  11693. }
  11694. }
  11695. // Find the actual ending position
  11696. var posB = size;
  11697. if (length < size) {
  11698. for (posB = posA; length > 0 && posB < size; length--) {
  11699. posB += getUTF16Length(str, posB);
  11700. }
  11701. }
  11702. return str.substring(posA, posB);
  11703. }
  11704. /**
  11705. * Fully Unicode-enabled replacement for String#substring()
  11706. *
  11707. * @param {string} str Valid Unicode string
  11708. * @param {number} start Location in Unicode sequence to begin extracting
  11709. * @param {?number} end Location in Unicode sequence to end extracting
  11710. * (default: end of the string)
  11711. * @return {string} Extracted sub-string
  11712. */
  11713. function substring(str, start, end) {
  11714. start = start || 0;
  11715. end = end === undefined ? Infinity : end || 0;
  11716. if (start < 0) {
  11717. start = 0;
  11718. }
  11719. if (end < 0) {
  11720. end = 0;
  11721. }
  11722. var length = Math.abs(end - start);
  11723. start = start < end ? start : end;
  11724. return substr(str, start, length);
  11725. }
  11726. /**
  11727. * Get a list of Unicode code-points from a String
  11728. *
  11729. * @param {string} str Valid Unicode string
  11730. * @return {array<number>} A list of code-points in [0..0x10FFFF]
  11731. */
  11732. function getCodePoints(str) {
  11733. var codePoints = [];
  11734. for (var pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
  11735. codePoints.push(str.codePointAt(pos));
  11736. }
  11737. return codePoints;
  11738. }
  11739. var UnicodeUtils = {
  11740. getCodePoints: getCodePoints,
  11741. getUTF16Length: getUTF16Length,
  11742. hasSurrogateUnit: hasSurrogateUnit,
  11743. isCodeUnitInSurrogateRange: isCodeUnitInSurrogateRange,
  11744. isSurrogatePair: isSurrogatePair,
  11745. strlen: strlen,
  11746. substring: substring,
  11747. substr: substr
  11748. };
  11749. var UnicodeUtils_1 = UnicodeUtils;
  11750. var isChrome = UserAgent_1.isBrowser('Chrome');
  11751. // In Chrome, the client rects will include the entire bounds of all nodes that
  11752. // begin (have a start tag) within the selection, even if the selection does
  11753. // not overlap the entire node. To resolve this, we split the range at each
  11754. // start tag and join the client rects together.
  11755. // https://code.google.com/p/chromium/issues/detail?id=324437
  11756. /* eslint-disable consistent-return */
  11757. function getRangeClientRectsChrome(range) {
  11758. var tempRange = range.cloneRange();
  11759. var clientRects = [];
  11760. for (var ancestor = range.endContainer; ancestor != null; ancestor = ancestor.parentNode) {
  11761. // If we've climbed up to the common ancestor, we can now use the
  11762. // original start point and stop climbing the tree.
  11763. var atCommonAncestor = ancestor === range.commonAncestorContainer;
  11764. if (atCommonAncestor) {
  11765. tempRange.setStart(range.startContainer, range.startOffset);
  11766. } else {
  11767. tempRange.setStart(tempRange.endContainer, 0);
  11768. }
  11769. var rects = Array.from(tempRange.getClientRects());
  11770. clientRects.push(rects);
  11771. if (atCommonAncestor) {
  11772. var _ref;
  11773. clientRects.reverse();
  11774. return (_ref = []).concat.apply(_ref, clientRects);
  11775. }
  11776. tempRange.setEndBefore(ancestor);
  11777. }
  11778. process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Found an unexpected detached subtree when getting range client rects.') : invariant_1(false) ;
  11779. }
  11780. /* eslint-enable consistent-return */
  11781. /**
  11782. * Like range.getClientRects() but normalizes for browser bugs.
  11783. */
  11784. var getRangeClientRects = isChrome ? getRangeClientRectsChrome : function (range) {
  11785. return Array.from(range.getClientRects());
  11786. };
  11787. var getRangeClientRects_1 = getRangeClientRects;
  11788. /**
  11789. * Copyright (c) 2013-present, Facebook, Inc.
  11790. * All rights reserved.
  11791. *
  11792. * This source code is licensed under the BSD-style license found in the
  11793. * LICENSE file in the root directory of this source tree. An additional grant
  11794. * of patent rights can be found in the PATENTS file in the same directory.
  11795. *
  11796. * @providesModule expandRangeToStartOfLine
  11797. * @format
  11798. *
  11799. */
  11800. /**
  11801. * Return the computed line height, in pixels, for the provided element.
  11802. */
  11803. function getLineHeightPx(element) {
  11804. var computed = getComputedStyle(element);
  11805. var div = document.createElement('div');
  11806. div.style.fontFamily = computed.fontFamily;
  11807. div.style.fontSize = computed.fontSize;
  11808. div.style.fontStyle = computed.fontStyle;
  11809. div.style.fontWeight = computed.fontWeight;
  11810. div.style.lineHeight = computed.lineHeight;
  11811. div.style.position = 'absolute';
  11812. div.textContent = 'M';
  11813. var documentBody = document.body;
  11814. !documentBody ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing document.body') : invariant_1(false) : void 0;
  11815. // forced layout here
  11816. documentBody.appendChild(div);
  11817. var rect = div.getBoundingClientRect();
  11818. documentBody.removeChild(div);
  11819. return rect.height;
  11820. }
  11821. /**
  11822. * Return whether every ClientRect in the provided list lies on the same line.
  11823. *
  11824. * We assume that the rects on the same line all contain the baseline, so the
  11825. * lowest top line needs to be above the highest bottom line (i.e., if you were
  11826. * to project the rects onto the y-axis, their intersection would be nonempty).
  11827. *
  11828. * In addition, we require that no two boxes are lineHeight (or more) apart at
  11829. * either top or bottom, which helps protect against false positives for fonts
  11830. * with extremely large glyph heights (e.g., with a font size of 17px, Zapfino
  11831. * produces rects of height 58px!).
  11832. */
  11833. function areRectsOnOneLine(rects, lineHeight) {
  11834. var minTop = Infinity;
  11835. var minBottom = Infinity;
  11836. var maxTop = -Infinity;
  11837. var maxBottom = -Infinity;
  11838. for (var ii = 0; ii < rects.length; ii++) {
  11839. var rect = rects[ii];
  11840. if (rect.width === 0 || rect.width === 1) {
  11841. // When a range starts or ends a soft wrap, many browsers (Chrome, IE,
  11842. // Safari) include an empty rect on the previous or next line. When the
  11843. // text lies in a container whose position is not integral (e.g., from
  11844. // margin: auto), Safari makes these empty rects have width 1 (instead of
  11845. // 0). Having one-pixel-wide characters seems unlikely (and most browsers
  11846. // report widths in subpixel precision anyway) so it's relatively safe to
  11847. // skip over them.
  11848. continue;
  11849. }
  11850. minTop = Math.min(minTop, rect.top);
  11851. minBottom = Math.min(minBottom, rect.bottom);
  11852. maxTop = Math.max(maxTop, rect.top);
  11853. maxBottom = Math.max(maxBottom, rect.bottom);
  11854. }
  11855. return maxTop <= minBottom && maxTop - minTop < lineHeight && maxBottom - minBottom < lineHeight;
  11856. }
  11857. /**
  11858. * Return the length of a node, as used by Range offsets.
  11859. */
  11860. function getNodeLength$1(node) {
  11861. // http://www.w3.org/TR/dom/#concept-node-length
  11862. switch (node.nodeType) {
  11863. case Node.DOCUMENT_TYPE_NODE:
  11864. return 0;
  11865. case Node.TEXT_NODE:
  11866. case Node.PROCESSING_INSTRUCTION_NODE:
  11867. case Node.COMMENT_NODE:
  11868. return node.length;
  11869. default:
  11870. return node.childNodes.length;
  11871. }
  11872. }
  11873. /**
  11874. * Given a collapsed range, move the start position backwards as far as
  11875. * possible while the range still spans only a single line.
  11876. */
  11877. function expandRangeToStartOfLine(range) {
  11878. !range.collapsed ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'expandRangeToStartOfLine: Provided range is not collapsed.') : invariant_1(false) : void 0;
  11879. range = range.cloneRange();
  11880. var containingElement = range.startContainer;
  11881. if (containingElement.nodeType !== 1) {
  11882. containingElement = containingElement.parentNode;
  11883. }
  11884. var lineHeight = getLineHeightPx(containingElement);
  11885. // Imagine our text looks like:
  11886. // <div><span>once upon a time, there was a <em>boy
  11887. // who lived</em> </span><q><strong>under^ the
  11888. // stairs</strong> in a small closet.</q></div>
  11889. // where the caret represents the cursor. First, we crawl up the tree until
  11890. // the range spans multiple lines (setting the start point to before
  11891. // "<strong>", then before "<div>"), then at each level we do a search to
  11892. // find the latest point which is still on a previous line. We'll find that
  11893. // the break point is inside the span, then inside the <em>, then in its text
  11894. // node child, the actual break point before "who".
  11895. var bestContainer = range.endContainer;
  11896. var bestOffset = range.endOffset;
  11897. range.setStart(range.startContainer, 0);
  11898. while (areRectsOnOneLine(getRangeClientRects_1(range), lineHeight)) {
  11899. bestContainer = range.startContainer;
  11900. bestOffset = range.startOffset;
  11901. !bestContainer.parentNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Found unexpected detached subtree when traversing.') : invariant_1(false) : void 0;
  11902. range.setStartBefore(bestContainer);
  11903. if (bestContainer.nodeType === 1 && getComputedStyle(bestContainer).display !== 'inline') {
  11904. // The start of the line is never in a different block-level container.
  11905. break;
  11906. }
  11907. }
  11908. // In the above example, range now spans from "<div>" to "under",
  11909. // bestContainer is <div>, and bestOffset is 1 (index of <q> inside <div>)].
  11910. // Picking out which child to recurse into here is a special case since we
  11911. // don't want to check past <q> -- once we find that the final range starts
  11912. // in <span>, we can look at all of its children (and all of their children)
  11913. // to find the break point.
  11914. // At all times, (bestContainer, bestOffset) is the latest single-line start
  11915. // point that we know of.
  11916. var currentContainer = bestContainer;
  11917. var maxIndexToConsider = bestOffset - 1;
  11918. do {
  11919. var nodeValue = currentContainer.nodeValue;
  11920. for (var ii = maxIndexToConsider; ii >= 0; ii--) {
  11921. if (nodeValue != null && ii > 0 && UnicodeUtils_1.isSurrogatePair(nodeValue, ii - 1)) {
  11922. // We're in the middle of a surrogate pair -- skip over so we never
  11923. // return a range with an endpoint in the middle of a code point.
  11924. continue;
  11925. }
  11926. range.setStart(currentContainer, ii);
  11927. if (areRectsOnOneLine(getRangeClientRects_1(range), lineHeight)) {
  11928. bestContainer = currentContainer;
  11929. bestOffset = ii;
  11930. } else {
  11931. break;
  11932. }
  11933. }
  11934. if (ii === -1 || currentContainer.childNodes.length === 0) {
  11935. // If ii === -1, then (bestContainer, bestOffset), which is equal to
  11936. // (currentContainer, 0), was a single-line start point but a start
  11937. // point before currentContainer wasn't, so the line break seems to
  11938. // have occurred immediately after currentContainer's start tag
  11939. //
  11940. // If currentContainer.childNodes.length === 0, we're already at a
  11941. // terminal node (e.g., text node) and should return our current best.
  11942. break;
  11943. }
  11944. currentContainer = currentContainer.childNodes[ii];
  11945. maxIndexToConsider = getNodeLength$1(currentContainer);
  11946. } while (true);
  11947. range.setStart(bestContainer, bestOffset);
  11948. return range;
  11949. }
  11950. var expandRangeToStartOfLine_1 = expandRangeToStartOfLine;
  11951. /**
  11952. * Convert the current selection range to an anchor/focus pair of offset keys
  11953. * and values that can be interpreted by components.
  11954. */
  11955. function getDraftEditorSelectionWithNodes(editorState, root, anchorNode, anchorOffset, focusNode, focusOffset) {
  11956. var anchorIsTextNode = anchorNode.nodeType === Node.TEXT_NODE;
  11957. var focusIsTextNode = focusNode.nodeType === Node.TEXT_NODE;
  11958. // If the selection range lies only on text nodes, the task is simple.
  11959. // Find the nearest offset-aware elements and use the
  11960. // offset values supplied by the selection range.
  11961. if (anchorIsTextNode && focusIsTextNode) {
  11962. return {
  11963. selectionState: getUpdatedSelectionState_1(editorState, nullthrows_1(findAncestorOffsetKey_1(anchorNode)), anchorOffset, nullthrows_1(findAncestorOffsetKey_1(focusNode)), focusOffset),
  11964. needsRecovery: false
  11965. };
  11966. }
  11967. var anchorPoint = null;
  11968. var focusPoint = null;
  11969. var needsRecovery = true;
  11970. // An element is selected. Convert this selection range into leaf offset
  11971. // keys and offset values for consumption at the component level. This
  11972. // is common in Firefox, where select-all and triple click behavior leads
  11973. // to entire elements being selected.
  11974. //
  11975. // Note that we use the `needsRecovery` parameter in the callback here. This
  11976. // is because when certain elements are selected, the behavior for subsequent
  11977. // cursor movement (e.g. via arrow keys) is uncertain and may not match
  11978. // expectations at the component level. For example, if an entire <div> is
  11979. // selected and the user presses the right arrow, Firefox keeps the selection
  11980. // on the <div>. If we allow subsequent keypresses to insert characters
  11981. // natively, they will be inserted into a browser-created text node to the
  11982. // right of that <div>. This is obviously undesirable.
  11983. //
  11984. // With the `needsRecovery` flag, we inform the caller that it is responsible
  11985. // for manually setting the selection state on the rendered document to
  11986. // ensure proper selection state maintenance.
  11987. if (anchorIsTextNode) {
  11988. anchorPoint = {
  11989. key: nullthrows_1(findAncestorOffsetKey_1(anchorNode)),
  11990. offset: anchorOffset
  11991. };
  11992. focusPoint = getPointForNonTextNode(root, focusNode, focusOffset);
  11993. } else if (focusIsTextNode) {
  11994. focusPoint = {
  11995. key: nullthrows_1(findAncestorOffsetKey_1(focusNode)),
  11996. offset: focusOffset
  11997. };
  11998. anchorPoint = getPointForNonTextNode(root, anchorNode, anchorOffset);
  11999. } else {
  12000. anchorPoint = getPointForNonTextNode(root, anchorNode, anchorOffset);
  12001. focusPoint = getPointForNonTextNode(root, focusNode, focusOffset);
  12002. // If the selection is collapsed on an empty block, don't force recovery.
  12003. // This way, on arrow key selection changes, the browser can move the
  12004. // cursor from a non-zero offset on one block, through empty blocks,
  12005. // to a matching non-zero offset on other text blocks.
  12006. if (anchorNode === focusNode && anchorOffset === focusOffset) {
  12007. needsRecovery = !!anchorNode.firstChild && anchorNode.firstChild.nodeName !== 'BR';
  12008. }
  12009. }
  12010. return {
  12011. selectionState: getUpdatedSelectionState_1(editorState, anchorPoint.key, anchorPoint.offset, focusPoint.key, focusPoint.offset),
  12012. needsRecovery: needsRecovery
  12013. };
  12014. }
  12015. /**
  12016. * Identify the first leaf descendant for the given node.
  12017. */
  12018. function getFirstLeaf(node) {
  12019. while (node.firstChild && (
  12020. // data-blocks has no offset
  12021. node.firstChild instanceof Element && node.firstChild.getAttribute('data-blocks') === 'true' || getSelectionOffsetKeyForNode_1(node.firstChild))) {
  12022. node = node.firstChild;
  12023. }
  12024. return node;
  12025. }
  12026. /**
  12027. * Identify the last leaf descendant for the given node.
  12028. */
  12029. function getLastLeaf(node) {
  12030. while (node.lastChild && (
  12031. // data-blocks has no offset
  12032. node.lastChild instanceof Element && node.lastChild.getAttribute('data-blocks') === 'true' || getSelectionOffsetKeyForNode_1(node.lastChild))) {
  12033. node = node.lastChild;
  12034. }
  12035. return node;
  12036. }
  12037. function getPointForNonTextNode(editorRoot, startNode, childOffset) {
  12038. var node = startNode;
  12039. var offsetKey = findAncestorOffsetKey_1(node);
  12040. !(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;
  12041. // If the editorRoot is the selection, step downward into the content
  12042. // wrapper.
  12043. if (editorRoot === node) {
  12044. node = node.firstChild;
  12045. !(node instanceof Element && node.getAttribute('data-contents') === 'true') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid DraftEditorContents structure.') : invariant_1(false) : void 0;
  12046. if (childOffset > 0) {
  12047. childOffset = node.childNodes.length;
  12048. }
  12049. }
  12050. // If the child offset is zero and we have an offset key, we're done.
  12051. // If there's no offset key because the entire editor is selected,
  12052. // find the leftmost ("first") leaf in the tree and use that as the offset
  12053. // key.
  12054. if (childOffset === 0) {
  12055. var key = null;
  12056. if (offsetKey != null) {
  12057. key = offsetKey;
  12058. } else {
  12059. var firstLeaf = getFirstLeaf(node);
  12060. key = nullthrows_1(getSelectionOffsetKeyForNode_1(firstLeaf));
  12061. }
  12062. return { key: key, offset: 0 };
  12063. }
  12064. var nodeBeforeCursor = node.childNodes[childOffset - 1];
  12065. var leafKey = null;
  12066. var textLength = null;
  12067. if (!getSelectionOffsetKeyForNode_1(nodeBeforeCursor)) {
  12068. // Our target node may be a leaf or a text node, in which case we're
  12069. // already where we want to be and can just use the child's length as
  12070. // our offset.
  12071. leafKey = nullthrows_1(offsetKey);
  12072. textLength = getTextContentLength(nodeBeforeCursor);
  12073. } else {
  12074. // Otherwise, we'll look at the child to the left of the cursor and find
  12075. // the last leaf node in its subtree.
  12076. var lastLeaf = getLastLeaf(nodeBeforeCursor);
  12077. leafKey = nullthrows_1(getSelectionOffsetKeyForNode_1(lastLeaf));
  12078. textLength = getTextContentLength(lastLeaf);
  12079. }
  12080. return {
  12081. key: leafKey,
  12082. offset: textLength
  12083. };
  12084. }
  12085. /**
  12086. * Return the length of a node's textContent, regarding single newline
  12087. * characters as zero-length. This allows us to avoid problems with identifying
  12088. * the correct selection offset for empty blocks in IE, in which we
  12089. * render newlines instead of break tags.
  12090. */
  12091. function getTextContentLength(node) {
  12092. var textContent = node.textContent;
  12093. return textContent === '\n' ? 0 : textContent.length;
  12094. }
  12095. var getDraftEditorSelectionWithNodes_1 = getDraftEditorSelectionWithNodes;
  12096. /**
  12097. * Copyright (c) 2013-present, Facebook, Inc.
  12098. * All rights reserved.
  12099. *
  12100. * This source code is licensed under the BSD-style license found in the
  12101. * LICENSE file in the root directory of this source tree. An additional grant
  12102. * of patent rights can be found in the PATENTS file in the same directory.
  12103. *
  12104. * @providesModule moveSelectionBackward
  12105. * @format
  12106. *
  12107. */
  12108. /**
  12109. * Given a collapsed selection, move the focus `maxDistance` backward within
  12110. * the selected block. If the selection will go beyond the start of the block,
  12111. * move focus to the end of the previous block, but no further.
  12112. *
  12113. * This function is not Unicode-aware, so surrogate pairs will be treated
  12114. * as having length 2.
  12115. */
  12116. function moveSelectionBackward(editorState, maxDistance) {
  12117. var selection = editorState.getSelection();
  12118. var content = editorState.getCurrentContent();
  12119. var key = selection.getStartKey();
  12120. var offset = selection.getStartOffset();
  12121. var focusKey = key;
  12122. var focusOffset = 0;
  12123. if (maxDistance > offset) {
  12124. var keyBefore = content.getKeyBefore(key);
  12125. if (keyBefore == null) {
  12126. focusKey = key;
  12127. } else {
  12128. focusKey = keyBefore;
  12129. var blockBefore = content.getBlockForKey(keyBefore);
  12130. focusOffset = blockBefore.getText().length;
  12131. }
  12132. } else {
  12133. focusOffset = offset - maxDistance;
  12134. }
  12135. return selection.merge({
  12136. focusKey: focusKey,
  12137. focusOffset: focusOffset,
  12138. isBackward: true
  12139. });
  12140. }
  12141. var moveSelectionBackward_1 = moveSelectionBackward;
  12142. /**
  12143. * For a collapsed selection state, remove text based on the specified strategy.
  12144. * If the selection state is not collapsed, remove the entire selected range.
  12145. */
  12146. function removeTextWithStrategy(editorState, strategy, direction) {
  12147. var selection = editorState.getSelection();
  12148. var content = editorState.getCurrentContent();
  12149. var target = selection;
  12150. if (selection.isCollapsed()) {
  12151. if (direction === 'forward') {
  12152. if (editorState.isSelectionAtEndOfContent()) {
  12153. return content;
  12154. }
  12155. } else if (editorState.isSelectionAtStartOfContent()) {
  12156. return content;
  12157. }
  12158. target = strategy(editorState);
  12159. if (target === selection) {
  12160. return content;
  12161. }
  12162. }
  12163. return DraftModifier_1.removeRange(content, target, direction);
  12164. }
  12165. var removeTextWithStrategy_1 = removeTextWithStrategy;
  12166. function keyCommandBackspaceToStartOfLine(editorState) {
  12167. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12168. var selection = strategyState.getSelection();
  12169. if (selection.isCollapsed() && selection.getAnchorOffset() === 0) {
  12170. return moveSelectionBackward_1(strategyState, 1);
  12171. }
  12172. var domSelection = commonjsGlobal.getSelection();
  12173. var range = domSelection.getRangeAt(0);
  12174. range = expandRangeToStartOfLine_1(range);
  12175. return getDraftEditorSelectionWithNodes_1(strategyState, null, range.endContainer, range.endOffset, range.startContainer, range.startOffset).selectionState;
  12176. }, 'backward');
  12177. if (afterRemoval === editorState.getCurrentContent()) {
  12178. return editorState;
  12179. }
  12180. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  12181. }
  12182. var keyCommandBackspaceToStartOfLine_1 = keyCommandBackspaceToStartOfLine;
  12183. /**
  12184. * Copyright (c) 2013-present, Facebook, Inc.
  12185. *
  12186. * This source code is licensed under the MIT license found in the
  12187. * LICENSE file in the root directory of this source tree.
  12188. *
  12189. * @typechecks
  12190. * @stub
  12191. *
  12192. */
  12193. // \u00a1-\u00b1\u00b4-\u00b8\u00ba\u00bb\u00bf
  12194. // is latin supplement punctuation except fractions and superscript
  12195. // numbers
  12196. // \u2010-\u2027\u2030-\u205e
  12197. // is punctuation from the general punctuation block:
  12198. // weird quotes, commas, bullets, dashes, etc.
  12199. // \u30fb\u3001\u3002\u3008-\u3011\u3014-\u301f
  12200. // is CJK punctuation
  12201. // \uff1a-\uff1f\uff01-\uff0f\uff3b-\uff40\uff5b-\uff65
  12202. // is some full-width/half-width punctuation
  12203. // \u2E2E\u061f\u066a-\u066c\u061b\u060c\u060d\uFD3e\uFD3F
  12204. // is some Arabic punctuation marks
  12205. // \u1801\u0964\u104a\u104b
  12206. // is misc. other language punctuation marks
  12207. 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]';
  12208. var TokenizeUtil = {
  12209. getPunctuation: function getPunctuation() {
  12210. return PUNCTUATION;
  12211. }
  12212. };
  12213. var punctuation = TokenizeUtil.getPunctuation();
  12214. // The apostrophe and curly single quotes behave in a curious way: when
  12215. // surrounded on both sides by word characters, they behave as word chars; when
  12216. // either neighbor is punctuation or an end of the string, they behave as
  12217. // punctuation.
  12218. var CHAMELEON_CHARS = '[\'\u2018\u2019]';
  12219. // Remove the underscore, which should count as part of the removable word. The
  12220. // "chameleon chars" also count as punctuation in this regex.
  12221. var WHITESPACE_AND_PUNCTUATION = '\\s|(?![_])' + punctuation;
  12222. var DELETE_STRING = '^' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)';
  12223. var DELETE_REGEX = new RegExp(DELETE_STRING);
  12224. var BACKSPACE_STRING = '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '$';
  12225. var BACKSPACE_REGEX = new RegExp(BACKSPACE_STRING);
  12226. function getRemovableWord(text, isBackward) {
  12227. var matches = isBackward ? BACKSPACE_REGEX.exec(text) : DELETE_REGEX.exec(text);
  12228. return matches ? matches[0] : text;
  12229. }
  12230. var DraftRemovableWord = {
  12231. getBackward: function getBackward(text) {
  12232. return getRemovableWord(text, true);
  12233. },
  12234. getForward: function getForward(text) {
  12235. return getRemovableWord(text, false);
  12236. }
  12237. };
  12238. var DraftRemovableWord_1 = DraftRemovableWord;
  12239. /**
  12240. * Delete the word that is left of the cursor, as well as any spaces or
  12241. * punctuation after the word.
  12242. */
  12243. function keyCommandBackspaceWord(editorState) {
  12244. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12245. var selection = strategyState.getSelection();
  12246. var offset = selection.getStartOffset();
  12247. // If there are no words before the cursor, remove the preceding newline.
  12248. if (offset === 0) {
  12249. return moveSelectionBackward_1(strategyState, 1);
  12250. }
  12251. var key = selection.getStartKey();
  12252. var content = strategyState.getCurrentContent();
  12253. var text = content.getBlockForKey(key).getText().slice(0, offset);
  12254. var toRemove = DraftRemovableWord_1.getBackward(text);
  12255. return moveSelectionBackward_1(strategyState, toRemove.length || 1);
  12256. }, 'backward');
  12257. if (afterRemoval === editorState.getCurrentContent()) {
  12258. return editorState;
  12259. }
  12260. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  12261. }
  12262. var keyCommandBackspaceWord_1 = keyCommandBackspaceWord;
  12263. /**
  12264. * Copyright (c) 2013-present, Facebook, Inc.
  12265. * All rights reserved.
  12266. *
  12267. * This source code is licensed under the BSD-style license found in the
  12268. * LICENSE file in the root directory of this source tree. An additional grant
  12269. * of patent rights can be found in the PATENTS file in the same directory.
  12270. *
  12271. * @providesModule moveSelectionForward
  12272. * @format
  12273. *
  12274. */
  12275. /**
  12276. * Given a collapsed selection, move the focus `maxDistance` forward within
  12277. * the selected block. If the selection will go beyond the end of the block,
  12278. * move focus to the start of the next block, but no further.
  12279. *
  12280. * This function is not Unicode-aware, so surrogate pairs will be treated
  12281. * as having length 2.
  12282. */
  12283. function moveSelectionForward(editorState, maxDistance) {
  12284. var selection = editorState.getSelection();
  12285. var key = selection.getStartKey();
  12286. var offset = selection.getStartOffset();
  12287. var content = editorState.getCurrentContent();
  12288. var focusKey = key;
  12289. var focusOffset;
  12290. var block = content.getBlockForKey(key);
  12291. if (maxDistance > block.getText().length - offset) {
  12292. focusKey = content.getKeyAfter(key);
  12293. focusOffset = 0;
  12294. } else {
  12295. focusOffset = offset + maxDistance;
  12296. }
  12297. return selection.merge({ focusKey: focusKey, focusOffset: focusOffset });
  12298. }
  12299. var moveSelectionForward_1 = moveSelectionForward;
  12300. /**
  12301. * Delete the word that is right of the cursor, as well as any spaces or
  12302. * punctuation before the word.
  12303. */
  12304. function keyCommandDeleteWord(editorState) {
  12305. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12306. var selection = strategyState.getSelection();
  12307. var offset = selection.getStartOffset();
  12308. var key = selection.getStartKey();
  12309. var content = strategyState.getCurrentContent();
  12310. var text = content.getBlockForKey(key).getText().slice(offset);
  12311. var toRemove = DraftRemovableWord_1.getForward(text);
  12312. // If there are no words in front of the cursor, remove the newline.
  12313. return moveSelectionForward_1(strategyState, toRemove.length || 1);
  12314. }, 'forward');
  12315. if (afterRemoval === editorState.getCurrentContent()) {
  12316. return editorState;
  12317. }
  12318. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  12319. }
  12320. var keyCommandDeleteWord_1 = keyCommandDeleteWord;
  12321. function keyCommandInsertNewline(editorState) {
  12322. var contentState = DraftModifier_1.splitBlock(editorState.getCurrentContent(), editorState.getSelection());
  12323. return EditorState_1.push(editorState, contentState, 'split-block');
  12324. }
  12325. var keyCommandInsertNewline_1 = keyCommandInsertNewline;
  12326. /**
  12327. * See comment for `moveSelectionToStartOfBlock`.
  12328. */
  12329. function keyCommandMoveSelectionToEndOfBlock(editorState) {
  12330. var selection = editorState.getSelection();
  12331. var endKey = selection.getEndKey();
  12332. var content = editorState.getCurrentContent();
  12333. var textLength = content.getBlockForKey(endKey).getLength();
  12334. return EditorState_1.set(editorState, {
  12335. selection: selection.merge({
  12336. anchorKey: endKey,
  12337. anchorOffset: textLength,
  12338. focusKey: endKey,
  12339. focusOffset: textLength,
  12340. isBackward: false
  12341. }),
  12342. forceSelection: true
  12343. });
  12344. }
  12345. var keyCommandMoveSelectionToEndOfBlock_1 = keyCommandMoveSelectionToEndOfBlock;
  12346. /**
  12347. * Collapse selection at the start of the first selected block. This is used
  12348. * for Firefox versions that attempt to navigate forward/backward instead of
  12349. * moving the cursor. Other browsers are able to move the cursor natively.
  12350. */
  12351. function keyCommandMoveSelectionToStartOfBlock(editorState) {
  12352. var selection = editorState.getSelection();
  12353. var startKey = selection.getStartKey();
  12354. return EditorState_1.set(editorState, {
  12355. selection: selection.merge({
  12356. anchorKey: startKey,
  12357. anchorOffset: 0,
  12358. focusKey: startKey,
  12359. focusOffset: 0,
  12360. isBackward: false
  12361. }),
  12362. forceSelection: true
  12363. });
  12364. }
  12365. var keyCommandMoveSelectionToStartOfBlock_1 = keyCommandMoveSelectionToStartOfBlock;
  12366. /**
  12367. * Remove the selected range. If the cursor is collapsed, remove the preceding
  12368. * character. This operation is Unicode-aware, so removing a single character
  12369. * will remove a surrogate pair properly as well.
  12370. */
  12371. function keyCommandPlainBackspace(editorState) {
  12372. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12373. var selection = strategyState.getSelection();
  12374. var content = strategyState.getCurrentContent();
  12375. var key = selection.getAnchorKey();
  12376. var offset = selection.getAnchorOffset();
  12377. var charBehind = content.getBlockForKey(key).getText()[offset - 1];
  12378. return moveSelectionBackward_1(strategyState, charBehind ? UnicodeUtils_1.getUTF16Length(charBehind, 0) : 1);
  12379. }, 'backward');
  12380. if (afterRemoval === editorState.getCurrentContent()) {
  12381. return editorState;
  12382. }
  12383. var selection = editorState.getSelection();
  12384. return EditorState_1.push(editorState, afterRemoval.set('selectionBefore', selection), selection.isCollapsed() ? 'backspace-character' : 'remove-range');
  12385. }
  12386. var keyCommandPlainBackspace_1 = keyCommandPlainBackspace;
  12387. /**
  12388. * Remove the selected range. If the cursor is collapsed, remove the following
  12389. * character. This operation is Unicode-aware, so removing a single character
  12390. * will remove a surrogate pair properly as well.
  12391. */
  12392. function keyCommandPlainDelete(editorState) {
  12393. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12394. var selection = strategyState.getSelection();
  12395. var content = strategyState.getCurrentContent();
  12396. var key = selection.getAnchorKey();
  12397. var offset = selection.getAnchorOffset();
  12398. var charAhead = content.getBlockForKey(key).getText()[offset];
  12399. return moveSelectionForward_1(strategyState, charAhead ? UnicodeUtils_1.getUTF16Length(charAhead, 0) : 1);
  12400. }, 'forward');
  12401. if (afterRemoval === editorState.getCurrentContent()) {
  12402. return editorState;
  12403. }
  12404. var selection = editorState.getSelection();
  12405. return EditorState_1.push(editorState, afterRemoval.set('selectionBefore', selection), selection.isCollapsed() ? 'delete-character' : 'remove-range');
  12406. }
  12407. var keyCommandPlainDelete_1 = keyCommandPlainDelete;
  12408. /**
  12409. * Transpose the characters on either side of a collapsed cursor, or
  12410. * if the cursor is at the end of the block, transpose the last two
  12411. * characters.
  12412. */
  12413. function keyCommandTransposeCharacters(editorState) {
  12414. var selection = editorState.getSelection();
  12415. if (!selection.isCollapsed()) {
  12416. return editorState;
  12417. }
  12418. var offset = selection.getAnchorOffset();
  12419. if (offset === 0) {
  12420. return editorState;
  12421. }
  12422. var blockKey = selection.getAnchorKey();
  12423. var content = editorState.getCurrentContent();
  12424. var block = content.getBlockForKey(blockKey);
  12425. var length = block.getLength();
  12426. // Nothing to transpose if there aren't two characters.
  12427. if (length <= 1) {
  12428. return editorState;
  12429. }
  12430. var removalRange;
  12431. var finalSelection;
  12432. if (offset === length) {
  12433. // The cursor is at the end of the block. Swap the last two characters.
  12434. removalRange = selection.set('anchorOffset', offset - 1);
  12435. finalSelection = selection;
  12436. } else {
  12437. removalRange = selection.set('focusOffset', offset + 1);
  12438. finalSelection = removalRange.set('anchorOffset', offset + 1);
  12439. }
  12440. // Extract the character to move as a fragment. This preserves its
  12441. // styling and entity, if any.
  12442. var movedFragment = getContentStateFragment_1(content, removalRange);
  12443. var afterRemoval = DraftModifier_1.removeRange(content, removalRange, 'backward');
  12444. // After the removal, the insertion target is one character back.
  12445. var selectionAfter = afterRemoval.getSelectionAfter();
  12446. var targetOffset = selectionAfter.getAnchorOffset() - 1;
  12447. var targetRange = selectionAfter.merge({
  12448. anchorOffset: targetOffset,
  12449. focusOffset: targetOffset
  12450. });
  12451. var afterInsert = DraftModifier_1.replaceWithFragment(afterRemoval, targetRange, movedFragment);
  12452. var newEditorState = EditorState_1.push(editorState, afterInsert, 'insert-fragment');
  12453. return EditorState_1.acceptSelection(newEditorState, finalSelection);
  12454. }
  12455. var keyCommandTransposeCharacters_1 = keyCommandTransposeCharacters;
  12456. function keyCommandUndo(e, editorState, updateFn) {
  12457. var undoneState = EditorState_1.undo(editorState);
  12458. // If the last change to occur was a spellcheck change, allow the undo
  12459. // event to fall through to the browser. This allows the browser to record
  12460. // the unwanted change, which should soon lead it to learn not to suggest
  12461. // the correction again.
  12462. if (editorState.getLastChangeType() === 'spellcheck-change') {
  12463. var nativelyRenderedContent = undoneState.getCurrentContent();
  12464. updateFn(EditorState_1.set(undoneState, { nativelyRenderedContent: nativelyRenderedContent }));
  12465. return;
  12466. }
  12467. // Otheriwse, manage the undo behavior manually.
  12468. e.preventDefault();
  12469. if (!editorState.getNativelyRenderedContent()) {
  12470. updateFn(undoneState);
  12471. return;
  12472. }
  12473. // Trigger a re-render with the current content state to ensure that the
  12474. // component tree has up-to-date props for comparison.
  12475. updateFn(EditorState_1.set(editorState, { nativelyRenderedContent: null }));
  12476. // Wait to ensure that the re-render has occurred before performing
  12477. // the undo action.
  12478. setTimeout(function () {
  12479. updateFn(undoneState);
  12480. }, 0);
  12481. }
  12482. var keyCommandUndo_1 = keyCommandUndo;
  12483. var isOptionKeyCommand = KeyBindingUtil_1.isOptionKeyCommand;
  12484. var isChrome$1 = UserAgent_1.isBrowser('Chrome');
  12485. /**
  12486. * Map a `DraftEditorCommand` command value to a corresponding function.
  12487. */
  12488. function onKeyCommand(command, editorState) {
  12489. switch (command) {
  12490. case 'redo':
  12491. return EditorState_1.redo(editorState);
  12492. case 'delete':
  12493. return keyCommandPlainDelete_1(editorState);
  12494. case 'delete-word':
  12495. return keyCommandDeleteWord_1(editorState);
  12496. case 'backspace':
  12497. return keyCommandPlainBackspace_1(editorState);
  12498. case 'backspace-word':
  12499. return keyCommandBackspaceWord_1(editorState);
  12500. case 'backspace-to-start-of-line':
  12501. return keyCommandBackspaceToStartOfLine_1(editorState);
  12502. case 'split-block':
  12503. return keyCommandInsertNewline_1(editorState);
  12504. case 'transpose-characters':
  12505. return keyCommandTransposeCharacters_1(editorState);
  12506. case 'move-selection-to-start-of-block':
  12507. return keyCommandMoveSelectionToStartOfBlock_1(editorState);
  12508. case 'move-selection-to-end-of-block':
  12509. return keyCommandMoveSelectionToEndOfBlock_1(editorState);
  12510. case 'secondary-cut':
  12511. return SecondaryClipboard_1.cut(editorState);
  12512. case 'secondary-paste':
  12513. return SecondaryClipboard_1.paste(editorState);
  12514. default:
  12515. return editorState;
  12516. }
  12517. }
  12518. /**
  12519. * Intercept keydown behavior to handle keys and commands manually, if desired.
  12520. *
  12521. * Keydown combinations may be mapped to `DraftCommand` values, which may
  12522. * correspond to command functions that modify the editor or its contents.
  12523. *
  12524. * See `getDefaultKeyBinding` for defaults. Alternatively, the top-level
  12525. * component may provide a custom mapping via the `keyBindingFn` prop.
  12526. */
  12527. function editOnKeyDown(editor, e) {
  12528. var keyCode = e.which;
  12529. var editorState = editor._latestEditorState;
  12530. switch (keyCode) {
  12531. case Keys.RETURN:
  12532. e.preventDefault();
  12533. // The top-level component may manually handle newline insertion. If
  12534. // no special handling is performed, fall through to command handling.
  12535. if (editor.props.handleReturn && isEventHandled_1(editor.props.handleReturn(e, editorState))) {
  12536. return;
  12537. }
  12538. break;
  12539. case Keys.ESC:
  12540. e.preventDefault();
  12541. editor.props.onEscape && editor.props.onEscape(e);
  12542. return;
  12543. case Keys.TAB:
  12544. editor.props.onTab && editor.props.onTab(e);
  12545. return;
  12546. case Keys.UP:
  12547. editor.props.onUpArrow && editor.props.onUpArrow(e);
  12548. return;
  12549. case Keys.RIGHT:
  12550. editor.props.onRightArrow && editor.props.onRightArrow(e);
  12551. return;
  12552. case Keys.DOWN:
  12553. editor.props.onDownArrow && editor.props.onDownArrow(e);
  12554. return;
  12555. case Keys.LEFT:
  12556. editor.props.onLeftArrow && editor.props.onLeftArrow(e);
  12557. return;
  12558. case Keys.SPACE:
  12559. // Handling for OSX where option + space scrolls.
  12560. if (isChrome$1 && isOptionKeyCommand(e)) {
  12561. e.preventDefault();
  12562. // Insert a nbsp into the editor.
  12563. var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), '\xA0');
  12564. editor.update(EditorState_1.push(editorState, contentState, 'insert-characters'));
  12565. return;
  12566. }
  12567. }
  12568. var command = editor.props.keyBindingFn(e);
  12569. // If no command is specified, allow keydown event to continue.
  12570. if (!command) {
  12571. return;
  12572. }
  12573. if (command === 'undo') {
  12574. // Since undo requires some special updating behavior to keep the editor
  12575. // in sync, handle it separately.
  12576. keyCommandUndo_1(e, editorState, editor.update);
  12577. return;
  12578. }
  12579. // At this point, we know that we're handling a command of some kind, so
  12580. // we don't want to insert a character following the keydown.
  12581. e.preventDefault();
  12582. // Allow components higher up the tree to handle the command first.
  12583. if (editor.props.handleKeyCommand && isEventHandled_1(editor.props.handleKeyCommand(command, editorState))) {
  12584. return;
  12585. }
  12586. var newState = onKeyCommand(command, editorState);
  12587. if (newState !== editorState) {
  12588. editor.update(newState);
  12589. }
  12590. }
  12591. var editOnKeyDown_1 = editOnKeyDown;
  12592. /**
  12593. * Copyright (c) 2013-present, Facebook, Inc.
  12594. *
  12595. * This source code is licensed under the MIT license found in the
  12596. * LICENSE file in the root directory of this source tree.
  12597. *
  12598. *
  12599. */
  12600. function _classCallCheck$e(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12601. var URI = function () {
  12602. function URI(uri) {
  12603. _classCallCheck$e(this, URI);
  12604. this._uri = uri;
  12605. }
  12606. URI.prototype.toString = function toString() {
  12607. return this._uri;
  12608. };
  12609. return URI;
  12610. }();
  12611. var URI_1 = URI;
  12612. var isOldIE = UserAgent_1.isBrowser('IE <= 9');
  12613. // Provides a dom node that will not execute scripts
  12614. // https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation.createHTMLDocument
  12615. // https://developer.mozilla.org/en-US/Add-ons/Code_snippets/HTML_to_DOM
  12616. function getSafeBodyFromHTML(html) {
  12617. var doc;
  12618. var root = null;
  12619. // Provides a safe context
  12620. if (!isOldIE && document.implementation && document.implementation.createHTMLDocument) {
  12621. doc = document.implementation.createHTMLDocument('foo');
  12622. !doc.documentElement ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing doc.documentElement') : invariant_1(false) : void 0;
  12623. doc.documentElement.innerHTML = html;
  12624. root = doc.getElementsByTagName('body')[0];
  12625. }
  12626. return root;
  12627. }
  12628. var getSafeBodyFromHTML_1 = getSafeBodyFromHTML;
  12629. 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; };
  12630. var _knownListItemDepthCl;
  12631. 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; }
  12632. var _require = immutable,
  12633. Set$1 = _require.Set;
  12634. var experimentalTreeDataSupport = DraftFeatureFlags_1.draft_tree_data_support;
  12635. var List$a = immutable.List,
  12636. OrderedSet$5 = immutable.OrderedSet;
  12637. var NBSP = '&nbsp;';
  12638. var SPACE = ' ';
  12639. // Arbitrary max indent
  12640. var MAX_DEPTH = 4;
  12641. // used for replacing characters in HTML
  12642. var REGEX_CR = new RegExp('\r', 'g');
  12643. var REGEX_LF = new RegExp('\n', 'g');
  12644. var REGEX_NBSP = new RegExp(NBSP, 'g');
  12645. var REGEX_CARRIAGE = new RegExp('&#13;?', 'g');
  12646. var REGEX_ZWS = new RegExp('&#8203;?', 'g');
  12647. // https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight
  12648. var boldValues = ['bold', 'bolder', '500', '600', '700', '800', '900'];
  12649. var notBoldValues = ['light', 'lighter', '100', '200', '300', '400'];
  12650. // Block tag flow is different because LIs do not have
  12651. // a deterministic style ;_;
  12652. var inlineTags = {
  12653. b: 'BOLD',
  12654. code: 'CODE',
  12655. del: 'STRIKETHROUGH',
  12656. em: 'ITALIC',
  12657. i: 'ITALIC',
  12658. s: 'STRIKETHROUGH',
  12659. strike: 'STRIKETHROUGH',
  12660. strong: 'BOLD',
  12661. u: 'UNDERLINE'
  12662. };
  12663. 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);
  12664. var anchorAttr = ['className', 'href', 'rel', 'target', 'title'];
  12665. var imgAttr = ['alt', 'className', 'height', 'src', 'width'];
  12666. var lastBlock = void 0;
  12667. var EMPTY_CHUNK = {
  12668. text: '',
  12669. inlines: [],
  12670. entities: [],
  12671. blocks: []
  12672. };
  12673. var EMPTY_BLOCK = {
  12674. children: List$a(),
  12675. depth: 0,
  12676. key: '',
  12677. type: ''
  12678. };
  12679. var getListBlockType = function getListBlockType(tag, lastList) {
  12680. if (tag === 'li') {
  12681. return lastList === 'ol' ? 'ordered-list-item' : 'unordered-list-item';
  12682. }
  12683. return null;
  12684. };
  12685. var getBlockMapSupportedTags = function getBlockMapSupportedTags(blockRenderMap) {
  12686. var unstyledElement = blockRenderMap.get('unstyled').element;
  12687. var tags = Set$1([]);
  12688. blockRenderMap.forEach(function (draftBlock) {
  12689. if (draftBlock.aliasedElements) {
  12690. draftBlock.aliasedElements.forEach(function (tag) {
  12691. tags = tags.add(tag);
  12692. });
  12693. }
  12694. tags = tags.add(draftBlock.element);
  12695. });
  12696. return tags.filter(function (tag) {
  12697. return tag && tag !== unstyledElement;
  12698. }).toArray().sort();
  12699. };
  12700. // custom element conversions
  12701. var getMultiMatchedType = function getMultiMatchedType(tag, lastList, multiMatchExtractor) {
  12702. for (var ii = 0; ii < multiMatchExtractor.length; ii++) {
  12703. var matchType = multiMatchExtractor[ii](tag, lastList);
  12704. if (matchType) {
  12705. return matchType;
  12706. }
  12707. }
  12708. return null;
  12709. };
  12710. var getBlockTypeForTag = function getBlockTypeForTag(tag, lastList, blockRenderMap) {
  12711. var matchedTypes = blockRenderMap.filter(function (draftBlock) {
  12712. return draftBlock.element === tag || draftBlock.wrapper === tag || draftBlock.aliasedElements && draftBlock.aliasedElements.some(function (alias) {
  12713. return alias === tag;
  12714. });
  12715. }).keySeq().toSet().toArray().sort();
  12716. // if we dont have any matched type, return unstyled
  12717. // if we have one matched type return it
  12718. // if we have multi matched types use the multi-match function to gather type
  12719. switch (matchedTypes.length) {
  12720. case 0:
  12721. return 'unstyled';
  12722. case 1:
  12723. return matchedTypes[0];
  12724. default:
  12725. return getMultiMatchedType(tag, lastList, [getListBlockType]) || 'unstyled';
  12726. }
  12727. };
  12728. var processInlineTag = function processInlineTag(tag, node, currentStyle) {
  12729. var styleToCheck = inlineTags[tag];
  12730. if (styleToCheck) {
  12731. currentStyle = currentStyle.add(styleToCheck).toOrderedSet();
  12732. } else if (node instanceof HTMLElement) {
  12733. var htmlElement = node;
  12734. currentStyle = currentStyle.withMutations(function (style) {
  12735. var fontWeight = htmlElement.style.fontWeight;
  12736. var fontStyle = htmlElement.style.fontStyle;
  12737. var textDecoration = htmlElement.style.textDecoration;
  12738. if (boldValues.indexOf(fontWeight) >= 0) {
  12739. style.add('BOLD');
  12740. } else if (notBoldValues.indexOf(fontWeight) >= 0) {
  12741. style.remove('BOLD');
  12742. }
  12743. if (fontStyle === 'italic') {
  12744. style.add('ITALIC');
  12745. } else if (fontStyle === 'normal') {
  12746. style.remove('ITALIC');
  12747. }
  12748. if (textDecoration === 'underline') {
  12749. style.add('UNDERLINE');
  12750. }
  12751. if (textDecoration === 'line-through') {
  12752. style.add('STRIKETHROUGH');
  12753. }
  12754. if (textDecoration === 'none') {
  12755. style.remove('UNDERLINE');
  12756. style.remove('STRIKETHROUGH');
  12757. }
  12758. }).toOrderedSet();
  12759. }
  12760. return currentStyle;
  12761. };
  12762. var joinChunks = function joinChunks(A, B, experimentalHasNestedBlocks) {
  12763. // Sometimes two blocks will touch in the DOM and we need to strip the
  12764. // extra delimiter to preserve niceness.
  12765. var lastInA = A.text.slice(-1);
  12766. var firstInB = B.text.slice(0, 1);
  12767. if (lastInA === '\r' && firstInB === '\r' && !experimentalHasNestedBlocks) {
  12768. A.text = A.text.slice(0, -1);
  12769. A.inlines.pop();
  12770. A.entities.pop();
  12771. A.blocks.pop();
  12772. }
  12773. // Kill whitespace after blocks
  12774. if (lastInA === '\r') {
  12775. if (B.text === SPACE || B.text === '\n') {
  12776. return A;
  12777. } else if (firstInB === SPACE || firstInB === '\n') {
  12778. B.text = B.text.slice(1);
  12779. B.inlines.shift();
  12780. B.entities.shift();
  12781. }
  12782. }
  12783. return {
  12784. text: A.text + B.text,
  12785. inlines: A.inlines.concat(B.inlines),
  12786. entities: A.entities.concat(B.entities),
  12787. blocks: A.blocks.concat(B.blocks)
  12788. };
  12789. };
  12790. /**
  12791. * Check to see if we have anything like <p> <blockquote> <h1>... to create
  12792. * block tags from. If we do, we can use those and ignore <div> tags. If we
  12793. * don't, we can treat <div> tags as meaningful (unstyled) blocks.
  12794. */
  12795. var containsSemanticBlockMarkup = function containsSemanticBlockMarkup(html, blockTags) {
  12796. return blockTags.some(function (tag) {
  12797. return html.indexOf('<' + tag) !== -1;
  12798. });
  12799. };
  12800. var hasValidLinkText = function hasValidLinkText(link) {
  12801. !(link instanceof HTMLAnchorElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Link must be an HTMLAnchorElement.') : invariant_1(false) : void 0;
  12802. var protocol = link.protocol;
  12803. return protocol === 'http:' || protocol === 'https:' || protocol === 'mailto:';
  12804. };
  12805. var getWhitespaceChunk = function getWhitespaceChunk(inEntity) {
  12806. var entities = new Array(1);
  12807. if (inEntity) {
  12808. entities[0] = inEntity;
  12809. }
  12810. return _extends$4({}, EMPTY_CHUNK, {
  12811. text: SPACE,
  12812. inlines: [OrderedSet$5()],
  12813. entities: entities
  12814. });
  12815. };
  12816. var getSoftNewlineChunk = function getSoftNewlineChunk() {
  12817. return _extends$4({}, EMPTY_CHUNK, {
  12818. text: '\n',
  12819. inlines: [OrderedSet$5()],
  12820. entities: new Array(1)
  12821. });
  12822. };
  12823. var getChunkedBlock = function getChunkedBlock() {
  12824. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  12825. return _extends$4({}, EMPTY_BLOCK, props);
  12826. };
  12827. var getBlockDividerChunk = function getBlockDividerChunk(block, depth) {
  12828. var parentKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  12829. return {
  12830. text: '\r',
  12831. inlines: [OrderedSet$5()],
  12832. entities: new Array(1),
  12833. blocks: [getChunkedBlock({
  12834. parent: parentKey,
  12835. key: generateRandomKey_1(),
  12836. type: block,
  12837. depth: Math.max(0, Math.min(MAX_DEPTH, depth))
  12838. })]
  12839. };
  12840. };
  12841. /**
  12842. * If we're pasting from one DraftEditor to another we can check to see if
  12843. * existing list item depth classes are being used and preserve this style
  12844. */
  12845. var getListItemDepth = function getListItemDepth(node) {
  12846. var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  12847. Object.keys(knownListItemDepthClasses).some(function (depthClass) {
  12848. if (node.classList.contains(depthClass)) {
  12849. depth = knownListItemDepthClasses[depthClass];
  12850. }
  12851. });
  12852. return depth;
  12853. };
  12854. var genFragment = function genFragment(entityMap, node, inlineStyle, lastList, inBlock, blockTags, depth, blockRenderMap, inEntity, parentKey) {
  12855. var lastLastBlock = lastBlock;
  12856. var nodeName = node.nodeName.toLowerCase();
  12857. var newEntityMap = entityMap;
  12858. var nextBlockType = 'unstyled';
  12859. var newBlock = false;
  12860. var inBlockType = inBlock && getBlockTypeForTag(inBlock, lastList, blockRenderMap);
  12861. var chunk = _extends$4({}, EMPTY_CHUNK);
  12862. var newChunk = null;
  12863. var blockKey = void 0;
  12864. // Base Case
  12865. if (nodeName === '#text') {
  12866. var _text = node.textContent;
  12867. var nodeTextContent = _text.trim();
  12868. // We should not create blocks for leading spaces that are
  12869. // existing around ol/ul and their children list items
  12870. if (lastList && nodeTextContent === '' && node.parentElement) {
  12871. var parentNodeName = node.parentElement.nodeName.toLowerCase();
  12872. if (parentNodeName === 'ol' || parentNodeName === 'ul') {
  12873. return { chunk: _extends$4({}, EMPTY_CHUNK), entityMap: entityMap };
  12874. }
  12875. }
  12876. if (nodeTextContent === '' && inBlock !== 'pre') {
  12877. return { chunk: getWhitespaceChunk(inEntity), entityMap: entityMap };
  12878. }
  12879. if (inBlock !== 'pre') {
  12880. // Can't use empty string because MSWord
  12881. _text = _text.replace(REGEX_LF, SPACE);
  12882. }
  12883. // save the last block so we can use it later
  12884. lastBlock = nodeName;
  12885. return {
  12886. chunk: {
  12887. text: _text,
  12888. inlines: Array(_text.length).fill(inlineStyle),
  12889. entities: Array(_text.length).fill(inEntity),
  12890. blocks: []
  12891. },
  12892. entityMap: entityMap
  12893. };
  12894. }
  12895. // save the last block so we can use it later
  12896. lastBlock = nodeName;
  12897. // BR tags
  12898. if (nodeName === 'br') {
  12899. if (lastLastBlock === 'br' && (!inBlock || inBlockType === 'unstyled')) {
  12900. return {
  12901. chunk: getBlockDividerChunk('unstyled', depth, parentKey),
  12902. entityMap: entityMap
  12903. };
  12904. }
  12905. return { chunk: getSoftNewlineChunk(), entityMap: entityMap };
  12906. }
  12907. // IMG tags
  12908. if (nodeName === 'img' && node instanceof HTMLImageElement && node.attributes.getNamedItem('src') && node.attributes.getNamedItem('src').value) {
  12909. var image = node;
  12910. var entityConfig = {};
  12911. imgAttr.forEach(function (attr) {
  12912. var imageAttribute = image.getAttribute(attr);
  12913. if (imageAttribute) {
  12914. entityConfig[attr] = imageAttribute;
  12915. }
  12916. });
  12917. // Forcing this node to have children because otherwise no entity will be
  12918. // created for this node.
  12919. // The child text node cannot just have a space or return as content -
  12920. // we strip those out.
  12921. // See https://github.com/facebook/draft-js/issues/231 for some context.
  12922. node.textContent = '\uD83D\uDCF7';
  12923. // TODO: update this when we remove DraftEntity entirely
  12924. inEntity = DraftEntity_1.__create('IMAGE', 'MUTABLE', entityConfig || {});
  12925. }
  12926. // Inline tags
  12927. inlineStyle = processInlineTag(nodeName, node, inlineStyle);
  12928. // Handle lists
  12929. if (nodeName === 'ul' || nodeName === 'ol') {
  12930. if (lastList) {
  12931. depth += 1;
  12932. }
  12933. lastList = nodeName;
  12934. }
  12935. if ( nodeName === 'li' && node instanceof HTMLElement) {
  12936. depth = getListItemDepth(node, depth);
  12937. }
  12938. var blockType = getBlockTypeForTag(nodeName, lastList, blockRenderMap);
  12939. var inListBlock = lastList && inBlock === 'li' && nodeName === 'li';
  12940. var inBlockOrHasNestedBlocks = (!inBlock || experimentalTreeDataSupport) && blockTags.indexOf(nodeName) !== -1;
  12941. // Block Tags
  12942. if (inListBlock || inBlockOrHasNestedBlocks) {
  12943. chunk = getBlockDividerChunk(blockType, depth, parentKey);
  12944. blockKey = chunk.blocks[0].key;
  12945. inBlock = nodeName;
  12946. newBlock = !experimentalTreeDataSupport;
  12947. }
  12948. // this is required so that we can handle 'ul' and 'ol'
  12949. if (inListBlock) {
  12950. nextBlockType = lastList === 'ul' ? 'unordered-list-item' : 'ordered-list-item';
  12951. }
  12952. // Recurse through children
  12953. var child = node.firstChild;
  12954. if (child != null) {
  12955. nodeName = child.nodeName.toLowerCase();
  12956. }
  12957. var entityId = null;
  12958. while (child) {
  12959. if (child instanceof HTMLAnchorElement && child.href && hasValidLinkText(child)) {
  12960. (function () {
  12961. var anchor = child;
  12962. var entityConfig = {};
  12963. anchorAttr.forEach(function (attr) {
  12964. var anchorAttribute = anchor.getAttribute(attr);
  12965. if (anchorAttribute) {
  12966. entityConfig[attr] = anchorAttribute;
  12967. }
  12968. });
  12969. entityConfig.url = new URI_1(anchor.href).toString();
  12970. // TODO: update this when we remove DraftEntity completely
  12971. entityId = DraftEntity_1.__create('LINK', 'MUTABLE', entityConfig || {});
  12972. })();
  12973. } else {
  12974. entityId = undefined;
  12975. }
  12976. var _genFragment = genFragment(newEntityMap, child, inlineStyle, lastList, inBlock, blockTags, depth, blockRenderMap, entityId || inEntity, null),
  12977. generatedChunk = _genFragment.chunk,
  12978. maybeUpdatedEntityMap = _genFragment.entityMap;
  12979. newChunk = generatedChunk;
  12980. newEntityMap = maybeUpdatedEntityMap;
  12981. chunk = joinChunks(chunk, newChunk, experimentalTreeDataSupport);
  12982. var sibling = child.nextSibling;
  12983. // Put in a newline to break up blocks inside blocks
  12984. if (!parentKey && sibling && blockTags.indexOf(nodeName) >= 0 && inBlock) {
  12985. chunk = joinChunks(chunk, getSoftNewlineChunk());
  12986. }
  12987. if (sibling) {
  12988. nodeName = sibling.nodeName.toLowerCase();
  12989. }
  12990. child = sibling;
  12991. }
  12992. if (newBlock) {
  12993. chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, parentKey));
  12994. }
  12995. return { chunk: chunk, entityMap: newEntityMap };
  12996. };
  12997. var getChunkForHTML = function getChunkForHTML(html, DOMBuilder, blockRenderMap, entityMap) {
  12998. html = html.trim().replace(REGEX_CR, '').replace(REGEX_NBSP, SPACE).replace(REGEX_CARRIAGE, '').replace(REGEX_ZWS, '');
  12999. var supportedBlockTags = getBlockMapSupportedTags(blockRenderMap);
  13000. var safeBody = DOMBuilder(html);
  13001. if (!safeBody) {
  13002. return null;
  13003. }
  13004. lastBlock = null;
  13005. // Sometimes we aren't dealing with content that contains nice semantic
  13006. // tags. In this case, use divs to separate everything out into paragraphs
  13007. // and hope for the best.
  13008. var workingBlocks = containsSemanticBlockMarkup(html, supportedBlockTags) ? supportedBlockTags : ['div'];
  13009. // Start with -1 block depth to offset the fact that we are passing in a fake
  13010. // UL block to start with.
  13011. var fragment = genFragment(entityMap, safeBody, OrderedSet$5(), 'ul', null, workingBlocks, -1, blockRenderMap);
  13012. var chunk = fragment.chunk;
  13013. var newEntityMap = fragment.entityMap;
  13014. // join with previous block to prevent weirdness on paste
  13015. if (chunk.text.indexOf('\r') === 0) {
  13016. chunk = {
  13017. text: chunk.text.slice(1),
  13018. inlines: chunk.inlines.slice(1),
  13019. entities: chunk.entities.slice(1),
  13020. blocks: chunk.blocks
  13021. };
  13022. }
  13023. // Kill block delimiter at the end
  13024. if (chunk.text.slice(-1) === '\r') {
  13025. chunk.text = chunk.text.slice(0, -1);
  13026. chunk.inlines = chunk.inlines.slice(0, -1);
  13027. chunk.entities = chunk.entities.slice(0, -1);
  13028. chunk.blocks.pop();
  13029. }
  13030. // If we saw no block tags, put an unstyled one in
  13031. if (chunk.blocks.length === 0) {
  13032. chunk.blocks.push(_extends$4({}, EMPTY_CHUNK, {
  13033. type: 'unstyled',
  13034. depth: 0
  13035. }));
  13036. }
  13037. // Sometimes we start with text that isn't in a block, which is then
  13038. // followed by blocks. Need to fix up the blocks to add in
  13039. // an unstyled block for this content
  13040. if (chunk.text.split('\r').length === chunk.blocks.length + 1) {
  13041. chunk.blocks.unshift({ type: 'unstyled', depth: 0 });
  13042. }
  13043. return { chunk: chunk, entityMap: newEntityMap };
  13044. };
  13045. var convertChunkToContentBlocks = function convertChunkToContentBlocks(chunk) {
  13046. if (!chunk || !chunk.text || !Array.isArray(chunk.blocks)) {
  13047. return null;
  13048. }
  13049. var initialState = {
  13050. cacheRef: {},
  13051. contentBlocks: []
  13052. };
  13053. var start = 0;
  13054. var rawBlocks = chunk.blocks,
  13055. rawInlines = chunk.inlines,
  13056. rawEntities = chunk.entities;
  13057. var BlockNodeRecord = ContentBlock_1;
  13058. return chunk.text.split('\r').reduce(function (acc, textBlock, index) {
  13059. // Make absolutely certain that our text is acceptable.
  13060. textBlock = sanitizeDraftText_1(textBlock);
  13061. var block = rawBlocks[index];
  13062. var end = start + textBlock.length;
  13063. var inlines = rawInlines.slice(start, end);
  13064. var entities = rawEntities.slice(start, end);
  13065. var characterList = List$a(inlines.map(function (style, index) {
  13066. var data = { style: style, entity: null };
  13067. if (entities[index]) {
  13068. data.entity = entities[index];
  13069. }
  13070. return CharacterMetadata_1.create(data);
  13071. }));
  13072. start = end + 1;
  13073. var depth = block.depth,
  13074. type = block.type,
  13075. parent = block.parent;
  13076. var key = block.key || generateRandomKey_1();
  13077. var parentTextNodeKey = null; // will be used to store container text nodes
  13078. // childrens add themselves to their parents since we are iterating in order
  13079. if (parent) {
  13080. var parentIndex = acc.cacheRef[parent];
  13081. var parentRecord = acc.contentBlocks[parentIndex];
  13082. // if parent has text we need to split it into a separate unstyled element
  13083. if (parentRecord.getChildKeys().isEmpty() && parentRecord.getText()) {
  13084. var parentCharacterList = parentRecord.getCharacterList();
  13085. var parentText = parentRecord.getText();
  13086. parentTextNodeKey = generateRandomKey_1();
  13087. var textNode = new ContentBlockNode_1({
  13088. key: parentTextNodeKey,
  13089. text: parentText,
  13090. characterList: parentCharacterList,
  13091. parent: parent,
  13092. nextSibling: key
  13093. });
  13094. acc.contentBlocks.push(textNode);
  13095. parentRecord = parentRecord.withMutations(function (block) {
  13096. block.set('characterList', List$a()).set('text', '').set('children', parentRecord.children.push(textNode.getKey()));
  13097. });
  13098. }
  13099. acc.contentBlocks[parentIndex] = parentRecord.set('children', parentRecord.children.push(key));
  13100. }
  13101. var blockNode = new BlockNodeRecord({
  13102. key: key,
  13103. parent: parent,
  13104. type: type,
  13105. depth: depth,
  13106. text: textBlock,
  13107. characterList: characterList,
  13108. prevSibling: parentTextNodeKey || (index === 0 || rawBlocks[index - 1].parent !== parent ? null : rawBlocks[index - 1].key),
  13109. nextSibling: index === rawBlocks.length - 1 || rawBlocks[index + 1].parent !== parent ? null : rawBlocks[index + 1].key
  13110. });
  13111. // insert node
  13112. acc.contentBlocks.push(blockNode);
  13113. // cache ref for building links
  13114. acc.cacheRef[blockNode.key] = index;
  13115. return acc;
  13116. }, initialState).contentBlocks;
  13117. };
  13118. var convertFromHTMLtoContentBlocks = function convertFromHTMLtoContentBlocks(html) {
  13119. var DOMBuilder = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getSafeBodyFromHTML_1;
  13120. var blockRenderMap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DefaultDraftBlockRenderMap_1;
  13121. // Be ABSOLUTELY SURE that the dom builder you pass here won't execute
  13122. // arbitrary code in whatever environment you're running this in. For an
  13123. // example of how we try to do this in-browser, see getSafeBodyFromHTML.
  13124. // TODO: replace DraftEntity with an OrderedMap here
  13125. var chunkData = getChunkForHTML(html, DOMBuilder, blockRenderMap, DraftEntity_1);
  13126. if (chunkData == null) {
  13127. return null;
  13128. }
  13129. var chunk = chunkData.chunk,
  13130. entityMap = chunkData.entityMap;
  13131. var contentBlocks = convertChunkToContentBlocks(chunk);
  13132. return {
  13133. contentBlocks: contentBlocks,
  13134. entityMap: entityMap
  13135. };
  13136. };
  13137. var convertFromHTMLToContentBlocks = convertFromHTMLtoContentBlocks;
  13138. var List$b = immutable.List,
  13139. Repeat$6 = immutable.Repeat;
  13140. var ContentBlockRecord$2 = ContentBlock_1;
  13141. var DraftPasteProcessor = {
  13142. processHTML: function processHTML(html, blockRenderMap) {
  13143. return convertFromHTMLToContentBlocks(html, getSafeBodyFromHTML_1, blockRenderMap);
  13144. },
  13145. processText: function processText(textBlocks, character, type) {
  13146. return textBlocks.reduce(function (acc, textLine, index) {
  13147. textLine = sanitizeDraftText_1(textLine);
  13148. var key = generateRandomKey_1();
  13149. var blockNodeConfig = {
  13150. key: key,
  13151. type: type,
  13152. text: textLine,
  13153. characterList: List$b(Repeat$6(character, textLine.length))
  13154. };
  13155. acc.push(new ContentBlockRecord$2(blockNodeConfig));
  13156. return acc;
  13157. }, []);
  13158. }
  13159. };
  13160. var DraftPasteProcessor_1 = DraftPasteProcessor;
  13161. /**
  13162. * Copyright (c) 2013-present, Facebook, Inc.
  13163. * All rights reserved.
  13164. *
  13165. * This source code is licensed under the BSD-style license found in the
  13166. * LICENSE file in the root directory of this source tree. An additional grant
  13167. * of patent rights can be found in the PATENTS file in the same directory.
  13168. *
  13169. * @providesModule adjustBlockDepthForContentState
  13170. * @format
  13171. *
  13172. */
  13173. function adjustBlockDepthForContentState(contentState, selectionState, adjustment, maxDepth) {
  13174. var startKey = selectionState.getStartKey();
  13175. var endKey = selectionState.getEndKey();
  13176. var blockMap = contentState.getBlockMap();
  13177. var blocks = blockMap.toSeq().skipUntil(function (_, k) {
  13178. return k === startKey;
  13179. }).takeUntil(function (_, k) {
  13180. return k === endKey;
  13181. }).concat([[endKey, blockMap.get(endKey)]]).map(function (block) {
  13182. var depth = block.getDepth() + adjustment;
  13183. depth = Math.max(0, Math.min(depth, maxDepth));
  13184. return block.set('depth', depth);
  13185. });
  13186. blockMap = blockMap.merge(blocks);
  13187. return contentState.merge({
  13188. blockMap: blockMap,
  13189. selectionBefore: selectionState,
  13190. selectionAfter: selectionState
  13191. });
  13192. }
  13193. var adjustBlockDepthForContentState_1 = adjustBlockDepthForContentState;
  13194. var RichTextEditorUtil = {
  13195. currentBlockContainsLink: function currentBlockContainsLink(editorState) {
  13196. var selection = editorState.getSelection();
  13197. var contentState = editorState.getCurrentContent();
  13198. var entityMap = contentState.getEntityMap();
  13199. return contentState.getBlockForKey(selection.getAnchorKey()).getCharacterList().slice(selection.getStartOffset(), selection.getEndOffset()).some(function (v) {
  13200. var entity = v.getEntity();
  13201. return !!entity && entityMap.__get(entity).getType() === 'LINK';
  13202. });
  13203. },
  13204. getCurrentBlockType: function getCurrentBlockType(editorState) {
  13205. var selection = editorState.getSelection();
  13206. return editorState.getCurrentContent().getBlockForKey(selection.getStartKey()).getType();
  13207. },
  13208. getDataObjectForLinkURL: function getDataObjectForLinkURL(uri) {
  13209. return { url: uri.toString() };
  13210. },
  13211. handleKeyCommand: function handleKeyCommand(editorState, command) {
  13212. switch (command) {
  13213. case 'bold':
  13214. return RichTextEditorUtil.toggleInlineStyle(editorState, 'BOLD');
  13215. case 'italic':
  13216. return RichTextEditorUtil.toggleInlineStyle(editorState, 'ITALIC');
  13217. case 'underline':
  13218. return RichTextEditorUtil.toggleInlineStyle(editorState, 'UNDERLINE');
  13219. case 'code':
  13220. return RichTextEditorUtil.toggleCode(editorState);
  13221. case 'backspace':
  13222. case 'backspace-word':
  13223. case 'backspace-to-start-of-line':
  13224. return RichTextEditorUtil.onBackspace(editorState);
  13225. case 'delete':
  13226. case 'delete-word':
  13227. case 'delete-to-end-of-block':
  13228. return RichTextEditorUtil.onDelete(editorState);
  13229. default:
  13230. // they may have custom editor commands; ignore those
  13231. return null;
  13232. }
  13233. },
  13234. insertSoftNewline: function insertSoftNewline(editorState) {
  13235. var contentState = DraftModifier_1.insertText(editorState.getCurrentContent(), editorState.getSelection(), '\n', editorState.getCurrentInlineStyle(), null);
  13236. var newEditorState = EditorState_1.push(editorState, contentState, 'insert-characters');
  13237. return EditorState_1.forceSelection(newEditorState, contentState.getSelectionAfter());
  13238. },
  13239. /**
  13240. * For collapsed selections at the start of styled blocks, backspace should
  13241. * just remove the existing style.
  13242. */
  13243. onBackspace: function onBackspace(editorState) {
  13244. var selection = editorState.getSelection();
  13245. if (!selection.isCollapsed() || selection.getAnchorOffset() || selection.getFocusOffset()) {
  13246. return null;
  13247. }
  13248. // First, try to remove a preceding atomic block.
  13249. var content = editorState.getCurrentContent();
  13250. var startKey = selection.getStartKey();
  13251. var blockBefore = content.getBlockBefore(startKey);
  13252. if (blockBefore && blockBefore.getType() === 'atomic') {
  13253. var blockMap = content.getBlockMap()['delete'](blockBefore.getKey());
  13254. var withoutAtomicBlock = content.merge({
  13255. blockMap: blockMap,
  13256. selectionAfter: selection
  13257. });
  13258. if (withoutAtomicBlock !== content) {
  13259. return EditorState_1.push(editorState, withoutAtomicBlock, 'remove-range');
  13260. }
  13261. }
  13262. // If that doesn't succeed, try to remove the current block style.
  13263. var withoutBlockStyle = RichTextEditorUtil.tryToRemoveBlockStyle(editorState);
  13264. if (withoutBlockStyle) {
  13265. return EditorState_1.push(editorState, withoutBlockStyle, 'change-block-type');
  13266. }
  13267. return null;
  13268. },
  13269. onDelete: function onDelete(editorState) {
  13270. var selection = editorState.getSelection();
  13271. if (!selection.isCollapsed()) {
  13272. return null;
  13273. }
  13274. var content = editorState.getCurrentContent();
  13275. var startKey = selection.getStartKey();
  13276. var block = content.getBlockForKey(startKey);
  13277. var length = block.getLength();
  13278. // The cursor is somewhere within the text. Behave normally.
  13279. if (selection.getStartOffset() < length) {
  13280. return null;
  13281. }
  13282. var blockAfter = content.getBlockAfter(startKey);
  13283. if (!blockAfter || blockAfter.getType() !== 'atomic') {
  13284. return null;
  13285. }
  13286. var atomicBlockTarget = selection.merge({
  13287. focusKey: blockAfter.getKey(),
  13288. focusOffset: blockAfter.getLength()
  13289. });
  13290. var withoutAtomicBlock = DraftModifier_1.removeRange(content, atomicBlockTarget, 'forward');
  13291. if (withoutAtomicBlock !== content) {
  13292. return EditorState_1.push(editorState, withoutAtomicBlock, 'remove-range');
  13293. }
  13294. return null;
  13295. },
  13296. onTab: function onTab(event, editorState, maxDepth) {
  13297. var selection = editorState.getSelection();
  13298. var key = selection.getAnchorKey();
  13299. if (key !== selection.getFocusKey()) {
  13300. return editorState;
  13301. }
  13302. var content = editorState.getCurrentContent();
  13303. var block = content.getBlockForKey(key);
  13304. var type = block.getType();
  13305. if (type !== 'unordered-list-item' && type !== 'ordered-list-item') {
  13306. return editorState;
  13307. }
  13308. event.preventDefault();
  13309. // Only allow indenting one level beyond the block above, and only if
  13310. // the block above is a list item as well.
  13311. var blockAbove = content.getBlockBefore(key);
  13312. if (!blockAbove) {
  13313. return editorState;
  13314. }
  13315. var typeAbove = blockAbove.getType();
  13316. if (typeAbove !== 'unordered-list-item' && typeAbove !== 'ordered-list-item') {
  13317. return editorState;
  13318. }
  13319. var depth = block.getDepth();
  13320. if (!event.shiftKey && depth === maxDepth) {
  13321. return editorState;
  13322. }
  13323. maxDepth = Math.min(blockAbove.getDepth() + 1, maxDepth);
  13324. var withAdjustment = adjustBlockDepthForContentState_1(content, selection, event.shiftKey ? -1 : 1, maxDepth);
  13325. return EditorState_1.push(editorState, withAdjustment, 'adjust-depth');
  13326. },
  13327. toggleBlockType: function toggleBlockType(editorState, blockType) {
  13328. var selection = editorState.getSelection();
  13329. var startKey = selection.getStartKey();
  13330. var endKey = selection.getEndKey();
  13331. var content = editorState.getCurrentContent();
  13332. var target = selection;
  13333. // Triple-click can lead to a selection that includes offset 0 of the
  13334. // following block. The `SelectionState` for this case is accurate, but
  13335. // we should avoid toggling block type for the trailing block because it
  13336. // is a confusing interaction.
  13337. if (startKey !== endKey && selection.getEndOffset() === 0) {
  13338. var blockBefore = nullthrows_1(content.getBlockBefore(endKey));
  13339. endKey = blockBefore.getKey();
  13340. target = target.merge({
  13341. anchorKey: startKey,
  13342. anchorOffset: selection.getStartOffset(),
  13343. focusKey: endKey,
  13344. focusOffset: blockBefore.getLength(),
  13345. isBackward: false
  13346. });
  13347. }
  13348. var hasAtomicBlock = content.getBlockMap().skipWhile(function (_, k) {
  13349. return k !== startKey;
  13350. }).reverse().skipWhile(function (_, k) {
  13351. return k !== endKey;
  13352. }).some(function (v) {
  13353. return v.getType() === 'atomic';
  13354. });
  13355. if (hasAtomicBlock) {
  13356. return editorState;
  13357. }
  13358. var typeToSet = content.getBlockForKey(startKey).getType() === blockType ? 'unstyled' : blockType;
  13359. return EditorState_1.push(editorState, DraftModifier_1.setBlockType(content, target, typeToSet), 'change-block-type');
  13360. },
  13361. toggleCode: function toggleCode(editorState) {
  13362. var selection = editorState.getSelection();
  13363. var anchorKey = selection.getAnchorKey();
  13364. var focusKey = selection.getFocusKey();
  13365. if (selection.isCollapsed() || anchorKey !== focusKey) {
  13366. return RichTextEditorUtil.toggleBlockType(editorState, 'code-block');
  13367. }
  13368. return RichTextEditorUtil.toggleInlineStyle(editorState, 'CODE');
  13369. },
  13370. /**
  13371. * Toggle the specified inline style for the selection. If the
  13372. * user's selection is collapsed, apply or remove the style for the
  13373. * internal state. If it is not collapsed, apply the change directly
  13374. * to the document state.
  13375. */
  13376. toggleInlineStyle: function toggleInlineStyle(editorState, inlineStyle) {
  13377. var selection = editorState.getSelection();
  13378. var currentStyle = editorState.getCurrentInlineStyle();
  13379. // If the selection is collapsed, toggle the specified style on or off and
  13380. // set the result as the new inline style override. This will then be
  13381. // used as the inline style for the next character to be inserted.
  13382. if (selection.isCollapsed()) {
  13383. return EditorState_1.setInlineStyleOverride(editorState, currentStyle.has(inlineStyle) ? currentStyle.remove(inlineStyle) : currentStyle.add(inlineStyle));
  13384. }
  13385. // If characters are selected, immediately apply or remove the
  13386. // inline style on the document state itself.
  13387. var content = editorState.getCurrentContent();
  13388. var newContent;
  13389. // If the style is already present for the selection range, remove it.
  13390. // Otherwise, apply it.
  13391. if (currentStyle.has(inlineStyle)) {
  13392. newContent = DraftModifier_1.removeInlineStyle(content, selection, inlineStyle);
  13393. } else {
  13394. newContent = DraftModifier_1.applyInlineStyle(content, selection, inlineStyle);
  13395. }
  13396. return EditorState_1.push(editorState, newContent, 'change-inline-style');
  13397. },
  13398. toggleLink: function toggleLink(editorState, targetSelection, entityKey) {
  13399. var withoutLink = DraftModifier_1.applyEntity(editorState.getCurrentContent(), targetSelection, entityKey);
  13400. return EditorState_1.push(editorState, withoutLink, 'apply-entity');
  13401. },
  13402. /**
  13403. * When a collapsed cursor is at the start of the first styled block, or
  13404. * an empty styled block, changes block to 'unstyled'. Returns null if
  13405. * block or selection does not meet that criteria.
  13406. */
  13407. tryToRemoveBlockStyle: function tryToRemoveBlockStyle(editorState) {
  13408. var selection = editorState.getSelection();
  13409. var offset = selection.getAnchorOffset();
  13410. if (selection.isCollapsed() && offset === 0) {
  13411. var key = selection.getAnchorKey();
  13412. var content = editorState.getCurrentContent();
  13413. var block = content.getBlockForKey(key);
  13414. var firstBlock = content.getFirstBlock();
  13415. if (block.getLength() > 0 && block !== firstBlock) {
  13416. return null;
  13417. }
  13418. var type = block.getType();
  13419. var blockBefore = content.getBlockBefore(key);
  13420. if (type === 'code-block' && blockBefore && blockBefore.getType() === 'code-block' && blockBefore.getLength() !== 0) {
  13421. return null;
  13422. }
  13423. if (type !== 'unstyled') {
  13424. return DraftModifier_1.setBlockType(content, selection, 'unstyled');
  13425. }
  13426. }
  13427. return null;
  13428. }
  13429. };
  13430. var RichTextEditorUtil_1 = RichTextEditorUtil;
  13431. /**
  13432. * Copyright (c) 2013-present, Facebook, Inc.
  13433. * All rights reserved.
  13434. *
  13435. * This source code is licensed under the BSD-style license found in the
  13436. * LICENSE file in the root directory of this source tree. An additional grant
  13437. * of patent rights can be found in the PATENTS file in the same directory.
  13438. *
  13439. * @providesModule splitTextIntoTextBlocks
  13440. * @format
  13441. *
  13442. */
  13443. var NEWLINE_REGEX = /\r\n?|\n/g;
  13444. function splitTextIntoTextBlocks(text) {
  13445. return text.split(NEWLINE_REGEX);
  13446. }
  13447. var splitTextIntoTextBlocks_1 = splitTextIntoTextBlocks;
  13448. /**
  13449. * Paste content.
  13450. */
  13451. function editOnPaste(editor, e) {
  13452. e.preventDefault();
  13453. var data = new DataTransfer_1(e.clipboardData);
  13454. // Get files, unless this is likely to be a string the user wants inline.
  13455. if (!data.isRichText()) {
  13456. var files = data.getFiles();
  13457. var defaultFileText = data.getText();
  13458. if (files.length > 0) {
  13459. // Allow customized paste handling for images, etc. Otherwise, fall
  13460. // through to insert text contents into the editor.
  13461. if (editor.props.handlePastedFiles && isEventHandled_1(editor.props.handlePastedFiles(files))) {
  13462. return;
  13463. }
  13464. getTextContentFromFiles_1(files, function ( /*string*/fileText) {
  13465. fileText = fileText || defaultFileText;
  13466. if (!fileText) {
  13467. return;
  13468. }
  13469. var editorState = editor._latestEditorState;
  13470. var blocks = splitTextIntoTextBlocks_1(fileText);
  13471. var character = CharacterMetadata_1.create({
  13472. style: editorState.getCurrentInlineStyle(),
  13473. entity: getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())
  13474. });
  13475. var currentBlockType = RichTextEditorUtil_1.getCurrentBlockType(editorState);
  13476. var text = DraftPasteProcessor_1.processText(blocks, character, currentBlockType);
  13477. var fragment = BlockMapBuilder_1.createFromArray(text);
  13478. var withInsertedText = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), fragment);
  13479. editor.update(EditorState_1.push(editorState, withInsertedText, 'insert-fragment'));
  13480. });
  13481. return;
  13482. }
  13483. }
  13484. var textBlocks = [];
  13485. var text = data.getText();
  13486. var html = data.getHTML();
  13487. var editorState = editor._latestEditorState;
  13488. if (editor.props.handlePastedText && isEventHandled_1(editor.props.handlePastedText(text, html, editorState))) {
  13489. return;
  13490. }
  13491. if (text) {
  13492. textBlocks = splitTextIntoTextBlocks_1(text);
  13493. }
  13494. if (!editor.props.stripPastedStyles) {
  13495. // If the text from the paste event is rich content that matches what we
  13496. // already have on the internal clipboard, assume that we should just use
  13497. // the clipboard fragment for the paste. This will allow us to preserve
  13498. // styling and entities, if any are present. Note that newlines are
  13499. // stripped during comparison -- this is because copy/paste within the
  13500. // editor in Firefox and IE will not include empty lines. The resulting
  13501. // paste will preserve the newlines correctly.
  13502. var internalClipboard = editor.getClipboard();
  13503. if (data.isRichText() && internalClipboard) {
  13504. if (
  13505. // If the editorKey is present in the pasted HTML, it should be safe to
  13506. // assume this is an internal paste.
  13507. html.indexOf(editor.getEditorKey()) !== -1 ||
  13508. // The copy may have been made within a single block, in which case the
  13509. // editor key won't be part of the paste. In this case, just check
  13510. // whether the pasted text matches the internal clipboard.
  13511. textBlocks.length === 1 && internalClipboard.size === 1 && internalClipboard.first().getText() === text) {
  13512. editor.update(insertFragment$1(editor._latestEditorState, internalClipboard));
  13513. return;
  13514. }
  13515. } else if (internalClipboard && data.types.includes('com.apple.webarchive') && !data.types.includes('text/html') && areTextBlocksAndClipboardEqual(textBlocks, internalClipboard)) {
  13516. // Safari does not properly store text/html in some cases.
  13517. // Use the internalClipboard if present and equal to what is on
  13518. // the clipboard. See https://bugs.webkit.org/show_bug.cgi?id=19893.
  13519. editor.update(insertFragment$1(editor._latestEditorState, internalClipboard));
  13520. return;
  13521. }
  13522. // If there is html paste data, try to parse that.
  13523. if (html) {
  13524. var htmlFragment = DraftPasteProcessor_1.processHTML(html, editor.props.blockRenderMap);
  13525. if (htmlFragment) {
  13526. var contentBlocks = htmlFragment.contentBlocks,
  13527. entityMap = htmlFragment.entityMap;
  13528. if (contentBlocks) {
  13529. var htmlMap = BlockMapBuilder_1.createFromArray(contentBlocks);
  13530. editor.update(insertFragment$1(editor._latestEditorState, htmlMap, entityMap));
  13531. return;
  13532. }
  13533. }
  13534. }
  13535. // Otherwise, create a new fragment from our pasted text. Also
  13536. // empty the internal clipboard, since it's no longer valid.
  13537. editor.setClipboard(null);
  13538. }
  13539. if (textBlocks.length) {
  13540. var character = CharacterMetadata_1.create({
  13541. style: editorState.getCurrentInlineStyle(),
  13542. entity: getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())
  13543. });
  13544. var currentBlockType = RichTextEditorUtil_1.getCurrentBlockType(editorState);
  13545. var textFragment = DraftPasteProcessor_1.processText(textBlocks, character, currentBlockType);
  13546. var textMap = BlockMapBuilder_1.createFromArray(textFragment);
  13547. editor.update(insertFragment$1(editor._latestEditorState, textMap));
  13548. }
  13549. }
  13550. function insertFragment$1(editorState, fragment, entityMap) {
  13551. var newContent = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), fragment);
  13552. // TODO: merge the entity map once we stop using DraftEntity
  13553. // like this:
  13554. // const mergedEntityMap = newContent.getEntityMap().merge(entityMap);
  13555. return EditorState_1.push(editorState, newContent.set('entityMap', entityMap), 'insert-fragment');
  13556. }
  13557. function areTextBlocksAndClipboardEqual(textBlocks, blockMap) {
  13558. return textBlocks.length === blockMap.size && blockMap.valueSeq().every(function (block, ii) {
  13559. return block.getText() === textBlocks[ii];
  13560. });
  13561. }
  13562. var editOnPaste_1 = editOnPaste;
  13563. /**
  13564. * Convert the current selection range to an anchor/focus pair of offset keys
  13565. * and values that can be interpreted by components.
  13566. */
  13567. function getDraftEditorSelection(editorState, root) {
  13568. var selection = commonjsGlobal.getSelection();
  13569. // No active selection.
  13570. if (selection.rangeCount === 0) {
  13571. return {
  13572. selectionState: editorState.getSelection().set('hasFocus', false),
  13573. needsRecovery: false
  13574. };
  13575. }
  13576. return getDraftEditorSelectionWithNodes_1(editorState, root, selection.anchorNode, selection.anchorOffset, selection.focusNode, selection.focusOffset);
  13577. }
  13578. var getDraftEditorSelection_1 = getDraftEditorSelection;
  13579. function editOnSelect(editor) {
  13580. if (editor._blockSelectEvents || editor._latestEditorState !== editor.props.editorState) {
  13581. return;
  13582. }
  13583. var editorState = editor.props.editorState;
  13584. var editorNode = reactDom.findDOMNode(editor.editorContainer);
  13585. !editorNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing editorNode') : invariant_1(false) : void 0;
  13586. !(editorNode.firstChild instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode.firstChild is not an HTMLElement') : invariant_1(false) : void 0;
  13587. var documentSelection = getDraftEditorSelection_1(editorState, editorNode.firstChild);
  13588. var updatedSelectionState = documentSelection.selectionState;
  13589. if (updatedSelectionState !== editorState.getSelection()) {
  13590. if (documentSelection.needsRecovery) {
  13591. editorState = EditorState_1.forceSelection(editorState, updatedSelectionState);
  13592. } else {
  13593. editorState = EditorState_1.acceptSelection(editorState, updatedSelectionState);
  13594. }
  13595. editor.update(editorState);
  13596. }
  13597. }
  13598. var editOnSelect_1 = editOnSelect;
  13599. var DraftEditorEditHandler = {
  13600. onBeforeInput: editOnBeforeInput_1,
  13601. onBlur: editOnBlur_1,
  13602. onCompositionStart: editOnCompositionStart_1,
  13603. onCopy: editOnCopy_1,
  13604. onCut: editOnCut_1,
  13605. onDragOver: editOnDragOver_1,
  13606. onDragStart: editOnDragStart_1,
  13607. onFocus: editOnFocus_1,
  13608. onInput: editOnInput_1,
  13609. onKeyDown: editOnKeyDown_1,
  13610. onPaste: editOnPaste_1,
  13611. onSelect: editOnSelect_1
  13612. };
  13613. var DraftEditorEditHandler_1 = DraftEditorEditHandler;
  13614. function _classCallCheck$f(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13615. 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; }
  13616. 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; }
  13617. /**
  13618. * This component is responsible for rendering placeholder text for the
  13619. * `DraftEditor` component.
  13620. *
  13621. * Override placeholder style via CSS.
  13622. */
  13623. var DraftEditorPlaceholder = function (_React$Component) {
  13624. _inherits$a(DraftEditorPlaceholder, _React$Component);
  13625. function DraftEditorPlaceholder() {
  13626. _classCallCheck$f(this, DraftEditorPlaceholder);
  13627. return _possibleConstructorReturn$a(this, _React$Component.apply(this, arguments));
  13628. }
  13629. DraftEditorPlaceholder.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  13630. return this.props.text !== nextProps.text || this.props.editorState.getSelection().getHasFocus() !== nextProps.editorState.getSelection().getHasFocus();
  13631. };
  13632. DraftEditorPlaceholder.prototype.render = function render() {
  13633. var hasFocus = this.props.editorState.getSelection().getHasFocus();
  13634. var className = cx_1({
  13635. 'public/DraftEditorPlaceholder/root': true,
  13636. 'public/DraftEditorPlaceholder/hasFocus': hasFocus
  13637. });
  13638. var contentStyle = {
  13639. whiteSpace: 'pre-wrap'
  13640. };
  13641. return React.createElement(
  13642. 'div',
  13643. { className: className },
  13644. React.createElement(
  13645. 'div',
  13646. {
  13647. className: cx_1('public/DraftEditorPlaceholder/inner'),
  13648. id: this.props.accessibilityID,
  13649. style: contentStyle },
  13650. this.props.text
  13651. )
  13652. );
  13653. };
  13654. return DraftEditorPlaceholder;
  13655. }(React.Component);
  13656. var DraftEditorPlaceholder_react = DraftEditorPlaceholder;
  13657. var isOSX$1 = UserAgent_1.isPlatform('Mac OS X');
  13658. var isWindows = UserAgent_1.isPlatform('Windows');
  13659. // Firefox on OSX had a bug resulting in navigation instead of cursor movement.
  13660. // This bug was fixed in Firefox 29. Feature detection is virtually impossible
  13661. // so we just check the version number. See #342765.
  13662. var shouldFixFirefoxMovement = isOSX$1 && UserAgent_1.isBrowser('Firefox < 29');
  13663. var hasCommandModifier = KeyBindingUtil_1.hasCommandModifier,
  13664. isCtrlKeyCommand = KeyBindingUtil_1.isCtrlKeyCommand;
  13665. function shouldRemoveWord(e) {
  13666. return isOSX$1 && e.altKey || isCtrlKeyCommand(e);
  13667. }
  13668. /**
  13669. * Get the appropriate undo/redo command for a Z key command.
  13670. */
  13671. function getZCommand(e) {
  13672. if (!hasCommandModifier(e)) {
  13673. return null;
  13674. }
  13675. return e.shiftKey ? 'redo' : 'undo';
  13676. }
  13677. function getDeleteCommand(e) {
  13678. // Allow default "cut" behavior for Windows on Shift + Delete.
  13679. if (isWindows && e.shiftKey) {
  13680. return null;
  13681. }
  13682. return shouldRemoveWord(e) ? 'delete-word' : 'delete';
  13683. }
  13684. function getBackspaceCommand(e) {
  13685. if (hasCommandModifier(e) && isOSX$1) {
  13686. return 'backspace-to-start-of-line';
  13687. }
  13688. return shouldRemoveWord(e) ? 'backspace-word' : 'backspace';
  13689. }
  13690. /**
  13691. * Retrieve a bound key command for the given event.
  13692. */
  13693. function getDefaultKeyBinding(e) {
  13694. switch (e.keyCode) {
  13695. case 66:
  13696. // B
  13697. return hasCommandModifier(e) ? 'bold' : null;
  13698. case 68:
  13699. // D
  13700. return isCtrlKeyCommand(e) ? 'delete' : null;
  13701. case 72:
  13702. // H
  13703. return isCtrlKeyCommand(e) ? 'backspace' : null;
  13704. case 73:
  13705. // I
  13706. return hasCommandModifier(e) ? 'italic' : null;
  13707. case 74:
  13708. // J
  13709. return hasCommandModifier(e) ? 'code' : null;
  13710. case 75:
  13711. // K
  13712. return !isWindows && isCtrlKeyCommand(e) ? 'secondary-cut' : null;
  13713. case 77:
  13714. // M
  13715. return isCtrlKeyCommand(e) ? 'split-block' : null;
  13716. case 79:
  13717. // O
  13718. return isCtrlKeyCommand(e) ? 'split-block' : null;
  13719. case 84:
  13720. // T
  13721. return isOSX$1 && isCtrlKeyCommand(e) ? 'transpose-characters' : null;
  13722. case 85:
  13723. // U
  13724. return hasCommandModifier(e) ? 'underline' : null;
  13725. case 87:
  13726. // W
  13727. return isOSX$1 && isCtrlKeyCommand(e) ? 'backspace-word' : null;
  13728. case 89:
  13729. // Y
  13730. if (isCtrlKeyCommand(e)) {
  13731. return isWindows ? 'redo' : 'secondary-paste';
  13732. }
  13733. return null;
  13734. case 90:
  13735. // Z
  13736. return getZCommand(e) || null;
  13737. case Keys.RETURN:
  13738. return 'split-block';
  13739. case Keys.DELETE:
  13740. return getDeleteCommand(e);
  13741. case Keys.BACKSPACE:
  13742. return getBackspaceCommand(e);
  13743. // LEFT/RIGHT handlers serve as a workaround for a Firefox bug.
  13744. case Keys.LEFT:
  13745. return shouldFixFirefoxMovement && hasCommandModifier(e) ? 'move-selection-to-start-of-block' : null;
  13746. case Keys.RIGHT:
  13747. return shouldFixFirefoxMovement && hasCommandModifier(e) ? 'move-selection-to-end-of-block' : null;
  13748. default:
  13749. return null;
  13750. }
  13751. }
  13752. var getDefaultKeyBinding_1 = getDefaultKeyBinding;
  13753. 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; };
  13754. function _classCallCheck$g(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13755. 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; }
  13756. 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; }
  13757. var isIE = UserAgent_1.isBrowser('IE');
  13758. // IE does not support the `input` event on contentEditable, so we can't
  13759. // observe spellcheck behavior.
  13760. var allowSpellCheck = !isIE;
  13761. // Define a set of handler objects to correspond to each possible `mode`
  13762. // of editor behavior.
  13763. var handlerMap = {
  13764. edit: DraftEditorEditHandler_1,
  13765. composite: DraftEditorCompositionHandler_1,
  13766. drag: DraftEditorDragHandler_1,
  13767. cut: null,
  13768. render: null
  13769. };
  13770. /**
  13771. * `DraftEditor` is the root editor component. It composes a `contentEditable`
  13772. * div, and provides a wide variety of useful function props for managing the
  13773. * state of the editor. See `DraftEditorProps` for details.
  13774. */
  13775. var DraftEditor = function (_React$Component) {
  13776. _inherits$b(DraftEditor, _React$Component);
  13777. function DraftEditor(props) {
  13778. _classCallCheck$g(this, DraftEditor);
  13779. var _this = _possibleConstructorReturn$b(this, _React$Component.call(this, props));
  13780. _this.focus = function (scrollPosition) {
  13781. var editorState = _this.props.editorState;
  13782. var alreadyHasFocus = editorState.getSelection().getHasFocus();
  13783. var editorNode = reactDom.findDOMNode(_this.editor);
  13784. if (!editorNode) {
  13785. // once in a while people call 'focus' in a setTimeout, and the node has
  13786. // been deleted, so it can be null in that case.
  13787. return;
  13788. }
  13789. var scrollParent = Style_1.getScrollParent(editorNode);
  13790. var _ref = scrollPosition || getScrollPosition_1(scrollParent),
  13791. x = _ref.x,
  13792. y = _ref.y;
  13793. !(editorNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode is not an HTMLElement') : invariant_1(false) : void 0;
  13794. editorNode.focus();
  13795. // Restore scroll position
  13796. if (scrollParent === window) {
  13797. window.scrollTo(x, y);
  13798. } else {
  13799. Scroll_1.setTop(scrollParent, y);
  13800. }
  13801. // On Chrome and Safari, calling focus on contenteditable focuses the
  13802. // cursor at the first character. This is something you don't expect when
  13803. // you're clicking on an input element but not directly on a character.
  13804. // Put the cursor back where it was before the blur.
  13805. if (!alreadyHasFocus) {
  13806. _this.update(EditorState_1.forceSelection(editorState, editorState.getSelection()));
  13807. }
  13808. };
  13809. _this.blur = function () {
  13810. var editorNode = reactDom.findDOMNode(_this.editor);
  13811. !(editorNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode is not an HTMLElement') : invariant_1(false) : void 0;
  13812. editorNode.blur();
  13813. };
  13814. _this.setMode = function (mode) {
  13815. _this._handler = handlerMap[mode];
  13816. };
  13817. _this.exitCurrentMode = function () {
  13818. _this.setMode('edit');
  13819. };
  13820. _this.restoreEditorDOM = function (scrollPosition) {
  13821. _this.setState({ contentsKey: _this.state.contentsKey + 1 }, function () {
  13822. _this.focus(scrollPosition);
  13823. });
  13824. };
  13825. _this.setClipboard = function (clipboard) {
  13826. _this._clipboard = clipboard;
  13827. };
  13828. _this.getClipboard = function () {
  13829. return _this._clipboard;
  13830. };
  13831. _this.update = function (editorState) {
  13832. _this._latestEditorState = editorState;
  13833. _this.props.onChange(editorState);
  13834. };
  13835. _this.onDragEnter = function () {
  13836. _this._dragCount++;
  13837. };
  13838. _this.onDragLeave = function () {
  13839. _this._dragCount--;
  13840. if (_this._dragCount === 0) {
  13841. _this.exitCurrentMode();
  13842. }
  13843. };
  13844. _this._blockSelectEvents = false;
  13845. _this._clipboard = null;
  13846. _this._handler = null;
  13847. _this._dragCount = 0;
  13848. _this._editorKey = props.editorKey || generateRandomKey_1();
  13849. _this._placeholderAccessibilityID = 'placeholder-' + _this._editorKey;
  13850. _this._latestEditorState = props.editorState;
  13851. _this._latestCommittedEditorState = props.editorState;
  13852. _this._onBeforeInput = _this._buildHandler('onBeforeInput');
  13853. _this._onBlur = _this._buildHandler('onBlur');
  13854. _this._onCharacterData = _this._buildHandler('onCharacterData');
  13855. _this._onCompositionEnd = _this._buildHandler('onCompositionEnd');
  13856. _this._onCompositionStart = _this._buildHandler('onCompositionStart');
  13857. _this._onCopy = _this._buildHandler('onCopy');
  13858. _this._onCut = _this._buildHandler('onCut');
  13859. _this._onDragEnd = _this._buildHandler('onDragEnd');
  13860. _this._onDragOver = _this._buildHandler('onDragOver');
  13861. _this._onDragStart = _this._buildHandler('onDragStart');
  13862. _this._onDrop = _this._buildHandler('onDrop');
  13863. _this._onInput = _this._buildHandler('onInput');
  13864. _this._onFocus = _this._buildHandler('onFocus');
  13865. _this._onKeyDown = _this._buildHandler('onKeyDown');
  13866. _this._onKeyPress = _this._buildHandler('onKeyPress');
  13867. _this._onKeyUp = _this._buildHandler('onKeyUp');
  13868. _this._onMouseDown = _this._buildHandler('onMouseDown');
  13869. _this._onMouseUp = _this._buildHandler('onMouseUp');
  13870. _this._onPaste = _this._buildHandler('onPaste');
  13871. _this._onSelect = _this._buildHandler('onSelect');
  13872. _this.getEditorKey = function () {
  13873. return _this._editorKey;
  13874. };
  13875. // See `restoreEditorDOM()`.
  13876. _this.state = { contentsKey: 0 };
  13877. return _this;
  13878. }
  13879. /**
  13880. * Build a method that will pass the event to the specified handler method.
  13881. * This allows us to look up the correct handler function for the current
  13882. * editor mode, if any has been specified.
  13883. */
  13884. /**
  13885. * Define proxies that can route events to the current handler.
  13886. */
  13887. DraftEditor.prototype._buildHandler = function _buildHandler(eventName) {
  13888. var _this2 = this;
  13889. return function (e) {
  13890. if (!_this2.props.readOnly) {
  13891. var method = _this2._handler && _this2._handler[eventName];
  13892. method && method(_this2, e);
  13893. }
  13894. };
  13895. };
  13896. DraftEditor.prototype._showPlaceholder = function _showPlaceholder() {
  13897. return !!this.props.placeholder && !this.props.editorState.isInCompositionMode() && !this.props.editorState.getCurrentContent().hasText();
  13898. };
  13899. DraftEditor.prototype._renderPlaceholder = function _renderPlaceholder() {
  13900. if (this._showPlaceholder()) {
  13901. var placeHolderProps = {
  13902. text: nullthrows_1(this.props.placeholder),
  13903. editorState: this.props.editorState,
  13904. textAlignment: this.props.textAlignment,
  13905. accessibilityID: this._placeholderAccessibilityID
  13906. };
  13907. return React.createElement(DraftEditorPlaceholder_react, placeHolderProps);
  13908. }
  13909. return null;
  13910. };
  13911. DraftEditor.prototype.render = function render() {
  13912. var _this3 = this;
  13913. var _props = this.props,
  13914. blockRenderMap = _props.blockRenderMap,
  13915. blockRendererFn = _props.blockRendererFn,
  13916. blockStyleFn = _props.blockStyleFn,
  13917. customStyleFn = _props.customStyleFn,
  13918. customStyleMap = _props.customStyleMap,
  13919. editorState = _props.editorState,
  13920. readOnly = _props.readOnly,
  13921. textAlignment = _props.textAlignment,
  13922. textDirectionality = _props.textDirectionality;
  13923. var rootClass = cx_1({
  13924. 'DraftEditor/root': true,
  13925. 'DraftEditor/alignLeft': textAlignment === 'left',
  13926. 'DraftEditor/alignRight': textAlignment === 'right',
  13927. 'DraftEditor/alignCenter': textAlignment === 'center'
  13928. });
  13929. var contentStyle = {
  13930. outline: 'none',
  13931. // fix parent-draggable Safari bug. #1326
  13932. userSelect: 'text',
  13933. WebkitUserSelect: 'text',
  13934. whiteSpace: 'pre-wrap',
  13935. wordWrap: 'break-word'
  13936. };
  13937. // The aria-expanded and aria-haspopup properties should only be rendered
  13938. // for a combobox.
  13939. var ariaRole = this.props.role || 'textbox';
  13940. var ariaExpanded = ariaRole === 'combobox' ? !!this.props.ariaExpanded : null;
  13941. var editorContentsProps = {
  13942. blockRenderMap: blockRenderMap,
  13943. blockRendererFn: blockRendererFn,
  13944. blockStyleFn: blockStyleFn,
  13945. customStyleMap: _extends$5({}, DefaultDraftInlineStyle, customStyleMap),
  13946. customStyleFn: customStyleFn,
  13947. editorKey: this._editorKey,
  13948. editorState: editorState,
  13949. key: 'contents' + this.state.contentsKey,
  13950. textDirectionality: textDirectionality
  13951. };
  13952. return React.createElement(
  13953. 'div',
  13954. { className: rootClass },
  13955. this._renderPlaceholder(),
  13956. React.createElement(
  13957. 'div',
  13958. {
  13959. className: cx_1('DraftEditor/editorContainer'),
  13960. ref: function ref(_ref3) {
  13961. return _this3.editorContainer = _ref3;
  13962. } },
  13963. React.createElement(
  13964. 'div',
  13965. {
  13966. 'aria-activedescendant': readOnly ? null : this.props.ariaActiveDescendantID,
  13967. 'aria-autocomplete': readOnly ? null : this.props.ariaAutoComplete,
  13968. 'aria-controls': readOnly ? null : this.props.ariaControls,
  13969. 'aria-describedby': this.props.ariaDescribedBy || this._placeholderAccessibilityID,
  13970. 'aria-expanded': readOnly ? null : ariaExpanded,
  13971. 'aria-label': this.props.ariaLabel,
  13972. 'aria-labelledby': this.props.ariaLabelledBy,
  13973. 'aria-multiline': this.props.ariaMultiline,
  13974. autoCapitalize: this.props.autoCapitalize,
  13975. autoComplete: this.props.autoComplete,
  13976. autoCorrect: this.props.autoCorrect,
  13977. className: cx_1({
  13978. // Chrome's built-in translation feature mutates the DOM in ways
  13979. // that Draft doesn't expect (ex: adding <font> tags inside
  13980. // DraftEditorLeaf spans) and causes problems. We add notranslate
  13981. // here which makes its autotranslation skip over this subtree.
  13982. notranslate: !readOnly,
  13983. 'public/DraftEditor/content': true
  13984. }),
  13985. contentEditable: !readOnly,
  13986. 'data-testid': this.props.webDriverTestID,
  13987. onBeforeInput: this._onBeforeInput,
  13988. onBlur: this._onBlur,
  13989. onCompositionEnd: this._onCompositionEnd,
  13990. onCompositionStart: this._onCompositionStart,
  13991. onCopy: this._onCopy,
  13992. onCut: this._onCut,
  13993. onDragEnd: this._onDragEnd,
  13994. onDragEnter: this.onDragEnter,
  13995. onDragLeave: this.onDragLeave,
  13996. onDragOver: this._onDragOver,
  13997. onDragStart: this._onDragStart,
  13998. onDrop: this._onDrop,
  13999. onFocus: this._onFocus,
  14000. onInput: this._onInput,
  14001. onKeyDown: this._onKeyDown,
  14002. onKeyPress: this._onKeyPress,
  14003. onKeyUp: this._onKeyUp,
  14004. onMouseUp: this._onMouseUp,
  14005. onPaste: this._onPaste,
  14006. onSelect: this._onSelect,
  14007. ref: function ref(_ref2) {
  14008. return _this3.editor = _ref2;
  14009. },
  14010. role: readOnly ? null : ariaRole,
  14011. spellCheck: allowSpellCheck && this.props.spellCheck,
  14012. style: contentStyle,
  14013. suppressContentEditableWarning: true,
  14014. tabIndex: this.props.tabIndex },
  14015. React.createElement(DraftEditorContents_react, editorContentsProps)
  14016. )
  14017. )
  14018. );
  14019. };
  14020. DraftEditor.prototype.componentDidMount = function componentDidMount() {
  14021. this.setMode('edit');
  14022. /**
  14023. * IE has a hardcoded "feature" that attempts to convert link text into
  14024. * anchors in contentEditable DOM. This breaks the editor's expectations of
  14025. * the DOM, and control is lost. Disable it to make IE behave.
  14026. * See: http://blogs.msdn.com/b/ieinternals/archive/2010/09/15/
  14027. * ie9-beta-minor-change-list.aspx
  14028. */
  14029. if (isIE) {
  14030. document.execCommand('AutoUrlDetect', false, false);
  14031. }
  14032. };
  14033. /**
  14034. * Prevent selection events from affecting the current editor state. This
  14035. * is mostly intended to defend against IE, which fires off `selectionchange`
  14036. * events regardless of whether the selection is set via the browser or
  14037. * programmatically. We only care about selection events that occur because
  14038. * of browser interaction, not re-renders and forced selections.
  14039. */
  14040. DraftEditor.prototype.componentWillUpdate = function componentWillUpdate(nextProps) {
  14041. this._blockSelectEvents = true;
  14042. this._latestEditorState = nextProps.editorState;
  14043. };
  14044. DraftEditor.prototype.componentDidUpdate = function componentDidUpdate() {
  14045. this._blockSelectEvents = false;
  14046. this._latestCommittedEditorState = this.props.editorState;
  14047. };
  14048. /**
  14049. * Used via `this.focus()`.
  14050. *
  14051. * Force focus back onto the editor node.
  14052. *
  14053. * We attempt to preserve scroll position when focusing. You can also pass
  14054. * a specified scroll position (for cases like `cut` behavior where it should
  14055. * be restored to a known position).
  14056. */
  14057. /**
  14058. * Used via `this.setMode(...)`.
  14059. *
  14060. * Set the behavior mode for the editor component. This switches the current
  14061. * handler module to ensure that DOM events are managed appropriately for
  14062. * the active mode.
  14063. */
  14064. /**
  14065. * Used via `this.restoreEditorDOM()`.
  14066. *
  14067. * Force a complete re-render of the DraftEditorContents based on the current
  14068. * EditorState. This is useful when we know we are going to lose control of
  14069. * the DOM state (cut command, IME) and we want to make sure that
  14070. * reconciliation occurs on a version of the DOM that is synchronized with
  14071. * our EditorState.
  14072. */
  14073. /**
  14074. * Used via `this.setClipboard(...)`.
  14075. *
  14076. * Set the clipboard state for a cut/copy event.
  14077. */
  14078. /**
  14079. * Used via `this.getClipboard()`.
  14080. *
  14081. * Retrieve the clipboard state for a cut/copy event.
  14082. */
  14083. /**
  14084. * Used via `this.update(...)`.
  14085. *
  14086. * Propagate a new `EditorState` object to higher-level components. This is
  14087. * the method by which event handlers inform the `DraftEditor` component of
  14088. * state changes. A component that composes a `DraftEditor` **must** provide
  14089. * an `onChange` prop to receive state updates passed along from this
  14090. * function.
  14091. */
  14092. /**
  14093. * Used in conjunction with `onDragLeave()`, by counting the number of times
  14094. * a dragged element enters and leaves the editor (or any of its children),
  14095. * to determine when the dragged element absolutely leaves the editor.
  14096. */
  14097. /**
  14098. * See `onDragEnter()`.
  14099. */
  14100. return DraftEditor;
  14101. }(React.Component);
  14102. DraftEditor.defaultProps = {
  14103. blockRenderMap: DefaultDraftBlockRenderMap_1,
  14104. blockRendererFn: emptyFunction_1.thatReturnsNull,
  14105. blockStyleFn: emptyFunction_1.thatReturns(''),
  14106. keyBindingFn: getDefaultKeyBinding_1,
  14107. readOnly: false,
  14108. spellCheck: false,
  14109. stripPastedStyles: false
  14110. };
  14111. var DraftEditor_react = DraftEditor;
  14112. /**
  14113. * Copyright (c) 2013-present, Facebook, Inc.
  14114. * All rights reserved.
  14115. *
  14116. * This source code is licensed under the BSD-style license found in the
  14117. * LICENSE file in the root directory of this source tree. An additional grant
  14118. * of patent rights can be found in the PATENTS file in the same directory.
  14119. *
  14120. * @providesModule DraftStringKey
  14121. * @format
  14122. *
  14123. */
  14124. var DraftStringKey = {
  14125. stringify: function stringify(key) {
  14126. return '_' + String(key);
  14127. },
  14128. unstringify: function unstringify(key) {
  14129. return key.slice(1);
  14130. }
  14131. };
  14132. var DraftStringKey_1 = DraftStringKey;
  14133. var strlen$1 = UnicodeUtils_1.strlen;
  14134. /**
  14135. * Convert to UTF-8 character counts for storage.
  14136. */
  14137. function encodeEntityRanges(block, storageMap) {
  14138. var encoded = [];
  14139. block.findEntityRanges(function (character) {
  14140. return !!character.getEntity();
  14141. }, function ( /*number*/start, /*number*/end) {
  14142. var text = block.getText();
  14143. var key = block.getEntityAt(start);
  14144. encoded.push({
  14145. offset: strlen$1(text.slice(0, start)),
  14146. length: strlen$1(text.slice(start, end)),
  14147. // Encode the key as a number for range storage.
  14148. key: Number(storageMap[DraftStringKey_1.stringify(key)])
  14149. });
  14150. });
  14151. return encoded;
  14152. }
  14153. var encodeEntityRanges_1 = encodeEntityRanges;
  14154. var areEqual$1 = function areEqual(a, b) {
  14155. return a === b;
  14156. };
  14157. var isTruthy = function isTruthy(a) {
  14158. return !!a;
  14159. };
  14160. var EMPTY_ARRAY = [];
  14161. /**
  14162. * Helper function for getting encoded styles for each inline style. Convert
  14163. * to UTF-8 character counts for storage.
  14164. */
  14165. function getEncodedInlinesForType(block, styleList, styleToEncode) {
  14166. var ranges = [];
  14167. // Obtain an array with ranges for only the specified style.
  14168. var filteredInlines = styleList.map(function (style) {
  14169. return style.has(styleToEncode);
  14170. }).toList();
  14171. findRangesImmutable_1(filteredInlines, areEqual$1,
  14172. // We only want to keep ranges with nonzero style values.
  14173. isTruthy, function (start, end) {
  14174. var text = block.getText();
  14175. ranges.push({
  14176. offset: UnicodeUtils_1.strlen(text.slice(0, start)),
  14177. length: UnicodeUtils_1.strlen(text.slice(start, end)),
  14178. style: styleToEncode
  14179. });
  14180. });
  14181. return ranges;
  14182. }
  14183. /*
  14184. * Retrieve the encoded arrays of inline styles, with each individual style
  14185. * treated separately.
  14186. */
  14187. function encodeInlineStyleRanges(block) {
  14188. var styleList = block.getCharacterList().map(function (c) {
  14189. return c.getStyle();
  14190. }).toList();
  14191. var ranges = styleList.flatten().toSet().map(function (style) {
  14192. return getEncodedInlinesForType(block, styleList, style);
  14193. });
  14194. return Array.prototype.concat.apply(EMPTY_ARRAY, ranges.toJS());
  14195. }
  14196. var encodeInlineStyleRanges_1 = encodeInlineStyleRanges;
  14197. 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; };
  14198. var createRawBlock = function createRawBlock(block, entityStorageMap) {
  14199. return {
  14200. key: block.getKey(),
  14201. text: block.getText(),
  14202. type: block.getType(),
  14203. depth: block.getDepth(),
  14204. inlineStyleRanges: encodeInlineStyleRanges_1(block),
  14205. entityRanges: encodeEntityRanges_1(block, entityStorageMap),
  14206. data: block.getData().toObject()
  14207. };
  14208. };
  14209. var insertRawBlock = function insertRawBlock(block, entityMap, rawBlocks, blockCacheRef) {
  14210. if (block instanceof ContentBlock_1) {
  14211. rawBlocks.push(createRawBlock(block, entityMap));
  14212. return;
  14213. }
  14214. !(block instanceof ContentBlockNode_1) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'block is not a BlockNode') : invariant_1(false) : void 0;
  14215. var parentKey = block.getParentKey();
  14216. var rawBlock = blockCacheRef[block.getKey()] = _extends$6({}, createRawBlock(block, entityMap), {
  14217. children: []
  14218. });
  14219. if (parentKey) {
  14220. blockCacheRef[parentKey].children.push(rawBlock);
  14221. return;
  14222. }
  14223. rawBlocks.push(rawBlock);
  14224. };
  14225. var encodeRawBlocks = function encodeRawBlocks(contentState, rawState) {
  14226. var entityMap = rawState.entityMap;
  14227. var rawBlocks = [];
  14228. var blockCacheRef = {};
  14229. var entityCacheRef = {};
  14230. var entityStorageKey = 0;
  14231. contentState.getBlockMap().forEach(function (block) {
  14232. block.findEntityRanges(function (character) {
  14233. return character.getEntity() !== null;
  14234. }, function (start) {
  14235. var entityKey = block.getEntityAt(start);
  14236. // Stringify to maintain order of otherwise numeric keys.
  14237. var stringifiedEntityKey = DraftStringKey_1.stringify(entityKey);
  14238. // This makes this function resilient to two entities
  14239. // erroneously having the same key
  14240. if (entityCacheRef[stringifiedEntityKey]) {
  14241. return;
  14242. }
  14243. entityCacheRef[stringifiedEntityKey] = entityKey;
  14244. // we need the `any` casting here since this is a temporary state
  14245. // where we will later on flip the entity map and populate it with
  14246. // real entity, at this stage we just need to map back the entity
  14247. // key used by the BlockNode
  14248. entityMap[stringifiedEntityKey] = '' + entityStorageKey;
  14249. entityStorageKey++;
  14250. });
  14251. insertRawBlock(block, entityMap, rawBlocks, blockCacheRef);
  14252. });
  14253. return {
  14254. blocks: rawBlocks,
  14255. entityMap: entityMap
  14256. };
  14257. };
  14258. // Flip storage map so that our storage keys map to global
  14259. // DraftEntity keys.
  14260. var encodeRawEntityMap = function encodeRawEntityMap(contentState, rawState) {
  14261. var blocks = rawState.blocks,
  14262. entityMap = rawState.entityMap;
  14263. var rawEntityMap = {};
  14264. Object.keys(entityMap).forEach(function (key, index) {
  14265. var entity = contentState.getEntity(DraftStringKey_1.unstringify(key));
  14266. rawEntityMap[index] = {
  14267. type: entity.getType(),
  14268. mutability: entity.getMutability(),
  14269. data: entity.getData()
  14270. };
  14271. });
  14272. return {
  14273. blocks: blocks,
  14274. entityMap: rawEntityMap
  14275. };
  14276. };
  14277. var convertFromDraftStateToRaw = function convertFromDraftStateToRaw(contentState) {
  14278. var rawDraftContentState = {
  14279. entityMap: {},
  14280. blocks: []
  14281. };
  14282. // add blocks
  14283. rawDraftContentState = encodeRawBlocks(contentState, rawDraftContentState);
  14284. // add entities
  14285. rawDraftContentState = encodeRawEntityMap(contentState, rawDraftContentState);
  14286. return rawDraftContentState;
  14287. };
  14288. var convertFromDraftStateToRaw_1 = convertFromDraftStateToRaw;
  14289. 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; };
  14290. /**
  14291. * Copyright (c) 2013-present, Facebook, Inc.
  14292. * All rights reserved.
  14293. *
  14294. * This source code is licensed under the BSD-style license found in the
  14295. * LICENSE file in the root directory of this source tree. An additional grant
  14296. * of patent rights can be found in the PATENTS file in the same directory.
  14297. *
  14298. * @providesModule DraftTreeAdapter
  14299. * @format
  14300. *
  14301. *
  14302. * This is unstable and not part of the public API and should not be used by
  14303. * production systems. This file may be update/removed without notice.
  14304. */
  14305. var traverseInDepthOrder = function traverseInDepthOrder(blocks, fn) {
  14306. var stack = [].concat(blocks).reverse();
  14307. while (stack.length) {
  14308. var _block = stack.pop();
  14309. fn(_block);
  14310. var children = _block.children;
  14311. !Array.isArray(children) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid tree raw block') : invariant_1(false) : void 0;
  14312. stack = stack.concat([].concat(children.reverse()));
  14313. }
  14314. };
  14315. var isListBlock = function isListBlock(block) {
  14316. if (!(block && block.type)) {
  14317. return false;
  14318. }
  14319. var type = block.type;
  14320. return type === 'unordered-list-item' || type === 'ordered-list-item';
  14321. };
  14322. var addDepthToChildren = function addDepthToChildren(block) {
  14323. if (Array.isArray(block.children)) {
  14324. block.children = block.children.map(function (child) {
  14325. return child.type === block.type ? _extends$7({}, child, { depth: (block.depth || 0) + 1 }) : child;
  14326. });
  14327. }
  14328. };
  14329. /**
  14330. * This adapter is intended to be be used as an adapter to draft tree data
  14331. *
  14332. * draft state <=====> draft tree state
  14333. */
  14334. var DraftTreeAdapter = {
  14335. /**
  14336. * Converts from a tree raw state back to draft raw state
  14337. */
  14338. fromRawTreeStateToRawState: function fromRawTreeStateToRawState(draftTreeState) {
  14339. var blocks = draftTreeState.blocks;
  14340. var transformedBlocks = [];
  14341. !Array.isArray(blocks) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid raw state') : invariant_1(false) : void 0;
  14342. if (!Array.isArray(blocks) || !blocks.length) {
  14343. return draftTreeState;
  14344. }
  14345. traverseInDepthOrder(blocks, function (block) {
  14346. var newBlock = _extends$7({}, block);
  14347. if (isListBlock(block)) {
  14348. newBlock.depth = newBlock.depth || 0;
  14349. addDepthToChildren(block);
  14350. }
  14351. delete newBlock.children;
  14352. transformedBlocks.push(newBlock);
  14353. });
  14354. draftTreeState.blocks = transformedBlocks;
  14355. return _extends$7({}, draftTreeState, {
  14356. blocks: transformedBlocks
  14357. });
  14358. },
  14359. /**
  14360. * Converts from draft raw state to tree draft state
  14361. */
  14362. fromRawStateToRawTreeState: function fromRawStateToRawTreeState(draftState) {
  14363. var lastListDepthCacheRef = {};
  14364. var transformedBlocks = [];
  14365. draftState.blocks.forEach(function (block) {
  14366. var isList = isListBlock(block);
  14367. var depth = block.depth || 0;
  14368. var treeBlock = _extends$7({}, block, {
  14369. children: []
  14370. });
  14371. if (!isList) {
  14372. // reset the cache path
  14373. lastListDepthCacheRef = {};
  14374. transformedBlocks.push(treeBlock);
  14375. return;
  14376. }
  14377. // update our depth cache reference path
  14378. lastListDepthCacheRef[depth] = treeBlock;
  14379. // if we are greater than zero we must have seen a parent already
  14380. if (depth > 0) {
  14381. var parent = lastListDepthCacheRef[depth - 1];
  14382. !parent ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid depth for RawDraftContentBlock') : invariant_1(false) : void 0;
  14383. // push nested list blocks
  14384. parent.children.push(treeBlock);
  14385. return;
  14386. }
  14387. // push root list blocks
  14388. transformedBlocks.push(treeBlock);
  14389. });
  14390. return _extends$7({}, draftState, {
  14391. blocks: transformedBlocks
  14392. });
  14393. }
  14394. };
  14395. var DraftTreeAdapter_1 = DraftTreeAdapter;
  14396. var List$c = immutable.List;
  14397. function createCharacterList(inlineStyles, entities) {
  14398. var characterArray = inlineStyles.map(function (style, ii) {
  14399. var entity = entities[ii];
  14400. return CharacterMetadata_1.create({ style: style, entity: entity });
  14401. });
  14402. return List$c(characterArray);
  14403. }
  14404. var createCharacterList_1 = createCharacterList;
  14405. var substr$1 = UnicodeUtils_1.substr;
  14406. /**
  14407. * Convert to native JavaScript string lengths to determine ranges.
  14408. */
  14409. function decodeEntityRanges(text, ranges) {
  14410. var entities = Array(text.length).fill(null);
  14411. if (ranges) {
  14412. ranges.forEach(function (range) {
  14413. // Using Unicode-enabled substrings converted to JavaScript lengths,
  14414. // fill the output array with entity keys.
  14415. var start = substr$1(text, 0, range.offset).length;
  14416. var end = start + substr$1(text, range.offset, range.length).length;
  14417. for (var ii = start; ii < end; ii++) {
  14418. entities[ii] = range.key;
  14419. }
  14420. });
  14421. }
  14422. return entities;
  14423. }
  14424. var decodeEntityRanges_1 = decodeEntityRanges;
  14425. var OrderedSet$6 = immutable.OrderedSet;
  14426. var substr$2 = UnicodeUtils_1.substr;
  14427. var EMPTY_SET$3 = OrderedSet$6();
  14428. /**
  14429. * Convert to native JavaScript string lengths to determine ranges.
  14430. */
  14431. function decodeInlineStyleRanges(text, ranges) {
  14432. var styles = Array(text.length).fill(EMPTY_SET$3);
  14433. if (ranges) {
  14434. ranges.forEach(function ( /*object*/range) {
  14435. var cursor = substr$2(text, 0, range.offset).length;
  14436. var end = cursor + substr$2(text, range.offset, range.length).length;
  14437. while (cursor < end) {
  14438. styles[cursor] = styles[cursor].add(range.style);
  14439. cursor++;
  14440. }
  14441. });
  14442. }
  14443. return styles;
  14444. }
  14445. var decodeInlineStyleRanges_1 = decodeInlineStyleRanges;
  14446. 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; };
  14447. var List$d = immutable.List,
  14448. Map$a = immutable.Map,
  14449. OrderedMap$4 = immutable.OrderedMap;
  14450. var decodeBlockNodeConfig = function decodeBlockNodeConfig(block, entityMap) {
  14451. var key = block.key,
  14452. type = block.type,
  14453. data = block.data,
  14454. text = block.text,
  14455. depth = block.depth;
  14456. var blockNodeConfig = {
  14457. text: text,
  14458. depth: depth || 0,
  14459. type: type || 'unstyled',
  14460. key: key || generateRandomKey_1(),
  14461. data: Map$a(data),
  14462. characterList: decodeCharacterList(block, entityMap)
  14463. };
  14464. return blockNodeConfig;
  14465. };
  14466. var decodeCharacterList = function decodeCharacterList(block, entityMap) {
  14467. var text = block.text,
  14468. rawEntityRanges = block.entityRanges,
  14469. rawInlineStyleRanges = block.inlineStyleRanges;
  14470. var entityRanges = rawEntityRanges || [];
  14471. var inlineStyleRanges = rawInlineStyleRanges || [];
  14472. // Translate entity range keys to the DraftEntity map.
  14473. return createCharacterList_1(decodeInlineStyleRanges_1(text, inlineStyleRanges), decodeEntityRanges_1(text, entityRanges.filter(function (range) {
  14474. return entityMap.hasOwnProperty(range.key);
  14475. }).map(function (range) {
  14476. return _extends$8({}, range, { key: entityMap[range.key] });
  14477. })));
  14478. };
  14479. var decodeContentBlocks = function decodeContentBlocks(blocks, entityMap) {
  14480. return OrderedMap$4(blocks.map(function (block) {
  14481. var contentBlock = new ContentBlock_1(decodeBlockNodeConfig(block, entityMap));
  14482. return [contentBlock.getKey(), contentBlock];
  14483. }));
  14484. };
  14485. var decodeRawBlocks = function decodeRawBlocks(rawState, entityMap) {
  14486. var isTreeRawBlock = Array.isArray(rawState.blocks[0].children);
  14487. var rawBlocks = rawState.blocks;
  14488. {
  14489. return decodeContentBlocks(isTreeRawBlock ? DraftTreeAdapter_1.fromRawTreeStateToRawState(rawState).blocks : rawBlocks, entityMap);
  14490. }
  14491. };
  14492. var decodeRawEntityMap = function decodeRawEntityMap(rawState) {
  14493. var rawEntityMap = rawState.entityMap;
  14494. var entityMap = {};
  14495. // TODO: Update this once we completely remove DraftEntity
  14496. Object.keys(rawEntityMap).forEach(function (rawEntityKey) {
  14497. var _rawEntityMap$rawEnti = rawEntityMap[rawEntityKey],
  14498. type = _rawEntityMap$rawEnti.type,
  14499. mutability = _rawEntityMap$rawEnti.mutability,
  14500. data = _rawEntityMap$rawEnti.data;
  14501. // get the key reference to created entity
  14502. entityMap[rawEntityKey] = DraftEntity_1.__create(type, mutability, data || {});
  14503. });
  14504. return entityMap;
  14505. };
  14506. var convertFromRawToDraftState = function convertFromRawToDraftState(rawState) {
  14507. !Array.isArray(rawState.blocks) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'invalid RawDraftContentState') : invariant_1(false) : void 0;
  14508. // decode entities
  14509. var entityMap = decodeRawEntityMap(rawState);
  14510. // decode blockMap
  14511. var blockMap = decodeRawBlocks(rawState, entityMap);
  14512. // create initial selection
  14513. var selectionState = blockMap.isEmpty() ? new SelectionState_1() : SelectionState_1.createEmpty(blockMap.first().getKey());
  14514. return new ContentState_1({
  14515. blockMap: blockMap,
  14516. entityMap: entityMap,
  14517. selectionBefore: selectionState,
  14518. selectionAfter: selectionState
  14519. });
  14520. };
  14521. var convertFromRawToDraftState_1 = convertFromRawToDraftState;
  14522. /**
  14523. * Like range.getBoundingClientRect() but normalizes for browser bugs.
  14524. */
  14525. function getRangeBoundingClientRect(range) {
  14526. // "Return a DOMRect object describing the smallest rectangle that includes
  14527. // the first rectangle in list and all of the remaining rectangles of which
  14528. // the height or width is not zero."
  14529. // http://www.w3.org/TR/cssom-view/#dom-range-getboundingclientrect
  14530. var rects = getRangeClientRects_1(range);
  14531. var top = 0;
  14532. var right = 0;
  14533. var bottom = 0;
  14534. var left = 0;
  14535. if (rects.length) {
  14536. // If the first rectangle has 0 width, we use the second, this is needed
  14537. // because Chrome renders a 0 width rectangle when the selection contains
  14538. // a line break.
  14539. if (rects.length > 1 && rects[0].width === 0) {
  14540. var _rects$ = rects[1];
  14541. top = _rects$.top;
  14542. right = _rects$.right;
  14543. bottom = _rects$.bottom;
  14544. left = _rects$.left;
  14545. } else {
  14546. var _rects$2 = rects[0];
  14547. top = _rects$2.top;
  14548. right = _rects$2.right;
  14549. bottom = _rects$2.bottom;
  14550. left = _rects$2.left;
  14551. }
  14552. for (var ii = 1; ii < rects.length; ii++) {
  14553. var rect = rects[ii];
  14554. if (rect.height !== 0 && rect.width !== 0) {
  14555. top = Math.min(top, rect.top);
  14556. right = Math.max(right, rect.right);
  14557. bottom = Math.max(bottom, rect.bottom);
  14558. left = Math.min(left, rect.left);
  14559. }
  14560. }
  14561. }
  14562. return {
  14563. top: top,
  14564. right: right,
  14565. bottom: bottom,
  14566. left: left,
  14567. width: right - left,
  14568. height: bottom - top
  14569. };
  14570. }
  14571. var getRangeBoundingClientRect_1 = getRangeBoundingClientRect;
  14572. /**
  14573. * Return the bounding ClientRect for the visible DOM selection, if any.
  14574. * In cases where there are no selected ranges or the bounding rect is
  14575. * temporarily invalid, return null.
  14576. */
  14577. function getVisibleSelectionRect(global) {
  14578. var selection = global.getSelection();
  14579. if (!selection.rangeCount) {
  14580. return null;
  14581. }
  14582. var range = selection.getRangeAt(0);
  14583. var boundingRect = getRangeBoundingClientRect_1(range);
  14584. var top = boundingRect.top,
  14585. right = boundingRect.right,
  14586. bottom = boundingRect.bottom,
  14587. left = boundingRect.left;
  14588. // When a re-render leads to a node being removed, the DOM selection will
  14589. // temporarily be placed on an ancestor node, which leads to an invalid
  14590. // bounding rect. Discard this state.
  14591. if (top === 0 && right === 0 && bottom === 0 && left === 0) {
  14592. return null;
  14593. }
  14594. return boundingRect;
  14595. }
  14596. var getVisibleSelectionRect_1 = getVisibleSelectionRect;
  14597. var DraftPublic = {
  14598. Editor: DraftEditor_react,
  14599. EditorBlock: DraftEditorBlock_react,
  14600. EditorState: EditorState_1,
  14601. CompositeDecorator: CompositeDraftDecorator_1,
  14602. Entity: DraftEntity_1,
  14603. EntityInstance: DraftEntityInstance_1,
  14604. BlockMapBuilder: BlockMapBuilder_1,
  14605. CharacterMetadata: CharacterMetadata_1,
  14606. ContentBlock: ContentBlock_1,
  14607. ContentState: ContentState_1,
  14608. SelectionState: SelectionState_1,
  14609. AtomicBlockUtils: AtomicBlockUtils_1,
  14610. KeyBindingUtil: KeyBindingUtil_1,
  14611. Modifier: DraftModifier_1,
  14612. RichUtils: RichTextEditorUtil_1,
  14613. DefaultDraftBlockRenderMap: DefaultDraftBlockRenderMap_1,
  14614. DefaultDraftInlineStyle: DefaultDraftInlineStyle,
  14615. convertFromHTML: convertFromHTMLToContentBlocks,
  14616. convertFromRaw: convertFromRawToDraftState_1,
  14617. convertToRaw: convertFromDraftStateToRaw_1,
  14618. genKey: generateRandomKey_1,
  14619. getDefaultKeyBinding: getDefaultKeyBinding_1,
  14620. getVisibleSelectionRect: getVisibleSelectionRect_1
  14621. };
  14622. var Draft = DraftPublic;
  14623. var Draft_1 = Draft.Editor;
  14624. var Draft_3 = Draft.EditorState;
  14625. var Draft_4 = Draft.CompositeDecorator;
  14626. var Draft_14 = Draft.Modifier;
  14627. var Draft_15 = Draft.RichUtils;
  14628. var Draft_20 = Draft.convertToRaw;
  14629. var immutable$1 = createCommonjsModule(function (module, exports) {
  14630. /**
  14631. * Copyright (c) 2014-2015, Facebook, Inc.
  14632. * All rights reserved.
  14633. *
  14634. * This source code is licensed under the BSD-style license found in the
  14635. * LICENSE file in the root directory of this source tree. An additional grant
  14636. * of patent rights can be found in the PATENTS file in the same directory.
  14637. */
  14638. (function (global, factory) {
  14639. module.exports = factory() ;
  14640. }(commonjsGlobal, function () {var SLICE$0 = Array.prototype.slice;
  14641. function createClass(ctor, superClass) {
  14642. if (superClass) {
  14643. ctor.prototype = Object.create(superClass.prototype);
  14644. }
  14645. ctor.prototype.constructor = ctor;
  14646. }
  14647. function Iterable(value) {
  14648. return isIterable(value) ? value : Seq(value);
  14649. }
  14650. createClass(KeyedIterable, Iterable);
  14651. function KeyedIterable(value) {
  14652. return isKeyed(value) ? value : KeyedSeq(value);
  14653. }
  14654. createClass(IndexedIterable, Iterable);
  14655. function IndexedIterable(value) {
  14656. return isIndexed(value) ? value : IndexedSeq(value);
  14657. }
  14658. createClass(SetIterable, Iterable);
  14659. function SetIterable(value) {
  14660. return isIterable(value) && !isAssociative(value) ? value : SetSeq(value);
  14661. }
  14662. function isIterable(maybeIterable) {
  14663. return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]);
  14664. }
  14665. function isKeyed(maybeKeyed) {
  14666. return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
  14667. }
  14668. function isIndexed(maybeIndexed) {
  14669. return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
  14670. }
  14671. function isAssociative(maybeAssociative) {
  14672. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  14673. }
  14674. function isOrdered(maybeOrdered) {
  14675. return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
  14676. }
  14677. Iterable.isIterable = isIterable;
  14678. Iterable.isKeyed = isKeyed;
  14679. Iterable.isIndexed = isIndexed;
  14680. Iterable.isAssociative = isAssociative;
  14681. Iterable.isOrdered = isOrdered;
  14682. Iterable.Keyed = KeyedIterable;
  14683. Iterable.Indexed = IndexedIterable;
  14684. Iterable.Set = SetIterable;
  14685. var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  14686. var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  14687. var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  14688. var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  14689. // Used for setting prototype methods that IE8 chokes on.
  14690. var DELETE = 'delete';
  14691. // Constants describing the size of trie nodes.
  14692. var SHIFT = 5; // Resulted in best performance after ______?
  14693. var SIZE = 1 << SHIFT;
  14694. var MASK = SIZE - 1;
  14695. // A consistent shared value representing "not set" which equals nothing other
  14696. // than itself, and nothing that could be provided externally.
  14697. var NOT_SET = {};
  14698. // Boolean references, Rough equivalent of `bool &`.
  14699. var CHANGE_LENGTH = { value: false };
  14700. var DID_ALTER = { value: false };
  14701. function MakeRef(ref) {
  14702. ref.value = false;
  14703. return ref;
  14704. }
  14705. function SetRef(ref) {
  14706. ref && (ref.value = true);
  14707. }
  14708. // A function which returns a value representing an "owner" for transient writes
  14709. // to tries. The return value will only ever equal itself, and will not equal
  14710. // the return of any subsequent call of this function.
  14711. function OwnerID() {}
  14712. // http://jsperf.com/copy-array-inline
  14713. function arrCopy(arr, offset) {
  14714. offset = offset || 0;
  14715. var len = Math.max(0, arr.length - offset);
  14716. var newArr = new Array(len);
  14717. for (var ii = 0; ii < len; ii++) {
  14718. newArr[ii] = arr[ii + offset];
  14719. }
  14720. return newArr;
  14721. }
  14722. function ensureSize(iter) {
  14723. if (iter.size === undefined) {
  14724. iter.size = iter.__iterate(returnTrue);
  14725. }
  14726. return iter.size;
  14727. }
  14728. function wrapIndex(iter, index) {
  14729. // This implements "is array index" which the ECMAString spec defines as:
  14730. //
  14731. // A String property name P is an array index if and only if
  14732. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  14733. // to 2^32−1.
  14734. //
  14735. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  14736. if (typeof index !== 'number') {
  14737. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  14738. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  14739. return NaN;
  14740. }
  14741. index = uint32Index;
  14742. }
  14743. return index < 0 ? ensureSize(iter) + index : index;
  14744. }
  14745. function returnTrue() {
  14746. return true;
  14747. }
  14748. function wholeSlice(begin, end, size) {
  14749. return (begin === 0 || (size !== undefined && begin <= -size)) &&
  14750. (end === undefined || (size !== undefined && end >= size));
  14751. }
  14752. function resolveBegin(begin, size) {
  14753. return resolveIndex(begin, size, 0);
  14754. }
  14755. function resolveEnd(end, size) {
  14756. return resolveIndex(end, size, size);
  14757. }
  14758. function resolveIndex(index, size, defaultIndex) {
  14759. return index === undefined ?
  14760. defaultIndex :
  14761. index < 0 ?
  14762. Math.max(0, size + index) :
  14763. size === undefined ?
  14764. index :
  14765. Math.min(size, index);
  14766. }
  14767. /* global Symbol */
  14768. var ITERATE_KEYS = 0;
  14769. var ITERATE_VALUES = 1;
  14770. var ITERATE_ENTRIES = 2;
  14771. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  14772. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  14773. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  14774. function Iterator(next) {
  14775. this.next = next;
  14776. }
  14777. Iterator.prototype.toString = function() {
  14778. return '[Iterator]';
  14779. };
  14780. Iterator.KEYS = ITERATE_KEYS;
  14781. Iterator.VALUES = ITERATE_VALUES;
  14782. Iterator.ENTRIES = ITERATE_ENTRIES;
  14783. Iterator.prototype.inspect =
  14784. Iterator.prototype.toSource = function () { return this.toString(); };
  14785. Iterator.prototype[ITERATOR_SYMBOL] = function () {
  14786. return this;
  14787. };
  14788. function iteratorValue(type, k, v, iteratorResult) {
  14789. var value = type === 0 ? k : type === 1 ? v : [k, v];
  14790. iteratorResult ? (iteratorResult.value = value) : (iteratorResult = {
  14791. value: value, done: false
  14792. });
  14793. return iteratorResult;
  14794. }
  14795. function iteratorDone() {
  14796. return { value: undefined, done: true };
  14797. }
  14798. function hasIterator(maybeIterable) {
  14799. return !!getIteratorFn(maybeIterable);
  14800. }
  14801. function isIterator(maybeIterator) {
  14802. return maybeIterator && typeof maybeIterator.next === 'function';
  14803. }
  14804. function getIterator(iterable) {
  14805. var iteratorFn = getIteratorFn(iterable);
  14806. return iteratorFn && iteratorFn.call(iterable);
  14807. }
  14808. function getIteratorFn(iterable) {
  14809. var iteratorFn = iterable && (
  14810. (REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  14811. iterable[FAUX_ITERATOR_SYMBOL]
  14812. );
  14813. if (typeof iteratorFn === 'function') {
  14814. return iteratorFn;
  14815. }
  14816. }
  14817. function isArrayLike(value) {
  14818. return value && typeof value.length === 'number';
  14819. }
  14820. createClass(Seq, Iterable);
  14821. function Seq(value) {
  14822. return value === null || value === undefined ? emptySequence() :
  14823. isIterable(value) ? value.toSeq() : seqFromValue(value);
  14824. }
  14825. Seq.of = function(/*...values*/) {
  14826. return Seq(arguments);
  14827. };
  14828. Seq.prototype.toSeq = function() {
  14829. return this;
  14830. };
  14831. Seq.prototype.toString = function() {
  14832. return this.__toString('Seq {', '}');
  14833. };
  14834. Seq.prototype.cacheResult = function() {
  14835. if (!this._cache && this.__iterateUncached) {
  14836. this._cache = this.entrySeq().toArray();
  14837. this.size = this._cache.length;
  14838. }
  14839. return this;
  14840. };
  14841. // abstract __iterateUncached(fn, reverse)
  14842. Seq.prototype.__iterate = function(fn, reverse) {
  14843. return seqIterate(this, fn, reverse, true);
  14844. };
  14845. // abstract __iteratorUncached(type, reverse)
  14846. Seq.prototype.__iterator = function(type, reverse) {
  14847. return seqIterator(this, type, reverse, true);
  14848. };
  14849. createClass(KeyedSeq, Seq);
  14850. function KeyedSeq(value) {
  14851. return value === null || value === undefined ?
  14852. emptySequence().toKeyedSeq() :
  14853. isIterable(value) ?
  14854. (isKeyed(value) ? value.toSeq() : value.fromEntrySeq()) :
  14855. keyedSeqFromValue(value);
  14856. }
  14857. KeyedSeq.prototype.toKeyedSeq = function() {
  14858. return this;
  14859. };
  14860. createClass(IndexedSeq, Seq);
  14861. function IndexedSeq(value) {
  14862. return value === null || value === undefined ? emptySequence() :
  14863. !isIterable(value) ? indexedSeqFromValue(value) :
  14864. isKeyed(value) ? value.entrySeq() : value.toIndexedSeq();
  14865. }
  14866. IndexedSeq.of = function(/*...values*/) {
  14867. return IndexedSeq(arguments);
  14868. };
  14869. IndexedSeq.prototype.toIndexedSeq = function() {
  14870. return this;
  14871. };
  14872. IndexedSeq.prototype.toString = function() {
  14873. return this.__toString('Seq [', ']');
  14874. };
  14875. IndexedSeq.prototype.__iterate = function(fn, reverse) {
  14876. return seqIterate(this, fn, reverse, false);
  14877. };
  14878. IndexedSeq.prototype.__iterator = function(type, reverse) {
  14879. return seqIterator(this, type, reverse, false);
  14880. };
  14881. createClass(SetSeq, Seq);
  14882. function SetSeq(value) {
  14883. return (
  14884. value === null || value === undefined ? emptySequence() :
  14885. !isIterable(value) ? indexedSeqFromValue(value) :
  14886. isKeyed(value) ? value.entrySeq() : value
  14887. ).toSetSeq();
  14888. }
  14889. SetSeq.of = function(/*...values*/) {
  14890. return SetSeq(arguments);
  14891. };
  14892. SetSeq.prototype.toSetSeq = function() {
  14893. return this;
  14894. };
  14895. Seq.isSeq = isSeq;
  14896. Seq.Keyed = KeyedSeq;
  14897. Seq.Set = SetSeq;
  14898. Seq.Indexed = IndexedSeq;
  14899. var IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
  14900. Seq.prototype[IS_SEQ_SENTINEL] = true;
  14901. createClass(ArraySeq, IndexedSeq);
  14902. function ArraySeq(array) {
  14903. this._array = array;
  14904. this.size = array.length;
  14905. }
  14906. ArraySeq.prototype.get = function(index, notSetValue) {
  14907. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  14908. };
  14909. ArraySeq.prototype.__iterate = function(fn, reverse) {
  14910. var array = this._array;
  14911. var maxIndex = array.length - 1;
  14912. for (var ii = 0; ii <= maxIndex; ii++) {
  14913. if (fn(array[reverse ? maxIndex - ii : ii], ii, this) === false) {
  14914. return ii + 1;
  14915. }
  14916. }
  14917. return ii;
  14918. };
  14919. ArraySeq.prototype.__iterator = function(type, reverse) {
  14920. var array = this._array;
  14921. var maxIndex = array.length - 1;
  14922. var ii = 0;
  14923. return new Iterator(function()
  14924. {return ii > maxIndex ?
  14925. iteratorDone() :
  14926. iteratorValue(type, ii, array[reverse ? maxIndex - ii++ : ii++])}
  14927. );
  14928. };
  14929. createClass(ObjectSeq, KeyedSeq);
  14930. function ObjectSeq(object) {
  14931. var keys = Object.keys(object);
  14932. this._object = object;
  14933. this._keys = keys;
  14934. this.size = keys.length;
  14935. }
  14936. ObjectSeq.prototype.get = function(key, notSetValue) {
  14937. if (notSetValue !== undefined && !this.has(key)) {
  14938. return notSetValue;
  14939. }
  14940. return this._object[key];
  14941. };
  14942. ObjectSeq.prototype.has = function(key) {
  14943. return this._object.hasOwnProperty(key);
  14944. };
  14945. ObjectSeq.prototype.__iterate = function(fn, reverse) {
  14946. var object = this._object;
  14947. var keys = this._keys;
  14948. var maxIndex = keys.length - 1;
  14949. for (var ii = 0; ii <= maxIndex; ii++) {
  14950. var key = keys[reverse ? maxIndex - ii : ii];
  14951. if (fn(object[key], key, this) === false) {
  14952. return ii + 1;
  14953. }
  14954. }
  14955. return ii;
  14956. };
  14957. ObjectSeq.prototype.__iterator = function(type, reverse) {
  14958. var object = this._object;
  14959. var keys = this._keys;
  14960. var maxIndex = keys.length - 1;
  14961. var ii = 0;
  14962. return new Iterator(function() {
  14963. var key = keys[reverse ? maxIndex - ii : ii];
  14964. return ii++ > maxIndex ?
  14965. iteratorDone() :
  14966. iteratorValue(type, key, object[key]);
  14967. });
  14968. };
  14969. ObjectSeq.prototype[IS_ORDERED_SENTINEL] = true;
  14970. createClass(IterableSeq, IndexedSeq);
  14971. function IterableSeq(iterable) {
  14972. this._iterable = iterable;
  14973. this.size = iterable.length || iterable.size;
  14974. }
  14975. IterableSeq.prototype.__iterateUncached = function(fn, reverse) {
  14976. if (reverse) {
  14977. return this.cacheResult().__iterate(fn, reverse);
  14978. }
  14979. var iterable = this._iterable;
  14980. var iterator = getIterator(iterable);
  14981. var iterations = 0;
  14982. if (isIterator(iterator)) {
  14983. var step;
  14984. while (!(step = iterator.next()).done) {
  14985. if (fn(step.value, iterations++, this) === false) {
  14986. break;
  14987. }
  14988. }
  14989. }
  14990. return iterations;
  14991. };
  14992. IterableSeq.prototype.__iteratorUncached = function(type, reverse) {
  14993. if (reverse) {
  14994. return this.cacheResult().__iterator(type, reverse);
  14995. }
  14996. var iterable = this._iterable;
  14997. var iterator = getIterator(iterable);
  14998. if (!isIterator(iterator)) {
  14999. return new Iterator(iteratorDone);
  15000. }
  15001. var iterations = 0;
  15002. return new Iterator(function() {
  15003. var step = iterator.next();
  15004. return step.done ? step : iteratorValue(type, iterations++, step.value);
  15005. });
  15006. };
  15007. createClass(IteratorSeq, IndexedSeq);
  15008. function IteratorSeq(iterator) {
  15009. this._iterator = iterator;
  15010. this._iteratorCache = [];
  15011. }
  15012. IteratorSeq.prototype.__iterateUncached = function(fn, reverse) {
  15013. if (reverse) {
  15014. return this.cacheResult().__iterate(fn, reverse);
  15015. }
  15016. var iterator = this._iterator;
  15017. var cache = this._iteratorCache;
  15018. var iterations = 0;
  15019. while (iterations < cache.length) {
  15020. if (fn(cache[iterations], iterations++, this) === false) {
  15021. return iterations;
  15022. }
  15023. }
  15024. var step;
  15025. while (!(step = iterator.next()).done) {
  15026. var val = step.value;
  15027. cache[iterations] = val;
  15028. if (fn(val, iterations++, this) === false) {
  15029. break;
  15030. }
  15031. }
  15032. return iterations;
  15033. };
  15034. IteratorSeq.prototype.__iteratorUncached = function(type, reverse) {
  15035. if (reverse) {
  15036. return this.cacheResult().__iterator(type, reverse);
  15037. }
  15038. var iterator = this._iterator;
  15039. var cache = this._iteratorCache;
  15040. var iterations = 0;
  15041. return new Iterator(function() {
  15042. if (iterations >= cache.length) {
  15043. var step = iterator.next();
  15044. if (step.done) {
  15045. return step;
  15046. }
  15047. cache[iterations] = step.value;
  15048. }
  15049. return iteratorValue(type, iterations, cache[iterations++]);
  15050. });
  15051. };
  15052. // # pragma Helper functions
  15053. function isSeq(maybeSeq) {
  15054. return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]);
  15055. }
  15056. var EMPTY_SEQ;
  15057. function emptySequence() {
  15058. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  15059. }
  15060. function keyedSeqFromValue(value) {
  15061. var seq =
  15062. Array.isArray(value) ? new ArraySeq(value).fromEntrySeq() :
  15063. isIterator(value) ? new IteratorSeq(value).fromEntrySeq() :
  15064. hasIterator(value) ? new IterableSeq(value).fromEntrySeq() :
  15065. typeof value === 'object' ? new ObjectSeq(value) :
  15066. undefined;
  15067. if (!seq) {
  15068. throw new TypeError(
  15069. 'Expected Array or iterable object of [k, v] entries, '+
  15070. 'or keyed object: ' + value
  15071. );
  15072. }
  15073. return seq;
  15074. }
  15075. function indexedSeqFromValue(value) {
  15076. var seq = maybeIndexedSeqFromValue(value);
  15077. if (!seq) {
  15078. throw new TypeError(
  15079. 'Expected Array or iterable object of values: ' + value
  15080. );
  15081. }
  15082. return seq;
  15083. }
  15084. function seqFromValue(value) {
  15085. var seq = maybeIndexedSeqFromValue(value) ||
  15086. (typeof value === 'object' && new ObjectSeq(value));
  15087. if (!seq) {
  15088. throw new TypeError(
  15089. 'Expected Array or iterable object of values, or keyed object: ' + value
  15090. );
  15091. }
  15092. return seq;
  15093. }
  15094. function maybeIndexedSeqFromValue(value) {
  15095. return (
  15096. isArrayLike(value) ? new ArraySeq(value) :
  15097. isIterator(value) ? new IteratorSeq(value) :
  15098. hasIterator(value) ? new IterableSeq(value) :
  15099. undefined
  15100. );
  15101. }
  15102. function seqIterate(seq, fn, reverse, useKeys) {
  15103. var cache = seq._cache;
  15104. if (cache) {
  15105. var maxIndex = cache.length - 1;
  15106. for (var ii = 0; ii <= maxIndex; ii++) {
  15107. var entry = cache[reverse ? maxIndex - ii : ii];
  15108. if (fn(entry[1], useKeys ? entry[0] : ii, seq) === false) {
  15109. return ii + 1;
  15110. }
  15111. }
  15112. return ii;
  15113. }
  15114. return seq.__iterateUncached(fn, reverse);
  15115. }
  15116. function seqIterator(seq, type, reverse, useKeys) {
  15117. var cache = seq._cache;
  15118. if (cache) {
  15119. var maxIndex = cache.length - 1;
  15120. var ii = 0;
  15121. return new Iterator(function() {
  15122. var entry = cache[reverse ? maxIndex - ii : ii];
  15123. return ii++ > maxIndex ?
  15124. iteratorDone() :
  15125. iteratorValue(type, useKeys ? entry[0] : ii - 1, entry[1]);
  15126. });
  15127. }
  15128. return seq.__iteratorUncached(type, reverse);
  15129. }
  15130. function fromJS(json, converter) {
  15131. return converter ?
  15132. fromJSWith(converter, json, '', {'': json}) :
  15133. fromJSDefault(json);
  15134. }
  15135. function fromJSWith(converter, json, key, parentJSON) {
  15136. if (Array.isArray(json)) {
  15137. return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  15138. }
  15139. if (isPlainObj(json)) {
  15140. return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  15141. }
  15142. return json;
  15143. }
  15144. function fromJSDefault(json) {
  15145. if (Array.isArray(json)) {
  15146. return IndexedSeq(json).map(fromJSDefault).toList();
  15147. }
  15148. if (isPlainObj(json)) {
  15149. return KeyedSeq(json).map(fromJSDefault).toMap();
  15150. }
  15151. return json;
  15152. }
  15153. function isPlainObj(value) {
  15154. return value && (value.constructor === Object || value.constructor === undefined);
  15155. }
  15156. /**
  15157. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  15158. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  15159. *
  15160. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  15161. * value, which is different from the algorithm described by
  15162. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  15163. *
  15164. * This is extended further to allow Objects to describe the values they
  15165. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  15166. *
  15167. * Note: because of this extension, the key equality of Immutable.Map and the
  15168. * value equality of Immutable.Set will differ from ES6 Map and Set.
  15169. *
  15170. * ### Defining custom values
  15171. *
  15172. * The easiest way to describe the value an object represents is by implementing
  15173. * `valueOf`. For example, `Date` represents a value by returning a unix
  15174. * timestamp for `valueOf`:
  15175. *
  15176. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  15177. * var date2 = new Date(1234567890000);
  15178. * date1.valueOf(); // 1234567890000
  15179. * assert( date1 !== date2 );
  15180. * assert( Immutable.is( date1, date2 ) );
  15181. *
  15182. * Note: overriding `valueOf` may have other implications if you use this object
  15183. * where JavaScript expects a primitive, such as implicit string coercion.
  15184. *
  15185. * For more complex types, especially collections, implementing `valueOf` may
  15186. * not be performant. An alternative is to implement `equals` and `hashCode`.
  15187. *
  15188. * `equals` takes another object, presumably of similar type, and returns true
  15189. * if the it is equal. Equality is symmetrical, so the same result should be
  15190. * returned if this and the argument are flipped.
  15191. *
  15192. * assert( a.equals(b) === b.equals(a) );
  15193. *
  15194. * `hashCode` returns a 32bit integer number representing the object which will
  15195. * be used to determine how to store the value object in a Map or Set. You must
  15196. * provide both or neither methods, one must not exist without the other.
  15197. *
  15198. * Also, an important relationship between these methods must be upheld: if two
  15199. * values are equal, they *must* return the same hashCode. If the values are not
  15200. * equal, they might have the same hashCode; this is called a hash collision,
  15201. * and while undesirable for performance reasons, it is acceptable.
  15202. *
  15203. * if (a.equals(b)) {
  15204. * assert( a.hashCode() === b.hashCode() );
  15205. * }
  15206. *
  15207. * All Immutable collections implement `equals` and `hashCode`.
  15208. *
  15209. */
  15210. function is(valueA, valueB) {
  15211. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  15212. return true;
  15213. }
  15214. if (!valueA || !valueB) {
  15215. return false;
  15216. }
  15217. if (typeof valueA.valueOf === 'function' &&
  15218. typeof valueB.valueOf === 'function') {
  15219. valueA = valueA.valueOf();
  15220. valueB = valueB.valueOf();
  15221. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  15222. return true;
  15223. }
  15224. if (!valueA || !valueB) {
  15225. return false;
  15226. }
  15227. }
  15228. if (typeof valueA.equals === 'function' &&
  15229. typeof valueB.equals === 'function' &&
  15230. valueA.equals(valueB)) {
  15231. return true;
  15232. }
  15233. return false;
  15234. }
  15235. function deepEqual(a, b) {
  15236. if (a === b) {
  15237. return true;
  15238. }
  15239. if (
  15240. !isIterable(b) ||
  15241. a.size !== undefined && b.size !== undefined && a.size !== b.size ||
  15242. a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
  15243. isKeyed(a) !== isKeyed(b) ||
  15244. isIndexed(a) !== isIndexed(b) ||
  15245. isOrdered(a) !== isOrdered(b)
  15246. ) {
  15247. return false;
  15248. }
  15249. if (a.size === 0 && b.size === 0) {
  15250. return true;
  15251. }
  15252. var notAssociative = !isAssociative(a);
  15253. if (isOrdered(a)) {
  15254. var entries = a.entries();
  15255. return b.every(function(v, k) {
  15256. var entry = entries.next().value;
  15257. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  15258. }) && entries.next().done;
  15259. }
  15260. var flipped = false;
  15261. if (a.size === undefined) {
  15262. if (b.size === undefined) {
  15263. if (typeof a.cacheResult === 'function') {
  15264. a.cacheResult();
  15265. }
  15266. } else {
  15267. flipped = true;
  15268. var _ = a;
  15269. a = b;
  15270. b = _;
  15271. }
  15272. }
  15273. var allEqual = true;
  15274. var bSize = b.__iterate(function(v, k) {
  15275. if (notAssociative ? !a.has(v) :
  15276. flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
  15277. allEqual = false;
  15278. return false;
  15279. }
  15280. });
  15281. return allEqual && a.size === bSize;
  15282. }
  15283. createClass(Repeat, IndexedSeq);
  15284. function Repeat(value, times) {
  15285. if (!(this instanceof Repeat)) {
  15286. return new Repeat(value, times);
  15287. }
  15288. this._value = value;
  15289. this.size = times === undefined ? Infinity : Math.max(0, times);
  15290. if (this.size === 0) {
  15291. if (EMPTY_REPEAT) {
  15292. return EMPTY_REPEAT;
  15293. }
  15294. EMPTY_REPEAT = this;
  15295. }
  15296. }
  15297. Repeat.prototype.toString = function() {
  15298. if (this.size === 0) {
  15299. return 'Repeat []';
  15300. }
  15301. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  15302. };
  15303. Repeat.prototype.get = function(index, notSetValue) {
  15304. return this.has(index) ? this._value : notSetValue;
  15305. };
  15306. Repeat.prototype.includes = function(searchValue) {
  15307. return is(this._value, searchValue);
  15308. };
  15309. Repeat.prototype.slice = function(begin, end) {
  15310. var size = this.size;
  15311. return wholeSlice(begin, end, size) ? this :
  15312. new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
  15313. };
  15314. Repeat.prototype.reverse = function() {
  15315. return this;
  15316. };
  15317. Repeat.prototype.indexOf = function(searchValue) {
  15318. if (is(this._value, searchValue)) {
  15319. return 0;
  15320. }
  15321. return -1;
  15322. };
  15323. Repeat.prototype.lastIndexOf = function(searchValue) {
  15324. if (is(this._value, searchValue)) {
  15325. return this.size;
  15326. }
  15327. return -1;
  15328. };
  15329. Repeat.prototype.__iterate = function(fn, reverse) {
  15330. for (var ii = 0; ii < this.size; ii++) {
  15331. if (fn(this._value, ii, this) === false) {
  15332. return ii + 1;
  15333. }
  15334. }
  15335. return ii;
  15336. };
  15337. Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
  15338. var ii = 0;
  15339. return new Iterator(function()
  15340. {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
  15341. );
  15342. };
  15343. Repeat.prototype.equals = function(other) {
  15344. return other instanceof Repeat ?
  15345. is(this._value, other._value) :
  15346. deepEqual(other);
  15347. };
  15348. var EMPTY_REPEAT;
  15349. function invariant(condition, error) {
  15350. if (!condition) throw new Error(error);
  15351. }
  15352. createClass(Range, IndexedSeq);
  15353. function Range(start, end, step) {
  15354. if (!(this instanceof Range)) {
  15355. return new Range(start, end, step);
  15356. }
  15357. invariant(step !== 0, 'Cannot step a Range by 0');
  15358. start = start || 0;
  15359. if (end === undefined) {
  15360. end = Infinity;
  15361. }
  15362. step = step === undefined ? 1 : Math.abs(step);
  15363. if (end < start) {
  15364. step = -step;
  15365. }
  15366. this._start = start;
  15367. this._end = end;
  15368. this._step = step;
  15369. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  15370. if (this.size === 0) {
  15371. if (EMPTY_RANGE) {
  15372. return EMPTY_RANGE;
  15373. }
  15374. EMPTY_RANGE = this;
  15375. }
  15376. }
  15377. Range.prototype.toString = function() {
  15378. if (this.size === 0) {
  15379. return 'Range []';
  15380. }
  15381. return 'Range [ ' +
  15382. this._start + '...' + this._end +
  15383. (this._step > 1 ? ' by ' + this._step : '') +
  15384. ' ]';
  15385. };
  15386. Range.prototype.get = function(index, notSetValue) {
  15387. return this.has(index) ?
  15388. this._start + wrapIndex(this, index) * this._step :
  15389. notSetValue;
  15390. };
  15391. Range.prototype.includes = function(searchValue) {
  15392. var possibleIndex = (searchValue - this._start) / this._step;
  15393. return possibleIndex >= 0 &&
  15394. possibleIndex < this.size &&
  15395. possibleIndex === Math.floor(possibleIndex);
  15396. };
  15397. Range.prototype.slice = function(begin, end) {
  15398. if (wholeSlice(begin, end, this.size)) {
  15399. return this;
  15400. }
  15401. begin = resolveBegin(begin, this.size);
  15402. end = resolveEnd(end, this.size);
  15403. if (end <= begin) {
  15404. return new Range(0, 0);
  15405. }
  15406. return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
  15407. };
  15408. Range.prototype.indexOf = function(searchValue) {
  15409. var offsetValue = searchValue - this._start;
  15410. if (offsetValue % this._step === 0) {
  15411. var index = offsetValue / this._step;
  15412. if (index >= 0 && index < this.size) {
  15413. return index
  15414. }
  15415. }
  15416. return -1;
  15417. };
  15418. Range.prototype.lastIndexOf = function(searchValue) {
  15419. return this.indexOf(searchValue);
  15420. };
  15421. Range.prototype.__iterate = function(fn, reverse) {
  15422. var maxIndex = this.size - 1;
  15423. var step = this._step;
  15424. var value = reverse ? this._start + maxIndex * step : this._start;
  15425. for (var ii = 0; ii <= maxIndex; ii++) {
  15426. if (fn(value, ii, this) === false) {
  15427. return ii + 1;
  15428. }
  15429. value += reverse ? -step : step;
  15430. }
  15431. return ii;
  15432. };
  15433. Range.prototype.__iterator = function(type, reverse) {
  15434. var maxIndex = this.size - 1;
  15435. var step = this._step;
  15436. var value = reverse ? this._start + maxIndex * step : this._start;
  15437. var ii = 0;
  15438. return new Iterator(function() {
  15439. var v = value;
  15440. value += reverse ? -step : step;
  15441. return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
  15442. });
  15443. };
  15444. Range.prototype.equals = function(other) {
  15445. return other instanceof Range ?
  15446. this._start === other._start &&
  15447. this._end === other._end &&
  15448. this._step === other._step :
  15449. deepEqual(this, other);
  15450. };
  15451. var EMPTY_RANGE;
  15452. createClass(Collection, Iterable);
  15453. function Collection() {
  15454. throw TypeError('Abstract');
  15455. }
  15456. createClass(KeyedCollection, Collection);function KeyedCollection() {}
  15457. createClass(IndexedCollection, Collection);function IndexedCollection() {}
  15458. createClass(SetCollection, Collection);function SetCollection() {}
  15459. Collection.Keyed = KeyedCollection;
  15460. Collection.Indexed = IndexedCollection;
  15461. Collection.Set = SetCollection;
  15462. var imul =
  15463. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
  15464. Math.imul :
  15465. function imul(a, b) {
  15466. a = a | 0; // int
  15467. b = b | 0; // int
  15468. var c = a & 0xffff;
  15469. var d = b & 0xffff;
  15470. // Shift by 0 fixes the sign on the high part.
  15471. return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int
  15472. };
  15473. // v8 has an optimization for storing 31-bit signed numbers.
  15474. // Values which have either 00 or 11 as the high order bits qualify.
  15475. // This function drops the highest order bit in a signed number, maintaining
  15476. // the sign bit.
  15477. function smi(i32) {
  15478. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
  15479. }
  15480. function hash(o) {
  15481. if (o === false || o === null || o === undefined) {
  15482. return 0;
  15483. }
  15484. if (typeof o.valueOf === 'function') {
  15485. o = o.valueOf();
  15486. if (o === false || o === null || o === undefined) {
  15487. return 0;
  15488. }
  15489. }
  15490. if (o === true) {
  15491. return 1;
  15492. }
  15493. var type = typeof o;
  15494. if (type === 'number') {
  15495. var h = o | 0;
  15496. if (h !== o) {
  15497. h ^= o * 0xFFFFFFFF;
  15498. }
  15499. while (o > 0xFFFFFFFF) {
  15500. o /= 0xFFFFFFFF;
  15501. h ^= o;
  15502. }
  15503. return smi(h);
  15504. }
  15505. if (type === 'string') {
  15506. return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
  15507. }
  15508. if (typeof o.hashCode === 'function') {
  15509. return o.hashCode();
  15510. }
  15511. if (type === 'object') {
  15512. return hashJSObj(o);
  15513. }
  15514. if (typeof o.toString === 'function') {
  15515. return hashString(o.toString());
  15516. }
  15517. throw new Error('Value type ' + type + ' cannot be hashed.');
  15518. }
  15519. function cachedHashString(string) {
  15520. var hash = stringHashCache[string];
  15521. if (hash === undefined) {
  15522. hash = hashString(string);
  15523. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  15524. STRING_HASH_CACHE_SIZE = 0;
  15525. stringHashCache = {};
  15526. }
  15527. STRING_HASH_CACHE_SIZE++;
  15528. stringHashCache[string] = hash;
  15529. }
  15530. return hash;
  15531. }
  15532. // http://jsperf.com/hashing-strings
  15533. function hashString(string) {
  15534. // This is the hash from JVM
  15535. // The hash code for a string is computed as
  15536. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  15537. // where s[i] is the ith character of the string and n is the length of
  15538. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  15539. // (exclusive) by dropping high bits.
  15540. var hash = 0;
  15541. for (var ii = 0; ii < string.length; ii++) {
  15542. hash = 31 * hash + string.charCodeAt(ii) | 0;
  15543. }
  15544. return smi(hash);
  15545. }
  15546. function hashJSObj(obj) {
  15547. var hash;
  15548. if (usingWeakMap) {
  15549. hash = weakMap.get(obj);
  15550. if (hash !== undefined) {
  15551. return hash;
  15552. }
  15553. }
  15554. hash = obj[UID_HASH_KEY];
  15555. if (hash !== undefined) {
  15556. return hash;
  15557. }
  15558. if (!canDefineProperty) {
  15559. hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  15560. if (hash !== undefined) {
  15561. return hash;
  15562. }
  15563. hash = getIENodeHash(obj);
  15564. if (hash !== undefined) {
  15565. return hash;
  15566. }
  15567. }
  15568. hash = ++objHashUID;
  15569. if (objHashUID & 0x40000000) {
  15570. objHashUID = 0;
  15571. }
  15572. if (usingWeakMap) {
  15573. weakMap.set(obj, hash);
  15574. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  15575. throw new Error('Non-extensible objects are not allowed as keys.');
  15576. } else if (canDefineProperty) {
  15577. Object.defineProperty(obj, UID_HASH_KEY, {
  15578. 'enumerable': false,
  15579. 'configurable': false,
  15580. 'writable': false,
  15581. 'value': hash
  15582. });
  15583. } else if (obj.propertyIsEnumerable !== undefined &&
  15584. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
  15585. // Since we can't define a non-enumerable property on the object
  15586. // we'll hijack one of the less-used non-enumerable properties to
  15587. // save our hash on it. Since this is a function it will not show up in
  15588. // `JSON.stringify` which is what we want.
  15589. obj.propertyIsEnumerable = function() {
  15590. return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
  15591. };
  15592. obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
  15593. } else if (obj.nodeType !== undefined) {
  15594. // At this point we couldn't get the IE `uniqueID` to use as a hash
  15595. // and we couldn't use a non-enumerable property to exploit the
  15596. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  15597. // itself.
  15598. obj[UID_HASH_KEY] = hash;
  15599. } else {
  15600. throw new Error('Unable to set a non-enumerable property on object.');
  15601. }
  15602. return hash;
  15603. }
  15604. // Get references to ES5 object methods.
  15605. var isExtensible = Object.isExtensible;
  15606. // True if Object.defineProperty works as expected. IE8 fails this test.
  15607. var canDefineProperty = (function() {
  15608. try {
  15609. Object.defineProperty({}, '@', {});
  15610. return true;
  15611. } catch (e) {
  15612. return false;
  15613. }
  15614. }());
  15615. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  15616. // and avoid memory leaks from the IE cloneNode bug.
  15617. function getIENodeHash(node) {
  15618. if (node && node.nodeType > 0) {
  15619. switch (node.nodeType) {
  15620. case 1: // Element
  15621. return node.uniqueID;
  15622. case 9: // Document
  15623. return node.documentElement && node.documentElement.uniqueID;
  15624. }
  15625. }
  15626. }
  15627. // If possible, use a WeakMap.
  15628. var usingWeakMap = typeof WeakMap === 'function';
  15629. var weakMap;
  15630. if (usingWeakMap) {
  15631. weakMap = new WeakMap();
  15632. }
  15633. var objHashUID = 0;
  15634. var UID_HASH_KEY = '__immutablehash__';
  15635. if (typeof Symbol === 'function') {
  15636. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  15637. }
  15638. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  15639. var STRING_HASH_CACHE_MAX_SIZE = 255;
  15640. var STRING_HASH_CACHE_SIZE = 0;
  15641. var stringHashCache = {};
  15642. function assertNotInfinite(size) {
  15643. invariant(
  15644. size !== Infinity,
  15645. 'Cannot perform this action with an infinite size.'
  15646. );
  15647. }
  15648. createClass(Map, KeyedCollection);
  15649. // @pragma Construction
  15650. function Map(value) {
  15651. return value === null || value === undefined ? emptyMap() :
  15652. isMap(value) && !isOrdered(value) ? value :
  15653. emptyMap().withMutations(function(map ) {
  15654. var iter = KeyedIterable(value);
  15655. assertNotInfinite(iter.size);
  15656. iter.forEach(function(v, k) {return map.set(k, v)});
  15657. });
  15658. }
  15659. Map.prototype.toString = function() {
  15660. return this.__toString('Map {', '}');
  15661. };
  15662. // @pragma Access
  15663. Map.prototype.get = function(k, notSetValue) {
  15664. return this._root ?
  15665. this._root.get(0, undefined, k, notSetValue) :
  15666. notSetValue;
  15667. };
  15668. // @pragma Modification
  15669. Map.prototype.set = function(k, v) {
  15670. return updateMap(this, k, v);
  15671. };
  15672. Map.prototype.setIn = function(keyPath, v) {
  15673. return this.updateIn(keyPath, NOT_SET, function() {return v});
  15674. };
  15675. Map.prototype.remove = function(k) {
  15676. return updateMap(this, k, NOT_SET);
  15677. };
  15678. Map.prototype.deleteIn = function(keyPath) {
  15679. return this.updateIn(keyPath, function() {return NOT_SET});
  15680. };
  15681. Map.prototype.update = function(k, notSetValue, updater) {
  15682. return arguments.length === 1 ?
  15683. k(this) :
  15684. this.updateIn([k], notSetValue, updater);
  15685. };
  15686. Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
  15687. if (!updater) {
  15688. updater = notSetValue;
  15689. notSetValue = undefined;
  15690. }
  15691. var updatedValue = updateInDeepMap(
  15692. this,
  15693. forceIterator(keyPath),
  15694. notSetValue,
  15695. updater
  15696. );
  15697. return updatedValue === NOT_SET ? undefined : updatedValue;
  15698. };
  15699. Map.prototype.clear = function() {
  15700. if (this.size === 0) {
  15701. return this;
  15702. }
  15703. if (this.__ownerID) {
  15704. this.size = 0;
  15705. this._root = null;
  15706. this.__hash = undefined;
  15707. this.__altered = true;
  15708. return this;
  15709. }
  15710. return emptyMap();
  15711. };
  15712. // @pragma Composition
  15713. Map.prototype.merge = function(/*...iters*/) {
  15714. return mergeIntoMapWith(this, undefined, arguments);
  15715. };
  15716. Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  15717. return mergeIntoMapWith(this, merger, iters);
  15718. };
  15719. Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  15720. return this.updateIn(
  15721. keyPath,
  15722. emptyMap(),
  15723. function(m ) {return typeof m.merge === 'function' ?
  15724. m.merge.apply(m, iters) :
  15725. iters[iters.length - 1]}
  15726. );
  15727. };
  15728. Map.prototype.mergeDeep = function(/*...iters*/) {
  15729. return mergeIntoMapWith(this, deepMerger, arguments);
  15730. };
  15731. Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  15732. return mergeIntoMapWith(this, deepMergerWith(merger), iters);
  15733. };
  15734. Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  15735. return this.updateIn(
  15736. keyPath,
  15737. emptyMap(),
  15738. function(m ) {return typeof m.mergeDeep === 'function' ?
  15739. m.mergeDeep.apply(m, iters) :
  15740. iters[iters.length - 1]}
  15741. );
  15742. };
  15743. Map.prototype.sort = function(comparator) {
  15744. // Late binding
  15745. return OrderedMap(sortFactory(this, comparator));
  15746. };
  15747. Map.prototype.sortBy = function(mapper, comparator) {
  15748. // Late binding
  15749. return OrderedMap(sortFactory(this, comparator, mapper));
  15750. };
  15751. // @pragma Mutability
  15752. Map.prototype.withMutations = function(fn) {
  15753. var mutable = this.asMutable();
  15754. fn(mutable);
  15755. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  15756. };
  15757. Map.prototype.asMutable = function() {
  15758. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  15759. };
  15760. Map.prototype.asImmutable = function() {
  15761. return this.__ensureOwner();
  15762. };
  15763. Map.prototype.wasAltered = function() {
  15764. return this.__altered;
  15765. };
  15766. Map.prototype.__iterator = function(type, reverse) {
  15767. return new MapIterator(this, type, reverse);
  15768. };
  15769. Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  15770. var iterations = 0;
  15771. this._root && this._root.iterate(function(entry ) {
  15772. iterations++;
  15773. return fn(entry[1], entry[0], this$0);
  15774. }, reverse);
  15775. return iterations;
  15776. };
  15777. Map.prototype.__ensureOwner = function(ownerID) {
  15778. if (ownerID === this.__ownerID) {
  15779. return this;
  15780. }
  15781. if (!ownerID) {
  15782. this.__ownerID = ownerID;
  15783. this.__altered = false;
  15784. return this;
  15785. }
  15786. return makeMap(this.size, this._root, ownerID, this.__hash);
  15787. };
  15788. function isMap(maybeMap) {
  15789. return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
  15790. }
  15791. Map.isMap = isMap;
  15792. var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
  15793. var MapPrototype = Map.prototype;
  15794. MapPrototype[IS_MAP_SENTINEL] = true;
  15795. MapPrototype[DELETE] = MapPrototype.remove;
  15796. MapPrototype.removeIn = MapPrototype.deleteIn;
  15797. // #pragma Trie Nodes
  15798. function ArrayMapNode(ownerID, entries) {
  15799. this.ownerID = ownerID;
  15800. this.entries = entries;
  15801. }
  15802. ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  15803. var entries = this.entries;
  15804. for (var ii = 0, len = entries.length; ii < len; ii++) {
  15805. if (is(key, entries[ii][0])) {
  15806. return entries[ii][1];
  15807. }
  15808. }
  15809. return notSetValue;
  15810. };
  15811. ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  15812. var removed = value === NOT_SET;
  15813. var entries = this.entries;
  15814. var idx = 0;
  15815. for (var len = entries.length; idx < len; idx++) {
  15816. if (is(key, entries[idx][0])) {
  15817. break;
  15818. }
  15819. }
  15820. var exists = idx < len;
  15821. if (exists ? entries[idx][1] === value : removed) {
  15822. return this;
  15823. }
  15824. SetRef(didAlter);
  15825. (removed || !exists) && SetRef(didChangeSize);
  15826. if (removed && entries.length === 1) {
  15827. return; // undefined
  15828. }
  15829. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  15830. return createNodes(ownerID, entries, key, value);
  15831. }
  15832. var isEditable = ownerID && ownerID === this.ownerID;
  15833. var newEntries = isEditable ? entries : arrCopy(entries);
  15834. if (exists) {
  15835. if (removed) {
  15836. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  15837. } else {
  15838. newEntries[idx] = [key, value];
  15839. }
  15840. } else {
  15841. newEntries.push([key, value]);
  15842. }
  15843. if (isEditable) {
  15844. this.entries = newEntries;
  15845. return this;
  15846. }
  15847. return new ArrayMapNode(ownerID, newEntries);
  15848. };
  15849. function BitmapIndexedNode(ownerID, bitmap, nodes) {
  15850. this.ownerID = ownerID;
  15851. this.bitmap = bitmap;
  15852. this.nodes = nodes;
  15853. }
  15854. BitmapIndexedNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  15855. if (keyHash === undefined) {
  15856. keyHash = hash(key);
  15857. }
  15858. var bit = (1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK));
  15859. var bitmap = this.bitmap;
  15860. return (bitmap & bit) === 0 ? notSetValue :
  15861. this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue);
  15862. };
  15863. BitmapIndexedNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  15864. if (keyHash === undefined) {
  15865. keyHash = hash(key);
  15866. }
  15867. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  15868. var bit = 1 << keyHashFrag;
  15869. var bitmap = this.bitmap;
  15870. var exists = (bitmap & bit) !== 0;
  15871. if (!exists && value === NOT_SET) {
  15872. return this;
  15873. }
  15874. var idx = popCount(bitmap & (bit - 1));
  15875. var nodes = this.nodes;
  15876. var node = exists ? nodes[idx] : undefined;
  15877. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  15878. if (newNode === node) {
  15879. return this;
  15880. }
  15881. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  15882. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  15883. }
  15884. if (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) {
  15885. return nodes[idx ^ 1];
  15886. }
  15887. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  15888. return newNode;
  15889. }
  15890. var isEditable = ownerID && ownerID === this.ownerID;
  15891. var newBitmap = exists ? newNode ? bitmap : bitmap ^ bit : bitmap | bit;
  15892. var newNodes = exists ? newNode ?
  15893. setIn(nodes, idx, newNode, isEditable) :
  15894. spliceOut(nodes, idx, isEditable) :
  15895. spliceIn(nodes, idx, newNode, isEditable);
  15896. if (isEditable) {
  15897. this.bitmap = newBitmap;
  15898. this.nodes = newNodes;
  15899. return this;
  15900. }
  15901. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  15902. };
  15903. function HashArrayMapNode(ownerID, count, nodes) {
  15904. this.ownerID = ownerID;
  15905. this.count = count;
  15906. this.nodes = nodes;
  15907. }
  15908. HashArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  15909. if (keyHash === undefined) {
  15910. keyHash = hash(key);
  15911. }
  15912. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  15913. var node = this.nodes[idx];
  15914. return node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue;
  15915. };
  15916. HashArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  15917. if (keyHash === undefined) {
  15918. keyHash = hash(key);
  15919. }
  15920. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  15921. var removed = value === NOT_SET;
  15922. var nodes = this.nodes;
  15923. var node = nodes[idx];
  15924. if (removed && !node) {
  15925. return this;
  15926. }
  15927. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  15928. if (newNode === node) {
  15929. return this;
  15930. }
  15931. var newCount = this.count;
  15932. if (!node) {
  15933. newCount++;
  15934. } else if (!newNode) {
  15935. newCount--;
  15936. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  15937. return packNodes(ownerID, nodes, newCount, idx);
  15938. }
  15939. }
  15940. var isEditable = ownerID && ownerID === this.ownerID;
  15941. var newNodes = setIn(nodes, idx, newNode, isEditable);
  15942. if (isEditable) {
  15943. this.count = newCount;
  15944. this.nodes = newNodes;
  15945. return this;
  15946. }
  15947. return new HashArrayMapNode(ownerID, newCount, newNodes);
  15948. };
  15949. function HashCollisionNode(ownerID, keyHash, entries) {
  15950. this.ownerID = ownerID;
  15951. this.keyHash = keyHash;
  15952. this.entries = entries;
  15953. }
  15954. HashCollisionNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  15955. var entries = this.entries;
  15956. for (var ii = 0, len = entries.length; ii < len; ii++) {
  15957. if (is(key, entries[ii][0])) {
  15958. return entries[ii][1];
  15959. }
  15960. }
  15961. return notSetValue;
  15962. };
  15963. HashCollisionNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  15964. if (keyHash === undefined) {
  15965. keyHash = hash(key);
  15966. }
  15967. var removed = value === NOT_SET;
  15968. if (keyHash !== this.keyHash) {
  15969. if (removed) {
  15970. return this;
  15971. }
  15972. SetRef(didAlter);
  15973. SetRef(didChangeSize);
  15974. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  15975. }
  15976. var entries = this.entries;
  15977. var idx = 0;
  15978. for (var len = entries.length; idx < len; idx++) {
  15979. if (is(key, entries[idx][0])) {
  15980. break;
  15981. }
  15982. }
  15983. var exists = idx < len;
  15984. if (exists ? entries[idx][1] === value : removed) {
  15985. return this;
  15986. }
  15987. SetRef(didAlter);
  15988. (removed || !exists) && SetRef(didChangeSize);
  15989. if (removed && len === 2) {
  15990. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  15991. }
  15992. var isEditable = ownerID && ownerID === this.ownerID;
  15993. var newEntries = isEditable ? entries : arrCopy(entries);
  15994. if (exists) {
  15995. if (removed) {
  15996. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  15997. } else {
  15998. newEntries[idx] = [key, value];
  15999. }
  16000. } else {
  16001. newEntries.push([key, value]);
  16002. }
  16003. if (isEditable) {
  16004. this.entries = newEntries;
  16005. return this;
  16006. }
  16007. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  16008. };
  16009. function ValueNode(ownerID, keyHash, entry) {
  16010. this.ownerID = ownerID;
  16011. this.keyHash = keyHash;
  16012. this.entry = entry;
  16013. }
  16014. ValueNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  16015. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  16016. };
  16017. ValueNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  16018. var removed = value === NOT_SET;
  16019. var keyMatch = is(key, this.entry[0]);
  16020. if (keyMatch ? value === this.entry[1] : removed) {
  16021. return this;
  16022. }
  16023. SetRef(didAlter);
  16024. if (removed) {
  16025. SetRef(didChangeSize);
  16026. return; // undefined
  16027. }
  16028. if (keyMatch) {
  16029. if (ownerID && ownerID === this.ownerID) {
  16030. this.entry[1] = value;
  16031. return this;
  16032. }
  16033. return new ValueNode(ownerID, this.keyHash, [key, value]);
  16034. }
  16035. SetRef(didChangeSize);
  16036. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  16037. };
  16038. // #pragma Iterators
  16039. ArrayMapNode.prototype.iterate =
  16040. HashCollisionNode.prototype.iterate = function (fn, reverse) {
  16041. var entries = this.entries;
  16042. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  16043. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  16044. return false;
  16045. }
  16046. }
  16047. };
  16048. BitmapIndexedNode.prototype.iterate =
  16049. HashArrayMapNode.prototype.iterate = function (fn, reverse) {
  16050. var nodes = this.nodes;
  16051. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  16052. var node = nodes[reverse ? maxIndex - ii : ii];
  16053. if (node && node.iterate(fn, reverse) === false) {
  16054. return false;
  16055. }
  16056. }
  16057. };
  16058. ValueNode.prototype.iterate = function (fn, reverse) {
  16059. return fn(this.entry);
  16060. };
  16061. createClass(MapIterator, Iterator);
  16062. function MapIterator(map, type, reverse) {
  16063. this._type = type;
  16064. this._reverse = reverse;
  16065. this._stack = map._root && mapIteratorFrame(map._root);
  16066. }
  16067. MapIterator.prototype.next = function() {
  16068. var type = this._type;
  16069. var stack = this._stack;
  16070. while (stack) {
  16071. var node = stack.node;
  16072. var index = stack.index++;
  16073. var maxIndex;
  16074. if (node.entry) {
  16075. if (index === 0) {
  16076. return mapIteratorValue(type, node.entry);
  16077. }
  16078. } else if (node.entries) {
  16079. maxIndex = node.entries.length - 1;
  16080. if (index <= maxIndex) {
  16081. return mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index]);
  16082. }
  16083. } else {
  16084. maxIndex = node.nodes.length - 1;
  16085. if (index <= maxIndex) {
  16086. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  16087. if (subNode) {
  16088. if (subNode.entry) {
  16089. return mapIteratorValue(type, subNode.entry);
  16090. }
  16091. stack = this._stack = mapIteratorFrame(subNode, stack);
  16092. }
  16093. continue;
  16094. }
  16095. }
  16096. stack = this._stack = this._stack.__prev;
  16097. }
  16098. return iteratorDone();
  16099. };
  16100. function mapIteratorValue(type, entry) {
  16101. return iteratorValue(type, entry[0], entry[1]);
  16102. }
  16103. function mapIteratorFrame(node, prev) {
  16104. return {
  16105. node: node,
  16106. index: 0,
  16107. __prev: prev
  16108. };
  16109. }
  16110. function makeMap(size, root, ownerID, hash) {
  16111. var map = Object.create(MapPrototype);
  16112. map.size = size;
  16113. map._root = root;
  16114. map.__ownerID = ownerID;
  16115. map.__hash = hash;
  16116. map.__altered = false;
  16117. return map;
  16118. }
  16119. var EMPTY_MAP;
  16120. function emptyMap() {
  16121. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  16122. }
  16123. function updateMap(map, k, v) {
  16124. var newRoot;
  16125. var newSize;
  16126. if (!map._root) {
  16127. if (v === NOT_SET) {
  16128. return map;
  16129. }
  16130. newSize = 1;
  16131. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  16132. } else {
  16133. var didChangeSize = MakeRef(CHANGE_LENGTH);
  16134. var didAlter = MakeRef(DID_ALTER);
  16135. newRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter);
  16136. if (!didAlter.value) {
  16137. return map;
  16138. }
  16139. newSize = map.size + (didChangeSize.value ? v === NOT_SET ? -1 : 1 : 0);
  16140. }
  16141. if (map.__ownerID) {
  16142. map.size = newSize;
  16143. map._root = newRoot;
  16144. map.__hash = undefined;
  16145. map.__altered = true;
  16146. return map;
  16147. }
  16148. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  16149. }
  16150. function updateNode(node, ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  16151. if (!node) {
  16152. if (value === NOT_SET) {
  16153. return node;
  16154. }
  16155. SetRef(didAlter);
  16156. SetRef(didChangeSize);
  16157. return new ValueNode(ownerID, keyHash, [key, value]);
  16158. }
  16159. return node.update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter);
  16160. }
  16161. function isLeafNode(node) {
  16162. return node.constructor === ValueNode || node.constructor === HashCollisionNode;
  16163. }
  16164. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  16165. if (node.keyHash === keyHash) {
  16166. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  16167. }
  16168. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  16169. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  16170. var newNode;
  16171. var nodes = idx1 === idx2 ?
  16172. [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)] :
  16173. ((newNode = new ValueNode(ownerID, keyHash, entry)), idx1 < idx2 ? [node, newNode] : [newNode, node]);
  16174. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  16175. }
  16176. function createNodes(ownerID, entries, key, value) {
  16177. if (!ownerID) {
  16178. ownerID = new OwnerID();
  16179. }
  16180. var node = new ValueNode(ownerID, hash(key), [key, value]);
  16181. for (var ii = 0; ii < entries.length; ii++) {
  16182. var entry = entries[ii];
  16183. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  16184. }
  16185. return node;
  16186. }
  16187. function packNodes(ownerID, nodes, count, excluding) {
  16188. var bitmap = 0;
  16189. var packedII = 0;
  16190. var packedNodes = new Array(count);
  16191. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  16192. var node = nodes[ii];
  16193. if (node !== undefined && ii !== excluding) {
  16194. bitmap |= bit;
  16195. packedNodes[packedII++] = node;
  16196. }
  16197. }
  16198. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  16199. }
  16200. function expandNodes(ownerID, nodes, bitmap, including, node) {
  16201. var count = 0;
  16202. var expandedNodes = new Array(SIZE);
  16203. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  16204. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  16205. }
  16206. expandedNodes[including] = node;
  16207. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  16208. }
  16209. function mergeIntoMapWith(map, merger, iterables) {
  16210. var iters = [];
  16211. for (var ii = 0; ii < iterables.length; ii++) {
  16212. var value = iterables[ii];
  16213. var iter = KeyedIterable(value);
  16214. if (!isIterable(value)) {
  16215. iter = iter.map(function(v ) {return fromJS(v)});
  16216. }
  16217. iters.push(iter);
  16218. }
  16219. return mergeIntoCollectionWith(map, merger, iters);
  16220. }
  16221. function deepMerger(existing, value, key) {
  16222. return existing && existing.mergeDeep && isIterable(value) ?
  16223. existing.mergeDeep(value) :
  16224. is(existing, value) ? existing : value;
  16225. }
  16226. function deepMergerWith(merger) {
  16227. return function(existing, value, key) {
  16228. if (existing && existing.mergeDeepWith && isIterable(value)) {
  16229. return existing.mergeDeepWith(merger, value);
  16230. }
  16231. var nextValue = merger(existing, value, key);
  16232. return is(existing, nextValue) ? existing : nextValue;
  16233. };
  16234. }
  16235. function mergeIntoCollectionWith(collection, merger, iters) {
  16236. iters = iters.filter(function(x ) {return x.size !== 0});
  16237. if (iters.length === 0) {
  16238. return collection;
  16239. }
  16240. if (collection.size === 0 && !collection.__ownerID && iters.length === 1) {
  16241. return collection.constructor(iters[0]);
  16242. }
  16243. return collection.withMutations(function(collection ) {
  16244. var mergeIntoMap = merger ?
  16245. function(value, key) {
  16246. collection.update(key, NOT_SET, function(existing )
  16247. {return existing === NOT_SET ? value : merger(existing, value, key)}
  16248. );
  16249. } :
  16250. function(value, key) {
  16251. collection.set(key, value);
  16252. };
  16253. for (var ii = 0; ii < iters.length; ii++) {
  16254. iters[ii].forEach(mergeIntoMap);
  16255. }
  16256. });
  16257. }
  16258. function updateInDeepMap(existing, keyPathIter, notSetValue, updater) {
  16259. var isNotSet = existing === NOT_SET;
  16260. var step = keyPathIter.next();
  16261. if (step.done) {
  16262. var existingValue = isNotSet ? notSetValue : existing;
  16263. var newValue = updater(existingValue);
  16264. return newValue === existingValue ? existing : newValue;
  16265. }
  16266. invariant(
  16267. isNotSet || (existing && existing.set),
  16268. 'invalid keyPath'
  16269. );
  16270. var key = step.value;
  16271. var nextExisting = isNotSet ? NOT_SET : existing.get(key, NOT_SET);
  16272. var nextUpdated = updateInDeepMap(
  16273. nextExisting,
  16274. keyPathIter,
  16275. notSetValue,
  16276. updater
  16277. );
  16278. return nextUpdated === nextExisting ? existing :
  16279. nextUpdated === NOT_SET ? existing.remove(key) :
  16280. (isNotSet ? emptyMap() : existing).set(key, nextUpdated);
  16281. }
  16282. function popCount(x) {
  16283. x = x - ((x >> 1) & 0x55555555);
  16284. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  16285. x = (x + (x >> 4)) & 0x0f0f0f0f;
  16286. x = x + (x >> 8);
  16287. x = x + (x >> 16);
  16288. return x & 0x7f;
  16289. }
  16290. function setIn(array, idx, val, canEdit) {
  16291. var newArray = canEdit ? array : arrCopy(array);
  16292. newArray[idx] = val;
  16293. return newArray;
  16294. }
  16295. function spliceIn(array, idx, val, canEdit) {
  16296. var newLen = array.length + 1;
  16297. if (canEdit && idx + 1 === newLen) {
  16298. array[idx] = val;
  16299. return array;
  16300. }
  16301. var newArray = new Array(newLen);
  16302. var after = 0;
  16303. for (var ii = 0; ii < newLen; ii++) {
  16304. if (ii === idx) {
  16305. newArray[ii] = val;
  16306. after = -1;
  16307. } else {
  16308. newArray[ii] = array[ii + after];
  16309. }
  16310. }
  16311. return newArray;
  16312. }
  16313. function spliceOut(array, idx, canEdit) {
  16314. var newLen = array.length - 1;
  16315. if (canEdit && idx === newLen) {
  16316. array.pop();
  16317. return array;
  16318. }
  16319. var newArray = new Array(newLen);
  16320. var after = 0;
  16321. for (var ii = 0; ii < newLen; ii++) {
  16322. if (ii === idx) {
  16323. after = 1;
  16324. }
  16325. newArray[ii] = array[ii + after];
  16326. }
  16327. return newArray;
  16328. }
  16329. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  16330. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  16331. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  16332. createClass(List, IndexedCollection);
  16333. // @pragma Construction
  16334. function List(value) {
  16335. var empty = emptyList();
  16336. if (value === null || value === undefined) {
  16337. return empty;
  16338. }
  16339. if (isList(value)) {
  16340. return value;
  16341. }
  16342. var iter = IndexedIterable(value);
  16343. var size = iter.size;
  16344. if (size === 0) {
  16345. return empty;
  16346. }
  16347. assertNotInfinite(size);
  16348. if (size > 0 && size < SIZE) {
  16349. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  16350. }
  16351. return empty.withMutations(function(list ) {
  16352. list.setSize(size);
  16353. iter.forEach(function(v, i) {return list.set(i, v)});
  16354. });
  16355. }
  16356. List.of = function(/*...values*/) {
  16357. return this(arguments);
  16358. };
  16359. List.prototype.toString = function() {
  16360. return this.__toString('List [', ']');
  16361. };
  16362. // @pragma Access
  16363. List.prototype.get = function(index, notSetValue) {
  16364. index = wrapIndex(this, index);
  16365. if (index >= 0 && index < this.size) {
  16366. index += this._origin;
  16367. var node = listNodeFor(this, index);
  16368. return node && node.array[index & MASK];
  16369. }
  16370. return notSetValue;
  16371. };
  16372. // @pragma Modification
  16373. List.prototype.set = function(index, value) {
  16374. return updateList(this, index, value);
  16375. };
  16376. List.prototype.remove = function(index) {
  16377. return !this.has(index) ? this :
  16378. index === 0 ? this.shift() :
  16379. index === this.size - 1 ? this.pop() :
  16380. this.splice(index, 1);
  16381. };
  16382. List.prototype.insert = function(index, value) {
  16383. return this.splice(index, 0, value);
  16384. };
  16385. List.prototype.clear = function() {
  16386. if (this.size === 0) {
  16387. return this;
  16388. }
  16389. if (this.__ownerID) {
  16390. this.size = this._origin = this._capacity = 0;
  16391. this._level = SHIFT;
  16392. this._root = this._tail = null;
  16393. this.__hash = undefined;
  16394. this.__altered = true;
  16395. return this;
  16396. }
  16397. return emptyList();
  16398. };
  16399. List.prototype.push = function(/*...values*/) {
  16400. var values = arguments;
  16401. var oldSize = this.size;
  16402. return this.withMutations(function(list ) {
  16403. setListBounds(list, 0, oldSize + values.length);
  16404. for (var ii = 0; ii < values.length; ii++) {
  16405. list.set(oldSize + ii, values[ii]);
  16406. }
  16407. });
  16408. };
  16409. List.prototype.pop = function() {
  16410. return setListBounds(this, 0, -1);
  16411. };
  16412. List.prototype.unshift = function(/*...values*/) {
  16413. var values = arguments;
  16414. return this.withMutations(function(list ) {
  16415. setListBounds(list, -values.length);
  16416. for (var ii = 0; ii < values.length; ii++) {
  16417. list.set(ii, values[ii]);
  16418. }
  16419. });
  16420. };
  16421. List.prototype.shift = function() {
  16422. return setListBounds(this, 1);
  16423. };
  16424. // @pragma Composition
  16425. List.prototype.merge = function(/*...iters*/) {
  16426. return mergeIntoListWith(this, undefined, arguments);
  16427. };
  16428. List.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  16429. return mergeIntoListWith(this, merger, iters);
  16430. };
  16431. List.prototype.mergeDeep = function(/*...iters*/) {
  16432. return mergeIntoListWith(this, deepMerger, arguments);
  16433. };
  16434. List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  16435. return mergeIntoListWith(this, deepMergerWith(merger), iters);
  16436. };
  16437. List.prototype.setSize = function(size) {
  16438. return setListBounds(this, 0, size);
  16439. };
  16440. // @pragma Iteration
  16441. List.prototype.slice = function(begin, end) {
  16442. var size = this.size;
  16443. if (wholeSlice(begin, end, size)) {
  16444. return this;
  16445. }
  16446. return setListBounds(
  16447. this,
  16448. resolveBegin(begin, size),
  16449. resolveEnd(end, size)
  16450. );
  16451. };
  16452. List.prototype.__iterator = function(type, reverse) {
  16453. var index = 0;
  16454. var values = iterateList(this, reverse);
  16455. return new Iterator(function() {
  16456. var value = values();
  16457. return value === DONE ?
  16458. iteratorDone() :
  16459. iteratorValue(type, index++, value);
  16460. });
  16461. };
  16462. List.prototype.__iterate = function(fn, reverse) {
  16463. var index = 0;
  16464. var values = iterateList(this, reverse);
  16465. var value;
  16466. while ((value = values()) !== DONE) {
  16467. if (fn(value, index++, this) === false) {
  16468. break;
  16469. }
  16470. }
  16471. return index;
  16472. };
  16473. List.prototype.__ensureOwner = function(ownerID) {
  16474. if (ownerID === this.__ownerID) {
  16475. return this;
  16476. }
  16477. if (!ownerID) {
  16478. this.__ownerID = ownerID;
  16479. return this;
  16480. }
  16481. return makeList(this._origin, this._capacity, this._level, this._root, this._tail, ownerID, this.__hash);
  16482. };
  16483. function isList(maybeList) {
  16484. return !!(maybeList && maybeList[IS_LIST_SENTINEL]);
  16485. }
  16486. List.isList = isList;
  16487. var IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
  16488. var ListPrototype = List.prototype;
  16489. ListPrototype[IS_LIST_SENTINEL] = true;
  16490. ListPrototype[DELETE] = ListPrototype.remove;
  16491. ListPrototype.setIn = MapPrototype.setIn;
  16492. ListPrototype.deleteIn =
  16493. ListPrototype.removeIn = MapPrototype.removeIn;
  16494. ListPrototype.update = MapPrototype.update;
  16495. ListPrototype.updateIn = MapPrototype.updateIn;
  16496. ListPrototype.mergeIn = MapPrototype.mergeIn;
  16497. ListPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  16498. ListPrototype.withMutations = MapPrototype.withMutations;
  16499. ListPrototype.asMutable = MapPrototype.asMutable;
  16500. ListPrototype.asImmutable = MapPrototype.asImmutable;
  16501. ListPrototype.wasAltered = MapPrototype.wasAltered;
  16502. function VNode(array, ownerID) {
  16503. this.array = array;
  16504. this.ownerID = ownerID;
  16505. }
  16506. // TODO: seems like these methods are very similar
  16507. VNode.prototype.removeBefore = function(ownerID, level, index) {
  16508. if (index === level ? 1 << level : this.array.length === 0) {
  16509. return this;
  16510. }
  16511. var originIndex = (index >>> level) & MASK;
  16512. if (originIndex >= this.array.length) {
  16513. return new VNode([], ownerID);
  16514. }
  16515. var removingFirst = originIndex === 0;
  16516. var newChild;
  16517. if (level > 0) {
  16518. var oldChild = this.array[originIndex];
  16519. newChild = oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  16520. if (newChild === oldChild && removingFirst) {
  16521. return this;
  16522. }
  16523. }
  16524. if (removingFirst && !newChild) {
  16525. return this;
  16526. }
  16527. var editable = editableVNode(this, ownerID);
  16528. if (!removingFirst) {
  16529. for (var ii = 0; ii < originIndex; ii++) {
  16530. editable.array[ii] = undefined;
  16531. }
  16532. }
  16533. if (newChild) {
  16534. editable.array[originIndex] = newChild;
  16535. }
  16536. return editable;
  16537. };
  16538. VNode.prototype.removeAfter = function(ownerID, level, index) {
  16539. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  16540. return this;
  16541. }
  16542. var sizeIndex = ((index - 1) >>> level) & MASK;
  16543. if (sizeIndex >= this.array.length) {
  16544. return this;
  16545. }
  16546. var newChild;
  16547. if (level > 0) {
  16548. var oldChild = this.array[sizeIndex];
  16549. newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  16550. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  16551. return this;
  16552. }
  16553. }
  16554. var editable = editableVNode(this, ownerID);
  16555. editable.array.splice(sizeIndex + 1);
  16556. if (newChild) {
  16557. editable.array[sizeIndex] = newChild;
  16558. }
  16559. return editable;
  16560. };
  16561. var DONE = {};
  16562. function iterateList(list, reverse) {
  16563. var left = list._origin;
  16564. var right = list._capacity;
  16565. var tailPos = getTailOffset(right);
  16566. var tail = list._tail;
  16567. return iterateNodeOrLeaf(list._root, list._level, 0);
  16568. function iterateNodeOrLeaf(node, level, offset) {
  16569. return level === 0 ?
  16570. iterateLeaf(node, offset) :
  16571. iterateNode(node, level, offset);
  16572. }
  16573. function iterateLeaf(node, offset) {
  16574. var array = offset === tailPos ? tail && tail.array : node && node.array;
  16575. var from = offset > left ? 0 : left - offset;
  16576. var to = right - offset;
  16577. if (to > SIZE) {
  16578. to = SIZE;
  16579. }
  16580. return function() {
  16581. if (from === to) {
  16582. return DONE;
  16583. }
  16584. var idx = reverse ? --to : from++;
  16585. return array && array[idx];
  16586. };
  16587. }
  16588. function iterateNode(node, level, offset) {
  16589. var values;
  16590. var array = node && node.array;
  16591. var from = offset > left ? 0 : (left - offset) >> level;
  16592. var to = ((right - offset) >> level) + 1;
  16593. if (to > SIZE) {
  16594. to = SIZE;
  16595. }
  16596. return function() {
  16597. do {
  16598. if (values) {
  16599. var value = values();
  16600. if (value !== DONE) {
  16601. return value;
  16602. }
  16603. values = null;
  16604. }
  16605. if (from === to) {
  16606. return DONE;
  16607. }
  16608. var idx = reverse ? --to : from++;
  16609. values = iterateNodeOrLeaf(
  16610. array && array[idx], level - SHIFT, offset + (idx << level)
  16611. );
  16612. } while (true);
  16613. };
  16614. }
  16615. }
  16616. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  16617. var list = Object.create(ListPrototype);
  16618. list.size = capacity - origin;
  16619. list._origin = origin;
  16620. list._capacity = capacity;
  16621. list._level = level;
  16622. list._root = root;
  16623. list._tail = tail;
  16624. list.__ownerID = ownerID;
  16625. list.__hash = hash;
  16626. list.__altered = false;
  16627. return list;
  16628. }
  16629. var EMPTY_LIST;
  16630. function emptyList() {
  16631. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  16632. }
  16633. function updateList(list, index, value) {
  16634. index = wrapIndex(list, index);
  16635. if (index !== index) {
  16636. return list;
  16637. }
  16638. if (index >= list.size || index < 0) {
  16639. return list.withMutations(function(list ) {
  16640. index < 0 ?
  16641. setListBounds(list, index).set(0, value) :
  16642. setListBounds(list, 0, index + 1).set(index, value);
  16643. });
  16644. }
  16645. index += list._origin;
  16646. var newTail = list._tail;
  16647. var newRoot = list._root;
  16648. var didAlter = MakeRef(DID_ALTER);
  16649. if (index >= getTailOffset(list._capacity)) {
  16650. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  16651. } else {
  16652. newRoot = updateVNode(newRoot, list.__ownerID, list._level, index, value, didAlter);
  16653. }
  16654. if (!didAlter.value) {
  16655. return list;
  16656. }
  16657. if (list.__ownerID) {
  16658. list._root = newRoot;
  16659. list._tail = newTail;
  16660. list.__hash = undefined;
  16661. list.__altered = true;
  16662. return list;
  16663. }
  16664. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  16665. }
  16666. function updateVNode(node, ownerID, level, index, value, didAlter) {
  16667. var idx = (index >>> level) & MASK;
  16668. var nodeHas = node && idx < node.array.length;
  16669. if (!nodeHas && value === undefined) {
  16670. return node;
  16671. }
  16672. var newNode;
  16673. if (level > 0) {
  16674. var lowerNode = node && node.array[idx];
  16675. var newLowerNode = updateVNode(lowerNode, ownerID, level - SHIFT, index, value, didAlter);
  16676. if (newLowerNode === lowerNode) {
  16677. return node;
  16678. }
  16679. newNode = editableVNode(node, ownerID);
  16680. newNode.array[idx] = newLowerNode;
  16681. return newNode;
  16682. }
  16683. if (nodeHas && node.array[idx] === value) {
  16684. return node;
  16685. }
  16686. SetRef(didAlter);
  16687. newNode = editableVNode(node, ownerID);
  16688. if (value === undefined && idx === newNode.array.length - 1) {
  16689. newNode.array.pop();
  16690. } else {
  16691. newNode.array[idx] = value;
  16692. }
  16693. return newNode;
  16694. }
  16695. function editableVNode(node, ownerID) {
  16696. if (ownerID && node && ownerID === node.ownerID) {
  16697. return node;
  16698. }
  16699. return new VNode(node ? node.array.slice() : [], ownerID);
  16700. }
  16701. function listNodeFor(list, rawIndex) {
  16702. if (rawIndex >= getTailOffset(list._capacity)) {
  16703. return list._tail;
  16704. }
  16705. if (rawIndex < 1 << (list._level + SHIFT)) {
  16706. var node = list._root;
  16707. var level = list._level;
  16708. while (node && level > 0) {
  16709. node = node.array[(rawIndex >>> level) & MASK];
  16710. level -= SHIFT;
  16711. }
  16712. return node;
  16713. }
  16714. }
  16715. function setListBounds(list, begin, end) {
  16716. // Sanitize begin & end using this shorthand for ToInt32(argument)
  16717. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  16718. if (begin !== undefined) {
  16719. begin = begin | 0;
  16720. }
  16721. if (end !== undefined) {
  16722. end = end | 0;
  16723. }
  16724. var owner = list.__ownerID || new OwnerID();
  16725. var oldOrigin = list._origin;
  16726. var oldCapacity = list._capacity;
  16727. var newOrigin = oldOrigin + begin;
  16728. var newCapacity = end === undefined ? oldCapacity : end < 0 ? oldCapacity + end : oldOrigin + end;
  16729. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  16730. return list;
  16731. }
  16732. // If it's going to end after it starts, it's empty.
  16733. if (newOrigin >= newCapacity) {
  16734. return list.clear();
  16735. }
  16736. var newLevel = list._level;
  16737. var newRoot = list._root;
  16738. // New origin might need creating a higher root.
  16739. var offsetShift = 0;
  16740. while (newOrigin + offsetShift < 0) {
  16741. newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner);
  16742. newLevel += SHIFT;
  16743. offsetShift += 1 << newLevel;
  16744. }
  16745. if (offsetShift) {
  16746. newOrigin += offsetShift;
  16747. oldOrigin += offsetShift;
  16748. newCapacity += offsetShift;
  16749. oldCapacity += offsetShift;
  16750. }
  16751. var oldTailOffset = getTailOffset(oldCapacity);
  16752. var newTailOffset = getTailOffset(newCapacity);
  16753. // New size might need creating a higher root.
  16754. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  16755. newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner);
  16756. newLevel += SHIFT;
  16757. }
  16758. // Locate or create the new tail.
  16759. var oldTail = list._tail;
  16760. var newTail = newTailOffset < oldTailOffset ?
  16761. listNodeFor(list, newCapacity - 1) :
  16762. newTailOffset > oldTailOffset ? new VNode([], owner) : oldTail;
  16763. // Merge Tail into tree.
  16764. if (oldTail && newTailOffset > oldTailOffset && newOrigin < oldCapacity && oldTail.array.length) {
  16765. newRoot = editableVNode(newRoot, owner);
  16766. var node = newRoot;
  16767. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  16768. var idx = (oldTailOffset >>> level) & MASK;
  16769. node = node.array[idx] = editableVNode(node.array[idx], owner);
  16770. }
  16771. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  16772. }
  16773. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  16774. if (newCapacity < oldCapacity) {
  16775. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  16776. }
  16777. // If the new origin is within the tail, then we do not need a root.
  16778. if (newOrigin >= newTailOffset) {
  16779. newOrigin -= newTailOffset;
  16780. newCapacity -= newTailOffset;
  16781. newLevel = SHIFT;
  16782. newRoot = null;
  16783. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  16784. // Otherwise, if the root has been trimmed, garbage collect.
  16785. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  16786. offsetShift = 0;
  16787. // Identify the new top root node of the subtree of the old root.
  16788. while (newRoot) {
  16789. var beginIndex = (newOrigin >>> newLevel) & MASK;
  16790. if (beginIndex !== (newTailOffset >>> newLevel) & MASK) {
  16791. break;
  16792. }
  16793. if (beginIndex) {
  16794. offsetShift += (1 << newLevel) * beginIndex;
  16795. }
  16796. newLevel -= SHIFT;
  16797. newRoot = newRoot.array[beginIndex];
  16798. }
  16799. // Trim the new sides of the new root.
  16800. if (newRoot && newOrigin > oldOrigin) {
  16801. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  16802. }
  16803. if (newRoot && newTailOffset < oldTailOffset) {
  16804. newRoot = newRoot.removeAfter(owner, newLevel, newTailOffset - offsetShift);
  16805. }
  16806. if (offsetShift) {
  16807. newOrigin -= offsetShift;
  16808. newCapacity -= offsetShift;
  16809. }
  16810. }
  16811. if (list.__ownerID) {
  16812. list.size = newCapacity - newOrigin;
  16813. list._origin = newOrigin;
  16814. list._capacity = newCapacity;
  16815. list._level = newLevel;
  16816. list._root = newRoot;
  16817. list._tail = newTail;
  16818. list.__hash = undefined;
  16819. list.__altered = true;
  16820. return list;
  16821. }
  16822. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  16823. }
  16824. function mergeIntoListWith(list, merger, iterables) {
  16825. var iters = [];
  16826. var maxSize = 0;
  16827. for (var ii = 0; ii < iterables.length; ii++) {
  16828. var value = iterables[ii];
  16829. var iter = IndexedIterable(value);
  16830. if (iter.size > maxSize) {
  16831. maxSize = iter.size;
  16832. }
  16833. if (!isIterable(value)) {
  16834. iter = iter.map(function(v ) {return fromJS(v)});
  16835. }
  16836. iters.push(iter);
  16837. }
  16838. if (maxSize > list.size) {
  16839. list = list.setSize(maxSize);
  16840. }
  16841. return mergeIntoCollectionWith(list, merger, iters);
  16842. }
  16843. function getTailOffset(size) {
  16844. return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
  16845. }
  16846. createClass(OrderedMap, Map);
  16847. // @pragma Construction
  16848. function OrderedMap(value) {
  16849. return value === null || value === undefined ? emptyOrderedMap() :
  16850. isOrderedMap(value) ? value :
  16851. emptyOrderedMap().withMutations(function(map ) {
  16852. var iter = KeyedIterable(value);
  16853. assertNotInfinite(iter.size);
  16854. iter.forEach(function(v, k) {return map.set(k, v)});
  16855. });
  16856. }
  16857. OrderedMap.of = function(/*...values*/) {
  16858. return this(arguments);
  16859. };
  16860. OrderedMap.prototype.toString = function() {
  16861. return this.__toString('OrderedMap {', '}');
  16862. };
  16863. // @pragma Access
  16864. OrderedMap.prototype.get = function(k, notSetValue) {
  16865. var index = this._map.get(k);
  16866. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  16867. };
  16868. // @pragma Modification
  16869. OrderedMap.prototype.clear = function() {
  16870. if (this.size === 0) {
  16871. return this;
  16872. }
  16873. if (this.__ownerID) {
  16874. this.size = 0;
  16875. this._map.clear();
  16876. this._list.clear();
  16877. return this;
  16878. }
  16879. return emptyOrderedMap();
  16880. };
  16881. OrderedMap.prototype.set = function(k, v) {
  16882. return updateOrderedMap(this, k, v);
  16883. };
  16884. OrderedMap.prototype.remove = function(k) {
  16885. return updateOrderedMap(this, k, NOT_SET);
  16886. };
  16887. OrderedMap.prototype.wasAltered = function() {
  16888. return this._map.wasAltered() || this._list.wasAltered();
  16889. };
  16890. OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  16891. return this._list.__iterate(
  16892. function(entry ) {return entry && fn(entry[1], entry[0], this$0)},
  16893. reverse
  16894. );
  16895. };
  16896. OrderedMap.prototype.__iterator = function(type, reverse) {
  16897. return this._list.fromEntrySeq().__iterator(type, reverse);
  16898. };
  16899. OrderedMap.prototype.__ensureOwner = function(ownerID) {
  16900. if (ownerID === this.__ownerID) {
  16901. return this;
  16902. }
  16903. var newMap = this._map.__ensureOwner(ownerID);
  16904. var newList = this._list.__ensureOwner(ownerID);
  16905. if (!ownerID) {
  16906. this.__ownerID = ownerID;
  16907. this._map = newMap;
  16908. this._list = newList;
  16909. return this;
  16910. }
  16911. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  16912. };
  16913. function isOrderedMap(maybeOrderedMap) {
  16914. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  16915. }
  16916. OrderedMap.isOrderedMap = isOrderedMap;
  16917. OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
  16918. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  16919. function makeOrderedMap(map, list, ownerID, hash) {
  16920. var omap = Object.create(OrderedMap.prototype);
  16921. omap.size = map ? map.size : 0;
  16922. omap._map = map;
  16923. omap._list = list;
  16924. omap.__ownerID = ownerID;
  16925. omap.__hash = hash;
  16926. return omap;
  16927. }
  16928. var EMPTY_ORDERED_MAP;
  16929. function emptyOrderedMap() {
  16930. return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()));
  16931. }
  16932. function updateOrderedMap(omap, k, v) {
  16933. var map = omap._map;
  16934. var list = omap._list;
  16935. var i = map.get(k);
  16936. var has = i !== undefined;
  16937. var newMap;
  16938. var newList;
  16939. if (v === NOT_SET) { // removed
  16940. if (!has) {
  16941. return omap;
  16942. }
  16943. if (list.size >= SIZE && list.size >= map.size * 2) {
  16944. newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx});
  16945. newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap();
  16946. if (omap.__ownerID) {
  16947. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  16948. }
  16949. } else {
  16950. newMap = map.remove(k);
  16951. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  16952. }
  16953. } else {
  16954. if (has) {
  16955. if (v === list.get(i)[1]) {
  16956. return omap;
  16957. }
  16958. newMap = map;
  16959. newList = list.set(i, [k, v]);
  16960. } else {
  16961. newMap = map.set(k, list.size);
  16962. newList = list.set(list.size, [k, v]);
  16963. }
  16964. }
  16965. if (omap.__ownerID) {
  16966. omap.size = newMap.size;
  16967. omap._map = newMap;
  16968. omap._list = newList;
  16969. omap.__hash = undefined;
  16970. return omap;
  16971. }
  16972. return makeOrderedMap(newMap, newList);
  16973. }
  16974. createClass(ToKeyedSequence, KeyedSeq);
  16975. function ToKeyedSequence(indexed, useKeys) {
  16976. this._iter = indexed;
  16977. this._useKeys = useKeys;
  16978. this.size = indexed.size;
  16979. }
  16980. ToKeyedSequence.prototype.get = function(key, notSetValue) {
  16981. return this._iter.get(key, notSetValue);
  16982. };
  16983. ToKeyedSequence.prototype.has = function(key) {
  16984. return this._iter.has(key);
  16985. };
  16986. ToKeyedSequence.prototype.valueSeq = function() {
  16987. return this._iter.valueSeq();
  16988. };
  16989. ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
  16990. var reversedSequence = reverseFactory(this, true);
  16991. if (!this._useKeys) {
  16992. reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
  16993. }
  16994. return reversedSequence;
  16995. };
  16996. ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
  16997. var mappedSequence = mapFactory(this, mapper, context);
  16998. if (!this._useKeys) {
  16999. mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
  17000. }
  17001. return mappedSequence;
  17002. };
  17003. ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17004. var ii;
  17005. return this._iter.__iterate(
  17006. this._useKeys ?
  17007. function(v, k) {return fn(v, k, this$0)} :
  17008. ((ii = reverse ? resolveSize(this) : 0),
  17009. function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
  17010. reverse
  17011. );
  17012. };
  17013. ToKeyedSequence.prototype.__iterator = function(type, reverse) {
  17014. if (this._useKeys) {
  17015. return this._iter.__iterator(type, reverse);
  17016. }
  17017. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  17018. var ii = reverse ? resolveSize(this) : 0;
  17019. return new Iterator(function() {
  17020. var step = iterator.next();
  17021. return step.done ? step :
  17022. iteratorValue(type, reverse ? --ii : ii++, step.value, step);
  17023. });
  17024. };
  17025. ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
  17026. createClass(ToIndexedSequence, IndexedSeq);
  17027. function ToIndexedSequence(iter) {
  17028. this._iter = iter;
  17029. this.size = iter.size;
  17030. }
  17031. ToIndexedSequence.prototype.includes = function(value) {
  17032. return this._iter.includes(value);
  17033. };
  17034. ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17035. var iterations = 0;
  17036. return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
  17037. };
  17038. ToIndexedSequence.prototype.__iterator = function(type, reverse) {
  17039. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  17040. var iterations = 0;
  17041. return new Iterator(function() {
  17042. var step = iterator.next();
  17043. return step.done ? step :
  17044. iteratorValue(type, iterations++, step.value, step)
  17045. });
  17046. };
  17047. createClass(ToSetSequence, SetSeq);
  17048. function ToSetSequence(iter) {
  17049. this._iter = iter;
  17050. this.size = iter.size;
  17051. }
  17052. ToSetSequence.prototype.has = function(key) {
  17053. return this._iter.includes(key);
  17054. };
  17055. ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17056. return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
  17057. };
  17058. ToSetSequence.prototype.__iterator = function(type, reverse) {
  17059. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  17060. return new Iterator(function() {
  17061. var step = iterator.next();
  17062. return step.done ? step :
  17063. iteratorValue(type, step.value, step.value, step);
  17064. });
  17065. };
  17066. createClass(FromEntriesSequence, KeyedSeq);
  17067. function FromEntriesSequence(entries) {
  17068. this._iter = entries;
  17069. this.size = entries.size;
  17070. }
  17071. FromEntriesSequence.prototype.entrySeq = function() {
  17072. return this._iter.toSeq();
  17073. };
  17074. FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17075. return this._iter.__iterate(function(entry ) {
  17076. // Check if entry exists first so array access doesn't throw for holes
  17077. // in the parent iteration.
  17078. if (entry) {
  17079. validateEntry(entry);
  17080. var indexedIterable = isIterable(entry);
  17081. return fn(
  17082. indexedIterable ? entry.get(1) : entry[1],
  17083. indexedIterable ? entry.get(0) : entry[0],
  17084. this$0
  17085. );
  17086. }
  17087. }, reverse);
  17088. };
  17089. FromEntriesSequence.prototype.__iterator = function(type, reverse) {
  17090. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  17091. return new Iterator(function() {
  17092. while (true) {
  17093. var step = iterator.next();
  17094. if (step.done) {
  17095. return step;
  17096. }
  17097. var entry = step.value;
  17098. // Check if entry exists first so array access doesn't throw for holes
  17099. // in the parent iteration.
  17100. if (entry) {
  17101. validateEntry(entry);
  17102. var indexedIterable = isIterable(entry);
  17103. return iteratorValue(
  17104. type,
  17105. indexedIterable ? entry.get(0) : entry[0],
  17106. indexedIterable ? entry.get(1) : entry[1],
  17107. step
  17108. );
  17109. }
  17110. }
  17111. });
  17112. };
  17113. ToIndexedSequence.prototype.cacheResult =
  17114. ToKeyedSequence.prototype.cacheResult =
  17115. ToSetSequence.prototype.cacheResult =
  17116. FromEntriesSequence.prototype.cacheResult =
  17117. cacheResultThrough;
  17118. function flipFactory(iterable) {
  17119. var flipSequence = makeSequence(iterable);
  17120. flipSequence._iter = iterable;
  17121. flipSequence.size = iterable.size;
  17122. flipSequence.flip = function() {return iterable};
  17123. flipSequence.reverse = function () {
  17124. var reversedSequence = iterable.reverse.apply(this); // super.reverse()
  17125. reversedSequence.flip = function() {return iterable.reverse()};
  17126. return reversedSequence;
  17127. };
  17128. flipSequence.has = function(key ) {return iterable.includes(key)};
  17129. flipSequence.includes = function(key ) {return iterable.has(key)};
  17130. flipSequence.cacheResult = cacheResultThrough;
  17131. flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  17132. return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
  17133. };
  17134. flipSequence.__iteratorUncached = function(type, reverse) {
  17135. if (type === ITERATE_ENTRIES) {
  17136. var iterator = iterable.__iterator(type, reverse);
  17137. return new Iterator(function() {
  17138. var step = iterator.next();
  17139. if (!step.done) {
  17140. var k = step.value[0];
  17141. step.value[0] = step.value[1];
  17142. step.value[1] = k;
  17143. }
  17144. return step;
  17145. });
  17146. }
  17147. return iterable.__iterator(
  17148. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  17149. reverse
  17150. );
  17151. };
  17152. return flipSequence;
  17153. }
  17154. function mapFactory(iterable, mapper, context) {
  17155. var mappedSequence = makeSequence(iterable);
  17156. mappedSequence.size = iterable.size;
  17157. mappedSequence.has = function(key ) {return iterable.has(key)};
  17158. mappedSequence.get = function(key, notSetValue) {
  17159. var v = iterable.get(key, NOT_SET);
  17160. return v === NOT_SET ?
  17161. notSetValue :
  17162. mapper.call(context, v, key, iterable);
  17163. };
  17164. mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  17165. return iterable.__iterate(
  17166. function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
  17167. reverse
  17168. );
  17169. };
  17170. mappedSequence.__iteratorUncached = function (type, reverse) {
  17171. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  17172. return new Iterator(function() {
  17173. var step = iterator.next();
  17174. if (step.done) {
  17175. return step;
  17176. }
  17177. var entry = step.value;
  17178. var key = entry[0];
  17179. return iteratorValue(
  17180. type,
  17181. key,
  17182. mapper.call(context, entry[1], key, iterable),
  17183. step
  17184. );
  17185. });
  17186. };
  17187. return mappedSequence;
  17188. }
  17189. function reverseFactory(iterable, useKeys) {
  17190. var reversedSequence = makeSequence(iterable);
  17191. reversedSequence._iter = iterable;
  17192. reversedSequence.size = iterable.size;
  17193. reversedSequence.reverse = function() {return iterable};
  17194. if (iterable.flip) {
  17195. reversedSequence.flip = function () {
  17196. var flipSequence = flipFactory(iterable);
  17197. flipSequence.reverse = function() {return iterable.flip()};
  17198. return flipSequence;
  17199. };
  17200. }
  17201. reversedSequence.get = function(key, notSetValue)
  17202. {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
  17203. reversedSequence.has = function(key )
  17204. {return iterable.has(useKeys ? key : -1 - key)};
  17205. reversedSequence.includes = function(value ) {return iterable.includes(value)};
  17206. reversedSequence.cacheResult = cacheResultThrough;
  17207. reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
  17208. return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
  17209. };
  17210. reversedSequence.__iterator =
  17211. function(type, reverse) {return iterable.__iterator(type, !reverse)};
  17212. return reversedSequence;
  17213. }
  17214. function filterFactory(iterable, predicate, context, useKeys) {
  17215. var filterSequence = makeSequence(iterable);
  17216. if (useKeys) {
  17217. filterSequence.has = function(key ) {
  17218. var v = iterable.get(key, NOT_SET);
  17219. return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
  17220. };
  17221. filterSequence.get = function(key, notSetValue) {
  17222. var v = iterable.get(key, NOT_SET);
  17223. return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
  17224. v : notSetValue;
  17225. };
  17226. }
  17227. filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  17228. var iterations = 0;
  17229. iterable.__iterate(function(v, k, c) {
  17230. if (predicate.call(context, v, k, c)) {
  17231. iterations++;
  17232. return fn(v, useKeys ? k : iterations - 1, this$0);
  17233. }
  17234. }, reverse);
  17235. return iterations;
  17236. };
  17237. filterSequence.__iteratorUncached = function (type, reverse) {
  17238. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  17239. var iterations = 0;
  17240. return new Iterator(function() {
  17241. while (true) {
  17242. var step = iterator.next();
  17243. if (step.done) {
  17244. return step;
  17245. }
  17246. var entry = step.value;
  17247. var key = entry[0];
  17248. var value = entry[1];
  17249. if (predicate.call(context, value, key, iterable)) {
  17250. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  17251. }
  17252. }
  17253. });
  17254. };
  17255. return filterSequence;
  17256. }
  17257. function countByFactory(iterable, grouper, context) {
  17258. var groups = Map().asMutable();
  17259. iterable.__iterate(function(v, k) {
  17260. groups.update(
  17261. grouper.call(context, v, k, iterable),
  17262. 0,
  17263. function(a ) {return a + 1}
  17264. );
  17265. });
  17266. return groups.asImmutable();
  17267. }
  17268. function groupByFactory(iterable, grouper, context) {
  17269. var isKeyedIter = isKeyed(iterable);
  17270. var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable();
  17271. iterable.__iterate(function(v, k) {
  17272. groups.update(
  17273. grouper.call(context, v, k, iterable),
  17274. function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
  17275. );
  17276. });
  17277. var coerce = iterableClass(iterable);
  17278. return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
  17279. }
  17280. function sliceFactory(iterable, begin, end, useKeys) {
  17281. var originalSize = iterable.size;
  17282. // Sanitize begin & end using this shorthand for ToInt32(argument)
  17283. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  17284. if (begin !== undefined) {
  17285. begin = begin | 0;
  17286. }
  17287. if (end !== undefined) {
  17288. end = end | 0;
  17289. }
  17290. if (wholeSlice(begin, end, originalSize)) {
  17291. return iterable;
  17292. }
  17293. var resolvedBegin = resolveBegin(begin, originalSize);
  17294. var resolvedEnd = resolveEnd(end, originalSize);
  17295. // begin or end will be NaN if they were provided as negative numbers and
  17296. // this iterable's size is unknown. In that case, cache first so there is
  17297. // a known size and these do not resolve to NaN.
  17298. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  17299. return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
  17300. }
  17301. // Note: resolvedEnd is undefined when the original sequence's length is
  17302. // unknown and this slice did not supply an end and should contain all
  17303. // elements after resolvedBegin.
  17304. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  17305. var resolvedSize = resolvedEnd - resolvedBegin;
  17306. var sliceSize;
  17307. if (resolvedSize === resolvedSize) {
  17308. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  17309. }
  17310. var sliceSeq = makeSequence(iterable);
  17311. // If iterable.size is undefined, the size of the realized sliceSeq is
  17312. // unknown at this point unless the number of items to slice is 0
  17313. sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
  17314. if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
  17315. sliceSeq.get = function (index, notSetValue) {
  17316. index = wrapIndex(this, index);
  17317. return index >= 0 && index < sliceSize ?
  17318. iterable.get(index + resolvedBegin, notSetValue) :
  17319. notSetValue;
  17320. };
  17321. }
  17322. sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
  17323. if (sliceSize === 0) {
  17324. return 0;
  17325. }
  17326. if (reverse) {
  17327. return this.cacheResult().__iterate(fn, reverse);
  17328. }
  17329. var skipped = 0;
  17330. var isSkipping = true;
  17331. var iterations = 0;
  17332. iterable.__iterate(function(v, k) {
  17333. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  17334. iterations++;
  17335. return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
  17336. iterations !== sliceSize;
  17337. }
  17338. });
  17339. return iterations;
  17340. };
  17341. sliceSeq.__iteratorUncached = function(type, reverse) {
  17342. if (sliceSize !== 0 && reverse) {
  17343. return this.cacheResult().__iterator(type, reverse);
  17344. }
  17345. // Don't bother instantiating parent iterator if taking 0.
  17346. var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
  17347. var skipped = 0;
  17348. var iterations = 0;
  17349. return new Iterator(function() {
  17350. while (skipped++ < resolvedBegin) {
  17351. iterator.next();
  17352. }
  17353. if (++iterations > sliceSize) {
  17354. return iteratorDone();
  17355. }
  17356. var step = iterator.next();
  17357. if (useKeys || type === ITERATE_VALUES) {
  17358. return step;
  17359. } else if (type === ITERATE_KEYS) {
  17360. return iteratorValue(type, iterations - 1, undefined, step);
  17361. } else {
  17362. return iteratorValue(type, iterations - 1, step.value[1], step);
  17363. }
  17364. });
  17365. };
  17366. return sliceSeq;
  17367. }
  17368. function takeWhileFactory(iterable, predicate, context) {
  17369. var takeSequence = makeSequence(iterable);
  17370. takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  17371. if (reverse) {
  17372. return this.cacheResult().__iterate(fn, reverse);
  17373. }
  17374. var iterations = 0;
  17375. iterable.__iterate(function(v, k, c)
  17376. {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
  17377. );
  17378. return iterations;
  17379. };
  17380. takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  17381. if (reverse) {
  17382. return this.cacheResult().__iterator(type, reverse);
  17383. }
  17384. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  17385. var iterating = true;
  17386. return new Iterator(function() {
  17387. if (!iterating) {
  17388. return iteratorDone();
  17389. }
  17390. var step = iterator.next();
  17391. if (step.done) {
  17392. return step;
  17393. }
  17394. var entry = step.value;
  17395. var k = entry[0];
  17396. var v = entry[1];
  17397. if (!predicate.call(context, v, k, this$0)) {
  17398. iterating = false;
  17399. return iteratorDone();
  17400. }
  17401. return type === ITERATE_ENTRIES ? step :
  17402. iteratorValue(type, k, v, step);
  17403. });
  17404. };
  17405. return takeSequence;
  17406. }
  17407. function skipWhileFactory(iterable, predicate, context, useKeys) {
  17408. var skipSequence = makeSequence(iterable);
  17409. skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  17410. if (reverse) {
  17411. return this.cacheResult().__iterate(fn, reverse);
  17412. }
  17413. var isSkipping = true;
  17414. var iterations = 0;
  17415. iterable.__iterate(function(v, k, c) {
  17416. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  17417. iterations++;
  17418. return fn(v, useKeys ? k : iterations - 1, this$0);
  17419. }
  17420. });
  17421. return iterations;
  17422. };
  17423. skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  17424. if (reverse) {
  17425. return this.cacheResult().__iterator(type, reverse);
  17426. }
  17427. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  17428. var skipping = true;
  17429. var iterations = 0;
  17430. return new Iterator(function() {
  17431. var step, k, v;
  17432. do {
  17433. step = iterator.next();
  17434. if (step.done) {
  17435. if (useKeys || type === ITERATE_VALUES) {
  17436. return step;
  17437. } else if (type === ITERATE_KEYS) {
  17438. return iteratorValue(type, iterations++, undefined, step);
  17439. } else {
  17440. return iteratorValue(type, iterations++, step.value[1], step);
  17441. }
  17442. }
  17443. var entry = step.value;
  17444. k = entry[0];
  17445. v = entry[1];
  17446. skipping && (skipping = predicate.call(context, v, k, this$0));
  17447. } while (skipping);
  17448. return type === ITERATE_ENTRIES ? step :
  17449. iteratorValue(type, k, v, step);
  17450. });
  17451. };
  17452. return skipSequence;
  17453. }
  17454. function concatFactory(iterable, values) {
  17455. var isKeyedIterable = isKeyed(iterable);
  17456. var iters = [iterable].concat(values).map(function(v ) {
  17457. if (!isIterable(v)) {
  17458. v = isKeyedIterable ?
  17459. keyedSeqFromValue(v) :
  17460. indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  17461. } else if (isKeyedIterable) {
  17462. v = KeyedIterable(v);
  17463. }
  17464. return v;
  17465. }).filter(function(v ) {return v.size !== 0});
  17466. if (iters.length === 0) {
  17467. return iterable;
  17468. }
  17469. if (iters.length === 1) {
  17470. var singleton = iters[0];
  17471. if (singleton === iterable ||
  17472. isKeyedIterable && isKeyed(singleton) ||
  17473. isIndexed(iterable) && isIndexed(singleton)) {
  17474. return singleton;
  17475. }
  17476. }
  17477. var concatSeq = new ArraySeq(iters);
  17478. if (isKeyedIterable) {
  17479. concatSeq = concatSeq.toKeyedSeq();
  17480. } else if (!isIndexed(iterable)) {
  17481. concatSeq = concatSeq.toSetSeq();
  17482. }
  17483. concatSeq = concatSeq.flatten(true);
  17484. concatSeq.size = iters.reduce(
  17485. function(sum, seq) {
  17486. if (sum !== undefined) {
  17487. var size = seq.size;
  17488. if (size !== undefined) {
  17489. return sum + size;
  17490. }
  17491. }
  17492. },
  17493. 0
  17494. );
  17495. return concatSeq;
  17496. }
  17497. function flattenFactory(iterable, depth, useKeys) {
  17498. var flatSequence = makeSequence(iterable);
  17499. flatSequence.__iterateUncached = function(fn, reverse) {
  17500. var iterations = 0;
  17501. var stopped = false;
  17502. function flatDeep(iter, currentDepth) {var this$0 = this;
  17503. iter.__iterate(function(v, k) {
  17504. if ((!depth || currentDepth < depth) && isIterable(v)) {
  17505. flatDeep(v, currentDepth + 1);
  17506. } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
  17507. stopped = true;
  17508. }
  17509. return !stopped;
  17510. }, reverse);
  17511. }
  17512. flatDeep(iterable, 0);
  17513. return iterations;
  17514. };
  17515. flatSequence.__iteratorUncached = function(type, reverse) {
  17516. var iterator = iterable.__iterator(type, reverse);
  17517. var stack = [];
  17518. var iterations = 0;
  17519. return new Iterator(function() {
  17520. while (iterator) {
  17521. var step = iterator.next();
  17522. if (step.done !== false) {
  17523. iterator = stack.pop();
  17524. continue;
  17525. }
  17526. var v = step.value;
  17527. if (type === ITERATE_ENTRIES) {
  17528. v = v[1];
  17529. }
  17530. if ((!depth || stack.length < depth) && isIterable(v)) {
  17531. stack.push(iterator);
  17532. iterator = v.__iterator(type, reverse);
  17533. } else {
  17534. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  17535. }
  17536. }
  17537. return iteratorDone();
  17538. });
  17539. };
  17540. return flatSequence;
  17541. }
  17542. function flatMapFactory(iterable, mapper, context) {
  17543. var coerce = iterableClass(iterable);
  17544. return iterable.toSeq().map(
  17545. function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
  17546. ).flatten(true);
  17547. }
  17548. function interposeFactory(iterable, separator) {
  17549. var interposedSequence = makeSequence(iterable);
  17550. interposedSequence.size = iterable.size && iterable.size * 2 -1;
  17551. interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  17552. var iterations = 0;
  17553. iterable.__iterate(function(v, k)
  17554. {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
  17555. fn(v, iterations++, this$0) !== false},
  17556. reverse
  17557. );
  17558. return iterations;
  17559. };
  17560. interposedSequence.__iteratorUncached = function(type, reverse) {
  17561. var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
  17562. var iterations = 0;
  17563. var step;
  17564. return new Iterator(function() {
  17565. if (!step || iterations % 2) {
  17566. step = iterator.next();
  17567. if (step.done) {
  17568. return step;
  17569. }
  17570. }
  17571. return iterations % 2 ?
  17572. iteratorValue(type, iterations++, separator) :
  17573. iteratorValue(type, iterations++, step.value, step);
  17574. });
  17575. };
  17576. return interposedSequence;
  17577. }
  17578. function sortFactory(iterable, comparator, mapper) {
  17579. if (!comparator) {
  17580. comparator = defaultComparator;
  17581. }
  17582. var isKeyedIterable = isKeyed(iterable);
  17583. var index = 0;
  17584. var entries = iterable.toSeq().map(
  17585. function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
  17586. ).toArray();
  17587. entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
  17588. isKeyedIterable ?
  17589. function(v, i) { entries[i].length = 2; } :
  17590. function(v, i) { entries[i] = v[1]; }
  17591. );
  17592. return isKeyedIterable ? KeyedSeq(entries) :
  17593. isIndexed(iterable) ? IndexedSeq(entries) :
  17594. SetSeq(entries);
  17595. }
  17596. function maxFactory(iterable, comparator, mapper) {
  17597. if (!comparator) {
  17598. comparator = defaultComparator;
  17599. }
  17600. if (mapper) {
  17601. var entry = iterable.toSeq()
  17602. .map(function(v, k) {return [v, mapper(v, k, iterable)]})
  17603. .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
  17604. return entry && entry[0];
  17605. } else {
  17606. return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
  17607. }
  17608. }
  17609. function maxCompare(comparator, a, b) {
  17610. var comp = comparator(b, a);
  17611. // b is considered the new max if the comparator declares them equal, but
  17612. // they are not equal and b is in fact a nullish value.
  17613. return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
  17614. }
  17615. function zipWithFactory(keyIter, zipper, iters) {
  17616. var zipSequence = makeSequence(keyIter);
  17617. zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
  17618. // Note: this a generic base implementation of __iterate in terms of
  17619. // __iterator which may be more generically useful in the future.
  17620. zipSequence.__iterate = function(fn, reverse) {
  17621. /* generic:
  17622. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  17623. var step;
  17624. var iterations = 0;
  17625. while (!(step = iterator.next()).done) {
  17626. iterations++;
  17627. if (fn(step.value[1], step.value[0], this) === false) {
  17628. break;
  17629. }
  17630. }
  17631. return iterations;
  17632. */
  17633. // indexed:
  17634. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  17635. var step;
  17636. var iterations = 0;
  17637. while (!(step = iterator.next()).done) {
  17638. if (fn(step.value, iterations++, this) === false) {
  17639. break;
  17640. }
  17641. }
  17642. return iterations;
  17643. };
  17644. zipSequence.__iteratorUncached = function(type, reverse) {
  17645. var iterators = iters.map(function(i )
  17646. {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
  17647. );
  17648. var iterations = 0;
  17649. var isDone = false;
  17650. return new Iterator(function() {
  17651. var steps;
  17652. if (!isDone) {
  17653. steps = iterators.map(function(i ) {return i.next()});
  17654. isDone = steps.some(function(s ) {return s.done});
  17655. }
  17656. if (isDone) {
  17657. return iteratorDone();
  17658. }
  17659. return iteratorValue(
  17660. type,
  17661. iterations++,
  17662. zipper.apply(null, steps.map(function(s ) {return s.value}))
  17663. );
  17664. });
  17665. };
  17666. return zipSequence
  17667. }
  17668. // #pragma Helper Functions
  17669. function reify(iter, seq) {
  17670. return isSeq(iter) ? seq : iter.constructor(seq);
  17671. }
  17672. function validateEntry(entry) {
  17673. if (entry !== Object(entry)) {
  17674. throw new TypeError('Expected [K, V] tuple: ' + entry);
  17675. }
  17676. }
  17677. function resolveSize(iter) {
  17678. assertNotInfinite(iter.size);
  17679. return ensureSize(iter);
  17680. }
  17681. function iterableClass(iterable) {
  17682. return isKeyed(iterable) ? KeyedIterable :
  17683. isIndexed(iterable) ? IndexedIterable :
  17684. SetIterable;
  17685. }
  17686. function makeSequence(iterable) {
  17687. return Object.create(
  17688. (
  17689. isKeyed(iterable) ? KeyedSeq :
  17690. isIndexed(iterable) ? IndexedSeq :
  17691. SetSeq
  17692. ).prototype
  17693. );
  17694. }
  17695. function cacheResultThrough() {
  17696. if (this._iter.cacheResult) {
  17697. this._iter.cacheResult();
  17698. this.size = this._iter.size;
  17699. return this;
  17700. } else {
  17701. return Seq.prototype.cacheResult.call(this);
  17702. }
  17703. }
  17704. function defaultComparator(a, b) {
  17705. return a > b ? 1 : a < b ? -1 : 0;
  17706. }
  17707. function forceIterator(keyPath) {
  17708. var iter = getIterator(keyPath);
  17709. if (!iter) {
  17710. // Array might not be iterable in this environment, so we need a fallback
  17711. // to our wrapped type.
  17712. if (!isArrayLike(keyPath)) {
  17713. throw new TypeError('Expected iterable or array-like: ' + keyPath);
  17714. }
  17715. iter = getIterator(Iterable(keyPath));
  17716. }
  17717. return iter;
  17718. }
  17719. createClass(Record, KeyedCollection);
  17720. function Record(defaultValues, name) {
  17721. var hasInitialized;
  17722. var RecordType = function Record(values) {
  17723. if (values instanceof RecordType) {
  17724. return values;
  17725. }
  17726. if (!(this instanceof RecordType)) {
  17727. return new RecordType(values);
  17728. }
  17729. if (!hasInitialized) {
  17730. hasInitialized = true;
  17731. var keys = Object.keys(defaultValues);
  17732. setProps(RecordTypePrototype, keys);
  17733. RecordTypePrototype.size = keys.length;
  17734. RecordTypePrototype._name = name;
  17735. RecordTypePrototype._keys = keys;
  17736. RecordTypePrototype._defaultValues = defaultValues;
  17737. }
  17738. this._map = Map(values);
  17739. };
  17740. var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
  17741. RecordTypePrototype.constructor = RecordType;
  17742. return RecordType;
  17743. }
  17744. Record.prototype.toString = function() {
  17745. return this.__toString(recordName(this) + ' {', '}');
  17746. };
  17747. // @pragma Access
  17748. Record.prototype.has = function(k) {
  17749. return this._defaultValues.hasOwnProperty(k);
  17750. };
  17751. Record.prototype.get = function(k, notSetValue) {
  17752. if (!this.has(k)) {
  17753. return notSetValue;
  17754. }
  17755. var defaultVal = this._defaultValues[k];
  17756. return this._map ? this._map.get(k, defaultVal) : defaultVal;
  17757. };
  17758. // @pragma Modification
  17759. Record.prototype.clear = function() {
  17760. if (this.__ownerID) {
  17761. this._map && this._map.clear();
  17762. return this;
  17763. }
  17764. var RecordType = this.constructor;
  17765. return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap()));
  17766. };
  17767. Record.prototype.set = function(k, v) {
  17768. if (!this.has(k)) {
  17769. throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
  17770. }
  17771. var newMap = this._map && this._map.set(k, v);
  17772. if (this.__ownerID || newMap === this._map) {
  17773. return this;
  17774. }
  17775. return makeRecord(this, newMap);
  17776. };
  17777. Record.prototype.remove = function(k) {
  17778. if (!this.has(k)) {
  17779. return this;
  17780. }
  17781. var newMap = this._map && this._map.remove(k);
  17782. if (this.__ownerID || newMap === this._map) {
  17783. return this;
  17784. }
  17785. return makeRecord(this, newMap);
  17786. };
  17787. Record.prototype.wasAltered = function() {
  17788. return this._map.wasAltered();
  17789. };
  17790. Record.prototype.__iterator = function(type, reverse) {var this$0 = this;
  17791. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse);
  17792. };
  17793. Record.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17794. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse);
  17795. };
  17796. Record.prototype.__ensureOwner = function(ownerID) {
  17797. if (ownerID === this.__ownerID) {
  17798. return this;
  17799. }
  17800. var newMap = this._map && this._map.__ensureOwner(ownerID);
  17801. if (!ownerID) {
  17802. this.__ownerID = ownerID;
  17803. this._map = newMap;
  17804. return this;
  17805. }
  17806. return makeRecord(this, newMap, ownerID);
  17807. };
  17808. var RecordPrototype = Record.prototype;
  17809. RecordPrototype[DELETE] = RecordPrototype.remove;
  17810. RecordPrototype.deleteIn =
  17811. RecordPrototype.removeIn = MapPrototype.removeIn;
  17812. RecordPrototype.merge = MapPrototype.merge;
  17813. RecordPrototype.mergeWith = MapPrototype.mergeWith;
  17814. RecordPrototype.mergeIn = MapPrototype.mergeIn;
  17815. RecordPrototype.mergeDeep = MapPrototype.mergeDeep;
  17816. RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith;
  17817. RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  17818. RecordPrototype.setIn = MapPrototype.setIn;
  17819. RecordPrototype.update = MapPrototype.update;
  17820. RecordPrototype.updateIn = MapPrototype.updateIn;
  17821. RecordPrototype.withMutations = MapPrototype.withMutations;
  17822. RecordPrototype.asMutable = MapPrototype.asMutable;
  17823. RecordPrototype.asImmutable = MapPrototype.asImmutable;
  17824. function makeRecord(likeRecord, map, ownerID) {
  17825. var record = Object.create(Object.getPrototypeOf(likeRecord));
  17826. record._map = map;
  17827. record.__ownerID = ownerID;
  17828. return record;
  17829. }
  17830. function recordName(record) {
  17831. return record._name || record.constructor.name || 'Record';
  17832. }
  17833. function setProps(prototype, names) {
  17834. try {
  17835. names.forEach(setProp.bind(undefined, prototype));
  17836. } catch (error) {
  17837. // Object.defineProperty failed. Probably IE8.
  17838. }
  17839. }
  17840. function setProp(prototype, name) {
  17841. Object.defineProperty(prototype, name, {
  17842. get: function() {
  17843. return this.get(name);
  17844. },
  17845. set: function(value) {
  17846. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  17847. this.set(name, value);
  17848. }
  17849. });
  17850. }
  17851. createClass(Set, SetCollection);
  17852. // @pragma Construction
  17853. function Set(value) {
  17854. return value === null || value === undefined ? emptySet() :
  17855. isSet(value) && !isOrdered(value) ? value :
  17856. emptySet().withMutations(function(set ) {
  17857. var iter = SetIterable(value);
  17858. assertNotInfinite(iter.size);
  17859. iter.forEach(function(v ) {return set.add(v)});
  17860. });
  17861. }
  17862. Set.of = function(/*...values*/) {
  17863. return this(arguments);
  17864. };
  17865. Set.fromKeys = function(value) {
  17866. return this(KeyedIterable(value).keySeq());
  17867. };
  17868. Set.prototype.toString = function() {
  17869. return this.__toString('Set {', '}');
  17870. };
  17871. // @pragma Access
  17872. Set.prototype.has = function(value) {
  17873. return this._map.has(value);
  17874. };
  17875. // @pragma Modification
  17876. Set.prototype.add = function(value) {
  17877. return updateSet(this, this._map.set(value, true));
  17878. };
  17879. Set.prototype.remove = function(value) {
  17880. return updateSet(this, this._map.remove(value));
  17881. };
  17882. Set.prototype.clear = function() {
  17883. return updateSet(this, this._map.clear());
  17884. };
  17885. // @pragma Composition
  17886. Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
  17887. iters = iters.filter(function(x ) {return x.size !== 0});
  17888. if (iters.length === 0) {
  17889. return this;
  17890. }
  17891. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  17892. return this.constructor(iters[0]);
  17893. }
  17894. return this.withMutations(function(set ) {
  17895. for (var ii = 0; ii < iters.length; ii++) {
  17896. SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)});
  17897. }
  17898. });
  17899. };
  17900. Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
  17901. if (iters.length === 0) {
  17902. return this;
  17903. }
  17904. iters = iters.map(function(iter ) {return SetIterable(iter)});
  17905. var originalSet = this;
  17906. return this.withMutations(function(set ) {
  17907. originalSet.forEach(function(value ) {
  17908. if (!iters.every(function(iter ) {return iter.includes(value)})) {
  17909. set.remove(value);
  17910. }
  17911. });
  17912. });
  17913. };
  17914. Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
  17915. if (iters.length === 0) {
  17916. return this;
  17917. }
  17918. iters = iters.map(function(iter ) {return SetIterable(iter)});
  17919. var originalSet = this;
  17920. return this.withMutations(function(set ) {
  17921. originalSet.forEach(function(value ) {
  17922. if (iters.some(function(iter ) {return iter.includes(value)})) {
  17923. set.remove(value);
  17924. }
  17925. });
  17926. });
  17927. };
  17928. Set.prototype.merge = function() {
  17929. return this.union.apply(this, arguments);
  17930. };
  17931. Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  17932. return this.union.apply(this, iters);
  17933. };
  17934. Set.prototype.sort = function(comparator) {
  17935. // Late binding
  17936. return OrderedSet(sortFactory(this, comparator));
  17937. };
  17938. Set.prototype.sortBy = function(mapper, comparator) {
  17939. // Late binding
  17940. return OrderedSet(sortFactory(this, comparator, mapper));
  17941. };
  17942. Set.prototype.wasAltered = function() {
  17943. return this._map.wasAltered();
  17944. };
  17945. Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17946. return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
  17947. };
  17948. Set.prototype.__iterator = function(type, reverse) {
  17949. return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
  17950. };
  17951. Set.prototype.__ensureOwner = function(ownerID) {
  17952. if (ownerID === this.__ownerID) {
  17953. return this;
  17954. }
  17955. var newMap = this._map.__ensureOwner(ownerID);
  17956. if (!ownerID) {
  17957. this.__ownerID = ownerID;
  17958. this._map = newMap;
  17959. return this;
  17960. }
  17961. return this.__make(newMap, ownerID);
  17962. };
  17963. function isSet(maybeSet) {
  17964. return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
  17965. }
  17966. Set.isSet = isSet;
  17967. var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
  17968. var SetPrototype = Set.prototype;
  17969. SetPrototype[IS_SET_SENTINEL] = true;
  17970. SetPrototype[DELETE] = SetPrototype.remove;
  17971. SetPrototype.mergeDeep = SetPrototype.merge;
  17972. SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
  17973. SetPrototype.withMutations = MapPrototype.withMutations;
  17974. SetPrototype.asMutable = MapPrototype.asMutable;
  17975. SetPrototype.asImmutable = MapPrototype.asImmutable;
  17976. SetPrototype.__empty = emptySet;
  17977. SetPrototype.__make = makeSet;
  17978. function updateSet(set, newMap) {
  17979. if (set.__ownerID) {
  17980. set.size = newMap.size;
  17981. set._map = newMap;
  17982. return set;
  17983. }
  17984. return newMap === set._map ? set :
  17985. newMap.size === 0 ? set.__empty() :
  17986. set.__make(newMap);
  17987. }
  17988. function makeSet(map, ownerID) {
  17989. var set = Object.create(SetPrototype);
  17990. set.size = map ? map.size : 0;
  17991. set._map = map;
  17992. set.__ownerID = ownerID;
  17993. return set;
  17994. }
  17995. var EMPTY_SET;
  17996. function emptySet() {
  17997. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  17998. }
  17999. createClass(OrderedSet, Set);
  18000. // @pragma Construction
  18001. function OrderedSet(value) {
  18002. return value === null || value === undefined ? emptyOrderedSet() :
  18003. isOrderedSet(value) ? value :
  18004. emptyOrderedSet().withMutations(function(set ) {
  18005. var iter = SetIterable(value);
  18006. assertNotInfinite(iter.size);
  18007. iter.forEach(function(v ) {return set.add(v)});
  18008. });
  18009. }
  18010. OrderedSet.of = function(/*...values*/) {
  18011. return this(arguments);
  18012. };
  18013. OrderedSet.fromKeys = function(value) {
  18014. return this(KeyedIterable(value).keySeq());
  18015. };
  18016. OrderedSet.prototype.toString = function() {
  18017. return this.__toString('OrderedSet {', '}');
  18018. };
  18019. function isOrderedSet(maybeOrderedSet) {
  18020. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  18021. }
  18022. OrderedSet.isOrderedSet = isOrderedSet;
  18023. var OrderedSetPrototype = OrderedSet.prototype;
  18024. OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
  18025. OrderedSetPrototype.__empty = emptyOrderedSet;
  18026. OrderedSetPrototype.__make = makeOrderedSet;
  18027. function makeOrderedSet(map, ownerID) {
  18028. var set = Object.create(OrderedSetPrototype);
  18029. set.size = map ? map.size : 0;
  18030. set._map = map;
  18031. set.__ownerID = ownerID;
  18032. return set;
  18033. }
  18034. var EMPTY_ORDERED_SET;
  18035. function emptyOrderedSet() {
  18036. return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
  18037. }
  18038. createClass(Stack, IndexedCollection);
  18039. // @pragma Construction
  18040. function Stack(value) {
  18041. return value === null || value === undefined ? emptyStack() :
  18042. isStack(value) ? value :
  18043. emptyStack().unshiftAll(value);
  18044. }
  18045. Stack.of = function(/*...values*/) {
  18046. return this(arguments);
  18047. };
  18048. Stack.prototype.toString = function() {
  18049. return this.__toString('Stack [', ']');
  18050. };
  18051. // @pragma Access
  18052. Stack.prototype.get = function(index, notSetValue) {
  18053. var head = this._head;
  18054. index = wrapIndex(this, index);
  18055. while (head && index--) {
  18056. head = head.next;
  18057. }
  18058. return head ? head.value : notSetValue;
  18059. };
  18060. Stack.prototype.peek = function() {
  18061. return this._head && this._head.value;
  18062. };
  18063. // @pragma Modification
  18064. Stack.prototype.push = function(/*...values*/) {
  18065. if (arguments.length === 0) {
  18066. return this;
  18067. }
  18068. var newSize = this.size + arguments.length;
  18069. var head = this._head;
  18070. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  18071. head = {
  18072. value: arguments[ii],
  18073. next: head
  18074. };
  18075. }
  18076. if (this.__ownerID) {
  18077. this.size = newSize;
  18078. this._head = head;
  18079. this.__hash = undefined;
  18080. this.__altered = true;
  18081. return this;
  18082. }
  18083. return makeStack(newSize, head);
  18084. };
  18085. Stack.prototype.pushAll = function(iter) {
  18086. iter = IndexedIterable(iter);
  18087. if (iter.size === 0) {
  18088. return this;
  18089. }
  18090. assertNotInfinite(iter.size);
  18091. var newSize = this.size;
  18092. var head = this._head;
  18093. iter.reverse().forEach(function(value ) {
  18094. newSize++;
  18095. head = {
  18096. value: value,
  18097. next: head
  18098. };
  18099. });
  18100. if (this.__ownerID) {
  18101. this.size = newSize;
  18102. this._head = head;
  18103. this.__hash = undefined;
  18104. this.__altered = true;
  18105. return this;
  18106. }
  18107. return makeStack(newSize, head);
  18108. };
  18109. Stack.prototype.pop = function() {
  18110. return this.slice(1);
  18111. };
  18112. Stack.prototype.unshift = function(/*...values*/) {
  18113. return this.push.apply(this, arguments);
  18114. };
  18115. Stack.prototype.unshiftAll = function(iter) {
  18116. return this.pushAll(iter);
  18117. };
  18118. Stack.prototype.shift = function() {
  18119. return this.pop.apply(this, arguments);
  18120. };
  18121. Stack.prototype.clear = function() {
  18122. if (this.size === 0) {
  18123. return this;
  18124. }
  18125. if (this.__ownerID) {
  18126. this.size = 0;
  18127. this._head = undefined;
  18128. this.__hash = undefined;
  18129. this.__altered = true;
  18130. return this;
  18131. }
  18132. return emptyStack();
  18133. };
  18134. Stack.prototype.slice = function(begin, end) {
  18135. if (wholeSlice(begin, end, this.size)) {
  18136. return this;
  18137. }
  18138. var resolvedBegin = resolveBegin(begin, this.size);
  18139. var resolvedEnd = resolveEnd(end, this.size);
  18140. if (resolvedEnd !== this.size) {
  18141. // super.slice(begin, end);
  18142. return IndexedCollection.prototype.slice.call(this, begin, end);
  18143. }
  18144. var newSize = this.size - resolvedBegin;
  18145. var head = this._head;
  18146. while (resolvedBegin--) {
  18147. head = head.next;
  18148. }
  18149. if (this.__ownerID) {
  18150. this.size = newSize;
  18151. this._head = head;
  18152. this.__hash = undefined;
  18153. this.__altered = true;
  18154. return this;
  18155. }
  18156. return makeStack(newSize, head);
  18157. };
  18158. // @pragma Mutability
  18159. Stack.prototype.__ensureOwner = function(ownerID) {
  18160. if (ownerID === this.__ownerID) {
  18161. return this;
  18162. }
  18163. if (!ownerID) {
  18164. this.__ownerID = ownerID;
  18165. this.__altered = false;
  18166. return this;
  18167. }
  18168. return makeStack(this.size, this._head, ownerID, this.__hash);
  18169. };
  18170. // @pragma Iteration
  18171. Stack.prototype.__iterate = function(fn, reverse) {
  18172. if (reverse) {
  18173. return this.reverse().__iterate(fn);
  18174. }
  18175. var iterations = 0;
  18176. var node = this._head;
  18177. while (node) {
  18178. if (fn(node.value, iterations++, this) === false) {
  18179. break;
  18180. }
  18181. node = node.next;
  18182. }
  18183. return iterations;
  18184. };
  18185. Stack.prototype.__iterator = function(type, reverse) {
  18186. if (reverse) {
  18187. return this.reverse().__iterator(type);
  18188. }
  18189. var iterations = 0;
  18190. var node = this._head;
  18191. return new Iterator(function() {
  18192. if (node) {
  18193. var value = node.value;
  18194. node = node.next;
  18195. return iteratorValue(type, iterations++, value);
  18196. }
  18197. return iteratorDone();
  18198. });
  18199. };
  18200. function isStack(maybeStack) {
  18201. return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
  18202. }
  18203. Stack.isStack = isStack;
  18204. var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
  18205. var StackPrototype = Stack.prototype;
  18206. StackPrototype[IS_STACK_SENTINEL] = true;
  18207. StackPrototype.withMutations = MapPrototype.withMutations;
  18208. StackPrototype.asMutable = MapPrototype.asMutable;
  18209. StackPrototype.asImmutable = MapPrototype.asImmutable;
  18210. StackPrototype.wasAltered = MapPrototype.wasAltered;
  18211. function makeStack(size, head, ownerID, hash) {
  18212. var map = Object.create(StackPrototype);
  18213. map.size = size;
  18214. map._head = head;
  18215. map.__ownerID = ownerID;
  18216. map.__hash = hash;
  18217. map.__altered = false;
  18218. return map;
  18219. }
  18220. var EMPTY_STACK;
  18221. function emptyStack() {
  18222. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  18223. }
  18224. /**
  18225. * Contributes additional methods to a constructor
  18226. */
  18227. function mixin(ctor, methods) {
  18228. var keyCopier = function(key ) { ctor.prototype[key] = methods[key]; };
  18229. Object.keys(methods).forEach(keyCopier);
  18230. Object.getOwnPropertySymbols &&
  18231. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  18232. return ctor;
  18233. }
  18234. Iterable.Iterator = Iterator;
  18235. mixin(Iterable, {
  18236. // ### Conversion to other types
  18237. toArray: function() {
  18238. assertNotInfinite(this.size);
  18239. var array = new Array(this.size || 0);
  18240. this.valueSeq().__iterate(function(v, i) { array[i] = v; });
  18241. return array;
  18242. },
  18243. toIndexedSeq: function() {
  18244. return new ToIndexedSequence(this);
  18245. },
  18246. toJS: function() {
  18247. return this.toSeq().map(
  18248. function(value ) {return value && typeof value.toJS === 'function' ? value.toJS() : value}
  18249. ).__toJS();
  18250. },
  18251. toJSON: function() {
  18252. return this.toSeq().map(
  18253. function(value ) {return value && typeof value.toJSON === 'function' ? value.toJSON() : value}
  18254. ).__toJS();
  18255. },
  18256. toKeyedSeq: function() {
  18257. return new ToKeyedSequence(this, true);
  18258. },
  18259. toMap: function() {
  18260. // Use Late Binding here to solve the circular dependency.
  18261. return Map(this.toKeyedSeq());
  18262. },
  18263. toObject: function() {
  18264. assertNotInfinite(this.size);
  18265. var object = {};
  18266. this.__iterate(function(v, k) { object[k] = v; });
  18267. return object;
  18268. },
  18269. toOrderedMap: function() {
  18270. // Use Late Binding here to solve the circular dependency.
  18271. return OrderedMap(this.toKeyedSeq());
  18272. },
  18273. toOrderedSet: function() {
  18274. // Use Late Binding here to solve the circular dependency.
  18275. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  18276. },
  18277. toSet: function() {
  18278. // Use Late Binding here to solve the circular dependency.
  18279. return Set(isKeyed(this) ? this.valueSeq() : this);
  18280. },
  18281. toSetSeq: function() {
  18282. return new ToSetSequence(this);
  18283. },
  18284. toSeq: function() {
  18285. return isIndexed(this) ? this.toIndexedSeq() :
  18286. isKeyed(this) ? this.toKeyedSeq() :
  18287. this.toSetSeq();
  18288. },
  18289. toStack: function() {
  18290. // Use Late Binding here to solve the circular dependency.
  18291. return Stack(isKeyed(this) ? this.valueSeq() : this);
  18292. },
  18293. toList: function() {
  18294. // Use Late Binding here to solve the circular dependency.
  18295. return List(isKeyed(this) ? this.valueSeq() : this);
  18296. },
  18297. // ### Common JavaScript methods and properties
  18298. toString: function() {
  18299. return '[Iterable]';
  18300. },
  18301. __toString: function(head, tail) {
  18302. if (this.size === 0) {
  18303. return head + tail;
  18304. }
  18305. return head + ' ' + this.toSeq().map(this.__toStringMapper).join(', ') + ' ' + tail;
  18306. },
  18307. // ### ES6 Collection methods (ES6 Array and Map)
  18308. concat: function() {var values = SLICE$0.call(arguments, 0);
  18309. return reify(this, concatFactory(this, values));
  18310. },
  18311. includes: function(searchValue) {
  18312. return this.some(function(value ) {return is(value, searchValue)});
  18313. },
  18314. entries: function() {
  18315. return this.__iterator(ITERATE_ENTRIES);
  18316. },
  18317. every: function(predicate, context) {
  18318. assertNotInfinite(this.size);
  18319. var returnValue = true;
  18320. this.__iterate(function(v, k, c) {
  18321. if (!predicate.call(context, v, k, c)) {
  18322. returnValue = false;
  18323. return false;
  18324. }
  18325. });
  18326. return returnValue;
  18327. },
  18328. filter: function(predicate, context) {
  18329. return reify(this, filterFactory(this, predicate, context, true));
  18330. },
  18331. find: function(predicate, context, notSetValue) {
  18332. var entry = this.findEntry(predicate, context);
  18333. return entry ? entry[1] : notSetValue;
  18334. },
  18335. findEntry: function(predicate, context) {
  18336. var found;
  18337. this.__iterate(function(v, k, c) {
  18338. if (predicate.call(context, v, k, c)) {
  18339. found = [k, v];
  18340. return false;
  18341. }
  18342. });
  18343. return found;
  18344. },
  18345. findLastEntry: function(predicate, context) {
  18346. return this.toSeq().reverse().findEntry(predicate, context);
  18347. },
  18348. forEach: function(sideEffect, context) {
  18349. assertNotInfinite(this.size);
  18350. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  18351. },
  18352. join: function(separator) {
  18353. assertNotInfinite(this.size);
  18354. separator = separator !== undefined ? '' + separator : ',';
  18355. var joined = '';
  18356. var isFirst = true;
  18357. this.__iterate(function(v ) {
  18358. isFirst ? (isFirst = false) : (joined += separator);
  18359. joined += v !== null && v !== undefined ? v.toString() : '';
  18360. });
  18361. return joined;
  18362. },
  18363. keys: function() {
  18364. return this.__iterator(ITERATE_KEYS);
  18365. },
  18366. map: function(mapper, context) {
  18367. return reify(this, mapFactory(this, mapper, context));
  18368. },
  18369. reduce: function(reducer, initialReduction, context) {
  18370. assertNotInfinite(this.size);
  18371. var reduction;
  18372. var useFirst;
  18373. if (arguments.length < 2) {
  18374. useFirst = true;
  18375. } else {
  18376. reduction = initialReduction;
  18377. }
  18378. this.__iterate(function(v, k, c) {
  18379. if (useFirst) {
  18380. useFirst = false;
  18381. reduction = v;
  18382. } else {
  18383. reduction = reducer.call(context, reduction, v, k, c);
  18384. }
  18385. });
  18386. return reduction;
  18387. },
  18388. reduceRight: function(reducer, initialReduction, context) {
  18389. var reversed = this.toKeyedSeq().reverse();
  18390. return reversed.reduce.apply(reversed, arguments);
  18391. },
  18392. reverse: function() {
  18393. return reify(this, reverseFactory(this, true));
  18394. },
  18395. slice: function(begin, end) {
  18396. return reify(this, sliceFactory(this, begin, end, true));
  18397. },
  18398. some: function(predicate, context) {
  18399. return !this.every(not(predicate), context);
  18400. },
  18401. sort: function(comparator) {
  18402. return reify(this, sortFactory(this, comparator));
  18403. },
  18404. values: function() {
  18405. return this.__iterator(ITERATE_VALUES);
  18406. },
  18407. // ### More sequential methods
  18408. butLast: function() {
  18409. return this.slice(0, -1);
  18410. },
  18411. isEmpty: function() {
  18412. return this.size !== undefined ? this.size === 0 : !this.some(function() {return true});
  18413. },
  18414. count: function(predicate, context) {
  18415. return ensureSize(
  18416. predicate ? this.toSeq().filter(predicate, context) : this
  18417. );
  18418. },
  18419. countBy: function(grouper, context) {
  18420. return countByFactory(this, grouper, context);
  18421. },
  18422. equals: function(other) {
  18423. return deepEqual(this, other);
  18424. },
  18425. entrySeq: function() {
  18426. var iterable = this;
  18427. if (iterable._cache) {
  18428. // We cache as an entries array, so we can just return the cache!
  18429. return new ArraySeq(iterable._cache);
  18430. }
  18431. var entriesSequence = iterable.toSeq().map(entryMapper).toIndexedSeq();
  18432. entriesSequence.fromEntrySeq = function() {return iterable.toSeq()};
  18433. return entriesSequence;
  18434. },
  18435. filterNot: function(predicate, context) {
  18436. return this.filter(not(predicate), context);
  18437. },
  18438. findLast: function(predicate, context, notSetValue) {
  18439. return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
  18440. },
  18441. first: function() {
  18442. return this.find(returnTrue);
  18443. },
  18444. flatMap: function(mapper, context) {
  18445. return reify(this, flatMapFactory(this, mapper, context));
  18446. },
  18447. flatten: function(depth) {
  18448. return reify(this, flattenFactory(this, depth, true));
  18449. },
  18450. fromEntrySeq: function() {
  18451. return new FromEntriesSequence(this);
  18452. },
  18453. get: function(searchKey, notSetValue) {
  18454. return this.find(function(_, key) {return is(key, searchKey)}, undefined, notSetValue);
  18455. },
  18456. getIn: function(searchKeyPath, notSetValue) {
  18457. var nested = this;
  18458. // Note: in an ES6 environment, we would prefer:
  18459. // for (var key of searchKeyPath) {
  18460. var iter = forceIterator(searchKeyPath);
  18461. var step;
  18462. while (!(step = iter.next()).done) {
  18463. var key = step.value;
  18464. nested = nested && nested.get ? nested.get(key, NOT_SET) : NOT_SET;
  18465. if (nested === NOT_SET) {
  18466. return notSetValue;
  18467. }
  18468. }
  18469. return nested;
  18470. },
  18471. groupBy: function(grouper, context) {
  18472. return groupByFactory(this, grouper, context);
  18473. },
  18474. has: function(searchKey) {
  18475. return this.get(searchKey, NOT_SET) !== NOT_SET;
  18476. },
  18477. hasIn: function(searchKeyPath) {
  18478. return this.getIn(searchKeyPath, NOT_SET) !== NOT_SET;
  18479. },
  18480. isSubset: function(iter) {
  18481. iter = typeof iter.includes === 'function' ? iter : Iterable(iter);
  18482. return this.every(function(value ) {return iter.includes(value)});
  18483. },
  18484. isSuperset: function(iter) {
  18485. iter = typeof iter.isSubset === 'function' ? iter : Iterable(iter);
  18486. return iter.isSubset(this);
  18487. },
  18488. keySeq: function() {
  18489. return this.toSeq().map(keyMapper).toIndexedSeq();
  18490. },
  18491. last: function() {
  18492. return this.toSeq().reverse().first();
  18493. },
  18494. max: function(comparator) {
  18495. return maxFactory(this, comparator);
  18496. },
  18497. maxBy: function(mapper, comparator) {
  18498. return maxFactory(this, comparator, mapper);
  18499. },
  18500. min: function(comparator) {
  18501. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator);
  18502. },
  18503. minBy: function(mapper, comparator) {
  18504. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator, mapper);
  18505. },
  18506. rest: function() {
  18507. return this.slice(1);
  18508. },
  18509. skip: function(amount) {
  18510. return this.slice(Math.max(0, amount));
  18511. },
  18512. skipLast: function(amount) {
  18513. return reify(this, this.toSeq().reverse().skip(amount).reverse());
  18514. },
  18515. skipWhile: function(predicate, context) {
  18516. return reify(this, skipWhileFactory(this, predicate, context, true));
  18517. },
  18518. skipUntil: function(predicate, context) {
  18519. return this.skipWhile(not(predicate), context);
  18520. },
  18521. sortBy: function(mapper, comparator) {
  18522. return reify(this, sortFactory(this, comparator, mapper));
  18523. },
  18524. take: function(amount) {
  18525. return this.slice(0, Math.max(0, amount));
  18526. },
  18527. takeLast: function(amount) {
  18528. return reify(this, this.toSeq().reverse().take(amount).reverse());
  18529. },
  18530. takeWhile: function(predicate, context) {
  18531. return reify(this, takeWhileFactory(this, predicate, context));
  18532. },
  18533. takeUntil: function(predicate, context) {
  18534. return this.takeWhile(not(predicate), context);
  18535. },
  18536. valueSeq: function() {
  18537. return this.toIndexedSeq();
  18538. },
  18539. // ### Hashable Object
  18540. hashCode: function() {
  18541. return this.__hash || (this.__hash = hashIterable(this));
  18542. }
  18543. // ### Internal
  18544. // abstract __iterate(fn, reverse)
  18545. // abstract __iterator(type, reverse)
  18546. });
  18547. // var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  18548. // var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  18549. // var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  18550. // var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  18551. var IterablePrototype = Iterable.prototype;
  18552. IterablePrototype[IS_ITERABLE_SENTINEL] = true;
  18553. IterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.values;
  18554. IterablePrototype.__toJS = IterablePrototype.toArray;
  18555. IterablePrototype.__toStringMapper = quoteString;
  18556. IterablePrototype.inspect =
  18557. IterablePrototype.toSource = function() { return this.toString(); };
  18558. IterablePrototype.chain = IterablePrototype.flatMap;
  18559. IterablePrototype.contains = IterablePrototype.includes;
  18560. // Temporary warning about using length
  18561. (function () {
  18562. try {
  18563. Object.defineProperty(IterablePrototype, 'length', {
  18564. get: function () {
  18565. if (!Iterable.noLengthWarning) {
  18566. var stack;
  18567. try {
  18568. throw new Error();
  18569. } catch (error) {
  18570. stack = error.stack;
  18571. }
  18572. if (stack.indexOf('_wrapObject') === -1) {
  18573. console && console.warn && console.warn(
  18574. 'iterable.length has been deprecated, '+
  18575. 'use iterable.size or iterable.count(). '+
  18576. 'This warning will become a silent error in a future version. ' +
  18577. stack
  18578. );
  18579. return this.size;
  18580. }
  18581. }
  18582. }
  18583. });
  18584. } catch (e) {}
  18585. })();
  18586. mixin(KeyedIterable, {
  18587. // ### More sequential methods
  18588. flip: function() {
  18589. return reify(this, flipFactory(this));
  18590. },
  18591. findKey: function(predicate, context) {
  18592. var entry = this.findEntry(predicate, context);
  18593. return entry && entry[0];
  18594. },
  18595. findLastKey: function(predicate, context) {
  18596. return this.toSeq().reverse().findKey(predicate, context);
  18597. },
  18598. keyOf: function(searchValue) {
  18599. return this.findKey(function(value ) {return is(value, searchValue)});
  18600. },
  18601. lastKeyOf: function(searchValue) {
  18602. return this.findLastKey(function(value ) {return is(value, searchValue)});
  18603. },
  18604. mapEntries: function(mapper, context) {var this$0 = this;
  18605. var iterations = 0;
  18606. return reify(this,
  18607. this.toSeq().map(
  18608. function(v, k) {return mapper.call(context, [k, v], iterations++, this$0)}
  18609. ).fromEntrySeq()
  18610. );
  18611. },
  18612. mapKeys: function(mapper, context) {var this$0 = this;
  18613. return reify(this,
  18614. this.toSeq().flip().map(
  18615. function(k, v) {return mapper.call(context, k, v, this$0)}
  18616. ).flip()
  18617. );
  18618. }
  18619. });
  18620. var KeyedIterablePrototype = KeyedIterable.prototype;
  18621. KeyedIterablePrototype[IS_KEYED_SENTINEL] = true;
  18622. KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries;
  18623. KeyedIterablePrototype.__toJS = IterablePrototype.toObject;
  18624. KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)};
  18625. mixin(IndexedIterable, {
  18626. // ### Conversion to other types
  18627. toKeyedSeq: function() {
  18628. return new ToKeyedSequence(this, false);
  18629. },
  18630. // ### ES6 Collection methods (ES6 Array and Map)
  18631. filter: function(predicate, context) {
  18632. return reify(this, filterFactory(this, predicate, context, false));
  18633. },
  18634. findIndex: function(predicate, context) {
  18635. var entry = this.findEntry(predicate, context);
  18636. return entry ? entry[0] : -1;
  18637. },
  18638. indexOf: function(searchValue) {
  18639. var key = this.toKeyedSeq().keyOf(searchValue);
  18640. return key === undefined ? -1 : key;
  18641. },
  18642. lastIndexOf: function(searchValue) {
  18643. var key = this.toKeyedSeq().reverse().keyOf(searchValue);
  18644. return key === undefined ? -1 : key;
  18645. // var index =
  18646. // return this.toSeq().reverse().indexOf(searchValue);
  18647. },
  18648. reverse: function() {
  18649. return reify(this, reverseFactory(this, false));
  18650. },
  18651. slice: function(begin, end) {
  18652. return reify(this, sliceFactory(this, begin, end, false));
  18653. },
  18654. splice: function(index, removeNum /*, ...values*/) {
  18655. var numArgs = arguments.length;
  18656. removeNum = Math.max(removeNum | 0, 0);
  18657. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  18658. return this;
  18659. }
  18660. // If index is negative, it should resolve relative to the size of the
  18661. // collection. However size may be expensive to compute if not cached, so
  18662. // only call count() if the number is in fact negative.
  18663. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  18664. var spliced = this.slice(0, index);
  18665. return reify(
  18666. this,
  18667. numArgs === 1 ?
  18668. spliced :
  18669. spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  18670. );
  18671. },
  18672. // ### More collection methods
  18673. findLastIndex: function(predicate, context) {
  18674. var key = this.toKeyedSeq().findLastKey(predicate, context);
  18675. return key === undefined ? -1 : key;
  18676. },
  18677. first: function() {
  18678. return this.get(0);
  18679. },
  18680. flatten: function(depth) {
  18681. return reify(this, flattenFactory(this, depth, false));
  18682. },
  18683. get: function(index, notSetValue) {
  18684. index = wrapIndex(this, index);
  18685. return (index < 0 || (this.size === Infinity ||
  18686. (this.size !== undefined && index > this.size))) ?
  18687. notSetValue :
  18688. this.find(function(_, key) {return key === index}, undefined, notSetValue);
  18689. },
  18690. has: function(index) {
  18691. index = wrapIndex(this, index);
  18692. return index >= 0 && (this.size !== undefined ?
  18693. this.size === Infinity || index < this.size :
  18694. this.indexOf(index) !== -1
  18695. );
  18696. },
  18697. interpose: function(separator) {
  18698. return reify(this, interposeFactory(this, separator));
  18699. },
  18700. interleave: function(/*...iterables*/) {
  18701. var iterables = [this].concat(arrCopy(arguments));
  18702. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, iterables);
  18703. var interleaved = zipped.flatten(true);
  18704. if (zipped.size) {
  18705. interleaved.size = zipped.size * iterables.length;
  18706. }
  18707. return reify(this, interleaved);
  18708. },
  18709. last: function() {
  18710. return this.get(-1);
  18711. },
  18712. skipWhile: function(predicate, context) {
  18713. return reify(this, skipWhileFactory(this, predicate, context, false));
  18714. },
  18715. zip: function(/*, ...iterables */) {
  18716. var iterables = [this].concat(arrCopy(arguments));
  18717. return reify(this, zipWithFactory(this, defaultZipper, iterables));
  18718. },
  18719. zipWith: function(zipper/*, ...iterables */) {
  18720. var iterables = arrCopy(arguments);
  18721. iterables[0] = this;
  18722. return reify(this, zipWithFactory(this, zipper, iterables));
  18723. }
  18724. });
  18725. IndexedIterable.prototype[IS_INDEXED_SENTINEL] = true;
  18726. IndexedIterable.prototype[IS_ORDERED_SENTINEL] = true;
  18727. mixin(SetIterable, {
  18728. // ### ES6 Collection methods (ES6 Array and Map)
  18729. get: function(value, notSetValue) {
  18730. return this.has(value) ? value : notSetValue;
  18731. },
  18732. includes: function(value) {
  18733. return this.has(value);
  18734. },
  18735. // ### More sequential methods
  18736. keySeq: function() {
  18737. return this.valueSeq();
  18738. }
  18739. });
  18740. SetIterable.prototype.has = IterablePrototype.includes;
  18741. // Mixin subclasses
  18742. mixin(KeyedSeq, KeyedIterable.prototype);
  18743. mixin(IndexedSeq, IndexedIterable.prototype);
  18744. mixin(SetSeq, SetIterable.prototype);
  18745. mixin(KeyedCollection, KeyedIterable.prototype);
  18746. mixin(IndexedCollection, IndexedIterable.prototype);
  18747. mixin(SetCollection, SetIterable.prototype);
  18748. // #pragma Helper functions
  18749. function keyMapper(v, k) {
  18750. return k;
  18751. }
  18752. function entryMapper(v, k) {
  18753. return [k, v];
  18754. }
  18755. function not(predicate) {
  18756. return function() {
  18757. return !predicate.apply(this, arguments);
  18758. }
  18759. }
  18760. function neg(predicate) {
  18761. return function() {
  18762. return -predicate.apply(this, arguments);
  18763. }
  18764. }
  18765. function quoteString(value) {
  18766. return typeof value === 'string' ? JSON.stringify(value) : value;
  18767. }
  18768. function defaultZipper() {
  18769. return arrCopy(arguments);
  18770. }
  18771. function defaultNegComparator(a, b) {
  18772. return a < b ? 1 : a > b ? -1 : 0;
  18773. }
  18774. function hashIterable(iterable) {
  18775. if (iterable.size === Infinity) {
  18776. return 0;
  18777. }
  18778. var ordered = isOrdered(iterable);
  18779. var keyed = isKeyed(iterable);
  18780. var h = ordered ? 1 : 0;
  18781. var size = iterable.__iterate(
  18782. keyed ?
  18783. ordered ?
  18784. function(v, k) { h = 31 * h + hashMerge(hash(v), hash(k)) | 0; } :
  18785. function(v, k) { h = h + hashMerge(hash(v), hash(k)) | 0; } :
  18786. ordered ?
  18787. function(v ) { h = 31 * h + hash(v) | 0; } :
  18788. function(v ) { h = h + hash(v) | 0; }
  18789. );
  18790. return murmurHashOfSize(size, h);
  18791. }
  18792. function murmurHashOfSize(size, h) {
  18793. h = imul(h, 0xCC9E2D51);
  18794. h = imul(h << 15 | h >>> -15, 0x1B873593);
  18795. h = imul(h << 13 | h >>> -13, 5);
  18796. h = (h + 0xE6546B64 | 0) ^ size;
  18797. h = imul(h ^ h >>> 16, 0x85EBCA6B);
  18798. h = imul(h ^ h >>> 13, 0xC2B2AE35);
  18799. h = smi(h ^ h >>> 16);
  18800. return h;
  18801. }
  18802. function hashMerge(a, b) {
  18803. return a ^ b + 0x9E3779B9 + (a << 6) + (a >> 2) | 0; // int
  18804. }
  18805. var Immutable = {
  18806. Iterable: Iterable,
  18807. Seq: Seq,
  18808. Collection: Collection,
  18809. Map: Map,
  18810. OrderedMap: OrderedMap,
  18811. List: List,
  18812. Stack: Stack,
  18813. Set: Set,
  18814. OrderedSet: OrderedSet,
  18815. Record: Record,
  18816. Range: Range,
  18817. Repeat: Repeat,
  18818. is: is,
  18819. fromJS: fromJS
  18820. };
  18821. return Immutable;
  18822. }));
  18823. });
  18824. var draftjsUtils = createCommonjsModule(function (module, exports) {
  18825. !function(e,t){module.exports=t(Draft,immutable$1);}("undefined"!=typeof self?self:commonjsGlobal,function(e,t){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r});},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=3)}([function(t,n){t.exports=e;},function(e,t,n){function r(e){var t=e.getSelection(),n=e.getCurrentContent(),r=t.getStartKey(),o=t.getEndKey(),i=n.getBlockMap();return i.toSeq().skipUntil(function(e,t){return t===r}).takeUntil(function(e,t){return t===o}).concat([[o,i.get(o)]])}function o(e){return r(e).toList()}function i(e){if(e)return o(e).get(0)}function l(e){if(e){var t=i(e),n=e.getCurrentContent(),r=n.getBlockMap().toSeq().toList(),o=0;if(r.forEach(function(e,n){e.get("key")===t.get("key")&&(o=n-1);}),o>-1)return r.get(o)}}function c(e){return e?e.getCurrentContent().getBlockMap().toList():new v.List}function a(e){var t=o(e);if(!t.some(function(e){return e.type!==t.get(0).type}))return t.get(0).type}function f(e){var t=p.RichUtils.tryToRemoveBlockStyle(e);return t?p.EditorState.push(e,t,"change-block-type"):e}function u(e){var t="",n=e.getSelection(),r=n.getAnchorOffset(),i=n.getFocusOffset(),l=o(e);if(l.size>0){if(n.getIsBackward()){var c=r;r=i,i=c;}for(var a=0;a<l.size;a+=1){var f=0===a?r:0,u=a===l.size-1?i:l.get(a).getText().length;t+=l.get(a).getText().slice(f,u);}}return t}function s(e){var t=e.getCurrentContent(),n=e.getSelection(),r=p.Modifier.removeRange(t,n,"forward"),o=r.getSelectionAfter(),i=r.getBlockForKey(o.getStartKey());return r=p.Modifier.insertText(r,o,"\n",i.getInlineStyleAt(o.getStartOffset()),null),p.EditorState.push(e,r,"insert-fragment")}function g(e){var t=p.Modifier.splitBlock(e.getCurrentContent(),e.getSelection());return f(p.EditorState.push(e,t,"split-block"))}function d(e){var t=e.getCurrentContent().getBlockMap().toList(),n=e.getSelection().merge({anchorKey:t.first().get("key"),anchorOffset:0,focusKey:t.last().get("key"),focusOffset:t.last().getLength()}),r=p.Modifier.removeRange(e.getCurrentContent(),n,"forward");return p.EditorState.push(e,r,"remove-range")}function S(e,t){var n=p.Modifier.setBlockData(e.getCurrentContent(),e.getSelection(),t);return p.EditorState.push(e,n,"change-block-data")}function y(e){var t=new v.Map({}),n=o(e);if(n&&n.size>0)for(var r=0;r<n.size;r+=1){var i=function(e){var r=n.get(e).getData();if(!r||0===r.size)return t=t.clear(),"break";if(0===e)t=r;else if(t.forEach(function(e,n){r.get(n)&&r.get(n)===e||(t=t.delete(n));}),0===t.size)return t=t.clear(),"break"}(r);if("break"===i)break}return t}Object.defineProperty(t,"__esModule",{value:!0}),t.blockRenderMap=void 0,t.getSelectedBlocksMap=r,t.getSelectedBlocksList=o,t.getSelectedBlock=i,t.getBlockBeforeSelectedBlock=l,t.getAllBlocks=c,t.getSelectedBlocksType=a,t.removeSelectedBlocksStyle=f,t.getSelectionText=u,t.addLineBreakRemovingSelection=s,t.insertNewUnstyledBlock=g,t.clearEditorContent=d,t.setBlockData=S,t.getSelectedBlocksMetadata=y;var p=n(0),v=n(6),k=(0, v.Map)({code:{element:"pre"}});t.blockRenderMap=p.DefaultDraftBlockRenderMap.merge(k);},function(e,t,n){function r(e){if(e){var t=e.getType();return "unordered-list-item"===t||"ordered-list-item"===t}return !1}function o(e,t,n){var r=e.getSelection(),o=e.getCurrentContent(),i=o.getBlockMap(),l=(0, c.getSelectedBlocksMap)(e).map(function(e){var r=e.getDepth()+t;return r=Math.max(0,Math.min(r,n)),e.set("depth",r)});return i=i.merge(l),o.merge({blockMap:i,selectionBefore:r,selectionAfter:r})}function i(e,t,n){var r=e.getSelection(),i=void 0;i=r.getIsBackward()?r.getFocusKey():r.getAnchorKey();var c=e.getCurrentContent(),a=c.getBlockForKey(i),f=a.getType();if("unordered-list-item"!==f&&"ordered-list-item"!==f)return e;var u=c.getBlockBefore(i);if(!u)return e;if(u.getType()!==f)return e;var s=a.getDepth();if(1===t&&s===n)return e;var g=Math.min(u.getDepth()+1,n),d=o(e,t,g);return l.EditorState.push(e,d,"adjust-depth")}Object.defineProperty(t,"__esModule",{value:!0}),t.isListBlock=r,t.changeDepth=i;var l=n(0),c=n(1);},function(e,t,n){e.exports=n(4);},function(e,t,n){var r=n(5),o=n(1),i=n(7),l=function(e){return e&&e.__esModule?e:{default:e}}(i),c=n(2);e.exports={getSelectedBlocksMap:o.getSelectedBlocksMap,getSelectedBlocksList:o.getSelectedBlocksList,getSelectedBlock:o.getSelectedBlock,getBlockBeforeSelectedBlock:o.getBlockBeforeSelectedBlock,getAllBlocks:o.getAllBlocks,getSelectedBlocksType:o.getSelectedBlocksType,removeSelectedBlocksStyle:o.removeSelectedBlocksStyle,getSelectionText:o.getSelectionText,addLineBreakRemovingSelection:o.addLineBreakRemovingSelection,insertNewUnstyledBlock:o.insertNewUnstyledBlock,clearEditorContent:o.clearEditorContent,setBlockData:o.setBlockData,getSelectedBlocksMetadata:o.getSelectedBlocksMetadata,blockRenderMap:o.blockRenderMap,getEntityRange:r.getEntityRange,getCustomStyleMap:r.getCustomStyleMap,toggleCustomInlineStyle:r.toggleCustomInlineStyle,getSelectionEntity:r.getSelectionEntity,extractInlineStyle:r.extractInlineStyle,removeAllInlineStyles:r.removeAllInlineStyles,getSelectionInlineStyle:r.getSelectionInlineStyle,getSelectionCustomInlineStyle:r.getSelectionCustomInlineStyle,handleNewLine:l.default,isListBlock:c.isListBlock,changeDepth:c.changeDepth};},function(e,t,n){function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e){var t=e.getSelection();if(t.isCollapsed()){var n={},r=e.getCurrentInlineStyle().toList().toJS();if(r)return ["BOLD","ITALIC","UNDERLINE","STRIKETHROUGH","CODE","SUPERSCRIPT","SUBSCRIPT"].forEach(function(e){n[e]=r.indexOf(e)>=0;}),n}var o=t.getStartOffset(),i=t.getEndOffset(),l=(0, p.getSelectedBlocksList)(e);if(l.size>0){var c=function(){for(var e={BOLD:!0,ITALIC:!0,UNDERLINE:!0,STRIKETHROUGH:!0,CODE:!0,SUPERSCRIPT:!0,SUBSCRIPT:!0},t=0;t<l.size;t+=1){var n=0===t?o:0,r=t===l.size-1?i:l.get(t).getText().length;n===r&&0===n?(n=1,r=2):n===r&&(n-=1);for(var c=n;c<r;c+=1)!function(n){var r=l.get(t).getInlineStyleAt(n);["BOLD","ITALIC","UNDERLINE","STRIKETHROUGH","CODE","SUPERSCRIPT","SUBSCRIPT"].forEach(function(t){e[t]=e[t]&&r.get(t)===t;});}(c);}return {v:e}}();if("object"===(void 0===c?"undefined":S(c)))return c.v}return {}}function i(e){var t=void 0,n=e.getSelection(),r=n.getStartOffset(),o=n.getEndOffset();r===o&&0===r?o=1:r===o&&(r-=1);for(var i=(0, p.getSelectedBlock)(e),l=r;l<o;l+=1){var c=i.getEntityAt(l);if(!c){t=void 0;break}if(l===r)t=c;else if(t!==c){t=void 0;break}}return t}function l(e,t){var n=(0, p.getSelectedBlock)(e),r=void 0;return n.findEntityRanges(function(e){return e.get("entity")===t},function(e,t){r={start:e,end:t,text:n.get("text").slice(e,t)};}),r}function c(e,t,n){var r=e.getSelection(),o=Object.keys(v[t]).reduce(function(e,t){return y.Modifier.removeInlineStyle(e,r,t)},e.getCurrentContent()),i=y.EditorState.push(e,o,"changeinline-style"),l=e.getCurrentInlineStyle();if(r.isCollapsed()&&(i=l.reduce(function(e,t){return y.RichUtils.toggleInlineStyle(e,t)},i)),"SUPERSCRIPT"===t||"SUBSCRIPT"==t)l.has(n)||(i=y.RichUtils.toggleInlineStyle(i,n));else{var c="bgcolor"===t?"backgroundColor":t;l.has(c+"-"+n)||(i=y.RichUtils.toggleInlineStyle(i,t.toLowerCase()+"-"+n),k(t,c,n));}return i}function a(e){if(e){e.getCurrentContent().getBlockMap().map(function(e){return e.get("characterList")}).toList().flatten().forEach(function(e){e&&0===e.indexOf("color-")?k("color","color",e.substr(6)):e&&0===e.indexOf("bgcolor-")?k("bgcolor","backgroundColor",e.substr(8)):e&&0===e.indexOf("fontsize-")?k("fontSize","fontSize",+e.substr(9)):e&&0===e.indexOf("fontfamily-")&&k("fontFamily","fontFamily",e.substr(11));});}}function f(e,t,n){var r=e.getInlineStyleAt(n).toList(),o=r.filter(function(e){return e.startsWith(t.toLowerCase())});if(o&&o.size>0)return o.get(0)}function u(e,t){var n=e.getCurrentInlineStyle().toList(),r=n.filter(function(e){return e.startsWith(t.toLowerCase())});if(r&&r.size>0)return r.get(0)}function s(e,t){if(e&&t&&t.length>0){var n=function(){var n=e.getSelection(),r={};if(n.isCollapsed())return t.forEach(function(t){r[t]=u(e,t);}),{v:r};var o=n.getStartOffset(),i=n.getEndOffset(),l=(0, p.getSelectedBlocksList)(e);if(l.size>0){for(var c=0;c<l.size;c+=1)!function(e){var n=0===e?o:0,c=e===l.size-1?i:l.get(e).getText().length;n===c&&0===n?(n=1,c=2):n===c&&(n-=1);for(var a=n;a<c;a+=1)!function(o){o===n?t.forEach(function(t){r[t]=f(l.get(e),t,o);}):t.forEach(function(t){r[t]&&r[t]!==f(l.get(e),t,o)&&(r[t]=void 0);});}(a);}(c);return {v:r}}}();if("object"===(void 0===n?"undefined":S(n)))return n.v}return {}}function g(e){var t=e.getCurrentInlineStyle(),n=e.getCurrentContent();return t.forEach(function(t){n=y.Modifier.removeInlineStyle(n,e.getSelection(),t);}),y.EditorState.push(e,n,"change-inline-style")}Object.defineProperty(t,"__esModule",{value:!0}),t.getCustomStyleMap=void 0;var d=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r]);}return e},S="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};t.getSelectionInlineStyle=o,t.getSelectionEntity=i,t.getEntityRange=l,t.toggleCustomInlineStyle=c,t.extractInlineStyle=a,t.getSelectionCustomInlineStyle=s,t.removeAllInlineStyles=g;var y=n(0),p=n(1),v={color:{},bgcolor:{},fontSize:{},fontFamily:{},CODE:{fontFamily:"monospace",wordWrap:"break-word",background:"#f1f1f1",borderRadius:3,padding:"1px 3px"},SUPERSCRIPT:{fontSize:11,position:"relative",top:-8,display:"inline-flex"},SUBSCRIPT:{fontSize:11,position:"relative",bottom:-8,display:"inline-flex"}},k=function(e,t,n){v[e][e.toLowerCase()+"-"+n]=r({},""+t,n);};t.getCustomStyleMap=function(){return d({},v.color,v.bgcolor,v.fontSize,v.fontFamily,{CODE:v.CODE,SUPERSCRIPT:v.SUPERSCRIPT,SUBSCRIPT:v.SUBSCRIPT})};},function(e,n){e.exports=t;},function(e,t,n){function r(e){var t=e.getSelection();if(t.isCollapsed()){var n=e.getCurrentContent(),r=t.getStartKey(),o=n.getBlockForKey(r);if(!(0, a.isListBlock)(o)&&"unstyled"!==o.getType()&&o.getLength()===t.getStartOffset())return (0, c.insertNewUnstyledBlock)(e);if((0, a.isListBlock)(o)&&0===o.getLength()){var i=o.getDepth();if(0===i)return (0, c.removeSelectedBlocksStyle)(e);if(i>0)return (0, a.changeDepth)(e,-1,i)}}}function o(e){return 13===e.which&&(e.getModifierState("Shift")||e.getModifierState("Alt")||e.getModifierState("Control"))}function i(e,t){if(o(t)){return e.getSelection().isCollapsed()?l.RichUtils.insertSoftNewline(e):(0, c.addLineBreakRemovingSelection)(e)}return r(e)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=i;var l=n(0),c=n(1),a=n(2);}])});
  18826. });
  18827. unwrapExports(draftjsUtils);
  18828. var draftjsUtils_1 = draftjsUtils.draftjsUtils;
  18829. var interopRequireDefault = createCommonjsModule(function (module) {
  18830. function _interopRequireDefault(obj) {
  18831. return obj && obj.__esModule ? obj : {
  18832. "default": obj
  18833. };
  18834. }
  18835. module.exports = _interopRequireDefault;
  18836. });
  18837. unwrapExports(interopRequireDefault);
  18838. /**
  18839. * Copyright (c) 2013-present, Facebook, Inc.
  18840. *
  18841. * This source code is licensed under the MIT license found in the
  18842. * LICENSE file in the root directory of this source tree.
  18843. */
  18844. /**
  18845. * Use invariant() to assert state which your program assumes to be true.
  18846. *
  18847. * Provide sprintf-style format (only %s is supported) and arguments
  18848. * to provide information about what broke and what you were
  18849. * expecting.
  18850. *
  18851. * The invariant message will be stripped in production, but the invariant
  18852. * will remain to ensure logic does not differ in production.
  18853. */
  18854. var invariant$1 = function(condition, format, a, b, c, d, e, f) {
  18855. if (process.env.NODE_ENV !== 'production') {
  18856. if (format === undefined) {
  18857. throw new Error('invariant requires an error message argument');
  18858. }
  18859. }
  18860. if (!condition) {
  18861. var error;
  18862. if (format === undefined) {
  18863. error = new Error(
  18864. 'Minified exception occurred; use the non-minified dev environment ' +
  18865. 'for the full error message and additional helpful warnings.'
  18866. );
  18867. } else {
  18868. var args = [a, b, c, d, e, f];
  18869. var argIndex = 0;
  18870. error = new Error(
  18871. format.replace(/%s/g, function() { return args[argIndex++]; })
  18872. );
  18873. error.name = 'Invariant Violation';
  18874. }
  18875. error.framesToPop = 1; // we don't care about invariant's own frame
  18876. throw error;
  18877. }
  18878. };
  18879. var browser = invariant$1;
  18880. function _arrayWithoutHoles(arr) {
  18881. if (Array.isArray(arr)) {
  18882. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
  18883. arr2[i] = arr[i];
  18884. }
  18885. return arr2;
  18886. }
  18887. }
  18888. var arrayWithoutHoles = _arrayWithoutHoles;
  18889. function _iterableToArray(iter) {
  18890. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  18891. }
  18892. var iterableToArray = _iterableToArray;
  18893. function _nonIterableSpread() {
  18894. throw new TypeError("Invalid attempt to spread non-iterable instance");
  18895. }
  18896. var nonIterableSpread = _nonIterableSpread;
  18897. function _toConsumableArray(arr) {
  18898. return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread();
  18899. }
  18900. var toConsumableArray = _toConsumableArray;
  18901. var updateMutation_1 = createCommonjsModule(function (module, exports) {
  18902. Object.defineProperty(exports, "__esModule", {
  18903. value: true
  18904. });
  18905. exports["default"] = updateMutation;
  18906. function updateMutation(mutation, originalOffset, originalLength, newLength, prefixLength, suffixLength) {
  18907. // three cases we can reasonably adjust - disjoint mutations that
  18908. // happen later on where the offset will need to be changed,
  18909. // mutations that completely contain the new one where we can adjust
  18910. // the length, and mutations that occur partially within the new one.
  18911. var lengthDiff = newLength - originalLength;
  18912. var mutationAfterChange = originalOffset + originalLength <= mutation.offset;
  18913. if (mutationAfterChange) {
  18914. return Object.assign({}, mutation, {
  18915. offset: mutation.offset + lengthDiff
  18916. });
  18917. }
  18918. var mutationContainsChange = originalOffset >= mutation.offset && originalOffset + originalLength <= mutation.offset + mutation.length;
  18919. if (mutationContainsChange) {
  18920. return Object.assign({}, mutation, {
  18921. length: mutation.length + lengthDiff
  18922. });
  18923. }
  18924. var mutationWithinPrefixChange = mutation.offset >= originalOffset && mutation.offset + mutation.length <= originalOffset + originalLength && prefixLength > 0;
  18925. if (mutationWithinPrefixChange) {
  18926. return Object.assign({}, mutation, {
  18927. offset: mutation.offset + prefixLength
  18928. });
  18929. }
  18930. var mutationContainsPrefix = mutation.offset < originalOffset && mutation.offset + mutation.length <= originalOffset + originalLength && mutation.offset + mutation.length > originalOffset && prefixLength > 0;
  18931. if (mutationContainsPrefix) {
  18932. return [Object.assign({}, mutation, {
  18933. length: originalOffset - mutation.offset
  18934. }), Object.assign({}, mutation, {
  18935. offset: originalOffset + prefixLength,
  18936. length: mutation.offset - originalOffset + mutation.length
  18937. })];
  18938. }
  18939. var mutationContainsSuffix = mutation.offset >= originalOffset && mutation.offset + mutation.length > originalOffset + originalLength && originalOffset + originalLength > mutation.offset && suffixLength > 0;
  18940. if (mutationContainsSuffix) {
  18941. return [Object.assign({}, mutation, {
  18942. offset: mutation.offset + prefixLength,
  18943. length: originalOffset + originalLength - mutation.offset
  18944. }), Object.assign({}, mutation, {
  18945. offset: originalOffset + originalLength + prefixLength + suffixLength,
  18946. length: mutation.offset + mutation.length - (originalOffset + originalLength)
  18947. })];
  18948. }
  18949. return mutation;
  18950. }
  18951. });
  18952. unwrapExports(updateMutation_1);
  18953. var rangeSort = createCommonjsModule(function (module, exports) {
  18954. Object.defineProperty(exports, "__esModule", {
  18955. value: true
  18956. });
  18957. exports["default"] = void 0;
  18958. var _default = function _default(r1, r2) {
  18959. if (r1.offset === r2.offset) {
  18960. return r2.length - r1.length;
  18961. }
  18962. return r1.offset - r2.offset;
  18963. };
  18964. exports["default"] = _default;
  18965. });
  18966. unwrapExports(rangeSort);
  18967. var encodeBlock = createCommonjsModule(function (module, exports) {
  18968. Object.defineProperty(exports, "__esModule", {
  18969. value: true
  18970. });
  18971. exports["default"] = void 0;
  18972. var _toConsumableArray2 = interopRequireDefault(toConsumableArray);
  18973. var _updateMutation = interopRequireDefault(updateMutation_1);
  18974. var _rangeSort = interopRequireDefault(rangeSort);
  18975. var ENTITY_MAP = {
  18976. '&': '&amp;',
  18977. '<': '&lt;',
  18978. '>': '&gt;',
  18979. '"': '&quot;',
  18980. "'": '&#x27;',
  18981. '`': '&#x60;',
  18982. '\n': '<br/>'
  18983. };
  18984. var _default = function _default(block) {
  18985. var blockText = (0, _toConsumableArray2["default"])(block.text);
  18986. var entities = block.entityRanges.sort(_rangeSort["default"]);
  18987. var styles = block.inlineStyleRanges.sort(_rangeSort["default"]);
  18988. var resultText = '';
  18989. var _loop = function _loop(index) {
  18990. var _char = blockText[index];
  18991. if (ENTITY_MAP[_char] !== undefined) {
  18992. var encoded = ENTITY_MAP[_char];
  18993. var resultIndex = (0, _toConsumableArray2["default"])(resultText).length;
  18994. resultText += encoded;
  18995. var updateForChar = function updateForChar(mutation) {
  18996. return (0, _updateMutation["default"])(mutation, resultIndex, _char.length, encoded.length, 0, 0);
  18997. };
  18998. entities = entities.map(updateForChar);
  18999. styles = styles.map(updateForChar);
  19000. } else {
  19001. resultText += _char;
  19002. }
  19003. };
  19004. for (var index = 0; index < blockText.length; index++) {
  19005. _loop(index);
  19006. }
  19007. return Object.assign({}, block, {
  19008. text: resultText,
  19009. inlineStyleRanges: styles,
  19010. entityRanges: entities
  19011. });
  19012. };
  19013. exports["default"] = _default;
  19014. });
  19015. unwrapExports(encodeBlock);
  19016. var _typeof_1 = createCommonjsModule(function (module) {
  19017. function _typeof(obj) {
  19018. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  19019. module.exports = _typeof = function _typeof(obj) {
  19020. return typeof obj;
  19021. };
  19022. } else {
  19023. module.exports = _typeof = function _typeof(obj) {
  19024. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  19025. };
  19026. }
  19027. return _typeof(obj);
  19028. }
  19029. module.exports = _typeof;
  19030. });
  19031. var splitReactElement_1 = createCommonjsModule(function (module, exports) {
  19032. Object.defineProperty(exports, "__esModule", {
  19033. value: true
  19034. });
  19035. exports["default"] = splitReactElement;
  19036. var _invariant = interopRequireDefault(browser);
  19037. var _react = interopRequireDefault(React);
  19038. var _server = interopRequireDefault(server);
  19039. // see http://w3c.github.io/html/syntax.html#writing-html-documents-elements
  19040. var VOID_TAGS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
  19041. function splitReactElement(element) {
  19042. if (VOID_TAGS.indexOf(element.type) !== -1) {
  19043. return _server["default"].renderToStaticMarkup(element);
  19044. }
  19045. var tags = _server["default"].renderToStaticMarkup(_react["default"].cloneElement(element, {}, '\r')).split('\r');
  19046. (0, _invariant["default"])(tags.length > 1, "convertToHTML: Element of type ".concat(element.type, " must render children"));
  19047. (0, _invariant["default"])(tags.length < 3, "convertToHTML: Element of type ".concat(element.type, " cannot use carriage return character"));
  19048. return {
  19049. start: tags[0],
  19050. end: tags[1]
  19051. };
  19052. }
  19053. });
  19054. unwrapExports(splitReactElement_1);
  19055. var getElementHTML_1 = createCommonjsModule(function (module, exports) {
  19056. Object.defineProperty(exports, "__esModule", {
  19057. value: true
  19058. });
  19059. exports["default"] = getElementHTML;
  19060. var _typeof2 = interopRequireDefault(_typeof_1);
  19061. var _invariant = interopRequireDefault(browser);
  19062. var _react = interopRequireDefault(React);
  19063. var _server = interopRequireDefault(server);
  19064. var _splitReactElement = interopRequireDefault(splitReactElement_1);
  19065. function hasChildren(element) {
  19066. return _react["default"].isValidElement(element) && _react["default"].Children.count(element.props.children) > 0;
  19067. }
  19068. function getElementHTML(element) {
  19069. var text = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  19070. if (element === undefined || element === null) {
  19071. return element;
  19072. }
  19073. if (typeof element === 'string') {
  19074. return element;
  19075. }
  19076. if (_react["default"].isValidElement(element)) {
  19077. if (hasChildren(element)) {
  19078. return _server["default"].renderToStaticMarkup(element);
  19079. }
  19080. var tags = (0, _splitReactElement["default"])(element);
  19081. if (text !== null && (0, _typeof2["default"])(tags) === 'object') {
  19082. var start = tags.start,
  19083. end = tags.end;
  19084. return start + text + end;
  19085. }
  19086. return tags;
  19087. }
  19088. (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');
  19089. if (text !== null) {
  19090. var _start = element.start,
  19091. _end = element.end;
  19092. return _start + text + _end;
  19093. }
  19094. return element;
  19095. }
  19096. });
  19097. unwrapExports(getElementHTML_1);
  19098. var getElementTagLength_1 = createCommonjsModule(function (module, exports) {
  19099. Object.defineProperty(exports, "__esModule", {
  19100. value: true
  19101. });
  19102. exports["default"] = void 0;
  19103. var _typeof2 = interopRequireDefault(_typeof_1);
  19104. var _react = interopRequireDefault(React);
  19105. var _splitReactElement = interopRequireDefault(splitReactElement_1);
  19106. var getElementTagLength = function getElementTagLength(element) {
  19107. var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'start';
  19108. if (_react["default"].isValidElement(element)) {
  19109. var splitElement = (0, _splitReactElement["default"])(element);
  19110. if (typeof splitElement === 'string') {
  19111. return 0;
  19112. }
  19113. var length = splitElement[type].length;
  19114. var child = _react["default"].Children.toArray(element.props.children)[0];
  19115. return length + (child && _react["default"].isValidElement(child) ? getElementTagLength(child, type) : 0);
  19116. }
  19117. if ((0, _typeof2["default"])(element) === 'object') {
  19118. return element[type] ? element[type].length : 0;
  19119. }
  19120. return 0;
  19121. };
  19122. var _default = getElementTagLength;
  19123. exports["default"] = _default;
  19124. });
  19125. unwrapExports(getElementTagLength_1);
  19126. var blockEntities = createCommonjsModule(function (module, exports) {
  19127. Object.defineProperty(exports, "__esModule", {
  19128. value: true
  19129. });
  19130. exports["default"] = void 0;
  19131. var _toConsumableArray2 = interopRequireDefault(toConsumableArray);
  19132. var _updateMutation = interopRequireDefault(updateMutation_1);
  19133. var _rangeSort = interopRequireDefault(rangeSort);
  19134. var _getElementHTML = interopRequireDefault(getElementHTML_1);
  19135. var _getElementTagLength = interopRequireDefault(getElementTagLength_1);
  19136. var converter = function converter() {
  19137. var originalText = arguments.length > 1 ? arguments[1] : undefined;
  19138. return originalText;
  19139. };
  19140. var _default = function _default(block, entityMap) {
  19141. var entityConverter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : converter;
  19142. var resultText = (0, _toConsumableArray2["default"])(block.text);
  19143. var getEntityHTML = entityConverter;
  19144. if (entityConverter.__isMiddleware) {
  19145. getEntityHTML = entityConverter(converter);
  19146. }
  19147. if (Object.prototype.hasOwnProperty.call(block, 'entityRanges') && block.entityRanges.length > 0) {
  19148. var entities = block.entityRanges.sort(_rangeSort["default"]);
  19149. var styles = block.inlineStyleRanges;
  19150. var _loop = function _loop(index) {
  19151. var entityRange = entities[index];
  19152. var entity = entityMap[entityRange.key];
  19153. var originalText = resultText.slice(entityRange.offset, entityRange.offset + entityRange.length).join('');
  19154. var entityHTML = getEntityHTML(entity, originalText);
  19155. var converted = (0, _toConsumableArray2["default"])((0, _getElementHTML["default"])(entityHTML, originalText) || originalText);
  19156. var prefixLength = (0, _getElementTagLength["default"])(entityHTML, 'start');
  19157. var suffixLength = (0, _getElementTagLength["default"])(entityHTML, 'end');
  19158. var updateLaterMutation = function updateLaterMutation(mutation, mutationIndex) {
  19159. if (mutationIndex > index || Object.prototype.hasOwnProperty.call(mutation, 'style')) {
  19160. return (0, _updateMutation["default"])(mutation, entityRange.offset, entityRange.length, converted.length, prefixLength, suffixLength);
  19161. }
  19162. return mutation;
  19163. };
  19164. var updateLaterMutations = function updateLaterMutations(mutationList) {
  19165. return mutationList.reduce(function (acc, mutation, mutationIndex) {
  19166. var updatedMutation = updateLaterMutation(mutation, mutationIndex);
  19167. if (Array.isArray(updatedMutation)) {
  19168. return acc.concat(updatedMutation);
  19169. }
  19170. return acc.concat([updatedMutation]);
  19171. }, []);
  19172. };
  19173. entities = updateLaterMutations(entities);
  19174. styles = updateLaterMutations(styles);
  19175. resultText = [].concat((0, _toConsumableArray2["default"])(resultText.slice(0, entityRange.offset)), (0, _toConsumableArray2["default"])(converted), (0, _toConsumableArray2["default"])(resultText.slice(entityRange.offset + entityRange.length)));
  19176. };
  19177. for (var index = 0; index < entities.length; index++) {
  19178. _loop(index);
  19179. }
  19180. return Object.assign({}, block, {
  19181. text: resultText.join(''),
  19182. inlineStyleRanges: styles,
  19183. entityRanges: entities
  19184. });
  19185. }
  19186. return block;
  19187. };
  19188. exports["default"] = _default;
  19189. });
  19190. unwrapExports(blockEntities);
  19191. var styleObjectFunction = createCommonjsModule(function (module, exports) {
  19192. Object.defineProperty(exports, "__esModule", {
  19193. value: true
  19194. });
  19195. exports["default"] = void 0;
  19196. var _default = function _default(object) {
  19197. return function (style) {
  19198. if (typeof object === 'function') {
  19199. return object(style);
  19200. }
  19201. return object[style];
  19202. };
  19203. };
  19204. exports["default"] = _default;
  19205. });
  19206. unwrapExports(styleObjectFunction);
  19207. var accumulateFunction = createCommonjsModule(function (module, exports) {
  19208. Object.defineProperty(exports, "__esModule", {
  19209. value: true
  19210. });
  19211. exports["default"] = void 0;
  19212. var _default = function _default(newFn, rest) {
  19213. return function () {
  19214. var newResult = newFn.apply(void 0, arguments);
  19215. if (newResult !== undefined && newResult !== null) {
  19216. return newResult;
  19217. }
  19218. return rest.apply(void 0, arguments);
  19219. };
  19220. };
  19221. exports["default"] = _default;
  19222. });
  19223. unwrapExports(accumulateFunction);
  19224. var defaultInlineHTML_1 = createCommonjsModule(function (module, exports) {
  19225. Object.defineProperty(exports, "__esModule", {
  19226. value: true
  19227. });
  19228. exports["default"] = defaultInlineHTML;
  19229. var _react = interopRequireDefault(React);
  19230. function defaultInlineHTML(style) {
  19231. switch (style) {
  19232. case 'BOLD':
  19233. return _react["default"].createElement("strong", null);
  19234. case 'ITALIC':
  19235. return _react["default"].createElement("em", null);
  19236. case 'UNDERLINE':
  19237. return _react["default"].createElement("u", null);
  19238. case 'CODE':
  19239. return _react["default"].createElement("code", null);
  19240. default:
  19241. return {
  19242. start: '',
  19243. end: ''
  19244. };
  19245. }
  19246. }
  19247. });
  19248. unwrapExports(defaultInlineHTML_1);
  19249. var blockInlineStyles = createCommonjsModule(function (module, exports) {
  19250. Object.defineProperty(exports, "__esModule", {
  19251. value: true
  19252. });
  19253. exports["default"] = void 0;
  19254. var _toConsumableArray2 = interopRequireDefault(toConsumableArray);
  19255. var _invariant = interopRequireDefault(browser);
  19256. var _styleObjectFunction = interopRequireDefault(styleObjectFunction);
  19257. var _accumulateFunction = interopRequireDefault(accumulateFunction);
  19258. var _getElementHTML = interopRequireDefault(getElementHTML_1);
  19259. var _rangeSort = interopRequireDefault(rangeSort);
  19260. var _defaultInlineHTML = interopRequireDefault(defaultInlineHTML_1);
  19261. var subtractStyles = function subtractStyles(original, toRemove) {
  19262. return original.filter(function (el) {
  19263. return !toRemove.some(function (elToRemove) {
  19264. return elToRemove.style === el.style;
  19265. });
  19266. });
  19267. };
  19268. var popEndingStyles = function popEndingStyles(styleStack, endingStyles) {
  19269. return endingStyles.reduceRight(function (stack, style) {
  19270. var styleToRemove = stack[stack.length - 1];
  19271. (0, _invariant["default"])(styleToRemove.style === style.style, "Style ".concat(styleToRemove.style, " to be removed doesn't match expected ").concat(style.style));
  19272. return stack.slice(0, -1);
  19273. }, styleStack);
  19274. };
  19275. var characterStyles = function characterStyles(offset, ranges) {
  19276. return ranges.filter(function (range) {
  19277. return offset >= range.offset && offset < range.offset + range.length;
  19278. });
  19279. };
  19280. var rangeIsSubset = function rangeIsSubset(firstRange, secondRange) {
  19281. // returns true if the second range is a subset of the first
  19282. var secondStartWithinFirst = firstRange.offset <= secondRange.offset;
  19283. var secondEndWithinFirst = firstRange.offset + firstRange.length >= secondRange.offset + secondRange.length;
  19284. return secondStartWithinFirst && secondEndWithinFirst;
  19285. };
  19286. var latestStyleLast = function latestStyleLast(s1, s2) {
  19287. // make sure longer-lasting styles are added first
  19288. var s2endIndex = s2.offset + s2.length;
  19289. var s1endIndex = s1.offset + s1.length;
  19290. return s2endIndex - s1endIndex;
  19291. };
  19292. var getStylesToReset = function getStylesToReset(remainingStyles, newStyles) {
  19293. var i = 0;
  19294. while (i < remainingStyles.length) {
  19295. if (newStyles.every(rangeIsSubset.bind(null, remainingStyles[i]))) {
  19296. i++;
  19297. } else {
  19298. return remainingStyles.slice(i);
  19299. }
  19300. }
  19301. return [];
  19302. };
  19303. var appendStartMarkup = function appendStartMarkup(inlineHTML, string, styleRange) {
  19304. return string + (0, _getElementHTML["default"])(inlineHTML(styleRange.style)).start;
  19305. };
  19306. var prependEndMarkup = function prependEndMarkup(inlineHTML, string, styleRange) {
  19307. return (0, _getElementHTML["default"])(inlineHTML(styleRange.style)).end + string;
  19308. };
  19309. var defaultCustomInlineHTML = function defaultCustomInlineHTML(next) {
  19310. return function (style) {
  19311. return next(style);
  19312. };
  19313. };
  19314. defaultCustomInlineHTML.__isMiddleware = true;
  19315. var _default = function _default(rawBlock) {
  19316. var customInlineHTML = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultCustomInlineHTML;
  19317. (0, _invariant["default"])(rawBlock !== null && rawBlock !== undefined, 'Expected raw block to be non-null');
  19318. var inlineHTML;
  19319. if (customInlineHTML.__isMiddleware === true) {
  19320. inlineHTML = customInlineHTML(_defaultInlineHTML["default"]);
  19321. } else {
  19322. inlineHTML = (0, _accumulateFunction["default"])((0, _styleObjectFunction["default"])(customInlineHTML), (0, _styleObjectFunction["default"])(_defaultInlineHTML["default"]));
  19323. }
  19324. var result = '';
  19325. var styleStack = [];
  19326. var sortedRanges = rawBlock.inlineStyleRanges.sort(_rangeSort["default"]);
  19327. var originalTextArray = (0, _toConsumableArray2["default"])(rawBlock.text);
  19328. for (var i = 0; i < originalTextArray.length; i++) {
  19329. var styles = characterStyles(i, sortedRanges);
  19330. var endingStyles = subtractStyles(styleStack, styles);
  19331. var newStyles = subtractStyles(styles, styleStack);
  19332. var remainingStyles = subtractStyles(styleStack, endingStyles); // reset styles: look for any already existing styles that will need to
  19333. // end before styles that are being added on this character. to solve this
  19334. // close out those current tags and all nested children,
  19335. // then open new ones nested within the new styles.
  19336. var resetStyles = getStylesToReset(remainingStyles, newStyles);
  19337. var openingStyles = resetStyles.concat(newStyles).sort(latestStyleLast);
  19338. var openingStyleTags = openingStyles.reduce(appendStartMarkup.bind(null, inlineHTML), '');
  19339. var endingStyleTags = endingStyles.concat(resetStyles).reduce(prependEndMarkup.bind(null, inlineHTML), '');
  19340. result += endingStyleTags + openingStyleTags + originalTextArray[i];
  19341. styleStack = popEndingStyles(styleStack, resetStyles.concat(endingStyles));
  19342. styleStack = styleStack.concat(openingStyles);
  19343. (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"));
  19344. }
  19345. result = styleStack.reduceRight(function (res, openStyle) {
  19346. return res + (0, _getElementHTML["default"])(inlineHTML(openStyle.style)).end;
  19347. }, result);
  19348. return result;
  19349. };
  19350. exports["default"] = _default;
  19351. });
  19352. unwrapExports(blockInlineStyles);
  19353. var blockTypeObjectFunction = createCommonjsModule(function (module, exports) {
  19354. Object.defineProperty(exports, "__esModule", {
  19355. value: true
  19356. });
  19357. exports["default"] = void 0;
  19358. var _default = function _default(typeObject) {
  19359. return function (block) {
  19360. if (typeof typeObject === 'function') {
  19361. // handle case where typeObject is already a function
  19362. return typeObject(block);
  19363. }
  19364. return typeObject[block.type];
  19365. };
  19366. };
  19367. exports["default"] = _default;
  19368. });
  19369. unwrapExports(blockTypeObjectFunction);
  19370. var getBlockTags_1 = createCommonjsModule(function (module, exports) {
  19371. Object.defineProperty(exports, "__esModule", {
  19372. value: true
  19373. });
  19374. exports["default"] = getBlockTags;
  19375. var _invariant = interopRequireDefault(browser);
  19376. var _react = interopRequireDefault(React);
  19377. var _server = interopRequireDefault(server);
  19378. var _splitReactElement = interopRequireDefault(splitReactElement_1);
  19379. function hasChildren(element) {
  19380. return _react["default"].isValidElement(element) && _react["default"].Children.count(element.props.children) > 0;
  19381. }
  19382. function getBlockTags(blockHTML) {
  19383. (0, _invariant["default"])(blockHTML !== null && blockHTML !== undefined, 'Expected block HTML value to be non-null');
  19384. if (typeof blockHTML === 'string') {
  19385. return blockHTML;
  19386. }
  19387. if (_react["default"].isValidElement(blockHTML)) {
  19388. if (hasChildren(blockHTML)) {
  19389. return _server["default"].renderToStaticMarkup(blockHTML);
  19390. }
  19391. return (0, _splitReactElement["default"])(blockHTML);
  19392. }
  19393. if (Object.prototype.hasOwnProperty.call(blockHTML, 'element') && _react["default"].isValidElement(blockHTML.element)) {
  19394. return Object.assign({}, blockHTML, (0, _splitReactElement["default"])(blockHTML.element));
  19395. }
  19396. (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');
  19397. return blockHTML;
  19398. }
  19399. });
  19400. unwrapExports(getBlockTags_1);
  19401. var getNestedBlockTags_1 = createCommonjsModule(function (module, exports) {
  19402. Object.defineProperty(exports, "__esModule", {
  19403. value: true
  19404. });
  19405. exports["default"] = getNestedBlockTags;
  19406. var _invariant = interopRequireDefault(browser);
  19407. var _react = interopRequireDefault(React);
  19408. var _splitReactElement2 = interopRequireDefault(splitReactElement_1);
  19409. function getNestedBlockTags(blockHTML) {
  19410. (0, _invariant["default"])(blockHTML !== null && blockHTML !== undefined, 'Expected block HTML value to be non-null');
  19411. if (_react["default"].isValidElement(blockHTML.nest)) {
  19412. var _splitReactElement = (0, _splitReactElement2["default"])(blockHTML.nest),
  19413. start = _splitReactElement.start,
  19414. end = _splitReactElement.end;
  19415. return Object.assign({}, blockHTML, {
  19416. nestStart: start,
  19417. nestEnd: end
  19418. });
  19419. }
  19420. (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');
  19421. return blockHTML;
  19422. }
  19423. });
  19424. unwrapExports(getNestedBlockTags_1);
  19425. var defaultBlockHTML = createCommonjsModule(function (module, exports) {
  19426. Object.defineProperty(exports, "__esModule", {
  19427. value: true
  19428. });
  19429. exports["default"] = void 0;
  19430. var _react = interopRequireDefault(React);
  19431. var _default = {
  19432. unstyled: _react["default"].createElement("p", null),
  19433. paragraph: _react["default"].createElement("p", null),
  19434. 'header-one': _react["default"].createElement("h1", null),
  19435. 'header-two': _react["default"].createElement("h2", null),
  19436. 'header-three': _react["default"].createElement("h3", null),
  19437. 'header-four': _react["default"].createElement("h4", null),
  19438. 'header-five': _react["default"].createElement("h5", null),
  19439. 'header-six': _react["default"].createElement("h6", null),
  19440. blockquote: _react["default"].createElement("blockquote", null),
  19441. 'unordered-list-item': {
  19442. element: _react["default"].createElement("li", null),
  19443. nest: _react["default"].createElement("ul", null)
  19444. },
  19445. 'ordered-list-item': {
  19446. element: _react["default"].createElement("li", null),
  19447. nest: _react["default"].createElement("ol", null)
  19448. },
  19449. media: _react["default"].createElement("figure", null),
  19450. atomic: _react["default"].createElement("figure", null)
  19451. };
  19452. exports["default"] = _default;
  19453. });
  19454. unwrapExports(defaultBlockHTML);
  19455. var convertToHTML_1 = createCommonjsModule(function (module, exports) {
  19456. Object.defineProperty(exports, "__esModule", {
  19457. value: true
  19458. });
  19459. exports["default"] = void 0;
  19460. var _invariant = interopRequireDefault(browser);
  19461. var _react = interopRequireDefault(React);
  19462. var _server = interopRequireDefault(server);
  19463. var _encodeBlock = interopRequireDefault(encodeBlock);
  19464. var _blockEntities = interopRequireDefault(blockEntities);
  19465. var _blockInlineStyles = interopRequireDefault(blockInlineStyles);
  19466. var _accumulateFunction = interopRequireDefault(accumulateFunction);
  19467. var _blockTypeObjectFunction = interopRequireDefault(blockTypeObjectFunction);
  19468. var _getBlockTags = interopRequireDefault(getBlockTags_1);
  19469. var _getNestedBlockTags = interopRequireDefault(getNestedBlockTags_1);
  19470. var _defaultBlockHTML = interopRequireDefault(defaultBlockHTML);
  19471. // import Immutable from 'immutable'; // eslint-disable-line no-unused-vars
  19472. var defaultEntityToHTML = function defaultEntityToHTML(entity, originalText) {
  19473. return originalText;
  19474. };
  19475. var convertToHTML = function convertToHTML(_ref) {
  19476. var _ref$styleToHTML = _ref.styleToHTML,
  19477. styleToHTML = _ref$styleToHTML === void 0 ? {} : _ref$styleToHTML,
  19478. _ref$blockToHTML = _ref.blockToHTML,
  19479. blockToHTML = _ref$blockToHTML === void 0 ? {} : _ref$blockToHTML,
  19480. _ref$entityToHTML = _ref.entityToHTML,
  19481. entityToHTML = _ref$entityToHTML === void 0 ? defaultEntityToHTML : _ref$entityToHTML;
  19482. return function (contentState) {
  19483. (0, _invariant["default"])(contentState !== null && contentState !== undefined, 'Expected contentState to be non-null');
  19484. var getBlockHTML;
  19485. if (blockToHTML.__isMiddleware === true) {
  19486. getBlockHTML = blockToHTML((0, _blockTypeObjectFunction["default"])(_defaultBlockHTML["default"]));
  19487. } else {
  19488. getBlockHTML = (0, _accumulateFunction["default"])((0, _blockTypeObjectFunction["default"])(blockToHTML), (0, _blockTypeObjectFunction["default"])(_defaultBlockHTML["default"]));
  19489. }
  19490. var rawState = (0, Draft.convertToRaw)(contentState);
  19491. var listStack = [];
  19492. var result = rawState.blocks.map(function (block) {
  19493. var type = block.type,
  19494. depth = block.depth;
  19495. var closeNestTags = '';
  19496. var openNestTags = '';
  19497. var blockHTMLResult = getBlockHTML(block);
  19498. if (!blockHTMLResult) {
  19499. throw new Error("convertToHTML: missing HTML definition for block with type ".concat(block.type));
  19500. }
  19501. if (!blockHTMLResult.nest) {
  19502. // this block can't be nested, so reset all nesting if necessary
  19503. closeNestTags = listStack.reduceRight(function (string, nestedBlock) {
  19504. return string + (0, _getNestedBlockTags["default"])(getBlockHTML(nestedBlock)).nestEnd;
  19505. }, '');
  19506. listStack = [];
  19507. } else {
  19508. while (depth + 1 !== listStack.length || type !== listStack[depth].type) {
  19509. if (depth + 1 === listStack.length) {
  19510. // depth is right but doesn't match type
  19511. var blockToClose = listStack[depth];
  19512. closeNestTags += (0, _getNestedBlockTags["default"])(getBlockHTML(blockToClose)).nestEnd;
  19513. openNestTags += (0, _getNestedBlockTags["default"])(getBlockHTML(block)).nestStart;
  19514. listStack[depth] = block;
  19515. } else if (depth + 1 < listStack.length) {
  19516. var _blockToClose = listStack[listStack.length - 1];
  19517. closeNestTags += (0, _getNestedBlockTags["default"])(getBlockHTML(_blockToClose)).nestEnd;
  19518. listStack = listStack.slice(0, -1);
  19519. } else {
  19520. openNestTags += (0, _getNestedBlockTags["default"])(getBlockHTML(block)).nestStart;
  19521. listStack.push(block);
  19522. }
  19523. }
  19524. }
  19525. var innerHTML = (0, _blockInlineStyles["default"])((0, _blockEntities["default"])((0, _encodeBlock["default"])(block), rawState.entityMap, entityToHTML), styleToHTML);
  19526. var blockHTML = (0, _getBlockTags["default"])(getBlockHTML(block));
  19527. var html;
  19528. if (typeof blockHTML === 'string') {
  19529. html = blockHTML;
  19530. } else {
  19531. html = blockHTML.start + innerHTML + blockHTML.end;
  19532. }
  19533. if (innerHTML.length === 0 && Object.prototype.hasOwnProperty.call(blockHTML, 'empty')) {
  19534. if (_react["default"].isValidElement(blockHTML.empty)) {
  19535. html = _server["default"].renderToStaticMarkup(blockHTML.empty);
  19536. } else {
  19537. html = blockHTML.empty;
  19538. }
  19539. }
  19540. return closeNestTags + openNestTags + html;
  19541. }).join('');
  19542. result = listStack.reduce(function (res, nestBlock) {
  19543. return res + (0, _getNestedBlockTags["default"])(getBlockHTML(nestBlock)).nestEnd;
  19544. }, result);
  19545. return result;
  19546. };
  19547. };
  19548. var _default = function _default() {
  19549. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  19550. args[_key] = arguments[_key];
  19551. }
  19552. if (args.length === 1 && Object.prototype.hasOwnProperty.call(args[0], '_map') && args[0].getBlockMap != null) {
  19553. // skip higher-order function and use defaults
  19554. return convertToHTML({}).apply(void 0, args);
  19555. }
  19556. return convertToHTML.apply(void 0, args);
  19557. };
  19558. exports["default"] = _default;
  19559. });
  19560. unwrapExports(convertToHTML_1);
  19561. var immutable$2 = createCommonjsModule(function (module, exports) {
  19562. /**
  19563. * Copyright (c) 2014-2015, Facebook, Inc.
  19564. * All rights reserved.
  19565. *
  19566. * This source code is licensed under the BSD-style license found in the
  19567. * LICENSE file in the root directory of this source tree. An additional grant
  19568. * of patent rights can be found in the PATENTS file in the same directory.
  19569. */
  19570. (function (global, factory) {
  19571. module.exports = factory() ;
  19572. }(commonjsGlobal, function () {var SLICE$0 = Array.prototype.slice;
  19573. function createClass(ctor, superClass) {
  19574. if (superClass) {
  19575. ctor.prototype = Object.create(superClass.prototype);
  19576. }
  19577. ctor.prototype.constructor = ctor;
  19578. }
  19579. function Iterable(value) {
  19580. return isIterable(value) ? value : Seq(value);
  19581. }
  19582. createClass(KeyedIterable, Iterable);
  19583. function KeyedIterable(value) {
  19584. return isKeyed(value) ? value : KeyedSeq(value);
  19585. }
  19586. createClass(IndexedIterable, Iterable);
  19587. function IndexedIterable(value) {
  19588. return isIndexed(value) ? value : IndexedSeq(value);
  19589. }
  19590. createClass(SetIterable, Iterable);
  19591. function SetIterable(value) {
  19592. return isIterable(value) && !isAssociative(value) ? value : SetSeq(value);
  19593. }
  19594. function isIterable(maybeIterable) {
  19595. return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]);
  19596. }
  19597. function isKeyed(maybeKeyed) {
  19598. return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
  19599. }
  19600. function isIndexed(maybeIndexed) {
  19601. return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
  19602. }
  19603. function isAssociative(maybeAssociative) {
  19604. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  19605. }
  19606. function isOrdered(maybeOrdered) {
  19607. return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
  19608. }
  19609. Iterable.isIterable = isIterable;
  19610. Iterable.isKeyed = isKeyed;
  19611. Iterable.isIndexed = isIndexed;
  19612. Iterable.isAssociative = isAssociative;
  19613. Iterable.isOrdered = isOrdered;
  19614. Iterable.Keyed = KeyedIterable;
  19615. Iterable.Indexed = IndexedIterable;
  19616. Iterable.Set = SetIterable;
  19617. var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  19618. var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  19619. var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  19620. var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  19621. // Used for setting prototype methods that IE8 chokes on.
  19622. var DELETE = 'delete';
  19623. // Constants describing the size of trie nodes.
  19624. var SHIFT = 5; // Resulted in best performance after ______?
  19625. var SIZE = 1 << SHIFT;
  19626. var MASK = SIZE - 1;
  19627. // A consistent shared value representing "not set" which equals nothing other
  19628. // than itself, and nothing that could be provided externally.
  19629. var NOT_SET = {};
  19630. // Boolean references, Rough equivalent of `bool &`.
  19631. var CHANGE_LENGTH = { value: false };
  19632. var DID_ALTER = { value: false };
  19633. function MakeRef(ref) {
  19634. ref.value = false;
  19635. return ref;
  19636. }
  19637. function SetRef(ref) {
  19638. ref && (ref.value = true);
  19639. }
  19640. // A function which returns a value representing an "owner" for transient writes
  19641. // to tries. The return value will only ever equal itself, and will not equal
  19642. // the return of any subsequent call of this function.
  19643. function OwnerID() {}
  19644. // http://jsperf.com/copy-array-inline
  19645. function arrCopy(arr, offset) {
  19646. offset = offset || 0;
  19647. var len = Math.max(0, arr.length - offset);
  19648. var newArr = new Array(len);
  19649. for (var ii = 0; ii < len; ii++) {
  19650. newArr[ii] = arr[ii + offset];
  19651. }
  19652. return newArr;
  19653. }
  19654. function ensureSize(iter) {
  19655. if (iter.size === undefined) {
  19656. iter.size = iter.__iterate(returnTrue);
  19657. }
  19658. return iter.size;
  19659. }
  19660. function wrapIndex(iter, index) {
  19661. // This implements "is array index" which the ECMAString spec defines as:
  19662. //
  19663. // A String property name P is an array index if and only if
  19664. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  19665. // to 2^32−1.
  19666. //
  19667. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  19668. if (typeof index !== 'number') {
  19669. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  19670. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  19671. return NaN;
  19672. }
  19673. index = uint32Index;
  19674. }
  19675. return index < 0 ? ensureSize(iter) + index : index;
  19676. }
  19677. function returnTrue() {
  19678. return true;
  19679. }
  19680. function wholeSlice(begin, end, size) {
  19681. return (begin === 0 || (size !== undefined && begin <= -size)) &&
  19682. (end === undefined || (size !== undefined && end >= size));
  19683. }
  19684. function resolveBegin(begin, size) {
  19685. return resolveIndex(begin, size, 0);
  19686. }
  19687. function resolveEnd(end, size) {
  19688. return resolveIndex(end, size, size);
  19689. }
  19690. function resolveIndex(index, size, defaultIndex) {
  19691. return index === undefined ?
  19692. defaultIndex :
  19693. index < 0 ?
  19694. Math.max(0, size + index) :
  19695. size === undefined ?
  19696. index :
  19697. Math.min(size, index);
  19698. }
  19699. /* global Symbol */
  19700. var ITERATE_KEYS = 0;
  19701. var ITERATE_VALUES = 1;
  19702. var ITERATE_ENTRIES = 2;
  19703. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  19704. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  19705. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  19706. function Iterator(next) {
  19707. this.next = next;
  19708. }
  19709. Iterator.prototype.toString = function() {
  19710. return '[Iterator]';
  19711. };
  19712. Iterator.KEYS = ITERATE_KEYS;
  19713. Iterator.VALUES = ITERATE_VALUES;
  19714. Iterator.ENTRIES = ITERATE_ENTRIES;
  19715. Iterator.prototype.inspect =
  19716. Iterator.prototype.toSource = function () { return this.toString(); };
  19717. Iterator.prototype[ITERATOR_SYMBOL] = function () {
  19718. return this;
  19719. };
  19720. function iteratorValue(type, k, v, iteratorResult) {
  19721. var value = type === 0 ? k : type === 1 ? v : [k, v];
  19722. iteratorResult ? (iteratorResult.value = value) : (iteratorResult = {
  19723. value: value, done: false
  19724. });
  19725. return iteratorResult;
  19726. }
  19727. function iteratorDone() {
  19728. return { value: undefined, done: true };
  19729. }
  19730. function hasIterator(maybeIterable) {
  19731. return !!getIteratorFn(maybeIterable);
  19732. }
  19733. function isIterator(maybeIterator) {
  19734. return maybeIterator && typeof maybeIterator.next === 'function';
  19735. }
  19736. function getIterator(iterable) {
  19737. var iteratorFn = getIteratorFn(iterable);
  19738. return iteratorFn && iteratorFn.call(iterable);
  19739. }
  19740. function getIteratorFn(iterable) {
  19741. var iteratorFn = iterable && (
  19742. (REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  19743. iterable[FAUX_ITERATOR_SYMBOL]
  19744. );
  19745. if (typeof iteratorFn === 'function') {
  19746. return iteratorFn;
  19747. }
  19748. }
  19749. function isArrayLike(value) {
  19750. return value && typeof value.length === 'number';
  19751. }
  19752. createClass(Seq, Iterable);
  19753. function Seq(value) {
  19754. return value === null || value === undefined ? emptySequence() :
  19755. isIterable(value) ? value.toSeq() : seqFromValue(value);
  19756. }
  19757. Seq.of = function(/*...values*/) {
  19758. return Seq(arguments);
  19759. };
  19760. Seq.prototype.toSeq = function() {
  19761. return this;
  19762. };
  19763. Seq.prototype.toString = function() {
  19764. return this.__toString('Seq {', '}');
  19765. };
  19766. Seq.prototype.cacheResult = function() {
  19767. if (!this._cache && this.__iterateUncached) {
  19768. this._cache = this.entrySeq().toArray();
  19769. this.size = this._cache.length;
  19770. }
  19771. return this;
  19772. };
  19773. // abstract __iterateUncached(fn, reverse)
  19774. Seq.prototype.__iterate = function(fn, reverse) {
  19775. return seqIterate(this, fn, reverse, true);
  19776. };
  19777. // abstract __iteratorUncached(type, reverse)
  19778. Seq.prototype.__iterator = function(type, reverse) {
  19779. return seqIterator(this, type, reverse, true);
  19780. };
  19781. createClass(KeyedSeq, Seq);
  19782. function KeyedSeq(value) {
  19783. return value === null || value === undefined ?
  19784. emptySequence().toKeyedSeq() :
  19785. isIterable(value) ?
  19786. (isKeyed(value) ? value.toSeq() : value.fromEntrySeq()) :
  19787. keyedSeqFromValue(value);
  19788. }
  19789. KeyedSeq.prototype.toKeyedSeq = function() {
  19790. return this;
  19791. };
  19792. createClass(IndexedSeq, Seq);
  19793. function IndexedSeq(value) {
  19794. return value === null || value === undefined ? emptySequence() :
  19795. !isIterable(value) ? indexedSeqFromValue(value) :
  19796. isKeyed(value) ? value.entrySeq() : value.toIndexedSeq();
  19797. }
  19798. IndexedSeq.of = function(/*...values*/) {
  19799. return IndexedSeq(arguments);
  19800. };
  19801. IndexedSeq.prototype.toIndexedSeq = function() {
  19802. return this;
  19803. };
  19804. IndexedSeq.prototype.toString = function() {
  19805. return this.__toString('Seq [', ']');
  19806. };
  19807. IndexedSeq.prototype.__iterate = function(fn, reverse) {
  19808. return seqIterate(this, fn, reverse, false);
  19809. };
  19810. IndexedSeq.prototype.__iterator = function(type, reverse) {
  19811. return seqIterator(this, type, reverse, false);
  19812. };
  19813. createClass(SetSeq, Seq);
  19814. function SetSeq(value) {
  19815. return (
  19816. value === null || value === undefined ? emptySequence() :
  19817. !isIterable(value) ? indexedSeqFromValue(value) :
  19818. isKeyed(value) ? value.entrySeq() : value
  19819. ).toSetSeq();
  19820. }
  19821. SetSeq.of = function(/*...values*/) {
  19822. return SetSeq(arguments);
  19823. };
  19824. SetSeq.prototype.toSetSeq = function() {
  19825. return this;
  19826. };
  19827. Seq.isSeq = isSeq;
  19828. Seq.Keyed = KeyedSeq;
  19829. Seq.Set = SetSeq;
  19830. Seq.Indexed = IndexedSeq;
  19831. var IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
  19832. Seq.prototype[IS_SEQ_SENTINEL] = true;
  19833. createClass(ArraySeq, IndexedSeq);
  19834. function ArraySeq(array) {
  19835. this._array = array;
  19836. this.size = array.length;
  19837. }
  19838. ArraySeq.prototype.get = function(index, notSetValue) {
  19839. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  19840. };
  19841. ArraySeq.prototype.__iterate = function(fn, reverse) {
  19842. var array = this._array;
  19843. var maxIndex = array.length - 1;
  19844. for (var ii = 0; ii <= maxIndex; ii++) {
  19845. if (fn(array[reverse ? maxIndex - ii : ii], ii, this) === false) {
  19846. return ii + 1;
  19847. }
  19848. }
  19849. return ii;
  19850. };
  19851. ArraySeq.prototype.__iterator = function(type, reverse) {
  19852. var array = this._array;
  19853. var maxIndex = array.length - 1;
  19854. var ii = 0;
  19855. return new Iterator(function()
  19856. {return ii > maxIndex ?
  19857. iteratorDone() :
  19858. iteratorValue(type, ii, array[reverse ? maxIndex - ii++ : ii++])}
  19859. );
  19860. };
  19861. createClass(ObjectSeq, KeyedSeq);
  19862. function ObjectSeq(object) {
  19863. var keys = Object.keys(object);
  19864. this._object = object;
  19865. this._keys = keys;
  19866. this.size = keys.length;
  19867. }
  19868. ObjectSeq.prototype.get = function(key, notSetValue) {
  19869. if (notSetValue !== undefined && !this.has(key)) {
  19870. return notSetValue;
  19871. }
  19872. return this._object[key];
  19873. };
  19874. ObjectSeq.prototype.has = function(key) {
  19875. return this._object.hasOwnProperty(key);
  19876. };
  19877. ObjectSeq.prototype.__iterate = function(fn, reverse) {
  19878. var object = this._object;
  19879. var keys = this._keys;
  19880. var maxIndex = keys.length - 1;
  19881. for (var ii = 0; ii <= maxIndex; ii++) {
  19882. var key = keys[reverse ? maxIndex - ii : ii];
  19883. if (fn(object[key], key, this) === false) {
  19884. return ii + 1;
  19885. }
  19886. }
  19887. return ii;
  19888. };
  19889. ObjectSeq.prototype.__iterator = function(type, reverse) {
  19890. var object = this._object;
  19891. var keys = this._keys;
  19892. var maxIndex = keys.length - 1;
  19893. var ii = 0;
  19894. return new Iterator(function() {
  19895. var key = keys[reverse ? maxIndex - ii : ii];
  19896. return ii++ > maxIndex ?
  19897. iteratorDone() :
  19898. iteratorValue(type, key, object[key]);
  19899. });
  19900. };
  19901. ObjectSeq.prototype[IS_ORDERED_SENTINEL] = true;
  19902. createClass(IterableSeq, IndexedSeq);
  19903. function IterableSeq(iterable) {
  19904. this._iterable = iterable;
  19905. this.size = iterable.length || iterable.size;
  19906. }
  19907. IterableSeq.prototype.__iterateUncached = function(fn, reverse) {
  19908. if (reverse) {
  19909. return this.cacheResult().__iterate(fn, reverse);
  19910. }
  19911. var iterable = this._iterable;
  19912. var iterator = getIterator(iterable);
  19913. var iterations = 0;
  19914. if (isIterator(iterator)) {
  19915. var step;
  19916. while (!(step = iterator.next()).done) {
  19917. if (fn(step.value, iterations++, this) === false) {
  19918. break;
  19919. }
  19920. }
  19921. }
  19922. return iterations;
  19923. };
  19924. IterableSeq.prototype.__iteratorUncached = function(type, reverse) {
  19925. if (reverse) {
  19926. return this.cacheResult().__iterator(type, reverse);
  19927. }
  19928. var iterable = this._iterable;
  19929. var iterator = getIterator(iterable);
  19930. if (!isIterator(iterator)) {
  19931. return new Iterator(iteratorDone);
  19932. }
  19933. var iterations = 0;
  19934. return new Iterator(function() {
  19935. var step = iterator.next();
  19936. return step.done ? step : iteratorValue(type, iterations++, step.value);
  19937. });
  19938. };
  19939. createClass(IteratorSeq, IndexedSeq);
  19940. function IteratorSeq(iterator) {
  19941. this._iterator = iterator;
  19942. this._iteratorCache = [];
  19943. }
  19944. IteratorSeq.prototype.__iterateUncached = function(fn, reverse) {
  19945. if (reverse) {
  19946. return this.cacheResult().__iterate(fn, reverse);
  19947. }
  19948. var iterator = this._iterator;
  19949. var cache = this._iteratorCache;
  19950. var iterations = 0;
  19951. while (iterations < cache.length) {
  19952. if (fn(cache[iterations], iterations++, this) === false) {
  19953. return iterations;
  19954. }
  19955. }
  19956. var step;
  19957. while (!(step = iterator.next()).done) {
  19958. var val = step.value;
  19959. cache[iterations] = val;
  19960. if (fn(val, iterations++, this) === false) {
  19961. break;
  19962. }
  19963. }
  19964. return iterations;
  19965. };
  19966. IteratorSeq.prototype.__iteratorUncached = function(type, reverse) {
  19967. if (reverse) {
  19968. return this.cacheResult().__iterator(type, reverse);
  19969. }
  19970. var iterator = this._iterator;
  19971. var cache = this._iteratorCache;
  19972. var iterations = 0;
  19973. return new Iterator(function() {
  19974. if (iterations >= cache.length) {
  19975. var step = iterator.next();
  19976. if (step.done) {
  19977. return step;
  19978. }
  19979. cache[iterations] = step.value;
  19980. }
  19981. return iteratorValue(type, iterations, cache[iterations++]);
  19982. });
  19983. };
  19984. // # pragma Helper functions
  19985. function isSeq(maybeSeq) {
  19986. return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]);
  19987. }
  19988. var EMPTY_SEQ;
  19989. function emptySequence() {
  19990. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  19991. }
  19992. function keyedSeqFromValue(value) {
  19993. var seq =
  19994. Array.isArray(value) ? new ArraySeq(value).fromEntrySeq() :
  19995. isIterator(value) ? new IteratorSeq(value).fromEntrySeq() :
  19996. hasIterator(value) ? new IterableSeq(value).fromEntrySeq() :
  19997. typeof value === 'object' ? new ObjectSeq(value) :
  19998. undefined;
  19999. if (!seq) {
  20000. throw new TypeError(
  20001. 'Expected Array or iterable object of [k, v] entries, '+
  20002. 'or keyed object: ' + value
  20003. );
  20004. }
  20005. return seq;
  20006. }
  20007. function indexedSeqFromValue(value) {
  20008. var seq = maybeIndexedSeqFromValue(value);
  20009. if (!seq) {
  20010. throw new TypeError(
  20011. 'Expected Array or iterable object of values: ' + value
  20012. );
  20013. }
  20014. return seq;
  20015. }
  20016. function seqFromValue(value) {
  20017. var seq = maybeIndexedSeqFromValue(value) ||
  20018. (typeof value === 'object' && new ObjectSeq(value));
  20019. if (!seq) {
  20020. throw new TypeError(
  20021. 'Expected Array or iterable object of values, or keyed object: ' + value
  20022. );
  20023. }
  20024. return seq;
  20025. }
  20026. function maybeIndexedSeqFromValue(value) {
  20027. return (
  20028. isArrayLike(value) ? new ArraySeq(value) :
  20029. isIterator(value) ? new IteratorSeq(value) :
  20030. hasIterator(value) ? new IterableSeq(value) :
  20031. undefined
  20032. );
  20033. }
  20034. function seqIterate(seq, fn, reverse, useKeys) {
  20035. var cache = seq._cache;
  20036. if (cache) {
  20037. var maxIndex = cache.length - 1;
  20038. for (var ii = 0; ii <= maxIndex; ii++) {
  20039. var entry = cache[reverse ? maxIndex - ii : ii];
  20040. if (fn(entry[1], useKeys ? entry[0] : ii, seq) === false) {
  20041. return ii + 1;
  20042. }
  20043. }
  20044. return ii;
  20045. }
  20046. return seq.__iterateUncached(fn, reverse);
  20047. }
  20048. function seqIterator(seq, type, reverse, useKeys) {
  20049. var cache = seq._cache;
  20050. if (cache) {
  20051. var maxIndex = cache.length - 1;
  20052. var ii = 0;
  20053. return new Iterator(function() {
  20054. var entry = cache[reverse ? maxIndex - ii : ii];
  20055. return ii++ > maxIndex ?
  20056. iteratorDone() :
  20057. iteratorValue(type, useKeys ? entry[0] : ii - 1, entry[1]);
  20058. });
  20059. }
  20060. return seq.__iteratorUncached(type, reverse);
  20061. }
  20062. function fromJS(json, converter) {
  20063. return converter ?
  20064. fromJSWith(converter, json, '', {'': json}) :
  20065. fromJSDefault(json);
  20066. }
  20067. function fromJSWith(converter, json, key, parentJSON) {
  20068. if (Array.isArray(json)) {
  20069. return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  20070. }
  20071. if (isPlainObj(json)) {
  20072. return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  20073. }
  20074. return json;
  20075. }
  20076. function fromJSDefault(json) {
  20077. if (Array.isArray(json)) {
  20078. return IndexedSeq(json).map(fromJSDefault).toList();
  20079. }
  20080. if (isPlainObj(json)) {
  20081. return KeyedSeq(json).map(fromJSDefault).toMap();
  20082. }
  20083. return json;
  20084. }
  20085. function isPlainObj(value) {
  20086. return value && (value.constructor === Object || value.constructor === undefined);
  20087. }
  20088. /**
  20089. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  20090. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  20091. *
  20092. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  20093. * value, which is different from the algorithm described by
  20094. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  20095. *
  20096. * This is extended further to allow Objects to describe the values they
  20097. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  20098. *
  20099. * Note: because of this extension, the key equality of Immutable.Map and the
  20100. * value equality of Immutable.Set will differ from ES6 Map and Set.
  20101. *
  20102. * ### Defining custom values
  20103. *
  20104. * The easiest way to describe the value an object represents is by implementing
  20105. * `valueOf`. For example, `Date` represents a value by returning a unix
  20106. * timestamp for `valueOf`:
  20107. *
  20108. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  20109. * var date2 = new Date(1234567890000);
  20110. * date1.valueOf(); // 1234567890000
  20111. * assert( date1 !== date2 );
  20112. * assert( Immutable.is( date1, date2 ) );
  20113. *
  20114. * Note: overriding `valueOf` may have other implications if you use this object
  20115. * where JavaScript expects a primitive, such as implicit string coercion.
  20116. *
  20117. * For more complex types, especially collections, implementing `valueOf` may
  20118. * not be performant. An alternative is to implement `equals` and `hashCode`.
  20119. *
  20120. * `equals` takes another object, presumably of similar type, and returns true
  20121. * if the it is equal. Equality is symmetrical, so the same result should be
  20122. * returned if this and the argument are flipped.
  20123. *
  20124. * assert( a.equals(b) === b.equals(a) );
  20125. *
  20126. * `hashCode` returns a 32bit integer number representing the object which will
  20127. * be used to determine how to store the value object in a Map or Set. You must
  20128. * provide both or neither methods, one must not exist without the other.
  20129. *
  20130. * Also, an important relationship between these methods must be upheld: if two
  20131. * values are equal, they *must* return the same hashCode. If the values are not
  20132. * equal, they might have the same hashCode; this is called a hash collision,
  20133. * and while undesirable for performance reasons, it is acceptable.
  20134. *
  20135. * if (a.equals(b)) {
  20136. * assert( a.hashCode() === b.hashCode() );
  20137. * }
  20138. *
  20139. * All Immutable collections implement `equals` and `hashCode`.
  20140. *
  20141. */
  20142. function is(valueA, valueB) {
  20143. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  20144. return true;
  20145. }
  20146. if (!valueA || !valueB) {
  20147. return false;
  20148. }
  20149. if (typeof valueA.valueOf === 'function' &&
  20150. typeof valueB.valueOf === 'function') {
  20151. valueA = valueA.valueOf();
  20152. valueB = valueB.valueOf();
  20153. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  20154. return true;
  20155. }
  20156. if (!valueA || !valueB) {
  20157. return false;
  20158. }
  20159. }
  20160. if (typeof valueA.equals === 'function' &&
  20161. typeof valueB.equals === 'function' &&
  20162. valueA.equals(valueB)) {
  20163. return true;
  20164. }
  20165. return false;
  20166. }
  20167. function deepEqual(a, b) {
  20168. if (a === b) {
  20169. return true;
  20170. }
  20171. if (
  20172. !isIterable(b) ||
  20173. a.size !== undefined && b.size !== undefined && a.size !== b.size ||
  20174. a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
  20175. isKeyed(a) !== isKeyed(b) ||
  20176. isIndexed(a) !== isIndexed(b) ||
  20177. isOrdered(a) !== isOrdered(b)
  20178. ) {
  20179. return false;
  20180. }
  20181. if (a.size === 0 && b.size === 0) {
  20182. return true;
  20183. }
  20184. var notAssociative = !isAssociative(a);
  20185. if (isOrdered(a)) {
  20186. var entries = a.entries();
  20187. return b.every(function(v, k) {
  20188. var entry = entries.next().value;
  20189. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  20190. }) && entries.next().done;
  20191. }
  20192. var flipped = false;
  20193. if (a.size === undefined) {
  20194. if (b.size === undefined) {
  20195. if (typeof a.cacheResult === 'function') {
  20196. a.cacheResult();
  20197. }
  20198. } else {
  20199. flipped = true;
  20200. var _ = a;
  20201. a = b;
  20202. b = _;
  20203. }
  20204. }
  20205. var allEqual = true;
  20206. var bSize = b.__iterate(function(v, k) {
  20207. if (notAssociative ? !a.has(v) :
  20208. flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
  20209. allEqual = false;
  20210. return false;
  20211. }
  20212. });
  20213. return allEqual && a.size === bSize;
  20214. }
  20215. createClass(Repeat, IndexedSeq);
  20216. function Repeat(value, times) {
  20217. if (!(this instanceof Repeat)) {
  20218. return new Repeat(value, times);
  20219. }
  20220. this._value = value;
  20221. this.size = times === undefined ? Infinity : Math.max(0, times);
  20222. if (this.size === 0) {
  20223. if (EMPTY_REPEAT) {
  20224. return EMPTY_REPEAT;
  20225. }
  20226. EMPTY_REPEAT = this;
  20227. }
  20228. }
  20229. Repeat.prototype.toString = function() {
  20230. if (this.size === 0) {
  20231. return 'Repeat []';
  20232. }
  20233. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  20234. };
  20235. Repeat.prototype.get = function(index, notSetValue) {
  20236. return this.has(index) ? this._value : notSetValue;
  20237. };
  20238. Repeat.prototype.includes = function(searchValue) {
  20239. return is(this._value, searchValue);
  20240. };
  20241. Repeat.prototype.slice = function(begin, end) {
  20242. var size = this.size;
  20243. return wholeSlice(begin, end, size) ? this :
  20244. new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
  20245. };
  20246. Repeat.prototype.reverse = function() {
  20247. return this;
  20248. };
  20249. Repeat.prototype.indexOf = function(searchValue) {
  20250. if (is(this._value, searchValue)) {
  20251. return 0;
  20252. }
  20253. return -1;
  20254. };
  20255. Repeat.prototype.lastIndexOf = function(searchValue) {
  20256. if (is(this._value, searchValue)) {
  20257. return this.size;
  20258. }
  20259. return -1;
  20260. };
  20261. Repeat.prototype.__iterate = function(fn, reverse) {
  20262. for (var ii = 0; ii < this.size; ii++) {
  20263. if (fn(this._value, ii, this) === false) {
  20264. return ii + 1;
  20265. }
  20266. }
  20267. return ii;
  20268. };
  20269. Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
  20270. var ii = 0;
  20271. return new Iterator(function()
  20272. {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
  20273. );
  20274. };
  20275. Repeat.prototype.equals = function(other) {
  20276. return other instanceof Repeat ?
  20277. is(this._value, other._value) :
  20278. deepEqual(other);
  20279. };
  20280. var EMPTY_REPEAT;
  20281. function invariant(condition, error) {
  20282. if (!condition) throw new Error(error);
  20283. }
  20284. createClass(Range, IndexedSeq);
  20285. function Range(start, end, step) {
  20286. if (!(this instanceof Range)) {
  20287. return new Range(start, end, step);
  20288. }
  20289. invariant(step !== 0, 'Cannot step a Range by 0');
  20290. start = start || 0;
  20291. if (end === undefined) {
  20292. end = Infinity;
  20293. }
  20294. step = step === undefined ? 1 : Math.abs(step);
  20295. if (end < start) {
  20296. step = -step;
  20297. }
  20298. this._start = start;
  20299. this._end = end;
  20300. this._step = step;
  20301. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  20302. if (this.size === 0) {
  20303. if (EMPTY_RANGE) {
  20304. return EMPTY_RANGE;
  20305. }
  20306. EMPTY_RANGE = this;
  20307. }
  20308. }
  20309. Range.prototype.toString = function() {
  20310. if (this.size === 0) {
  20311. return 'Range []';
  20312. }
  20313. return 'Range [ ' +
  20314. this._start + '...' + this._end +
  20315. (this._step > 1 ? ' by ' + this._step : '') +
  20316. ' ]';
  20317. };
  20318. Range.prototype.get = function(index, notSetValue) {
  20319. return this.has(index) ?
  20320. this._start + wrapIndex(this, index) * this._step :
  20321. notSetValue;
  20322. };
  20323. Range.prototype.includes = function(searchValue) {
  20324. var possibleIndex = (searchValue - this._start) / this._step;
  20325. return possibleIndex >= 0 &&
  20326. possibleIndex < this.size &&
  20327. possibleIndex === Math.floor(possibleIndex);
  20328. };
  20329. Range.prototype.slice = function(begin, end) {
  20330. if (wholeSlice(begin, end, this.size)) {
  20331. return this;
  20332. }
  20333. begin = resolveBegin(begin, this.size);
  20334. end = resolveEnd(end, this.size);
  20335. if (end <= begin) {
  20336. return new Range(0, 0);
  20337. }
  20338. return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
  20339. };
  20340. Range.prototype.indexOf = function(searchValue) {
  20341. var offsetValue = searchValue - this._start;
  20342. if (offsetValue % this._step === 0) {
  20343. var index = offsetValue / this._step;
  20344. if (index >= 0 && index < this.size) {
  20345. return index
  20346. }
  20347. }
  20348. return -1;
  20349. };
  20350. Range.prototype.lastIndexOf = function(searchValue) {
  20351. return this.indexOf(searchValue);
  20352. };
  20353. Range.prototype.__iterate = function(fn, reverse) {
  20354. var maxIndex = this.size - 1;
  20355. var step = this._step;
  20356. var value = reverse ? this._start + maxIndex * step : this._start;
  20357. for (var ii = 0; ii <= maxIndex; ii++) {
  20358. if (fn(value, ii, this) === false) {
  20359. return ii + 1;
  20360. }
  20361. value += reverse ? -step : step;
  20362. }
  20363. return ii;
  20364. };
  20365. Range.prototype.__iterator = function(type, reverse) {
  20366. var maxIndex = this.size - 1;
  20367. var step = this._step;
  20368. var value = reverse ? this._start + maxIndex * step : this._start;
  20369. var ii = 0;
  20370. return new Iterator(function() {
  20371. var v = value;
  20372. value += reverse ? -step : step;
  20373. return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
  20374. });
  20375. };
  20376. Range.prototype.equals = function(other) {
  20377. return other instanceof Range ?
  20378. this._start === other._start &&
  20379. this._end === other._end &&
  20380. this._step === other._step :
  20381. deepEqual(this, other);
  20382. };
  20383. var EMPTY_RANGE;
  20384. createClass(Collection, Iterable);
  20385. function Collection() {
  20386. throw TypeError('Abstract');
  20387. }
  20388. createClass(KeyedCollection, Collection);function KeyedCollection() {}
  20389. createClass(IndexedCollection, Collection);function IndexedCollection() {}
  20390. createClass(SetCollection, Collection);function SetCollection() {}
  20391. Collection.Keyed = KeyedCollection;
  20392. Collection.Indexed = IndexedCollection;
  20393. Collection.Set = SetCollection;
  20394. var imul =
  20395. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
  20396. Math.imul :
  20397. function imul(a, b) {
  20398. a = a | 0; // int
  20399. b = b | 0; // int
  20400. var c = a & 0xffff;
  20401. var d = b & 0xffff;
  20402. // Shift by 0 fixes the sign on the high part.
  20403. return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int
  20404. };
  20405. // v8 has an optimization for storing 31-bit signed numbers.
  20406. // Values which have either 00 or 11 as the high order bits qualify.
  20407. // This function drops the highest order bit in a signed number, maintaining
  20408. // the sign bit.
  20409. function smi(i32) {
  20410. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
  20411. }
  20412. function hash(o) {
  20413. if (o === false || o === null || o === undefined) {
  20414. return 0;
  20415. }
  20416. if (typeof o.valueOf === 'function') {
  20417. o = o.valueOf();
  20418. if (o === false || o === null || o === undefined) {
  20419. return 0;
  20420. }
  20421. }
  20422. if (o === true) {
  20423. return 1;
  20424. }
  20425. var type = typeof o;
  20426. if (type === 'number') {
  20427. var h = o | 0;
  20428. if (h !== o) {
  20429. h ^= o * 0xFFFFFFFF;
  20430. }
  20431. while (o > 0xFFFFFFFF) {
  20432. o /= 0xFFFFFFFF;
  20433. h ^= o;
  20434. }
  20435. return smi(h);
  20436. }
  20437. if (type === 'string') {
  20438. return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
  20439. }
  20440. if (typeof o.hashCode === 'function') {
  20441. return o.hashCode();
  20442. }
  20443. if (type === 'object') {
  20444. return hashJSObj(o);
  20445. }
  20446. if (typeof o.toString === 'function') {
  20447. return hashString(o.toString());
  20448. }
  20449. throw new Error('Value type ' + type + ' cannot be hashed.');
  20450. }
  20451. function cachedHashString(string) {
  20452. var hash = stringHashCache[string];
  20453. if (hash === undefined) {
  20454. hash = hashString(string);
  20455. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  20456. STRING_HASH_CACHE_SIZE = 0;
  20457. stringHashCache = {};
  20458. }
  20459. STRING_HASH_CACHE_SIZE++;
  20460. stringHashCache[string] = hash;
  20461. }
  20462. return hash;
  20463. }
  20464. // http://jsperf.com/hashing-strings
  20465. function hashString(string) {
  20466. // This is the hash from JVM
  20467. // The hash code for a string is computed as
  20468. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  20469. // where s[i] is the ith character of the string and n is the length of
  20470. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  20471. // (exclusive) by dropping high bits.
  20472. var hash = 0;
  20473. for (var ii = 0; ii < string.length; ii++) {
  20474. hash = 31 * hash + string.charCodeAt(ii) | 0;
  20475. }
  20476. return smi(hash);
  20477. }
  20478. function hashJSObj(obj) {
  20479. var hash;
  20480. if (usingWeakMap) {
  20481. hash = weakMap.get(obj);
  20482. if (hash !== undefined) {
  20483. return hash;
  20484. }
  20485. }
  20486. hash = obj[UID_HASH_KEY];
  20487. if (hash !== undefined) {
  20488. return hash;
  20489. }
  20490. if (!canDefineProperty) {
  20491. hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  20492. if (hash !== undefined) {
  20493. return hash;
  20494. }
  20495. hash = getIENodeHash(obj);
  20496. if (hash !== undefined) {
  20497. return hash;
  20498. }
  20499. }
  20500. hash = ++objHashUID;
  20501. if (objHashUID & 0x40000000) {
  20502. objHashUID = 0;
  20503. }
  20504. if (usingWeakMap) {
  20505. weakMap.set(obj, hash);
  20506. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  20507. throw new Error('Non-extensible objects are not allowed as keys.');
  20508. } else if (canDefineProperty) {
  20509. Object.defineProperty(obj, UID_HASH_KEY, {
  20510. 'enumerable': false,
  20511. 'configurable': false,
  20512. 'writable': false,
  20513. 'value': hash
  20514. });
  20515. } else if (obj.propertyIsEnumerable !== undefined &&
  20516. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
  20517. // Since we can't define a non-enumerable property on the object
  20518. // we'll hijack one of the less-used non-enumerable properties to
  20519. // save our hash on it. Since this is a function it will not show up in
  20520. // `JSON.stringify` which is what we want.
  20521. obj.propertyIsEnumerable = function() {
  20522. return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
  20523. };
  20524. obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
  20525. } else if (obj.nodeType !== undefined) {
  20526. // At this point we couldn't get the IE `uniqueID` to use as a hash
  20527. // and we couldn't use a non-enumerable property to exploit the
  20528. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  20529. // itself.
  20530. obj[UID_HASH_KEY] = hash;
  20531. } else {
  20532. throw new Error('Unable to set a non-enumerable property on object.');
  20533. }
  20534. return hash;
  20535. }
  20536. // Get references to ES5 object methods.
  20537. var isExtensible = Object.isExtensible;
  20538. // True if Object.defineProperty works as expected. IE8 fails this test.
  20539. var canDefineProperty = (function() {
  20540. try {
  20541. Object.defineProperty({}, '@', {});
  20542. return true;
  20543. } catch (e) {
  20544. return false;
  20545. }
  20546. }());
  20547. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  20548. // and avoid memory leaks from the IE cloneNode bug.
  20549. function getIENodeHash(node) {
  20550. if (node && node.nodeType > 0) {
  20551. switch (node.nodeType) {
  20552. case 1: // Element
  20553. return node.uniqueID;
  20554. case 9: // Document
  20555. return node.documentElement && node.documentElement.uniqueID;
  20556. }
  20557. }
  20558. }
  20559. // If possible, use a WeakMap.
  20560. var usingWeakMap = typeof WeakMap === 'function';
  20561. var weakMap;
  20562. if (usingWeakMap) {
  20563. weakMap = new WeakMap();
  20564. }
  20565. var objHashUID = 0;
  20566. var UID_HASH_KEY = '__immutablehash__';
  20567. if (typeof Symbol === 'function') {
  20568. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  20569. }
  20570. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  20571. var STRING_HASH_CACHE_MAX_SIZE = 255;
  20572. var STRING_HASH_CACHE_SIZE = 0;
  20573. var stringHashCache = {};
  20574. function assertNotInfinite(size) {
  20575. invariant(
  20576. size !== Infinity,
  20577. 'Cannot perform this action with an infinite size.'
  20578. );
  20579. }
  20580. createClass(Map, KeyedCollection);
  20581. // @pragma Construction
  20582. function Map(value) {
  20583. return value === null || value === undefined ? emptyMap() :
  20584. isMap(value) && !isOrdered(value) ? value :
  20585. emptyMap().withMutations(function(map ) {
  20586. var iter = KeyedIterable(value);
  20587. assertNotInfinite(iter.size);
  20588. iter.forEach(function(v, k) {return map.set(k, v)});
  20589. });
  20590. }
  20591. Map.prototype.toString = function() {
  20592. return this.__toString('Map {', '}');
  20593. };
  20594. // @pragma Access
  20595. Map.prototype.get = function(k, notSetValue) {
  20596. return this._root ?
  20597. this._root.get(0, undefined, k, notSetValue) :
  20598. notSetValue;
  20599. };
  20600. // @pragma Modification
  20601. Map.prototype.set = function(k, v) {
  20602. return updateMap(this, k, v);
  20603. };
  20604. Map.prototype.setIn = function(keyPath, v) {
  20605. return this.updateIn(keyPath, NOT_SET, function() {return v});
  20606. };
  20607. Map.prototype.remove = function(k) {
  20608. return updateMap(this, k, NOT_SET);
  20609. };
  20610. Map.prototype.deleteIn = function(keyPath) {
  20611. return this.updateIn(keyPath, function() {return NOT_SET});
  20612. };
  20613. Map.prototype.update = function(k, notSetValue, updater) {
  20614. return arguments.length === 1 ?
  20615. k(this) :
  20616. this.updateIn([k], notSetValue, updater);
  20617. };
  20618. Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
  20619. if (!updater) {
  20620. updater = notSetValue;
  20621. notSetValue = undefined;
  20622. }
  20623. var updatedValue = updateInDeepMap(
  20624. this,
  20625. forceIterator(keyPath),
  20626. notSetValue,
  20627. updater
  20628. );
  20629. return updatedValue === NOT_SET ? undefined : updatedValue;
  20630. };
  20631. Map.prototype.clear = function() {
  20632. if (this.size === 0) {
  20633. return this;
  20634. }
  20635. if (this.__ownerID) {
  20636. this.size = 0;
  20637. this._root = null;
  20638. this.__hash = undefined;
  20639. this.__altered = true;
  20640. return this;
  20641. }
  20642. return emptyMap();
  20643. };
  20644. // @pragma Composition
  20645. Map.prototype.merge = function(/*...iters*/) {
  20646. return mergeIntoMapWith(this, undefined, arguments);
  20647. };
  20648. Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  20649. return mergeIntoMapWith(this, merger, iters);
  20650. };
  20651. Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  20652. return this.updateIn(
  20653. keyPath,
  20654. emptyMap(),
  20655. function(m ) {return typeof m.merge === 'function' ?
  20656. m.merge.apply(m, iters) :
  20657. iters[iters.length - 1]}
  20658. );
  20659. };
  20660. Map.prototype.mergeDeep = function(/*...iters*/) {
  20661. return mergeIntoMapWith(this, deepMerger, arguments);
  20662. };
  20663. Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  20664. return mergeIntoMapWith(this, deepMergerWith(merger), iters);
  20665. };
  20666. Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  20667. return this.updateIn(
  20668. keyPath,
  20669. emptyMap(),
  20670. function(m ) {return typeof m.mergeDeep === 'function' ?
  20671. m.mergeDeep.apply(m, iters) :
  20672. iters[iters.length - 1]}
  20673. );
  20674. };
  20675. Map.prototype.sort = function(comparator) {
  20676. // Late binding
  20677. return OrderedMap(sortFactory(this, comparator));
  20678. };
  20679. Map.prototype.sortBy = function(mapper, comparator) {
  20680. // Late binding
  20681. return OrderedMap(sortFactory(this, comparator, mapper));
  20682. };
  20683. // @pragma Mutability
  20684. Map.prototype.withMutations = function(fn) {
  20685. var mutable = this.asMutable();
  20686. fn(mutable);
  20687. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  20688. };
  20689. Map.prototype.asMutable = function() {
  20690. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  20691. };
  20692. Map.prototype.asImmutable = function() {
  20693. return this.__ensureOwner();
  20694. };
  20695. Map.prototype.wasAltered = function() {
  20696. return this.__altered;
  20697. };
  20698. Map.prototype.__iterator = function(type, reverse) {
  20699. return new MapIterator(this, type, reverse);
  20700. };
  20701. Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  20702. var iterations = 0;
  20703. this._root && this._root.iterate(function(entry ) {
  20704. iterations++;
  20705. return fn(entry[1], entry[0], this$0);
  20706. }, reverse);
  20707. return iterations;
  20708. };
  20709. Map.prototype.__ensureOwner = function(ownerID) {
  20710. if (ownerID === this.__ownerID) {
  20711. return this;
  20712. }
  20713. if (!ownerID) {
  20714. this.__ownerID = ownerID;
  20715. this.__altered = false;
  20716. return this;
  20717. }
  20718. return makeMap(this.size, this._root, ownerID, this.__hash);
  20719. };
  20720. function isMap(maybeMap) {
  20721. return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
  20722. }
  20723. Map.isMap = isMap;
  20724. var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
  20725. var MapPrototype = Map.prototype;
  20726. MapPrototype[IS_MAP_SENTINEL] = true;
  20727. MapPrototype[DELETE] = MapPrototype.remove;
  20728. MapPrototype.removeIn = MapPrototype.deleteIn;
  20729. // #pragma Trie Nodes
  20730. function ArrayMapNode(ownerID, entries) {
  20731. this.ownerID = ownerID;
  20732. this.entries = entries;
  20733. }
  20734. ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  20735. var entries = this.entries;
  20736. for (var ii = 0, len = entries.length; ii < len; ii++) {
  20737. if (is(key, entries[ii][0])) {
  20738. return entries[ii][1];
  20739. }
  20740. }
  20741. return notSetValue;
  20742. };
  20743. ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  20744. var removed = value === NOT_SET;
  20745. var entries = this.entries;
  20746. var idx = 0;
  20747. for (var len = entries.length; idx < len; idx++) {
  20748. if (is(key, entries[idx][0])) {
  20749. break;
  20750. }
  20751. }
  20752. var exists = idx < len;
  20753. if (exists ? entries[idx][1] === value : removed) {
  20754. return this;
  20755. }
  20756. SetRef(didAlter);
  20757. (removed || !exists) && SetRef(didChangeSize);
  20758. if (removed && entries.length === 1) {
  20759. return; // undefined
  20760. }
  20761. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  20762. return createNodes(ownerID, entries, key, value);
  20763. }
  20764. var isEditable = ownerID && ownerID === this.ownerID;
  20765. var newEntries = isEditable ? entries : arrCopy(entries);
  20766. if (exists) {
  20767. if (removed) {
  20768. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  20769. } else {
  20770. newEntries[idx] = [key, value];
  20771. }
  20772. } else {
  20773. newEntries.push([key, value]);
  20774. }
  20775. if (isEditable) {
  20776. this.entries = newEntries;
  20777. return this;
  20778. }
  20779. return new ArrayMapNode(ownerID, newEntries);
  20780. };
  20781. function BitmapIndexedNode(ownerID, bitmap, nodes) {
  20782. this.ownerID = ownerID;
  20783. this.bitmap = bitmap;
  20784. this.nodes = nodes;
  20785. }
  20786. BitmapIndexedNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  20787. if (keyHash === undefined) {
  20788. keyHash = hash(key);
  20789. }
  20790. var bit = (1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK));
  20791. var bitmap = this.bitmap;
  20792. return (bitmap & bit) === 0 ? notSetValue :
  20793. this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue);
  20794. };
  20795. BitmapIndexedNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  20796. if (keyHash === undefined) {
  20797. keyHash = hash(key);
  20798. }
  20799. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  20800. var bit = 1 << keyHashFrag;
  20801. var bitmap = this.bitmap;
  20802. var exists = (bitmap & bit) !== 0;
  20803. if (!exists && value === NOT_SET) {
  20804. return this;
  20805. }
  20806. var idx = popCount(bitmap & (bit - 1));
  20807. var nodes = this.nodes;
  20808. var node = exists ? nodes[idx] : undefined;
  20809. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  20810. if (newNode === node) {
  20811. return this;
  20812. }
  20813. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  20814. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  20815. }
  20816. if (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) {
  20817. return nodes[idx ^ 1];
  20818. }
  20819. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  20820. return newNode;
  20821. }
  20822. var isEditable = ownerID && ownerID === this.ownerID;
  20823. var newBitmap = exists ? newNode ? bitmap : bitmap ^ bit : bitmap | bit;
  20824. var newNodes = exists ? newNode ?
  20825. setIn(nodes, idx, newNode, isEditable) :
  20826. spliceOut(nodes, idx, isEditable) :
  20827. spliceIn(nodes, idx, newNode, isEditable);
  20828. if (isEditable) {
  20829. this.bitmap = newBitmap;
  20830. this.nodes = newNodes;
  20831. return this;
  20832. }
  20833. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  20834. };
  20835. function HashArrayMapNode(ownerID, count, nodes) {
  20836. this.ownerID = ownerID;
  20837. this.count = count;
  20838. this.nodes = nodes;
  20839. }
  20840. HashArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  20841. if (keyHash === undefined) {
  20842. keyHash = hash(key);
  20843. }
  20844. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  20845. var node = this.nodes[idx];
  20846. return node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue;
  20847. };
  20848. HashArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  20849. if (keyHash === undefined) {
  20850. keyHash = hash(key);
  20851. }
  20852. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  20853. var removed = value === NOT_SET;
  20854. var nodes = this.nodes;
  20855. var node = nodes[idx];
  20856. if (removed && !node) {
  20857. return this;
  20858. }
  20859. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  20860. if (newNode === node) {
  20861. return this;
  20862. }
  20863. var newCount = this.count;
  20864. if (!node) {
  20865. newCount++;
  20866. } else if (!newNode) {
  20867. newCount--;
  20868. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  20869. return packNodes(ownerID, nodes, newCount, idx);
  20870. }
  20871. }
  20872. var isEditable = ownerID && ownerID === this.ownerID;
  20873. var newNodes = setIn(nodes, idx, newNode, isEditable);
  20874. if (isEditable) {
  20875. this.count = newCount;
  20876. this.nodes = newNodes;
  20877. return this;
  20878. }
  20879. return new HashArrayMapNode(ownerID, newCount, newNodes);
  20880. };
  20881. function HashCollisionNode(ownerID, keyHash, entries) {
  20882. this.ownerID = ownerID;
  20883. this.keyHash = keyHash;
  20884. this.entries = entries;
  20885. }
  20886. HashCollisionNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  20887. var entries = this.entries;
  20888. for (var ii = 0, len = entries.length; ii < len; ii++) {
  20889. if (is(key, entries[ii][0])) {
  20890. return entries[ii][1];
  20891. }
  20892. }
  20893. return notSetValue;
  20894. };
  20895. HashCollisionNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  20896. if (keyHash === undefined) {
  20897. keyHash = hash(key);
  20898. }
  20899. var removed = value === NOT_SET;
  20900. if (keyHash !== this.keyHash) {
  20901. if (removed) {
  20902. return this;
  20903. }
  20904. SetRef(didAlter);
  20905. SetRef(didChangeSize);
  20906. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  20907. }
  20908. var entries = this.entries;
  20909. var idx = 0;
  20910. for (var len = entries.length; idx < len; idx++) {
  20911. if (is(key, entries[idx][0])) {
  20912. break;
  20913. }
  20914. }
  20915. var exists = idx < len;
  20916. if (exists ? entries[idx][1] === value : removed) {
  20917. return this;
  20918. }
  20919. SetRef(didAlter);
  20920. (removed || !exists) && SetRef(didChangeSize);
  20921. if (removed && len === 2) {
  20922. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  20923. }
  20924. var isEditable = ownerID && ownerID === this.ownerID;
  20925. var newEntries = isEditable ? entries : arrCopy(entries);
  20926. if (exists) {
  20927. if (removed) {
  20928. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  20929. } else {
  20930. newEntries[idx] = [key, value];
  20931. }
  20932. } else {
  20933. newEntries.push([key, value]);
  20934. }
  20935. if (isEditable) {
  20936. this.entries = newEntries;
  20937. return this;
  20938. }
  20939. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  20940. };
  20941. function ValueNode(ownerID, keyHash, entry) {
  20942. this.ownerID = ownerID;
  20943. this.keyHash = keyHash;
  20944. this.entry = entry;
  20945. }
  20946. ValueNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  20947. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  20948. };
  20949. ValueNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  20950. var removed = value === NOT_SET;
  20951. var keyMatch = is(key, this.entry[0]);
  20952. if (keyMatch ? value === this.entry[1] : removed) {
  20953. return this;
  20954. }
  20955. SetRef(didAlter);
  20956. if (removed) {
  20957. SetRef(didChangeSize);
  20958. return; // undefined
  20959. }
  20960. if (keyMatch) {
  20961. if (ownerID && ownerID === this.ownerID) {
  20962. this.entry[1] = value;
  20963. return this;
  20964. }
  20965. return new ValueNode(ownerID, this.keyHash, [key, value]);
  20966. }
  20967. SetRef(didChangeSize);
  20968. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  20969. };
  20970. // #pragma Iterators
  20971. ArrayMapNode.prototype.iterate =
  20972. HashCollisionNode.prototype.iterate = function (fn, reverse) {
  20973. var entries = this.entries;
  20974. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  20975. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  20976. return false;
  20977. }
  20978. }
  20979. };
  20980. BitmapIndexedNode.prototype.iterate =
  20981. HashArrayMapNode.prototype.iterate = function (fn, reverse) {
  20982. var nodes = this.nodes;
  20983. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  20984. var node = nodes[reverse ? maxIndex - ii : ii];
  20985. if (node && node.iterate(fn, reverse) === false) {
  20986. return false;
  20987. }
  20988. }
  20989. };
  20990. ValueNode.prototype.iterate = function (fn, reverse) {
  20991. return fn(this.entry);
  20992. };
  20993. createClass(MapIterator, Iterator);
  20994. function MapIterator(map, type, reverse) {
  20995. this._type = type;
  20996. this._reverse = reverse;
  20997. this._stack = map._root && mapIteratorFrame(map._root);
  20998. }
  20999. MapIterator.prototype.next = function() {
  21000. var type = this._type;
  21001. var stack = this._stack;
  21002. while (stack) {
  21003. var node = stack.node;
  21004. var index = stack.index++;
  21005. var maxIndex;
  21006. if (node.entry) {
  21007. if (index === 0) {
  21008. return mapIteratorValue(type, node.entry);
  21009. }
  21010. } else if (node.entries) {
  21011. maxIndex = node.entries.length - 1;
  21012. if (index <= maxIndex) {
  21013. return mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index]);
  21014. }
  21015. } else {
  21016. maxIndex = node.nodes.length - 1;
  21017. if (index <= maxIndex) {
  21018. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  21019. if (subNode) {
  21020. if (subNode.entry) {
  21021. return mapIteratorValue(type, subNode.entry);
  21022. }
  21023. stack = this._stack = mapIteratorFrame(subNode, stack);
  21024. }
  21025. continue;
  21026. }
  21027. }
  21028. stack = this._stack = this._stack.__prev;
  21029. }
  21030. return iteratorDone();
  21031. };
  21032. function mapIteratorValue(type, entry) {
  21033. return iteratorValue(type, entry[0], entry[1]);
  21034. }
  21035. function mapIteratorFrame(node, prev) {
  21036. return {
  21037. node: node,
  21038. index: 0,
  21039. __prev: prev
  21040. };
  21041. }
  21042. function makeMap(size, root, ownerID, hash) {
  21043. var map = Object.create(MapPrototype);
  21044. map.size = size;
  21045. map._root = root;
  21046. map.__ownerID = ownerID;
  21047. map.__hash = hash;
  21048. map.__altered = false;
  21049. return map;
  21050. }
  21051. var EMPTY_MAP;
  21052. function emptyMap() {
  21053. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  21054. }
  21055. function updateMap(map, k, v) {
  21056. var newRoot;
  21057. var newSize;
  21058. if (!map._root) {
  21059. if (v === NOT_SET) {
  21060. return map;
  21061. }
  21062. newSize = 1;
  21063. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  21064. } else {
  21065. var didChangeSize = MakeRef(CHANGE_LENGTH);
  21066. var didAlter = MakeRef(DID_ALTER);
  21067. newRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter);
  21068. if (!didAlter.value) {
  21069. return map;
  21070. }
  21071. newSize = map.size + (didChangeSize.value ? v === NOT_SET ? -1 : 1 : 0);
  21072. }
  21073. if (map.__ownerID) {
  21074. map.size = newSize;
  21075. map._root = newRoot;
  21076. map.__hash = undefined;
  21077. map.__altered = true;
  21078. return map;
  21079. }
  21080. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  21081. }
  21082. function updateNode(node, ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  21083. if (!node) {
  21084. if (value === NOT_SET) {
  21085. return node;
  21086. }
  21087. SetRef(didAlter);
  21088. SetRef(didChangeSize);
  21089. return new ValueNode(ownerID, keyHash, [key, value]);
  21090. }
  21091. return node.update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter);
  21092. }
  21093. function isLeafNode(node) {
  21094. return node.constructor === ValueNode || node.constructor === HashCollisionNode;
  21095. }
  21096. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  21097. if (node.keyHash === keyHash) {
  21098. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  21099. }
  21100. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  21101. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  21102. var newNode;
  21103. var nodes = idx1 === idx2 ?
  21104. [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)] :
  21105. ((newNode = new ValueNode(ownerID, keyHash, entry)), idx1 < idx2 ? [node, newNode] : [newNode, node]);
  21106. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  21107. }
  21108. function createNodes(ownerID, entries, key, value) {
  21109. if (!ownerID) {
  21110. ownerID = new OwnerID();
  21111. }
  21112. var node = new ValueNode(ownerID, hash(key), [key, value]);
  21113. for (var ii = 0; ii < entries.length; ii++) {
  21114. var entry = entries[ii];
  21115. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  21116. }
  21117. return node;
  21118. }
  21119. function packNodes(ownerID, nodes, count, excluding) {
  21120. var bitmap = 0;
  21121. var packedII = 0;
  21122. var packedNodes = new Array(count);
  21123. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  21124. var node = nodes[ii];
  21125. if (node !== undefined && ii !== excluding) {
  21126. bitmap |= bit;
  21127. packedNodes[packedII++] = node;
  21128. }
  21129. }
  21130. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  21131. }
  21132. function expandNodes(ownerID, nodes, bitmap, including, node) {
  21133. var count = 0;
  21134. var expandedNodes = new Array(SIZE);
  21135. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  21136. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  21137. }
  21138. expandedNodes[including] = node;
  21139. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  21140. }
  21141. function mergeIntoMapWith(map, merger, iterables) {
  21142. var iters = [];
  21143. for (var ii = 0; ii < iterables.length; ii++) {
  21144. var value = iterables[ii];
  21145. var iter = KeyedIterable(value);
  21146. if (!isIterable(value)) {
  21147. iter = iter.map(function(v ) {return fromJS(v)});
  21148. }
  21149. iters.push(iter);
  21150. }
  21151. return mergeIntoCollectionWith(map, merger, iters);
  21152. }
  21153. function deepMerger(existing, value, key) {
  21154. return existing && existing.mergeDeep && isIterable(value) ?
  21155. existing.mergeDeep(value) :
  21156. is(existing, value) ? existing : value;
  21157. }
  21158. function deepMergerWith(merger) {
  21159. return function(existing, value, key) {
  21160. if (existing && existing.mergeDeepWith && isIterable(value)) {
  21161. return existing.mergeDeepWith(merger, value);
  21162. }
  21163. var nextValue = merger(existing, value, key);
  21164. return is(existing, nextValue) ? existing : nextValue;
  21165. };
  21166. }
  21167. function mergeIntoCollectionWith(collection, merger, iters) {
  21168. iters = iters.filter(function(x ) {return x.size !== 0});
  21169. if (iters.length === 0) {
  21170. return collection;
  21171. }
  21172. if (collection.size === 0 && !collection.__ownerID && iters.length === 1) {
  21173. return collection.constructor(iters[0]);
  21174. }
  21175. return collection.withMutations(function(collection ) {
  21176. var mergeIntoMap = merger ?
  21177. function(value, key) {
  21178. collection.update(key, NOT_SET, function(existing )
  21179. {return existing === NOT_SET ? value : merger(existing, value, key)}
  21180. );
  21181. } :
  21182. function(value, key) {
  21183. collection.set(key, value);
  21184. };
  21185. for (var ii = 0; ii < iters.length; ii++) {
  21186. iters[ii].forEach(mergeIntoMap);
  21187. }
  21188. });
  21189. }
  21190. function updateInDeepMap(existing, keyPathIter, notSetValue, updater) {
  21191. var isNotSet = existing === NOT_SET;
  21192. var step = keyPathIter.next();
  21193. if (step.done) {
  21194. var existingValue = isNotSet ? notSetValue : existing;
  21195. var newValue = updater(existingValue);
  21196. return newValue === existingValue ? existing : newValue;
  21197. }
  21198. invariant(
  21199. isNotSet || (existing && existing.set),
  21200. 'invalid keyPath'
  21201. );
  21202. var key = step.value;
  21203. var nextExisting = isNotSet ? NOT_SET : existing.get(key, NOT_SET);
  21204. var nextUpdated = updateInDeepMap(
  21205. nextExisting,
  21206. keyPathIter,
  21207. notSetValue,
  21208. updater
  21209. );
  21210. return nextUpdated === nextExisting ? existing :
  21211. nextUpdated === NOT_SET ? existing.remove(key) :
  21212. (isNotSet ? emptyMap() : existing).set(key, nextUpdated);
  21213. }
  21214. function popCount(x) {
  21215. x = x - ((x >> 1) & 0x55555555);
  21216. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  21217. x = (x + (x >> 4)) & 0x0f0f0f0f;
  21218. x = x + (x >> 8);
  21219. x = x + (x >> 16);
  21220. return x & 0x7f;
  21221. }
  21222. function setIn(array, idx, val, canEdit) {
  21223. var newArray = canEdit ? array : arrCopy(array);
  21224. newArray[idx] = val;
  21225. return newArray;
  21226. }
  21227. function spliceIn(array, idx, val, canEdit) {
  21228. var newLen = array.length + 1;
  21229. if (canEdit && idx + 1 === newLen) {
  21230. array[idx] = val;
  21231. return array;
  21232. }
  21233. var newArray = new Array(newLen);
  21234. var after = 0;
  21235. for (var ii = 0; ii < newLen; ii++) {
  21236. if (ii === idx) {
  21237. newArray[ii] = val;
  21238. after = -1;
  21239. } else {
  21240. newArray[ii] = array[ii + after];
  21241. }
  21242. }
  21243. return newArray;
  21244. }
  21245. function spliceOut(array, idx, canEdit) {
  21246. var newLen = array.length - 1;
  21247. if (canEdit && idx === newLen) {
  21248. array.pop();
  21249. return array;
  21250. }
  21251. var newArray = new Array(newLen);
  21252. var after = 0;
  21253. for (var ii = 0; ii < newLen; ii++) {
  21254. if (ii === idx) {
  21255. after = 1;
  21256. }
  21257. newArray[ii] = array[ii + after];
  21258. }
  21259. return newArray;
  21260. }
  21261. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  21262. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  21263. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  21264. createClass(List, IndexedCollection);
  21265. // @pragma Construction
  21266. function List(value) {
  21267. var empty = emptyList();
  21268. if (value === null || value === undefined) {
  21269. return empty;
  21270. }
  21271. if (isList(value)) {
  21272. return value;
  21273. }
  21274. var iter = IndexedIterable(value);
  21275. var size = iter.size;
  21276. if (size === 0) {
  21277. return empty;
  21278. }
  21279. assertNotInfinite(size);
  21280. if (size > 0 && size < SIZE) {
  21281. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  21282. }
  21283. return empty.withMutations(function(list ) {
  21284. list.setSize(size);
  21285. iter.forEach(function(v, i) {return list.set(i, v)});
  21286. });
  21287. }
  21288. List.of = function(/*...values*/) {
  21289. return this(arguments);
  21290. };
  21291. List.prototype.toString = function() {
  21292. return this.__toString('List [', ']');
  21293. };
  21294. // @pragma Access
  21295. List.prototype.get = function(index, notSetValue) {
  21296. index = wrapIndex(this, index);
  21297. if (index >= 0 && index < this.size) {
  21298. index += this._origin;
  21299. var node = listNodeFor(this, index);
  21300. return node && node.array[index & MASK];
  21301. }
  21302. return notSetValue;
  21303. };
  21304. // @pragma Modification
  21305. List.prototype.set = function(index, value) {
  21306. return updateList(this, index, value);
  21307. };
  21308. List.prototype.remove = function(index) {
  21309. return !this.has(index) ? this :
  21310. index === 0 ? this.shift() :
  21311. index === this.size - 1 ? this.pop() :
  21312. this.splice(index, 1);
  21313. };
  21314. List.prototype.insert = function(index, value) {
  21315. return this.splice(index, 0, value);
  21316. };
  21317. List.prototype.clear = function() {
  21318. if (this.size === 0) {
  21319. return this;
  21320. }
  21321. if (this.__ownerID) {
  21322. this.size = this._origin = this._capacity = 0;
  21323. this._level = SHIFT;
  21324. this._root = this._tail = null;
  21325. this.__hash = undefined;
  21326. this.__altered = true;
  21327. return this;
  21328. }
  21329. return emptyList();
  21330. };
  21331. List.prototype.push = function(/*...values*/) {
  21332. var values = arguments;
  21333. var oldSize = this.size;
  21334. return this.withMutations(function(list ) {
  21335. setListBounds(list, 0, oldSize + values.length);
  21336. for (var ii = 0; ii < values.length; ii++) {
  21337. list.set(oldSize + ii, values[ii]);
  21338. }
  21339. });
  21340. };
  21341. List.prototype.pop = function() {
  21342. return setListBounds(this, 0, -1);
  21343. };
  21344. List.prototype.unshift = function(/*...values*/) {
  21345. var values = arguments;
  21346. return this.withMutations(function(list ) {
  21347. setListBounds(list, -values.length);
  21348. for (var ii = 0; ii < values.length; ii++) {
  21349. list.set(ii, values[ii]);
  21350. }
  21351. });
  21352. };
  21353. List.prototype.shift = function() {
  21354. return setListBounds(this, 1);
  21355. };
  21356. // @pragma Composition
  21357. List.prototype.merge = function(/*...iters*/) {
  21358. return mergeIntoListWith(this, undefined, arguments);
  21359. };
  21360. List.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  21361. return mergeIntoListWith(this, merger, iters);
  21362. };
  21363. List.prototype.mergeDeep = function(/*...iters*/) {
  21364. return mergeIntoListWith(this, deepMerger, arguments);
  21365. };
  21366. List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  21367. return mergeIntoListWith(this, deepMergerWith(merger), iters);
  21368. };
  21369. List.prototype.setSize = function(size) {
  21370. return setListBounds(this, 0, size);
  21371. };
  21372. // @pragma Iteration
  21373. List.prototype.slice = function(begin, end) {
  21374. var size = this.size;
  21375. if (wholeSlice(begin, end, size)) {
  21376. return this;
  21377. }
  21378. return setListBounds(
  21379. this,
  21380. resolveBegin(begin, size),
  21381. resolveEnd(end, size)
  21382. );
  21383. };
  21384. List.prototype.__iterator = function(type, reverse) {
  21385. var index = 0;
  21386. var values = iterateList(this, reverse);
  21387. return new Iterator(function() {
  21388. var value = values();
  21389. return value === DONE ?
  21390. iteratorDone() :
  21391. iteratorValue(type, index++, value);
  21392. });
  21393. };
  21394. List.prototype.__iterate = function(fn, reverse) {
  21395. var index = 0;
  21396. var values = iterateList(this, reverse);
  21397. var value;
  21398. while ((value = values()) !== DONE) {
  21399. if (fn(value, index++, this) === false) {
  21400. break;
  21401. }
  21402. }
  21403. return index;
  21404. };
  21405. List.prototype.__ensureOwner = function(ownerID) {
  21406. if (ownerID === this.__ownerID) {
  21407. return this;
  21408. }
  21409. if (!ownerID) {
  21410. this.__ownerID = ownerID;
  21411. return this;
  21412. }
  21413. return makeList(this._origin, this._capacity, this._level, this._root, this._tail, ownerID, this.__hash);
  21414. };
  21415. function isList(maybeList) {
  21416. return !!(maybeList && maybeList[IS_LIST_SENTINEL]);
  21417. }
  21418. List.isList = isList;
  21419. var IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
  21420. var ListPrototype = List.prototype;
  21421. ListPrototype[IS_LIST_SENTINEL] = true;
  21422. ListPrototype[DELETE] = ListPrototype.remove;
  21423. ListPrototype.setIn = MapPrototype.setIn;
  21424. ListPrototype.deleteIn =
  21425. ListPrototype.removeIn = MapPrototype.removeIn;
  21426. ListPrototype.update = MapPrototype.update;
  21427. ListPrototype.updateIn = MapPrototype.updateIn;
  21428. ListPrototype.mergeIn = MapPrototype.mergeIn;
  21429. ListPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  21430. ListPrototype.withMutations = MapPrototype.withMutations;
  21431. ListPrototype.asMutable = MapPrototype.asMutable;
  21432. ListPrototype.asImmutable = MapPrototype.asImmutable;
  21433. ListPrototype.wasAltered = MapPrototype.wasAltered;
  21434. function VNode(array, ownerID) {
  21435. this.array = array;
  21436. this.ownerID = ownerID;
  21437. }
  21438. // TODO: seems like these methods are very similar
  21439. VNode.prototype.removeBefore = function(ownerID, level, index) {
  21440. if (index === level ? 1 << level : this.array.length === 0) {
  21441. return this;
  21442. }
  21443. var originIndex = (index >>> level) & MASK;
  21444. if (originIndex >= this.array.length) {
  21445. return new VNode([], ownerID);
  21446. }
  21447. var removingFirst = originIndex === 0;
  21448. var newChild;
  21449. if (level > 0) {
  21450. var oldChild = this.array[originIndex];
  21451. newChild = oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  21452. if (newChild === oldChild && removingFirst) {
  21453. return this;
  21454. }
  21455. }
  21456. if (removingFirst && !newChild) {
  21457. return this;
  21458. }
  21459. var editable = editableVNode(this, ownerID);
  21460. if (!removingFirst) {
  21461. for (var ii = 0; ii < originIndex; ii++) {
  21462. editable.array[ii] = undefined;
  21463. }
  21464. }
  21465. if (newChild) {
  21466. editable.array[originIndex] = newChild;
  21467. }
  21468. return editable;
  21469. };
  21470. VNode.prototype.removeAfter = function(ownerID, level, index) {
  21471. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  21472. return this;
  21473. }
  21474. var sizeIndex = ((index - 1) >>> level) & MASK;
  21475. if (sizeIndex >= this.array.length) {
  21476. return this;
  21477. }
  21478. var newChild;
  21479. if (level > 0) {
  21480. var oldChild = this.array[sizeIndex];
  21481. newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  21482. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  21483. return this;
  21484. }
  21485. }
  21486. var editable = editableVNode(this, ownerID);
  21487. editable.array.splice(sizeIndex + 1);
  21488. if (newChild) {
  21489. editable.array[sizeIndex] = newChild;
  21490. }
  21491. return editable;
  21492. };
  21493. var DONE = {};
  21494. function iterateList(list, reverse) {
  21495. var left = list._origin;
  21496. var right = list._capacity;
  21497. var tailPos = getTailOffset(right);
  21498. var tail = list._tail;
  21499. return iterateNodeOrLeaf(list._root, list._level, 0);
  21500. function iterateNodeOrLeaf(node, level, offset) {
  21501. return level === 0 ?
  21502. iterateLeaf(node, offset) :
  21503. iterateNode(node, level, offset);
  21504. }
  21505. function iterateLeaf(node, offset) {
  21506. var array = offset === tailPos ? tail && tail.array : node && node.array;
  21507. var from = offset > left ? 0 : left - offset;
  21508. var to = right - offset;
  21509. if (to > SIZE) {
  21510. to = SIZE;
  21511. }
  21512. return function() {
  21513. if (from === to) {
  21514. return DONE;
  21515. }
  21516. var idx = reverse ? --to : from++;
  21517. return array && array[idx];
  21518. };
  21519. }
  21520. function iterateNode(node, level, offset) {
  21521. var values;
  21522. var array = node && node.array;
  21523. var from = offset > left ? 0 : (left - offset) >> level;
  21524. var to = ((right - offset) >> level) + 1;
  21525. if (to > SIZE) {
  21526. to = SIZE;
  21527. }
  21528. return function() {
  21529. do {
  21530. if (values) {
  21531. var value = values();
  21532. if (value !== DONE) {
  21533. return value;
  21534. }
  21535. values = null;
  21536. }
  21537. if (from === to) {
  21538. return DONE;
  21539. }
  21540. var idx = reverse ? --to : from++;
  21541. values = iterateNodeOrLeaf(
  21542. array && array[idx], level - SHIFT, offset + (idx << level)
  21543. );
  21544. } while (true);
  21545. };
  21546. }
  21547. }
  21548. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  21549. var list = Object.create(ListPrototype);
  21550. list.size = capacity - origin;
  21551. list._origin = origin;
  21552. list._capacity = capacity;
  21553. list._level = level;
  21554. list._root = root;
  21555. list._tail = tail;
  21556. list.__ownerID = ownerID;
  21557. list.__hash = hash;
  21558. list.__altered = false;
  21559. return list;
  21560. }
  21561. var EMPTY_LIST;
  21562. function emptyList() {
  21563. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  21564. }
  21565. function updateList(list, index, value) {
  21566. index = wrapIndex(list, index);
  21567. if (index !== index) {
  21568. return list;
  21569. }
  21570. if (index >= list.size || index < 0) {
  21571. return list.withMutations(function(list ) {
  21572. index < 0 ?
  21573. setListBounds(list, index).set(0, value) :
  21574. setListBounds(list, 0, index + 1).set(index, value);
  21575. });
  21576. }
  21577. index += list._origin;
  21578. var newTail = list._tail;
  21579. var newRoot = list._root;
  21580. var didAlter = MakeRef(DID_ALTER);
  21581. if (index >= getTailOffset(list._capacity)) {
  21582. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  21583. } else {
  21584. newRoot = updateVNode(newRoot, list.__ownerID, list._level, index, value, didAlter);
  21585. }
  21586. if (!didAlter.value) {
  21587. return list;
  21588. }
  21589. if (list.__ownerID) {
  21590. list._root = newRoot;
  21591. list._tail = newTail;
  21592. list.__hash = undefined;
  21593. list.__altered = true;
  21594. return list;
  21595. }
  21596. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  21597. }
  21598. function updateVNode(node, ownerID, level, index, value, didAlter) {
  21599. var idx = (index >>> level) & MASK;
  21600. var nodeHas = node && idx < node.array.length;
  21601. if (!nodeHas && value === undefined) {
  21602. return node;
  21603. }
  21604. var newNode;
  21605. if (level > 0) {
  21606. var lowerNode = node && node.array[idx];
  21607. var newLowerNode = updateVNode(lowerNode, ownerID, level - SHIFT, index, value, didAlter);
  21608. if (newLowerNode === lowerNode) {
  21609. return node;
  21610. }
  21611. newNode = editableVNode(node, ownerID);
  21612. newNode.array[idx] = newLowerNode;
  21613. return newNode;
  21614. }
  21615. if (nodeHas && node.array[idx] === value) {
  21616. return node;
  21617. }
  21618. SetRef(didAlter);
  21619. newNode = editableVNode(node, ownerID);
  21620. if (value === undefined && idx === newNode.array.length - 1) {
  21621. newNode.array.pop();
  21622. } else {
  21623. newNode.array[idx] = value;
  21624. }
  21625. return newNode;
  21626. }
  21627. function editableVNode(node, ownerID) {
  21628. if (ownerID && node && ownerID === node.ownerID) {
  21629. return node;
  21630. }
  21631. return new VNode(node ? node.array.slice() : [], ownerID);
  21632. }
  21633. function listNodeFor(list, rawIndex) {
  21634. if (rawIndex >= getTailOffset(list._capacity)) {
  21635. return list._tail;
  21636. }
  21637. if (rawIndex < 1 << (list._level + SHIFT)) {
  21638. var node = list._root;
  21639. var level = list._level;
  21640. while (node && level > 0) {
  21641. node = node.array[(rawIndex >>> level) & MASK];
  21642. level -= SHIFT;
  21643. }
  21644. return node;
  21645. }
  21646. }
  21647. function setListBounds(list, begin, end) {
  21648. // Sanitize begin & end using this shorthand for ToInt32(argument)
  21649. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  21650. if (begin !== undefined) {
  21651. begin = begin | 0;
  21652. }
  21653. if (end !== undefined) {
  21654. end = end | 0;
  21655. }
  21656. var owner = list.__ownerID || new OwnerID();
  21657. var oldOrigin = list._origin;
  21658. var oldCapacity = list._capacity;
  21659. var newOrigin = oldOrigin + begin;
  21660. var newCapacity = end === undefined ? oldCapacity : end < 0 ? oldCapacity + end : oldOrigin + end;
  21661. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  21662. return list;
  21663. }
  21664. // If it's going to end after it starts, it's empty.
  21665. if (newOrigin >= newCapacity) {
  21666. return list.clear();
  21667. }
  21668. var newLevel = list._level;
  21669. var newRoot = list._root;
  21670. // New origin might need creating a higher root.
  21671. var offsetShift = 0;
  21672. while (newOrigin + offsetShift < 0) {
  21673. newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner);
  21674. newLevel += SHIFT;
  21675. offsetShift += 1 << newLevel;
  21676. }
  21677. if (offsetShift) {
  21678. newOrigin += offsetShift;
  21679. oldOrigin += offsetShift;
  21680. newCapacity += offsetShift;
  21681. oldCapacity += offsetShift;
  21682. }
  21683. var oldTailOffset = getTailOffset(oldCapacity);
  21684. var newTailOffset = getTailOffset(newCapacity);
  21685. // New size might need creating a higher root.
  21686. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  21687. newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner);
  21688. newLevel += SHIFT;
  21689. }
  21690. // Locate or create the new tail.
  21691. var oldTail = list._tail;
  21692. var newTail = newTailOffset < oldTailOffset ?
  21693. listNodeFor(list, newCapacity - 1) :
  21694. newTailOffset > oldTailOffset ? new VNode([], owner) : oldTail;
  21695. // Merge Tail into tree.
  21696. if (oldTail && newTailOffset > oldTailOffset && newOrigin < oldCapacity && oldTail.array.length) {
  21697. newRoot = editableVNode(newRoot, owner);
  21698. var node = newRoot;
  21699. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  21700. var idx = (oldTailOffset >>> level) & MASK;
  21701. node = node.array[idx] = editableVNode(node.array[idx], owner);
  21702. }
  21703. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  21704. }
  21705. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  21706. if (newCapacity < oldCapacity) {
  21707. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  21708. }
  21709. // If the new origin is within the tail, then we do not need a root.
  21710. if (newOrigin >= newTailOffset) {
  21711. newOrigin -= newTailOffset;
  21712. newCapacity -= newTailOffset;
  21713. newLevel = SHIFT;
  21714. newRoot = null;
  21715. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  21716. // Otherwise, if the root has been trimmed, garbage collect.
  21717. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  21718. offsetShift = 0;
  21719. // Identify the new top root node of the subtree of the old root.
  21720. while (newRoot) {
  21721. var beginIndex = (newOrigin >>> newLevel) & MASK;
  21722. if (beginIndex !== (newTailOffset >>> newLevel) & MASK) {
  21723. break;
  21724. }
  21725. if (beginIndex) {
  21726. offsetShift += (1 << newLevel) * beginIndex;
  21727. }
  21728. newLevel -= SHIFT;
  21729. newRoot = newRoot.array[beginIndex];
  21730. }
  21731. // Trim the new sides of the new root.
  21732. if (newRoot && newOrigin > oldOrigin) {
  21733. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  21734. }
  21735. if (newRoot && newTailOffset < oldTailOffset) {
  21736. newRoot = newRoot.removeAfter(owner, newLevel, newTailOffset - offsetShift);
  21737. }
  21738. if (offsetShift) {
  21739. newOrigin -= offsetShift;
  21740. newCapacity -= offsetShift;
  21741. }
  21742. }
  21743. if (list.__ownerID) {
  21744. list.size = newCapacity - newOrigin;
  21745. list._origin = newOrigin;
  21746. list._capacity = newCapacity;
  21747. list._level = newLevel;
  21748. list._root = newRoot;
  21749. list._tail = newTail;
  21750. list.__hash = undefined;
  21751. list.__altered = true;
  21752. return list;
  21753. }
  21754. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  21755. }
  21756. function mergeIntoListWith(list, merger, iterables) {
  21757. var iters = [];
  21758. var maxSize = 0;
  21759. for (var ii = 0; ii < iterables.length; ii++) {
  21760. var value = iterables[ii];
  21761. var iter = IndexedIterable(value);
  21762. if (iter.size > maxSize) {
  21763. maxSize = iter.size;
  21764. }
  21765. if (!isIterable(value)) {
  21766. iter = iter.map(function(v ) {return fromJS(v)});
  21767. }
  21768. iters.push(iter);
  21769. }
  21770. if (maxSize > list.size) {
  21771. list = list.setSize(maxSize);
  21772. }
  21773. return mergeIntoCollectionWith(list, merger, iters);
  21774. }
  21775. function getTailOffset(size) {
  21776. return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
  21777. }
  21778. createClass(OrderedMap, Map);
  21779. // @pragma Construction
  21780. function OrderedMap(value) {
  21781. return value === null || value === undefined ? emptyOrderedMap() :
  21782. isOrderedMap(value) ? value :
  21783. emptyOrderedMap().withMutations(function(map ) {
  21784. var iter = KeyedIterable(value);
  21785. assertNotInfinite(iter.size);
  21786. iter.forEach(function(v, k) {return map.set(k, v)});
  21787. });
  21788. }
  21789. OrderedMap.of = function(/*...values*/) {
  21790. return this(arguments);
  21791. };
  21792. OrderedMap.prototype.toString = function() {
  21793. return this.__toString('OrderedMap {', '}');
  21794. };
  21795. // @pragma Access
  21796. OrderedMap.prototype.get = function(k, notSetValue) {
  21797. var index = this._map.get(k);
  21798. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  21799. };
  21800. // @pragma Modification
  21801. OrderedMap.prototype.clear = function() {
  21802. if (this.size === 0) {
  21803. return this;
  21804. }
  21805. if (this.__ownerID) {
  21806. this.size = 0;
  21807. this._map.clear();
  21808. this._list.clear();
  21809. return this;
  21810. }
  21811. return emptyOrderedMap();
  21812. };
  21813. OrderedMap.prototype.set = function(k, v) {
  21814. return updateOrderedMap(this, k, v);
  21815. };
  21816. OrderedMap.prototype.remove = function(k) {
  21817. return updateOrderedMap(this, k, NOT_SET);
  21818. };
  21819. OrderedMap.prototype.wasAltered = function() {
  21820. return this._map.wasAltered() || this._list.wasAltered();
  21821. };
  21822. OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  21823. return this._list.__iterate(
  21824. function(entry ) {return entry && fn(entry[1], entry[0], this$0)},
  21825. reverse
  21826. );
  21827. };
  21828. OrderedMap.prototype.__iterator = function(type, reverse) {
  21829. return this._list.fromEntrySeq().__iterator(type, reverse);
  21830. };
  21831. OrderedMap.prototype.__ensureOwner = function(ownerID) {
  21832. if (ownerID === this.__ownerID) {
  21833. return this;
  21834. }
  21835. var newMap = this._map.__ensureOwner(ownerID);
  21836. var newList = this._list.__ensureOwner(ownerID);
  21837. if (!ownerID) {
  21838. this.__ownerID = ownerID;
  21839. this._map = newMap;
  21840. this._list = newList;
  21841. return this;
  21842. }
  21843. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  21844. };
  21845. function isOrderedMap(maybeOrderedMap) {
  21846. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  21847. }
  21848. OrderedMap.isOrderedMap = isOrderedMap;
  21849. OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
  21850. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  21851. function makeOrderedMap(map, list, ownerID, hash) {
  21852. var omap = Object.create(OrderedMap.prototype);
  21853. omap.size = map ? map.size : 0;
  21854. omap._map = map;
  21855. omap._list = list;
  21856. omap.__ownerID = ownerID;
  21857. omap.__hash = hash;
  21858. return omap;
  21859. }
  21860. var EMPTY_ORDERED_MAP;
  21861. function emptyOrderedMap() {
  21862. return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()));
  21863. }
  21864. function updateOrderedMap(omap, k, v) {
  21865. var map = omap._map;
  21866. var list = omap._list;
  21867. var i = map.get(k);
  21868. var has = i !== undefined;
  21869. var newMap;
  21870. var newList;
  21871. if (v === NOT_SET) { // removed
  21872. if (!has) {
  21873. return omap;
  21874. }
  21875. if (list.size >= SIZE && list.size >= map.size * 2) {
  21876. newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx});
  21877. newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap();
  21878. if (omap.__ownerID) {
  21879. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  21880. }
  21881. } else {
  21882. newMap = map.remove(k);
  21883. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  21884. }
  21885. } else {
  21886. if (has) {
  21887. if (v === list.get(i)[1]) {
  21888. return omap;
  21889. }
  21890. newMap = map;
  21891. newList = list.set(i, [k, v]);
  21892. } else {
  21893. newMap = map.set(k, list.size);
  21894. newList = list.set(list.size, [k, v]);
  21895. }
  21896. }
  21897. if (omap.__ownerID) {
  21898. omap.size = newMap.size;
  21899. omap._map = newMap;
  21900. omap._list = newList;
  21901. omap.__hash = undefined;
  21902. return omap;
  21903. }
  21904. return makeOrderedMap(newMap, newList);
  21905. }
  21906. createClass(ToKeyedSequence, KeyedSeq);
  21907. function ToKeyedSequence(indexed, useKeys) {
  21908. this._iter = indexed;
  21909. this._useKeys = useKeys;
  21910. this.size = indexed.size;
  21911. }
  21912. ToKeyedSequence.prototype.get = function(key, notSetValue) {
  21913. return this._iter.get(key, notSetValue);
  21914. };
  21915. ToKeyedSequence.prototype.has = function(key) {
  21916. return this._iter.has(key);
  21917. };
  21918. ToKeyedSequence.prototype.valueSeq = function() {
  21919. return this._iter.valueSeq();
  21920. };
  21921. ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
  21922. var reversedSequence = reverseFactory(this, true);
  21923. if (!this._useKeys) {
  21924. reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
  21925. }
  21926. return reversedSequence;
  21927. };
  21928. ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
  21929. var mappedSequence = mapFactory(this, mapper, context);
  21930. if (!this._useKeys) {
  21931. mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
  21932. }
  21933. return mappedSequence;
  21934. };
  21935. ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  21936. var ii;
  21937. return this._iter.__iterate(
  21938. this._useKeys ?
  21939. function(v, k) {return fn(v, k, this$0)} :
  21940. ((ii = reverse ? resolveSize(this) : 0),
  21941. function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
  21942. reverse
  21943. );
  21944. };
  21945. ToKeyedSequence.prototype.__iterator = function(type, reverse) {
  21946. if (this._useKeys) {
  21947. return this._iter.__iterator(type, reverse);
  21948. }
  21949. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  21950. var ii = reverse ? resolveSize(this) : 0;
  21951. return new Iterator(function() {
  21952. var step = iterator.next();
  21953. return step.done ? step :
  21954. iteratorValue(type, reverse ? --ii : ii++, step.value, step);
  21955. });
  21956. };
  21957. ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
  21958. createClass(ToIndexedSequence, IndexedSeq);
  21959. function ToIndexedSequence(iter) {
  21960. this._iter = iter;
  21961. this.size = iter.size;
  21962. }
  21963. ToIndexedSequence.prototype.includes = function(value) {
  21964. return this._iter.includes(value);
  21965. };
  21966. ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  21967. var iterations = 0;
  21968. return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
  21969. };
  21970. ToIndexedSequence.prototype.__iterator = function(type, reverse) {
  21971. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  21972. var iterations = 0;
  21973. return new Iterator(function() {
  21974. var step = iterator.next();
  21975. return step.done ? step :
  21976. iteratorValue(type, iterations++, step.value, step)
  21977. });
  21978. };
  21979. createClass(ToSetSequence, SetSeq);
  21980. function ToSetSequence(iter) {
  21981. this._iter = iter;
  21982. this.size = iter.size;
  21983. }
  21984. ToSetSequence.prototype.has = function(key) {
  21985. return this._iter.includes(key);
  21986. };
  21987. ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  21988. return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
  21989. };
  21990. ToSetSequence.prototype.__iterator = function(type, reverse) {
  21991. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  21992. return new Iterator(function() {
  21993. var step = iterator.next();
  21994. return step.done ? step :
  21995. iteratorValue(type, step.value, step.value, step);
  21996. });
  21997. };
  21998. createClass(FromEntriesSequence, KeyedSeq);
  21999. function FromEntriesSequence(entries) {
  22000. this._iter = entries;
  22001. this.size = entries.size;
  22002. }
  22003. FromEntriesSequence.prototype.entrySeq = function() {
  22004. return this._iter.toSeq();
  22005. };
  22006. FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  22007. return this._iter.__iterate(function(entry ) {
  22008. // Check if entry exists first so array access doesn't throw for holes
  22009. // in the parent iteration.
  22010. if (entry) {
  22011. validateEntry(entry);
  22012. var indexedIterable = isIterable(entry);
  22013. return fn(
  22014. indexedIterable ? entry.get(1) : entry[1],
  22015. indexedIterable ? entry.get(0) : entry[0],
  22016. this$0
  22017. );
  22018. }
  22019. }, reverse);
  22020. };
  22021. FromEntriesSequence.prototype.__iterator = function(type, reverse) {
  22022. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  22023. return new Iterator(function() {
  22024. while (true) {
  22025. var step = iterator.next();
  22026. if (step.done) {
  22027. return step;
  22028. }
  22029. var entry = step.value;
  22030. // Check if entry exists first so array access doesn't throw for holes
  22031. // in the parent iteration.
  22032. if (entry) {
  22033. validateEntry(entry);
  22034. var indexedIterable = isIterable(entry);
  22035. return iteratorValue(
  22036. type,
  22037. indexedIterable ? entry.get(0) : entry[0],
  22038. indexedIterable ? entry.get(1) : entry[1],
  22039. step
  22040. );
  22041. }
  22042. }
  22043. });
  22044. };
  22045. ToIndexedSequence.prototype.cacheResult =
  22046. ToKeyedSequence.prototype.cacheResult =
  22047. ToSetSequence.prototype.cacheResult =
  22048. FromEntriesSequence.prototype.cacheResult =
  22049. cacheResultThrough;
  22050. function flipFactory(iterable) {
  22051. var flipSequence = makeSequence(iterable);
  22052. flipSequence._iter = iterable;
  22053. flipSequence.size = iterable.size;
  22054. flipSequence.flip = function() {return iterable};
  22055. flipSequence.reverse = function () {
  22056. var reversedSequence = iterable.reverse.apply(this); // super.reverse()
  22057. reversedSequence.flip = function() {return iterable.reverse()};
  22058. return reversedSequence;
  22059. };
  22060. flipSequence.has = function(key ) {return iterable.includes(key)};
  22061. flipSequence.includes = function(key ) {return iterable.has(key)};
  22062. flipSequence.cacheResult = cacheResultThrough;
  22063. flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  22064. return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
  22065. };
  22066. flipSequence.__iteratorUncached = function(type, reverse) {
  22067. if (type === ITERATE_ENTRIES) {
  22068. var iterator = iterable.__iterator(type, reverse);
  22069. return new Iterator(function() {
  22070. var step = iterator.next();
  22071. if (!step.done) {
  22072. var k = step.value[0];
  22073. step.value[0] = step.value[1];
  22074. step.value[1] = k;
  22075. }
  22076. return step;
  22077. });
  22078. }
  22079. return iterable.__iterator(
  22080. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  22081. reverse
  22082. );
  22083. };
  22084. return flipSequence;
  22085. }
  22086. function mapFactory(iterable, mapper, context) {
  22087. var mappedSequence = makeSequence(iterable);
  22088. mappedSequence.size = iterable.size;
  22089. mappedSequence.has = function(key ) {return iterable.has(key)};
  22090. mappedSequence.get = function(key, notSetValue) {
  22091. var v = iterable.get(key, NOT_SET);
  22092. return v === NOT_SET ?
  22093. notSetValue :
  22094. mapper.call(context, v, key, iterable);
  22095. };
  22096. mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  22097. return iterable.__iterate(
  22098. function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
  22099. reverse
  22100. );
  22101. };
  22102. mappedSequence.__iteratorUncached = function (type, reverse) {
  22103. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  22104. return new Iterator(function() {
  22105. var step = iterator.next();
  22106. if (step.done) {
  22107. return step;
  22108. }
  22109. var entry = step.value;
  22110. var key = entry[0];
  22111. return iteratorValue(
  22112. type,
  22113. key,
  22114. mapper.call(context, entry[1], key, iterable),
  22115. step
  22116. );
  22117. });
  22118. };
  22119. return mappedSequence;
  22120. }
  22121. function reverseFactory(iterable, useKeys) {
  22122. var reversedSequence = makeSequence(iterable);
  22123. reversedSequence._iter = iterable;
  22124. reversedSequence.size = iterable.size;
  22125. reversedSequence.reverse = function() {return iterable};
  22126. if (iterable.flip) {
  22127. reversedSequence.flip = function () {
  22128. var flipSequence = flipFactory(iterable);
  22129. flipSequence.reverse = function() {return iterable.flip()};
  22130. return flipSequence;
  22131. };
  22132. }
  22133. reversedSequence.get = function(key, notSetValue)
  22134. {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
  22135. reversedSequence.has = function(key )
  22136. {return iterable.has(useKeys ? key : -1 - key)};
  22137. reversedSequence.includes = function(value ) {return iterable.includes(value)};
  22138. reversedSequence.cacheResult = cacheResultThrough;
  22139. reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
  22140. return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
  22141. };
  22142. reversedSequence.__iterator =
  22143. function(type, reverse) {return iterable.__iterator(type, !reverse)};
  22144. return reversedSequence;
  22145. }
  22146. function filterFactory(iterable, predicate, context, useKeys) {
  22147. var filterSequence = makeSequence(iterable);
  22148. if (useKeys) {
  22149. filterSequence.has = function(key ) {
  22150. var v = iterable.get(key, NOT_SET);
  22151. return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
  22152. };
  22153. filterSequence.get = function(key, notSetValue) {
  22154. var v = iterable.get(key, NOT_SET);
  22155. return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
  22156. v : notSetValue;
  22157. };
  22158. }
  22159. filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  22160. var iterations = 0;
  22161. iterable.__iterate(function(v, k, c) {
  22162. if (predicate.call(context, v, k, c)) {
  22163. iterations++;
  22164. return fn(v, useKeys ? k : iterations - 1, this$0);
  22165. }
  22166. }, reverse);
  22167. return iterations;
  22168. };
  22169. filterSequence.__iteratorUncached = function (type, reverse) {
  22170. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  22171. var iterations = 0;
  22172. return new Iterator(function() {
  22173. while (true) {
  22174. var step = iterator.next();
  22175. if (step.done) {
  22176. return step;
  22177. }
  22178. var entry = step.value;
  22179. var key = entry[0];
  22180. var value = entry[1];
  22181. if (predicate.call(context, value, key, iterable)) {
  22182. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  22183. }
  22184. }
  22185. });
  22186. };
  22187. return filterSequence;
  22188. }
  22189. function countByFactory(iterable, grouper, context) {
  22190. var groups = Map().asMutable();
  22191. iterable.__iterate(function(v, k) {
  22192. groups.update(
  22193. grouper.call(context, v, k, iterable),
  22194. 0,
  22195. function(a ) {return a + 1}
  22196. );
  22197. });
  22198. return groups.asImmutable();
  22199. }
  22200. function groupByFactory(iterable, grouper, context) {
  22201. var isKeyedIter = isKeyed(iterable);
  22202. var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable();
  22203. iterable.__iterate(function(v, k) {
  22204. groups.update(
  22205. grouper.call(context, v, k, iterable),
  22206. function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
  22207. );
  22208. });
  22209. var coerce = iterableClass(iterable);
  22210. return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
  22211. }
  22212. function sliceFactory(iterable, begin, end, useKeys) {
  22213. var originalSize = iterable.size;
  22214. // Sanitize begin & end using this shorthand for ToInt32(argument)
  22215. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  22216. if (begin !== undefined) {
  22217. begin = begin | 0;
  22218. }
  22219. if (end !== undefined) {
  22220. end = end | 0;
  22221. }
  22222. if (wholeSlice(begin, end, originalSize)) {
  22223. return iterable;
  22224. }
  22225. var resolvedBegin = resolveBegin(begin, originalSize);
  22226. var resolvedEnd = resolveEnd(end, originalSize);
  22227. // begin or end will be NaN if they were provided as negative numbers and
  22228. // this iterable's size is unknown. In that case, cache first so there is
  22229. // a known size and these do not resolve to NaN.
  22230. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  22231. return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
  22232. }
  22233. // Note: resolvedEnd is undefined when the original sequence's length is
  22234. // unknown and this slice did not supply an end and should contain all
  22235. // elements after resolvedBegin.
  22236. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  22237. var resolvedSize = resolvedEnd - resolvedBegin;
  22238. var sliceSize;
  22239. if (resolvedSize === resolvedSize) {
  22240. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  22241. }
  22242. var sliceSeq = makeSequence(iterable);
  22243. // If iterable.size is undefined, the size of the realized sliceSeq is
  22244. // unknown at this point unless the number of items to slice is 0
  22245. sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
  22246. if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
  22247. sliceSeq.get = function (index, notSetValue) {
  22248. index = wrapIndex(this, index);
  22249. return index >= 0 && index < sliceSize ?
  22250. iterable.get(index + resolvedBegin, notSetValue) :
  22251. notSetValue;
  22252. };
  22253. }
  22254. sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
  22255. if (sliceSize === 0) {
  22256. return 0;
  22257. }
  22258. if (reverse) {
  22259. return this.cacheResult().__iterate(fn, reverse);
  22260. }
  22261. var skipped = 0;
  22262. var isSkipping = true;
  22263. var iterations = 0;
  22264. iterable.__iterate(function(v, k) {
  22265. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  22266. iterations++;
  22267. return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
  22268. iterations !== sliceSize;
  22269. }
  22270. });
  22271. return iterations;
  22272. };
  22273. sliceSeq.__iteratorUncached = function(type, reverse) {
  22274. if (sliceSize !== 0 && reverse) {
  22275. return this.cacheResult().__iterator(type, reverse);
  22276. }
  22277. // Don't bother instantiating parent iterator if taking 0.
  22278. var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
  22279. var skipped = 0;
  22280. var iterations = 0;
  22281. return new Iterator(function() {
  22282. while (skipped++ < resolvedBegin) {
  22283. iterator.next();
  22284. }
  22285. if (++iterations > sliceSize) {
  22286. return iteratorDone();
  22287. }
  22288. var step = iterator.next();
  22289. if (useKeys || type === ITERATE_VALUES) {
  22290. return step;
  22291. } else if (type === ITERATE_KEYS) {
  22292. return iteratorValue(type, iterations - 1, undefined, step);
  22293. } else {
  22294. return iteratorValue(type, iterations - 1, step.value[1], step);
  22295. }
  22296. });
  22297. };
  22298. return sliceSeq;
  22299. }
  22300. function takeWhileFactory(iterable, predicate, context) {
  22301. var takeSequence = makeSequence(iterable);
  22302. takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  22303. if (reverse) {
  22304. return this.cacheResult().__iterate(fn, reverse);
  22305. }
  22306. var iterations = 0;
  22307. iterable.__iterate(function(v, k, c)
  22308. {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
  22309. );
  22310. return iterations;
  22311. };
  22312. takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  22313. if (reverse) {
  22314. return this.cacheResult().__iterator(type, reverse);
  22315. }
  22316. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  22317. var iterating = true;
  22318. return new Iterator(function() {
  22319. if (!iterating) {
  22320. return iteratorDone();
  22321. }
  22322. var step = iterator.next();
  22323. if (step.done) {
  22324. return step;
  22325. }
  22326. var entry = step.value;
  22327. var k = entry[0];
  22328. var v = entry[1];
  22329. if (!predicate.call(context, v, k, this$0)) {
  22330. iterating = false;
  22331. return iteratorDone();
  22332. }
  22333. return type === ITERATE_ENTRIES ? step :
  22334. iteratorValue(type, k, v, step);
  22335. });
  22336. };
  22337. return takeSequence;
  22338. }
  22339. function skipWhileFactory(iterable, predicate, context, useKeys) {
  22340. var skipSequence = makeSequence(iterable);
  22341. skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  22342. if (reverse) {
  22343. return this.cacheResult().__iterate(fn, reverse);
  22344. }
  22345. var isSkipping = true;
  22346. var iterations = 0;
  22347. iterable.__iterate(function(v, k, c) {
  22348. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  22349. iterations++;
  22350. return fn(v, useKeys ? k : iterations - 1, this$0);
  22351. }
  22352. });
  22353. return iterations;
  22354. };
  22355. skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  22356. if (reverse) {
  22357. return this.cacheResult().__iterator(type, reverse);
  22358. }
  22359. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  22360. var skipping = true;
  22361. var iterations = 0;
  22362. return new Iterator(function() {
  22363. var step, k, v;
  22364. do {
  22365. step = iterator.next();
  22366. if (step.done) {
  22367. if (useKeys || type === ITERATE_VALUES) {
  22368. return step;
  22369. } else if (type === ITERATE_KEYS) {
  22370. return iteratorValue(type, iterations++, undefined, step);
  22371. } else {
  22372. return iteratorValue(type, iterations++, step.value[1], step);
  22373. }
  22374. }
  22375. var entry = step.value;
  22376. k = entry[0];
  22377. v = entry[1];
  22378. skipping && (skipping = predicate.call(context, v, k, this$0));
  22379. } while (skipping);
  22380. return type === ITERATE_ENTRIES ? step :
  22381. iteratorValue(type, k, v, step);
  22382. });
  22383. };
  22384. return skipSequence;
  22385. }
  22386. function concatFactory(iterable, values) {
  22387. var isKeyedIterable = isKeyed(iterable);
  22388. var iters = [iterable].concat(values).map(function(v ) {
  22389. if (!isIterable(v)) {
  22390. v = isKeyedIterable ?
  22391. keyedSeqFromValue(v) :
  22392. indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  22393. } else if (isKeyedIterable) {
  22394. v = KeyedIterable(v);
  22395. }
  22396. return v;
  22397. }).filter(function(v ) {return v.size !== 0});
  22398. if (iters.length === 0) {
  22399. return iterable;
  22400. }
  22401. if (iters.length === 1) {
  22402. var singleton = iters[0];
  22403. if (singleton === iterable ||
  22404. isKeyedIterable && isKeyed(singleton) ||
  22405. isIndexed(iterable) && isIndexed(singleton)) {
  22406. return singleton;
  22407. }
  22408. }
  22409. var concatSeq = new ArraySeq(iters);
  22410. if (isKeyedIterable) {
  22411. concatSeq = concatSeq.toKeyedSeq();
  22412. } else if (!isIndexed(iterable)) {
  22413. concatSeq = concatSeq.toSetSeq();
  22414. }
  22415. concatSeq = concatSeq.flatten(true);
  22416. concatSeq.size = iters.reduce(
  22417. function(sum, seq) {
  22418. if (sum !== undefined) {
  22419. var size = seq.size;
  22420. if (size !== undefined) {
  22421. return sum + size;
  22422. }
  22423. }
  22424. },
  22425. 0
  22426. );
  22427. return concatSeq;
  22428. }
  22429. function flattenFactory(iterable, depth, useKeys) {
  22430. var flatSequence = makeSequence(iterable);
  22431. flatSequence.__iterateUncached = function(fn, reverse) {
  22432. var iterations = 0;
  22433. var stopped = false;
  22434. function flatDeep(iter, currentDepth) {var this$0 = this;
  22435. iter.__iterate(function(v, k) {
  22436. if ((!depth || currentDepth < depth) && isIterable(v)) {
  22437. flatDeep(v, currentDepth + 1);
  22438. } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
  22439. stopped = true;
  22440. }
  22441. return !stopped;
  22442. }, reverse);
  22443. }
  22444. flatDeep(iterable, 0);
  22445. return iterations;
  22446. };
  22447. flatSequence.__iteratorUncached = function(type, reverse) {
  22448. var iterator = iterable.__iterator(type, reverse);
  22449. var stack = [];
  22450. var iterations = 0;
  22451. return new Iterator(function() {
  22452. while (iterator) {
  22453. var step = iterator.next();
  22454. if (step.done !== false) {
  22455. iterator = stack.pop();
  22456. continue;
  22457. }
  22458. var v = step.value;
  22459. if (type === ITERATE_ENTRIES) {
  22460. v = v[1];
  22461. }
  22462. if ((!depth || stack.length < depth) && isIterable(v)) {
  22463. stack.push(iterator);
  22464. iterator = v.__iterator(type, reverse);
  22465. } else {
  22466. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  22467. }
  22468. }
  22469. return iteratorDone();
  22470. });
  22471. };
  22472. return flatSequence;
  22473. }
  22474. function flatMapFactory(iterable, mapper, context) {
  22475. var coerce = iterableClass(iterable);
  22476. return iterable.toSeq().map(
  22477. function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
  22478. ).flatten(true);
  22479. }
  22480. function interposeFactory(iterable, separator) {
  22481. var interposedSequence = makeSequence(iterable);
  22482. interposedSequence.size = iterable.size && iterable.size * 2 -1;
  22483. interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  22484. var iterations = 0;
  22485. iterable.__iterate(function(v, k)
  22486. {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
  22487. fn(v, iterations++, this$0) !== false},
  22488. reverse
  22489. );
  22490. return iterations;
  22491. };
  22492. interposedSequence.__iteratorUncached = function(type, reverse) {
  22493. var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
  22494. var iterations = 0;
  22495. var step;
  22496. return new Iterator(function() {
  22497. if (!step || iterations % 2) {
  22498. step = iterator.next();
  22499. if (step.done) {
  22500. return step;
  22501. }
  22502. }
  22503. return iterations % 2 ?
  22504. iteratorValue(type, iterations++, separator) :
  22505. iteratorValue(type, iterations++, step.value, step);
  22506. });
  22507. };
  22508. return interposedSequence;
  22509. }
  22510. function sortFactory(iterable, comparator, mapper) {
  22511. if (!comparator) {
  22512. comparator = defaultComparator;
  22513. }
  22514. var isKeyedIterable = isKeyed(iterable);
  22515. var index = 0;
  22516. var entries = iterable.toSeq().map(
  22517. function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
  22518. ).toArray();
  22519. entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
  22520. isKeyedIterable ?
  22521. function(v, i) { entries[i].length = 2; } :
  22522. function(v, i) { entries[i] = v[1]; }
  22523. );
  22524. return isKeyedIterable ? KeyedSeq(entries) :
  22525. isIndexed(iterable) ? IndexedSeq(entries) :
  22526. SetSeq(entries);
  22527. }
  22528. function maxFactory(iterable, comparator, mapper) {
  22529. if (!comparator) {
  22530. comparator = defaultComparator;
  22531. }
  22532. if (mapper) {
  22533. var entry = iterable.toSeq()
  22534. .map(function(v, k) {return [v, mapper(v, k, iterable)]})
  22535. .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
  22536. return entry && entry[0];
  22537. } else {
  22538. return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
  22539. }
  22540. }
  22541. function maxCompare(comparator, a, b) {
  22542. var comp = comparator(b, a);
  22543. // b is considered the new max if the comparator declares them equal, but
  22544. // they are not equal and b is in fact a nullish value.
  22545. return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
  22546. }
  22547. function zipWithFactory(keyIter, zipper, iters) {
  22548. var zipSequence = makeSequence(keyIter);
  22549. zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
  22550. // Note: this a generic base implementation of __iterate in terms of
  22551. // __iterator which may be more generically useful in the future.
  22552. zipSequence.__iterate = function(fn, reverse) {
  22553. /* generic:
  22554. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  22555. var step;
  22556. var iterations = 0;
  22557. while (!(step = iterator.next()).done) {
  22558. iterations++;
  22559. if (fn(step.value[1], step.value[0], this) === false) {
  22560. break;
  22561. }
  22562. }
  22563. return iterations;
  22564. */
  22565. // indexed:
  22566. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  22567. var step;
  22568. var iterations = 0;
  22569. while (!(step = iterator.next()).done) {
  22570. if (fn(step.value, iterations++, this) === false) {
  22571. break;
  22572. }
  22573. }
  22574. return iterations;
  22575. };
  22576. zipSequence.__iteratorUncached = function(type, reverse) {
  22577. var iterators = iters.map(function(i )
  22578. {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
  22579. );
  22580. var iterations = 0;
  22581. var isDone = false;
  22582. return new Iterator(function() {
  22583. var steps;
  22584. if (!isDone) {
  22585. steps = iterators.map(function(i ) {return i.next()});
  22586. isDone = steps.some(function(s ) {return s.done});
  22587. }
  22588. if (isDone) {
  22589. return iteratorDone();
  22590. }
  22591. return iteratorValue(
  22592. type,
  22593. iterations++,
  22594. zipper.apply(null, steps.map(function(s ) {return s.value}))
  22595. );
  22596. });
  22597. };
  22598. return zipSequence
  22599. }
  22600. // #pragma Helper Functions
  22601. function reify(iter, seq) {
  22602. return isSeq(iter) ? seq : iter.constructor(seq);
  22603. }
  22604. function validateEntry(entry) {
  22605. if (entry !== Object(entry)) {
  22606. throw new TypeError('Expected [K, V] tuple: ' + entry);
  22607. }
  22608. }
  22609. function resolveSize(iter) {
  22610. assertNotInfinite(iter.size);
  22611. return ensureSize(iter);
  22612. }
  22613. function iterableClass(iterable) {
  22614. return isKeyed(iterable) ? KeyedIterable :
  22615. isIndexed(iterable) ? IndexedIterable :
  22616. SetIterable;
  22617. }
  22618. function makeSequence(iterable) {
  22619. return Object.create(
  22620. (
  22621. isKeyed(iterable) ? KeyedSeq :
  22622. isIndexed(iterable) ? IndexedSeq :
  22623. SetSeq
  22624. ).prototype
  22625. );
  22626. }
  22627. function cacheResultThrough() {
  22628. if (this._iter.cacheResult) {
  22629. this._iter.cacheResult();
  22630. this.size = this._iter.size;
  22631. return this;
  22632. } else {
  22633. return Seq.prototype.cacheResult.call(this);
  22634. }
  22635. }
  22636. function defaultComparator(a, b) {
  22637. return a > b ? 1 : a < b ? -1 : 0;
  22638. }
  22639. function forceIterator(keyPath) {
  22640. var iter = getIterator(keyPath);
  22641. if (!iter) {
  22642. // Array might not be iterable in this environment, so we need a fallback
  22643. // to our wrapped type.
  22644. if (!isArrayLike(keyPath)) {
  22645. throw new TypeError('Expected iterable or array-like: ' + keyPath);
  22646. }
  22647. iter = getIterator(Iterable(keyPath));
  22648. }
  22649. return iter;
  22650. }
  22651. createClass(Record, KeyedCollection);
  22652. function Record(defaultValues, name) {
  22653. var hasInitialized;
  22654. var RecordType = function Record(values) {
  22655. if (values instanceof RecordType) {
  22656. return values;
  22657. }
  22658. if (!(this instanceof RecordType)) {
  22659. return new RecordType(values);
  22660. }
  22661. if (!hasInitialized) {
  22662. hasInitialized = true;
  22663. var keys = Object.keys(defaultValues);
  22664. setProps(RecordTypePrototype, keys);
  22665. RecordTypePrototype.size = keys.length;
  22666. RecordTypePrototype._name = name;
  22667. RecordTypePrototype._keys = keys;
  22668. RecordTypePrototype._defaultValues = defaultValues;
  22669. }
  22670. this._map = Map(values);
  22671. };
  22672. var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
  22673. RecordTypePrototype.constructor = RecordType;
  22674. return RecordType;
  22675. }
  22676. Record.prototype.toString = function() {
  22677. return this.__toString(recordName(this) + ' {', '}');
  22678. };
  22679. // @pragma Access
  22680. Record.prototype.has = function(k) {
  22681. return this._defaultValues.hasOwnProperty(k);
  22682. };
  22683. Record.prototype.get = function(k, notSetValue) {
  22684. if (!this.has(k)) {
  22685. return notSetValue;
  22686. }
  22687. var defaultVal = this._defaultValues[k];
  22688. return this._map ? this._map.get(k, defaultVal) : defaultVal;
  22689. };
  22690. // @pragma Modification
  22691. Record.prototype.clear = function() {
  22692. if (this.__ownerID) {
  22693. this._map && this._map.clear();
  22694. return this;
  22695. }
  22696. var RecordType = this.constructor;
  22697. return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap()));
  22698. };
  22699. Record.prototype.set = function(k, v) {
  22700. if (!this.has(k)) {
  22701. throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
  22702. }
  22703. var newMap = this._map && this._map.set(k, v);
  22704. if (this.__ownerID || newMap === this._map) {
  22705. return this;
  22706. }
  22707. return makeRecord(this, newMap);
  22708. };
  22709. Record.prototype.remove = function(k) {
  22710. if (!this.has(k)) {
  22711. return this;
  22712. }
  22713. var newMap = this._map && this._map.remove(k);
  22714. if (this.__ownerID || newMap === this._map) {
  22715. return this;
  22716. }
  22717. return makeRecord(this, newMap);
  22718. };
  22719. Record.prototype.wasAltered = function() {
  22720. return this._map.wasAltered();
  22721. };
  22722. Record.prototype.__iterator = function(type, reverse) {var this$0 = this;
  22723. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse);
  22724. };
  22725. Record.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  22726. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse);
  22727. };
  22728. Record.prototype.__ensureOwner = function(ownerID) {
  22729. if (ownerID === this.__ownerID) {
  22730. return this;
  22731. }
  22732. var newMap = this._map && this._map.__ensureOwner(ownerID);
  22733. if (!ownerID) {
  22734. this.__ownerID = ownerID;
  22735. this._map = newMap;
  22736. return this;
  22737. }
  22738. return makeRecord(this, newMap, ownerID);
  22739. };
  22740. var RecordPrototype = Record.prototype;
  22741. RecordPrototype[DELETE] = RecordPrototype.remove;
  22742. RecordPrototype.deleteIn =
  22743. RecordPrototype.removeIn = MapPrototype.removeIn;
  22744. RecordPrototype.merge = MapPrototype.merge;
  22745. RecordPrototype.mergeWith = MapPrototype.mergeWith;
  22746. RecordPrototype.mergeIn = MapPrototype.mergeIn;
  22747. RecordPrototype.mergeDeep = MapPrototype.mergeDeep;
  22748. RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith;
  22749. RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  22750. RecordPrototype.setIn = MapPrototype.setIn;
  22751. RecordPrototype.update = MapPrototype.update;
  22752. RecordPrototype.updateIn = MapPrototype.updateIn;
  22753. RecordPrototype.withMutations = MapPrototype.withMutations;
  22754. RecordPrototype.asMutable = MapPrototype.asMutable;
  22755. RecordPrototype.asImmutable = MapPrototype.asImmutable;
  22756. function makeRecord(likeRecord, map, ownerID) {
  22757. var record = Object.create(Object.getPrototypeOf(likeRecord));
  22758. record._map = map;
  22759. record.__ownerID = ownerID;
  22760. return record;
  22761. }
  22762. function recordName(record) {
  22763. return record._name || record.constructor.name || 'Record';
  22764. }
  22765. function setProps(prototype, names) {
  22766. try {
  22767. names.forEach(setProp.bind(undefined, prototype));
  22768. } catch (error) {
  22769. // Object.defineProperty failed. Probably IE8.
  22770. }
  22771. }
  22772. function setProp(prototype, name) {
  22773. Object.defineProperty(prototype, name, {
  22774. get: function() {
  22775. return this.get(name);
  22776. },
  22777. set: function(value) {
  22778. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  22779. this.set(name, value);
  22780. }
  22781. });
  22782. }
  22783. createClass(Set, SetCollection);
  22784. // @pragma Construction
  22785. function Set(value) {
  22786. return value === null || value === undefined ? emptySet() :
  22787. isSet(value) && !isOrdered(value) ? value :
  22788. emptySet().withMutations(function(set ) {
  22789. var iter = SetIterable(value);
  22790. assertNotInfinite(iter.size);
  22791. iter.forEach(function(v ) {return set.add(v)});
  22792. });
  22793. }
  22794. Set.of = function(/*...values*/) {
  22795. return this(arguments);
  22796. };
  22797. Set.fromKeys = function(value) {
  22798. return this(KeyedIterable(value).keySeq());
  22799. };
  22800. Set.prototype.toString = function() {
  22801. return this.__toString('Set {', '}');
  22802. };
  22803. // @pragma Access
  22804. Set.prototype.has = function(value) {
  22805. return this._map.has(value);
  22806. };
  22807. // @pragma Modification
  22808. Set.prototype.add = function(value) {
  22809. return updateSet(this, this._map.set(value, true));
  22810. };
  22811. Set.prototype.remove = function(value) {
  22812. return updateSet(this, this._map.remove(value));
  22813. };
  22814. Set.prototype.clear = function() {
  22815. return updateSet(this, this._map.clear());
  22816. };
  22817. // @pragma Composition
  22818. Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
  22819. iters = iters.filter(function(x ) {return x.size !== 0});
  22820. if (iters.length === 0) {
  22821. return this;
  22822. }
  22823. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  22824. return this.constructor(iters[0]);
  22825. }
  22826. return this.withMutations(function(set ) {
  22827. for (var ii = 0; ii < iters.length; ii++) {
  22828. SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)});
  22829. }
  22830. });
  22831. };
  22832. Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
  22833. if (iters.length === 0) {
  22834. return this;
  22835. }
  22836. iters = iters.map(function(iter ) {return SetIterable(iter)});
  22837. var originalSet = this;
  22838. return this.withMutations(function(set ) {
  22839. originalSet.forEach(function(value ) {
  22840. if (!iters.every(function(iter ) {return iter.includes(value)})) {
  22841. set.remove(value);
  22842. }
  22843. });
  22844. });
  22845. };
  22846. Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
  22847. if (iters.length === 0) {
  22848. return this;
  22849. }
  22850. iters = iters.map(function(iter ) {return SetIterable(iter)});
  22851. var originalSet = this;
  22852. return this.withMutations(function(set ) {
  22853. originalSet.forEach(function(value ) {
  22854. if (iters.some(function(iter ) {return iter.includes(value)})) {
  22855. set.remove(value);
  22856. }
  22857. });
  22858. });
  22859. };
  22860. Set.prototype.merge = function() {
  22861. return this.union.apply(this, arguments);
  22862. };
  22863. Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  22864. return this.union.apply(this, iters);
  22865. };
  22866. Set.prototype.sort = function(comparator) {
  22867. // Late binding
  22868. return OrderedSet(sortFactory(this, comparator));
  22869. };
  22870. Set.prototype.sortBy = function(mapper, comparator) {
  22871. // Late binding
  22872. return OrderedSet(sortFactory(this, comparator, mapper));
  22873. };
  22874. Set.prototype.wasAltered = function() {
  22875. return this._map.wasAltered();
  22876. };
  22877. Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  22878. return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
  22879. };
  22880. Set.prototype.__iterator = function(type, reverse) {
  22881. return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
  22882. };
  22883. Set.prototype.__ensureOwner = function(ownerID) {
  22884. if (ownerID === this.__ownerID) {
  22885. return this;
  22886. }
  22887. var newMap = this._map.__ensureOwner(ownerID);
  22888. if (!ownerID) {
  22889. this.__ownerID = ownerID;
  22890. this._map = newMap;
  22891. return this;
  22892. }
  22893. return this.__make(newMap, ownerID);
  22894. };
  22895. function isSet(maybeSet) {
  22896. return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
  22897. }
  22898. Set.isSet = isSet;
  22899. var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
  22900. var SetPrototype = Set.prototype;
  22901. SetPrototype[IS_SET_SENTINEL] = true;
  22902. SetPrototype[DELETE] = SetPrototype.remove;
  22903. SetPrototype.mergeDeep = SetPrototype.merge;
  22904. SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
  22905. SetPrototype.withMutations = MapPrototype.withMutations;
  22906. SetPrototype.asMutable = MapPrototype.asMutable;
  22907. SetPrototype.asImmutable = MapPrototype.asImmutable;
  22908. SetPrototype.__empty = emptySet;
  22909. SetPrototype.__make = makeSet;
  22910. function updateSet(set, newMap) {
  22911. if (set.__ownerID) {
  22912. set.size = newMap.size;
  22913. set._map = newMap;
  22914. return set;
  22915. }
  22916. return newMap === set._map ? set :
  22917. newMap.size === 0 ? set.__empty() :
  22918. set.__make(newMap);
  22919. }
  22920. function makeSet(map, ownerID) {
  22921. var set = Object.create(SetPrototype);
  22922. set.size = map ? map.size : 0;
  22923. set._map = map;
  22924. set.__ownerID = ownerID;
  22925. return set;
  22926. }
  22927. var EMPTY_SET;
  22928. function emptySet() {
  22929. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  22930. }
  22931. createClass(OrderedSet, Set);
  22932. // @pragma Construction
  22933. function OrderedSet(value) {
  22934. return value === null || value === undefined ? emptyOrderedSet() :
  22935. isOrderedSet(value) ? value :
  22936. emptyOrderedSet().withMutations(function(set ) {
  22937. var iter = SetIterable(value);
  22938. assertNotInfinite(iter.size);
  22939. iter.forEach(function(v ) {return set.add(v)});
  22940. });
  22941. }
  22942. OrderedSet.of = function(/*...values*/) {
  22943. return this(arguments);
  22944. };
  22945. OrderedSet.fromKeys = function(value) {
  22946. return this(KeyedIterable(value).keySeq());
  22947. };
  22948. OrderedSet.prototype.toString = function() {
  22949. return this.__toString('OrderedSet {', '}');
  22950. };
  22951. function isOrderedSet(maybeOrderedSet) {
  22952. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  22953. }
  22954. OrderedSet.isOrderedSet = isOrderedSet;
  22955. var OrderedSetPrototype = OrderedSet.prototype;
  22956. OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
  22957. OrderedSetPrototype.__empty = emptyOrderedSet;
  22958. OrderedSetPrototype.__make = makeOrderedSet;
  22959. function makeOrderedSet(map, ownerID) {
  22960. var set = Object.create(OrderedSetPrototype);
  22961. set.size = map ? map.size : 0;
  22962. set._map = map;
  22963. set.__ownerID = ownerID;
  22964. return set;
  22965. }
  22966. var EMPTY_ORDERED_SET;
  22967. function emptyOrderedSet() {
  22968. return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
  22969. }
  22970. createClass(Stack, IndexedCollection);
  22971. // @pragma Construction
  22972. function Stack(value) {
  22973. return value === null || value === undefined ? emptyStack() :
  22974. isStack(value) ? value :
  22975. emptyStack().unshiftAll(value);
  22976. }
  22977. Stack.of = function(/*...values*/) {
  22978. return this(arguments);
  22979. };
  22980. Stack.prototype.toString = function() {
  22981. return this.__toString('Stack [', ']');
  22982. };
  22983. // @pragma Access
  22984. Stack.prototype.get = function(index, notSetValue) {
  22985. var head = this._head;
  22986. index = wrapIndex(this, index);
  22987. while (head && index--) {
  22988. head = head.next;
  22989. }
  22990. return head ? head.value : notSetValue;
  22991. };
  22992. Stack.prototype.peek = function() {
  22993. return this._head && this._head.value;
  22994. };
  22995. // @pragma Modification
  22996. Stack.prototype.push = function(/*...values*/) {
  22997. if (arguments.length === 0) {
  22998. return this;
  22999. }
  23000. var newSize = this.size + arguments.length;
  23001. var head = this._head;
  23002. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  23003. head = {
  23004. value: arguments[ii],
  23005. next: head
  23006. };
  23007. }
  23008. if (this.__ownerID) {
  23009. this.size = newSize;
  23010. this._head = head;
  23011. this.__hash = undefined;
  23012. this.__altered = true;
  23013. return this;
  23014. }
  23015. return makeStack(newSize, head);
  23016. };
  23017. Stack.prototype.pushAll = function(iter) {
  23018. iter = IndexedIterable(iter);
  23019. if (iter.size === 0) {
  23020. return this;
  23021. }
  23022. assertNotInfinite(iter.size);
  23023. var newSize = this.size;
  23024. var head = this._head;
  23025. iter.reverse().forEach(function(value ) {
  23026. newSize++;
  23027. head = {
  23028. value: value,
  23029. next: head
  23030. };
  23031. });
  23032. if (this.__ownerID) {
  23033. this.size = newSize;
  23034. this._head = head;
  23035. this.__hash = undefined;
  23036. this.__altered = true;
  23037. return this;
  23038. }
  23039. return makeStack(newSize, head);
  23040. };
  23041. Stack.prototype.pop = function() {
  23042. return this.slice(1);
  23043. };
  23044. Stack.prototype.unshift = function(/*...values*/) {
  23045. return this.push.apply(this, arguments);
  23046. };
  23047. Stack.prototype.unshiftAll = function(iter) {
  23048. return this.pushAll(iter);
  23049. };
  23050. Stack.prototype.shift = function() {
  23051. return this.pop.apply(this, arguments);
  23052. };
  23053. Stack.prototype.clear = function() {
  23054. if (this.size === 0) {
  23055. return this;
  23056. }
  23057. if (this.__ownerID) {
  23058. this.size = 0;
  23059. this._head = undefined;
  23060. this.__hash = undefined;
  23061. this.__altered = true;
  23062. return this;
  23063. }
  23064. return emptyStack();
  23065. };
  23066. Stack.prototype.slice = function(begin, end) {
  23067. if (wholeSlice(begin, end, this.size)) {
  23068. return this;
  23069. }
  23070. var resolvedBegin = resolveBegin(begin, this.size);
  23071. var resolvedEnd = resolveEnd(end, this.size);
  23072. if (resolvedEnd !== this.size) {
  23073. // super.slice(begin, end);
  23074. return IndexedCollection.prototype.slice.call(this, begin, end);
  23075. }
  23076. var newSize = this.size - resolvedBegin;
  23077. var head = this._head;
  23078. while (resolvedBegin--) {
  23079. head = head.next;
  23080. }
  23081. if (this.__ownerID) {
  23082. this.size = newSize;
  23083. this._head = head;
  23084. this.__hash = undefined;
  23085. this.__altered = true;
  23086. return this;
  23087. }
  23088. return makeStack(newSize, head);
  23089. };
  23090. // @pragma Mutability
  23091. Stack.prototype.__ensureOwner = function(ownerID) {
  23092. if (ownerID === this.__ownerID) {
  23093. return this;
  23094. }
  23095. if (!ownerID) {
  23096. this.__ownerID = ownerID;
  23097. this.__altered = false;
  23098. return this;
  23099. }
  23100. return makeStack(this.size, this._head, ownerID, this.__hash);
  23101. };
  23102. // @pragma Iteration
  23103. Stack.prototype.__iterate = function(fn, reverse) {
  23104. if (reverse) {
  23105. return this.reverse().__iterate(fn);
  23106. }
  23107. var iterations = 0;
  23108. var node = this._head;
  23109. while (node) {
  23110. if (fn(node.value, iterations++, this) === false) {
  23111. break;
  23112. }
  23113. node = node.next;
  23114. }
  23115. return iterations;
  23116. };
  23117. Stack.prototype.__iterator = function(type, reverse) {
  23118. if (reverse) {
  23119. return this.reverse().__iterator(type);
  23120. }
  23121. var iterations = 0;
  23122. var node = this._head;
  23123. return new Iterator(function() {
  23124. if (node) {
  23125. var value = node.value;
  23126. node = node.next;
  23127. return iteratorValue(type, iterations++, value);
  23128. }
  23129. return iteratorDone();
  23130. });
  23131. };
  23132. function isStack(maybeStack) {
  23133. return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
  23134. }
  23135. Stack.isStack = isStack;
  23136. var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
  23137. var StackPrototype = Stack.prototype;
  23138. StackPrototype[IS_STACK_SENTINEL] = true;
  23139. StackPrototype.withMutations = MapPrototype.withMutations;
  23140. StackPrototype.asMutable = MapPrototype.asMutable;
  23141. StackPrototype.asImmutable = MapPrototype.asImmutable;
  23142. StackPrototype.wasAltered = MapPrototype.wasAltered;
  23143. function makeStack(size, head, ownerID, hash) {
  23144. var map = Object.create(StackPrototype);
  23145. map.size = size;
  23146. map._head = head;
  23147. map.__ownerID = ownerID;
  23148. map.__hash = hash;
  23149. map.__altered = false;
  23150. return map;
  23151. }
  23152. var EMPTY_STACK;
  23153. function emptyStack() {
  23154. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  23155. }
  23156. /**
  23157. * Contributes additional methods to a constructor
  23158. */
  23159. function mixin(ctor, methods) {
  23160. var keyCopier = function(key ) { ctor.prototype[key] = methods[key]; };
  23161. Object.keys(methods).forEach(keyCopier);
  23162. Object.getOwnPropertySymbols &&
  23163. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  23164. return ctor;
  23165. }
  23166. Iterable.Iterator = Iterator;
  23167. mixin(Iterable, {
  23168. // ### Conversion to other types
  23169. toArray: function() {
  23170. assertNotInfinite(this.size);
  23171. var array = new Array(this.size || 0);
  23172. this.valueSeq().__iterate(function(v, i) { array[i] = v; });
  23173. return array;
  23174. },
  23175. toIndexedSeq: function() {
  23176. return new ToIndexedSequence(this);
  23177. },
  23178. toJS: function() {
  23179. return this.toSeq().map(
  23180. function(value ) {return value && typeof value.toJS === 'function' ? value.toJS() : value}
  23181. ).__toJS();
  23182. },
  23183. toJSON: function() {
  23184. return this.toSeq().map(
  23185. function(value ) {return value && typeof value.toJSON === 'function' ? value.toJSON() : value}
  23186. ).__toJS();
  23187. },
  23188. toKeyedSeq: function() {
  23189. return new ToKeyedSequence(this, true);
  23190. },
  23191. toMap: function() {
  23192. // Use Late Binding here to solve the circular dependency.
  23193. return Map(this.toKeyedSeq());
  23194. },
  23195. toObject: function() {
  23196. assertNotInfinite(this.size);
  23197. var object = {};
  23198. this.__iterate(function(v, k) { object[k] = v; });
  23199. return object;
  23200. },
  23201. toOrderedMap: function() {
  23202. // Use Late Binding here to solve the circular dependency.
  23203. return OrderedMap(this.toKeyedSeq());
  23204. },
  23205. toOrderedSet: function() {
  23206. // Use Late Binding here to solve the circular dependency.
  23207. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  23208. },
  23209. toSet: function() {
  23210. // Use Late Binding here to solve the circular dependency.
  23211. return Set(isKeyed(this) ? this.valueSeq() : this);
  23212. },
  23213. toSetSeq: function() {
  23214. return new ToSetSequence(this);
  23215. },
  23216. toSeq: function() {
  23217. return isIndexed(this) ? this.toIndexedSeq() :
  23218. isKeyed(this) ? this.toKeyedSeq() :
  23219. this.toSetSeq();
  23220. },
  23221. toStack: function() {
  23222. // Use Late Binding here to solve the circular dependency.
  23223. return Stack(isKeyed(this) ? this.valueSeq() : this);
  23224. },
  23225. toList: function() {
  23226. // Use Late Binding here to solve the circular dependency.
  23227. return List(isKeyed(this) ? this.valueSeq() : this);
  23228. },
  23229. // ### Common JavaScript methods and properties
  23230. toString: function() {
  23231. return '[Iterable]';
  23232. },
  23233. __toString: function(head, tail) {
  23234. if (this.size === 0) {
  23235. return head + tail;
  23236. }
  23237. return head + ' ' + this.toSeq().map(this.__toStringMapper).join(', ') + ' ' + tail;
  23238. },
  23239. // ### ES6 Collection methods (ES6 Array and Map)
  23240. concat: function() {var values = SLICE$0.call(arguments, 0);
  23241. return reify(this, concatFactory(this, values));
  23242. },
  23243. includes: function(searchValue) {
  23244. return this.some(function(value ) {return is(value, searchValue)});
  23245. },
  23246. entries: function() {
  23247. return this.__iterator(ITERATE_ENTRIES);
  23248. },
  23249. every: function(predicate, context) {
  23250. assertNotInfinite(this.size);
  23251. var returnValue = true;
  23252. this.__iterate(function(v, k, c) {
  23253. if (!predicate.call(context, v, k, c)) {
  23254. returnValue = false;
  23255. return false;
  23256. }
  23257. });
  23258. return returnValue;
  23259. },
  23260. filter: function(predicate, context) {
  23261. return reify(this, filterFactory(this, predicate, context, true));
  23262. },
  23263. find: function(predicate, context, notSetValue) {
  23264. var entry = this.findEntry(predicate, context);
  23265. return entry ? entry[1] : notSetValue;
  23266. },
  23267. findEntry: function(predicate, context) {
  23268. var found;
  23269. this.__iterate(function(v, k, c) {
  23270. if (predicate.call(context, v, k, c)) {
  23271. found = [k, v];
  23272. return false;
  23273. }
  23274. });
  23275. return found;
  23276. },
  23277. findLastEntry: function(predicate, context) {
  23278. return this.toSeq().reverse().findEntry(predicate, context);
  23279. },
  23280. forEach: function(sideEffect, context) {
  23281. assertNotInfinite(this.size);
  23282. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  23283. },
  23284. join: function(separator) {
  23285. assertNotInfinite(this.size);
  23286. separator = separator !== undefined ? '' + separator : ',';
  23287. var joined = '';
  23288. var isFirst = true;
  23289. this.__iterate(function(v ) {
  23290. isFirst ? (isFirst = false) : (joined += separator);
  23291. joined += v !== null && v !== undefined ? v.toString() : '';
  23292. });
  23293. return joined;
  23294. },
  23295. keys: function() {
  23296. return this.__iterator(ITERATE_KEYS);
  23297. },
  23298. map: function(mapper, context) {
  23299. return reify(this, mapFactory(this, mapper, context));
  23300. },
  23301. reduce: function(reducer, initialReduction, context) {
  23302. assertNotInfinite(this.size);
  23303. var reduction;
  23304. var useFirst;
  23305. if (arguments.length < 2) {
  23306. useFirst = true;
  23307. } else {
  23308. reduction = initialReduction;
  23309. }
  23310. this.__iterate(function(v, k, c) {
  23311. if (useFirst) {
  23312. useFirst = false;
  23313. reduction = v;
  23314. } else {
  23315. reduction = reducer.call(context, reduction, v, k, c);
  23316. }
  23317. });
  23318. return reduction;
  23319. },
  23320. reduceRight: function(reducer, initialReduction, context) {
  23321. var reversed = this.toKeyedSeq().reverse();
  23322. return reversed.reduce.apply(reversed, arguments);
  23323. },
  23324. reverse: function() {
  23325. return reify(this, reverseFactory(this, true));
  23326. },
  23327. slice: function(begin, end) {
  23328. return reify(this, sliceFactory(this, begin, end, true));
  23329. },
  23330. some: function(predicate, context) {
  23331. return !this.every(not(predicate), context);
  23332. },
  23333. sort: function(comparator) {
  23334. return reify(this, sortFactory(this, comparator));
  23335. },
  23336. values: function() {
  23337. return this.__iterator(ITERATE_VALUES);
  23338. },
  23339. // ### More sequential methods
  23340. butLast: function() {
  23341. return this.slice(0, -1);
  23342. },
  23343. isEmpty: function() {
  23344. return this.size !== undefined ? this.size === 0 : !this.some(function() {return true});
  23345. },
  23346. count: function(predicate, context) {
  23347. return ensureSize(
  23348. predicate ? this.toSeq().filter(predicate, context) : this
  23349. );
  23350. },
  23351. countBy: function(grouper, context) {
  23352. return countByFactory(this, grouper, context);
  23353. },
  23354. equals: function(other) {
  23355. return deepEqual(this, other);
  23356. },
  23357. entrySeq: function() {
  23358. var iterable = this;
  23359. if (iterable._cache) {
  23360. // We cache as an entries array, so we can just return the cache!
  23361. return new ArraySeq(iterable._cache);
  23362. }
  23363. var entriesSequence = iterable.toSeq().map(entryMapper).toIndexedSeq();
  23364. entriesSequence.fromEntrySeq = function() {return iterable.toSeq()};
  23365. return entriesSequence;
  23366. },
  23367. filterNot: function(predicate, context) {
  23368. return this.filter(not(predicate), context);
  23369. },
  23370. findLast: function(predicate, context, notSetValue) {
  23371. return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
  23372. },
  23373. first: function() {
  23374. return this.find(returnTrue);
  23375. },
  23376. flatMap: function(mapper, context) {
  23377. return reify(this, flatMapFactory(this, mapper, context));
  23378. },
  23379. flatten: function(depth) {
  23380. return reify(this, flattenFactory(this, depth, true));
  23381. },
  23382. fromEntrySeq: function() {
  23383. return new FromEntriesSequence(this);
  23384. },
  23385. get: function(searchKey, notSetValue) {
  23386. return this.find(function(_, key) {return is(key, searchKey)}, undefined, notSetValue);
  23387. },
  23388. getIn: function(searchKeyPath, notSetValue) {
  23389. var nested = this;
  23390. // Note: in an ES6 environment, we would prefer:
  23391. // for (var key of searchKeyPath) {
  23392. var iter = forceIterator(searchKeyPath);
  23393. var step;
  23394. while (!(step = iter.next()).done) {
  23395. var key = step.value;
  23396. nested = nested && nested.get ? nested.get(key, NOT_SET) : NOT_SET;
  23397. if (nested === NOT_SET) {
  23398. return notSetValue;
  23399. }
  23400. }
  23401. return nested;
  23402. },
  23403. groupBy: function(grouper, context) {
  23404. return groupByFactory(this, grouper, context);
  23405. },
  23406. has: function(searchKey) {
  23407. return this.get(searchKey, NOT_SET) !== NOT_SET;
  23408. },
  23409. hasIn: function(searchKeyPath) {
  23410. return this.getIn(searchKeyPath, NOT_SET) !== NOT_SET;
  23411. },
  23412. isSubset: function(iter) {
  23413. iter = typeof iter.includes === 'function' ? iter : Iterable(iter);
  23414. return this.every(function(value ) {return iter.includes(value)});
  23415. },
  23416. isSuperset: function(iter) {
  23417. iter = typeof iter.isSubset === 'function' ? iter : Iterable(iter);
  23418. return iter.isSubset(this);
  23419. },
  23420. keySeq: function() {
  23421. return this.toSeq().map(keyMapper).toIndexedSeq();
  23422. },
  23423. last: function() {
  23424. return this.toSeq().reverse().first();
  23425. },
  23426. max: function(comparator) {
  23427. return maxFactory(this, comparator);
  23428. },
  23429. maxBy: function(mapper, comparator) {
  23430. return maxFactory(this, comparator, mapper);
  23431. },
  23432. min: function(comparator) {
  23433. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator);
  23434. },
  23435. minBy: function(mapper, comparator) {
  23436. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator, mapper);
  23437. },
  23438. rest: function() {
  23439. return this.slice(1);
  23440. },
  23441. skip: function(amount) {
  23442. return this.slice(Math.max(0, amount));
  23443. },
  23444. skipLast: function(amount) {
  23445. return reify(this, this.toSeq().reverse().skip(amount).reverse());
  23446. },
  23447. skipWhile: function(predicate, context) {
  23448. return reify(this, skipWhileFactory(this, predicate, context, true));
  23449. },
  23450. skipUntil: function(predicate, context) {
  23451. return this.skipWhile(not(predicate), context);
  23452. },
  23453. sortBy: function(mapper, comparator) {
  23454. return reify(this, sortFactory(this, comparator, mapper));
  23455. },
  23456. take: function(amount) {
  23457. return this.slice(0, Math.max(0, amount));
  23458. },
  23459. takeLast: function(amount) {
  23460. return reify(this, this.toSeq().reverse().take(amount).reverse());
  23461. },
  23462. takeWhile: function(predicate, context) {
  23463. return reify(this, takeWhileFactory(this, predicate, context));
  23464. },
  23465. takeUntil: function(predicate, context) {
  23466. return this.takeWhile(not(predicate), context);
  23467. },
  23468. valueSeq: function() {
  23469. return this.toIndexedSeq();
  23470. },
  23471. // ### Hashable Object
  23472. hashCode: function() {
  23473. return this.__hash || (this.__hash = hashIterable(this));
  23474. }
  23475. // ### Internal
  23476. // abstract __iterate(fn, reverse)
  23477. // abstract __iterator(type, reverse)
  23478. });
  23479. // var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  23480. // var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  23481. // var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  23482. // var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  23483. var IterablePrototype = Iterable.prototype;
  23484. IterablePrototype[IS_ITERABLE_SENTINEL] = true;
  23485. IterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.values;
  23486. IterablePrototype.__toJS = IterablePrototype.toArray;
  23487. IterablePrototype.__toStringMapper = quoteString;
  23488. IterablePrototype.inspect =
  23489. IterablePrototype.toSource = function() { return this.toString(); };
  23490. IterablePrototype.chain = IterablePrototype.flatMap;
  23491. IterablePrototype.contains = IterablePrototype.includes;
  23492. // Temporary warning about using length
  23493. (function () {
  23494. try {
  23495. Object.defineProperty(IterablePrototype, 'length', {
  23496. get: function () {
  23497. if (!Iterable.noLengthWarning) {
  23498. var stack;
  23499. try {
  23500. throw new Error();
  23501. } catch (error) {
  23502. stack = error.stack;
  23503. }
  23504. if (stack.indexOf('_wrapObject') === -1) {
  23505. console && console.warn && console.warn(
  23506. 'iterable.length has been deprecated, '+
  23507. 'use iterable.size or iterable.count(). '+
  23508. 'This warning will become a silent error in a future version. ' +
  23509. stack
  23510. );
  23511. return this.size;
  23512. }
  23513. }
  23514. }
  23515. });
  23516. } catch (e) {}
  23517. })();
  23518. mixin(KeyedIterable, {
  23519. // ### More sequential methods
  23520. flip: function() {
  23521. return reify(this, flipFactory(this));
  23522. },
  23523. findKey: function(predicate, context) {
  23524. var entry = this.findEntry(predicate, context);
  23525. return entry && entry[0];
  23526. },
  23527. findLastKey: function(predicate, context) {
  23528. return this.toSeq().reverse().findKey(predicate, context);
  23529. },
  23530. keyOf: function(searchValue) {
  23531. return this.findKey(function(value ) {return is(value, searchValue)});
  23532. },
  23533. lastKeyOf: function(searchValue) {
  23534. return this.findLastKey(function(value ) {return is(value, searchValue)});
  23535. },
  23536. mapEntries: function(mapper, context) {var this$0 = this;
  23537. var iterations = 0;
  23538. return reify(this,
  23539. this.toSeq().map(
  23540. function(v, k) {return mapper.call(context, [k, v], iterations++, this$0)}
  23541. ).fromEntrySeq()
  23542. );
  23543. },
  23544. mapKeys: function(mapper, context) {var this$0 = this;
  23545. return reify(this,
  23546. this.toSeq().flip().map(
  23547. function(k, v) {return mapper.call(context, k, v, this$0)}
  23548. ).flip()
  23549. );
  23550. }
  23551. });
  23552. var KeyedIterablePrototype = KeyedIterable.prototype;
  23553. KeyedIterablePrototype[IS_KEYED_SENTINEL] = true;
  23554. KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries;
  23555. KeyedIterablePrototype.__toJS = IterablePrototype.toObject;
  23556. KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)};
  23557. mixin(IndexedIterable, {
  23558. // ### Conversion to other types
  23559. toKeyedSeq: function() {
  23560. return new ToKeyedSequence(this, false);
  23561. },
  23562. // ### ES6 Collection methods (ES6 Array and Map)
  23563. filter: function(predicate, context) {
  23564. return reify(this, filterFactory(this, predicate, context, false));
  23565. },
  23566. findIndex: function(predicate, context) {
  23567. var entry = this.findEntry(predicate, context);
  23568. return entry ? entry[0] : -1;
  23569. },
  23570. indexOf: function(searchValue) {
  23571. var key = this.toKeyedSeq().keyOf(searchValue);
  23572. return key === undefined ? -1 : key;
  23573. },
  23574. lastIndexOf: function(searchValue) {
  23575. var key = this.toKeyedSeq().reverse().keyOf(searchValue);
  23576. return key === undefined ? -1 : key;
  23577. // var index =
  23578. // return this.toSeq().reverse().indexOf(searchValue);
  23579. },
  23580. reverse: function() {
  23581. return reify(this, reverseFactory(this, false));
  23582. },
  23583. slice: function(begin, end) {
  23584. return reify(this, sliceFactory(this, begin, end, false));
  23585. },
  23586. splice: function(index, removeNum /*, ...values*/) {
  23587. var numArgs = arguments.length;
  23588. removeNum = Math.max(removeNum | 0, 0);
  23589. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  23590. return this;
  23591. }
  23592. // If index is negative, it should resolve relative to the size of the
  23593. // collection. However size may be expensive to compute if not cached, so
  23594. // only call count() if the number is in fact negative.
  23595. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  23596. var spliced = this.slice(0, index);
  23597. return reify(
  23598. this,
  23599. numArgs === 1 ?
  23600. spliced :
  23601. spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  23602. );
  23603. },
  23604. // ### More collection methods
  23605. findLastIndex: function(predicate, context) {
  23606. var key = this.toKeyedSeq().findLastKey(predicate, context);
  23607. return key === undefined ? -1 : key;
  23608. },
  23609. first: function() {
  23610. return this.get(0);
  23611. },
  23612. flatten: function(depth) {
  23613. return reify(this, flattenFactory(this, depth, false));
  23614. },
  23615. get: function(index, notSetValue) {
  23616. index = wrapIndex(this, index);
  23617. return (index < 0 || (this.size === Infinity ||
  23618. (this.size !== undefined && index > this.size))) ?
  23619. notSetValue :
  23620. this.find(function(_, key) {return key === index}, undefined, notSetValue);
  23621. },
  23622. has: function(index) {
  23623. index = wrapIndex(this, index);
  23624. return index >= 0 && (this.size !== undefined ?
  23625. this.size === Infinity || index < this.size :
  23626. this.indexOf(index) !== -1
  23627. );
  23628. },
  23629. interpose: function(separator) {
  23630. return reify(this, interposeFactory(this, separator));
  23631. },
  23632. interleave: function(/*...iterables*/) {
  23633. var iterables = [this].concat(arrCopy(arguments));
  23634. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, iterables);
  23635. var interleaved = zipped.flatten(true);
  23636. if (zipped.size) {
  23637. interleaved.size = zipped.size * iterables.length;
  23638. }
  23639. return reify(this, interleaved);
  23640. },
  23641. last: function() {
  23642. return this.get(-1);
  23643. },
  23644. skipWhile: function(predicate, context) {
  23645. return reify(this, skipWhileFactory(this, predicate, context, false));
  23646. },
  23647. zip: function(/*, ...iterables */) {
  23648. var iterables = [this].concat(arrCopy(arguments));
  23649. return reify(this, zipWithFactory(this, defaultZipper, iterables));
  23650. },
  23651. zipWith: function(zipper/*, ...iterables */) {
  23652. var iterables = arrCopy(arguments);
  23653. iterables[0] = this;
  23654. return reify(this, zipWithFactory(this, zipper, iterables));
  23655. }
  23656. });
  23657. IndexedIterable.prototype[IS_INDEXED_SENTINEL] = true;
  23658. IndexedIterable.prototype[IS_ORDERED_SENTINEL] = true;
  23659. mixin(SetIterable, {
  23660. // ### ES6 Collection methods (ES6 Array and Map)
  23661. get: function(value, notSetValue) {
  23662. return this.has(value) ? value : notSetValue;
  23663. },
  23664. includes: function(value) {
  23665. return this.has(value);
  23666. },
  23667. // ### More sequential methods
  23668. keySeq: function() {
  23669. return this.valueSeq();
  23670. }
  23671. });
  23672. SetIterable.prototype.has = IterablePrototype.includes;
  23673. // Mixin subclasses
  23674. mixin(KeyedSeq, KeyedIterable.prototype);
  23675. mixin(IndexedSeq, IndexedIterable.prototype);
  23676. mixin(SetSeq, SetIterable.prototype);
  23677. mixin(KeyedCollection, KeyedIterable.prototype);
  23678. mixin(IndexedCollection, IndexedIterable.prototype);
  23679. mixin(SetCollection, SetIterable.prototype);
  23680. // #pragma Helper functions
  23681. function keyMapper(v, k) {
  23682. return k;
  23683. }
  23684. function entryMapper(v, k) {
  23685. return [k, v];
  23686. }
  23687. function not(predicate) {
  23688. return function() {
  23689. return !predicate.apply(this, arguments);
  23690. }
  23691. }
  23692. function neg(predicate) {
  23693. return function() {
  23694. return -predicate.apply(this, arguments);
  23695. }
  23696. }
  23697. function quoteString(value) {
  23698. return typeof value === 'string' ? JSON.stringify(value) : value;
  23699. }
  23700. function defaultZipper() {
  23701. return arrCopy(arguments);
  23702. }
  23703. function defaultNegComparator(a, b) {
  23704. return a < b ? 1 : a > b ? -1 : 0;
  23705. }
  23706. function hashIterable(iterable) {
  23707. if (iterable.size === Infinity) {
  23708. return 0;
  23709. }
  23710. var ordered = isOrdered(iterable);
  23711. var keyed = isKeyed(iterable);
  23712. var h = ordered ? 1 : 0;
  23713. var size = iterable.__iterate(
  23714. keyed ?
  23715. ordered ?
  23716. function(v, k) { h = 31 * h + hashMerge(hash(v), hash(k)) | 0; } :
  23717. function(v, k) { h = h + hashMerge(hash(v), hash(k)) | 0; } :
  23718. ordered ?
  23719. function(v ) { h = 31 * h + hash(v) | 0; } :
  23720. function(v ) { h = h + hash(v) | 0; }
  23721. );
  23722. return murmurHashOfSize(size, h);
  23723. }
  23724. function murmurHashOfSize(size, h) {
  23725. h = imul(h, 0xCC9E2D51);
  23726. h = imul(h << 15 | h >>> -15, 0x1B873593);
  23727. h = imul(h << 13 | h >>> -13, 5);
  23728. h = (h + 0xE6546B64 | 0) ^ size;
  23729. h = imul(h ^ h >>> 16, 0x85EBCA6B);
  23730. h = imul(h ^ h >>> 13, 0xC2B2AE35);
  23731. h = smi(h ^ h >>> 16);
  23732. return h;
  23733. }
  23734. function hashMerge(a, b) {
  23735. return a ^ b + 0x9E3779B9 + (a << 6) + (a >> 2) | 0; // int
  23736. }
  23737. var Immutable = {
  23738. Iterable: Iterable,
  23739. Seq: Seq,
  23740. Collection: Collection,
  23741. Map: Map,
  23742. OrderedMap: OrderedMap,
  23743. List: List,
  23744. Stack: Stack,
  23745. Set: Set,
  23746. OrderedSet: OrderedSet,
  23747. Record: Record,
  23748. Range: Range,
  23749. Repeat: Repeat,
  23750. is: is,
  23751. fromJS: fromJS
  23752. };
  23753. return Immutable;
  23754. }));
  23755. });
  23756. var parseHTML_1 = createCommonjsModule(function (module, exports) {
  23757. Object.defineProperty(exports, "__esModule", {
  23758. value: true
  23759. });
  23760. exports["default"] = parseHTML;
  23761. var fallback = function fallback(html) {
  23762. var doc = document.implementation.createHTMLDocument('');
  23763. doc.documentElement.innerHTML = html;
  23764. return doc;
  23765. };
  23766. function parseHTML(html) {
  23767. var doc;
  23768. if (typeof DOMParser !== 'undefined') {
  23769. var parser = new DOMParser();
  23770. doc = parser.parseFromString(html, 'text/html');
  23771. if (doc === null || doc.body === null) {
  23772. doc = fallback(html);
  23773. }
  23774. } else {
  23775. doc = fallback(html);
  23776. }
  23777. return doc.body;
  23778. }
  23779. });
  23780. unwrapExports(parseHTML_1);
  23781. var convertFromHTML_1 = createCommonjsModule(function (module, exports) {
  23782. Object.defineProperty(exports, "__esModule", {
  23783. value: true
  23784. });
  23785. exports["default"] = void 0;
  23786. var _parseHTML = interopRequireDefault(parseHTML_1);
  23787. var _rangeSort = interopRequireDefault(rangeSort);
  23788. /**
  23789. * Copyright (c) 2013-present, Facebook, Inc.
  23790. * All rights reserved.
  23791. *
  23792. * Copyright (c) 2013-present, Facebook, Inc.
  23793. * All rights reserved.
  23794. *
  23795. * This source code is licensed under the BSD-style license found in the
  23796. * LICENSE file in the /src directory of this source tree. An additional grant
  23797. * of patent rights can be found in the PATENTS file in the same directory.
  23798. */
  23799. var NBSP = '&nbsp;';
  23800. var SPACE = ' '; // Arbitrary max indent
  23801. var MAX_DEPTH = 4; // used for replacing characters in HTML
  23802. /* eslint-disable no-control-regex */
  23803. var REGEX_CR = new RegExp('\r', 'g');
  23804. var REGEX_LF = new RegExp('\n', 'g');
  23805. var REGEX_NBSP = new RegExp(NBSP, 'g');
  23806. var REGEX_BLOCK_DELIMITER = new RegExp('\r', 'g');
  23807. /* eslint-enable no-control-regex */
  23808. // Block tag flow is different because LIs do not have
  23809. // a deterministic style ;_;
  23810. var blockTags = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'li', 'blockquote', 'pre'];
  23811. var inlineTags = {
  23812. b: 'BOLD',
  23813. code: 'CODE',
  23814. del: 'STRIKETHROUGH',
  23815. em: 'ITALIC',
  23816. i: 'ITALIC',
  23817. s: 'STRIKETHROUGH',
  23818. strike: 'STRIKETHROUGH',
  23819. strong: 'BOLD',
  23820. u: 'UNDERLINE'
  23821. };
  23822. var handleMiddleware = function handleMiddleware(maybeMiddleware, base) {
  23823. if (maybeMiddleware && maybeMiddleware.__isMiddleware === true) {
  23824. return maybeMiddleware(base);
  23825. }
  23826. return maybeMiddleware;
  23827. };
  23828. var defaultHTMLToBlock = function defaultHTMLToBlock(nodeName, node, lastList) {
  23829. return undefined;
  23830. };
  23831. var defaultHTMLToStyle = function defaultHTMLToStyle(nodeName, node, currentStyle) {
  23832. return currentStyle;
  23833. };
  23834. var defaultHTMLToEntity = function defaultHTMLToEntity(nodeName, node) {
  23835. return undefined;
  23836. };
  23837. var defaultTextToEntity = function defaultTextToEntity(text) {
  23838. return [];
  23839. };
  23840. var nullthrows = function nullthrows(x) {
  23841. if (x != null) {
  23842. return x;
  23843. }
  23844. throw new Error('Got unexpected null or undefined');
  23845. };
  23846. var sanitizeDraftText = function sanitizeDraftText(input) {
  23847. return input.replace(REGEX_BLOCK_DELIMITER, '');
  23848. };
  23849. function getEmptyChunk() {
  23850. return {
  23851. text: '',
  23852. inlines: [],
  23853. entities: [],
  23854. blocks: []
  23855. };
  23856. }
  23857. function getWhitespaceChunk(inEntity) {
  23858. var entities = new Array(1);
  23859. if (inEntity) {
  23860. entities[0] = inEntity;
  23861. }
  23862. return {
  23863. text: SPACE,
  23864. inlines: [(0, immutable$2.OrderedSet)()],
  23865. entities: entities,
  23866. blocks: []
  23867. };
  23868. }
  23869. function getSoftNewlineChunk(block, depth) {
  23870. var flat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  23871. var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : (0, immutable$2.Map)();
  23872. if (flat === true) {
  23873. return {
  23874. text: '\r',
  23875. inlines: [(0, immutable$2.OrderedSet)()],
  23876. entities: new Array(1),
  23877. blocks: [{
  23878. type: block,
  23879. data: data,
  23880. depth: Math.max(0, Math.min(MAX_DEPTH, depth))
  23881. }],
  23882. isNewline: true
  23883. };
  23884. }
  23885. return {
  23886. text: '\n',
  23887. inlines: [(0, immutable$2.OrderedSet)()],
  23888. entities: new Array(1),
  23889. blocks: []
  23890. };
  23891. }
  23892. function getBlockDividerChunk(block, depth) {
  23893. var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : (0, immutable$2.Map)();
  23894. return {
  23895. text: '\r',
  23896. inlines: [(0, immutable$2.OrderedSet)()],
  23897. entities: new Array(1),
  23898. blocks: [{
  23899. type: block,
  23900. data: data,
  23901. depth: Math.max(0, Math.min(MAX_DEPTH, depth))
  23902. }]
  23903. };
  23904. }
  23905. function getBlockTypeForTag(tag, lastList) {
  23906. switch (tag) {
  23907. case 'h1':
  23908. return 'header-one';
  23909. case 'h2':
  23910. return 'header-two';
  23911. case 'h3':
  23912. return 'header-three';
  23913. case 'h4':
  23914. return 'header-four';
  23915. case 'h5':
  23916. return 'header-five';
  23917. case 'h6':
  23918. return 'header-six';
  23919. case 'li':
  23920. if (lastList === 'ol') {
  23921. return 'ordered-list-item';
  23922. }
  23923. return 'unordered-list-item';
  23924. case 'blockquote':
  23925. return 'blockquote';
  23926. case 'pre':
  23927. return 'code-block';
  23928. case 'div':
  23929. case 'p':
  23930. return 'unstyled';
  23931. default:
  23932. return null;
  23933. }
  23934. }
  23935. function baseCheckBlockType(nodeName, node, lastList) {
  23936. return getBlockTypeForTag(nodeName, lastList);
  23937. }
  23938. function processInlineTag(tag, node, currentStyle) {
  23939. var styleToCheck = inlineTags[tag];
  23940. if (styleToCheck) {
  23941. currentStyle = currentStyle.add(styleToCheck).toOrderedSet();
  23942. } else if (node instanceof HTMLElement) {
  23943. var htmlElement = node;
  23944. currentStyle = currentStyle.withMutations(function (style) {
  23945. if (htmlElement.style.fontWeight === 'bold') {
  23946. style.add('BOLD');
  23947. }
  23948. if (htmlElement.style.fontStyle === 'italic') {
  23949. style.add('ITALIC');
  23950. }
  23951. if (htmlElement.style.textDecoration === 'underline') {
  23952. style.add('UNDERLINE');
  23953. }
  23954. if (htmlElement.style.textDecoration === 'line-through') {
  23955. style.add('STRIKETHROUGH');
  23956. }
  23957. }).toOrderedSet();
  23958. }
  23959. return currentStyle;
  23960. }
  23961. function baseProcessInlineTag(tag, node) {
  23962. var inlineStyles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : (0, immutable$2.OrderedSet)();
  23963. return processInlineTag(tag, node, inlineStyles);
  23964. }
  23965. function joinChunks(A, B) {
  23966. var flat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  23967. // Sometimes two blocks will touch in the DOM and we need to strip the
  23968. // extra delimiter to preserve niceness.
  23969. var firstInB = B.text.slice(0, 1);
  23970. var lastInA = A.text.slice(-1);
  23971. var adjacentDividers = lastInA === '\r' && firstInB === '\r';
  23972. var isJoiningBlocks = A.text !== '\r' && B.text !== '\r'; // when joining two full blocks like this we want to pop one divider
  23973. var addingNewlineToEmptyBlock = A.text === '\r' && !A.isNewline && B.isNewline; // when joining a newline to an empty block we want to remove the newline
  23974. if (adjacentDividers && (isJoiningBlocks || addingNewlineToEmptyBlock)) {
  23975. A.text = A.text.slice(0, -1);
  23976. A.inlines.pop();
  23977. A.entities.pop();
  23978. A.blocks.pop();
  23979. } // Kill whitespace after blocks if flat mode is on
  23980. if (A.text.slice(-1) === '\r' && flat === true) {
  23981. if (B.text === SPACE || B.text === '\n') {
  23982. return A;
  23983. } else if (firstInB === SPACE || firstInB === '\n') {
  23984. B.text = B.text.slice(1);
  23985. B.inlines.shift();
  23986. B.entities.shift();
  23987. }
  23988. }
  23989. var isNewline = A.text.length === 0 && B.isNewline;
  23990. return {
  23991. text: A.text + B.text,
  23992. inlines: A.inlines.concat(B.inlines),
  23993. entities: A.entities.concat(B.entities),
  23994. blocks: A.blocks.concat(B.blocks),
  23995. isNewline: isNewline
  23996. };
  23997. }
  23998. /*
  23999. * Check to see if we have anything like <p> <blockquote> <h1>... to create
  24000. * block tags from. If we do, we can use those and ignore <div> tags. If we
  24001. * don't, we can treat <div> tags as meaningful (unstyled) blocks.
  24002. */
  24003. function containsSemanticBlockMarkup(html) {
  24004. return blockTags.some(function (tag) {
  24005. return html.indexOf("<".concat(tag)) !== -1;
  24006. });
  24007. }
  24008. function genFragment(node, inlineStyle, lastList, inBlock, fragmentBlockTags, depth, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, inEntity) {
  24009. var nodeName = node.nodeName.toLowerCase();
  24010. var newBlock = false;
  24011. var nextBlockType = 'unstyled'; // Base Case
  24012. if (nodeName === '#text') {
  24013. var text = node.textContent;
  24014. if (text.trim() === '' && inBlock === null) {
  24015. return getEmptyChunk();
  24016. }
  24017. if (text.trim() === '' && inBlock !== 'code-block') {
  24018. return getWhitespaceChunk(inEntity);
  24019. }
  24020. if (inBlock !== 'code-block') {
  24021. // Can't use empty string because MSWord
  24022. text = text.replace(REGEX_LF, SPACE);
  24023. }
  24024. var entities = Array(text.length).fill(inEntity);
  24025. var offsetChange = 0;
  24026. var textEntities = checkEntityText(text, createEntity, getEntity, mergeEntityData, replaceEntityData).sort(_rangeSort["default"]);
  24027. textEntities.forEach(function (_ref) {
  24028. var entity = _ref.entity,
  24029. offset = _ref.offset,
  24030. length = _ref.length,
  24031. result = _ref.result;
  24032. var adjustedOffset = offset + offsetChange;
  24033. if (result === null || result === undefined) {
  24034. result = text.substr(adjustedOffset, length);
  24035. }
  24036. var textArray = text.split('');
  24037. textArray.splice.bind(textArray, adjustedOffset, length).apply(textArray, result.split(''));
  24038. text = textArray.join('');
  24039. entities.splice.bind(entities, adjustedOffset, length).apply(entities, Array(result.length).fill(entity));
  24040. offsetChange += result.length - length;
  24041. });
  24042. return {
  24043. text: text,
  24044. inlines: Array(text.length).fill(inlineStyle),
  24045. entities: entities,
  24046. blocks: []
  24047. };
  24048. } // BR tags
  24049. if (nodeName === 'br') {
  24050. var _blockType = inBlock;
  24051. if (_blockType === null) {
  24052. // BR tag is at top level, treat it as an unstyled block
  24053. return getSoftNewlineChunk('unstyled', depth, true);
  24054. }
  24055. return getSoftNewlineChunk(_blockType || 'unstyled', depth, options.flat);
  24056. }
  24057. var chunk = getEmptyChunk();
  24058. var newChunk = null; // Inline tags
  24059. inlineStyle = processInlineTag(nodeName, node, inlineStyle);
  24060. inlineStyle = processCustomInlineStyles(nodeName, node, inlineStyle); // Handle lists
  24061. if (nodeName === 'ul' || nodeName === 'ol') {
  24062. if (lastList) {
  24063. depth += 1;
  24064. }
  24065. lastList = nodeName;
  24066. inBlock = null;
  24067. } // Block Tags
  24068. var blockInfo = checkBlockType(nodeName, node, lastList, inBlock);
  24069. var blockType;
  24070. var blockDataMap;
  24071. if (blockInfo === false) {
  24072. return getEmptyChunk();
  24073. }
  24074. blockInfo = blockInfo || {};
  24075. if (typeof blockInfo === 'string') {
  24076. blockType = blockInfo;
  24077. blockDataMap = (0, immutable$2.Map)();
  24078. } else {
  24079. blockType = typeof blockInfo === 'string' ? blockInfo : blockInfo.type;
  24080. blockDataMap = blockInfo.data ? (0, immutable$2.Map)(blockInfo.data) : (0, immutable$2.Map)();
  24081. }
  24082. if (!inBlock && (fragmentBlockTags.indexOf(nodeName) !== -1 || blockType)) {
  24083. chunk = getBlockDividerChunk(blockType || getBlockTypeForTag(nodeName, lastList), depth, blockDataMap);
  24084. inBlock = blockType || getBlockTypeForTag(nodeName, lastList);
  24085. newBlock = true;
  24086. } else if (lastList && (inBlock === 'ordered-list-item' || inBlock === 'unordered-list-item') && nodeName === 'li') {
  24087. var listItemBlockType = getBlockTypeForTag(nodeName, lastList);
  24088. chunk = getBlockDividerChunk(listItemBlockType, depth);
  24089. inBlock = listItemBlockType;
  24090. newBlock = true;
  24091. nextBlockType = lastList === 'ul' ? 'unordered-list-item' : 'ordered-list-item';
  24092. } else if (inBlock && inBlock !== 'atomic' && blockType === 'atomic') {
  24093. inBlock = blockType;
  24094. newBlock = true;
  24095. chunk = getSoftNewlineChunk(blockType, depth, true, // atomic blocks within non-atomic blocks must always be split out
  24096. blockDataMap);
  24097. } // Recurse through children
  24098. var child = node.firstChild; // hack to allow conversion of atomic blocks from HTML (e.g. <figure><img
  24099. // src="..." /></figure>). since metadata must be stored on an entity text
  24100. // must exist for the entity to apply to. the way chunks are joined strips
  24101. // whitespace at the end so it cannot be a space character.
  24102. if (child == null && inEntity && (blockType === 'atomic' || inBlock === 'atomic')) {
  24103. child = document.createTextNode('a');
  24104. }
  24105. if (child != null) {
  24106. nodeName = child.nodeName.toLowerCase();
  24107. }
  24108. var entityId = null;
  24109. while (child) {
  24110. entityId = checkEntityNode(nodeName, child, createEntity, getEntity, mergeEntityData, replaceEntityData);
  24111. newChunk = genFragment(child, inlineStyle, lastList, inBlock, fragmentBlockTags, depth, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, entityId || inEntity);
  24112. chunk = joinChunks(chunk, newChunk, options.flat);
  24113. var sibling = child.nextSibling; // Put in a newline to break up blocks inside blocks
  24114. if (sibling && fragmentBlockTags.indexOf(nodeName) >= 0 && inBlock) {
  24115. var newBlockInfo = checkBlockType(nodeName, child, lastList, inBlock);
  24116. var newBlockType = void 0;
  24117. var newBlockData = void 0;
  24118. if (newBlockInfo !== false) {
  24119. newBlockInfo = newBlockInfo || {};
  24120. if (typeof newBlockInfo === 'string') {
  24121. newBlockType = newBlockInfo;
  24122. newBlockData = (0, immutable$2.Map)();
  24123. } else {
  24124. newBlockType = newBlockInfo.type || getBlockTypeForTag(nodeName, lastList);
  24125. newBlockData = newBlockInfo.data ? (0, immutable$2.Map)(newBlockInfo.data) : (0, immutable$2.Map)();
  24126. }
  24127. chunk = joinChunks(chunk, getSoftNewlineChunk(newBlockType, depth, options.flat, newBlockData), options.flat);
  24128. }
  24129. }
  24130. if (sibling) {
  24131. nodeName = sibling.nodeName.toLowerCase();
  24132. }
  24133. child = sibling;
  24134. }
  24135. if (newBlock) {
  24136. chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, (0, immutable$2.Map)()), options.flat);
  24137. }
  24138. return chunk;
  24139. }
  24140. function getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, DOMBuilder) {
  24141. html = html.trim().replace(REGEX_CR, '').replace(REGEX_NBSP, SPACE);
  24142. var safeBody = DOMBuilder(html);
  24143. if (!safeBody) {
  24144. return null;
  24145. } // Sometimes we aren't dealing with content that contains nice semantic
  24146. // tags. In this case, use divs to separate everything out into paragraphs
  24147. // and hope for the best.
  24148. var workingBlocks = containsSemanticBlockMarkup(html) ? blockTags.concat(['div']) : ['div']; // Start with -1 block depth to offset the fact that we are passing in a fake
  24149. // UL block to sta rt with.
  24150. 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
  24151. if (chunk.text.indexOf('\r') === 0) {
  24152. chunk = {
  24153. text: chunk.text.slice(1),
  24154. inlines: chunk.inlines.slice(1),
  24155. entities: chunk.entities.slice(1),
  24156. blocks: chunk.blocks
  24157. };
  24158. } // Kill block delimiter at the end
  24159. if (chunk.text.slice(-1) === '\r') {
  24160. chunk.text = chunk.text.slice(0, -1);
  24161. chunk.inlines = chunk.inlines.slice(0, -1);
  24162. chunk.entities = chunk.entities.slice(0, -1);
  24163. chunk.blocks.pop();
  24164. } // If we saw no block tags, put an unstyled one in
  24165. if (chunk.blocks.length === 0) {
  24166. chunk.blocks.push({
  24167. type: 'unstyled',
  24168. data: (0, immutable$2.Map)(),
  24169. depth: 0
  24170. });
  24171. } // Sometimes we start with text that isn't in a block, which is then
  24172. // followed by blocks. Need to fix up the blocks to add in
  24173. // an unstyled block for this content
  24174. if (chunk.text.split('\r').length === chunk.blocks.length + 1) {
  24175. chunk.blocks.unshift({
  24176. type: 'unstyled',
  24177. data: (0, immutable$2.Map)(),
  24178. depth: 0
  24179. });
  24180. }
  24181. return chunk;
  24182. }
  24183. function convertFromHTMLtoContentBlocks(html, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, DOMBuilder, generateKey) {
  24184. // Be ABSOLUTELY SURE that the dom builder you pass hare won't execute
  24185. // arbitrary code in whatever environment you're running this in. For an
  24186. // example of how we try to do this in-browser, see getSafeBodyFromHTML.
  24187. var chunk = getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, DOMBuilder);
  24188. if (chunk == null) {
  24189. return [];
  24190. }
  24191. var start = 0;
  24192. return chunk.text.split('\r').map(function (textBlock, blockIndex) {
  24193. // Make absolutely certain that our text is acceptable.
  24194. textBlock = sanitizeDraftText(textBlock);
  24195. var end = start + textBlock.length;
  24196. var inlines = nullthrows(chunk).inlines.slice(start, end);
  24197. var entities = nullthrows(chunk).entities.slice(start, end);
  24198. var characterList = (0, immutable$2.List)(inlines.map(function (style, entityIndex) {
  24199. var data = {
  24200. style: style,
  24201. entity: null
  24202. };
  24203. if (entities[entityIndex]) {
  24204. data.entity = entities[entityIndex];
  24205. }
  24206. return Draft.CharacterMetadata.create(data);
  24207. }));
  24208. start = end + 1;
  24209. return new Draft.ContentBlock({
  24210. key: generateKey(),
  24211. type: nullthrows(chunk).blocks[blockIndex].type,
  24212. data: nullthrows(chunk).blocks[blockIndex].data,
  24213. depth: nullthrows(chunk).blocks[blockIndex].depth,
  24214. text: textBlock,
  24215. characterList: characterList
  24216. });
  24217. });
  24218. }
  24219. var convertFromHTML = function convertFromHTML(_ref2) {
  24220. var _ref2$htmlToStyle = _ref2.htmlToStyle,
  24221. htmlToStyle = _ref2$htmlToStyle === void 0 ? defaultHTMLToStyle : _ref2$htmlToStyle,
  24222. _ref2$htmlToEntity = _ref2.htmlToEntity,
  24223. htmlToEntity = _ref2$htmlToEntity === void 0 ? defaultHTMLToEntity : _ref2$htmlToEntity,
  24224. _ref2$textToEntity = _ref2.textToEntity,
  24225. textToEntity = _ref2$textToEntity === void 0 ? defaultTextToEntity : _ref2$textToEntity,
  24226. _ref2$htmlToBlock = _ref2.htmlToBlock,
  24227. htmlToBlock = _ref2$htmlToBlock === void 0 ? defaultHTMLToBlock : _ref2$htmlToBlock;
  24228. return function (html) {
  24229. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  24230. flat: false
  24231. };
  24232. var DOMBuilder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _parseHTML["default"];
  24233. var generateKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : Draft.genKey;
  24234. var contentState = Draft.ContentState.createFromText('');
  24235. var createEntityWithContentState = function createEntityWithContentState() {
  24236. if (contentState.createEntity) {
  24237. var _contentState;
  24238. contentState = (_contentState = contentState).createEntity.apply(_contentState, arguments);
  24239. return contentState.getLastCreatedEntityKey();
  24240. }
  24241. return Draft.Entity.create.apply(Draft.Entity, arguments);
  24242. };
  24243. var getEntityWithContentState = function getEntityWithContentState() {
  24244. if (contentState.getEntity) {
  24245. var _contentState2;
  24246. return (_contentState2 = contentState).getEntity.apply(_contentState2, arguments);
  24247. }
  24248. return Draft.Entity.get.apply(Draft.Entity, arguments);
  24249. };
  24250. var mergeEntityDataWithContentState = function mergeEntityDataWithContentState() {
  24251. if (contentState.mergeEntityData) {
  24252. var _contentState3;
  24253. contentState = (_contentState3 = contentState).mergeEntityData.apply(_contentState3, arguments);
  24254. return;
  24255. }
  24256. Draft.Entity.mergeData.apply(Draft.Entity, arguments);
  24257. };
  24258. var replaceEntityDataWithContentState = function replaceEntityDataWithContentState() {
  24259. if (contentState.replaceEntityData) {
  24260. var _contentState4;
  24261. contentState = (_contentState4 = contentState).replaceEntityData.apply(_contentState4, arguments);
  24262. return;
  24263. }
  24264. Draft.Entity.replaceData.apply(Draft.Entity, arguments);
  24265. };
  24266. var contentBlocks = convertFromHTMLtoContentBlocks(html, handleMiddleware(htmlToStyle, baseProcessInlineTag), handleMiddleware(htmlToEntity, defaultHTMLToEntity), handleMiddleware(textToEntity, defaultTextToEntity), handleMiddleware(htmlToBlock, baseCheckBlockType), createEntityWithContentState, getEntityWithContentState, mergeEntityDataWithContentState, replaceEntityDataWithContentState, options, DOMBuilder, generateKey);
  24267. var blockMap = Draft.BlockMapBuilder.createFromArray(contentBlocks);
  24268. var firstBlockKey = contentBlocks[0].getKey();
  24269. return contentState.merge({
  24270. blockMap: blockMap,
  24271. selectionBefore: Draft.SelectionState.createEmpty(firstBlockKey),
  24272. selectionAfter: Draft.SelectionState.createEmpty(firstBlockKey)
  24273. });
  24274. };
  24275. };
  24276. var _default = function _default() {
  24277. if (arguments.length >= 1 && typeof (arguments.length <= 0 ? undefined : arguments[0]) === 'string') {
  24278. return convertFromHTML({}).apply(void 0, arguments);
  24279. }
  24280. return convertFromHTML.apply(void 0, arguments);
  24281. };
  24282. exports["default"] = _default;
  24283. });
  24284. unwrapExports(convertFromHTML_1);
  24285. var lib = createCommonjsModule(function (module, exports) {
  24286. Object.defineProperty(exports, "__esModule", {
  24287. value: true
  24288. });
  24289. Object.defineProperty(exports, "convertToHTML", {
  24290. enumerable: true,
  24291. get: function get() {
  24292. return _convertToHTML["default"];
  24293. }
  24294. });
  24295. Object.defineProperty(exports, "convertFromHTML", {
  24296. enumerable: true,
  24297. get: function get() {
  24298. return _convertFromHTML["default"];
  24299. }
  24300. });
  24301. Object.defineProperty(exports, "parseHTML", {
  24302. enumerable: true,
  24303. get: function get() {
  24304. return _parseHTML["default"];
  24305. }
  24306. });
  24307. var _convertToHTML = interopRequireDefault(convertToHTML_1);
  24308. var _convertFromHTML = interopRequireDefault(convertFromHTML_1);
  24309. var _parseHTML = interopRequireDefault(parseHTML_1);
  24310. });
  24311. unwrapExports(lib);
  24312. var configs = createCommonjsModule(function (module, exports) {
  24313. Object.defineProperty(exports, "__esModule", {
  24314. value: true
  24315. });
  24316. exports.getFromHTMLConfig = exports.getToHTMLConfig = exports.blocks = exports.getHexColor = exports.defaultFontFamilies = exports.namedColors = undefined;
  24317. 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; };
  24318. var _react2 = _interopRequireDefault(React);
  24319. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  24320. 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; }
  24321. var namedColors = exports.namedColors = {
  24322. "aliceblue": "#f0f8ff",
  24323. "antiquewhite": "#faebd7",
  24324. "aqua": "#00ffff",
  24325. "aquamarine": "#7fffd4",
  24326. "azure": "#f0ffff",
  24327. "beige": "#f5f5dc",
  24328. "bisque": "#ffe4c4",
  24329. "black": "#000000",
  24330. "blanchedalmond": "#ffebcd",
  24331. "blue": "#0000ff",
  24332. "blueviolet": "#8a2be2",
  24333. "brown": "#a52a2a",
  24334. "burlywood": "#deb887",
  24335. "cadetblue": "#5f9ea0",
  24336. "chartreuse": "#7fff00",
  24337. "chocolate": "#d2691e",
  24338. "coral": "#ff7f50",
  24339. "cornflowerblue": "#6495ed",
  24340. "cornsilk": "#fff8dc",
  24341. "crimson": "#dc143c",
  24342. "cyan": "#00ffff",
  24343. "darkblue": "#00008b",
  24344. "darkcyan": "#008b8b",
  24345. "darkgoldenrod": "#b8860b",
  24346. "darkgray": "#a9a9a9",
  24347. "darkgreen": "#006400",
  24348. "darkkhaki": "#bdb76b",
  24349. "darkmagenta": "#8b008b",
  24350. "darkolivegreen": "#556b2f",
  24351. "darkorange": "#ff8c00",
  24352. "darkorchid": "#9932cc",
  24353. "darkred": "#8b0000",
  24354. "darksalmon": "#e9967a",
  24355. "darkseagreen": "#8fbc8f",
  24356. "darkslateblue": "#483d8b",
  24357. "darkslategray": "#2f4f4f",
  24358. "darkturquoise": "#00ced1",
  24359. "darkviolet": "#9400d3",
  24360. "deeppink": "#ff1493",
  24361. "deepskyblue": "#00bfff",
  24362. "dimgray": "#696969",
  24363. "dodgerblue": "#1e90ff",
  24364. "firebrick": "#b22222",
  24365. "floralwhite": "#fffaf0",
  24366. "forestgreen": "#228b22",
  24367. "fuchsia": "#ff00ff",
  24368. "gainsboro": "#dcdcdc",
  24369. "ghostwhite": "#f8f8ff",
  24370. "gold": "#ffd700",
  24371. "goldenrod": "#daa520",
  24372. "gray": "#808080",
  24373. "green": "#008000",
  24374. "greenyellow": "#adff2f",
  24375. "honeydew": "#f0fff0",
  24376. "hotpink": "#ff69b4",
  24377. "indianred ": "#cd5c5c",
  24378. "indigo": "#4b0082",
  24379. "ivory": "#fffff0",
  24380. "khaki": "#f0e68c",
  24381. "lavender": "#e6e6fa",
  24382. "lavenderblush": "#fff0f5",
  24383. "lawngreen": "#7cfc00",
  24384. "lemonchiffon": "#fffacd",
  24385. "lightblue": "#add8e6",
  24386. "lightcoral": "#f08080",
  24387. "lightcyan": "#e0ffff",
  24388. "lightgoldenrodyellow": "#fafad2",
  24389. "lightgrey": "#d3d3d3",
  24390. "lightgreen": "#90ee90",
  24391. "lightpink": "#ffb6c1",
  24392. "lightsalmon": "#ffa07a",
  24393. "lightseagreen": "#20b2aa",
  24394. "lightskyblue": "#87cefa",
  24395. "lightslategray": "#778899",
  24396. "lightsteelblue": "#b0c4de",
  24397. "lightyellow": "#ffffe0",
  24398. "lime": "#00ff00",
  24399. "limegreen": "#32cd32",
  24400. "linen": "#faf0e6",
  24401. "magenta": "#ff00ff",
  24402. "maroon": "#800000",
  24403. "mediumaquamarine": "#66cdaa",
  24404. "mediumblue": "#0000cd",
  24405. "mediumorchid": "#ba55d3",
  24406. "mediumpurple": "#9370d8",
  24407. "mediumseagreen": "#3cb371",
  24408. "mediumslateblue": "#7b68ee",
  24409. "mediumspringgreen": "#00fa9a",
  24410. "mediumturquoise": "#48d1cc",
  24411. "mediumvioletred": "#c71585",
  24412. "midnightblue": "#191970",
  24413. "mintcream": "#f5fffa",
  24414. "mistyrose": "#ffe4e1",
  24415. "moccasin": "#ffe4b5",
  24416. "navajowhite": "#ffdead",
  24417. "navy": "#000080",
  24418. "oldlace": "#fdf5e6",
  24419. "olive": "#808000",
  24420. "olivedrab": "#6b8e23",
  24421. "orange": "#ffa500",
  24422. "orangered": "#ff4500",
  24423. "orchid": "#da70d6",
  24424. "palegoldenrod": "#eee8aa",
  24425. "palegreen": "#98fb98",
  24426. "paleturquoise": "#afeeee",
  24427. "palevioletred": "#d87093",
  24428. "papayawhip": "#ffefd5",
  24429. "peachpuff": "#ffdab9",
  24430. "peru": "#cd853f",
  24431. "pink": "#ffc0cb",
  24432. "plum": "#dda0dd",
  24433. "powderblue": "#b0e0e6",
  24434. "purple": "#800080",
  24435. "rebeccapurple": "#663399",
  24436. "red": "#ff0000",
  24437. "rosybrown": "#bc8f8f",
  24438. "royalblue": "#4169e1",
  24439. "saddlebrown": "#8b4513",
  24440. "salmon": "#fa8072",
  24441. "sandybrown": "#f4a460",
  24442. "seagreen": "#2e8b57",
  24443. "seashell": "#fff5ee",
  24444. "sienna": "#a0522d",
  24445. "silver": "#c0c0c0",
  24446. "skyblue": "#87ceeb",
  24447. "slateblue": "#6a5acd",
  24448. "slategray": "#708090",
  24449. "snow": "#fffafa",
  24450. "springgreen": "#00ff7f",
  24451. "steelblue": "#4682b4",
  24452. "tan": "#d2b48c",
  24453. "teal": "#008080",
  24454. "thistle": "#d8bfd8",
  24455. "tomato": "#ff6347",
  24456. "turquoise": "#40e0d0",
  24457. "violet": "#ee82ee",
  24458. "wheat": "#f5deb3",
  24459. "white": "#ffffff",
  24460. "whitesmoke": "#f5f5f5",
  24461. "yellow": "#ffff00",
  24462. "yellowgreen": "#9acd32"
  24463. };
  24464. var getStyleValue = function getStyleValue(style) {
  24465. return style.split('-')[1];
  24466. };
  24467. var defaultUnitExportFn = function defaultUnitExportFn(unit) {
  24468. return unit + 'px';
  24469. };
  24470. var defaultUnitImportFn = function defaultUnitImportFn(unit) {
  24471. return unit.replace('px', '');
  24472. };
  24473. var ignoredNodeAttributes = ['style'];
  24474. var ignoredEntityNodeAttributes = ['style', 'href', 'target', 'alt', 'title', 'id', 'controls', 'autoplay', 'loop', 'poster'];
  24475. var spreadNodeAttributes = function spreadNodeAttributes(attributesObject) {
  24476. return Object.keys(attributesObject).reduce(function (attributeString, attributeName) {
  24477. return attributeString + " " + attributeName + "=\"" + attributesObject[attributeName] + "\"";
  24478. }, '').replace(/^\s$/, '');
  24479. };
  24480. var defaultFontFamilies = exports.defaultFontFamilies = [{
  24481. name: 'Araial',
  24482. family: 'Arial, Helvetica, sans-serif'
  24483. }, {
  24484. name: 'Georgia',
  24485. family: 'Georgia, serif'
  24486. }, {
  24487. name: 'Impact',
  24488. family: 'Impact, serif'
  24489. }, {
  24490. name: 'Monospace',
  24491. family: '"Courier New", Courier, monospace'
  24492. }, {
  24493. name: 'Tahoma',
  24494. family: "tahoma, arial, 'Hiragino Sans GB', 宋体, sans-serif"
  24495. }];
  24496. var getHexColor = exports.getHexColor = function getHexColor(color) {
  24497. color = color.replace('color:', '').replace(';', '').replace(' ', '');
  24498. if (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(color)) {
  24499. return color;
  24500. } else if (namedColors[color]) {
  24501. return namedColors[color];
  24502. } else if (color.indexOf('rgb') === 0) {
  24503. var rgbArray = color.split(',');
  24504. var convertedColor = rgbArray.length < 3 ? null : '#' + [rgbArray[0], rgbArray[1], rgbArray[2]].map(function (x) {
  24505. var hex = parseInt(x.replace(/\D/g, ''), 10).toString(16);
  24506. return hex.length === 1 ? '0' + hex : hex;
  24507. }).join('');
  24508. return (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(convertedColor) ? convertedColor : null
  24509. );
  24510. } else {
  24511. return null;
  24512. }
  24513. };
  24514. var blocks = exports.blocks = {
  24515. 'header-one': 'h1',
  24516. 'header-two': 'h2',
  24517. 'header-three': 'h3',
  24518. 'header-four': 'h4',
  24519. 'header-five': 'h5',
  24520. 'header-six': 'h6',
  24521. 'unstyled': 'p',
  24522. 'blockquote': 'blockquote'
  24523. };
  24524. var blockTypes = Object.keys(blocks);
  24525. var blockNames = blockTypes.map(function (key) {
  24526. return blocks[key];
  24527. });
  24528. var convertAtomicBlock = function convertAtomicBlock(block, contentState, blockNodeAttributes) {
  24529. if (!block || !block.key) {
  24530. return _react2.default.createElement("p", null);
  24531. }
  24532. var contentBlock = contentState.getBlockForKey(block.key);
  24533. var className = blockNodeAttributes.class,
  24534. nodeAttrAsProps = _objectWithoutProperties(blockNodeAttributes, ["class"]);
  24535. nodeAttrAsProps.className = className;
  24536. if (!contentBlock) {
  24537. return _react2.default.createElement("p", null);
  24538. }
  24539. var entityKey = contentBlock.getEntityAt(0);
  24540. if (!entityKey) {
  24541. return _react2.default.createElement("p", null);
  24542. }
  24543. var entity = contentState.getEntity(entityKey);
  24544. var mediaType = entity.getType().toLowerCase();
  24545. var _block$data = block.data,
  24546. float = _block$data.float,
  24547. alignment = _block$data.alignment;
  24548. var _entity$getData = entity.getData(),
  24549. url = _entity$getData.url,
  24550. link = _entity$getData.link,
  24551. link_target = _entity$getData.link_target,
  24552. width = _entity$getData.width,
  24553. height = _entity$getData.height,
  24554. meta = _entity$getData.meta;
  24555. if (mediaType === 'image') {
  24556. var imageWrapStyle = {};
  24557. var styledClassName = '';
  24558. if (float) {
  24559. imageWrapStyle.float = float;
  24560. styledClassName += ' float-' + float;
  24561. } else if (alignment) {
  24562. imageWrapStyle.textAlign = alignment;
  24563. styledClassName += ' align-' + alignment;
  24564. }
  24565. if (link) {
  24566. return _react2.default.createElement(
  24567. "div",
  24568. { className: "media-wrap image-wrap" + styledClassName, style: imageWrapStyle },
  24569. _react2.default.createElement(
  24570. "a",
  24571. { style: { display: 'inline-block' }, href: link, target: link_target },
  24572. _react2.default.createElement("img", _extends({}, nodeAttrAsProps, meta, { src: url, width: width, height: height, style: { width: width, height: height } }))
  24573. )
  24574. );
  24575. } else {
  24576. return _react2.default.createElement(
  24577. "div",
  24578. { className: "media-wrap image-wrap" + styledClassName, style: imageWrapStyle },
  24579. _react2.default.createElement("img", _extends({}, nodeAttrAsProps, meta, { src: url, width: width, height: height, style: { width: width, height: height } }))
  24580. );
  24581. }
  24582. } else if (mediaType === 'audio') {
  24583. return _react2.default.createElement(
  24584. "div",
  24585. { className: "media-wrap audio-wrap" },
  24586. _react2.default.createElement("audio", _extends({ controls: true }, nodeAttrAsProps, meta, { src: url }))
  24587. );
  24588. } else if (mediaType === 'video') {
  24589. return _react2.default.createElement(
  24590. "div",
  24591. { className: "media-wrap video-wrap" },
  24592. _react2.default.createElement("video", _extends({ controls: true }, nodeAttrAsProps, meta, { src: url, width: width, height: height }))
  24593. );
  24594. } else if (mediaType === 'embed') {
  24595. return _react2.default.createElement(
  24596. "div",
  24597. { className: "media-wrap embed-wrap" },
  24598. _react2.default.createElement("div", { dangerouslySetInnerHTML: { __html: url } })
  24599. );
  24600. } else if (mediaType === 'hr') {
  24601. return _react2.default.createElement("hr", null);
  24602. } else {
  24603. return _react2.default.createElement("p", null);
  24604. }
  24605. };
  24606. var entityToHTML = function entityToHTML(options) {
  24607. return function (entity, originalText) {
  24608. var entityExportFn = options.entityExportFn;
  24609. var entityType = entity.type.toLowerCase();
  24610. if (entityExportFn) {
  24611. var customOutput = entityExportFn(entity, originalText);
  24612. if (customOutput) {
  24613. return customOutput;
  24614. }
  24615. }
  24616. if (entityType === 'link') {
  24617. var _ref = entity.data.nodeAttributes || {},
  24618. className = _ref.class,
  24619. nodeAttrAsProps = _objectWithoutProperties(_ref, ["class"]);
  24620. nodeAttrAsProps.className = className;
  24621. return _react2.default.createElement("a", _extends({ href: entity.data.href, target: entity.data.target }, nodeAttrAsProps));
  24622. }
  24623. };
  24624. };
  24625. var styleToHTML = function styleToHTML(options) {
  24626. return function (style) {
  24627. var unitExportFn = options.unitExportFn || defaultUnitExportFn;
  24628. if (options.styleExportFn) {
  24629. var customOutput = options.styleExportFn(style, options);
  24630. if (customOutput) {
  24631. return customOutput;
  24632. }
  24633. }
  24634. style = style.toLowerCase();
  24635. if (style === 'strikethrough') {
  24636. return _react2.default.createElement("span", { style: { textDecoration: 'line-through' } });
  24637. } else if (style === 'superscript') {
  24638. return _react2.default.createElement("sup", null);
  24639. } else if (style === 'subscript') {
  24640. return _react2.default.createElement("sub", null);
  24641. } else if (style.indexOf('color-') === 0) {
  24642. return _react2.default.createElement("span", { style: { color: '#' + getStyleValue(style) } });
  24643. } else if (style.indexOf('bgcolor-') === 0) {
  24644. return _react2.default.createElement("span", { style: { backgroundColor: '#' + getStyleValue(style) } });
  24645. } else if (style.indexOf('fontsize-') === 0) {
  24646. return _react2.default.createElement("span", { style: { fontSize: unitExportFn(getStyleValue(style), 'font-size', 'html') } });
  24647. } else if (style.indexOf('lineheight-') === 0) {
  24648. return _react2.default.createElement("span", { style: { lineHeight: unitExportFn(getStyleValue(style), 'line-height', 'html') } });
  24649. } else if (style.indexOf('letterspacing-') === 0) {
  24650. return _react2.default.createElement("span", { style: { letterSpacing: unitExportFn(getStyleValue(style), 'letter-spacing', 'html') } });
  24651. } else if (style.indexOf('fontfamily-') === 0) {
  24652. var fontFamily = options.fontFamilies.find(function (item) {
  24653. return item.name.toLowerCase() === getStyleValue(style);
  24654. });
  24655. if (!fontFamily) return;
  24656. return _react2.default.createElement("span", { style: { fontFamily: fontFamily.family } });
  24657. }
  24658. };
  24659. };
  24660. var blockToHTML = function blockToHTML(options) {
  24661. return function (block) {
  24662. var blockExportFn = options.blockExportFn,
  24663. contentState = options.contentState;
  24664. if (blockExportFn) {
  24665. var customOutput = blockExportFn(contentState, block);
  24666. if (customOutput) {
  24667. return customOutput;
  24668. }
  24669. }
  24670. var blockStyle = '';
  24671. var blockType = block.type.toLowerCase();
  24672. var _block$data2 = block.data,
  24673. textAlign = _block$data2.textAlign,
  24674. textIndent = _block$data2.textIndent,
  24675. _block$data2$nodeAttr = _block$data2.nodeAttributes,
  24676. nodeAttributes = _block$data2$nodeAttr === undefined ? {} : _block$data2$nodeAttr;
  24677. var attributeString = spreadNodeAttributes(nodeAttributes);
  24678. if (textAlign || textIndent) {
  24679. blockStyle = ' style="';
  24680. if (textAlign) {
  24681. blockStyle += "text-align:" + textAlign + ";";
  24682. }
  24683. if (textIndent && !isNaN(textIndent) && textIndent > 0) {
  24684. blockStyle += "text-indent:" + textIndent * 2 + "em;";
  24685. }
  24686. blockStyle += '"';
  24687. }
  24688. if (blockType === 'atomic') {
  24689. return convertAtomicBlock(block, contentState, nodeAttributes);
  24690. } else if (blockType === 'code-block') {
  24691. var previousBlock = contentState.getBlockBefore(block.key);
  24692. var nextBlock = contentState.getBlockAfter(block.key);
  24693. var previousBlockType = previousBlock && previousBlock.getType();
  24694. var nextBlockType = nextBlock && nextBlock.getType();
  24695. var start = '';
  24696. var end = '';
  24697. if (previousBlockType !== 'code-block') {
  24698. start = "<pre" + attributeString + "><code>";
  24699. } else {
  24700. start = '';
  24701. }
  24702. if (nextBlockType !== 'code-block') {
  24703. end = '</code></pre>';
  24704. } else {
  24705. end = '<br/>';
  24706. }
  24707. return { start: start, end: end };
  24708. } else if (blocks[blockType]) {
  24709. return {
  24710. start: "<" + blocks[blockType] + blockStyle + attributeString + ">",
  24711. end: "</" + blocks[blockType] + ">"
  24712. };
  24713. } else if (blockType === 'unordered-list-item') {
  24714. return {
  24715. start: "<li" + blockStyle + attributeString + ">",
  24716. end: '</li>',
  24717. nest: _react2.default.createElement("ul", null)
  24718. };
  24719. } else if (blockType === 'ordered-list-item') {
  24720. return {
  24721. start: "<li" + blockStyle + attributeString + ">",
  24722. end: '</li>',
  24723. nest: _react2.default.createElement("ol", null)
  24724. };
  24725. }
  24726. };
  24727. };
  24728. var htmlToStyle = function htmlToStyle(options, source) {
  24729. return function (nodeName, node, currentStyle) {
  24730. if (!node || !node.style) {
  24731. return currentStyle;
  24732. }
  24733. var unitImportFn = options.unitImportFn || defaultUnitImportFn;
  24734. var newStyle = currentStyle;
  24735. [].forEach.call(node.style, function (style) {
  24736. if (nodeName === 'span' && style === 'color') {
  24737. var color = getHexColor(node.style.color);
  24738. newStyle = color ? newStyle.add('COLOR-' + color.replace('#', '').toUpperCase()) : newStyle;
  24739. } else if (nodeName === 'span' && style === 'background-color') {
  24740. var _color = getHexColor(node.style.backgroundColor);
  24741. newStyle = _color ? newStyle.add('BGCOLOR-' + _color.replace('#', '').toUpperCase()) : newStyle;
  24742. } else if (nodeName === 'span' && style === 'font-size') {
  24743. newStyle = newStyle.add('FONTSIZE-' + unitImportFn(node.style.fontSize, 'font-size', source));
  24744. } else if (nodeName === 'span' && style === 'line-height' && !isNaN(parseFloat(node.style.lineHeight, 10))) {
  24745. newStyle = newStyle.add('LINEHEIGHT-' + unitImportFn(node.style.lineHeight, 'line-height', source));
  24746. } else if (nodeName === 'span' && style === 'letter-spacing' && !isNaN(parseFloat(node.style.letterSpacing, 10))) {
  24747. newStyle = newStyle.add('LETTERSPACING-' + unitImportFn(node.style.letterSpacing, 'letter-spacing', source));
  24748. } else if (nodeName === 'span' && style === 'text-decoration') {
  24749. if (node.style.textDecoration === 'line-through') {
  24750. newStyle = newStyle.add('STRIKETHROUGH');
  24751. } else if (node.style.textDecoration === 'underline') {
  24752. newStyle = newStyle.add('UNDERLINE');
  24753. }
  24754. } else if (nodeName === 'span' && style === 'font-family') {
  24755. var fontFamily = options.fontFamilies.find(function (item) {
  24756. return item.family.toLowerCase() === node.style.fontFamily.toLowerCase();
  24757. });
  24758. if (!fontFamily) return;
  24759. newStyle = newStyle.add('FONTFAMILY-' + fontFamily.name.toUpperCase());
  24760. }
  24761. });
  24762. if (nodeName === 'sup') {
  24763. newStyle = newStyle.add('SUPERSCRIPT');
  24764. } else if (nodeName === 'sub') {
  24765. newStyle = newStyle.add('SUBSCRIPT');
  24766. }
  24767. options.styleImportFn && (newStyle = options.styleImportFn(nodeName, node, newStyle, source) || newStyle);
  24768. return newStyle;
  24769. };
  24770. };
  24771. var htmlToEntity = function htmlToEntity(options, source) {
  24772. return function (nodeName, node, createEntity) {
  24773. if (options && options.entityImportFn) {
  24774. var customInput = options.entityImportFn(nodeName, node, createEntity, source);
  24775. if (customInput) {
  24776. return customInput;
  24777. }
  24778. }
  24779. nodeName = nodeName.toLowerCase();
  24780. var alt = node.alt,
  24781. title = node.title,
  24782. id = node.id,
  24783. controls = node.controls,
  24784. autoplay = node.autoplay,
  24785. loop = node.loop,
  24786. poster = node.poster;
  24787. var meta = {};
  24788. var nodeAttributes = {};
  24789. id && (meta.id = id);
  24790. alt && (meta.alt = alt);
  24791. title && (meta.title = title);
  24792. controls && (meta.controls = controls);
  24793. autoplay && (meta.autoPlay = autoplay);
  24794. loop && (meta.loop = loop);
  24795. poster && (meta.poster = poster);
  24796. node.attributes && Object.keys(node.attributes).forEach(function (key) {
  24797. var attr = node.attributes[key];
  24798. ignoredEntityNodeAttributes.indexOf(attr.name) === -1 && (nodeAttributes[attr.name] = attr.value);
  24799. });
  24800. if (nodeName === 'a' && !node.querySelectorAll('img').length) {
  24801. var href = node.getAttribute('href');
  24802. var _target = node.getAttribute('target');
  24803. return createEntity('LINK', 'MUTABLE', { href: href, target: _target, nodeAttributes: nodeAttributes });
  24804. } else if (nodeName === 'audio') {
  24805. return createEntity('AUDIO', 'IMMUTABLE', { url: node.getAttribute('src'), meta: meta, nodeAttributes: nodeAttributes });
  24806. } else if (nodeName === 'video') {
  24807. return createEntity('VIDEO', 'IMMUTABLE', { url: node.getAttribute('src'), meta: meta, nodeAttributes: nodeAttributes });
  24808. } else if (nodeName === 'img') {
  24809. var parentNode = node.parentNode;
  24810. var entityData = { meta: meta };
  24811. var _node$style = node.style,
  24812. width = _node$style.width,
  24813. height = _node$style.height;
  24814. entityData.url = node.getAttribute('src');
  24815. width && (entityData.width = width);
  24816. height && (entityData.height = height);
  24817. if (parentNode.nodeName.toLowerCase() === 'a') {
  24818. entityData.link = parentNode.getAttribute('href');
  24819. entityData.link_target = parentNode.getAttribute('target');
  24820. }
  24821. return createEntity('IMAGE', 'IMMUTABLE', entityData);
  24822. } else if (nodeName === 'hr') {
  24823. return createEntity('HR', 'IMMUTABLE', {});
  24824. } else if (node.parentNode && node.parentNode.classList.contains('embed-wrap')) {
  24825. var embedContent = node.innerHTML || node.outerHTML;
  24826. if (embedContent) {
  24827. return createEntity('EMBED', 'IMMUTABLE', {
  24828. url: embedContent
  24829. });
  24830. }
  24831. }
  24832. };
  24833. };
  24834. var htmlToBlock = function htmlToBlock(options, source) {
  24835. return function (nodeName, node) {
  24836. if (options && options.blockImportFn) {
  24837. var customInput = options.blockImportFn(nodeName, node, source);
  24838. if (customInput) {
  24839. return customInput;
  24840. }
  24841. }
  24842. var nodeAttributes = {};
  24843. var nodeStyle = node.style || {};
  24844. node.attributes && Object.keys(node.attributes).forEach(function (key) {
  24845. var attr = node.attributes[key];
  24846. ignoredNodeAttributes.indexOf(attr.name) === -1 && (nodeAttributes[attr.name] = attr.value);
  24847. });
  24848. if (node.classList && node.classList.contains('media-wrap')) {
  24849. return {
  24850. type: 'atomic',
  24851. data: {
  24852. nodeAttributes: nodeAttributes,
  24853. float: nodeStyle.float,
  24854. alignment: nodeStyle.textAlign
  24855. }
  24856. };
  24857. } else if (nodeName === 'img') {
  24858. return {
  24859. type: 'atomic',
  24860. data: {
  24861. nodeAttributes: nodeAttributes,
  24862. float: nodeStyle.float,
  24863. alignment: nodeStyle.textAlign
  24864. }
  24865. };
  24866. } else if (nodeName === 'hr') {
  24867. return {
  24868. type: 'atomic',
  24869. data: { nodeAttributes: nodeAttributes }
  24870. };
  24871. } else if (nodeName === 'pre') {
  24872. node.innerHTML = node.innerHTML.replace(/<code(.*?)>/g, '').replace(/<\/code>/g, '');
  24873. return {
  24874. type: 'code-block',
  24875. data: { nodeAttributes: nodeAttributes }
  24876. };
  24877. } else if (blockNames.indexOf(nodeName) !== -1) {
  24878. var blockData = { nodeAttributes: nodeAttributes };
  24879. if (nodeStyle.textAlign) {
  24880. blockData.textAlign = nodeStyle.textAlign;
  24881. }
  24882. if (nodeStyle.textIndent) {
  24883. blockData.textIndent = /^\d+em$/.test(nodeStyle.textIndent) ? Math.ceil(parseInt(nodeStyle.textIndent, 10) / 2) : 1;
  24884. }
  24885. return {
  24886. type: blockTypes[blockNames.indexOf(nodeName)],
  24887. data: blockData
  24888. };
  24889. }
  24890. };
  24891. };
  24892. var getToHTMLConfig = exports.getToHTMLConfig = function getToHTMLConfig(options) {
  24893. return {
  24894. styleToHTML: styleToHTML(options),
  24895. entityToHTML: entityToHTML(options),
  24896. blockToHTML: blockToHTML(options)
  24897. };
  24898. };
  24899. var getFromHTMLConfig = exports.getFromHTMLConfig = function getFromHTMLConfig(options) {
  24900. var source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'unknow';
  24901. return {
  24902. htmlToStyle: htmlToStyle(options, source),
  24903. htmlToEntity: htmlToEntity(options, source),
  24904. htmlToBlock: htmlToBlock(options, source)
  24905. };
  24906. };
  24907. });
  24908. unwrapExports(configs);
  24909. var configs_1 = configs.getFromHTMLConfig;
  24910. var configs_2 = configs.getToHTMLConfig;
  24911. var configs_3 = configs.blocks;
  24912. var configs_4 = configs.getHexColor;
  24913. var configs_5 = configs.defaultFontFamilies;
  24914. var configs_6 = configs.namedColors;
  24915. var dist = createCommonjsModule(function (module, exports) {
  24916. Object.defineProperty(exports, "__esModule", {
  24917. value: true
  24918. });
  24919. exports.convertRawToEditorState = exports.convertEditorStateToRaw = exports.convertHTMLToEditorState = exports.convertEditorStateToHTML = exports.convertHTMLToRaw = exports.convertRawToHTML = undefined;
  24920. 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; };
  24921. var defaultConvertOptions = {
  24922. fontFamilies: configs.defaultFontFamilies
  24923. };
  24924. var convertRawToHTML = exports.convertRawToHTML = function convertRawToHTML(rawContent, options) {
  24925. options = _extends({}, defaultConvertOptions, options);
  24926. try {
  24927. var contentState = (0, Draft.convertFromRaw)(rawContent);
  24928. options.contentState = contentState;
  24929. return (0, lib.convertToHTML)((0, configs.getToHTMLConfig)(options))(contentState);
  24930. } catch (error) {
  24931. console.warn(error);
  24932. return '';
  24933. }
  24934. };
  24935. var convertHTMLToRaw = exports.convertHTMLToRaw = function convertHTMLToRaw(HTMLString, options, source) {
  24936. options = _extends({}, defaultConvertOptions, options);
  24937. try {
  24938. var contentState = (0, lib.convertFromHTML)((0, configs.getFromHTMLConfig)(options, source))(HTMLString);
  24939. return (0, Draft.convertToRaw)(contentState);
  24940. } catch (error) {
  24941. console.warn(error);
  24942. return {};
  24943. }
  24944. };
  24945. var convertEditorStateToHTML = exports.convertEditorStateToHTML = function convertEditorStateToHTML(editorState, options) {
  24946. options = _extends({}, defaultConvertOptions, options);
  24947. try {
  24948. var contentState = editorState.getCurrentContent();
  24949. options.contentState = contentState;
  24950. return (0, lib.convertToHTML)((0, configs.getToHTMLConfig)(options))(contentState);
  24951. } catch (error) {
  24952. console.warn(error);
  24953. return '';
  24954. }
  24955. };
  24956. var convertHTMLToEditorState = exports.convertHTMLToEditorState = function convertHTMLToEditorState(HTMLString, editorDecorators, options, source) {
  24957. options = _extends({}, defaultConvertOptions, options);
  24958. try {
  24959. return Draft.EditorState.createWithContent((0, lib.convertFromHTML)((0, configs.getFromHTMLConfig)(options, source))(HTMLString), editorDecorators);
  24960. } catch (error) {
  24961. console.warn(error);
  24962. return Draft.EditorState.createEmpty(editorDecorators);
  24963. }
  24964. };
  24965. var convertEditorStateToRaw = exports.convertEditorStateToRaw = function convertEditorStateToRaw(editorState) {
  24966. return (0, Draft.convertToRaw)(editorState.getCurrentContent());
  24967. };
  24968. var convertRawToEditorState = exports.convertRawToEditorState = function convertRawToEditorState(rawContent, editorDecorators) {
  24969. try {
  24970. return Draft.EditorState.createWithContent((0, Draft.convertFromRaw)(rawContent), editorDecorators);
  24971. } catch (error) {
  24972. console.warn(error);
  24973. return Draft.EditorState.createEmpty(editorDecorators);
  24974. }
  24975. };
  24976. });
  24977. unwrapExports(dist);
  24978. var dist_1 = dist.convertRawToEditorState;
  24979. var dist_2 = dist.convertEditorStateToRaw;
  24980. var dist_3 = dist.convertHTMLToEditorState;
  24981. var dist_4 = dist.convertEditorStateToHTML;
  24982. var dist_5 = dist.convertHTMLToRaw;
  24983. var dist_6 = dist.convertRawToHTML;
  24984. var content = createCommonjsModule(function (module, exports) {
  24985. Object.defineProperty(exports, "__esModule", {
  24986. value: true
  24987. });
  24988. 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;
  24989. var _immutable2 = _interopRequireDefault(immutable$1);
  24990. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  24991. var strictBlockTypes = ['atomic'];
  24992. var registerStrictBlockType = exports.registerStrictBlockType = function registerStrictBlockType(blockType) {
  24993. strictBlockTypes.indexOf(blockType) === -1 && strictBlockTypes.push(blockType);
  24994. };
  24995. var isEditorState = exports.isEditorState = function isEditorState(editorState) {
  24996. return editorState instanceof Draft.EditorState;
  24997. };
  24998. var createEmptyEditorState = exports.createEmptyEditorState = function createEmptyEditorState(editorDecorators) {
  24999. return Draft.EditorState.createEmpty(editorDecorators);
  25000. };
  25001. var createEditorState = exports.createEditorState = function createEditorState(contentState, editorDecorators) {
  25002. return Draft.EditorState.createWithContent(contentState, editorDecorators);
  25003. };
  25004. var isSelectionCollapsed = exports.isSelectionCollapsed = function isSelectionCollapsed(editorState) {
  25005. return editorState.getSelection().isCollapsed();
  25006. };
  25007. var selectionContainsBlockType = exports.selectionContainsBlockType = function selectionContainsBlockType(editorState, blockType) {
  25008. return getSelectedBlocks(editorState).find(function (block) {
  25009. return block.getType() === blockType;
  25010. });
  25011. };
  25012. var selectionContainsStrictBlock = exports.selectionContainsStrictBlock = function selectionContainsStrictBlock(editorState) {
  25013. return getSelectedBlocks(editorState).find(function (block) {
  25014. return ~strictBlockTypes.indexOf(block.getType());
  25015. });
  25016. };
  25017. var selectBlock = exports.selectBlock = function selectBlock(editorState, block) {
  25018. var blockKey = block.getKey();
  25019. return Draft.EditorState.forceSelection(editorState, new Draft.SelectionState({
  25020. anchorKey: blockKey,
  25021. anchorOffset: 0,
  25022. focusKey: blockKey,
  25023. focusOffset: block.getLength()
  25024. }));
  25025. };
  25026. var selectNextBlock = exports.selectNextBlock = function selectNextBlock(editorState, block) {
  25027. var nextBlock = editorState.getCurrentContent().getBlockAfter(block.getKey());
  25028. return nextBlock ? selectBlock(editorState, nextBlock) : editorState;
  25029. };
  25030. var removeBlock = exports.removeBlock = function removeBlock(editorState, block) {
  25031. var lastSelection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  25032. var nextContentState = void 0,
  25033. nextEditorState = void 0;
  25034. var blockKey = block.getKey();
  25035. nextContentState = Draft.Modifier.removeRange(editorState.getCurrentContent(), new Draft.SelectionState({
  25036. anchorKey: blockKey,
  25037. anchorOffset: 0,
  25038. focusKey: blockKey,
  25039. focusOffset: block.getLength()
  25040. }), 'backward');
  25041. nextContentState = Draft.Modifier.setBlockType(nextContentState, nextContentState.getSelectionAfter(), 'unstyled');
  25042. nextEditorState = Draft.EditorState.push(editorState, nextContentState, 'remove-range');
  25043. return Draft.EditorState.forceSelection(nextEditorState, lastSelection || nextContentState.getSelectionAfter());
  25044. };
  25045. var getSelectionBlock = exports.getSelectionBlock = function getSelectionBlock(editorState) {
  25046. return editorState.getCurrentContent().getBlockForKey(editorState.getSelection().getAnchorKey());
  25047. };
  25048. var updateEachCharacterOfSelection = exports.updateEachCharacterOfSelection = function updateEachCharacterOfSelection(editorState, callback) {
  25049. var selectionState = editorState.getSelection();
  25050. var contentState = editorState.getCurrentContent();
  25051. var contentBlocks = contentState.getBlockMap();
  25052. var selectedBlocks = getSelectedBlocks(editorState);
  25053. if (selectedBlocks.length === 0) {
  25054. return editorState;
  25055. }
  25056. var startKey = selectionState.getStartKey();
  25057. var startOffset = selectionState.getStartOffset();
  25058. var endKey = selectionState.getEndKey();
  25059. var endOffset = selectionState.getEndOffset();
  25060. var nextContentBlocks = contentBlocks.map(function (block) {
  25061. if (selectedBlocks.indexOf(block) === -1) {
  25062. return block;
  25063. }
  25064. var blockKey = block.getKey();
  25065. var charactersList = block.getCharacterList();
  25066. var nextCharactersList = null;
  25067. if (blockKey === startKey && blockKey === endKey) {
  25068. nextCharactersList = charactersList.map(function (character, index) {
  25069. if (index >= startOffset && index < endOffset) {
  25070. return callback(character);
  25071. }
  25072. return character;
  25073. });
  25074. } else if (blockKey === startKey) {
  25075. nextCharactersList = charactersList.map(function (character, index) {
  25076. if (index >= startOffset) {
  25077. return callback(character);
  25078. }
  25079. return character;
  25080. });
  25081. } else if (blockKey === endKey) {
  25082. nextCharactersList = charactersList.map(function (character, index) {
  25083. if (index < endOffset) {
  25084. return callback(character);
  25085. }
  25086. return character;
  25087. });
  25088. } else {
  25089. nextCharactersList = charactersList.map(function (character) {
  25090. return callback(character);
  25091. });
  25092. }
  25093. return block.merge({
  25094. 'characterList': nextCharactersList
  25095. });
  25096. });
  25097. return Draft.EditorState.push(editorState, contentState.merge({
  25098. blockMap: nextContentBlocks,
  25099. selectionBefore: selectionState,
  25100. selectionAfter: selectionState
  25101. }), 'update-selection-character-list');
  25102. };
  25103. var getSelectedBlocks = exports.getSelectedBlocks = function getSelectedBlocks(editorState) {
  25104. var selectionState = editorState.getSelection();
  25105. var contentState = editorState.getCurrentContent();
  25106. var startKey = selectionState.getStartKey();
  25107. var endKey = selectionState.getEndKey();
  25108. var isSameBlock = startKey === endKey;
  25109. var startingBlock = contentState.getBlockForKey(startKey);
  25110. var selectedBlocks = [startingBlock];
  25111. if (!isSameBlock) {
  25112. var blockKey = startKey;
  25113. while (blockKey !== endKey) {
  25114. var nextBlock = contentState.getBlockAfter(blockKey);
  25115. selectedBlocks.push(nextBlock);
  25116. blockKey = nextBlock.getKey();
  25117. }
  25118. }
  25119. return selectedBlocks;
  25120. };
  25121. var setSelectionBlockData = exports.setSelectionBlockData = function setSelectionBlockData(editorState, blockData, override) {
  25122. var newBlockData = override ? blockData : Object.assign({}, getSelectionBlockData(editorState).toJS(), blockData);
  25123. Object.keys(newBlockData).forEach(function (key) {
  25124. if (newBlockData.hasOwnProperty(key) && newBlockData[key] === undefined) {
  25125. delete newBlockData[key];
  25126. }
  25127. });
  25128. return (0, draftjsUtils.setBlockData)(editorState, newBlockData);
  25129. };
  25130. var getSelectionBlockData = exports.getSelectionBlockData = function getSelectionBlockData(editorState, name) {
  25131. var blockData = getSelectionBlock(editorState).getData();
  25132. return name ? blockData.get(name) : blockData;
  25133. };
  25134. var getSelectionBlockType = exports.getSelectionBlockType = function getSelectionBlockType(editorState) {
  25135. return getSelectionBlock(editorState).getType();
  25136. };
  25137. var getSelectionText = exports.getSelectionText = function getSelectionText(editorState) {
  25138. var selectionState = editorState.getSelection();
  25139. var contentState = editorState.getCurrentContent();
  25140. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  25141. return '';
  25142. }
  25143. var anchorKey = selectionState.getAnchorKey();
  25144. var currentContentBlock = contentState.getBlockForKey(anchorKey);
  25145. var start = selectionState.getStartOffset();
  25146. var end = selectionState.getEndOffset();
  25147. return currentContentBlock.getText().slice(start, end);
  25148. };
  25149. var toggleSelectionBlockType = exports.toggleSelectionBlockType = function toggleSelectionBlockType(editorState, blockType) {
  25150. if (selectionContainsStrictBlock(editorState)) {
  25151. return editorState;
  25152. }
  25153. return Draft.RichUtils.toggleBlockType(editorState, blockType);
  25154. };
  25155. var getSelectionEntityType = exports.getSelectionEntityType = function getSelectionEntityType(editorState) {
  25156. var entityKey = (0, draftjsUtils.getSelectionEntity)(editorState);
  25157. if (entityKey) {
  25158. var entity = editorState.getCurrentContent().getEntity(entityKey);
  25159. return entity ? entity.get('type') : null;
  25160. }
  25161. return null;
  25162. };
  25163. var getSelectionEntityData = exports.getSelectionEntityData = function getSelectionEntityData(editorState, type) {
  25164. var entityKey = (0, draftjsUtils.getSelectionEntity)(editorState);
  25165. if (entityKey) {
  25166. var entity = editorState.getCurrentContent().getEntity(entityKey);
  25167. if (entity && entity.get('type') === type) {
  25168. return entity.getData();
  25169. } else {
  25170. return {};
  25171. }
  25172. } else {
  25173. return {};
  25174. }
  25175. };
  25176. var toggleSelectionEntity = exports.toggleSelectionEntity = function toggleSelectionEntity(editorState, entity) {
  25177. var contentState = editorState.getCurrentContent();
  25178. var selectionState = editorState.getSelection();
  25179. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  25180. return editorState;
  25181. }
  25182. if (!entity || !entity.type || getSelectionEntityType(editorState) === entity.type) {
  25183. return Draft.EditorState.push(editorState, Draft.Modifier.applyEntity(contentState, selectionState, null), 'apply-entity');
  25184. }
  25185. try {
  25186. var nextContentState = contentState.createEntity(entity.type, entity.mutability, entity.data);
  25187. var entityKey = nextContentState.getLastCreatedEntityKey();
  25188. var nextEditorState = Draft.EditorState.set(editorState, {
  25189. currentContent: nextContentState
  25190. });
  25191. return Draft.EditorState.push(nextEditorState, Draft.Modifier.applyEntity(nextContentState, selectionState, entityKey), 'apply-entity');
  25192. } catch (error) {
  25193. console.warn(error);
  25194. return editorState;
  25195. }
  25196. };
  25197. var toggleSelectionLink = exports.toggleSelectionLink = function toggleSelectionLink(editorState, href, target) {
  25198. var contentState = editorState.getCurrentContent();
  25199. var selectionState = editorState.getSelection();
  25200. var entityData = { href: href, target: target };
  25201. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  25202. return editorState;
  25203. }
  25204. if (href === false) {
  25205. return Draft.RichUtils.toggleLink(editorState, selectionState, null);
  25206. }
  25207. if (href === null) {
  25208. delete entityData.href;
  25209. }
  25210. try {
  25211. var nextContentState = contentState.createEntity('LINK', 'MUTABLE', entityData);
  25212. var entityKey = nextContentState.getLastCreatedEntityKey();
  25213. var nextEditorState = Draft.EditorState.set(editorState, {
  25214. currentContent: nextContentState
  25215. });
  25216. nextEditorState = Draft.RichUtils.toggleLink(nextEditorState, selectionState, entityKey);
  25217. nextEditorState = Draft.EditorState.forceSelection(nextEditorState, selectionState.merge({
  25218. anchorOffset: selectionState.getEndOffset(),
  25219. focusOffset: selectionState.getEndOffset()
  25220. }));
  25221. nextEditorState = Draft.EditorState.push(nextEditorState, Draft.Modifier.insertText(nextEditorState.getCurrentContent(), nextEditorState.getSelection(), ''), 'insert-text');
  25222. return nextEditorState;
  25223. } catch (error) {
  25224. console.warn(error);
  25225. return editorState;
  25226. }
  25227. };
  25228. var getSelectionInlineStyle = exports.getSelectionInlineStyle = function getSelectionInlineStyle(editorState) {
  25229. return editorState.getCurrentInlineStyle();
  25230. };
  25231. var selectionHasInlineStyle = exports.selectionHasInlineStyle = function selectionHasInlineStyle(editorState, style) {
  25232. return getSelectionInlineStyle(editorState).has(style.toUpperCase());
  25233. };
  25234. var toggleSelectionInlineStyle = exports.toggleSelectionInlineStyle = function toggleSelectionInlineStyle(editorState, style) {
  25235. var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
  25236. var nextEditorState = editorState;
  25237. style = prefix + style.toUpperCase();
  25238. if (prefix) {
  25239. nextEditorState = updateEachCharacterOfSelection(nextEditorState, function (characterMetadata) {
  25240. return characterMetadata.toJS().style.reduce(function (characterMetadata, characterStyle) {
  25241. if (characterStyle.indexOf(prefix) === 0 && style !== characterStyle) {
  25242. return Draft.CharacterMetadata.removeStyle(characterMetadata, characterStyle);
  25243. } else {
  25244. return characterMetadata;
  25245. }
  25246. }, characterMetadata);
  25247. });
  25248. }
  25249. return Draft.RichUtils.toggleInlineStyle(nextEditorState, style);
  25250. };
  25251. var removeSelectionInlineStyles = exports.removeSelectionInlineStyles = function removeSelectionInlineStyles(editorState) {
  25252. return updateEachCharacterOfSelection(editorState, function (characterMetadata) {
  25253. return characterMetadata.merge({
  25254. style: _immutable2.default.OrderedSet([])
  25255. });
  25256. });
  25257. };
  25258. var toggleSelectionAlignment = exports.toggleSelectionAlignment = function toggleSelectionAlignment(editorState, alignment) {
  25259. return setSelectionBlockData(editorState, {
  25260. textAlign: getSelectionBlockData(editorState, 'textAlign') !== alignment ? alignment : undefined
  25261. });
  25262. };
  25263. var toggleSelectionIndent = exports.toggleSelectionIndent = function toggleSelectionIndent(editorState, textIndent) {
  25264. var maxIndent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 6;
  25265. return textIndent < 0 || textIndent > maxIndent || isNaN(textIndent) ? editorState : setSelectionBlockData(editorState, {
  25266. textIndent: textIndent || undefined
  25267. });
  25268. };
  25269. var increaseSelectionIndent = exports.increaseSelectionIndent = function increaseSelectionIndent(editorState) {
  25270. var maxIndent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 6;
  25271. var currentIndent = getSelectionBlockData(editorState, 'textIndent') || 0;
  25272. return toggleSelectionIndent(editorState, currentIndent + 1, maxIndent);
  25273. };
  25274. var decreaseSelectionIndent = exports.decreaseSelectionIndent = function decreaseSelectionIndent(editorState) {
  25275. var currentIndent = getSelectionBlockData(editorState, 'textIndent') || 0;
  25276. return toggleSelectionIndent(editorState, currentIndent - 1);
  25277. };
  25278. var toggleSelectionColor = exports.toggleSelectionColor = function toggleSelectionColor(editorState, color) {
  25279. return toggleSelectionInlineStyle(editorState, color.replace('#', ''), 'COLOR-');
  25280. };
  25281. var toggleSelectionBackgroundColor = exports.toggleSelectionBackgroundColor = function toggleSelectionBackgroundColor(editorState, color) {
  25282. return toggleSelectionInlineStyle(editorState, color.replace('#', ''), 'BGCOLOR-');
  25283. };
  25284. var toggleSelectionFontSize = exports.toggleSelectionFontSize = function toggleSelectionFontSize(editorState, fontSize) {
  25285. return toggleSelectionInlineStyle(editorState, fontSize, 'FONTSIZE-');
  25286. };
  25287. var toggleSelectionLineHeight = exports.toggleSelectionLineHeight = function toggleSelectionLineHeight(editorState, lineHeight) {
  25288. return toggleSelectionInlineStyle(editorState, lineHeight, 'LINEHEIGHT-');
  25289. };
  25290. var toggleSelectionFontFamily = exports.toggleSelectionFontFamily = function toggleSelectionFontFamily(editorState, fontFamily) {
  25291. return toggleSelectionInlineStyle(editorState, fontFamily, 'FONTFAMILY-');
  25292. };
  25293. var toggleSelectionLetterSpacing = exports.toggleSelectionLetterSpacing = function toggleSelectionLetterSpacing(editorState, letterSpacing) {
  25294. return toggleSelectionInlineStyle(editorState, letterSpacing, 'LETTERSPACING-');
  25295. };
  25296. var insertText = exports.insertText = function insertText(editorState, text, inlineStyle, entity) {
  25297. var selectionState = editorState.getSelection();
  25298. var currentSelectedBlockType = getSelectionBlockType(editorState);
  25299. if (currentSelectedBlockType === 'atomic') {
  25300. return editorState;
  25301. }
  25302. var entityKey = void 0;
  25303. var contentState = editorState.getCurrentContent();
  25304. if (entity && entity.type) {
  25305. contentState = contentState.createEntity(entity.type, entity.mutability || 'MUTABLE', entity.data || entityData);
  25306. entityKey = contentState.getLastCreatedEntityKey();
  25307. }
  25308. if (!selectionState.isCollapsed()) {
  25309. return Draft.EditorState.push(editorState, Draft.Modifier.replaceText(contentState, selectionState, text, inlineStyle, entityKey), 'replace-text');
  25310. } else {
  25311. return Draft.EditorState.push(editorState, Draft.Modifier.insertText(contentState, selectionState, text, inlineStyle, entityKey), 'insert-text');
  25312. }
  25313. };
  25314. var insertHTML = exports.insertHTML = function insertHTML(editorState, htmlString, source) {
  25315. if (!htmlString) {
  25316. return editorState;
  25317. }
  25318. var selectionState = editorState.getSelection();
  25319. var contentState = editorState.getCurrentContent();
  25320. var options = editorState.convertOptions || {};
  25321. try {
  25322. var _convertFromRaw = (0, Draft.convertFromRaw)((0, dist.convertHTMLToRaw)(htmlString, options, source)),
  25323. blockMap = _convertFromRaw.blockMap;
  25324. return Draft.EditorState.push(editorState, Draft.Modifier.replaceWithFragment(contentState, selectionState, blockMap), 'insert-fragment');
  25325. } catch (error) {
  25326. console.warn(error);
  25327. return editorState;
  25328. }
  25329. };
  25330. var insertAtomicBlock = exports.insertAtomicBlock = function insertAtomicBlock(editorState, type) {
  25331. var immutable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  25332. var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  25333. if (selectionContainsStrictBlock(editorState)) {
  25334. return insertAtomicBlock(selectNextBlock(editorState, getSelectionBlock(editorState)), type, immutable, data);
  25335. }
  25336. var selectionState = editorState.getSelection();
  25337. var contentState = editorState.getCurrentContent();
  25338. if (!selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  25339. return editorState;
  25340. }
  25341. var contentStateWithEntity = contentState.createEntity(type, immutable ? 'IMMUTABLE' : 'MUTABLE', data);
  25342. var entityKey = contentStateWithEntity.getLastCreatedEntityKey();
  25343. var newEditorState = Draft.AtomicBlockUtils.insertAtomicBlock(editorState, entityKey, ' ');
  25344. return newEditorState;
  25345. };
  25346. var insertHorizontalLine = exports.insertHorizontalLine = function insertHorizontalLine(editorState) {
  25347. return insertAtomicBlock(editorState, 'HR');
  25348. };
  25349. var insertMedias = exports.insertMedias = function insertMedias(editorState) {
  25350. var medias = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  25351. if (!medias.length) {
  25352. return editorState;
  25353. }
  25354. return medias.reduce(function (editorState, media) {
  25355. var url = media.url,
  25356. link = media.link,
  25357. link_target = media.link_target,
  25358. name = media.name,
  25359. type = media.type,
  25360. width = media.width,
  25361. height = media.height,
  25362. meta = media.meta;
  25363. return insertAtomicBlock(editorState, type, true, { url: url, link: link, link_target: link_target, name: name, type: type, width: width, height: height, meta: meta });
  25364. }, editorState);
  25365. };
  25366. var setMediaData = exports.setMediaData = function setMediaData(editorState, entityKey, data) {
  25367. return Draft.EditorState.push(editorState, editorState.getCurrentContent().mergeEntityData(entityKey, data), 'change-block-data');
  25368. };
  25369. var removeMedia = exports.removeMedia = function removeMedia(editorState, mediaBlock) {
  25370. return removeBlock(editorState, mediaBlock);
  25371. };
  25372. var setMediaPosition = exports.setMediaPosition = function setMediaPosition(editorState, mediaBlock, position) {
  25373. var newPosition = {};
  25374. var float = position.float,
  25375. alignment = position.alignment;
  25376. if (typeof float !== 'undefined') {
  25377. newPosition.float = mediaBlock.getData().get('float') === float ? null : float;
  25378. }
  25379. if (typeof alignment !== 'undefined') {
  25380. newPosition.alignment = mediaBlock.getData().get('alignment') === alignment ? null : alignment;
  25381. }
  25382. return setSelectionBlockData(selectBlock(editorState, mediaBlock), newPosition);
  25383. };
  25384. var clear = exports.clear = function clear(editorState) {
  25385. var contentState = editorState.getCurrentContent();
  25386. var firstBlock = contentState.getFirstBlock();
  25387. var lastBlock = contentState.getLastBlock();
  25388. var allSelected = new Draft.SelectionState({
  25389. anchorKey: firstBlock.getKey(),
  25390. anchorOffset: 0,
  25391. focusKey: lastBlock.getKey(),
  25392. focusOffset: lastBlock.getLength(),
  25393. hasFocus: true
  25394. });
  25395. return Draft.RichUtils.toggleBlockType(Draft.EditorState.push(editorState, Draft.Modifier.removeRange(contentState, allSelected, 'backward'), 'remove-range'), 'unstyled');
  25396. };
  25397. var handleKeyCommand = exports.handleKeyCommand = function handleKeyCommand(editorState, command) {
  25398. return Draft.RichUtils.handleKeyCommand(editorState, command);
  25399. };
  25400. var undo = exports.undo = function undo(editorState) {
  25401. return Draft.EditorState.undo(editorState);
  25402. };
  25403. var redo = exports.redo = function redo(editorState) {
  25404. return Draft.EditorState.redo(editorState);
  25405. };
  25406. });
  25407. unwrapExports(content);
  25408. var content_1 = content.redo;
  25409. var content_2 = content.undo;
  25410. var content_3 = content.handleKeyCommand;
  25411. var content_4 = content.clear;
  25412. var content_5 = content.setMediaPosition;
  25413. var content_6 = content.removeMedia;
  25414. var content_7 = content.setMediaData;
  25415. var content_8 = content.insertMedias;
  25416. var content_9 = content.insertHorizontalLine;
  25417. var content_10 = content.insertAtomicBlock;
  25418. var content_11 = content.insertHTML;
  25419. var content_12 = content.insertText;
  25420. var content_13 = content.toggleSelectionLetterSpacing;
  25421. var content_14 = content.toggleSelectionFontFamily;
  25422. var content_15 = content.toggleSelectionLineHeight;
  25423. var content_16 = content.toggleSelectionFontSize;
  25424. var content_17 = content.toggleSelectionBackgroundColor;
  25425. var content_18 = content.toggleSelectionColor;
  25426. var content_19 = content.decreaseSelectionIndent;
  25427. var content_20 = content.increaseSelectionIndent;
  25428. var content_21 = content.toggleSelectionIndent;
  25429. var content_22 = content.toggleSelectionAlignment;
  25430. var content_23 = content.removeSelectionInlineStyles;
  25431. var content_24 = content.toggleSelectionInlineStyle;
  25432. var content_25 = content.selectionHasInlineStyle;
  25433. var content_26 = content.getSelectionInlineStyle;
  25434. var content_27 = content.toggleSelectionLink;
  25435. var content_28 = content.toggleSelectionEntity;
  25436. var content_29 = content.getSelectionEntityData;
  25437. var content_30 = content.getSelectionEntityType;
  25438. var content_31 = content.toggleSelectionBlockType;
  25439. var content_32 = content.getSelectionText;
  25440. var content_33 = content.getSelectionBlockType;
  25441. var content_34 = content.getSelectionBlockData;
  25442. var content_35 = content.setSelectionBlockData;
  25443. var content_36 = content.getSelectedBlocks;
  25444. var content_37 = content.updateEachCharacterOfSelection;
  25445. var content_38 = content.getSelectionBlock;
  25446. var content_39 = content.removeBlock;
  25447. var content_40 = content.selectNextBlock;
  25448. var content_41 = content.selectBlock;
  25449. var content_42 = content.selectionContainsStrictBlock;
  25450. var content_43 = content.selectionContainsBlockType;
  25451. var content_44 = content.isSelectionCollapsed;
  25452. var content_45 = content.createEditorState;
  25453. var content_46 = content.createEmptyEditorState;
  25454. var content_47 = content.isEditorState;
  25455. var content_48 = content.registerStrictBlockType;
  25456. var base = createCommonjsModule(function (module, exports) {
  25457. Object.defineProperty(exports, "__esModule", {
  25458. value: true
  25459. });
  25460. var braftUniqueIndex = 0;
  25461. var UniqueIndex = exports.UniqueIndex = function UniqueIndex() {
  25462. return braftUniqueIndex += 1;
  25463. };
  25464. });
  25465. unwrapExports(base);
  25466. var base_1 = base.UniqueIndex;
  25467. var color = createCommonjsModule(function (module, exports) {
  25468. Object.defineProperty(exports, "__esModule", {
  25469. value: true
  25470. });
  25471. var _namedColors = {
  25472. "aliceblue": "#f0f8ff",
  25473. "antiquewhite": "#faebd7",
  25474. "aqua": "#00ffff",
  25475. "aquamarine": "#7fffd4",
  25476. "azure": "#f0ffff",
  25477. "beige": "#f5f5dc",
  25478. "bisque": "#ffe4c4",
  25479. "black": "#000000",
  25480. "blanchedalmond": "#ffebcd",
  25481. "blue": "#0000ff",
  25482. "blueviolet": "#8a2be2",
  25483. "brown": "#a52a2a",
  25484. "burlywood": "#deb887",
  25485. "cadetblue": "#5f9ea0",
  25486. "chartreuse": "#7fff00",
  25487. "chocolate": "#d2691e",
  25488. "coral": "#ff7f50",
  25489. "cornflowerblue": "#6495ed",
  25490. "cornsilk": "#fff8dc",
  25491. "crimson": "#dc143c",
  25492. "cyan": "#00ffff",
  25493. "darkblue": "#00008b",
  25494. "darkcyan": "#008b8b",
  25495. "darkgoldenrod": "#b8860b",
  25496. "darkgray": "#a9a9a9",
  25497. "darkgreen": "#006400",
  25498. "darkkhaki": "#bdb76b",
  25499. "darkmagenta": "#8b008b",
  25500. "darkolivegreen": "#556b2f",
  25501. "darkorange": "#ff8c00",
  25502. "darkorchid": "#9932cc",
  25503. "darkred": "#8b0000",
  25504. "darksalmon": "#e9967a",
  25505. "darkseagreen": "#8fbc8f",
  25506. "darkslateblue": "#483d8b",
  25507. "darkslategray": "#2f4f4f",
  25508. "darkturquoise": "#00ced1",
  25509. "darkviolet": "#9400d3",
  25510. "deeppink": "#ff1493",
  25511. "deepskyblue": "#00bfff",
  25512. "dimgray": "#696969",
  25513. "dodgerblue": "#1e90ff",
  25514. "firebrick": "#b22222",
  25515. "floralwhite": "#fffaf0",
  25516. "forestgreen": "#228b22",
  25517. "fuchsia": "#ff00ff",
  25518. "gainsboro": "#dcdcdc",
  25519. "ghostwhite": "#f8f8ff",
  25520. "gold": "#ffd700",
  25521. "goldenrod": "#daa520",
  25522. "gray": "#808080",
  25523. "green": "#008000",
  25524. "greenyellow": "#adff2f",
  25525. "honeydew": "#f0fff0",
  25526. "hotpink": "#ff69b4",
  25527. "indianred ": "#cd5c5c",
  25528. "indigo": "#4b0082",
  25529. "ivory": "#fffff0",
  25530. "khaki": "#f0e68c",
  25531. "lavender": "#e6e6fa",
  25532. "lavenderblush": "#fff0f5",
  25533. "lawngreen": "#7cfc00",
  25534. "lemonchiffon": "#fffacd",
  25535. "lightblue": "#add8e6",
  25536. "lightcoral": "#f08080",
  25537. "lightcyan": "#e0ffff",
  25538. "lightgoldenrodyellow": "#fafad2",
  25539. "lightgrey": "#d3d3d3",
  25540. "lightgreen": "#90ee90",
  25541. "lightpink": "#ffb6c1",
  25542. "lightsalmon": "#ffa07a",
  25543. "lightseagreen": "#20b2aa",
  25544. "lightskyblue": "#87cefa",
  25545. "lightslategray": "#778899",
  25546. "lightsteelblue": "#b0c4de",
  25547. "lightyellow": "#ffffe0",
  25548. "lime": "#00ff00",
  25549. "limegreen": "#32cd32",
  25550. "linen": "#faf0e6",
  25551. "magenta": "#ff00ff",
  25552. "maroon": "#800000",
  25553. "mediumaquamarine": "#66cdaa",
  25554. "mediumblue": "#0000cd",
  25555. "mediumorchid": "#ba55d3",
  25556. "mediumpurple": "#9370d8",
  25557. "mediumseagreen": "#3cb371",
  25558. "mediumslateblue": "#7b68ee",
  25559. "mediumspringgreen": "#00fa9a",
  25560. "mediumturquoise": "#48d1cc",
  25561. "mediumvioletred": "#c71585",
  25562. "midnightblue": "#191970",
  25563. "mintcream": "#f5fffa",
  25564. "mistyrose": "#ffe4e1",
  25565. "moccasin": "#ffe4b5",
  25566. "navajowhite": "#ffdead",
  25567. "navy": "#000080",
  25568. "oldlace": "#fdf5e6",
  25569. "olive": "#808000",
  25570. "olivedrab": "#6b8e23",
  25571. "orange": "#ffa500",
  25572. "orangered": "#ff4500",
  25573. "orchid": "#da70d6",
  25574. "palegoldenrod": "#eee8aa",
  25575. "palegreen": "#98fb98",
  25576. "paleturquoise": "#afeeee",
  25577. "palevioletred": "#d87093",
  25578. "papayawhip": "#ffefd5",
  25579. "peachpuff": "#ffdab9",
  25580. "peru": "#cd853f",
  25581. "pink": "#ffc0cb",
  25582. "plum": "#dda0dd",
  25583. "powderblue": "#b0e0e6",
  25584. "purple": "#800080",
  25585. "rebeccapurple": "#663399",
  25586. "red": "#ff0000",
  25587. "rosybrown": "#bc8f8f",
  25588. "royalblue": "#4169e1",
  25589. "saddlebrown": "#8b4513",
  25590. "salmon": "#fa8072",
  25591. "sandybrown": "#f4a460",
  25592. "seagreen": "#2e8b57",
  25593. "seashell": "#fff5ee",
  25594. "sienna": "#a0522d",
  25595. "silver": "#c0c0c0",
  25596. "skyblue": "#87ceeb",
  25597. "slateblue": "#6a5acd",
  25598. "slategray": "#708090",
  25599. "snow": "#fffafa",
  25600. "springgreen": "#00ff7f",
  25601. "steelblue": "#4682b4",
  25602. "tan": "#d2b48c",
  25603. "teal": "#008080",
  25604. "thistle": "#d8bfd8",
  25605. "tomato": "#ff6347",
  25606. "turquoise": "#40e0d0",
  25607. "violet": "#ee82ee",
  25608. "wheat": "#f5deb3",
  25609. "white": "#ffffff",
  25610. "whitesmoke": "#f5f5f5",
  25611. "yellow": "#ffff00",
  25612. "yellowgreen": "#9acd32"
  25613. };
  25614. var _getHexColor = function _getHexColor(color) {
  25615. color = color.replace('color:', '').replace(';', '').replace(' ', '');
  25616. if (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(color)) {
  25617. return color;
  25618. } else if (namedColors[color]) {
  25619. return namedColors[color];
  25620. } else if (color.indexOf('rgb') === 0) {
  25621. var rgbArray = color.split(',');
  25622. var convertedColor = rgbArray.length < 3 ? null : '#' + [rgbArray[0], rgbArray[1], rgbArray[2]].map(function (x) {
  25623. var hex = parseInt(x.replace(/\D/g, ''), 10).toString(16);
  25624. return hex.length === 1 ? '0' + hex : hex;
  25625. }).join('');
  25626. return (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(convertedColor) ? convertedColor : null
  25627. );
  25628. } else {
  25629. return null;
  25630. }
  25631. };
  25632. var namedColors = exports.namedColors = _namedColors;
  25633. var getHexColor = exports.getHexColor = _getHexColor;
  25634. var detectColorsFromHTMLString = exports.detectColorsFromHTMLString = function detectColorsFromHTMLString(html) {
  25635. return typeof html !== 'string' ? [] : (html.match(/color:[^;]{3,24};/g) || []).map(getHexColor).filter(function (color) {
  25636. return color;
  25637. });
  25638. };
  25639. var detectColorsFromDraftState = exports.detectColorsFromDraftState = function detectColorsFromDraftState(draftState) {
  25640. var result = [];
  25641. if (!draftState || !draftState.blocks || !draftState.blocks.length) {
  25642. return result;
  25643. }
  25644. draftState.blocks.forEach(function (block) {
  25645. if (block && block.inlineStyleRanges && block.inlineStyleRanges.length) {
  25646. block.inlineStyleRanges.forEach(function (inlineStyle) {
  25647. if (inlineStyle.style && inlineStyle.style.indexOf('COLOR-') >= 0) {
  25648. result.push('#' + inlineStyle.style.split('COLOR-')[1]);
  25649. }
  25650. });
  25651. }
  25652. });
  25653. return result.filter(function (color) {
  25654. return color;
  25655. });
  25656. };
  25657. });
  25658. unwrapExports(color);
  25659. var color_1 = color.namedColors;
  25660. var color_2 = color.getHexColor;
  25661. var color_3 = color.detectColorsFromHTMLString;
  25662. var color_4 = color.detectColorsFromDraftState;
  25663. var dist$1 = createCommonjsModule(function (module, exports) {
  25664. Object.defineProperty(exports, "__esModule", {
  25665. value: true
  25666. });
  25667. exports.ColorUtils = exports.BaseUtils = exports.ContentUtils = undefined;
  25668. var _ContentUtils = _interopRequireWildcard(content);
  25669. var _BaseUtils = _interopRequireWildcard(base);
  25670. var _ColorUtils = _interopRequireWildcard(color);
  25671. 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; } }
  25672. var ContentUtils = exports.ContentUtils = _ContentUtils;
  25673. var BaseUtils = exports.BaseUtils = _BaseUtils;
  25674. var ColorUtils = exports.ColorUtils = _ColorUtils;
  25675. });
  25676. unwrapExports(dist$1);
  25677. var dist_1$1 = dist$1.ColorUtils;
  25678. var dist_2$1 = dist$1.BaseUtils;
  25679. var dist_3$1 = dist$1.ContentUtils;
  25680. var dist$2 = createCommonjsModule(function (module, exports) {
  25681. (function webpackUniversalModuleDefinition(root, factory) {
  25682. module.exports = factory(React);
  25683. })(window, function(__WEBPACK_EXTERNAL_MODULE__2__) {
  25684. return /******/ (function(modules) { // webpackBootstrap
  25685. /******/ // The module cache
  25686. /******/ var installedModules = {};
  25687. /******/
  25688. /******/ // The require function
  25689. /******/ function __webpack_require__(moduleId) {
  25690. /******/
  25691. /******/ // Check if module is in cache
  25692. /******/ if(installedModules[moduleId]) {
  25693. /******/ return installedModules[moduleId].exports;
  25694. /******/ }
  25695. /******/ // Create a new module (and put it into the cache)
  25696. /******/ var module = installedModules[moduleId] = {
  25697. /******/ i: moduleId,
  25698. /******/ l: false,
  25699. /******/ exports: {}
  25700. /******/ };
  25701. /******/
  25702. /******/ // Execute the module function
  25703. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  25704. /******/
  25705. /******/ // Flag the module as loaded
  25706. /******/ module.l = true;
  25707. /******/
  25708. /******/ // Return the exports of the module
  25709. /******/ return module.exports;
  25710. /******/ }
  25711. /******/
  25712. /******/
  25713. /******/ // expose the modules object (__webpack_modules__)
  25714. /******/ __webpack_require__.m = modules;
  25715. /******/
  25716. /******/ // expose the module cache
  25717. /******/ __webpack_require__.c = installedModules;
  25718. /******/
  25719. /******/ // define getter function for harmony exports
  25720. /******/ __webpack_require__.d = function(exports, name, getter) {
  25721. /******/ if(!__webpack_require__.o(exports, name)) {
  25722. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  25723. /******/ }
  25724. /******/ };
  25725. /******/
  25726. /******/ // define __esModule on exports
  25727. /******/ __webpack_require__.r = function(exports) {
  25728. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  25729. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  25730. /******/ }
  25731. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  25732. /******/ };
  25733. /******/
  25734. /******/ // create a fake namespace object
  25735. /******/ // mode & 1: value is a module id, require it
  25736. /******/ // mode & 2: merge all properties of value into the ns
  25737. /******/ // mode & 4: return value when already ns object
  25738. /******/ // mode & 8|1: behave like require
  25739. /******/ __webpack_require__.t = function(value, mode) {
  25740. /******/ if(mode & 1) value = __webpack_require__(value);
  25741. /******/ if(mode & 8) return value;
  25742. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  25743. /******/ var ns = Object.create(null);
  25744. /******/ __webpack_require__.r(ns);
  25745. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  25746. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  25747. /******/ return ns;
  25748. /******/ };
  25749. /******/
  25750. /******/ // getDefaultExport function for compatibility with non-harmony modules
  25751. /******/ __webpack_require__.n = function(module) {
  25752. /******/ var getter = module && module.__esModule ?
  25753. /******/ function getDefault() { return module['default']; } :
  25754. /******/ function getModuleExports() { return module; };
  25755. /******/ __webpack_require__.d(getter, 'a', getter);
  25756. /******/ return getter;
  25757. /******/ };
  25758. /******/
  25759. /******/ // Object.prototype.hasOwnProperty.call
  25760. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  25761. /******/
  25762. /******/ // __webpack_public_path__
  25763. /******/ __webpack_require__.p = "/";
  25764. /******/
  25765. /******/
  25766. /******/ // Load entry module and return exports
  25767. /******/ return __webpack_require__(__webpack_require__.s = 20);
  25768. /******/ })
  25769. /************************************************************************/
  25770. /******/ ([
  25771. /* 0 */
  25772. /***/ (function(module, exports, __webpack_require__) {
  25773. Object.defineProperty(exports, "__esModule", {
  25774. value: true
  25775. });
  25776. var compressImage = exports.compressImage = function compressImage(url) {
  25777. var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1280;
  25778. var height = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 800;
  25779. return new Promise(function (resolve, reject) {
  25780. var image = new Image();
  25781. image.src = url;
  25782. image.onerror = function (error) {
  25783. reject(error);
  25784. };
  25785. image.onload = function () {
  25786. try {
  25787. var compressCanvas = document.createElement('canvas');
  25788. var scale = this.width > width || this.height > height ? this.width > this.height ? width / this.width : height / this.height : 1;
  25789. compressCanvas.width = this.width * scale;
  25790. compressCanvas.height = this.height * scale;
  25791. var canvasContext = compressCanvas.getContext('2d');
  25792. canvasContext.drawImage(this, 0, 0, compressCanvas.width, compressCanvas.height);
  25793. resolve({
  25794. url: compressCanvas.toDataURL('image/png', 1),
  25795. width: compressCanvas.width,
  25796. height: compressCanvas.height
  25797. });
  25798. } catch (error) {
  25799. reject(error);
  25800. }
  25801. };
  25802. });
  25803. };
  25804. /***/ }),
  25805. /* 1 */
  25806. /***/ (function(module, exports, __webpack_require__) {
  25807. Object.defineProperty(exports, "__esModule", {
  25808. value: true
  25809. });
  25810. var UniqueIndex = exports.UniqueIndex = function UniqueIndex() {
  25811. if (isNaN(window.__BRAFT_MM_UNIQUE_INDEX__)) {
  25812. window.__BRAFT_MM_UNIQUE_INDEX__ = 1;
  25813. } else {
  25814. window.__BRAFT_MM_UNIQUE_INDEX__ += 1;
  25815. }
  25816. return window.__BRAFT_MM_UNIQUE_INDEX__;
  25817. };
  25818. /***/ }),
  25819. /* 2 */
  25820. /***/ (function(module, exports) {
  25821. module.exports = __WEBPACK_EXTERNAL_MODULE__2__;
  25822. /***/ }),
  25823. /* 3 */
  25824. /***/ (function(module, exports, __webpack_require__) {
  25825. Object.defineProperty(exports, "__esModule", {
  25826. value: true
  25827. });
  25828. exports.default = {
  25829. remove: 'Kaldır',
  25830. cancel: 'İptal',
  25831. confirm: 'Onayla',
  25832. insert: 'Seçilenleri ekle',
  25833. width: 'Genişlik',
  25834. height: 'Yükseklik',
  25835. image: 'Resim',
  25836. video: 'Görüntü',
  25837. audio: 'Ses',
  25838. embed: 'Nesne göm',
  25839. caption: 'Kitaplık',
  25840. dragTip: 'Tıkla ya da dosya sürükle',
  25841. dropTip: 'Yüklemek için sürükleyin',
  25842. selectAll: 'Tümünü seç',
  25843. deselect: 'Seçimi kaldır',
  25844. removeSelected: 'Seçilenleri kaldır',
  25845. externalInputPlaceHolder: 'Kaynak adı|Kaynak bağlantısı',
  25846. externalInputTip: 'Kaynak asını ve bağlantısını "|" ile ayırın ve Enter\' a basın.',
  25847. addLocalFile: 'Yerel\' den ekle',
  25848. addExternalSource: 'Harici kaynaktan ekle',
  25849. unnamedItem: 'Adlandırılmamış giriş',
  25850. confirmInsert: 'Seçilenleri ekle'
  25851. };
  25852. /***/ }),
  25853. /* 4 */
  25854. /***/ (function(module, exports, __webpack_require__) {
  25855. Object.defineProperty(exports, "__esModule", {
  25856. value: true
  25857. });
  25858. exports.default = {
  25859. remove: '削除する',
  25860. cancel: 'キャンセル',
  25861. confirm: '確認する',
  25862. insert: '選択したアイテムを挿入',
  25863. width: '幅',
  25864. height: '身長',
  25865. image: '絵',
  25866. video: 'ビデオ',
  25867. audio: '音声',
  25868. embed: '埋め込みメディア',
  25869. caption: 'メディアライブラリー',
  25870. dragTip: 'ファイルをこの位置までクリックまたはドラッグします',
  25871. dropTip: 'アップロードするマウスを放します',
  25872. selectAll: 'すべて選択',
  25873. deselect: '選択を解除',
  25874. removeSelected: '選択したアイテムを削除',
  25875. externalInputPlaceHolder: 'リソース名|リソースアドレス',
  25876. externalInputTip: 'リソース名とリソースアドレスは "|"で区切ります。',
  25877. addLocalFile: 'ローカルリソースを追加する',
  25878. addExternalSource: 'ネットワークリソースを追加する',
  25879. unnamedItem: '名前のないアイテム',
  25880. confirmInsert: '選択したアイテムを挿入'
  25881. };
  25882. /***/ }),
  25883. /* 5 */
  25884. /***/ (function(module, exports, __webpack_require__) {
  25885. Object.defineProperty(exports, "__esModule", {
  25886. value: true
  25887. });
  25888. exports.default = {
  25889. remove: '삭제',
  25890. cancel: '취소',
  25891. confirm: '확인',
  25892. insert: '선택한항목삽입',
  25893. width: '너비',
  25894. height: '높이',
  25895. image: '그림',
  25896. video: '비디오',
  25897. audio: '오디오',
  25898. embed: '임베디드미디어',
  25899. caption: '미디어라이브러리',
  25900. dragTip: '파일을 클릭하거나이 지점으로 드래그하십시오.',
  25901. dropTip: '업로드하려면마우스를놓으십시오.',
  25902. selectAll: '모두 선택',
  25903. deselect: '선택 취소',
  25904. removeSelected: '선택한 항목 삭제',
  25905. externalInputPlaceHolder: '리소스 이름 | 리소스 주소',
  25906. externalInputTip: '자원 이름과 자원 주소를 "|"',
  25907. addLocalFile: '로컬 리소스 추가',
  25908. addExternalSource: '네트워크 리소스 추가',
  25909. unnamedItem: '이름없는 항목',
  25910. confirmInsert: '선택한 항목 삽입'
  25911. };
  25912. /***/ }),
  25913. /* 6 */
  25914. /***/ (function(module, exports, __webpack_require__) {
  25915. Object.defineProperty(exports, "__esModule", {
  25916. value: true
  25917. });
  25918. exports.default = {
  25919. remove: 'Usuń',
  25920. cancel: 'Anuluj',
  25921. confirm: 'Potwierdź',
  25922. insert: 'Wstaw wybrane elementy',
  25923. width: 'Szerokość',
  25924. height: 'Wysokość',
  25925. image: 'Obraz',
  25926. video: 'Wideo',
  25927. audio: 'Dźwięk',
  25928. embed: 'Obiekt',
  25929. caption: 'Biblioteka mediów',
  25930. dragTip: 'Kliknij lub przenieś tu pliki',
  25931. dropTip: 'Upuść aby dodać plik',
  25932. selectAll: 'Zaznacz wszystko',
  25933. deselect: 'Odznacz',
  25934. removeSelected: 'Usuń wybrane',
  25935. externalInputPlaceHolder: 'Nazwa źródła|Adres URL',
  25936. externalInputTip: 'Oddziel nazwę i adres URL źródła z pomocą "|", Potwierdź Enter-em',
  25937. addLocalFile: 'Dodaj z komputera',
  25938. addExternalSource: 'Dodaj z Internetu',
  25939. unnamedItem: 'Bez nazwy',
  25940. confirmInsert: 'Dodaj wybrane elementy'
  25941. };
  25942. /***/ }),
  25943. /* 7 */
  25944. /***/ (function(module, exports, __webpack_require__) {
  25945. Object.defineProperty(exports, "__esModule", {
  25946. value: true
  25947. });
  25948. exports.default = {
  25949. remove: '删除',
  25950. cancel: '取消',
  25951. confirm: '确认',
  25952. insert: '插入所选项目',
  25953. width: '宽度',
  25954. height: '高度',
  25955. image: '图片',
  25956. video: '视频',
  25957. audio: '音频',
  25958. embed: '嵌入式媒体',
  25959. caption: '媒体库',
  25960. dragTip: '点击或拖动文件至此',
  25961. dropTip: '放开鼠标以上传',
  25962. selectAll: '选择全部',
  25963. deselect: '取消选择',
  25964. removeSelected: '删除选中项目',
  25965. externalInputPlaceHolder: '资源名称|资源地址',
  25966. externalInputTip: '使用“|”分隔资源名称和资源地址',
  25967. addLocalFile: '添加本地资源',
  25968. addExternalSource: '添加网络资源',
  25969. unnamedItem: '未命名项目',
  25970. confirmInsert: '插入选中项目'
  25971. };
  25972. /***/ }),
  25973. /* 8 */
  25974. /***/ (function(module, exports, __webpack_require__) {
  25975. Object.defineProperty(exports, "__esModule", {
  25976. value: true
  25977. });
  25978. exports.default = {
  25979. remove: '删除',
  25980. cancel: '取消',
  25981. confirm: '确认',
  25982. insert: '插入所选项目',
  25983. width: '宽度',
  25984. height: '高度',
  25985. image: '图片',
  25986. video: '视频',
  25987. audio: '音频',
  25988. embed: '嵌入式媒体',
  25989. caption: '媒体库',
  25990. dragTip: '点击或拖动文件至此',
  25991. dropTip: '放开鼠标以上传',
  25992. selectAll: '选择全部',
  25993. deselect: '取消选择',
  25994. removeSelected: '删除选中项目',
  25995. externalInputPlaceHolder: '资源名称|资源地址',
  25996. externalInputTip: '使用“|”分隔资源名称和资源地址',
  25997. addLocalFile: '添加本地资源',
  25998. addExternalSource: '添加网络资源',
  25999. unnamedItem: '未命名项目',
  26000. confirmInsert: '插入选中项目'
  26001. };
  26002. /***/ }),
  26003. /* 9 */
  26004. /***/ (function(module, exports, __webpack_require__) {
  26005. Object.defineProperty(exports, "__esModule", {
  26006. value: true
  26007. });
  26008. exports.default = {
  26009. remove: 'Remove',
  26010. cancel: 'Cancel',
  26011. confirm: 'Confirm',
  26012. insert: 'Insert Selected Items',
  26013. width: 'Width',
  26014. height: 'Height',
  26015. image: 'Image',
  26016. video: 'Video',
  26017. audio: 'Audio',
  26018. embed: 'Embed',
  26019. caption: 'Media Library',
  26020. dragTip: 'Click Or Drag Files Here',
  26021. dropTip: 'Drop To Upload',
  26022. selectAll: 'Select All',
  26023. deselect: 'Deselect',
  26024. removeSelected: 'Remove Selected Items',
  26025. externalInputPlaceHolder: 'Source Name|Source URL',
  26026. externalInputTip: 'Split source name and source URL with "|", confirm by hit Enter.',
  26027. addLocalFile: 'Add from local',
  26028. addExternalSource: 'Add from Internet',
  26029. unnamedItem: 'Unnamed Item',
  26030. confirmInsert: 'Insert selected items'
  26031. };
  26032. /***/ }),
  26033. /* 10 */
  26034. /***/ (function(module, exports, __webpack_require__) {
  26035. Object.defineProperty(exports, "__esModule", {
  26036. value: true
  26037. });
  26038. var _en = __webpack_require__(9);
  26039. var _en2 = _interopRequireDefault(_en);
  26040. var _zh = __webpack_require__(8);
  26041. var _zh2 = _interopRequireDefault(_zh);
  26042. var _zhHant = __webpack_require__(7);
  26043. var _zhHant2 = _interopRequireDefault(_zhHant);
  26044. var _pl = __webpack_require__(6);
  26045. var _pl2 = _interopRequireDefault(_pl);
  26046. var _kr = __webpack_require__(5);
  26047. var _kr2 = _interopRequireDefault(_kr);
  26048. var _jpn = __webpack_require__(4);
  26049. var _jpn2 = _interopRequireDefault(_jpn);
  26050. var _tr = __webpack_require__(3);
  26051. var _tr2 = _interopRequireDefault(_tr);
  26052. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  26053. exports.default = {
  26054. "en": _en2.default,
  26055. "zh": _zh2.default,
  26056. "zh-hant": _zhHant2.default,
  26057. "pl": _pl2.default,
  26058. "kr": _kr2.default,
  26059. "jpn": _jpn2.default,
  26060. "tr": _tr2.default
  26061. };
  26062. /***/ }),
  26063. /* 11 */
  26064. /***/ (function(module, exports) {
  26065. /**
  26066. * When source maps are enabled, `style-loader` uses a link element with a data-uri to
  26067. * embed the css on the page. This breaks all relative urls because now they are relative to a
  26068. * bundle instead of the current page.
  26069. *
  26070. * One solution is to only use full urls, but that may be impossible.
  26071. *
  26072. * Instead, this function "fixes" the relative urls to be absolute according to the current page location.
  26073. *
  26074. * A rudimentary test suite is located at `test/fixUrls.js` and can be run via the `npm test` command.
  26075. *
  26076. */
  26077. module.exports = function (css) {
  26078. // get current location
  26079. var location = typeof window !== "undefined" && window.location;
  26080. if (!location) {
  26081. throw new Error("fixUrls requires window.location");
  26082. }
  26083. // blank or null?
  26084. if (!css || typeof css !== "string") {
  26085. return css;
  26086. }
  26087. var baseUrl = location.protocol + "//" + location.host;
  26088. var currentDir = baseUrl + location.pathname.replace(/\/[^\/]*$/, "/");
  26089. // convert each url(...)
  26090. /*
  26091. This regular expression is just a way to recursively match brackets within
  26092. a string.
  26093. /url\s*\( = Match on the word "url" with any whitespace after it and then a parens
  26094. ( = Start a capturing group
  26095. (?: = Start a non-capturing group
  26096. [^)(] = Match anything that isn't a parentheses
  26097. | = OR
  26098. \( = Match a start parentheses
  26099. (?: = Start another non-capturing groups
  26100. [^)(]+ = Match anything that isn't a parentheses
  26101. | = OR
  26102. \( = Match a start parentheses
  26103. [^)(]* = Match anything that isn't a parentheses
  26104. \) = Match a end parentheses
  26105. ) = End Group
  26106. *\) = Match anything and then a close parens
  26107. ) = Close non-capturing group
  26108. * = Match anything
  26109. ) = Close capturing group
  26110. \) = Match a close parens
  26111. /gi = Get all matches, not the first. Be case insensitive.
  26112. */
  26113. var fixedCss = css.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi, function(fullMatch, origUrl) {
  26114. // strip quotes (if they exist)
  26115. var unquotedOrigUrl = origUrl
  26116. .trim()
  26117. .replace(/^"(.*)"$/, function(o, $1){ return $1; })
  26118. .replace(/^'(.*)'$/, function(o, $1){ return $1; });
  26119. // already a full url? no change
  26120. if (/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(unquotedOrigUrl)) {
  26121. return fullMatch;
  26122. }
  26123. // convert the url to a full url
  26124. var newUrl;
  26125. if (unquotedOrigUrl.indexOf("//") === 0) {
  26126. //TODO: should we add protocol?
  26127. newUrl = unquotedOrigUrl;
  26128. } else if (unquotedOrigUrl.indexOf("/") === 0) {
  26129. // path should be relative to the base url
  26130. newUrl = baseUrl + unquotedOrigUrl; // already starts with '/'
  26131. } else {
  26132. // path should be relative to current directory
  26133. newUrl = currentDir + unquotedOrigUrl.replace(/^\.\//, ""); // Strip leading './'
  26134. }
  26135. // send back the fixed url(...)
  26136. return "url(" + JSON.stringify(newUrl) + ")";
  26137. });
  26138. // send back the fixed css
  26139. return fixedCss;
  26140. };
  26141. /***/ }),
  26142. /* 12 */
  26143. /***/ (function(module, exports, __webpack_require__) {
  26144. /*
  26145. MIT License http://www.opensource.org/licenses/mit-license.php
  26146. Author Tobias Koppers @sokra
  26147. */
  26148. var stylesInDom = {};
  26149. var memoize = function (fn) {
  26150. var memo;
  26151. return function () {
  26152. if (typeof memo === "undefined") memo = fn.apply(this, arguments);
  26153. return memo;
  26154. };
  26155. };
  26156. var isOldIE = memoize(function () {
  26157. // Test for IE <= 9 as proposed by Browserhacks
  26158. // @see http://browserhacks.com/#hack-e71d8692f65334173fee715c222cb805
  26159. // Tests for existence of standard globals is to allow style-loader
  26160. // to operate correctly into non-standard environments
  26161. // @see https://github.com/webpack-contrib/style-loader/issues/177
  26162. return window && document && document.all && !window.atob;
  26163. });
  26164. var getTarget = function (target) {
  26165. return document.querySelector(target);
  26166. };
  26167. var getElement = (function (fn) {
  26168. var memo = {};
  26169. return function(target) {
  26170. // If passing function in options, then use it for resolve "head" element.
  26171. // Useful for Shadow Root style i.e
  26172. // {
  26173. // insertInto: function () { return document.querySelector("#foo").shadowRoot }
  26174. // }
  26175. if (typeof target === 'function') {
  26176. return target();
  26177. }
  26178. if (typeof memo[target] === "undefined") {
  26179. var styleTarget = getTarget.call(this, target);
  26180. // Special case to return head of iframe instead of iframe itself
  26181. if (window.HTMLIFrameElement && styleTarget instanceof window.HTMLIFrameElement) {
  26182. try {
  26183. // This will throw an exception if access to iframe is blocked
  26184. // due to cross-origin restrictions
  26185. styleTarget = styleTarget.contentDocument.head;
  26186. } catch(e) {
  26187. styleTarget = null;
  26188. }
  26189. }
  26190. memo[target] = styleTarget;
  26191. }
  26192. return memo[target]
  26193. };
  26194. })();
  26195. var singleton = null;
  26196. var singletonCounter = 0;
  26197. var stylesInsertedAtTop = [];
  26198. var fixUrls = __webpack_require__(11);
  26199. module.exports = function(list, options) {
  26200. if (typeof DEBUG !== "undefined" && DEBUG) {
  26201. if (typeof document !== "object") throw new Error("The style-loader cannot be used in a non-browser environment");
  26202. }
  26203. options = options || {};
  26204. options.attrs = typeof options.attrs === "object" ? options.attrs : {};
  26205. // Force single-tag solution on IE6-9, which has a hard limit on the # of <style>
  26206. // tags it will allow on a page
  26207. if (!options.singleton && typeof options.singleton !== "boolean") options.singleton = isOldIE();
  26208. // By default, add <style> tags to the <head> element
  26209. if (!options.insertInto) options.insertInto = "head";
  26210. // By default, add <style> tags to the bottom of the target
  26211. if (!options.insertAt) options.insertAt = "bottom";
  26212. var styles = listToStyles(list, options);
  26213. addStylesToDom(styles, options);
  26214. return function update (newList) {
  26215. var mayRemove = [];
  26216. for (var i = 0; i < styles.length; i++) {
  26217. var item = styles[i];
  26218. var domStyle = stylesInDom[item.id];
  26219. domStyle.refs--;
  26220. mayRemove.push(domStyle);
  26221. }
  26222. if(newList) {
  26223. var newStyles = listToStyles(newList, options);
  26224. addStylesToDom(newStyles, options);
  26225. }
  26226. for (var i = 0; i < mayRemove.length; i++) {
  26227. var domStyle = mayRemove[i];
  26228. if(domStyle.refs === 0) {
  26229. for (var j = 0; j < domStyle.parts.length; j++) domStyle.parts[j]();
  26230. delete stylesInDom[domStyle.id];
  26231. }
  26232. }
  26233. };
  26234. };
  26235. function addStylesToDom (styles, options) {
  26236. for (var i = 0; i < styles.length; i++) {
  26237. var item = styles[i];
  26238. var domStyle = stylesInDom[item.id];
  26239. if(domStyle) {
  26240. domStyle.refs++;
  26241. for(var j = 0; j < domStyle.parts.length; j++) {
  26242. domStyle.parts[j](item.parts[j]);
  26243. }
  26244. for(; j < item.parts.length; j++) {
  26245. domStyle.parts.push(addStyle(item.parts[j], options));
  26246. }
  26247. } else {
  26248. var parts = [];
  26249. for(var j = 0; j < item.parts.length; j++) {
  26250. parts.push(addStyle(item.parts[j], options));
  26251. }
  26252. stylesInDom[item.id] = {id: item.id, refs: 1, parts: parts};
  26253. }
  26254. }
  26255. }
  26256. function listToStyles (list, options) {
  26257. var styles = [];
  26258. var newStyles = {};
  26259. for (var i = 0; i < list.length; i++) {
  26260. var item = list[i];
  26261. var id = options.base ? item[0] + options.base : item[0];
  26262. var css = item[1];
  26263. var media = item[2];
  26264. var sourceMap = item[3];
  26265. var part = {css: css, media: media, sourceMap: sourceMap};
  26266. if(!newStyles[id]) styles.push(newStyles[id] = {id: id, parts: [part]});
  26267. else newStyles[id].parts.push(part);
  26268. }
  26269. return styles;
  26270. }
  26271. function insertStyleElement (options, style) {
  26272. var target = getElement(options.insertInto);
  26273. if (!target) {
  26274. throw new Error("Couldn't find a style target. This probably means that the value for the 'insertInto' parameter is invalid.");
  26275. }
  26276. var lastStyleElementInsertedAtTop = stylesInsertedAtTop[stylesInsertedAtTop.length - 1];
  26277. if (options.insertAt === "top") {
  26278. if (!lastStyleElementInsertedAtTop) {
  26279. target.insertBefore(style, target.firstChild);
  26280. } else if (lastStyleElementInsertedAtTop.nextSibling) {
  26281. target.insertBefore(style, lastStyleElementInsertedAtTop.nextSibling);
  26282. } else {
  26283. target.appendChild(style);
  26284. }
  26285. stylesInsertedAtTop.push(style);
  26286. } else if (options.insertAt === "bottom") {
  26287. target.appendChild(style);
  26288. } else if (typeof options.insertAt === "object" && options.insertAt.before) {
  26289. var nextSibling = getElement(options.insertInto + " " + options.insertAt.before);
  26290. target.insertBefore(style, nextSibling);
  26291. } else {
  26292. 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");
  26293. }
  26294. }
  26295. function removeStyleElement (style) {
  26296. if (style.parentNode === null) return false;
  26297. style.parentNode.removeChild(style);
  26298. var idx = stylesInsertedAtTop.indexOf(style);
  26299. if(idx >= 0) {
  26300. stylesInsertedAtTop.splice(idx, 1);
  26301. }
  26302. }
  26303. function createStyleElement (options) {
  26304. var style = document.createElement("style");
  26305. if(options.attrs.type === undefined) {
  26306. options.attrs.type = "text/css";
  26307. }
  26308. addAttrs(style, options.attrs);
  26309. insertStyleElement(options, style);
  26310. return style;
  26311. }
  26312. function createLinkElement (options) {
  26313. var link = document.createElement("link");
  26314. if(options.attrs.type === undefined) {
  26315. options.attrs.type = "text/css";
  26316. }
  26317. options.attrs.rel = "stylesheet";
  26318. addAttrs(link, options.attrs);
  26319. insertStyleElement(options, link);
  26320. return link;
  26321. }
  26322. function addAttrs (el, attrs) {
  26323. Object.keys(attrs).forEach(function (key) {
  26324. el.setAttribute(key, attrs[key]);
  26325. });
  26326. }
  26327. function addStyle (obj, options) {
  26328. var style, update, remove, result;
  26329. // If a transform function was defined, run it on the css
  26330. if (options.transform && obj.css) {
  26331. result = options.transform(obj.css);
  26332. if (result) {
  26333. // If transform returns a value, use that instead of the original css.
  26334. // This allows running runtime transformations on the css.
  26335. obj.css = result;
  26336. } else {
  26337. // If the transform function returns a falsy value, don't add this css.
  26338. // This allows conditional loading of css
  26339. return function() {
  26340. // noop
  26341. };
  26342. }
  26343. }
  26344. if (options.singleton) {
  26345. var styleIndex = singletonCounter++;
  26346. style = singleton || (singleton = createStyleElement(options));
  26347. update = applyToSingletonTag.bind(null, style, styleIndex, false);
  26348. remove = applyToSingletonTag.bind(null, style, styleIndex, true);
  26349. } else if (
  26350. obj.sourceMap &&
  26351. typeof URL === "function" &&
  26352. typeof URL.createObjectURL === "function" &&
  26353. typeof URL.revokeObjectURL === "function" &&
  26354. typeof Blob === "function" &&
  26355. typeof btoa === "function"
  26356. ) {
  26357. style = createLinkElement(options);
  26358. update = updateLink.bind(null, style, options);
  26359. remove = function () {
  26360. removeStyleElement(style);
  26361. if(style.href) URL.revokeObjectURL(style.href);
  26362. };
  26363. } else {
  26364. style = createStyleElement(options);
  26365. update = applyToTag.bind(null, style);
  26366. remove = function () {
  26367. removeStyleElement(style);
  26368. };
  26369. }
  26370. update(obj);
  26371. return function updateStyle (newObj) {
  26372. if (newObj) {
  26373. if (
  26374. newObj.css === obj.css &&
  26375. newObj.media === obj.media &&
  26376. newObj.sourceMap === obj.sourceMap
  26377. ) {
  26378. return;
  26379. }
  26380. update(obj = newObj);
  26381. } else {
  26382. remove();
  26383. }
  26384. };
  26385. }
  26386. var replaceText = (function () {
  26387. var textStore = [];
  26388. return function (index, replacement) {
  26389. textStore[index] = replacement;
  26390. return textStore.filter(Boolean).join('\n');
  26391. };
  26392. })();
  26393. function applyToSingletonTag (style, index, remove, obj) {
  26394. var css = remove ? "" : obj.css;
  26395. if (style.styleSheet) {
  26396. style.styleSheet.cssText = replaceText(index, css);
  26397. } else {
  26398. var cssNode = document.createTextNode(css);
  26399. var childNodes = style.childNodes;
  26400. if (childNodes[index]) style.removeChild(childNodes[index]);
  26401. if (childNodes.length) {
  26402. style.insertBefore(cssNode, childNodes[index]);
  26403. } else {
  26404. style.appendChild(cssNode);
  26405. }
  26406. }
  26407. }
  26408. function applyToTag (style, obj) {
  26409. var css = obj.css;
  26410. var media = obj.media;
  26411. if(media) {
  26412. style.setAttribute("media", media);
  26413. }
  26414. if(style.styleSheet) {
  26415. style.styleSheet.cssText = css;
  26416. } else {
  26417. while(style.firstChild) {
  26418. style.removeChild(style.firstChild);
  26419. }
  26420. style.appendChild(document.createTextNode(css));
  26421. }
  26422. }
  26423. function updateLink (link, options, obj) {
  26424. var css = obj.css;
  26425. var sourceMap = obj.sourceMap;
  26426. /*
  26427. If convertToAbsoluteUrls isn't defined, but sourcemaps are enabled
  26428. and there is no publicPath defined then lets turn convertToAbsoluteUrls
  26429. on by default. Otherwise default to the convertToAbsoluteUrls option
  26430. directly
  26431. */
  26432. var autoFixUrls = options.convertToAbsoluteUrls === undefined && sourceMap;
  26433. if (options.convertToAbsoluteUrls || autoFixUrls) {
  26434. css = fixUrls(css);
  26435. }
  26436. if (sourceMap) {
  26437. // http://stackoverflow.com/a/26603875
  26438. css += "\n/*# sourceMappingURL=data:application/json;base64," + btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))) + " */";
  26439. }
  26440. var blob = new Blob([css], { type: "text/css" });
  26441. var oldSrc = link.href;
  26442. link.href = URL.createObjectURL(blob);
  26443. if(oldSrc) URL.revokeObjectURL(oldSrc);
  26444. }
  26445. /***/ }),
  26446. /* 13 */
  26447. /***/ (function(module, exports) {
  26448. 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=";
  26449. /***/ }),
  26450. /* 14 */
  26451. /***/ (function(module, exports) {
  26452. /*
  26453. MIT License http://www.opensource.org/licenses/mit-license.php
  26454. Author Tobias Koppers @sokra
  26455. */
  26456. // css base code, injected by the css-loader
  26457. module.exports = function(useSourceMap) {
  26458. var list = [];
  26459. // return the list of modules as css string
  26460. list.toString = function toString() {
  26461. return this.map(function (item) {
  26462. var content = cssWithMappingToString(item, useSourceMap);
  26463. if(item[2]) {
  26464. return "@media " + item[2] + "{" + content + "}";
  26465. } else {
  26466. return content;
  26467. }
  26468. }).join("");
  26469. };
  26470. // import a list of modules into the list
  26471. list.i = function(modules, mediaQuery) {
  26472. if(typeof modules === "string")
  26473. modules = [[null, modules, ""]];
  26474. var alreadyImportedModules = {};
  26475. for(var i = 0; i < this.length; i++) {
  26476. var id = this[i][0];
  26477. if(typeof id === "number")
  26478. alreadyImportedModules[id] = true;
  26479. }
  26480. for(i = 0; i < modules.length; i++) {
  26481. var item = modules[i];
  26482. // skip already imported module
  26483. // this implementation is not 100% perfect for weird media query combinations
  26484. // when a module is imported multiple times with different media queries.
  26485. // I hope this will never occur (Hey this way we have smaller bundles)
  26486. if(typeof item[0] !== "number" || !alreadyImportedModules[item[0]]) {
  26487. if(mediaQuery && !item[2]) {
  26488. item[2] = mediaQuery;
  26489. } else if(mediaQuery) {
  26490. item[2] = "(" + item[2] + ") and (" + mediaQuery + ")";
  26491. }
  26492. list.push(item);
  26493. }
  26494. }
  26495. };
  26496. return list;
  26497. };
  26498. function cssWithMappingToString(item, useSourceMap) {
  26499. var content = item[1] || '';
  26500. var cssMapping = item[3];
  26501. if (!cssMapping) {
  26502. return content;
  26503. }
  26504. if (useSourceMap && typeof btoa === 'function') {
  26505. var sourceMapping = toComment(cssMapping);
  26506. var sourceURLs = cssMapping.sources.map(function (source) {
  26507. return '/*# sourceURL=' + cssMapping.sourceRoot + source + ' */'
  26508. });
  26509. return [content].concat(sourceURLs).concat([sourceMapping]).join('\n');
  26510. }
  26511. return [content].join('\n');
  26512. }
  26513. // Adapted from convert-source-map (MIT)
  26514. function toComment(sourceMap) {
  26515. // eslint-disable-next-line no-undef
  26516. var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))));
  26517. var data = 'sourceMappingURL=data:application/json;charset=utf-8;base64,' + base64;
  26518. return '/*# ' + data + ' */';
  26519. }
  26520. /***/ }),
  26521. /* 15 */
  26522. /***/ (function(module, exports) {
  26523. module.exports = function escape(url) {
  26524. if (typeof url !== 'string') {
  26525. return url
  26526. }
  26527. // If url is already wrapped in quotes, remove them
  26528. if (/^['"].*['"]$/.test(url)) {
  26529. url = url.slice(1, -1);
  26530. }
  26531. // Should url be wrapped?
  26532. // See https://drafts.csswg.org/css-values-3/#urls
  26533. if (/["'() \t\n]/.test(url)) {
  26534. return '"' + url.replace(/"/g, '\\"').replace(/\n/g, '\\n') + '"'
  26535. }
  26536. return url
  26537. };
  26538. /***/ }),
  26539. /* 16 */
  26540. /***/ (function(module, exports, __webpack_require__) {
  26541. var escape = __webpack_require__(15);
  26542. exports = module.exports = __webpack_require__(14)(false);
  26543. // imports
  26544. // module
  26545. 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", ""]);
  26546. // exports
  26547. /***/ }),
  26548. /* 17 */
  26549. /***/ (function(module, exports, __webpack_require__) {
  26550. var content = __webpack_require__(16);
  26551. if(typeof content === 'string') content = [[module.i, content, '']];
  26552. var transform;
  26553. var options = {"hmr":true};
  26554. options.transform = transform;
  26555. options.insertInto = undefined;
  26556. var update = __webpack_require__(12)(content, options);
  26557. if(content.locals) module.exports = content.locals;
  26558. /***/ }),
  26559. /* 18 */
  26560. /***/ (function(module, exports, __webpack_require__) {
  26561. Object.defineProperty(exports, "__esModule", {
  26562. value: true
  26563. });
  26564. 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; };
  26565. 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; }; }();
  26566. __webpack_require__(17);
  26567. var _react = __webpack_require__(2);
  26568. var _react2 = _interopRequireDefault(_react);
  26569. var _base = __webpack_require__(1);
  26570. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  26571. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  26572. 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; }
  26573. 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; }
  26574. var defaultAccepts = {
  26575. image: 'image/png,image/jpeg,image/gif,image/webp,image/apng,image/svg',
  26576. video: 'video/mp4',
  26577. audio: 'audio/mp3'
  26578. };
  26579. var BraftFinderView = function (_React$Component) {
  26580. _inherits(BraftFinderView, _React$Component);
  26581. function BraftFinderView(props) {
  26582. _classCallCheck(this, BraftFinderView);
  26583. var _this = _possibleConstructorReturn(this, (BraftFinderView.__proto__ || Object.getPrototypeOf(BraftFinderView)).call(this, props));
  26584. _this.toggleSelectItem = function (event) {
  26585. var itemId = event.currentTarget.dataset.id;
  26586. var item = _this.controller.getMediaItem(itemId);
  26587. if (!item) {
  26588. return false;
  26589. }
  26590. if (item.selected) {
  26591. if (!_this.props.onBeforeDeselect || _this.props.onBeforeDeselect([item], _this.controller.getItems()) !== false) {
  26592. _this.controller.deselectMediaItem(itemId);
  26593. _this.props.onDeselect && _this.props.onDeselect([item], _this.controller.getItems());
  26594. }
  26595. } else {
  26596. if (!_this.props.onBeforeSelect || _this.props.onBeforeSelect([item], _this.controller.getItems()) !== false) {
  26597. _this.controller.selectMediaItem(itemId);
  26598. _this.props.onSelect && _this.props.onSelect([item], _this.controller.getItems());
  26599. }
  26600. }
  26601. };
  26602. _this.removeItem = function (event) {
  26603. var itemId = event.currentTarget.dataset.id;
  26604. var item = _this.controller.getMediaItem(itemId);
  26605. if (!item) {
  26606. return false;
  26607. }
  26608. if (!_this.props.onBeforeRemove || _this.props.onBeforeRemove([item], _this.controller.getItems()) !== false) {
  26609. _this.controller.removeMediaItem(itemId);
  26610. _this.props.onRemove && _this.props.onRemove([item], _this.controller.getItems());
  26611. }
  26612. event.stopPropagation();
  26613. };
  26614. _this.selectAllItems = function () {
  26615. var allItems = _this.controller.getItems();
  26616. if (!_this.props.onBeforeSelect || _this.props.onBeforeSelect(allItems, allItems) !== false) {
  26617. _this.controller.selectAllItems();
  26618. _this.props.onSelect && _this.props.onSelect(allItems, allItems);
  26619. }
  26620. };
  26621. _this.deselectAllItems = function () {
  26622. var allItems = _this.controller.getItems();
  26623. if (!_this.props.onBeforeDeselect || _this.props.onBeforeDeselect(allItems, allItems) !== false) {
  26624. _this.controller.deselectAllItems();
  26625. _this.props.onDeselect && _this.props.onDeselect(allItems, allItems);
  26626. }
  26627. };
  26628. _this.removeSelectedItems = function () {
  26629. var selectedItems = _this.controller.getSelectedItems();
  26630. if (!_this.props.onBeforeRemove || _this.props.onBeforeRemove(selectedItems, _this.controller.getItems()) !== false) {
  26631. _this.controller.removeSelectedItems();
  26632. _this.props.onRemove && _this.props.onRemove(selectedItems, _this.controller.getItems());
  26633. }
  26634. };
  26635. _this.handleDragLeave = function (event) {
  26636. event.preventDefault();
  26637. _this.dragCounter--;
  26638. _this.dragCounter === 0 && _this.setState({
  26639. draging: false
  26640. });
  26641. };
  26642. _this.handleDragDrop = function (event) {
  26643. event.preventDefault();
  26644. _this.dragCounter = 0;
  26645. _this.setState({ draging: false });
  26646. _this.reslovePickedFiles(event);
  26647. };
  26648. _this.handleDragEnter = function (event) {
  26649. event.preventDefault();
  26650. _this.dragCounter++;
  26651. _this.setState({ draging: true });
  26652. };
  26653. _this.reslovePickedFiles = function (event) {
  26654. event.persist();
  26655. var _ref = event.type === 'drop' ? event.dataTransfer : event.target,
  26656. files = _ref.files;
  26657. if (_this.props.onFileSelect) {
  26658. var result = _this.props.onFileSelect(files);
  26659. if (result === false) {
  26660. return false;
  26661. } else if (result instanceof FileList || result instanceof Array) {
  26662. files = result;
  26663. }
  26664. }
  26665. var accepts = _extends({}, defaultAccepts, _this.props.accepts);
  26666. _this.controller.resolveFiles({
  26667. files: files,
  26668. onItemReady: function onItemReady(_ref2) {
  26669. var id = _ref2.id;
  26670. return _this.controller.selectMediaItem(id);
  26671. },
  26672. onAllReady: function onAllReady() {
  26673. return event.target.value = null;
  26674. }
  26675. }, 0, accepts);
  26676. };
  26677. _this.inputExternal = function (event) {
  26678. _this.setState({
  26679. external: _extends({}, _this.state.external, {
  26680. url: event.target.value
  26681. })
  26682. });
  26683. };
  26684. _this.switchExternalType = function (event) {
  26685. _this.setState({
  26686. external: _extends({}, _this.state.external, { type: event.target.dataset.type })
  26687. });
  26688. };
  26689. _this.confirmAddExternal = function (event) {
  26690. if (event.target.nodeName.toLowerCase() === 'button' || event.keyCode === 13) {
  26691. var _this$state$external = _this.state.external,
  26692. url = _this$state$external.url,
  26693. type = _this$state$external.type;
  26694. url = url.split('|');
  26695. var name = url.length > 1 ? url[0] : _this.props.language.unnamedItem;
  26696. url = url.length > 1 ? url[1] : url[0];
  26697. var thumbnail = type === 'IMAGE' ? url : null;
  26698. _this.controller.addItems([{
  26699. thumbnail: thumbnail, url: url, name: name, type: type,
  26700. id: new Date().getTime() + '_' + (0, _base.UniqueIndex)(),
  26701. uploading: false,
  26702. uploadProgress: 1,
  26703. selected: true
  26704. }]);
  26705. _this.setState({
  26706. showExternalForm: false,
  26707. external: {
  26708. url: '',
  26709. type: 'IMAGE'
  26710. }
  26711. });
  26712. }
  26713. };
  26714. _this.toggleExternalForm = function () {
  26715. _this.setState({
  26716. showExternalForm: !_this.state.showExternalForm
  26717. });
  26718. };
  26719. _this.cancelInsert = function () {
  26720. _this.props.onCancel && _this.props.onCancel();
  26721. };
  26722. _this.confirmInsert = function () {
  26723. var selectedItems = _this.controller.getSelectedItems();
  26724. if (_this.props.onBeforeInsert) {
  26725. var filteredItems = _this.props.onBeforeInsert(selectedItems);
  26726. if (filteredItems && filteredItems instanceof Array) {
  26727. _this.controller.deselectAllItems();
  26728. _this.props.onInsert && _this.props.onInsert(filteredItems);
  26729. } else if (filteredItems !== false) {
  26730. _this.controller.deselectAllItems();
  26731. _this.props.onInsert && _this.props.onInsert(selectedItems);
  26732. }
  26733. } else {
  26734. _this.controller.deselectAllItems();
  26735. _this.props.onInsert && _this.props.onInsert(selectedItems);
  26736. }
  26737. };
  26738. _this.dragCounter = 0;
  26739. _this.controller = _this.props.controller;
  26740. var initialItems = _this.controller.getItems();
  26741. _this.state = {
  26742. draging: false,
  26743. error: false,
  26744. confirmable: initialItems.find(function (_ref3) {
  26745. var selected = _ref3.selected;
  26746. return selected;
  26747. }),
  26748. external: {
  26749. url: '',
  26750. type: 'IMAGE'
  26751. },
  26752. fileAccept: '',
  26753. showExternalForm: false,
  26754. allowExternal: false,
  26755. items: initialItems
  26756. };
  26757. _this.changeListenerId = _this.controller.onChange(function (items) {
  26758. _this.setState({ items: items, confirmable: items.find(function (_ref4) {
  26759. var selected = _ref4.selected;
  26760. return selected;
  26761. }) });
  26762. _this.props.onChange && _this.props.onChange(items);
  26763. });
  26764. return _this;
  26765. }
  26766. _createClass(BraftFinderView, [{
  26767. key: 'mapPropsToState',
  26768. value: function mapPropsToState(props) {
  26769. var accepts = props.accepts,
  26770. externals = props.externals;
  26771. accepts = _extends({}, defaultAccepts, accepts);
  26772. var fileAccept = !accepts ? [defaultAccepts.image, defaultAccepts.video, defaultAccepts.audio].join(',') : [accepts.image, accepts.video, accepts.audio].filter(function (item) {
  26773. return item;
  26774. }).join(',');
  26775. var external = {
  26776. url: '',
  26777. type: externals.image ? 'IMAGE' : externals.audio ? 'AUDIO' : externals.video ? 'VIDEO' : externals.embed ? 'EMBED' : ''
  26778. };
  26779. return {
  26780. fileAccept: fileAccept,
  26781. external: external,
  26782. allowExternal: externals && (externals.image || externals.audio || externals.video || externals.embed)
  26783. };
  26784. }
  26785. }, {
  26786. key: 'componentDidMount',
  26787. value: function componentDidMount() {
  26788. this.setState(this.mapPropsToState(this.props));
  26789. }
  26790. }, {
  26791. key: 'componentWillReceiveProps',
  26792. value: function componentWillReceiveProps(nextProps) {
  26793. this.setState(this.mapPropsToState(nextProps));
  26794. }
  26795. }, {
  26796. key: 'componentWillUnmount',
  26797. value: function componentWillUnmount() {
  26798. this.controller.offChange(this.changeListenerId);
  26799. }
  26800. }, {
  26801. key: 'render',
  26802. value: function render() {
  26803. var _props = this.props,
  26804. language = _props.language,
  26805. externals = _props.externals;
  26806. var _state = this.state,
  26807. items = _state.items,
  26808. draging = _state.draging,
  26809. confirmable = _state.confirmable,
  26810. fileAccept = _state.fileAccept,
  26811. external = _state.external,
  26812. showExternalForm = _state.showExternalForm,
  26813. allowExternal = _state.allowExternal;
  26814. return _react2.default.createElement(
  26815. 'div',
  26816. { className: 'braft-finder' },
  26817. _react2.default.createElement(
  26818. 'div',
  26819. {
  26820. onDragEnter: this.handleDragEnter,
  26821. onDragOver: this.handleDragEnter,
  26822. onDragLeave: this.handleDragLeave,
  26823. onDrop: this.handleDragDrop,
  26824. className: 'bf-uploader'
  26825. },
  26826. _react2.default.createElement(
  26827. 'div',
  26828. { className: "bf-drag-uploader " + (draging || !items.length ? 'active ' : ' ') + (draging ? 'draging' : '') },
  26829. _react2.default.createElement(
  26830. 'span',
  26831. { className: 'bf-drag-tip' },
  26832. _react2.default.createElement('input', { accept: fileAccept, onChange: this.reslovePickedFiles, multiple: true, type: 'file' }),
  26833. draging ? language.dropTip : language.dragTip
  26834. )
  26835. ),
  26836. items.length ? _react2.default.createElement(
  26837. 'div',
  26838. { className: 'bf-list-wrap' },
  26839. _react2.default.createElement(
  26840. 'div',
  26841. { className: 'bf-list-tools' },
  26842. _react2.default.createElement(
  26843. 'span',
  26844. { onClick: this.selectAllItems, className: 'bf-select-all' },
  26845. _react2.default.createElement('i', { className: 'braft-icon-done' }),
  26846. ' ',
  26847. language.selectAll
  26848. ),
  26849. _react2.default.createElement(
  26850. 'span',
  26851. { onClick: this.deselectAllItems, disabled: !confirmable, className: 'bf-deselect-all' },
  26852. _react2.default.createElement('i', { className: 'braft-icon-close' }),
  26853. ' ',
  26854. language.deselect
  26855. ),
  26856. _react2.default.createElement(
  26857. 'span',
  26858. { onClick: this.removeSelectedItems, disabled: !confirmable, className: 'bf-remove-selected' },
  26859. _react2.default.createElement('i', { className: 'braft-icon-bin' }),
  26860. ' ',
  26861. language.removeSelected
  26862. )
  26863. ),
  26864. this.buildItemList()
  26865. ) : null,
  26866. showExternalForm && allowExternal ? _react2.default.createElement(
  26867. 'div',
  26868. { className: 'bf-add-external' },
  26869. _react2.default.createElement(
  26870. 'div',
  26871. { className: 'bf-external-form' },
  26872. _react2.default.createElement(
  26873. 'div',
  26874. { className: 'bf-external-input' },
  26875. _react2.default.createElement(
  26876. 'div',
  26877. null,
  26878. _react2.default.createElement('input', { onKeyDown: this.confirmAddExternal, value: external.url, onChange: this.inputExternal, placeholder: language.externalInputPlaceHolder })
  26879. ),
  26880. _react2.default.createElement(
  26881. 'button',
  26882. { type: 'button', onClick: this.confirmAddExternal, disabled: !external.url.trim().length },
  26883. language.confirm
  26884. )
  26885. ),
  26886. _react2.default.createElement(
  26887. 'div',
  26888. { 'data-type': external.type, className: 'bf-switch-external-type' },
  26889. externals.image ? _react2.default.createElement(
  26890. 'button',
  26891. { type: 'button', onClick: this.switchExternalType, 'data-type': 'IMAGE' },
  26892. language.image
  26893. ) : null,
  26894. externals.audio ? _react2.default.createElement(
  26895. 'button',
  26896. { type: 'button', onClick: this.switchExternalType, 'data-type': 'AUDIO' },
  26897. language.audio
  26898. ) : null,
  26899. externals.video ? _react2.default.createElement(
  26900. 'button',
  26901. { type: 'button', onClick: this.switchExternalType, 'data-type': 'VIDEO' },
  26902. language.video
  26903. ) : null,
  26904. externals.embed ? _react2.default.createElement(
  26905. 'button',
  26906. { type: 'button', onClick: this.switchExternalType, 'data-type': 'EMBED' },
  26907. language.embed
  26908. ) : null
  26909. ),
  26910. _react2.default.createElement(
  26911. 'span',
  26912. { className: 'bf-external-tip' },
  26913. language.externalInputTip
  26914. )
  26915. )
  26916. ) : null
  26917. ),
  26918. _react2.default.createElement(
  26919. 'footer',
  26920. { className: 'bf-manager-footer' },
  26921. _react2.default.createElement(
  26922. 'div',
  26923. { className: 'pull-left' },
  26924. allowExternal ? _react2.default.createElement(
  26925. 'span',
  26926. {
  26927. onClick: this.toggleExternalForm,
  26928. className: 'bf-toggle-external-form'
  26929. },
  26930. showExternalForm ? _react2.default.createElement(
  26931. 'span',
  26932. { className: 'bf-bottom-text' },
  26933. _react2.default.createElement('i', { className: 'braft-icon-add' }),
  26934. ' ',
  26935. language.addLocalFile
  26936. ) : _react2.default.createElement(
  26937. 'span',
  26938. { className: 'bf-bottom-text' },
  26939. _react2.default.createElement('i', { className: 'braft-icon-add' }),
  26940. ' ',
  26941. language.addExternalSource
  26942. )
  26943. ) : null
  26944. ),
  26945. _react2.default.createElement(
  26946. 'div',
  26947. { className: 'pull-right' },
  26948. _react2.default.createElement(
  26949. 'button',
  26950. { onClick: this.confirmInsert, className: 'button button-insert', disabled: !confirmable },
  26951. language.insert
  26952. ),
  26953. _react2.default.createElement(
  26954. 'button',
  26955. { onClick: this.cancelInsert, className: 'button button-cancel' },
  26956. language.cancel
  26957. )
  26958. )
  26959. )
  26960. );
  26961. }
  26962. }, {
  26963. key: 'buildItemList',
  26964. value: function buildItemList() {
  26965. var _this2 = this;
  26966. return _react2.default.createElement(
  26967. 'ul',
  26968. { className: 'bf-list' },
  26969. _react2.default.createElement(
  26970. 'li',
  26971. { className: 'bf-add-item' },
  26972. _react2.default.createElement('i', { className: 'braft-icon-add' }),
  26973. _react2.default.createElement('input', { accept: this.state.fileAccept, onChange: this.reslovePickedFiles, multiple: true, type: 'file' })
  26974. ),
  26975. this.state.items.map(function (item, index) {
  26976. var previewerComponents = null;
  26977. var progressMarker = item.uploading && !_this2.props.hideProgress ? _react2.default.createElement(
  26978. 'div',
  26979. { className: 'bf-item-uploading' },
  26980. _react2.default.createElement('div', { className: 'bf-item-uploading-bar', style: { width: item.uploadProgress / 1 + '%' } })
  26981. ) : '';
  26982. switch (item.type) {
  26983. case 'IMAGE':
  26984. previewerComponents = _react2.default.createElement(
  26985. 'div',
  26986. { className: 'bf-image' },
  26987. progressMarker,
  26988. _react2.default.createElement('img', { src: item.thumbnail || item.url })
  26989. );
  26990. break;
  26991. case 'VIDEO':
  26992. previewerComponents = _react2.default.createElement(
  26993. 'div',
  26994. { className: 'bf-icon bf-video', title: item.url },
  26995. progressMarker,
  26996. _react2.default.createElement('i', { className: 'braft-icon-film' }),
  26997. _react2.default.createElement(
  26998. 'span',
  26999. null,
  27000. item.name || item.url
  27001. )
  27002. );
  27003. break;
  27004. case 'AUDIO':
  27005. previewerComponents = _react2.default.createElement(
  27006. 'div',
  27007. { className: 'bf-icon bf-audio', title: item.url },
  27008. progressMarker,
  27009. _react2.default.createElement('i', { className: 'braft-icon-music' }),
  27010. _react2.default.createElement(
  27011. 'span',
  27012. null,
  27013. item.name || item.url
  27014. )
  27015. );
  27016. break;
  27017. case 'EMBED':
  27018. previewerComponents = _react2.default.createElement(
  27019. 'div',
  27020. { className: 'bf-icon bf-embed', title: item.url },
  27021. progressMarker,
  27022. _react2.default.createElement('i', { className: 'braft-icon-code' }),
  27023. _react2.default.createElement(
  27024. 'span',
  27025. null,
  27026. item.name || _this2.props.language.embed
  27027. )
  27028. );
  27029. break;
  27030. default:
  27031. previewerComponents = _react2.default.createElement(
  27032. 'a',
  27033. { className: 'bf-icon bf-file', title: item.url, href: item.url },
  27034. progressMarker,
  27035. _react2.default.createElement('i', { className: 'braft-icon-file-text' }),
  27036. _react2.default.createElement(
  27037. 'span',
  27038. null,
  27039. item.name || item.url
  27040. )
  27041. );
  27042. break;
  27043. }
  27044. var className = ['bf-item'];
  27045. item.selected && className.push('active');
  27046. item.uploading && className.push('uploading');
  27047. item.error && className.push('error');
  27048. return _react2.default.createElement(
  27049. 'li',
  27050. {
  27051. key: index,
  27052. title: item.name,
  27053. 'data-id': item.id,
  27054. className: className.join(' '),
  27055. onClick: _this2.toggleSelectItem
  27056. },
  27057. previewerComponents,
  27058. _react2.default.createElement('span', { 'data-id': item.id, onClick: _this2.removeItem, className: 'bf-item-remove braft-icon-close' }),
  27059. _react2.default.createElement(
  27060. 'span',
  27061. { className: 'bf-item-title' },
  27062. item.name
  27063. )
  27064. );
  27065. })
  27066. );
  27067. }
  27068. }]);
  27069. return BraftFinderView;
  27070. }(_react2.default.Component);
  27071. BraftFinderView.defaultProps = {
  27072. accepts: defaultAccepts,
  27073. externals: {
  27074. image: true,
  27075. video: true,
  27076. audio: true,
  27077. embed: true
  27078. }
  27079. };
  27080. exports.default = BraftFinderView;
  27081. /***/ }),
  27082. /* 19 */
  27083. /***/ (function(module, exports, __webpack_require__) {
  27084. Object.defineProperty(exports, "__esModule", {
  27085. value: true
  27086. });
  27087. 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; };
  27088. var _base = __webpack_require__(1);
  27089. var _image = __webpack_require__(0);
  27090. 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); } }
  27091. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  27092. var defaultValidator = function defaultValidator() {
  27093. return true;
  27094. };
  27095. var BraftFinderController = function BraftFinderController() {
  27096. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  27097. _classCallCheck(this, BraftFinderController);
  27098. _initialiseProps.call(this);
  27099. this.items = props.items || [];
  27100. this.uploadFn = props.uploader;
  27101. this.validateFn = props.validator || defaultValidator;
  27102. this.changeListeners = [];
  27103. }
  27104. // resolvePastedFiles ({ clipboardData }, callback) {
  27105. // if (clipboardData && clipboardData.items && clipboardData.items[0].type.indexOf('image') > -1) {
  27106. // this.uploadImage(clipboardData.items[0].getAsFile(), callback)
  27107. // }
  27108. // }
  27109. ;
  27110. var _initialiseProps = function _initialiseProps() {
  27111. var _this = this;
  27112. this.setProps = function () {
  27113. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  27114. _this.items = props.items || _this.items || [];
  27115. _this.uploadFn = props.uploader;
  27116. _this.validateFn = props.validator || defaultValidator;
  27117. };
  27118. this.getMediaItem = function (id) {
  27119. return _this.items.find(function (item) {
  27120. return item.id === id;
  27121. });
  27122. };
  27123. this.getSelectedItems = function () {
  27124. return _this.items.filter(function (item) {
  27125. return item.selected;
  27126. });
  27127. };
  27128. this.getItems = function () {
  27129. return _this.items;
  27130. };
  27131. this.setItems = function (items) {
  27132. _this.items = items.map(function (item) {
  27133. return _extends({}, item, { id: item.id.toString() });
  27134. }) || [];
  27135. _this.applyChange();
  27136. _this.uploadItems();
  27137. };
  27138. this.addMediaItem = function (item) {
  27139. _this.addItems([item]);
  27140. };
  27141. this.addItems = function (items) {
  27142. _this.items = [].concat(_toConsumableArray(_this.items), _toConsumableArray(items.map(function (item) {
  27143. return _extends({}, item, { id: item.id.toString() });
  27144. })));
  27145. _this.applyChange();
  27146. _this.uploadItems();
  27147. };
  27148. this.selectMediaItem = function (id) {
  27149. var item = _this.getMediaItem(id);
  27150. if (item && (item.uploading || item.error)) {
  27151. return false;
  27152. }
  27153. _this.setMediaItemState(id, {
  27154. selected: true
  27155. });
  27156. };
  27157. this.selectAllItems = function () {
  27158. _this.items = _this.items.filter(function (item) {
  27159. return !item.error && !item.uploading;
  27160. }).map(function (item) {
  27161. return _extends({}, item, { selected: true });
  27162. });
  27163. _this.applyChange();
  27164. };
  27165. this.deselectMediaItem = function (id) {
  27166. _this.setMediaItemState(id, {
  27167. selected: false
  27168. });
  27169. };
  27170. this.deselectAllItems = function () {
  27171. _this.items = _this.items.map(function (item) {
  27172. return _extends({}, item, { selected: false });
  27173. });
  27174. _this.applyChange();
  27175. };
  27176. this.removeMediaItem = function (id) {
  27177. _this.items = _this.items.filter(function (item) {
  27178. return item.id !== id;
  27179. });
  27180. _this.applyChange();
  27181. };
  27182. this.removeItems = function () {
  27183. var ids = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  27184. _this.items = _this.items.filter(function (item) {
  27185. return !ids.includes(item.id);
  27186. });
  27187. _this.applyChange();
  27188. };
  27189. this.removeSelectedItems = function () {
  27190. _this.items = _this.items.filter(function (item) {
  27191. return !item.selected;
  27192. });
  27193. _this.applyChange();
  27194. };
  27195. this.removeErrorItems = function () {
  27196. _this.items = _this.items.filter(function (item) {
  27197. return !item.error;
  27198. });
  27199. _this.applyChange();
  27200. };
  27201. this.removeAllItems = function () {
  27202. _this.items = [];
  27203. _this.applyChange();
  27204. };
  27205. this.setMediaItemState = function (id, state) {
  27206. _this.items = _this.items.map(function (item) {
  27207. return item.id === id ? _extends({}, item, state) : item;
  27208. });
  27209. _this.applyChange();
  27210. };
  27211. this.reuploadErrorItems = function () {
  27212. _this.uploadItems(true);
  27213. };
  27214. this.uploadItems = function () {
  27215. var ignoreError = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  27216. _this.items.forEach(function (item, index) {
  27217. if (item.uploading || item.url) {
  27218. return false;
  27219. }
  27220. if (!ignoreError && item.error) {
  27221. return false;
  27222. }
  27223. if (item.type === 'IMAGE') {
  27224. _this.createThumbnail(item);
  27225. _this.uploadFn = _this.uploadFn || _this.createInlineImage;
  27226. } else if (!_this.uploadFn) {
  27227. _this.setMediaItemState(item.id, { error: 1 });
  27228. return false;
  27229. }
  27230. _this.setMediaItemState(item.id, {
  27231. uploading: true,
  27232. uploadProgress: 0,
  27233. error: 0
  27234. });
  27235. _this.uploadFn({
  27236. id: item.id,
  27237. file: item.file,
  27238. success: function success(res) {
  27239. _this.handleUploadSuccess(item.id, res);
  27240. },
  27241. progress: function progress(_progress) {
  27242. _this.setMediaItemState(item.id, {
  27243. uploading: true,
  27244. uploadProgress: _progress
  27245. });
  27246. },
  27247. error: function error(_error) {
  27248. _this.setMediaItemState(item.id, {
  27249. uploading: false,
  27250. error: 2
  27251. });
  27252. }
  27253. });
  27254. });
  27255. };
  27256. this.createThumbnail = function (_ref) {
  27257. var id = _ref.id,
  27258. file = _ref.file;
  27259. (0, _image.compressImage)(URL.createObjectURL(file), 226, 226).then(function (result) {
  27260. _this.setMediaItemState(id, { thumbnail: result.url });
  27261. });
  27262. };
  27263. this.createInlineImage = function (param) {
  27264. (0, _image.compressImage)(URL.createObjectURL(param.file), 1280, 800).then(function (result) {
  27265. param.success({ url: result.url });
  27266. }).catch(function (error) {
  27267. param.error(error);
  27268. });
  27269. };
  27270. this.handleUploadSuccess = function (id, data) {
  27271. _this.setMediaItemState(id, _extends({}, data, {
  27272. file: null,
  27273. uploadProgress: 1,
  27274. uploading: false,
  27275. selected: false
  27276. }));
  27277. var item = _this.getMediaItem(data.id || id);
  27278. item.onReady && item.onReady(item);
  27279. };
  27280. this.applyChange = function () {
  27281. _this.changeListeners.forEach(function (_ref2) {
  27282. var callback = _ref2.callback;
  27283. return callback(_this.items);
  27284. });
  27285. };
  27286. this.uploadImage = function (file, callback) {
  27287. var fileId = new Date().getTime() + '_' + (0, _base.UniqueIndex)();
  27288. _this.addMediaItem({
  27289. type: 'IMAGE',
  27290. id: fileId,
  27291. file: file,
  27292. name: fileId,
  27293. size: file.size,
  27294. uploadProgress: 0,
  27295. uploading: false,
  27296. selected: false,
  27297. error: 0,
  27298. onReady: callback
  27299. });
  27300. };
  27301. this.uploadImageRecursively = function (files, callback) {
  27302. var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  27303. if (files[index] && files[index].type.indexOf('image') > -1) {
  27304. _this.uploadImage(files[index], function (image) {
  27305. callback && callback(image);
  27306. index < files.length - 1 && _this.uploadImageRecursively(files, callback, index + 1);
  27307. });
  27308. } else {
  27309. index < files.length - 1 && _this.uploadImageRecursively(files, callback, index + 1);
  27310. }
  27311. };
  27312. this.addResolvedFiles = function (param, index, accepts) {
  27313. var data = {
  27314. id: new Date().getTime() + '_' + (0, _base.UniqueIndex)(),
  27315. file: param.files[index],
  27316. name: param.files[index].name,
  27317. size: param.files[index].size,
  27318. uploadProgress: 0,
  27319. uploading: false,
  27320. selected: false,
  27321. error: 0,
  27322. onReady: function onReady(item) {
  27323. param.onItemReady && param.onItemReady(item);
  27324. }
  27325. };
  27326. if (param.files[index].type.indexOf('image/') === 0 && accepts.image) {
  27327. data.type = 'IMAGE';
  27328. _this.addMediaItem(data);
  27329. } else if (param.files[index].type.indexOf('video/') === 0 && accepts.video) {
  27330. data.type = 'VIDEO';
  27331. _this.addMediaItem(data);
  27332. } else if (param.files[index].type.indexOf('audio/') === 0 && accepts.audio) {
  27333. data.type = 'AUDIO';
  27334. _this.addMediaItem(data);
  27335. }
  27336. setTimeout(function () {
  27337. _this.resolveFiles(param, index + 1, accepts);
  27338. }, 60);
  27339. };
  27340. this.resolveFiles = function (param, index, accepts) {
  27341. if (index < param.files.length) {
  27342. var validateResult = _this.validateFn(param.files[index]);
  27343. if (validateResult instanceof Promise) {
  27344. validateResult.then(function () {
  27345. _this.addResolvedFiles(param, index, accepts);
  27346. });
  27347. } else if (validateResult) {
  27348. _this.addResolvedFiles(param, index, accepts);
  27349. }
  27350. } else {
  27351. param.onAllReady && param.onAllReady();
  27352. }
  27353. };
  27354. this.onChange = function (callback) {
  27355. var listenerId = (0, _base.UniqueIndex)();
  27356. _this.changeListeners.push({
  27357. id: listenerId,
  27358. callback: callback
  27359. });
  27360. return listenerId;
  27361. };
  27362. this.offChange = function (listenerId) {
  27363. _this.changeListeners = _this.changeListeners.filter(function (_ref3) {
  27364. var id = _ref3.id;
  27365. return id !== listenerId;
  27366. });
  27367. };
  27368. };
  27369. exports.default = BraftFinderController;
  27370. /***/ }),
  27371. /* 20 */
  27372. /***/ (function(module, exports, __webpack_require__) {
  27373. Object.defineProperty(exports, "__esModule", {
  27374. value: true
  27375. });
  27376. exports.ImageUtils = undefined;
  27377. 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; };
  27378. var _react = __webpack_require__(2);
  27379. var _react2 = _interopRequireDefault(_react);
  27380. var _controller = __webpack_require__(19);
  27381. var _controller2 = _interopRequireDefault(_controller);
  27382. var _view = __webpack_require__(18);
  27383. var _view2 = _interopRequireDefault(_view);
  27384. var _languages = __webpack_require__(10);
  27385. var _languages2 = _interopRequireDefault(_languages);
  27386. var _image = __webpack_require__(0);
  27387. var ImageUtils = _interopRequireWildcard(_image);
  27388. 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; } }
  27389. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  27390. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  27391. 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; }
  27392. 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; }
  27393. var BraftFinder = function (_FinderController) {
  27394. _inherits(BraftFinder, _FinderController);
  27395. function BraftFinder(props) {
  27396. _classCallCheck(this, BraftFinder);
  27397. var _this = _possibleConstructorReturn(this, (BraftFinder.__proto__ || Object.getPrototypeOf(BraftFinder)).call(this, props));
  27398. _initialiseProps.call(_this);
  27399. _this.superProps = props;
  27400. return _this;
  27401. }
  27402. return BraftFinder;
  27403. }(_controller2.default);
  27404. var _initialiseProps = function _initialiseProps() {
  27405. var _this2 = this;
  27406. this.ReactComponent = function () {
  27407. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  27408. var componentProps = _extends({}, _this2.superProps, props);
  27409. var language = (typeof componentProps.language === 'function' ? componentProps.language(_languages2.default, 'braft-finder') : _languages2.default[componentProps.language]) || _languages2.default['zh'];
  27410. return _react2.default.createElement(_view2.default, _extends({}, componentProps, {
  27411. language: language,
  27412. controller: _this2
  27413. }));
  27414. };
  27415. };
  27416. exports.default = BraftFinder;
  27417. exports.ImageUtils = ImageUtils;
  27418. /***/ })
  27419. /******/ ]);
  27420. });
  27421. });
  27422. unwrapExports(dist$2);
  27423. var dist$3 = createCommonjsModule(function (module, exports) {
  27424. (function webpackUniversalModuleDefinition(root, factory) {
  27425. module.exports = factory(React, dist$1, Draft, immutable$1, dist, reactDom, dist$2, draftjsUtils);
  27426. })(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__) {
  27427. return /******/ (function(modules) { // webpackBootstrap
  27428. /******/ // The module cache
  27429. /******/ var installedModules = {};
  27430. /******/
  27431. /******/ // The require function
  27432. /******/ function __webpack_require__(moduleId) {
  27433. /******/
  27434. /******/ // Check if module is in cache
  27435. /******/ if(installedModules[moduleId]) {
  27436. /******/ return installedModules[moduleId].exports;
  27437. /******/ }
  27438. /******/ // Create a new module (and put it into the cache)
  27439. /******/ var module = installedModules[moduleId] = {
  27440. /******/ i: moduleId,
  27441. /******/ l: false,
  27442. /******/ exports: {}
  27443. /******/ };
  27444. /******/
  27445. /******/ // Execute the module function
  27446. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  27447. /******/
  27448. /******/ // Flag the module as loaded
  27449. /******/ module.l = true;
  27450. /******/
  27451. /******/ // Return the exports of the module
  27452. /******/ return module.exports;
  27453. /******/ }
  27454. /******/
  27455. /******/
  27456. /******/ // expose the modules object (__webpack_modules__)
  27457. /******/ __webpack_require__.m = modules;
  27458. /******/
  27459. /******/ // expose the module cache
  27460. /******/ __webpack_require__.c = installedModules;
  27461. /******/
  27462. /******/ // define getter function for harmony exports
  27463. /******/ __webpack_require__.d = function(exports, name, getter) {
  27464. /******/ if(!__webpack_require__.o(exports, name)) {
  27465. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  27466. /******/ }
  27467. /******/ };
  27468. /******/
  27469. /******/ // define __esModule on exports
  27470. /******/ __webpack_require__.r = function(exports) {
  27471. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  27472. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  27473. /******/ }
  27474. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  27475. /******/ };
  27476. /******/
  27477. /******/ // create a fake namespace object
  27478. /******/ // mode & 1: value is a module id, require it
  27479. /******/ // mode & 2: merge all properties of value into the ns
  27480. /******/ // mode & 4: return value when already ns object
  27481. /******/ // mode & 8|1: behave like require
  27482. /******/ __webpack_require__.t = function(value, mode) {
  27483. /******/ if(mode & 1) value = __webpack_require__(value);
  27484. /******/ if(mode & 8) return value;
  27485. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  27486. /******/ var ns = Object.create(null);
  27487. /******/ __webpack_require__.r(ns);
  27488. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  27489. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  27490. /******/ return ns;
  27491. /******/ };
  27492. /******/
  27493. /******/ // getDefaultExport function for compatibility with non-harmony modules
  27494. /******/ __webpack_require__.n = function(module) {
  27495. /******/ var getter = module && module.__esModule ?
  27496. /******/ function getDefault() { return module['default']; } :
  27497. /******/ function getModuleExports() { return module; };
  27498. /******/ __webpack_require__.d(getter, 'a', getter);
  27499. /******/ return getter;
  27500. /******/ };
  27501. /******/
  27502. /******/ // Object.prototype.hasOwnProperty.call
  27503. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  27504. /******/
  27505. /******/ // __webpack_public_path__
  27506. /******/ __webpack_require__.p = "/";
  27507. /******/
  27508. /******/
  27509. /******/ // Load entry module and return exports
  27510. /******/ return __webpack_require__(__webpack_require__.s = 39);
  27511. /******/ })
  27512. /************************************************************************/
  27513. /******/ ([
  27514. /* 0 */
  27515. /***/ (function(module, exports) {
  27516. module.exports = __WEBPACK_EXTERNAL_MODULE__0__;
  27517. /***/ }),
  27518. /* 1 */
  27519. /***/ (function(module, exports) {
  27520. function _assertThisInitialized(self) {
  27521. if (self === void 0) {
  27522. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  27523. }
  27524. return self;
  27525. }
  27526. module.exports = _assertThisInitialized;
  27527. /***/ }),
  27528. /* 2 */
  27529. /***/ (function(module, exports) {
  27530. function _defineProperty(obj, key, value) {
  27531. if (key in obj) {
  27532. Object.defineProperty(obj, key, {
  27533. value: value,
  27534. enumerable: true,
  27535. configurable: true,
  27536. writable: true
  27537. });
  27538. } else {
  27539. obj[key] = value;
  27540. }
  27541. return obj;
  27542. }
  27543. module.exports = _defineProperty;
  27544. /***/ }),
  27545. /* 3 */
  27546. /***/ (function(module, exports) {
  27547. module.exports = __WEBPACK_EXTERNAL_MODULE__3__;
  27548. /***/ }),
  27549. /* 4 */
  27550. /***/ (function(module, exports) {
  27551. function _classCallCheck(instance, Constructor) {
  27552. if (!(instance instanceof Constructor)) {
  27553. throw new TypeError("Cannot call a class as a function");
  27554. }
  27555. }
  27556. module.exports = _classCallCheck;
  27557. /***/ }),
  27558. /* 5 */
  27559. /***/ (function(module, exports, __webpack_require__) {
  27560. var defineProperty = __webpack_require__(2);
  27561. function _objectSpread(target) {
  27562. for (var i = 1; i < arguments.length; i++) {
  27563. var source = arguments[i] != null ? arguments[i] : {};
  27564. var ownKeys = Object.keys(source);
  27565. if (typeof Object.getOwnPropertySymbols === 'function') {
  27566. ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
  27567. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  27568. }));
  27569. }
  27570. ownKeys.forEach(function (key) {
  27571. defineProperty(target, key, source[key]);
  27572. });
  27573. }
  27574. return target;
  27575. }
  27576. module.exports = _objectSpread;
  27577. /***/ }),
  27578. /* 6 */
  27579. /***/ (function(module, exports) {
  27580. module.exports = __WEBPACK_EXTERNAL_MODULE__6__;
  27581. /***/ }),
  27582. /* 7 */
  27583. /***/ (function(module, exports) {
  27584. function _defineProperties(target, props) {
  27585. for (var i = 0; i < props.length; i++) {
  27586. var descriptor = props[i];
  27587. descriptor.enumerable = descriptor.enumerable || false;
  27588. descriptor.configurable = true;
  27589. if ("value" in descriptor) descriptor.writable = true;
  27590. Object.defineProperty(target, descriptor.key, descriptor);
  27591. }
  27592. }
  27593. function _createClass(Constructor, protoProps, staticProps) {
  27594. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  27595. if (staticProps) _defineProperties(Constructor, staticProps);
  27596. return Constructor;
  27597. }
  27598. module.exports = _createClass;
  27599. /***/ }),
  27600. /* 8 */
  27601. /***/ (function(module, exports, __webpack_require__) {
  27602. var _typeof = __webpack_require__(15);
  27603. var assertThisInitialized = __webpack_require__(1);
  27604. function _possibleConstructorReturn(self, call) {
  27605. if (call && (_typeof(call) === "object" || typeof call === "function")) {
  27606. return call;
  27607. }
  27608. return assertThisInitialized(self);
  27609. }
  27610. module.exports = _possibleConstructorReturn;
  27611. /***/ }),
  27612. /* 9 */
  27613. /***/ (function(module, exports) {
  27614. function _getPrototypeOf(o) {
  27615. module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  27616. return o.__proto__ || Object.getPrototypeOf(o);
  27617. };
  27618. return _getPrototypeOf(o);
  27619. }
  27620. module.exports = _getPrototypeOf;
  27621. /***/ }),
  27622. /* 10 */
  27623. /***/ (function(module, exports, __webpack_require__) {
  27624. var setPrototypeOf = __webpack_require__(26);
  27625. function _inherits(subClass, superClass) {
  27626. if (typeof superClass !== "function" && superClass !== null) {
  27627. throw new TypeError("Super expression must either be null or a function");
  27628. }
  27629. subClass.prototype = Object.create(superClass && superClass.prototype, {
  27630. constructor: {
  27631. value: subClass,
  27632. writable: true,
  27633. configurable: true
  27634. }
  27635. });
  27636. if (superClass) setPrototypeOf(subClass, superClass);
  27637. }
  27638. module.exports = _inherits;
  27639. /***/ }),
  27640. /* 11 */
  27641. /***/ (function(module, exports) {
  27642. function _extends() {
  27643. module.exports = _extends = Object.assign || function (target) {
  27644. for (var i = 1; i < arguments.length; i++) {
  27645. var source = arguments[i];
  27646. for (var key in source) {
  27647. if (Object.prototype.hasOwnProperty.call(source, key)) {
  27648. target[key] = source[key];
  27649. }
  27650. }
  27651. }
  27652. return target;
  27653. };
  27654. return _extends.apply(this, arguments);
  27655. }
  27656. module.exports = _extends;
  27657. /***/ }),
  27658. /* 12 */
  27659. /***/ (function(module, exports, __webpack_require__) {
  27660. var arrayWithoutHoles = __webpack_require__(27);
  27661. var iterableToArray = __webpack_require__(28);
  27662. var nonIterableSpread = __webpack_require__(29);
  27663. function _toConsumableArray(arr) {
  27664. return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread();
  27665. }
  27666. module.exports = _toConsumableArray;
  27667. /***/ }),
  27668. /* 13 */
  27669. /***/ (function(module, exports) {
  27670. module.exports = __WEBPACK_EXTERNAL_MODULE__13__;
  27671. /***/ }),
  27672. /* 14 */
  27673. /***/ (function(module, exports) {
  27674. module.exports = __WEBPACK_EXTERNAL_MODULE__14__;
  27675. /***/ }),
  27676. /* 15 */
  27677. /***/ (function(module, exports) {
  27678. 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); }
  27679. function _typeof(obj) {
  27680. if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") {
  27681. module.exports = _typeof = function _typeof(obj) {
  27682. return _typeof2(obj);
  27683. };
  27684. } else {
  27685. module.exports = _typeof = function _typeof(obj) {
  27686. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj);
  27687. };
  27688. }
  27689. return _typeof(obj);
  27690. }
  27691. module.exports = _typeof;
  27692. /***/ }),
  27693. /* 16 */
  27694. /***/ (function(module, exports) {
  27695. module.exports = __WEBPACK_EXTERNAL_MODULE__16__;
  27696. /***/ }),
  27697. /* 17 */
  27698. /***/ (function(module, exports) {
  27699. module.exports = __WEBPACK_EXTERNAL_MODULE__17__;
  27700. /***/ }),
  27701. /* 18 */
  27702. /***/ (function(module, exports, __webpack_require__) {
  27703. var Immutable = __webpack_require__(13);
  27704. var KEY_SEPARATOR = '-';
  27705. function MultiDecorator(decorators) {
  27706. this.decorators = Immutable.List(decorators);
  27707. }
  27708. /**
  27709. Return list of decoration IDs per character
  27710. @param {ContentBlock}
  27711. @return {List<String>}
  27712. */
  27713. MultiDecorator.prototype.getDecorations = function(block) {
  27714. var decorations = Array(block.getText().length).fill(null);
  27715. this.decorators.forEach(function(decorator, i) {
  27716. var _decorations = decorator.getDecorations(block);
  27717. _decorations.forEach(function(key, offset) {
  27718. if (!key) {
  27719. return;
  27720. }
  27721. key = i + KEY_SEPARATOR + key;
  27722. decorations[offset] = key;
  27723. });
  27724. });
  27725. return Immutable.List(decorations);
  27726. };
  27727. /**
  27728. Return component to render a decoration
  27729. @param {String}
  27730. @return {Function}
  27731. */
  27732. MultiDecorator.prototype.getComponentForKey = function(key) {
  27733. var decorator = this.getDecoratorForKey(key);
  27734. return decorator.getComponentForKey(
  27735. this.getInnerKey(key)
  27736. );
  27737. };
  27738. /**
  27739. Return props to render a decoration
  27740. @param {String}
  27741. @return {Object}
  27742. */
  27743. MultiDecorator.prototype.getPropsForKey = function(key) {
  27744. var decorator = this.getDecoratorForKey(key);
  27745. return decorator.getPropsForKey(
  27746. this.getInnerKey(key)
  27747. );
  27748. };
  27749. /**
  27750. Return a decorator for a specific key
  27751. @param {String}
  27752. @return {Decorator}
  27753. */
  27754. MultiDecorator.prototype.getDecoratorForKey = function(key) {
  27755. var parts = key.split(KEY_SEPARATOR);
  27756. var index = Number(parts[0]);
  27757. return this.decorators.get(index);
  27758. };
  27759. /**
  27760. Return inner key for a decorator
  27761. @param {String}
  27762. @return {String}
  27763. */
  27764. MultiDecorator.prototype.getInnerKey = function(key) {
  27765. var parts = key.split(KEY_SEPARATOR);
  27766. return parts.slice(1).join(KEY_SEPARATOR);
  27767. };
  27768. module.exports = MultiDecorator;
  27769. /***/ }),
  27770. /* 19 */
  27771. /***/ (function(module, exports, __webpack_require__) {
  27772. /**
  27773. * Copyright (c) 2013-present, Facebook, Inc.
  27774. * All rights reserved.
  27775. *
  27776. * This source code is licensed under the BSD-style license found in the
  27777. * LICENSE file in the root directory of this source tree. An additional grant
  27778. * of patent rights can be found in the PATENTS file in the same directory.
  27779. *
  27780. * @providesModule CharacterMetadata
  27781. * @format
  27782. *
  27783. */
  27784. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  27785. 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; }
  27786. 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; }
  27787. var _require = __webpack_require__(13),
  27788. Map = _require.Map,
  27789. OrderedSet = _require.OrderedSet,
  27790. Record = _require.Record;
  27791. // Immutable.map is typed such that the value for every key in the map
  27792. // must be the same type
  27793. var EMPTY_SET = OrderedSet();
  27794. var defaultRecord = {
  27795. style: EMPTY_SET,
  27796. entity: null
  27797. };
  27798. var CharacterMetadataRecord = Record(defaultRecord);
  27799. var CharacterMetadata = function (_CharacterMetadataRec) {
  27800. _inherits(CharacterMetadata, _CharacterMetadataRec);
  27801. function CharacterMetadata() {
  27802. _classCallCheck(this, CharacterMetadata);
  27803. return _possibleConstructorReturn(this, _CharacterMetadataRec.apply(this, arguments));
  27804. }
  27805. CharacterMetadata.prototype.getStyle = function getStyle() {
  27806. return this.get('style');
  27807. };
  27808. CharacterMetadata.prototype.getEntity = function getEntity() {
  27809. return this.get('entity');
  27810. };
  27811. CharacterMetadata.prototype.hasStyle = function hasStyle(style) {
  27812. return this.getStyle().includes(style);
  27813. };
  27814. CharacterMetadata.applyStyle = function applyStyle(record, style) {
  27815. var withStyle = record.set('style', record.getStyle().add(style));
  27816. return CharacterMetadata.create(withStyle);
  27817. };
  27818. CharacterMetadata.removeStyle = function removeStyle(record, style) {
  27819. var withoutStyle = record.set('style', record.getStyle().remove(style));
  27820. return CharacterMetadata.create(withoutStyle);
  27821. };
  27822. CharacterMetadata.applyEntity = function applyEntity(record, entityKey) {
  27823. var withEntity = record.getEntity() === entityKey ? record : record.set('entity', entityKey);
  27824. return CharacterMetadata.create(withEntity);
  27825. };
  27826. /**
  27827. * Use this function instead of the `CharacterMetadata` constructor.
  27828. * Since most content generally uses only a very small number of
  27829. * style/entity permutations, we can reuse these objects as often as
  27830. * possible.
  27831. */
  27832. CharacterMetadata.create = function create(config) {
  27833. if (!config) {
  27834. return EMPTY;
  27835. }
  27836. var defaultConfig = {
  27837. style: EMPTY_SET,
  27838. entity: null
  27839. };
  27840. // Fill in unspecified properties, if necessary.
  27841. var configMap = Map(defaultConfig).merge(config);
  27842. var existing = pool.get(configMap);
  27843. if (existing) {
  27844. return existing;
  27845. }
  27846. var newCharacter = new CharacterMetadata(configMap);
  27847. pool = pool.set(configMap, newCharacter);
  27848. return newCharacter;
  27849. };
  27850. return CharacterMetadata;
  27851. }(CharacterMetadataRecord);
  27852. var EMPTY = new CharacterMetadata();
  27853. var pool = Map([[Map(defaultRecord), EMPTY]]);
  27854. CharacterMetadata.EMPTY = EMPTY;
  27855. module.exports = CharacterMetadata;
  27856. /***/ }),
  27857. /* 20 */
  27858. /***/ (function(module, exports, __webpack_require__) {
  27859. /**
  27860. * Copyright (c) 2013-present, Facebook, Inc.
  27861. * All rights reserved.
  27862. *
  27863. * This source code is licensed under the BSD-style license found in the
  27864. * LICENSE file in the root directory of this source tree. An additional grant
  27865. * of patent rights can be found in the PATENTS file in the same directory.
  27866. *
  27867. * @providesModule findRangesImmutable
  27868. * @format
  27869. *
  27870. */
  27871. /**
  27872. * Search through an array to find contiguous stretches of elements that
  27873. * match a specified filter function.
  27874. *
  27875. * When ranges are found, execute a specified `found` function to supply
  27876. * the values to the caller.
  27877. */
  27878. function findRangesImmutable(haystack, areEqualFn, filterFn, foundFn) {
  27879. if (!haystack.size) {
  27880. return;
  27881. }
  27882. var cursor = 0;
  27883. haystack.reduce(function (value, nextValue, nextIndex) {
  27884. if (!areEqualFn(value, nextValue)) {
  27885. if (filterFn(value)) {
  27886. foundFn(cursor, nextIndex);
  27887. }
  27888. cursor = nextIndex;
  27889. }
  27890. return nextValue;
  27891. });
  27892. filterFn(haystack.last()) && foundFn(cursor, haystack.count());
  27893. }
  27894. module.exports = findRangesImmutable;
  27895. /***/ }),
  27896. /* 21 */
  27897. /***/ (function(module, exports, __webpack_require__) {
  27898. var objectWithoutPropertiesLoose = __webpack_require__(25);
  27899. function _objectWithoutProperties(source, excluded) {
  27900. if (source == null) return {};
  27901. var target = objectWithoutPropertiesLoose(source, excluded);
  27902. var key, i;
  27903. if (Object.getOwnPropertySymbols) {
  27904. var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
  27905. for (i = 0; i < sourceSymbolKeys.length; i++) {
  27906. key = sourceSymbolKeys[i];
  27907. if (excluded.indexOf(key) >= 0) continue;
  27908. if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
  27909. target[key] = source[key];
  27910. }
  27911. }
  27912. return target;
  27913. }
  27914. module.exports = _objectWithoutProperties;
  27915. /***/ }),
  27916. /* 22 */
  27917. /***/ (function(module, exports, __webpack_require__) {
  27918. /**
  27919. * Copyright (c) 2013-present, Facebook, Inc.
  27920. * All rights reserved.
  27921. *
  27922. * This source code is licensed under the BSD-style license found in the
  27923. * LICENSE file in the root directory of this source tree. An additional grant
  27924. * of patent rights can be found in the PATENTS file in the same directory.
  27925. *
  27926. * @providesModule getFragmentFromSelection
  27927. * @format
  27928. *
  27929. */
  27930. var getContentStateFragment = __webpack_require__(30);
  27931. function getFragmentFromSelection(editorState) {
  27932. var selectionState = editorState.getSelection();
  27933. if (selectionState.isCollapsed()) {
  27934. return null;
  27935. }
  27936. return getContentStateFragment(editorState.getCurrentContent(), selectionState);
  27937. }
  27938. module.exports = getFragmentFromSelection;
  27939. /***/ }),
  27940. /* 23 */
  27941. /***/ (function(module, exports) {
  27942. module.exports = __WEBPACK_EXTERNAL_MODULE__23__;
  27943. /***/ }),
  27944. /* 24 */
  27945. /***/ (function(module, exports, __webpack_require__) {
  27946. var arrayWithHoles = __webpack_require__(36);
  27947. var iterableToArrayLimit = __webpack_require__(37);
  27948. var nonIterableRest = __webpack_require__(38);
  27949. function _slicedToArray(arr, i) {
  27950. return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || nonIterableRest();
  27951. }
  27952. module.exports = _slicedToArray;
  27953. /***/ }),
  27954. /* 25 */
  27955. /***/ (function(module, exports) {
  27956. function _objectWithoutPropertiesLoose(source, excluded) {
  27957. if (source == null) return {};
  27958. var target = {};
  27959. var sourceKeys = Object.keys(source);
  27960. var key, i;
  27961. for (i = 0; i < sourceKeys.length; i++) {
  27962. key = sourceKeys[i];
  27963. if (excluded.indexOf(key) >= 0) continue;
  27964. target[key] = source[key];
  27965. }
  27966. return target;
  27967. }
  27968. module.exports = _objectWithoutPropertiesLoose;
  27969. /***/ }),
  27970. /* 26 */
  27971. /***/ (function(module, exports) {
  27972. function _setPrototypeOf(o, p) {
  27973. module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  27974. o.__proto__ = p;
  27975. return o;
  27976. };
  27977. return _setPrototypeOf(o, p);
  27978. }
  27979. module.exports = _setPrototypeOf;
  27980. /***/ }),
  27981. /* 27 */
  27982. /***/ (function(module, exports) {
  27983. function _arrayWithoutHoles(arr) {
  27984. if (Array.isArray(arr)) {
  27985. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
  27986. arr2[i] = arr[i];
  27987. }
  27988. return arr2;
  27989. }
  27990. }
  27991. module.exports = _arrayWithoutHoles;
  27992. /***/ }),
  27993. /* 28 */
  27994. /***/ (function(module, exports) {
  27995. function _iterableToArray(iter) {
  27996. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  27997. }
  27998. module.exports = _iterableToArray;
  27999. /***/ }),
  28000. /* 29 */
  28001. /***/ (function(module, exports) {
  28002. function _nonIterableSpread() {
  28003. throw new TypeError("Invalid attempt to spread non-iterable instance");
  28004. }
  28005. module.exports = _nonIterableSpread;
  28006. /***/ }),
  28007. /* 30 */
  28008. /***/ (function(module, exports, __webpack_require__) {
  28009. /**
  28010. * Copyright (c) 2013-present, Facebook, Inc.
  28011. * All rights reserved.
  28012. *
  28013. * This source code is licensed under the BSD-style license found in the
  28014. * LICENSE file in the root directory of this source tree. An additional grant
  28015. * of patent rights can be found in the PATENTS file in the same directory.
  28016. *
  28017. * @providesModule getContentStateFragment
  28018. * @format
  28019. *
  28020. */
  28021. var randomizeBlockMapKeys = __webpack_require__(31);
  28022. var removeEntitiesAtEdges = __webpack_require__(34);
  28023. var getContentStateFragment = function getContentStateFragment(contentState, selectionState) {
  28024. var startKey = selectionState.getStartKey();
  28025. var startOffset = selectionState.getStartOffset();
  28026. var endKey = selectionState.getEndKey();
  28027. var endOffset = selectionState.getEndOffset();
  28028. // Edge entities should be stripped to ensure that we don't preserve
  28029. // invalid partial entities when the fragment is reused. We do, however,
  28030. // preserve entities that are entirely within the selection range.
  28031. var contentWithoutEdgeEntities = removeEntitiesAtEdges(contentState, selectionState);
  28032. var blockMap = contentWithoutEdgeEntities.getBlockMap();
  28033. var blockKeys = blockMap.keySeq();
  28034. var startIndex = blockKeys.indexOf(startKey);
  28035. var endIndex = blockKeys.indexOf(endKey) + 1;
  28036. return randomizeBlockMapKeys(blockMap.slice(startIndex, endIndex).map(function (block, blockKey) {
  28037. var text = block.getText();
  28038. var chars = block.getCharacterList();
  28039. if (startKey === endKey) {
  28040. return block.merge({
  28041. text: text.slice(startOffset, endOffset),
  28042. characterList: chars.slice(startOffset, endOffset)
  28043. });
  28044. }
  28045. if (blockKey === startKey) {
  28046. return block.merge({
  28047. text: text.slice(startOffset),
  28048. characterList: chars.slice(startOffset)
  28049. });
  28050. }
  28051. if (blockKey === endKey) {
  28052. return block.merge({
  28053. text: text.slice(0, endOffset),
  28054. characterList: chars.slice(0, endOffset)
  28055. });
  28056. }
  28057. return block;
  28058. }));
  28059. };
  28060. module.exports = getContentStateFragment;
  28061. /***/ }),
  28062. /* 31 */
  28063. /***/ (function(module, exports, __webpack_require__) {
  28064. /**
  28065. * Copyright (c) 2013-present, Facebook, Inc.
  28066. * All rights reserved.
  28067. *
  28068. * This source code is licensed under the BSD-style license found in the
  28069. * LICENSE file in the root directory of this source tree. An additional grant
  28070. * of patent rights can be found in the PATENTS file in the same directory.
  28071. *
  28072. * @providesModule randomizeBlockMapKeys
  28073. * @format
  28074. *
  28075. */
  28076. var ContentBlockNode = __webpack_require__(32);
  28077. var Immutable = __webpack_require__(13);
  28078. var generateRandomKey = __webpack_require__(33);
  28079. var OrderedMap = Immutable.OrderedMap;
  28080. var randomizeContentBlockNodeKeys = function randomizeContentBlockNodeKeys(blockMap) {
  28081. var newKeysRef = {};
  28082. // we keep track of root blocks in order to update subsequent sibling links
  28083. var lastRootBlock = void 0;
  28084. return OrderedMap(blockMap.withMutations(function (blockMapState) {
  28085. blockMapState.forEach(function (block, index) {
  28086. var oldKey = block.getKey();
  28087. var nextKey = block.getNextSiblingKey();
  28088. var prevKey = block.getPrevSiblingKey();
  28089. var childrenKeys = block.getChildKeys();
  28090. var parentKey = block.getParentKey();
  28091. // new key that we will use to build linking
  28092. var key = generateRandomKey();
  28093. // we will add it here to re-use it later
  28094. newKeysRef[oldKey] = key;
  28095. if (nextKey) {
  28096. var nextBlock = blockMapState.get(nextKey);
  28097. if (nextBlock) {
  28098. blockMapState.setIn([nextKey, 'prevSibling'], key);
  28099. } else {
  28100. // this can happen when generating random keys for fragments
  28101. blockMapState.setIn([oldKey, 'nextSibling'], null);
  28102. }
  28103. }
  28104. if (prevKey) {
  28105. var prevBlock = blockMapState.get(prevKey);
  28106. if (prevBlock) {
  28107. blockMapState.setIn([prevKey, 'nextSibling'], key);
  28108. } else {
  28109. // this can happen when generating random keys for fragments
  28110. blockMapState.setIn([oldKey, 'prevSibling'], null);
  28111. }
  28112. }
  28113. if (parentKey && blockMapState.get(parentKey)) {
  28114. var parentBlock = blockMapState.get(parentKey);
  28115. var parentChildrenList = parentBlock.getChildKeys();
  28116. blockMapState.setIn([parentKey, 'children'], parentChildrenList.set(parentChildrenList.indexOf(block.getKey()), key));
  28117. } else {
  28118. // blocks will then be treated as root block nodes
  28119. blockMapState.setIn([oldKey, 'parent'], null);
  28120. if (lastRootBlock) {
  28121. blockMapState.setIn([lastRootBlock.getKey(), 'nextSibling'], key);
  28122. blockMapState.setIn([oldKey, 'prevSibling'], newKeysRef[lastRootBlock.getKey()]);
  28123. }
  28124. lastRootBlock = blockMapState.get(oldKey);
  28125. }
  28126. childrenKeys.forEach(function (childKey) {
  28127. var childBlock = blockMapState.get(childKey);
  28128. if (childBlock) {
  28129. blockMapState.setIn([childKey, 'parent'], key);
  28130. } else {
  28131. blockMapState.setIn([oldKey, 'children'], block.getChildKeys().filter(function (child) {
  28132. return child !== childKey;
  28133. }));
  28134. }
  28135. });
  28136. });
  28137. }).toArray().map(function (block) {
  28138. return [newKeysRef[block.getKey()], block.set('key', newKeysRef[block.getKey()])];
  28139. }));
  28140. };
  28141. var randomizeContentBlockKeys = function randomizeContentBlockKeys(blockMap) {
  28142. return OrderedMap(blockMap.toArray().map(function (block) {
  28143. var key = generateRandomKey();
  28144. return [key, block.set('key', key)];
  28145. }));
  28146. };
  28147. var randomizeBlockMapKeys = function randomizeBlockMapKeys(blockMap) {
  28148. var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode;
  28149. if (!isTreeBasedBlockMap) {
  28150. return randomizeContentBlockKeys(blockMap);
  28151. }
  28152. return randomizeContentBlockNodeKeys(blockMap);
  28153. };
  28154. module.exports = randomizeBlockMapKeys;
  28155. /***/ }),
  28156. /* 32 */
  28157. /***/ (function(module, exports, __webpack_require__) {
  28158. /**
  28159. * Copyright (c) 2013-present, Facebook, Inc.
  28160. * All rights reserved.
  28161. *
  28162. * This source code is licensed under the BSD-style license found in the
  28163. * LICENSE file in the root directory of this source tree. An additional grant
  28164. * of patent rights can be found in the PATENTS file in the same directory.
  28165. *
  28166. * @providesModule ContentBlockNode
  28167. * @format
  28168. *
  28169. *
  28170. * This file is a fork of ContentBlock adding support for nesting references by
  28171. * providing links to children, parent, prevSibling, and nextSibling.
  28172. *
  28173. * This is unstable and not part of the public API and should not be used by
  28174. * production systems. This file may be update/removed without notice.
  28175. */
  28176. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  28177. 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; }
  28178. 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; }
  28179. var CharacterMetadata = __webpack_require__(19);
  28180. var Immutable = __webpack_require__(13);
  28181. var findRangesImmutable = __webpack_require__(20);
  28182. var List = Immutable.List,
  28183. Map = Immutable.Map,
  28184. OrderedSet = Immutable.OrderedSet,
  28185. Record = Immutable.Record,
  28186. Repeat = Immutable.Repeat;
  28187. var EMPTY_SET = OrderedSet();
  28188. var defaultRecord = {
  28189. parent: null,
  28190. characterList: List(),
  28191. data: Map(),
  28192. depth: 0,
  28193. key: '',
  28194. text: '',
  28195. type: 'unstyled',
  28196. children: List(),
  28197. prevSibling: null,
  28198. nextSibling: null
  28199. };
  28200. var haveEqualStyle = function haveEqualStyle(charA, charB) {
  28201. return charA.getStyle() === charB.getStyle();
  28202. };
  28203. var haveEqualEntity = function haveEqualEntity(charA, charB) {
  28204. return charA.getEntity() === charB.getEntity();
  28205. };
  28206. var decorateCharacterList = function decorateCharacterList(config) {
  28207. if (!config) {
  28208. return config;
  28209. }
  28210. var characterList = config.characterList,
  28211. text = config.text;
  28212. if (text && !characterList) {
  28213. config.characterList = List(Repeat(CharacterMetadata.EMPTY, text.length));
  28214. }
  28215. return config;
  28216. };
  28217. var ContentBlockNode = function (_Record) {
  28218. _inherits(ContentBlockNode, _Record);
  28219. function ContentBlockNode() {
  28220. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultRecord;
  28221. _classCallCheck(this, ContentBlockNode);
  28222. return _possibleConstructorReturn(this, _Record.call(this, decorateCharacterList(props)));
  28223. }
  28224. ContentBlockNode.prototype.getKey = function getKey() {
  28225. return this.get('key');
  28226. };
  28227. ContentBlockNode.prototype.getType = function getType() {
  28228. return this.get('type');
  28229. };
  28230. ContentBlockNode.prototype.getText = function getText() {
  28231. return this.get('text');
  28232. };
  28233. ContentBlockNode.prototype.getCharacterList = function getCharacterList() {
  28234. return this.get('characterList');
  28235. };
  28236. ContentBlockNode.prototype.getLength = function getLength() {
  28237. return this.getText().length;
  28238. };
  28239. ContentBlockNode.prototype.getDepth = function getDepth() {
  28240. return this.get('depth');
  28241. };
  28242. ContentBlockNode.prototype.getData = function getData() {
  28243. return this.get('data');
  28244. };
  28245. ContentBlockNode.prototype.getInlineStyleAt = function getInlineStyleAt(offset) {
  28246. var character = this.getCharacterList().get(offset);
  28247. return character ? character.getStyle() : EMPTY_SET;
  28248. };
  28249. ContentBlockNode.prototype.getEntityAt = function getEntityAt(offset) {
  28250. var character = this.getCharacterList().get(offset);
  28251. return character ? character.getEntity() : null;
  28252. };
  28253. ContentBlockNode.prototype.getChildKeys = function getChildKeys() {
  28254. return this.get('children');
  28255. };
  28256. ContentBlockNode.prototype.getParentKey = function getParentKey() {
  28257. return this.get('parent');
  28258. };
  28259. ContentBlockNode.prototype.getPrevSiblingKey = function getPrevSiblingKey() {
  28260. return this.get('prevSibling');
  28261. };
  28262. ContentBlockNode.prototype.getNextSiblingKey = function getNextSiblingKey() {
  28263. return this.get('nextSibling');
  28264. };
  28265. ContentBlockNode.prototype.findStyleRanges = function findStyleRanges(filterFn, callback) {
  28266. findRangesImmutable(this.getCharacterList(), haveEqualStyle, filterFn, callback);
  28267. };
  28268. ContentBlockNode.prototype.findEntityRanges = function findEntityRanges(filterFn, callback) {
  28269. findRangesImmutable(this.getCharacterList(), haveEqualEntity, filterFn, callback);
  28270. };
  28271. return ContentBlockNode;
  28272. }(Record(defaultRecord));
  28273. module.exports = ContentBlockNode;
  28274. /***/ }),
  28275. /* 33 */
  28276. /***/ (function(module, exports, __webpack_require__) {
  28277. /**
  28278. * Copyright (c) 2013-present, Facebook, Inc.
  28279. * All rights reserved.
  28280. *
  28281. * This source code is licensed under the BSD-style license found in the
  28282. * LICENSE file in the root directory of this source tree. An additional grant
  28283. * of patent rights can be found in the PATENTS file in the same directory.
  28284. *
  28285. * @providesModule generateRandomKey
  28286. * @format
  28287. *
  28288. */
  28289. var seenKeys = {};
  28290. var MULTIPLIER = Math.pow(2, 24);
  28291. function generateRandomKey() {
  28292. var key = void 0;
  28293. while (key === undefined || seenKeys.hasOwnProperty(key) || !isNaN(+key)) {
  28294. key = Math.floor(Math.random() * MULTIPLIER).toString(32);
  28295. }
  28296. seenKeys[key] = true;
  28297. return key;
  28298. }
  28299. module.exports = generateRandomKey;
  28300. /***/ }),
  28301. /* 34 */
  28302. /***/ (function(module, exports, __webpack_require__) {
  28303. /**
  28304. * Copyright (c) 2013-present, Facebook, Inc.
  28305. * All rights reserved.
  28306. *
  28307. * This source code is licensed under the BSD-style license found in the
  28308. * LICENSE file in the root directory of this source tree. An additional grant
  28309. * of patent rights can be found in the PATENTS file in the same directory.
  28310. *
  28311. * @providesModule removeEntitiesAtEdges
  28312. * @format
  28313. *
  28314. */
  28315. var CharacterMetadata = __webpack_require__(19);
  28316. var findRangesImmutable = __webpack_require__(20);
  28317. var invariant = __webpack_require__(35);
  28318. function removeEntitiesAtEdges(contentState, selectionState) {
  28319. var blockMap = contentState.getBlockMap();
  28320. var entityMap = contentState.getEntityMap();
  28321. var updatedBlocks = {};
  28322. var startKey = selectionState.getStartKey();
  28323. var startOffset = selectionState.getStartOffset();
  28324. var startBlock = blockMap.get(startKey);
  28325. var updatedStart = removeForBlock(entityMap, startBlock, startOffset);
  28326. if (updatedStart !== startBlock) {
  28327. updatedBlocks[startKey] = updatedStart;
  28328. }
  28329. var endKey = selectionState.getEndKey();
  28330. var endOffset = selectionState.getEndOffset();
  28331. var endBlock = blockMap.get(endKey);
  28332. if (startKey === endKey) {
  28333. endBlock = updatedStart;
  28334. }
  28335. var updatedEnd = removeForBlock(entityMap, endBlock, endOffset);
  28336. if (updatedEnd !== endBlock) {
  28337. updatedBlocks[endKey] = updatedEnd;
  28338. }
  28339. if (!Object.keys(updatedBlocks).length) {
  28340. return contentState.set('selectionAfter', selectionState);
  28341. }
  28342. return contentState.merge({
  28343. blockMap: blockMap.merge(updatedBlocks),
  28344. selectionAfter: selectionState
  28345. });
  28346. }
  28347. function getRemovalRange(characters, key, offset) {
  28348. var removalRange;
  28349. findRangesImmutable(characters, function (a, b) {
  28350. return a.getEntity() === b.getEntity();
  28351. }, function (element) {
  28352. return element.getEntity() === key;
  28353. }, function (start, end) {
  28354. if (start <= offset && end >= offset) {
  28355. removalRange = { start: start, end: end };
  28356. }
  28357. });
  28358. !(typeof removalRange === 'object') ? invariant(false) : void 0;
  28359. return removalRange;
  28360. }
  28361. function removeForBlock(entityMap, block, offset) {
  28362. var chars = block.getCharacterList();
  28363. var charBefore = offset > 0 ? chars.get(offset - 1) : undefined;
  28364. var charAfter = offset < chars.count() ? chars.get(offset) : undefined;
  28365. var entityBeforeCursor = charBefore ? charBefore.getEntity() : undefined;
  28366. var entityAfterCursor = charAfter ? charAfter.getEntity() : undefined;
  28367. if (entityAfterCursor && entityAfterCursor === entityBeforeCursor) {
  28368. var entity = entityMap.__get(entityAfterCursor);
  28369. if (entity.getMutability() !== 'MUTABLE') {
  28370. var _getRemovalRange = getRemovalRange(chars, entityAfterCursor, offset),
  28371. start = _getRemovalRange.start,
  28372. end = _getRemovalRange.end;
  28373. var current;
  28374. while (start < end) {
  28375. current = chars.get(start);
  28376. chars = chars.set(start, CharacterMetadata.applyEntity(current, null));
  28377. start++;
  28378. }
  28379. return block.set('characterList', chars);
  28380. }
  28381. }
  28382. return block;
  28383. }
  28384. module.exports = removeEntitiesAtEdges;
  28385. /***/ }),
  28386. /* 35 */
  28387. /***/ (function(module, exports, __webpack_require__) {
  28388. function invariant(condition, format, a, b, c, d, e, f) {
  28389. if (!condition) {
  28390. var error;
  28391. if (format === undefined) {
  28392. error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
  28393. } else {
  28394. var args = [a, b, c, d, e, f];
  28395. var argIndex = 0;
  28396. error = new Error(format.replace(/%s/g, function () {
  28397. return args[argIndex++];
  28398. }));
  28399. error.name = 'Invariant Violation';
  28400. }
  28401. error.framesToPop = 1; // we don't care about invariant's own frame
  28402. throw error;
  28403. }
  28404. }
  28405. module.exports = invariant;
  28406. /***/ }),
  28407. /* 36 */
  28408. /***/ (function(module, exports) {
  28409. function _arrayWithHoles(arr) {
  28410. if (Array.isArray(arr)) return arr;
  28411. }
  28412. module.exports = _arrayWithHoles;
  28413. /***/ }),
  28414. /* 37 */
  28415. /***/ (function(module, exports) {
  28416. function _iterableToArrayLimit(arr, i) {
  28417. var _arr = [];
  28418. var _n = true;
  28419. var _d = false;
  28420. var _e = undefined;
  28421. try {
  28422. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  28423. _arr.push(_s.value);
  28424. if (i && _arr.length === i) break;
  28425. }
  28426. } catch (err) {
  28427. _d = true;
  28428. _e = err;
  28429. } finally {
  28430. try {
  28431. if (!_n && _i["return"] != null) _i["return"]();
  28432. } finally {
  28433. if (_d) throw _e;
  28434. }
  28435. }
  28436. return _arr;
  28437. }
  28438. module.exports = _iterableToArrayLimit;
  28439. /***/ }),
  28440. /* 38 */
  28441. /***/ (function(module, exports) {
  28442. function _nonIterableRest() {
  28443. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  28444. }
  28445. module.exports = _nonIterableRest;
  28446. /***/ }),
  28447. /* 39 */
  28448. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  28449. __webpack_require__.r(__webpack_exports__);
  28450. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/typeof.js
  28451. var helpers_typeof = __webpack_require__(15);
  28452. var typeof_default = /*#__PURE__*/__webpack_require__.n(helpers_typeof);
  28453. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/objectSpread.js
  28454. var objectSpread = __webpack_require__(5);
  28455. var objectSpread_default = /*#__PURE__*/__webpack_require__.n(objectSpread);
  28456. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/objectWithoutProperties.js
  28457. var objectWithoutProperties = __webpack_require__(21);
  28458. var objectWithoutProperties_default = /*#__PURE__*/__webpack_require__.n(objectWithoutProperties);
  28459. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/classCallCheck.js
  28460. var classCallCheck = __webpack_require__(4);
  28461. var classCallCheck_default = /*#__PURE__*/__webpack_require__.n(classCallCheck);
  28462. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/createClass.js
  28463. var createClass = __webpack_require__(7);
  28464. var createClass_default = /*#__PURE__*/__webpack_require__.n(createClass);
  28465. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js
  28466. var possibleConstructorReturn = __webpack_require__(8);
  28467. var possibleConstructorReturn_default = /*#__PURE__*/__webpack_require__.n(possibleConstructorReturn);
  28468. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/getPrototypeOf.js
  28469. var getPrototypeOf = __webpack_require__(9);
  28470. var getPrototypeOf_default = /*#__PURE__*/__webpack_require__.n(getPrototypeOf);
  28471. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/inherits.js
  28472. var inherits = __webpack_require__(10);
  28473. var inherits_default = /*#__PURE__*/__webpack_require__.n(inherits);
  28474. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/assertThisInitialized.js
  28475. var assertThisInitialized = __webpack_require__(1);
  28476. var assertThisInitialized_default = /*#__PURE__*/__webpack_require__.n(assertThisInitialized);
  28477. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/defineProperty.js
  28478. var defineProperty = __webpack_require__(2);
  28479. var defineProperty_default = /*#__PURE__*/__webpack_require__.n(defineProperty);
  28480. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/toConsumableArray.js
  28481. var toConsumableArray = __webpack_require__(12);
  28482. var toConsumableArray_default = /*#__PURE__*/__webpack_require__.n(toConsumableArray);
  28483. // EXTERNAL MODULE: ../node_modules/draft-js/dist/Draft.css
  28484. var Draft = __webpack_require__(40);
  28485. // EXTERNAL MODULE: ./assets/scss/_base.scss
  28486. var _base = __webpack_require__(42);
  28487. // EXTERNAL MODULE: external "react"
  28488. var external_react_ = __webpack_require__(0);
  28489. var external_react_default = /*#__PURE__*/__webpack_require__.n(external_react_);
  28490. // CONCATENATED MODULE: ./languages/en.js
  28491. /* harmony default export */ var en = ({
  28492. base: {
  28493. remove: 'Remove',
  28494. cancel: 'Cancel',
  28495. confirm: 'Confirm',
  28496. inert: 'Insert',
  28497. width: 'Width',
  28498. height: 'Height'
  28499. },
  28500. controls: {
  28501. clear: 'Clear',
  28502. undo: 'Undo',
  28503. redo: 'Redo',
  28504. fontSize: 'Font Size',
  28505. color: 'Color',
  28506. textColor: 'Text',
  28507. tempColors: 'Temp Colors',
  28508. backgroundColor: 'Background',
  28509. bold: 'Bold',
  28510. lineHeight: 'Line Height',
  28511. letterSpacing: 'Letter Spacing',
  28512. textIndent: 'Text Indent',
  28513. increaseIndent: 'Increase Indent',
  28514. decreaseIndent: 'Decrease Indent',
  28515. italic: 'Italic',
  28516. underline: 'Underline',
  28517. strikeThrough: 'Strike Through',
  28518. fontFamily: 'Font Family',
  28519. textAlign: 'Text Alignment',
  28520. alignLeft: 'Left Alignment',
  28521. alignCenter: 'Center Alignment',
  28522. alignRight: 'Right Alignment',
  28523. alignJustify: 'Justify Alignment',
  28524. floatLeft: 'Left Float',
  28525. floatRight: 'Right Float',
  28526. superScript: 'Super Script',
  28527. subScript: 'Sub Script',
  28528. removeStyles: 'Remove Styles',
  28529. headings: 'Headings',
  28530. header: 'Header',
  28531. normal: 'Normal',
  28532. orderedList: 'Ordered List',
  28533. unorderedList: 'Unordered List',
  28534. blockQuote: 'Quote',
  28535. code: 'Code',
  28536. link: 'Link',
  28537. unlink: 'Unlink',
  28538. hr: 'Horizontal Line',
  28539. media: 'Media',
  28540. mediaLibirary: 'Media Library',
  28541. emoji: 'Emoji',
  28542. fullscreen: 'Fullscreen',
  28543. exitFullscreen: 'Exit Fullscreen'
  28544. },
  28545. linkEditor: {
  28546. textInputPlaceHolder: 'Input link text',
  28547. linkInputPlaceHolder: 'Input link URL',
  28548. inputWithEnterPlaceHolder: 'Input link URL and press Enter',
  28549. openInNewWindow: 'Open in new window',
  28550. removeLink: 'Remove Link'
  28551. },
  28552. audioPlayer: {
  28553. title: 'Play Audio'
  28554. },
  28555. videoPlayer: {
  28556. title: 'Play Video',
  28557. embedTitle: 'Embed Media'
  28558. },
  28559. media: {
  28560. image: 'Image',
  28561. video: 'Video',
  28562. audio: 'Audio',
  28563. embed: 'Embed'
  28564. }
  28565. });
  28566. // CONCATENATED MODULE: ./languages/zh.js
  28567. /* harmony default export */ var zh = ({
  28568. base: {
  28569. remove: '删除',
  28570. cancel: '取消',
  28571. confirm: '确定',
  28572. inert: '插入',
  28573. width: '宽度',
  28574. height: '高度'
  28575. },
  28576. controls: {
  28577. clear: '清除内容',
  28578. undo: '撤销',
  28579. redo: '重做',
  28580. fontSize: '字号',
  28581. lineHeight: '行高',
  28582. letterSpacing: '字间距',
  28583. textIndent: '段落缩进',
  28584. increaseIndent: '增加缩进',
  28585. decreaseIndent: '减少缩进',
  28586. border: '边框',
  28587. color: '颜色',
  28588. textColor: '文字颜色',
  28589. backgroundColor: '背景颜色',
  28590. tempColors: '临时颜色',
  28591. bold: '加粗',
  28592. italic: '斜体',
  28593. underline: '下划线',
  28594. strikeThrough: '删除线',
  28595. fontFamily: '字体',
  28596. textAlign: '文本对齐',
  28597. alignLeft: '居左',
  28598. alignCenter: '居中',
  28599. alignRight: '居右',
  28600. alignJustify: '两端',
  28601. floatLeft: '左浮动',
  28602. floatRight: '右浮动',
  28603. superScript: '上标',
  28604. subScript: '下标',
  28605. removeStyles: '清除样式',
  28606. headings: '标题',
  28607. header: '标题',
  28608. normal: '常规',
  28609. orderedList: '有序列表',
  28610. unorderedList: '无序列表',
  28611. blockQuote: '引用',
  28612. code: '代码',
  28613. link: '链接',
  28614. unlink: '清除链接',
  28615. hr: '水平线',
  28616. media: '媒体',
  28617. mediaLibirary: '媒体库',
  28618. emoji: '小表情',
  28619. fullscreen: '全屏',
  28620. exitFullscreen: '退出全屏'
  28621. },
  28622. linkEditor: {
  28623. textInputPlaceHolder: '输入链接文字',
  28624. linkInputPlaceHolder: '输入链接地址',
  28625. inputWithEnterPlaceHolder: '输入链接地址并回车',
  28626. openInNewWindow: '在新窗口打开',
  28627. removeLink: '移除链接'
  28628. },
  28629. audioPlayer: {
  28630. title: '播放音频文件'
  28631. },
  28632. videoPlayer: {
  28633. title: '播放视频文件',
  28634. embedTitle: '嵌入式媒体'
  28635. },
  28636. media: {
  28637. image: '图像',
  28638. video: '视频',
  28639. audio: '音频',
  28640. embed: '嵌入式媒体'
  28641. }
  28642. });
  28643. // CONCATENATED MODULE: ./languages/zh-hant.js
  28644. /* harmony default export */ var zh_hant = ({
  28645. base: {
  28646. remove: '刪除',
  28647. cancel: '取消',
  28648. confirm: '確定',
  28649. inert: '插入',
  28650. width: '宽度',
  28651. height: '高度'
  28652. },
  28653. controls: {
  28654. clear: '清除内容',
  28655. undo: '撤銷',
  28656. redo: '重做',
  28657. fontSize: '字號',
  28658. color: '顏色',
  28659. textColor: '文字顏色',
  28660. backgroundColor: '背景顏色',
  28661. tempColors: '臨時顏色',
  28662. bold: '加粗',
  28663. lineHeight: '行高',
  28664. letterSpacing: '字間距',
  28665. textIndent: '段落縮進',
  28666. increaseIndent: '增加縮進',
  28667. decreaseIndent: '减少縮進',
  28668. border: '邊框',
  28669. italic: '斜體',
  28670. underline: '下劃線',
  28671. strikeThrough: '刪除線',
  28672. fontFamily: '字體',
  28673. textAlign: '文本對齊',
  28674. alignLeft: '居左',
  28675. alignCenter: '居中',
  28676. alignRight: '居右',
  28677. alignJustify: '兩端對齊',
  28678. floatLeft: '左浮動',
  28679. floatRight: '右浮動',
  28680. superScript: '上標',
  28681. subScript: '下標',
  28682. removeStyles: '清除样式',
  28683. headings: '標題',
  28684. header: '標題',
  28685. normal: '常規',
  28686. orderedList: '有序列表',
  28687. unorderedList: '無序列表',
  28688. blockQuote: '引用',
  28689. code: '代碼',
  28690. link: '鏈接',
  28691. unlink: '清除鏈接',
  28692. hr: '水平线',
  28693. media: '媒體',
  28694. mediaLibirary: '媒體库',
  28695. emoji: '小表情',
  28696. fullscreen: '全熒幕',
  28697. exitFullscreen: '退出全熒幕'
  28698. },
  28699. linkEditor: {
  28700. textInputPlaceHolder: '輸入鏈接文字',
  28701. linkInputPlaceHolder: '輸入鏈接地址',
  28702. inputWithEnterPlaceHolder: '輸入鏈接地址並回車',
  28703. openInNewWindow: '在新窗口打開',
  28704. removeLink: '移除鏈接'
  28705. },
  28706. audioPlayer: {
  28707. title: '播放音頻文件'
  28708. },
  28709. videoPlayer: {
  28710. title: '播放視頻文件',
  28711. embedTitle: '嵌入式媒體'
  28712. },
  28713. media: {
  28714. image: '圖像',
  28715. video: '視頻',
  28716. audio: '音頻',
  28717. embed: '嵌入式媒體'
  28718. }
  28719. });
  28720. // CONCATENATED MODULE: ./languages/pl.js
  28721. /* harmony default export */ var pl = ({
  28722. base: {
  28723. remove: 'Usuń',
  28724. cancel: 'Anuluj',
  28725. confirm: 'Potwierdź',
  28726. inert: 'Wstaw',
  28727. width: 'Szerokość',
  28728. height: 'Wysokość'
  28729. },
  28730. controls: {
  28731. clear: 'Wyczyść',
  28732. undo: 'Cofnij',
  28733. redo: 'Przywróć',
  28734. fontSize: 'Wielkość',
  28735. color: 'Kolor',
  28736. textColor: 'Kolor tekstu',
  28737. tempColors: 'Kolory',
  28738. backgroundColor: 'Tło',
  28739. bold: 'Pogrubienie',
  28740. lineHeight: 'Wysokość linii',
  28741. letterSpacing: 'Odstęp znaków',
  28742. textIndent: 'Wcięcie tekstu',
  28743. increaseIndent: 'Zwiększ wcięcie',
  28744. decreaseIndent: 'Zmniejsz wcięcie',
  28745. italic: 'Italiki',
  28746. underline: 'Podkreślenie',
  28747. strikeThrough: 'Przekreślenie',
  28748. fontFamily: 'Czcionka',
  28749. textAlign: 'Wyrównanie tekstu',
  28750. alignLeft: 'Do lewej',
  28751. alignCenter: 'Wycentruj',
  28752. alignRight: 'Do prawej',
  28753. alignJustify: 'Wyjustuj',
  28754. floatLeft: 'Do lewej',
  28755. floatRight: 'Do prawej',
  28756. superScript: 'Superskrypt',
  28757. subScript: 'Subskrypt',
  28758. removeStyles: 'Usuń stylowanie',
  28759. headings: 'Nagłówki',
  28760. header: 'Nagłówek',
  28761. normal: 'Normalny',
  28762. orderedList: 'Lista uporządkowana',
  28763. unorderedList: 'Lista nieuporządkowana',
  28764. blockQuote: 'Cytat',
  28765. code: 'Kod',
  28766. link: 'Link',
  28767. unlink: 'Usuń link',
  28768. hr: 'Linia pozioma',
  28769. media: 'Media',
  28770. mediaLibirary: 'Biblioteka mediów',
  28771. emoji: 'Emoji'
  28772. },
  28773. linkEditor: {
  28774. textInputPlaceHolder: 'Wpisz tekst linku',
  28775. linkInputPlaceHolder: 'Wpisz Adres URL',
  28776. inputWithEnterPlaceHolder: 'Wpisz adres URL i naciśnij Enter',
  28777. openInNewWindow: 'Otwórz w nowym oknie',
  28778. removeLink: 'Usuń link'
  28779. },
  28780. audioPlayer: {
  28781. title: 'Odtwórz audio'
  28782. },
  28783. videoPlayer: {
  28784. title: 'Odtwórz wideo',
  28785. embedTitle: 'Tytuł'
  28786. },
  28787. media: {
  28788. image: 'Obraz',
  28789. video: 'Wideo',
  28790. audio: 'Audio',
  28791. embed: 'Obiekt osadzony'
  28792. }
  28793. });
  28794. // CONCATENATED MODULE: ./languages/kr.js
  28795. /* harmony default export */ var kr = ({
  28796. base: {
  28797. remove: '삭제',
  28798. cancel: '취소',
  28799. confirm: '결정',
  28800. inert: '삽입',
  28801. width: '너비',
  28802. height: '높이'
  28803. },
  28804. controls: {
  28805. clear: '콘텐츠지우기',
  28806. undo: '취소',
  28807. redo: '다시하기',
  28808. fontSize: '글자크기',
  28809. lineHeight: '행높이',
  28810. letterSpacing: '단어간격',
  28811. textIndent: '단락들여쓰기',
  28812. increaseIndent: '들여쓰기늘리기',
  28813. decreaseIndent: '들여쓰기줄이기',
  28814. border: '국경',
  28815. color: '색상',
  28816. textColor: '텍스트색상',
  28817. backgroundColor: '배경색상',
  28818. tempColors: '임시색',
  28819. bold: '굵게',
  28820. italic: '기울임꼴',
  28821. underline: '밑줄',
  28822. strikeThrough: '취소선',
  28823. fontFamily: '글꼴',
  28824. textAlign: '텍스트정렬',
  28825. alignLeft: '왼쪽',
  28826. alignCenter: '중심',
  28827. alignRight: '오른쪽',
  28828. alignJustify: '양쪽끝',
  28829. floatLeft: '떠다니기',
  28830. floatRight: '오른쪽부동',
  28831. superScript: '위첨자',
  28832. subScript: '첨자',
  28833. removeStyles: '스타일지우기',
  28834. headings: '제목',
  28835. header: '제목',
  28836. normal: '재래식',
  28837. orderedList: '순서가지정된목록',
  28838. unorderedList: '정렬되지않은목록',
  28839. blockQuote: '참고문헌',
  28840. code: '코드',
  28841. link: '링크',
  28842. unlink: '링크삭제',
  28843. hr: '수평선',
  28844. media: '미디어',
  28845. mediaLibirary: '미디어라이브러리',
  28846. emoji: '작은표현',
  28847. fullscreen: '전체화면',
  28848. exitFullscreen: '전체화면종료'
  28849. },
  28850. linkEditor: {
  28851. textInputPlaceHolder: '링크텍스트입력',
  28852. linkInputPlaceHolder: '링크주소입력',
  28853. inputWithEnterPlaceHolder: '링크주소입력.',
  28854. openInNewWindow: '새창열기',
  28855. removeLink: '링크삭제'
  28856. },
  28857. audioPlayer: {
  28858. title: '오디오파일재생'
  28859. },
  28860. videoPlayer: {
  28861. title: '비디오파일재생',
  28862. embedTitle: '임베디드미디어'
  28863. },
  28864. media: {
  28865. image: '이미지',
  28866. video: '비디오',
  28867. audio: '오디오',
  28868. embed: '임베디드미디어'
  28869. }
  28870. });
  28871. // CONCATENATED MODULE: ./languages/tr.js
  28872. /* harmony default export */ var tr = ({
  28873. base: {
  28874. remove: 'Kaldır',
  28875. cancel: 'İptal',
  28876. confirm: 'Onayla',
  28877. inert: 'Ekle',
  28878. width: 'Genişlik',
  28879. height: 'Yükseklik'
  28880. },
  28881. controls: {
  28882. clear: 'Temizle',
  28883. undo: 'Geri al',
  28884. redo: 'İleri al',
  28885. fontSize: 'Yazı boyutu',
  28886. color: 'Renk',
  28887. textColor: 'Yazı rengi',
  28888. tempColors: 'Geçici renkler',
  28889. backgroundColor: 'Arkaplan',
  28890. bold: 'Kalın',
  28891. lineHeight: 'Satır yüksekliği',
  28892. letterSpacing: 'Harf aralığı',
  28893. textIndent: 'Çentik aralığı',
  28894. increaseIndent: 'Çentiği genişlet',
  28895. decreaseIndent: 'Çentiği daralt',
  28896. italic: 'Eğik',
  28897. underline: 'Altı çizili',
  28898. strikeThrough: 'Üstü çizili',
  28899. fontFamily: 'Yazı tipi',
  28900. textAlign: 'Metin Hizalama',
  28901. alignLeft: 'Sola hizala',
  28902. alignCenter: 'Ortaya hizala',
  28903. alignRight: 'Sağa hizala',
  28904. alignJustify: 'Her iki tarafa hizala',
  28905. floatLeft: 'Sola yatır',
  28906. floatRight: 'Sağa yatır',
  28907. superScript: 'Ana kod',
  28908. subScript: 'Alt kod',
  28909. removeStyles: 'Stilleri kaldır',
  28910. headings: 'Başlıklar',
  28911. header: 'Başlık',
  28912. normal: 'Normal',
  28913. orderedList: 'Sıralı liste',
  28914. unorderedList: 'Sırasız liste',
  28915. blockQuote: 'Alıntı',
  28916. code: 'Kod',
  28917. link: 'Bağlantı',
  28918. unlink: 'Bağlantıyı kaldır',
  28919. hr: 'Yatay çizgi',
  28920. media: 'Medya',
  28921. mediaLibirary: 'Kütüphane',
  28922. emoji: 'İfade',
  28923. fullscreen: 'Tam ekran',
  28924. exitFullscreen: 'Tam ekrandan çık'
  28925. },
  28926. linkEditor: {
  28927. textInputPlaceHolder: 'Bağlantı metnini girin',
  28928. linkInputPlaceHolder: 'Bağlantı URL\' si girin',
  28929. inputWithEnterPlaceHolder: 'Bağlantı URL\'si girin ve Enter\' a basın',
  28930. openInNewWindow: 'Yeni pencerede aç',
  28931. removeLink: 'Bağlantıyı kaldır'
  28932. },
  28933. audioPlayer: {
  28934. title: 'Ses çal'
  28935. },
  28936. videoPlayer: {
  28937. title: 'Görüntü oynat',
  28938. embedTitle: 'Görüntüyü göm'
  28939. },
  28940. media: {
  28941. image: 'Resim',
  28942. video: 'Görüntü',
  28943. audio: 'Ses',
  28944. embed: 'Gömülü nesne'
  28945. }
  28946. });
  28947. // CONCATENATED MODULE: ./languages/jpn.js
  28948. /* harmony default export */ var jpn = ({
  28949. base: {
  28950. remove: '削除',
  28951. cancel: 'キャンセル',
  28952. confirm: '決定',
  28953. inert: '挿入',
  28954. width: '幅',
  28955. height: '高さ'
  28956. },
  28957. controls: {
  28958. clear: 'クリアコンテンツ',
  28959. undo: 'キャンセル',
  28960. redo: 'キャンセル',
  28961. fontSize: 'フォントサイズ',
  28962. lineHeight: 'フォントサイズ',
  28963. letterSpacing: 'ワード間隔',
  28964. textIndent: '段落のインデント',
  28965. increaseIndent: 'インデントを増やす',
  28966. decreaseIndent: 'インデントを減らす',
  28967. border: '国境',
  28968. color: '色',
  28969. textColor: 'テキストの色',
  28970. backgroundColor: '背景色',
  28971. tempColors: '仮色',
  28972. bold: '太字',
  28973. italic: 'イタリック体',
  28974. underline: '下線',
  28975. strikeThrough: '取り消し線',
  28976. fontFamily: 'フォント',
  28977. textAlign: 'テキストの配置',
  28978. alignLeft: '左',
  28979. alignCenter: '中央揃え',
  28980. alignRight: '右に立つ',
  28981. alignJustify: '両端',
  28982. floatLeft: '左フローティング',
  28983. floatRight: '右フローティング',
  28984. superScript: '上付き',
  28985. subScript: '下付き文字',
  28986. removeStyles: 'クリアスタイル',
  28987. headings: '役職',
  28988. header: '役職',
  28989. normal: '従来の',
  28990. orderedList: '順序付きリスト',
  28991. unorderedList: '番号なしリスト',
  28992. blockQuote: '参照',
  28993. code: 'コード',
  28994. link: 'リンク',
  28995. unlink: 'リンクを解除',
  28996. hr: '横線',
  28997. media: 'メディア',
  28998. mediaLibirary: 'メディアライブラリー',
  28999. emoji: '小さな表現',
  29000. fullscreen: '全画面',
  29001. exitFullscreen: '全画面を退く'
  29002. },
  29003. linkEditor: {
  29004. textInputPlaceHolder: 'リンクテキストを入力',
  29005. linkInputPlaceHolder: 'リンクアドレスを入力',
  29006. inputWithEnterPlaceHolder: 'リンクアドレスを入力して戻ります',
  29007. openInNewWindow: '新しいウィンドウで開く',
  29008. removeLink: '新しいウィンドウで開く'
  29009. },
  29010. audioPlayer: {
  29011. title: 'オーディオファイルを再生する'
  29012. },
  29013. videoPlayer: {
  29014. title: 'ビデオファイルを再生する',
  29015. embedTitle: '埋め込みメディア'
  29016. },
  29017. media: {
  29018. image: '画像',
  29019. video: 'ビデオ',
  29020. audio: '音声',
  29021. embed: '埋め込みメディア'
  29022. }
  29023. });
  29024. // CONCATENATED MODULE: ./languages/ru.js
  29025. /* harmony default export */ var ru = ({
  29026. base: {
  29027. remove: 'Удалить',
  29028. cancel: 'Отмена',
  29029. confirm: 'Подтвердить',
  29030. insert: 'Вставить',
  29031. width: 'Ширина',
  29032. height: 'Высота'
  29033. },
  29034. controls: {
  29035. clear: 'Очистить',
  29036. undo: 'Отменить',
  29037. redo: 'Повторить',
  29038. fontSize: 'Размер шрифта',
  29039. color: 'Цвет',
  29040. textColor: 'Цвет текста',
  29041. tempColors: 'Temp Colors',
  29042. backgroundColor: 'Цвет фона',
  29043. bold: 'Жирный',
  29044. lineHeight: 'Межстрочный интервал',
  29045. letterSpacing: 'Межбуквенный интервал',
  29046. textIndent: 'Отступ',
  29047. increaseIndent: 'Увеличить отступ',
  29048. decreaseIndent: 'Уменьшить отступ',
  29049. italic: 'Курсив',
  29050. underline: 'Подчеркнутый',
  29051. strikeThrough: 'Перечеркнутый',
  29052. fontFamily: 'Шрифт',
  29053. textAlign: 'Расположение текста',
  29054. alignLeft: 'По левому краю',
  29055. alignCenter: 'По центру',
  29056. alignRight: 'По правому краю',
  29057. alignJustify: 'По ширине',
  29058. floatLeft: 'Обтекание слева',
  29059. floatRight: 'Обтекание справа',
  29060. superScript: 'Надстрочный индекс',
  29061. subScript: 'Подстрочный индекс',
  29062. removeStyles: 'Убрать стили',
  29063. headings: 'Заголовки',
  29064. header: 'Заголовок',
  29065. normal: 'Обычный',
  29066. orderedList: 'Упорядоченный список',
  29067. unorderedList: 'Неупорядоченный список',
  29068. blockQuote: 'Цитата',
  29069. code: 'Код',
  29070. link: 'Вставить ссылку',
  29071. unlink: 'Убрать ссылку',
  29072. hr: 'Горизонтальная линия',
  29073. media: 'Медиа',
  29074. mediaLibirary: 'Медиа библиотека',
  29075. emoji: 'Emoji',
  29076. fullscreen: 'Полноэкранный режим',
  29077. exitFullscreen: 'Выйти из полноэкранного режима'
  29078. },
  29079. linkEditor: {
  29080. textInputPlaceHolder: 'Введите текст ссылки',
  29081. linkInputPlaceHolder: 'Вставить ссылку',
  29082. inputWithEnterPlaceHolder: 'Вставить ссылку и нажать Enter',
  29083. openInNewWindow: 'Открыть в новом окне',
  29084. removeLink: 'Убрать ссылку'
  29085. },
  29086. audioPlayer: {
  29087. title: 'Воспроизвести аудиофайл'
  29088. },
  29089. videoPlayer: {
  29090. title: 'Воспроизвести видеофайл',
  29091. embedTitle: 'Embed Media'
  29092. },
  29093. media: {
  29094. image: 'Картинка',
  29095. video: 'Видео',
  29096. audio: 'Аудио',
  29097. embed: 'Встроенное'
  29098. }
  29099. });
  29100. // CONCATENATED MODULE: ./languages/fr.js
  29101. /* harmony default export */ var fr = ({
  29102. base: {
  29103. remove: 'Supprimer',
  29104. cancel: 'Annuler',
  29105. confirm: 'Confirmer',
  29106. inert: 'Insérer',
  29107. width: 'Largeur',
  29108. height: 'Hauteur'
  29109. },
  29110. controls: {
  29111. clear: 'Effacer',
  29112. undo: 'Annuler',
  29113. redo: 'Refaire',
  29114. fontSize: 'Taille de police',
  29115. color: 'Couleur',
  29116. textColor: 'Texte',
  29117. tempColors: 'Couleurs temporaire',
  29118. backgroundColor: 'Couleur d\'arrière plan',
  29119. bold: 'Gras',
  29120. lineHeight: 'Hauteur de ligne',
  29121. letterSpacing: 'Espacement des lettres',
  29122. textIndent: 'Indentation du texte',
  29123. increaseIndent: 'Augmenter l\'indentation',
  29124. decreaseIndent: 'Réduire l\'indentation',
  29125. italic: 'Italique',
  29126. underline: 'Souligner',
  29127. strikeThrough: 'Barrer',
  29128. fontFamily: 'Police d\'écriture',
  29129. textAlign: 'Alignement du texte',
  29130. alignLeft: 'Aligner à gauche',
  29131. alignCenter: 'Aligner au centre',
  29132. alignRight: 'Aligner à droite',
  29133. alignJustify: 'Justifier',
  29134. floatLeft: 'Déplacer à gauche',
  29135. floatRight: 'Déplacer à droite',
  29136. superScript: 'Super-script',
  29137. subScript: 'Sous-script',
  29138. removeStyles: 'Supprimer les styles',
  29139. headings: 'Titres',
  29140. header: 'Entêtes',
  29141. normal: 'Normal',
  29142. orderedList: 'Liste ordonnée',
  29143. unorderedList: 'Liste non-ordonnée',
  29144. blockQuote: 'Citation',
  29145. code: 'Code',
  29146. link: 'Insérer un lien',
  29147. unlink: 'Supprimer le lien',
  29148. hr: 'Ligne horizontale',
  29149. media: 'Média',
  29150. mediaLibirary: 'Bibliothêque',
  29151. emoji: 'Emoji',
  29152. fullscreen: 'Plein écran',
  29153. exitFullscreen: 'Quitter le plein écran'
  29154. },
  29155. linkEditor: {
  29156. textInputPlaceHolder: 'Insérer le texte à afficher',
  29157. linkInputPlaceHolder: 'Insérer le lien URL',
  29158. inputWithEnterPlaceHolder: 'Insérer le lien URL puis appuyer sur Entrée',
  29159. openInNewWindow: 'Ouvrir dans une nouvelle fenêtre',
  29160. removeLink: 'Supprimer le lien'
  29161. },
  29162. audioPlayer: {
  29163. title: 'Lancer le son audio'
  29164. },
  29165. videoPlayer: {
  29166. title: 'Lancer la video',
  29167. embedTitle: 'Intégrer média'
  29168. },
  29169. media: {
  29170. image: 'Image',
  29171. video: 'Vidéo',
  29172. audio: 'Audio',
  29173. embed: 'Intégré'
  29174. }
  29175. });
  29176. // CONCATENATED MODULE: ./languages/pt-br.js
  29177. /* harmony default export */ var pt_br = ({
  29178. base: {
  29179. remove: 'Remover',
  29180. cancel: 'Cancelar',
  29181. confirm: 'Confirmar',
  29182. inert: 'Inserir',
  29183. width: 'Largura',
  29184. height: 'Altura'
  29185. },
  29186. controls: {
  29187. clear: 'Limpar',
  29188. undo: 'Desfazer',
  29189. redo: 'Refazer',
  29190. fontSize: 'Tamanho da Fonte',
  29191. color: 'Cor',
  29192. textColor: 'Texto',
  29193. tempColors: 'Temp Colors',
  29194. backgroundColor: 'Cor de Fundo',
  29195. bold: 'Negrito',
  29196. lineHeight: 'Altura da LinhaLine Height',
  29197. letterSpacing: 'Espaçamento entre Letras',
  29198. textIndent: 'Identação de Texto',
  29199. increaseIndent: 'Aumentar Identação',
  29200. decreaseIndent: 'Diminuir Identção',
  29201. italic: 'Itálico',
  29202. underline: 'Sublinhado',
  29203. strikeThrough: 'Riscado',
  29204. fontFamily: 'Família da Fonte',
  29205. textAlign: 'Alinhamento de Texto',
  29206. alignLeft: 'Alinhamento à Esquerda',
  29207. alignCenter: 'Alinhamento Centralizado',
  29208. alignRight: 'Alinhamento à Direita',
  29209. alignJustify: 'Alinhamento Justificado',
  29210. floatLeft: 'Flutuação à Esquerda',
  29211. floatRight: 'Flutuação à Direita',
  29212. superScript: 'Sobrescrito',
  29213. subScript: 'Subscrito',
  29214. removeStyles: 'Remover Estilos',
  29215. headings: 'Cabeçalhos',
  29216. header: 'Cabeçalho',
  29217. normal: 'Normal',
  29218. orderedList: 'Lista Ordenada',
  29219. unorderedList: 'Lista Não Ordenada',
  29220. blockQuote: 'Citação',
  29221. code: 'Código',
  29222. link: 'Link',
  29223. unlink: 'Remover Link',
  29224. hr: 'Linha Horizontal',
  29225. media: 'Mídia',
  29226. mediaLibirary: 'Biblioteca de Mídia',
  29227. emoji: 'Emoji',
  29228. fullscreen: 'Tela Cheia',
  29229. exitFullscreen: 'Sair de Tela Cheia'
  29230. },
  29231. linkEditor: {
  29232. textInputPlaceHolder: 'Insira o texto do link',
  29233. linkInputPlaceHolder: 'Insira a URL do link',
  29234. inputWithEnterPlaceHolder: 'Insira a URL do link e aperte Enter',
  29235. openInNewWindow: 'Abrir em nova janela',
  29236. removeLink: 'Remover Link'
  29237. },
  29238. audioPlayer: {
  29239. title: 'Tocar Áudio'
  29240. },
  29241. videoPlayer: {
  29242. title: 'Tocar Vídeo',
  29243. embedTitle: 'Mídia Embutida'
  29244. },
  29245. media: {
  29246. image: 'Imagem',
  29247. video: 'Vídeo',
  29248. audio: 'Áudio',
  29249. embed: 'Embutido'
  29250. }
  29251. });
  29252. // CONCATENATED MODULE: ./languages/index.js
  29253. /* harmony default export */ var languages = ({
  29254. 'en': en,
  29255. 'zh': zh,
  29256. 'zh-hant': zh_hant,
  29257. 'pl': pl,
  29258. 'kr': kr,
  29259. 'tr': tr,
  29260. 'jpn': jpn,
  29261. 'ru': ru,
  29262. 'fr': fr,
  29263. 'pt-br': pt_br
  29264. });
  29265. // EXTERNAL MODULE: external "braft-finder"
  29266. var external_braft_finder_ = __webpack_require__(17);
  29267. var external_braft_finder_default = /*#__PURE__*/__webpack_require__.n(external_braft_finder_);
  29268. // EXTERNAL MODULE: external "braft-utils"
  29269. var external_braft_utils_ = __webpack_require__(3);
  29270. // EXTERNAL MODULE: external "draft-js"
  29271. var external_draft_js_ = __webpack_require__(6);
  29272. // EXTERNAL MODULE: external "immutable"
  29273. var external_immutable_ = __webpack_require__(13);
  29274. var external_immutable_default = /*#__PURE__*/__webpack_require__.n(external_immutable_);
  29275. // CONCATENATED MODULE: ./configs/keybindings.js
  29276. // TODO
  29277. // 允许自定义的快捷键设置
  29278. /* harmony default export */ var keybindings = (function (customKeyBindingFn) {
  29279. return function (event) {
  29280. if (event.keyCode === 83 && (external_draft_js_["KeyBindingUtil"].hasCommandModifier(event) || external_draft_js_["KeyBindingUtil"].isCtrlKeyCommand(event))) {
  29281. return 'braft-save';
  29282. }
  29283. if (customKeyBindingFn) {
  29284. return customKeyBindingFn(event) || Object(external_draft_js_["getDefaultKeyBinding"])(event);
  29285. }
  29286. return Object(external_draft_js_["getDefaultKeyBinding"])(event);
  29287. };
  29288. });
  29289. // CONCATENATED MODULE: ./configs/props.js
  29290. /* harmony default export */ var configs_props = ({
  29291. language: 'zh',
  29292. 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'],
  29293. excludeControls: [],
  29294. extendControls: [],
  29295. extendAtomics: [],
  29296. componentBelowControlBar: null,
  29297. media: {
  29298. pasteImage: true,
  29299. imagePasteLimit: 5,
  29300. image: true,
  29301. video: true,
  29302. audio: true,
  29303. uploadFn: null,
  29304. validateFn: null,
  29305. onBeforeDeselect: null,
  29306. onDeselect: null,
  29307. onBeforeSelect: null,
  29308. onSelect: null,
  29309. onBeforeRemove: null,
  29310. onRemove: null,
  29311. onCancel: null,
  29312. onFileSelect: null,
  29313. onBeforeInsert: null,
  29314. onInsert: null,
  29315. onChange: null,
  29316. accepts: {
  29317. image: 'image/png,image/jpeg,image/gif,image/webp,image/apng,image/svg',
  29318. video: 'video/mp4',
  29319. audio: 'audio/mp3'
  29320. },
  29321. externals: {
  29322. audio: true,
  29323. video: true,
  29324. image: true,
  29325. embed: true
  29326. }
  29327. },
  29328. imageControls: ['float-left', 'float-right', 'align-left', 'align-center', 'align-right', 'link', 'size', 'remove'],
  29329. imageResizable: true,
  29330. colors: ['#000000', '#333333', '#666666', '#999999', '#cccccc', '#ffffff', '#61a951', '#16a085', '#07a9fe', '#003ba5', '#8e44ad', '#f32784', '#c0392b', '#d35400', '#f39c12', '#fdda00'],
  29331. colorPicker: null,
  29332. colorPickerTheme: 'dark',
  29333. colorPickerAutoHide: true,
  29334. codeTabIndents: 2,
  29335. headings: ['header-one', 'header-two', 'header-three', 'header-four', 'header-five', 'header-six', 'unstyled'],
  29336. textAligns: ['left', 'center', 'right', 'justify'],
  29337. textBackgroundColor: true,
  29338. allowInsertLinkText: false,
  29339. defaultLinkTarget: '',
  29340. letterSpacings: [0, 1, 2, 3, 4, 5, 6],
  29341. lineHeights: [1, 1.2, 1.5, 1.75, 2, 2.5, 3, 4],
  29342. fontSizes: [12, 14, 16, 18, 20, 24, 28, 30, 32, 36, 40, 48, 56, 64, 72, 96, 120, 144],
  29343. fontFamilies: [{
  29344. name: 'Araial',
  29345. family: 'Arial, Helvetica, sans-serif'
  29346. }, {
  29347. name: 'Georgia',
  29348. family: 'Georgia, serif'
  29349. }, {
  29350. name: 'Impact',
  29351. family: 'Impact, serif'
  29352. }, {
  29353. name: 'Monospace',
  29354. family: '"Courier New", Courier, monospace'
  29355. }, {
  29356. name: 'Tahoma',
  29357. family: 'tahoma, arial, "Hiragino Sans GB", 宋体, sans-serif'
  29358. }],
  29359. converts: {
  29360. unitExportFn: function unitExportFn(value, type) {
  29361. return type === 'line-height' ? value : "".concat(value, "px");
  29362. }
  29363. },
  29364. emojis: ['🤣', '🙌', '💚', '💛', '👏', '😉', '💯', '💕', '💞', '💘', '💙', '💝', '🖤', '💜', '❤️', '😍', '😻', '💓', '💗', '😋', '😇', '😂', '😹', '😘', '💖', '😁', '😀', '🤞', '😲', '😄', '😊', '👍', '😌', '😃', '😅', '✌️', '🤗', '💋', '😗', '😽', '😚', '🤠', '😙', '😺', '👄', '😸', '😏', '😼', '👌', '😎', '😆', '😛', '🙏', '🤝', '🙂', '🤑', '😝', '😐', '😑', '🤤', '😤', '🙃', '🤡', '😶', '😪', '😴', '😵', '😓', '👊', '😦', '😷', '🤐', '😜', '🤓', '👻', '😥', '🙄', '🤔', '🤒', '🙁', '😔', '😯', '☹️', '☠️', '😰', '😩', '😖', '😕', '😒', '😣', '😢', '😮', '😿', '🤧', '😫', '🤥', '😞', '😬', '👎', '💀', '😳', '😨', '🤕', '🤢', '😱', '😭', '😠', '😈', '😧', '💔', '😟', '🙀', '💩', '👿', '😡', '😾', '🖕'],
  29365. stripPastedStyles: false,
  29366. triggerChangeOnMount: true,
  29367. className: '',
  29368. style: {},
  29369. controlBarClassName: '',
  29370. controlBarStyle: {},
  29371. contentClassName: '',
  29372. contentStyle: {},
  29373. draftProps: {},
  29374. hooks: {},
  29375. onChange: null,
  29376. onFocus: null,
  29377. onBlur: null,
  29378. onTab: null,
  29379. onDelete: null,
  29380. onSave: null,
  29381. fixPlaceholder: false
  29382. });
  29383. // EXTERNAL MODULE: ../node_modules/draft-js/lib/getFragmentFromSelection.js
  29384. var getFragmentFromSelection = __webpack_require__(22);
  29385. var getFragmentFromSelection_default = /*#__PURE__*/__webpack_require__.n(getFragmentFromSelection);
  29386. // EXTERNAL MODULE: external "draftjs-utils"
  29387. var external_draftjs_utils_ = __webpack_require__(23);
  29388. // CONCATENATED MODULE: ./configs/handlers.js
  29389. var handlers_keyCommandHandlers = function keyCommandHandlers(command, editorState, editor) {
  29390. if (editor.editorProps.handleKeyCommand && editor.editorProps.handleKeyCommand(command, editorState, editor) === 'handled') {
  29391. return 'handled';
  29392. }
  29393. if (command === 'braft-save') {
  29394. editor.editorProps.onSave && editor.editorProps.onSave(editorState);
  29395. return 'handled';
  29396. }
  29397. var _editor$editorProps = editor.editorProps,
  29398. controls = _editor$editorProps.controls,
  29399. excludeControls = _editor$editorProps.excludeControls;
  29400. var allowIndent = (controls.indexOf('text-indent') !== 0 || controls.find(function (item) {
  29401. return item.key === 'text-indent';
  29402. })) && excludeControls.indexOf('text-indent') === -1;
  29403. var cursorStart = editorState.getSelection().getStartOffset();
  29404. var cursorEnd = editorState.getSelection().getEndOffset();
  29405. var cursorIsAtFirst = cursorStart === 0 && cursorEnd === 0;
  29406. if (command === 'backspace') {
  29407. if (editor.editorProps.onDelete && editor.editorProps.onDelete(editorState) === false) {
  29408. return 'handled';
  29409. }
  29410. var blockType = external_braft_utils_["ContentUtils"].getSelectionBlockType(editorState);
  29411. if (allowIndent && cursorIsAtFirst && blockType !== 'code-block') {
  29412. editor.setValue(external_braft_utils_["ContentUtils"].decreaseSelectionIndent(editorState));
  29413. }
  29414. }
  29415. if (command === 'tab') {
  29416. var _blockType = external_braft_utils_["ContentUtils"].getSelectionBlockType(editorState);
  29417. if (_blockType === 'code-block') {
  29418. editor.setValue(external_braft_utils_["ContentUtils"].insertText(editorState, ' '.repeat(editor.editorProps.codeTabIndents)));
  29419. return 'handled';
  29420. } else if (_blockType === 'ordered-list-item' || _blockType === 'unordered-list-item') {
  29421. var newEditorState = external_draft_js_["RichUtils"].onTab(event, editorState, 4);
  29422. if (newEditorState !== editorState) {
  29423. editor.setValue(newEditorState);
  29424. }
  29425. return 'handled';
  29426. } else if (_blockType !== 'atomic' && allowIndent && cursorIsAtFirst) {
  29427. editor.setValue(external_braft_utils_["ContentUtils"].increaseSelectionIndent(editorState));
  29428. return 'handled';
  29429. }
  29430. }
  29431. var nextEditorState = external_braft_utils_["ContentUtils"].handleKeyCommand(editorState, command);
  29432. if (nextEditorState) {
  29433. editor.setValue(nextEditorState);
  29434. return 'handled';
  29435. }
  29436. return 'not-handled';
  29437. };
  29438. var handlers_returnHandlers = function returnHandlers(event, editorState, editor) {
  29439. if (editor.editorProps.handleReturn && editor.editorProps.handleReturn(event, editorState, editor) === 'handled') {
  29440. return 'handled';
  29441. }
  29442. var currentBlock = external_braft_utils_["ContentUtils"].getSelectionBlock(editorState);
  29443. var currentBlockType = currentBlock.getType();
  29444. if (currentBlockType === 'unordered-list-item' || currentBlockType === 'ordered-list-item') {
  29445. if (currentBlock.getLength() === 0) {
  29446. editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionBlockType(editorState, 'unstyled'));
  29447. return 'handled';
  29448. }
  29449. return 'not-handled';
  29450. } else if (currentBlockType === 'code-block') {
  29451. if (event.which === 13 && (event.getModifierState('Shift') || event.getModifierState('Alt') || event.getModifierState('Control'))) {
  29452. editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionBlockType(editorState, 'unstyled'));
  29453. return 'handled';
  29454. }
  29455. return 'not-handled';
  29456. } else if (currentBlockType === 'blockquote') {
  29457. if (event.which === 13) {
  29458. if (event.getModifierState('Shift') || event.getModifierState('Alt') || event.getModifierState('Control')) {
  29459. event.which = 0;
  29460. } else {
  29461. editor.setValue(external_draft_js_["RichUtils"].insertSoftNewline(editorState));
  29462. return 'handled';
  29463. }
  29464. }
  29465. }
  29466. var nextEditorState = Object(external_draftjs_utils_["handleNewLine"])(editorState, event);
  29467. if (nextEditorState) {
  29468. editor.setValue(nextEditorState);
  29469. return 'handled';
  29470. }
  29471. return 'not-handled';
  29472. };
  29473. var beforeInputHandlers = function beforeInputHandlers(chars, editorState, editor) {
  29474. if (editor.editorProps.handleBeforeInput && editor.editorProps.handleBeforeInput(chars, editorState, editor) === 'handled') {
  29475. return 'handled';
  29476. }
  29477. return 'not-handled';
  29478. };
  29479. var handlers_compositionStartHandler = function compositionStartHandler(_, editor) {
  29480. var editorState = editor.state.editorState;
  29481. var selectedBlocks = external_braft_utils_["ContentUtils"].getSelectedBlocks(editorState);
  29482. if (selectedBlocks && selectedBlocks.length > 1) {
  29483. var nextEditorState = external_draft_js_["EditorState"].push(editorState, external_draft_js_["Modifier"].removeRange(editorState.getCurrentContent(), editorState.getSelection(), 'backward'), 'remove-range');
  29484. editor.setValue(nextEditorState);
  29485. }
  29486. };
  29487. var handlers_dropHandlers = function dropHandlers(selectionState, dataTransfer, editor) {
  29488. if (editor.editorProps.readOnly || editor.editorProps.disabled) {
  29489. return 'handled';
  29490. }
  29491. if (window && window.__BRAFT_DRAGING__IMAGE__) {
  29492. var nextEditorState = external_draft_js_["EditorState"].forceSelection(editor.state.editorState, selectionState);
  29493. nextEditorState = external_braft_utils_["ContentUtils"].insertMedias(nextEditorState, [window.__BRAFT_DRAGING__IMAGE__.mediaData]);
  29494. nextEditorState = external_braft_utils_["ContentUtils"].removeBlock(nextEditorState, window.__BRAFT_DRAGING__IMAGE__.block, nextEditorState.getSelection());
  29495. window.__BRAFT_DRAGING__IMAGE__ = null;
  29496. editor.lockOrUnlockEditor(true);
  29497. editor.setValue(nextEditorState);
  29498. return 'handled';
  29499. } else if (!dataTransfer || !dataTransfer.getText()) {
  29500. return 'handled';
  29501. }
  29502. return 'not-handled';
  29503. };
  29504. var handlers_handleFiles = function handleFiles(files, editor) {
  29505. var _editor$constructor$d = objectSpread_default()({}, editor.constructor.defaultProps.media, editor.editorProps.media),
  29506. pasteImage = _editor$constructor$d.pasteImage,
  29507. validateFn = _editor$constructor$d.validateFn,
  29508. imagePasteLimit = _editor$constructor$d.imagePasteLimit;
  29509. pasteImage && files.slice(0, imagePasteLimit).forEach(function (file) {
  29510. if (file && file.type.indexOf('image') > -1 && editor.braftFinder) {
  29511. var validateResult = validateFn ? validateFn(file) : true;
  29512. if (validateResult instanceof Promise) {
  29513. validateResult.then(function () {
  29514. editor.braftFinder.uploadImage(file, function (image) {
  29515. editor.isLiving && editor.setValue(external_braft_utils_["ContentUtils"].insertMedias(editor.state.editorState, [image]));
  29516. });
  29517. });
  29518. } else if (validateResult) {
  29519. editor.braftFinder.uploadImage(file, function (image) {
  29520. editor.isLiving && editor.setValue(external_braft_utils_["ContentUtils"].insertMedias(editor.state.editorState, [image]));
  29521. });
  29522. }
  29523. }
  29524. });
  29525. if (files[0] && files[0].type.indexOf('image') > -1 && pasteImage) {
  29526. return 'handled';
  29527. }
  29528. return 'not-handled';
  29529. };
  29530. var droppedFilesHandlers = function droppedFilesHandlers(selectionState, files, editor) {
  29531. if (editor.editorProps.handleDroppedFiles && editor.editorProps.handleDroppedFiles(selectionState, files, editor) === 'handled') {
  29532. return 'handled';
  29533. }
  29534. return handlers_handleFiles(files, editor);
  29535. };
  29536. var pastedFilesHandlers = function pastedFilesHandlers(files, editor) {
  29537. if (editor.editorProps.handlePastedFiles && editor.editorProps.handlePastedFiles(files, editor) === 'handled') {
  29538. return 'handled';
  29539. }
  29540. return handlers_handleFiles(files, editor);
  29541. };
  29542. var handlers_copyHandlers = function copyHandlers(event, editor) {
  29543. var blockMap = getFragmentFromSelection_default()(editor.state.editorState);
  29544. if (blockMap && blockMap.toArray) {
  29545. try {
  29546. var tempContentState = external_draft_js_["ContentState"].createFromBlockArray(blockMap.toArray());
  29547. var tempEditorState = external_draft_js_["EditorState"].createWithContent(tempContentState);
  29548. var clipboardData = event.clipboardData || window.clipboardData || event.originalEvent.clipboardData;
  29549. tempEditorState.setConvertOptions(editor.state.editorState.convertOptions);
  29550. clipboardData.setData('text/html', tempEditorState.toHTML());
  29551. clipboardData.setData('text/plain', tempEditorState.toText());
  29552. event.preventDefault();
  29553. } catch (error) {
  29554. console.warn(error);
  29555. }
  29556. }
  29557. };
  29558. var handlers_pastedTextHandlers = function pastedTextHandlers(text, html, editorState, editor) {
  29559. if (editor.editorProps.handlePastedText && editor.editorProps.handlePastedText(text, html, editorState, editor) === 'handled') {
  29560. return 'handled';
  29561. }
  29562. if (!html || editor.editorProps.stripPastedStyles) {
  29563. return false;
  29564. }
  29565. var tempColors = external_braft_utils_["ColorUtils"].detectColorsFromHTMLString(html);
  29566. editor.setState({
  29567. tempColors: toConsumableArray_default()(editor.state.tempColors).concat(toConsumableArray_default()(tempColors)).filter(function (item) {
  29568. return editor.editorProps.colors.indexOf(item) === -1;
  29569. }).filter(function (item, index, array) {
  29570. return array.indexOf(item) === index;
  29571. })
  29572. }, function () {
  29573. editor.setValue(external_braft_utils_["ContentUtils"].insertHTML(editorState, html, 'paste'));
  29574. });
  29575. return 'handled';
  29576. };
  29577. // CONCATENATED MODULE: ./helpers/extension.js
  29578. // TODO
  29579. // - block-style和atomic类型的扩展支持
  29580. var extension_extensionControls = [];
  29581. var extension_extensionDecorators = [];
  29582. var extension_propInterceptors = [];
  29583. var extension_extensionBlockRenderMaps = [];
  29584. var extension_extensionBlockRendererFns = [];
  29585. var extensionInlineStyleMaps = [];
  29586. var extension_extensionInlineStyleFns = [];
  29587. var extensionEntities = [];
  29588. var inlineStyleImporters = [];
  29589. var inlineStyleExporters = [];
  29590. var blockImporters = [];
  29591. var blockExporters = [];
  29592. var filterByEditorId = function filterByEditorId(items, editorId) {
  29593. if (!editorId) {
  29594. return items.filter(function (item) {
  29595. return !item.includeEditors;
  29596. }).map(function (item) {
  29597. return item.data;
  29598. });
  29599. }
  29600. return items.map(function (item) {
  29601. if (!item.includeEditors && !item.excludeEditors) {
  29602. return item.data;
  29603. }
  29604. if (item.includeEditors) {
  29605. return item.includeEditors.indexOf(editorId) !== -1 ? item.data : false;
  29606. }
  29607. if (item.excludeEditors) {
  29608. return item.excludeEditors.indexOf(editorId) !== -1 ? false : item.data;
  29609. }
  29610. return false;
  29611. }).filter(function (item) {
  29612. return item;
  29613. });
  29614. };
  29615. var getPropInterceptors = function getPropInterceptors(editorId) {
  29616. return filterByEditorId(extension_propInterceptors, editorId);
  29617. };
  29618. var getExtensionControls = function getExtensionControls(editorId) {
  29619. return filterByEditorId(extension_extensionControls, editorId);
  29620. };
  29621. var getExtensionDecorators = function getExtensionDecorators(editorId) {
  29622. return filterByEditorId(extension_extensionDecorators, editorId);
  29623. };
  29624. var getExtensionBlockRenderMaps = function getExtensionBlockRenderMaps(editorId) {
  29625. return filterByEditorId(extension_extensionBlockRenderMaps, editorId);
  29626. };
  29627. var getExtensionBlockRendererFns = function getExtensionBlockRendererFns(editorId) {
  29628. return filterByEditorId(extension_extensionBlockRendererFns, editorId);
  29629. };
  29630. var getExtensionInlineStyleMap = function getExtensionInlineStyleMap(editorId) {
  29631. var inlineStyleMap = {};
  29632. filterByEditorId(extensionInlineStyleMaps, editorId).forEach(function (item) {
  29633. inlineStyleMap[item.inlineStyleName] = item.styleMap;
  29634. });
  29635. return inlineStyleMap;
  29636. };
  29637. var getExtensionInlineStyleFns = function getExtensionInlineStyleFns(editorId) {
  29638. return filterByEditorId(extension_extensionInlineStyleFns, editorId);
  29639. };
  29640. var compositeStyleImportFn = function compositeStyleImportFn(styleImportFn, editorId) {
  29641. return function (nodeName, node, style) {
  29642. filterByEditorId(inlineStyleImporters, editorId).forEach(function (styleImporter) {
  29643. if (styleImporter.importer && styleImporter.importer(nodeName, node)) {
  29644. style = style.add(styleImporter.inlineStyleName);
  29645. }
  29646. });
  29647. return styleImportFn ? styleImportFn(nodeName, node, style) : style;
  29648. };
  29649. };
  29650. var compositeStyleExportFn = function compositeStyleExportFn(styleExportFn, editorId) {
  29651. return function (style) {
  29652. style = style.toUpperCase();
  29653. var result = styleExportFn ? styleExportFn(style) : undefined;
  29654. if (result) {
  29655. return result;
  29656. }
  29657. filterByEditorId(inlineStyleExporters, editorId).find(function (item) {
  29658. if (item.inlineStyleName === style) {
  29659. result = item.exporter;
  29660. return true;
  29661. }
  29662. });
  29663. return result;
  29664. };
  29665. };
  29666. var compositeEntityImportFn = function compositeEntityImportFn(entityImportFn, editorId) {
  29667. return function (nodeName, node, createEntity, source) {
  29668. var result = entityImportFn ? entityImportFn(nodeName, node, createEntity, source) : null;
  29669. if (result) {
  29670. return result;
  29671. }
  29672. filterByEditorId(extensionEntities, editorId).find(function (entityItem) {
  29673. var matched = entityItem.importer ? entityItem.importer(nodeName, node, source) : null;
  29674. matched && (result = createEntity(entityItem.entityType, matched.mutability || 'MUTABLE', matched.data || {}));
  29675. return !!matched;
  29676. });
  29677. return result;
  29678. };
  29679. };
  29680. var compositeEntityExportFn = function compositeEntityExportFn(entityExportFn, editorId) {
  29681. return function (entity, originalText) {
  29682. var result = entityExportFn ? entityExportFn(entity, originalText) : undefined;
  29683. if (result) {
  29684. return result;
  29685. }
  29686. var entityType = entity.type.toUpperCase();
  29687. filterByEditorId(extensionEntities, editorId).find(function (entityItem) {
  29688. if (entityItem.entityType === entityType) {
  29689. result = entityItem.exporter ? entityItem.exporter(entity, originalText) : undefined;
  29690. return true;
  29691. }
  29692. });
  29693. return result;
  29694. };
  29695. };
  29696. var compositeBlockImportFn = function compositeBlockImportFn(blockImportFn, editorId) {
  29697. return function (nodeName, node, source) {
  29698. var result = blockImportFn ? blockImportFn(nodeName, node, source) : null;
  29699. if (result) {
  29700. return result;
  29701. }
  29702. filterByEditorId(blockImporters, editorId).find(function (blockImporter) {
  29703. var matched = blockImporter.importer ? blockImporter.importer(nodeName, node, source) : undefined;
  29704. matched && (result = matched);
  29705. return !!matched;
  29706. });
  29707. return result;
  29708. };
  29709. };
  29710. var compositeBlockExportFn = function compositeBlockExportFn(blockExportFn, editorId) {
  29711. return function (contentState, block) {
  29712. var result = blockExportFn ? blockExportFn(contentState, block) : null;
  29713. if (result) {
  29714. return result;
  29715. }
  29716. filterByEditorId(blockExporters, editorId).find(function (blockExporter) {
  29717. var matched = blockExporter.exporter ? blockExporter.exporter(contentState, block) : undefined;
  29718. matched && (result = matched);
  29719. return !!matched;
  29720. });
  29721. return result;
  29722. };
  29723. };
  29724. var extension_useExtension = function useExtension(extension) {
  29725. if (extension instanceof Array) {
  29726. extension.forEach(useExtension);
  29727. return false;
  29728. }
  29729. if (!extension || !extension.type || typeof extension.type !== 'string') {
  29730. return false;
  29731. }
  29732. var includeEditors = extension.includeEditors,
  29733. excludeEditors = extension.excludeEditors;
  29734. if (extension.type === 'control') {
  29735. extension_extensionControls.push({
  29736. includeEditors: includeEditors,
  29737. excludeEditors: excludeEditors,
  29738. data: extension.control
  29739. });
  29740. } else if (extension.type === 'inline-style') {
  29741. var inlineStyleName = extension.name.toUpperCase();
  29742. if (extension.control) {
  29743. extension_extensionControls.push({
  29744. includeEditors: includeEditors,
  29745. excludeEditors: excludeEditors,
  29746. data: objectSpread_default()({
  29747. key: inlineStyleName,
  29748. type: 'inline-style',
  29749. command: inlineStyleName
  29750. }, extension.control)
  29751. });
  29752. }
  29753. if (extension.style) {
  29754. extensionInlineStyleMaps.push({
  29755. includeEditors: includeEditors,
  29756. excludeEditors: excludeEditors,
  29757. data: {
  29758. inlineStyleName: inlineStyleName,
  29759. styleMap: extension.style
  29760. }
  29761. });
  29762. }
  29763. if (extension.styleFn) {
  29764. extension_extensionInlineStyleFns.push({
  29765. includeEditors: includeEditors,
  29766. excludeEditors: excludeEditors,
  29767. data: {
  29768. inlineStyleName: inlineStyleName,
  29769. styleFn: extension.styleFn
  29770. }
  29771. });
  29772. }
  29773. if (extension.importer) {
  29774. inlineStyleImporters.push({
  29775. includeEditors: includeEditors,
  29776. excludeEditors: excludeEditors,
  29777. data: {
  29778. inlineStyleName: inlineStyleName,
  29779. importer: extension.importer
  29780. }
  29781. });
  29782. }
  29783. inlineStyleExporters.push({
  29784. includeEditors: includeEditors,
  29785. excludeEditors: excludeEditors,
  29786. data: {
  29787. inlineStyleName: inlineStyleName,
  29788. exporter: extension.exporter ? extension.exporter(extension) : external_react_default.a.createElement("span", {
  29789. style: extension.style
  29790. })
  29791. }
  29792. });
  29793. } else if (extension.type === 'block-style') ; else if (extension.type === 'entity') {
  29794. var entityType = extension.name.toUpperCase();
  29795. if (extension.control) {
  29796. extension_extensionControls.push({
  29797. includeEditors: includeEditors,
  29798. excludeEditors: excludeEditors,
  29799. data: typeof extension.control === 'function' ? extension.control : objectSpread_default()({
  29800. key: entityType,
  29801. type: 'entity',
  29802. command: entityType,
  29803. data: {
  29804. mutability: extension.mutability || 'MUTABLE',
  29805. data: extension.data || {}
  29806. }
  29807. }, extension.control)
  29808. });
  29809. }
  29810. extensionEntities.push({
  29811. includeEditors: includeEditors,
  29812. excludeEditors: excludeEditors,
  29813. data: {
  29814. entityType: entityType,
  29815. importer: extension.importer,
  29816. exporter: extension.exporter
  29817. }
  29818. });
  29819. extension_extensionDecorators.push({
  29820. includeEditors: includeEditors,
  29821. excludeEditors: excludeEditors,
  29822. data: {
  29823. type: 'entity',
  29824. decorator: {
  29825. key: entityType,
  29826. component: extension.component
  29827. }
  29828. }
  29829. });
  29830. } else if (extension.type === 'block') {
  29831. var blockType = extension.name;
  29832. if (extension.renderMap) {
  29833. extension_extensionBlockRenderMaps.push({
  29834. includeEditors: includeEditors,
  29835. excludeEditors: excludeEditors,
  29836. data: {
  29837. blockType: blockType,
  29838. renderMap: extension.renderMap
  29839. }
  29840. });
  29841. }
  29842. if (extension.rendererFn) {
  29843. extension_extensionBlockRendererFns.push({
  29844. includeEditors: includeEditors,
  29845. excludeEditors: excludeEditors,
  29846. data: {
  29847. blockType: blockType,
  29848. rendererFn: extension.rendererFn
  29849. }
  29850. });
  29851. }
  29852. if (extension.importer) {
  29853. blockImporters.push({
  29854. includeEditors: includeEditors,
  29855. excludeEditors: excludeEditors,
  29856. data: {
  29857. blockType: blockType,
  29858. importer: extension.importer
  29859. }
  29860. });
  29861. }
  29862. if (extension.exporter) {
  29863. blockExporters.push({
  29864. includeEditors: includeEditors,
  29865. excludeEditors: excludeEditors,
  29866. data: {
  29867. blockType: blockType,
  29868. exporter: extension.exporter
  29869. }
  29870. });
  29871. }
  29872. } else if (extension.type === 'atomic') ; else if (extension.type === 'decorator') {
  29873. var decorator = extension.decorator;
  29874. if (decorator && decorator.strategy && decorator.component) {
  29875. extension_extensionDecorators.push({
  29876. includeEditors: includeEditors,
  29877. excludeEditors: excludeEditors,
  29878. data: {
  29879. type: 'strategy',
  29880. decorator: decorator
  29881. }
  29882. });
  29883. } else if (decorator && decorator.getDecorations) {
  29884. extension_extensionDecorators.push({
  29885. includeEditors: includeEditors,
  29886. excludeEditors: excludeEditors,
  29887. data: {
  29888. type: 'class',
  29889. decorator: decorator
  29890. }
  29891. });
  29892. }
  29893. } else if (extension.type === 'prop-interception') {
  29894. extension_propInterceptors.push({
  29895. includeEditors: includeEditors,
  29896. excludeEditors: excludeEditors,
  29897. data: extension.interceptor
  29898. });
  29899. }
  29900. };
  29901. var createExtensibleEditor = function createExtensibleEditor(BraftEditor) {
  29902. BraftEditor.use = extension_useExtension;
  29903. return BraftEditor;
  29904. };
  29905. // CONCATENATED MODULE: ./renderers/block/blockRenderMap.js
  29906. /* harmony default export */ var block_blockRenderMap = (function (props, blockRenderMap) {
  29907. var customBlockRenderMap = Object(external_immutable_["Map"])({
  29908. 'atomic': {
  29909. element: ''
  29910. },
  29911. 'code-block': {
  29912. element: 'code',
  29913. wrapper: external_react_default.a.createElement("pre", {
  29914. className: "braft-code-block"
  29915. })
  29916. }
  29917. });
  29918. try {
  29919. var extensionBlockRenderMaps = getExtensionBlockRenderMaps(props.editorId);
  29920. customBlockRenderMap = extensionBlockRenderMaps.reduce(function (customBlockRenderMap, item) {
  29921. return customBlockRenderMap.merge(typeof item.renderMap === 'function' ? item.renderMap(props) : item.renderMap);
  29922. }, customBlockRenderMap);
  29923. if (blockRenderMap) {
  29924. if (typeof blockRenderMap === 'function') {
  29925. customBlockRenderMap = customBlockRenderMap.merge(blockRenderMap(props));
  29926. } else {
  29927. customBlockRenderMap = customBlockRenderMap.merge(blockRenderMap);
  29928. }
  29929. }
  29930. customBlockRenderMap = external_draft_js_["DefaultDraftBlockRenderMap"].merge(customBlockRenderMap);
  29931. } catch (error) {
  29932. console.warn(error);
  29933. }
  29934. return customBlockRenderMap;
  29935. });
  29936. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/extends.js
  29937. var helpers_extends = __webpack_require__(11);
  29938. var extends_default = /*#__PURE__*/__webpack_require__.n(helpers_extends);
  29939. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/slicedToArray.js
  29940. var slicedToArray = __webpack_require__(24);
  29941. var slicedToArray_default = /*#__PURE__*/__webpack_require__.n(slicedToArray);
  29942. // EXTERNAL MODULE: ./renderers/atomics/Image/style.scss
  29943. var Image_style = __webpack_require__(45);
  29944. // EXTERNAL MODULE: ./components/common/Switch/style.scss
  29945. var Switch_style = __webpack_require__(46);
  29946. // CONCATENATED MODULE: ./components/common/Switch/index.jsx
  29947. /* harmony default export */ var Switch = (function (props) {
  29948. var active = props.active,
  29949. _onClick = props.onClick,
  29950. className = props.className;
  29951. return external_react_default.a.createElement("div", {
  29952. onClick: function onClick() {
  29953. return _onClick();
  29954. },
  29955. className: 'bf-switch ' + className + (active ? ' active' : '')
  29956. });
  29957. });
  29958. // CONCATENATED MODULE: ./configs/controls.js
  29959. /* harmony default export */ var configs_controls = (function (lang, editor) {
  29960. return [{
  29961. key: 'undo',
  29962. title: lang.controls.undo,
  29963. text: external_react_default.a.createElement("i", {
  29964. className: "bfi-undo"
  29965. }),
  29966. type: 'editor-method',
  29967. command: 'undo'
  29968. }, {
  29969. key: 'redo',
  29970. title: lang.controls.redo,
  29971. text: external_react_default.a.createElement("i", {
  29972. className: "bfi-redo"
  29973. }),
  29974. type: 'editor-method',
  29975. command: 'redo'
  29976. }, {
  29977. key: 'remove-styles',
  29978. title: lang.controls.removeStyles,
  29979. text: external_react_default.a.createElement("i", {
  29980. className: "bfi-format_clear"
  29981. }),
  29982. type: 'editor-method',
  29983. command: 'removeSelectionInlineStyles'
  29984. }, {
  29985. key: 'hr',
  29986. title: lang.controls.hr,
  29987. text: external_react_default.a.createElement("i", {
  29988. className: "bfi-hr"
  29989. }),
  29990. type: 'editor-method',
  29991. command: 'insertHorizontalLine'
  29992. }, {
  29993. key: 'bold',
  29994. title: lang.controls.bold,
  29995. text: external_react_default.a.createElement("i", {
  29996. className: "bfi-bold"
  29997. }),
  29998. type: 'inline-style',
  29999. command: 'bold'
  30000. }, {
  30001. key: 'italic',
  30002. title: lang.controls.italic,
  30003. text: external_react_default.a.createElement("i", {
  30004. className: "bfi-italic"
  30005. }),
  30006. type: 'inline-style',
  30007. command: 'italic'
  30008. }, {
  30009. key: 'underline',
  30010. title: lang.controls.underline,
  30011. text: external_react_default.a.createElement("i", {
  30012. className: "bfi-underlined"
  30013. }),
  30014. type: 'inline-style',
  30015. command: 'underline'
  30016. }, {
  30017. key: 'strike-through',
  30018. title: lang.controls.strikeThrough,
  30019. text: external_react_default.a.createElement("i", {
  30020. className: "bfi-strikethrough"
  30021. }),
  30022. type: 'inline-style',
  30023. command: 'strikethrough'
  30024. }, {
  30025. key: 'superscript',
  30026. title: lang.controls.superScript,
  30027. text: external_react_default.a.createElement("i", {
  30028. className: "bfi-superscript"
  30029. }),
  30030. type: 'inline-style',
  30031. command: 'superscript'
  30032. }, {
  30033. key: 'subscript',
  30034. title: lang.controls.subScript,
  30035. text: external_react_default.a.createElement("i", {
  30036. className: "bfi-subscript"
  30037. }),
  30038. type: 'inline-style',
  30039. command: 'subscript'
  30040. }, {
  30041. key: 'headings',
  30042. title: lang.controls.headings,
  30043. type: 'headings'
  30044. }, {
  30045. key: 'blockquote',
  30046. title: lang.controls.blockQuote,
  30047. text: external_react_default.a.createElement("i", {
  30048. className: "bfi-quote"
  30049. }),
  30050. type: 'block-type',
  30051. command: 'blockquote'
  30052. }, {
  30053. key: 'code',
  30054. title: lang.controls.code,
  30055. text: external_react_default.a.createElement("i", {
  30056. className: "bfi-code"
  30057. }),
  30058. type: 'block-type',
  30059. command: 'code-block'
  30060. }, {
  30061. key: 'list-ul',
  30062. title: lang.controls.unorderedList,
  30063. text: external_react_default.a.createElement("i", {
  30064. className: "bfi-list"
  30065. }),
  30066. type: 'block-type',
  30067. command: 'unordered-list-item'
  30068. }, {
  30069. key: 'list-ol',
  30070. title: lang.controls.orderedList,
  30071. text: external_react_default.a.createElement("i", {
  30072. className: "bfi-list-numbered"
  30073. }),
  30074. type: 'block-type',
  30075. command: 'ordered-list-item'
  30076. }, {
  30077. key: 'link',
  30078. title: lang.controls.link,
  30079. type: 'link'
  30080. }, {
  30081. key: 'text-color',
  30082. title: lang.controls.color,
  30083. type: 'text-color'
  30084. }, {
  30085. key: 'line-height',
  30086. title: lang.controls.lineHeight,
  30087. type: 'line-height'
  30088. }, {
  30089. key: 'letter-spacing',
  30090. title: lang.controls.letterSpacing,
  30091. type: 'letter-spacing'
  30092. }, {
  30093. key: 'text-indent',
  30094. title: lang.controls.textIndent,
  30095. type: 'text-indent'
  30096. }, {
  30097. key: 'font-size',
  30098. title: lang.controls.fontSize,
  30099. type: 'font-size'
  30100. }, {
  30101. key: 'font-family',
  30102. title: lang.controls.fontFamily,
  30103. type: 'font-family'
  30104. }, {
  30105. key: 'text-align',
  30106. title: lang.controls.textAlign,
  30107. type: 'text-align'
  30108. }, {
  30109. key: 'media',
  30110. title: lang.controls.media,
  30111. text: external_react_default.a.createElement("i", {
  30112. className: "bfi-media"
  30113. }),
  30114. type: 'media'
  30115. }, {
  30116. key: 'emoji',
  30117. title: lang.controls.emoji,
  30118. text: external_react_default.a.createElement("i", {
  30119. className: "bfi-emoji"
  30120. }),
  30121. type: 'emoji'
  30122. }, {
  30123. key: 'clear',
  30124. title: lang.controls.clear,
  30125. text: external_react_default.a.createElement("i", {
  30126. className: "bfi-clear_all"
  30127. }),
  30128. type: 'editor-method',
  30129. command: 'clearEditorContent'
  30130. }, {
  30131. key: 'fullscreen',
  30132. title: editor.state.isFullscreen ? lang.controls.exitFullscreen : lang.controls.fullscreen,
  30133. text: external_react_default.a.createElement("i", {
  30134. className: editor.state.isFullscreen ? 'bfi-fullscreen-exit' : 'bfi-fullscreen'
  30135. }),
  30136. type: 'editor-method',
  30137. command: 'toggleFullscreen'
  30138. }, {
  30139. key: 'modal',
  30140. type: 'modal'
  30141. }, {
  30142. key: 'button',
  30143. type: 'button'
  30144. }, {
  30145. key: 'dropdown',
  30146. type: 'dropdown'
  30147. }, {
  30148. key: 'component',
  30149. type: 'component'
  30150. }];
  30151. });
  30152. var imageControlItems = {
  30153. 'float-left': {
  30154. text: external_react_default.a.createElement("span", {
  30155. "data-float": "left"
  30156. }, "\uE91E"),
  30157. command: 'setImageFloat|left'
  30158. },
  30159. 'float-right': {
  30160. text: external_react_default.a.createElement("span", {
  30161. "data-float": "right"
  30162. }, "\uE914"),
  30163. command: 'setImageFloat|right'
  30164. },
  30165. 'align-left': {
  30166. text: external_react_default.a.createElement("span", {
  30167. "data-align": "left"
  30168. }, "\uE027"),
  30169. command: 'setImageAlignment|left'
  30170. },
  30171. 'align-center': {
  30172. text: external_react_default.a.createElement("span", {
  30173. "data-align": "center"
  30174. }, "\uE028"),
  30175. command: 'setImageAlignment|center'
  30176. },
  30177. 'align-right': {
  30178. text: external_react_default.a.createElement("span", {
  30179. "data-align": "right"
  30180. }, "\uE029"),
  30181. command: 'setImageAlignment|right'
  30182. },
  30183. 'size': {
  30184. text: external_react_default.a.createElement("span", null, "\uE3C2"),
  30185. command: 'toggleSizeEditor'
  30186. },
  30187. 'link': {
  30188. text: external_react_default.a.createElement("span", null, "\uE91A"),
  30189. command: 'toggleLinkEditor'
  30190. },
  30191. 'remove': {
  30192. text: external_react_default.a.createElement("span", null, "\uE9AC"),
  30193. command: 'removeImage'
  30194. }
  30195. };
  30196. // CONCATENATED MODULE: ./renderers/atomics/Image/index.jsx
  30197. var Image_Image =
  30198. /*#__PURE__*/
  30199. function (_React$Component) {
  30200. inherits_default()(Image, _React$Component);
  30201. function Image() {
  30202. var _getPrototypeOf2;
  30203. var _this;
  30204. classCallCheck_default()(this, Image);
  30205. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  30206. args[_key] = arguments[_key];
  30207. }
  30208. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(Image)).call.apply(_getPrototypeOf2, [this].concat(args)));
  30209. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  30210. toolbarVisible: false,
  30211. toolbarOffset: 0,
  30212. linkEditorVisible: false,
  30213. sizeEditorVisible: false,
  30214. tempLink: null,
  30215. tempWidth: null,
  30216. tempHeight: null
  30217. });
  30218. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "initialLeft", void 0);
  30219. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "initialTop", void 0);
  30220. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "initialWidth", void 0);
  30221. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "initialHeight", void 0);
  30222. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "reSizeType", void 0);
  30223. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "changeSize", function (e) {
  30224. var type = _this.reSizeType;
  30225. if (!_this.initialLeft) {
  30226. _this.initialLeft = e.screenX;
  30227. _this.initialTop = e.screenY;
  30228. }
  30229. if (type === 'rightbottom') {
  30230. _this.initialHeight += e.screenY - _this.initialTop;
  30231. _this.initialWidth += e.screenX - _this.initialLeft;
  30232. }
  30233. if (type === 'leftbottom') {
  30234. _this.initialHeight += e.screenY - _this.initialTop;
  30235. _this.initialWidth += -e.screenX + _this.initialLeft;
  30236. }
  30237. _this.initialLeft = e.screenX;
  30238. _this.initialTop = e.screenY;
  30239. });
  30240. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "moveImage", function (e) {
  30241. _this.changeSize(e);
  30242. _this.setState({
  30243. tempWidth: Math.abs(_this.initialWidth),
  30244. tempHeight: Math.abs(_this.initialHeight)
  30245. });
  30246. });
  30247. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "upImage", function () {
  30248. _this.confirmImageSize();
  30249. document.removeEventListener('mousemove', _this.moveImage);
  30250. document.removeEventListener('mouseup', _this.upImage);
  30251. });
  30252. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "repareChangeSize", function (type) {
  30253. return function (e) {
  30254. _this.reSizeType = type;
  30255. var imageRect = _this.imageElement.getBoundingClientRect();
  30256. _this.initialLeft = _this.initialTop = 0;
  30257. _this.initialWidth = imageRect.width;
  30258. _this.initialHeight = imageRect.height;
  30259. e.preventDefault();
  30260. document.addEventListener('mousemove', _this.moveImage);
  30261. document.addEventListener('mouseup', _this.upImage);
  30262. };
  30263. });
  30264. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "preventDragEvent", function (event) {
  30265. event.stopPropagation();
  30266. event.preventDefault();
  30267. });
  30268. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleDragStart", function () {
  30269. if (_this.props.editor.editorProps.readOnly || _this.props.editor.editorProps.disabled) {
  30270. return false;
  30271. }
  30272. window.__BRAFT_DRAGING__IMAGE__ = {
  30273. block: _this.props.block,
  30274. mediaData: objectSpread_default()({
  30275. type: 'IMAGE'
  30276. }, _this.props.mediaData)
  30277. };
  30278. _this.setState({
  30279. toolbarVisible: false
  30280. }, function () {
  30281. _this.unlockEditor();
  30282. });
  30283. return true;
  30284. });
  30285. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleDragEnd", function () {
  30286. window.__BRAFT_DRAGING__IMAGE__ = null;
  30287. return false;
  30288. });
  30289. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "executeCommand", function (command) {
  30290. if (typeof command === 'string') {
  30291. var _command$split = command.split('|'),
  30292. _command$split2 = slicedToArray_default()(_command$split, 2),
  30293. method = _command$split2[0],
  30294. param = _command$split2[1];
  30295. _this[method] && _this[method](param);
  30296. } else if (typeof command === 'function') {
  30297. command(_this.props.block, _this.props.mediaData, _this.props.editor.getValue());
  30298. }
  30299. });
  30300. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeImage", function () {
  30301. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editor.getValue(), _this.props.block));
  30302. _this.unlockEditor();
  30303. });
  30304. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggleLinkEditor", function () {
  30305. _this.setState({
  30306. linkEditorVisible: !_this.state.linkEditorVisible,
  30307. sizeEditorVisible: false
  30308. });
  30309. });
  30310. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggleSizeEditor", function () {
  30311. _this.setState({
  30312. linkEditorVisible: false,
  30313. sizeEditorVisible: !_this.state.sizeEditorVisible
  30314. });
  30315. });
  30316. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleLinkInputKeyDown", function (e) {
  30317. if (e.keyCode === 13) {
  30318. _this.confirmImageLink();
  30319. } else {
  30320. return;
  30321. }
  30322. });
  30323. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageLink", function (e) {
  30324. _this.setState({
  30325. tempLink: e.currentTarget.value
  30326. });
  30327. return;
  30328. });
  30329. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "confirmImageLink", function () {
  30330. var link = _this.state.tempLink;
  30331. var hookReturns = _this.props.hooks('set-image-link', link)(link);
  30332. if (hookReturns === false) {
  30333. return false;
  30334. }
  30335. if (typeof hookReturns === 'string') {
  30336. link = hookReturns;
  30337. }
  30338. if (link !== null) {
  30339. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaData(_this.props.editor.getValue(), _this.props.entityKey, {
  30340. link: link
  30341. }));
  30342. window.setImmediate(_this.props.editor.forceRender);
  30343. }
  30344. });
  30345. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleSizeInputKeyDown", function (e) {
  30346. if (e.keyCode === 13) {
  30347. _this.confirmImageSize();
  30348. } else {
  30349. return;
  30350. }
  30351. });
  30352. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageWidth", function (_ref) {
  30353. var currentTarget = _ref.currentTarget;
  30354. var value = currentTarget.value;
  30355. value && !isNaN(value) && (value = value + 'px');
  30356. _this.setState({
  30357. tempWidth: value
  30358. });
  30359. return;
  30360. });
  30361. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageHeight", function (_ref2) {
  30362. var currentTarget = _ref2.currentTarget;
  30363. var value = currentTarget.value;
  30364. value && !isNaN(value) && (value = value + 'px');
  30365. _this.setState({
  30366. tempHeight: value
  30367. });
  30368. return;
  30369. });
  30370. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "confirmImageSize", function () {
  30371. var _this$state = _this.state,
  30372. width = _this$state.tempWidth,
  30373. height = _this$state.tempHeight;
  30374. var newImageSize = {};
  30375. width !== null && (newImageSize.width = width);
  30376. height !== null && (newImageSize.height = height);
  30377. var hookReturns = _this.props.hooks('set-image-size', newImageSize)(newImageSize);
  30378. if (hookReturns === false) {
  30379. return false;
  30380. }
  30381. if (hookReturns && (hookReturns.width || hookReturns.height)) {
  30382. newImageSize = hookReturns;
  30383. }
  30384. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaData(_this.props.editor.getValue(), _this.props.entityKey, newImageSize));
  30385. window.setImmediate(_this.props.editor.forceRender);
  30386. });
  30387. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageFloat", function (float) {
  30388. var hookReturns = _this.props.hooks('set-image-float', float)(float);
  30389. if (hookReturns === false) {
  30390. return false;
  30391. }
  30392. if (typeof hookReturns === 'string') {
  30393. float = hookReturns;
  30394. }
  30395. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaPosition(_this.props.editor.getValue(), _this.props.block, {
  30396. float: float
  30397. }));
  30398. _this.unlockEditor();
  30399. });
  30400. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageAlignment", function (alignment) {
  30401. var hookReturns = _this.props.hooks('set-image-alignment', alignment)(alignment);
  30402. if (hookReturns === false) {
  30403. return false;
  30404. }
  30405. if (typeof hookReturns === 'string') {
  30406. alignment = hookReturns;
  30407. }
  30408. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaPosition(_this.props.editor.getValue(), _this.props.block, {
  30409. alignment: alignment
  30410. }));
  30411. _this.unlockEditor();
  30412. });
  30413. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "showToolbar", function (event) {
  30414. if (_this.props.editor.editorProps.readOnly || _this.props.editor.editorProps.disabled) {
  30415. return false;
  30416. }
  30417. event.preventDefault();
  30418. if (!_this.state.toolbarVisible) {
  30419. _this.setState({
  30420. toolbarVisible: true
  30421. }, function () {
  30422. _this.lockEditor();
  30423. _this.setState({
  30424. toolbarOffset: _this.calcToolbarOffset()
  30425. });
  30426. });
  30427. }
  30428. });
  30429. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "hideToolbar", function (event) {
  30430. event.preventDefault();
  30431. _this.setState({
  30432. toolbarVisible: false
  30433. }, function () {
  30434. _this.unlockEditor(); // this.props.editor.requestFocus()
  30435. });
  30436. });
  30437. return _this;
  30438. }
  30439. createClass_default()(Image, [{
  30440. key: "render",
  30441. value: function render() {
  30442. var _this2 = this;
  30443. var _this$props = this.props,
  30444. mediaData = _this$props.mediaData,
  30445. language = _this$props.language,
  30446. imageControls = _this$props.imageControls,
  30447. imageResizable = _this$props.imageResizable;
  30448. var _this$state2 = this.state,
  30449. toolbarVisible = _this$state2.toolbarVisible,
  30450. toolbarOffset = _this$state2.toolbarOffset,
  30451. linkEditorVisible = _this$state2.linkEditorVisible,
  30452. sizeEditorVisible = _this$state2.sizeEditorVisible,
  30453. tempWidth = _this$state2.tempWidth,
  30454. tempHeight = _this$state2.tempHeight;
  30455. var blockData = this.props.block.getData();
  30456. var float = blockData.get('float');
  30457. var alignment = blockData.get('alignment');
  30458. var url = mediaData.url,
  30459. link = mediaData.link,
  30460. link_target = mediaData.link_target,
  30461. width = mediaData.width,
  30462. height = mediaData.height,
  30463. meta = mediaData.meta;
  30464. var imageStyles = {};
  30465. var clearFix = false;
  30466. if (float) {
  30467. alignment = null;
  30468. } else if (alignment === 'left') {
  30469. imageStyles.float = 'left';
  30470. clearFix = true;
  30471. } else if (alignment === 'right') {
  30472. imageStyles.float = 'right';
  30473. clearFix = true;
  30474. } else if (alignment === 'center') {
  30475. imageStyles.textAlign = 'center';
  30476. } else {
  30477. imageStyles.float = 'left';
  30478. clearFix = true;
  30479. }
  30480. var renderedControlItems = imageControls.map(function (item, index) {
  30481. if (typeof item === 'string' && imageControlItems[item]) {
  30482. return external_react_default.a.createElement("a", {
  30483. className: item === 'link' && link ? 'active' : '',
  30484. key: index,
  30485. onClick: function onClick() {
  30486. return _this2.executeCommand(imageControlItems[item].command);
  30487. }
  30488. }, imageControlItems[item].text);
  30489. } else if (item && (item.render || item.text)) {
  30490. return item.render ? item.render(mediaData, _this2.props.block) : external_react_default.a.createElement("a", {
  30491. key: index,
  30492. onClick: function onClick() {
  30493. return item.onClick && _this2.executeCommand(item.onClick);
  30494. }
  30495. }, item.text);
  30496. } else {
  30497. return null;
  30498. }
  30499. });
  30500. return external_react_default.a.createElement("div", {
  30501. className: "bf-media"
  30502. }, external_react_default.a.createElement("div", {
  30503. style: imageStyles,
  30504. draggable: true,
  30505. onMouseEnter: this.showToolbar,
  30506. onMouseMove: this.showToolbar,
  30507. onMouseLeave: this.hideToolbar,
  30508. onDragStart: this.handleDragStart,
  30509. onDragEnd: this.handleDragEnd,
  30510. ref: function ref(instance) {
  30511. return _this2.mediaEmbederInstance = instance;
  30512. },
  30513. className: "bf-image"
  30514. }, toolbarVisible ? external_react_default.a.createElement("div", {
  30515. style: {
  30516. marginLeft: toolbarOffset
  30517. },
  30518. ref: function ref(instance) {
  30519. return _this2.toolbarElement = instance;
  30520. },
  30521. "data-float": float,
  30522. "data-align": alignment,
  30523. className: "bf-media-toolbar"
  30524. }, linkEditorVisible ? external_react_default.a.createElement("div", {
  30525. className: "bf-image-link-editor"
  30526. }, external_react_default.a.createElement("div", {
  30527. className: "editor-input-group"
  30528. }, external_react_default.a.createElement("input", {
  30529. type: "text",
  30530. placeholder: language.linkEditor.inputWithEnterPlaceHolder,
  30531. onKeyDown: this.handleLinkInputKeyDown,
  30532. onChange: this.setImageLink,
  30533. defaultValue: link
  30534. }), external_react_default.a.createElement("button", {
  30535. type: "button",
  30536. onClick: this.confirmImageLink
  30537. }, language.base.confirm)), external_react_default.a.createElement("div", {
  30538. className: "switch-group"
  30539. }, external_react_default.a.createElement(Switch, {
  30540. active: link_target === '_blank',
  30541. onClick: function onClick() {
  30542. return _this2.setImageLinkTarget(link_target);
  30543. }
  30544. }), external_react_default.a.createElement("label", null, language.linkEditor.openInNewWindow))) : null, sizeEditorVisible ? external_react_default.a.createElement("div", {
  30545. className: "bf-image-size-editor"
  30546. }, external_react_default.a.createElement("div", {
  30547. className: "editor-input-group"
  30548. }, external_react_default.a.createElement("input", {
  30549. type: "text",
  30550. placeholder: language.base.width,
  30551. onKeyDown: this.handleSizeInputKeyDown,
  30552. onChange: this.setImageWidth,
  30553. defaultValue: width
  30554. }), external_react_default.a.createElement("input", {
  30555. type: "text",
  30556. placeholder: language.base.height,
  30557. onKeyDown: this.handleSizeInputKeyDown,
  30558. onChange: this.setImageHeight,
  30559. defaultValue: height
  30560. }), external_react_default.a.createElement("button", {
  30561. type: "button",
  30562. onClick: this.confirmImageSize
  30563. }, language.base.confirm))) : null, renderedControlItems, external_react_default.a.createElement("i", {
  30564. style: {
  30565. marginLeft: toolbarOffset * -1
  30566. },
  30567. className: "bf-media-toolbar-arrow"
  30568. })) : null, external_react_default.a.createElement("div", {
  30569. style: {
  30570. position: 'relative',
  30571. width: "".concat(width, "px"),
  30572. height: "".concat(height, "px"),
  30573. display: 'inline-block'
  30574. }
  30575. }, external_react_default.a.createElement("img", extends_default()({
  30576. ref: function ref(instance) {
  30577. return _this2.imageElement = instance;
  30578. },
  30579. src: url,
  30580. width: width,
  30581. height: height
  30582. }, meta)), toolbarVisible && imageResizable ? external_react_default.a.createElement("div", {
  30583. className: "bf-csize-icon right-bottom",
  30584. onMouseDown: this.repareChangeSize('rightbottom')
  30585. }) : null, toolbarVisible && imageResizable ? external_react_default.a.createElement("div", {
  30586. className: "bf-csize-icon left-bottom",
  30587. onMouseDown: this.repareChangeSize('leftbottom')
  30588. }) : null, external_react_default.a.createElement("div", {
  30589. className: "bf-pre-csize ".concat(this.reSizeType),
  30590. style: {
  30591. width: "".concat(tempWidth, "px"),
  30592. height: "".concat(tempHeight, "px")
  30593. }
  30594. }))), clearFix && external_react_default.a.createElement("div", {
  30595. className: "clearfix",
  30596. style: {
  30597. clear: 'both',
  30598. height: 0,
  30599. lineHeight: 0,
  30600. float: 'none'
  30601. }
  30602. }));
  30603. }
  30604. }, {
  30605. key: "lockEditor",
  30606. value: function lockEditor() {
  30607. this.props.editor.lockOrUnlockEditor(true);
  30608. }
  30609. }, {
  30610. key: "unlockEditor",
  30611. value: function unlockEditor() {
  30612. this.props.editor.lockOrUnlockEditor(false);
  30613. }
  30614. }, {
  30615. key: "calcToolbarOffset",
  30616. value: function calcToolbarOffset() {
  30617. var _this$props2 = this.props,
  30618. getContainerNode = _this$props2.getContainerNode,
  30619. containerNode = _this$props2.containerNode;
  30620. var container = getContainerNode ? getContainerNode() : containerNode;
  30621. if (!container) {
  30622. return 0;
  30623. }
  30624. var viewRect = container.querySelector('.bf-content').getBoundingClientRect();
  30625. var toolbarRect = this.toolbarElement.getBoundingClientRect();
  30626. var imageRect = this.imageElement.getBoundingClientRect();
  30627. var right = viewRect.right - (imageRect.right - imageRect.width / 2 + toolbarRect.width / 2);
  30628. var left = imageRect.left + imageRect.width / 2 - toolbarRect.width / 2 - viewRect.left;
  30629. if (right < 10) {
  30630. return right - 10;
  30631. } else if (left < 10) {
  30632. return left * -1 + 10;
  30633. } else {
  30634. return 0;
  30635. }
  30636. }
  30637. }, {
  30638. key: "setImageLinkTarget",
  30639. value: function setImageLinkTarget(link_target) {
  30640. var hookReturns = this.props.hooks('set-image-link-target', link_target)(link_target);
  30641. if (hookReturns === false) {
  30642. return false;
  30643. }
  30644. if (typeof hookReturns === 'string') {
  30645. link_target = hookReturns;
  30646. }
  30647. link_target = link_target === '_blank' ? '' : '_blank';
  30648. this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaData(this.props.editor.getValue(), this.props.entityKey, {
  30649. link_target: link_target
  30650. }));
  30651. window.setImmediate(this.props.editor.forceRender);
  30652. }
  30653. }]);
  30654. return Image;
  30655. }(external_react_default.a.Component);
  30656. // EXTERNAL MODULE: ./renderers/atomics/Video/style.scss
  30657. var Video_style = __webpack_require__(47);
  30658. // EXTERNAL MODULE: ./components/common/Modal/style.scss
  30659. var Modal_style = __webpack_require__(48);
  30660. // EXTERNAL MODULE: external "react-dom"
  30661. var external_react_dom_ = __webpack_require__(16);
  30662. var external_react_dom_default = /*#__PURE__*/__webpack_require__.n(external_react_dom_);
  30663. // CONCATENATED MODULE: ./components/common/Modal/index.jsx
  30664. var Modal_Modal =
  30665. /*#__PURE__*/
  30666. function (_React$Component) {
  30667. inherits_default()(Modal, _React$Component);
  30668. function Modal(props) {
  30669. var _this;
  30670. classCallCheck_default()(this, Modal);
  30671. _this = possibleConstructorReturn_default()(this, getPrototypeOf_default()(Modal).call(this, props));
  30672. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleTransitionEnd", function () {
  30673. if (!_this.rootElement || !_this.rootElement.classList) {
  30674. return false;
  30675. }
  30676. if (!_this.rootElement.classList.contains('active')) {
  30677. external_react_dom_default.a.unmountComponentAtNode(_this.rootElement) && _this.rootElement.parentNode.removeChild(_this.rootElement);
  30678. }
  30679. });
  30680. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleMouseDown", function (event) {
  30681. var tagName = event.target.tagName.toLowerCase();
  30682. if (tagName === 'input' || tagName === 'textarea') {
  30683. return false;
  30684. }
  30685. event.preventDefault();
  30686. });
  30687. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleCancel", function () {
  30688. _this.props.closeOnCancel && _this.close();
  30689. _this.props.onCancel && _this.props.onCancel();
  30690. });
  30691. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleConfirm", function () {
  30692. _this.props.closeOnConfirm && _this.close();
  30693. _this.props.onConfirm && _this.props.onConfirm();
  30694. });
  30695. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleMaskClick", function () {
  30696. _this.props.closeOnBlur && _this.close();
  30697. _this.props.onBlue && _this.props.onBlue();
  30698. });
  30699. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "close", function () {
  30700. _this.unrenderComponent();
  30701. _this.props.onClose && _this.props.onClose();
  30702. });
  30703. _this.active = false;
  30704. _this.componentId = 'BRAFT-MODAL-' + external_braft_utils_["BaseUtils"].UniqueIndex();
  30705. return _this;
  30706. }
  30707. createClass_default()(Modal, [{
  30708. key: "componentDidMount",
  30709. value: function componentDidMount() {
  30710. if (this.props.visible) {
  30711. this.active = true;
  30712. this.renderComponent(this.props);
  30713. }
  30714. }
  30715. }, {
  30716. key: "componentWillReceiveProps",
  30717. value: function componentWillReceiveProps(next) {
  30718. if (this.props.visible && !next.visible) {
  30719. this.unrenderComponent();
  30720. } else if (this.props.visible || next.visible) {
  30721. this.active = true;
  30722. this.renderComponent(next);
  30723. }
  30724. }
  30725. }, {
  30726. key: "render",
  30727. value: function render() {
  30728. return null;
  30729. }
  30730. }, {
  30731. key: "unrenderComponent",
  30732. value: function unrenderComponent() {
  30733. this.active = false;
  30734. this.activeId && window.clearImmediate(this.activeId);
  30735. if (this.rootElement && this.rootElement.classList) {
  30736. this.rootElement.classList.remove('active');
  30737. }
  30738. }
  30739. }, {
  30740. key: "renderComponent",
  30741. value: function renderComponent(props) {
  30742. var _this2 = this;
  30743. if (!this.active) {
  30744. return false;
  30745. }
  30746. var title = props.title,
  30747. className = props.className,
  30748. width = props.width,
  30749. height = props.height,
  30750. children = props.children,
  30751. component = props.component,
  30752. confirmable = props.confirmable,
  30753. showFooter = props.showFooter,
  30754. showCancel = props.showCancel,
  30755. showConfirm = props.showConfirm,
  30756. showClose = props.showClose,
  30757. cancelText = props.cancelText,
  30758. confirmText = props.confirmText,
  30759. bottomText = props.bottomText,
  30760. language = props.language;
  30761. typeof showCancel === 'undefined' && (showCancel = true);
  30762. typeof showClose === 'undefined' && (showClose = true);
  30763. typeof showConfirm === 'undefined' && (showConfirm = true);
  30764. typeof showFooter === 'undefined' && (showFooter = true);
  30765. var childComponent = external_react_default.a.createElement("div", {
  30766. onMouseDown: this.handleMouseDown,
  30767. className: 'bf-modal ' + (className || '')
  30768. }, external_react_default.a.createElement("div", {
  30769. className: "bf-modal-mask",
  30770. onClick: this.handleMaskClick
  30771. }), external_react_default.a.createElement("div", {
  30772. onTransitionEnd: this.handleTransitionEnd,
  30773. style: {
  30774. width: width,
  30775. height: height
  30776. },
  30777. className: "bf-modal-content"
  30778. }, external_react_default.a.createElement("div", {
  30779. className: "bf-modal-header"
  30780. }, external_react_default.a.createElement("h3", {
  30781. className: "bf-modal-caption"
  30782. }, title), showClose && external_react_default.a.createElement("button", {
  30783. type: "button",
  30784. onClick: this.close,
  30785. className: "bf-modal-close-button"
  30786. }, external_react_default.a.createElement("i", {
  30787. className: "bfi-close"
  30788. }))), external_react_default.a.createElement("div", {
  30789. className: "bf-modal-body"
  30790. }, children || component), showFooter ? external_react_default.a.createElement("div", {
  30791. className: "bf-modal-footer"
  30792. }, external_react_default.a.createElement("div", {
  30793. className: "bf-modal-addon-text"
  30794. }, bottomText), external_react_default.a.createElement("div", {
  30795. className: "bf-modal-buttons"
  30796. }, showCancel && external_react_default.a.createElement("button", {
  30797. type: "button",
  30798. onClick: this.handleCancel,
  30799. className: "bf-modal-cancel"
  30800. }, cancelText || language.base.cancel), showConfirm && external_react_default.a.createElement("button", {
  30801. type: "button",
  30802. onClick: this.handleConfirm,
  30803. className: 'bf-modal-confirm ' + (!confirmable ? 'disabled' : '')
  30804. }, confirmText || language.base.confirm))) : null));
  30805. this.rootElement = document.querySelector('#' + this.componentId);
  30806. if (!this.rootElement) {
  30807. this.rootElement = document.createElement('div');
  30808. this.rootElement.id = this.componentId;
  30809. this.rootElement.className = 'bf-modal-root';
  30810. document.body.appendChild(this.rootElement);
  30811. }
  30812. external_react_dom_default.a.render(childComponent, this.rootElement);
  30813. this.activeId = window.setImmediate(function () {
  30814. _this2.rootElement.classList.add('active');
  30815. });
  30816. }
  30817. }]);
  30818. return Modal;
  30819. }(external_react_default.a.Component);
  30820. defineProperty_default()(Modal_Modal, "defaultProps", {
  30821. showFooter: true,
  30822. closeOnBlur: true
  30823. });
  30824. var Modal_showModal = function showModal(props) {
  30825. var hostNode = document.createElement('div');
  30826. hostNode.style.display = 'none';
  30827. document.body.appendChild(hostNode);
  30828. props = objectSpread_default()({
  30829. visible: true,
  30830. closeOnConfirm: true,
  30831. closeOnCancel: true
  30832. }, props);
  30833. var close = function close() {
  30834. external_react_dom_default.a.unmountComponentAtNode(hostNode) && hostNode.parentNode.removeChild(hostNode);
  30835. };
  30836. var onConfirm = function onConfirm() {
  30837. props.onConfirm && props.onConfirm();
  30838. };
  30839. var onCancel = function onCancel() {
  30840. props.onCancel && props.onCancel();
  30841. };
  30842. var onClose = function onClose() {
  30843. close();
  30844. props.onClose && props.onClose();
  30845. };
  30846. var modalInstance = external_react_dom_default.a.render(external_react_default.a.createElement(Modal_Modal, extends_default()({}, props, {
  30847. onConfirm: onConfirm,
  30848. onCancel: onCancel,
  30849. onClose: onClose
  30850. })), hostNode);
  30851. modalInstance.destroy = close;
  30852. modalInstance.update = modalInstance.renderComponent;
  30853. return modalInstance;
  30854. };
  30855. // EXTERNAL MODULE: ./components/business/PlayerModal/style.scss
  30856. var PlayerModal_style = __webpack_require__(49);
  30857. // CONCATENATED MODULE: ./components/business/PlayerModal/index.jsx
  30858. var PlayerModal_playViaModal = function playViaModal(title, component, language) {
  30859. return Modal_showModal({
  30860. title: title,
  30861. component: component,
  30862. language: language,
  30863. showFooter: false
  30864. });
  30865. };
  30866. var typeIconsMap = {
  30867. 'video': 'bfi-film',
  30868. 'audio': 'bfi-music',
  30869. 'embed': 'bfi-code'
  30870. };
  30871. /* harmony default export */ var PlayerModal = (function (_ref) {
  30872. var title = _ref.title,
  30873. type = _ref.type,
  30874. language = _ref.language,
  30875. name = _ref.name,
  30876. url = _ref.url,
  30877. poster = _ref.poster,
  30878. children = _ref.children,
  30879. onRemove = _ref.onRemove;
  30880. return external_react_default.a.createElement("div", {
  30881. className: "bf-player-holder ".concat(type)
  30882. }, external_react_default.a.createElement("div", {
  30883. className: "icon-badge"
  30884. }, external_react_default.a.createElement("i", {
  30885. className: typeIconsMap[type]
  30886. }), external_react_default.a.createElement("span", {
  30887. className: "text"
  30888. }, language.media[type])), external_react_default.a.createElement("button", {
  30889. onMouseDown: onRemove,
  30890. className: "button-remove"
  30891. }, external_react_default.a.createElement("i", {
  30892. className: "bfi-close"
  30893. })), external_react_default.a.createElement("button", {
  30894. onMouseDown: function onMouseDown() {
  30895. return PlayerModal_playViaModal(name ? "".concat(title, ":").concat(name) : title, children, language);
  30896. },
  30897. className: "button-play"
  30898. }, external_react_default.a.createElement("i", {
  30899. className: "bfi-play_arrow"
  30900. })), name ? external_react_default.a.createElement("h5", {
  30901. className: "bf-name"
  30902. }, name) : null, external_react_default.a.createElement("h6", {
  30903. className: "bf-url"
  30904. }, url), poster ? external_react_default.a.createElement("div", {
  30905. className: "bf-poster",
  30906. style: {
  30907. backgroundImage: "url(".concat(poster, ")")
  30908. }
  30909. }) : null);
  30910. });
  30911. // CONCATENATED MODULE: ./renderers/atomics/Video/index.jsx
  30912. var Video_Video =
  30913. /*#__PURE__*/
  30914. function (_React$Component) {
  30915. inherits_default()(Video, _React$Component);
  30916. function Video() {
  30917. var _getPrototypeOf2;
  30918. var _this;
  30919. classCallCheck_default()(this, Video);
  30920. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  30921. args[_key] = arguments[_key];
  30922. }
  30923. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(Video)).call.apply(_getPrototypeOf2, [this].concat(args)));
  30924. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeVideo", function () {
  30925. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editorState, _this.props.block));
  30926. });
  30927. return _this;
  30928. }
  30929. createClass_default()(Video, [{
  30930. key: "render",
  30931. value: function render() {
  30932. var _this$props = this.props,
  30933. mediaData = _this$props.mediaData,
  30934. language = _this$props.language;
  30935. var url = mediaData.url,
  30936. name = mediaData.name,
  30937. meta = mediaData.meta;
  30938. return external_react_default.a.createElement("div", {
  30939. className: "bf-video-wrap"
  30940. }, external_react_default.a.createElement(PlayerModal, {
  30941. type: "video",
  30942. onRemove: this.removeVideo,
  30943. poster: meta ? meta.poster || '' : '',
  30944. language: language,
  30945. url: url,
  30946. name: name,
  30947. title: language.videoPlayer.title
  30948. }, external_react_default.a.createElement("div", {
  30949. className: "bf-video-player"
  30950. }, external_react_default.a.createElement("video", {
  30951. controls: true,
  30952. poster: meta ? meta.poster || '' : ''
  30953. }, external_react_default.a.createElement("source", {
  30954. src: url
  30955. })))));
  30956. }
  30957. }]);
  30958. return Video;
  30959. }(external_react_default.a.Component);
  30960. // EXTERNAL MODULE: ./renderers/atomics/Audio/style.scss
  30961. var Audio_style = __webpack_require__(50);
  30962. // CONCATENATED MODULE: ./renderers/atomics/Audio/index.jsx
  30963. var Audio_Audio =
  30964. /*#__PURE__*/
  30965. function (_React$Component) {
  30966. inherits_default()(Audio, _React$Component);
  30967. function Audio() {
  30968. var _getPrototypeOf2;
  30969. var _this;
  30970. classCallCheck_default()(this, Audio);
  30971. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  30972. args[_key] = arguments[_key];
  30973. }
  30974. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(Audio)).call.apply(_getPrototypeOf2, [this].concat(args)));
  30975. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeAudio", function () {
  30976. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editorState, _this.props.block));
  30977. });
  30978. return _this;
  30979. }
  30980. createClass_default()(Audio, [{
  30981. key: "render",
  30982. value: function render() {
  30983. var _this$props = this.props,
  30984. mediaData = _this$props.mediaData,
  30985. language = _this$props.language;
  30986. var url = mediaData.url,
  30987. name = mediaData.name,
  30988. meta = mediaData.meta;
  30989. return external_react_default.a.createElement("div", {
  30990. className: "bf-audio-wrap"
  30991. }, external_react_default.a.createElement(PlayerModal, {
  30992. type: "audio",
  30993. onRemove: this.removeAudio,
  30994. poster: meta ? meta.poster || '' : '',
  30995. language: language,
  30996. url: url,
  30997. name: name,
  30998. title: language.audioPlayer.title
  30999. }, external_react_default.a.createElement("div", {
  31000. className: "bf-audio-player"
  31001. }, external_react_default.a.createElement("audio", {
  31002. controls: true,
  31003. src: url
  31004. }))));
  31005. }
  31006. }]);
  31007. return Audio;
  31008. }(external_react_default.a.Component);
  31009. // EXTERNAL MODULE: ./renderers/atomics/Embed/style.scss
  31010. var Embed_style = __webpack_require__(51);
  31011. // CONCATENATED MODULE: ./renderers/atomics/Embed/index.jsx
  31012. var Embed_Embed =
  31013. /*#__PURE__*/
  31014. function (_React$Component) {
  31015. inherits_default()(Embed, _React$Component);
  31016. function Embed() {
  31017. var _getPrototypeOf2;
  31018. var _this;
  31019. classCallCheck_default()(this, Embed);
  31020. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  31021. args[_key] = arguments[_key];
  31022. }
  31023. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(Embed)).call.apply(_getPrototypeOf2, [this].concat(args)));
  31024. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeEmbed", function () {
  31025. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editorState, _this.props.block));
  31026. });
  31027. return _this;
  31028. }
  31029. createClass_default()(Embed, [{
  31030. key: "render",
  31031. value: function render() {
  31032. var _this$props = this.props,
  31033. mediaData = _this$props.mediaData,
  31034. language = _this$props.language;
  31035. var name = mediaData.name,
  31036. url = mediaData.url,
  31037. meta = mediaData.meta;
  31038. return external_react_default.a.createElement("div", {
  31039. className: "bf-embed-wrap"
  31040. }, external_react_default.a.createElement(PlayerModal, {
  31041. type: "embed",
  31042. onRemove: this.removeEmbed,
  31043. poster: meta ? meta.poster || '' : '',
  31044. language: language,
  31045. url: url,
  31046. name: name,
  31047. title: language.videoPlayer.embedTitle
  31048. }, external_react_default.a.createElement("div", {
  31049. className: "bf-embed-player",
  31050. dangerouslySetInnerHTML: {
  31051. __html: url
  31052. }
  31053. })));
  31054. }
  31055. }]);
  31056. return Embed;
  31057. }(external_react_default.a.Component);
  31058. // EXTERNAL MODULE: ./renderers/atomics/HorizontalLine/style.scss
  31059. var HorizontalLine_style = __webpack_require__(52);
  31060. // CONCATENATED MODULE: ./renderers/atomics/HorizontalLine/index.jsx
  31061. var HorizontalLine_HorizontalLine =
  31062. /*#__PURE__*/
  31063. function (_React$Component) {
  31064. inherits_default()(HorizontalLine, _React$Component);
  31065. function HorizontalLine() {
  31066. var _getPrototypeOf2;
  31067. var _this;
  31068. classCallCheck_default()(this, HorizontalLine);
  31069. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  31070. args[_key] = arguments[_key];
  31071. }
  31072. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(HorizontalLine)).call.apply(_getPrototypeOf2, [this].concat(args)));
  31073. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeHorizontalLine", function () {
  31074. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editorState, _this.props.block));
  31075. });
  31076. return _this;
  31077. }
  31078. createClass_default()(HorizontalLine, [{
  31079. key: "render",
  31080. value: function render() {
  31081. return external_react_default.a.createElement("div", {
  31082. className: "bf-hr"
  31083. }, external_react_default.a.createElement("div", {
  31084. className: "bf-media-toolbar"
  31085. }, external_react_default.a.createElement("a", {
  31086. onClick: this.removeHorizontalLine
  31087. }, "\uE9AC")));
  31088. }
  31089. }]);
  31090. return HorizontalLine;
  31091. }(external_react_default.a.Component);
  31092. // CONCATENATED MODULE: ./renderers/block/blockRendererFn.js
  31093. var blockRendererFn_BlockRenderFnContext = function BlockRenderFnContext() {
  31094. var _this = this;
  31095. classCallCheck_default()(this, BlockRenderFnContext);
  31096. defineProperty_default()(this, "superProps", void 0);
  31097. defineProperty_default()(this, "customBlockRendererFn", void 0);
  31098. defineProperty_default()(this, "getRenderFn", function (superProps, customBlockRendererFn) {
  31099. _this.superProps = superProps;
  31100. _this.customBlockRendererFn = customBlockRendererFn;
  31101. return _this.blockRendererFn;
  31102. });
  31103. defineProperty_default()(this, "renderAtomicBlock", function (props) {
  31104. var superProps = _this.superProps;
  31105. var entityKey = props.block.getEntityAt(0);
  31106. if (!entityKey) {
  31107. return null;
  31108. }
  31109. var entity = props.contentState.getEntity(entityKey);
  31110. var mediaData = entity.getData();
  31111. var mediaType = entity.getType();
  31112. var mediaProps = objectSpread_default()({}, superProps, {
  31113. block: props.block,
  31114. mediaData: mediaData,
  31115. entityKey: entityKey
  31116. });
  31117. if (mediaType === 'IMAGE') {
  31118. return external_react_default.a.createElement(Image_Image, mediaProps);
  31119. } else if (mediaType === 'AUDIO') {
  31120. return external_react_default.a.createElement(Audio_Audio, mediaProps);
  31121. } else if (mediaType === 'VIDEO') {
  31122. return external_react_default.a.createElement(Video_Video, mediaProps);
  31123. } else if (mediaType === 'EMBED') {
  31124. return external_react_default.a.createElement(Embed_Embed, mediaProps);
  31125. } else if (mediaType === 'HR') {
  31126. return external_react_default.a.createElement(HorizontalLine_HorizontalLine, mediaProps);
  31127. }
  31128. if (superProps.extendAtomics) {
  31129. var atomics = superProps.extendAtomics;
  31130. for (var i = 0; i < atomics.length; i++) {
  31131. if (mediaType === atomics[i].type) {
  31132. var Component = atomics[i].component;
  31133. return external_react_default.a.createElement(Component, mediaProps);
  31134. }
  31135. }
  31136. }
  31137. return null;
  31138. });
  31139. defineProperty_default()(this, "blockRendererFn", function (block) {
  31140. var customBlockRendererFn = _this.customBlockRendererFn,
  31141. superProps = _this.superProps;
  31142. var blockType = block.getType();
  31143. var blockRenderer = null;
  31144. if (customBlockRendererFn) {
  31145. blockRenderer = customBlockRendererFn(block, superProps) || null;
  31146. }
  31147. if (blockRenderer) {
  31148. return blockRenderer;
  31149. }
  31150. var extensionBlockRendererFns = getExtensionBlockRendererFns(superProps.editorId);
  31151. extensionBlockRendererFns.find(function (item) {
  31152. if (item.blockType === blockType || item.blockType instanceof RegExp && item.blockType.test(blockType)) {
  31153. blockRenderer = item.rendererFn ? item.rendererFn(superProps) : null;
  31154. return true;
  31155. }
  31156. });
  31157. if (blockRenderer) {
  31158. return blockRenderer;
  31159. }
  31160. if (blockType === 'atomic') {
  31161. blockRenderer = {
  31162. component: _this.renderAtomicBlock,
  31163. editable: false
  31164. };
  31165. }
  31166. return blockRenderer;
  31167. });
  31168. };
  31169. var blockRenderFnContext = new blockRendererFn_BlockRenderFnContext();
  31170. /* harmony default export */ var block_blockRendererFn = (blockRenderFnContext.getRenderFn);
  31171. // CONCATENATED MODULE: ./renderers/block/blockStyleFn.js
  31172. /* harmony default export */ var block_blockStyleFn = (function (customBlockStyleFn) {
  31173. return function (block) {
  31174. var blockAlignment = block.getData() && block.getData().get('textAlign');
  31175. var blockIndent = block.getData() && block.getData().get('textIndent');
  31176. var blockFloat = block.getData() && block.getData().get('float');
  31177. var result = '';
  31178. if (blockAlignment) {
  31179. result = "bfa-".concat(blockAlignment);
  31180. }
  31181. if (blockIndent && blockIndent !== 0) {
  31182. result += " bftd-".concat(blockIndent);
  31183. }
  31184. if (blockFloat) {
  31185. result += " bff-".concat(blockFloat);
  31186. }
  31187. if (customBlockStyleFn) {
  31188. result += customBlockStyleFn(block) || '';
  31189. }
  31190. return result;
  31191. };
  31192. });
  31193. // CONCATENATED MODULE: ./renderers/inline/inlineStyleMap.js
  31194. /* harmony default export */ var inlineStyleMap = (function (props) {
  31195. var customStyleMap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  31196. var extensionInlineStyleMap = getExtensionInlineStyleMap(props.editorId);
  31197. return objectSpread_default()({
  31198. 'SUPERSCRIPT': {
  31199. position: 'relative',
  31200. top: '-8px',
  31201. fontSize: '11px'
  31202. },
  31203. 'SUBSCRIPT': {
  31204. position: 'relative',
  31205. bottom: '-8px',
  31206. fontSize: '11px'
  31207. }
  31208. }, extensionInlineStyleMap, customStyleMap);
  31209. });
  31210. // CONCATENATED MODULE: ./renderers/inline/inlineStyleFn.js
  31211. var getStyleValue = function getStyleValue(style) {
  31212. return style.split('-')[1];
  31213. };
  31214. /* harmony default export */ var inlineStyleFn = (function (props, options) {
  31215. return function (styles, block) {
  31216. var output = {};
  31217. var fontFamilies = options.fontFamilies,
  31218. unitExportFn = options.unitExportFn,
  31219. customStyleFn = options.customStyleFn;
  31220. var extensionInlineStyleFns = getExtensionInlineStyleFns(props.editorId);
  31221. extensionInlineStyleFns.forEach(function (item) {
  31222. output = item.styleFn ? item.styleFn(styles, block, output) : output;
  31223. });
  31224. output = customStyleFn ? customStyleFn(styles, block, output) : {};
  31225. styles.forEach(function (style) {
  31226. if (style.indexOf('COLOR-') === 0) {
  31227. output.color = '#' + getStyleValue(style);
  31228. } else if (style.indexOf('BGCOLOR-') === 0) {
  31229. output.backgroundColor = '#' + getStyleValue(style);
  31230. } else if (style.indexOf('FONTSIZE-') === 0) {
  31231. output.fontSize = unitExportFn(getStyleValue(style), 'font-size', 'editor');
  31232. } else if (style.indexOf('LINEHEIGHT-') === 0) {
  31233. output.lineHeight = unitExportFn(getStyleValue(style), 'line-height', 'editor');
  31234. } else if (style.indexOf('LETTERSPACING-') === 0) {
  31235. output.letterSpacing = unitExportFn(getStyleValue(style), 'letter-spacing', 'editor');
  31236. } else if (style.indexOf('TEXTINDENT-') === 0) {
  31237. output.textIndent = unitExportFn(getStyleValue(style), 'text-indent', 'editor');
  31238. } else if (style.indexOf('FONTFAMILY-') === 0) {
  31239. output.fontFamily = (fontFamilies.find(function (item) {
  31240. return item.name.toUpperCase() === getStyleValue(style);
  31241. }) || {}).family || '';
  31242. }
  31243. });
  31244. return output;
  31245. };
  31246. });
  31247. // EXTERNAL MODULE: ../node_modules/draft-js-multidecorators/index.js
  31248. var draft_js_multidecorators = __webpack_require__(18);
  31249. var draft_js_multidecorators_default = /*#__PURE__*/__webpack_require__.n(draft_js_multidecorators);
  31250. // CONCATENATED MODULE: ./renderers/decorators/Link/index.jsx
  31251. /* harmony default export */ var Link = (function (props) {
  31252. var children = props.children,
  31253. entityKey = props.entityKey,
  31254. contentState = props.contentState;
  31255. var _contentState$getEnti = contentState.getEntity(entityKey).getData(),
  31256. href = _contentState$getEnti.href,
  31257. target = _contentState$getEnti.target;
  31258. return external_react_default.a.createElement("span", {
  31259. className: "bf-link-wrap"
  31260. }, external_react_default.a.createElement("a", {
  31261. onClick: function onClick(event) {
  31262. return viewLink(event, href);
  31263. },
  31264. className: "bf-link",
  31265. href: href,
  31266. target: target
  31267. }, children));
  31268. });
  31269. var viewLink = function viewLink(event, link) {
  31270. // 当按下Ctrl/command键时,点击打开链接文字中的url
  31271. if (event.getModifierState('Control') || event.getModifierState('Meta')) {
  31272. var tempLink = document.createElement('a');
  31273. tempLink.href = link;
  31274. tempLink.target = event.currentTarget.target;
  31275. tempLink.click();
  31276. }
  31277. };
  31278. // CONCATENATED MODULE: ./renderers/decorators/index.js
  31279. var KEY_SEPARATOR = '-';
  31280. draft_js_multidecorators_default.a.prototype.getDecorations = function (block, contentState) {
  31281. var decorations = Array(block.getText().length).fill(null);
  31282. this.decorators.forEach(function (decorator, i) {
  31283. decorator.getDecorations(block, contentState).forEach(function (key, offset) {
  31284. if (!key) {
  31285. return;
  31286. }
  31287. key = i + KEY_SEPARATOR + key;
  31288. decorations[offset] = key;
  31289. });
  31290. });
  31291. return external_immutable_default.a.List(decorations);
  31292. };
  31293. var builtinDecorators = [{
  31294. type: 'entity',
  31295. decorator: {
  31296. key: 'LINK',
  31297. component: Link
  31298. }
  31299. }];
  31300. var createStrategy = function createStrategy(type) {
  31301. return function (block, callback, contentState) {
  31302. block.findEntityRanges(function (character) {
  31303. var entityKey = character.getEntity();
  31304. return entityKey !== null && contentState.getEntity(entityKey).getType() === type;
  31305. }, callback);
  31306. };
  31307. };
  31308. /* harmony default export */ var decorators = (function (editorId) {
  31309. var extensionDecorators = getExtensionDecorators(editorId);
  31310. var entityDecorators = builtinDecorators.concat(toConsumableArray_default()(extensionDecorators.filter(function (item) {
  31311. return item.type === 'entity';
  31312. })));
  31313. var strategyDecorators = extensionDecorators.filter(function (item) {
  31314. return item.type === 'strategy';
  31315. });
  31316. var classDecorators = extensionDecorators.filter(function (item) {
  31317. return item.type === 'class';
  31318. });
  31319. return new draft_js_multidecorators_default.a(toConsumableArray_default()(classDecorators.map(function (item) {
  31320. return item.decorator;
  31321. })).concat([// combine decorators created with strategy
  31322. new external_draft_js_["CompositeDecorator"](strategyDecorators.map(function (item) {
  31323. return item.decorator;
  31324. })), // combine decorators for entities
  31325. new external_draft_js_["CompositeDecorator"](entityDecorators.map(function (item) {
  31326. return {
  31327. strategy: createStrategy(item.decorator.key),
  31328. component: item.decorator.component
  31329. };
  31330. }))]));
  31331. });
  31332. // CONCATENATED MODULE: ./renderers/index.js
  31333. var getBlockRenderMap = block_blockRenderMap;
  31334. var getBlockRendererFn = block_blockRendererFn;
  31335. var getBlockStyleFn = block_blockStyleFn;
  31336. var getCustomStyleMap = inlineStyleMap;
  31337. var getCustomStyleFn = inlineStyleFn;
  31338. var getDecorators = decorators;
  31339. // EXTERNAL MODULE: ./components/business/ControlBar/style.scss
  31340. var ControlBar_style = __webpack_require__(53);
  31341. // EXTERNAL MODULE: ./components/business/LinkEditor/style.scss
  31342. var LinkEditor_style = __webpack_require__(54);
  31343. // EXTERNAL MODULE: ./components/common/DropDown/style.scss
  31344. var DropDown_style = __webpack_require__(55);
  31345. // CONCATENATED MODULE: ./helpers/responsive.js
  31346. var resizeEventHandlers = [];
  31347. var responsiveHelperInited = false;
  31348. var debouce = false;
  31349. /* harmony default export */ var responsive = ({
  31350. resolve: function resolve(eventHandler) {
  31351. var id = external_braft_utils_["BaseUtils"].UniqueIndex();
  31352. resizeEventHandlers.push({
  31353. id: id,
  31354. eventHandler: eventHandler
  31355. });
  31356. return id;
  31357. },
  31358. unresolve: function unresolve(id) {
  31359. resizeEventHandlers = resizeEventHandlers.filter(function (item) {
  31360. return item.id !== id;
  31361. });
  31362. }
  31363. });
  31364. if (!responsiveHelperInited && (typeof window === "undefined" ? "undefined" : typeof_default()(window)) === 'object') {
  31365. window.addEventListener('resize', function (event) {
  31366. clearTimeout(debouce);
  31367. debouce = setTimeout(function () {
  31368. resizeEventHandlers.map(function (item) {
  31369. typeof item.eventHandler === 'function' && item.eventHandler(event);
  31370. });
  31371. debouce = false;
  31372. }, 100);
  31373. });
  31374. responsiveHelperInited = true;
  31375. }
  31376. // CONCATENATED MODULE: ./components/common/DropDown/index.jsx
  31377. var DropDown_DropDown =
  31378. /*#__PURE__*/
  31379. function (_React$Component) {
  31380. inherits_default()(DropDown, _React$Component);
  31381. function DropDown() {
  31382. var _getPrototypeOf2;
  31383. var _this;
  31384. classCallCheck_default()(this, DropDown);
  31385. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  31386. args[_key] = arguments[_key];
  31387. }
  31388. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(DropDown)).call.apply(_getPrototypeOf2, [this].concat(args)));
  31389. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "responsiveResolveId", null);
  31390. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "dropDownHandlerElement", null);
  31391. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "dropDownContentElement", null);
  31392. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  31393. active: false,
  31394. offset: 0
  31395. });
  31396. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "fixDropDownPosition", function () {
  31397. var viewRect = _this.props.getContainerNode().getBoundingClientRect();
  31398. var handlerRect = _this.dropDownHandlerElement.getBoundingClientRect();
  31399. var contentRect = _this.dropDownContentElement.getBoundingClientRect();
  31400. var offset = 0;
  31401. var right = handlerRect.right - handlerRect.width / 2 + contentRect.width / 2;
  31402. var left = handlerRect.left + handlerRect.width / 2 - contentRect.width / 2;
  31403. right = viewRect.right - right;
  31404. left = left - viewRect.left;
  31405. if (right < 10) {
  31406. offset = right - 10;
  31407. } else if (left < 10) {
  31408. offset = left * -1 + 10;
  31409. }
  31410. if (offset !== _this.state.offset) {
  31411. _this.setState({
  31412. offset: offset
  31413. });
  31414. }
  31415. });
  31416. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "registerClickEvent", function (event) {
  31417. var autoHide = _this.props.autoHide;
  31418. var active = _this.state.active;
  31419. if (_this.dropDownContentElement.contains(event.target) || _this.dropDownHandlerElement.contains(event.target)) {
  31420. return false;
  31421. }
  31422. autoHide && active && _this.hide();
  31423. });
  31424. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggle", function () {
  31425. _this.setState({
  31426. active: !_this.state.active
  31427. });
  31428. });
  31429. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "show", function () {
  31430. _this.setState({
  31431. active: true
  31432. });
  31433. });
  31434. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "hide", function () {
  31435. _this.setState({
  31436. active: false
  31437. });
  31438. });
  31439. return _this;
  31440. }
  31441. createClass_default()(DropDown, [{
  31442. key: "componentDidMount",
  31443. value: function componentDidMount() {
  31444. if (document) {
  31445. document.body.addEventListener('click', this.registerClickEvent);
  31446. this.responsiveResolveId = responsive.resolve(this.fixDropDownPosition);
  31447. }
  31448. }
  31449. }, {
  31450. key: "componentWillReceiveProps",
  31451. value: function componentWillReceiveProps(next) {
  31452. if (!this.props.disabled && next.disabled) {
  31453. this.hide();
  31454. }
  31455. }
  31456. }, {
  31457. key: "componentDidUpdate",
  31458. value: function componentDidUpdate(prevState) {
  31459. if (!prevState.active && this.state.active) {
  31460. this.fixDropDownPosition();
  31461. }
  31462. }
  31463. }, {
  31464. key: "componentWillUnmount",
  31465. value: function componentWillUnmount() {
  31466. if (document) {
  31467. document.body.removeEventListener('click', this.registerClickEvent);
  31468. responsive.unresolve(this.responsiveResolveId);
  31469. }
  31470. }
  31471. }, {
  31472. key: "render",
  31473. value: function render() {
  31474. var _this2 = this;
  31475. var _this$state = this.state,
  31476. active = _this$state.active,
  31477. offset = _this$state.offset;
  31478. var _this$props = this.props,
  31479. caption = _this$props.caption,
  31480. htmlCaption = _this$props.htmlCaption,
  31481. title = _this$props.title,
  31482. disabled = _this$props.disabled,
  31483. showArrow = _this$props.showArrow,
  31484. arrowActive = _this$props.arrowActive,
  31485. className = _this$props.className,
  31486. children = _this$props.children,
  31487. theme = _this$props.theme;
  31488. disabled && (active = false);
  31489. theme === 'light' && (className = ' light-theme ' + className);
  31490. return external_react_default.a.createElement("div", {
  31491. className: 'bf-dropdown ' + (active ? 'active ' : '') + (disabled ? 'disabled ' : '') + className
  31492. }, htmlCaption ? external_react_default.a.createElement("button", {
  31493. type: "button",
  31494. className: "dropdown-handler",
  31495. "data-title": title,
  31496. onClick: this.toggle,
  31497. dangerouslySetInnerHTML: htmlCaption ? {
  31498. __html: htmlCaption
  31499. } : null,
  31500. ref: function ref(instance) {
  31501. return _this2.dropDownHandlerElement = instance;
  31502. }
  31503. }) : external_react_default.a.createElement("button", {
  31504. type: "button",
  31505. className: "dropdown-handler",
  31506. "data-title": title,
  31507. onClick: this.toggle,
  31508. ref: function ref(instance) {
  31509. return _this2.dropDownHandlerElement = instance;
  31510. }
  31511. }, external_react_default.a.createElement("span", null, caption), showArrow !== false ? external_react_default.a.createElement("i", {
  31512. className: "bfi-drop-down"
  31513. }) : null), external_react_default.a.createElement("div", {
  31514. className: "dropdown-content",
  31515. style: {
  31516. marginLeft: offset
  31517. },
  31518. ref: function ref(instance) {
  31519. return _this2.dropDownContentElement = instance;
  31520. }
  31521. }, external_react_default.a.createElement("i", {
  31522. style: {
  31523. marginLeft: offset * -1
  31524. },
  31525. className: 'dropdown-arrow' + (arrowActive ? ' active' : '')
  31526. }), external_react_default.a.createElement("div", {
  31527. className: "dropdown-content-inner"
  31528. }, children)));
  31529. }
  31530. }]);
  31531. return DropDown;
  31532. }(external_react_default.a.Component);
  31533. // CONCATENATED MODULE: ./components/business/ControlGroup/index.jsx
  31534. /* harmony default export */ var ControlGroup = (function (props) {
  31535. if (external_react_default.a.Fragment) {
  31536. return external_react_default.a.createElement(external_react_default.a.Fragment, null, props.children);
  31537. } else {
  31538. return external_react_default.a.createElement("div", {
  31539. className: "control-item-group"
  31540. }, props.children);
  31541. }
  31542. });
  31543. // CONCATENATED MODULE: ./components/business/LinkEditor/index.jsx
  31544. var LinkEditor_LinkEditor =
  31545. /*#__PURE__*/
  31546. function (_React$Component) {
  31547. inherits_default()(LinkEditor, _React$Component);
  31548. function LinkEditor(props) {
  31549. var _this;
  31550. classCallCheck_default()(this, LinkEditor);
  31551. _this = possibleConstructorReturn_default()(this, getPrototypeOf_default()(LinkEditor).call(this, props));
  31552. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "dropDownInstance", null);
  31553. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handeKeyDown", function (e) {
  31554. if (e.keyCode === 13) {
  31555. _this.handleConfirm();
  31556. e.preventDefault();
  31557. return false;
  31558. }
  31559. });
  31560. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleTnputText", function (e) {
  31561. _this.setState({
  31562. text: e.currentTarget.value
  31563. });
  31564. });
  31565. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleInputLink", function (e) {
  31566. _this.setState({
  31567. href: e.currentTarget.value
  31568. });
  31569. });
  31570. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setTarget", function () {
  31571. _this.setState({
  31572. target: _this.state.target === '_blank' ? '' : '_blank'
  31573. });
  31574. });
  31575. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleCancel", function () {
  31576. _this.dropDownInstance.hide();
  31577. });
  31578. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleUnlink", function () {
  31579. _this.dropDownInstance.hide();
  31580. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLink(_this.props.editorState, false));
  31581. });
  31582. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleConfirm", function () {
  31583. var _this$state = _this.state,
  31584. text = _this$state.text,
  31585. href = _this$state.href,
  31586. target = _this$state.target,
  31587. textSelected = _this$state.textSelected;
  31588. var hookReturns = _this.props.hooks('toggle-link', {
  31589. href: href,
  31590. target: target
  31591. })({
  31592. href: href,
  31593. target: target
  31594. });
  31595. _this.dropDownInstance.hide();
  31596. _this.props.editor.requestFocus();
  31597. if (hookReturns === false) {
  31598. return false;
  31599. }
  31600. if (hookReturns) {
  31601. typeof hookReturns.href === 'string' && (href = hookReturns.href);
  31602. typeof hookReturns.target === 'string' && (target = hookReturns.target);
  31603. }
  31604. if (textSelected) {
  31605. if (href) {
  31606. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLink(_this.props.editorState, href, target));
  31607. } else {
  31608. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLink(_this.props.editorState, false));
  31609. }
  31610. } else {
  31611. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].insertText(_this.props.editorState, text || href, null, {
  31612. type: 'LINK',
  31613. data: {
  31614. href: href,
  31615. target: target
  31616. }
  31617. }));
  31618. }
  31619. });
  31620. _this.state = {
  31621. text: '',
  31622. href: '',
  31623. target: props.defaultLinkTarget || '',
  31624. textSelected: false
  31625. };
  31626. return _this;
  31627. }
  31628. createClass_default()(LinkEditor, [{
  31629. key: "componentWillReceiveProps",
  31630. value: function componentWillReceiveProps(nextProps) {
  31631. var _ContentUtils$getSele = external_braft_utils_["ContentUtils"].getSelectionEntityData(nextProps.editorState, 'LINK'),
  31632. href = _ContentUtils$getSele.href,
  31633. target = _ContentUtils$getSele.target;
  31634. var textSelected = !external_braft_utils_["ContentUtils"].isSelectionCollapsed(this.props.editorState) && external_braft_utils_["ContentUtils"].getSelectionBlockType(this.props.editorState) !== 'atomic';
  31635. var selectedText = '';
  31636. if (textSelected) {
  31637. selectedText = external_braft_utils_["ContentUtils"].getSelectionText(this.props.editorState);
  31638. }
  31639. this.setState({
  31640. textSelected: textSelected,
  31641. text: selectedText,
  31642. href: href || '',
  31643. target: typeof target === 'undefined' ? nextProps.defaultLinkTarget || '' : target || ''
  31644. });
  31645. }
  31646. }, {
  31647. key: "render",
  31648. value: function render() {
  31649. var _this2 = this;
  31650. var allowInsertLinkText = this.props.allowInsertLinkText;
  31651. var _this$state2 = this.state,
  31652. text = _this$state2.text,
  31653. href = _this$state2.href,
  31654. target = _this$state2.target,
  31655. textSelected = _this$state2.textSelected;
  31656. var caption = external_react_default.a.createElement("i", {
  31657. className: "bfi-link"
  31658. });
  31659. return external_react_default.a.createElement(ControlGroup, null, external_react_default.a.createElement(DropDown_DropDown, {
  31660. key: 0,
  31661. caption: caption,
  31662. title: this.props.language.controls.link,
  31663. autoHide: true,
  31664. getContainerNode: this.props.getContainerNode,
  31665. showArrow: false,
  31666. ref: function ref(instance) {
  31667. return _this2.dropDownInstance = instance;
  31668. },
  31669. className: 'control-item dropdown link-editor-dropdown'
  31670. }, external_react_default.a.createElement("div", {
  31671. className: "bf-link-editor"
  31672. }, allowInsertLinkText ? external_react_default.a.createElement("div", {
  31673. className: "input-group"
  31674. }, external_react_default.a.createElement("input", {
  31675. type: "text",
  31676. value: text,
  31677. spellCheck: false,
  31678. disabled: textSelected,
  31679. placeholder: this.props.language.linkEditor.textInputPlaceHolder,
  31680. onKeyDown: this.handeKeyDown,
  31681. onChange: this.handleTnputText
  31682. })) : null, external_react_default.a.createElement("div", {
  31683. className: "input-group"
  31684. }, external_react_default.a.createElement("input", {
  31685. type: "text",
  31686. value: href,
  31687. spellCheck: false,
  31688. placeholder: this.props.language.linkEditor.linkInputPlaceHolder,
  31689. onKeyDown: this.handeKeyDown,
  31690. onChange: this.handleInputLink
  31691. })), external_react_default.a.createElement("div", {
  31692. className: "switch-group"
  31693. }, external_react_default.a.createElement(Switch, {
  31694. active: target === '_blank',
  31695. onClick: this.setTarget
  31696. }), external_react_default.a.createElement("label", null, this.props.language.linkEditor.openInNewWindow)), external_react_default.a.createElement("div", {
  31697. className: "buttons"
  31698. }, external_react_default.a.createElement("a", {
  31699. onClick: this.handleUnlink,
  31700. className: "primary button-remove-link pull-left"
  31701. }, external_react_default.a.createElement("i", {
  31702. className: "bfi-close"
  31703. }), external_react_default.a.createElement("span", null, this.props.language.linkEditor.removeLink)), external_react_default.a.createElement("button", {
  31704. type: "button",
  31705. onClick: this.handleConfirm,
  31706. className: "primary pull-right"
  31707. }, this.props.language.base.confirm), external_react_default.a.createElement("button", {
  31708. type: "button",
  31709. onClick: this.handleCancel,
  31710. className: "default pull-right"
  31711. }, this.props.language.base.cancel)))), external_react_default.a.createElement("button", {
  31712. key: 1,
  31713. type: "button",
  31714. "data-title": this.props.language.controls.unlink,
  31715. className: "control-item button",
  31716. onClick: this.handleUnlink,
  31717. disabled: !textSelected || !href
  31718. }, external_react_default.a.createElement("i", {
  31719. className: "bfi-link-off"
  31720. })));
  31721. }
  31722. }]);
  31723. return LinkEditor;
  31724. }(external_react_default.a.Component);
  31725. // EXTERNAL MODULE: ./components/business/Headings/style.scss
  31726. var Headings_style = __webpack_require__(56);
  31727. // CONCATENATED MODULE: ./configs/maps.js
  31728. var maps_getHeadings = function getHeadings(lang) {
  31729. return [{
  31730. key: 'header-one',
  31731. title: lang.controls.header + ' 1',
  31732. text: external_react_default.a.createElement("h1", null, lang.controls.header, " 1"),
  31733. type: 'block-type',
  31734. command: 'header-one'
  31735. }, {
  31736. key: 'header-two',
  31737. title: lang.controls.header + ' 2',
  31738. text: external_react_default.a.createElement("h2", null, lang.controls.header, " 2"),
  31739. type: 'block-type',
  31740. command: 'header-two'
  31741. }, {
  31742. key: 'header-three',
  31743. title: lang.controls.header + ' 3',
  31744. text: external_react_default.a.createElement("h3", null, lang.controls.header, " 3"),
  31745. type: 'block-type',
  31746. command: 'header-three'
  31747. }, {
  31748. key: 'header-four',
  31749. title: lang.controls.header + ' 4',
  31750. text: external_react_default.a.createElement("h4", null, lang.controls.header, " 4"),
  31751. type: 'block-type',
  31752. command: 'header-four'
  31753. }, {
  31754. key: 'header-five',
  31755. title: lang.controls.header + ' 5',
  31756. text: external_react_default.a.createElement("h5", null, lang.controls.header, " 5"),
  31757. type: 'block-type',
  31758. command: 'header-five'
  31759. }, {
  31760. key: 'header-six',
  31761. title: lang.controls.header + ' 6',
  31762. text: external_react_default.a.createElement("h6", null, lang.controls.header, " 6"),
  31763. type: 'block-type',
  31764. command: 'header-six'
  31765. }, {
  31766. key: 'unstyled',
  31767. title: lang.controls.normal,
  31768. text: lang.controls.normal,
  31769. type: 'block-type',
  31770. command: 'unstyled'
  31771. }];
  31772. };
  31773. // CONCATENATED MODULE: ./components/business/Headings/index.jsx
  31774. /* harmony default export */ var Headings = (function (props) {
  31775. var dropDownInstance = null;
  31776. var headings = maps_getHeadings(props.language).filter(function (item) {
  31777. return props.headings.indexOf(item.key) !== -1;
  31778. });
  31779. var currentHeadingIndex = headings.findIndex(function (item) {
  31780. return item.command === props.current;
  31781. });
  31782. var caption = headings[currentHeadingIndex] ? headings[currentHeadingIndex].title : props.language.controls.normal;
  31783. return external_react_default.a.createElement(DropDown_DropDown, {
  31784. caption: caption,
  31785. autoHide: true,
  31786. getContainerNode: props.getContainerNode,
  31787. title: props.language.controls.headings,
  31788. arrowActive: currentHeadingIndex === 0,
  31789. ref: function ref(instance) {
  31790. return dropDownInstance = instance;
  31791. },
  31792. className: 'control-item dropdown headings-dropdown'
  31793. }, external_react_default.a.createElement("ul", {
  31794. className: "menu"
  31795. }, headings.map(function (item, index) {
  31796. var isActive = props.current === item.command;
  31797. return external_react_default.a.createElement("li", {
  31798. key: index,
  31799. className: 'menu-item' + (isActive ? ' active' : ''),
  31800. onClick: function onClick() {
  31801. props.onChange(item.command, item.type), dropDownInstance.hide();
  31802. }
  31803. }, item.text);
  31804. })));
  31805. });
  31806. // EXTERNAL MODULE: ./components/business/TextColor/style.scss
  31807. var TextColor_style = __webpack_require__(57);
  31808. // EXTERNAL MODULE: ./components/common/ColorPicker/style.scss
  31809. var ColorPicker_style = __webpack_require__(58);
  31810. // CONCATENATED MODULE: ./components/common/ColorPicker/index.jsx
  31811. /* harmony default export */ var common_ColorPicker = (function (props) {
  31812. return external_react_default.a.createElement("div", {
  31813. className: "bf-colors-wrap"
  31814. }, external_react_default.a.createElement("ul", {
  31815. className: "bf-colors"
  31816. }, props.presetColors.map(function (item, index) {
  31817. var className = props.color && item.toLowerCase() === props.color.toLowerCase() ? 'color-item active' : 'color-item';
  31818. return external_react_default.a.createElement("li", {
  31819. key: index,
  31820. title: item,
  31821. className: className,
  31822. style: {
  31823. color: item
  31824. },
  31825. "data-color": item.replace('#', ''),
  31826. onClick: function onClick(e) {
  31827. props.onChange(e.currentTarget.dataset.color, true);
  31828. }
  31829. });
  31830. })));
  31831. });
  31832. // CONCATENATED MODULE: ./components/business/TextColor/index.jsx
  31833. var TextColor_TextColor =
  31834. /*#__PURE__*/
  31835. function (_React$Component) {
  31836. inherits_default()(TextColor, _React$Component);
  31837. function TextColor() {
  31838. var _getPrototypeOf2;
  31839. var _this;
  31840. classCallCheck_default()(this, TextColor);
  31841. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  31842. args[_key] = arguments[_key];
  31843. }
  31844. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(TextColor)).call.apply(_getPrototypeOf2, [this].concat(args)));
  31845. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  31846. colorType: 'color'
  31847. });
  31848. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "switchColorType", function (_ref) {
  31849. var currentTarget = _ref.currentTarget;
  31850. _this.setState({
  31851. colorType: currentTarget.dataset.type
  31852. });
  31853. });
  31854. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggleColor", function (color, closePicker) {
  31855. if (color) {
  31856. var hookReturns = _this.props.hooks("toggle-text-".concat(_this.state.colorType), color)(color);
  31857. if (hookReturns === false) {
  31858. return false;
  31859. }
  31860. if (typeof hookReturns === 'string') {
  31861. color = hookReturns;
  31862. }
  31863. if (_this.state.colorType === 'color') {
  31864. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionColor(_this.props.editorState, color));
  31865. } else {
  31866. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionBackgroundColor(_this.props.editorState, color));
  31867. }
  31868. }
  31869. if (closePicker) {
  31870. _this.dropDownInstance.hide();
  31871. _this.props.editor.requestFocus();
  31872. }
  31873. });
  31874. return _this;
  31875. }
  31876. createClass_default()(TextColor, [{
  31877. key: "render",
  31878. value: function render() {
  31879. var _this2 = this;
  31880. var captionStyle = {};
  31881. var currentColor = null;
  31882. var colorType = this.state.colorType;
  31883. var selectionStyles = this.props.editorState.getCurrentInlineStyle().toJS();
  31884. selectionStyles.forEach(function (style) {
  31885. if (style.indexOf('COLOR-') === 0) {
  31886. captionStyle.color = '#' + style.split('-')[1];
  31887. colorType === 'color' && (currentColor = captionStyle.color);
  31888. }
  31889. if (style.indexOf('BGCOLOR-') === 0) {
  31890. captionStyle.backgroundColor = '#' + style.split('-')[1];
  31891. colorType === 'background-color' && (currentColor = captionStyle.backgroundColor);
  31892. }
  31893. });
  31894. var caption = external_react_default.a.createElement("i", {
  31895. style: captionStyle,
  31896. className: "bfi-text-color"
  31897. }, external_react_default.a.createElement("span", {
  31898. className: "path1"
  31899. }), external_react_default.a.createElement("span", {
  31900. className: "path2"
  31901. }));
  31902. var ColorPicker = this.props.colorPicker || common_ColorPicker;
  31903. return external_react_default.a.createElement(DropDown_DropDown, {
  31904. caption: caption,
  31905. title: this.props.language.controls.color,
  31906. showArrow: false,
  31907. autoHide: this.props.autoHide,
  31908. theme: this.props.theme,
  31909. getContainerNode: this.props.getContainerNode,
  31910. ref: function ref(instance) {
  31911. return _this2.dropDownInstance = instance;
  31912. },
  31913. className: 'control-item dropdown text-color-dropdown'
  31914. }, external_react_default.a.createElement("div", {
  31915. className: "bf-text-color-picker-wrap"
  31916. }, external_react_default.a.createElement("div", {
  31917. className: "bf-color-switch-buttons",
  31918. style: this.props.enableBackgroundColor ? {} : {
  31919. display: 'none'
  31920. }
  31921. }, external_react_default.a.createElement("button", {
  31922. type: "button",
  31923. "data-type": "color",
  31924. className: colorType === 'color' ? 'active' : '',
  31925. onClick: this.switchColorType
  31926. }, this.props.language.controls.textColor), external_react_default.a.createElement("button", {
  31927. type: "button",
  31928. "data-type": "background-color",
  31929. className: colorType === 'background-color' ? 'active' : '',
  31930. onClick: this.switchColorType
  31931. }, this.props.language.controls.backgroundColor)), external_react_default.a.createElement(ColorPicker, {
  31932. width: 200,
  31933. color: currentColor,
  31934. disableAlpha: true,
  31935. presetColors: this.props.colors,
  31936. onChange: this.toggleColor
  31937. })));
  31938. }
  31939. }]);
  31940. return TextColor;
  31941. }(external_react_default.a.Component);
  31942. // EXTERNAL MODULE: ./components/business/FontSize/style.scss
  31943. var FontSize_style = __webpack_require__(59);
  31944. // CONCATENATED MODULE: ./components/business/FontSize/index.jsx
  31945. var FontSize_toggleFontSize = function toggleFontSize(event, props) {
  31946. var fontSize = event.currentTarget.dataset.size;
  31947. var hookReturns = props.hooks('toggle-font-size', fontSize)(fontSize);
  31948. if (hookReturns === false) {
  31949. return false;
  31950. }
  31951. if (!isNaN(fontSize)) {
  31952. fontSize = hookReturns;
  31953. }
  31954. props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionFontSize(props.editorState, fontSize));
  31955. props.editor.requestFocus();
  31956. };
  31957. /* harmony default export */ var FontSize = (function (props) {
  31958. var caption = null;
  31959. var currentFontSize = null;
  31960. var dropDownInstance = null;
  31961. props.fontSizes.find(function (item) {
  31962. if (external_braft_utils_["ContentUtils"].selectionHasInlineStyle(props.editorState, 'FONTSIZE-' + item)) {
  31963. caption = item;
  31964. currentFontSize = item;
  31965. return true;
  31966. }
  31967. return false;
  31968. });
  31969. return external_react_default.a.createElement(DropDown_DropDown, {
  31970. autoHide: true,
  31971. caption: caption || props.defaultCaption,
  31972. getContainerNode: props.getContainerNode,
  31973. title: props.language.controls.fontSize,
  31974. ref: function ref(instance) {
  31975. return dropDownInstance = instance;
  31976. },
  31977. className: 'control-item dropdown bf-font-size-dropdown'
  31978. }, external_react_default.a.createElement("ul", {
  31979. className: "bf-font-sizes"
  31980. }, props.fontSizes.map(function (item, index) {
  31981. return external_react_default.a.createElement("li", {
  31982. key: index,
  31983. className: item === currentFontSize ? 'active' : null,
  31984. "data-size": item,
  31985. onClick: function onClick(event) {
  31986. FontSize_toggleFontSize(event, props), dropDownInstance.hide();
  31987. }
  31988. }, item);
  31989. })));
  31990. });
  31991. // EXTERNAL MODULE: ./components/business/LineHeight/style.scss
  31992. var LineHeight_style = __webpack_require__(60);
  31993. // CONCATENATED MODULE: ./components/business/LineHeight/index.jsx
  31994. var LineHeight_toggleLineHeight = function toggleLineHeight(event, props) {
  31995. var lineHeight = event.currentTarget.dataset.size;
  31996. var hookReturns = props.hooks('toggle-line-height', lineHeight)(lineHeight);
  31997. if (hookReturns === false) {
  31998. return false;
  31999. }
  32000. if (!isNaN(hookReturns)) {
  32001. lineHeight = hookReturns;
  32002. }
  32003. props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLineHeight(props.editorState, lineHeight));
  32004. props.editor.requestFocus();
  32005. };
  32006. /* harmony default export */ var LineHeight = (function (props) {
  32007. var caption = null;
  32008. var currentLineHeight = null;
  32009. var dropDownInstance = null;
  32010. props.lineHeights.find(function (item) {
  32011. if (external_braft_utils_["ContentUtils"].selectionHasInlineStyle(props.editorState, 'LINEHEIGHT-' + item)) {
  32012. caption = item;
  32013. currentLineHeight = item;
  32014. return true;
  32015. }
  32016. return false;
  32017. });
  32018. return external_react_default.a.createElement(DropDown_DropDown, {
  32019. autoHide: true,
  32020. caption: caption || props.defaultCaption,
  32021. getContainerNode: props.getContainerNode,
  32022. title: props.language.controls.lineHeight,
  32023. ref: function ref(instance) {
  32024. return dropDownInstance = instance;
  32025. },
  32026. className: 'control-item dropdown bf-line-height-dropdown'
  32027. }, external_react_default.a.createElement("ul", {
  32028. className: "bf-line-heights"
  32029. }, props.lineHeights.map(function (item, index) {
  32030. return external_react_default.a.createElement("li", {
  32031. key: index,
  32032. className: item === currentLineHeight ? 'active' : null,
  32033. "data-size": item,
  32034. onClick: function onClick(event) {
  32035. LineHeight_toggleLineHeight(event, props), dropDownInstance.hide();
  32036. }
  32037. }, item);
  32038. })));
  32039. });
  32040. // EXTERNAL MODULE: ./components/business/FontFamily/style.scss
  32041. var FontFamily_style = __webpack_require__(61);
  32042. // CONCATENATED MODULE: ./components/business/FontFamily/index.jsx
  32043. var FontFamily_toggleFontFamily = function toggleFontFamily(event, props) {
  32044. var fontFamilyName = event.currentTarget.dataset.name;
  32045. var hookReturns = props.hooks('toggle-font-family', fontFamilyName)(fontFamilyName, props.fontFamilies);
  32046. if (hookReturns === false) {
  32047. return false;
  32048. }
  32049. if (typeof hookReturns === 'string') {
  32050. fontFamilyName = hookReturns;
  32051. }
  32052. props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionFontFamily(props.editorState, fontFamilyName));
  32053. props.editor.requestFocus();
  32054. };
  32055. /* harmony default export */ var FontFamily = (function (props) {
  32056. var caption = null;
  32057. var currentIndex = null;
  32058. var dropDownInstance = null;
  32059. props.fontFamilies.find(function (item, index) {
  32060. if (external_braft_utils_["ContentUtils"].selectionHasInlineStyle(props.editorState, 'FONTFAMILY-' + item.name)) {
  32061. caption = item.name;
  32062. currentIndex = index;
  32063. return true;
  32064. }
  32065. return false;
  32066. });
  32067. return external_react_default.a.createElement(DropDown_DropDown, {
  32068. caption: caption || props.defaultCaption,
  32069. getContainerNode: props.getContainerNode,
  32070. title: props.language.controls.fontFamily,
  32071. autoHide: true,
  32072. arrowActive: currentIndex === 0,
  32073. ref: function ref(instance) {
  32074. return dropDownInstance = instance;
  32075. },
  32076. className: 'control-item dropdown font-family-dropdown'
  32077. }, external_react_default.a.createElement("ul", {
  32078. className: "menu"
  32079. }, props.fontFamilies.map(function (item, index) {
  32080. return external_react_default.a.createElement("li", {
  32081. key: index,
  32082. className: 'menu-item ' + (index === currentIndex ? 'active' : ''),
  32083. "data-name": item.name,
  32084. onClick: function onClick(event) {
  32085. FontFamily_toggleFontFamily(event, props), dropDownInstance.hide();
  32086. }
  32087. }, external_react_default.a.createElement("span", {
  32088. style: {
  32089. fontFamily: item.family
  32090. }
  32091. }, item.name));
  32092. })));
  32093. });
  32094. // CONCATENATED MODULE: ./components/business/TextAlign/index.jsx
  32095. var TextAlign_TextAlign =
  32096. /*#__PURE__*/
  32097. function (_React$Component) {
  32098. inherits_default()(TextAlign, _React$Component);
  32099. function TextAlign() {
  32100. var _getPrototypeOf2;
  32101. var _this;
  32102. classCallCheck_default()(this, TextAlign);
  32103. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  32104. args[_key] = arguments[_key];
  32105. }
  32106. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(TextAlign)).call.apply(_getPrototypeOf2, [this].concat(args)));
  32107. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  32108. currentAlignment: undefined
  32109. });
  32110. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setAlignment", function (event) {
  32111. var alignment = event.currentTarget.dataset.alignment;
  32112. var hookReturns = _this.props.hooks('toggle-text-alignment', alignment)(alignment);
  32113. if (_this.props.textAligns.indexOf(hookReturns) > -1) {
  32114. alignment = hookReturns;
  32115. }
  32116. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionAlignment(_this.props.editorState, alignment));
  32117. _this.props.editor.requestFocus();
  32118. });
  32119. return _this;
  32120. }
  32121. createClass_default()(TextAlign, [{
  32122. key: "componentWillReceiveProps",
  32123. value: function componentWillReceiveProps(next) {
  32124. this.setState({
  32125. currentAlignment: external_braft_utils_["ContentUtils"].getSelectionBlockData(next.editorState, 'textAlign')
  32126. });
  32127. }
  32128. }, {
  32129. key: "render",
  32130. value: function render() {
  32131. var _this2 = this;
  32132. var textAlignmentTitles = [this.props.language.controls.alignLeft, this.props.language.controls.alignCenter, this.props.language.controls.alignRight, this.props.language.controls.alignJustify];
  32133. return external_react_default.a.createElement(ControlGroup, null, this.props.textAligns.map(function (item, index) {
  32134. return external_react_default.a.createElement("button", {
  32135. type: "button",
  32136. key: index,
  32137. "data-title": textAlignmentTitles[index],
  32138. "data-alignment": item,
  32139. className: 'control-item button ' + (item === _this2.state.currentAlignment ? 'active' : null),
  32140. onClick: _this2.setAlignment
  32141. }, external_react_default.a.createElement("i", {
  32142. className: 'bfi-align-' + item
  32143. }));
  32144. }));
  32145. }
  32146. }]);
  32147. return TextAlign;
  32148. }(external_react_default.a.Component);
  32149. // EXTERNAL MODULE: ./components/business/EmojiPicker/style.scss
  32150. var EmojiPicker_style = __webpack_require__(62);
  32151. // CONCATENATED MODULE: ./components/business/EmojiPicker/index.jsx
  32152. var EmojiPicker_insertEmoji = function insertEmoji(event, props) {
  32153. var emoji = event.currentTarget.dataset.emoji;
  32154. var hookReturns = props.hooks('insert-emoji', emoji)(emoji);
  32155. if (hookReturns === false) {
  32156. return false;
  32157. }
  32158. if (typeof hookReturns === 'string') {
  32159. emoji = hookReturns;
  32160. }
  32161. props.editor.setValue(external_braft_utils_["ContentUtils"].insertText(props.editorState, emoji));
  32162. props.editor.requestFocus();
  32163. };
  32164. /* harmony default export */ var EmojiPicker = (function (props) {
  32165. return external_react_default.a.createElement(DropDown_DropDown, {
  32166. caption: props.defaultCaption,
  32167. autoHide: true,
  32168. showArrow: false,
  32169. getContainerNode: props.getContainerNode,
  32170. title: props.language.controls.emoji,
  32171. className: 'control-item dropdown bf-emoji-dropdown'
  32172. }, external_react_default.a.createElement("div", {
  32173. className: "bf-emojis-wrap"
  32174. }, external_react_default.a.createElement("ul", {
  32175. className: "bf-emojis"
  32176. }, props.emojis.map(function (item, index) {
  32177. return external_react_default.a.createElement("li", {
  32178. key: index,
  32179. "data-emoji": item,
  32180. onClick: function onClick(event) {
  32181. return EmojiPicker_insertEmoji(event, props);
  32182. }
  32183. }, item);
  32184. }))));
  32185. });
  32186. // EXTERNAL MODULE: ./components/business/LetterSpacing/style.scss
  32187. var LetterSpacing_style = __webpack_require__(63);
  32188. // CONCATENATED MODULE: ./components/business/LetterSpacing/index.jsx
  32189. var LetterSpacing_toggleLetterSpacing = function toggleLetterSpacing(event, props) {
  32190. var letterSpacing = event.currentTarget.dataset.size;
  32191. var hookReturns = props.hooks('toggle-letter-spacing', letterSpacing)(letterSpacing);
  32192. if (hookReturns === false) {
  32193. return false;
  32194. }
  32195. if (!isNaN(hookReturns)) {
  32196. letterSpacing = hookReturns;
  32197. }
  32198. props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLetterSpacing(props.editorState, letterSpacing));
  32199. props.editor.requestFocus();
  32200. };
  32201. /* harmony default export */ var LetterSpacing = (function (props) {
  32202. var caption = null;
  32203. var currentLetterSpacing = null;
  32204. var dropDownInstance = null;
  32205. props.letterSpacings.find(function (item) {
  32206. if (external_braft_utils_["ContentUtils"].selectionHasInlineStyle(props.editorState, 'LETTERSPACING-' + item)) {
  32207. caption = item;
  32208. currentLetterSpacing = item;
  32209. return true;
  32210. }
  32211. return false;
  32212. });
  32213. return external_react_default.a.createElement(DropDown_DropDown, {
  32214. autoHide: true,
  32215. caption: caption || props.defaultCaption,
  32216. getContainerNode: props.getContainerNode,
  32217. title: props.language.controls.letterSpacing,
  32218. ref: function ref(instance) {
  32219. return dropDownInstance = instance;
  32220. },
  32221. className: 'control-item dropdown bf-letter-spacing-dropdown'
  32222. }, external_react_default.a.createElement("ul", {
  32223. className: "bf-letter-spacings"
  32224. }, props.letterSpacings.map(function (item, index) {
  32225. return external_react_default.a.createElement("li", {
  32226. key: index,
  32227. className: item === currentLetterSpacing ? 'active' : null,
  32228. "data-size": item,
  32229. onClick: function onClick(event) {
  32230. LetterSpacing_toggleLetterSpacing(event, props), dropDownInstance.hide();
  32231. }
  32232. }, item);
  32233. })));
  32234. });
  32235. // CONCATENATED MODULE: ./components/business/TextIndent/index.jsx
  32236. var TextIndent_TextAlign =
  32237. /*#__PURE__*/
  32238. function (_React$Component) {
  32239. inherits_default()(TextAlign, _React$Component);
  32240. function TextAlign() {
  32241. var _getPrototypeOf2;
  32242. var _this;
  32243. classCallCheck_default()(this, TextAlign);
  32244. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  32245. args[_key] = arguments[_key];
  32246. }
  32247. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(TextAlign)).call.apply(_getPrototypeOf2, [this].concat(args)));
  32248. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  32249. currentIndent: 0
  32250. });
  32251. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "increaseIndent", function () {
  32252. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].increaseSelectionIndent(_this.props.editorState));
  32253. _this.props.editor.requestFocus();
  32254. });
  32255. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "decreaseIndent", function () {
  32256. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].decreaseSelectionIndent(_this.props.editorState));
  32257. _this.props.editor.requestFocus();
  32258. });
  32259. return _this;
  32260. }
  32261. createClass_default()(TextAlign, [{
  32262. key: "componentWillReceiveProps",
  32263. value: function componentWillReceiveProps(nextProps) {
  32264. this.setState({
  32265. currentIndent: external_braft_utils_["ContentUtils"].getSelectionBlockData(nextProps.editorState, 'textIndent') || 0
  32266. });
  32267. }
  32268. }, {
  32269. key: "render",
  32270. value: function render() {
  32271. var currentIndent = this.state.currentIndent;
  32272. var language = this.props.language;
  32273. return external_react_default.a.createElement(ControlGroup, null, external_react_default.a.createElement("button", {
  32274. key: 0,
  32275. type: "button",
  32276. "data-title": language.controls.increaseIndent,
  32277. disabled: currentIndent >= 6,
  32278. className: "control-item button button-indent-increase".concat(currentIndent > 0 && currentIndent < 6 ? ' active' : ''),
  32279. onClick: this.increaseIndent
  32280. }, external_react_default.a.createElement("i", {
  32281. className: 'bfi-indent-increase'
  32282. })), external_react_default.a.createElement("button", {
  32283. key: 1,
  32284. type: "button",
  32285. "data-title": language.controls.decreaseIndent,
  32286. disabled: currentIndent <= 0,
  32287. className: "control-item button button-indent-decrease",
  32288. onClick: this.decreaseIndent
  32289. }, external_react_default.a.createElement("i", {
  32290. className: 'bfi-indent-decrease'
  32291. })));
  32292. }
  32293. }]);
  32294. return TextAlign;
  32295. }(external_react_default.a.Component);
  32296. // CONCATENATED MODULE: ./components/business/ControlBar/index.jsx
  32297. var commandHookMap = {
  32298. 'inline-style': 'toggle-inline-style',
  32299. 'block-type': 'change-block-type',
  32300. 'editor-method': 'exec-editor-command'
  32301. };
  32302. var exclusiveInlineStyles = {
  32303. 'superscript': 'subscript',
  32304. 'subscript': 'superscript'
  32305. };
  32306. var mergeControls = function mergeControls(commonProps, builtControls, extensionControls, extendControls) {
  32307. extensionControls = extensionControls.map(function (item) {
  32308. return typeof item === 'function' ? item(commonProps) : item;
  32309. });
  32310. extendControls = extendControls.map(function (item) {
  32311. return typeof item === 'function' ? item(commonProps) : item;
  32312. });
  32313. if (extensionControls.length === 0 && extendControls.length === 0) {
  32314. return builtControls;
  32315. }
  32316. return builtControls.map(function (item) {
  32317. return extendControls.find(function (subItem) {
  32318. return subItem.replace === (item.key || item);
  32319. }) || extensionControls.find(function (subItem) {
  32320. return subItem.replace === (item.key || item);
  32321. }) || item;
  32322. }).concat(extensionControls.length ? 'separator' : '').concat(extensionControls.filter(function (item) {
  32323. return !item.replace;
  32324. })).concat(extendControls.filter(function (item) {
  32325. return typeof item === 'string' || !item.replace;
  32326. }));
  32327. };
  32328. var ControlBar_ControlBar =
  32329. /*#__PURE__*/
  32330. function (_React$Component) {
  32331. inherits_default()(ControlBar, _React$Component);
  32332. function ControlBar() {
  32333. var _getPrototypeOf2;
  32334. var _this;
  32335. classCallCheck_default()(this, ControlBar);
  32336. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  32337. args[_key] = arguments[_key];
  32338. }
  32339. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(ControlBar)).call.apply(_getPrototypeOf2, [this].concat(args)));
  32340. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "allControls", []);
  32341. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "mediaLibiraryModal", null);
  32342. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "extendedModals", {});
  32343. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "openBraftFinder", function () {
  32344. if (!_this.props.braftFinder || !_this.props.braftFinder.ReactComponent) {
  32345. return false;
  32346. }
  32347. if (_this.props.hooks('open-braft-finder')() === false) {
  32348. return false;
  32349. }
  32350. var mediaProps = _this.props.media;
  32351. var MediaLibrary = _this.props.braftFinder.ReactComponent;
  32352. _this.mediaLibiraryModal = Modal_showModal({
  32353. title: _this.props.language.controls.mediaLibirary,
  32354. language: _this.props.language,
  32355. width: 640,
  32356. showFooter: false,
  32357. component: external_react_default.a.createElement(MediaLibrary, {
  32358. accepts: mediaProps.accepts,
  32359. onCancel: _this.closeBraftFinder,
  32360. onInsert: _this.insertMedias,
  32361. onChange: mediaProps.onChange,
  32362. externals: mediaProps.externals,
  32363. onBeforeSelect: _this.bindBraftFinderHook('select-medias'),
  32364. onBeforeDeselect: _this.bindBraftFinderHook('deselect-medias'),
  32365. onBeforeRemove: _this.bindBraftFinderHook('remove-medias'),
  32366. onBeforeInsert: _this.bindBraftFinderHook('insert-medias'),
  32367. onFileSelect: _this.bindBraftFinderHook('select-files')
  32368. })
  32369. });
  32370. });
  32371. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "bindBraftFinderHook", function (hookName) {
  32372. return function () {
  32373. return _this.props.hooks(hookName, arguments.length <= 0 ? undefined : arguments[0]).apply(void 0, arguments);
  32374. };
  32375. });
  32376. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "insertMedias", function (medias) {
  32377. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].insertMedias(_this.props.editorState, medias));
  32378. _this.props.editor.requestFocus();
  32379. _this.props.media.onInsert && _this.props.media.onInsert(medias);
  32380. _this.closeBraftFinder();
  32381. });
  32382. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "closeBraftFinder", function () {
  32383. _this.props.media.onCancel && _this.props.media.onCancel();
  32384. _this.mediaLibiraryModal && _this.mediaLibiraryModal.close();
  32385. });
  32386. return _this;
  32387. }
  32388. createClass_default()(ControlBar, [{
  32389. key: "componentDidUpdate",
  32390. value: function componentDidUpdate() {
  32391. var _this2 = this;
  32392. var language = this.props.language;
  32393. this.allControls.forEach(function (item) {
  32394. if (item.type === 'modal') {
  32395. if (item.modal && item.modal.id && _this2.extendedModals[item.modal.id]) {
  32396. _this2.extendedModals[item.modal.id].update(objectSpread_default()({}, item.modal, {
  32397. language: language
  32398. }));
  32399. }
  32400. }
  32401. });
  32402. }
  32403. }, {
  32404. key: "getControlItemClassName",
  32405. value: function getControlItemClassName(data) {
  32406. var className = 'control-item button';
  32407. var type = data.type,
  32408. command = data.command;
  32409. if (type === 'inline-style' && external_braft_utils_["ContentUtils"].selectionHasInlineStyle(this.props.editorState, command)) {
  32410. className += ' active';
  32411. } else if (type === 'block-type' && external_braft_utils_["ContentUtils"].getSelectionBlockType(this.props.editorState) === command) {
  32412. className += ' active';
  32413. } else if (type === 'entity' && external_braft_utils_["ContentUtils"].getSelectionEntityType(this.props.editorState) === command) {
  32414. className += ' active';
  32415. }
  32416. return className;
  32417. }
  32418. }, {
  32419. key: "applyControl",
  32420. value: function applyControl(command, type) {
  32421. var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  32422. var hookReturns = this.props.hooks(commandHookMap[type] || type, command)(command);
  32423. var editorState = this.props.editorState;
  32424. if (hookReturns === false) {
  32425. return false;
  32426. }
  32427. if (typeof hookReturns === 'string') {
  32428. command = hookReturns;
  32429. }
  32430. if (type === 'inline-style') {
  32431. var exclusiveInlineStyle = exclusiveInlineStyles[command];
  32432. if (exclusiveInlineStyle && external_braft_utils_["ContentUtils"].selectionHasInlineStyle(editorState, exclusiveInlineStyle)) {
  32433. editorState = external_braft_utils_["ContentUtils"].toggleSelectionInlineStyle(editorState, exclusiveInlineStyle);
  32434. }
  32435. this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionInlineStyle(editorState, command));
  32436. } else if (type === 'block-type') {
  32437. this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionBlockType(editorState, command));
  32438. } else if (type === 'entity') {
  32439. this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionEntity(editorState, {
  32440. type: command,
  32441. mutability: data.mutability || 'MUTABLE',
  32442. data: data.data || {}
  32443. }));
  32444. } else if (type === 'editor-method') {
  32445. this.props.editor[command] && this.props.editor[command]();
  32446. }
  32447. }
  32448. }, {
  32449. key: "render",
  32450. value: function render() {
  32451. var _this3 = this;
  32452. var _this$props = this.props,
  32453. editor = _this$props.editor,
  32454. editorId = _this$props.editorId,
  32455. editorState = _this$props.editorState,
  32456. className = _this$props.className,
  32457. style = _this$props.style,
  32458. controls = _this$props.controls,
  32459. media = _this$props.media,
  32460. extendControls = _this$props.extendControls,
  32461. language = _this$props.language,
  32462. hooks = _this$props.hooks,
  32463. colors = _this$props.colors,
  32464. colorPicker = _this$props.colorPicker,
  32465. colorPickerTheme = _this$props.colorPickerTheme,
  32466. colorPickerAutoHide = _this$props.colorPickerAutoHide,
  32467. headings = _this$props.headings,
  32468. fontSizes = _this$props.fontSizes,
  32469. fontFamilies = _this$props.fontFamilies,
  32470. emojis = _this$props.emojis,
  32471. getContainerNode = _this$props.getContainerNode,
  32472. lineHeights = _this$props.lineHeights,
  32473. letterSpacings = _this$props.letterSpacings,
  32474. textAligns = _this$props.textAligns,
  32475. textBackgroundColor = _this$props.textBackgroundColor,
  32476. allowInsertLinkText = _this$props.allowInsertLinkText,
  32477. defaultLinkTarget = _this$props.defaultLinkTarget;
  32478. var currentBlockType = external_braft_utils_["ContentUtils"].getSelectionBlockType(editorState);
  32479. var commonProps = {
  32480. editor: editor,
  32481. editorId: editorId,
  32482. editorState: editorState,
  32483. language: language,
  32484. getContainerNode: getContainerNode,
  32485. hooks: hooks
  32486. };
  32487. var renderedControls = [];
  32488. var editorControls = configs_controls(language, editor);
  32489. var extensionControls = getExtensionControls(editorId);
  32490. var allControls = mergeControls(commonProps, controls, extensionControls, extendControls);
  32491. this.allControls = allControls;
  32492. return external_react_default.a.createElement("div", {
  32493. className: "bf-controlbar ".concat(className || ''),
  32494. style: style,
  32495. onMouseDown: this.preventDefault
  32496. }, allControls.map(function (item, index) {
  32497. var itemKey = typeof item === 'string' ? item : item.key;
  32498. if (typeof itemKey !== 'string') {
  32499. return null;
  32500. }
  32501. if (renderedControls.indexOf(itemKey) > -1) {
  32502. return null;
  32503. }
  32504. if (itemKey.toLowerCase() === 'separator') {
  32505. return external_react_default.a.createElement("span", {
  32506. key: index,
  32507. className: "separator-line"
  32508. });
  32509. }
  32510. var controlItem = editorControls.find(function (subItem) {
  32511. return subItem.key.toLowerCase() === itemKey.toLowerCase();
  32512. });
  32513. if (typeof item !== 'string') {
  32514. controlItem = objectSpread_default()({}, controlItem, item);
  32515. }
  32516. if (!controlItem) {
  32517. return null;
  32518. }
  32519. renderedControls.push(itemKey);
  32520. if (controlItem.type === 'headings') {
  32521. return external_react_default.a.createElement(Headings, extends_default()({
  32522. key: index,
  32523. headings: headings,
  32524. current: currentBlockType,
  32525. onChange: function onChange(command) {
  32526. return _this3.applyControl(command, 'block-type');
  32527. }
  32528. }, commonProps));
  32529. } else if (controlItem.type === 'text-color') {
  32530. return external_react_default.a.createElement(TextColor_TextColor, extends_default()({
  32531. key: index,
  32532. colors: colors,
  32533. colorPicker: colorPicker,
  32534. theme: colorPickerTheme,
  32535. autoHide: colorPickerAutoHide,
  32536. enableBackgroundColor: textBackgroundColor
  32537. }, commonProps));
  32538. } else if (controlItem.type === 'font-size') {
  32539. return external_react_default.a.createElement(FontSize, extends_default()({
  32540. key: index,
  32541. fontSizes: fontSizes,
  32542. defaultCaption: controlItem.title
  32543. }, commonProps));
  32544. } else if (controlItem.type === 'line-height') {
  32545. return external_react_default.a.createElement(LineHeight, extends_default()({
  32546. key: index,
  32547. lineHeights: lineHeights,
  32548. defaultCaption: controlItem.title
  32549. }, commonProps));
  32550. } else if (controlItem.type === 'letter-spacing') {
  32551. return external_react_default.a.createElement(LetterSpacing, extends_default()({
  32552. key: index,
  32553. letterSpacings: letterSpacings,
  32554. defaultCaption: controlItem.title
  32555. }, commonProps));
  32556. } else if (controlItem.type === 'text-indent') {
  32557. return external_react_default.a.createElement(TextIndent_TextAlign, extends_default()({
  32558. key: index,
  32559. defaultCaption: controlItem.title
  32560. }, commonProps));
  32561. } else if (controlItem.type === 'font-family') {
  32562. return external_react_default.a.createElement(FontFamily, extends_default()({
  32563. key: index,
  32564. fontFamilies: fontFamilies,
  32565. defaultCaption: controlItem.title
  32566. }, commonProps));
  32567. } else if (controlItem.type === 'emoji') {
  32568. return external_react_default.a.createElement(EmojiPicker, extends_default()({
  32569. key: index,
  32570. emojis: emojis,
  32571. defaultCaption: controlItem.text
  32572. }, commonProps));
  32573. } else if (controlItem.type === 'link') {
  32574. return external_react_default.a.createElement(LinkEditor_LinkEditor, extends_default()({
  32575. key: index,
  32576. defaultLinkTarget: defaultLinkTarget,
  32577. allowInsertLinkText: allowInsertLinkText
  32578. }, commonProps));
  32579. } else if (controlItem.type === 'text-align') {
  32580. return external_react_default.a.createElement(TextAlign_TextAlign, extends_default()({
  32581. key: index,
  32582. textAligns: textAligns
  32583. }, commonProps));
  32584. } else if (controlItem.type === 'media') {
  32585. if (!media.image && !media.video && !media.audio) {
  32586. return null;
  32587. }
  32588. return external_react_default.a.createElement("button", {
  32589. type: "button",
  32590. key: index,
  32591. "data-title": controlItem.title,
  32592. disabled: controlItem.disabled,
  32593. className: "control-item media button",
  32594. onClick: _this3.openBraftFinder
  32595. }, controlItem.text);
  32596. } else if (controlItem.type === 'dropdown') {
  32597. return external_react_default.a.createElement(DropDown_DropDown, extends_default()({
  32598. key: index,
  32599. className: "control-item extend-control-item dropdown ".concat(controlItem.className || ''),
  32600. caption: controlItem.text,
  32601. htmlCaption: controlItem.html,
  32602. showArrow: controlItem.showArrow,
  32603. title: controlItem.title,
  32604. arrowActive: controlItem.arrowActive,
  32605. theme: controlItem.theme,
  32606. autoHide: controlItem.autoHide,
  32607. disabled: controlItem.disabled,
  32608. ref: controlItem.ref
  32609. }, commonProps), controlItem.component);
  32610. } else if (controlItem.type === 'modal') {
  32611. return external_react_default.a.createElement("button", {
  32612. type: "button",
  32613. key: index,
  32614. "data-title": controlItem.title,
  32615. disabled: controlItem.disabled,
  32616. className: "control-item extend-control-item button ".concat(controlItem.className || ''),
  32617. dangerouslySetInnerHTML: controlItem.html ? {
  32618. __html: controlItem.html
  32619. } : null,
  32620. onClick: function onClick(event) {
  32621. if (controlItem.modal && controlItem.modal.id) {
  32622. if (_this3.extendedModals[controlItem.modal.id]) {
  32623. _this3.extendedModals[controlItem.modal.id].active = true;
  32624. _this3.extendedModals[controlItem.modal.id].update(objectSpread_default()({}, controlItem.modal, {
  32625. language: language
  32626. }));
  32627. } else {
  32628. _this3.extendedModals[controlItem.modal.id] = Modal_showModal(objectSpread_default()({}, controlItem.modal, {
  32629. language: language
  32630. }));
  32631. controlItem.modal.onCreate && controlItem.modal.onCreate(_this3.extendedModals[controlItem.modal.id]);
  32632. }
  32633. }
  32634. controlItem.onClick && controlItem.onClick(event);
  32635. }
  32636. }, !controlItem.html ? controlItem.text : null);
  32637. } else if (controlItem.type === 'component') {
  32638. return external_react_default.a.createElement("div", {
  32639. key: index,
  32640. className: "component-wrapper ".concat(controlItem.className || '')
  32641. }, controlItem.component);
  32642. } else if (controlItem.type === 'button') {
  32643. return external_react_default.a.createElement("button", {
  32644. type: "button",
  32645. key: index,
  32646. "data-title": controlItem.title,
  32647. disabled: controlItem.disabled,
  32648. className: "control-item button ".concat(controlItem.className || ''),
  32649. dangerouslySetInnerHTML: controlItem.html ? {
  32650. __html: controlItem.html
  32651. } : null,
  32652. onClick: function onClick(event) {
  32653. return controlItem.onClick && controlItem.onClick(event);
  32654. }
  32655. }, !controlItem.html ? controlItem.text : null);
  32656. } else if (controlItem) {
  32657. var disabled = false;
  32658. if (controlItem.command === 'undo') {
  32659. disabled = editorState.getUndoStack().size === 0;
  32660. } else if (controlItem.command === 'redo') {
  32661. disabled = editorState.getRedoStack().size === 0;
  32662. }
  32663. return external_react_default.a.createElement("button", {
  32664. type: "button",
  32665. key: index,
  32666. disabled: disabled,
  32667. "data-title": controlItem.title,
  32668. className: _this3.getControlItemClassName({
  32669. type: controlItem.type,
  32670. command: controlItem.command
  32671. }),
  32672. onClick: function onClick() {
  32673. return _this3.applyControl(controlItem.command, controlItem.type, controlItem.data);
  32674. }
  32675. }, controlItem.text);
  32676. }
  32677. }));
  32678. }
  32679. }, {
  32680. key: "preventDefault",
  32681. value: function preventDefault(event) {
  32682. var tagName = event.target.tagName.toLowerCase();
  32683. if (tagName === 'input' || tagName === 'label') ; else {
  32684. event.preventDefault();
  32685. }
  32686. }
  32687. }]);
  32688. return ControlBar;
  32689. }(external_react_default.a.Component);
  32690. // CONCATENATED MODULE: ./editor/index.jsx
  32691. var buildHooks = function buildHooks(hooks) {
  32692. return function (hookName) {
  32693. var defaultReturns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  32694. return hooks[hookName] || function () {
  32695. return defaultReturns;
  32696. };
  32697. };
  32698. };
  32699. var filterColors = function filterColors(colors, colors2) {
  32700. return colors.filter(function (item) {
  32701. return !colors2.find(function (color) {
  32702. return color.toLowerCase() === item.toLowerCase();
  32703. });
  32704. }).filter(function (item, index, array) {
  32705. return array.indexOf(item) === index;
  32706. });
  32707. };
  32708. var editor_isControlEnabled = function isControlEnabled(props, controlName) {
  32709. return toConsumableArray_default()(props.controls).concat(toConsumableArray_default()(props.extendControls)).find(function (item) {
  32710. return item === controlName || item.key === controlName;
  32711. }) && props.excludeControls.indexOf(controlName) === -1;
  32712. };
  32713. var editor_getConvertOptions = function getConvertOptions(props) {
  32714. var editorId = props.editorId || props.id;
  32715. var convertOptions = objectSpread_default()({}, configs_props.converts, props.converts, {
  32716. fontFamilies: props.fontFamilies
  32717. });
  32718. convertOptions.styleImportFn = compositeStyleImportFn(convertOptions.styleImportFn, editorId);
  32719. convertOptions.styleExportFn = compositeStyleExportFn(convertOptions.styleExportFn, editorId);
  32720. convertOptions.entityImportFn = compositeEntityImportFn(convertOptions.entityImportFn, editorId);
  32721. convertOptions.entityExportFn = compositeEntityExportFn(convertOptions.entityExportFn, editorId);
  32722. convertOptions.blockImportFn = compositeBlockImportFn(convertOptions.blockImportFn, editorId);
  32723. convertOptions.blockExportFn = compositeBlockExportFn(convertOptions.blockExportFn, editorId);
  32724. return convertOptions;
  32725. };
  32726. var editor_BraftEditor =
  32727. /*#__PURE__*/
  32728. function (_React$Component) {
  32729. inherits_default()(BraftEditor, _React$Component);
  32730. function BraftEditor(props) {
  32731. var _this;
  32732. classCallCheck_default()(this, BraftEditor);
  32733. _this = possibleConstructorReturn_default()(this, getPrototypeOf_default()(BraftEditor).call(this, props));
  32734. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "onChange", function (editorState, callback) {
  32735. if (!(editorState instanceof external_draft_js_["EditorState"])) {
  32736. editorState = external_draft_js_["EditorState"].set(editorState, {
  32737. decorator: _this.editorDecorators
  32738. });
  32739. }
  32740. if (!editorState.convertOptions) {
  32741. editorState.setConvertOptions(editor_getConvertOptions(_this.editorProps));
  32742. }
  32743. _this.setState({
  32744. editorState: editorState
  32745. }, function () {
  32746. _this.props.onChange && _this.props.onChange(editorState);
  32747. callback && callback(editorState);
  32748. });
  32749. });
  32750. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "getDraftInstance", function () {
  32751. return _this.draftInstance;
  32752. });
  32753. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "getFinderInstance", function () {
  32754. return _this.braftFinder;
  32755. });
  32756. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "getValue", function () {
  32757. return _this.state.editorState;
  32758. });
  32759. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setValue", function (editorState, callback) {
  32760. return _this.onChange(editorState, callback);
  32761. });
  32762. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "forceRender", function () {
  32763. var selectionState = _this.state.editorState.getSelection();
  32764. _this.setValue(external_draft_js_["EditorState"].set(_this.state.editorState, {
  32765. decorator: _this.editorDecorators
  32766. }), function () {
  32767. _this.setValue(external_draft_js_["EditorState"].forceSelection(_this.state.editorState, selectionState));
  32768. });
  32769. });
  32770. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "onTab", function (event) {
  32771. if (handlers_keyCommandHandlers('tab', _this.state.editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this))) === 'handled') {
  32772. event.preventDefault();
  32773. }
  32774. _this.editorProps.onTab && _this.editorProps.onTab(event);
  32775. });
  32776. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "onFocus", function () {
  32777. _this.isFocused = true;
  32778. _this.editorProps.onFocus && _this.editorProps.onFocus(_this.state.editorState);
  32779. });
  32780. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "onBlur", function () {
  32781. _this.isFocused = false;
  32782. _this.editorProps.onBlur && _this.editorProps.onBlur(_this.state.editorState);
  32783. });
  32784. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "requestFocus", function () {
  32785. setTimeout(function () {
  32786. return _this.draftInstance.focus();
  32787. }, 0);
  32788. });
  32789. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleKeyCommand", function (command, editorState) {
  32790. return handlers_keyCommandHandlers(command, editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32791. });
  32792. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleReturn", function (event, editorState) {
  32793. return handlers_returnHandlers(event, editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32794. });
  32795. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleBeforeInput", function (chars, editorState) {
  32796. return beforeInputHandlers(chars, editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32797. });
  32798. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleDrop", function (selectionState, dataTransfer) {
  32799. return handlers_dropHandlers(selectionState, dataTransfer, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32800. });
  32801. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleDroppedFiles", function (selectionState, files) {
  32802. return droppedFilesHandlers(selectionState, files, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32803. });
  32804. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handlePastedFiles", function (files) {
  32805. return pastedFilesHandlers(files, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32806. });
  32807. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleCopyContent", function (event) {
  32808. return handlers_copyHandlers(event, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32809. });
  32810. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handlePastedText", function (text, html, editorState) {
  32811. return handlers_pastedTextHandlers(text, html, editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32812. });
  32813. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleCompositionStart", function (event) {
  32814. return handlers_compositionStartHandler(event, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32815. });
  32816. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "undo", function () {
  32817. _this.setValue(external_braft_utils_["ContentUtils"].undo(_this.state.editorState));
  32818. });
  32819. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "redo", function () {
  32820. _this.setValue(external_braft_utils_["ContentUtils"].redo(_this.state.editorState));
  32821. });
  32822. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeSelectionInlineStyles", function () {
  32823. _this.setValue(external_braft_utils_["ContentUtils"].removeSelectionInlineStyles(_this.state.editorState));
  32824. });
  32825. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "insertHorizontalLine", function () {
  32826. _this.setValue(external_braft_utils_["ContentUtils"].insertHorizontalLine(_this.state.editorState));
  32827. });
  32828. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "clearEditorContent", function () {
  32829. _this.setValue(external_braft_utils_["ContentUtils"].clear(_this.state.editorState), function (editorState) {
  32830. _this.setValue(external_braft_utils_["ContentUtils"].toggleSelectionIndent(editorState, 0));
  32831. });
  32832. });
  32833. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggleFullscreen", function (fullscreen) {
  32834. _this.setState({
  32835. isFullscreen: typeof fullscreen !== 'undefined' ? fullscreen : !_this.state.isFullscreen
  32836. }, function () {
  32837. _this.editorProps.onFullscreen && _this.editorProps.onFullscreen(_this.state.isFullscreen);
  32838. });
  32839. });
  32840. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setEditorContainerNode", function (containerNode) {
  32841. _this.containerNode = containerNode;
  32842. });
  32843. _this.editorProps = _this.getEditorProps(props);
  32844. _this.editorDecorators = getDecorators(_this.editorProps.editorId || _this.editorProps.id);
  32845. _this.isFocused = false;
  32846. _this.isLiving = false;
  32847. _this.braftFinder = null;
  32848. _this.valueInitialized = !!(_this.props.defaultValue || _this.props.value);
  32849. 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);
  32850. defaultEditorState.setConvertOptions(editor_getConvertOptions(_this.editorProps));
  32851. var tempColors = [];
  32852. if (external_braft_utils_["ContentUtils"].isEditorState(defaultEditorState)) {
  32853. var colors = external_braft_utils_["ColorUtils"].detectColorsFromDraftState(defaultEditorState.toRAW(true));
  32854. defaultEditorState.setConvertOptions(editor_getConvertOptions(_this.editorProps));
  32855. tempColors = filterColors(colors, _this.editorProps.colors);
  32856. }
  32857. _this.state = {
  32858. tempColors: tempColors,
  32859. editorState: defaultEditorState,
  32860. isFullscreen: false,
  32861. draftProps: {}
  32862. };
  32863. _this.containerNode = null;
  32864. return _this;
  32865. }
  32866. createClass_default()(BraftEditor, [{
  32867. key: "getEditorProps",
  32868. value: function getEditorProps(props) {
  32869. var _this2 = this;
  32870. props = props || this.props;
  32871. var _props = props,
  32872. value = _props.value,
  32873. defaultValue = _props.defaultValue,
  32874. onChange = _props.onChange,
  32875. restProps = objectWithoutProperties_default()(_props, ["value", "defaultValue", "onChange"]); // eslint-disable-line no-unused-vars
  32876. var propInterceptors = getPropInterceptors(restProps.editorId || restProps.id);
  32877. if (propInterceptors.length === 0) {
  32878. return restProps;
  32879. }
  32880. var porpsMap = Object(external_immutable_["Map"])(restProps);
  32881. propInterceptors.forEach(function (interceptor) {
  32882. porpsMap = porpsMap.merge(Object(external_immutable_["Map"])(interceptor(porpsMap.toJS(), _this2) || {}));
  32883. });
  32884. return porpsMap.toJS();
  32885. }
  32886. }, {
  32887. key: "componentWillMount",
  32888. value: function componentWillMount() {
  32889. if (editor_isControlEnabled(this.editorProps, 'media')) {
  32890. var _this$editorProps = this.editorProps,
  32891. language = _this$editorProps.language,
  32892. media = _this$editorProps.media;
  32893. var _defaultProps$media$m = objectSpread_default()({}, configs_props.media, media),
  32894. uploadFn = _defaultProps$media$m.uploadFn,
  32895. validateFn = _defaultProps$media$m.validateFn,
  32896. items = _defaultProps$media$m.items;
  32897. this.braftFinder = new external_braft_finder_default.a({
  32898. items: items,
  32899. language: language,
  32900. uploader: uploadFn,
  32901. validator: validateFn
  32902. });
  32903. this.forceUpdate();
  32904. }
  32905. }
  32906. }, {
  32907. key: "componentDidMount",
  32908. value: function componentDidMount() {
  32909. this.isLiving = true;
  32910. }
  32911. }, {
  32912. key: "componentDidUpdate",
  32913. value: function componentDidUpdate(_, prevState) {
  32914. if (prevState.editorState !== this.state.editorState) {
  32915. this.state.editorState.setConvertOptions(editor_getConvertOptions(this.editorProps));
  32916. }
  32917. }
  32918. }, {
  32919. key: "componentWillReceiveProps",
  32920. value: function componentWillReceiveProps(props) {
  32921. var _this3 = this;
  32922. this.editorProps = this.getEditorProps(props);
  32923. var editorState = props.value;
  32924. var _this$editorProps2 = this.editorProps,
  32925. media = _this$editorProps2.media,
  32926. language = _this$editorProps2.language;
  32927. var currentProps = this.getEditorProps();
  32928. if (!editor_isControlEnabled(currentProps, 'media') && editor_isControlEnabled(this.editorProps, 'media') && !this.braftFinder) {
  32929. var _defaultProps$media$m2 = objectSpread_default()({}, configs_props.media, media),
  32930. uploadFn = _defaultProps$media$m2.uploadFn,
  32931. validateFn = _defaultProps$media$m2.validateFn,
  32932. items = _defaultProps$media$m2.items;
  32933. this.braftFinder = new external_braft_finder_default.a({
  32934. items: items,
  32935. language: language,
  32936. uploader: uploadFn,
  32937. validator: validateFn
  32938. });
  32939. this.forceUpdate();
  32940. }
  32941. if (media && media.items && this.braftFinder) {
  32942. this.braftFinder.setItems(media.items);
  32943. }
  32944. var nextEditorState;
  32945. if (!this.valueInitialized && typeof this.props.defaultValue === 'undefined' && external_braft_utils_["ContentUtils"].isEditorState(props.defaultValue)) {
  32946. nextEditorState = props.defaultValue;
  32947. } else if (external_braft_utils_["ContentUtils"].isEditorState(editorState)) {
  32948. nextEditorState = editorState;
  32949. }
  32950. if (nextEditorState) {
  32951. if (nextEditorState && nextEditorState !== this.state.editorState) {
  32952. var tempColors = external_braft_utils_["ColorUtils"].detectColorsFromDraftState(nextEditorState.toRAW(true));
  32953. nextEditorState.setConvertOptions(editor_getConvertOptions(this.editorProps));
  32954. this.setState({
  32955. tempColors: filterColors(toConsumableArray_default()(this.state.tempColors).concat(toConsumableArray_default()(tempColors)), currentProps.colors),
  32956. editorState: nextEditorState
  32957. }, function () {
  32958. _this3.props.onChange && _this3.props.onChange(nextEditorState);
  32959. });
  32960. } else {
  32961. this.setState({
  32962. editorState: nextEditorState
  32963. });
  32964. }
  32965. }
  32966. }
  32967. }, {
  32968. key: "componentWillUnmount",
  32969. value: function componentWillUnmount() {
  32970. this.isLiving = false;
  32971. this.controlBarInstance && this.controlBarInstance.closeBraftFinder();
  32972. }
  32973. }, {
  32974. key: "lockOrUnlockEditor",
  32975. value: function lockOrUnlockEditor(editorLocked) {
  32976. this.setState({
  32977. editorLocked: editorLocked
  32978. });
  32979. }
  32980. }, {
  32981. key: "render",
  32982. value: function render() {
  32983. var _this4 = this;
  32984. var _this$editorProps3 = this.editorProps,
  32985. id = _this$editorProps3.id,
  32986. editorId = _this$editorProps3.editorId,
  32987. controls = _this$editorProps3.controls,
  32988. excludeControls = _this$editorProps3.excludeControls,
  32989. extendControls = _this$editorProps3.extendControls,
  32990. readOnly = _this$editorProps3.readOnly,
  32991. disabled = _this$editorProps3.disabled,
  32992. media = _this$editorProps3.media,
  32993. language = _this$editorProps3.language,
  32994. colors = _this$editorProps3.colors,
  32995. colorPicker = _this$editorProps3.colorPicker,
  32996. colorPickerTheme = _this$editorProps3.colorPickerTheme,
  32997. colorPickerAutoHide = _this$editorProps3.colorPickerAutoHide,
  32998. hooks = _this$editorProps3.hooks,
  32999. fontSizes = _this$editorProps3.fontSizes,
  33000. fontFamilies = _this$editorProps3.fontFamilies,
  33001. emojis = _this$editorProps3.emojis,
  33002. placeholder = _this$editorProps3.placeholder,
  33003. fixPlaceholder = _this$editorProps3.fixPlaceholder,
  33004. headings = _this$editorProps3.headings,
  33005. imageControls = _this$editorProps3.imageControls,
  33006. imageResizable = _this$editorProps3.imageResizable,
  33007. lineHeights = _this$editorProps3.lineHeights,
  33008. letterSpacings = _this$editorProps3.letterSpacings,
  33009. textAligns = _this$editorProps3.textAligns,
  33010. textBackgroundColor = _this$editorProps3.textBackgroundColor,
  33011. allowInsertLinkText = _this$editorProps3.allowInsertLinkText,
  33012. defaultLinkTarget = _this$editorProps3.defaultLinkTarget,
  33013. extendAtomics = _this$editorProps3.extendAtomics,
  33014. className = _this$editorProps3.className,
  33015. style = _this$editorProps3.style,
  33016. controlBarClassName = _this$editorProps3.controlBarClassName,
  33017. controlBarStyle = _this$editorProps3.controlBarStyle,
  33018. contentClassName = _this$editorProps3.contentClassName,
  33019. contentStyle = _this$editorProps3.contentStyle,
  33020. stripPastedStyles = _this$editorProps3.stripPastedStyles,
  33021. componentBelowControlBar = _this$editorProps3.componentBelowControlBar;
  33022. var _this$state = this.state,
  33023. isFullscreen = _this$state.isFullscreen,
  33024. editorState = _this$state.editorState;
  33025. editorId = editorId || id;
  33026. hooks = buildHooks(hooks);
  33027. controls = controls.filter(function (item) {
  33028. return excludeControls.indexOf(item) === -1;
  33029. });
  33030. language = (typeof language === 'function' ? language(languages, 'braft-editor') : languages[language]) || languages[configs_props.language];
  33031. var externalMedias = media && media.externals ? objectSpread_default()({}, configs_props.media.externals, media.externals) : configs_props.media.externals;
  33032. var accepts = media && media.accepts ? objectSpread_default()({}, configs_props.media.accepts, media.accepts) : configs_props.media.accepts;
  33033. media = objectSpread_default()({}, configs_props.media, media, {
  33034. externalMedias: externalMedias,
  33035. accepts: accepts
  33036. });
  33037. if (!media.uploadFn) {
  33038. media.video = false;
  33039. media.audio = false;
  33040. }
  33041. var controlBarProps = {
  33042. editor: this,
  33043. editorState: editorState,
  33044. braftFinder: this.braftFinder,
  33045. ref: function ref(instance) {
  33046. return _this4.controlBarInstance = instance;
  33047. },
  33048. getContainerNode: function getContainerNode() {
  33049. return _this4.containerNode;
  33050. },
  33051. className: controlBarClassName,
  33052. style: controlBarStyle,
  33053. colors: toConsumableArray_default()(colors).concat(toConsumableArray_default()(this.state.tempColors)),
  33054. colorPicker: colorPicker,
  33055. colorPickerTheme: colorPickerTheme,
  33056. colorPickerAutoHide: colorPickerAutoHide,
  33057. hooks: hooks,
  33058. editorId: editorId,
  33059. media: media,
  33060. controls: controls,
  33061. language: language,
  33062. extendControls: extendControls,
  33063. headings: headings,
  33064. fontSizes: fontSizes,
  33065. fontFamilies: fontFamilies,
  33066. emojis: emojis,
  33067. lineHeights: lineHeights,
  33068. letterSpacings: letterSpacings,
  33069. textAligns: textAligns,
  33070. textBackgroundColor: textBackgroundColor,
  33071. allowInsertLinkText: allowInsertLinkText,
  33072. defaultLinkTarget: defaultLinkTarget
  33073. };
  33074. var unitExportFn = editorState.convertOptions.unitExportFn;
  33075. var commonProps = {
  33076. editor: this,
  33077. editorId: editorId,
  33078. hooks: hooks,
  33079. editorState: editorState,
  33080. containerNode: this.containerNode,
  33081. imageControls: imageControls,
  33082. imageResizable: imageResizable,
  33083. language: language,
  33084. extendAtomics: extendAtomics
  33085. };
  33086. var blockRendererFn = getBlockRendererFn(commonProps, this.editorProps.blockRendererFn);
  33087. var blockRenderMap = getBlockRenderMap(commonProps, this.editorProps.blockRenderMap);
  33088. var blockStyleFn = getBlockStyleFn(this.editorProps.blockStyleFn);
  33089. var customStyleMap = getCustomStyleMap(commonProps, this.editorProps.customStyleMap);
  33090. var customStyleFn = getCustomStyleFn(commonProps, {
  33091. fontFamilies: fontFamilies,
  33092. unitExportFn: unitExportFn,
  33093. customStyleFn: this.editorProps.customStyleFn
  33094. });
  33095. var keyBindingFn = keybindings(this.editorProps.keyBindingFn);
  33096. var mixedProps = {};
  33097. if (this.state.editorLocked || this.editorProps.disabled || this.editorProps.readOnly || this.editorProps.draftProps.readOnly) {
  33098. mixedProps.readOnly = true;
  33099. }
  33100. if (placeholder && fixPlaceholder && editorState.isEmpty() && editorState.getCurrentContent().getFirstBlock().getType() !== 'unstyled') {
  33101. placeholder = '';
  33102. }
  33103. var draftProps = objectSpread_default()({
  33104. ref: function ref(instance) {
  33105. _this4.draftInstance = instance;
  33106. },
  33107. editorState: editorState,
  33108. handleKeyCommand: this.handleKeyCommand,
  33109. handleReturn: this.handleReturn,
  33110. handleBeforeInput: this.handleBeforeInput,
  33111. handleDrop: this.handleDrop,
  33112. handleDroppedFiles: this.handleDroppedFiles,
  33113. handlePastedText: this.handlePastedText,
  33114. handlePastedFiles: this.handlePastedFiles,
  33115. onChange: this.onChange,
  33116. onTab: this.onTab,
  33117. onFocus: this.onFocus,
  33118. onBlur: this.onBlur,
  33119. blockRenderMap: blockRenderMap,
  33120. blockRendererFn: blockRendererFn,
  33121. blockStyleFn: blockStyleFn,
  33122. customStyleMap: customStyleMap,
  33123. customStyleFn: customStyleFn,
  33124. keyBindingFn: keyBindingFn,
  33125. placeholder: placeholder,
  33126. stripPastedStyles: stripPastedStyles
  33127. }, this.editorProps.draftProps, mixedProps);
  33128. return external_react_default.a.createElement("div", {
  33129. style: style,
  33130. ref: this.setEditorContainerNode,
  33131. className: "bf-container ".concat(className).concat(disabled ? ' disabled' : '').concat(readOnly ? ' read-only' : '').concat(isFullscreen ? ' fullscreen' : '')
  33132. }, external_react_default.a.createElement(ControlBar_ControlBar, controlBarProps), componentBelowControlBar, external_react_default.a.createElement("div", {
  33133. onCompositionStart: this.handleCompositionStart,
  33134. className: "bf-content ".concat(contentClassName),
  33135. onCopy: this.handleCopyContent,
  33136. style: contentStyle
  33137. }, external_react_default.a.createElement(external_draft_js_["Editor"], draftProps)));
  33138. }
  33139. }]);
  33140. return BraftEditor;
  33141. }(external_react_default.a.Component);
  33142. defineProperty_default()(editor_BraftEditor, "defaultProps", configs_props);
  33143. // EXTERNAL MODULE: external "braft-convert"
  33144. var external_braft_convert_ = __webpack_require__(14);
  33145. // CONCATENATED MODULE: ./index.jsx
  33146. /* concated harmony reexport EditorState */__webpack_require__.d(__webpack_exports__, "EditorState", function() { return external_draft_js_["EditorState"]; });
  33147. /* concated harmony reexport getDecorators */__webpack_require__.d(__webpack_exports__, "getDecorators", function() { return getDecorators; });
  33148. external_draft_js_["EditorState"].prototype.setConvertOptions = function () {
  33149. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  33150. this.convertOptions = options;
  33151. };
  33152. external_draft_js_["EditorState"].prototype.toHTML = function () {
  33153. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  33154. var convertOptions = this.convertOptions || {};
  33155. return Object(external_braft_convert_["convertEditorStateToHTML"])(this, objectSpread_default()({}, convertOptions, options));
  33156. };
  33157. external_draft_js_["EditorState"].prototype.toRAW = function (noStringify) {
  33158. return noStringify ? Object(external_braft_convert_["convertEditorStateToRaw"])(this) : JSON.stringify(Object(external_braft_convert_["convertEditorStateToRaw"])(this));
  33159. };
  33160. external_draft_js_["EditorState"].prototype.toText = function () {
  33161. return this.getCurrentContent().getPlainText();
  33162. };
  33163. external_draft_js_["EditorState"].prototype.isEmpty = function () {
  33164. return !this.getCurrentContent().hasText();
  33165. };
  33166. editor_BraftEditor.createEditorState = external_draft_js_["EditorState"].createFrom = function (content) {
  33167. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  33168. options.unitExportFn = options.unitExportFn || editor_BraftEditor.defaultProps.converts.unitExportFn;
  33169. options.styleImportFn = compositeStyleImportFn(options.styleImportFn, options.editorId);
  33170. options.entityImportFn = compositeEntityImportFn(options.entityImportFn, options.editorId);
  33171. options.blockImportFn = compositeBlockImportFn(options.blockImportFn, options.editorId);
  33172. var editorState = null;
  33173. if (content instanceof external_draft_js_["EditorState"]) {
  33174. editorState = content;
  33175. } else if (typeof_default()(content) === 'object' && content && content.blocks && content.entityMap) {
  33176. editorState = Object(external_braft_convert_["convertRawToEditorState"])(content, getDecorators(options.editorId));
  33177. } else if (typeof content === 'string') {
  33178. try {
  33179. if (/^(-)?\d+$/.test(content)) {
  33180. editorState = Object(external_braft_convert_["convertHTMLToEditorState"])(content, getDecorators(options.editorId), options, 'create');
  33181. } else {
  33182. editorState = external_draft_js_["EditorState"].createFrom(JSON.parse(content), options);
  33183. }
  33184. } catch (error) {
  33185. editorState = Object(external_braft_convert_["convertHTMLToEditorState"])(content, getDecorators(options.editorId), options, 'create');
  33186. }
  33187. } else if (typeof content === 'number') {
  33188. editorState = Object(external_braft_convert_["convertHTMLToEditorState"])(content.toLocaleString().replace(/,/g, ''), getDecorators(options.editorId), options, 'create');
  33189. } else {
  33190. editorState = external_draft_js_["EditorState"].createEmpty(getDecorators(options.editorId));
  33191. }
  33192. options.styleExportFn = compositeStyleExportFn(options.styleExportFn, options.editorId);
  33193. options.entityExportFn = compositeEntityExportFn(options.entityExportFn, options.editorId);
  33194. options.blockExportFn = compositeBlockExportFn(options.blockExportFn, options.editorId);
  33195. editorState.setConvertOptions(options);
  33196. return editorState;
  33197. };
  33198. /* harmony default export */ var index_0 = __webpack_exports__["default"] = (createExtensibleEditor(editor_BraftEditor));
  33199. // 2.1版本开发计划
  33200. // [ ]优化选中多行文字是插入链接报错的问题
  33201. // [ ]新增编辑器内图片删除hook
  33202. // 2.2版本开发计划
  33203. // [ ]表格功能
  33204. // [ ]美化UI,包括图标和界面风格
  33205. // 2.3版本开发计划
  33206. // [ ]初级md快捷输入支持
  33207. // [ ]图片裁切等简单的编辑功能
  33208. // [ ]允许自定义快捷键
  33209. /***/ }),
  33210. /* 40 */
  33211. /***/ (function(module, exports) {
  33212. // removed by extract-text-webpack-plugin
  33213. /***/ }),
  33214. /* 41 */,
  33215. /* 42 */
  33216. /***/ (function(module, exports) {
  33217. // removed by extract-text-webpack-plugin
  33218. /***/ }),
  33219. /* 43 */,
  33220. /* 44 */,
  33221. /* 45 */
  33222. /***/ (function(module, exports) {
  33223. // removed by extract-text-webpack-plugin
  33224. /***/ }),
  33225. /* 46 */
  33226. /***/ (function(module, exports) {
  33227. // removed by extract-text-webpack-plugin
  33228. /***/ }),
  33229. /* 47 */
  33230. /***/ (function(module, exports) {
  33231. // removed by extract-text-webpack-plugin
  33232. /***/ }),
  33233. /* 48 */
  33234. /***/ (function(module, exports) {
  33235. // removed by extract-text-webpack-plugin
  33236. /***/ }),
  33237. /* 49 */
  33238. /***/ (function(module, exports) {
  33239. // removed by extract-text-webpack-plugin
  33240. /***/ }),
  33241. /* 50 */
  33242. /***/ (function(module, exports) {
  33243. // removed by extract-text-webpack-plugin
  33244. /***/ }),
  33245. /* 51 */
  33246. /***/ (function(module, exports) {
  33247. // removed by extract-text-webpack-plugin
  33248. /***/ }),
  33249. /* 52 */
  33250. /***/ (function(module, exports) {
  33251. // removed by extract-text-webpack-plugin
  33252. /***/ }),
  33253. /* 53 */
  33254. /***/ (function(module, exports) {
  33255. // removed by extract-text-webpack-plugin
  33256. /***/ }),
  33257. /* 54 */
  33258. /***/ (function(module, exports) {
  33259. // removed by extract-text-webpack-plugin
  33260. /***/ }),
  33261. /* 55 */
  33262. /***/ (function(module, exports) {
  33263. // removed by extract-text-webpack-plugin
  33264. /***/ }),
  33265. /* 56 */
  33266. /***/ (function(module, exports) {
  33267. // removed by extract-text-webpack-plugin
  33268. /***/ }),
  33269. /* 57 */
  33270. /***/ (function(module, exports) {
  33271. // removed by extract-text-webpack-plugin
  33272. /***/ }),
  33273. /* 58 */
  33274. /***/ (function(module, exports) {
  33275. // removed by extract-text-webpack-plugin
  33276. /***/ }),
  33277. /* 59 */
  33278. /***/ (function(module, exports) {
  33279. // removed by extract-text-webpack-plugin
  33280. /***/ }),
  33281. /* 60 */
  33282. /***/ (function(module, exports) {
  33283. // removed by extract-text-webpack-plugin
  33284. /***/ }),
  33285. /* 61 */
  33286. /***/ (function(module, exports) {
  33287. // removed by extract-text-webpack-plugin
  33288. /***/ }),
  33289. /* 62 */
  33290. /***/ (function(module, exports) {
  33291. // removed by extract-text-webpack-plugin
  33292. /***/ }),
  33293. /* 63 */
  33294. /***/ (function(module, exports) {
  33295. // removed by extract-text-webpack-plugin
  33296. /***/ })
  33297. /******/ ]);
  33298. });
  33299. });
  33300. var BraftEditor = unwrapExports(dist$3);
  33301. var css = ".index_bf-controlbar__ej8fA{margin:0;padding:0 5px;box-shadow:inset 0 -1px 0 0 rgba(0,0,0,.2)}.index_bf-controlbar__ej8fA:after{display:block;content:\"\";clear:both}.index_bf-controlbar__ej8fA button{padding:0;outline:none}.index_bf-controlbar__ej8fA button[disabled]{pointer-events:none;opacity:.3}.index_bf-controlbar__ej8fA [data-title]{position:relative}.index_bf-controlbar__ej8fA [data-title]:after,.index_bf-controlbar__ej8fA [data-title]:before{position:absolute;z-index:10;top:100%;left:50%;pointer-events:none;opacity:0;transform:translateX(-50%) translateY(-5px);transition:opacity .3s,transform .3s}.index_bf-controlbar__ej8fA [data-title]:before{margin-top:3px;border:5px solid transparent;border-bottom-color:#21242a;content:\"\"}.index_bf-controlbar__ej8fA [data-title]:after{margin-top:12px;padding:5px;background-color:#21242a;border-radius:2px;box-shadow:0 5px 15px rgba(0,0,0,.2);color:#fff;font-size:12px;line-height:16px;white-space:nowrap;content:attr(data-title)}.index_bf-controlbar__ej8fA [data-title]:hover:after,.index_bf-controlbar__ej8fA [data-title]:hover:before{opacity:1;transform:translateX(-50%) translateY(0)}.index_bf-controlbar__ej8fA input{outline:none}.index_bf-controlbar__ej8fA .index_separator-line__3SV92{display:block;float:left;height:26px;width:1px;margin:10px;box-shadow:inset -1px 0 0 0 rgba(0,0,0,.1)}.index_bf-controlbar__ej8fA .index_separator-line__3SV92+.index_control-item__2E9Ul,.index_bf-controlbar__ej8fA .index_separator-line__3SV92+.index_control-item-group__2GENZ{margin-left:0}.index_bf-controlbar__ej8fA .index_separator-line__3SV92+.index_separator-line__3SV92,.index_bf-controlbar__ej8fA .index_separator-line__3SV92.index_first-child__2fRfM,.index_bf-controlbar__ej8fA .index_separator-line__3SV92.index_last-child__1d0yb{display:none}.index_bf-controlbar__ej8fA .index_control-item-group__2GENZ{float:left;height:36px;margin:5px 0 5px 3px}.index_bf-controlbar__ej8fA .index_control-item-group__2GENZ:first-child{margin-left:0}.index_bf-controlbar__ej8fA .index_control-item-group__2GENZ>.index_control-item__2E9Ul{margin-top:0;margin-bottom:0}.index_bf-controlbar__ej8fA .index_dropdown-handler__1xChS{border-radius:2px}.index_bf-controlbar__ej8fA .index_control-item__2E9Ul{display:block;float:left;height:36px;margin:5px 0 5px 3px;border-radius:2px;cursor:pointer}.index_bf-controlbar__ej8fA .index_control-item__2E9Ul.index_component-wrapper__OLlmp{cursor:default}.index_bf-controlbar__ej8fA .index_control-item__2E9Ul:first-child{margin-left:0}.index_bf-controlbar__ej8fA .index_control-item__2E9Ul.index_button__2IaUw{box-sizing:border-box;min-width:36px;padding:0 8px;background-color:transparent;border:none;color:#6a6f7b;font-size:14px}.index_bf-controlbar__ej8fA .index_control-item__2E9Ul.index_button__2IaUw:hover{background-color:rgba(0,0,0,.05)}.index_bf-controlbar__ej8fA .index_control-item__2E9Ul.index_button__2IaUw.index_active__3_mlp{color:#3498db}.index_bf-controlbar__ej8fA .index_control-item__2E9Ul.index_button__2IaUw i:before{display:block;height:36px;font-size:18px;line-height:36px}.index_bf-controlbar__ej8fA .index_control-item__2E9Ul.index_button__2IaUw .index_bfi-redo__1Q-LG:before,.index_bf-controlbar__ej8fA .index_control-item__2E9Ul.index_button__2IaUw .index_bfi-undo___pDce:before{font-size:14px}.index_bf-controlbar__ej8fA .index_dropdown__1rkgF .index_control-item__2E9Ul{width:100%;float:none;margin:0}.index_DraftEditor-editorContainer__1FR0o,.index_DraftEditor-root__mlfOI,.index_public-DraftEditor-content__T2mZu{height:inherit;text-align:initial}.index_public-DraftEditor-content__T2mZu[contenteditable=true]{-webkit-user-modify:read-write-plaintext-only}.index_DraftEditor-root__mlfOI{position:relative}.index_DraftEditor-editorContainer__1FR0o{background-color:hsla(0,0%,100%,0);border-left:.1px solid transparent;position:relative;z-index:1}.index_public-DraftEditor-block__IOQ0s{position:relative}.index_DraftEditor-alignLeft__gR9_E .index_public-DraftStyleDefault-block__3m05I{text-align:left}.index_DraftEditor-alignLeft__gR9_E .index_public-DraftEditorPlaceholder-root__1T6lJ{left:0;text-align:left}.index_DraftEditor-alignCenter__3Fyko .index_public-DraftStyleDefault-block__3m05I{text-align:center}.index_DraftEditor-alignCenter__3Fyko .index_public-DraftEditorPlaceholder-root__1T6lJ{margin:0 auto;text-align:center;width:100%}.index_DraftEditor-alignRight__3ghf4 .index_public-DraftStyleDefault-block__3m05I{text-align:right}.index_DraftEditor-alignRight__3ghf4 .index_public-DraftEditorPlaceholder-root__1T6lJ{right:0;text-align:right}.index_public-DraftEditorPlaceholder-root__1T6lJ{color:#9197a3;position:absolute;z-index:1}.index_public-DraftEditorPlaceholder-hasFocus__kQoHC{color:#bdc1c9}.index_DraftEditorPlaceholder-hidden__22I_U{display:none}.index_public-DraftStyleDefault-block__3m05I{position:relative;white-space:pre-wrap}.index_public-DraftStyleDefault-ltr__3qMdW{direction:ltr;text-align:left}.index_public-DraftStyleDefault-rtl__2k3sG{direction:rtl;text-align:right}.index_public-DraftStyleDefault-listLTR__Mmamr{direction:ltr}.index_public-DraftStyleDefault-listRTL__2WhLE{direction:rtl}.index_public-DraftStyleDefault-ol__32plX,.index_public-DraftStyleDefault-ul__1_opE{margin:16px 0;padding:0}.index_public-DraftStyleDefault-depth0__2YvNJ.index_public-DraftStyleDefault-listLTR__Mmamr{margin-left:1.5em}.index_public-DraftStyleDefault-depth0__2YvNJ.index_public-DraftStyleDefault-listRTL__2WhLE{margin-right:1.5em}.index_public-DraftStyleDefault-depth1__3dbfg.index_public-DraftStyleDefault-listLTR__Mmamr{margin-left:3em}.index_public-DraftStyleDefault-depth1__3dbfg.index_public-DraftStyleDefault-listRTL__2WhLE{margin-right:3em}.index_public-DraftStyleDefault-depth2__2mADP.index_public-DraftStyleDefault-listLTR__Mmamr{margin-left:4.5em}.index_public-DraftStyleDefault-depth2__2mADP.index_public-DraftStyleDefault-listRTL__2WhLE{margin-right:4.5em}.index_public-DraftStyleDefault-depth3__1V80Q.index_public-DraftStyleDefault-listLTR__Mmamr{margin-left:6em}.index_public-DraftStyleDefault-depth3__1V80Q.index_public-DraftStyleDefault-listRTL__2WhLE{margin-right:6em}.index_public-DraftStyleDefault-depth4__9Zzf6.index_public-DraftStyleDefault-listLTR__Mmamr{margin-left:7.5em}.index_public-DraftStyleDefault-depth4__9Zzf6.index_public-DraftStyleDefault-listRTL__2WhLE{margin-right:7.5em}.index_public-DraftStyleDefault-unorderedListItem__fNkjl{list-style-type:square;position:relative}.index_public-DraftStyleDefault-unorderedListItem__fNkjl.index_public-DraftStyleDefault-depth0__2YvNJ{list-style-type:disc}.index_public-DraftStyleDefault-unorderedListItem__fNkjl.index_public-DraftStyleDefault-depth1__3dbfg{list-style-type:circle}.index_public-DraftStyleDefault-orderedListItem__3J0MZ{list-style-type:none;position:relative}.index_public-DraftStyleDefault-orderedListItem__3J0MZ.index_public-DraftStyleDefault-listLTR__Mmamr:before{left:-36px;position:absolute;text-align:right;width:30px}.index_public-DraftStyleDefault-orderedListItem__3J0MZ.index_public-DraftStyleDefault-listRTL__2WhLE:before{position:absolute;right:-36px;text-align:left;width:30px}.index_public-DraftStyleDefault-orderedListItem__3J0MZ:before{content:counter(a) \". \";counter-increment:a}.index_public-DraftStyleDefault-orderedListItem__3J0MZ.index_public-DraftStyleDefault-depth1__3dbfg:before{content:counter(b) \". \";counter-increment:b}.index_public-DraftStyleDefault-orderedListItem__3J0MZ.index_public-DraftStyleDefault-depth2__2mADP:before{content:counter(c) \". \";counter-increment:c}.index_public-DraftStyleDefault-orderedListItem__3J0MZ.index_public-DraftStyleDefault-depth3__1V80Q:before{content:counter(d) \". \";counter-increment:d}.index_public-DraftStyleDefault-orderedListItem__3J0MZ.index_public-DraftStyleDefault-depth4__9Zzf6:before{content:counter(e) \". \";counter-increment:e}.index_public-DraftStyleDefault-depth0__2YvNJ.index_public-DraftStyleDefault-reset__1awm7{counter-reset:a}.index_public-DraftStyleDefault-depth1__3dbfg.index_public-DraftStyleDefault-reset__1awm7{counter-reset:b}.index_public-DraftStyleDefault-depth2__2mADP.index_public-DraftStyleDefault-reset__1awm7{counter-reset:c}.index_public-DraftStyleDefault-depth3__1V80Q.index_public-DraftStyleDefault-reset__1awm7{counter-reset:d}.index_public-DraftStyleDefault-depth4__9Zzf6.index_public-DraftStyleDefault-reset__1awm7{counter-reset:e}.index_bf-switch__1LPr-{position:relative;width:32px;height:16px;background-color:hsla(0,0%,100%,.15);border-radius:8px;transition:background .3s}.index_bf-switch__1LPr-.index_active__3_mlp{background-color:#3498db}.index_bf-switch__1LPr-.index_active__3_mlp:before{left:16px}.index_bf-switch__1LPr-:before{position:absolute;left:0;display:block;width:16px;height:16px;border-radius:8px;background-color:#eee;content:\"\";transform:scale(1.2);transition:.3s}@font-face{font-family:braft-icons;src:url(data:application/font-woff;base64,d09GRgABAAAAACxUAAsAAAAALAgAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABPUy8yAAABCAAAAGAAAABgDxIH02NtYXAAAAFoAAAA9AAAAPQXCcwWZ2FzcAAAAlwAAAAIAAAACAAAABBnbHlmAAACZAAAJggAACYI9aImY2hlYWQAAChsAAAANgAAADYTSfwFaGhlYQAAKKQAAAAkAAAAJAfCBAxobXR4AAAoyAAAASwAAAEsIgAgXGxvY2EAACn0AAAAmAAAAJhQxVqgbWF4cAAAKowAAAAgAAAAIABVAH1uYW1lAAAqrAAAAYYAAAGGmUoJ+3Bvc3QAACw0AAAAIAAAACAAAwAAAAMD+QGQAAUAAAKZAswAAACPApkCzAAAAesAMwEJAAAAAAAAAAAAAAAAAAAAARAAAAAAAAAAAAAAAAAAAAAAQAAA6rADwP/AAEADwABAAAAAAQAAAAAAAAAAAAAAIAAAAAAAAwAAAAMAAAAcAAEAAwAAABwAAwABAAAAHAAEANgAAAAyACAABAASAAEAIOAp4DTgN+BC4LjiKOI547jjwuQp6SbpMelG6WjpgOms6mjqbOpu6nXqsP/9//8AAAAAACDgJuA04DfgQuC44ijiOeO448LkKekA6SzpRuln6YDprOpo6mvqbupz6rD//f//AAH/4x/eH9Qf0h/IH1Md5B3UHFYcTRvnFxEXDBb4FtgWwRaWFdsV2RXYFdQVmgADAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAH//wAPAAEAAAAAAAAAAAACAAA3OQEAAAAAAQAAAAAAAAAAAAIAADc5AQAAAAABAAAAAAAAAAAAAgAANzkBAAAAAAQAVQCAA6sC1QARACMANQBHAAATITIXFhUUBwYjISInJjU0NzYTITIXFhUUBwYjISInJjU0NzY3ITIXFhUUBwYjISInJjU0NzY3ITIXFhUUBwYjISInJjU0NzaAAwASDA0NDBL9ABIMDQ0MEgMAEgwNDQwS/QASDA0NDBIDABIMDQ0MEv0AEgwNDQwSAwASDA0NDBL9ABIMDQ0MAtUMDRESDQwMDRIRDQz+AAwNERINDAwNEhENDKsNDBIRDQwMDRESDA2rDQwSEgwNDQwSEgwNAAAABABVAIADqwLVABEAIwA1AEcAABMhMhcWFRQHBiMhIicmNTQ3NhMhMhcWFRQHBiMhIicmNTQ3NjchMhcWFRQHBiMhIicmNTQ3NjchMhcWFRQHBiMhIicmNTQ3NoADABIMDQ0MEv0AEgwNDQwSAlUSDA0MDRL9qxIMDQ0MEgMAEgwNDQwS/QASDA0NDBICVRIMDQwNEv2rEgwNDQwC1QwNERINDAwNEhENDP4ADA0REg0MDA0SEQ0Mqw0MEhENDAwNERIMDasNDBISDA0NDBISDA0AAAAEAFUAgAOrAtUAEQAkADYASQAAEyEyFxYVFAcGIyEiJyY1NDc2EyEyFxYVFAcGIyEiJyY1NDc2MychMhcWFRQHBiMhIicmNTQ3NjchMhcWFRQHBiMhIicmNTQ3NjOAAwASDA0NDBL9ABIMDQ0MZwJWEQ0MDA0R/aoRDQwMDRFVAwASDA0NDBL9ABIMDQ0MZwJWEQ0MDA0R/aoRDQwMDREC1QwNERINDAwNEhENDP4ADA0REg0MDA0SEQ0Mqw0MEhENDAwNERIMDasNDBISDA0NDBISDA0AAAAEAFUAgAOrAtUAEQAkADYASQAAEyEyFxYVFAcGIyEiJyY1NDc2EyEyFxYVFAcGIyEiJyY1NDc2MychMhcWFRQHBiMhIicmNTQ3NjchMhcWFRQHBiMhIicmNTQ3NjOAAwASDA0NDBL9ABIMDQ0MvQJVEgwNDQwS/asSDA0MDRKrAwASDA0NDBL9ABIMDQ0MvQJVEgwNDQwS/asSDA0MDRIC1QwNERINDAwNEhENDP4ADA0REg0MDA0SEQ0Mqw0MEhENDAwNERIMDasNDBISDA0NDBISDA0AAAACAQAAgQMAAtUAAwAHAAABMxEjIREzEQJWqqr+qqoC1f2sAlT9rAAAAQFWAIEDKgLVAAIAAAkCAVYB1P4sAtX+1v7WAAEAqgArA1YDgQAuAAABMhceARcWFRQHDgEHBiMiJy4BJyY1MxQXHgEXFjMyNz4BNzY1NCcuAScmIxUnNwIARj8+XRsbGxtdPj5HRj8+XRsbVhQURS8vNTUvL0UUFBQURS8vNdbWAtUbG1w+PkZHPj5dGxsbG10+Pkc2Li9FFBQUFEUvLjY1Ly5GFBSs1tYAAAMAMwCqA80CqwAEAAkADQAAEyEVITUDNSEVITc1IRX/As79MswCzv0yaALKAqtnZ/3/Z2fOZWUABQCAACsDgAMrAAMABwALAA8AEwAAAREhEQERIREDESERAREhEQMhESEDKv8AAQD/AFT/AAEA/wBWAwD9AAHVAQD/AP6sAQD/AAFUAQD/AP6sAQD/AAKq/QAAAAACAFYAKwNWAtUACAARAAABIRUjByc3IycnFwEHJwcjNwEBAAJW+ERaHmZ4dAwCaDbyQoBo/tgC1YCgWEh4CAr9ljbynPYBKAACAIAAKwN0Ax8AAwAWAAAlAScBAR4BDwEXBycBIzUBJzcXNzYyFwEoAVhS/qgCngwBDYZSPDz+gsoBfDw8UoYMJAyBAVhS/qgB6AwjDYZSPDz+hMoBfjw8UoYMDAAAAAAEAIAAKwOAAysACAARABoAIwAAATIWHQEjNSM1EzUzFRQGKwE1JRUzFSMiJj0BETQ2OwEVIxUjAyoiNFaqqlYzI6r+VqqqIjQzI6qqVgMrNCKqqlb9VqqqIzNWqqpWMyOqAaoiNFaqAAYAgAArA4ADKwAHAAsAEwAbAB8AIwAAAREzFTMVIxUXITUhJTMRIzUjNTMBIxEzFSEVIQEhFSERIRUhAoBWqqqq/lYBqv2qVlaqqgEAVFQBVv6q/lYBqv5WAQD/AAIrAQBWVFaqVFb/AFZU/lYBAFZUAlRU/lRUAAIAgABNA4ADTQATAB0AACUhESE1ISIGFREUFjMhMjY1ESMRAxUzARcBFTMRIQMr/aoBK/7VIzIyIwJWIzJV1pr+XDwBpFX+1aICVVYyJP2rIzIyIwEr/tUCq1b+XTwBo5kBKwAEAFUAIgOrA3cABAAhAD0AQgAAJTMRIxETIgcOAQcGFRQXHgEXFjMyNz4BNzY1NCcuAScmIxEiJy4BJyY1NDc+ATc2MzIXHgEXFhUUBw4BBwYDMzUjFQHVVlYrWE5OdCEiIiF0Tk5YWE5OdCEiIiF0Tk5YRz4+XRobGxpdPj5HRz4+XRobGxpdPj5yVlb3AQD/AAKAISJzTk5YWU1OdCEiIiF0Tk1ZWE5OcyIh/QAbG10+PkdGPz5cGxsbG1w+P0ZHPj5dGxsB1lVVAAAEAFUAIgOrA3cABAAhAD0AUgAAJTM1IxUTIgcOAQcGFRQXHgEXFjMyNz4BNzY1NCcuAScmIxEiJy4BJyY1NDc+ATc2MzIXHgEXFhUUBw4BBwYDIgYVMzQ2MzIWFRQGFTM0NjU0JiMB1VZWK1hOTnQhIiIhdE5OWFhOTnQhIiIhdE5OWEc+Pl0aGxsaXT4+R0c+Pl0aGxsaXT4+R0dkVjIjIzKAVoBkR81VVQKqISJzTk5YWU1OdCEiIiF0Tk1ZWE5OcyIh/QAbG10+PkdGPz5cGxsbG1w+P0ZHPj5dGxsCVmRHIzIyI0AtaEg9UEdkAAACAFUAzQOrAs0ABQALAAABJzcnCQElNyc3CQEBkcTEPP8AAQABGsTEPAEA/wABCcTEPP8A/wA8xMQ8/wD/AAAAAwErAM0C9QMiAA8AGQAiAAABPgE1NCYjIREhMjY1NCYnJzMyFhUUBisBNRMjNTMyFhUUBgKaHydjSP72ASxDWzIp74AaJiYagJWVlRslJQIAFkEgSWL9q19DME4TtyUbGiaA/oCAJRsaJgAAAQCAACYDgAN3ADQAAAEiBgclPgE1NCYnJR4BMzI2NTQmIyIGFRQWFwUuASMiBhUUFjMyNjcFDgEVFBYzMjY1NCYjAwAYKxH+0AICAgIBLREtGTVLSzU1SwIC/tMRLRk1S0s1GS0RATACAkk0NElJNAEfEg+xBw8IBw8IrxATSzU2Sko2Bw8HsBATSzU1SxIQsQcOBzNJSTM0SQAAAQErAU0C1QIiAAIAAAEXNwEr1dUCItXVAAAAAAMAVQAiA6sDdwAcACsAOgAAASIHDgEHBhUUFx4BFxYzMjc+ATc2NTQnLgEnJiMBNDc+ATc2MzIWFwEuATUBIiYnAR4BFRQHDgEHBiMCAFhOTXQiIiIidE1OWFhOTXQiIiIidE1OWP6rGxtcPj9GOmot/iIjJQFVOmotAd4jJRsbXD4/RgN3ISJ0Tk1YWE5OdCEiIiF0Tk5YWE1OdCIh/lZGPj5dGxslI/4iLWo6/qomIwHeLWs5Rz4+XRsbAAAAAAMAgADNA4ACzQADAAcACwAANyE1ITUhNSE1FSE1gAMA/QADAP0AAwDNVYBV1lZWAAEBKwF3AtUCTQACAAABNxcBK9XVAXfW1gAAAAADAasAdwJVAyIADAAYACQAAAEyNjU0JiMiBhUUFjMVIgYVFBYzMjY1NCYDIgYVFBYzMjY1NCYCACMyMiMjMjIjIzIyIyMyMiMjMjIjIzIyAnczIyMyMiMjM1UyIyMzMyMjMv8AMiMjMzMjIzIAAAAAAwCrAXcDVQIiAAwAGAAkAAABIgYVFBYzMjY1NCYjISIGFRQWMzI2NTQmISIGFRQWMzI2NTQmAQAjMjIjIzIyIwIAIzIyIyMyMv7dIzIyIyMyMgIiMiMjMzMjIzIyIyMzMyMjMjIjIzMzIyMyAAAAAAIAAP/ABAADgAApAC0AAAERIzU0JiMhIgYdARQWMyEyNj0BMxEhFSMiBhURFBY7ATI2NRE0JisBNQEhNSEEAMAmGv1AGiYmGgLAGiaA/cAgDRMTDYANExMNIAFA/UACwAGAAYBAGiYmGsAaJiYaQP8AgBMN/sANExMNAUANE0ABgEAAAAQA1QCiAysC9wAGAA0AEwAaAAATMxUzNSMVEyMVMzUjFQEzNTM1IxM1IxUzNSPVgFbWgIDWVgEAVoDWVlbWgAEigNVVAVVV1YD+K4BVAQCA1VUAAAEAZAAlA1wDXABEAAABERQHBgcGBwYjIicmJyYnJjU0NzY3Njc2MzIXEQURFAcGBwYHBiMiJyYnJicmNTQ3Njc2NzYzMhcRNDc2NyU2MzIXFhUDXBERGhkaGRYXGRoZGhEREREaGRoZFzMr/oURERoZGhkXFhkaGRoRERERGhkaGRY0KwoJDwGbBggUDg4DLP3WGBQTCgsFBQUFCwoTFBgZExQKCwUFEwEKdv6iGRMTCwsFBQUFCwsTExkZExMLCgYFEwHeDw0MBX8CDg4UAAAEAHUAQgOJA1YALwA8AGIAeAAAAS4BBw4BJy4BJy4BBwYiJyYGBw4BJyYGBxQVHAEVFBUeATM2MzoBMzIzMjY3PAE1BSImNTQ2MzIWFRQGJyUqASM8ATU6ATMUFhUUFxwBFQYHFAYHDgEnLgE3PgE3OgEzPAE1BT4BNzoBMxQWBw4BJy4BNz4BNzoBMwKBARkZChUJCxcEFEMvBw8HHikMDCgdFyILCxgWNDM0ZzQzNBsaAf77L0FBMDBAQDEBtx8/IDRoNgEBAQENCxVFICIlBgc3JAcNCf7OAQICEyQTAwUFSiMmOAIBOiYHEAkCzhcaAQEBAwIJCC0fCAEBBhgbGxYGBBMVKCgpUCgoKQ8VARcaSpRK7T8uMEA/LzBAARchPyAKEgkzMjNmMjMzFCwRIBAOD0IjJjQDN2053QwUCi5dLSUsBgVEJig+BAAAAAAEANUAogMrAvcABQALABEAFwAAASMVMzUjAzM1MzUjASMVMzUjAxUzFTM1AStW1oBWVoDWAgCA1laAgFYBd9VVASuAVf4AVdUBgFWA1QAAAAQAAAAABAADQAAbADMATwBTAAABFBceARcWMzI3PgE3NjU0Jy4BJyYjIgcOAQcGASMuASMhIgYHIyIGFREUFjMhMjY1ETQmASInLgEnJjU0Nz4BNzYzMhceARcWFRQHDgEHBgEjNTMBMBAROCYmKysmJjgREBAROCYmKysmJjgREAKQ4AwkMP8AMCQM4BomJhoDgBomJv4mOzQzTRcWFhdNMzQ7OzQzTRcWFhdNMzQBhYCAAWArJiY4ERAQETgmJisrJiY4ERAQETgmJgE1MFBQMCYa/cAaJiYaAkAaJv2EFhdNMzQ7OzQzTRcWFhdNMzQ7OzQzTRcWAbxAAAEAkQCiA4AC3gAGAAABJwcXAScBAYCzPO8CADz+PAEaszzvAgA8/jwAAAAAAQDiAIADHgLJACYAAAE3NjQnJiIPAScmIgcGFB8BBwYUFx4BMzI2PwEXHgEzMjY3NjQvAQI84g0NDCQM4uIMJAwNDeLiDQ0GEAgIEAbi4gYQCAgQBg0N4gGr4gwjDQwM4uIMDA0jDOLiDSMMBwYGB+HhBwYGBwwjDeIAAAUAVQCVA6sC6wAZACoARABeAHgAAAEhIgYHDgEVFBYXHgEzITI2Nz4BNTQmJy4BJTQmIyEiBh0BFBYzITI2PQEDISIGBw4BFRQWFx4BMyEyNjc+ATU0JicuAQMhIgYHDgEVFBYXHgEzITI2Nz4BNTQmJy4BBSEiBgcOARUUFhceATMhMjY3PgE1NCYnLgEB1f6rCQ8GBgcHBgYPCQFVCQ8GBwYGBwYPAc0ZEv8AEhkZEgEAEhkr/QAJDwYGBwcGBg8JAwAJDwYGBwcGBg8J/QAJDwYGBwcGBg8JAwAJDwYGBwcGBg/+TP6rCQ8GBgcHBgYPCQFVCQ8GBwYGBwYPAZUGBgYQCAkPBgcGBgcGDwkIEAYGBoERGRkRrBEZGRGs/tUHBgYPCQkPBgYHBwYGDwkJDwYGBwIABwYGDwkJDwYGBwcGBg8JCQ8GBgerBgcGDwkIEAYGBgYGBhAICQ8GBwYAAAAABABVAE0DqwNNAA4AEgAeACIAAAEhIgYVETMVITUzETQmIwMhNSE3IiY1NDYzMhYVFAYDIRUhAyv9qjVLqwIAq0s1gP6qAVaAEhkZEhEZGTz+AAIAAndKNv8AqqoBADZK/ivVVhkREhkZEhEZAYCrAAIAgABjA2oDTQAiAC8AAAEjJz4BNTQnLgEnJiMiBw4BBwYVFBceARcWMzI2NxcVFzcnISImNTQ2MzIWFRQGIwKVIQwfJBYWSzMyOjkzMksWFhYWSzIzOTRcJQvWP9X/AE9xcU9QcHBQAXcMJF0zOjIzSxYWFhZLMzI6OTIzSxYWJB8MItQ/1XFPUHBwUE9xAAIAZAAiA5wDdwBNAFkAAAE+ATU0Jic3PgEvAS4BDwEuAS8BLgErASIGDwEOAQcnJgYPAQYWHwEOARUUFhcHDgEfAR4BPwEeAR8BHgE7ATI2PwE+ATcXFjY/ATYmJwUiJjU0NjMyFhUUBgM9AQICAVoGAwRVBA8HahEkFBABDAiqCAwBEBQkEWoHDwRVBAMGWgECAgFaBgMEVQQPB2oRJBQQAQwIqggMARAUJBFqBw8EVQQDBv5pPldXPj5XVwGjChULCxQLRgUPB5QHBQMqDBUIcgcKCgdyCBUMKgMFB5QHDwVGCxUKCxUKRgUQB5MHBQIrDRUIcQgKCghxCBUNKwMGB5MHEAUmWD4+V1c+PlgAAQDVAKIDKwL3AAsAAAEhESMRITUhETMRIQMr/wBW/wABAFYBAAGi/wABAFUBAP8AAAAAAAQAVf/vA6sC7wAeADMAOAA9AAATNwEHJyM1JyM1Jw4BFRQWOwEVIyInLgEnJjU0NjcnBTIXHgEXFhUUBgcnPgE1NCYrATUzITMVIycFFSMnM1U3Ask2q0mMSmogJWdIgIA1Li9FFRQyKlwCVjUuL0UVFEc5PC88Z0iAgP6qgDZRAV0zVYgCuTb9NzerSYxKaxhIKklmURQURS8vNTpnIlwfFRRFLy41R3YhPRRWN0hnUVFR1lVVAAADAFUAmgOrApoAGgA1ADkAAAEjFTMyFhUUBisBFTMyNz4BNzY1NCcuAScmIwE0NjsBNSMiBw4BBwYVFBceARcWOwE1IyImNRchNSECq4CASGdnSICANS4vRRUUFBVFLy41/ftnSICANS4vRRUUFBVFLy41gIBIZ68BVv6qAppRZ0hJZlEUFEUvLzU1Li9FFRT/AEhnURUURS8uNTUvL0UUFFFmSStVAAAFAFUAIgOrA3cAHAA4AEQAUABYAAABIgcOAQcGFRQXHgEXFjMyNz4BNzY1NCcuAScmIxEiJy4BJyY1NDc+ATc2MzIXHgEXFhUUBw4BBwYTMjY1NCYjIgYVFBYhMjY1NCYjIgYVFBYTMjY3IR4BMwIAWU1OdCEiIiF0Tk1ZWE5OdCEiIiF0Tk5YRz4+XRsaGhtdPj5HRz4+XRsaGhtdPj5OGyUlGxomJv7wGiYmGhslJbBLdRr+TBp1SwN3ISJzTk5YWU1OdCEiIiF0Tk1ZWE5OcyIh/QAbG10+PkdHPj5dGhsbGl0+PkdHPj5dGxsBgCYaGyUlGxomJhobJSUbGib+61RBQVQAAAAJAAAAQAQAA0AAAwAHAAsADwATABcAGwAfACIAABMRIREBIzUzNSM1MzUjNTMBIREhEyM1MzUjNTM1IzUzBRElAAQA/MCAgICAgIACQP4AAgDAgICAgICA/cABAANA/QADAP1AgICAgID9gAKA/YCAgICAgID+gMAAAAAAAgDVAE0DKwNNABkAHgAAJTI3PgE3NjURIxEUBiMiJjURIxEUFx4BFxYHFSE1IQIANS8uRhQUa1c+PldrFBRGLi/2Alb9qvcVFEUvLzQBVv6qPVhYPQFW/qo0Ly9FFBVVVVUAAAUAVQCVA6sC6wAaACsARQBfAHoAAAEhMhYXHgEVFAYHDgEjISImJy4BNTQ2Nz4BMyU0NjMhMhYdARQGIyEiJj0BEyEyFhceARUUBgcOASMhIiYnLgE1NDY3PgETITIWFx4BFRQGBw4BIyEiJicuATU0Njc+AQUhMhYXHgEVFAYHDgEjISImJy4BNTQ2Nz4BMwIrAVUJDwYGBwcGBg8J/qsJDwYHBgYHBg8J/ioZEgEAEhkZEv8AEhkrAwAJDwYGBwcGBg8J/QAJDwYGBwcGBg8JAwAJDwYGBwcGBg8J/QAJDwYGBwcGBg8BtAFVCQ8GBgcHBgYPCf6rCQ8GBwYGBwYPCQGVBgYGEAgJDwYHBgYHBg8JCBAGBgaBERkZEawRGRkRrP7VBwYGDwkJDwYGBwcGBg8JCQ8GBgcCAAcGBg8JCQ8GBgcHBgYPCQkPBgYHqwYHBg8JCBAGBgYGBgYQCAkPBgcGAAAAAAMAgACiA4ADIgAEAA0AEQAAJTM1IxUDFTMVMzUzNSEDITUhAauqqtbWqtb9qlUDAP0AooCAAoCAgICA/lVWAAACAIAAogOrAyIACAARAAABFTMRMxEzNSEBMxEzETM1IRUBgNWA1v3V/wCAgID+gAMigP4AAgCA/qv+1QErgIAAAgDVAPcDKwKiAAYADQAAJTM3ESERMwUzNxEhETMBAIBV/wCAAQCAVv8AgPerAQD/AKurAQD/AAAGAFUAdwOAAyIACwASAB0AIgAnACwAADczFSMVMxUjFTM1IxMzNSMVMxUHMwcVMzUjNzUjFRMVITUhESE1IRURITUhFVVWKytWgIArK1YrK01NgExMgNYCVf2rAlX9qwJV/av3FSsVK6sBVasrgIBZJytaJisBAFVV/atVVQEAVVUAAAAGAGsAjQOAAw0ACwAXACMAKAAtADIAABMiBhUUFjMyNjU0JgMiBhUUFjMyNjU0JgMiBhUUFjMyNjU0JhchNSEVESE1IRURFSE1IasbJSUbGiYmGhslJRsaJiYaGyUlGxomJmYCVf2rAlX9qwJV/asCDSYaGyUlGxomAQAmGhslJRsaJv4AJhoaJiYaGiZrVVUBAFVVAVVVVQAAAAABAQAAzQMAAyIACwAAARUzAyMVITUjEzM1AatekncBVV6SdwMigP6rgIABVYAAAAABAAABawQAAesAAwAAEyEVIQAEAPwAAeuAAAAABgBA/8ADwAPAABkAIQA5AEcAVQBjAAABLgEnLgEnLgEjISIGFREUFjMhMjY1ETQmJyceARcjNR4BExQGIyEiJjURNDYzMDM6ATMyMRUUFjsBAyEiJjU0NjMhMhYVFAYnISImNTQ2MyEyFhUUBichIiY1NDYzITIWFRQGA5YRLRkaMxcnKQv+ECEvLyEC4CEvDhyFFyUNmhEphgkH/SAHCQkHTU66TU4TDeCg/kANExMNAcANExMN/kANExMNAcANExMN/kANExMNAcANExMC2xczGhktERwOLyH8oCEvLyECcAspJzYXKRGaDSX86AcJCQcDYAcJ4A0T/gATDQ0TEw0NE4ATDQ0TEw0NE4ATDQ0TEw0NEwAAAAUAAP/ABAADwAAIAAsAEwAWABwAAAERIQcRIREhESUVIwMRMzUhFQcRExUjASERMzUhAoD+QMABgAKA/MBlG8ABQMDAZQHl/gDAAUACwAEAwP3A/wADAKVl/gABwMDAwP8AAWVl/gABwMAAAAUAQP/ABAADwAANABgANAA3AD0AAAEjNTQmKwEiBh0BIxUhJyM1OAExMzgBMRUFNTQmKwEVMxUjBxEhETM1IyIGFREUFjMhFSERBRUjASERMzUhAsCAJhqAGiaAAgDAgIABQBMNQCDAwP8AIEANExMNASACgP5AZQHl/gDAAUADQEAaJiYaQICAQEDAoA0TQIDA/wACQEATDf2ADRPAAsBbZf5AAYDAAAYAgABNA4ADTQADAAcACwAPABMAFwAANyE1IRkBNycBITUhARUhNQEhNSERITUhgAMA/QCrqwFVAav+Vf6rAwD+VQGr/lUBq/5VTVUB1f6rq6r+gFYCAFZW/wBV/wBVAAYAgABNA4ADTQADAAcACwAPABMAFwAAJSE1ISUXEQcRITUhERUhNQEhNSERITUhAdUBq/5V/qurqwMA/QADAP5VAav+VQGr/lX3VoCrAVWq/oBVAqtWVv8AVf8AVQAAAAEAAP/NBAAAdwADAAA3IRUhAAQA/AB3qgAAAAACAOsA9wMVA00ACAAMAAABAzM3IRczAyMDGwEjAdXqYC8BCzBg6lY7ZmbMA039qoCAAlb+gAEO/vIAAAACAAD/wAQAA8AADgASAAABBxcDIxcBFTMBFzUlFzcFJzcXAiBgYODgsP7wJwFpsAEAYGD9wEDgQAPAYGD/ALD+lycBELDg4GBgQEDgQAAAAAEAQP/AA4oDwAARAAAFNjc2JicmBxUJARU2Fx4BBwYC+isTEzhVVqj+gAGAyXFyRignQE1bW5ozMgT+AYABgPgFTk7siokAAAEAdv/AA8ADwAASAAABNQkBNSYHDgEXFhcmJyY2NzYXAkABgP6AqFZVOBMTK2knKEZycckCyPj+gP6A/gQyM5pbW01yiYrsTk4FAAAHAAD/wAQAA0YACwAXACMALwA7AEcAUwAAJTQ2MzIWFRQGIyImATQ2MzIWFRQGIyImJTQ2MzIWFRQGIyImATQ2MzIWFRQGIyImATQ2MzIWFRQGIyImJTQ2MzIWFRQGIyImATQ2MzIWFRQGIyImAaA4KCg4OCgoOP5gOCgoODgoKDgDQDgoKDg4KCg4/To4KCg4OCgoOAJMOCgoODgoKDj9tDgoKDg4KCg4Akw4KCg4OCgoOCAoODgoKDg4AcgoODgoKDg4KCg4OCgoODgBTig4OCgoODj93Cg4OCgoODgoKDg4KCg4OAJ0KDg4KCg4OAAFAHwAAAOEA1UAIgAtADgARgBUAAABIzU0JisBIgYdASMiBhUUFjsBERQWMyEyNjURMzI2NTQmIyU0NjsBMhYdASM1ARQGIyEiJjURIREBIgYdARQWMzI2PQE0JjMiBh0BFBYzMjY9ATQmA12bRDCcMESbEBcXECdEMAGEMEQnEBcXEP4vFhCcEBboAV0XEP58EBcB0v7JEBYWEBAXF4wQFxcQEBYWAronMEREMCcXEBAW/gcwREQwAfkWEBAXJxAXFxAnJ/2TEBYWEAH5/gcBhBcQ6BAXFxDoEBcXEOgQFxcQ6BAXAAAABwAA/8AEAAPAAAMABwALAA8AEwAbACMAABMzFSM3MxUjJTMVIzczFSMlMxUjAxMhEzMTIRMBAyEDIwMhAwCAgMDAwAEAgIDAwMABAICAEBD9ABAgEAKAEP1AEAMAECAQ/YAQAcBAQEBAQEBAQEACQP5AAcD+gAGA/AABgP6AAUD+wAAABABQAIAEAAPAAAgADQAQAEAAAD8BIRczAyMDMxMzFyM3ARsBAyMiJjU0NjsBMjY1NCYrASIGFRQWFx4BOwEyFhUUBisBIgYVFBY7ATI2NTQmJy4BwjoBCDpywODAcppIOrw6AWSgoKBADRMTDYANExMNgCg4DQwNJRVADRMTDYANExMNgCg4DQwNJYDAwAKA/YACAMDA/gABAP8AAsATDQ0TEw0NEzgoEiENDxETDQ0TEw0NEzgoEiENDxEAAAAABABQ/8AEAAMAAAgADQAQAEAAAD8BIRczAyMDMxMzFyM3JQsBEyMiJjU0NjsBMjY1NCYrASIGFRQWFx4BOwEyFhUUBisBIgYVFBY7ATI2NTQmJy4BwjoBCDpywODAcppIOrw6AqSgoKBADRMTDYANExMNgCg4DQwNJRVADRMTDYANExMNgCg4DQwNJYDAwAKA/YACAMDAgP8AAQD9gBMNDRMTDQ0TOCgSIQ0PERMNDRMTDQ0TOCgSIQ0PEQAHAAD/wAQAA8AABwAPABMAFwAbAB8AIgAAAREhESMRIREFESERMxEhESUzFSMnMxUjJTMVIzczFSMlFwcBAAMAQP2AAsD9AEACgP5AgIDAgIABgICAwICA/IDAwAJAAYD+gAFA/sDA/kABwP6AAYCAQEBAQEBAQODAwAAAAQCA/8ADgAPAABcAAAEhFSMRIxEjESMRIicuAScmNTQ3PgE3NgGAAgCAgICANS8uRhQUFBRGLi8DwID8gAOA/IACABQURi4vNTUvLkYUFAACAAD/wAQAA8AAFwAaAAABIgcOAQcGFRQXHgEXFjMRMxEzETMRMzUJAgIANS8uRhQUFBRGLi81gICAgPwAAQD/AAPAFBRGLi81NS8uRhQU/gADgPyAA4CA/UABAAEAAAACAAD/wAQAA8AAFwAaAAABIgcOAQcGFRQXHgEXFjMRMxEzETMRMzUFCQEBADUvLkYUFBQURi4vNYCAgIABAP8AAQADwBQURi4vNTUvLkYUFP4AA4D8gAOAgMD/AP8AAAABAAD/zgQAA7MAYwAAASIHDgEHBhUUFx4BFxYXFjY1PAEnBiYxLgExJjYxHgExFjY3PgE3JicuAScmNTQ2Ny4BNzAWFz4BMzIWFz4BMRYGBx4BFRQHDgEHBgceARUUBhUUFjc2Nz4BNzY1NCcuAScmIwIAal1eiygoGhpdQUBMExABakISJyMnJigiXRYEEgsrKipCFBUcGQQMFUNKHkEhIUEeSkMVDAQZHBUUQyopKw4VARATTEFAXRoaKCiLXl1qA7MoKItdXmpUTU2ALy8ZBBIKCTYgF1QsHxgHAzI7BwoYIgoFDA04Ly9JKkUbCUk1AzEICQkIMQM1SQkbRSpKLy44DA0FCzAjNEwNChIEGS8wf01NVGpeXYsoKAAAAAABAAAAAQAAt9HlfV8PPPUACwQAAAAAANgVW8QAAAAA2BVbxAAA/8AEAAPAAAAACAACAAAAAAAAAAEAAAPA/8AAAAQAAAAAAAQAAAEAAAAAAAAAAAAAAAAAAABLBAAAAAAAAAAAAAAAAgAAAAQAAFUEAABVBAAAVQQAAFUEAAEABAABVgQAAKoEAAAzBAAAgAQAAFYEAACABAAAgAQAAIAEAACABAAAVQQAAFUEAABVBAABKwQAAIAEAAErBAAAVQQAAIAEAAErBAABqwQAAKsEAAAABAAA1QQAAGQEAAB1BAAA1QQAAAAEAACRBAAA4gQAAFUEAABVBAAAgAQAAGQEAADVBAAAVQQAAFUEAABVBAAAAAQAANUEAABVBAAAgAQAAIAEAADVBAAAVQQAAGsEAAEABAAAAAQAAEAEAAAABAAAQAQAAIAEAACABAAAAAQAAOsEAAAABAAAQAQAAHYEAAAABAAAfAQAAAAEAABQBAAAUAQAAAAEAACABAAAAAQAAAAEAAAAAAAAAAAKABQAHgCIAPIBXgHKAd4B7AI0AlACfgKiAtIDBgNCA3QD2gRSBHIEqAT2BQQFZAV8BYoFwgX6BjwGZgbOB3YHnggcCDIIcAkiCVoJogoqCkQKoAr0C3gLtgvoDJwMvAzcDPgNOg2IDaANrg46DnAOxA70DyQPMg9QD3gPnA/CEDoQrhDwEVARrhHsEhQSRBJ0EwQAAQAAAEsAewAJAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAA4ArgABAAAAAAABAAcAAAABAAAAAAACAAcAYAABAAAAAAADAAcANgABAAAAAAAEAAcAdQABAAAAAAAFAAsAFQABAAAAAAAGAAcASwABAAAAAAAKABoAigADAAEECQABAA4ABwADAAEECQACAA4AZwADAAEECQADAA4APQADAAEECQAEAA4AfAADAAEECQAFABYAIAADAAEECQAGAA4AUgADAAEECQAKADQApGljb21vb24AaQBjAG8AbQBvAG8AblZlcnNpb24gMS4wAFYAZQByAHMAaQBvAG4AIAAxAC4AMGljb21vb24AaQBjAG8AbQBvAG8Abmljb21vb24AaQBjAG8AbQBvAG8AblJlZ3VsYXIAUgBlAGcAdQBsAGEAcmljb21vb24AaQBjAG8AbQBvAG8AbkZvbnQgZ2VuZXJhdGVkIGJ5IEljb01vb24uAEYAbwBuAHQAIABnAGUAbgBlAHIAYQB0AGUAZAAgAGIAeQAgAEkAYwBvAE0AbwBvAG4ALgAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=);font-weight:400;font-style:normal}.index_bf-container__1HxhF [class*=\" bfi-\"],.index_bf-container__1HxhF [class^=bfi-],.index_bf-modal-root__1P_VQ [class*=\" bfi-\"],.index_bf-modal-root__1P_VQ [class^=bfi-]{font-family:braft-icons!important;speak:none;font-style:normal;font-weight:400;font-variant:normal;text-transform:none;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.index_bf-container__1HxhF .index_bfi-table__2fSIV:before,.index_bf-modal-root__1P_VQ .index_bfi-table__2fSIV:before{content:\"\\E228\"}.index_bf-container__1HxhF .index_bfi-clear_all__2OHjw:before,.index_bf-modal-root__1P_VQ .index_bfi-clear_all__2OHjw:before{content:\"\\E0B8\"}.index_bf-container__1HxhF .index_bfi-format_clear__2Z6-D:before,.index_bf-modal-root__1P_VQ .index_bfi-format_clear__2Z6-D:before{content:\"\\E239\"}.index_bf-container__1HxhF .index_bfi-hr__1-frF:before,.index_bf-modal-root__1P_VQ .index_bfi-hr__1-frF:before{content:\"\\E925\"}.index_bf-container__1HxhF .index_bfi-colorize__itEld:before,.index_bf-modal-root__1P_VQ .index_bfi-colorize__itEld:before{content:\"\\E3B8\"}.index_bf-container__1HxhF .index_bfi-crop_free__1UXYS:before,.index_bf-modal-root__1P_VQ .index_bfi-crop_free__1UXYS:before{content:\"\\E3C2\"}.index_bf-container__1HxhF .index_bfi-pause__1OwwZ:before,.index_bf-modal-root__1P_VQ .index_bfi-pause__1OwwZ:before{content:\"\\E034\"}.index_bf-container__1HxhF .index_bfi-play_arrow__1hL7J:before,.index_bf-modal-root__1P_VQ .index_bfi-play_arrow__1hL7J:before{content:\"\\E037\"}.index_bf-container__1HxhF .index_bfi-bin__h1RKN:before,.index_bf-modal-root__1P_VQ .index_bfi-bin__h1RKN:before{content:\"\\E9AC\"}.index_bf-container__1HxhF .index_bfi-replay__11NQk:before,.index_bf-modal-root__1P_VQ .index_bfi-replay__11NQk:before{content:\"\\E042\"}.index_bf-container__1HxhF .index_bfi-tune__axH8Q:before,.index_bf-modal-root__1P_VQ .index_bfi-tune__axH8Q:before{content:\"\\E429\"}.index_bf-container__1HxhF .index_bfi-close__3PhYm:before,.index_bf-modal-root__1P_VQ .index_bfi-close__3PhYm:before{content:\"\\E913\"}.index_bf-container__1HxhF .index_bfi-align-center__3WjMb:before,.index_bf-modal-root__1P_VQ .index_bfi-align-center__3WjMb:before{content:\"\\E028\"}.index_bf-container__1HxhF .index_bfi-align-justify__1QkRU:before,.index_bf-modal-root__1P_VQ .index_bfi-align-justify__1QkRU:before{content:\"\\E026\"}.index_bf-container__1HxhF .index_bfi-align-left__1oX7J:before,.index_bf-modal-root__1P_VQ .index_bfi-align-left__1oX7J:before{content:\"\\E027\"}.index_bf-container__1HxhF .index_bfi-align-right__1eM5M:before,.index_bf-modal-root__1P_VQ .index_bfi-align-right__1eM5M:before{content:\"\\E029\"}.index_bf-container__1HxhF .index_bfi-image-right__2H-ST:before,.index_bf-modal-root__1P_VQ .index_bfi-image-right__2H-ST:before{content:\"\\E914\"}.index_bf-container__1HxhF .index_bfi-image-left__zW8ok:before,.index_bf-modal-root__1P_VQ .index_bfi-image-left__zW8ok:before{content:\"\\E91E\"}.index_bf-container__1HxhF .index_bfi-music__1XtpY:before,.index_bf-modal-root__1P_VQ .index_bfi-music__1XtpY:before{content:\"\\E90E\"}.index_bf-container__1HxhF .index_bfi-camera__2X5Zb:before,.index_bf-modal-root__1P_VQ .index_bfi-camera__2X5Zb:before{content:\"\\E911\"}.index_bf-container__1HxhF .index_bfi-copy__16C-6:before,.index_bf-modal-root__1P_VQ .index_bfi-copy__16C-6:before{content:\"\\E92C\"}.index_bf-container__1HxhF .index_bfi-file-text__12Obf:before,.index_bf-modal-root__1P_VQ .index_bfi-file-text__12Obf:before{content:\"\\E926\"}.index_bf-container__1HxhF .index_bfi-film__2C48n:before,.index_bf-modal-root__1P_VQ .index_bfi-film__2C48n:before{content:\"\\E91C\"}.index_bf-container__1HxhF .index_bfi-github__3XePr:before,.index_bf-modal-root__1P_VQ .index_bfi-github__3XePr:before{content:\"\\EAB0\"}.index_bf-container__1HxhF .index_bfi-ltr__rDkrQ:before,.index_bf-modal-root__1P_VQ .index_bfi-ltr__rDkrQ:before{content:\"\\EA74\"}.index_bf-container__1HxhF .index_bfi-page-break__DhcNp:before,.index_bf-modal-root__1P_VQ .index_bfi-page-break__DhcNp:before{content:\"\\EA68\"}.index_bf-container__1HxhF .index_bfi-pagebreak__m3gAm:before,.index_bf-modal-root__1P_VQ .index_bfi-pagebreak__m3gAm:before{content:\"\\EA6E\"}.index_bf-container__1HxhF .index_bfi-paint-format__pjAiv:before,.index_bf-modal-root__1P_VQ .index_bfi-paint-format__pjAiv:before{content:\"\\E90C\"}.index_bf-container__1HxhF .index_bfi-paste__G7Hrh:before,.index_bf-modal-root__1P_VQ .index_bfi-paste__G7Hrh:before{content:\"\\E92D\"}.index_bf-container__1HxhF .index_bfi-pilcrow__4zJYM:before,.index_bf-modal-root__1P_VQ .index_bfi-pilcrow__4zJYM:before{content:\"\\EA73\"}.index_bf-container__1HxhF .index_bfi-pushpin__3PUoC:before,.index_bf-modal-root__1P_VQ .index_bfi-pushpin__3PUoC:before{content:\"\\E946\"}.index_bf-container__1HxhF .index_bfi-redo__1Q-LG:before,.index_bf-modal-root__1P_VQ .index_bfi-redo__1Q-LG:before{content:\"\\E968\"}.index_bf-container__1HxhF .index_bfi-rtl__sPVOR:before,.index_bf-modal-root__1P_VQ .index_bfi-rtl__sPVOR:before{content:\"\\EA75\"}.index_bf-container__1HxhF .index_bfi-spinner__Dek6M:before,.index_bf-modal-root__1P_VQ .index_bfi-spinner__Dek6M:before{content:\"\\E980\"}.index_bf-container__1HxhF .index_bfi-subscript__kYu6m:before,.index_bf-modal-root__1P_VQ .index_bfi-subscript__kYu6m:before{content:\"\\EA6C\"}.index_bf-container__1HxhF .index_bfi-superscript__3qvwy:before,.index_bf-modal-root__1P_VQ .index_bfi-superscript__3qvwy:before{content:\"\\EA6B\"}.index_bf-container__1HxhF .index_bfi-undo___pDce:before,.index_bf-modal-root__1P_VQ .index_bfi-undo___pDce:before{content:\"\\E967\"}.index_bf-container__1HxhF .index_bfi-media__3Ijxb:before,.index_bf-modal-root__1P_VQ .index_bfi-media__3Ijxb:before{content:\"\\E90F\"}.index_bf-container__1HxhF .index_bfi-add__LigZq:before,.index_bf-modal-root__1P_VQ .index_bfi-add__LigZq:before{content:\"\\E918\"}.index_bf-container__1HxhF .index_bfi-bold__dn9AC:before,.index_bf-modal-root__1P_VQ .index_bfi-bold__dn9AC:before{content:\"\\E904\"}.index_bf-container__1HxhF .index_bfi-code__3tDKj:before,.index_bf-modal-root__1P_VQ .index_bfi-code__3tDKj:before{content:\"\\E903\"}.index_bf-container__1HxhF .index_bfi-done__J_3zM:before,.index_bf-modal-root__1P_VQ .index_bfi-done__J_3zM:before{content:\"\\E912\"}.index_bf-container__1HxhF .index_bfi-drop-down__2-Azn:before,.index_bf-modal-root__1P_VQ .index_bfi-drop-down__2-Azn:before{content:\"\\E906\"}.index_bf-container__1HxhF .index_bfi-drop-up__f9cHI:before,.index_bf-modal-root__1P_VQ .index_bfi-drop-up__f9cHI:before{content:\"\\E909\"}.index_bf-container__1HxhF .index_bfi-emoji__37yM6:before,.index_bf-modal-root__1P_VQ .index_bfi-emoji__37yM6:before{content:\"\\E91B\"}.index_bf-container__1HxhF .index_bfi-font-size__1cbPf:before,.index_bf-modal-root__1P_VQ .index_bfi-font-size__1cbPf:before{content:\"\\E920\"}.index_bf-container__1HxhF .index_bfi-fullscreen__2txWy:before,.index_bf-modal-root__1P_VQ .index_bfi-fullscreen__2txWy:before{content:\"\\E910\"}.index_bf-container__1HxhF .index_bfi-fullscreen-exit__33svQ:before,.index_bf-modal-root__1P_VQ .index_bfi-fullscreen-exit__33svQ:before{content:\"\\E90D\"}.index_bf-container__1HxhF .index_bfi-help__xa9vi:before,.index_bf-modal-root__1P_VQ .index_bfi-help__xa9vi:before{content:\"\\E902\"}.index_bf-container__1HxhF .index_bfi-indent-decrease__1CtRw:before,.index_bf-modal-root__1P_VQ .index_bfi-indent-decrease__1CtRw:before{content:\"\\E92F\"}.index_bf-container__1HxhF .index_bfi-indent-increase__2kSOy:before,.index_bf-modal-root__1P_VQ .index_bfi-indent-increase__2kSOy:before{content:\"\\E92E\"}.index_bf-container__1HxhF .index_bfi-info__3gDtD:before,.index_bf-modal-root__1P_VQ .index_bfi-info__3gDtD:before{content:\"\\E901\"}.index_bf-container__1HxhF .index_bfi-italic__1ENXj:before,.index_bf-modal-root__1P_VQ .index_bfi-italic__1ENXj:before{content:\"\\E924\"}.index_bf-container__1HxhF .index_bfi-link__3-0Rp:before,.index_bf-modal-root__1P_VQ .index_bfi-link__3-0Rp:before{content:\"\\E91A\"}.index_bf-container__1HxhF .index_bfi-link-off__2xzYa:before,.index_bf-modal-root__1P_VQ .index_bfi-link-off__2xzYa:before{content:\"\\E919\"}.index_bf-container__1HxhF .index_bfi-list__3GI0k:before,.index_bf-modal-root__1P_VQ .index_bfi-list__3GI0k:before{content:\"\\E923\"}.index_bf-container__1HxhF .index_bfi-list-numbered__U2An6:before,.index_bf-modal-root__1P_VQ .index_bfi-list-numbered__U2An6:before{content:\"\\E922\"}.index_bf-container__1HxhF .index_bfi-menu__YEtEG:before,.index_bf-modal-root__1P_VQ .index_bfi-menu__YEtEG:before{content:\"\\E908\"}.index_bf-container__1HxhF .index_bfi-more-horiz__38Kqk:before,.index_bf-modal-root__1P_VQ .index_bfi-more-horiz__38Kqk:before{content:\"\\E90B\"}.index_bf-container__1HxhF .index_bfi-more-vert__1Xpoy:before,.index_bf-modal-root__1P_VQ .index_bfi-more-vert__1Xpoy:before{content:\"\\E90A\"}.index_bf-container__1HxhF .index_bfi-not-disturb__2wwfA:before,.index_bf-modal-root__1P_VQ .index_bfi-not-disturb__2wwfA:before{content:\"\\E907\"}.index_bf-container__1HxhF .index_bfi-print__1Vdsh:before,.index_bf-modal-root__1P_VQ .index_bfi-print__1Vdsh:before{content:\"\\E915\"}.index_bf-container__1HxhF .index_bfi-quote__1xD3O:before,.index_bf-modal-root__1P_VQ .index_bfi-quote__1xD3O:before{content:\"\\E921\"}.index_bf-container__1HxhF .index_bfi-search__2G21G:before,.index_bf-modal-root__1P_VQ .index_bfi-search__2G21G:before{content:\"\\E916\"}.index_bf-container__1HxhF .index_bfi-settingsx__5qqai:before,.index_bf-modal-root__1P_VQ .index_bfi-settingsx__5qqai:before{content:\"\\E917\"}.index_bf-container__1HxhF .index_bfi-share__LmF7D:before,.index_bf-modal-root__1P_VQ .index_bfi-share__LmF7D:before{content:\"\\E905\"}.index_bf-container__1HxhF .index_bfi-share-square__sA_aV:before,.index_bf-modal-root__1P_VQ .index_bfi-share-square__sA_aV:before{content:\"\\E900\"}.index_bf-container__1HxhF .index_bfi-strikethrough__3Oij6:before,.index_bf-modal-root__1P_VQ .index_bfi-strikethrough__3Oij6:before{content:\"\\E91F\"}.index_bf-container__1HxhF .index_bfi-text-color__1p69s .index_path1__1i_Zc:before,.index_bf-modal-root__1P_VQ .index_bfi-text-color__1p69s .index_path1__1i_Zc:before{font-family:braft-icons!important;content:\"\\E930\";opacity:.36}.index_bf-container__1HxhF .index_bfi-text-color__1p69s .index_path2__DFG_e:before,.index_bf-modal-root__1P_VQ .index_bfi-text-color__1p69s .index_path2__DFG_e:before{font-family:braft-icons!important;content:\"\\E931\";margin-left:-1em}.index_bf-container__1HxhF .index_bfi-underlined__oAOe6:before,.index_bf-modal-root__1P_VQ .index_bfi-underlined__oAOe6:before{content:\"\\E91D\"}.index_bf-content__5lf-j{height:500px;padding-bottom:10px;overflow:auto;font-size:16px}.index_bf-content__5lf-j img{-webkit-user-select:none;user-select:none}.index_bf-content__5lf-j *{line-height:normal}.index_bf-container__1HxhF{position:relative;height:100%;padding:0}.index_bf-container__1HxhF.index_disabled__KFBp_{pointer-events:none;opacity:.7;filter:grayscale(70%)}.index_bf-container__1HxhF.index_read-only__3HgNB .index_bf-controlbar__ej8fA{pointer-events:none}.index_bf-container__1HxhF.index_read-only__3HgNB .index_bf-image__1MXDI img:hover{outline:none}.index_bf-container__1HxhF.index_read-only__3HgNB .index_bf-hr__39L4E{pointer-events:none}.index_bf-container__1HxhF.index_fullscreen__2MrQv{position:fixed;display:flex;flex-direction:column;z-index:99999;top:0;right:0;bottom:0;left:0;background-color:#fff;height:100%!important}.index_bf-container__1HxhF.index_fullscreen__2MrQv .index_bf-content__5lf-j{flex-grow:1;height:auto}.index_bf-container__1HxhF .index_input-group__1Y0_d{display:block}.index_bf-container__1HxhF .index_input-group__1Y0_d input{box-sizing:border-box;width:100%;height:36px;padding:0 15px;font-size:14px}.index_bf-container__1HxhF .index_pull-left__33hHK{float:left}.index_bf-container__1HxhF .index_pull-right__22QW0{float:right}.index_bf-container__1HxhF button{line-height:normal}.index_bf-container__1HxhF button.index_default__11aE1,.index_bf-container__1HxhF button.index_ghost__q2A8s,.index_bf-container__1HxhF button.index_primary__1ex4f{height:32px;padding:0 20px;color:#fff;font-size:12px}.index_bf-container__1HxhF button.index_default__11aE1{background-color:hsla(0,0%,100%,.15);border:none}.index_bf-container__1HxhF button.index_default__11aE1:hover{background-color:hsla(0,0%,100%,.1)}.index_bf-container__1HxhF button.index_ghost__q2A8s{background-color:transparent;border:none;box-shadow:inset 0 0 0 .5px hsla(0,0%,100%,.5)}.index_bf-container__1HxhF button.index_ghost__q2A8s:hover{box-shadow:inset 0 0 0 .5px hsla(0,0%,100%,.7)}.index_bf-container__1HxhF button.index_primary__1ex4f{background-color:#3498db;border:none;color:#fff}.index_bf-container__1HxhF button.index_primary__1ex4f:hover{background-color:#2084c7}.index_bf-container__1HxhF .index_public-DraftEditorPlaceholder-root__1T6lJ{top:15px;left:15px;font-size:16px;pointer-events:none}.index_bf-container__1HxhF .index_DraftEditor-editorContainer__1FR0o{box-sizing:border-box;border:none}.index_bf-container__1HxhF .index_DraftEditor-root__mlfOI,.index_bf-container__1HxhF .index_public-DraftEditor-content__T2mZu{height:100%}.index_bf-container__1HxhF .index_public-DraftEditor-content__T2mZu{box-sizing:border-box;padding:15px;word-wrap:break-word;word-break:break-all}.index_bf-container__1HxhF .index_public-DraftEditor-content__T2mZu>div{padding-bottom:20px}.index_bf-container__1HxhF .index_public-DraftEditor-content__T2mZu .index_braft-link__1ZeMr{color:#4078c0}.index_bf-container__1HxhF .index_public-DraftEditor-content__T2mZu blockquote{margin:0 0 10px;padding:15px 20px;background-color:#f1f2f3;border-left:5px solid #ccc;color:#666;font-style:italic}.index_bf-container__1HxhF .index_public-DraftEditor-content__T2mZu pre{max-width:100%;max-height:100%;margin:10px 0;padding:15px;overflow:auto;background-color:#f1f2f3;border-radius:3px;color:#666;font-family:monospace;font-size:14px;font-weight:400;line-height:16px;word-wrap:break-word;white-space:pre-wrap}.index_bf-container__1HxhF .index_public-DraftEditor-content__T2mZu pre pre{margin:0;padding:0}.index_bf-container__1HxhF .index_bfa-left__3CWAj,.index_bf-container__1HxhF .index_bfa-left__3CWAj .index_public-DraftStyleDefault-ltr__3qMdW{text-align:left}.index_bf-container__1HxhF .index_bfa-right__Sy5sn,.index_bf-container__1HxhF .index_bfa-right__Sy5sn .index_public-DraftStyleDefault-ltr__3qMdW{text-align:right}.index_bf-container__1HxhF .index_bfa-center__3iBxk,.index_bf-container__1HxhF .index_bfa-center__3iBxk .index_public-DraftStyleDefault-ltr__3qMdW{text-align:center}.index_bf-container__1HxhF .index_bfa-justify__C4cm4,.index_bf-container__1HxhF .index_bfa-justify__C4cm4 .index_public-DraftStyleDefault-ltr__3qMdW{text-align:justify}.index_bf-container__1HxhF .index_bfa-center__3iBxk>div,.index_bf-container__1HxhF .index_bfa-justify__C4cm4>div,.index_bf-container__1HxhF .index_bfa-left__3CWAj>div,.index_bf-container__1HxhF .index_bfa-right__Sy5sn>div{display:inline-block}.index_bf-container__1HxhF .index_bff-left__pCNho:hover,.index_bf-container__1HxhF .index_bff-right__vpxtc:hover{z-index:2}.index_bf-container__1HxhF .index_bff-left__pCNho{position:relative;z-index:1;float:left;margin:0 10px 0 0}.index_bf-container__1HxhF .index_bff-right__vpxtc{position:relative;z-index:1;float:right;margin:0 0 0 10px}.index_bf-container__1HxhF .index_bftd-1__382qR{text-indent:2em;display:initial}.index_bf-container__1HxhF .index_bftd-2__11te-{text-indent:4em;display:initial}.index_bf-container__1HxhF .index_bftd-3__2BZeG{text-indent:6em;display:initial}.index_bf-container__1HxhF .index_bftd-4__4c1Sw{text-indent:8em;display:initial}.index_bf-container__1HxhF .index_bftd-5__34mlP{text-indent:10em;display:initial}.index_bf-container__1HxhF .index_bftd-6__1bsox{text-indent:12em;display:initial}.index_bf-container__1HxhF .index_bf-image__1MXDI,.index_bf-container__1HxhF .index_bf-media__33Dic{position:relative}.index_bf-container__1HxhF .index_bf-image__1MXDI img{display:block;max-width:100%;font-size:0;resize:both;outline-offset:1px}.index_bf-container__1HxhF .index_bf-image__1MXDI img:hover{outline:1px solid #3498db}.index_bf-container__1HxhF .index_bf-media-toolbar__28qi5{position:absolute;z-index:3;bottom:15px;left:50%;width:auto;background-color:#21242a;border-radius:2px;font-weight:400;text-align:center;white-space:nowrap;transform:translateX(-50%);box-shadow:0 5px 15px rgba(0,0,0,.2);-webkit-user-select:none;user-select:none}.index_bf-container__1HxhF .index_bf-media-toolbar__28qi5 .index_bf-media-toolbar-arrow__M3uMb,.index_bf-container__1HxhF .index_bf-media-toolbar__28qi5:before{position:absolute;bottom:-10px;left:50%;display:block;border:5px solid transparent;border-top-color:#21242a;content:\"\";transform:translateX(-5px)}.index_bf-container__1HxhF .index_bf-media-toolbar__28qi5 a{display:inline-block;min-width:40px;height:40px;color:hsla(0,0%,100%,.5);font-family:braft-icons!important;font-size:18px;font-weight:400;line-height:40px;text-align:center;text-decoration:none;text-transform:uppercase;cursor:pointer}.index_bf-container__1HxhF .index_bf-media-toolbar__28qi5 a:hover{color:#fff}.index_bf-container__1HxhF .index_bf-media-toolbar__28qi5 a:first-child{border-radius:2px 0 0 2px}.index_bf-container__1HxhF .index_bf-media-toolbar__28qi5 a:last-child{border-radius:0 2px 2px 0}.index_bf-container__1HxhF .index_bf-media-toolbar__28qi5 a.index_active__3_mlp{color:#3498db}.index_bf-video-player__3Eqxs video{display:block;width:640px;max-width:80vw;height:auto;margin:0 10px 10px;object-fit:contain}.index_bf-audio-player__67sKu audio{width:480px;max-width:80vw;margin:0 10px 10px}.index_bf-player-holder__1k4R5{position:relative;height:240px;overflow:hidden;background-color:#21242a;border-radius:3px}.index_bf-player-holder__1k4R5 .index_icon-badge__35ukN{position:absolute;z-index:2;top:0;left:0;height:30px;padding:0 15px;border-radius:0 0 3px 0;color:#fff;background-color:hsla(0,0%,100%,.1)}.index_bf-player-holder__1k4R5 .index_icon-badge__35ukN i,.index_bf-player-holder__1k4R5 .index_icon-badge__35ukN span{display:block;float:left;line-height:30px}.index_bf-player-holder__1k4R5 .index_icon-badge__35ukN span{margin-left:5px;font-size:12px}.index_bf-player-holder__1k4R5 .index_button-remove__cTw4D{position:absolute;z-index:2;top:5px;right:5px;width:40px;height:40px;background-color:transparent;border:none;border-radius:50%;outline:none;color:#fff;font-size:24px;text-align:center;cursor:pointer}.index_bf-player-holder__1k4R5 .index_button-remove__cTw4D:hover{color:#e74c3c}.index_bf-player-holder__1k4R5 .index_button-play__1GpMM{position:relative;z-index:2;display:block;width:80px;height:80px;margin:40px auto 20px;background-color:rgba(0,0,0,.7);border:none;border-radius:50%;outline:none;color:#fff;font-size:48px;line-height:80px;text-align:center;backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);cursor:pointer}.index_bf-player-holder__1k4R5 .index_button-play__1GpMM:hover{background-color:#3498db}.index_bf-player-holder__1k4R5 .index_bf-name__3FBAI{position:relative;z-index:2;margin:0;color:#fff;font-size:14px;font-weight:500;text-align:center}.index_bf-player-holder__1k4R5 .index_bf-url__1di3g{position:relative;z-index:2;width:70%;margin:10px auto;color:hsla(0,0%,100%,.5);font-size:12px;font-weight:400;text-align:center}.index_bf-player-holder__1k4R5 .index_bf-poster__drCvq{position:absolute;top:0;left:0;width:100%;height:100%;background-repeat:no-repeat;background-position:50% 50%;background-size:cover;opacity:.3}.index_bf-modal__23mEu{position:fixed;z-index:99999;top:0;left:0;width:100%;height:100%}.index_bf-modal__23mEu button{outline:none}.index_bf-modal-mask__3MKbg{position:absolute;z-index:1;top:0;left:0;width:100%;height:100%;background-color:rgba(0,0,0,.1);opacity:0;transition:opacity .2s}.index_bf-modal-content__1RScF{position:absolute;z-index:2;top:45%;left:50%;max-width:95%;background-color:#fff;border-radius:2px;box-shadow:0 15px 30px rgba(0,0,0,.1);opacity:0;transform:translate(-50%,-40%);transition:transform .2s,opacity .2s}.index_bf-modal-header__3jeX-{height:50px}.index_bf-modal-caption__2z9hD{float:left;margin:0;padding:0 15px;color:#999;font-size:14px;font-weight:400;line-height:50px}.index_bf-modal-close-button__13UMv{float:right;width:50px;height:50px;background-color:transparent;border:none;color:#ccc;font-size:18px;cursor:pointer}.index_bf-modal-close-button__13UMv:hover{color:#e74c3c}.index_bf-modal-body__3MjbZ{overflow:auto}.index_bf-modal-footer__3Pc0k{min-height:15px;padding:0 15px;overflow:hidden}.index_bf-modal-addon-text__3dQDG{float:left;color:#999;font-size:12px;line-height:60px}.index_bf-modal-buttons__2IuAO{float:right}.index_bf-modal-cancel__30ePe,.index_bf-modal-confirm__3woeJ{height:36px;margin:12px 0 12px 15px;padding:0 30px;border:none;border-radius:2px;font-size:12px;font-weight:700;cursor:pointer}.index_bf-modal-cancel__30ePe{background-color:#e8e9ea;color:#999}.index_bf-modal-cancel__30ePe:hover{background-color:#d8d9da}.index_bf-modal-confirm__3woeJ{background-color:#3498db;color:#fff}.index_bf-modal-confirm__3woeJ:hover{background-color:#2084c7}.index_bf-modal-confirm__3woeJ.index_disabled__KFBp_{opacity:.3;pointer-events:none;filter:grayscale(.4)}.index_bf-modal-root__1P_VQ.index_active__3_mlp .index_bf-modal-mask__3MKbg{opacity:1}.index_bf-modal-root__1P_VQ.index_active__3_mlp .index_bf-modal-content__1RScF{opacity:1;transform:translate(-50%,-50%)}.index_bf-content__5lf-j .index_bf-hr__39L4E{position:relative;box-sizing:content-box;height:15px;padding-top:15px;text-align:center}.index_bf-content__5lf-j .index_bf-hr__39L4E:before{display:block;height:1px;background-color:rgba(0,0,0,.1);content:\"\"}.index_bf-content__5lf-j .index_bf-hr__39L4E:hover:before{background-color:rgba(0,0,0,.3)}.index_bf-content__5lf-j .index_bf-hr__39L4E:hover .index_bf-media-toolbar__28qi5{display:block}.index_bf-content__5lf-j .index_bf-hr__39L4E .index_bf-media-toolbar__28qi5{display:none}.index_bf-image-link-editor__L5XLU,.index_bf-image-size-editor__3DAVi{padding-bottom:1px;overflow:hidden;border-radius:2px 2px 0 0;box-shadow:inset 0 -1px 0 0 hsla(0,0%,100%,.1)}.index_bf-image-link-editor__L5XLU .index_editor-input-group__1hcX3,.index_bf-image-size-editor__3DAVi .index_editor-input-group__1hcX3{width:300px;margin:8px 10px;overflow:hidden}.index_bf-image-link-editor__L5XLU input,.index_bf-image-size-editor__3DAVi input{display:block;float:left;box-sizing:content-box;height:32px;margin:0 5px 0 0;padding:0 10px;background-color:hsla(0,0%,100%,.1);border:none;border-radius:2px;outline:none;box-shadow:inset 0 0 0 1px hsla(0,0%,100%,.1);color:#fff;font-weight:700}.index_bf-image-link-editor__L5XLU input:hover,.index_bf-image-size-editor__3DAVi input:hover{box-shadow:inset 0 0 0 1px rgba(52,152,219,.5)}.index_bf-image-link-editor__L5XLU input:focus,.index_bf-image-size-editor__3DAVi input:focus{box-shadow:inset 0 0 0 1px #3498db}.index_bf-image-link-editor__L5XLU button,.index_bf-image-size-editor__3DAVi button{float:left;width:90px;height:32px;margin:0;padding:0 20px;background-color:#3498db;border:none;color:#fff;font-size:12px;border-radius:2px;cursor:pointer}.index_bf-image-link-editor__L5XLU button:hover,.index_bf-image-size-editor__3DAVi button:hover{background-color:#2084c7}.index_bf-image-size-editor__3DAVi input{width:80px}.index_bf-image-link-editor__L5XLU input{width:185px}.index_bf-image-link-editor__L5XLU .index_switch-group__3nsEF{height:16px;margin:10px}.index_bf-image-link-editor__L5XLU .index_switch-group__3nsEF .index_bf-switch__1LPr-{float:left}.index_bf-image-link-editor__L5XLU .index_switch-group__3nsEF label{float:left;margin-left:15px;color:#999;font-size:12px;line-height:16px}.index_bf-content__5lf-j .index_bf-image__1MXDI{position:relative}.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-csize-icon__13EM-{position:absolute;z-index:2;width:10px;height:10px;background-color:rgba(52,152,219,.3)}.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-csize-icon__13EM-.index_right-bottom__2jlUD{right:0;bottom:0;cursor:se-resize}.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-csize-icon__13EM-.index_left-bottom__1H0sb{left:0;bottom:0;cursor:sw-resize}.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-pre-csize__2lLOX{position:absolute;z-index:1;background:transparent}.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-pre-csize__2lLOX.index_rightbottom__S1Zly{left:0;top:0;border:1px dashed #00bfff}.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-pre-csize__2lLOX.index_leftbottom__wbQiO{right:0;top:0;border:1px dashed #00bfff}.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-media-toolbar__28qi5:before{visibility:hidden}.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-media-toolbar__28qi5[data-align=center] [data-align=center],.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-media-toolbar__28qi5[data-align=left] [data-align=left],.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-media-toolbar__28qi5[data-align=right] [data-align=right],.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-media-toolbar__28qi5[data-float=left] [data-float=left],.index_bf-content__5lf-j .index_bf-image__1MXDI .index_bf-media-toolbar__28qi5[data-float=right] [data-float=right]{color:#3498db}.index_headings-dropdown__1KzQP{min-width:110px}.index_headings-dropdown__1KzQP .index_menu__10kCt{width:200px;overflow:hidden}.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov-{padding:15px 20px;text-align:left;line-height:normal}.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h1,.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h2,.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h3,.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h4,.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h5,.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h6{margin:0;padding:0;color:inherit}.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h1{font-size:28px}.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h2{font-size:24px}.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h3{font-size:20px}.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h4{font-size:16px}.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h5{font-size:14px}.index_headings-dropdown__1KzQP .index_menu__10kCt .index_menu-item__2_Ov- h6{font-size:12px}.index_bf-link-editor__w7aBK{width:360px;padding-top:25px}.index_bf-link-editor__w7aBK .index_input-group__1Y0_d{margin:0 15px 8px}.index_bf-link-editor__w7aBK .index_input-group__1Y0_d input{background-color:hsla(0,0%,100%,.07);border:none;border-radius:2px;box-shadow:inset 0 0 0 1px hsla(0,0%,100%,.1);color:#fff;font-weight:700}.index_bf-link-editor__w7aBK .index_input-group__1Y0_d input:hover{box-shadow:inset 0 0 0 1px rgba(52,152,219,.5)}.index_bf-link-editor__w7aBK .index_input-group__1Y0_d input:focus{box-shadow:inset 0 0 0 1px #3498db}.index_bf-link-editor__w7aBK .index_input-group__1Y0_d input:disabled{color:hsla(0,0%,100%,.7);box-shadow:none}.index_bf-link-editor__w7aBK .index_switch-group__3nsEF{height:16px;margin:15px}.index_bf-link-editor__w7aBK .index_switch-group__3nsEF .index_bf-switch__1LPr-{float:left}.index_bf-link-editor__w7aBK .index_switch-group__3nsEF label{float:left;margin-left:15px;color:#999;font-size:12px;line-height:16px}.index_bf-link-editor__w7aBK .index_buttons__3QT_I{box-sizing:content-box;height:32px;margin-top:20px;padding:15px;overflow:hidden;box-shadow:inset 0 1px 0 0 hsla(0,0%,100%,.1)}.index_bf-link-editor__w7aBK .index_buttons__3QT_I .index_button-remove-link__2004W{color:#999;font-size:12px;line-height:32px;cursor:pointer}.index_bf-link-editor__w7aBK .index_buttons__3QT_I .index_button-remove-link__2004W:hover{color:#e74c3c}.index_bf-link-editor__w7aBK .index_buttons__3QT_I .index_button-remove-link__2004W i{margin-right:5px;font-size:16px}.index_bf-link-editor__w7aBK .index_buttons__3QT_I .index_button-remove-link__2004W i,.index_bf-link-editor__w7aBK .index_buttons__3QT_I .index_button-remove-link__2004W span{display:block;float:left;line-height:32px}.index_bf-link-editor__w7aBK .index_buttons__3QT_I button{margin-left:10px;border-radius:2px;font-weight:700;cursor:pointer}.index_bf-dropdown__zgKp1{position:relative;width:auto;height:36px;margin:0}.index_bf-dropdown__zgKp1.index_disabled__KFBp_{pointer-events:none;opacity:.3}.index_bf-dropdown__zgKp1.index_light-theme__iYoel .index_dropdown-content__2HerW{border:1px solid #ccc}.index_bf-dropdown__zgKp1.index_light-theme__iYoel .index_dropdown-content__2HerW .index_dropdown-arrow__3KWgU{background-color:#fff;border:1px solid #ccc}.index_bf-dropdown__zgKp1.index_light-theme__iYoel .index_dropdown-content__2HerW .index_dropdown-content-inner__5r4YN{background-color:#fff}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW{box-sizing:content-box;position:absolute;z-index:10;top:100%;left:50%;visibility:hidden;float:left;width:auto;min-width:100%;margin-top:9px;border-radius:2px;box-shadow:0 5px 15px rgba(0,0,0,.2);opacity:0;cursor:default;transform:translate(-50%,20px);transition:.2s}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW ::-webkit-scrollbar-track{background-color:transparent}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW ::-webkit-scrollbar{width:4px;background-color:transparent;border-radius:2px}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW ::-webkit-scrollbar-thumb{background-color:hsla(0,0%,100%,.3);border-radius:2px}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW .index_dropdown-arrow__3KWgU{position:absolute;z-index:1;top:-3px;left:50%;width:10px;height:10px;background-color:#21242a;transform:translateX(-50%) rotate(45deg);transition:margin .2s}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW .index_dropdown-arrow__3KWgU.index_active__3_mlp{background-color:#3498db}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW .index_menu__10kCt{list-style:none;margin:0;padding:0;overflow:hidden;border-radius:2px}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW .index_menu-item__2_Ov-{display:block;list-style:none;margin:0;font-size:16px;cursor:pointer}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW .index_menu-item__2_Ov-:hover{background-color:rgba(0,0,0,.1)}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW .index_menu-item__2_Ov-.index_active__3_mlp{background-color:#3498db;color:#fff}.index_bf-dropdown__zgKp1 .index_dropdown-content__2HerW .index_menu-item__2_Ov-:not(.index_active__3_mlp){color:hsla(0,0%,100%,.6);box-shadow:inset 0 -1px 0 0 hsla(0,0%,100%,.1)}.index_bf-dropdown__zgKp1 .index_dropdown-content-inner__5r4YN{position:relative;z-index:2;overflow:auto;background-color:#21242a;border-radius:2px}.index_bf-dropdown__zgKp1 .index_dropdown-handler__1xChS{position:relative;display:block;width:100%;height:36px;background-color:transparent;border:none;color:#6a6f7b;cursor:pointer}.index_bf-dropdown__zgKp1 .index_dropdown-handler__1xChS:hover{background-color:rgba(0,0,0,.05)}.index_bf-dropdown__zgKp1 .index_dropdown-handler__1xChS *{display:inline;padding:0;font-size:inherit;font-weight:400}.index_bf-dropdown__zgKp1 .index_dropdown-handler__1xChS>span{float:left;padding:0 10px;font-size:14px;line-height:36px;pointer-events:none}.index_bf-dropdown__zgKp1 .index_dropdown-handler__1xChS>span i{display:block;height:36px;font-size:16px;line-height:36px;text-align:center}.index_bf-dropdown__zgKp1 .index_dropdown-handler__1xChS .index_bfi-drop-down__2-Azn{float:right;width:30px;height:36px;font-size:16px;line-height:36px;text-align:center;pointer-events:none}.index_bf-dropdown__zgKp1.index_active__3_mlp .index_dropdown-handler__1xChS{background-color:rgba(0,0,0,.05)}.index_bf-dropdown__zgKp1.index_active__3_mlp .index_dropdown-content__2HerW{visibility:visible;opacity:1;transform:translate(-50%)}.index_text-color-dropdown__pnJCI.index_light-theme__iYoel .index_bf-color-switch-buttons__R4l-y button{border-bottom:1px solid #ccc;color:#616569}.index_text-color-dropdown__pnJCI.index_light-theme__iYoel .index_bf-color-switch-buttons__R4l-y button.index_active__3_mlp{border-bottom-color:#3498db;color:#3498db}.index_text-color-dropdown__pnJCI button.index_dropdown-handler__1xChS span{width:36px;padding:0;overflow:hidden;border-radius:2px}.index_text-color-dropdown__pnJCI .index_bf-text-color-picker-wrap__2xWAh{overflow:hidden}.index_text-color-dropdown__pnJCI .index_bf-color-switch-buttons__R4l-y{height:36px}.index_text-color-dropdown__pnJCI .index_bf-color-switch-buttons__R4l-y button{float:left;width:50%;height:36px;background-color:transparent;border:none;border-bottom:1px solid hsla(0,0%,100%,.1);color:hsla(0,0%,100%,.5);font-size:12px;font-weight:400;text-transform:uppercase;cursor:pointer}.index_text-color-dropdown__pnJCI .index_bf-color-switch-buttons__R4l-y button.index_active__3_mlp{border-bottom-color:#3498db;color:#3498db}.index_bf-colors__2Jog3{box-sizing:content-box;list-style:none;width:240px;margin:0;padding:15px;overflow:hidden}.index_bf-colors__2Jog3 li{box-sizing:content-box;display:block;float:left;width:24px;height:24px;margin:5px;padding:0;background-color:currentColor;border:3px solid transparent;border-radius:50%;cursor:pointer;transition:transform .2s}.index_bf-colors__2Jog3 li:hover{transform:scale(1.3)}.index_bf-colors__2Jog3 li.index_active__3_mlp{box-shadow:0 0 0 2px #3498db}.index_bf-font-size-dropdown__38pES{min-width:95px}.index_bf-font-sizes__2rRGp{box-sizing:content-box;width:210px;list-style:none;margin:0;padding:5px;overflow:hidden}.index_bf-font-sizes__2rRGp li{display:block;float:left;width:60px;height:30px;background-color:hsla(0,0%,100%,.1);border-radius:2px;margin:5px;color:#fff;font-size:12px;line-height:30px;text-align:center;text-transform:uppercase;cursor:pointer}.index_bf-font-sizes__2rRGp li:hover{background-color:hsla(0,0%,100%,.2)}.index_bf-font-sizes__2rRGp li.index_active__3_mlp{background-color:#3498db}.index_font-family-dropdown__rYXD5{min-width:120px}.index_font-family-dropdown__rYXD5 .index_dropdown-content__2HerW{width:180px}.index_font-family-dropdown__rYXD5 .index_menu-item__2_Ov-{padding:12px 15px}.index_bf-line-height-dropdown__ee0Ld{min-width:95px}.index_bf-line-heights__2Oa0w{box-sizing:content-box;width:210px;list-style:none;margin:0;padding:5px;overflow:hidden}.index_bf-line-heights__2Oa0w li{display:block;float:left;width:60px;height:30px;background-color:hsla(0,0%,100%,.1);border-radius:2px;margin:5px;color:#fff;font-size:12px;line-height:30px;text-align:center;text-transform:uppercase;cursor:pointer}.index_bf-line-heights__2Oa0w li:hover{background-color:hsla(0,0%,100%,.2)}.index_bf-line-heights__2Oa0w li.index_active__3_mlp{background-color:#3498db}.index_bf-letter-spacing-dropdown__1t21I{min-width:95px}.index_bf-letter-spacings__MYcL5{box-sizing:content-box;width:210px;list-style:none;margin:0;padding:5px;overflow:hidden}.index_bf-letter-spacings__MYcL5 li{display:block;float:left;width:60px;height:30px;background-color:hsla(0,0%,100%,.1);border-radius:2px;margin:5px;color:#fff;font-size:12px;line-height:30px;text-align:center;text-transform:uppercase;cursor:pointer}.index_bf-letter-spacings__MYcL5 li:hover{background-color:hsla(0,0%,100%,.2)}.index_bf-letter-spacings__MYcL5 li.index_active__3_mlp{background-color:#3498db}.index_bf-emojis-wrap__3FqEM{position:relative;width:210px;height:220px;overflow:hidden}.index_bf-emojis-wrap__3FqEM:after,.index_bf-emojis-wrap__3FqEM:before{position:absolute;z-index:1;right:0;left:0;height:30px;border-radius:2px;content:\"\";pointer-events:none}.index_bf-emojis-wrap__3FqEM:before{top:0;background-image:linear-gradient(0deg,rgba(33,36,42,0),#21242a)}.index_bf-emojis-wrap__3FqEM:after{bottom:0;background-image:linear-gradient(rgba(33,36,42,0),#21242a)}.index_bf-emojis__3p4Ps{box-sizing:content-box;width:200px;height:195px;list-style:none;margin:0;padding:15px 15px 20px;overflow:auto}.index_bf-emojis__3p4Ps li{display:block;float:left;width:30px;height:30px;margin:0;padding:0;color:#fff;border-radius:2px;font-family:Apple Color Emoji,Segoe UI,Segoe UI Emoji,Segoe UI Symbol;font-size:18px;line-height:32px;text-align:center;cursor:pointer;-webkit-user-select:none;user-select:none;transition:transform .2s}.index_bf-emojis__3p4Ps li:hover{transform:scale(1.5)}";
  33302. styleInject(css);
  33303. var css$1 = ".emoticon_braft-emoticon-picker__26_HU{box-sizing:border-box;width:210px;height:210px;overflow:hidden}.emoticon_braft-emoticon-picker__26_HU:after,.emoticon_braft-emoticon-picker__26_HU:before{position:absolute;z-index:1;right:0;left:0;height:30px;border-radius:2px;content:\"\";pointer-events:none}.emoticon_braft-emoticon-picker__26_HU:before{top:0;background-image:linear-gradient(0deg,rgba(33,36,42,0),#21242a)}.emoticon_braft-emoticon-picker__26_HU:after{bottom:0;background-image:linear-gradient(rgba(33,36,42,0),#21242a)}.emoticon_braft-emoticon-picker__26_HU .emoticon_braft-emoticons-list__P1AeK{box-sizing:content-box;width:200px;height:190px;margin:0;padding:15px 15px 20px;overflow:auto}.emoticon_braft-emoticon-picker__26_HU .emoticon_braft-emoticons-list__P1AeK img{display:block;box-sizing:content-box;float:left;width:20px;height:20px;margin:3px;padding:5px;border-radius:3px}.emoticon_braft-emoticon-picker__26_HU .emoticon_braft-emoticons-list__P1AeK img:hover{background-color:#3498db}.emoticon_braft-emoticon-in-editor__10cwl{position:relative;padding:0 2px;letter-spacing:12px}.emoticon_braft-emoticon-in-editor__10cwl img{position:absolute;top:0;left:2px;width:16px;height:16px}";
  33304. styleInject(css$1);
  33305. var immutable$3 = createCommonjsModule(function (module, exports) {
  33306. /**
  33307. * Copyright (c) 2014-present, Facebook, Inc.
  33308. *
  33309. * This source code is licensed under the MIT license found in the
  33310. * LICENSE file in the root directory of this source tree.
  33311. */
  33312. (function (global, factory) {
  33313. factory(exports) ;
  33314. }(commonjsGlobal, (function (exports) {
  33315. // Used for setting prototype methods that IE8 chokes on.
  33316. var DELETE = 'delete';
  33317. // Constants describing the size of trie nodes.
  33318. var SHIFT = 5; // Resulted in best performance after ______?
  33319. var SIZE = 1 << SHIFT;
  33320. var MASK = SIZE - 1;
  33321. // A consistent shared value representing "not set" which equals nothing other
  33322. // than itself, and nothing that could be provided externally.
  33323. var NOT_SET = {};
  33324. // Boolean references, Rough equivalent of `bool &`.
  33325. function MakeRef() {
  33326. return { value: false };
  33327. }
  33328. function SetRef(ref) {
  33329. if (ref) {
  33330. ref.value = true;
  33331. }
  33332. }
  33333. // A function which returns a value representing an "owner" for transient writes
  33334. // to tries. The return value will only ever equal itself, and will not equal
  33335. // the return of any subsequent call of this function.
  33336. function OwnerID() {}
  33337. function ensureSize(iter) {
  33338. if (iter.size === undefined) {
  33339. iter.size = iter.__iterate(returnTrue);
  33340. }
  33341. return iter.size;
  33342. }
  33343. function wrapIndex(iter, index) {
  33344. // This implements "is array index" which the ECMAString spec defines as:
  33345. //
  33346. // A String property name P is an array index if and only if
  33347. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  33348. // to 2^32−1.
  33349. //
  33350. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  33351. if (typeof index !== 'number') {
  33352. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  33353. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  33354. return NaN;
  33355. }
  33356. index = uint32Index;
  33357. }
  33358. return index < 0 ? ensureSize(iter) + index : index;
  33359. }
  33360. function returnTrue() {
  33361. return true;
  33362. }
  33363. function wholeSlice(begin, end, size) {
  33364. return (
  33365. ((begin === 0 && !isNeg(begin)) ||
  33366. (size !== undefined && begin <= -size)) &&
  33367. (end === undefined || (size !== undefined && end >= size))
  33368. );
  33369. }
  33370. function resolveBegin(begin, size) {
  33371. return resolveIndex(begin, size, 0);
  33372. }
  33373. function resolveEnd(end, size) {
  33374. return resolveIndex(end, size, size);
  33375. }
  33376. function resolveIndex(index, size, defaultIndex) {
  33377. // Sanitize indices using this shorthand for ToInt32(argument)
  33378. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  33379. return index === undefined
  33380. ? defaultIndex
  33381. : isNeg(index)
  33382. ? size === Infinity
  33383. ? size
  33384. : Math.max(0, size + index) | 0
  33385. : size === undefined || size === index
  33386. ? index
  33387. : Math.min(size, index) | 0;
  33388. }
  33389. function isNeg(value) {
  33390. // Account for -0 which is negative, but not less than 0.
  33391. return value < 0 || (value === 0 && 1 / value === -Infinity);
  33392. }
  33393. // Note: value is unchanged to not break immutable-devtools.
  33394. var IS_COLLECTION_SYMBOL = '@@__IMMUTABLE_ITERABLE__@@';
  33395. function isCollection(maybeCollection) {
  33396. return Boolean(maybeCollection && maybeCollection[IS_COLLECTION_SYMBOL]);
  33397. }
  33398. var IS_KEYED_SYMBOL = '@@__IMMUTABLE_KEYED__@@';
  33399. function isKeyed(maybeKeyed) {
  33400. return Boolean(maybeKeyed && maybeKeyed[IS_KEYED_SYMBOL]);
  33401. }
  33402. var IS_INDEXED_SYMBOL = '@@__IMMUTABLE_INDEXED__@@';
  33403. function isIndexed(maybeIndexed) {
  33404. return Boolean(maybeIndexed && maybeIndexed[IS_INDEXED_SYMBOL]);
  33405. }
  33406. function isAssociative(maybeAssociative) {
  33407. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  33408. }
  33409. var Collection = function Collection(value) {
  33410. return isCollection(value) ? value : Seq(value);
  33411. };
  33412. var KeyedCollection = /*@__PURE__*/(function (Collection) {
  33413. function KeyedCollection(value) {
  33414. return isKeyed(value) ? value : KeyedSeq(value);
  33415. }
  33416. if ( Collection ) KeyedCollection.__proto__ = Collection;
  33417. KeyedCollection.prototype = Object.create( Collection && Collection.prototype );
  33418. KeyedCollection.prototype.constructor = KeyedCollection;
  33419. return KeyedCollection;
  33420. }(Collection));
  33421. var IndexedCollection = /*@__PURE__*/(function (Collection) {
  33422. function IndexedCollection(value) {
  33423. return isIndexed(value) ? value : IndexedSeq(value);
  33424. }
  33425. if ( Collection ) IndexedCollection.__proto__ = Collection;
  33426. IndexedCollection.prototype = Object.create( Collection && Collection.prototype );
  33427. IndexedCollection.prototype.constructor = IndexedCollection;
  33428. return IndexedCollection;
  33429. }(Collection));
  33430. var SetCollection = /*@__PURE__*/(function (Collection) {
  33431. function SetCollection(value) {
  33432. return isCollection(value) && !isAssociative(value) ? value : SetSeq(value);
  33433. }
  33434. if ( Collection ) SetCollection.__proto__ = Collection;
  33435. SetCollection.prototype = Object.create( Collection && Collection.prototype );
  33436. SetCollection.prototype.constructor = SetCollection;
  33437. return SetCollection;
  33438. }(Collection));
  33439. Collection.Keyed = KeyedCollection;
  33440. Collection.Indexed = IndexedCollection;
  33441. Collection.Set = SetCollection;
  33442. var IS_SEQ_SYMBOL = '@@__IMMUTABLE_SEQ__@@';
  33443. function isSeq(maybeSeq) {
  33444. return Boolean(maybeSeq && maybeSeq[IS_SEQ_SYMBOL]);
  33445. }
  33446. var IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@';
  33447. function isRecord(maybeRecord) {
  33448. return Boolean(maybeRecord && maybeRecord[IS_RECORD_SYMBOL]);
  33449. }
  33450. function isImmutable(maybeImmutable) {
  33451. return isCollection(maybeImmutable) || isRecord(maybeImmutable);
  33452. }
  33453. var IS_ORDERED_SYMBOL = '@@__IMMUTABLE_ORDERED__@@';
  33454. function isOrdered(maybeOrdered) {
  33455. return Boolean(maybeOrdered && maybeOrdered[IS_ORDERED_SYMBOL]);
  33456. }
  33457. var ITERATE_KEYS = 0;
  33458. var ITERATE_VALUES = 1;
  33459. var ITERATE_ENTRIES = 2;
  33460. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  33461. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  33462. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  33463. var Iterator = function Iterator(next) {
  33464. this.next = next;
  33465. };
  33466. Iterator.prototype.toString = function toString () {
  33467. return '[Iterator]';
  33468. };
  33469. Iterator.KEYS = ITERATE_KEYS;
  33470. Iterator.VALUES = ITERATE_VALUES;
  33471. Iterator.ENTRIES = ITERATE_ENTRIES;
  33472. Iterator.prototype.inspect = Iterator.prototype.toSource = function() {
  33473. return this.toString();
  33474. };
  33475. Iterator.prototype[ITERATOR_SYMBOL] = function() {
  33476. return this;
  33477. };
  33478. function iteratorValue(type, k, v, iteratorResult) {
  33479. var value = type === 0 ? k : type === 1 ? v : [k, v];
  33480. iteratorResult
  33481. ? (iteratorResult.value = value)
  33482. : (iteratorResult = {
  33483. value: value,
  33484. done: false,
  33485. });
  33486. return iteratorResult;
  33487. }
  33488. function iteratorDone() {
  33489. return { value: undefined, done: true };
  33490. }
  33491. function hasIterator(maybeIterable) {
  33492. return !!getIteratorFn(maybeIterable);
  33493. }
  33494. function isIterator(maybeIterator) {
  33495. return maybeIterator && typeof maybeIterator.next === 'function';
  33496. }
  33497. function getIterator(iterable) {
  33498. var iteratorFn = getIteratorFn(iterable);
  33499. return iteratorFn && iteratorFn.call(iterable);
  33500. }
  33501. function getIteratorFn(iterable) {
  33502. var iteratorFn =
  33503. iterable &&
  33504. ((REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  33505. iterable[FAUX_ITERATOR_SYMBOL]);
  33506. if (typeof iteratorFn === 'function') {
  33507. return iteratorFn;
  33508. }
  33509. }
  33510. var hasOwnProperty = Object.prototype.hasOwnProperty;
  33511. function isArrayLike(value) {
  33512. if (Array.isArray(value) || typeof value === 'string') {
  33513. return true;
  33514. }
  33515. return (
  33516. value &&
  33517. typeof value === 'object' &&
  33518. Number.isInteger(value.length) &&
  33519. value.length >= 0 &&
  33520. (value.length === 0
  33521. ? // Only {length: 0} is considered Array-like.
  33522. Object.keys(value).length === 1
  33523. : // An object is only Array-like if it has a property where the last value
  33524. // in the array-like may be found (which could be undefined).
  33525. value.hasOwnProperty(value.length - 1))
  33526. );
  33527. }
  33528. var Seq = /*@__PURE__*/(function (Collection$$1) {
  33529. function Seq(value) {
  33530. return value === null || value === undefined
  33531. ? emptySequence()
  33532. : isImmutable(value)
  33533. ? value.toSeq()
  33534. : seqFromValue(value);
  33535. }
  33536. if ( Collection$$1 ) Seq.__proto__ = Collection$$1;
  33537. Seq.prototype = Object.create( Collection$$1 && Collection$$1.prototype );
  33538. Seq.prototype.constructor = Seq;
  33539. Seq.prototype.toSeq = function toSeq () {
  33540. return this;
  33541. };
  33542. Seq.prototype.toString = function toString () {
  33543. return this.__toString('Seq {', '}');
  33544. };
  33545. Seq.prototype.cacheResult = function cacheResult () {
  33546. if (!this._cache && this.__iterateUncached) {
  33547. this._cache = this.entrySeq().toArray();
  33548. this.size = this._cache.length;
  33549. }
  33550. return this;
  33551. };
  33552. // abstract __iterateUncached(fn, reverse)
  33553. Seq.prototype.__iterate = function __iterate (fn, reverse) {
  33554. var cache = this._cache;
  33555. if (cache) {
  33556. var size = cache.length;
  33557. var i = 0;
  33558. while (i !== size) {
  33559. var entry = cache[reverse ? size - ++i : i++];
  33560. if (fn(entry[1], entry[0], this) === false) {
  33561. break;
  33562. }
  33563. }
  33564. return i;
  33565. }
  33566. return this.__iterateUncached(fn, reverse);
  33567. };
  33568. // abstract __iteratorUncached(type, reverse)
  33569. Seq.prototype.__iterator = function __iterator (type, reverse) {
  33570. var cache = this._cache;
  33571. if (cache) {
  33572. var size = cache.length;
  33573. var i = 0;
  33574. return new Iterator(function () {
  33575. if (i === size) {
  33576. return iteratorDone();
  33577. }
  33578. var entry = cache[reverse ? size - ++i : i++];
  33579. return iteratorValue(type, entry[0], entry[1]);
  33580. });
  33581. }
  33582. return this.__iteratorUncached(type, reverse);
  33583. };
  33584. return Seq;
  33585. }(Collection));
  33586. var KeyedSeq = /*@__PURE__*/(function (Seq) {
  33587. function KeyedSeq(value) {
  33588. return value === null || value === undefined
  33589. ? emptySequence().toKeyedSeq()
  33590. : isCollection(value)
  33591. ? isKeyed(value)
  33592. ? value.toSeq()
  33593. : value.fromEntrySeq()
  33594. : isRecord(value)
  33595. ? value.toSeq()
  33596. : keyedSeqFromValue(value);
  33597. }
  33598. if ( Seq ) KeyedSeq.__proto__ = Seq;
  33599. KeyedSeq.prototype = Object.create( Seq && Seq.prototype );
  33600. KeyedSeq.prototype.constructor = KeyedSeq;
  33601. KeyedSeq.prototype.toKeyedSeq = function toKeyedSeq () {
  33602. return this;
  33603. };
  33604. return KeyedSeq;
  33605. }(Seq));
  33606. var IndexedSeq = /*@__PURE__*/(function (Seq) {
  33607. function IndexedSeq(value) {
  33608. return value === null || value === undefined
  33609. ? emptySequence()
  33610. : isCollection(value)
  33611. ? isKeyed(value)
  33612. ? value.entrySeq()
  33613. : value.toIndexedSeq()
  33614. : isRecord(value)
  33615. ? value.toSeq().entrySeq()
  33616. : indexedSeqFromValue(value);
  33617. }
  33618. if ( Seq ) IndexedSeq.__proto__ = Seq;
  33619. IndexedSeq.prototype = Object.create( Seq && Seq.prototype );
  33620. IndexedSeq.prototype.constructor = IndexedSeq;
  33621. IndexedSeq.of = function of (/*...values*/) {
  33622. return IndexedSeq(arguments);
  33623. };
  33624. IndexedSeq.prototype.toIndexedSeq = function toIndexedSeq () {
  33625. return this;
  33626. };
  33627. IndexedSeq.prototype.toString = function toString () {
  33628. return this.__toString('Seq [', ']');
  33629. };
  33630. return IndexedSeq;
  33631. }(Seq));
  33632. var SetSeq = /*@__PURE__*/(function (Seq) {
  33633. function SetSeq(value) {
  33634. return (isCollection(value) && !isAssociative(value)
  33635. ? value
  33636. : IndexedSeq(value)
  33637. ).toSetSeq();
  33638. }
  33639. if ( Seq ) SetSeq.__proto__ = Seq;
  33640. SetSeq.prototype = Object.create( Seq && Seq.prototype );
  33641. SetSeq.prototype.constructor = SetSeq;
  33642. SetSeq.of = function of (/*...values*/) {
  33643. return SetSeq(arguments);
  33644. };
  33645. SetSeq.prototype.toSetSeq = function toSetSeq () {
  33646. return this;
  33647. };
  33648. return SetSeq;
  33649. }(Seq));
  33650. Seq.isSeq = isSeq;
  33651. Seq.Keyed = KeyedSeq;
  33652. Seq.Set = SetSeq;
  33653. Seq.Indexed = IndexedSeq;
  33654. Seq.prototype[IS_SEQ_SYMBOL] = true;
  33655. // #pragma Root Sequences
  33656. var ArraySeq = /*@__PURE__*/(function (IndexedSeq) {
  33657. function ArraySeq(array) {
  33658. this._array = array;
  33659. this.size = array.length;
  33660. }
  33661. if ( IndexedSeq ) ArraySeq.__proto__ = IndexedSeq;
  33662. ArraySeq.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
  33663. ArraySeq.prototype.constructor = ArraySeq;
  33664. ArraySeq.prototype.get = function get (index, notSetValue) {
  33665. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  33666. };
  33667. ArraySeq.prototype.__iterate = function __iterate (fn, reverse) {
  33668. var array = this._array;
  33669. var size = array.length;
  33670. var i = 0;
  33671. while (i !== size) {
  33672. var ii = reverse ? size - ++i : i++;
  33673. if (fn(array[ii], ii, this) === false) {
  33674. break;
  33675. }
  33676. }
  33677. return i;
  33678. };
  33679. ArraySeq.prototype.__iterator = function __iterator (type, reverse) {
  33680. var array = this._array;
  33681. var size = array.length;
  33682. var i = 0;
  33683. return new Iterator(function () {
  33684. if (i === size) {
  33685. return iteratorDone();
  33686. }
  33687. var ii = reverse ? size - ++i : i++;
  33688. return iteratorValue(type, ii, array[ii]);
  33689. });
  33690. };
  33691. return ArraySeq;
  33692. }(IndexedSeq));
  33693. var ObjectSeq = /*@__PURE__*/(function (KeyedSeq) {
  33694. function ObjectSeq(object) {
  33695. var keys = Object.keys(object);
  33696. this._object = object;
  33697. this._keys = keys;
  33698. this.size = keys.length;
  33699. }
  33700. if ( KeyedSeq ) ObjectSeq.__proto__ = KeyedSeq;
  33701. ObjectSeq.prototype = Object.create( KeyedSeq && KeyedSeq.prototype );
  33702. ObjectSeq.prototype.constructor = ObjectSeq;
  33703. ObjectSeq.prototype.get = function get (key, notSetValue) {
  33704. if (notSetValue !== undefined && !this.has(key)) {
  33705. return notSetValue;
  33706. }
  33707. return this._object[key];
  33708. };
  33709. ObjectSeq.prototype.has = function has (key) {
  33710. return hasOwnProperty.call(this._object, key);
  33711. };
  33712. ObjectSeq.prototype.__iterate = function __iterate (fn, reverse) {
  33713. var object = this._object;
  33714. var keys = this._keys;
  33715. var size = keys.length;
  33716. var i = 0;
  33717. while (i !== size) {
  33718. var key = keys[reverse ? size - ++i : i++];
  33719. if (fn(object[key], key, this) === false) {
  33720. break;
  33721. }
  33722. }
  33723. return i;
  33724. };
  33725. ObjectSeq.prototype.__iterator = function __iterator (type, reverse) {
  33726. var object = this._object;
  33727. var keys = this._keys;
  33728. var size = keys.length;
  33729. var i = 0;
  33730. return new Iterator(function () {
  33731. if (i === size) {
  33732. return iteratorDone();
  33733. }
  33734. var key = keys[reverse ? size - ++i : i++];
  33735. return iteratorValue(type, key, object[key]);
  33736. });
  33737. };
  33738. return ObjectSeq;
  33739. }(KeyedSeq));
  33740. ObjectSeq.prototype[IS_ORDERED_SYMBOL] = true;
  33741. var CollectionSeq = /*@__PURE__*/(function (IndexedSeq) {
  33742. function CollectionSeq(collection) {
  33743. this._collection = collection;
  33744. this.size = collection.length || collection.size;
  33745. }
  33746. if ( IndexedSeq ) CollectionSeq.__proto__ = IndexedSeq;
  33747. CollectionSeq.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
  33748. CollectionSeq.prototype.constructor = CollectionSeq;
  33749. CollectionSeq.prototype.__iterateUncached = function __iterateUncached (fn, reverse) {
  33750. if (reverse) {
  33751. return this.cacheResult().__iterate(fn, reverse);
  33752. }
  33753. var collection = this._collection;
  33754. var iterator = getIterator(collection);
  33755. var iterations = 0;
  33756. if (isIterator(iterator)) {
  33757. var step;
  33758. while (!(step = iterator.next()).done) {
  33759. if (fn(step.value, iterations++, this) === false) {
  33760. break;
  33761. }
  33762. }
  33763. }
  33764. return iterations;
  33765. };
  33766. CollectionSeq.prototype.__iteratorUncached = function __iteratorUncached (type, reverse) {
  33767. if (reverse) {
  33768. return this.cacheResult().__iterator(type, reverse);
  33769. }
  33770. var collection = this._collection;
  33771. var iterator = getIterator(collection);
  33772. if (!isIterator(iterator)) {
  33773. return new Iterator(iteratorDone);
  33774. }
  33775. var iterations = 0;
  33776. return new Iterator(function () {
  33777. var step = iterator.next();
  33778. return step.done ? step : iteratorValue(type, iterations++, step.value);
  33779. });
  33780. };
  33781. return CollectionSeq;
  33782. }(IndexedSeq));
  33783. // # pragma Helper functions
  33784. var EMPTY_SEQ;
  33785. function emptySequence() {
  33786. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  33787. }
  33788. function keyedSeqFromValue(value) {
  33789. var seq = Array.isArray(value)
  33790. ? new ArraySeq(value)
  33791. : hasIterator(value)
  33792. ? new CollectionSeq(value)
  33793. : undefined;
  33794. if (seq) {
  33795. return seq.fromEntrySeq();
  33796. }
  33797. if (typeof value === 'object') {
  33798. return new ObjectSeq(value);
  33799. }
  33800. throw new TypeError(
  33801. 'Expected Array or collection object of [k, v] entries, or keyed object: ' +
  33802. value
  33803. );
  33804. }
  33805. function indexedSeqFromValue(value) {
  33806. var seq = maybeIndexedSeqFromValue(value);
  33807. if (seq) {
  33808. return seq;
  33809. }
  33810. throw new TypeError(
  33811. 'Expected Array or collection object of values: ' + value
  33812. );
  33813. }
  33814. function seqFromValue(value) {
  33815. var seq = maybeIndexedSeqFromValue(value);
  33816. if (seq) {
  33817. return seq;
  33818. }
  33819. if (typeof value === 'object') {
  33820. return new ObjectSeq(value);
  33821. }
  33822. throw new TypeError(
  33823. 'Expected Array or collection object of values, or keyed object: ' + value
  33824. );
  33825. }
  33826. function maybeIndexedSeqFromValue(value) {
  33827. return isArrayLike(value)
  33828. ? new ArraySeq(value)
  33829. : hasIterator(value)
  33830. ? new CollectionSeq(value)
  33831. : undefined;
  33832. }
  33833. var IS_MAP_SYMBOL = '@@__IMMUTABLE_MAP__@@';
  33834. function isMap(maybeMap) {
  33835. return Boolean(maybeMap && maybeMap[IS_MAP_SYMBOL]);
  33836. }
  33837. function isOrderedMap(maybeOrderedMap) {
  33838. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  33839. }
  33840. function isValueObject(maybeValue) {
  33841. return Boolean(
  33842. maybeValue &&
  33843. typeof maybeValue.equals === 'function' &&
  33844. typeof maybeValue.hashCode === 'function'
  33845. );
  33846. }
  33847. /**
  33848. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  33849. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  33850. *
  33851. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  33852. * value, which is different from the algorithm described by
  33853. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  33854. *
  33855. * This is extended further to allow Objects to describe the values they
  33856. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  33857. *
  33858. * Note: because of this extension, the key equality of Immutable.Map and the
  33859. * value equality of Immutable.Set will differ from ES6 Map and Set.
  33860. *
  33861. * ### Defining custom values
  33862. *
  33863. * The easiest way to describe the value an object represents is by implementing
  33864. * `valueOf`. For example, `Date` represents a value by returning a unix
  33865. * timestamp for `valueOf`:
  33866. *
  33867. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  33868. * var date2 = new Date(1234567890000);
  33869. * date1.valueOf(); // 1234567890000
  33870. * assert( date1 !== date2 );
  33871. * assert( Immutable.is( date1, date2 ) );
  33872. *
  33873. * Note: overriding `valueOf` may have other implications if you use this object
  33874. * where JavaScript expects a primitive, such as implicit string coercion.
  33875. *
  33876. * For more complex types, especially collections, implementing `valueOf` may
  33877. * not be performant. An alternative is to implement `equals` and `hashCode`.
  33878. *
  33879. * `equals` takes another object, presumably of similar type, and returns true
  33880. * if it is equal. Equality is symmetrical, so the same result should be
  33881. * returned if this and the argument are flipped.
  33882. *
  33883. * assert( a.equals(b) === b.equals(a) );
  33884. *
  33885. * `hashCode` returns a 32bit integer number representing the object which will
  33886. * be used to determine how to store the value object in a Map or Set. You must
  33887. * provide both or neither methods, one must not exist without the other.
  33888. *
  33889. * Also, an important relationship between these methods must be upheld: if two
  33890. * values are equal, they *must* return the same hashCode. If the values are not
  33891. * equal, they might have the same hashCode; this is called a hash collision,
  33892. * and while undesirable for performance reasons, it is acceptable.
  33893. *
  33894. * if (a.equals(b)) {
  33895. * assert( a.hashCode() === b.hashCode() );
  33896. * }
  33897. *
  33898. * All Immutable collections are Value Objects: they implement `equals()`
  33899. * and `hashCode()`.
  33900. */
  33901. function is(valueA, valueB) {
  33902. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  33903. return true;
  33904. }
  33905. if (!valueA || !valueB) {
  33906. return false;
  33907. }
  33908. if (
  33909. typeof valueA.valueOf === 'function' &&
  33910. typeof valueB.valueOf === 'function'
  33911. ) {
  33912. valueA = valueA.valueOf();
  33913. valueB = valueB.valueOf();
  33914. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  33915. return true;
  33916. }
  33917. if (!valueA || !valueB) {
  33918. return false;
  33919. }
  33920. }
  33921. return !!(
  33922. isValueObject(valueA) &&
  33923. isValueObject(valueB) &&
  33924. valueA.equals(valueB)
  33925. );
  33926. }
  33927. var imul =
  33928. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2
  33929. ? Math.imul
  33930. : function imul(a, b) {
  33931. a |= 0; // int
  33932. b |= 0; // int
  33933. var c = a & 0xffff;
  33934. var d = b & 0xffff;
  33935. // Shift by 0 fixes the sign on the high part.
  33936. return (c * d + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0)) | 0; // int
  33937. };
  33938. // v8 has an optimization for storing 31-bit signed numbers.
  33939. // Values which have either 00 or 11 as the high order bits qualify.
  33940. // This function drops the highest order bit in a signed number, maintaining
  33941. // the sign bit.
  33942. function smi(i32) {
  33943. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xbfffffff);
  33944. }
  33945. var defaultValueOf = Object.prototype.valueOf;
  33946. function hash(o) {
  33947. switch (typeof o) {
  33948. case 'boolean':
  33949. // The hash values for built-in constants are a 1 value for each 5-byte
  33950. // shift region expect for the first, which encodes the value. This
  33951. // reduces the odds of a hash collision for these common values.
  33952. return o ? 0x42108421 : 0x42108420;
  33953. case 'number':
  33954. return hashNumber(o);
  33955. case 'string':
  33956. return o.length > STRING_HASH_CACHE_MIN_STRLEN
  33957. ? cachedHashString(o)
  33958. : hashString(o);
  33959. case 'object':
  33960. case 'function':
  33961. if (o === null) {
  33962. return 0x42108422;
  33963. }
  33964. if (typeof o.hashCode === 'function') {
  33965. // Drop any high bits from accidentally long hash codes.
  33966. return smi(o.hashCode(o));
  33967. }
  33968. if (o.valueOf !== defaultValueOf && typeof o.valueOf === 'function') {
  33969. o = o.valueOf(o);
  33970. }
  33971. return hashJSObj(o);
  33972. case 'undefined':
  33973. return 0x42108423;
  33974. default:
  33975. if (typeof o.toString === 'function') {
  33976. return hashString(o.toString());
  33977. }
  33978. throw new Error('Value type ' + typeof o + ' cannot be hashed.');
  33979. }
  33980. }
  33981. // Compress arbitrarily large numbers into smi hashes.
  33982. function hashNumber(n) {
  33983. if (n !== n || n === Infinity) {
  33984. return 0;
  33985. }
  33986. var hash = n | 0;
  33987. if (hash !== n) {
  33988. hash ^= n * 0xffffffff;
  33989. }
  33990. while (n > 0xffffffff) {
  33991. n /= 0xffffffff;
  33992. hash ^= n;
  33993. }
  33994. return smi(hash);
  33995. }
  33996. function cachedHashString(string) {
  33997. var hashed = stringHashCache[string];
  33998. if (hashed === undefined) {
  33999. hashed = hashString(string);
  34000. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  34001. STRING_HASH_CACHE_SIZE = 0;
  34002. stringHashCache = {};
  34003. }
  34004. STRING_HASH_CACHE_SIZE++;
  34005. stringHashCache[string] = hashed;
  34006. }
  34007. return hashed;
  34008. }
  34009. // http://jsperf.com/hashing-strings
  34010. function hashString(string) {
  34011. // This is the hash from JVM
  34012. // The hash code for a string is computed as
  34013. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  34014. // where s[i] is the ith character of the string and n is the length of
  34015. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  34016. // (exclusive) by dropping high bits.
  34017. var hashed = 0;
  34018. for (var ii = 0; ii < string.length; ii++) {
  34019. hashed = (31 * hashed + string.charCodeAt(ii)) | 0;
  34020. }
  34021. return smi(hashed);
  34022. }
  34023. function hashJSObj(obj) {
  34024. var hashed;
  34025. if (usingWeakMap) {
  34026. hashed = weakMap.get(obj);
  34027. if (hashed !== undefined) {
  34028. return hashed;
  34029. }
  34030. }
  34031. hashed = obj[UID_HASH_KEY];
  34032. if (hashed !== undefined) {
  34033. return hashed;
  34034. }
  34035. if (!canDefineProperty) {
  34036. hashed = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  34037. if (hashed !== undefined) {
  34038. return hashed;
  34039. }
  34040. hashed = getIENodeHash(obj);
  34041. if (hashed !== undefined) {
  34042. return hashed;
  34043. }
  34044. }
  34045. hashed = ++objHashUID;
  34046. if (objHashUID & 0x40000000) {
  34047. objHashUID = 0;
  34048. }
  34049. if (usingWeakMap) {
  34050. weakMap.set(obj, hashed);
  34051. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  34052. throw new Error('Non-extensible objects are not allowed as keys.');
  34053. } else if (canDefineProperty) {
  34054. Object.defineProperty(obj, UID_HASH_KEY, {
  34055. enumerable: false,
  34056. configurable: false,
  34057. writable: false,
  34058. value: hashed,
  34059. });
  34060. } else if (
  34061. obj.propertyIsEnumerable !== undefined &&
  34062. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable
  34063. ) {
  34064. // Since we can't define a non-enumerable property on the object
  34065. // we'll hijack one of the less-used non-enumerable properties to
  34066. // save our hash on it. Since this is a function it will not show up in
  34067. // `JSON.stringify` which is what we want.
  34068. obj.propertyIsEnumerable = function() {
  34069. return this.constructor.prototype.propertyIsEnumerable.apply(
  34070. this,
  34071. arguments
  34072. );
  34073. };
  34074. obj.propertyIsEnumerable[UID_HASH_KEY] = hashed;
  34075. } else if (obj.nodeType !== undefined) {
  34076. // At this point we couldn't get the IE `uniqueID` to use as a hash
  34077. // and we couldn't use a non-enumerable property to exploit the
  34078. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  34079. // itself.
  34080. obj[UID_HASH_KEY] = hashed;
  34081. } else {
  34082. throw new Error('Unable to set a non-enumerable property on object.');
  34083. }
  34084. return hashed;
  34085. }
  34086. // Get references to ES5 object methods.
  34087. var isExtensible = Object.isExtensible;
  34088. // True if Object.defineProperty works as expected. IE8 fails this test.
  34089. var canDefineProperty = (function() {
  34090. try {
  34091. Object.defineProperty({}, '@', {});
  34092. return true;
  34093. } catch (e) {
  34094. return false;
  34095. }
  34096. })();
  34097. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  34098. // and avoid memory leaks from the IE cloneNode bug.
  34099. function getIENodeHash(node) {
  34100. if (node && node.nodeType > 0) {
  34101. switch (node.nodeType) {
  34102. case 1: // Element
  34103. return node.uniqueID;
  34104. case 9: // Document
  34105. return node.documentElement && node.documentElement.uniqueID;
  34106. }
  34107. }
  34108. }
  34109. // If possible, use a WeakMap.
  34110. var usingWeakMap = typeof WeakMap === 'function';
  34111. var weakMap;
  34112. if (usingWeakMap) {
  34113. weakMap = new WeakMap();
  34114. }
  34115. var objHashUID = 0;
  34116. var UID_HASH_KEY = '__immutablehash__';
  34117. if (typeof Symbol === 'function') {
  34118. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  34119. }
  34120. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  34121. var STRING_HASH_CACHE_MAX_SIZE = 255;
  34122. var STRING_HASH_CACHE_SIZE = 0;
  34123. var stringHashCache = {};
  34124. var ToKeyedSequence = /*@__PURE__*/(function (KeyedSeq$$1) {
  34125. function ToKeyedSequence(indexed, useKeys) {
  34126. this._iter = indexed;
  34127. this._useKeys = useKeys;
  34128. this.size = indexed.size;
  34129. }
  34130. if ( KeyedSeq$$1 ) ToKeyedSequence.__proto__ = KeyedSeq$$1;
  34131. ToKeyedSequence.prototype = Object.create( KeyedSeq$$1 && KeyedSeq$$1.prototype );
  34132. ToKeyedSequence.prototype.constructor = ToKeyedSequence;
  34133. ToKeyedSequence.prototype.get = function get (key, notSetValue) {
  34134. return this._iter.get(key, notSetValue);
  34135. };
  34136. ToKeyedSequence.prototype.has = function has (key) {
  34137. return this._iter.has(key);
  34138. };
  34139. ToKeyedSequence.prototype.valueSeq = function valueSeq () {
  34140. return this._iter.valueSeq();
  34141. };
  34142. ToKeyedSequence.prototype.reverse = function reverse () {
  34143. var this$1 = this;
  34144. var reversedSequence = reverseFactory(this, true);
  34145. if (!this._useKeys) {
  34146. reversedSequence.valueSeq = function () { return this$1._iter.toSeq().reverse(); };
  34147. }
  34148. return reversedSequence;
  34149. };
  34150. ToKeyedSequence.prototype.map = function map (mapper, context) {
  34151. var this$1 = this;
  34152. var mappedSequence = mapFactory(this, mapper, context);
  34153. if (!this._useKeys) {
  34154. mappedSequence.valueSeq = function () { return this$1._iter.toSeq().map(mapper, context); };
  34155. }
  34156. return mappedSequence;
  34157. };
  34158. ToKeyedSequence.prototype.__iterate = function __iterate (fn, reverse) {
  34159. var this$1 = this;
  34160. return this._iter.__iterate(function (v, k) { return fn(v, k, this$1); }, reverse);
  34161. };
  34162. ToKeyedSequence.prototype.__iterator = function __iterator (type, reverse) {
  34163. return this._iter.__iterator(type, reverse);
  34164. };
  34165. return ToKeyedSequence;
  34166. }(KeyedSeq));
  34167. ToKeyedSequence.prototype[IS_ORDERED_SYMBOL] = true;
  34168. var ToIndexedSequence = /*@__PURE__*/(function (IndexedSeq$$1) {
  34169. function ToIndexedSequence(iter) {
  34170. this._iter = iter;
  34171. this.size = iter.size;
  34172. }
  34173. if ( IndexedSeq$$1 ) ToIndexedSequence.__proto__ = IndexedSeq$$1;
  34174. ToIndexedSequence.prototype = Object.create( IndexedSeq$$1 && IndexedSeq$$1.prototype );
  34175. ToIndexedSequence.prototype.constructor = ToIndexedSequence;
  34176. ToIndexedSequence.prototype.includes = function includes (value) {
  34177. return this._iter.includes(value);
  34178. };
  34179. ToIndexedSequence.prototype.__iterate = function __iterate (fn, reverse) {
  34180. var this$1 = this;
  34181. var i = 0;
  34182. reverse && ensureSize(this);
  34183. return this._iter.__iterate(
  34184. function (v) { return fn(v, reverse ? this$1.size - ++i : i++, this$1); },
  34185. reverse
  34186. );
  34187. };
  34188. ToIndexedSequence.prototype.__iterator = function __iterator (type, reverse) {
  34189. var this$1 = this;
  34190. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  34191. var i = 0;
  34192. reverse && ensureSize(this);
  34193. return new Iterator(function () {
  34194. var step = iterator.next();
  34195. return step.done
  34196. ? step
  34197. : iteratorValue(
  34198. type,
  34199. reverse ? this$1.size - ++i : i++,
  34200. step.value,
  34201. step
  34202. );
  34203. });
  34204. };
  34205. return ToIndexedSequence;
  34206. }(IndexedSeq));
  34207. var ToSetSequence = /*@__PURE__*/(function (SetSeq$$1) {
  34208. function ToSetSequence(iter) {
  34209. this._iter = iter;
  34210. this.size = iter.size;
  34211. }
  34212. if ( SetSeq$$1 ) ToSetSequence.__proto__ = SetSeq$$1;
  34213. ToSetSequence.prototype = Object.create( SetSeq$$1 && SetSeq$$1.prototype );
  34214. ToSetSequence.prototype.constructor = ToSetSequence;
  34215. ToSetSequence.prototype.has = function has (key) {
  34216. return this._iter.includes(key);
  34217. };
  34218. ToSetSequence.prototype.__iterate = function __iterate (fn, reverse) {
  34219. var this$1 = this;
  34220. return this._iter.__iterate(function (v) { return fn(v, v, this$1); }, reverse);
  34221. };
  34222. ToSetSequence.prototype.__iterator = function __iterator (type, reverse) {
  34223. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  34224. return new Iterator(function () {
  34225. var step = iterator.next();
  34226. return step.done
  34227. ? step
  34228. : iteratorValue(type, step.value, step.value, step);
  34229. });
  34230. };
  34231. return ToSetSequence;
  34232. }(SetSeq));
  34233. var FromEntriesSequence = /*@__PURE__*/(function (KeyedSeq$$1) {
  34234. function FromEntriesSequence(entries) {
  34235. this._iter = entries;
  34236. this.size = entries.size;
  34237. }
  34238. if ( KeyedSeq$$1 ) FromEntriesSequence.__proto__ = KeyedSeq$$1;
  34239. FromEntriesSequence.prototype = Object.create( KeyedSeq$$1 && KeyedSeq$$1.prototype );
  34240. FromEntriesSequence.prototype.constructor = FromEntriesSequence;
  34241. FromEntriesSequence.prototype.entrySeq = function entrySeq () {
  34242. return this._iter.toSeq();
  34243. };
  34244. FromEntriesSequence.prototype.__iterate = function __iterate (fn, reverse) {
  34245. var this$1 = this;
  34246. return this._iter.__iterate(function (entry) {
  34247. // Check if entry exists first so array access doesn't throw for holes
  34248. // in the parent iteration.
  34249. if (entry) {
  34250. validateEntry(entry);
  34251. var indexedCollection = isCollection(entry);
  34252. return fn(
  34253. indexedCollection ? entry.get(1) : entry[1],
  34254. indexedCollection ? entry.get(0) : entry[0],
  34255. this$1
  34256. );
  34257. }
  34258. }, reverse);
  34259. };
  34260. FromEntriesSequence.prototype.__iterator = function __iterator (type, reverse) {
  34261. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  34262. return new Iterator(function () {
  34263. while (true) {
  34264. var step = iterator.next();
  34265. if (step.done) {
  34266. return step;
  34267. }
  34268. var entry = step.value;
  34269. // Check if entry exists first so array access doesn't throw for holes
  34270. // in the parent iteration.
  34271. if (entry) {
  34272. validateEntry(entry);
  34273. var indexedCollection = isCollection(entry);
  34274. return iteratorValue(
  34275. type,
  34276. indexedCollection ? entry.get(0) : entry[0],
  34277. indexedCollection ? entry.get(1) : entry[1],
  34278. step
  34279. );
  34280. }
  34281. }
  34282. });
  34283. };
  34284. return FromEntriesSequence;
  34285. }(KeyedSeq));
  34286. ToIndexedSequence.prototype.cacheResult = ToKeyedSequence.prototype.cacheResult = ToSetSequence.prototype.cacheResult = FromEntriesSequence.prototype.cacheResult = cacheResultThrough;
  34287. function flipFactory(collection) {
  34288. var flipSequence = makeSequence(collection);
  34289. flipSequence._iter = collection;
  34290. flipSequence.size = collection.size;
  34291. flipSequence.flip = function () { return collection; };
  34292. flipSequence.reverse = function() {
  34293. var reversedSequence = collection.reverse.apply(this); // super.reverse()
  34294. reversedSequence.flip = function () { return collection.reverse(); };
  34295. return reversedSequence;
  34296. };
  34297. flipSequence.has = function (key) { return collection.includes(key); };
  34298. flipSequence.includes = function (key) { return collection.has(key); };
  34299. flipSequence.cacheResult = cacheResultThrough;
  34300. flipSequence.__iterateUncached = function(fn, reverse) {
  34301. var this$1 = this;
  34302. return collection.__iterate(function (v, k) { return fn(k, v, this$1) !== false; }, reverse);
  34303. };
  34304. flipSequence.__iteratorUncached = function(type, reverse) {
  34305. if (type === ITERATE_ENTRIES) {
  34306. var iterator = collection.__iterator(type, reverse);
  34307. return new Iterator(function () {
  34308. var step = iterator.next();
  34309. if (!step.done) {
  34310. var k = step.value[0];
  34311. step.value[0] = step.value[1];
  34312. step.value[1] = k;
  34313. }
  34314. return step;
  34315. });
  34316. }
  34317. return collection.__iterator(
  34318. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  34319. reverse
  34320. );
  34321. };
  34322. return flipSequence;
  34323. }
  34324. function mapFactory(collection, mapper, context) {
  34325. var mappedSequence = makeSequence(collection);
  34326. mappedSequence.size = collection.size;
  34327. mappedSequence.has = function (key) { return collection.has(key); };
  34328. mappedSequence.get = function (key, notSetValue) {
  34329. var v = collection.get(key, NOT_SET);
  34330. return v === NOT_SET
  34331. ? notSetValue
  34332. : mapper.call(context, v, key, collection);
  34333. };
  34334. mappedSequence.__iterateUncached = function(fn, reverse) {
  34335. var this$1 = this;
  34336. return collection.__iterate(
  34337. function (v, k, c) { return fn(mapper.call(context, v, k, c), k, this$1) !== false; },
  34338. reverse
  34339. );
  34340. };
  34341. mappedSequence.__iteratorUncached = function(type, reverse) {
  34342. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  34343. return new Iterator(function () {
  34344. var step = iterator.next();
  34345. if (step.done) {
  34346. return step;
  34347. }
  34348. var entry = step.value;
  34349. var key = entry[0];
  34350. return iteratorValue(
  34351. type,
  34352. key,
  34353. mapper.call(context, entry[1], key, collection),
  34354. step
  34355. );
  34356. });
  34357. };
  34358. return mappedSequence;
  34359. }
  34360. function reverseFactory(collection, useKeys) {
  34361. var this$1 = this;
  34362. var reversedSequence = makeSequence(collection);
  34363. reversedSequence._iter = collection;
  34364. reversedSequence.size = collection.size;
  34365. reversedSequence.reverse = function () { return collection; };
  34366. if (collection.flip) {
  34367. reversedSequence.flip = function() {
  34368. var flipSequence = flipFactory(collection);
  34369. flipSequence.reverse = function () { return collection.flip(); };
  34370. return flipSequence;
  34371. };
  34372. }
  34373. reversedSequence.get = function (key, notSetValue) { return collection.get(useKeys ? key : -1 - key, notSetValue); };
  34374. reversedSequence.has = function (key) { return collection.has(useKeys ? key : -1 - key); };
  34375. reversedSequence.includes = function (value) { return collection.includes(value); };
  34376. reversedSequence.cacheResult = cacheResultThrough;
  34377. reversedSequence.__iterate = function(fn, reverse) {
  34378. var this$1 = this;
  34379. var i = 0;
  34380. reverse && ensureSize(collection);
  34381. return collection.__iterate(
  34382. function (v, k) { return fn(v, useKeys ? k : reverse ? this$1.size - ++i : i++, this$1); },
  34383. !reverse
  34384. );
  34385. };
  34386. reversedSequence.__iterator = function (type, reverse) {
  34387. var i = 0;
  34388. reverse && ensureSize(collection);
  34389. var iterator = collection.__iterator(ITERATE_ENTRIES, !reverse);
  34390. return new Iterator(function () {
  34391. var step = iterator.next();
  34392. if (step.done) {
  34393. return step;
  34394. }
  34395. var entry = step.value;
  34396. return iteratorValue(
  34397. type,
  34398. useKeys ? entry[0] : reverse ? this$1.size - ++i : i++,
  34399. entry[1],
  34400. step
  34401. );
  34402. });
  34403. };
  34404. return reversedSequence;
  34405. }
  34406. function filterFactory(collection, predicate, context, useKeys) {
  34407. var filterSequence = makeSequence(collection);
  34408. if (useKeys) {
  34409. filterSequence.has = function (key) {
  34410. var v = collection.get(key, NOT_SET);
  34411. return v !== NOT_SET && !!predicate.call(context, v, key, collection);
  34412. };
  34413. filterSequence.get = function (key, notSetValue) {
  34414. var v = collection.get(key, NOT_SET);
  34415. return v !== NOT_SET && predicate.call(context, v, key, collection)
  34416. ? v
  34417. : notSetValue;
  34418. };
  34419. }
  34420. filterSequence.__iterateUncached = function(fn, reverse) {
  34421. var this$1 = this;
  34422. var iterations = 0;
  34423. collection.__iterate(function (v, k, c) {
  34424. if (predicate.call(context, v, k, c)) {
  34425. iterations++;
  34426. return fn(v, useKeys ? k : iterations - 1, this$1);
  34427. }
  34428. }, reverse);
  34429. return iterations;
  34430. };
  34431. filterSequence.__iteratorUncached = function(type, reverse) {
  34432. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  34433. var iterations = 0;
  34434. return new Iterator(function () {
  34435. while (true) {
  34436. var step = iterator.next();
  34437. if (step.done) {
  34438. return step;
  34439. }
  34440. var entry = step.value;
  34441. var key = entry[0];
  34442. var value = entry[1];
  34443. if (predicate.call(context, value, key, collection)) {
  34444. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  34445. }
  34446. }
  34447. });
  34448. };
  34449. return filterSequence;
  34450. }
  34451. function countByFactory(collection, grouper, context) {
  34452. var groups = Map().asMutable();
  34453. collection.__iterate(function (v, k) {
  34454. groups.update(grouper.call(context, v, k, collection), 0, function (a) { return a + 1; });
  34455. });
  34456. return groups.asImmutable();
  34457. }
  34458. function groupByFactory(collection, grouper, context) {
  34459. var isKeyedIter = isKeyed(collection);
  34460. var groups = (isOrdered(collection) ? OrderedMap() : Map()).asMutable();
  34461. collection.__iterate(function (v, k) {
  34462. groups.update(
  34463. grouper.call(context, v, k, collection),
  34464. function (a) { return ((a = a || []), a.push(isKeyedIter ? [k, v] : v), a); }
  34465. );
  34466. });
  34467. var coerce = collectionClass(collection);
  34468. return groups.map(function (arr) { return reify(collection, coerce(arr)); }).asImmutable();
  34469. }
  34470. function sliceFactory(collection, begin, end, useKeys) {
  34471. var originalSize = collection.size;
  34472. if (wholeSlice(begin, end, originalSize)) {
  34473. return collection;
  34474. }
  34475. var resolvedBegin = resolveBegin(begin, originalSize);
  34476. var resolvedEnd = resolveEnd(end, originalSize);
  34477. // begin or end will be NaN if they were provided as negative numbers and
  34478. // this collection's size is unknown. In that case, cache first so there is
  34479. // a known size and these do not resolve to NaN.
  34480. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  34481. return sliceFactory(collection.toSeq().cacheResult(), begin, end, useKeys);
  34482. }
  34483. // Note: resolvedEnd is undefined when the original sequence's length is
  34484. // unknown and this slice did not supply an end and should contain all
  34485. // elements after resolvedBegin.
  34486. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  34487. var resolvedSize = resolvedEnd - resolvedBegin;
  34488. var sliceSize;
  34489. if (resolvedSize === resolvedSize) {
  34490. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  34491. }
  34492. var sliceSeq = makeSequence(collection);
  34493. // If collection.size is undefined, the size of the realized sliceSeq is
  34494. // unknown at this point unless the number of items to slice is 0
  34495. sliceSeq.size =
  34496. sliceSize === 0 ? sliceSize : (collection.size && sliceSize) || undefined;
  34497. if (!useKeys && isSeq(collection) && sliceSize >= 0) {
  34498. sliceSeq.get = function(index, notSetValue) {
  34499. index = wrapIndex(this, index);
  34500. return index >= 0 && index < sliceSize
  34501. ? collection.get(index + resolvedBegin, notSetValue)
  34502. : notSetValue;
  34503. };
  34504. }
  34505. sliceSeq.__iterateUncached = function(fn, reverse) {
  34506. var this$1 = this;
  34507. if (sliceSize === 0) {
  34508. return 0;
  34509. }
  34510. if (reverse) {
  34511. return this.cacheResult().__iterate(fn, reverse);
  34512. }
  34513. var skipped = 0;
  34514. var isSkipping = true;
  34515. var iterations = 0;
  34516. collection.__iterate(function (v, k) {
  34517. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  34518. iterations++;
  34519. return (
  34520. fn(v, useKeys ? k : iterations - 1, this$1) !== false &&
  34521. iterations !== sliceSize
  34522. );
  34523. }
  34524. });
  34525. return iterations;
  34526. };
  34527. sliceSeq.__iteratorUncached = function(type, reverse) {
  34528. if (sliceSize !== 0 && reverse) {
  34529. return this.cacheResult().__iterator(type, reverse);
  34530. }
  34531. // Don't bother instantiating parent iterator if taking 0.
  34532. if (sliceSize === 0) {
  34533. return new Iterator(iteratorDone);
  34534. }
  34535. var iterator = collection.__iterator(type, reverse);
  34536. var skipped = 0;
  34537. var iterations = 0;
  34538. return new Iterator(function () {
  34539. while (skipped++ < resolvedBegin) {
  34540. iterator.next();
  34541. }
  34542. if (++iterations > sliceSize) {
  34543. return iteratorDone();
  34544. }
  34545. var step = iterator.next();
  34546. if (useKeys || type === ITERATE_VALUES || step.done) {
  34547. return step;
  34548. }
  34549. if (type === ITERATE_KEYS) {
  34550. return iteratorValue(type, iterations - 1, undefined, step);
  34551. }
  34552. return iteratorValue(type, iterations - 1, step.value[1], step);
  34553. });
  34554. };
  34555. return sliceSeq;
  34556. }
  34557. function takeWhileFactory(collection, predicate, context) {
  34558. var takeSequence = makeSequence(collection);
  34559. takeSequence.__iterateUncached = function(fn, reverse) {
  34560. var this$1 = this;
  34561. if (reverse) {
  34562. return this.cacheResult().__iterate(fn, reverse);
  34563. }
  34564. var iterations = 0;
  34565. collection.__iterate(
  34566. function (v, k, c) { return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$1); }
  34567. );
  34568. return iterations;
  34569. };
  34570. takeSequence.__iteratorUncached = function(type, reverse) {
  34571. var this$1 = this;
  34572. if (reverse) {
  34573. return this.cacheResult().__iterator(type, reverse);
  34574. }
  34575. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  34576. var iterating = true;
  34577. return new Iterator(function () {
  34578. if (!iterating) {
  34579. return iteratorDone();
  34580. }
  34581. var step = iterator.next();
  34582. if (step.done) {
  34583. return step;
  34584. }
  34585. var entry = step.value;
  34586. var k = entry[0];
  34587. var v = entry[1];
  34588. if (!predicate.call(context, v, k, this$1)) {
  34589. iterating = false;
  34590. return iteratorDone();
  34591. }
  34592. return type === ITERATE_ENTRIES ? step : iteratorValue(type, k, v, step);
  34593. });
  34594. };
  34595. return takeSequence;
  34596. }
  34597. function skipWhileFactory(collection, predicate, context, useKeys) {
  34598. var skipSequence = makeSequence(collection);
  34599. skipSequence.__iterateUncached = function(fn, reverse) {
  34600. var this$1 = this;
  34601. if (reverse) {
  34602. return this.cacheResult().__iterate(fn, reverse);
  34603. }
  34604. var isSkipping = true;
  34605. var iterations = 0;
  34606. collection.__iterate(function (v, k, c) {
  34607. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  34608. iterations++;
  34609. return fn(v, useKeys ? k : iterations - 1, this$1);
  34610. }
  34611. });
  34612. return iterations;
  34613. };
  34614. skipSequence.__iteratorUncached = function(type, reverse) {
  34615. var this$1 = this;
  34616. if (reverse) {
  34617. return this.cacheResult().__iterator(type, reverse);
  34618. }
  34619. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  34620. var skipping = true;
  34621. var iterations = 0;
  34622. return new Iterator(function () {
  34623. var step;
  34624. var k;
  34625. var v;
  34626. do {
  34627. step = iterator.next();
  34628. if (step.done) {
  34629. if (useKeys || type === ITERATE_VALUES) {
  34630. return step;
  34631. }
  34632. if (type === ITERATE_KEYS) {
  34633. return iteratorValue(type, iterations++, undefined, step);
  34634. }
  34635. return iteratorValue(type, iterations++, step.value[1], step);
  34636. }
  34637. var entry = step.value;
  34638. k = entry[0];
  34639. v = entry[1];
  34640. skipping && (skipping = predicate.call(context, v, k, this$1));
  34641. } while (skipping);
  34642. return type === ITERATE_ENTRIES ? step : iteratorValue(type, k, v, step);
  34643. });
  34644. };
  34645. return skipSequence;
  34646. }
  34647. function concatFactory(collection, values) {
  34648. var isKeyedCollection = isKeyed(collection);
  34649. var iters = [collection]
  34650. .concat(values)
  34651. .map(function (v) {
  34652. if (!isCollection(v)) {
  34653. v = isKeyedCollection
  34654. ? keyedSeqFromValue(v)
  34655. : indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  34656. } else if (isKeyedCollection) {
  34657. v = KeyedCollection(v);
  34658. }
  34659. return v;
  34660. })
  34661. .filter(function (v) { return v.size !== 0; });
  34662. if (iters.length === 0) {
  34663. return collection;
  34664. }
  34665. if (iters.length === 1) {
  34666. var singleton = iters[0];
  34667. if (
  34668. singleton === collection ||
  34669. (isKeyedCollection && isKeyed(singleton)) ||
  34670. (isIndexed(collection) && isIndexed(singleton))
  34671. ) {
  34672. return singleton;
  34673. }
  34674. }
  34675. var concatSeq = new ArraySeq(iters);
  34676. if (isKeyedCollection) {
  34677. concatSeq = concatSeq.toKeyedSeq();
  34678. } else if (!isIndexed(collection)) {
  34679. concatSeq = concatSeq.toSetSeq();
  34680. }
  34681. concatSeq = concatSeq.flatten(true);
  34682. concatSeq.size = iters.reduce(function (sum, seq) {
  34683. if (sum !== undefined) {
  34684. var size = seq.size;
  34685. if (size !== undefined) {
  34686. return sum + size;
  34687. }
  34688. }
  34689. }, 0);
  34690. return concatSeq;
  34691. }
  34692. function flattenFactory(collection, depth, useKeys) {
  34693. var flatSequence = makeSequence(collection);
  34694. flatSequence.__iterateUncached = function(fn, reverse) {
  34695. if (reverse) {
  34696. return this.cacheResult().__iterate(fn, reverse);
  34697. }
  34698. var iterations = 0;
  34699. var stopped = false;
  34700. function flatDeep(iter, currentDepth) {
  34701. iter.__iterate(function (v, k) {
  34702. if ((!depth || currentDepth < depth) && isCollection(v)) {
  34703. flatDeep(v, currentDepth + 1);
  34704. } else {
  34705. iterations++;
  34706. if (fn(v, useKeys ? k : iterations - 1, flatSequence) === false) {
  34707. stopped = true;
  34708. }
  34709. }
  34710. return !stopped;
  34711. }, reverse);
  34712. }
  34713. flatDeep(collection, 0);
  34714. return iterations;
  34715. };
  34716. flatSequence.__iteratorUncached = function(type, reverse) {
  34717. if (reverse) {
  34718. return this.cacheResult().__iterator(type, reverse);
  34719. }
  34720. var iterator = collection.__iterator(type, reverse);
  34721. var stack = [];
  34722. var iterations = 0;
  34723. return new Iterator(function () {
  34724. while (iterator) {
  34725. var step = iterator.next();
  34726. if (step.done !== false) {
  34727. iterator = stack.pop();
  34728. continue;
  34729. }
  34730. var v = step.value;
  34731. if (type === ITERATE_ENTRIES) {
  34732. v = v[1];
  34733. }
  34734. if ((!depth || stack.length < depth) && isCollection(v)) {
  34735. stack.push(iterator);
  34736. iterator = v.__iterator(type, reverse);
  34737. } else {
  34738. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  34739. }
  34740. }
  34741. return iteratorDone();
  34742. });
  34743. };
  34744. return flatSequence;
  34745. }
  34746. function flatMapFactory(collection, mapper, context) {
  34747. var coerce = collectionClass(collection);
  34748. return collection
  34749. .toSeq()
  34750. .map(function (v, k) { return coerce(mapper.call(context, v, k, collection)); })
  34751. .flatten(true);
  34752. }
  34753. function interposeFactory(collection, separator) {
  34754. var interposedSequence = makeSequence(collection);
  34755. interposedSequence.size = collection.size && collection.size * 2 - 1;
  34756. interposedSequence.__iterateUncached = function(fn, reverse) {
  34757. var this$1 = this;
  34758. var iterations = 0;
  34759. collection.__iterate(
  34760. function (v) { return (!iterations || fn(separator, iterations++, this$1) !== false) &&
  34761. fn(v, iterations++, this$1) !== false; },
  34762. reverse
  34763. );
  34764. return iterations;
  34765. };
  34766. interposedSequence.__iteratorUncached = function(type, reverse) {
  34767. var iterator = collection.__iterator(ITERATE_VALUES, reverse);
  34768. var iterations = 0;
  34769. var step;
  34770. return new Iterator(function () {
  34771. if (!step || iterations % 2) {
  34772. step = iterator.next();
  34773. if (step.done) {
  34774. return step;
  34775. }
  34776. }
  34777. return iterations % 2
  34778. ? iteratorValue(type, iterations++, separator)
  34779. : iteratorValue(type, iterations++, step.value, step);
  34780. });
  34781. };
  34782. return interposedSequence;
  34783. }
  34784. function sortFactory(collection, comparator, mapper) {
  34785. if (!comparator) {
  34786. comparator = defaultComparator;
  34787. }
  34788. var isKeyedCollection = isKeyed(collection);
  34789. var index = 0;
  34790. var entries = collection
  34791. .toSeq()
  34792. .map(function (v, k) { return [k, v, index++, mapper ? mapper(v, k, collection) : v]; })
  34793. .valueSeq()
  34794. .toArray();
  34795. entries.sort(function (a, b) { return comparator(a[3], b[3]) || a[2] - b[2]; }).forEach(
  34796. isKeyedCollection
  34797. ? function (v, i) {
  34798. entries[i].length = 2;
  34799. }
  34800. : function (v, i) {
  34801. entries[i] = v[1];
  34802. }
  34803. );
  34804. return isKeyedCollection
  34805. ? KeyedSeq(entries)
  34806. : isIndexed(collection)
  34807. ? IndexedSeq(entries)
  34808. : SetSeq(entries);
  34809. }
  34810. function maxFactory(collection, comparator, mapper) {
  34811. if (!comparator) {
  34812. comparator = defaultComparator;
  34813. }
  34814. if (mapper) {
  34815. var entry = collection
  34816. .toSeq()
  34817. .map(function (v, k) { return [v, mapper(v, k, collection)]; })
  34818. .reduce(function (a, b) { return (maxCompare(comparator, a[1], b[1]) ? b : a); });
  34819. return entry && entry[0];
  34820. }
  34821. return collection.reduce(function (a, b) { return (maxCompare(comparator, a, b) ? b : a); });
  34822. }
  34823. function maxCompare(comparator, a, b) {
  34824. var comp = comparator(b, a);
  34825. // b is considered the new max if the comparator declares them equal, but
  34826. // they are not equal and b is in fact a nullish value.
  34827. return (
  34828. (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) ||
  34829. comp > 0
  34830. );
  34831. }
  34832. function zipWithFactory(keyIter, zipper, iters, zipAll) {
  34833. var zipSequence = makeSequence(keyIter);
  34834. var sizes = new ArraySeq(iters).map(function (i) { return i.size; });
  34835. zipSequence.size = zipAll ? sizes.max() : sizes.min();
  34836. // Note: this a generic base implementation of __iterate in terms of
  34837. // __iterator which may be more generically useful in the future.
  34838. zipSequence.__iterate = function(fn, reverse) {
  34839. /* generic:
  34840. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  34841. var step;
  34842. var iterations = 0;
  34843. while (!(step = iterator.next()).done) {
  34844. iterations++;
  34845. if (fn(step.value[1], step.value[0], this) === false) {
  34846. break;
  34847. }
  34848. }
  34849. return iterations;
  34850. */
  34851. // indexed:
  34852. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  34853. var step;
  34854. var iterations = 0;
  34855. while (!(step = iterator.next()).done) {
  34856. if (fn(step.value, iterations++, this) === false) {
  34857. break;
  34858. }
  34859. }
  34860. return iterations;
  34861. };
  34862. zipSequence.__iteratorUncached = function(type, reverse) {
  34863. var iterators = iters.map(
  34864. function (i) { return ((i = Collection(i)), getIterator(reverse ? i.reverse() : i)); }
  34865. );
  34866. var iterations = 0;
  34867. var isDone = false;
  34868. return new Iterator(function () {
  34869. var steps;
  34870. if (!isDone) {
  34871. steps = iterators.map(function (i) { return i.next(); });
  34872. isDone = zipAll ? steps.every(function (s) { return s.done; }) : steps.some(function (s) { return s.done; });
  34873. }
  34874. if (isDone) {
  34875. return iteratorDone();
  34876. }
  34877. return iteratorValue(
  34878. type,
  34879. iterations++,
  34880. zipper.apply(null, steps.map(function (s) { return s.value; }))
  34881. );
  34882. });
  34883. };
  34884. return zipSequence;
  34885. }
  34886. // #pragma Helper Functions
  34887. function reify(iter, seq) {
  34888. return iter === seq ? iter : isSeq(iter) ? seq : iter.constructor(seq);
  34889. }
  34890. function validateEntry(entry) {
  34891. if (entry !== Object(entry)) {
  34892. throw new TypeError('Expected [K, V] tuple: ' + entry);
  34893. }
  34894. }
  34895. function collectionClass(collection) {
  34896. return isKeyed(collection)
  34897. ? KeyedCollection
  34898. : isIndexed(collection)
  34899. ? IndexedCollection
  34900. : SetCollection;
  34901. }
  34902. function makeSequence(collection) {
  34903. return Object.create(
  34904. (isKeyed(collection)
  34905. ? KeyedSeq
  34906. : isIndexed(collection)
  34907. ? IndexedSeq
  34908. : SetSeq
  34909. ).prototype
  34910. );
  34911. }
  34912. function cacheResultThrough() {
  34913. if (this._iter.cacheResult) {
  34914. this._iter.cacheResult();
  34915. this.size = this._iter.size;
  34916. return this;
  34917. }
  34918. return Seq.prototype.cacheResult.call(this);
  34919. }
  34920. function defaultComparator(a, b) {
  34921. if (a === undefined && b === undefined) {
  34922. return 0;
  34923. }
  34924. if (a === undefined) {
  34925. return 1;
  34926. }
  34927. if (b === undefined) {
  34928. return -1;
  34929. }
  34930. return a > b ? 1 : a < b ? -1 : 0;
  34931. }
  34932. // http://jsperf.com/copy-array-inline
  34933. function arrCopy(arr, offset) {
  34934. offset = offset || 0;
  34935. var len = Math.max(0, arr.length - offset);
  34936. var newArr = new Array(len);
  34937. for (var ii = 0; ii < len; ii++) {
  34938. newArr[ii] = arr[ii + offset];
  34939. }
  34940. return newArr;
  34941. }
  34942. function invariant(condition, error) {
  34943. if (!condition) { throw new Error(error); }
  34944. }
  34945. function assertNotInfinite(size) {
  34946. invariant(
  34947. size !== Infinity,
  34948. 'Cannot perform this action with an infinite size.'
  34949. );
  34950. }
  34951. function coerceKeyPath(keyPath) {
  34952. if (isArrayLike(keyPath) && typeof keyPath !== 'string') {
  34953. return keyPath;
  34954. }
  34955. if (isOrdered(keyPath)) {
  34956. return keyPath.toArray();
  34957. }
  34958. throw new TypeError(
  34959. 'Invalid keyPath: expected Ordered Collection or Array: ' + keyPath
  34960. );
  34961. }
  34962. function isPlainObj(value) {
  34963. return (
  34964. value &&
  34965. (typeof value.constructor !== 'function' ||
  34966. value.constructor.name === 'Object')
  34967. );
  34968. }
  34969. /**
  34970. * Returns true if the value is a potentially-persistent data structure, either
  34971. * provided by Immutable.js or a plain Array or Object.
  34972. */
  34973. function isDataStructure(value) {
  34974. return (
  34975. typeof value === 'object' &&
  34976. (isImmutable(value) || Array.isArray(value) || isPlainObj(value))
  34977. );
  34978. }
  34979. /**
  34980. * Converts a value to a string, adding quotes if a string was provided.
  34981. */
  34982. function quoteString(value) {
  34983. try {
  34984. return typeof value === 'string' ? JSON.stringify(value) : String(value);
  34985. } catch (_ignoreError) {
  34986. return JSON.stringify(value);
  34987. }
  34988. }
  34989. function has(collection, key) {
  34990. return isImmutable(collection)
  34991. ? collection.has(key)
  34992. : isDataStructure(collection) && hasOwnProperty.call(collection, key);
  34993. }
  34994. function get(collection, key, notSetValue) {
  34995. return isImmutable(collection)
  34996. ? collection.get(key, notSetValue)
  34997. : !has(collection, key)
  34998. ? notSetValue
  34999. : typeof collection.get === 'function'
  35000. ? collection.get(key)
  35001. : collection[key];
  35002. }
  35003. function shallowCopy(from) {
  35004. if (Array.isArray(from)) {
  35005. return arrCopy(from);
  35006. }
  35007. var to = {};
  35008. for (var key in from) {
  35009. if (hasOwnProperty.call(from, key)) {
  35010. to[key] = from[key];
  35011. }
  35012. }
  35013. return to;
  35014. }
  35015. function remove(collection, key) {
  35016. if (!isDataStructure(collection)) {
  35017. throw new TypeError(
  35018. 'Cannot update non-data-structure value: ' + collection
  35019. );
  35020. }
  35021. if (isImmutable(collection)) {
  35022. if (!collection.remove) {
  35023. throw new TypeError(
  35024. 'Cannot update immutable value without .remove() method: ' + collection
  35025. );
  35026. }
  35027. return collection.remove(key);
  35028. }
  35029. if (!hasOwnProperty.call(collection, key)) {
  35030. return collection;
  35031. }
  35032. var collectionCopy = shallowCopy(collection);
  35033. if (Array.isArray(collectionCopy)) {
  35034. collectionCopy.splice(key, 1);
  35035. } else {
  35036. delete collectionCopy[key];
  35037. }
  35038. return collectionCopy;
  35039. }
  35040. function set(collection, key, value) {
  35041. if (!isDataStructure(collection)) {
  35042. throw new TypeError(
  35043. 'Cannot update non-data-structure value: ' + collection
  35044. );
  35045. }
  35046. if (isImmutable(collection)) {
  35047. if (!collection.set) {
  35048. throw new TypeError(
  35049. 'Cannot update immutable value without .set() method: ' + collection
  35050. );
  35051. }
  35052. return collection.set(key, value);
  35053. }
  35054. if (hasOwnProperty.call(collection, key) && value === collection[key]) {
  35055. return collection;
  35056. }
  35057. var collectionCopy = shallowCopy(collection);
  35058. collectionCopy[key] = value;
  35059. return collectionCopy;
  35060. }
  35061. function updateIn(collection, keyPath, notSetValue, updater) {
  35062. if (!updater) {
  35063. updater = notSetValue;
  35064. notSetValue = undefined;
  35065. }
  35066. var updatedValue = updateInDeeply(
  35067. isImmutable(collection),
  35068. collection,
  35069. coerceKeyPath(keyPath),
  35070. 0,
  35071. notSetValue,
  35072. updater
  35073. );
  35074. return updatedValue === NOT_SET ? notSetValue : updatedValue;
  35075. }
  35076. function updateInDeeply(
  35077. inImmutable,
  35078. existing,
  35079. keyPath,
  35080. i,
  35081. notSetValue,
  35082. updater
  35083. ) {
  35084. var wasNotSet = existing === NOT_SET;
  35085. if (i === keyPath.length) {
  35086. var existingValue = wasNotSet ? notSetValue : existing;
  35087. var newValue = updater(existingValue);
  35088. return newValue === existingValue ? existing : newValue;
  35089. }
  35090. if (!wasNotSet && !isDataStructure(existing)) {
  35091. throw new TypeError(
  35092. 'Cannot update within non-data-structure value in path [' +
  35093. keyPath.slice(0, i).map(quoteString) +
  35094. ']: ' +
  35095. existing
  35096. );
  35097. }
  35098. var key = keyPath[i];
  35099. var nextExisting = wasNotSet ? NOT_SET : get(existing, key, NOT_SET);
  35100. var nextUpdated = updateInDeeply(
  35101. nextExisting === NOT_SET ? inImmutable : isImmutable(nextExisting),
  35102. nextExisting,
  35103. keyPath,
  35104. i + 1,
  35105. notSetValue,
  35106. updater
  35107. );
  35108. return nextUpdated === nextExisting
  35109. ? existing
  35110. : nextUpdated === NOT_SET
  35111. ? remove(existing, key)
  35112. : set(
  35113. wasNotSet ? (inImmutable ? emptyMap() : {}) : existing,
  35114. key,
  35115. nextUpdated
  35116. );
  35117. }
  35118. function setIn(collection, keyPath, value) {
  35119. return updateIn(collection, keyPath, NOT_SET, function () { return value; });
  35120. }
  35121. function setIn$1(keyPath, v) {
  35122. return setIn(this, keyPath, v);
  35123. }
  35124. function removeIn(collection, keyPath) {
  35125. return updateIn(collection, keyPath, function () { return NOT_SET; });
  35126. }
  35127. function deleteIn(keyPath) {
  35128. return removeIn(this, keyPath);
  35129. }
  35130. function update(collection, key, notSetValue, updater) {
  35131. return updateIn(collection, [key], notSetValue, updater);
  35132. }
  35133. function update$1(key, notSetValue, updater) {
  35134. return arguments.length === 1
  35135. ? key(this)
  35136. : update(this, key, notSetValue, updater);
  35137. }
  35138. function updateIn$1(keyPath, notSetValue, updater) {
  35139. return updateIn(this, keyPath, notSetValue, updater);
  35140. }
  35141. function merge() {
  35142. var iters = [], len = arguments.length;
  35143. while ( len-- ) iters[ len ] = arguments[ len ];
  35144. return mergeIntoKeyedWith(this, iters);
  35145. }
  35146. function mergeWith(merger) {
  35147. var iters = [], len = arguments.length - 1;
  35148. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  35149. if (typeof merger !== 'function') {
  35150. throw new TypeError('Invalid merger function: ' + merger);
  35151. }
  35152. return mergeIntoKeyedWith(this, iters, merger);
  35153. }
  35154. function mergeIntoKeyedWith(collection, collections, merger) {
  35155. var iters = [];
  35156. for (var ii = 0; ii < collections.length; ii++) {
  35157. var collection$1 = KeyedCollection(collections[ii]);
  35158. if (collection$1.size !== 0) {
  35159. iters.push(collection$1);
  35160. }
  35161. }
  35162. if (iters.length === 0) {
  35163. return collection;
  35164. }
  35165. if (
  35166. collection.toSeq().size === 0 &&
  35167. !collection.__ownerID &&
  35168. iters.length === 1
  35169. ) {
  35170. return collection.constructor(iters[0]);
  35171. }
  35172. return collection.withMutations(function (collection) {
  35173. var mergeIntoCollection = merger
  35174. ? function (value, key) {
  35175. update(
  35176. collection,
  35177. key,
  35178. NOT_SET,
  35179. function (oldVal) { return (oldVal === NOT_SET ? value : merger(oldVal, value, key)); }
  35180. );
  35181. }
  35182. : function (value, key) {
  35183. collection.set(key, value);
  35184. };
  35185. for (var ii = 0; ii < iters.length; ii++) {
  35186. iters[ii].forEach(mergeIntoCollection);
  35187. }
  35188. });
  35189. }
  35190. function merge$1(collection) {
  35191. var sources = [], len = arguments.length - 1;
  35192. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  35193. return mergeWithSources(collection, sources);
  35194. }
  35195. function mergeWith$1(merger, collection) {
  35196. var sources = [], len = arguments.length - 2;
  35197. while ( len-- > 0 ) sources[ len ] = arguments[ len + 2 ];
  35198. return mergeWithSources(collection, sources, merger);
  35199. }
  35200. function mergeDeep(collection) {
  35201. var sources = [], len = arguments.length - 1;
  35202. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  35203. return mergeDeepWithSources(collection, sources);
  35204. }
  35205. function mergeDeepWith(merger, collection) {
  35206. var sources = [], len = arguments.length - 2;
  35207. while ( len-- > 0 ) sources[ len ] = arguments[ len + 2 ];
  35208. return mergeDeepWithSources(collection, sources, merger);
  35209. }
  35210. function mergeDeepWithSources(collection, sources, merger) {
  35211. return mergeWithSources(collection, sources, deepMergerWith(merger));
  35212. }
  35213. function mergeWithSources(collection, sources, merger) {
  35214. if (!isDataStructure(collection)) {
  35215. throw new TypeError(
  35216. 'Cannot merge into non-data-structure value: ' + collection
  35217. );
  35218. }
  35219. if (isImmutable(collection)) {
  35220. return typeof merger === 'function' && collection.mergeWith
  35221. ? collection.mergeWith.apply(collection, [ merger ].concat( sources ))
  35222. : collection.merge
  35223. ? collection.merge.apply(collection, sources)
  35224. : collection.concat.apply(collection, sources);
  35225. }
  35226. var isArray = Array.isArray(collection);
  35227. var merged = collection;
  35228. var Collection$$1 = isArray ? IndexedCollection : KeyedCollection;
  35229. var mergeItem = isArray
  35230. ? function (value) {
  35231. // Copy on write
  35232. if (merged === collection) {
  35233. merged = shallowCopy(merged);
  35234. }
  35235. merged.push(value);
  35236. }
  35237. : function (value, key) {
  35238. var hasVal = hasOwnProperty.call(merged, key);
  35239. var nextVal =
  35240. hasVal && merger ? merger(merged[key], value, key) : value;
  35241. if (!hasVal || nextVal !== merged[key]) {
  35242. // Copy on write
  35243. if (merged === collection) {
  35244. merged = shallowCopy(merged);
  35245. }
  35246. merged[key] = nextVal;
  35247. }
  35248. };
  35249. for (var i = 0; i < sources.length; i++) {
  35250. Collection$$1(sources[i]).forEach(mergeItem);
  35251. }
  35252. return merged;
  35253. }
  35254. function deepMergerWith(merger) {
  35255. function deepMerger(oldValue, newValue, key) {
  35256. return isDataStructure(oldValue) && isDataStructure(newValue)
  35257. ? mergeWithSources(oldValue, [newValue], deepMerger)
  35258. : merger
  35259. ? merger(oldValue, newValue, key)
  35260. : newValue;
  35261. }
  35262. return deepMerger;
  35263. }
  35264. function mergeDeep$1() {
  35265. var iters = [], len = arguments.length;
  35266. while ( len-- ) iters[ len ] = arguments[ len ];
  35267. return mergeDeepWithSources(this, iters);
  35268. }
  35269. function mergeDeepWith$1(merger) {
  35270. var iters = [], len = arguments.length - 1;
  35271. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  35272. return mergeDeepWithSources(this, iters, merger);
  35273. }
  35274. function mergeIn(keyPath) {
  35275. var iters = [], len = arguments.length - 1;
  35276. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  35277. return updateIn(this, keyPath, emptyMap(), function (m) { return mergeWithSources(m, iters); });
  35278. }
  35279. function mergeDeepIn(keyPath) {
  35280. var iters = [], len = arguments.length - 1;
  35281. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  35282. return updateIn(this, keyPath, emptyMap(), function (m) { return mergeDeepWithSources(m, iters); }
  35283. );
  35284. }
  35285. function withMutations(fn) {
  35286. var mutable = this.asMutable();
  35287. fn(mutable);
  35288. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  35289. }
  35290. function asMutable() {
  35291. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  35292. }
  35293. function asImmutable() {
  35294. return this.__ensureOwner();
  35295. }
  35296. function wasAltered() {
  35297. return this.__altered;
  35298. }
  35299. var Map = /*@__PURE__*/(function (KeyedCollection$$1) {
  35300. function Map(value) {
  35301. return value === null || value === undefined
  35302. ? emptyMap()
  35303. : isMap(value) && !isOrdered(value)
  35304. ? value
  35305. : emptyMap().withMutations(function (map) {
  35306. var iter = KeyedCollection$$1(value);
  35307. assertNotInfinite(iter.size);
  35308. iter.forEach(function (v, k) { return map.set(k, v); });
  35309. });
  35310. }
  35311. if ( KeyedCollection$$1 ) Map.__proto__ = KeyedCollection$$1;
  35312. Map.prototype = Object.create( KeyedCollection$$1 && KeyedCollection$$1.prototype );
  35313. Map.prototype.constructor = Map;
  35314. Map.of = function of () {
  35315. var keyValues = [], len = arguments.length;
  35316. while ( len-- ) keyValues[ len ] = arguments[ len ];
  35317. return emptyMap().withMutations(function (map) {
  35318. for (var i = 0; i < keyValues.length; i += 2) {
  35319. if (i + 1 >= keyValues.length) {
  35320. throw new Error('Missing value for key: ' + keyValues[i]);
  35321. }
  35322. map.set(keyValues[i], keyValues[i + 1]);
  35323. }
  35324. });
  35325. };
  35326. Map.prototype.toString = function toString () {
  35327. return this.__toString('Map {', '}');
  35328. };
  35329. // @pragma Access
  35330. Map.prototype.get = function get (k, notSetValue) {
  35331. return this._root
  35332. ? this._root.get(0, undefined, k, notSetValue)
  35333. : notSetValue;
  35334. };
  35335. // @pragma Modification
  35336. Map.prototype.set = function set (k, v) {
  35337. return updateMap(this, k, v);
  35338. };
  35339. Map.prototype.remove = function remove (k) {
  35340. return updateMap(this, k, NOT_SET);
  35341. };
  35342. Map.prototype.deleteAll = function deleteAll (keys) {
  35343. var collection = Collection(keys);
  35344. if (collection.size === 0) {
  35345. return this;
  35346. }
  35347. return this.withMutations(function (map) {
  35348. collection.forEach(function (key) { return map.remove(key); });
  35349. });
  35350. };
  35351. Map.prototype.clear = function clear () {
  35352. if (this.size === 0) {
  35353. return this;
  35354. }
  35355. if (this.__ownerID) {
  35356. this.size = 0;
  35357. this._root = null;
  35358. this.__hash = undefined;
  35359. this.__altered = true;
  35360. return this;
  35361. }
  35362. return emptyMap();
  35363. };
  35364. // @pragma Composition
  35365. Map.prototype.sort = function sort (comparator) {
  35366. // Late binding
  35367. return OrderedMap(sortFactory(this, comparator));
  35368. };
  35369. Map.prototype.sortBy = function sortBy (mapper, comparator) {
  35370. // Late binding
  35371. return OrderedMap(sortFactory(this, comparator, mapper));
  35372. };
  35373. Map.prototype.map = function map (mapper, context) {
  35374. return this.withMutations(function (map) {
  35375. map.forEach(function (value, key) {
  35376. map.set(key, mapper.call(context, value, key, map));
  35377. });
  35378. });
  35379. };
  35380. // @pragma Mutability
  35381. Map.prototype.__iterator = function __iterator (type, reverse) {
  35382. return new MapIterator(this, type, reverse);
  35383. };
  35384. Map.prototype.__iterate = function __iterate (fn, reverse) {
  35385. var this$1 = this;
  35386. var iterations = 0;
  35387. this._root &&
  35388. this._root.iterate(function (entry) {
  35389. iterations++;
  35390. return fn(entry[1], entry[0], this$1);
  35391. }, reverse);
  35392. return iterations;
  35393. };
  35394. Map.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  35395. if (ownerID === this.__ownerID) {
  35396. return this;
  35397. }
  35398. if (!ownerID) {
  35399. if (this.size === 0) {
  35400. return emptyMap();
  35401. }
  35402. this.__ownerID = ownerID;
  35403. this.__altered = false;
  35404. return this;
  35405. }
  35406. return makeMap(this.size, this._root, ownerID, this.__hash);
  35407. };
  35408. return Map;
  35409. }(KeyedCollection));
  35410. Map.isMap = isMap;
  35411. var MapPrototype = Map.prototype;
  35412. MapPrototype[IS_MAP_SYMBOL] = true;
  35413. MapPrototype[DELETE] = MapPrototype.remove;
  35414. MapPrototype.removeAll = MapPrototype.deleteAll;
  35415. MapPrototype.setIn = setIn$1;
  35416. MapPrototype.removeIn = MapPrototype.deleteIn = deleteIn;
  35417. MapPrototype.update = update$1;
  35418. MapPrototype.updateIn = updateIn$1;
  35419. MapPrototype.merge = MapPrototype.concat = merge;
  35420. MapPrototype.mergeWith = mergeWith;
  35421. MapPrototype.mergeDeep = mergeDeep$1;
  35422. MapPrototype.mergeDeepWith = mergeDeepWith$1;
  35423. MapPrototype.mergeIn = mergeIn;
  35424. MapPrototype.mergeDeepIn = mergeDeepIn;
  35425. MapPrototype.withMutations = withMutations;
  35426. MapPrototype.wasAltered = wasAltered;
  35427. MapPrototype.asImmutable = asImmutable;
  35428. MapPrototype['@@transducer/init'] = MapPrototype.asMutable = asMutable;
  35429. MapPrototype['@@transducer/step'] = function(result, arr) {
  35430. return result.set(arr[0], arr[1]);
  35431. };
  35432. MapPrototype['@@transducer/result'] = function(obj) {
  35433. return obj.asImmutable();
  35434. };
  35435. // #pragma Trie Nodes
  35436. var ArrayMapNode = function ArrayMapNode(ownerID, entries) {
  35437. this.ownerID = ownerID;
  35438. this.entries = entries;
  35439. };
  35440. ArrayMapNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  35441. var entries = this.entries;
  35442. for (var ii = 0, len = entries.length; ii < len; ii++) {
  35443. if (is(key, entries[ii][0])) {
  35444. return entries[ii][1];
  35445. }
  35446. }
  35447. return notSetValue;
  35448. };
  35449. ArrayMapNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  35450. var removed = value === NOT_SET;
  35451. var entries = this.entries;
  35452. var idx = 0;
  35453. var len = entries.length;
  35454. for (; idx < len; idx++) {
  35455. if (is(key, entries[idx][0])) {
  35456. break;
  35457. }
  35458. }
  35459. var exists = idx < len;
  35460. if (exists ? entries[idx][1] === value : removed) {
  35461. return this;
  35462. }
  35463. SetRef(didAlter);
  35464. (removed || !exists) && SetRef(didChangeSize);
  35465. if (removed && entries.length === 1) {
  35466. return; // undefined
  35467. }
  35468. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  35469. return createNodes(ownerID, entries, key, value);
  35470. }
  35471. var isEditable = ownerID && ownerID === this.ownerID;
  35472. var newEntries = isEditable ? entries : arrCopy(entries);
  35473. if (exists) {
  35474. if (removed) {
  35475. idx === len - 1
  35476. ? newEntries.pop()
  35477. : (newEntries[idx] = newEntries.pop());
  35478. } else {
  35479. newEntries[idx] = [key, value];
  35480. }
  35481. } else {
  35482. newEntries.push([key, value]);
  35483. }
  35484. if (isEditable) {
  35485. this.entries = newEntries;
  35486. return this;
  35487. }
  35488. return new ArrayMapNode(ownerID, newEntries);
  35489. };
  35490. var BitmapIndexedNode = function BitmapIndexedNode(ownerID, bitmap, nodes) {
  35491. this.ownerID = ownerID;
  35492. this.bitmap = bitmap;
  35493. this.nodes = nodes;
  35494. };
  35495. BitmapIndexedNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  35496. if (keyHash === undefined) {
  35497. keyHash = hash(key);
  35498. }
  35499. var bit = 1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK);
  35500. var bitmap = this.bitmap;
  35501. return (bitmap & bit) === 0
  35502. ? notSetValue
  35503. : this.nodes[popCount(bitmap & (bit - 1))].get(
  35504. shift + SHIFT,
  35505. keyHash,
  35506. key,
  35507. notSetValue
  35508. );
  35509. };
  35510. BitmapIndexedNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  35511. if (keyHash === undefined) {
  35512. keyHash = hash(key);
  35513. }
  35514. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  35515. var bit = 1 << keyHashFrag;
  35516. var bitmap = this.bitmap;
  35517. var exists = (bitmap & bit) !== 0;
  35518. if (!exists && value === NOT_SET) {
  35519. return this;
  35520. }
  35521. var idx = popCount(bitmap & (bit - 1));
  35522. var nodes = this.nodes;
  35523. var node = exists ? nodes[idx] : undefined;
  35524. var newNode = updateNode(
  35525. node,
  35526. ownerID,
  35527. shift + SHIFT,
  35528. keyHash,
  35529. key,
  35530. value,
  35531. didChangeSize,
  35532. didAlter
  35533. );
  35534. if (newNode === node) {
  35535. return this;
  35536. }
  35537. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  35538. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  35539. }
  35540. if (
  35541. exists &&
  35542. !newNode &&
  35543. nodes.length === 2 &&
  35544. isLeafNode(nodes[idx ^ 1])
  35545. ) {
  35546. return nodes[idx ^ 1];
  35547. }
  35548. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  35549. return newNode;
  35550. }
  35551. var isEditable = ownerID && ownerID === this.ownerID;
  35552. var newBitmap = exists ? (newNode ? bitmap : bitmap ^ bit) : bitmap | bit;
  35553. var newNodes = exists
  35554. ? newNode
  35555. ? setAt(nodes, idx, newNode, isEditable)
  35556. : spliceOut(nodes, idx, isEditable)
  35557. : spliceIn(nodes, idx, newNode, isEditable);
  35558. if (isEditable) {
  35559. this.bitmap = newBitmap;
  35560. this.nodes = newNodes;
  35561. return this;
  35562. }
  35563. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  35564. };
  35565. var HashArrayMapNode = function HashArrayMapNode(ownerID, count, nodes) {
  35566. this.ownerID = ownerID;
  35567. this.count = count;
  35568. this.nodes = nodes;
  35569. };
  35570. HashArrayMapNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  35571. if (keyHash === undefined) {
  35572. keyHash = hash(key);
  35573. }
  35574. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  35575. var node = this.nodes[idx];
  35576. return node
  35577. ? node.get(shift + SHIFT, keyHash, key, notSetValue)
  35578. : notSetValue;
  35579. };
  35580. HashArrayMapNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  35581. if (keyHash === undefined) {
  35582. keyHash = hash(key);
  35583. }
  35584. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  35585. var removed = value === NOT_SET;
  35586. var nodes = this.nodes;
  35587. var node = nodes[idx];
  35588. if (removed && !node) {
  35589. return this;
  35590. }
  35591. var newNode = updateNode(
  35592. node,
  35593. ownerID,
  35594. shift + SHIFT,
  35595. keyHash,
  35596. key,
  35597. value,
  35598. didChangeSize,
  35599. didAlter
  35600. );
  35601. if (newNode === node) {
  35602. return this;
  35603. }
  35604. var newCount = this.count;
  35605. if (!node) {
  35606. newCount++;
  35607. } else if (!newNode) {
  35608. newCount--;
  35609. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  35610. return packNodes(ownerID, nodes, newCount, idx);
  35611. }
  35612. }
  35613. var isEditable = ownerID && ownerID === this.ownerID;
  35614. var newNodes = setAt(nodes, idx, newNode, isEditable);
  35615. if (isEditable) {
  35616. this.count = newCount;
  35617. this.nodes = newNodes;
  35618. return this;
  35619. }
  35620. return new HashArrayMapNode(ownerID, newCount, newNodes);
  35621. };
  35622. var HashCollisionNode = function HashCollisionNode(ownerID, keyHash, entries) {
  35623. this.ownerID = ownerID;
  35624. this.keyHash = keyHash;
  35625. this.entries = entries;
  35626. };
  35627. HashCollisionNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  35628. var entries = this.entries;
  35629. for (var ii = 0, len = entries.length; ii < len; ii++) {
  35630. if (is(key, entries[ii][0])) {
  35631. return entries[ii][1];
  35632. }
  35633. }
  35634. return notSetValue;
  35635. };
  35636. HashCollisionNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  35637. if (keyHash === undefined) {
  35638. keyHash = hash(key);
  35639. }
  35640. var removed = value === NOT_SET;
  35641. if (keyHash !== this.keyHash) {
  35642. if (removed) {
  35643. return this;
  35644. }
  35645. SetRef(didAlter);
  35646. SetRef(didChangeSize);
  35647. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  35648. }
  35649. var entries = this.entries;
  35650. var idx = 0;
  35651. var len = entries.length;
  35652. for (; idx < len; idx++) {
  35653. if (is(key, entries[idx][0])) {
  35654. break;
  35655. }
  35656. }
  35657. var exists = idx < len;
  35658. if (exists ? entries[idx][1] === value : removed) {
  35659. return this;
  35660. }
  35661. SetRef(didAlter);
  35662. (removed || !exists) && SetRef(didChangeSize);
  35663. if (removed && len === 2) {
  35664. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  35665. }
  35666. var isEditable = ownerID && ownerID === this.ownerID;
  35667. var newEntries = isEditable ? entries : arrCopy(entries);
  35668. if (exists) {
  35669. if (removed) {
  35670. idx === len - 1
  35671. ? newEntries.pop()
  35672. : (newEntries[idx] = newEntries.pop());
  35673. } else {
  35674. newEntries[idx] = [key, value];
  35675. }
  35676. } else {
  35677. newEntries.push([key, value]);
  35678. }
  35679. if (isEditable) {
  35680. this.entries = newEntries;
  35681. return this;
  35682. }
  35683. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  35684. };
  35685. var ValueNode = function ValueNode(ownerID, keyHash, entry) {
  35686. this.ownerID = ownerID;
  35687. this.keyHash = keyHash;
  35688. this.entry = entry;
  35689. };
  35690. ValueNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  35691. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  35692. };
  35693. ValueNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  35694. var removed = value === NOT_SET;
  35695. var keyMatch = is(key, this.entry[0]);
  35696. if (keyMatch ? value === this.entry[1] : removed) {
  35697. return this;
  35698. }
  35699. SetRef(didAlter);
  35700. if (removed) {
  35701. SetRef(didChangeSize);
  35702. return; // undefined
  35703. }
  35704. if (keyMatch) {
  35705. if (ownerID && ownerID === this.ownerID) {
  35706. this.entry[1] = value;
  35707. return this;
  35708. }
  35709. return new ValueNode(ownerID, this.keyHash, [key, value]);
  35710. }
  35711. SetRef(didChangeSize);
  35712. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  35713. };
  35714. // #pragma Iterators
  35715. ArrayMapNode.prototype.iterate = HashCollisionNode.prototype.iterate = function(
  35716. fn,
  35717. reverse
  35718. ) {
  35719. var entries = this.entries;
  35720. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  35721. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  35722. return false;
  35723. }
  35724. }
  35725. };
  35726. BitmapIndexedNode.prototype.iterate = HashArrayMapNode.prototype.iterate = function(
  35727. fn,
  35728. reverse
  35729. ) {
  35730. var nodes = this.nodes;
  35731. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  35732. var node = nodes[reverse ? maxIndex - ii : ii];
  35733. if (node && node.iterate(fn, reverse) === false) {
  35734. return false;
  35735. }
  35736. }
  35737. };
  35738. // eslint-disable-next-line no-unused-vars
  35739. ValueNode.prototype.iterate = function(fn, reverse) {
  35740. return fn(this.entry);
  35741. };
  35742. var MapIterator = /*@__PURE__*/(function (Iterator$$1) {
  35743. function MapIterator(map, type, reverse) {
  35744. this._type = type;
  35745. this._reverse = reverse;
  35746. this._stack = map._root && mapIteratorFrame(map._root);
  35747. }
  35748. if ( Iterator$$1 ) MapIterator.__proto__ = Iterator$$1;
  35749. MapIterator.prototype = Object.create( Iterator$$1 && Iterator$$1.prototype );
  35750. MapIterator.prototype.constructor = MapIterator;
  35751. MapIterator.prototype.next = function next () {
  35752. var type = this._type;
  35753. var stack = this._stack;
  35754. while (stack) {
  35755. var node = stack.node;
  35756. var index = stack.index++;
  35757. var maxIndex = (void 0);
  35758. if (node.entry) {
  35759. if (index === 0) {
  35760. return mapIteratorValue(type, node.entry);
  35761. }
  35762. } else if (node.entries) {
  35763. maxIndex = node.entries.length - 1;
  35764. if (index <= maxIndex) {
  35765. return mapIteratorValue(
  35766. type,
  35767. node.entries[this._reverse ? maxIndex - index : index]
  35768. );
  35769. }
  35770. } else {
  35771. maxIndex = node.nodes.length - 1;
  35772. if (index <= maxIndex) {
  35773. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  35774. if (subNode) {
  35775. if (subNode.entry) {
  35776. return mapIteratorValue(type, subNode.entry);
  35777. }
  35778. stack = this._stack = mapIteratorFrame(subNode, stack);
  35779. }
  35780. continue;
  35781. }
  35782. }
  35783. stack = this._stack = this._stack.__prev;
  35784. }
  35785. return iteratorDone();
  35786. };
  35787. return MapIterator;
  35788. }(Iterator));
  35789. function mapIteratorValue(type, entry) {
  35790. return iteratorValue(type, entry[0], entry[1]);
  35791. }
  35792. function mapIteratorFrame(node, prev) {
  35793. return {
  35794. node: node,
  35795. index: 0,
  35796. __prev: prev,
  35797. };
  35798. }
  35799. function makeMap(size, root, ownerID, hash$$1) {
  35800. var map = Object.create(MapPrototype);
  35801. map.size = size;
  35802. map._root = root;
  35803. map.__ownerID = ownerID;
  35804. map.__hash = hash$$1;
  35805. map.__altered = false;
  35806. return map;
  35807. }
  35808. var EMPTY_MAP;
  35809. function emptyMap() {
  35810. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  35811. }
  35812. function updateMap(map, k, v) {
  35813. var newRoot;
  35814. var newSize;
  35815. if (!map._root) {
  35816. if (v === NOT_SET) {
  35817. return map;
  35818. }
  35819. newSize = 1;
  35820. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  35821. } else {
  35822. var didChangeSize = MakeRef();
  35823. var didAlter = MakeRef();
  35824. newRoot = updateNode(
  35825. map._root,
  35826. map.__ownerID,
  35827. 0,
  35828. undefined,
  35829. k,
  35830. v,
  35831. didChangeSize,
  35832. didAlter
  35833. );
  35834. if (!didAlter.value) {
  35835. return map;
  35836. }
  35837. newSize = map.size + (didChangeSize.value ? (v === NOT_SET ? -1 : 1) : 0);
  35838. }
  35839. if (map.__ownerID) {
  35840. map.size = newSize;
  35841. map._root = newRoot;
  35842. map.__hash = undefined;
  35843. map.__altered = true;
  35844. return map;
  35845. }
  35846. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  35847. }
  35848. function updateNode(
  35849. node,
  35850. ownerID,
  35851. shift,
  35852. keyHash,
  35853. key,
  35854. value,
  35855. didChangeSize,
  35856. didAlter
  35857. ) {
  35858. if (!node) {
  35859. if (value === NOT_SET) {
  35860. return node;
  35861. }
  35862. SetRef(didAlter);
  35863. SetRef(didChangeSize);
  35864. return new ValueNode(ownerID, keyHash, [key, value]);
  35865. }
  35866. return node.update(
  35867. ownerID,
  35868. shift,
  35869. keyHash,
  35870. key,
  35871. value,
  35872. didChangeSize,
  35873. didAlter
  35874. );
  35875. }
  35876. function isLeafNode(node) {
  35877. return (
  35878. node.constructor === ValueNode || node.constructor === HashCollisionNode
  35879. );
  35880. }
  35881. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  35882. if (node.keyHash === keyHash) {
  35883. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  35884. }
  35885. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  35886. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  35887. var newNode;
  35888. var nodes =
  35889. idx1 === idx2
  35890. ? [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)]
  35891. : ((newNode = new ValueNode(ownerID, keyHash, entry)),
  35892. idx1 < idx2 ? [node, newNode] : [newNode, node]);
  35893. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  35894. }
  35895. function createNodes(ownerID, entries, key, value) {
  35896. if (!ownerID) {
  35897. ownerID = new OwnerID();
  35898. }
  35899. var node = new ValueNode(ownerID, hash(key), [key, value]);
  35900. for (var ii = 0; ii < entries.length; ii++) {
  35901. var entry = entries[ii];
  35902. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  35903. }
  35904. return node;
  35905. }
  35906. function packNodes(ownerID, nodes, count, excluding) {
  35907. var bitmap = 0;
  35908. var packedII = 0;
  35909. var packedNodes = new Array(count);
  35910. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  35911. var node = nodes[ii];
  35912. if (node !== undefined && ii !== excluding) {
  35913. bitmap |= bit;
  35914. packedNodes[packedII++] = node;
  35915. }
  35916. }
  35917. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  35918. }
  35919. function expandNodes(ownerID, nodes, bitmap, including, node) {
  35920. var count = 0;
  35921. var expandedNodes = new Array(SIZE);
  35922. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  35923. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  35924. }
  35925. expandedNodes[including] = node;
  35926. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  35927. }
  35928. function popCount(x) {
  35929. x -= (x >> 1) & 0x55555555;
  35930. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  35931. x = (x + (x >> 4)) & 0x0f0f0f0f;
  35932. x += x >> 8;
  35933. x += x >> 16;
  35934. return x & 0x7f;
  35935. }
  35936. function setAt(array, idx, val, canEdit) {
  35937. var newArray = canEdit ? array : arrCopy(array);
  35938. newArray[idx] = val;
  35939. return newArray;
  35940. }
  35941. function spliceIn(array, idx, val, canEdit) {
  35942. var newLen = array.length + 1;
  35943. if (canEdit && idx + 1 === newLen) {
  35944. array[idx] = val;
  35945. return array;
  35946. }
  35947. var newArray = new Array(newLen);
  35948. var after = 0;
  35949. for (var ii = 0; ii < newLen; ii++) {
  35950. if (ii === idx) {
  35951. newArray[ii] = val;
  35952. after = -1;
  35953. } else {
  35954. newArray[ii] = array[ii + after];
  35955. }
  35956. }
  35957. return newArray;
  35958. }
  35959. function spliceOut(array, idx, canEdit) {
  35960. var newLen = array.length - 1;
  35961. if (canEdit && idx === newLen) {
  35962. array.pop();
  35963. return array;
  35964. }
  35965. var newArray = new Array(newLen);
  35966. var after = 0;
  35967. for (var ii = 0; ii < newLen; ii++) {
  35968. if (ii === idx) {
  35969. after = 1;
  35970. }
  35971. newArray[ii] = array[ii + after];
  35972. }
  35973. return newArray;
  35974. }
  35975. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  35976. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  35977. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  35978. var IS_LIST_SYMBOL = '@@__IMMUTABLE_LIST__@@';
  35979. function isList(maybeList) {
  35980. return Boolean(maybeList && maybeList[IS_LIST_SYMBOL]);
  35981. }
  35982. var List = /*@__PURE__*/(function (IndexedCollection$$1) {
  35983. function List(value) {
  35984. var empty = emptyList();
  35985. if (value === null || value === undefined) {
  35986. return empty;
  35987. }
  35988. if (isList(value)) {
  35989. return value;
  35990. }
  35991. var iter = IndexedCollection$$1(value);
  35992. var size = iter.size;
  35993. if (size === 0) {
  35994. return empty;
  35995. }
  35996. assertNotInfinite(size);
  35997. if (size > 0 && size < SIZE) {
  35998. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  35999. }
  36000. return empty.withMutations(function (list) {
  36001. list.setSize(size);
  36002. iter.forEach(function (v, i) { return list.set(i, v); });
  36003. });
  36004. }
  36005. if ( IndexedCollection$$1 ) List.__proto__ = IndexedCollection$$1;
  36006. List.prototype = Object.create( IndexedCollection$$1 && IndexedCollection$$1.prototype );
  36007. List.prototype.constructor = List;
  36008. List.of = function of (/*...values*/) {
  36009. return this(arguments);
  36010. };
  36011. List.prototype.toString = function toString () {
  36012. return this.__toString('List [', ']');
  36013. };
  36014. // @pragma Access
  36015. List.prototype.get = function get (index, notSetValue) {
  36016. index = wrapIndex(this, index);
  36017. if (index >= 0 && index < this.size) {
  36018. index += this._origin;
  36019. var node = listNodeFor(this, index);
  36020. return node && node.array[index & MASK];
  36021. }
  36022. return notSetValue;
  36023. };
  36024. // @pragma Modification
  36025. List.prototype.set = function set (index, value) {
  36026. return updateList(this, index, value);
  36027. };
  36028. List.prototype.remove = function remove (index) {
  36029. return !this.has(index)
  36030. ? this
  36031. : index === 0
  36032. ? this.shift()
  36033. : index === this.size - 1
  36034. ? this.pop()
  36035. : this.splice(index, 1);
  36036. };
  36037. List.prototype.insert = function insert (index, value) {
  36038. return this.splice(index, 0, value);
  36039. };
  36040. List.prototype.clear = function clear () {
  36041. if (this.size === 0) {
  36042. return this;
  36043. }
  36044. if (this.__ownerID) {
  36045. this.size = this._origin = this._capacity = 0;
  36046. this._level = SHIFT;
  36047. this._root = this._tail = null;
  36048. this.__hash = undefined;
  36049. this.__altered = true;
  36050. return this;
  36051. }
  36052. return emptyList();
  36053. };
  36054. List.prototype.push = function push (/*...values*/) {
  36055. var values = arguments;
  36056. var oldSize = this.size;
  36057. return this.withMutations(function (list) {
  36058. setListBounds(list, 0, oldSize + values.length);
  36059. for (var ii = 0; ii < values.length; ii++) {
  36060. list.set(oldSize + ii, values[ii]);
  36061. }
  36062. });
  36063. };
  36064. List.prototype.pop = function pop () {
  36065. return setListBounds(this, 0, -1);
  36066. };
  36067. List.prototype.unshift = function unshift (/*...values*/) {
  36068. var values = arguments;
  36069. return this.withMutations(function (list) {
  36070. setListBounds(list, -values.length);
  36071. for (var ii = 0; ii < values.length; ii++) {
  36072. list.set(ii, values[ii]);
  36073. }
  36074. });
  36075. };
  36076. List.prototype.shift = function shift () {
  36077. return setListBounds(this, 1);
  36078. };
  36079. // @pragma Composition
  36080. List.prototype.concat = function concat (/*...collections*/) {
  36081. var arguments$1 = arguments;
  36082. var seqs = [];
  36083. for (var i = 0; i < arguments.length; i++) {
  36084. var argument = arguments$1[i];
  36085. var seq = IndexedCollection$$1(
  36086. typeof argument !== 'string' && hasIterator(argument)
  36087. ? argument
  36088. : [argument]
  36089. );
  36090. if (seq.size !== 0) {
  36091. seqs.push(seq);
  36092. }
  36093. }
  36094. if (seqs.length === 0) {
  36095. return this;
  36096. }
  36097. if (this.size === 0 && !this.__ownerID && seqs.length === 1) {
  36098. return this.constructor(seqs[0]);
  36099. }
  36100. return this.withMutations(function (list) {
  36101. seqs.forEach(function (seq) { return seq.forEach(function (value) { return list.push(value); }); });
  36102. });
  36103. };
  36104. List.prototype.setSize = function setSize (size) {
  36105. return setListBounds(this, 0, size);
  36106. };
  36107. List.prototype.map = function map (mapper, context) {
  36108. var this$1 = this;
  36109. return this.withMutations(function (list) {
  36110. for (var i = 0; i < this$1.size; i++) {
  36111. list.set(i, mapper.call(context, list.get(i), i, list));
  36112. }
  36113. });
  36114. };
  36115. // @pragma Iteration
  36116. List.prototype.slice = function slice (begin, end) {
  36117. var size = this.size;
  36118. if (wholeSlice(begin, end, size)) {
  36119. return this;
  36120. }
  36121. return setListBounds(
  36122. this,
  36123. resolveBegin(begin, size),
  36124. resolveEnd(end, size)
  36125. );
  36126. };
  36127. List.prototype.__iterator = function __iterator (type, reverse) {
  36128. var index = reverse ? this.size : 0;
  36129. var values = iterateList(this, reverse);
  36130. return new Iterator(function () {
  36131. var value = values();
  36132. return value === DONE
  36133. ? iteratorDone()
  36134. : iteratorValue(type, reverse ? --index : index++, value);
  36135. });
  36136. };
  36137. List.prototype.__iterate = function __iterate (fn, reverse) {
  36138. var index = reverse ? this.size : 0;
  36139. var values = iterateList(this, reverse);
  36140. var value;
  36141. while ((value = values()) !== DONE) {
  36142. if (fn(value, reverse ? --index : index++, this) === false) {
  36143. break;
  36144. }
  36145. }
  36146. return index;
  36147. };
  36148. List.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  36149. if (ownerID === this.__ownerID) {
  36150. return this;
  36151. }
  36152. if (!ownerID) {
  36153. if (this.size === 0) {
  36154. return emptyList();
  36155. }
  36156. this.__ownerID = ownerID;
  36157. this.__altered = false;
  36158. return this;
  36159. }
  36160. return makeList(
  36161. this._origin,
  36162. this._capacity,
  36163. this._level,
  36164. this._root,
  36165. this._tail,
  36166. ownerID,
  36167. this.__hash
  36168. );
  36169. };
  36170. return List;
  36171. }(IndexedCollection));
  36172. List.isList = isList;
  36173. var ListPrototype = List.prototype;
  36174. ListPrototype[IS_LIST_SYMBOL] = true;
  36175. ListPrototype[DELETE] = ListPrototype.remove;
  36176. ListPrototype.merge = ListPrototype.concat;
  36177. ListPrototype.setIn = setIn$1;
  36178. ListPrototype.deleteIn = ListPrototype.removeIn = deleteIn;
  36179. ListPrototype.update = update$1;
  36180. ListPrototype.updateIn = updateIn$1;
  36181. ListPrototype.mergeIn = mergeIn;
  36182. ListPrototype.mergeDeepIn = mergeDeepIn;
  36183. ListPrototype.withMutations = withMutations;
  36184. ListPrototype.wasAltered = wasAltered;
  36185. ListPrototype.asImmutable = asImmutable;
  36186. ListPrototype['@@transducer/init'] = ListPrototype.asMutable = asMutable;
  36187. ListPrototype['@@transducer/step'] = function(result, arr) {
  36188. return result.push(arr);
  36189. };
  36190. ListPrototype['@@transducer/result'] = function(obj) {
  36191. return obj.asImmutable();
  36192. };
  36193. var VNode = function VNode(array, ownerID) {
  36194. this.array = array;
  36195. this.ownerID = ownerID;
  36196. };
  36197. // TODO: seems like these methods are very similar
  36198. VNode.prototype.removeBefore = function removeBefore (ownerID, level, index) {
  36199. if (index === level ? 1 << level : this.array.length === 0) {
  36200. return this;
  36201. }
  36202. var originIndex = (index >>> level) & MASK;
  36203. if (originIndex >= this.array.length) {
  36204. return new VNode([], ownerID);
  36205. }
  36206. var removingFirst = originIndex === 0;
  36207. var newChild;
  36208. if (level > 0) {
  36209. var oldChild = this.array[originIndex];
  36210. newChild =
  36211. oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  36212. if (newChild === oldChild && removingFirst) {
  36213. return this;
  36214. }
  36215. }
  36216. if (removingFirst && !newChild) {
  36217. return this;
  36218. }
  36219. var editable = editableVNode(this, ownerID);
  36220. if (!removingFirst) {
  36221. for (var ii = 0; ii < originIndex; ii++) {
  36222. editable.array[ii] = undefined;
  36223. }
  36224. }
  36225. if (newChild) {
  36226. editable.array[originIndex] = newChild;
  36227. }
  36228. return editable;
  36229. };
  36230. VNode.prototype.removeAfter = function removeAfter (ownerID, level, index) {
  36231. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  36232. return this;
  36233. }
  36234. var sizeIndex = ((index - 1) >>> level) & MASK;
  36235. if (sizeIndex >= this.array.length) {
  36236. return this;
  36237. }
  36238. var newChild;
  36239. if (level > 0) {
  36240. var oldChild = this.array[sizeIndex];
  36241. newChild =
  36242. oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  36243. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  36244. return this;
  36245. }
  36246. }
  36247. var editable = editableVNode(this, ownerID);
  36248. editable.array.splice(sizeIndex + 1);
  36249. if (newChild) {
  36250. editable.array[sizeIndex] = newChild;
  36251. }
  36252. return editable;
  36253. };
  36254. var DONE = {};
  36255. function iterateList(list, reverse) {
  36256. var left = list._origin;
  36257. var right = list._capacity;
  36258. var tailPos = getTailOffset(right);
  36259. var tail = list._tail;
  36260. return iterateNodeOrLeaf(list._root, list._level, 0);
  36261. function iterateNodeOrLeaf(node, level, offset) {
  36262. return level === 0
  36263. ? iterateLeaf(node, offset)
  36264. : iterateNode(node, level, offset);
  36265. }
  36266. function iterateLeaf(node, offset) {
  36267. var array = offset === tailPos ? tail && tail.array : node && node.array;
  36268. var from = offset > left ? 0 : left - offset;
  36269. var to = right - offset;
  36270. if (to > SIZE) {
  36271. to = SIZE;
  36272. }
  36273. return function () {
  36274. if (from === to) {
  36275. return DONE;
  36276. }
  36277. var idx = reverse ? --to : from++;
  36278. return array && array[idx];
  36279. };
  36280. }
  36281. function iterateNode(node, level, offset) {
  36282. var values;
  36283. var array = node && node.array;
  36284. var from = offset > left ? 0 : (left - offset) >> level;
  36285. var to = ((right - offset) >> level) + 1;
  36286. if (to > SIZE) {
  36287. to = SIZE;
  36288. }
  36289. return function () {
  36290. while (true) {
  36291. if (values) {
  36292. var value = values();
  36293. if (value !== DONE) {
  36294. return value;
  36295. }
  36296. values = null;
  36297. }
  36298. if (from === to) {
  36299. return DONE;
  36300. }
  36301. var idx = reverse ? --to : from++;
  36302. values = iterateNodeOrLeaf(
  36303. array && array[idx],
  36304. level - SHIFT,
  36305. offset + (idx << level)
  36306. );
  36307. }
  36308. };
  36309. }
  36310. }
  36311. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  36312. var list = Object.create(ListPrototype);
  36313. list.size = capacity - origin;
  36314. list._origin = origin;
  36315. list._capacity = capacity;
  36316. list._level = level;
  36317. list._root = root;
  36318. list._tail = tail;
  36319. list.__ownerID = ownerID;
  36320. list.__hash = hash;
  36321. list.__altered = false;
  36322. return list;
  36323. }
  36324. var EMPTY_LIST;
  36325. function emptyList() {
  36326. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  36327. }
  36328. function updateList(list, index, value) {
  36329. index = wrapIndex(list, index);
  36330. if (index !== index) {
  36331. return list;
  36332. }
  36333. if (index >= list.size || index < 0) {
  36334. return list.withMutations(function (list) {
  36335. index < 0
  36336. ? setListBounds(list, index).set(0, value)
  36337. : setListBounds(list, 0, index + 1).set(index, value);
  36338. });
  36339. }
  36340. index += list._origin;
  36341. var newTail = list._tail;
  36342. var newRoot = list._root;
  36343. var didAlter = MakeRef();
  36344. if (index >= getTailOffset(list._capacity)) {
  36345. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  36346. } else {
  36347. newRoot = updateVNode(
  36348. newRoot,
  36349. list.__ownerID,
  36350. list._level,
  36351. index,
  36352. value,
  36353. didAlter
  36354. );
  36355. }
  36356. if (!didAlter.value) {
  36357. return list;
  36358. }
  36359. if (list.__ownerID) {
  36360. list._root = newRoot;
  36361. list._tail = newTail;
  36362. list.__hash = undefined;
  36363. list.__altered = true;
  36364. return list;
  36365. }
  36366. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  36367. }
  36368. function updateVNode(node, ownerID, level, index, value, didAlter) {
  36369. var idx = (index >>> level) & MASK;
  36370. var nodeHas = node && idx < node.array.length;
  36371. if (!nodeHas && value === undefined) {
  36372. return node;
  36373. }
  36374. var newNode;
  36375. if (level > 0) {
  36376. var lowerNode = node && node.array[idx];
  36377. var newLowerNode = updateVNode(
  36378. lowerNode,
  36379. ownerID,
  36380. level - SHIFT,
  36381. index,
  36382. value,
  36383. didAlter
  36384. );
  36385. if (newLowerNode === lowerNode) {
  36386. return node;
  36387. }
  36388. newNode = editableVNode(node, ownerID);
  36389. newNode.array[idx] = newLowerNode;
  36390. return newNode;
  36391. }
  36392. if (nodeHas && node.array[idx] === value) {
  36393. return node;
  36394. }
  36395. if (didAlter) {
  36396. SetRef(didAlter);
  36397. }
  36398. newNode = editableVNode(node, ownerID);
  36399. if (value === undefined && idx === newNode.array.length - 1) {
  36400. newNode.array.pop();
  36401. } else {
  36402. newNode.array[idx] = value;
  36403. }
  36404. return newNode;
  36405. }
  36406. function editableVNode(node, ownerID) {
  36407. if (ownerID && node && ownerID === node.ownerID) {
  36408. return node;
  36409. }
  36410. return new VNode(node ? node.array.slice() : [], ownerID);
  36411. }
  36412. function listNodeFor(list, rawIndex) {
  36413. if (rawIndex >= getTailOffset(list._capacity)) {
  36414. return list._tail;
  36415. }
  36416. if (rawIndex < 1 << (list._level + SHIFT)) {
  36417. var node = list._root;
  36418. var level = list._level;
  36419. while (node && level > 0) {
  36420. node = node.array[(rawIndex >>> level) & MASK];
  36421. level -= SHIFT;
  36422. }
  36423. return node;
  36424. }
  36425. }
  36426. function setListBounds(list, begin, end) {
  36427. // Sanitize begin & end using this shorthand for ToInt32(argument)
  36428. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  36429. if (begin !== undefined) {
  36430. begin |= 0;
  36431. }
  36432. if (end !== undefined) {
  36433. end |= 0;
  36434. }
  36435. var owner = list.__ownerID || new OwnerID();
  36436. var oldOrigin = list._origin;
  36437. var oldCapacity = list._capacity;
  36438. var newOrigin = oldOrigin + begin;
  36439. var newCapacity =
  36440. end === undefined
  36441. ? oldCapacity
  36442. : end < 0
  36443. ? oldCapacity + end
  36444. : oldOrigin + end;
  36445. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  36446. return list;
  36447. }
  36448. // If it's going to end after it starts, it's empty.
  36449. if (newOrigin >= newCapacity) {
  36450. return list.clear();
  36451. }
  36452. var newLevel = list._level;
  36453. var newRoot = list._root;
  36454. // New origin might need creating a higher root.
  36455. var offsetShift = 0;
  36456. while (newOrigin + offsetShift < 0) {
  36457. newRoot = new VNode(
  36458. newRoot && newRoot.array.length ? [undefined, newRoot] : [],
  36459. owner
  36460. );
  36461. newLevel += SHIFT;
  36462. offsetShift += 1 << newLevel;
  36463. }
  36464. if (offsetShift) {
  36465. newOrigin += offsetShift;
  36466. oldOrigin += offsetShift;
  36467. newCapacity += offsetShift;
  36468. oldCapacity += offsetShift;
  36469. }
  36470. var oldTailOffset = getTailOffset(oldCapacity);
  36471. var newTailOffset = getTailOffset(newCapacity);
  36472. // New size might need creating a higher root.
  36473. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  36474. newRoot = new VNode(
  36475. newRoot && newRoot.array.length ? [newRoot] : [],
  36476. owner
  36477. );
  36478. newLevel += SHIFT;
  36479. }
  36480. // Locate or create the new tail.
  36481. var oldTail = list._tail;
  36482. var newTail =
  36483. newTailOffset < oldTailOffset
  36484. ? listNodeFor(list, newCapacity - 1)
  36485. : newTailOffset > oldTailOffset
  36486. ? new VNode([], owner)
  36487. : oldTail;
  36488. // Merge Tail into tree.
  36489. if (
  36490. oldTail &&
  36491. newTailOffset > oldTailOffset &&
  36492. newOrigin < oldCapacity &&
  36493. oldTail.array.length
  36494. ) {
  36495. newRoot = editableVNode(newRoot, owner);
  36496. var node = newRoot;
  36497. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  36498. var idx = (oldTailOffset >>> level) & MASK;
  36499. node = node.array[idx] = editableVNode(node.array[idx], owner);
  36500. }
  36501. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  36502. }
  36503. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  36504. if (newCapacity < oldCapacity) {
  36505. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  36506. }
  36507. // If the new origin is within the tail, then we do not need a root.
  36508. if (newOrigin >= newTailOffset) {
  36509. newOrigin -= newTailOffset;
  36510. newCapacity -= newTailOffset;
  36511. newLevel = SHIFT;
  36512. newRoot = null;
  36513. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  36514. // Otherwise, if the root has been trimmed, garbage collect.
  36515. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  36516. offsetShift = 0;
  36517. // Identify the new top root node of the subtree of the old root.
  36518. while (newRoot) {
  36519. var beginIndex = (newOrigin >>> newLevel) & MASK;
  36520. if ((beginIndex !== newTailOffset >>> newLevel) & MASK) {
  36521. break;
  36522. }
  36523. if (beginIndex) {
  36524. offsetShift += (1 << newLevel) * beginIndex;
  36525. }
  36526. newLevel -= SHIFT;
  36527. newRoot = newRoot.array[beginIndex];
  36528. }
  36529. // Trim the new sides of the new root.
  36530. if (newRoot && newOrigin > oldOrigin) {
  36531. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  36532. }
  36533. if (newRoot && newTailOffset < oldTailOffset) {
  36534. newRoot = newRoot.removeAfter(
  36535. owner,
  36536. newLevel,
  36537. newTailOffset - offsetShift
  36538. );
  36539. }
  36540. if (offsetShift) {
  36541. newOrigin -= offsetShift;
  36542. newCapacity -= offsetShift;
  36543. }
  36544. }
  36545. if (list.__ownerID) {
  36546. list.size = newCapacity - newOrigin;
  36547. list._origin = newOrigin;
  36548. list._capacity = newCapacity;
  36549. list._level = newLevel;
  36550. list._root = newRoot;
  36551. list._tail = newTail;
  36552. list.__hash = undefined;
  36553. list.__altered = true;
  36554. return list;
  36555. }
  36556. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  36557. }
  36558. function getTailOffset(size) {
  36559. return size < SIZE ? 0 : ((size - 1) >>> SHIFT) << SHIFT;
  36560. }
  36561. var OrderedMap = /*@__PURE__*/(function (Map$$1) {
  36562. function OrderedMap(value) {
  36563. return value === null || value === undefined
  36564. ? emptyOrderedMap()
  36565. : isOrderedMap(value)
  36566. ? value
  36567. : emptyOrderedMap().withMutations(function (map) {
  36568. var iter = KeyedCollection(value);
  36569. assertNotInfinite(iter.size);
  36570. iter.forEach(function (v, k) { return map.set(k, v); });
  36571. });
  36572. }
  36573. if ( Map$$1 ) OrderedMap.__proto__ = Map$$1;
  36574. OrderedMap.prototype = Object.create( Map$$1 && Map$$1.prototype );
  36575. OrderedMap.prototype.constructor = OrderedMap;
  36576. OrderedMap.of = function of (/*...values*/) {
  36577. return this(arguments);
  36578. };
  36579. OrderedMap.prototype.toString = function toString () {
  36580. return this.__toString('OrderedMap {', '}');
  36581. };
  36582. // @pragma Access
  36583. OrderedMap.prototype.get = function get (k, notSetValue) {
  36584. var index = this._map.get(k);
  36585. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  36586. };
  36587. // @pragma Modification
  36588. OrderedMap.prototype.clear = function clear () {
  36589. if (this.size === 0) {
  36590. return this;
  36591. }
  36592. if (this.__ownerID) {
  36593. this.size = 0;
  36594. this._map.clear();
  36595. this._list.clear();
  36596. return this;
  36597. }
  36598. return emptyOrderedMap();
  36599. };
  36600. OrderedMap.prototype.set = function set (k, v) {
  36601. return updateOrderedMap(this, k, v);
  36602. };
  36603. OrderedMap.prototype.remove = function remove (k) {
  36604. return updateOrderedMap(this, k, NOT_SET);
  36605. };
  36606. OrderedMap.prototype.wasAltered = function wasAltered () {
  36607. return this._map.wasAltered() || this._list.wasAltered();
  36608. };
  36609. OrderedMap.prototype.__iterate = function __iterate (fn, reverse) {
  36610. var this$1 = this;
  36611. return this._list.__iterate(
  36612. function (entry) { return entry && fn(entry[1], entry[0], this$1); },
  36613. reverse
  36614. );
  36615. };
  36616. OrderedMap.prototype.__iterator = function __iterator (type, reverse) {
  36617. return this._list.fromEntrySeq().__iterator(type, reverse);
  36618. };
  36619. OrderedMap.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  36620. if (ownerID === this.__ownerID) {
  36621. return this;
  36622. }
  36623. var newMap = this._map.__ensureOwner(ownerID);
  36624. var newList = this._list.__ensureOwner(ownerID);
  36625. if (!ownerID) {
  36626. if (this.size === 0) {
  36627. return emptyOrderedMap();
  36628. }
  36629. this.__ownerID = ownerID;
  36630. this._map = newMap;
  36631. this._list = newList;
  36632. return this;
  36633. }
  36634. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  36635. };
  36636. return OrderedMap;
  36637. }(Map));
  36638. OrderedMap.isOrderedMap = isOrderedMap;
  36639. OrderedMap.prototype[IS_ORDERED_SYMBOL] = true;
  36640. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  36641. function makeOrderedMap(map, list, ownerID, hash) {
  36642. var omap = Object.create(OrderedMap.prototype);
  36643. omap.size = map ? map.size : 0;
  36644. omap._map = map;
  36645. omap._list = list;
  36646. omap.__ownerID = ownerID;
  36647. omap.__hash = hash;
  36648. return omap;
  36649. }
  36650. var EMPTY_ORDERED_MAP;
  36651. function emptyOrderedMap() {
  36652. return (
  36653. EMPTY_ORDERED_MAP ||
  36654. (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()))
  36655. );
  36656. }
  36657. function updateOrderedMap(omap, k, v) {
  36658. var map = omap._map;
  36659. var list = omap._list;
  36660. var i = map.get(k);
  36661. var has = i !== undefined;
  36662. var newMap;
  36663. var newList;
  36664. if (v === NOT_SET) {
  36665. // removed
  36666. if (!has) {
  36667. return omap;
  36668. }
  36669. if (list.size >= SIZE && list.size >= map.size * 2) {
  36670. newList = list.filter(function (entry, idx) { return entry !== undefined && i !== idx; });
  36671. newMap = newList
  36672. .toKeyedSeq()
  36673. .map(function (entry) { return entry[0]; })
  36674. .flip()
  36675. .toMap();
  36676. if (omap.__ownerID) {
  36677. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  36678. }
  36679. } else {
  36680. newMap = map.remove(k);
  36681. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  36682. }
  36683. } else if (has) {
  36684. if (v === list.get(i)[1]) {
  36685. return omap;
  36686. }
  36687. newMap = map;
  36688. newList = list.set(i, [k, v]);
  36689. } else {
  36690. newMap = map.set(k, list.size);
  36691. newList = list.set(list.size, [k, v]);
  36692. }
  36693. if (omap.__ownerID) {
  36694. omap.size = newMap.size;
  36695. omap._map = newMap;
  36696. omap._list = newList;
  36697. omap.__hash = undefined;
  36698. return omap;
  36699. }
  36700. return makeOrderedMap(newMap, newList);
  36701. }
  36702. var IS_STACK_SYMBOL = '@@__IMMUTABLE_STACK__@@';
  36703. function isStack(maybeStack) {
  36704. return Boolean(maybeStack && maybeStack[IS_STACK_SYMBOL]);
  36705. }
  36706. var Stack = /*@__PURE__*/(function (IndexedCollection$$1) {
  36707. function Stack(value) {
  36708. return value === null || value === undefined
  36709. ? emptyStack()
  36710. : isStack(value)
  36711. ? value
  36712. : emptyStack().pushAll(value);
  36713. }
  36714. if ( IndexedCollection$$1 ) Stack.__proto__ = IndexedCollection$$1;
  36715. Stack.prototype = Object.create( IndexedCollection$$1 && IndexedCollection$$1.prototype );
  36716. Stack.prototype.constructor = Stack;
  36717. Stack.of = function of (/*...values*/) {
  36718. return this(arguments);
  36719. };
  36720. Stack.prototype.toString = function toString () {
  36721. return this.__toString('Stack [', ']');
  36722. };
  36723. // @pragma Access
  36724. Stack.prototype.get = function get (index, notSetValue) {
  36725. var head = this._head;
  36726. index = wrapIndex(this, index);
  36727. while (head && index--) {
  36728. head = head.next;
  36729. }
  36730. return head ? head.value : notSetValue;
  36731. };
  36732. Stack.prototype.peek = function peek () {
  36733. return this._head && this._head.value;
  36734. };
  36735. // @pragma Modification
  36736. Stack.prototype.push = function push (/*...values*/) {
  36737. var arguments$1 = arguments;
  36738. if (arguments.length === 0) {
  36739. return this;
  36740. }
  36741. var newSize = this.size + arguments.length;
  36742. var head = this._head;
  36743. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  36744. head = {
  36745. value: arguments$1[ii],
  36746. next: head,
  36747. };
  36748. }
  36749. if (this.__ownerID) {
  36750. this.size = newSize;
  36751. this._head = head;
  36752. this.__hash = undefined;
  36753. this.__altered = true;
  36754. return this;
  36755. }
  36756. return makeStack(newSize, head);
  36757. };
  36758. Stack.prototype.pushAll = function pushAll (iter) {
  36759. iter = IndexedCollection$$1(iter);
  36760. if (iter.size === 0) {
  36761. return this;
  36762. }
  36763. if (this.size === 0 && isStack(iter)) {
  36764. return iter;
  36765. }
  36766. assertNotInfinite(iter.size);
  36767. var newSize = this.size;
  36768. var head = this._head;
  36769. iter.__iterate(function (value) {
  36770. newSize++;
  36771. head = {
  36772. value: value,
  36773. next: head,
  36774. };
  36775. }, /* reverse */ true);
  36776. if (this.__ownerID) {
  36777. this.size = newSize;
  36778. this._head = head;
  36779. this.__hash = undefined;
  36780. this.__altered = true;
  36781. return this;
  36782. }
  36783. return makeStack(newSize, head);
  36784. };
  36785. Stack.prototype.pop = function pop () {
  36786. return this.slice(1);
  36787. };
  36788. Stack.prototype.clear = function clear () {
  36789. if (this.size === 0) {
  36790. return this;
  36791. }
  36792. if (this.__ownerID) {
  36793. this.size = 0;
  36794. this._head = undefined;
  36795. this.__hash = undefined;
  36796. this.__altered = true;
  36797. return this;
  36798. }
  36799. return emptyStack();
  36800. };
  36801. Stack.prototype.slice = function slice (begin, end) {
  36802. if (wholeSlice(begin, end, this.size)) {
  36803. return this;
  36804. }
  36805. var resolvedBegin = resolveBegin(begin, this.size);
  36806. var resolvedEnd = resolveEnd(end, this.size);
  36807. if (resolvedEnd !== this.size) {
  36808. // super.slice(begin, end);
  36809. return IndexedCollection$$1.prototype.slice.call(this, begin, end);
  36810. }
  36811. var newSize = this.size - resolvedBegin;
  36812. var head = this._head;
  36813. while (resolvedBegin--) {
  36814. head = head.next;
  36815. }
  36816. if (this.__ownerID) {
  36817. this.size = newSize;
  36818. this._head = head;
  36819. this.__hash = undefined;
  36820. this.__altered = true;
  36821. return this;
  36822. }
  36823. return makeStack(newSize, head);
  36824. };
  36825. // @pragma Mutability
  36826. Stack.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  36827. if (ownerID === this.__ownerID) {
  36828. return this;
  36829. }
  36830. if (!ownerID) {
  36831. if (this.size === 0) {
  36832. return emptyStack();
  36833. }
  36834. this.__ownerID = ownerID;
  36835. this.__altered = false;
  36836. return this;
  36837. }
  36838. return makeStack(this.size, this._head, ownerID, this.__hash);
  36839. };
  36840. // @pragma Iteration
  36841. Stack.prototype.__iterate = function __iterate (fn, reverse) {
  36842. var this$1 = this;
  36843. if (reverse) {
  36844. return new ArraySeq(this.toArray()).__iterate(
  36845. function (v, k) { return fn(v, k, this$1); },
  36846. reverse
  36847. );
  36848. }
  36849. var iterations = 0;
  36850. var node = this._head;
  36851. while (node) {
  36852. if (fn(node.value, iterations++, this) === false) {
  36853. break;
  36854. }
  36855. node = node.next;
  36856. }
  36857. return iterations;
  36858. };
  36859. Stack.prototype.__iterator = function __iterator (type, reverse) {
  36860. if (reverse) {
  36861. return new ArraySeq(this.toArray()).__iterator(type, reverse);
  36862. }
  36863. var iterations = 0;
  36864. var node = this._head;
  36865. return new Iterator(function () {
  36866. if (node) {
  36867. var value = node.value;
  36868. node = node.next;
  36869. return iteratorValue(type, iterations++, value);
  36870. }
  36871. return iteratorDone();
  36872. });
  36873. };
  36874. return Stack;
  36875. }(IndexedCollection));
  36876. Stack.isStack = isStack;
  36877. var StackPrototype = Stack.prototype;
  36878. StackPrototype[IS_STACK_SYMBOL] = true;
  36879. StackPrototype.shift = StackPrototype.pop;
  36880. StackPrototype.unshift = StackPrototype.push;
  36881. StackPrototype.unshiftAll = StackPrototype.pushAll;
  36882. StackPrototype.withMutations = withMutations;
  36883. StackPrototype.wasAltered = wasAltered;
  36884. StackPrototype.asImmutable = asImmutable;
  36885. StackPrototype['@@transducer/init'] = StackPrototype.asMutable = asMutable;
  36886. StackPrototype['@@transducer/step'] = function(result, arr) {
  36887. return result.unshift(arr);
  36888. };
  36889. StackPrototype['@@transducer/result'] = function(obj) {
  36890. return obj.asImmutable();
  36891. };
  36892. function makeStack(size, head, ownerID, hash) {
  36893. var map = Object.create(StackPrototype);
  36894. map.size = size;
  36895. map._head = head;
  36896. map.__ownerID = ownerID;
  36897. map.__hash = hash;
  36898. map.__altered = false;
  36899. return map;
  36900. }
  36901. var EMPTY_STACK;
  36902. function emptyStack() {
  36903. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  36904. }
  36905. var IS_SET_SYMBOL = '@@__IMMUTABLE_SET__@@';
  36906. function isSet(maybeSet) {
  36907. return Boolean(maybeSet && maybeSet[IS_SET_SYMBOL]);
  36908. }
  36909. function isOrderedSet(maybeOrderedSet) {
  36910. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  36911. }
  36912. function deepEqual(a, b) {
  36913. if (a === b) {
  36914. return true;
  36915. }
  36916. if (
  36917. !isCollection(b) ||
  36918. (a.size !== undefined && b.size !== undefined && a.size !== b.size) ||
  36919. (a.__hash !== undefined &&
  36920. b.__hash !== undefined &&
  36921. a.__hash !== b.__hash) ||
  36922. isKeyed(a) !== isKeyed(b) ||
  36923. isIndexed(a) !== isIndexed(b) ||
  36924. isOrdered(a) !== isOrdered(b)
  36925. ) {
  36926. return false;
  36927. }
  36928. if (a.size === 0 && b.size === 0) {
  36929. return true;
  36930. }
  36931. var notAssociative = !isAssociative(a);
  36932. if (isOrdered(a)) {
  36933. var entries = a.entries();
  36934. return (
  36935. b.every(function (v, k) {
  36936. var entry = entries.next().value;
  36937. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  36938. }) && entries.next().done
  36939. );
  36940. }
  36941. var flipped = false;
  36942. if (a.size === undefined) {
  36943. if (b.size === undefined) {
  36944. if (typeof a.cacheResult === 'function') {
  36945. a.cacheResult();
  36946. }
  36947. } else {
  36948. flipped = true;
  36949. var _ = a;
  36950. a = b;
  36951. b = _;
  36952. }
  36953. }
  36954. var allEqual = true;
  36955. var bSize = b.__iterate(function (v, k) {
  36956. if (
  36957. notAssociative
  36958. ? !a.has(v)
  36959. : flipped
  36960. ? !is(v, a.get(k, NOT_SET))
  36961. : !is(a.get(k, NOT_SET), v)
  36962. ) {
  36963. allEqual = false;
  36964. return false;
  36965. }
  36966. });
  36967. return allEqual && a.size === bSize;
  36968. }
  36969. /**
  36970. * Contributes additional methods to a constructor
  36971. */
  36972. function mixin(ctor, methods) {
  36973. var keyCopier = function (key) {
  36974. ctor.prototype[key] = methods[key];
  36975. };
  36976. Object.keys(methods).forEach(keyCopier);
  36977. Object.getOwnPropertySymbols &&
  36978. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  36979. return ctor;
  36980. }
  36981. function toJS(value) {
  36982. if (!value || typeof value !== 'object') {
  36983. return value;
  36984. }
  36985. if (!isCollection(value)) {
  36986. if (!isDataStructure(value)) {
  36987. return value;
  36988. }
  36989. value = Seq(value);
  36990. }
  36991. if (isKeyed(value)) {
  36992. var result$1 = {};
  36993. value.__iterate(function (v, k) {
  36994. result$1[k] = toJS(v);
  36995. });
  36996. return result$1;
  36997. }
  36998. var result = [];
  36999. value.__iterate(function (v) {
  37000. result.push(toJS(v));
  37001. });
  37002. return result;
  37003. }
  37004. var Set = /*@__PURE__*/(function (SetCollection$$1) {
  37005. function Set(value) {
  37006. return value === null || value === undefined
  37007. ? emptySet()
  37008. : isSet(value) && !isOrdered(value)
  37009. ? value
  37010. : emptySet().withMutations(function (set) {
  37011. var iter = SetCollection$$1(value);
  37012. assertNotInfinite(iter.size);
  37013. iter.forEach(function (v) { return set.add(v); });
  37014. });
  37015. }
  37016. if ( SetCollection$$1 ) Set.__proto__ = SetCollection$$1;
  37017. Set.prototype = Object.create( SetCollection$$1 && SetCollection$$1.prototype );
  37018. Set.prototype.constructor = Set;
  37019. Set.of = function of (/*...values*/) {
  37020. return this(arguments);
  37021. };
  37022. Set.fromKeys = function fromKeys (value) {
  37023. return this(KeyedCollection(value).keySeq());
  37024. };
  37025. Set.intersect = function intersect (sets) {
  37026. sets = Collection(sets).toArray();
  37027. return sets.length
  37028. ? SetPrototype.intersect.apply(Set(sets.pop()), sets)
  37029. : emptySet();
  37030. };
  37031. Set.union = function union (sets) {
  37032. sets = Collection(sets).toArray();
  37033. return sets.length
  37034. ? SetPrototype.union.apply(Set(sets.pop()), sets)
  37035. : emptySet();
  37036. };
  37037. Set.prototype.toString = function toString () {
  37038. return this.__toString('Set {', '}');
  37039. };
  37040. // @pragma Access
  37041. Set.prototype.has = function has (value) {
  37042. return this._map.has(value);
  37043. };
  37044. // @pragma Modification
  37045. Set.prototype.add = function add (value) {
  37046. return updateSet(this, this._map.set(value, value));
  37047. };
  37048. Set.prototype.remove = function remove (value) {
  37049. return updateSet(this, this._map.remove(value));
  37050. };
  37051. Set.prototype.clear = function clear () {
  37052. return updateSet(this, this._map.clear());
  37053. };
  37054. // @pragma Composition
  37055. Set.prototype.map = function map (mapper, context) {
  37056. var this$1 = this;
  37057. var removes = [];
  37058. var adds = [];
  37059. this.forEach(function (value) {
  37060. var mapped = mapper.call(context, value, value, this$1);
  37061. if (mapped !== value) {
  37062. removes.push(value);
  37063. adds.push(mapped);
  37064. }
  37065. });
  37066. return this.withMutations(function (set) {
  37067. removes.forEach(function (value) { return set.remove(value); });
  37068. adds.forEach(function (value) { return set.add(value); });
  37069. });
  37070. };
  37071. Set.prototype.union = function union () {
  37072. var iters = [], len = arguments.length;
  37073. while ( len-- ) iters[ len ] = arguments[ len ];
  37074. iters = iters.filter(function (x) { return x.size !== 0; });
  37075. if (iters.length === 0) {
  37076. return this;
  37077. }
  37078. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  37079. return this.constructor(iters[0]);
  37080. }
  37081. return this.withMutations(function (set) {
  37082. for (var ii = 0; ii < iters.length; ii++) {
  37083. SetCollection$$1(iters[ii]).forEach(function (value) { return set.add(value); });
  37084. }
  37085. });
  37086. };
  37087. Set.prototype.intersect = function intersect () {
  37088. var iters = [], len = arguments.length;
  37089. while ( len-- ) iters[ len ] = arguments[ len ];
  37090. if (iters.length === 0) {
  37091. return this;
  37092. }
  37093. iters = iters.map(function (iter) { return SetCollection$$1(iter); });
  37094. var toRemove = [];
  37095. this.forEach(function (value) {
  37096. if (!iters.every(function (iter) { return iter.includes(value); })) {
  37097. toRemove.push(value);
  37098. }
  37099. });
  37100. return this.withMutations(function (set) {
  37101. toRemove.forEach(function (value) {
  37102. set.remove(value);
  37103. });
  37104. });
  37105. };
  37106. Set.prototype.subtract = function subtract () {
  37107. var iters = [], len = arguments.length;
  37108. while ( len-- ) iters[ len ] = arguments[ len ];
  37109. if (iters.length === 0) {
  37110. return this;
  37111. }
  37112. iters = iters.map(function (iter) { return SetCollection$$1(iter); });
  37113. var toRemove = [];
  37114. this.forEach(function (value) {
  37115. if (iters.some(function (iter) { return iter.includes(value); })) {
  37116. toRemove.push(value);
  37117. }
  37118. });
  37119. return this.withMutations(function (set) {
  37120. toRemove.forEach(function (value) {
  37121. set.remove(value);
  37122. });
  37123. });
  37124. };
  37125. Set.prototype.sort = function sort (comparator) {
  37126. // Late binding
  37127. return OrderedSet(sortFactory(this, comparator));
  37128. };
  37129. Set.prototype.sortBy = function sortBy (mapper, comparator) {
  37130. // Late binding
  37131. return OrderedSet(sortFactory(this, comparator, mapper));
  37132. };
  37133. Set.prototype.wasAltered = function wasAltered () {
  37134. return this._map.wasAltered();
  37135. };
  37136. Set.prototype.__iterate = function __iterate (fn, reverse) {
  37137. var this$1 = this;
  37138. return this._map.__iterate(function (k) { return fn(k, k, this$1); }, reverse);
  37139. };
  37140. Set.prototype.__iterator = function __iterator (type, reverse) {
  37141. return this._map.__iterator(type, reverse);
  37142. };
  37143. Set.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  37144. if (ownerID === this.__ownerID) {
  37145. return this;
  37146. }
  37147. var newMap = this._map.__ensureOwner(ownerID);
  37148. if (!ownerID) {
  37149. if (this.size === 0) {
  37150. return this.__empty();
  37151. }
  37152. this.__ownerID = ownerID;
  37153. this._map = newMap;
  37154. return this;
  37155. }
  37156. return this.__make(newMap, ownerID);
  37157. };
  37158. return Set;
  37159. }(SetCollection));
  37160. Set.isSet = isSet;
  37161. var SetPrototype = Set.prototype;
  37162. SetPrototype[IS_SET_SYMBOL] = true;
  37163. SetPrototype[DELETE] = SetPrototype.remove;
  37164. SetPrototype.merge = SetPrototype.concat = SetPrototype.union;
  37165. SetPrototype.withMutations = withMutations;
  37166. SetPrototype.asImmutable = asImmutable;
  37167. SetPrototype['@@transducer/init'] = SetPrototype.asMutable = asMutable;
  37168. SetPrototype['@@transducer/step'] = function(result, arr) {
  37169. return result.add(arr);
  37170. };
  37171. SetPrototype['@@transducer/result'] = function(obj) {
  37172. return obj.asImmutable();
  37173. };
  37174. SetPrototype.__empty = emptySet;
  37175. SetPrototype.__make = makeSet;
  37176. function updateSet(set, newMap) {
  37177. if (set.__ownerID) {
  37178. set.size = newMap.size;
  37179. set._map = newMap;
  37180. return set;
  37181. }
  37182. return newMap === set._map
  37183. ? set
  37184. : newMap.size === 0
  37185. ? set.__empty()
  37186. : set.__make(newMap);
  37187. }
  37188. function makeSet(map, ownerID) {
  37189. var set = Object.create(SetPrototype);
  37190. set.size = map ? map.size : 0;
  37191. set._map = map;
  37192. set.__ownerID = ownerID;
  37193. return set;
  37194. }
  37195. var EMPTY_SET;
  37196. function emptySet() {
  37197. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  37198. }
  37199. /**
  37200. * Returns a lazy seq of nums from start (inclusive) to end
  37201. * (exclusive), by step, where start defaults to 0, step to 1, and end to
  37202. * infinity. When start is equal to end, returns empty list.
  37203. */
  37204. var Range = /*@__PURE__*/(function (IndexedSeq$$1) {
  37205. function Range(start, end, step) {
  37206. if (!(this instanceof Range)) {
  37207. return new Range(start, end, step);
  37208. }
  37209. invariant(step !== 0, 'Cannot step a Range by 0');
  37210. start = start || 0;
  37211. if (end === undefined) {
  37212. end = Infinity;
  37213. }
  37214. step = step === undefined ? 1 : Math.abs(step);
  37215. if (end < start) {
  37216. step = -step;
  37217. }
  37218. this._start = start;
  37219. this._end = end;
  37220. this._step = step;
  37221. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  37222. if (this.size === 0) {
  37223. if (EMPTY_RANGE) {
  37224. return EMPTY_RANGE;
  37225. }
  37226. EMPTY_RANGE = this;
  37227. }
  37228. }
  37229. if ( IndexedSeq$$1 ) Range.__proto__ = IndexedSeq$$1;
  37230. Range.prototype = Object.create( IndexedSeq$$1 && IndexedSeq$$1.prototype );
  37231. Range.prototype.constructor = Range;
  37232. Range.prototype.toString = function toString () {
  37233. if (this.size === 0) {
  37234. return 'Range []';
  37235. }
  37236. return (
  37237. 'Range [ ' +
  37238. this._start +
  37239. '...' +
  37240. this._end +
  37241. (this._step !== 1 ? ' by ' + this._step : '') +
  37242. ' ]'
  37243. );
  37244. };
  37245. Range.prototype.get = function get (index, notSetValue) {
  37246. return this.has(index)
  37247. ? this._start + wrapIndex(this, index) * this._step
  37248. : notSetValue;
  37249. };
  37250. Range.prototype.includes = function includes (searchValue) {
  37251. var possibleIndex = (searchValue - this._start) / this._step;
  37252. return (
  37253. possibleIndex >= 0 &&
  37254. possibleIndex < this.size &&
  37255. possibleIndex === Math.floor(possibleIndex)
  37256. );
  37257. };
  37258. Range.prototype.slice = function slice (begin, end) {
  37259. if (wholeSlice(begin, end, this.size)) {
  37260. return this;
  37261. }
  37262. begin = resolveBegin(begin, this.size);
  37263. end = resolveEnd(end, this.size);
  37264. if (end <= begin) {
  37265. return new Range(0, 0);
  37266. }
  37267. return new Range(
  37268. this.get(begin, this._end),
  37269. this.get(end, this._end),
  37270. this._step
  37271. );
  37272. };
  37273. Range.prototype.indexOf = function indexOf (searchValue) {
  37274. var offsetValue = searchValue - this._start;
  37275. if (offsetValue % this._step === 0) {
  37276. var index = offsetValue / this._step;
  37277. if (index >= 0 && index < this.size) {
  37278. return index;
  37279. }
  37280. }
  37281. return -1;
  37282. };
  37283. Range.prototype.lastIndexOf = function lastIndexOf (searchValue) {
  37284. return this.indexOf(searchValue);
  37285. };
  37286. Range.prototype.__iterate = function __iterate (fn, reverse) {
  37287. var size = this.size;
  37288. var step = this._step;
  37289. var value = reverse ? this._start + (size - 1) * step : this._start;
  37290. var i = 0;
  37291. while (i !== size) {
  37292. if (fn(value, reverse ? size - ++i : i++, this) === false) {
  37293. break;
  37294. }
  37295. value += reverse ? -step : step;
  37296. }
  37297. return i;
  37298. };
  37299. Range.prototype.__iterator = function __iterator (type, reverse) {
  37300. var size = this.size;
  37301. var step = this._step;
  37302. var value = reverse ? this._start + (size - 1) * step : this._start;
  37303. var i = 0;
  37304. return new Iterator(function () {
  37305. if (i === size) {
  37306. return iteratorDone();
  37307. }
  37308. var v = value;
  37309. value += reverse ? -step : step;
  37310. return iteratorValue(type, reverse ? size - ++i : i++, v);
  37311. });
  37312. };
  37313. Range.prototype.equals = function equals (other) {
  37314. return other instanceof Range
  37315. ? this._start === other._start &&
  37316. this._end === other._end &&
  37317. this._step === other._step
  37318. : deepEqual(this, other);
  37319. };
  37320. return Range;
  37321. }(IndexedSeq));
  37322. var EMPTY_RANGE;
  37323. function getIn(collection, searchKeyPath, notSetValue) {
  37324. var keyPath = coerceKeyPath(searchKeyPath);
  37325. var i = 0;
  37326. while (i !== keyPath.length) {
  37327. collection = get(collection, keyPath[i++], NOT_SET);
  37328. if (collection === NOT_SET) {
  37329. return notSetValue;
  37330. }
  37331. }
  37332. return collection;
  37333. }
  37334. function getIn$1(searchKeyPath, notSetValue) {
  37335. return getIn(this, searchKeyPath, notSetValue);
  37336. }
  37337. function hasIn(collection, keyPath) {
  37338. return getIn(collection, keyPath, NOT_SET) !== NOT_SET;
  37339. }
  37340. function hasIn$1(searchKeyPath) {
  37341. return hasIn(this, searchKeyPath);
  37342. }
  37343. function toObject() {
  37344. assertNotInfinite(this.size);
  37345. var object = {};
  37346. this.__iterate(function (v, k) {
  37347. object[k] = v;
  37348. });
  37349. return object;
  37350. }
  37351. // Note: all of these methods are deprecated.
  37352. Collection.isIterable = isCollection;
  37353. Collection.isKeyed = isKeyed;
  37354. Collection.isIndexed = isIndexed;
  37355. Collection.isAssociative = isAssociative;
  37356. Collection.isOrdered = isOrdered;
  37357. Collection.Iterator = Iterator;
  37358. mixin(Collection, {
  37359. // ### Conversion to other types
  37360. toArray: function toArray() {
  37361. assertNotInfinite(this.size);
  37362. var array = new Array(this.size || 0);
  37363. var useTuples = isKeyed(this);
  37364. var i = 0;
  37365. this.__iterate(function (v, k) {
  37366. // Keyed collections produce an array of tuples.
  37367. array[i++] = useTuples ? [k, v] : v;
  37368. });
  37369. return array;
  37370. },
  37371. toIndexedSeq: function toIndexedSeq() {
  37372. return new ToIndexedSequence(this);
  37373. },
  37374. toJS: function toJS$1() {
  37375. return toJS(this);
  37376. },
  37377. toKeyedSeq: function toKeyedSeq() {
  37378. return new ToKeyedSequence(this, true);
  37379. },
  37380. toMap: function toMap() {
  37381. // Use Late Binding here to solve the circular dependency.
  37382. return Map(this.toKeyedSeq());
  37383. },
  37384. toObject: toObject,
  37385. toOrderedMap: function toOrderedMap() {
  37386. // Use Late Binding here to solve the circular dependency.
  37387. return OrderedMap(this.toKeyedSeq());
  37388. },
  37389. toOrderedSet: function toOrderedSet() {
  37390. // Use Late Binding here to solve the circular dependency.
  37391. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  37392. },
  37393. toSet: function toSet() {
  37394. // Use Late Binding here to solve the circular dependency.
  37395. return Set(isKeyed(this) ? this.valueSeq() : this);
  37396. },
  37397. toSetSeq: function toSetSeq() {
  37398. return new ToSetSequence(this);
  37399. },
  37400. toSeq: function toSeq() {
  37401. return isIndexed(this)
  37402. ? this.toIndexedSeq()
  37403. : isKeyed(this)
  37404. ? this.toKeyedSeq()
  37405. : this.toSetSeq();
  37406. },
  37407. toStack: function toStack() {
  37408. // Use Late Binding here to solve the circular dependency.
  37409. return Stack(isKeyed(this) ? this.valueSeq() : this);
  37410. },
  37411. toList: function toList() {
  37412. // Use Late Binding here to solve the circular dependency.
  37413. return List(isKeyed(this) ? this.valueSeq() : this);
  37414. },
  37415. // ### Common JavaScript methods and properties
  37416. toString: function toString() {
  37417. return '[Collection]';
  37418. },
  37419. __toString: function __toString(head, tail) {
  37420. if (this.size === 0) {
  37421. return head + tail;
  37422. }
  37423. return (
  37424. head +
  37425. ' ' +
  37426. this.toSeq()
  37427. .map(this.__toStringMapper)
  37428. .join(', ') +
  37429. ' ' +
  37430. tail
  37431. );
  37432. },
  37433. // ### ES6 Collection methods (ES6 Array and Map)
  37434. concat: function concat() {
  37435. var values = [], len = arguments.length;
  37436. while ( len-- ) values[ len ] = arguments[ len ];
  37437. return reify(this, concatFactory(this, values));
  37438. },
  37439. includes: function includes(searchValue) {
  37440. return this.some(function (value) { return is(value, searchValue); });
  37441. },
  37442. entries: function entries() {
  37443. return this.__iterator(ITERATE_ENTRIES);
  37444. },
  37445. every: function every(predicate, context) {
  37446. assertNotInfinite(this.size);
  37447. var returnValue = true;
  37448. this.__iterate(function (v, k, c) {
  37449. if (!predicate.call(context, v, k, c)) {
  37450. returnValue = false;
  37451. return false;
  37452. }
  37453. });
  37454. return returnValue;
  37455. },
  37456. filter: function filter(predicate, context) {
  37457. return reify(this, filterFactory(this, predicate, context, true));
  37458. },
  37459. find: function find(predicate, context, notSetValue) {
  37460. var entry = this.findEntry(predicate, context);
  37461. return entry ? entry[1] : notSetValue;
  37462. },
  37463. forEach: function forEach(sideEffect, context) {
  37464. assertNotInfinite(this.size);
  37465. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  37466. },
  37467. join: function join(separator) {
  37468. assertNotInfinite(this.size);
  37469. separator = separator !== undefined ? '' + separator : ',';
  37470. var joined = '';
  37471. var isFirst = true;
  37472. this.__iterate(function (v) {
  37473. isFirst ? (isFirst = false) : (joined += separator);
  37474. joined += v !== null && v !== undefined ? v.toString() : '';
  37475. });
  37476. return joined;
  37477. },
  37478. keys: function keys() {
  37479. return this.__iterator(ITERATE_KEYS);
  37480. },
  37481. map: function map(mapper, context) {
  37482. return reify(this, mapFactory(this, mapper, context));
  37483. },
  37484. reduce: function reduce$1(reducer, initialReduction, context) {
  37485. return reduce(
  37486. this,
  37487. reducer,
  37488. initialReduction,
  37489. context,
  37490. arguments.length < 2,
  37491. false
  37492. );
  37493. },
  37494. reduceRight: function reduceRight(reducer, initialReduction, context) {
  37495. return reduce(
  37496. this,
  37497. reducer,
  37498. initialReduction,
  37499. context,
  37500. arguments.length < 2,
  37501. true
  37502. );
  37503. },
  37504. reverse: function reverse() {
  37505. return reify(this, reverseFactory(this, true));
  37506. },
  37507. slice: function slice(begin, end) {
  37508. return reify(this, sliceFactory(this, begin, end, true));
  37509. },
  37510. some: function some(predicate, context) {
  37511. return !this.every(not(predicate), context);
  37512. },
  37513. sort: function sort(comparator) {
  37514. return reify(this, sortFactory(this, comparator));
  37515. },
  37516. values: function values() {
  37517. return this.__iterator(ITERATE_VALUES);
  37518. },
  37519. // ### More sequential methods
  37520. butLast: function butLast() {
  37521. return this.slice(0, -1);
  37522. },
  37523. isEmpty: function isEmpty() {
  37524. return this.size !== undefined ? this.size === 0 : !this.some(function () { return true; });
  37525. },
  37526. count: function count(predicate, context) {
  37527. return ensureSize(
  37528. predicate ? this.toSeq().filter(predicate, context) : this
  37529. );
  37530. },
  37531. countBy: function countBy(grouper, context) {
  37532. return countByFactory(this, grouper, context);
  37533. },
  37534. equals: function equals(other) {
  37535. return deepEqual(this, other);
  37536. },
  37537. entrySeq: function entrySeq() {
  37538. var collection = this;
  37539. if (collection._cache) {
  37540. // We cache as an entries array, so we can just return the cache!
  37541. return new ArraySeq(collection._cache);
  37542. }
  37543. var entriesSequence = collection
  37544. .toSeq()
  37545. .map(entryMapper)
  37546. .toIndexedSeq();
  37547. entriesSequence.fromEntrySeq = function () { return collection.toSeq(); };
  37548. return entriesSequence;
  37549. },
  37550. filterNot: function filterNot(predicate, context) {
  37551. return this.filter(not(predicate), context);
  37552. },
  37553. findEntry: function findEntry(predicate, context, notSetValue) {
  37554. var found = notSetValue;
  37555. this.__iterate(function (v, k, c) {
  37556. if (predicate.call(context, v, k, c)) {
  37557. found = [k, v];
  37558. return false;
  37559. }
  37560. });
  37561. return found;
  37562. },
  37563. findKey: function findKey(predicate, context) {
  37564. var entry = this.findEntry(predicate, context);
  37565. return entry && entry[0];
  37566. },
  37567. findLast: function findLast(predicate, context, notSetValue) {
  37568. return this.toKeyedSeq()
  37569. .reverse()
  37570. .find(predicate, context, notSetValue);
  37571. },
  37572. findLastEntry: function findLastEntry(predicate, context, notSetValue) {
  37573. return this.toKeyedSeq()
  37574. .reverse()
  37575. .findEntry(predicate, context, notSetValue);
  37576. },
  37577. findLastKey: function findLastKey(predicate, context) {
  37578. return this.toKeyedSeq()
  37579. .reverse()
  37580. .findKey(predicate, context);
  37581. },
  37582. first: function first(notSetValue) {
  37583. return this.find(returnTrue, null, notSetValue);
  37584. },
  37585. flatMap: function flatMap(mapper, context) {
  37586. return reify(this, flatMapFactory(this, mapper, context));
  37587. },
  37588. flatten: function flatten(depth) {
  37589. return reify(this, flattenFactory(this, depth, true));
  37590. },
  37591. fromEntrySeq: function fromEntrySeq() {
  37592. return new FromEntriesSequence(this);
  37593. },
  37594. get: function get(searchKey, notSetValue) {
  37595. return this.find(function (_, key) { return is(key, searchKey); }, undefined, notSetValue);
  37596. },
  37597. getIn: getIn$1,
  37598. groupBy: function groupBy(grouper, context) {
  37599. return groupByFactory(this, grouper, context);
  37600. },
  37601. has: function has(searchKey) {
  37602. return this.get(searchKey, NOT_SET) !== NOT_SET;
  37603. },
  37604. hasIn: hasIn$1,
  37605. isSubset: function isSubset(iter) {
  37606. iter = typeof iter.includes === 'function' ? iter : Collection(iter);
  37607. return this.every(function (value) { return iter.includes(value); });
  37608. },
  37609. isSuperset: function isSuperset(iter) {
  37610. iter = typeof iter.isSubset === 'function' ? iter : Collection(iter);
  37611. return iter.isSubset(this);
  37612. },
  37613. keyOf: function keyOf(searchValue) {
  37614. return this.findKey(function (value) { return is(value, searchValue); });
  37615. },
  37616. keySeq: function keySeq() {
  37617. return this.toSeq()
  37618. .map(keyMapper)
  37619. .toIndexedSeq();
  37620. },
  37621. last: function last(notSetValue) {
  37622. return this.toSeq()
  37623. .reverse()
  37624. .first(notSetValue);
  37625. },
  37626. lastKeyOf: function lastKeyOf(searchValue) {
  37627. return this.toKeyedSeq()
  37628. .reverse()
  37629. .keyOf(searchValue);
  37630. },
  37631. max: function max(comparator) {
  37632. return maxFactory(this, comparator);
  37633. },
  37634. maxBy: function maxBy(mapper, comparator) {
  37635. return maxFactory(this, comparator, mapper);
  37636. },
  37637. min: function min(comparator) {
  37638. return maxFactory(
  37639. this,
  37640. comparator ? neg(comparator) : defaultNegComparator
  37641. );
  37642. },
  37643. minBy: function minBy(mapper, comparator) {
  37644. return maxFactory(
  37645. this,
  37646. comparator ? neg(comparator) : defaultNegComparator,
  37647. mapper
  37648. );
  37649. },
  37650. rest: function rest() {
  37651. return this.slice(1);
  37652. },
  37653. skip: function skip(amount) {
  37654. return amount === 0 ? this : this.slice(Math.max(0, amount));
  37655. },
  37656. skipLast: function skipLast(amount) {
  37657. return amount === 0 ? this : this.slice(0, -Math.max(0, amount));
  37658. },
  37659. skipWhile: function skipWhile(predicate, context) {
  37660. return reify(this, skipWhileFactory(this, predicate, context, true));
  37661. },
  37662. skipUntil: function skipUntil(predicate, context) {
  37663. return this.skipWhile(not(predicate), context);
  37664. },
  37665. sortBy: function sortBy(mapper, comparator) {
  37666. return reify(this, sortFactory(this, comparator, mapper));
  37667. },
  37668. take: function take(amount) {
  37669. return this.slice(0, Math.max(0, amount));
  37670. },
  37671. takeLast: function takeLast(amount) {
  37672. return this.slice(-Math.max(0, amount));
  37673. },
  37674. takeWhile: function takeWhile(predicate, context) {
  37675. return reify(this, takeWhileFactory(this, predicate, context));
  37676. },
  37677. takeUntil: function takeUntil(predicate, context) {
  37678. return this.takeWhile(not(predicate), context);
  37679. },
  37680. update: function update(fn) {
  37681. return fn(this);
  37682. },
  37683. valueSeq: function valueSeq() {
  37684. return this.toIndexedSeq();
  37685. },
  37686. // ### Hashable Object
  37687. hashCode: function hashCode() {
  37688. return this.__hash || (this.__hash = hashCollection(this));
  37689. },
  37690. // ### Internal
  37691. // abstract __iterate(fn, reverse)
  37692. // abstract __iterator(type, reverse)
  37693. });
  37694. var CollectionPrototype = Collection.prototype;
  37695. CollectionPrototype[IS_COLLECTION_SYMBOL] = true;
  37696. CollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.values;
  37697. CollectionPrototype.toJSON = CollectionPrototype.toArray;
  37698. CollectionPrototype.__toStringMapper = quoteString;
  37699. CollectionPrototype.inspect = CollectionPrototype.toSource = function() {
  37700. return this.toString();
  37701. };
  37702. CollectionPrototype.chain = CollectionPrototype.flatMap;
  37703. CollectionPrototype.contains = CollectionPrototype.includes;
  37704. mixin(KeyedCollection, {
  37705. // ### More sequential methods
  37706. flip: function flip() {
  37707. return reify(this, flipFactory(this));
  37708. },
  37709. mapEntries: function mapEntries(mapper, context) {
  37710. var this$1 = this;
  37711. var iterations = 0;
  37712. return reify(
  37713. this,
  37714. this.toSeq()
  37715. .map(function (v, k) { return mapper.call(context, [k, v], iterations++, this$1); })
  37716. .fromEntrySeq()
  37717. );
  37718. },
  37719. mapKeys: function mapKeys(mapper, context) {
  37720. var this$1 = this;
  37721. return reify(
  37722. this,
  37723. this.toSeq()
  37724. .flip()
  37725. .map(function (k, v) { return mapper.call(context, k, v, this$1); })
  37726. .flip()
  37727. );
  37728. },
  37729. });
  37730. var KeyedCollectionPrototype = KeyedCollection.prototype;
  37731. KeyedCollectionPrototype[IS_KEYED_SYMBOL] = true;
  37732. KeyedCollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.entries;
  37733. KeyedCollectionPrototype.toJSON = toObject;
  37734. KeyedCollectionPrototype.__toStringMapper = function (v, k) { return quoteString(k) + ': ' + quoteString(v); };
  37735. mixin(IndexedCollection, {
  37736. // ### Conversion to other types
  37737. toKeyedSeq: function toKeyedSeq() {
  37738. return new ToKeyedSequence(this, false);
  37739. },
  37740. // ### ES6 Collection methods (ES6 Array and Map)
  37741. filter: function filter(predicate, context) {
  37742. return reify(this, filterFactory(this, predicate, context, false));
  37743. },
  37744. findIndex: function findIndex(predicate, context) {
  37745. var entry = this.findEntry(predicate, context);
  37746. return entry ? entry[0] : -1;
  37747. },
  37748. indexOf: function indexOf(searchValue) {
  37749. var key = this.keyOf(searchValue);
  37750. return key === undefined ? -1 : key;
  37751. },
  37752. lastIndexOf: function lastIndexOf(searchValue) {
  37753. var key = this.lastKeyOf(searchValue);
  37754. return key === undefined ? -1 : key;
  37755. },
  37756. reverse: function reverse() {
  37757. return reify(this, reverseFactory(this, false));
  37758. },
  37759. slice: function slice(begin, end) {
  37760. return reify(this, sliceFactory(this, begin, end, false));
  37761. },
  37762. splice: function splice(index, removeNum /*, ...values*/) {
  37763. var numArgs = arguments.length;
  37764. removeNum = Math.max(removeNum || 0, 0);
  37765. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  37766. return this;
  37767. }
  37768. // If index is negative, it should resolve relative to the size of the
  37769. // collection. However size may be expensive to compute if not cached, so
  37770. // only call count() if the number is in fact negative.
  37771. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  37772. var spliced = this.slice(0, index);
  37773. return reify(
  37774. this,
  37775. numArgs === 1
  37776. ? spliced
  37777. : spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  37778. );
  37779. },
  37780. // ### More collection methods
  37781. findLastIndex: function findLastIndex(predicate, context) {
  37782. var entry = this.findLastEntry(predicate, context);
  37783. return entry ? entry[0] : -1;
  37784. },
  37785. first: function first(notSetValue) {
  37786. return this.get(0, notSetValue);
  37787. },
  37788. flatten: function flatten(depth) {
  37789. return reify(this, flattenFactory(this, depth, false));
  37790. },
  37791. get: function get(index, notSetValue) {
  37792. index = wrapIndex(this, index);
  37793. return index < 0 ||
  37794. (this.size === Infinity || (this.size !== undefined && index > this.size))
  37795. ? notSetValue
  37796. : this.find(function (_, key) { return key === index; }, undefined, notSetValue);
  37797. },
  37798. has: function has(index) {
  37799. index = wrapIndex(this, index);
  37800. return (
  37801. index >= 0 &&
  37802. (this.size !== undefined
  37803. ? this.size === Infinity || index < this.size
  37804. : this.indexOf(index) !== -1)
  37805. );
  37806. },
  37807. interpose: function interpose(separator) {
  37808. return reify(this, interposeFactory(this, separator));
  37809. },
  37810. interleave: function interleave(/*...collections*/) {
  37811. var collections = [this].concat(arrCopy(arguments));
  37812. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, collections);
  37813. var interleaved = zipped.flatten(true);
  37814. if (zipped.size) {
  37815. interleaved.size = zipped.size * collections.length;
  37816. }
  37817. return reify(this, interleaved);
  37818. },
  37819. keySeq: function keySeq() {
  37820. return Range(0, this.size);
  37821. },
  37822. last: function last(notSetValue) {
  37823. return this.get(-1, notSetValue);
  37824. },
  37825. skipWhile: function skipWhile(predicate, context) {
  37826. return reify(this, skipWhileFactory(this, predicate, context, false));
  37827. },
  37828. zip: function zip(/*, ...collections */) {
  37829. var collections = [this].concat(arrCopy(arguments));
  37830. return reify(this, zipWithFactory(this, defaultZipper, collections));
  37831. },
  37832. zipAll: function zipAll(/*, ...collections */) {
  37833. var collections = [this].concat(arrCopy(arguments));
  37834. return reify(this, zipWithFactory(this, defaultZipper, collections, true));
  37835. },
  37836. zipWith: function zipWith(zipper /*, ...collections */) {
  37837. var collections = arrCopy(arguments);
  37838. collections[0] = this;
  37839. return reify(this, zipWithFactory(this, zipper, collections));
  37840. },
  37841. });
  37842. var IndexedCollectionPrototype = IndexedCollection.prototype;
  37843. IndexedCollectionPrototype[IS_INDEXED_SYMBOL] = true;
  37844. IndexedCollectionPrototype[IS_ORDERED_SYMBOL] = true;
  37845. mixin(SetCollection, {
  37846. // ### ES6 Collection methods (ES6 Array and Map)
  37847. get: function get(value, notSetValue) {
  37848. return this.has(value) ? value : notSetValue;
  37849. },
  37850. includes: function includes(value) {
  37851. return this.has(value);
  37852. },
  37853. // ### More sequential methods
  37854. keySeq: function keySeq() {
  37855. return this.valueSeq();
  37856. },
  37857. });
  37858. SetCollection.prototype.has = CollectionPrototype.includes;
  37859. SetCollection.prototype.contains = SetCollection.prototype.includes;
  37860. // Mixin subclasses
  37861. mixin(KeyedSeq, KeyedCollection.prototype);
  37862. mixin(IndexedSeq, IndexedCollection.prototype);
  37863. mixin(SetSeq, SetCollection.prototype);
  37864. // #pragma Helper functions
  37865. function reduce(collection, reducer, reduction, context, useFirst, reverse) {
  37866. assertNotInfinite(collection.size);
  37867. collection.__iterate(function (v, k, c) {
  37868. if (useFirst) {
  37869. useFirst = false;
  37870. reduction = v;
  37871. } else {
  37872. reduction = reducer.call(context, reduction, v, k, c);
  37873. }
  37874. }, reverse);
  37875. return reduction;
  37876. }
  37877. function keyMapper(v, k) {
  37878. return k;
  37879. }
  37880. function entryMapper(v, k) {
  37881. return [k, v];
  37882. }
  37883. function not(predicate) {
  37884. return function() {
  37885. return !predicate.apply(this, arguments);
  37886. };
  37887. }
  37888. function neg(predicate) {
  37889. return function() {
  37890. return -predicate.apply(this, arguments);
  37891. };
  37892. }
  37893. function defaultZipper() {
  37894. return arrCopy(arguments);
  37895. }
  37896. function defaultNegComparator(a, b) {
  37897. return a < b ? 1 : a > b ? -1 : 0;
  37898. }
  37899. function hashCollection(collection) {
  37900. if (collection.size === Infinity) {
  37901. return 0;
  37902. }
  37903. var ordered = isOrdered(collection);
  37904. var keyed = isKeyed(collection);
  37905. var h = ordered ? 1 : 0;
  37906. var size = collection.__iterate(
  37907. keyed
  37908. ? ordered
  37909. ? function (v, k) {
  37910. h = (31 * h + hashMerge(hash(v), hash(k))) | 0;
  37911. }
  37912. : function (v, k) {
  37913. h = (h + hashMerge(hash(v), hash(k))) | 0;
  37914. }
  37915. : ordered
  37916. ? function (v) {
  37917. h = (31 * h + hash(v)) | 0;
  37918. }
  37919. : function (v) {
  37920. h = (h + hash(v)) | 0;
  37921. }
  37922. );
  37923. return murmurHashOfSize(size, h);
  37924. }
  37925. function murmurHashOfSize(size, h) {
  37926. h = imul(h, 0xcc9e2d51);
  37927. h = imul((h << 15) | (h >>> -15), 0x1b873593);
  37928. h = imul((h << 13) | (h >>> -13), 5);
  37929. h = ((h + 0xe6546b64) | 0) ^ size;
  37930. h = imul(h ^ (h >>> 16), 0x85ebca6b);
  37931. h = imul(h ^ (h >>> 13), 0xc2b2ae35);
  37932. h = smi(h ^ (h >>> 16));
  37933. return h;
  37934. }
  37935. function hashMerge(a, b) {
  37936. return (a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2))) | 0; // int
  37937. }
  37938. var OrderedSet = /*@__PURE__*/(function (Set$$1) {
  37939. function OrderedSet(value) {
  37940. return value === null || value === undefined
  37941. ? emptyOrderedSet()
  37942. : isOrderedSet(value)
  37943. ? value
  37944. : emptyOrderedSet().withMutations(function (set) {
  37945. var iter = SetCollection(value);
  37946. assertNotInfinite(iter.size);
  37947. iter.forEach(function (v) { return set.add(v); });
  37948. });
  37949. }
  37950. if ( Set$$1 ) OrderedSet.__proto__ = Set$$1;
  37951. OrderedSet.prototype = Object.create( Set$$1 && Set$$1.prototype );
  37952. OrderedSet.prototype.constructor = OrderedSet;
  37953. OrderedSet.of = function of (/*...values*/) {
  37954. return this(arguments);
  37955. };
  37956. OrderedSet.fromKeys = function fromKeys (value) {
  37957. return this(KeyedCollection(value).keySeq());
  37958. };
  37959. OrderedSet.prototype.toString = function toString () {
  37960. return this.__toString('OrderedSet {', '}');
  37961. };
  37962. return OrderedSet;
  37963. }(Set));
  37964. OrderedSet.isOrderedSet = isOrderedSet;
  37965. var OrderedSetPrototype = OrderedSet.prototype;
  37966. OrderedSetPrototype[IS_ORDERED_SYMBOL] = true;
  37967. OrderedSetPrototype.zip = IndexedCollectionPrototype.zip;
  37968. OrderedSetPrototype.zipWith = IndexedCollectionPrototype.zipWith;
  37969. OrderedSetPrototype.__empty = emptyOrderedSet;
  37970. OrderedSetPrototype.__make = makeOrderedSet;
  37971. function makeOrderedSet(map, ownerID) {
  37972. var set = Object.create(OrderedSetPrototype);
  37973. set.size = map ? map.size : 0;
  37974. set._map = map;
  37975. set.__ownerID = ownerID;
  37976. return set;
  37977. }
  37978. var EMPTY_ORDERED_SET;
  37979. function emptyOrderedSet() {
  37980. return (
  37981. EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()))
  37982. );
  37983. }
  37984. var Record = function Record(defaultValues, name) {
  37985. var hasInitialized;
  37986. var RecordType = function Record(values) {
  37987. var this$1 = this;
  37988. if (values instanceof RecordType) {
  37989. return values;
  37990. }
  37991. if (!(this instanceof RecordType)) {
  37992. return new RecordType(values);
  37993. }
  37994. if (!hasInitialized) {
  37995. hasInitialized = true;
  37996. var keys = Object.keys(defaultValues);
  37997. var indices = (RecordTypePrototype._indices = {});
  37998. // Deprecated: left to attempt not to break any external code which
  37999. // relies on a ._name property existing on record instances.
  38000. // Use Record.getDescriptiveName() instead
  38001. RecordTypePrototype._name = name;
  38002. RecordTypePrototype._keys = keys;
  38003. RecordTypePrototype._defaultValues = defaultValues;
  38004. for (var i = 0; i < keys.length; i++) {
  38005. var propName = keys[i];
  38006. indices[propName] = i;
  38007. if (RecordTypePrototype[propName]) {
  38008. /* eslint-disable no-console */
  38009. typeof console === 'object' &&
  38010. console.warn &&
  38011. console.warn(
  38012. 'Cannot define ' +
  38013. recordName(this) +
  38014. ' with property "' +
  38015. propName +
  38016. '" since that property name is part of the Record API.'
  38017. );
  38018. /* eslint-enable no-console */
  38019. } else {
  38020. setProp(RecordTypePrototype, propName);
  38021. }
  38022. }
  38023. }
  38024. this.__ownerID = undefined;
  38025. this._values = List().withMutations(function (l) {
  38026. l.setSize(this$1._keys.length);
  38027. KeyedCollection(values).forEach(function (v, k) {
  38028. l.set(this$1._indices[k], v === this$1._defaultValues[k] ? undefined : v);
  38029. });
  38030. });
  38031. };
  38032. var RecordTypePrototype = (RecordType.prototype = Object.create(
  38033. RecordPrototype
  38034. ));
  38035. RecordTypePrototype.constructor = RecordType;
  38036. if (name) {
  38037. RecordType.displayName = name;
  38038. }
  38039. return RecordType;
  38040. };
  38041. Record.prototype.toString = function toString () {
  38042. var str = recordName(this) + ' { ';
  38043. var keys = this._keys;
  38044. var k;
  38045. for (var i = 0, l = keys.length; i !== l; i++) {
  38046. k = keys[i];
  38047. str += (i ? ', ' : '') + k + ': ' + quoteString(this.get(k));
  38048. }
  38049. return str + ' }';
  38050. };
  38051. Record.prototype.equals = function equals (other) {
  38052. return (
  38053. this === other ||
  38054. (other &&
  38055. this._keys === other._keys &&
  38056. recordSeq(this).equals(recordSeq(other)))
  38057. );
  38058. };
  38059. Record.prototype.hashCode = function hashCode () {
  38060. return recordSeq(this).hashCode();
  38061. };
  38062. // @pragma Access
  38063. Record.prototype.has = function has (k) {
  38064. return this._indices.hasOwnProperty(k);
  38065. };
  38066. Record.prototype.get = function get (k, notSetValue) {
  38067. if (!this.has(k)) {
  38068. return notSetValue;
  38069. }
  38070. var index = this._indices[k];
  38071. var value = this._values.get(index);
  38072. return value === undefined ? this._defaultValues[k] : value;
  38073. };
  38074. // @pragma Modification
  38075. Record.prototype.set = function set (k, v) {
  38076. if (this.has(k)) {
  38077. var newValues = this._values.set(
  38078. this._indices[k],
  38079. v === this._defaultValues[k] ? undefined : v
  38080. );
  38081. if (newValues !== this._values && !this.__ownerID) {
  38082. return makeRecord(this, newValues);
  38083. }
  38084. }
  38085. return this;
  38086. };
  38087. Record.prototype.remove = function remove (k) {
  38088. return this.set(k);
  38089. };
  38090. Record.prototype.clear = function clear () {
  38091. var newValues = this._values.clear().setSize(this._keys.length);
  38092. return this.__ownerID ? this : makeRecord(this, newValues);
  38093. };
  38094. Record.prototype.wasAltered = function wasAltered () {
  38095. return this._values.wasAltered();
  38096. };
  38097. Record.prototype.toSeq = function toSeq () {
  38098. return recordSeq(this);
  38099. };
  38100. Record.prototype.toJS = function toJS$1 () {
  38101. return toJS(this);
  38102. };
  38103. Record.prototype.entries = function entries () {
  38104. return this.__iterator(ITERATE_ENTRIES);
  38105. };
  38106. Record.prototype.__iterator = function __iterator (type, reverse) {
  38107. return recordSeq(this).__iterator(type, reverse);
  38108. };
  38109. Record.prototype.__iterate = function __iterate (fn, reverse) {
  38110. return recordSeq(this).__iterate(fn, reverse);
  38111. };
  38112. Record.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  38113. if (ownerID === this.__ownerID) {
  38114. return this;
  38115. }
  38116. var newValues = this._values.__ensureOwner(ownerID);
  38117. if (!ownerID) {
  38118. this.__ownerID = ownerID;
  38119. this._values = newValues;
  38120. return this;
  38121. }
  38122. return makeRecord(this, newValues, ownerID);
  38123. };
  38124. Record.isRecord = isRecord;
  38125. Record.getDescriptiveName = recordName;
  38126. var RecordPrototype = Record.prototype;
  38127. RecordPrototype[IS_RECORD_SYMBOL] = true;
  38128. RecordPrototype[DELETE] = RecordPrototype.remove;
  38129. RecordPrototype.deleteIn = RecordPrototype.removeIn = deleteIn;
  38130. RecordPrototype.getIn = getIn$1;
  38131. RecordPrototype.hasIn = CollectionPrototype.hasIn;
  38132. RecordPrototype.merge = merge;
  38133. RecordPrototype.mergeWith = mergeWith;
  38134. RecordPrototype.mergeIn = mergeIn;
  38135. RecordPrototype.mergeDeep = mergeDeep$1;
  38136. RecordPrototype.mergeDeepWith = mergeDeepWith$1;
  38137. RecordPrototype.mergeDeepIn = mergeDeepIn;
  38138. RecordPrototype.setIn = setIn$1;
  38139. RecordPrototype.update = update$1;
  38140. RecordPrototype.updateIn = updateIn$1;
  38141. RecordPrototype.withMutations = withMutations;
  38142. RecordPrototype.asMutable = asMutable;
  38143. RecordPrototype.asImmutable = asImmutable;
  38144. RecordPrototype[ITERATOR_SYMBOL] = RecordPrototype.entries;
  38145. RecordPrototype.toJSON = RecordPrototype.toObject =
  38146. CollectionPrototype.toObject;
  38147. RecordPrototype.inspect = RecordPrototype.toSource = function() {
  38148. return this.toString();
  38149. };
  38150. function makeRecord(likeRecord, values, ownerID) {
  38151. var record = Object.create(Object.getPrototypeOf(likeRecord));
  38152. record._values = values;
  38153. record.__ownerID = ownerID;
  38154. return record;
  38155. }
  38156. function recordName(record) {
  38157. return record.constructor.displayName || record.constructor.name || 'Record';
  38158. }
  38159. function recordSeq(record) {
  38160. return keyedSeqFromValue(record._keys.map(function (k) { return [k, record.get(k)]; }));
  38161. }
  38162. function setProp(prototype, name) {
  38163. try {
  38164. Object.defineProperty(prototype, name, {
  38165. get: function() {
  38166. return this.get(name);
  38167. },
  38168. set: function(value) {
  38169. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  38170. this.set(name, value);
  38171. },
  38172. });
  38173. } catch (error) {
  38174. // Object.defineProperty failed. Probably IE8.
  38175. }
  38176. }
  38177. /**
  38178. * Returns a lazy Seq of `value` repeated `times` times. When `times` is
  38179. * undefined, returns an infinite sequence of `value`.
  38180. */
  38181. var Repeat = /*@__PURE__*/(function (IndexedSeq$$1) {
  38182. function Repeat(value, times) {
  38183. if (!(this instanceof Repeat)) {
  38184. return new Repeat(value, times);
  38185. }
  38186. this._value = value;
  38187. this.size = times === undefined ? Infinity : Math.max(0, times);
  38188. if (this.size === 0) {
  38189. if (EMPTY_REPEAT) {
  38190. return EMPTY_REPEAT;
  38191. }
  38192. EMPTY_REPEAT = this;
  38193. }
  38194. }
  38195. if ( IndexedSeq$$1 ) Repeat.__proto__ = IndexedSeq$$1;
  38196. Repeat.prototype = Object.create( IndexedSeq$$1 && IndexedSeq$$1.prototype );
  38197. Repeat.prototype.constructor = Repeat;
  38198. Repeat.prototype.toString = function toString () {
  38199. if (this.size === 0) {
  38200. return 'Repeat []';
  38201. }
  38202. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  38203. };
  38204. Repeat.prototype.get = function get (index, notSetValue) {
  38205. return this.has(index) ? this._value : notSetValue;
  38206. };
  38207. Repeat.prototype.includes = function includes (searchValue) {
  38208. return is(this._value, searchValue);
  38209. };
  38210. Repeat.prototype.slice = function slice (begin, end) {
  38211. var size = this.size;
  38212. return wholeSlice(begin, end, size)
  38213. ? this
  38214. : new Repeat(
  38215. this._value,
  38216. resolveEnd(end, size) - resolveBegin(begin, size)
  38217. );
  38218. };
  38219. Repeat.prototype.reverse = function reverse () {
  38220. return this;
  38221. };
  38222. Repeat.prototype.indexOf = function indexOf (searchValue) {
  38223. if (is(this._value, searchValue)) {
  38224. return 0;
  38225. }
  38226. return -1;
  38227. };
  38228. Repeat.prototype.lastIndexOf = function lastIndexOf (searchValue) {
  38229. if (is(this._value, searchValue)) {
  38230. return this.size;
  38231. }
  38232. return -1;
  38233. };
  38234. Repeat.prototype.__iterate = function __iterate (fn, reverse) {
  38235. var size = this.size;
  38236. var i = 0;
  38237. while (i !== size) {
  38238. if (fn(this._value, reverse ? size - ++i : i++, this) === false) {
  38239. break;
  38240. }
  38241. }
  38242. return i;
  38243. };
  38244. Repeat.prototype.__iterator = function __iterator (type, reverse) {
  38245. var this$1 = this;
  38246. var size = this.size;
  38247. var i = 0;
  38248. return new Iterator(
  38249. function () { return i === size
  38250. ? iteratorDone()
  38251. : iteratorValue(type, reverse ? size - ++i : i++, this$1._value); }
  38252. );
  38253. };
  38254. Repeat.prototype.equals = function equals (other) {
  38255. return other instanceof Repeat
  38256. ? is(this._value, other._value)
  38257. : deepEqual(other);
  38258. };
  38259. return Repeat;
  38260. }(IndexedSeq));
  38261. var EMPTY_REPEAT;
  38262. function fromJS(value, converter) {
  38263. return fromJSWith(
  38264. [],
  38265. converter || defaultConverter,
  38266. value,
  38267. '',
  38268. converter && converter.length > 2 ? [] : undefined,
  38269. { '': value }
  38270. );
  38271. }
  38272. function fromJSWith(stack, converter, value, key, keyPath, parentValue) {
  38273. var toSeq = Array.isArray(value)
  38274. ? IndexedSeq
  38275. : isPlainObj(value)
  38276. ? KeyedSeq
  38277. : null;
  38278. if (toSeq) {
  38279. if (~stack.indexOf(value)) {
  38280. throw new TypeError('Cannot convert circular structure to Immutable');
  38281. }
  38282. stack.push(value);
  38283. keyPath && key !== '' && keyPath.push(key);
  38284. var converted = converter.call(
  38285. parentValue,
  38286. key,
  38287. toSeq(value).map(function (v, k) { return fromJSWith(stack, converter, v, k, keyPath, value); }
  38288. ),
  38289. keyPath && keyPath.slice()
  38290. );
  38291. stack.pop();
  38292. keyPath && keyPath.pop();
  38293. return converted;
  38294. }
  38295. return value;
  38296. }
  38297. function defaultConverter(k, v) {
  38298. return isKeyed(v) ? v.toMap() : v.toList();
  38299. }
  38300. var version = "4.0.0-rc.11";
  38301. var Immutable = {
  38302. version: version,
  38303. Collection: Collection,
  38304. // Note: Iterable is deprecated
  38305. Iterable: Collection,
  38306. Seq: Seq,
  38307. Map: Map,
  38308. OrderedMap: OrderedMap,
  38309. List: List,
  38310. Stack: Stack,
  38311. Set: Set,
  38312. OrderedSet: OrderedSet,
  38313. Record: Record,
  38314. Range: Range,
  38315. Repeat: Repeat,
  38316. is: is,
  38317. fromJS: fromJS,
  38318. hash: hash,
  38319. isImmutable: isImmutable,
  38320. isCollection: isCollection,
  38321. isKeyed: isKeyed,
  38322. isIndexed: isIndexed,
  38323. isAssociative: isAssociative,
  38324. isOrdered: isOrdered,
  38325. isValueObject: isValueObject,
  38326. isSeq: isSeq,
  38327. isList: isList,
  38328. isMap: isMap,
  38329. isOrderedMap: isOrderedMap,
  38330. isStack: isStack,
  38331. isSet: isSet,
  38332. isOrderedSet: isOrderedSet,
  38333. isRecord: isRecord,
  38334. get: get,
  38335. getIn: getIn,
  38336. has: has,
  38337. hasIn: hasIn,
  38338. merge: merge$1,
  38339. mergeDeep: mergeDeep,
  38340. mergeWith: mergeWith$1,
  38341. mergeDeepWith: mergeDeepWith,
  38342. remove: remove,
  38343. removeIn: removeIn,
  38344. set: set,
  38345. setIn: setIn,
  38346. update: update,
  38347. updateIn: updateIn,
  38348. };
  38349. // Note: Iterable is deprecated
  38350. var Iterable = Collection;
  38351. exports.default = Immutable;
  38352. exports.version = version;
  38353. exports.Collection = Collection;
  38354. exports.Iterable = Iterable;
  38355. exports.Seq = Seq;
  38356. exports.Map = Map;
  38357. exports.OrderedMap = OrderedMap;
  38358. exports.List = List;
  38359. exports.Stack = Stack;
  38360. exports.Set = Set;
  38361. exports.OrderedSet = OrderedSet;
  38362. exports.Record = Record;
  38363. exports.Range = Range;
  38364. exports.Repeat = Repeat;
  38365. exports.is = is;
  38366. exports.fromJS = fromJS;
  38367. exports.hash = hash;
  38368. exports.isImmutable = isImmutable;
  38369. exports.isCollection = isCollection;
  38370. exports.isKeyed = isKeyed;
  38371. exports.isIndexed = isIndexed;
  38372. exports.isAssociative = isAssociative;
  38373. exports.isOrdered = isOrdered;
  38374. exports.isValueObject = isValueObject;
  38375. exports.get = get;
  38376. exports.getIn = getIn;
  38377. exports.has = has;
  38378. exports.hasIn = hasIn;
  38379. exports.merge = merge$1;
  38380. exports.mergeDeep = mergeDeep;
  38381. exports.mergeWith = mergeWith$1;
  38382. exports.mergeDeepWith = mergeDeepWith;
  38383. exports.remove = remove;
  38384. exports.removeIn = removeIn;
  38385. exports.set = set;
  38386. exports.setIn = setIn;
  38387. exports.update = update;
  38388. exports.updateIn = updateIn;
  38389. Object.defineProperty(exports, '__esModule', { value: true });
  38390. })));
  38391. });
  38392. unwrapExports(immutable$3);
  38393. var draftjsUtils$1 = createCommonjsModule(function (module, exports) {
  38394. !function(t,e){module.exports=e(Draft,immutable$3);}(window,function(n,r){return u={},o.m=i=[function(t,e){t.exports=n;},function(t,e){t.exports=r;},function(t,e,n){t.exports=n(3);},function(t,e,n){n.r(e);var C=n(0),i=n(1);function m(t){var e=t.getSelection(),n=t.getCurrentContent(),r=e.getStartKey(),o=e.getEndKey(),i=n.getBlockMap();return i.toSeq().skipUntil(function(t,e){return e===r}).takeUntil(function(t,e){return e===o}).concat([[o,i.get(o)]])}function a(t){return m(t).toList()}function f(t){if(t)return a(t).get(0)}function r(t){if(t){var n=f(t),e=t.getCurrentContent().getBlockMap().toSeq().toList(),r=0;if(e.forEach(function(t,e){t.get("key")===n.get("key")&&(r=e-1);}),-1<r)return e.get(r)}}function o(t){return t?t.getCurrentContent().getBlockMap().toList():new i.List}function u(t){var e=a(t);if(!e.some(function(t){return t.type!==e.get(0).type}))return e.get(0).type}function c(t){var e=C.RichUtils.tryToRemoveBlockStyle(t);return e?C.EditorState.push(t,e,"change-block-type"):t}function l(t){var e="",n=t.getSelection(),r=n.getAnchorOffset(),o=n.getFocusOffset(),i=a(t);if(0<i.size){if(n.getIsBackward()){var u=r;r=o,o=u;}for(var c=0;c<i.size;c+=1){var f=0===c?r:0,l=c===i.size-1?o:i.get(c).getText().length;e+=i.get(c).getText().slice(f,l);}}return e}function s(t){var e=t.getCurrentContent(),n=t.getSelection(),r=C.Modifier.removeRange(e,n,"forward"),o=r.getSelectionAfter(),i=r.getBlockForKey(o.getStartKey());return r=C.Modifier.insertText(r,o,"\n",i.getInlineStyleAt(o.getStartOffset()),null),C.EditorState.push(t,r,"insert-fragment")}function g(t){var e=C.Modifier.splitBlock(t.getCurrentContent(),t.getSelection());return c(C.EditorState.push(t,e,"split-block"))}function d(t){var e=t.getCurrentContent().getBlockMap().toList(),n=t.getSelection().merge({anchorKey:e.first().get("key"),anchorOffset:0,focusKey:e.last().get("key"),focusOffset:e.last().getLength()}),r=C.Modifier.removeRange(t.getCurrentContent(),n,"forward");return C.EditorState.push(t,r,"remove-range")}function S(t,e){var n=C.Modifier.setBlockData(t.getCurrentContent(),t.getSelection(),e);return C.EditorState.push(t,n,"change-block-data")}function p(t){var r=new i.Map({}),e=a(t);if(e&&0<e.size)for(var n=function(t){var n=e.get(t).getData();if(!n||0===n.size)return r=r.clear(),"break";if(0===t)r=n;else if(r.forEach(function(t,e){n.get(e)&&n.get(e)===t||(r=r.delete(e));}),0===r.size)return r=r.clear(),"break"},o=0;o<e.size;o+=1){if("break"===n(o))break}return r}var y=Object(i.Map)({code:{element:"pre"}}),v=C.DefaultDraftBlockRenderMap.merge(y);function b(t){if(t){var e=t.getType();return "unordered-list-item"===e||"ordered-list-item"===e}return !1}function h(t,e,n){var r,o=t.getSelection();r=o.getIsBackward()?o.getFocusKey():o.getAnchorKey();var i=t.getCurrentContent(),u=i.getBlockForKey(r),c=u.getType();if("unordered-list-item"!==c&&"ordered-list-item"!==c)return t;var f=i.getBlockBefore(r);if(!f)return t;if(f.getType()!==c)return t;var l=u.getDepth();if(1===e&&l===n)return t;var a,s,g,d,S,p,y,v=Math.min(f.getDepth()+1,n),b=(s=e,g=v,d=(a=t).getSelection(),S=a.getCurrentContent(),p=S.getBlockMap(),y=m(a).map(function(t){var e=t.getDepth()+s;return e=Math.max(0,Math.min(e,g)),t.set("depth",e)}),p=p.merge(y),S.merge({blockMap:p,selectionBefore:d,selectionAfter:d}));return C.EditorState.push(t,b,"adjust-depth")}function O(t,e){var n;return 13===(n=e).which&&(n.getModifierState("Shift")||n.getModifierState("Alt")||n.getModifierState("Control"))?t.getSelection().isCollapsed()?C.RichUtils.insertSoftNewline(t):s(t):function(t){var e=t.getSelection();if(e.isCollapsed()){var n=t.getCurrentContent(),r=e.getStartKey(),o=n.getBlockForKey(r);if(!b(o)&&"unstyled"!==o.getType()&&o.getLength()===e.getStartOffset())return g(t);if(b(o)&&0===o.getLength()){var i=o.getDepth();if(0===i)return c(t);if(0<i)return h(t,-1,i)}}}(t)}function k(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r);}return n}function E(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function I(t){return (I="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function R(t){var e=t.getSelection();if(e.isCollapsed()){var n={},r=t.getCurrentInlineStyle().toList().toJS();if(r)return ["BOLD","ITALIC","UNDERLINE","STRIKETHROUGH","CODE","SUPERSCRIPT","SUBSCRIPT"].forEach(function(t){n[t]=0<=r.indexOf(t);}),n}var u=e.getStartOffset(),c=e.getEndOffset(),f=a(t);if(0<f.size){var o=function(){for(var n={BOLD:!0,ITALIC:!0,UNDERLINE:!0,STRIKETHROUGH:!0,CODE:!0,SUPERSCRIPT:!0,SUBSCRIPT:!0},r=0;r<f.size;r+=1){var t=0===r?u:0,e=r===f.size-1?c:f.get(r).getText().length;t===e&&0===t?(t=1,e=2):t===e&&--t;for(var o=function(t){var e=f.get(r).getInlineStyleAt(t);["BOLD","ITALIC","UNDERLINE","STRIKETHROUGH","CODE","SUPERSCRIPT","SUBSCRIPT"].forEach(function(t){n[t]=n[t]&&e.get(t)===t;});},i=t;i<e;i+=1)o(i);}return {v:n}}();if("object"===I(o))return o.v}return {}}function B(t){var e,n=t.getSelection(),r=n.getStartOffset(),o=n.getEndOffset();r===o&&0===r?o=1:r===o&&--r;for(var i=f(t),u=r;u<o;u+=1){var c=i.getEntityAt(u);if(!c){e=void 0;break}if(u===r)e=c;else if(e!==c){e=void 0;break}}return e}function T(t,e){var n,r=f(t);return r.findEntityRanges(function(t){return t.get("entity")===e},function(t,e){n={start:t,end:e,text:r.get("text").slice(t,e)};}),n}function P(t,e,n){x[t]["".concat(t.toLowerCase(),"-").concat(n)]=E({},"".concat(e),n);}function j(){return function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?k(Object(n),!0).forEach(function(t){E(e,t,n[t]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):k(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t));});}return e}({},x.color,{},x.bgcolor,{},x.fontSize,{},x.fontFamily,{CODE:x.CODE,SUPERSCRIPT:x.SUPERSCRIPT,SUBSCRIPT:x.SUBSCRIPT})}var x={color:{},bgcolor:{},fontSize:{},fontFamily:{},CODE:{fontFamily:"monospace",wordWrap:"break-word",background:"#f1f1f1",borderRadius:3,padding:"1px 3px"},SUPERSCRIPT:{fontSize:11,position:"relative",top:-8,display:"inline-flex"},SUBSCRIPT:{fontSize:11,position:"relative",bottom:-8,display:"inline-flex"}};function M(t,e,n){var r=t.getSelection(),o=Object.keys(x[e]).reduce(function(t,e){return C.Modifier.removeInlineStyle(t,r,e)},t.getCurrentContent()),i=C.EditorState.push(t,o,"changeinline-style"),u=t.getCurrentInlineStyle();if(r.isCollapsed()&&(i=u.reduce(function(t,e){return C.RichUtils.toggleInlineStyle(t,e)},i)),"SUPERSCRIPT"===e||"SUBSCRIPT"==e)u.has(n)||(i=C.RichUtils.toggleInlineStyle(i,n));else{var c="bgcolor"===e?"backgroundColor":e;u.has("".concat(c,"-").concat(n))||(i=C.RichUtils.toggleInlineStyle(i,"".concat(e.toLowerCase(),"-").concat(n)),P(e,c,n));}return i}function L(t){t&&t.getCurrentContent().getBlockMap().map(function(t){return t.get("characterList")}).toList().flatten().forEach(function(t){t&&0===t.indexOf("color-")?P("color","color",t.substr(6)):t&&0===t.indexOf("bgcolor-")?P("bgcolor","backgroundColor",t.substr(8)):t&&0===t.indexOf("fontsize-")?P("fontSize","fontSize",+t.substr(9)):t&&0===t.indexOf("fontfamily-")&&P("fontFamily","fontFamily",t.substr(11));});}function U(t,e,n){var r=t.getInlineStyleAt(n).toList().filter(function(t){return t.startsWith(e.toLowerCase())});if(r&&0<r.size)return r.get(0)}function w(r,l){if(r&&l&&0<l.length){var t=function(){var t=r.getSelection(),i={};if(t.isCollapsed())return l.forEach(function(t){i[t]=function(t,e){var n=t.getCurrentInlineStyle().toList().filter(function(t){return t.startsWith(e.toLowerCase())});if(n&&0<n.size)return n.get(0)}(r,t);}),{v:i};var u=t.getStartOffset(),c=t.getEndOffset(),f=a(r);if(0<f.size){for(var e=function(n){var t=0===n?u:0,e=n===f.size-1?c:f.get(n).getText().length;t===e&&0===t?(t=1,e=2):t===e&&--t;for(var r=function(e){e===t?l.forEach(function(t){i[t]=U(f.get(n),t,e);}):l.forEach(function(t){i[t]&&i[t]!==U(f.get(n),t,e)&&(i[t]=void 0);});},o=t;o<e;o+=1)r(o);},n=0;n<f.size;n+=1)e(n);return {v:i}}}();if("object"===I(t))return t.v}return {}}function D(e){var t=e.getCurrentInlineStyle(),n=e.getCurrentContent();return t.forEach(function(t){n=C.Modifier.removeInlineStyle(n,e.getSelection(),t);}),C.EditorState.push(e,n,"change-inline-style")}n.d(e,"isListBlock",function(){return b}),n.d(e,"changeDepth",function(){return h}),n.d(e,"handleNewLine",function(){return O}),n.d(e,"getEntityRange",function(){return T}),n.d(e,"getCustomStyleMap",function(){return j}),n.d(e,"toggleCustomInlineStyle",function(){return M}),n.d(e,"getSelectionEntity",function(){return B}),n.d(e,"extractInlineStyle",function(){return L}),n.d(e,"removeAllInlineStyles",function(){return D}),n.d(e,"getSelectionInlineStyle",function(){return R}),n.d(e,"getSelectionCustomInlineStyle",function(){return w}),n.d(e,"getSelectedBlocksMap",function(){return m}),n.d(e,"getSelectedBlocksList",function(){return a}),n.d(e,"getSelectedBlock",function(){return f}),n.d(e,"getBlockBeforeSelectedBlock",function(){return r}),n.d(e,"getAllBlocks",function(){return o}),n.d(e,"getSelectedBlocksType",function(){return u}),n.d(e,"removeSelectedBlocksStyle",function(){return c}),n.d(e,"getSelectionText",function(){return l}),n.d(e,"addLineBreakRemovingSelection",function(){return s}),n.d(e,"insertNewUnstyledBlock",function(){return g}),n.d(e,"clearEditorContent",function(){return d}),n.d(e,"setBlockData",function(){return S}),n.d(e,"getSelectedBlocksMetadata",function(){return p}),n.d(e,"blockRenderMap",function(){return v});}],o.c=u,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n});},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0});},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)o.d(n,r,function(t){return e[t]}.bind(null,r));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=2);function o(t){if(u[t])return u[t].exports;var e=u[t]={i:t,l:!1,exports:{}};return i[t].call(e.exports,e,e.exports,o),e.l=!0,e.exports}var i,u;});
  38395. });
  38396. unwrapExports(draftjsUtils$1);
  38397. var draftjsUtils_1$1 = draftjsUtils$1.draftjsUtils;
  38398. var content$1 = createCommonjsModule(function (module, exports) {
  38399. Object.defineProperty(exports, "__esModule", {
  38400. value: true
  38401. });
  38402. 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;
  38403. var _immutable2 = _interopRequireDefault(immutable$3);
  38404. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  38405. var strictBlockTypes = ['atomic'];
  38406. var registerStrictBlockType = exports.registerStrictBlockType = function registerStrictBlockType(blockType) {
  38407. strictBlockTypes.indexOf(blockType) === -1 && strictBlockTypes.push(blockType);
  38408. };
  38409. var isEditorState = exports.isEditorState = function isEditorState(editorState) {
  38410. return editorState instanceof Draft.EditorState;
  38411. };
  38412. var createEmptyEditorState = exports.createEmptyEditorState = function createEmptyEditorState(editorDecorators) {
  38413. return Draft.EditorState.createEmpty(editorDecorators);
  38414. };
  38415. var createEditorState = exports.createEditorState = function createEditorState(contentState, editorDecorators) {
  38416. return Draft.EditorState.createWithContent(contentState, editorDecorators);
  38417. };
  38418. var isSelectionCollapsed = exports.isSelectionCollapsed = function isSelectionCollapsed(editorState) {
  38419. return editorState.getSelection().isCollapsed();
  38420. };
  38421. var selectionContainsBlockType = exports.selectionContainsBlockType = function selectionContainsBlockType(editorState, blockType) {
  38422. return getSelectedBlocks(editorState).find(function (block) {
  38423. return block.getType() === blockType;
  38424. });
  38425. };
  38426. var selectionContainsStrictBlock = exports.selectionContainsStrictBlock = function selectionContainsStrictBlock(editorState) {
  38427. return getSelectedBlocks(editorState).find(function (block) {
  38428. return ~strictBlockTypes.indexOf(block.getType());
  38429. });
  38430. };
  38431. var selectBlock = exports.selectBlock = function selectBlock(editorState, block) {
  38432. var blockKey = block.getKey();
  38433. return Draft.EditorState.forceSelection(editorState, new Draft.SelectionState({
  38434. anchorKey: blockKey,
  38435. anchorOffset: 0,
  38436. focusKey: blockKey,
  38437. focusOffset: block.getLength()
  38438. }));
  38439. };
  38440. var selectNextBlock = exports.selectNextBlock = function selectNextBlock(editorState, block) {
  38441. var nextBlock = editorState.getCurrentContent().getBlockAfter(block.getKey());
  38442. return nextBlock ? selectBlock(editorState, nextBlock) : editorState;
  38443. };
  38444. var removeBlock = exports.removeBlock = function removeBlock(editorState, block) {
  38445. var lastSelection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  38446. var nextContentState = void 0,
  38447. nextEditorState = void 0;
  38448. var blockKey = block.getKey();
  38449. nextContentState = Draft.Modifier.removeRange(editorState.getCurrentContent(), new Draft.SelectionState({
  38450. anchorKey: blockKey,
  38451. anchorOffset: 0,
  38452. focusKey: blockKey,
  38453. focusOffset: block.getLength()
  38454. }), 'backward');
  38455. nextContentState = Draft.Modifier.setBlockType(nextContentState, nextContentState.getSelectionAfter(), 'unstyled');
  38456. nextEditorState = Draft.EditorState.push(editorState, nextContentState, 'remove-range');
  38457. return Draft.EditorState.forceSelection(nextEditorState, lastSelection || nextContentState.getSelectionAfter());
  38458. };
  38459. var getSelectionBlock = exports.getSelectionBlock = function getSelectionBlock(editorState) {
  38460. return editorState.getCurrentContent().getBlockForKey(editorState.getSelection().getAnchorKey());
  38461. };
  38462. var updateEachCharacterOfSelection = exports.updateEachCharacterOfSelection = function updateEachCharacterOfSelection(editorState, callback) {
  38463. var selectionState = editorState.getSelection();
  38464. var contentState = editorState.getCurrentContent();
  38465. var contentBlocks = contentState.getBlockMap();
  38466. var selectedBlocks = getSelectedBlocks(editorState);
  38467. if (selectedBlocks.length === 0) {
  38468. return editorState;
  38469. }
  38470. var startKey = selectionState.getStartKey();
  38471. var startOffset = selectionState.getStartOffset();
  38472. var endKey = selectionState.getEndKey();
  38473. var endOffset = selectionState.getEndOffset();
  38474. var nextContentBlocks = contentBlocks.map(function (block) {
  38475. if (selectedBlocks.indexOf(block) === -1) {
  38476. return block;
  38477. }
  38478. var blockKey = block.getKey();
  38479. var charactersList = block.getCharacterList();
  38480. var nextCharactersList = null;
  38481. if (blockKey === startKey && blockKey === endKey) {
  38482. nextCharactersList = charactersList.map(function (character, index) {
  38483. if (index >= startOffset && index < endOffset) {
  38484. return callback(character);
  38485. }
  38486. return character;
  38487. });
  38488. } else if (blockKey === startKey) {
  38489. nextCharactersList = charactersList.map(function (character, index) {
  38490. if (index >= startOffset) {
  38491. return callback(character);
  38492. }
  38493. return character;
  38494. });
  38495. } else if (blockKey === endKey) {
  38496. nextCharactersList = charactersList.map(function (character, index) {
  38497. if (index < endOffset) {
  38498. return callback(character);
  38499. }
  38500. return character;
  38501. });
  38502. } else {
  38503. nextCharactersList = charactersList.map(function (character) {
  38504. return callback(character);
  38505. });
  38506. }
  38507. return block.merge({
  38508. 'characterList': nextCharactersList
  38509. });
  38510. });
  38511. return Draft.EditorState.push(editorState, contentState.merge({
  38512. blockMap: nextContentBlocks,
  38513. selectionBefore: selectionState,
  38514. selectionAfter: selectionState
  38515. }), 'update-selection-character-list');
  38516. };
  38517. var getSelectedBlocks = exports.getSelectedBlocks = function getSelectedBlocks(editorState) {
  38518. var selectionState = editorState.getSelection();
  38519. var contentState = editorState.getCurrentContent();
  38520. var startKey = selectionState.getStartKey();
  38521. var endKey = selectionState.getEndKey();
  38522. var isSameBlock = startKey === endKey;
  38523. var startingBlock = contentState.getBlockForKey(startKey);
  38524. var selectedBlocks = [startingBlock];
  38525. if (!isSameBlock) {
  38526. var blockKey = startKey;
  38527. while (blockKey !== endKey) {
  38528. var nextBlock = contentState.getBlockAfter(blockKey);
  38529. selectedBlocks.push(nextBlock);
  38530. blockKey = nextBlock.getKey();
  38531. }
  38532. }
  38533. return selectedBlocks;
  38534. };
  38535. var setSelectionBlockData = exports.setSelectionBlockData = function setSelectionBlockData(editorState, blockData, override) {
  38536. var newBlockData = override ? blockData : Object.assign({}, getSelectionBlockData(editorState).toJS(), blockData);
  38537. Object.keys(newBlockData).forEach(function (key) {
  38538. if (newBlockData.hasOwnProperty(key) && newBlockData[key] === undefined) {
  38539. delete newBlockData[key];
  38540. }
  38541. });
  38542. return (0, draftjsUtils$1.setBlockData)(editorState, newBlockData);
  38543. };
  38544. var getSelectionBlockData = exports.getSelectionBlockData = function getSelectionBlockData(editorState, name) {
  38545. var blockData = getSelectionBlock(editorState).getData();
  38546. return name ? blockData.get(name) : blockData;
  38547. };
  38548. var getSelectionBlockType = exports.getSelectionBlockType = function getSelectionBlockType(editorState) {
  38549. return getSelectionBlock(editorState).getType();
  38550. };
  38551. var getSelectionText = exports.getSelectionText = function getSelectionText(editorState) {
  38552. var selectionState = editorState.getSelection();
  38553. var contentState = editorState.getCurrentContent();
  38554. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  38555. return '';
  38556. }
  38557. var anchorKey = selectionState.getAnchorKey();
  38558. var currentContentBlock = contentState.getBlockForKey(anchorKey);
  38559. var start = selectionState.getStartOffset();
  38560. var end = selectionState.getEndOffset();
  38561. return currentContentBlock.getText().slice(start, end);
  38562. };
  38563. var toggleSelectionBlockType = exports.toggleSelectionBlockType = function toggleSelectionBlockType(editorState, blockType) {
  38564. if (selectionContainsStrictBlock(editorState)) {
  38565. return editorState;
  38566. }
  38567. return Draft.RichUtils.toggleBlockType(editorState, blockType);
  38568. };
  38569. var getSelectionEntityType = exports.getSelectionEntityType = function getSelectionEntityType(editorState) {
  38570. var entityKey = (0, draftjsUtils$1.getSelectionEntity)(editorState);
  38571. if (entityKey) {
  38572. var entity = editorState.getCurrentContent().getEntity(entityKey);
  38573. return entity ? entity.get('type') : null;
  38574. }
  38575. return null;
  38576. };
  38577. var getSelectionEntityData = exports.getSelectionEntityData = function getSelectionEntityData(editorState, type) {
  38578. var entityKey = (0, draftjsUtils$1.getSelectionEntity)(editorState);
  38579. if (entityKey) {
  38580. var entity = editorState.getCurrentContent().getEntity(entityKey);
  38581. if (entity && entity.get('type') === type) {
  38582. return entity.getData();
  38583. } else {
  38584. return {};
  38585. }
  38586. } else {
  38587. return {};
  38588. }
  38589. };
  38590. var toggleSelectionEntity = exports.toggleSelectionEntity = function toggleSelectionEntity(editorState, entity) {
  38591. var contentState = editorState.getCurrentContent();
  38592. var selectionState = editorState.getSelection();
  38593. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  38594. return editorState;
  38595. }
  38596. if (!entity || !entity.type || getSelectionEntityType(editorState) === entity.type) {
  38597. return Draft.EditorState.push(editorState, Draft.Modifier.applyEntity(contentState, selectionState, null), 'apply-entity');
  38598. }
  38599. try {
  38600. var nextContentState = contentState.createEntity(entity.type, entity.mutability, entity.data);
  38601. var entityKey = nextContentState.getLastCreatedEntityKey();
  38602. var nextEditorState = Draft.EditorState.set(editorState, {
  38603. currentContent: nextContentState
  38604. });
  38605. return Draft.EditorState.push(nextEditorState, Draft.Modifier.applyEntity(nextContentState, selectionState, entityKey), 'apply-entity');
  38606. } catch (error) {
  38607. console.warn(error);
  38608. return editorState;
  38609. }
  38610. };
  38611. var toggleSelectionLink = exports.toggleSelectionLink = function toggleSelectionLink(editorState, href, target) {
  38612. var contentState = editorState.getCurrentContent();
  38613. var selectionState = editorState.getSelection();
  38614. var entityData = { href: href, target: target };
  38615. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  38616. return editorState;
  38617. }
  38618. if (href === false) {
  38619. return Draft.RichUtils.toggleLink(editorState, selectionState, null);
  38620. }
  38621. if (href === null) {
  38622. delete entityData.href;
  38623. }
  38624. try {
  38625. var nextContentState = contentState.createEntity('LINK', 'MUTABLE', entityData);
  38626. var entityKey = nextContentState.getLastCreatedEntityKey();
  38627. var nextEditorState = Draft.EditorState.set(editorState, {
  38628. currentContent: nextContentState
  38629. });
  38630. nextEditorState = Draft.RichUtils.toggleLink(nextEditorState, selectionState, entityKey);
  38631. nextEditorState = Draft.EditorState.forceSelection(nextEditorState, selectionState.merge({
  38632. anchorOffset: selectionState.getEndOffset(),
  38633. focusOffset: selectionState.getEndOffset()
  38634. }));
  38635. nextEditorState = Draft.EditorState.push(nextEditorState, Draft.Modifier.insertText(nextEditorState.getCurrentContent(), nextEditorState.getSelection(), ''), 'insert-text');
  38636. return nextEditorState;
  38637. } catch (error) {
  38638. console.warn(error);
  38639. return editorState;
  38640. }
  38641. };
  38642. var getSelectionInlineStyle = exports.getSelectionInlineStyle = function getSelectionInlineStyle(editorState) {
  38643. return editorState.getCurrentInlineStyle();
  38644. };
  38645. var selectionHasInlineStyle = exports.selectionHasInlineStyle = function selectionHasInlineStyle(editorState, style) {
  38646. return getSelectionInlineStyle(editorState).has(style.toUpperCase());
  38647. };
  38648. var toggleSelectionInlineStyle = exports.toggleSelectionInlineStyle = function toggleSelectionInlineStyle(editorState, style) {
  38649. var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
  38650. var nextEditorState = editorState;
  38651. style = prefix + style.toUpperCase();
  38652. if (prefix) {
  38653. nextEditorState = updateEachCharacterOfSelection(nextEditorState, function (characterMetadata) {
  38654. return characterMetadata.toJS().style.reduce(function (characterMetadata, characterStyle) {
  38655. if (characterStyle.indexOf(prefix) === 0 && style !== characterStyle) {
  38656. return Draft.CharacterMetadata.removeStyle(characterMetadata, characterStyle);
  38657. } else {
  38658. return characterMetadata;
  38659. }
  38660. }, characterMetadata);
  38661. });
  38662. }
  38663. return Draft.RichUtils.toggleInlineStyle(nextEditorState, style);
  38664. };
  38665. var removeSelectionInlineStyles = exports.removeSelectionInlineStyles = function removeSelectionInlineStyles(editorState) {
  38666. return updateEachCharacterOfSelection(editorState, function (characterMetadata) {
  38667. return characterMetadata.merge({
  38668. style: _immutable2.default.OrderedSet([])
  38669. });
  38670. });
  38671. };
  38672. var toggleSelectionAlignment = exports.toggleSelectionAlignment = function toggleSelectionAlignment(editorState, alignment) {
  38673. return setSelectionBlockData(editorState, {
  38674. textAlign: getSelectionBlockData(editorState, 'textAlign') !== alignment ? alignment : undefined
  38675. });
  38676. };
  38677. var toggleSelectionIndent = exports.toggleSelectionIndent = function toggleSelectionIndent(editorState, textIndent) {
  38678. var maxIndent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 6;
  38679. return textIndent < 0 || textIndent > maxIndent || isNaN(textIndent) ? editorState : setSelectionBlockData(editorState, {
  38680. textIndent: textIndent || undefined
  38681. });
  38682. };
  38683. var increaseSelectionIndent = exports.increaseSelectionIndent = function increaseSelectionIndent(editorState) {
  38684. var maxIndent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 6;
  38685. var currentIndent = getSelectionBlockData(editorState, 'textIndent') || 0;
  38686. return toggleSelectionIndent(editorState, currentIndent + 1, maxIndent);
  38687. };
  38688. var decreaseSelectionIndent = exports.decreaseSelectionIndent = function decreaseSelectionIndent(editorState) {
  38689. var currentIndent = getSelectionBlockData(editorState, 'textIndent') || 0;
  38690. return toggleSelectionIndent(editorState, currentIndent - 1);
  38691. };
  38692. var toggleSelectionColor = exports.toggleSelectionColor = function toggleSelectionColor(editorState, color) {
  38693. return toggleSelectionInlineStyle(editorState, color.replace('#', ''), 'COLOR-');
  38694. };
  38695. var toggleSelectionBackgroundColor = exports.toggleSelectionBackgroundColor = function toggleSelectionBackgroundColor(editorState, color) {
  38696. return toggleSelectionInlineStyle(editorState, color.replace('#', ''), 'BGCOLOR-');
  38697. };
  38698. var toggleSelectionFontSize = exports.toggleSelectionFontSize = function toggleSelectionFontSize(editorState, fontSize) {
  38699. return toggleSelectionInlineStyle(editorState, fontSize, 'FONTSIZE-');
  38700. };
  38701. var toggleSelectionLineHeight = exports.toggleSelectionLineHeight = function toggleSelectionLineHeight(editorState, lineHeight) {
  38702. return toggleSelectionInlineStyle(editorState, lineHeight, 'LINEHEIGHT-');
  38703. };
  38704. var toggleSelectionFontFamily = exports.toggleSelectionFontFamily = function toggleSelectionFontFamily(editorState, fontFamily) {
  38705. return toggleSelectionInlineStyle(editorState, fontFamily, 'FONTFAMILY-');
  38706. };
  38707. var toggleSelectionLetterSpacing = exports.toggleSelectionLetterSpacing = function toggleSelectionLetterSpacing(editorState, letterSpacing) {
  38708. return toggleSelectionInlineStyle(editorState, letterSpacing, 'LETTERSPACING-');
  38709. };
  38710. var insertText = exports.insertText = function insertText(editorState, text, inlineStyle, entity) {
  38711. var selectionState = editorState.getSelection();
  38712. var currentSelectedBlockType = getSelectionBlockType(editorState);
  38713. if (currentSelectedBlockType === 'atomic') {
  38714. return editorState;
  38715. }
  38716. var entityKey = void 0;
  38717. var contentState = editorState.getCurrentContent();
  38718. if (entity && entity.type) {
  38719. contentState = contentState.createEntity(entity.type, entity.mutability || 'MUTABLE', entity.data || entityData);
  38720. entityKey = contentState.getLastCreatedEntityKey();
  38721. }
  38722. if (!selectionState.isCollapsed()) {
  38723. return Draft.EditorState.push(editorState, Draft.Modifier.replaceText(contentState, selectionState, text, inlineStyle, entityKey), 'replace-text');
  38724. } else {
  38725. return Draft.EditorState.push(editorState, Draft.Modifier.insertText(contentState, selectionState, text, inlineStyle, entityKey), 'insert-text');
  38726. }
  38727. };
  38728. var insertHTML = exports.insertHTML = function insertHTML(editorState, htmlString, source) {
  38729. if (!htmlString) {
  38730. return editorState;
  38731. }
  38732. var selectionState = editorState.getSelection();
  38733. var contentState = editorState.getCurrentContent();
  38734. var options = editorState.convertOptions || {};
  38735. try {
  38736. var _convertFromRaw = (0, Draft.convertFromRaw)((0, dist.convertHTMLToRaw)(htmlString, options, source)),
  38737. blockMap = _convertFromRaw.blockMap;
  38738. return Draft.EditorState.push(editorState, Draft.Modifier.replaceWithFragment(contentState, selectionState, blockMap), 'insert-fragment');
  38739. } catch (error) {
  38740. console.warn(error);
  38741. return editorState;
  38742. }
  38743. };
  38744. var insertAtomicBlock = exports.insertAtomicBlock = function insertAtomicBlock(editorState, type) {
  38745. var immutable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  38746. var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  38747. if (selectionContainsStrictBlock(editorState)) {
  38748. return insertAtomicBlock(selectNextBlock(editorState, getSelectionBlock(editorState)), type, immutable, data);
  38749. }
  38750. var selectionState = editorState.getSelection();
  38751. var contentState = editorState.getCurrentContent();
  38752. if (!selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  38753. return editorState;
  38754. }
  38755. var contentStateWithEntity = contentState.createEntity(type, immutable ? 'IMMUTABLE' : 'MUTABLE', data);
  38756. var entityKey = contentStateWithEntity.getLastCreatedEntityKey();
  38757. var newEditorState = Draft.AtomicBlockUtils.insertAtomicBlock(editorState, entityKey, ' ');
  38758. return newEditorState;
  38759. };
  38760. var insertHorizontalLine = exports.insertHorizontalLine = function insertHorizontalLine(editorState) {
  38761. return insertAtomicBlock(editorState, 'HR');
  38762. };
  38763. var insertMedias = exports.insertMedias = function insertMedias(editorState) {
  38764. var medias = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  38765. if (!medias.length) {
  38766. return editorState;
  38767. }
  38768. return medias.reduce(function (editorState, media) {
  38769. var url = media.url,
  38770. link = media.link,
  38771. link_target = media.link_target,
  38772. name = media.name,
  38773. type = media.type,
  38774. width = media.width,
  38775. height = media.height,
  38776. meta = media.meta;
  38777. return insertAtomicBlock(editorState, type, true, { url: url, link: link, link_target: link_target, name: name, type: type, width: width, height: height, meta: meta });
  38778. }, editorState);
  38779. };
  38780. var setMediaData = exports.setMediaData = function setMediaData(editorState, entityKey, data) {
  38781. return Draft.EditorState.push(editorState, editorState.getCurrentContent().mergeEntityData(entityKey, data), 'change-block-data');
  38782. };
  38783. var removeMedia = exports.removeMedia = function removeMedia(editorState, mediaBlock) {
  38784. return removeBlock(editorState, mediaBlock);
  38785. };
  38786. var setMediaPosition = exports.setMediaPosition = function setMediaPosition(editorState, mediaBlock, position) {
  38787. var newPosition = {};
  38788. var float = position.float,
  38789. alignment = position.alignment;
  38790. if (typeof float !== 'undefined') {
  38791. newPosition.float = mediaBlock.getData().get('float') === float ? null : float;
  38792. }
  38793. if (typeof alignment !== 'undefined') {
  38794. newPosition.alignment = mediaBlock.getData().get('alignment') === alignment ? null : alignment;
  38795. }
  38796. return setSelectionBlockData(selectBlock(editorState, mediaBlock), newPosition);
  38797. };
  38798. var clear = exports.clear = function clear(editorState) {
  38799. var contentState = editorState.getCurrentContent();
  38800. var firstBlock = contentState.getFirstBlock();
  38801. var lastBlock = contentState.getLastBlock();
  38802. var allSelected = new Draft.SelectionState({
  38803. anchorKey: firstBlock.getKey(),
  38804. anchorOffset: 0,
  38805. focusKey: lastBlock.getKey(),
  38806. focusOffset: lastBlock.getLength(),
  38807. hasFocus: true
  38808. });
  38809. return Draft.RichUtils.toggleBlockType(Draft.EditorState.push(editorState, Draft.Modifier.removeRange(contentState, allSelected, 'backward'), 'remove-range'), 'unstyled');
  38810. };
  38811. var handleKeyCommand = exports.handleKeyCommand = function handleKeyCommand(editorState, command) {
  38812. return Draft.RichUtils.handleKeyCommand(editorState, command);
  38813. };
  38814. var undo = exports.undo = function undo(editorState) {
  38815. return Draft.EditorState.undo(editorState);
  38816. };
  38817. var redo = exports.redo = function redo(editorState) {
  38818. return Draft.EditorState.redo(editorState);
  38819. };
  38820. });
  38821. unwrapExports(content$1);
  38822. var content_1$1 = content$1.redo;
  38823. var content_2$1 = content$1.undo;
  38824. var content_3$1 = content$1.handleKeyCommand;
  38825. var content_4$1 = content$1.clear;
  38826. var content_5$1 = content$1.setMediaPosition;
  38827. var content_6$1 = content$1.removeMedia;
  38828. var content_7$1 = content$1.setMediaData;
  38829. var content_8$1 = content$1.insertMedias;
  38830. var content_9$1 = content$1.insertHorizontalLine;
  38831. var content_10$1 = content$1.insertAtomicBlock;
  38832. var content_11$1 = content$1.insertHTML;
  38833. var content_12$1 = content$1.insertText;
  38834. var content_13$1 = content$1.toggleSelectionLetterSpacing;
  38835. var content_14$1 = content$1.toggleSelectionFontFamily;
  38836. var content_15$1 = content$1.toggleSelectionLineHeight;
  38837. var content_16$1 = content$1.toggleSelectionFontSize;
  38838. var content_17$1 = content$1.toggleSelectionBackgroundColor;
  38839. var content_18$1 = content$1.toggleSelectionColor;
  38840. var content_19$1 = content$1.decreaseSelectionIndent;
  38841. var content_20$1 = content$1.increaseSelectionIndent;
  38842. var content_21$1 = content$1.toggleSelectionIndent;
  38843. var content_22$1 = content$1.toggleSelectionAlignment;
  38844. var content_23$1 = content$1.removeSelectionInlineStyles;
  38845. var content_24$1 = content$1.toggleSelectionInlineStyle;
  38846. var content_25$1 = content$1.selectionHasInlineStyle;
  38847. var content_26$1 = content$1.getSelectionInlineStyle;
  38848. var content_27$1 = content$1.toggleSelectionLink;
  38849. var content_28$1 = content$1.toggleSelectionEntity;
  38850. var content_29$1 = content$1.getSelectionEntityData;
  38851. var content_30$1 = content$1.getSelectionEntityType;
  38852. var content_31$1 = content$1.toggleSelectionBlockType;
  38853. var content_32$1 = content$1.getSelectionText;
  38854. var content_33$1 = content$1.getSelectionBlockType;
  38855. var content_34$1 = content$1.getSelectionBlockData;
  38856. var content_35$1 = content$1.setSelectionBlockData;
  38857. var content_36$1 = content$1.getSelectedBlocks;
  38858. var content_37$1 = content$1.updateEachCharacterOfSelection;
  38859. var content_38$1 = content$1.getSelectionBlock;
  38860. var content_39$1 = content$1.removeBlock;
  38861. var content_40$1 = content$1.selectNextBlock;
  38862. var content_41$1 = content$1.selectBlock;
  38863. var content_42$1 = content$1.selectionContainsStrictBlock;
  38864. var content_43$1 = content$1.selectionContainsBlockType;
  38865. var content_44$1 = content$1.isSelectionCollapsed;
  38866. var content_45$1 = content$1.createEditorState;
  38867. var content_46$1 = content$1.createEmptyEditorState;
  38868. var content_47$1 = content$1.isEditorState;
  38869. var content_48$1 = content$1.registerStrictBlockType;
  38870. var base$1 = createCommonjsModule(function (module, exports) {
  38871. Object.defineProperty(exports, "__esModule", {
  38872. value: true
  38873. });
  38874. var braftUniqueIndex = 0;
  38875. var UniqueIndex = exports.UniqueIndex = function UniqueIndex() {
  38876. return braftUniqueIndex += 1;
  38877. };
  38878. });
  38879. unwrapExports(base$1);
  38880. var base_1$1 = base$1.UniqueIndex;
  38881. var color$1 = createCommonjsModule(function (module, exports) {
  38882. Object.defineProperty(exports, "__esModule", {
  38883. value: true
  38884. });
  38885. var _namedColors = {
  38886. "aliceblue": "#f0f8ff",
  38887. "antiquewhite": "#faebd7",
  38888. "aqua": "#00ffff",
  38889. "aquamarine": "#7fffd4",
  38890. "azure": "#f0ffff",
  38891. "beige": "#f5f5dc",
  38892. "bisque": "#ffe4c4",
  38893. "black": "#000000",
  38894. "blanchedalmond": "#ffebcd",
  38895. "blue": "#0000ff",
  38896. "blueviolet": "#8a2be2",
  38897. "brown": "#a52a2a",
  38898. "burlywood": "#deb887",
  38899. "cadetblue": "#5f9ea0",
  38900. "chartreuse": "#7fff00",
  38901. "chocolate": "#d2691e",
  38902. "coral": "#ff7f50",
  38903. "cornflowerblue": "#6495ed",
  38904. "cornsilk": "#fff8dc",
  38905. "crimson": "#dc143c",
  38906. "cyan": "#00ffff",
  38907. "darkblue": "#00008b",
  38908. "darkcyan": "#008b8b",
  38909. "darkgoldenrod": "#b8860b",
  38910. "darkgray": "#a9a9a9",
  38911. "darkgreen": "#006400",
  38912. "darkkhaki": "#bdb76b",
  38913. "darkmagenta": "#8b008b",
  38914. "darkolivegreen": "#556b2f",
  38915. "darkorange": "#ff8c00",
  38916. "darkorchid": "#9932cc",
  38917. "darkred": "#8b0000",
  38918. "darksalmon": "#e9967a",
  38919. "darkseagreen": "#8fbc8f",
  38920. "darkslateblue": "#483d8b",
  38921. "darkslategray": "#2f4f4f",
  38922. "darkturquoise": "#00ced1",
  38923. "darkviolet": "#9400d3",
  38924. "deeppink": "#ff1493",
  38925. "deepskyblue": "#00bfff",
  38926. "dimgray": "#696969",
  38927. "dodgerblue": "#1e90ff",
  38928. "firebrick": "#b22222",
  38929. "floralwhite": "#fffaf0",
  38930. "forestgreen": "#228b22",
  38931. "fuchsia": "#ff00ff",
  38932. "gainsboro": "#dcdcdc",
  38933. "ghostwhite": "#f8f8ff",
  38934. "gold": "#ffd700",
  38935. "goldenrod": "#daa520",
  38936. "gray": "#808080",
  38937. "green": "#008000",
  38938. "greenyellow": "#adff2f",
  38939. "honeydew": "#f0fff0",
  38940. "hotpink": "#ff69b4",
  38941. "indianred ": "#cd5c5c",
  38942. "indigo": "#4b0082",
  38943. "ivory": "#fffff0",
  38944. "khaki": "#f0e68c",
  38945. "lavender": "#e6e6fa",
  38946. "lavenderblush": "#fff0f5",
  38947. "lawngreen": "#7cfc00",
  38948. "lemonchiffon": "#fffacd",
  38949. "lightblue": "#add8e6",
  38950. "lightcoral": "#f08080",
  38951. "lightcyan": "#e0ffff",
  38952. "lightgoldenrodyellow": "#fafad2",
  38953. "lightgrey": "#d3d3d3",
  38954. "lightgreen": "#90ee90",
  38955. "lightpink": "#ffb6c1",
  38956. "lightsalmon": "#ffa07a",
  38957. "lightseagreen": "#20b2aa",
  38958. "lightskyblue": "#87cefa",
  38959. "lightslategray": "#778899",
  38960. "lightsteelblue": "#b0c4de",
  38961. "lightyellow": "#ffffe0",
  38962. "lime": "#00ff00",
  38963. "limegreen": "#32cd32",
  38964. "linen": "#faf0e6",
  38965. "magenta": "#ff00ff",
  38966. "maroon": "#800000",
  38967. "mediumaquamarine": "#66cdaa",
  38968. "mediumblue": "#0000cd",
  38969. "mediumorchid": "#ba55d3",
  38970. "mediumpurple": "#9370d8",
  38971. "mediumseagreen": "#3cb371",
  38972. "mediumslateblue": "#7b68ee",
  38973. "mediumspringgreen": "#00fa9a",
  38974. "mediumturquoise": "#48d1cc",
  38975. "mediumvioletred": "#c71585",
  38976. "midnightblue": "#191970",
  38977. "mintcream": "#f5fffa",
  38978. "mistyrose": "#ffe4e1",
  38979. "moccasin": "#ffe4b5",
  38980. "navajowhite": "#ffdead",
  38981. "navy": "#000080",
  38982. "oldlace": "#fdf5e6",
  38983. "olive": "#808000",
  38984. "olivedrab": "#6b8e23",
  38985. "orange": "#ffa500",
  38986. "orangered": "#ff4500",
  38987. "orchid": "#da70d6",
  38988. "palegoldenrod": "#eee8aa",
  38989. "palegreen": "#98fb98",
  38990. "paleturquoise": "#afeeee",
  38991. "palevioletred": "#d87093",
  38992. "papayawhip": "#ffefd5",
  38993. "peachpuff": "#ffdab9",
  38994. "peru": "#cd853f",
  38995. "pink": "#ffc0cb",
  38996. "plum": "#dda0dd",
  38997. "powderblue": "#b0e0e6",
  38998. "purple": "#800080",
  38999. "rebeccapurple": "#663399",
  39000. "red": "#ff0000",
  39001. "rosybrown": "#bc8f8f",
  39002. "royalblue": "#4169e1",
  39003. "saddlebrown": "#8b4513",
  39004. "salmon": "#fa8072",
  39005. "sandybrown": "#f4a460",
  39006. "seagreen": "#2e8b57",
  39007. "seashell": "#fff5ee",
  39008. "sienna": "#a0522d",
  39009. "silver": "#c0c0c0",
  39010. "skyblue": "#87ceeb",
  39011. "slateblue": "#6a5acd",
  39012. "slategray": "#708090",
  39013. "snow": "#fffafa",
  39014. "springgreen": "#00ff7f",
  39015. "steelblue": "#4682b4",
  39016. "tan": "#d2b48c",
  39017. "teal": "#008080",
  39018. "thistle": "#d8bfd8",
  39019. "tomato": "#ff6347",
  39020. "turquoise": "#40e0d0",
  39021. "violet": "#ee82ee",
  39022. "wheat": "#f5deb3",
  39023. "white": "#ffffff",
  39024. "whitesmoke": "#f5f5f5",
  39025. "yellow": "#ffff00",
  39026. "yellowgreen": "#9acd32"
  39027. };
  39028. var _getHexColor = function _getHexColor(color) {
  39029. color = color.replace('color:', '').replace(';', '').replace(' ', '');
  39030. if (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(color)) {
  39031. return color;
  39032. } else if (namedColors[color]) {
  39033. return namedColors[color];
  39034. } else if (color.indexOf('rgb') === 0) {
  39035. var rgbArray = color.split(',');
  39036. var convertedColor = rgbArray.length < 3 ? null : '#' + [rgbArray[0], rgbArray[1], rgbArray[2]].map(function (x) {
  39037. var hex = parseInt(x.replace(/\D/g, ''), 10).toString(16);
  39038. return hex.length === 1 ? '0' + hex : hex;
  39039. }).join('');
  39040. return (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(convertedColor) ? convertedColor : null
  39041. );
  39042. } else {
  39043. return null;
  39044. }
  39045. };
  39046. var namedColors = exports.namedColors = _namedColors;
  39047. var getHexColor = exports.getHexColor = _getHexColor;
  39048. var detectColorsFromHTMLString = exports.detectColorsFromHTMLString = function detectColorsFromHTMLString(html) {
  39049. return typeof html !== 'string' ? [] : (html.match(/color:[^;]{3,24};/g) || []).map(getHexColor).filter(function (color) {
  39050. return color;
  39051. });
  39052. };
  39053. var detectColorsFromDraftState = exports.detectColorsFromDraftState = function detectColorsFromDraftState(draftState) {
  39054. var result = [];
  39055. if (!draftState || !draftState.blocks || !draftState.blocks.length) {
  39056. return result;
  39057. }
  39058. draftState.blocks.forEach(function (block) {
  39059. if (block && block.inlineStyleRanges && block.inlineStyleRanges.length) {
  39060. block.inlineStyleRanges.forEach(function (inlineStyle) {
  39061. if (inlineStyle.style && inlineStyle.style.indexOf('COLOR-') >= 0) {
  39062. result.push('#' + inlineStyle.style.split('COLOR-')[1]);
  39063. }
  39064. });
  39065. }
  39066. });
  39067. return result.filter(function (color) {
  39068. return color;
  39069. });
  39070. };
  39071. });
  39072. unwrapExports(color$1);
  39073. var color_1$1 = color$1.namedColors;
  39074. var color_2$1 = color$1.getHexColor;
  39075. var color_3$1 = color$1.detectColorsFromHTMLString;
  39076. var color_4$1 = color$1.detectColorsFromDraftState;
  39077. var dist$4 = createCommonjsModule(function (module, exports) {
  39078. Object.defineProperty(exports, "__esModule", {
  39079. value: true
  39080. });
  39081. exports.ColorUtils = exports.BaseUtils = exports.ContentUtils = undefined;
  39082. var _ContentUtils = _interopRequireWildcard(content$1);
  39083. var _BaseUtils = _interopRequireWildcard(base$1);
  39084. var _ColorUtils = _interopRequireWildcard(color$1);
  39085. 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; } }
  39086. var ContentUtils = exports.ContentUtils = _ContentUtils;
  39087. var BaseUtils = exports.BaseUtils = _BaseUtils;
  39088. var ColorUtils = exports.ColorUtils = _ColorUtils;
  39089. });
  39090. unwrapExports(dist$4);
  39091. var dist_1$2 = dist$4.ColorUtils;
  39092. var dist_2$2 = dist$4.BaseUtils;
  39093. var dist_3$2 = dist$4.ContentUtils;
  39094. var emoticon = createCommonjsModule(function (module, exports) {
  39095. (function webpackUniversalModuleDefinition(root, factory) {
  39096. module.exports = factory(React, dist$4);
  39097. })(window, function(__WEBPACK_EXTERNAL_MODULE__1__, __WEBPACK_EXTERNAL_MODULE__6__) {
  39098. return /******/ (function(modules) { // webpackBootstrap
  39099. /******/ // The module cache
  39100. /******/ var installedModules = {};
  39101. /******/
  39102. /******/ // The require function
  39103. /******/ function __webpack_require__(moduleId) {
  39104. /******/
  39105. /******/ // Check if module is in cache
  39106. /******/ if(installedModules[moduleId]) {
  39107. /******/ return installedModules[moduleId].exports;
  39108. /******/ }
  39109. /******/ // Create a new module (and put it into the cache)
  39110. /******/ var module = installedModules[moduleId] = {
  39111. /******/ i: moduleId,
  39112. /******/ l: false,
  39113. /******/ exports: {}
  39114. /******/ };
  39115. /******/
  39116. /******/ // Execute the module function
  39117. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  39118. /******/
  39119. /******/ // Flag the module as loaded
  39120. /******/ module.l = true;
  39121. /******/
  39122. /******/ // Return the exports of the module
  39123. /******/ return module.exports;
  39124. /******/ }
  39125. /******/
  39126. /******/
  39127. /******/ // expose the modules object (__webpack_modules__)
  39128. /******/ __webpack_require__.m = modules;
  39129. /******/
  39130. /******/ // expose the module cache
  39131. /******/ __webpack_require__.c = installedModules;
  39132. /******/
  39133. /******/ // define getter function for harmony exports
  39134. /******/ __webpack_require__.d = function(exports, name, getter) {
  39135. /******/ if(!__webpack_require__.o(exports, name)) {
  39136. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  39137. /******/ }
  39138. /******/ };
  39139. /******/
  39140. /******/ // define __esModule on exports
  39141. /******/ __webpack_require__.r = function(exports) {
  39142. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  39143. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  39144. /******/ }
  39145. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  39146. /******/ };
  39147. /******/
  39148. /******/ // create a fake namespace object
  39149. /******/ // mode & 1: value is a module id, require it
  39150. /******/ // mode & 2: merge all properties of value into the ns
  39151. /******/ // mode & 4: return value when already ns object
  39152. /******/ // mode & 8|1: behave like require
  39153. /******/ __webpack_require__.t = function(value, mode) {
  39154. /******/ if(mode & 1) value = __webpack_require__(value);
  39155. /******/ if(mode & 8) return value;
  39156. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  39157. /******/ var ns = Object.create(null);
  39158. /******/ __webpack_require__.r(ns);
  39159. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  39160. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  39161. /******/ return ns;
  39162. /******/ };
  39163. /******/
  39164. /******/ // getDefaultExport function for compatibility with non-harmony modules
  39165. /******/ __webpack_require__.n = function(module) {
  39166. /******/ var getter = module && module.__esModule ?
  39167. /******/ function getDefault() { return module['default']; } :
  39168. /******/ function getModuleExports() { return module; };
  39169. /******/ __webpack_require__.d(getter, 'a', getter);
  39170. /******/ return getter;
  39171. /******/ };
  39172. /******/
  39173. /******/ // Object.prototype.hasOwnProperty.call
  39174. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  39175. /******/
  39176. /******/ // __webpack_public_path__
  39177. /******/ __webpack_require__.p = "/";
  39178. /******/
  39179. /******/
  39180. /******/ // Load entry module and return exports
  39181. /******/ return __webpack_require__(__webpack_require__.s = 33);
  39182. /******/ })
  39183. /************************************************************************/
  39184. /******/ ({
  39185. /***/ 1:
  39186. /***/ (function(module, exports) {
  39187. module.exports = __WEBPACK_EXTERNAL_MODULE__1__;
  39188. /***/ }),
  39189. /***/ 2:
  39190. /***/ (function(module, exports) {
  39191. function _defineProperty(obj, key, value) {
  39192. if (key in obj) {
  39193. Object.defineProperty(obj, key, {
  39194. value: value,
  39195. enumerable: true,
  39196. configurable: true,
  39197. writable: true
  39198. });
  39199. } else {
  39200. obj[key] = value;
  39201. }
  39202. return obj;
  39203. }
  39204. module.exports = _defineProperty;
  39205. /***/ }),
  39206. /***/ 33:
  39207. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  39208. __webpack_require__.r(__webpack_exports__);
  39209. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "defaultEmoticons", function() { return defaultEmoticons; });
  39210. /* harmony import */ var _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
  39211. /* harmony import */ var _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0__);
  39212. /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
  39213. /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
  39214. /* harmony import */ var braft_utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6);
  39215. /* harmony import */ var _styles_scss__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(48);
  39216. // https://www.iconfinder.com/iconsets/emoji-18
  39217. 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) {
  39218. return "".concat(item, ".png");
  39219. });
  39220. var insertEmoticon = function insertEmoticon(editor, editorState, src) {
  39221. editor.setValue(braft_utils__WEBPACK_IMPORTED_MODULE_2__["ContentUtils"].insertText(editorState, ' ', null, {
  39222. type: 'EMOTICON',
  39223. mutability: 'IMMUTABLE',
  39224. data: {
  39225. src: src
  39226. }
  39227. }));
  39228. };
  39229. var controlRef = null;
  39230. var bindControlRef = function bindControlRef(ref) {
  39231. return controlRef = ref;
  39232. };
  39233. /* harmony default export */ __webpack_exports__["default"] = (function (options) {
  39234. options = _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0___default()({
  39235. emoticons: [],
  39236. closeOnSelect: false,
  39237. closeOnBlur: false
  39238. }, options);
  39239. var _options = options,
  39240. emoticons = _options.emoticons,
  39241. closeOnSelect = _options.closeOnSelect,
  39242. closeOnBlur = _options.closeOnBlur,
  39243. includeEditors = _options.includeEditors,
  39244. excludeEditors = _options.excludeEditors;
  39245. return {
  39246. type: 'entity',
  39247. includeEditors: includeEditors,
  39248. excludeEditors: excludeEditors,
  39249. name: 'EMOTICON',
  39250. control: function control(props) {
  39251. return {
  39252. key: 'EMOTICON',
  39253. replace: 'emoji',
  39254. type: 'dropdown',
  39255. text: react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("i", {
  39256. className: "bfi-emoji"
  39257. }),
  39258. showArrow: false,
  39259. ref: bindControlRef,
  39260. autoHide: closeOnBlur,
  39261. component: react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("div", {
  39262. className: "braft-emoticon-picker"
  39263. }, react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("div", {
  39264. className: "braft-emoticons-list"
  39265. }, emoticons.map(function (item, index) {
  39266. return react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("img", {
  39267. onClick: function onClick() {
  39268. insertEmoticon(props.editor, props.editorState, item);
  39269. closeOnSelect && controlRef && controlRef.hide();
  39270. },
  39271. key: index,
  39272. src: item
  39273. });
  39274. })))
  39275. };
  39276. },
  39277. mutability: 'IMMUTABLE',
  39278. component: function component(props) {
  39279. var entity = props.contentState.getEntity(props.entityKey);
  39280. var _entity$getData = entity.getData(),
  39281. src = _entity$getData.src;
  39282. return react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("span", {
  39283. className: "braft-emoticon-in-editor"
  39284. }, react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("img", {
  39285. src: src
  39286. }), props.children);
  39287. },
  39288. importer: function importer(nodeName, node) {
  39289. if (nodeName.toLowerCase() === 'span' && node.classList && node.classList.contains('braft-emoticon-wrap')) {
  39290. var imgNode = node.querySelector('img');
  39291. var src = imgNode.getAttribute('src'); // 移除img节点以避免生成atomic block
  39292. node.removeChild(imgNode);
  39293. return {
  39294. mutability: 'IMMUTABLE',
  39295. data: {
  39296. src: src
  39297. }
  39298. };
  39299. }
  39300. },
  39301. exporter: function exporter(entityObject, initialText) {
  39302. var src = entityObject.data.src;
  39303. return react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("span", {
  39304. className: "braft-emoticon-wrap"
  39305. }, react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("img", {
  39306. src: src
  39307. }), initialText);
  39308. }
  39309. };
  39310. });
  39311. /***/ }),
  39312. /***/ 48:
  39313. /***/ (function(module, exports) {
  39314. // removed by extract-text-webpack-plugin
  39315. /***/ }),
  39316. /***/ 5:
  39317. /***/ (function(module, exports, __webpack_require__) {
  39318. var defineProperty = __webpack_require__(2);
  39319. function _objectSpread(target) {
  39320. for (var i = 1; i < arguments.length; i++) {
  39321. var source = arguments[i] != null ? arguments[i] : {};
  39322. var ownKeys = Object.keys(source);
  39323. if (typeof Object.getOwnPropertySymbols === 'function') {
  39324. ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
  39325. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  39326. }));
  39327. }
  39328. ownKeys.forEach(function (key) {
  39329. defineProperty(target, key, source[key]);
  39330. });
  39331. }
  39332. return target;
  39333. }
  39334. module.exports = _objectSpread;
  39335. /***/ }),
  39336. /***/ 6:
  39337. /***/ (function(module, exports) {
  39338. module.exports = __WEBPACK_EXTERNAL_MODULE__6__;
  39339. /***/ })
  39340. /******/ });
  39341. });
  39342. });
  39343. var Emoticon = unwrapExports(emoticon);
  39344. var emoticon_1 = emoticon.defaultEmoticons;
  39345. var maxLength = createCommonjsModule(function (module, exports) {
  39346. (function webpackUniversalModuleDefinition(root, factory) {
  39347. module.exports = factory();
  39348. })(window, function() {
  39349. return /******/ (function(modules) { // webpackBootstrap
  39350. /******/ // The module cache
  39351. /******/ var installedModules = {};
  39352. /******/
  39353. /******/ // The require function
  39354. /******/ function __webpack_require__(moduleId) {
  39355. /******/
  39356. /******/ // Check if module is in cache
  39357. /******/ if(installedModules[moduleId]) {
  39358. /******/ return installedModules[moduleId].exports;
  39359. /******/ }
  39360. /******/ // Create a new module (and put it into the cache)
  39361. /******/ var module = installedModules[moduleId] = {
  39362. /******/ i: moduleId,
  39363. /******/ l: false,
  39364. /******/ exports: {}
  39365. /******/ };
  39366. /******/
  39367. /******/ // Execute the module function
  39368. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  39369. /******/
  39370. /******/ // Flag the module as loaded
  39371. /******/ module.l = true;
  39372. /******/
  39373. /******/ // Return the exports of the module
  39374. /******/ return module.exports;
  39375. /******/ }
  39376. /******/
  39377. /******/
  39378. /******/ // expose the modules object (__webpack_modules__)
  39379. /******/ __webpack_require__.m = modules;
  39380. /******/
  39381. /******/ // expose the module cache
  39382. /******/ __webpack_require__.c = installedModules;
  39383. /******/
  39384. /******/ // define getter function for harmony exports
  39385. /******/ __webpack_require__.d = function(exports, name, getter) {
  39386. /******/ if(!__webpack_require__.o(exports, name)) {
  39387. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  39388. /******/ }
  39389. /******/ };
  39390. /******/
  39391. /******/ // define __esModule on exports
  39392. /******/ __webpack_require__.r = function(exports) {
  39393. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  39394. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  39395. /******/ }
  39396. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  39397. /******/ };
  39398. /******/
  39399. /******/ // create a fake namespace object
  39400. /******/ // mode & 1: value is a module id, require it
  39401. /******/ // mode & 2: merge all properties of value into the ns
  39402. /******/ // mode & 4: return value when already ns object
  39403. /******/ // mode & 8|1: behave like require
  39404. /******/ __webpack_require__.t = function(value, mode) {
  39405. /******/ if(mode & 1) value = __webpack_require__(value);
  39406. /******/ if(mode & 8) return value;
  39407. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  39408. /******/ var ns = Object.create(null);
  39409. /******/ __webpack_require__.r(ns);
  39410. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  39411. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  39412. /******/ return ns;
  39413. /******/ };
  39414. /******/
  39415. /******/ // getDefaultExport function for compatibility with non-harmony modules
  39416. /******/ __webpack_require__.n = function(module) {
  39417. /******/ var getter = module && module.__esModule ?
  39418. /******/ function getDefault() { return module['default']; } :
  39419. /******/ function getModuleExports() { return module; };
  39420. /******/ __webpack_require__.d(getter, 'a', getter);
  39421. /******/ return getter;
  39422. /******/ };
  39423. /******/
  39424. /******/ // Object.prototype.hasOwnProperty.call
  39425. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  39426. /******/
  39427. /******/ // __webpack_public_path__
  39428. /******/ __webpack_require__.p = "/";
  39429. /******/
  39430. /******/
  39431. /******/ // Load entry module and return exports
  39432. /******/ return __webpack_require__(__webpack_require__.s = 34);
  39433. /******/ })
  39434. /************************************************************************/
  39435. /******/ ({
  39436. /***/ 2:
  39437. /***/ (function(module, exports) {
  39438. function _defineProperty(obj, key, value) {
  39439. if (key in obj) {
  39440. Object.defineProperty(obj, key, {
  39441. value: value,
  39442. enumerable: true,
  39443. configurable: true,
  39444. writable: true
  39445. });
  39446. } else {
  39447. obj[key] = value;
  39448. }
  39449. return obj;
  39450. }
  39451. module.exports = _defineProperty;
  39452. /***/ }),
  39453. /***/ 34:
  39454. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  39455. __webpack_require__.r(__webpack_exports__);
  39456. /* harmony import */ var _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
  39457. /* harmony import */ var _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0__);
  39458. var getSelectedTextLength = function getSelectedTextLength(editorState) {
  39459. var currentSelection = editorState.getSelection();
  39460. var isCollapsed = currentSelection.isCollapsed();
  39461. var length = 0;
  39462. if (!isCollapsed) {
  39463. var currentContent = editorState.getCurrentContent();
  39464. var startKey = currentSelection.getStartKey();
  39465. var endKey = currentSelection.getEndKey();
  39466. var startBlock = currentContent.getBlockForKey(startKey);
  39467. var isStartAndEndBlockAreTheSame = startKey === endKey;
  39468. var startBlockTextLength = startBlock.getLength();
  39469. var startSelectedTextLength = startBlockTextLength - currentSelection.getStartOffset();
  39470. var endSelectedTextLength = currentSelection.getEndOffset();
  39471. var keyAfterEnd = currentContent.getKeyAfter(endKey);
  39472. if (isStartAndEndBlockAreTheSame) {
  39473. length += currentSelection.getEndOffset() - currentSelection.getStartOffset();
  39474. } else {
  39475. var currentKey = startKey;
  39476. while (currentKey && currentKey !== keyAfterEnd) {
  39477. if (currentKey === startKey) {
  39478. length += startSelectedTextLength + 1;
  39479. } else if (currentKey === endKey) {
  39480. length += endSelectedTextLength;
  39481. } else {
  39482. length += currentContent.getBlockForKey(currentKey).getLength() + 1;
  39483. }
  39484. currentKey = currentContent.getKeyAfter(currentKey);
  39485. }
  39486. }
  39487. }
  39488. return length;
  39489. };
  39490. /* harmony default export */ __webpack_exports__["default"] = (function (options) {
  39491. options = _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0___default()({
  39492. defaultValue: Infinity
  39493. }, options);
  39494. var _options = options,
  39495. includeEditors = _options.includeEditors,
  39496. excludeEditors = _options.excludeEditors,
  39497. defaultValue = _options.defaultValue;
  39498. return {
  39499. type: 'prop-interception',
  39500. includeEditors: includeEditors,
  39501. excludeEditors: excludeEditors,
  39502. interceptor: function interceptor(editorProps) {
  39503. var maxLength = editorProps.maxLength || defaultValue;
  39504. editorProps.handleBeforeInput = function (_, editorState) {
  39505. if (maxLength === Infinity) {
  39506. return 'not-handled';
  39507. }
  39508. var currentContentLength = editorState.toText().length;
  39509. var selectedTextLength = getSelectedTextLength(editorState);
  39510. if (currentContentLength - selectedTextLength > maxLength - 1) {
  39511. editorProps.onReachMaxLength && editorProps.onReachMaxLength(maxLength);
  39512. return 'handled';
  39513. }
  39514. };
  39515. editorProps.handlePastedText = function (pastedText, _, editorState) {
  39516. if (maxLength === Infinity) {
  39517. return 'not-handled';
  39518. }
  39519. var currentContentLength = editorState.toText().length;
  39520. var selectedTextLength = getSelectedTextLength(editorState);
  39521. if (currentContentLength + pastedText.length - selectedTextLength > maxLength) {
  39522. editorProps.onReachMaxLength && editorProps.onReachMaxLength(maxLength);
  39523. return 'handled';
  39524. }
  39525. };
  39526. return editorProps;
  39527. }
  39528. };
  39529. });
  39530. /***/ }),
  39531. /***/ 5:
  39532. /***/ (function(module, exports, __webpack_require__) {
  39533. var defineProperty = __webpack_require__(2);
  39534. function _objectSpread(target) {
  39535. for (var i = 1; i < arguments.length; i++) {
  39536. var source = arguments[i] != null ? arguments[i] : {};
  39537. var ownKeys = Object.keys(source);
  39538. if (typeof Object.getOwnPropertySymbols === 'function') {
  39539. ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
  39540. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  39541. }));
  39542. }
  39543. ownKeys.forEach(function (key) {
  39544. defineProperty(target, key, source[key]);
  39545. });
  39546. }
  39547. return target;
  39548. }
  39549. module.exports = _objectSpread;
  39550. /***/ })
  39551. /******/ });
  39552. });
  39553. });
  39554. var MaxLength = unwrapExports(maxLength);
  39555. var lengthOptions = {
  39556. defaultValue: 100 // 指定默认限制数,如不指定则为Infinity(无限)
  39557. // includeEditors: ['editor-id-1'], // 指定该模块对哪些BraftEditor生效,不传此属性则对所有BraftEditor有效
  39558. // excludeEditors: ['editor-id-2'], // 指定该模块对哪些BraftEditor无效
  39559. };
  39560. BraftEditor.use(MaxLength(lengthOptions)); // 转换默认表情包列表,让webpack可以正确加载到默认表情包中的图片,请确保已对png格式的文件配置了loader
  39561. // 如果你使用的webpack版本不支持动态require,或者使用的其他打包工具,请勿使用此写法
  39562. var emoticons = emoticon_1.map(function (item) {
  39563. return require("braft-extensions/dist/assets/".concat(item));
  39564. }); // 也可以使用自己的表情包资源,不受打包工具限制
  39565. // const emoticons = ['http://path/to/emoticon-1.png', 'http://path/to/emoticon-2.png', 'http://path/to/emoticon-3.png', 'http://path/to/emoticon-4.png', ...]
  39566. var emotionOptions = {
  39567. // includeEditors: ['editor-id-1'], // 指定该模块对哪些BraftEditor生效,不传此属性则对所有BraftEditor有效
  39568. // excludeEditors: ['editor-id-2'], // 指定该模块对哪些BraftEditor无效
  39569. emoticons: emoticons,
  39570. // 指定可用表情图片列表,默认为空
  39571. closeOnBlur: true,
  39572. // 指定是否在点击表情选择器之外的地方时关闭表情选择器,默认false
  39573. closeOnSelect: false // 指定是否在选择表情后关闭表情选择器,默认false
  39574. };
  39575. BraftEditor.use(Emoticon(emotionOptions));
  39576. var BarftEditorPage = function BarftEditorPage() {
  39577. var controls = ["bold", "italic", "underline", "separator", "link", "emoji", "separator", "media"];
  39578. var _useState = useState(BraftEditor.createEditorState("<p>Hello <b>World!</b></p>")),
  39579. _useState2 = _slicedToArray(_useState, 2),
  39580. editorState = _useState2[0],
  39581. setEditorState = _useState2[1];
  39582. return React.createElement("div", {
  39583. className: "editor-wrapper"
  39584. }, React.createElement(BraftEditor, {
  39585. value: editorState,
  39586. onChange: setEditorState,
  39587. controls: controls,
  39588. contentStyle: {
  39589. height: 210,
  39590. boxShadow: "inset 0 1px 3px rgba(0,0,0,.1)"
  39591. }
  39592. }));
  39593. };
  39594. var css$2 = ".RichTextEditor_wrapper__A033L .RichTextEditor_btnListWrapper__3iF9d {\n display: flex;\n}\n.RichTextEditor_wrapper__A033L .RichTextEditor_editorWrapper__PzQ_1 {\n border: 1px solid #ccc;\n}\n";
  39595. var styles = {"wrapper":"RichTextEditor_wrapper__A033L","btnListWrapper":"RichTextEditor_btnListWrapper__3iF9d","editorWrapper":"RichTextEditor_editorWrapper__PzQ_1"};
  39596. styleInject(css$2);
  39597. // 自定义组件,用于超链接
  39598. var Link = function Link(props) {
  39599. // 这里通过contentState来获取entity�,之后通过getData获取entity中包含的数据
  39600. var _props$contentState$g = props.contentState.getEntity(props.entityKey).getData(),
  39601. url = _props$contentState$g.url;
  39602. return React.createElement("a", {
  39603. href: url
  39604. }, props.children);
  39605. }; // decorator,用于超链接
  39606. var decorator = new Draft_4([{
  39607. strategy: function strategy(contentBlock, callback, contentState) {
  39608. // 这个方法接收2个函数作为参数,如果第一个参数的函数执行时�返回true,就会执行第二个参数函数,同时会�将匹配的�字符的起始位置和结束位置传递给第二个参数。
  39609. contentBlock.findEntityRanges(function (character) {
  39610. var entityKey = character.getEntity();
  39611. return entityKey !== null && contentState.getEntity(entityKey).getType() === 'LINK';
  39612. }, function () {
  39613. callback.apply(void 0, arguments);
  39614. });
  39615. },
  39616. component: Link
  39617. }, {
  39618. strategy: function strategy(contentBlock, callback, contentState) {
  39619. contentBlock.findEntityRanges(function (character) {
  39620. var entityKey = character.getEntity();
  39621. return entityKey !== null && contentState.getEntity(entityKey).getType() === 'EMOJI';
  39622. }, function () {
  39623. callback.apply(void 0, arguments);
  39624. });
  39625. },
  39626. // component: (props: any) => (<span style={{ color: 'red' }}>[Emoji]</span>)
  39627. component: function component(props) {
  39628. return React.createElement("i", {
  39629. style: {
  39630. display: 'inline-block',
  39631. height: '18px',
  39632. width: '18px',
  39633. backgroundImage: "url(https://i.pinimg.com/originals/03/7e/79/037e79b2fb52127537be79110891ae3f.png)",
  39634. backgroundSize: '100% 100%',
  39635. color: 'transparent'
  39636. }
  39637. }, "e");
  39638. }
  39639. }]);
  39640. var RichTextEditor =
  39641. /*#__PURE__*/
  39642. function (_React$Component) {
  39643. _inherits$c(RichTextEditor, _React$Component);
  39644. function RichTextEditor(props) {
  39645. var _this;
  39646. _classCallCheck$h(this, RichTextEditor);
  39647. _this = _possibleConstructorReturn$c(this, _getPrototypeOf(RichTextEditor).call(this, props));
  39648. _defineProperty$1(_assertThisInitialized(_this), "onChange", void 0);
  39649. _this.state = {
  39650. editorState: Draft_3.createEmpty(decorator)
  39651. };
  39652. _this.onChange = function (editorState) {
  39653. return _this.setState({
  39654. editorState: editorState
  39655. });
  39656. };
  39657. _this.handleKeyCommand = _this.handleKeyCommand.bind(_assertThisInitialized(_this));
  39658. _this.defaultBlockStyleFn = _this.defaultBlockStyleFn.bind(_assertThisInitialized(_this));
  39659. return _this;
  39660. }
  39661. _createClass(RichTextEditor, [{
  39662. key: "handleKeyCommand",
  39663. value: function handleKeyCommand(command, editorState) {
  39664. var newState = Draft_15.handleKeyCommand(editorState, command);
  39665. console.log('command: ', command);
  39666. console.log('newState: ', newState);
  39667. if (newState) {
  39668. this.onChange(newState);
  39669. return "handled";
  39670. }
  39671. switch (command) {
  39672. case 'backspace':
  39673. var contentState = editorState.getCurrentContent();
  39674. var selectionState = editorState.getSelection();
  39675. var _ref = [selectionState.getStartOffset(), selectionState.getEndOffset()],
  39676. startOffset = _ref[0],
  39677. endOffset = _ref[1];
  39678. if (startOffset === endOffset) {
  39679. // 未选中状态
  39680. console.log(selectionState.getAnchorKey());
  39681. } // 选中状态
  39682. break;
  39683. }
  39684. return "not-handled";
  39685. }
  39686. }, {
  39687. key: "_onBoldClick",
  39688. value: function _onBoldClick() {
  39689. this.onChange(Draft_15.toggleInlineStyle(this.state.editorState, 'BOLD'));
  39690. }
  39691. }, {
  39692. key: "_onLinkClick",
  39693. value: function _onLinkClick() {
  39694. var editorState = this.state.editorState;
  39695. var contentState = editorState.getCurrentContent();
  39696. var selectionState = editorState.getSelection();
  39697. var contentStateWithEntity = contentState.createEntity('LINK', 'MUTABLE', {
  39698. url: 'http://www.zombo.com'
  39699. });
  39700. var entityKey = contentStateWithEntity.getLastCreatedEntityKey();
  39701. var contentStateWithLink = Draft_14.applyEntity(contentStateWithEntity, selectionState, entityKey);
  39702. var newEditorState = Draft_3.push(editorState, contentStateWithLink, 'apply-entity');
  39703. this.onChange(newEditorState);
  39704. }
  39705. }, {
  39706. key: "_onEmojiClick",
  39707. value: function _onEmojiClick(e, emojiCode) {
  39708. var editorState = this.state.editorState;
  39709. var contentState = editorState.getCurrentContent();
  39710. var selectionState = editorState.getSelection();
  39711. var EMOJIEntity = contentState.createEntity('EMOJI', 'IMMUTABLE', {
  39712. emojiCode: emojiCode
  39713. });
  39714. var entityKey = EMOJIEntity.getLastCreatedEntityKey();
  39715. var ncsWithEntity = Draft_14.insertText(contentState, selectionState, 'e', undefined, entityKey);
  39716. var newEditorState = Draft_3.push(editorState, ncsWithEntity, 'insert-characters'); // const newEditorState = AtomicBlockUtils.insertAtomicBlock(
  39717. // editorState,
  39718. // entityKey,
  39719. // ' '
  39720. // );
  39721. this.onChange(newEditorState);
  39722. }
  39723. }, {
  39724. key: "_onCheckRange",
  39725. value: function _onCheckRange() {
  39726. console.log(this.state.editorState.getCurrentContent());
  39727. console.log(Draft_20(this.state.editorState.getCurrentContent()));
  39728. }
  39729. }, {
  39730. key: "defaultBlockStyleFn",
  39731. value: function defaultBlockStyleFn(contentBlock) {
  39732. var type = contentBlock.getType();
  39733. return "";
  39734. }
  39735. }, {
  39736. key: "defaultBlockRenderFn",
  39737. value: function defaultBlockRenderFn(contentBlock) {
  39738. var type = contentBlock.getType();
  39739. return contentBlock;
  39740. }
  39741. }, {
  39742. key: "render",
  39743. value: function render() {
  39744. var _this2 = this;
  39745. var editorState = this.state.editorState;
  39746. return React.createElement("div", {
  39747. className: styles.wrapper
  39748. }, React.createElement("div", {
  39749. className: styles.btnListWrapper
  39750. }, React.createElement("button", {
  39751. onClick: this._onBoldClick.bind(this)
  39752. }, "Bold"), React.createElement("button", {
  39753. onClick: this._onCheckRange.bind(this)
  39754. }, "Check"), React.createElement("button", {
  39755. onClick: this._onLinkClick.bind(this)
  39756. }, "Link"), React.createElement("button", {
  39757. onClick: function onClick(e) {
  39758. return _this2._onEmojiClick(e, '0011');
  39759. }
  39760. }, "Emoji")), React.createElement("div", {
  39761. className: styles.editorWrapper
  39762. }, React.createElement(Draft_1, {
  39763. editorState: editorState,
  39764. blockStyleFn: this.defaultBlockStyleFn,
  39765. blockRendererFn: this.defaultBlockRenderFn,
  39766. handleKeyCommand: this.handleKeyCommand,
  39767. onChange: this.onChange
  39768. })));
  39769. }
  39770. }]);
  39771. return RichTextEditor;
  39772. }(React.Component);
  39773. /*!
  39774. * isobject <https://github.com/jonschlinkert/isobject>
  39775. *
  39776. * Copyright (c) 2014-2017, Jon Schlinkert.
  39777. * Released under the MIT License.
  39778. */
  39779. function isObject(val) {
  39780. return val != null && typeof val === 'object' && Array.isArray(val) === false;
  39781. }
  39782. /*!
  39783. * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
  39784. *
  39785. * Copyright (c) 2014-2017, Jon Schlinkert.
  39786. * Released under the MIT License.
  39787. */
  39788. function isObjectObject(o) {
  39789. return isObject(o) === true
  39790. && Object.prototype.toString.call(o) === '[object Object]';
  39791. }
  39792. function isPlainObject(o) {
  39793. var ctor,prot;
  39794. if (isObjectObject(o) === false) return false;
  39795. // If has modified constructor
  39796. ctor = o.constructor;
  39797. if (typeof ctor !== 'function') return false;
  39798. // If has modified prototype
  39799. prot = ctor.prototype;
  39800. if (isObjectObject(prot) === false) return false;
  39801. // If constructor does not have an Object-specific method
  39802. if (prot.hasOwnProperty('isPrototypeOf') === false) {
  39803. return false;
  39804. }
  39805. // Most likely a plain Object
  39806. return true;
  39807. }
  39808. var index_cjs = isPlainObject;
  39809. var immer_1 = createCommonjsModule(function (module, exports) {
  39810. Object.defineProperty(exports, '__esModule', { value: true });
  39811. // Should be no imports here!
  39812. var _a; // SOme things that should be evaluated before all else...
  39813. var hasSymbol = typeof Symbol !== "undefined";
  39814. var hasMap = typeof Map !== "undefined";
  39815. var hasSet = typeof Set !== "undefined";
  39816. /**
  39817. * The sentinel value returned by producers to replace the draft with undefined.
  39818. */
  39819. var NOTHING = hasSymbol ? Symbol("immer-nothing") : (_a = {}, _a["immer-nothing"] = true, _a);
  39820. /**
  39821. * To let Immer treat your class instances as plain immutable objects
  39822. * (albeit with a custom prototype), you must define either an instance property
  39823. * or a static property on each of your custom classes.
  39824. *
  39825. * Otherwise, your class instance will never be drafted, which means it won't be
  39826. * safe to mutate in a produce callback.
  39827. */
  39828. var DRAFTABLE = hasSymbol ? Symbol("immer-draftable") : "__$immer_draftable";
  39829. var DRAFT_STATE = hasSymbol ? Symbol("immer-state") : "__$immer_state";
  39830. var iteratorSymbol = hasSymbol ? Symbol.iterator : "@@iterator";
  39831. /* istanbul ignore next */
  39832. var extendStatics = function (d, b) {
  39833. extendStatics = Object.setPrototypeOf || {
  39834. __proto__: []
  39835. } instanceof Array && function (d, b) {
  39836. d.__proto__ = b;
  39837. } || function (d, b) {
  39838. for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } }
  39839. };
  39840. return extendStatics(d, b);
  39841. }; // Ugly hack to resolve #502 and inherit built in Map / Set
  39842. function __extends(d, b) {
  39843. extendStatics(d, b);
  39844. function __() {
  39845. this.constructor = d;
  39846. }
  39847. d.prototype = ( // @ts-ignore
  39848. __.prototype = b.prototype, new __());
  39849. }
  39850. var Archtype;
  39851. (function (Archtype) {
  39852. Archtype[Archtype["Object"] = 0] = "Object";
  39853. Archtype[Archtype["Array"] = 1] = "Array";
  39854. Archtype[Archtype["Map"] = 2] = "Map";
  39855. Archtype[Archtype["Set"] = 3] = "Set";
  39856. })(Archtype || (Archtype = {}));
  39857. var ProxyType;
  39858. (function (ProxyType) {
  39859. ProxyType[ProxyType["ProxyObject"] = 0] = "ProxyObject";
  39860. ProxyType[ProxyType["ProxyArray"] = 1] = "ProxyArray";
  39861. ProxyType[ProxyType["ES5Object"] = 2] = "ES5Object";
  39862. ProxyType[ProxyType["ES5Array"] = 3] = "ES5Array";
  39863. ProxyType[ProxyType["Map"] = 4] = "Map";
  39864. ProxyType[ProxyType["Set"] = 5] = "Set";
  39865. })(ProxyType || (ProxyType = {}));
  39866. /** Returns true if the given value is an Immer draft */
  39867. function isDraft(value) {
  39868. return !!value && !!value[DRAFT_STATE];
  39869. }
  39870. /** Returns true if the given value can be drafted by Immer */
  39871. function isDraftable(value) {
  39872. if (!value) { return false; }
  39873. return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!value.constructor[DRAFTABLE] || isMap(value) || isSet(value);
  39874. }
  39875. function isPlainObject(value) {
  39876. if (!value || typeof value !== "object") { return false; }
  39877. var proto = Object.getPrototypeOf(value);
  39878. return !proto || proto === Object.prototype;
  39879. }
  39880. function original(value) {
  39881. if (value && value[DRAFT_STATE]) {
  39882. return value[DRAFT_STATE].base;
  39883. } // otherwise return undefined
  39884. }
  39885. var ownKeys = typeof Reflect !== "undefined" && Reflect.ownKeys ? Reflect.ownKeys : typeof Object.getOwnPropertySymbols !== "undefined" ? function (obj) {
  39886. return Object.getOwnPropertyNames(obj).concat(Object.getOwnPropertySymbols(obj));
  39887. } :
  39888. /* istanbul ignore next */
  39889. Object.getOwnPropertyNames;
  39890. function each(obj, iter) {
  39891. if (getArchtype(obj) === Archtype.Object) {
  39892. ownKeys(obj).forEach(function (key) {
  39893. return iter(key, obj[key], obj);
  39894. });
  39895. } else {
  39896. obj.forEach(function (entry, index) {
  39897. return iter(index, entry, obj);
  39898. });
  39899. }
  39900. }
  39901. function isEnumerable(base, prop) {
  39902. var desc = Object.getOwnPropertyDescriptor(base, prop);
  39903. return desc && desc.enumerable ? true : false;
  39904. }
  39905. function getArchtype(thing) {
  39906. /* istanbul ignore next */
  39907. if (!thing) { die(); }
  39908. if (thing[DRAFT_STATE]) {
  39909. switch (thing[DRAFT_STATE].type) {
  39910. case ProxyType.ES5Object:
  39911. case ProxyType.ProxyObject:
  39912. return Archtype.Object;
  39913. case ProxyType.ES5Array:
  39914. case ProxyType.ProxyArray:
  39915. return Archtype.Array;
  39916. case ProxyType.Map:
  39917. return Archtype.Map;
  39918. case ProxyType.Set:
  39919. return Archtype.Set;
  39920. }
  39921. }
  39922. return Array.isArray(thing) ? Archtype.Array : isMap(thing) ? Archtype.Map : isSet(thing) ? Archtype.Set : Archtype.Object;
  39923. }
  39924. function has(thing, prop) {
  39925. return getArchtype(thing) === Archtype.Map ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
  39926. }
  39927. function get(thing, prop) {
  39928. // @ts-ignore
  39929. return getArchtype(thing) === Archtype.Map ? thing.get(prop) : thing[prop];
  39930. }
  39931. function set(thing, propOrOldValue, value) {
  39932. switch (getArchtype(thing)) {
  39933. case Archtype.Map:
  39934. thing.set(propOrOldValue, value);
  39935. break;
  39936. case Archtype.Set:
  39937. thing.delete(propOrOldValue);
  39938. thing.add(value);
  39939. break;
  39940. default:
  39941. thing[propOrOldValue] = value;
  39942. }
  39943. }
  39944. function is(x, y) {
  39945. // From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js
  39946. if (x === y) {
  39947. return x !== 0 || 1 / x === 1 / y;
  39948. } else {
  39949. return x !== x && y !== y;
  39950. }
  39951. }
  39952. function isMap(target) {
  39953. return hasMap && target instanceof Map;
  39954. }
  39955. function isSet(target) {
  39956. return hasSet && target instanceof Set;
  39957. }
  39958. function latest(state) {
  39959. return state.copy || state.base;
  39960. }
  39961. function shallowCopy(base, invokeGetters) {
  39962. if (invokeGetters === void 0) {
  39963. invokeGetters = false;
  39964. }
  39965. if (Array.isArray(base)) { return base.slice(); }
  39966. var clone = Object.create(Object.getPrototypeOf(base));
  39967. ownKeys(base).forEach(function (key) {
  39968. if (key === DRAFT_STATE) {
  39969. return; // Never copy over draft state.
  39970. }
  39971. var desc = Object.getOwnPropertyDescriptor(base, key);
  39972. var value = desc.value;
  39973. if (desc.get) {
  39974. if (!invokeGetters) {
  39975. throw new Error("Immer drafts cannot have computed properties");
  39976. }
  39977. value = desc.get.call(base);
  39978. }
  39979. if (desc.enumerable) {
  39980. clone[key] = value;
  39981. } else {
  39982. Object.defineProperty(clone, key, {
  39983. value: value,
  39984. writable: true,
  39985. configurable: true
  39986. });
  39987. }
  39988. });
  39989. return clone;
  39990. }
  39991. function freeze(obj, deep) {
  39992. if (!isDraftable(obj) || isDraft(obj) || Object.isFrozen(obj)) { return; }
  39993. var type = getArchtype(obj);
  39994. if (type === Archtype.Set) {
  39995. obj.add = obj.clear = obj.delete = dontMutateFrozenCollections;
  39996. } else if (type === Archtype.Map) {
  39997. obj.set = obj.clear = obj.delete = dontMutateFrozenCollections;
  39998. }
  39999. Object.freeze(obj);
  40000. if (deep) { each(obj, function (_, value) {
  40001. return freeze(value, true);
  40002. }); }
  40003. }
  40004. function dontMutateFrozenCollections() {
  40005. throw new Error("This object has been frozen and should not be mutated");
  40006. }
  40007. function createHiddenProperty(target, prop, value) {
  40008. Object.defineProperty(target, prop, {
  40009. value: value,
  40010. enumerable: false,
  40011. writable: true
  40012. });
  40013. }
  40014. /* istanbul ignore next */
  40015. function die() {
  40016. throw new Error("Illegal state, please file a bug");
  40017. }
  40018. /** Each scope represents a `produce` call. */
  40019. var ImmerScope =
  40020. /** @class */
  40021. function () {
  40022. function ImmerScope(parent, immer) {
  40023. this.drafts = [];
  40024. this.parent = parent;
  40025. this.immer = immer; // Whenever the modified draft contains a draft from another scope, we
  40026. // need to prevent auto-freezing so the unowned draft can be finalized.
  40027. this.canAutoFreeze = true;
  40028. }
  40029. ImmerScope.prototype.usePatches = function (patchListener) {
  40030. if (patchListener) {
  40031. this.patches = [];
  40032. this.inversePatches = [];
  40033. this.patchListener = patchListener;
  40034. }
  40035. };
  40036. ImmerScope.prototype.revoke = function () {
  40037. this.leave();
  40038. this.drafts.forEach(revoke); // @ts-ignore
  40039. this.drafts = null;
  40040. };
  40041. ImmerScope.prototype.leave = function () {
  40042. if (this === ImmerScope.current) {
  40043. ImmerScope.current = this.parent;
  40044. }
  40045. };
  40046. ImmerScope.enter = function (immer) {
  40047. var scope = new ImmerScope(ImmerScope.current, immer);
  40048. ImmerScope.current = scope;
  40049. return scope;
  40050. };
  40051. return ImmerScope;
  40052. }();
  40053. function revoke(draft) {
  40054. var state = draft[DRAFT_STATE];
  40055. if (state.type === ProxyType.ProxyObject || state.type === ProxyType.ProxyArray) { state.revoke(); }else { state.revoked = true; }
  40056. }
  40057. function processResult(immer, result, scope) {
  40058. var baseDraft = scope.drafts[0];
  40059. var isReplaced = result !== undefined && result !== baseDraft;
  40060. immer.willFinalize(scope, result, isReplaced);
  40061. if (isReplaced) {
  40062. if (baseDraft[DRAFT_STATE].modified) {
  40063. scope.revoke();
  40064. throw new Error("An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft."); // prettier-ignore
  40065. }
  40066. if (isDraftable(result)) {
  40067. // Finalize the result in case it contains (or is) a subset of the draft.
  40068. result = finalize(immer, result, scope);
  40069. maybeFreeze(immer, result);
  40070. }
  40071. if (scope.patches) {
  40072. scope.patches.push({
  40073. op: "replace",
  40074. path: [],
  40075. value: result
  40076. });
  40077. scope.inversePatches.push({
  40078. op: "replace",
  40079. path: [],
  40080. value: baseDraft[DRAFT_STATE].base
  40081. });
  40082. }
  40083. } else {
  40084. // Finalize the base draft.
  40085. result = finalize(immer, baseDraft, scope, []);
  40086. }
  40087. scope.revoke();
  40088. if (scope.patches) {
  40089. scope.patchListener(scope.patches, scope.inversePatches);
  40090. }
  40091. return result !== NOTHING ? result : undefined;
  40092. }
  40093. function finalize(immer, draft, scope, path) {
  40094. var state = draft[DRAFT_STATE];
  40095. if (!state) {
  40096. if (Object.isFrozen(draft)) { return draft; }
  40097. return finalizeTree(immer, draft, scope);
  40098. } // Never finalize drafts owned by another scope.
  40099. if (state.scope !== scope) {
  40100. return draft;
  40101. }
  40102. if (!state.modified) {
  40103. maybeFreeze(immer, state.base, true);
  40104. return state.base;
  40105. }
  40106. if (!state.finalized) {
  40107. state.finalized = true;
  40108. finalizeTree(immer, state.draft, scope, path); // We cannot really delete anything inside of a Set. We can only replace the whole Set.
  40109. if (immer.onDelete && state.type !== ProxyType.Set) {
  40110. // The `assigned` object is unreliable with ES5 drafts.
  40111. if (immer.useProxies) {
  40112. var assigned = state.assigned;
  40113. each(assigned, function (prop, exists) {
  40114. if (!exists) { immer.onDelete(state, prop); }
  40115. });
  40116. } else {
  40117. var base = state.base,
  40118. copy_1 = state.copy;
  40119. each(base, function (prop) {
  40120. if (!has(copy_1, prop)) { immer.onDelete(state, prop); }
  40121. });
  40122. }
  40123. }
  40124. if (immer.onCopy) {
  40125. immer.onCopy(state);
  40126. } // At this point, all descendants of `state.copy` have been finalized,
  40127. // so we can be sure that `scope.canAutoFreeze` is accurate.
  40128. if (immer.autoFreeze && scope.canAutoFreeze) {
  40129. freeze(state.copy, false);
  40130. }
  40131. if (path && scope.patches) {
  40132. generatePatches(state, path, scope.patches, scope.inversePatches);
  40133. }
  40134. }
  40135. return state.copy;
  40136. }
  40137. function finalizeTree(immer, root, scope, rootPath) {
  40138. var state = root[DRAFT_STATE];
  40139. if (state) {
  40140. if (state.type === ProxyType.ES5Object || state.type === ProxyType.ES5Array) {
  40141. // Create the final copy, with added keys and without deleted keys.
  40142. state.copy = shallowCopy(state.draft, true);
  40143. }
  40144. root = state.copy;
  40145. }
  40146. each(root, function (key, value) {
  40147. return finalizeProperty(immer, scope, root, state, root, key, value, rootPath);
  40148. });
  40149. return root;
  40150. }
  40151. function finalizeProperty(immer, scope, root, rootState, parentValue, prop, childValue, rootPath) {
  40152. if (childValue === parentValue) {
  40153. throw Error("Immer forbids circular references");
  40154. } // In the `finalizeTree` method, only the `root` object may be a draft.
  40155. var isDraftProp = !!rootState && parentValue === root;
  40156. var isSetMember = isSet(parentValue);
  40157. if (isDraft(childValue)) {
  40158. var path = rootPath && isDraftProp && !isSetMember && // Set objects are atomic since they have no keys.
  40159. !has(rootState.assigned, prop) // Skip deep patches for assigned keys.
  40160. ? rootPath.concat(prop) : undefined; // Drafts owned by `scope` are finalized here.
  40161. childValue = finalize(immer, childValue, scope, path);
  40162. set(parentValue, prop, childValue); // Drafts from another scope must prevent auto-freezing.
  40163. if (isDraft(childValue)) {
  40164. scope.canAutoFreeze = false;
  40165. }
  40166. } // Unchanged draft properties are ignored.
  40167. else if (isDraftProp && is(childValue, get(rootState.base, prop))) {
  40168. return;
  40169. } // Search new objects for unfinalized drafts. Frozen objects should never contain drafts.
  40170. // TODO: the recursion over here looks weird, shouldn't non-draft stuff have it's own recursion?
  40171. // especially the passing on of root and rootState doesn't make sense...
  40172. else if (isDraftable(childValue) && !Object.isFrozen(childValue)) {
  40173. each(childValue, function (key, grandChild) {
  40174. return finalizeProperty(immer, scope, root, rootState, childValue, key, grandChild, rootPath);
  40175. });
  40176. maybeFreeze(immer, childValue);
  40177. }
  40178. if (isDraftProp && immer.onAssign && !isSetMember) {
  40179. immer.onAssign(rootState, prop, childValue);
  40180. }
  40181. }
  40182. function maybeFreeze(immer, value, deep) {
  40183. if (deep === void 0) {
  40184. deep = false;
  40185. }
  40186. if (immer.autoFreeze && !isDraft(value)) {
  40187. freeze(value, deep);
  40188. }
  40189. }
  40190. /**
  40191. * Returns a new draft of the `base` object.
  40192. *
  40193. * The second argument is the parent draft-state (used internally).
  40194. */
  40195. function createProxy(base, parent) {
  40196. var isArray = Array.isArray(base);
  40197. var state = {
  40198. type: isArray ? ProxyType.ProxyArray : ProxyType.ProxyObject,
  40199. // Track which produce call this is associated with.
  40200. scope: parent ? parent.scope : ImmerScope.current,
  40201. // True for both shallow and deep changes.
  40202. modified: false,
  40203. // Used during finalization.
  40204. finalized: false,
  40205. // Track which properties have been assigned (true) or deleted (false).
  40206. assigned: {},
  40207. // The parent draft state.
  40208. parent: parent,
  40209. // The base state.
  40210. base: base,
  40211. // The base proxy.
  40212. draft: null,
  40213. // Any property proxies.
  40214. drafts: {},
  40215. // The base copy with any updated values.
  40216. copy: null,
  40217. // Called by the `produce` function.
  40218. revoke: null,
  40219. isManual: false
  40220. }; // the traps must target something, a bit like the 'real' base.
  40221. // but also, we need to be able to determine from the target what the relevant state is
  40222. // (to avoid creating traps per instance to capture the state in closure,
  40223. // and to avoid creating weird hidden properties as well)
  40224. // So the trick is to use 'state' as the actual 'target'! (and make sure we intercept everything)
  40225. // Note that in the case of an array, we put the state in an array to have better Reflect defaults ootb
  40226. var target = state;
  40227. var traps = objectTraps;
  40228. if (isArray) {
  40229. target = [state];
  40230. traps = arrayTraps;
  40231. } // TODO: optimization: might be faster, cheaper if we created a non-revocable proxy
  40232. // and administrate revoking ourselves
  40233. var _a = Proxy.revocable(target, traps),
  40234. revoke = _a.revoke,
  40235. proxy = _a.proxy;
  40236. state.draft = proxy;
  40237. state.revoke = revoke;
  40238. return proxy;
  40239. }
  40240. /**
  40241. * Object drafts
  40242. */
  40243. var objectTraps = {
  40244. get: function (state, prop) {
  40245. if (prop === DRAFT_STATE) { return state; }
  40246. var drafts = state.drafts; // Check for existing draft in unmodified state.
  40247. if (!state.modified && has(drafts, prop)) {
  40248. return drafts[prop];
  40249. }
  40250. var value = latest(state)[prop];
  40251. if (state.finalized || !isDraftable(value)) {
  40252. return value;
  40253. } // Check for existing draft in modified state.
  40254. if (state.modified) {
  40255. // Assigned values are never drafted. This catches any drafts we created, too.
  40256. if (value !== peek(state.base, prop)) { return value; } // Store drafts on the copy (when one exists).
  40257. // @ts-ignore
  40258. drafts = state.copy;
  40259. }
  40260. return drafts[prop] = state.scope.immer.createProxy(value, state);
  40261. },
  40262. has: function (state, prop) {
  40263. return prop in latest(state);
  40264. },
  40265. ownKeys: function (state) {
  40266. return Reflect.ownKeys(latest(state));
  40267. },
  40268. set: function (state, prop
  40269. /* strictly not, but helps TS */
  40270. , value) {
  40271. if (!state.modified) {
  40272. var baseValue = peek(state.base, prop); // Optimize based on value's truthiness. Truthy values are guaranteed to
  40273. // never be undefined, so we can avoid the `in` operator. Lastly, truthy
  40274. // values may be drafts, but falsy values are never drafts.
  40275. var isUnchanged = value ? is(baseValue, value) || value === state.drafts[prop] : is(baseValue, value) && prop in state.base;
  40276. if (isUnchanged) { return true; }
  40277. prepareCopy(state);
  40278. markChanged(state);
  40279. }
  40280. state.assigned[prop] = true; // @ts-ignore
  40281. state.copy[prop] = value;
  40282. return true;
  40283. },
  40284. deleteProperty: function (state, prop) {
  40285. // The `undefined` check is a fast path for pre-existing keys.
  40286. if (peek(state.base, prop) !== undefined || prop in state.base) {
  40287. state.assigned[prop] = false;
  40288. prepareCopy(state);
  40289. markChanged(state);
  40290. } else if (state.assigned[prop]) {
  40291. // if an originally not assigned property was deleted
  40292. delete state.assigned[prop];
  40293. } // @ts-ignore
  40294. if (state.copy) { delete state.copy[prop]; }
  40295. return true;
  40296. },
  40297. // Note: We never coerce `desc.value` into an Immer draft, because we can't make
  40298. // the same guarantee in ES5 mode.
  40299. getOwnPropertyDescriptor: function (state, prop) {
  40300. var owner = latest(state);
  40301. var desc = Reflect.getOwnPropertyDescriptor(owner, prop);
  40302. if (desc) {
  40303. desc.writable = true;
  40304. desc.configurable = state.type !== ProxyType.ProxyArray || prop !== "length";
  40305. }
  40306. return desc;
  40307. },
  40308. defineProperty: function () {
  40309. throw new Error("Object.defineProperty() cannot be used on an Immer draft"); // prettier-ignore
  40310. },
  40311. getPrototypeOf: function (state) {
  40312. return Object.getPrototypeOf(state.base);
  40313. },
  40314. setPrototypeOf: function () {
  40315. throw new Error("Object.setPrototypeOf() cannot be used on an Immer draft"); // prettier-ignore
  40316. }
  40317. };
  40318. /**
  40319. * Array drafts
  40320. */
  40321. var arrayTraps = {};
  40322. each(objectTraps, function (key, fn) {
  40323. // @ts-ignore
  40324. arrayTraps[key] = function () {
  40325. arguments[0] = arguments[0][0];
  40326. return fn.apply(this, arguments);
  40327. };
  40328. });
  40329. arrayTraps.deleteProperty = function (state, prop) {
  40330. if (isNaN(parseInt(prop))) {
  40331. throw new Error("Immer only supports deleting array indices"); // prettier-ignore
  40332. }
  40333. return objectTraps.deleteProperty.call(this, state[0], prop);
  40334. };
  40335. arrayTraps.set = function (state, prop, value) {
  40336. if (prop !== "length" && isNaN(parseInt(prop))) {
  40337. throw new Error("Immer only supports setting array indices and the 'length' property"); // prettier-ignore
  40338. }
  40339. return objectTraps.set.call(this, state[0], prop, value, state[0]);
  40340. };
  40341. /**
  40342. * Map drafts
  40343. */
  40344. // Access a property without creating an Immer draft.
  40345. function peek(draft, prop) {
  40346. var state = draft[DRAFT_STATE];
  40347. var desc = Reflect.getOwnPropertyDescriptor(state ? latest(state) : draft, prop);
  40348. return desc && desc.value;
  40349. }
  40350. function markChanged(state) {
  40351. if (!state.modified) {
  40352. state.modified = true;
  40353. if (state.type === ProxyType.ProxyObject || state.type === ProxyType.ProxyArray) {
  40354. var copy_1 = state.copy = shallowCopy(state.base);
  40355. each(state.drafts, function (key, value) {
  40356. // @ts-ignore
  40357. copy_1[key] = value;
  40358. });
  40359. state.drafts = undefined;
  40360. }
  40361. if (state.parent) {
  40362. markChanged(state.parent);
  40363. }
  40364. }
  40365. }
  40366. function prepareCopy(state) {
  40367. if (!state.copy) {
  40368. state.copy = shallowCopy(state.base);
  40369. }
  40370. }
  40371. function willFinalizeES5(scope, result, isReplaced) {
  40372. scope.drafts.forEach(function (draft) {
  40373. draft[DRAFT_STATE].finalizing = true;
  40374. });
  40375. if (!isReplaced) {
  40376. if (scope.patches) {
  40377. markChangesRecursively(scope.drafts[0]);
  40378. } // This is faster when we don't care about which attributes changed.
  40379. markChangesSweep(scope.drafts);
  40380. } // When a child draft is returned, look for changes.
  40381. else if (isDraft(result) && result[DRAFT_STATE].scope === scope) {
  40382. markChangesSweep(scope.drafts);
  40383. }
  40384. }
  40385. function createES5Proxy(base, parent) {
  40386. var isArray = Array.isArray(base);
  40387. var draft = clonePotentialDraft(base);
  40388. each(draft, function (prop) {
  40389. proxyProperty(draft, prop, isArray || isEnumerable(base, prop));
  40390. });
  40391. var state = {
  40392. type: isArray ? ProxyType.ES5Array : ProxyType.ES5Object,
  40393. scope: parent ? parent.scope : ImmerScope.current,
  40394. modified: false,
  40395. finalizing: false,
  40396. finalized: false,
  40397. assigned: {},
  40398. parent: parent,
  40399. base: base,
  40400. draft: draft,
  40401. copy: null,
  40402. revoked: false,
  40403. isManual: false
  40404. };
  40405. createHiddenProperty(draft, DRAFT_STATE, state);
  40406. return draft;
  40407. } // Access a property without creating an Immer draft.
  40408. function peek$1(draft, prop) {
  40409. var state = draft[DRAFT_STATE];
  40410. if (state && !state.finalizing) {
  40411. state.finalizing = true;
  40412. var value = draft[prop];
  40413. state.finalizing = false;
  40414. return value;
  40415. }
  40416. return draft[prop];
  40417. }
  40418. function get$1(state, prop) {
  40419. assertUnrevoked(state);
  40420. var value = peek$1(latest(state), prop);
  40421. if (state.finalizing) { return value; } // Create a draft if the value is unmodified.
  40422. if (value === peek$1(state.base, prop) && isDraftable(value)) {
  40423. prepareCopy$1(state); // @ts-ignore
  40424. return state.copy[prop] = state.scope.immer.createProxy(value, state);
  40425. }
  40426. return value;
  40427. }
  40428. function set$1(state, prop, value) {
  40429. assertUnrevoked(state);
  40430. state.assigned[prop] = true;
  40431. if (!state.modified) {
  40432. if (is(value, peek$1(latest(state), prop))) { return; }
  40433. markChangedES5(state);
  40434. prepareCopy$1(state);
  40435. } // @ts-ignore
  40436. state.copy[prop] = value;
  40437. }
  40438. function markChangedES5(state) {
  40439. if (!state.modified) {
  40440. state.modified = true;
  40441. if (state.parent) { markChangedES5(state.parent); }
  40442. }
  40443. }
  40444. function prepareCopy$1(state) {
  40445. if (!state.copy) { state.copy = clonePotentialDraft(state.base); }
  40446. }
  40447. function clonePotentialDraft(base) {
  40448. var state = base && base[DRAFT_STATE];
  40449. if (state) {
  40450. state.finalizing = true;
  40451. var draft = shallowCopy(state.draft, true);
  40452. state.finalizing = false;
  40453. return draft;
  40454. }
  40455. return shallowCopy(base);
  40456. } // property descriptors are recycled to make sure we don't create a get and set closure per property,
  40457. // but share them all instead
  40458. var descriptors = {};
  40459. function proxyProperty(draft, prop, enumerable) {
  40460. var desc = descriptors[prop];
  40461. if (desc) {
  40462. desc.enumerable = enumerable;
  40463. } else {
  40464. descriptors[prop] = desc = {
  40465. configurable: true,
  40466. enumerable: enumerable,
  40467. get: function () {
  40468. return get$1(this[DRAFT_STATE], prop);
  40469. },
  40470. set: function (value) {
  40471. set$1(this[DRAFT_STATE], prop, value);
  40472. }
  40473. };
  40474. }
  40475. Object.defineProperty(draft, prop, desc);
  40476. }
  40477. function assertUnrevoked(state) {
  40478. if (state.revoked === true) { throw new Error("Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + JSON.stringify(latest(state))); }
  40479. } // This looks expensive, but only proxies are visited, and only objects without known changes are scanned.
  40480. function markChangesSweep(drafts) {
  40481. // The natural order of drafts in the `scope` array is based on when they
  40482. // were accessed. By processing drafts in reverse natural order, we have a
  40483. // better chance of processing leaf nodes first. When a leaf node is known to
  40484. // have changed, we can avoid any traversal of its ancestor nodes.
  40485. for (var i = drafts.length - 1; i >= 0; i--) {
  40486. var state = drafts[i][DRAFT_STATE];
  40487. if (!state.modified) {
  40488. switch (state.type) {
  40489. case ProxyType.ES5Array:
  40490. if (hasArrayChanges(state)) { markChangedES5(state); }
  40491. break;
  40492. case ProxyType.ES5Object:
  40493. if (hasObjectChanges(state)) { markChangedES5(state); }
  40494. break;
  40495. }
  40496. }
  40497. }
  40498. }
  40499. function markChangesRecursively(object) {
  40500. if (!object || typeof object !== "object") { return; }
  40501. var state = object[DRAFT_STATE];
  40502. if (!state) { return; }
  40503. var base = state.base,
  40504. draft = state.draft,
  40505. assigned = state.assigned,
  40506. type = state.type;
  40507. if (type === ProxyType.ES5Object) {
  40508. // Look for added keys.
  40509. // TODO: looks quite duplicate to hasObjectChanges,
  40510. // probably there is a faster way to detect changes, as sweep + recurse seems to do some
  40511. // unnecessary work.
  40512. // also: probably we can store the information we detect here, to speed up tree finalization!
  40513. each(draft, function (key) {
  40514. if (key === DRAFT_STATE) { return; } // The `undefined` check is a fast path for pre-existing keys.
  40515. if (base[key] === undefined && !has(base, key)) {
  40516. assigned[key] = true;
  40517. markChangedES5(state);
  40518. } else if (!assigned[key]) {
  40519. // Only untouched properties trigger recursion.
  40520. markChangesRecursively(draft[key]);
  40521. }
  40522. }); // Look for removed keys.
  40523. each(base, function (key) {
  40524. // The `undefined` check is a fast path for pre-existing keys.
  40525. if (draft[key] === undefined && !has(draft, key)) {
  40526. assigned[key] = false;
  40527. markChangedES5(state);
  40528. }
  40529. });
  40530. } else if (type === ProxyType.ES5Array && hasArrayChanges(state)) {
  40531. markChangedES5(state);
  40532. assigned.length = true;
  40533. if (draft.length < base.length) {
  40534. for (var i = draft.length; i < base.length; i++) { assigned[i] = false; }
  40535. } else {
  40536. for (var i = base.length; i < draft.length; i++) { assigned[i] = true; }
  40537. }
  40538. for (var i = 0; i < draft.length; i++) {
  40539. // Only untouched indices trigger recursion.
  40540. if (assigned[i] === undefined) { markChangesRecursively(draft[i]); }
  40541. }
  40542. }
  40543. }
  40544. function hasObjectChanges(state) {
  40545. var base = state.base,
  40546. draft = state.draft; // Search for added keys and changed keys. Start at the back, because
  40547. // non-numeric keys are ordered by time of definition on the object.
  40548. var keys = Object.keys(draft);
  40549. for (var i = keys.length - 1; i >= 0; i--) {
  40550. var key = keys[i];
  40551. var baseValue = base[key]; // The `undefined` check is a fast path for pre-existing keys.
  40552. if (baseValue === undefined && !has(base, key)) {
  40553. return true;
  40554. } // Once a base key is deleted, future changes go undetected, because its
  40555. // descriptor is erased. This branch detects any missed changes.
  40556. else {
  40557. var value = draft[key];
  40558. var state_1 = value && value[DRAFT_STATE];
  40559. if (state_1 ? state_1.base !== baseValue : !is(value, baseValue)) {
  40560. return true;
  40561. }
  40562. }
  40563. } // At this point, no keys were added or changed.
  40564. // Compare key count to determine if keys were deleted.
  40565. return keys.length !== Object.keys(base).length;
  40566. }
  40567. function hasArrayChanges(state) {
  40568. var draft = state.draft;
  40569. if (draft.length !== state.base.length) { return true; } // See #116
  40570. // If we first shorten the length, our array interceptors will be removed.
  40571. // If after that new items are added, result in the same original length,
  40572. // those last items will have no intercepting property.
  40573. // So if there is no own descriptor on the last position, we know that items were removed and added
  40574. // N.B.: splice, unshift, etc only shift values around, but not prop descriptors, so we only have to check
  40575. // the last one
  40576. var descriptor = Object.getOwnPropertyDescriptor(draft, draft.length - 1); // descriptor can be null, but only for newly created sparse arrays, eg. new Array(10)
  40577. if (descriptor && !descriptor.get) { return true; } // For all other cases, we don't have to compare, as they would have been picked up by the index setters
  40578. return false;
  40579. }
  40580. var DraftMap = function (_super) {
  40581. if (!_super) {
  40582. /* istanbul ignore next */
  40583. throw new Error("Map is not polyfilled");
  40584. }
  40585. __extends(DraftMap, _super); // Create class manually, cause #502
  40586. function DraftMap(target, parent) {
  40587. this[DRAFT_STATE] = {
  40588. type: ProxyType.Map,
  40589. parent: parent,
  40590. scope: parent ? parent.scope : ImmerScope.current,
  40591. modified: false,
  40592. finalized: false,
  40593. copy: undefined,
  40594. assigned: undefined,
  40595. base: target,
  40596. draft: this,
  40597. isManual: false,
  40598. revoked: false
  40599. };
  40600. return this;
  40601. }
  40602. var p = DraftMap.prototype; // TODO: smaller build size if we create a util for Object.defineProperty
  40603. Object.defineProperty(p, "size", {
  40604. get: function () {
  40605. return latest(this[DRAFT_STATE]).size;
  40606. },
  40607. enumerable: true,
  40608. configurable: true
  40609. });
  40610. p.has = function (key) {
  40611. return latest(this[DRAFT_STATE]).has(key);
  40612. };
  40613. p.set = function (key, value) {
  40614. var state = this[DRAFT_STATE];
  40615. assertUnrevoked(state);
  40616. if (latest(state).get(key) !== value) {
  40617. prepareCopy$2(state);
  40618. state.scope.immer.markChanged(state);
  40619. state.assigned.set(key, true);
  40620. state.copy.set(key, value);
  40621. state.assigned.set(key, true);
  40622. }
  40623. return this;
  40624. };
  40625. p.delete = function (key) {
  40626. if (!this.has(key)) {
  40627. return false;
  40628. }
  40629. var state = this[DRAFT_STATE];
  40630. assertUnrevoked(state);
  40631. prepareCopy$2(state);
  40632. state.scope.immer.markChanged(state);
  40633. state.assigned.set(key, false);
  40634. state.copy.delete(key);
  40635. return true;
  40636. };
  40637. p.clear = function () {
  40638. var state = this[DRAFT_STATE];
  40639. assertUnrevoked(state);
  40640. prepareCopy$2(state);
  40641. state.scope.immer.markChanged(state);
  40642. state.assigned = new Map();
  40643. return state.copy.clear();
  40644. };
  40645. p.forEach = function (cb, thisArg) {
  40646. var _this = this;
  40647. var state = this[DRAFT_STATE];
  40648. latest(state).forEach(function (_value, key, _map) {
  40649. cb.call(thisArg, _this.get(key), key, _this);
  40650. });
  40651. };
  40652. p.get = function (key) {
  40653. var state = this[DRAFT_STATE];
  40654. assertUnrevoked(state);
  40655. var value = latest(state).get(key);
  40656. if (state.finalized || !isDraftable(value)) {
  40657. return value;
  40658. }
  40659. if (value !== state.base.get(key)) {
  40660. return value; // either already drafted or reassigned
  40661. } // despite what it looks, this creates a draft only once, see above condition
  40662. var draft = state.scope.immer.createProxy(value, state);
  40663. prepareCopy$2(state);
  40664. state.copy.set(key, draft);
  40665. return draft;
  40666. };
  40667. p.keys = function () {
  40668. return latest(this[DRAFT_STATE]).keys();
  40669. };
  40670. p.values = function () {
  40671. var _a;
  40672. var _this = this;
  40673. var iterator = this.keys();
  40674. return _a = {}, _a[iteratorSymbol] = function () {
  40675. return _this.values();
  40676. }, _a.next = function () {
  40677. var r = iterator.next();
  40678. /* istanbul ignore next */
  40679. if (r.done) { return r; }
  40680. var value = _this.get(r.value);
  40681. return {
  40682. done: false,
  40683. value: value
  40684. };
  40685. }, _a;
  40686. };
  40687. p.entries = function () {
  40688. var _a;
  40689. var _this = this;
  40690. var iterator = this.keys();
  40691. return _a = {}, _a[iteratorSymbol] = function () {
  40692. return _this.entries();
  40693. }, _a.next = function () {
  40694. var r = iterator.next();
  40695. /* istanbul ignore next */
  40696. if (r.done) { return r; }
  40697. var value = _this.get(r.value);
  40698. return {
  40699. done: false,
  40700. value: [r.value, value]
  40701. };
  40702. }, _a;
  40703. };
  40704. p[iteratorSymbol] = function () {
  40705. return this.entries();
  40706. };
  40707. return DraftMap;
  40708. }(Map);
  40709. function proxyMap(target, parent) {
  40710. // @ts-ignore
  40711. return new DraftMap(target, parent);
  40712. }
  40713. function prepareCopy$2(state) {
  40714. if (!state.copy) {
  40715. state.assigned = new Map();
  40716. state.copy = new Map(state.base);
  40717. }
  40718. }
  40719. var DraftSet = function (_super) {
  40720. if (!_super) {
  40721. /* istanbul ignore next */
  40722. throw new Error("Set is not polyfilled");
  40723. }
  40724. __extends(DraftSet, _super); // Create class manually, cause #502
  40725. function DraftSet(target, parent) {
  40726. this[DRAFT_STATE] = {
  40727. type: ProxyType.Set,
  40728. parent: parent,
  40729. scope: parent ? parent.scope : ImmerScope.current,
  40730. modified: false,
  40731. finalized: false,
  40732. copy: undefined,
  40733. base: target,
  40734. draft: this,
  40735. drafts: new Map(),
  40736. revoked: false,
  40737. isManual: false
  40738. };
  40739. return this;
  40740. }
  40741. var p = DraftSet.prototype;
  40742. Object.defineProperty(p, "size", {
  40743. get: function () {
  40744. return latest(this[DRAFT_STATE]).size;
  40745. },
  40746. enumerable: true,
  40747. configurable: true
  40748. });
  40749. p.has = function (value) {
  40750. var state = this[DRAFT_STATE];
  40751. assertUnrevoked(state); // bit of trickery here, to be able to recognize both the value, and the draft of its value
  40752. if (!state.copy) {
  40753. return state.base.has(value);
  40754. }
  40755. if (state.copy.has(value)) { return true; }
  40756. if (state.drafts.has(value) && state.copy.has(state.drafts.get(value))) { return true; }
  40757. return false;
  40758. };
  40759. p.add = function (value) {
  40760. var state = this[DRAFT_STATE];
  40761. assertUnrevoked(state);
  40762. if (state.copy) {
  40763. state.copy.add(value);
  40764. } else if (!state.base.has(value)) {
  40765. prepareCopy$3(state);
  40766. state.scope.immer.markChanged(state);
  40767. state.copy.add(value);
  40768. }
  40769. return this;
  40770. };
  40771. p.delete = function (value) {
  40772. if (!this.has(value)) {
  40773. return false;
  40774. }
  40775. var state = this[DRAFT_STATE];
  40776. assertUnrevoked(state);
  40777. prepareCopy$3(state);
  40778. state.scope.immer.markChanged(state);
  40779. return state.copy.delete(value) || (state.drafts.has(value) ? state.copy.delete(state.drafts.get(value)) :
  40780. /* istanbul ignore next */
  40781. false);
  40782. };
  40783. p.clear = function () {
  40784. var state = this[DRAFT_STATE];
  40785. assertUnrevoked(state);
  40786. prepareCopy$3(state);
  40787. state.scope.immer.markChanged(state);
  40788. return state.copy.clear();
  40789. };
  40790. p.values = function () {
  40791. var state = this[DRAFT_STATE];
  40792. assertUnrevoked(state);
  40793. prepareCopy$3(state);
  40794. return state.copy.values();
  40795. };
  40796. p.entries = function entries() {
  40797. var state = this[DRAFT_STATE];
  40798. assertUnrevoked(state);
  40799. prepareCopy$3(state);
  40800. return state.copy.entries();
  40801. };
  40802. p.keys = function () {
  40803. return this.values();
  40804. };
  40805. p[iteratorSymbol] = function () {
  40806. return this.values();
  40807. };
  40808. p.forEach = function forEach(cb, thisArg) {
  40809. var iterator = this.values();
  40810. var result = iterator.next();
  40811. while (!result.done) {
  40812. cb.call(thisArg, result.value, result.value, this);
  40813. result = iterator.next();
  40814. }
  40815. };
  40816. return DraftSet;
  40817. }(Set);
  40818. function proxySet(target, parent) {
  40819. // @ts-ignore
  40820. return new DraftSet(target, parent);
  40821. }
  40822. function prepareCopy$3(state) {
  40823. if (!state.copy) {
  40824. // create drafts for all entries to preserve insertion order
  40825. state.copy = new Set();
  40826. state.base.forEach(function (value) {
  40827. if (isDraftable(value)) {
  40828. var draft = state.scope.immer.createProxy(value, state);
  40829. state.drafts.set(value, draft);
  40830. state.copy.add(draft);
  40831. } else {
  40832. state.copy.add(value);
  40833. }
  40834. });
  40835. }
  40836. }
  40837. function generatePatches(state, basePath, patches, inversePatches) {
  40838. switch (state.type) {
  40839. case ProxyType.ProxyObject:
  40840. case ProxyType.ES5Object:
  40841. case ProxyType.Map:
  40842. return generatePatchesFromAssigned(state, basePath, patches, inversePatches);
  40843. case ProxyType.ES5Array:
  40844. case ProxyType.ProxyArray:
  40845. return generateArrayPatches(state, basePath, patches, inversePatches);
  40846. case ProxyType.Set:
  40847. return generateSetPatches(state, basePath, patches, inversePatches);
  40848. }
  40849. }
  40850. function generateArrayPatches(state, basePath, patches, inversePatches) {
  40851. var _a, _b;
  40852. var base = state.base,
  40853. assigned = state.assigned,
  40854. copy = state.copy;
  40855. /* istanbul ignore next */
  40856. if (!copy) { die(); } // Reduce complexity by ensuring `base` is never longer.
  40857. if (copy.length < base.length) {
  40858. _a = [copy, base], base = _a[0], copy = _a[1];
  40859. _b = [inversePatches, patches], patches = _b[0], inversePatches = _b[1];
  40860. }
  40861. var delta = copy.length - base.length; // Find the first replaced index.
  40862. var start = 0;
  40863. while (base[start] === copy[start] && start < base.length) {
  40864. ++start;
  40865. } // Find the last replaced index. Search from the end to optimize splice patches.
  40866. var end = base.length;
  40867. while (end > start && base[end - 1] === copy[end + delta - 1]) {
  40868. --end;
  40869. } // Process replaced indices.
  40870. for (var i = start; i < end; ++i) {
  40871. if (assigned[i] && copy[i] !== base[i]) {
  40872. var path = basePath.concat([i]);
  40873. patches.push({
  40874. op: "replace",
  40875. path: path,
  40876. value: copy[i]
  40877. });
  40878. inversePatches.push({
  40879. op: "replace",
  40880. path: path,
  40881. value: base[i]
  40882. });
  40883. }
  40884. }
  40885. var replaceCount = patches.length; // Process added indices.
  40886. for (var i = end + delta - 1; i >= end; --i) {
  40887. var path = basePath.concat([i]);
  40888. patches[replaceCount + i - end] = {
  40889. op: "add",
  40890. path: path,
  40891. value: copy[i]
  40892. };
  40893. inversePatches.push({
  40894. op: "remove",
  40895. path: path
  40896. });
  40897. }
  40898. } // This is used for both Map objects and normal objects.
  40899. function generatePatchesFromAssigned(state, basePath, patches, inversePatches) {
  40900. var base = state.base,
  40901. copy = state.copy;
  40902. each(state.assigned, function (key, assignedValue) {
  40903. var origValue = get(base, key);
  40904. var value = get(copy, key);
  40905. var op = !assignedValue ? "remove" : has(base, key) ? "replace" : "add";
  40906. if (origValue === value && op === "replace") { return; }
  40907. var path = basePath.concat(key);
  40908. patches.push(op === "remove" ? {
  40909. op: op,
  40910. path: path
  40911. } : {
  40912. op: op,
  40913. path: path,
  40914. value: value
  40915. });
  40916. inversePatches.push(op === "add" ? {
  40917. op: "remove",
  40918. path: path
  40919. } : op === "remove" ? {
  40920. op: "add",
  40921. path: path,
  40922. value: origValue
  40923. } : {
  40924. op: "replace",
  40925. path: path,
  40926. value: origValue
  40927. });
  40928. });
  40929. }
  40930. function generateSetPatches(state, basePath, patches, inversePatches) {
  40931. var base = state.base,
  40932. copy = state.copy;
  40933. var i = 0;
  40934. base.forEach(function (value) {
  40935. if (!copy.has(value)) {
  40936. var path = basePath.concat([i]);
  40937. patches.push({
  40938. op: "remove",
  40939. path: path,
  40940. value: value
  40941. });
  40942. inversePatches.unshift({
  40943. op: "add",
  40944. path: path,
  40945. value: value
  40946. });
  40947. }
  40948. i++;
  40949. });
  40950. i = 0;
  40951. copy.forEach(function (value) {
  40952. if (!base.has(value)) {
  40953. var path = basePath.concat([i]);
  40954. patches.push({
  40955. op: "add",
  40956. path: path,
  40957. value: value
  40958. });
  40959. inversePatches.unshift({
  40960. op: "remove",
  40961. path: path,
  40962. value: value
  40963. });
  40964. }
  40965. i++;
  40966. });
  40967. }
  40968. function applyPatches(draft, patches) {
  40969. patches.forEach(function (patch) {
  40970. var path = patch.path,
  40971. op = patch.op;
  40972. /* istanbul ignore next */
  40973. if (!path.length) { die(); }
  40974. var base = draft;
  40975. for (var i = 0; i < path.length - 1; i++) {
  40976. base = get(base, path[i]);
  40977. if (!base || typeof base !== "object") { throw new Error("Cannot apply patch, path doesn't resolve: " + path.join("/")); } // prettier-ignore
  40978. }
  40979. var type = getArchtype(base);
  40980. var value = deepClonePatchValue(patch.value); // used to clone patch to ensure original patch is not modified, see #411
  40981. var key = path[path.length - 1];
  40982. switch (op) {
  40983. case "replace":
  40984. switch (type) {
  40985. case Archtype.Map:
  40986. return base.set(key, value);
  40987. /* istanbul ignore next */
  40988. case Archtype.Set:
  40989. throw new Error('Sets cannot have "replace" patches.');
  40990. default:
  40991. // if value is an object, then it's assigned by reference
  40992. // in the following add or remove ops, the value field inside the patch will also be modifyed
  40993. // so we use value from the cloned patch
  40994. // @ts-ignore
  40995. return base[key] = value;
  40996. }
  40997. case "add":
  40998. switch (type) {
  40999. case Archtype.Array:
  41000. return base.splice(key, 0, value);
  41001. case Archtype.Map:
  41002. return base.set(key, value);
  41003. case Archtype.Set:
  41004. return base.add(value);
  41005. default:
  41006. return base[key] = value;
  41007. }
  41008. case "remove":
  41009. switch (type) {
  41010. case Archtype.Array:
  41011. return base.splice(key, 1);
  41012. case Archtype.Map:
  41013. return base.delete(key);
  41014. case Archtype.Set:
  41015. return base.delete(patch.value);
  41016. default:
  41017. return delete base[key];
  41018. }
  41019. default:
  41020. throw new Error("Unsupported patch operation: " + op);
  41021. }
  41022. });
  41023. return draft;
  41024. }
  41025. function deepClonePatchValue(obj) {
  41026. if (!obj || typeof obj !== "object") { return obj; }
  41027. if (Array.isArray(obj)) { return obj.map(deepClonePatchValue); }
  41028. if (isMap(obj)) { return new Map(Array.from(obj.entries()).map(function (_a) {
  41029. var k = _a[0],
  41030. v = _a[1];
  41031. return [k, deepClonePatchValue(v)];
  41032. })); } // Not needed: if (isSet(obj)) return new Set(Array.from(obj.values()).map(deepClone))
  41033. var cloned = Object.create(Object.getPrototypeOf(obj));
  41034. for (var key in obj) { cloned[key] = deepClonePatchValue(obj[key]); }
  41035. return cloned;
  41036. }
  41037. /*! *****************************************************************************
  41038. Copyright (c) Microsoft Corporation. All rights reserved.
  41039. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  41040. this file except in compliance with the License. You may obtain a copy of the
  41041. License at http://www.apache.org/licenses/LICENSE-2.0
  41042. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41043. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  41044. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  41045. MERCHANTABLITY OR NON-INFRINGEMENT.
  41046. See the Apache Version 2.0 License for specific language governing permissions
  41047. and limitations under the License.
  41048. ***************************************************************************** */
  41049. function __spreadArrays() {
  41050. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  41051. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  41052. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  41053. r[k] = a[j];
  41054. return r;
  41055. }
  41056. /* istanbul ignore next */
  41057. function verifyMinified() {}
  41058. var configDefaults = {
  41059. useProxies: typeof Proxy !== "undefined" && typeof Proxy.revocable !== "undefined" && typeof Reflect !== "undefined",
  41060. autoFreeze: typeof process !== "undefined" ? process.env.NODE_ENV !== "production" :
  41061. /* istanbul ignore next */
  41062. verifyMinified.name === "verifyMinified",
  41063. onAssign: null,
  41064. onDelete: null,
  41065. onCopy: null
  41066. };
  41067. var Immer =
  41068. /** @class */
  41069. function () {
  41070. function Immer(config) {
  41071. var _this = this;
  41072. this.useProxies = false;
  41073. this.autoFreeze = false;
  41074. each(configDefaults, function (key, value) {
  41075. var _a, _b; // @ts-ignore
  41076. _this[key] = (_b = (_a = config) === null || _a === void 0 ? void 0 : _a[key], _b !== null && _b !== void 0 ? _b : value);
  41077. });
  41078. this.setUseProxies(this.useProxies);
  41079. this.produce = this.produce.bind(this);
  41080. this.produceWithPatches = this.produceWithPatches.bind(this);
  41081. }
  41082. /**
  41083. * The `produce` function takes a value and a "recipe function" (whose
  41084. * return value often depends on the base state). The recipe function is
  41085. * free to mutate its first argument however it wants. All mutations are
  41086. * only ever applied to a __copy__ of the base state.
  41087. *
  41088. * Pass only a function to create a "curried producer" which relieves you
  41089. * from passing the recipe function every time.
  41090. *
  41091. * Only plain objects and arrays are made mutable. All other objects are
  41092. * considered uncopyable.
  41093. *
  41094. * Note: This function is __bound__ to its `Immer` instance.
  41095. *
  41096. * @param {any} base - the initial state
  41097. * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified
  41098. * @param {Function} patchListener - optional function that will be called with all the patches produced here
  41099. * @returns {any} a new state, or the initial state if nothing was modified
  41100. */
  41101. Immer.prototype.produce = function (base, recipe, patchListener) {
  41102. var _this = this; // curried invocation
  41103. if (typeof base === "function" && typeof recipe !== "function") {
  41104. var defaultBase_1 = recipe;
  41105. recipe = base;
  41106. var self_1 = this;
  41107. return function curriedProduce(base) {
  41108. var arguments$1 = arguments;
  41109. var _this = this;
  41110. if (base === void 0) {
  41111. base = defaultBase_1;
  41112. }
  41113. var args = [];
  41114. for (var _i = 1; _i < arguments.length; _i++) {
  41115. args[_i - 1] = arguments$1[_i];
  41116. }
  41117. return self_1.produce(base, function (draft) {
  41118. return recipe.call.apply(recipe, __spreadArrays([_this, draft], args));
  41119. }); // prettier-ignore
  41120. };
  41121. } // prettier-ignore
  41122. {
  41123. if (typeof recipe !== "function") {
  41124. throw new Error("The first or second argument to `produce` must be a function");
  41125. }
  41126. if (patchListener !== undefined && typeof patchListener !== "function") {
  41127. throw new Error("The third argument to `produce` must be a function or undefined");
  41128. }
  41129. }
  41130. var result; // Only plain objects, arrays, and "immerable classes" are drafted.
  41131. if (isDraftable(base)) {
  41132. var scope_1 = ImmerScope.enter(this);
  41133. var proxy = this.createProxy(base, undefined);
  41134. var hasError = true;
  41135. try {
  41136. result = recipe(proxy);
  41137. hasError = false;
  41138. } finally {
  41139. // finally instead of catch + rethrow better preserves original stack
  41140. if (hasError) { scope_1.revoke(); }else { scope_1.leave(); }
  41141. }
  41142. if (typeof Promise !== "undefined" && result instanceof Promise) {
  41143. return result.then(function (result) {
  41144. scope_1.usePatches(patchListener);
  41145. return processResult(_this, result, scope_1);
  41146. }, function (error) {
  41147. scope_1.revoke();
  41148. throw error;
  41149. });
  41150. }
  41151. scope_1.usePatches(patchListener);
  41152. return processResult(this, result, scope_1);
  41153. } else {
  41154. result = recipe(base);
  41155. if (result === NOTHING) { return undefined; }
  41156. if (result === undefined) { result = base; }
  41157. maybeFreeze(this, result, true);
  41158. return result;
  41159. }
  41160. };
  41161. Immer.prototype.produceWithPatches = function (arg1, arg2, arg3) {
  41162. var _this = this;
  41163. if (typeof arg1 === "function") {
  41164. return function (state) {
  41165. var arguments$1 = arguments;
  41166. var args = [];
  41167. for (var _i = 1; _i < arguments.length; _i++) {
  41168. args[_i - 1] = arguments$1[_i];
  41169. }
  41170. return _this.produceWithPatches(state, function (draft) {
  41171. return arg1.apply(void 0, __spreadArrays([draft], args));
  41172. });
  41173. };
  41174. } // non-curried form
  41175. /* istanbul ignore next */
  41176. if (arg3) { die(); }
  41177. var patches, inversePatches;
  41178. var nextState = this.produce(arg1, arg2, function (p, ip) {
  41179. patches = p;
  41180. inversePatches = ip;
  41181. });
  41182. return [nextState, patches, inversePatches];
  41183. };
  41184. Immer.prototype.createDraft = function (base) {
  41185. if (!isDraftable(base)) {
  41186. throw new Error("First argument to `createDraft` must be a plain object, an array, or an immerable object"); // prettier-ignore
  41187. }
  41188. var scope = ImmerScope.enter(this);
  41189. var proxy = this.createProxy(base, undefined);
  41190. proxy[DRAFT_STATE].isManual = true;
  41191. scope.leave();
  41192. return proxy;
  41193. };
  41194. Immer.prototype.finishDraft = function (draft, patchListener) {
  41195. var state = draft && draft[DRAFT_STATE];
  41196. if (!state || !state.isManual) {
  41197. throw new Error("First argument to `finishDraft` must be a draft returned by `createDraft`"); // prettier-ignore
  41198. }
  41199. if (state.finalized) {
  41200. throw new Error("The given draft is already finalized"); // prettier-ignore
  41201. }
  41202. var scope = state.scope;
  41203. scope.usePatches(patchListener);
  41204. return processResult(this, undefined, scope);
  41205. };
  41206. /**
  41207. * Pass true to automatically freeze all copies created by Immer.
  41208. *
  41209. * By default, auto-freezing is disabled in production.
  41210. */
  41211. Immer.prototype.setAutoFreeze = function (value) {
  41212. this.autoFreeze = value;
  41213. };
  41214. /**
  41215. * Pass true to use the ES2015 `Proxy` class when creating drafts, which is
  41216. * always faster than using ES5 proxies.
  41217. *
  41218. * By default, feature detection is used, so calling this is rarely necessary.
  41219. */
  41220. Immer.prototype.setUseProxies = function (value) {
  41221. this.useProxies = value;
  41222. };
  41223. Immer.prototype.applyPatches = function (base, patches) {
  41224. // If a patch replaces the entire state, take that replacement as base
  41225. // before applying patches
  41226. var i;
  41227. for (i = patches.length - 1; i >= 0; i--) {
  41228. var patch = patches[i];
  41229. if (patch.path.length === 0 && patch.op === "replace") {
  41230. base = patch.value;
  41231. break;
  41232. }
  41233. }
  41234. if (isDraft(base)) {
  41235. // N.B: never hits if some patch a replacement, patches are never drafts
  41236. return applyPatches(base, patches);
  41237. } // Otherwise, produce a copy of the base state.
  41238. return this.produce(base, function (draft) {
  41239. return applyPatches(draft, patches.slice(i + 1));
  41240. });
  41241. };
  41242. Immer.prototype.createProxy = function (value, parent) {
  41243. // precondition: createProxy should be guarded by isDraftable, so we know we can safely draft
  41244. var draft = isMap(value) ? proxyMap(value, parent) : isSet(value) ? proxySet(value, parent) : this.useProxies ? createProxy(value, parent) : createES5Proxy(value, parent);
  41245. var scope = parent ? parent.scope : ImmerScope.current;
  41246. scope.drafts.push(draft);
  41247. return draft;
  41248. };
  41249. Immer.prototype.willFinalize = function (scope, thing, isReplaced) {
  41250. if (!this.useProxies) { willFinalizeES5(scope, thing, isReplaced); }
  41251. };
  41252. Immer.prototype.markChanged = function (state) {
  41253. if (this.useProxies) {
  41254. markChanged(state);
  41255. } else {
  41256. markChangedES5(state);
  41257. }
  41258. };
  41259. return Immer;
  41260. }();
  41261. var immer = new Immer();
  41262. /**
  41263. * The `produce` function takes a value and a "recipe function" (whose
  41264. * return value often depends on the base state). The recipe function is
  41265. * free to mutate its first argument however it wants. All mutations are
  41266. * only ever applied to a __copy__ of the base state.
  41267. *
  41268. * Pass only a function to create a "curried producer" which relieves you
  41269. * from passing the recipe function every time.
  41270. *
  41271. * Only plain objects and arrays are made mutable. All other objects are
  41272. * considered uncopyable.
  41273. *
  41274. * Note: This function is __bound__ to its `Immer` instance.
  41275. *
  41276. * @param {any} base - the initial state
  41277. * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified
  41278. * @param {Function} patchListener - optional function that will be called with all the patches produced here
  41279. * @returns {any} a new state, or the initial state if nothing was modified
  41280. */
  41281. var produce = immer.produce;
  41282. /**
  41283. * Like `produce`, but `produceWithPatches` always returns a tuple
  41284. * [nextState, patches, inversePatches] (instead of just the next state)
  41285. */
  41286. var produceWithPatches = immer.produceWithPatches.bind(immer);
  41287. /**
  41288. * Pass true to automatically freeze all copies created by Immer.
  41289. *
  41290. * By default, auto-freezing is disabled in production.
  41291. */
  41292. var setAutoFreeze = immer.setAutoFreeze.bind(immer);
  41293. /**
  41294. * Pass true to use the ES2015 `Proxy` class when creating drafts, which is
  41295. * always faster than using ES5 proxies.
  41296. *
  41297. * By default, feature detection is used, so calling this is rarely necessary.
  41298. */
  41299. var setUseProxies = immer.setUseProxies.bind(immer);
  41300. /**
  41301. * Apply an array of Immer patches to the first argument.
  41302. *
  41303. * This function is a producer, which means copy-on-write is in effect.
  41304. */
  41305. var applyPatches$1 = immer.applyPatches.bind(immer);
  41306. /**
  41307. * Create an Immer draft from the given base state, which may be a draft itself.
  41308. * The draft can be modified until you finalize it with the `finishDraft` function.
  41309. */
  41310. var createDraft = immer.createDraft.bind(immer);
  41311. /**
  41312. * Finalize an Immer draft from a `createDraft` call, returning the base state
  41313. * (if no changes were made) or a modified copy. The draft must *not* be
  41314. * mutated afterwards.
  41315. *
  41316. * Pass a function as the 2nd argument to generate Immer patches based on the
  41317. * changes that were made.
  41318. */
  41319. var finishDraft = immer.finishDraft.bind(immer);
  41320. /**
  41321. * This function is actually a no-op, but can be used to cast an immutable type
  41322. * to an draft type and make TypeScript happy
  41323. *
  41324. * @param value
  41325. */
  41326. function castDraft(value) {
  41327. return value;
  41328. }
  41329. /**
  41330. * This function is actually a no-op, but can be used to cast a mutable type
  41331. * to an immutable type and make TypeScript happy
  41332. * @param value
  41333. */
  41334. function castImmutable(value) {
  41335. return value;
  41336. }
  41337. exports.Immer = Immer;
  41338. exports.applyPatches = applyPatches$1;
  41339. exports.castDraft = castDraft;
  41340. exports.castImmutable = castImmutable;
  41341. exports.createDraft = createDraft;
  41342. exports.default = produce;
  41343. exports.finishDraft = finishDraft;
  41344. exports.immerable = DRAFTABLE;
  41345. exports.isDraft = isDraft;
  41346. exports.isDraftable = isDraftable;
  41347. exports.nothing = NOTHING;
  41348. exports.original = original;
  41349. exports.produce = produce;
  41350. exports.produceWithPatches = produceWithPatches;
  41351. exports.setAutoFreeze = setAutoFreeze;
  41352. exports.setUseProxies = setUseProxies;
  41353. });
  41354. unwrapExports(immer_1);
  41355. var immer_2 = immer_1.Immer;
  41356. var immer_3 = immer_1.applyPatches;
  41357. var immer_4 = immer_1.castDraft;
  41358. var immer_5 = immer_1.castImmutable;
  41359. var immer_6 = immer_1.createDraft;
  41360. var immer_7 = immer_1.finishDraft;
  41361. var immer_8 = immer_1.immerable;
  41362. var immer_9 = immer_1.isDraft;
  41363. var immer_10 = immer_1.isDraftable;
  41364. var immer_11 = immer_1.nothing;
  41365. var immer_12 = immer_1.original;
  41366. var immer_13 = immer_1.produce;
  41367. var immer_14 = immer_1.produceWithPatches;
  41368. var immer_15 = immer_1.setAutoFreeze;
  41369. var immer_16 = immer_1.setUseProxies;
  41370. var esrever = createCommonjsModule(function (module, exports) {
  41371. (function(root) {
  41372. // Detect free variables `exports`
  41373. var freeExports = exports;
  41374. // Detect free variable `module`
  41375. var freeModule = module &&
  41376. module.exports == freeExports && module;
  41377. // Detect free variable `global`, from Node.js or Browserified code,
  41378. // and use it as `root`
  41379. var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal;
  41380. if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
  41381. root = freeGlobal;
  41382. }
  41383. /*--------------------------------------------------------------------------*/
  41384. var regexSymbolWithCombiningMarks = /([\0-\u02FF\u0370-\u1AAF\u1B00-\u1DBF\u1E00-\u20CF\u2100-\uD7FF\uE000-\uFE1F\uFE30-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])([\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]+)/g;
  41385. var regexSurrogatePair = /([\uD800-\uDBFF])([\uDC00-\uDFFF])/g;
  41386. var reverse = function(string) {
  41387. // Step 1: deal with combining marks and astral symbols (surrogate pairs)
  41388. string = string
  41389. // Swap symbols with their combining marks so the combining marks go first
  41390. .replace(regexSymbolWithCombiningMarks, function($0, $1, $2) {
  41391. // Reverse the combining marks so they will end up in the same order
  41392. // later on (after another round of reversing)
  41393. return reverse($2) + $1;
  41394. })
  41395. // Swap high and low surrogates so the low surrogates go first
  41396. .replace(regexSurrogatePair, '$2$1');
  41397. // Step 2: reverse the code units in the string
  41398. var result = '';
  41399. var index = string.length;
  41400. while (index--) {
  41401. result += string.charAt(index);
  41402. }
  41403. return result;
  41404. };
  41405. /*--------------------------------------------------------------------------*/
  41406. var esrever = {
  41407. 'version': '0.2.0',
  41408. 'reverse': reverse
  41409. };
  41410. // Some AMD build optimizers, like r.js, check for specific condition patterns
  41411. // like the following:
  41412. if (freeExports && !freeExports.nodeType) {
  41413. if (freeModule) { // in Node.js, io.js, or RingoJS v0.8.0+
  41414. freeModule.exports = esrever;
  41415. } else { // in Narwhal or RingoJS v0.7.0-
  41416. for (var key in esrever) {
  41417. esrever.hasOwnProperty(key) && (freeExports[key] = esrever[key]);
  41418. }
  41419. }
  41420. } else { // in Rhino or a web browser
  41421. root.esrever = esrever;
  41422. }
  41423. }(commonjsGlobal));
  41424. });
  41425. var dist$5 = createCommonjsModule(function (module, exports) {
  41426. Object.defineProperty(exports, '__esModule', { value: true });
  41427. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  41428. var isPlainObject = _interopDefault(index_cjs);
  41429. function _defineProperty(obj, key, value) {
  41430. if (key in obj) {
  41431. Object.defineProperty(obj, key, {
  41432. value: value,
  41433. enumerable: true,
  41434. configurable: true,
  41435. writable: true
  41436. });
  41437. } else {
  41438. obj[key] = value;
  41439. }
  41440. return obj;
  41441. }
  41442. var DIRTY_PATHS = new WeakMap();
  41443. var FLUSHING = new WeakMap();
  41444. var NORMALIZING = new WeakMap();
  41445. var PATH_REFS = new WeakMap();
  41446. var POINT_REFS = new WeakMap();
  41447. var RANGE_REFS = new WeakMap();
  41448. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  41449. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  41450. /**
  41451. * Create a new Slate `Editor` object.
  41452. */
  41453. var createEditor = () => {
  41454. var editor = {
  41455. children: [],
  41456. operations: [],
  41457. selection: null,
  41458. marks: null,
  41459. isInline: () => false,
  41460. isVoid: () => false,
  41461. onChange: () => {},
  41462. apply: op => {
  41463. for (var ref of Editor.pathRefs(editor)) {
  41464. PathRef.transform(ref, op);
  41465. }
  41466. for (var _ref of Editor.pointRefs(editor)) {
  41467. PointRef.transform(_ref, op);
  41468. }
  41469. for (var _ref2 of Editor.rangeRefs(editor)) {
  41470. RangeRef.transform(_ref2, op);
  41471. }
  41472. var set = new Set();
  41473. var dirtyPaths = [];
  41474. var add = path => {
  41475. if (path) {
  41476. var key = path.join(',');
  41477. if (!set.has(key)) {
  41478. set.add(key);
  41479. dirtyPaths.push(path);
  41480. }
  41481. }
  41482. };
  41483. var oldDirtyPaths = DIRTY_PATHS.get(editor) || [];
  41484. var newDirtyPaths = getDirtyPaths(op);
  41485. for (var path of oldDirtyPaths) {
  41486. var newPath = Path.transform(path, op);
  41487. add(newPath);
  41488. }
  41489. for (var _path of newDirtyPaths) {
  41490. add(_path);
  41491. }
  41492. DIRTY_PATHS.set(editor, dirtyPaths);
  41493. Editor.transform(editor, op);
  41494. editor.operations.push(op);
  41495. Editor.normalize(editor); // Clear any formats applied to the cursor if the selection changes.
  41496. if (op.type === 'set_selection') {
  41497. editor.marks = null;
  41498. }
  41499. if (!FLUSHING.get(editor)) {
  41500. FLUSHING.set(editor, true);
  41501. Promise.resolve().then(() => {
  41502. FLUSHING.set(editor, false);
  41503. editor.onChange();
  41504. editor.operations = [];
  41505. });
  41506. }
  41507. },
  41508. addMark: (key, value) => {
  41509. var {
  41510. selection
  41511. } = editor;
  41512. if (selection) {
  41513. if (Range.isExpanded(selection)) {
  41514. Transforms.setNodes(editor, {
  41515. [key]: value
  41516. }, {
  41517. match: Text.isText,
  41518. split: true
  41519. });
  41520. } else {
  41521. var marks = _objectSpread({}, Editor.marks(editor) || {}, {
  41522. [key]: value
  41523. });
  41524. editor.marks = marks;
  41525. editor.onChange();
  41526. }
  41527. }
  41528. },
  41529. deleteBackward: unit => {
  41530. var {
  41531. selection
  41532. } = editor;
  41533. if (selection && Range.isCollapsed(selection)) {
  41534. Transforms.delete(editor, {
  41535. unit,
  41536. reverse: true
  41537. });
  41538. }
  41539. },
  41540. deleteForward: unit => {
  41541. var {
  41542. selection
  41543. } = editor;
  41544. if (selection && Range.isCollapsed(selection)) {
  41545. Transforms.delete(editor, {
  41546. unit
  41547. });
  41548. }
  41549. },
  41550. deleteFragment: () => {
  41551. var {
  41552. selection
  41553. } = editor;
  41554. if (selection && Range.isExpanded(selection)) {
  41555. Transforms.delete(editor);
  41556. }
  41557. },
  41558. insertBreak: () => {
  41559. Transforms.splitNodes(editor, {
  41560. always: true
  41561. });
  41562. },
  41563. insertFragment: fragment => {
  41564. Transforms.insertFragment(editor, fragment);
  41565. },
  41566. insertNode: node => {
  41567. Transforms.insertNodes(editor, node);
  41568. },
  41569. insertText: text => {
  41570. var {
  41571. selection,
  41572. marks
  41573. } = editor;
  41574. if (selection) {
  41575. // If the cursor is at the end of an inline, move it outside of
  41576. // the inline before inserting
  41577. if (Range.isCollapsed(selection)) {
  41578. var inline = Editor.above(editor, {
  41579. match: n => Editor.isInline(editor, n),
  41580. mode: 'highest'
  41581. });
  41582. if (inline) {
  41583. var [, inlinePath] = inline;
  41584. if (Editor.isEnd(editor, selection.anchor, inlinePath)) {
  41585. var point = Editor.after(editor, inlinePath);
  41586. Transforms.setSelection(editor, {
  41587. anchor: point,
  41588. focus: point
  41589. });
  41590. }
  41591. }
  41592. }
  41593. if (marks) {
  41594. var node = _objectSpread({
  41595. text
  41596. }, marks);
  41597. Transforms.insertNodes(editor, node);
  41598. } else {
  41599. Transforms.insertText(editor, text);
  41600. }
  41601. editor.marks = null;
  41602. }
  41603. },
  41604. normalizeNode: entry => {
  41605. var [node, path] = entry; // There are no core normalizations for text nodes.
  41606. if (Text.isText(node)) {
  41607. return;
  41608. } // Ensure that block and inline nodes have at least one text child.
  41609. if (Element.isElement(node) && node.children.length === 0) {
  41610. var child = {
  41611. text: ''
  41612. };
  41613. Transforms.insertNodes(editor, child, {
  41614. at: path.concat(0),
  41615. voids: true
  41616. });
  41617. return;
  41618. } // Determine whether the node should have block or inline children.
  41619. var shouldHaveInlines = Editor.isEditor(node) ? false : Element.isElement(node) && (editor.isInline(node) || node.children.length === 0 || Text.isText(node.children[0]) || editor.isInline(node.children[0])); // Since we'll be applying operations while iterating, keep track of an
  41620. // index that accounts for any added/removed nodes.
  41621. var n = 0;
  41622. for (var i = 0; i < node.children.length; i++, n++) {
  41623. var _child = node.children[i];
  41624. var prev = node.children[i - 1];
  41625. var isLast = i === node.children.length - 1;
  41626. var isInlineOrText = Text.isText(_child) || Element.isElement(_child) && editor.isInline(_child); // Only allow block nodes in the top-level children and parent blocks
  41627. // that only contain block nodes. Similarly, only allow inline nodes in
  41628. // other inline nodes, or parent blocks that only contain inlines and
  41629. // text.
  41630. if (isInlineOrText !== shouldHaveInlines) {
  41631. Transforms.removeNodes(editor, {
  41632. at: path.concat(n),
  41633. voids: true
  41634. });
  41635. n--;
  41636. } else if (Element.isElement(_child)) {
  41637. // Ensure that inline nodes are surrounded by text nodes.
  41638. if (editor.isInline(_child)) {
  41639. if (prev == null || !Text.isText(prev)) {
  41640. var newChild = {
  41641. text: ''
  41642. };
  41643. Transforms.insertNodes(editor, newChild, {
  41644. at: path.concat(n),
  41645. voids: true
  41646. });
  41647. n++;
  41648. } else if (isLast) {
  41649. var _newChild = {
  41650. text: ''
  41651. };
  41652. Transforms.insertNodes(editor, _newChild, {
  41653. at: path.concat(n + 1),
  41654. voids: true
  41655. });
  41656. n++;
  41657. }
  41658. }
  41659. } else {
  41660. // Merge adjacent text nodes that are empty or match.
  41661. if (prev != null && Text.isText(prev)) {
  41662. if (Text.equals(_child, prev, {
  41663. loose: true
  41664. })) {
  41665. Transforms.mergeNodes(editor, {
  41666. at: path.concat(n),
  41667. voids: true
  41668. });
  41669. n--;
  41670. } else if (prev.text === '') {
  41671. Transforms.removeNodes(editor, {
  41672. at: path.concat(n - 1),
  41673. voids: true
  41674. });
  41675. n--;
  41676. } else if (isLast && _child.text === '') {
  41677. Transforms.removeNodes(editor, {
  41678. at: path.concat(n),
  41679. voids: true
  41680. });
  41681. n--;
  41682. }
  41683. }
  41684. }
  41685. }
  41686. },
  41687. removeMark: key => {
  41688. var {
  41689. selection
  41690. } = editor;
  41691. if (selection) {
  41692. if (Range.isExpanded(selection)) {
  41693. Transforms.unsetNodes(editor, key, {
  41694. match: Text.isText,
  41695. split: true
  41696. });
  41697. } else {
  41698. var marks = _objectSpread({}, Editor.marks(editor) || {});
  41699. delete marks[key];
  41700. editor.marks = marks;
  41701. editor.onChange();
  41702. }
  41703. }
  41704. }
  41705. };
  41706. return editor;
  41707. };
  41708. /**
  41709. * Get the "dirty" paths generated from an operation.
  41710. */
  41711. var getDirtyPaths = op => {
  41712. switch (op.type) {
  41713. case 'insert_text':
  41714. case 'remove_text':
  41715. case 'set_node':
  41716. {
  41717. var {
  41718. path
  41719. } = op;
  41720. return Path.levels(path);
  41721. }
  41722. case 'insert_node':
  41723. {
  41724. var {
  41725. node,
  41726. path: _path2
  41727. } = op;
  41728. var levels = Path.levels(_path2);
  41729. var descendants = Text.isText(node) ? [] : Array.from(Node.nodes(node), (_ref3) => {
  41730. var [, p] = _ref3;
  41731. return _path2.concat(p);
  41732. });
  41733. return [...levels, ...descendants];
  41734. }
  41735. case 'merge_node':
  41736. {
  41737. var {
  41738. path: _path3
  41739. } = op;
  41740. var ancestors = Path.ancestors(_path3);
  41741. var previousPath = Path.previous(_path3);
  41742. return [...ancestors, previousPath];
  41743. }
  41744. case 'move_node':
  41745. {
  41746. var {
  41747. path: _path4,
  41748. newPath
  41749. } = op;
  41750. if (Path.equals(_path4, newPath)) {
  41751. return [];
  41752. }
  41753. var oldAncestors = [];
  41754. var newAncestors = [];
  41755. for (var ancestor of Path.ancestors(_path4)) {
  41756. var p = Path.transform(ancestor, op);
  41757. oldAncestors.push(p);
  41758. }
  41759. for (var _ancestor of Path.ancestors(newPath)) {
  41760. var _p = Path.transform(_ancestor, op);
  41761. newAncestors.push(_p);
  41762. }
  41763. return [...oldAncestors, ...newAncestors];
  41764. }
  41765. case 'remove_node':
  41766. {
  41767. var {
  41768. path: _path5
  41769. } = op;
  41770. var _ancestors = Path.ancestors(_path5);
  41771. return [..._ancestors];
  41772. }
  41773. case 'split_node':
  41774. {
  41775. var {
  41776. path: _path6
  41777. } = op;
  41778. var _levels = Path.levels(_path6);
  41779. var nextPath = Path.next(_path6);
  41780. return [..._levels, nextPath];
  41781. }
  41782. default:
  41783. {
  41784. return [];
  41785. }
  41786. }
  41787. };
  41788. function _objectWithoutPropertiesLoose(source, excluded) {
  41789. if (source == null) return {};
  41790. var target = {};
  41791. var sourceKeys = Object.keys(source);
  41792. var key, i;
  41793. for (i = 0; i < sourceKeys.length; i++) {
  41794. key = sourceKeys[i];
  41795. if (excluded.indexOf(key) >= 0) continue;
  41796. target[key] = source[key];
  41797. }
  41798. return target;
  41799. }
  41800. function _objectWithoutProperties(source, excluded) {
  41801. if (source == null) return {};
  41802. var target = _objectWithoutPropertiesLoose(source, excluded);
  41803. var key, i;
  41804. if (Object.getOwnPropertySymbols) {
  41805. var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
  41806. for (i = 0; i < sourceSymbolKeys.length; i++) {
  41807. key = sourceSymbolKeys[i];
  41808. if (excluded.indexOf(key) >= 0) continue;
  41809. if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
  41810. target[key] = source[key];
  41811. }
  41812. }
  41813. return target;
  41814. }
  41815. /**
  41816. * Constants for string distance checking.
  41817. */
  41818. var SPACE = /\s/;
  41819. var PUNCTUATION = /[\u0021-\u0023\u0025-\u002A\u002C-\u002F\u003A\u003B\u003F\u0040\u005B-\u005D\u005F\u007B\u007D\u00A1\u00A7\u00AB\u00B6\u00B7\u00BB\u00BF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E3B\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]/;
  41820. var CHAMELEON = /['\u2018\u2019]/;
  41821. var SURROGATE_START = 0xd800;
  41822. var SURROGATE_END = 0xdfff;
  41823. var ZERO_WIDTH_JOINER = 0x200d;
  41824. /**
  41825. * Get the distance to the end of the first character in a string of text.
  41826. */
  41827. var getCharacterDistance = text => {
  41828. var offset = 0; // prev types:
  41829. // SURR: surrogate pair
  41830. // MOD: modifier (technically also surrogate pair)
  41831. // ZWJ: zero width joiner
  41832. // VAR: variation selector
  41833. // BMP: sequenceable character from basic multilingual plane
  41834. var prev = null;
  41835. var charCode = text.charCodeAt(0);
  41836. while (charCode) {
  41837. if (isSurrogate(charCode)) {
  41838. var modifier = isModifier(charCode, text, offset); // Early returns are the heart of this function, where we decide if previous and current
  41839. // codepoints should form a single character (in terms of how many of them should selection
  41840. // jump over).
  41841. if (prev === 'SURR' || prev === 'BMP') {
  41842. break;
  41843. }
  41844. offset += 2;
  41845. prev = modifier ? 'MOD' : 'SURR';
  41846. charCode = text.charCodeAt(offset); // Absolutely fine to `continue` without any checks because if `charCode` is NaN (which
  41847. // is the case when out of `text` range), next `while` loop won"t execute and we"re done.
  41848. continue;
  41849. }
  41850. if (charCode === ZERO_WIDTH_JOINER) {
  41851. offset += 1;
  41852. prev = 'ZWJ';
  41853. charCode = text.charCodeAt(offset);
  41854. continue;
  41855. }
  41856. if (isBMPEmoji(charCode)) {
  41857. if (prev && prev !== 'ZWJ' && prev !== 'VAR') {
  41858. break;
  41859. }
  41860. offset += 1;
  41861. prev = 'BMP';
  41862. charCode = text.charCodeAt(offset);
  41863. continue;
  41864. }
  41865. if (isVariationSelector(charCode)) {
  41866. if (prev && prev !== 'ZWJ') {
  41867. break;
  41868. }
  41869. offset += 1;
  41870. prev = 'VAR';
  41871. charCode = text.charCodeAt(offset);
  41872. continue;
  41873. } // Modifier 'groups up' with what ever character is before that (even whitespace), need to
  41874. // look ahead.
  41875. if (prev === 'MOD') {
  41876. offset += 1;
  41877. break;
  41878. } // If while loop ever gets here, we're done (e.g latin chars).
  41879. break;
  41880. }
  41881. return offset || 1;
  41882. };
  41883. /**
  41884. * Get the distance to the end of the first word in a string of text.
  41885. */
  41886. var getWordDistance = text => {
  41887. var length = 0;
  41888. var i = 0;
  41889. var started = false;
  41890. var char;
  41891. while (char = text.charAt(i)) {
  41892. var l = getCharacterDistance(char);
  41893. char = text.slice(i, i + l);
  41894. var rest = text.slice(i + l);
  41895. if (isWordCharacter(char, rest)) {
  41896. started = true;
  41897. length += l;
  41898. } else if (!started) {
  41899. length += l;
  41900. } else {
  41901. break;
  41902. }
  41903. i += l;
  41904. }
  41905. return length;
  41906. };
  41907. /**
  41908. * Check if a character is a word character. The `remaining` argument is used
  41909. * because sometimes you must read subsequent characters to truly determine it.
  41910. */
  41911. var isWordCharacter = (char, remaining) => {
  41912. if (SPACE.test(char)) {
  41913. return false;
  41914. } // Chameleons count as word characters as long as they're in a word, so
  41915. // recurse to see if the next one is a word character or not.
  41916. if (CHAMELEON.test(char)) {
  41917. var next = remaining.charAt(0);
  41918. var length = getCharacterDistance(next);
  41919. next = remaining.slice(0, length);
  41920. var rest = remaining.slice(length);
  41921. if (isWordCharacter(next, rest)) {
  41922. return true;
  41923. }
  41924. }
  41925. if (PUNCTUATION.test(char)) {
  41926. return false;
  41927. }
  41928. return true;
  41929. };
  41930. /**
  41931. * Determines if `code` is a surrogate
  41932. */
  41933. var isSurrogate = code => SURROGATE_START <= code && code <= SURROGATE_END;
  41934. /**
  41935. * Does `code` form Modifier with next one.
  41936. *
  41937. * https://emojipedia.org/modifiers/
  41938. */
  41939. var isModifier = (code, text, offset) => {
  41940. if (code === 0xd83c) {
  41941. var next = text.charCodeAt(offset + 1);
  41942. return next <= 0xdfff && next >= 0xdffb;
  41943. }
  41944. return false;
  41945. };
  41946. /**
  41947. * Is `code` a Variation Selector.
  41948. *
  41949. * https://codepoints.net/variation_selectors
  41950. */
  41951. var isVariationSelector = code => {
  41952. return code <= 0xfe0f && code >= 0xfe00;
  41953. };
  41954. /**
  41955. * Is `code` one of the BMP codes used in emoji sequences.
  41956. *
  41957. * https://emojipedia.org/emoji-zwj-sequences/
  41958. */
  41959. var isBMPEmoji = code => {
  41960. // This requires tiny bit of maintanance, better ideas?
  41961. // Fortunately it only happens if new Unicode Standard
  41962. // is released. Fails gracefully if upkeep lags behind,
  41963. // same way Slate previously behaved with all emojis.
  41964. return code === 0x2764 || // heart (❤)
  41965. code === 0x2642 || // male (♂)
  41966. code === 0x2640 || // female (♀)
  41967. code === 0x2620 || // scull (☠)
  41968. code === 0x2695 || // medical (⚕)
  41969. code === 0x2708 || // plane (✈️)
  41970. code === 0x25ef // large circle (◯)
  41971. ;
  41972. };
  41973. function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  41974. function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  41975. var Editor = {
  41976. /**
  41977. * Get the ancestor above a location in the document.
  41978. */
  41979. above(editor) {
  41980. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  41981. var {
  41982. voids = false,
  41983. mode = 'lowest',
  41984. at = editor.selection,
  41985. match
  41986. } = options;
  41987. if (!at) {
  41988. return;
  41989. }
  41990. var path = Editor.path(editor, at);
  41991. var reverse = mode === 'lowest';
  41992. for (var [n, p] of Editor.levels(editor, {
  41993. at: path,
  41994. voids,
  41995. match,
  41996. reverse
  41997. })) {
  41998. if (!Text.isText(n) && !Path.equals(path, p)) {
  41999. return [n, p];
  42000. }
  42001. }
  42002. },
  42003. /**
  42004. * Add a custom property to the leaf text nodes in the current selection.
  42005. *
  42006. * If the selection is currently collapsed, the marks will be added to the
  42007. * `editor.marks` property instead, and applied when text is inserted next.
  42008. */
  42009. addMark(editor, key, value) {
  42010. editor.addMark(key, value);
  42011. },
  42012. /**
  42013. * Get the point after a location.
  42014. */
  42015. after(editor, at) {
  42016. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  42017. var anchor = Editor.point(editor, at, {
  42018. edge: 'end'
  42019. });
  42020. var focus = Editor.end(editor, []);
  42021. var range = {
  42022. anchor,
  42023. focus
  42024. };
  42025. var {
  42026. distance = 1
  42027. } = options;
  42028. var d = 0;
  42029. var target;
  42030. for (var p of Editor.positions(editor, _objectSpread$1({}, options, {
  42031. at: range
  42032. }))) {
  42033. if (d > distance) {
  42034. break;
  42035. }
  42036. if (d !== 0) {
  42037. target = p;
  42038. }
  42039. d++;
  42040. }
  42041. return target;
  42042. },
  42043. /**
  42044. * Get the point before a location.
  42045. */
  42046. before(editor, at) {
  42047. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  42048. var anchor = Editor.start(editor, []);
  42049. var focus = Editor.point(editor, at, {
  42050. edge: 'start'
  42051. });
  42052. var range = {
  42053. anchor,
  42054. focus
  42055. };
  42056. var {
  42057. distance = 1
  42058. } = options;
  42059. var d = 0;
  42060. var target;
  42061. for (var p of Editor.positions(editor, _objectSpread$1({}, options, {
  42062. at: range,
  42063. reverse: true
  42064. }))) {
  42065. if (d > distance) {
  42066. break;
  42067. }
  42068. if (d !== 0) {
  42069. target = p;
  42070. }
  42071. d++;
  42072. }
  42073. return target;
  42074. },
  42075. /**
  42076. * Delete content in the editor backward from the current selection.
  42077. */
  42078. deleteBackward(editor) {
  42079. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  42080. var {
  42081. unit = 'character'
  42082. } = options;
  42083. editor.deleteBackward(unit);
  42084. },
  42085. /**
  42086. * Delete content in the editor forward from the current selection.
  42087. */
  42088. deleteForward(editor) {
  42089. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  42090. var {
  42091. unit = 'character'
  42092. } = options;
  42093. editor.deleteForward(unit);
  42094. },
  42095. /**
  42096. * Delete the content in the current selection.
  42097. */
  42098. deleteFragment(editor) {
  42099. editor.deleteFragment();
  42100. },
  42101. /**
  42102. * Get the start and end points of a location.
  42103. */
  42104. edges(editor, at) {
  42105. return [Editor.start(editor, at), Editor.end(editor, at)];
  42106. },
  42107. /**
  42108. * Get the end point of a location.
  42109. */
  42110. end(editor, at) {
  42111. return Editor.point(editor, at, {
  42112. edge: 'end'
  42113. });
  42114. },
  42115. /**
  42116. * Get the first node at a location.
  42117. */
  42118. first(editor, at) {
  42119. var path = Editor.path(editor, at, {
  42120. edge: 'start'
  42121. });
  42122. return Editor.node(editor, path);
  42123. },
  42124. /**
  42125. * Get the fragment at a location.
  42126. */
  42127. fragment(editor, at) {
  42128. var range = Editor.range(editor, at);
  42129. var fragment = Node.fragment(editor, range);
  42130. return fragment;
  42131. },
  42132. /**
  42133. * Check if a node has block children.
  42134. */
  42135. hasBlocks(editor, element) {
  42136. return element.children.some(n => Editor.isBlock(editor, n));
  42137. },
  42138. /**
  42139. * Check if a node has inline and text children.
  42140. */
  42141. hasInlines(editor, element) {
  42142. return element.children.some(n => Text.isText(n) || Editor.isInline(editor, n));
  42143. },
  42144. /**
  42145. * Check if a node has text children.
  42146. */
  42147. hasTexts(editor, element) {
  42148. return element.children.every(n => Text.isText(n));
  42149. },
  42150. /**
  42151. * Insert a block break at the current selection.
  42152. *
  42153. * If the selection is currently expanded, it will be deleted first.
  42154. */
  42155. insertBreak(editor) {
  42156. editor.insertBreak();
  42157. },
  42158. /**
  42159. * Insert a fragment at the current selection.
  42160. *
  42161. * If the selection is currently expanded, it will be deleted first.
  42162. */
  42163. insertFragment(editor, fragment) {
  42164. editor.insertFragment(fragment);
  42165. },
  42166. /**
  42167. * Insert a node at the current selection.
  42168. *
  42169. * If the selection is currently expanded, it will be deleted first.
  42170. */
  42171. insertNode(editor, node) {
  42172. editor.insertNode(node);
  42173. },
  42174. /**
  42175. * Insert text at the current selection.
  42176. *
  42177. * If the selection is currently expanded, it will be deleted first.
  42178. */
  42179. insertText(editor, text) {
  42180. editor.insertText(text);
  42181. },
  42182. /**
  42183. * Check if a value is a block `Element` object.
  42184. */
  42185. isBlock(editor, value) {
  42186. return Element.isElement(value) && !editor.isInline(value);
  42187. },
  42188. /**
  42189. * Check if a value is an `Editor` object.
  42190. */
  42191. isEditor(value) {
  42192. return isPlainObject(value) && typeof value.addMark === 'function' && typeof value.apply === 'function' && typeof value.deleteBackward === 'function' && typeof value.deleteForward === 'function' && typeof value.deleteFragment === 'function' && typeof value.insertBreak === 'function' && typeof value.insertFragment === 'function' && typeof value.insertNode === 'function' && typeof value.insertText === 'function' && typeof value.isInline === 'function' && typeof value.isVoid === 'function' && typeof value.normalizeNode === 'function' && typeof value.onChange === 'function' && typeof value.removeMark === 'function' && (value.marks === null || isPlainObject(value.marks)) && (value.selection === null || Range.isRange(value.selection)) && Node.isNodeList(value.children) && Operation.isOperationList(value.operations);
  42193. },
  42194. /**
  42195. * Check if a point is the end point of a location.
  42196. */
  42197. isEnd(editor, point, at) {
  42198. var end = Editor.end(editor, at);
  42199. return Point.equals(point, end);
  42200. },
  42201. /**
  42202. * Check if a point is an edge of a location.
  42203. */
  42204. isEdge(editor, point, at) {
  42205. return Editor.isStart(editor, point, at) || Editor.isEnd(editor, point, at);
  42206. },
  42207. /**
  42208. * Check if an element is empty, accounting for void nodes.
  42209. */
  42210. isEmpty(editor, element) {
  42211. var {
  42212. children
  42213. } = element;
  42214. var [first] = children;
  42215. return children.length === 0 || children.length === 1 && Text.isText(first) && first.text === '' && !editor.isVoid(element);
  42216. },
  42217. /**
  42218. * Check if a value is an inline `Element` object.
  42219. */
  42220. isInline(editor, value) {
  42221. return Element.isElement(value) && editor.isInline(value);
  42222. },
  42223. /**
  42224. * Check if the editor is currently normalizing after each operation.
  42225. */
  42226. isNormalizing(editor) {
  42227. var isNormalizing = NORMALIZING.get(editor);
  42228. return isNormalizing === undefined ? true : isNormalizing;
  42229. },
  42230. /**
  42231. * Check if a point is the start point of a location.
  42232. */
  42233. isStart(editor, point, at) {
  42234. // PERF: If the offset isn't `0` we know it's not the start.
  42235. if (point.offset !== 0) {
  42236. return false;
  42237. }
  42238. var start = Editor.start(editor, at);
  42239. return Point.equals(point, start);
  42240. },
  42241. /**
  42242. * Check if a value is a void `Element` object.
  42243. */
  42244. isVoid(editor, value) {
  42245. return Element.isElement(value) && editor.isVoid(value);
  42246. },
  42247. /**
  42248. * Get the last node at a location.
  42249. */
  42250. last(editor, at) {
  42251. var path = Editor.path(editor, at, {
  42252. edge: 'end'
  42253. });
  42254. return Editor.node(editor, path);
  42255. },
  42256. /**
  42257. * Get the leaf text node at a location.
  42258. */
  42259. leaf(editor, at) {
  42260. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  42261. var path = Editor.path(editor, at, options);
  42262. var node = Node.leaf(editor, path);
  42263. return [node, path];
  42264. },
  42265. /**
  42266. * Iterate through all of the levels at a location.
  42267. */
  42268. *levels(editor) {
  42269. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  42270. var {
  42271. at = editor.selection,
  42272. reverse = false,
  42273. voids = false
  42274. } = options;
  42275. var {
  42276. match
  42277. } = options;
  42278. if (match == null) {
  42279. match = () => true;
  42280. }
  42281. if (!at) {
  42282. return;
  42283. }
  42284. var levels = [];
  42285. var path = Editor.path(editor, at);
  42286. for (var [n, p] of Node.levels(editor, path)) {
  42287. if (!match(n)) {
  42288. continue;
  42289. }
  42290. levels.push([n, p]);
  42291. if (!voids && Editor.isVoid(editor, n)) {
  42292. break;
  42293. }
  42294. }
  42295. if (reverse) {
  42296. levels.reverse();
  42297. }
  42298. yield* levels;
  42299. },
  42300. /**
  42301. * Get the marks that would be added to text at the current selection.
  42302. */
  42303. marks(editor) {
  42304. var {
  42305. marks,
  42306. selection
  42307. } = editor;
  42308. if (!selection) {
  42309. return null;
  42310. }
  42311. if (marks) {
  42312. return marks;
  42313. }
  42314. if (Range.isExpanded(selection)) {
  42315. var [match] = Editor.nodes(editor, {
  42316. match: Text.isText
  42317. });
  42318. if (match) {
  42319. var [_node] = match;
  42320. var _rest = _objectWithoutProperties(_node, ["text"]);
  42321. return _rest;
  42322. } else {
  42323. return {};
  42324. }
  42325. }
  42326. var {
  42327. anchor
  42328. } = selection;
  42329. var {
  42330. path
  42331. } = anchor;
  42332. var [node] = Editor.leaf(editor, path);
  42333. if (anchor.offset === 0) {
  42334. var prev = Editor.previous(editor, {
  42335. at: path,
  42336. match: Text.isText
  42337. });
  42338. var block = Editor.above(editor, {
  42339. match: n => Editor.isBlock(editor, n)
  42340. });
  42341. if (prev && block) {
  42342. var [prevNode, prevPath] = prev;
  42343. var [, blockPath] = block;
  42344. if (Path.isAncestor(blockPath, prevPath)) {
  42345. node = prevNode;
  42346. }
  42347. }
  42348. }
  42349. var rest = _objectWithoutProperties(node, ["text"]);
  42350. return rest;
  42351. },
  42352. /**
  42353. * Get the matching node in the branch of the document after a location.
  42354. */
  42355. next(editor) {
  42356. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  42357. var {
  42358. mode = 'lowest',
  42359. voids = false
  42360. } = options;
  42361. var {
  42362. match,
  42363. at = editor.selection
  42364. } = options;
  42365. if (!at) {
  42366. return;
  42367. }
  42368. var [, from] = Editor.last(editor, at);
  42369. var [, to] = Editor.last(editor, []);
  42370. var span = [from, to];
  42371. if (Path.isPath(at) && at.length === 0) {
  42372. throw new Error("Cannot get the next node from the root node!");
  42373. }
  42374. if (match == null) {
  42375. if (Path.isPath(at)) {
  42376. var [parent] = Editor.parent(editor, at);
  42377. match = n => parent.children.includes(n);
  42378. } else {
  42379. match = () => true;
  42380. }
  42381. }
  42382. var [, next] = Editor.nodes(editor, {
  42383. at: span,
  42384. match,
  42385. mode,
  42386. voids
  42387. });
  42388. return next;
  42389. },
  42390. /**
  42391. * Get the node at a location.
  42392. */
  42393. node(editor, at) {
  42394. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  42395. var path = Editor.path(editor, at, options);
  42396. var node = Node.get(editor, path);
  42397. return [node, path];
  42398. },
  42399. /**
  42400. * Iterate through all of the nodes in the Editor.
  42401. */
  42402. *nodes(editor) {
  42403. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  42404. var {
  42405. at = editor.selection,
  42406. mode = 'all',
  42407. universal = false,
  42408. reverse = false,
  42409. voids = false
  42410. } = options;
  42411. var {
  42412. match
  42413. } = options;
  42414. if (!match) {
  42415. match = () => true;
  42416. }
  42417. if (!at) {
  42418. return;
  42419. }
  42420. var from;
  42421. var to;
  42422. if (Span.isSpan(at)) {
  42423. from = at[0];
  42424. to = at[1];
  42425. } else {
  42426. var first = Editor.path(editor, at, {
  42427. edge: 'start'
  42428. });
  42429. var last = Editor.path(editor, at, {
  42430. edge: 'end'
  42431. });
  42432. from = reverse ? last : first;
  42433. to = reverse ? first : last;
  42434. }
  42435. var iterable = Node.nodes(editor, {
  42436. reverse,
  42437. from,
  42438. to,
  42439. pass: (_ref) => {
  42440. var [n] = _ref;
  42441. return voids ? false : Editor.isVoid(editor, n);
  42442. }
  42443. });
  42444. var matches = [];
  42445. var hit;
  42446. for (var [node, path] of iterable) {
  42447. var isLower = hit && Path.compare(path, hit[1]) === 0; // In highest mode any node lower than the last hit is not a match.
  42448. if (mode === 'highest' && isLower) {
  42449. continue;
  42450. }
  42451. if (!match(node)) {
  42452. // If we've arrived at a leaf text node that is not lower than the last
  42453. // hit, then we've found a branch that doesn't include a match, which
  42454. // means the match is not universal.
  42455. if (universal && !isLower && Text.isText(node)) {
  42456. return;
  42457. } else {
  42458. continue;
  42459. }
  42460. } // If there's a match and it's lower than the last, update the hit.
  42461. if (mode === 'lowest' && isLower) {
  42462. hit = [node, path];
  42463. continue;
  42464. } // In lowest mode we emit the last hit, once it's guaranteed lowest.
  42465. var emit = mode === 'lowest' ? hit : [node, path];
  42466. if (emit) {
  42467. if (universal) {
  42468. matches.push(emit);
  42469. } else {
  42470. yield emit;
  42471. }
  42472. }
  42473. hit = [node, path];
  42474. } // Since lowest is always emitting one behind, catch up at the end.
  42475. if (mode === 'lowest' && hit) {
  42476. if (universal) {
  42477. matches.push(hit);
  42478. } else {
  42479. yield hit;
  42480. }
  42481. } // Universal defers to ensure that the match occurs in every branch, so we
  42482. // yield all of the matches after iterating.
  42483. if (universal) {
  42484. yield* matches;
  42485. }
  42486. },
  42487. /**
  42488. * Normalize any dirty objects in the editor.
  42489. */
  42490. normalize(editor) {
  42491. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  42492. var {
  42493. force = false
  42494. } = options;
  42495. var getDirtyPaths = editor => {
  42496. return DIRTY_PATHS.get(editor) || [];
  42497. };
  42498. if (!Editor.isNormalizing(editor)) {
  42499. return;
  42500. }
  42501. if (force) {
  42502. var allPaths = Array.from(Node.nodes(editor), (_ref2) => {
  42503. var [, p] = _ref2;
  42504. return p;
  42505. });
  42506. DIRTY_PATHS.set(editor, allPaths);
  42507. }
  42508. if (getDirtyPaths(editor).length === 0) {
  42509. return;
  42510. }
  42511. Editor.withoutNormalizing(editor, () => {
  42512. var max = getDirtyPaths(editor).length * 42; // HACK: better way?
  42513. var m = 0;
  42514. while (getDirtyPaths(editor).length !== 0) {
  42515. if (m > max) {
  42516. throw new Error("\n Could not completely normalize the editor after ".concat(max, " iterations! This is usually due to incorrect normalization logic that leaves a node in an invalid state.\n "));
  42517. }
  42518. var path = getDirtyPaths(editor).pop();
  42519. var entry = Editor.node(editor, path);
  42520. editor.normalizeNode(entry);
  42521. m++;
  42522. }
  42523. });
  42524. },
  42525. /**
  42526. * Get the parent node of a location.
  42527. */
  42528. parent(editor, at) {
  42529. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  42530. var path = Editor.path(editor, at, options);
  42531. var parentPath = Path.parent(path);
  42532. var entry = Editor.node(editor, parentPath);
  42533. return entry;
  42534. },
  42535. /**
  42536. * Get the path of a location.
  42537. */
  42538. path(editor, at) {
  42539. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  42540. var {
  42541. depth,
  42542. edge
  42543. } = options;
  42544. if (Path.isPath(at)) {
  42545. if (edge === 'start') {
  42546. var [, firstPath] = Node.first(editor, at);
  42547. at = firstPath;
  42548. } else if (edge === 'end') {
  42549. var [, lastPath] = Node.last(editor, at);
  42550. at = lastPath;
  42551. }
  42552. }
  42553. if (Range.isRange(at)) {
  42554. if (edge === 'start') {
  42555. at = Range.start(at);
  42556. } else if (edge === 'end') {
  42557. at = Range.end(at);
  42558. } else {
  42559. at = Path.common(at.anchor.path, at.focus.path);
  42560. }
  42561. }
  42562. if (Point.isPoint(at)) {
  42563. at = at.path;
  42564. }
  42565. if (depth != null) {
  42566. at = at.slice(0, depth);
  42567. }
  42568. return at;
  42569. },
  42570. /**
  42571. * Create a mutable ref for a `Path` object, which will stay in sync as new
  42572. * operations are applied to the editor.
  42573. */
  42574. pathRef(editor, path) {
  42575. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  42576. var {
  42577. affinity = 'forward'
  42578. } = options;
  42579. var ref = {
  42580. current: path,
  42581. affinity,
  42582. unref() {
  42583. var {
  42584. current
  42585. } = ref;
  42586. var pathRefs = Editor.pathRefs(editor);
  42587. pathRefs.delete(ref);
  42588. ref.current = null;
  42589. return current;
  42590. }
  42591. };
  42592. var refs = Editor.pathRefs(editor);
  42593. refs.add(ref);
  42594. return ref;
  42595. },
  42596. /**
  42597. * Get the set of currently tracked path refs of the editor.
  42598. */
  42599. pathRefs(editor) {
  42600. var refs = PATH_REFS.get(editor);
  42601. if (!refs) {
  42602. refs = new Set();
  42603. PATH_REFS.set(editor, refs);
  42604. }
  42605. return refs;
  42606. },
  42607. /**
  42608. * Get the start or end point of a location.
  42609. */
  42610. point(editor, at) {
  42611. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  42612. var {
  42613. edge = 'start'
  42614. } = options;
  42615. if (Path.isPath(at)) {
  42616. var path;
  42617. if (edge === 'end') {
  42618. var [, lastPath] = Node.last(editor, at);
  42619. path = lastPath;
  42620. } else {
  42621. var [, firstPath] = Node.first(editor, at);
  42622. path = firstPath;
  42623. }
  42624. var node = Node.get(editor, path);
  42625. if (!Text.isText(node)) {
  42626. throw new Error("Cannot get the ".concat(edge, " point in the node at path [").concat(at, "] because it has no ").concat(edge, " text node."));
  42627. }
  42628. return {
  42629. path,
  42630. offset: edge === 'end' ? node.text.length : 0
  42631. };
  42632. }
  42633. if (Range.isRange(at)) {
  42634. var [start, end] = Range.edges(at);
  42635. return edge === 'start' ? start : end;
  42636. }
  42637. return at;
  42638. },
  42639. /**
  42640. * Create a mutable ref for a `Point` object, which will stay in sync as new
  42641. * operations are applied to the editor.
  42642. */
  42643. pointRef(editor, point) {
  42644. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  42645. var {
  42646. affinity = 'forward'
  42647. } = options;
  42648. var ref = {
  42649. current: point,
  42650. affinity,
  42651. unref() {
  42652. var {
  42653. current
  42654. } = ref;
  42655. var pointRefs = Editor.pointRefs(editor);
  42656. pointRefs.delete(ref);
  42657. ref.current = null;
  42658. return current;
  42659. }
  42660. };
  42661. var refs = Editor.pointRefs(editor);
  42662. refs.add(ref);
  42663. return ref;
  42664. },
  42665. /**
  42666. * Get the set of currently tracked point refs of the editor.
  42667. */
  42668. pointRefs(editor) {
  42669. var refs = POINT_REFS.get(editor);
  42670. if (!refs) {
  42671. refs = new Set();
  42672. POINT_REFS.set(editor, refs);
  42673. }
  42674. return refs;
  42675. },
  42676. /**
  42677. * Iterate through all of the positions in the document where a `Point` can be
  42678. * placed.
  42679. *
  42680. * By default it will move forward by individual offsets at a time, but you
  42681. * can pass the `unit: 'character'` option to moved forward one character, word,
  42682. * or line at at time.
  42683. *
  42684. * Note: void nodes are treated as a single point, and iteration will not
  42685. * happen inside their content.
  42686. */
  42687. *positions(editor) {
  42688. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  42689. var {
  42690. at = editor.selection,
  42691. unit = 'offset',
  42692. reverse = false
  42693. } = options;
  42694. if (!at) {
  42695. return;
  42696. }
  42697. var range = Editor.range(editor, at);
  42698. var [start, end] = Range.edges(range);
  42699. var first = reverse ? end : start;
  42700. var string = '';
  42701. var available = 0;
  42702. var offset = 0;
  42703. var distance = null;
  42704. var isNewBlock = false;
  42705. var advance = () => {
  42706. if (distance == null) {
  42707. if (unit === 'character') {
  42708. distance = getCharacterDistance(string);
  42709. } else if (unit === 'word') {
  42710. distance = getWordDistance(string);
  42711. } else if (unit === 'line' || unit === 'block') {
  42712. distance = string.length;
  42713. } else {
  42714. distance = 1;
  42715. }
  42716. string = string.slice(distance);
  42717. } // Add or substract the offset.
  42718. offset = reverse ? offset - distance : offset + distance; // Subtract the distance traveled from the available text.
  42719. available = available - distance; // If the available had room to spare, reset the distance so that it will
  42720. // advance again next time. Otherwise, set it to the overflow amount.
  42721. distance = available >= 0 ? null : 0 - available;
  42722. };
  42723. for (var [node, path] of Editor.nodes(editor, {
  42724. at,
  42725. reverse
  42726. })) {
  42727. if (Element.isElement(node)) {
  42728. // Void nodes are a special case, since we don't want to iterate over
  42729. // their content. We instead always just yield their first point.
  42730. if (editor.isVoid(node)) {
  42731. yield Editor.start(editor, path);
  42732. continue;
  42733. }
  42734. if (editor.isInline(node)) {
  42735. continue;
  42736. }
  42737. if (Editor.hasInlines(editor, node)) {
  42738. var e = Path.isAncestor(path, end.path) ? end : Editor.end(editor, path);
  42739. var s = Path.isAncestor(path, start.path) ? start : Editor.start(editor, path);
  42740. var text = Editor.string(editor, {
  42741. anchor: s,
  42742. focus: e
  42743. });
  42744. string = reverse ? esrever.reverse(text) : text;
  42745. isNewBlock = true;
  42746. }
  42747. }
  42748. if (Text.isText(node)) {
  42749. var isFirst = Path.equals(path, first.path);
  42750. available = node.text.length;
  42751. offset = reverse ? available : 0;
  42752. if (isFirst) {
  42753. available = reverse ? first.offset : available - first.offset;
  42754. offset = first.offset;
  42755. }
  42756. if (isFirst || isNewBlock || unit === 'offset') {
  42757. yield {
  42758. path,
  42759. offset
  42760. };
  42761. }
  42762. while (true) {
  42763. // If there's no more string, continue to the next block.
  42764. if (string === '') {
  42765. break;
  42766. } else {
  42767. advance();
  42768. } // If the available space hasn't overflow, we have another point to
  42769. // yield in the current text node.
  42770. if (available >= 0) {
  42771. yield {
  42772. path,
  42773. offset
  42774. };
  42775. } else {
  42776. break;
  42777. }
  42778. }
  42779. isNewBlock = false;
  42780. }
  42781. }
  42782. },
  42783. /**
  42784. * Get the matching node in the branch of the document before a location.
  42785. */
  42786. previous(editor) {
  42787. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  42788. var {
  42789. mode = 'lowest',
  42790. voids = false
  42791. } = options;
  42792. var {
  42793. match,
  42794. at = editor.selection
  42795. } = options;
  42796. if (!at) {
  42797. return;
  42798. }
  42799. var [, from] = Editor.first(editor, at);
  42800. var [, to] = Editor.first(editor, []);
  42801. var span = [from, to];
  42802. if (Path.isPath(at) && at.length === 0) {
  42803. throw new Error("Cannot get the previous node from the root node!");
  42804. }
  42805. if (match == null) {
  42806. if (Path.isPath(at)) {
  42807. var [parent] = Editor.parent(editor, at);
  42808. match = n => parent.children.includes(n);
  42809. } else {
  42810. match = () => true;
  42811. }
  42812. }
  42813. var [, previous] = Editor.nodes(editor, {
  42814. reverse: true,
  42815. at: span,
  42816. match,
  42817. mode,
  42818. voids
  42819. });
  42820. return previous;
  42821. },
  42822. /**
  42823. * Get a range of a location.
  42824. */
  42825. range(editor, at, to) {
  42826. if (Range.isRange(at) && !to) {
  42827. return at;
  42828. }
  42829. var start = Editor.start(editor, at);
  42830. var end = Editor.end(editor, to || at);
  42831. return {
  42832. anchor: start,
  42833. focus: end
  42834. };
  42835. },
  42836. /**
  42837. * Create a mutable ref for a `Range` object, which will stay in sync as new
  42838. * operations are applied to the editor.
  42839. */
  42840. rangeRef(editor, range) {
  42841. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  42842. var {
  42843. affinity = 'forward'
  42844. } = options;
  42845. var ref = {
  42846. current: range,
  42847. affinity,
  42848. unref() {
  42849. var {
  42850. current
  42851. } = ref;
  42852. var rangeRefs = Editor.rangeRefs(editor);
  42853. rangeRefs.delete(ref);
  42854. ref.current = null;
  42855. return current;
  42856. }
  42857. };
  42858. var refs = Editor.rangeRefs(editor);
  42859. refs.add(ref);
  42860. return ref;
  42861. },
  42862. /**
  42863. * Get the set of currently tracked range refs of the editor.
  42864. */
  42865. rangeRefs(editor) {
  42866. var refs = RANGE_REFS.get(editor);
  42867. if (!refs) {
  42868. refs = new Set();
  42869. RANGE_REFS.set(editor, refs);
  42870. }
  42871. return refs;
  42872. },
  42873. /**
  42874. * Remove a custom property from all of the leaf text nodes in the current
  42875. * selection.
  42876. *
  42877. * If the selection is currently collapsed, the removal will be stored on
  42878. * `editor.marks` and applied to the text inserted next.
  42879. */
  42880. removeMark(editor, key) {
  42881. editor.removeMark(key);
  42882. },
  42883. /**
  42884. * Get the start point of a location.
  42885. */
  42886. start(editor, at) {
  42887. return Editor.point(editor, at, {
  42888. edge: 'start'
  42889. });
  42890. },
  42891. /**
  42892. * Get the text string content of a location.
  42893. *
  42894. * Note: the text of void nodes is presumed to be an empty string, regardless
  42895. * of what their actual content is.
  42896. */
  42897. string(editor, at) {
  42898. var range = Editor.range(editor, at);
  42899. var [start, end] = Range.edges(range);
  42900. var text = '';
  42901. for (var [node, path] of Editor.nodes(editor, {
  42902. at: range,
  42903. match: Text.isText
  42904. })) {
  42905. var t = node.text;
  42906. if (Path.equals(path, end.path)) {
  42907. t = t.slice(0, end.offset);
  42908. }
  42909. if (Path.equals(path, start.path)) {
  42910. t = t.slice(start.offset);
  42911. }
  42912. text += t;
  42913. }
  42914. return text;
  42915. },
  42916. /**
  42917. * Transform the editor by an operation.
  42918. */
  42919. transform(editor, op) {
  42920. editor.children = immer_1.createDraft(editor.children);
  42921. var selection = editor.selection && immer_1.createDraft(editor.selection);
  42922. switch (op.type) {
  42923. case 'insert_node':
  42924. {
  42925. var {
  42926. path,
  42927. node
  42928. } = op;
  42929. var parent = Node.parent(editor, path);
  42930. var index = path[path.length - 1];
  42931. parent.children.splice(index, 0, node);
  42932. if (selection) {
  42933. for (var [point, key] of Range.points(selection)) {
  42934. selection[key] = Point.transform(point, op);
  42935. }
  42936. }
  42937. break;
  42938. }
  42939. case 'insert_text':
  42940. {
  42941. var {
  42942. path: _path,
  42943. offset,
  42944. text
  42945. } = op;
  42946. var _node2 = Node.leaf(editor, _path);
  42947. var before = _node2.text.slice(0, offset);
  42948. var after = _node2.text.slice(offset);
  42949. _node2.text = before + text + after;
  42950. if (selection) {
  42951. for (var [_point, _key] of Range.points(selection)) {
  42952. selection[_key] = Point.transform(_point, op);
  42953. }
  42954. }
  42955. break;
  42956. }
  42957. case 'merge_node':
  42958. {
  42959. var {
  42960. path: _path2
  42961. } = op;
  42962. var _node3 = Node.get(editor, _path2);
  42963. var prevPath = Path.previous(_path2);
  42964. var prev = Node.get(editor, prevPath);
  42965. var _parent = Node.parent(editor, _path2);
  42966. var _index = _path2[_path2.length - 1];
  42967. if (Text.isText(_node3) && Text.isText(prev)) {
  42968. prev.text += _node3.text;
  42969. } else if (!Text.isText(_node3) && !Text.isText(prev)) {
  42970. prev.children.push(..._node3.children);
  42971. } else {
  42972. throw new Error("Cannot apply a \"merge_node\" operation at path [".concat(_path2, "] to nodes of different interaces: ").concat(_node3, " ").concat(prev));
  42973. }
  42974. _parent.children.splice(_index, 1);
  42975. if (selection) {
  42976. for (var [_point2, _key2] of Range.points(selection)) {
  42977. selection[_key2] = Point.transform(_point2, op);
  42978. }
  42979. }
  42980. break;
  42981. }
  42982. case 'move_node':
  42983. {
  42984. var {
  42985. path: _path3,
  42986. newPath
  42987. } = op;
  42988. if (Path.isAncestor(_path3, newPath)) {
  42989. throw new Error("Cannot move a path [".concat(_path3, "] to new path [").concat(newPath, "] because the destination is inside itself."));
  42990. }
  42991. var _node4 = Node.get(editor, _path3);
  42992. var _parent2 = Node.parent(editor, _path3);
  42993. var _index2 = _path3[_path3.length - 1]; // This is tricky, but since the `path` and `newPath` both refer to
  42994. // the same snapshot in time, there's a mismatch. After either
  42995. // removing the original position, the second step's path can be out
  42996. // of date. So instead of using the `op.newPath` directly, we
  42997. // transform `op.path` to ascertain what the `newPath` would be after
  42998. // the operation was applied.
  42999. _parent2.children.splice(_index2, 1);
  43000. var truePath = Path.transform(_path3, op);
  43001. var newParent = Node.get(editor, Path.parent(truePath));
  43002. var newIndex = truePath[truePath.length - 1];
  43003. newParent.children.splice(newIndex, 0, _node4);
  43004. if (selection) {
  43005. for (var [_point3, _key3] of Range.points(selection)) {
  43006. selection[_key3] = Point.transform(_point3, op);
  43007. }
  43008. }
  43009. break;
  43010. }
  43011. case 'remove_node':
  43012. {
  43013. var {
  43014. path: _path4
  43015. } = op;
  43016. var _index3 = _path4[_path4.length - 1];
  43017. var _parent3 = Node.parent(editor, _path4);
  43018. _parent3.children.splice(_index3, 1); // Transform all of the points in the value, but if the point was in the
  43019. // node that was removed we need to update the range or remove it.
  43020. if (selection) {
  43021. for (var [_point4, _key4] of Range.points(selection)) {
  43022. var result = Point.transform(_point4, op);
  43023. if (selection != null && result != null) {
  43024. selection[_key4] = result;
  43025. } else {
  43026. var _prev = void 0;
  43027. var next = void 0;
  43028. for (var [n, p] of Node.texts(editor)) {
  43029. if (Path.compare(p, _path4) === -1) {
  43030. _prev = [n, p];
  43031. } else {
  43032. next = [n, p];
  43033. break;
  43034. }
  43035. }
  43036. if (_prev) {
  43037. _point4.path = _prev[1];
  43038. _point4.offset = _prev[0].text.length;
  43039. } else if (next) {
  43040. _point4.path = next[1];
  43041. _point4.offset = 0;
  43042. } else {
  43043. selection = null;
  43044. }
  43045. }
  43046. }
  43047. }
  43048. break;
  43049. }
  43050. case 'remove_text':
  43051. {
  43052. var {
  43053. path: _path5,
  43054. offset: _offset,
  43055. text: _text2
  43056. } = op;
  43057. var _node5 = Node.leaf(editor, _path5);
  43058. var _before = _node5.text.slice(0, _offset);
  43059. var _after = _node5.text.slice(_offset + _text2.length);
  43060. _node5.text = _before + _after;
  43061. if (selection) {
  43062. for (var [_point5, _key5] of Range.points(selection)) {
  43063. selection[_key5] = Point.transform(_point5, op);
  43064. }
  43065. }
  43066. break;
  43067. }
  43068. case 'set_node':
  43069. {
  43070. var {
  43071. path: _path6,
  43072. newProperties
  43073. } = op;
  43074. if (_path6.length === 0) {
  43075. throw new Error("Cannot set properties on the root node!");
  43076. }
  43077. var _node6 = Node.get(editor, _path6);
  43078. for (var _key6 in newProperties) {
  43079. if (_key6 === 'children' || _key6 === 'text') {
  43080. throw new Error("Cannot set the \"".concat(_key6, "\" property of nodes!"));
  43081. }
  43082. var value = newProperties[_key6];
  43083. if (value == null) {
  43084. delete _node6[_key6];
  43085. } else {
  43086. _node6[_key6] = value;
  43087. }
  43088. }
  43089. break;
  43090. }
  43091. case 'set_selection':
  43092. {
  43093. var {
  43094. newProperties: _newProperties
  43095. } = op;
  43096. if (_newProperties == null) {
  43097. selection = _newProperties;
  43098. } else if (selection == null) {
  43099. if (!Range.isRange(_newProperties)) {
  43100. throw new Error("Cannot apply an incomplete \"set_selection\" operation properties ".concat(JSON.stringify(_newProperties), " when there is no current selection."));
  43101. }
  43102. selection = _newProperties;
  43103. } else {
  43104. Object.assign(selection, _newProperties);
  43105. }
  43106. break;
  43107. }
  43108. case 'split_node':
  43109. {
  43110. var {
  43111. path: _path7,
  43112. position,
  43113. properties
  43114. } = op;
  43115. if (_path7.length === 0) {
  43116. throw new Error("Cannot apply a \"split_node\" operation at path [".concat(_path7, "] because the root node cannot be split."));
  43117. }
  43118. var _node7 = Node.get(editor, _path7);
  43119. var _parent4 = Node.parent(editor, _path7);
  43120. var _index4 = _path7[_path7.length - 1];
  43121. var newNode;
  43122. if (Text.isText(_node7)) {
  43123. var _before2 = _node7.text.slice(0, position);
  43124. var _after2 = _node7.text.slice(position);
  43125. _node7.text = _before2;
  43126. newNode = _objectSpread$1({}, _node7, {}, properties, {
  43127. text: _after2
  43128. });
  43129. } else {
  43130. var _before3 = _node7.children.slice(0, position);
  43131. var _after3 = _node7.children.slice(position);
  43132. _node7.children = _before3;
  43133. newNode = _objectSpread$1({}, _node7, {}, properties, {
  43134. children: _after3
  43135. });
  43136. }
  43137. _parent4.children.splice(_index4 + 1, 0, newNode);
  43138. if (selection) {
  43139. for (var [_point6, _key7] of Range.points(selection)) {
  43140. selection[_key7] = Point.transform(_point6, op);
  43141. }
  43142. }
  43143. break;
  43144. }
  43145. }
  43146. editor.children = immer_1.finishDraft(editor.children);
  43147. if (selection) {
  43148. editor.selection = immer_1.isDraft(selection) ? immer_1.finishDraft(selection) : selection;
  43149. } else {
  43150. editor.selection = null;
  43151. }
  43152. },
  43153. /**
  43154. * Convert a range into a non-hanging one.
  43155. */
  43156. unhangRange(editor, range) {
  43157. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  43158. var {
  43159. voids = false
  43160. } = options;
  43161. var [start, end] = Range.edges(range); // PERF: exit early if we can guarantee that the range isn't hanging.
  43162. if (start.offset !== 0 || end.offset !== 0 || Range.isCollapsed(range)) {
  43163. return range;
  43164. }
  43165. var endBlock = Editor.above(editor, {
  43166. at: end,
  43167. match: n => Editor.isBlock(editor, n)
  43168. });
  43169. var blockPath = endBlock ? endBlock[1] : [];
  43170. var first = Editor.start(editor, []);
  43171. var before = {
  43172. anchor: first,
  43173. focus: end
  43174. };
  43175. var skip = true;
  43176. for (var [node, path] of Editor.nodes(editor, {
  43177. at: before,
  43178. match: Text.isText,
  43179. reverse: true,
  43180. voids
  43181. })) {
  43182. if (skip) {
  43183. skip = false;
  43184. continue;
  43185. }
  43186. if (node.text !== '' || Path.isBefore(path, blockPath)) {
  43187. end = {
  43188. path,
  43189. offset: node.text.length
  43190. };
  43191. break;
  43192. }
  43193. }
  43194. return {
  43195. anchor: start,
  43196. focus: end
  43197. };
  43198. },
  43199. /**
  43200. * Match a void node in the current branch of the editor.
  43201. */
  43202. void(editor) {
  43203. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  43204. return Editor.above(editor, _objectSpread$1({}, options, {
  43205. match: n => Editor.isVoid(editor, n)
  43206. }));
  43207. },
  43208. /**
  43209. * Call a function, deferring normalization until after it completes.
  43210. */
  43211. withoutNormalizing(editor, fn) {
  43212. var value = Editor.isNormalizing(editor);
  43213. NORMALIZING.set(editor, false);
  43214. fn();
  43215. NORMALIZING.set(editor, value);
  43216. Editor.normalize(editor);
  43217. }
  43218. };
  43219. var Element = {
  43220. /**
  43221. * Check if a value implements the `Element` interface.
  43222. */
  43223. isElement(value) {
  43224. return isPlainObject(value) && Node.isNodeList(value.children) && !Editor.isEditor(value);
  43225. },
  43226. /**
  43227. * Check if a value is an array of `Element` objects.
  43228. */
  43229. isElementList(value) {
  43230. return Array.isArray(value) && (value.length === 0 || Element.isElement(value[0]));
  43231. },
  43232. /**
  43233. * Check if an element matches set of properties.
  43234. *
  43235. * Note: this checks custom properties, and it does not ensure that any
  43236. * children are equivalent.
  43237. */
  43238. matches(element, props) {
  43239. for (var key in props) {
  43240. if (key === 'children') {
  43241. continue;
  43242. }
  43243. if (element[key] !== props[key]) {
  43244. return false;
  43245. }
  43246. }
  43247. return true;
  43248. }
  43249. };
  43250. var Location = {
  43251. /**
  43252. * Check if a value implements the `Location` interface.
  43253. */
  43254. isLocation(value) {
  43255. return Path.isPath(value) || Point.isPoint(value) || Range.isRange(value);
  43256. }
  43257. };
  43258. var Span = {
  43259. /**
  43260. * Check if a value implements the `Span` interface.
  43261. */
  43262. isSpan(value) {
  43263. return Array.isArray(value) && value.length === 2 && value.every(Path.isPath);
  43264. }
  43265. };
  43266. var Node = {
  43267. /**
  43268. * Get the node at a specific path, asserting that it's an ancestor node.
  43269. */
  43270. ancestor(root, path) {
  43271. var node = Node.get(root, path);
  43272. if (Text.isText(node)) {
  43273. throw new Error("Cannot get the ancestor node at path [".concat(path, "] because it refers to a text node instead: ").concat(node));
  43274. }
  43275. return node;
  43276. },
  43277. /**
  43278. * Return an iterable of all the ancestor nodes above a specific path.
  43279. *
  43280. * By default the order is bottom-up, from lowest to highest ancestor in
  43281. * the tree, but you can pass the `reverse: true` option to go top-down.
  43282. */
  43283. *ancestors(root, path) {
  43284. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  43285. for (var p of Path.ancestors(path, options)) {
  43286. var n = Node.ancestor(root, p);
  43287. var entry = [n, p];
  43288. yield entry;
  43289. }
  43290. },
  43291. /**
  43292. * Get the child of a node at a specific index.
  43293. */
  43294. child(root, index) {
  43295. if (Text.isText(root)) {
  43296. throw new Error("Cannot get the child of a text node: ".concat(JSON.stringify(root)));
  43297. }
  43298. var c = root.children[index];
  43299. if (c == null) {
  43300. throw new Error("Cannot get child at index `".concat(index, "` in node: ").concat(JSON.stringify(root)));
  43301. }
  43302. return c;
  43303. },
  43304. /**
  43305. * Iterate over the children of a node at a specific path.
  43306. */
  43307. *children(root, path) {
  43308. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  43309. var {
  43310. reverse = false
  43311. } = options;
  43312. var ancestor = Node.ancestor(root, path);
  43313. var {
  43314. children
  43315. } = ancestor;
  43316. var index = reverse ? children.length - 1 : 0;
  43317. while (reverse ? index >= 0 : index < children.length) {
  43318. var child = Node.child(ancestor, index);
  43319. var childPath = path.concat(index);
  43320. yield [child, childPath];
  43321. index = reverse ? index - 1 : index + 1;
  43322. }
  43323. },
  43324. /**
  43325. * Get an entry for the common ancesetor node of two paths.
  43326. */
  43327. common(root, path, another) {
  43328. var p = Path.common(path, another);
  43329. var n = Node.get(root, p);
  43330. return [n, p];
  43331. },
  43332. /**
  43333. * Get the node at a specific path, asserting that it's a descendant node.
  43334. */
  43335. descendant(root, path) {
  43336. var node = Node.get(root, path);
  43337. if (Editor.isEditor(node)) {
  43338. throw new Error("Cannot get the descendant node at path [".concat(path, "] because it refers to the root editor node instead: ").concat(node));
  43339. }
  43340. return node;
  43341. },
  43342. /**
  43343. * Return an iterable of all the descendant node entries inside a root node.
  43344. */
  43345. *descendants(root) {
  43346. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  43347. for (var [node, path] of Node.nodes(root, options)) {
  43348. if (path.length !== 0) {
  43349. // NOTE: we have to coerce here because checking the path's length does
  43350. // guarantee that `node` is not a `Editor`, but TypeScript doesn't know.
  43351. yield [node, path];
  43352. }
  43353. }
  43354. },
  43355. /**
  43356. * Return an iterable of all the element nodes inside a root node. Each iteration
  43357. * will return an `ElementEntry` tuple consisting of `[Element, Path]`. If the
  43358. * root node is an element it will be included in the iteration as well.
  43359. */
  43360. *elements(root) {
  43361. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  43362. for (var [node, path] of Node.nodes(root, options)) {
  43363. if (Element.isElement(node)) {
  43364. yield [node, path];
  43365. }
  43366. }
  43367. },
  43368. /**
  43369. * Get the first node entry in a root node from a path.
  43370. */
  43371. first(root, path) {
  43372. var p = path.slice();
  43373. var n = Node.get(root, p);
  43374. while (n) {
  43375. if (Text.isText(n) || n.children.length === 0) {
  43376. break;
  43377. } else {
  43378. n = n.children[0];
  43379. p.push(0);
  43380. }
  43381. }
  43382. return [n, p];
  43383. },
  43384. /**
  43385. * Get the sliced fragment represented by a range inside a root node.
  43386. */
  43387. fragment(root, range) {
  43388. if (Text.isText(root)) {
  43389. throw new Error("Cannot get a fragment starting from a root text node: ".concat(JSON.stringify(root)));
  43390. }
  43391. var newRoot = immer_1.produce(root, r => {
  43392. var [start, end] = Range.edges(range);
  43393. var iterable = Node.nodes(r, {
  43394. reverse: true,
  43395. pass: (_ref) => {
  43396. var [, path] = _ref;
  43397. return !Range.includes(range, path);
  43398. }
  43399. });
  43400. for (var [, path] of iterable) {
  43401. if (!Range.includes(range, path)) {
  43402. var parent = Node.parent(r, path);
  43403. var index = path[path.length - 1];
  43404. parent.children.splice(index, 1);
  43405. }
  43406. if (Path.equals(path, end.path)) {
  43407. var leaf = Node.leaf(r, path);
  43408. leaf.text = leaf.text.slice(0, end.offset);
  43409. }
  43410. if (Path.equals(path, start.path)) {
  43411. var _leaf = Node.leaf(r, path);
  43412. _leaf.text = _leaf.text.slice(start.offset);
  43413. }
  43414. }
  43415. delete r.selection;
  43416. });
  43417. return newRoot.children;
  43418. },
  43419. /**
  43420. * Get the descendant node referred to by a specific path. If the path is an
  43421. * empty array, it refers to the root node itself.
  43422. */
  43423. get(root, path) {
  43424. var node = root;
  43425. for (var i = 0; i < path.length; i++) {
  43426. var p = path[i];
  43427. if (Text.isText(node) || !node.children[p]) {
  43428. throw new Error("Cannot find a descendant at path [".concat(path, "] in node: ").concat(JSON.stringify(root)));
  43429. }
  43430. node = node.children[p];
  43431. }
  43432. return node;
  43433. },
  43434. /**
  43435. * Check if a descendant node exists at a specific path.
  43436. */
  43437. has(root, path) {
  43438. var node = root;
  43439. for (var i = 0; i < path.length; i++) {
  43440. var p = path[i];
  43441. if (Text.isText(node) || !node.children[p]) {
  43442. return false;
  43443. }
  43444. node = node.children[p];
  43445. }
  43446. return true;
  43447. },
  43448. /**
  43449. * Check if a value implements the `Node` interface.
  43450. */
  43451. isNode(value) {
  43452. return Text.isText(value) || Element.isElement(value) || Editor.isEditor(value);
  43453. },
  43454. /**
  43455. * Check if a value is a list of `Node` objects.
  43456. */
  43457. isNodeList(value) {
  43458. return Array.isArray(value) && (value.length === 0 || Node.isNode(value[0]));
  43459. },
  43460. /**
  43461. * Get the lash node entry in a root node from a path.
  43462. */
  43463. last(root, path) {
  43464. var p = path.slice();
  43465. var n = Node.get(root, p);
  43466. while (n) {
  43467. if (Text.isText(n) || n.children.length === 0) {
  43468. break;
  43469. } else {
  43470. var i = n.children.length - 1;
  43471. n = n.children[i];
  43472. p.push(i);
  43473. }
  43474. }
  43475. return [n, p];
  43476. },
  43477. /**
  43478. * Get the node at a specific path, ensuring it's a leaf text node.
  43479. */
  43480. leaf(root, path) {
  43481. var node = Node.get(root, path);
  43482. if (!Text.isText(node)) {
  43483. throw new Error("Cannot get the leaf node at path [".concat(path, "] because it refers to a non-leaf node: ").concat(node));
  43484. }
  43485. return node;
  43486. },
  43487. /**
  43488. * Return an iterable of the in a branch of the tree, from a specific path.
  43489. *
  43490. * By default the order is top-down, from lowest to highest node in the tree,
  43491. * but you can pass the `reverse: true` option to go bottom-up.
  43492. */
  43493. *levels(root, path) {
  43494. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  43495. for (var p of Path.levels(path, options)) {
  43496. var n = Node.get(root, p);
  43497. yield [n, p];
  43498. }
  43499. },
  43500. /**
  43501. * Check if a node matches a set of props.
  43502. */
  43503. matches(node, props) {
  43504. return Element.isElement(node) && Element.matches(node, props) || Text.isText(node) && Text.matches(node, props);
  43505. },
  43506. /**
  43507. * Return an iterable of all the node entries of a root node. Each entry is
  43508. * returned as a `[Node, Path]` tuple, with the path referring to the node's
  43509. * position inside the root node.
  43510. */
  43511. *nodes(root) {
  43512. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  43513. var {
  43514. pass,
  43515. reverse = false
  43516. } = options;
  43517. var {
  43518. from = [],
  43519. to
  43520. } = options;
  43521. var visited = new Set();
  43522. var p = [];
  43523. var n = root;
  43524. while (true) {
  43525. if (to && (reverse ? Path.isBefore(p, to) : Path.isAfter(p, to))) {
  43526. break;
  43527. }
  43528. if (!visited.has(n)) {
  43529. yield [n, p];
  43530. } // If we're allowed to go downward and we haven't decsended yet, do.
  43531. if (!visited.has(n) && !Text.isText(n) && n.children.length !== 0 && (pass == null || pass([n, p]) === false)) {
  43532. visited.add(n);
  43533. var nextIndex = reverse ? n.children.length - 1 : 0;
  43534. if (Path.isAncestor(p, from)) {
  43535. nextIndex = from[p.length];
  43536. }
  43537. p = p.concat(nextIndex);
  43538. n = Node.get(root, p);
  43539. continue;
  43540. } // If we're at the root and we can't go down, we're done.
  43541. if (p.length === 0) {
  43542. break;
  43543. } // If we're going forward...
  43544. if (!reverse) {
  43545. var newPath = Path.next(p);
  43546. if (Node.has(root, newPath)) {
  43547. p = newPath;
  43548. n = Node.get(root, p);
  43549. continue;
  43550. }
  43551. } // If we're going backward...
  43552. if (reverse && p[p.length - 1] !== 0) {
  43553. var _newPath = Path.previous(p);
  43554. p = _newPath;
  43555. n = Node.get(root, p);
  43556. continue;
  43557. } // Otherwise we're going upward...
  43558. p = Path.parent(p);
  43559. n = Node.get(root, p);
  43560. visited.add(n);
  43561. }
  43562. },
  43563. /**
  43564. * Get the parent of a node at a specific path.
  43565. */
  43566. parent(root, path) {
  43567. var parentPath = Path.parent(path);
  43568. var p = Node.get(root, parentPath);
  43569. if (Text.isText(p)) {
  43570. throw new Error("Cannot get the parent of path [".concat(path, "] because it does not exist in the root."));
  43571. }
  43572. return p;
  43573. },
  43574. /**
  43575. * Get the concatenated text string of a node's content.
  43576. *
  43577. * Note that this will not include spaces or line breaks between block nodes.
  43578. * It is not a user-facing string, but a string for performing offset-related
  43579. * computations for a node.
  43580. */
  43581. string(node) {
  43582. if (Text.isText(node)) {
  43583. return node.text;
  43584. } else {
  43585. return node.children.map(Node.string).join('');
  43586. }
  43587. },
  43588. /**
  43589. * Return an iterable of all leaf text nodes in a root node.
  43590. */
  43591. *texts(root) {
  43592. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  43593. for (var [node, path] of Node.nodes(root, options)) {
  43594. if (Text.isText(node)) {
  43595. yield [node, path];
  43596. }
  43597. }
  43598. }
  43599. };
  43600. function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  43601. function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$2(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  43602. var Operation = {
  43603. /**
  43604. * Check of a value is a `NodeOperation` object.
  43605. */
  43606. isNodeOperation(value) {
  43607. return Operation.isOperation(value) && value.type.endsWith('_node');
  43608. },
  43609. /**
  43610. * Check of a value is an `Operation` object.
  43611. */
  43612. isOperation(value) {
  43613. if (!isPlainObject(value)) {
  43614. return false;
  43615. }
  43616. switch (value.type) {
  43617. case 'insert_node':
  43618. return Path.isPath(value.path) && Node.isNode(value.node);
  43619. case 'insert_text':
  43620. return typeof value.offset === 'number' && typeof value.text === 'string' && Path.isPath(value.path);
  43621. case 'merge_node':
  43622. return typeof value.position === 'number' && (typeof value.target === 'number' || value.target === null) && Path.isPath(value.path) && isPlainObject(value.properties);
  43623. case 'move_node':
  43624. return Path.isPath(value.path) && Path.isPath(value.newPath);
  43625. case 'remove_node':
  43626. return Path.isPath(value.path) && Node.isNode(value.node);
  43627. case 'remove_text':
  43628. return typeof value.offset === 'number' && typeof value.text === 'string' && Path.isPath(value.path);
  43629. case 'set_node':
  43630. return Path.isPath(value.path) && isPlainObject(value.properties) && isPlainObject(value.newProperties);
  43631. case 'set_selection':
  43632. return value.properties === null && Range.isRange(value.newProperties) || value.newProperties === null && Range.isRange(value.properties) || isPlainObject(value.properties) && isPlainObject(value.newProperties);
  43633. case 'split_node':
  43634. return Path.isPath(value.path) && typeof value.position === 'number' && (typeof value.target === 'number' || value.target === null) && isPlainObject(value.properties);
  43635. default:
  43636. return false;
  43637. }
  43638. },
  43639. /**
  43640. * Check if a value is a list of `Operation` objects.
  43641. */
  43642. isOperationList(value) {
  43643. return Array.isArray(value) && (value.length === 0 || Operation.isOperation(value[0]));
  43644. },
  43645. /**
  43646. * Check of a value is a `SelectionOperation` object.
  43647. */
  43648. isSelectionOperation(value) {
  43649. return Operation.isOperation(value) && value.type.endsWith('_selection');
  43650. },
  43651. /**
  43652. * Check of a value is a `TextOperation` object.
  43653. */
  43654. isTextOperation(value) {
  43655. return Operation.isOperation(value) && value.type.endsWith('_text');
  43656. },
  43657. /**
  43658. * Invert an operation, returning a new operation that will exactly undo the
  43659. * original when applied.
  43660. */
  43661. inverse(op) {
  43662. switch (op.type) {
  43663. case 'insert_node':
  43664. {
  43665. return _objectSpread$2({}, op, {
  43666. type: 'remove_node'
  43667. });
  43668. }
  43669. case 'insert_text':
  43670. {
  43671. return _objectSpread$2({}, op, {
  43672. type: 'remove_text'
  43673. });
  43674. }
  43675. case 'merge_node':
  43676. {
  43677. return _objectSpread$2({}, op, {
  43678. type: 'split_node',
  43679. path: Path.previous(op.path)
  43680. });
  43681. }
  43682. case 'move_node':
  43683. {
  43684. var {
  43685. newPath,
  43686. path
  43687. } = op; // PERF: in this case the move operation is a no-op anyways.
  43688. if (Path.equals(newPath, path)) {
  43689. return op;
  43690. } // We need to get the original path here, but sometimes the `newPath`
  43691. // is a younger sibling of (or ends before) the original, and this
  43692. // accounts for it.
  43693. var inversePath = Path.transform(path, op);
  43694. var inverseNewPath = Path.transform(Path.next(path), op);
  43695. return _objectSpread$2({}, op, {
  43696. path: inversePath,
  43697. newPath: inverseNewPath
  43698. });
  43699. }
  43700. case 'remove_node':
  43701. {
  43702. return _objectSpread$2({}, op, {
  43703. type: 'insert_node'
  43704. });
  43705. }
  43706. case 'remove_text':
  43707. {
  43708. return _objectSpread$2({}, op, {
  43709. type: 'insert_text'
  43710. });
  43711. }
  43712. case 'set_node':
  43713. {
  43714. var {
  43715. properties,
  43716. newProperties
  43717. } = op;
  43718. return _objectSpread$2({}, op, {
  43719. properties: newProperties,
  43720. newProperties: properties
  43721. });
  43722. }
  43723. case 'set_selection':
  43724. {
  43725. var {
  43726. properties: _properties,
  43727. newProperties: _newProperties
  43728. } = op;
  43729. if (_properties == null) {
  43730. return _objectSpread$2({}, op, {
  43731. properties: _newProperties,
  43732. newProperties: null
  43733. });
  43734. } else if (_newProperties == null) {
  43735. return _objectSpread$2({}, op, {
  43736. properties: null,
  43737. newProperties: _properties
  43738. });
  43739. } else {
  43740. return _objectSpread$2({}, op, {
  43741. properties: _newProperties,
  43742. newProperties: _properties
  43743. });
  43744. }
  43745. }
  43746. case 'split_node':
  43747. {
  43748. return _objectSpread$2({}, op, {
  43749. type: 'merge_node',
  43750. path: Path.next(op.path)
  43751. });
  43752. }
  43753. }
  43754. }
  43755. };
  43756. var Path = {
  43757. /**
  43758. * Get a list of ancestor paths for a given path.
  43759. *
  43760. * The paths are sorted from deepest to shallowest ancestor. However, if the
  43761. * `reverse: true` option is passed, they are reversed.
  43762. */
  43763. ancestors(path) {
  43764. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  43765. var {
  43766. reverse = false
  43767. } = options;
  43768. var paths = Path.levels(path, options);
  43769. if (reverse) {
  43770. paths = paths.slice(1);
  43771. } else {
  43772. paths = paths.slice(0, -1);
  43773. }
  43774. return paths;
  43775. },
  43776. /**
  43777. * Get the common ancestor path of two paths.
  43778. */
  43779. common(path, another) {
  43780. var common = [];
  43781. for (var i = 0; i < path.length && i < another.length; i++) {
  43782. var av = path[i];
  43783. var bv = another[i];
  43784. if (av !== bv) {
  43785. break;
  43786. }
  43787. common.push(av);
  43788. }
  43789. return common;
  43790. },
  43791. /**
  43792. * Compare a path to another, returning an integer indicating whether the path
  43793. * was before, at, or after the other.
  43794. *
  43795. * Note: Two paths of unequal length can still receive a `0` result if one is
  43796. * directly above or below the other. If you want exact matching, use
  43797. * [[Path.equals]] instead.
  43798. */
  43799. compare(path, another) {
  43800. var min = Math.min(path.length, another.length);
  43801. for (var i = 0; i < min; i++) {
  43802. if (path[i] < another[i]) return -1;
  43803. if (path[i] > another[i]) return 1;
  43804. }
  43805. return 0;
  43806. },
  43807. /**
  43808. * Check if a path ends after one of the indexes in another.
  43809. */
  43810. endsAfter(path, another) {
  43811. var i = path.length - 1;
  43812. var as = path.slice(0, i);
  43813. var bs = another.slice(0, i);
  43814. var av = path[i];
  43815. var bv = another[i];
  43816. return Path.equals(as, bs) && av > bv;
  43817. },
  43818. /**
  43819. * Check if a path ends at one of the indexes in another.
  43820. */
  43821. endsAt(path, another) {
  43822. var i = path.length;
  43823. var as = path.slice(0, i);
  43824. var bs = another.slice(0, i);
  43825. return Path.equals(as, bs);
  43826. },
  43827. /**
  43828. * Check if a path ends before one of the indexes in another.
  43829. */
  43830. endsBefore(path, another) {
  43831. var i = path.length - 1;
  43832. var as = path.slice(0, i);
  43833. var bs = another.slice(0, i);
  43834. var av = path[i];
  43835. var bv = another[i];
  43836. return Path.equals(as, bs) && av < bv;
  43837. },
  43838. /**
  43839. * Check if a path is exactly equal to another.
  43840. */
  43841. equals(path, another) {
  43842. return path.length === another.length && path.every((n, i) => n === another[i]);
  43843. },
  43844. /**
  43845. * Check if a path is after another.
  43846. */
  43847. isAfter(path, another) {
  43848. return Path.compare(path, another) === 1;
  43849. },
  43850. /**
  43851. * Check if a path is an ancestor of another.
  43852. */
  43853. isAncestor(path, another) {
  43854. return path.length < another.length && Path.compare(path, another) === 0;
  43855. },
  43856. /**
  43857. * Check if a path is before another.
  43858. */
  43859. isBefore(path, another) {
  43860. return Path.compare(path, another) === -1;
  43861. },
  43862. /**
  43863. * Check if a path is a child of another.
  43864. */
  43865. isChild(path, another) {
  43866. return path.length === another.length + 1 && Path.compare(path, another) === 0;
  43867. },
  43868. /**
  43869. * Check if a path is equal to or an ancestor of another.
  43870. */
  43871. isCommon(path, another) {
  43872. return path.length <= another.length && Path.compare(path, another) === 0;
  43873. },
  43874. /**
  43875. * Check if a path is a descendant of another.
  43876. */
  43877. isDescendant(path, another) {
  43878. return path.length > another.length && Path.compare(path, another) === 0;
  43879. },
  43880. /**
  43881. * Check if a path is the parent of another.
  43882. */
  43883. isParent(path, another) {
  43884. return path.length + 1 === another.length && Path.compare(path, another) === 0;
  43885. },
  43886. /**
  43887. * Check is a value implements the `Path` interface.
  43888. */
  43889. isPath(value) {
  43890. return Array.isArray(value) && (value.length === 0 || typeof value[0] === 'number');
  43891. },
  43892. /**
  43893. * Check if a path is a sibling of another.
  43894. */
  43895. isSibling(path, another) {
  43896. if (path.length !== another.length) {
  43897. return false;
  43898. }
  43899. var as = path.slice(0, -1);
  43900. var bs = another.slice(0, -1);
  43901. var al = path[path.length - 1];
  43902. var bl = another[another.length - 1];
  43903. return al !== bl && Path.equals(as, bs);
  43904. },
  43905. /**
  43906. * Get a list of paths at every level down to a path. Note: this is the same
  43907. * as `Path.ancestors`, but including the path itself.
  43908. *
  43909. * The paths are sorted from shallowest to deepest. However, if the `reverse:
  43910. * true` option is passed, they are reversed.
  43911. */
  43912. levels(path) {
  43913. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  43914. var {
  43915. reverse = false
  43916. } = options;
  43917. var list = [];
  43918. for (var i = 0; i <= path.length; i++) {
  43919. list.push(path.slice(0, i));
  43920. }
  43921. if (reverse) {
  43922. list.reverse();
  43923. }
  43924. return list;
  43925. },
  43926. /**
  43927. * Given a path, get the path to the next sibling node.
  43928. */
  43929. next(path) {
  43930. if (path.length === 0) {
  43931. throw new Error("Cannot get the next path of a root path [".concat(path, "], because it has no next index."));
  43932. }
  43933. var last = path[path.length - 1];
  43934. return path.slice(0, -1).concat(last + 1);
  43935. },
  43936. /**
  43937. * Given a path, return a new path referring to the parent node above it.
  43938. */
  43939. parent(path) {
  43940. if (path.length === 0) {
  43941. throw new Error("Cannot get the parent path of the root path [".concat(path, "]."));
  43942. }
  43943. return path.slice(0, -1);
  43944. },
  43945. /**
  43946. * Given a path, get the path to the previous sibling node.
  43947. */
  43948. previous(path) {
  43949. if (path.length === 0) {
  43950. throw new Error("Cannot get the previous path of a root path [".concat(path, "], because it has no previous index."));
  43951. }
  43952. var last = path[path.length - 1];
  43953. if (last <= 0) {
  43954. throw new Error("Cannot get the previous path of a first child path [".concat(path, "] because it would result in a negative index."));
  43955. }
  43956. return path.slice(0, -1).concat(last - 1);
  43957. },
  43958. /**
  43959. * Get a path relative to an ancestor.
  43960. */
  43961. relative(path, ancestor) {
  43962. if (!Path.isAncestor(ancestor, path) && !Path.equals(path, ancestor)) {
  43963. throw new Error("Cannot get the relative path of [".concat(path, "] inside ancestor [").concat(ancestor, "], because it is not above or equal to the path."));
  43964. }
  43965. return path.slice(ancestor.length);
  43966. },
  43967. /**
  43968. * Transform a path by an operation.
  43969. */
  43970. transform(path, operation) {
  43971. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  43972. return immer_1.produce(path, p => {
  43973. var {
  43974. affinity = 'forward'
  43975. } = options; // PERF: Exit early if the operation is guaranteed not to have an effect.
  43976. if (path.length === 0) {
  43977. return;
  43978. }
  43979. switch (operation.type) {
  43980. case 'insert_node':
  43981. {
  43982. var {
  43983. path: op
  43984. } = operation;
  43985. if (Path.equals(op, p) || Path.endsBefore(op, p) || Path.isAncestor(op, p)) {
  43986. p[op.length - 1] += 1;
  43987. }
  43988. break;
  43989. }
  43990. case 'remove_node':
  43991. {
  43992. var {
  43993. path: _op
  43994. } = operation;
  43995. if (Path.equals(_op, p) || Path.isAncestor(_op, p)) {
  43996. return null;
  43997. } else if (Path.endsBefore(_op, p)) {
  43998. p[_op.length - 1] -= 1;
  43999. }
  44000. break;
  44001. }
  44002. case 'merge_node':
  44003. {
  44004. var {
  44005. path: _op2,
  44006. position
  44007. } = operation;
  44008. if (Path.equals(_op2, p) || Path.endsBefore(_op2, p)) {
  44009. p[_op2.length - 1] -= 1;
  44010. } else if (Path.isAncestor(_op2, p)) {
  44011. p[_op2.length - 1] -= 1;
  44012. p[_op2.length] += position;
  44013. }
  44014. break;
  44015. }
  44016. case 'split_node':
  44017. {
  44018. var {
  44019. path: _op3,
  44020. position: _position
  44021. } = operation;
  44022. if (Path.equals(_op3, p)) {
  44023. if (affinity === 'forward') {
  44024. p[p.length - 1] += 1;
  44025. } else if (affinity === 'backward') ; else {
  44026. return null;
  44027. }
  44028. } else if (Path.endsBefore(_op3, p)) {
  44029. p[_op3.length - 1] += 1;
  44030. } else if (Path.isAncestor(_op3, p) && path[_op3.length] >= _position) {
  44031. p[_op3.length - 1] += 1;
  44032. p[_op3.length] -= _position;
  44033. }
  44034. break;
  44035. }
  44036. case 'move_node':
  44037. {
  44038. var {
  44039. path: _op4,
  44040. newPath: onp
  44041. } = operation; // If the old and new path are the same, it's a no-op.
  44042. if (Path.equals(_op4, onp)) {
  44043. return;
  44044. }
  44045. if (Path.isAncestor(_op4, p) || Path.equals(_op4, p)) {
  44046. var copy = onp.slice();
  44047. if (Path.endsBefore(_op4, onp) && _op4.length < onp.length) {
  44048. var i = Math.min(onp.length, _op4.length) - 1;
  44049. copy[i] -= 1;
  44050. }
  44051. return copy.concat(p.slice(_op4.length));
  44052. } else if (Path.endsBefore(onp, p) || Path.equals(onp, p) || Path.isAncestor(onp, p)) {
  44053. if (Path.endsBefore(_op4, p)) {
  44054. p[_op4.length - 1] -= 1;
  44055. }
  44056. p[onp.length - 1] += 1;
  44057. } else if (Path.endsBefore(_op4, p)) {
  44058. if (Path.equals(onp, p)) {
  44059. p[onp.length - 1] += 1;
  44060. }
  44061. p[_op4.length - 1] -= 1;
  44062. }
  44063. break;
  44064. }
  44065. }
  44066. });
  44067. }
  44068. };
  44069. var PathRef = {
  44070. /**
  44071. * Transform the path ref's current value by an operation.
  44072. */
  44073. transform(ref, op) {
  44074. var {
  44075. current,
  44076. affinity
  44077. } = ref;
  44078. if (current == null) {
  44079. return;
  44080. }
  44081. var path = Path.transform(current, op, {
  44082. affinity
  44083. });
  44084. ref.current = path;
  44085. if (path == null) {
  44086. ref.unref();
  44087. }
  44088. }
  44089. };
  44090. function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  44091. function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$3(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  44092. var Point = {
  44093. /**
  44094. * Compare a point to another, returning an integer indicating whether the
  44095. * point was before, at, or after the other.
  44096. */
  44097. compare(point, another) {
  44098. var result = Path.compare(point.path, another.path);
  44099. if (result === 0) {
  44100. if (point.offset < another.offset) return -1;
  44101. if (point.offset > another.offset) return 1;
  44102. return 0;
  44103. }
  44104. return result;
  44105. },
  44106. /**
  44107. * Check if a point is after another.
  44108. */
  44109. isAfter(point, another) {
  44110. return Point.compare(point, another) === 1;
  44111. },
  44112. /**
  44113. * Check if a point is before another.
  44114. */
  44115. isBefore(point, another) {
  44116. return Point.compare(point, another) === -1;
  44117. },
  44118. /**
  44119. * Check if a point is exactly equal to another.
  44120. */
  44121. equals(point, another) {
  44122. // PERF: ensure the offsets are equal first since they are cheaper to check.
  44123. return point.offset === another.offset && Path.equals(point.path, another.path);
  44124. },
  44125. /**
  44126. * Check if a value implements the `Point` interface.
  44127. */
  44128. isPoint(value) {
  44129. return isPlainObject(value) && typeof value.offset === 'number' && Path.isPath(value.path);
  44130. },
  44131. /**
  44132. * Transform a point by an operation.
  44133. */
  44134. transform(point, op) {
  44135. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  44136. return immer_1.produce(point, p => {
  44137. var {
  44138. affinity = 'forward'
  44139. } = options;
  44140. var {
  44141. path,
  44142. offset
  44143. } = p;
  44144. switch (op.type) {
  44145. case 'insert_node':
  44146. case 'move_node':
  44147. {
  44148. p.path = Path.transform(path, op, options);
  44149. break;
  44150. }
  44151. case 'insert_text':
  44152. {
  44153. if (Path.equals(op.path, path) && op.offset <= offset) {
  44154. p.offset += op.text.length;
  44155. }
  44156. break;
  44157. }
  44158. case 'merge_node':
  44159. {
  44160. if (Path.equals(op.path, path)) {
  44161. p.offset += op.position;
  44162. }
  44163. p.path = Path.transform(path, op, options);
  44164. break;
  44165. }
  44166. case 'remove_text':
  44167. {
  44168. if (Path.equals(op.path, path) && op.offset <= offset) {
  44169. p.offset -= Math.min(offset - op.offset, op.text.length);
  44170. }
  44171. break;
  44172. }
  44173. case 'remove_node':
  44174. {
  44175. if (Path.equals(op.path, path) || Path.isAncestor(op.path, path)) {
  44176. return null;
  44177. }
  44178. p.path = Path.transform(path, op, options);
  44179. break;
  44180. }
  44181. case 'split_node':
  44182. {
  44183. if (Path.equals(op.path, path)) {
  44184. if (op.position === offset && affinity == null) {
  44185. return null;
  44186. } else if (op.position < offset || op.position === offset && affinity === 'forward') {
  44187. p.offset -= op.position;
  44188. p.path = Path.transform(path, op, _objectSpread$3({}, options, {
  44189. affinity: 'forward'
  44190. }));
  44191. }
  44192. } else {
  44193. p.path = Path.transform(path, op, options);
  44194. }
  44195. break;
  44196. }
  44197. }
  44198. });
  44199. }
  44200. };
  44201. var PointRef = {
  44202. /**
  44203. * Transform the point ref's current value by an operation.
  44204. */
  44205. transform(ref, op) {
  44206. var {
  44207. current,
  44208. affinity
  44209. } = ref;
  44210. if (current == null) {
  44211. return;
  44212. }
  44213. var point = Point.transform(current, op, {
  44214. affinity
  44215. });
  44216. ref.current = point;
  44217. if (point == null) {
  44218. ref.unref();
  44219. }
  44220. }
  44221. };
  44222. function ownKeys$4(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  44223. function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$4(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  44224. var Range = {
  44225. /**
  44226. * Get the start and end points of a range, in the order in which they appear
  44227. * in the document.
  44228. */
  44229. edges(range) {
  44230. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  44231. var {
  44232. reverse = false
  44233. } = options;
  44234. var {
  44235. anchor,
  44236. focus
  44237. } = range;
  44238. return Range.isBackward(range) === reverse ? [anchor, focus] : [focus, anchor];
  44239. },
  44240. /**
  44241. * Get the end point of a range.
  44242. */
  44243. end(range) {
  44244. var [, end] = Range.edges(range);
  44245. return end;
  44246. },
  44247. /**
  44248. * Check if a range is exactly equal to another.
  44249. */
  44250. equals(range, another) {
  44251. return Point.equals(range.anchor, another.anchor) && Point.equals(range.focus, another.focus);
  44252. },
  44253. /**
  44254. * Check if a range includes a path, a point or part of another range.
  44255. */
  44256. includes(range, target) {
  44257. if (Range.isRange(target)) {
  44258. if (Range.includes(range, target.anchor) || Range.includes(range, target.focus)) {
  44259. return true;
  44260. }
  44261. var [rs, re] = Range.edges(range);
  44262. var [ts, te] = Range.edges(target);
  44263. return Point.isBefore(rs, ts) && Point.isAfter(re, te);
  44264. }
  44265. var [start, end] = Range.edges(range);
  44266. var isAfterStart = false;
  44267. var isBeforeEnd = false;
  44268. if (Point.isPoint(target)) {
  44269. isAfterStart = Point.compare(target, start) >= 0;
  44270. isBeforeEnd = Point.compare(target, end) <= 0;
  44271. } else {
  44272. isAfterStart = Path.compare(target, start.path) >= 0;
  44273. isBeforeEnd = Path.compare(target, end.path) <= 0;
  44274. }
  44275. return isAfterStart && isBeforeEnd;
  44276. },
  44277. /**
  44278. * Get the intersection of a range with another.
  44279. */
  44280. intersection(range, another) {
  44281. var rest = _objectWithoutProperties(range, ["anchor", "focus"]);
  44282. var [s1, e1] = Range.edges(range);
  44283. var [s2, e2] = Range.edges(another);
  44284. var start = Point.isBefore(s1, s2) ? s2 : s1;
  44285. var end = Point.isBefore(e1, e2) ? e1 : e2;
  44286. if (Point.isBefore(end, start)) {
  44287. return null;
  44288. } else {
  44289. return _objectSpread$4({
  44290. anchor: start,
  44291. focus: end
  44292. }, rest);
  44293. }
  44294. },
  44295. /**
  44296. * Check if a range is backward, meaning that its anchor point appears in the
  44297. * document _after_ its focus point.
  44298. */
  44299. isBackward(range) {
  44300. var {
  44301. anchor,
  44302. focus
  44303. } = range;
  44304. return Point.isAfter(anchor, focus);
  44305. },
  44306. /**
  44307. * Check if a range is collapsed, meaning that both its anchor and focus
  44308. * points refer to the exact same position in the document.
  44309. */
  44310. isCollapsed(range) {
  44311. var {
  44312. anchor,
  44313. focus
  44314. } = range;
  44315. return Point.equals(anchor, focus);
  44316. },
  44317. /**
  44318. * Check if a range is expanded.
  44319. *
  44320. * This is the opposite of [[Range.isCollapsed]] and is provided for legibility.
  44321. */
  44322. isExpanded(range) {
  44323. return !Range.isCollapsed(range);
  44324. },
  44325. /**
  44326. * Check if a range is forward.
  44327. *
  44328. * This is the opposite of [[Range.isBackward]] and is provided for legibility.
  44329. */
  44330. isForward(range) {
  44331. return !Range.isBackward(range);
  44332. },
  44333. /**
  44334. * Check if a value implements the [[Range]] interface.
  44335. */
  44336. isRange(value) {
  44337. return isPlainObject(value) && Point.isPoint(value.anchor) && Point.isPoint(value.focus);
  44338. },
  44339. /**
  44340. * Iterate through all of the point entries in a range.
  44341. */
  44342. *points(range) {
  44343. yield [range.anchor, 'anchor'];
  44344. yield [range.focus, 'focus'];
  44345. },
  44346. /**
  44347. * Get the start point of a range.
  44348. */
  44349. start(range) {
  44350. var [start] = Range.edges(range);
  44351. return start;
  44352. },
  44353. /**
  44354. * Transform a range by an operation.
  44355. */
  44356. transform(range, op, options) {
  44357. var {
  44358. affinity = 'inward'
  44359. } = options;
  44360. var affinityAnchor;
  44361. var affinityFocus;
  44362. if (affinity === 'inward') {
  44363. if (Range.isForward(range)) {
  44364. affinityAnchor = 'forward';
  44365. affinityFocus = 'backward';
  44366. } else {
  44367. affinityAnchor = 'backward';
  44368. affinityFocus = 'forward';
  44369. }
  44370. } else if (affinity === 'outward') {
  44371. if (Range.isForward(range)) {
  44372. affinityAnchor = 'backward';
  44373. affinityFocus = 'forward';
  44374. } else {
  44375. affinityAnchor = 'forward';
  44376. affinityFocus = 'backward';
  44377. }
  44378. } else {
  44379. affinityAnchor = affinity;
  44380. affinityFocus = affinity;
  44381. }
  44382. return immer_1.produce(range, r => {
  44383. var anchor = Point.transform(r.anchor, op, {
  44384. affinity: affinityAnchor
  44385. });
  44386. var focus = Point.transform(r.focus, op, {
  44387. affinity: affinityFocus
  44388. });
  44389. if (!anchor || !focus) {
  44390. return null;
  44391. }
  44392. r.anchor = anchor;
  44393. r.focus = focus;
  44394. });
  44395. }
  44396. };
  44397. var RangeRef = {
  44398. /**
  44399. * Transform the range ref's current value by an operation.
  44400. */
  44401. transform(ref, op) {
  44402. var {
  44403. current,
  44404. affinity
  44405. } = ref;
  44406. if (current == null) {
  44407. return;
  44408. }
  44409. var path = Range.transform(current, op, {
  44410. affinity
  44411. });
  44412. ref.current = path;
  44413. if (path == null) {
  44414. ref.unref();
  44415. }
  44416. }
  44417. };
  44418. function ownKeys$5(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  44419. function _objectSpread$5(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$5(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$5(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  44420. var Text = {
  44421. /**
  44422. * Check if two text nodes are equal.
  44423. */
  44424. equals(text, another) {
  44425. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  44426. var {
  44427. loose = false
  44428. } = options;
  44429. for (var key in text) {
  44430. if (loose && key === 'text') {
  44431. continue;
  44432. }
  44433. if (text[key] !== another[key]) {
  44434. return false;
  44435. }
  44436. }
  44437. for (var _key in another) {
  44438. if (loose && _key === 'text') {
  44439. continue;
  44440. }
  44441. if (text[_key] !== another[_key]) {
  44442. return false;
  44443. }
  44444. }
  44445. return true;
  44446. },
  44447. /**
  44448. * Check if a value implements the `Text` interface.
  44449. */
  44450. isText(value) {
  44451. return isPlainObject(value) && typeof value.text === 'string';
  44452. },
  44453. /**
  44454. * Check if a value is a list of `Text` objects.
  44455. */
  44456. isTextList(value) {
  44457. return Array.isArray(value) && (value.length === 0 || Text.isText(value[0]));
  44458. },
  44459. /**
  44460. * Check if an text matches set of properties.
  44461. *
  44462. * Note: this is for matching custom properties, and it does not ensure that
  44463. * the `text` property are two nodes equal.
  44464. */
  44465. matches(text, props) {
  44466. for (var key in props) {
  44467. if (key === 'text') {
  44468. continue;
  44469. }
  44470. if (text[key] !== props[key]) {
  44471. return false;
  44472. }
  44473. }
  44474. return true;
  44475. },
  44476. /**
  44477. * Get the leaves for a text node given decorations.
  44478. */
  44479. decorations(node, decorations) {
  44480. var leaves = [_objectSpread$5({}, node)];
  44481. for (var dec of decorations) {
  44482. var rest = _objectWithoutProperties(dec, ["anchor", "focus"]);
  44483. var [start, end] = Range.edges(dec);
  44484. var next = [];
  44485. var o = 0;
  44486. for (var leaf of leaves) {
  44487. var {
  44488. length
  44489. } = leaf.text;
  44490. var offset = o;
  44491. o += length; // If the range encompases the entire leaf, add the range.
  44492. if (start.offset <= offset && end.offset >= offset + length) {
  44493. Object.assign(leaf, rest);
  44494. next.push(leaf);
  44495. continue;
  44496. } // If the range starts after the leaf, or ends before it, continue.
  44497. if (start.offset > offset + length || end.offset < offset || end.offset === offset && offset !== 0) {
  44498. next.push(leaf);
  44499. continue;
  44500. } // Otherwise we need to split the leaf, at the start, end, or both,
  44501. // and add the range to the middle intersecting section. Do the end
  44502. // split first since we don't need to update the offset that way.
  44503. var middle = leaf;
  44504. var before = void 0;
  44505. var after = void 0;
  44506. if (end.offset < offset + length) {
  44507. var off = end.offset - offset;
  44508. after = _objectSpread$5({}, middle, {
  44509. text: middle.text.slice(off)
  44510. });
  44511. middle = _objectSpread$5({}, middle, {
  44512. text: middle.text.slice(0, off)
  44513. });
  44514. }
  44515. if (start.offset > offset) {
  44516. var _off = start.offset - offset;
  44517. before = _objectSpread$5({}, middle, {
  44518. text: middle.text.slice(0, _off)
  44519. });
  44520. middle = _objectSpread$5({}, middle, {
  44521. text: middle.text.slice(_off)
  44522. });
  44523. }
  44524. Object.assign(middle, rest);
  44525. if (before) {
  44526. next.push(before);
  44527. }
  44528. next.push(middle);
  44529. if (after) {
  44530. next.push(after);
  44531. }
  44532. }
  44533. leaves = next;
  44534. }
  44535. return leaves;
  44536. }
  44537. };
  44538. function ownKeys$6(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  44539. function _objectSpread$6(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$6(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$6(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  44540. var GeneralTransforms = {
  44541. /**
  44542. * Transform the editor by an operation.
  44543. */
  44544. transform(editor, op) {
  44545. editor.children = immer_1.createDraft(editor.children);
  44546. var selection = editor.selection && immer_1.createDraft(editor.selection);
  44547. switch (op.type) {
  44548. case 'insert_node':
  44549. {
  44550. var {
  44551. path,
  44552. node
  44553. } = op;
  44554. var parent = Node.parent(editor, path);
  44555. var index = path[path.length - 1];
  44556. parent.children.splice(index, 0, node);
  44557. if (selection) {
  44558. for (var [point, key] of Range.points(selection)) {
  44559. selection[key] = Point.transform(point, op);
  44560. }
  44561. }
  44562. break;
  44563. }
  44564. case 'insert_text':
  44565. {
  44566. var {
  44567. path: _path,
  44568. offset,
  44569. text
  44570. } = op;
  44571. var _node = Node.leaf(editor, _path);
  44572. var before = _node.text.slice(0, offset);
  44573. var after = _node.text.slice(offset);
  44574. _node.text = before + text + after;
  44575. if (selection) {
  44576. for (var [_point, _key] of Range.points(selection)) {
  44577. selection[_key] = Point.transform(_point, op);
  44578. }
  44579. }
  44580. break;
  44581. }
  44582. case 'merge_node':
  44583. {
  44584. var {
  44585. path: _path2
  44586. } = op;
  44587. var _node2 = Node.get(editor, _path2);
  44588. var prevPath = Path.previous(_path2);
  44589. var prev = Node.get(editor, prevPath);
  44590. var _parent = Node.parent(editor, _path2);
  44591. var _index = _path2[_path2.length - 1];
  44592. if (Text.isText(_node2) && Text.isText(prev)) {
  44593. prev.text += _node2.text;
  44594. } else if (!Text.isText(_node2) && !Text.isText(prev)) {
  44595. prev.children.push(..._node2.children);
  44596. } else {
  44597. throw new Error("Cannot apply a \"merge_node\" operation at path [".concat(_path2, "] to nodes of different interaces: ").concat(_node2, " ").concat(prev));
  44598. }
  44599. _parent.children.splice(_index, 1);
  44600. if (selection) {
  44601. for (var [_point2, _key2] of Range.points(selection)) {
  44602. selection[_key2] = Point.transform(_point2, op);
  44603. }
  44604. }
  44605. break;
  44606. }
  44607. case 'move_node':
  44608. {
  44609. var {
  44610. path: _path3,
  44611. newPath
  44612. } = op;
  44613. if (Path.isAncestor(_path3, newPath)) {
  44614. throw new Error("Cannot move a path [".concat(_path3, "] to new path [").concat(newPath, "] because the destination is inside itself."));
  44615. }
  44616. var _node3 = Node.get(editor, _path3);
  44617. var _parent2 = Node.parent(editor, _path3);
  44618. var _index2 = _path3[_path3.length - 1]; // This is tricky, but since the `path` and `newPath` both refer to
  44619. // the same snapshot in time, there's a mismatch. After either
  44620. // removing the original position, the second step's path can be out
  44621. // of date. So instead of using the `op.newPath` directly, we
  44622. // transform `op.path` to ascertain what the `newPath` would be after
  44623. // the operation was applied.
  44624. _parent2.children.splice(_index2, 1);
  44625. var truePath = Path.transform(_path3, op);
  44626. var newParent = Node.get(editor, Path.parent(truePath));
  44627. var newIndex = truePath[truePath.length - 1];
  44628. newParent.children.splice(newIndex, 0, _node3);
  44629. if (selection) {
  44630. for (var [_point3, _key3] of Range.points(selection)) {
  44631. selection[_key3] = Point.transform(_point3, op);
  44632. }
  44633. }
  44634. break;
  44635. }
  44636. case 'remove_node':
  44637. {
  44638. var {
  44639. path: _path4
  44640. } = op;
  44641. var _index3 = _path4[_path4.length - 1];
  44642. var _parent3 = Node.parent(editor, _path4);
  44643. _parent3.children.splice(_index3, 1); // Transform all of the points in the value, but if the point was in the
  44644. // node that was removed we need to update the range or remove it.
  44645. if (selection) {
  44646. for (var [_point4, _key4] of Range.points(selection)) {
  44647. var result = Point.transform(_point4, op);
  44648. if (selection != null && result != null) {
  44649. selection[_key4] = result;
  44650. } else {
  44651. var _prev = void 0;
  44652. var next = void 0;
  44653. for (var [n, p] of Node.texts(editor)) {
  44654. if (Path.compare(p, _path4) === -1) {
  44655. _prev = [n, p];
  44656. } else {
  44657. next = [n, p];
  44658. break;
  44659. }
  44660. }
  44661. if (_prev) {
  44662. _point4.path = _prev[1];
  44663. _point4.offset = _prev[0].text.length;
  44664. } else if (next) {
  44665. _point4.path = next[1];
  44666. _point4.offset = 0;
  44667. } else {
  44668. selection = null;
  44669. }
  44670. }
  44671. }
  44672. }
  44673. break;
  44674. }
  44675. case 'remove_text':
  44676. {
  44677. var {
  44678. path: _path5,
  44679. offset: _offset,
  44680. text: _text
  44681. } = op;
  44682. var _node4 = Node.leaf(editor, _path5);
  44683. var _before = _node4.text.slice(0, _offset);
  44684. var _after = _node4.text.slice(_offset + _text.length);
  44685. _node4.text = _before + _after;
  44686. if (selection) {
  44687. for (var [_point5, _key5] of Range.points(selection)) {
  44688. selection[_key5] = Point.transform(_point5, op);
  44689. }
  44690. }
  44691. break;
  44692. }
  44693. case 'set_node':
  44694. {
  44695. var {
  44696. path: _path6,
  44697. newProperties
  44698. } = op;
  44699. if (_path6.length === 0) {
  44700. throw new Error("Cannot set properties on the root node!");
  44701. }
  44702. var _node5 = Node.get(editor, _path6);
  44703. for (var _key6 in newProperties) {
  44704. if (_key6 === 'children' || _key6 === 'text') {
  44705. throw new Error("Cannot set the \"".concat(_key6, "\" property of nodes!"));
  44706. }
  44707. var value = newProperties[_key6];
  44708. if (value == null) {
  44709. delete _node5[_key6];
  44710. } else {
  44711. _node5[_key6] = value;
  44712. }
  44713. }
  44714. break;
  44715. }
  44716. case 'set_selection':
  44717. {
  44718. var {
  44719. newProperties: _newProperties
  44720. } = op;
  44721. if (_newProperties == null) {
  44722. selection = _newProperties;
  44723. } else if (selection == null) {
  44724. if (!Range.isRange(_newProperties)) {
  44725. throw new Error("Cannot apply an incomplete \"set_selection\" operation properties ".concat(JSON.stringify(_newProperties), " when there is no current selection."));
  44726. }
  44727. selection = _newProperties;
  44728. } else {
  44729. Object.assign(selection, _newProperties);
  44730. }
  44731. break;
  44732. }
  44733. case 'split_node':
  44734. {
  44735. var {
  44736. path: _path7,
  44737. position,
  44738. properties
  44739. } = op;
  44740. if (_path7.length === 0) {
  44741. throw new Error("Cannot apply a \"split_node\" operation at path [".concat(_path7, "] because the root node cannot be split."));
  44742. }
  44743. var _node6 = Node.get(editor, _path7);
  44744. var _parent4 = Node.parent(editor, _path7);
  44745. var _index4 = _path7[_path7.length - 1];
  44746. var newNode;
  44747. if (Text.isText(_node6)) {
  44748. var _before2 = _node6.text.slice(0, position);
  44749. var _after2 = _node6.text.slice(position);
  44750. _node6.text = _before2;
  44751. newNode = _objectSpread$6({}, _node6, {}, properties, {
  44752. text: _after2
  44753. });
  44754. } else {
  44755. var _before3 = _node6.children.slice(0, position);
  44756. var _after3 = _node6.children.slice(position);
  44757. _node6.children = _before3;
  44758. newNode = _objectSpread$6({}, _node6, {}, properties, {
  44759. children: _after3
  44760. });
  44761. }
  44762. _parent4.children.splice(_index4 + 1, 0, newNode);
  44763. if (selection) {
  44764. for (var [_point6, _key7] of Range.points(selection)) {
  44765. selection[_key7] = Point.transform(_point6, op);
  44766. }
  44767. }
  44768. break;
  44769. }
  44770. }
  44771. editor.children = immer_1.finishDraft(editor.children);
  44772. if (selection) {
  44773. editor.selection = immer_1.isDraft(selection) ? immer_1.finishDraft(selection) : selection;
  44774. } else {
  44775. editor.selection = null;
  44776. }
  44777. }
  44778. };
  44779. function ownKeys$7(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  44780. function _objectSpread$7(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$7(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$7(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  44781. var NodeTransforms = {
  44782. /**
  44783. * Insert nodes at a specific location in the Editor.
  44784. */
  44785. insertNodes(editor, nodes) {
  44786. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  44787. Editor.withoutNormalizing(editor, () => {
  44788. var {
  44789. hanging = false,
  44790. voids = false,
  44791. mode = 'lowest'
  44792. } = options;
  44793. var {
  44794. at,
  44795. match,
  44796. select
  44797. } = options;
  44798. if (Node.isNode(nodes)) {
  44799. nodes = [nodes];
  44800. }
  44801. if (nodes.length === 0) {
  44802. return;
  44803. }
  44804. var [node] = nodes; // By default, use the selection as the target location. But if there is
  44805. // no selection, insert at the end of the document since that is such a
  44806. // common use case when inserting from a non-selected state.
  44807. if (!at) {
  44808. if (editor.selection) {
  44809. at = editor.selection;
  44810. } else if (editor.children.length > 0) {
  44811. at = Editor.end(editor, []);
  44812. } else {
  44813. at = [0];
  44814. }
  44815. select = true;
  44816. }
  44817. if (select == null) {
  44818. select = false;
  44819. }
  44820. if (Range.isRange(at)) {
  44821. if (!hanging) {
  44822. at = Editor.unhangRange(editor, at);
  44823. }
  44824. if (Range.isCollapsed(at)) {
  44825. at = at.anchor;
  44826. } else {
  44827. var [, end] = Range.edges(at);
  44828. var pointRef = Editor.pointRef(editor, end);
  44829. Transforms.delete(editor, {
  44830. at
  44831. });
  44832. at = pointRef.unref();
  44833. }
  44834. }
  44835. if (Point.isPoint(at)) {
  44836. if (match == null) {
  44837. if (Text.isText(node)) {
  44838. match = n => Text.isText(n);
  44839. } else if (editor.isInline(node)) {
  44840. match = n => Text.isText(n) || Editor.isInline(editor, n);
  44841. } else {
  44842. match = n => Editor.isBlock(editor, n);
  44843. }
  44844. }
  44845. var [entry] = Editor.nodes(editor, {
  44846. at: at.path,
  44847. match,
  44848. mode,
  44849. voids
  44850. });
  44851. if (entry) {
  44852. var [, _matchPath] = entry;
  44853. var pathRef = Editor.pathRef(editor, _matchPath);
  44854. var isAtEnd = Editor.isEnd(editor, at, _matchPath);
  44855. Transforms.splitNodes(editor, {
  44856. at,
  44857. match,
  44858. mode,
  44859. voids
  44860. });
  44861. var path = pathRef.unref();
  44862. at = isAtEnd ? Path.next(path) : path;
  44863. } else {
  44864. return;
  44865. }
  44866. }
  44867. var parentPath = Path.parent(at);
  44868. var index = at[at.length - 1];
  44869. if (!voids && Editor.void(editor, {
  44870. at: parentPath
  44871. })) {
  44872. return;
  44873. }
  44874. for (var _node of nodes) {
  44875. var _path = parentPath.concat(index);
  44876. index++;
  44877. editor.apply({
  44878. type: 'insert_node',
  44879. path: _path,
  44880. node: _node
  44881. });
  44882. }
  44883. if (select) {
  44884. var point = Editor.end(editor, at);
  44885. if (point) {
  44886. Transforms.select(editor, point);
  44887. }
  44888. }
  44889. });
  44890. },
  44891. /**
  44892. * Lift nodes at a specific location upwards in the document tree, splitting
  44893. * their parent in two if necessary.
  44894. */
  44895. liftNodes(editor) {
  44896. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  44897. Editor.withoutNormalizing(editor, () => {
  44898. var {
  44899. at = editor.selection,
  44900. mode = 'lowest',
  44901. voids = false
  44902. } = options;
  44903. var {
  44904. match
  44905. } = options;
  44906. if (match == null) {
  44907. match = Path.isPath(at) ? matchPath(editor, at) : n => Editor.isBlock(editor, n);
  44908. }
  44909. if (!at) {
  44910. return;
  44911. }
  44912. var matches = Editor.nodes(editor, {
  44913. at,
  44914. match,
  44915. mode,
  44916. voids
  44917. });
  44918. var pathRefs = Array.from(matches, (_ref) => {
  44919. var [, p] = _ref;
  44920. return Editor.pathRef(editor, p);
  44921. });
  44922. for (var pathRef of pathRefs) {
  44923. var path = pathRef.unref();
  44924. if (path.length < 2) {
  44925. throw new Error("Cannot lift node at a path [".concat(path, "] because it has a depth of less than `2`."));
  44926. }
  44927. var [parent, parentPath] = Editor.node(editor, Path.parent(path));
  44928. var index = path[path.length - 1];
  44929. var {
  44930. length
  44931. } = parent.children;
  44932. if (length === 1) {
  44933. var toPath = Path.next(parentPath);
  44934. Transforms.moveNodes(editor, {
  44935. at: path,
  44936. to: toPath,
  44937. voids
  44938. });
  44939. Transforms.removeNodes(editor, {
  44940. at: parentPath,
  44941. voids
  44942. });
  44943. } else if (index === 0) {
  44944. Transforms.moveNodes(editor, {
  44945. at: path,
  44946. to: parentPath,
  44947. voids
  44948. });
  44949. } else if (index === length - 1) {
  44950. var _toPath = Path.next(parentPath);
  44951. Transforms.moveNodes(editor, {
  44952. at: path,
  44953. to: _toPath,
  44954. voids
  44955. });
  44956. } else {
  44957. var splitPath = Path.next(path);
  44958. var _toPath2 = Path.next(parentPath);
  44959. Transforms.splitNodes(editor, {
  44960. at: splitPath,
  44961. voids
  44962. });
  44963. Transforms.moveNodes(editor, {
  44964. at: path,
  44965. to: _toPath2,
  44966. voids
  44967. });
  44968. }
  44969. }
  44970. });
  44971. },
  44972. /**
  44973. * Merge a node at a location with the previous node of the same depth,
  44974. * removing any empty containing nodes after the merge if necessary.
  44975. */
  44976. mergeNodes(editor) {
  44977. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  44978. Editor.withoutNormalizing(editor, () => {
  44979. var {
  44980. match,
  44981. at = editor.selection
  44982. } = options;
  44983. var {
  44984. hanging = false,
  44985. voids = false,
  44986. mode = 'lowest'
  44987. } = options;
  44988. if (!at) {
  44989. return;
  44990. }
  44991. if (match == null) {
  44992. if (Path.isPath(at)) {
  44993. var [parent] = Editor.parent(editor, at);
  44994. match = n => parent.children.includes(n);
  44995. } else {
  44996. match = n => Editor.isBlock(editor, n);
  44997. }
  44998. }
  44999. if (!hanging && Range.isRange(at)) {
  45000. at = Editor.unhangRange(editor, at);
  45001. }
  45002. if (Range.isRange(at)) {
  45003. if (Range.isCollapsed(at)) {
  45004. at = at.anchor;
  45005. } else {
  45006. var [, end] = Range.edges(at);
  45007. var pointRef = Editor.pointRef(editor, end);
  45008. Transforms.delete(editor, {
  45009. at
  45010. });
  45011. at = pointRef.unref();
  45012. if (options.at == null) {
  45013. Transforms.select(editor, at);
  45014. }
  45015. }
  45016. }
  45017. var [current] = Editor.nodes(editor, {
  45018. at,
  45019. match,
  45020. voids,
  45021. mode
  45022. });
  45023. var prev = Editor.previous(editor, {
  45024. at,
  45025. match,
  45026. voids,
  45027. mode
  45028. });
  45029. if (!current || !prev) {
  45030. return;
  45031. }
  45032. var [node, path] = current;
  45033. var [prevNode, prevPath] = prev;
  45034. if (path.length === 0 || prevPath.length === 0) {
  45035. return;
  45036. }
  45037. var newPath = Path.next(prevPath);
  45038. var commonPath = Path.common(path, prevPath);
  45039. var isPreviousSibling = Path.isSibling(path, prevPath);
  45040. var levels = Array.from(Editor.levels(editor, {
  45041. at: path
  45042. }), (_ref2) => {
  45043. var [n] = _ref2;
  45044. return n;
  45045. }).slice(commonPath.length).slice(0, -1); // Determine if the merge will leave an ancestor of the path empty as a
  45046. // result, in which case we'll want to remove it after merging.
  45047. var emptyAncestor = Editor.above(editor, {
  45048. at: path,
  45049. mode: 'highest',
  45050. match: n => levels.includes(n) && Element.isElement(n) && n.children.length === 1
  45051. });
  45052. var emptyRef = emptyAncestor && Editor.pathRef(editor, emptyAncestor[1]);
  45053. var properties;
  45054. var position; // Ensure that the nodes are equivalent, and figure out what the position
  45055. // and extra properties of the merge will be.
  45056. if (Text.isText(node) && Text.isText(prevNode)) {
  45057. var rest = _objectWithoutProperties(node, ["text"]);
  45058. position = prevNode.text.length;
  45059. properties = rest;
  45060. } else if (Element.isElement(node) && Element.isElement(prevNode)) {
  45061. var rest = _objectWithoutProperties(node, ["children"]);
  45062. position = prevNode.children.length;
  45063. properties = rest;
  45064. } else {
  45065. throw new Error("Cannot merge the node at path [".concat(path, "] with the previous sibling because it is not the same kind: ").concat(JSON.stringify(node), " ").concat(JSON.stringify(prevNode)));
  45066. } // If the node isn't already the next sibling of the previous node, move
  45067. // it so that it is before merging.
  45068. if (!isPreviousSibling) {
  45069. Transforms.moveNodes(editor, {
  45070. at: path,
  45071. to: newPath,
  45072. voids
  45073. });
  45074. } // If there was going to be an empty ancestor of the node that was merged,
  45075. // we remove it from the tree.
  45076. if (emptyRef) {
  45077. Transforms.removeNodes(editor, {
  45078. at: emptyRef.current,
  45079. voids
  45080. });
  45081. } // If the target node that we're merging with is empty, remove it instead
  45082. // of merging the two. This is a common rich text editor behavior to
  45083. // prevent losing formatting when deleting entire nodes when you have a
  45084. // hanging selection.
  45085. if (Element.isElement(prevNode) && Editor.isEmpty(editor, prevNode) || Text.isText(prevNode) && prevNode.text === '') {
  45086. Transforms.removeNodes(editor, {
  45087. at: prevPath,
  45088. voids
  45089. });
  45090. } else {
  45091. editor.apply({
  45092. type: 'merge_node',
  45093. path: newPath,
  45094. position,
  45095. target: null,
  45096. properties
  45097. });
  45098. }
  45099. if (emptyRef) {
  45100. emptyRef.unref();
  45101. }
  45102. });
  45103. },
  45104. /**
  45105. * Move the nodes at a location to a new location.
  45106. */
  45107. moveNodes(editor, options) {
  45108. Editor.withoutNormalizing(editor, () => {
  45109. var {
  45110. to,
  45111. at = editor.selection,
  45112. mode = 'lowest',
  45113. voids = false
  45114. } = options;
  45115. var {
  45116. match
  45117. } = options;
  45118. if (!at) {
  45119. return;
  45120. }
  45121. if (match == null) {
  45122. match = Path.isPath(at) ? matchPath(editor, at) : n => Editor.isBlock(editor, n);
  45123. }
  45124. var toRef = Editor.pathRef(editor, to);
  45125. var targets = Editor.nodes(editor, {
  45126. at,
  45127. match,
  45128. mode,
  45129. voids
  45130. });
  45131. var pathRefs = Array.from(targets, (_ref3) => {
  45132. var [, p] = _ref3;
  45133. return Editor.pathRef(editor, p);
  45134. });
  45135. for (var pathRef of pathRefs) {
  45136. var path = pathRef.unref();
  45137. var newPath = toRef.current;
  45138. if (path.length !== 0) {
  45139. editor.apply({
  45140. type: 'move_node',
  45141. path,
  45142. newPath
  45143. });
  45144. }
  45145. }
  45146. toRef.unref();
  45147. });
  45148. },
  45149. /**
  45150. * Remove the nodes at a specific location in the document.
  45151. */
  45152. removeNodes(editor) {
  45153. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  45154. Editor.withoutNormalizing(editor, () => {
  45155. var {
  45156. hanging = false,
  45157. voids = false,
  45158. mode = 'lowest'
  45159. } = options;
  45160. var {
  45161. at = editor.selection,
  45162. match
  45163. } = options;
  45164. if (!at) {
  45165. return;
  45166. }
  45167. if (match == null) {
  45168. match = Path.isPath(at) ? matchPath(editor, at) : n => Editor.isBlock(editor, n);
  45169. }
  45170. if (!hanging && Range.isRange(at)) {
  45171. at = Editor.unhangRange(editor, at);
  45172. }
  45173. var depths = Editor.nodes(editor, {
  45174. at,
  45175. match,
  45176. mode,
  45177. voids
  45178. });
  45179. var pathRefs = Array.from(depths, (_ref4) => {
  45180. var [, p] = _ref4;
  45181. return Editor.pathRef(editor, p);
  45182. });
  45183. for (var pathRef of pathRefs) {
  45184. var path = pathRef.unref();
  45185. if (path) {
  45186. var [node] = Editor.node(editor, path);
  45187. editor.apply({
  45188. type: 'remove_node',
  45189. path,
  45190. node
  45191. });
  45192. }
  45193. }
  45194. });
  45195. },
  45196. /**
  45197. * Set new properties on the nodes at a location.
  45198. */
  45199. setNodes(editor, props) {
  45200. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  45201. Editor.withoutNormalizing(editor, () => {
  45202. var {
  45203. match,
  45204. at = editor.selection
  45205. } = options;
  45206. var {
  45207. hanging = false,
  45208. mode = 'lowest',
  45209. split = false,
  45210. voids = false
  45211. } = options;
  45212. if (!at) {
  45213. return;
  45214. }
  45215. if (match == null) {
  45216. match = Path.isPath(at) ? matchPath(editor, at) : n => Editor.isBlock(editor, n);
  45217. }
  45218. if (!hanging && Range.isRange(at)) {
  45219. at = Editor.unhangRange(editor, at);
  45220. }
  45221. if (split && Range.isRange(at)) {
  45222. var rangeRef = Editor.rangeRef(editor, at, {
  45223. affinity: 'inward'
  45224. });
  45225. var [start, end] = Range.edges(at);
  45226. var splitMode = mode === 'lowest' ? 'lowest' : 'highest';
  45227. Transforms.splitNodes(editor, {
  45228. at: end,
  45229. match,
  45230. mode: splitMode,
  45231. voids
  45232. });
  45233. Transforms.splitNodes(editor, {
  45234. at: start,
  45235. match,
  45236. mode: splitMode,
  45237. voids
  45238. });
  45239. at = rangeRef.unref();
  45240. if (options.at == null) {
  45241. Transforms.select(editor, at);
  45242. }
  45243. }
  45244. for (var [node, path] of Editor.nodes(editor, {
  45245. at,
  45246. match,
  45247. mode,
  45248. voids
  45249. })) {
  45250. var properties = {};
  45251. var newProperties = {}; // You can't set properties on the editor node.
  45252. if (path.length === 0) {
  45253. continue;
  45254. }
  45255. for (var k in props) {
  45256. if (k === 'children' || k === 'text') {
  45257. continue;
  45258. }
  45259. if (props[k] !== node[k]) {
  45260. properties[k] = node[k];
  45261. newProperties[k] = props[k];
  45262. }
  45263. }
  45264. if (Object.keys(newProperties).length !== 0) {
  45265. editor.apply({
  45266. type: 'set_node',
  45267. path,
  45268. properties,
  45269. newProperties
  45270. });
  45271. }
  45272. }
  45273. });
  45274. },
  45275. /**
  45276. * Split the nodes at a specific location.
  45277. */
  45278. splitNodes(editor) {
  45279. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  45280. Editor.withoutNormalizing(editor, () => {
  45281. var {
  45282. mode = 'lowest',
  45283. voids = false
  45284. } = options;
  45285. var {
  45286. match,
  45287. at = editor.selection,
  45288. height = 0,
  45289. always = false
  45290. } = options;
  45291. if (match == null) {
  45292. match = n => Editor.isBlock(editor, n);
  45293. }
  45294. if (Range.isRange(at)) {
  45295. at = deleteRange(editor, at);
  45296. } // If the target is a path, the default height-skipping and position
  45297. // counters need to account for us potentially splitting at a non-leaf.
  45298. if (Path.isPath(at)) {
  45299. var path = at;
  45300. var point = Editor.point(editor, path);
  45301. var [parent] = Editor.parent(editor, path);
  45302. match = n => n === parent;
  45303. height = point.path.length - path.length + 1;
  45304. at = point;
  45305. always = true;
  45306. }
  45307. if (!at) {
  45308. return;
  45309. }
  45310. var beforeRef = Editor.pointRef(editor, at, {
  45311. affinity: 'backward'
  45312. });
  45313. var [highest] = Editor.nodes(editor, {
  45314. at,
  45315. match,
  45316. mode,
  45317. voids
  45318. });
  45319. if (!highest) {
  45320. return;
  45321. }
  45322. var voidMatch = Editor.void(editor, {
  45323. at,
  45324. mode: 'highest'
  45325. });
  45326. var nudge = 0;
  45327. if (!voids && voidMatch) {
  45328. var [voidNode, voidPath] = voidMatch;
  45329. if (Element.isElement(voidNode) && editor.isInline(voidNode)) {
  45330. var after = Editor.after(editor, voidPath);
  45331. if (!after) {
  45332. var text = {
  45333. text: ''
  45334. };
  45335. var afterPath = Path.next(voidPath);
  45336. Transforms.insertNodes(editor, text, {
  45337. at: afterPath,
  45338. voids
  45339. });
  45340. after = Editor.point(editor, afterPath);
  45341. }
  45342. at = after;
  45343. always = true;
  45344. }
  45345. var siblingHeight = at.path.length - voidPath.length;
  45346. height = siblingHeight + 1;
  45347. always = true;
  45348. }
  45349. var afterRef = Editor.pointRef(editor, at);
  45350. var depth = at.path.length - height;
  45351. var [, highestPath] = highest;
  45352. var lowestPath = at.path.slice(0, depth);
  45353. var position = height === 0 ? at.offset : at.path[depth] + nudge;
  45354. var target = null;
  45355. for (var [node, _path2] of Editor.levels(editor, {
  45356. at: lowestPath,
  45357. reverse: true,
  45358. voids
  45359. })) {
  45360. var split = false;
  45361. if (_path2.length < highestPath.length || _path2.length === 0 || !voids && Editor.isVoid(editor, node)) {
  45362. break;
  45363. }
  45364. var _point = beforeRef.current;
  45365. var isEnd = Editor.isEnd(editor, _point, _path2);
  45366. if (always || !beforeRef || !Editor.isEdge(editor, _point, _path2)) {
  45367. split = true;
  45368. var properties = _objectWithoutProperties(node, ["text", "children"]);
  45369. editor.apply({
  45370. type: 'split_node',
  45371. path: _path2,
  45372. position,
  45373. target,
  45374. properties
  45375. });
  45376. }
  45377. target = position;
  45378. position = _path2[_path2.length - 1] + (split || isEnd ? 1 : 0);
  45379. }
  45380. if (options.at == null) {
  45381. var _point2 = afterRef.current || Editor.end(editor, []);
  45382. Transforms.select(editor, _point2);
  45383. }
  45384. beforeRef.unref();
  45385. afterRef.unref();
  45386. });
  45387. },
  45388. /**
  45389. * Unset properties on the nodes at a location.
  45390. */
  45391. unsetNodes(editor, props) {
  45392. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  45393. if (!Array.isArray(props)) {
  45394. props = [props];
  45395. }
  45396. var obj = {};
  45397. for (var key of props) {
  45398. obj[key] = null;
  45399. }
  45400. Transforms.setNodes(editor, obj, options);
  45401. },
  45402. /**
  45403. * Unwrap the nodes at a location from a parent node, splitting the parent if
  45404. * necessary to ensure that only the content in the range is unwrapped.
  45405. */
  45406. unwrapNodes(editor, options) {
  45407. Editor.withoutNormalizing(editor, () => {
  45408. var {
  45409. mode = 'lowest',
  45410. split = false,
  45411. voids = false
  45412. } = options;
  45413. var {
  45414. at = editor.selection,
  45415. match
  45416. } = options;
  45417. if (!at) {
  45418. return;
  45419. }
  45420. if (match == null) {
  45421. match = Path.isPath(at) ? matchPath(editor, at) : n => Editor.isBlock(editor, n);
  45422. }
  45423. if (Path.isPath(at)) {
  45424. at = Editor.range(editor, at);
  45425. }
  45426. var rangeRef = Range.isRange(at) ? Editor.rangeRef(editor, at) : null;
  45427. var matches = Editor.nodes(editor, {
  45428. at,
  45429. match,
  45430. mode,
  45431. voids
  45432. });
  45433. var pathRefs = Array.from(matches, (_ref5) => {
  45434. var [, p] = _ref5;
  45435. return Editor.pathRef(editor, p);
  45436. });
  45437. var _loop = function _loop(pathRef) {
  45438. var path = pathRef.unref();
  45439. var [node] = Editor.node(editor, path);
  45440. var range = Editor.range(editor, path);
  45441. if (split && rangeRef) {
  45442. range = Range.intersection(rangeRef.current, range);
  45443. }
  45444. Transforms.liftNodes(editor, {
  45445. at: range,
  45446. match: n => node.children.includes(n),
  45447. voids
  45448. });
  45449. };
  45450. for (var pathRef of pathRefs) {
  45451. _loop(pathRef);
  45452. }
  45453. if (rangeRef) {
  45454. rangeRef.unref();
  45455. }
  45456. });
  45457. },
  45458. /**
  45459. * Wrap the nodes at a location in a new container node, splitting the edges
  45460. * of the range first to ensure that only the content in the range is wrapped.
  45461. */
  45462. wrapNodes(editor, element) {
  45463. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  45464. Editor.withoutNormalizing(editor, () => {
  45465. var {
  45466. mode = 'lowest',
  45467. split = false,
  45468. voids = false
  45469. } = options;
  45470. var {
  45471. match,
  45472. at = editor.selection
  45473. } = options;
  45474. if (!at) {
  45475. return;
  45476. }
  45477. if (match == null) {
  45478. if (Path.isPath(at)) {
  45479. match = matchPath(editor, at);
  45480. } else if (editor.isInline(element)) {
  45481. match = n => Editor.isInline(editor, n) || Text.isText(n);
  45482. } else {
  45483. match = n => Editor.isBlock(editor, n);
  45484. }
  45485. }
  45486. if (split && Range.isRange(at)) {
  45487. var [start, end] = Range.edges(at);
  45488. var rangeRef = Editor.rangeRef(editor, at, {
  45489. affinity: 'inward'
  45490. });
  45491. Transforms.splitNodes(editor, {
  45492. at: end,
  45493. match,
  45494. voids
  45495. });
  45496. Transforms.splitNodes(editor, {
  45497. at: start,
  45498. match,
  45499. voids
  45500. });
  45501. at = rangeRef.unref();
  45502. if (options.at == null) {
  45503. Transforms.select(editor, at);
  45504. }
  45505. }
  45506. var roots = Array.from(Editor.nodes(editor, {
  45507. at,
  45508. match: editor.isInline(element) ? n => Editor.isBlock(editor, n) : n => Editor.isEditor(n),
  45509. mode: 'highest',
  45510. voids
  45511. }));
  45512. for (var [, rootPath] of roots) {
  45513. var a = Range.isRange(at) ? Range.intersection(at, Editor.range(editor, rootPath)) : at;
  45514. if (!a) {
  45515. continue;
  45516. }
  45517. var matches = Array.from(Editor.nodes(editor, {
  45518. at: a,
  45519. match,
  45520. mode,
  45521. voids
  45522. }));
  45523. if (matches.length > 0) {
  45524. (function () {
  45525. var [first] = matches;
  45526. var last = matches[matches.length - 1];
  45527. var [, firstPath] = first;
  45528. var [, lastPath] = last;
  45529. var commonPath = Path.equals(firstPath, lastPath) ? Path.parent(firstPath) : Path.common(firstPath, lastPath);
  45530. var range = Editor.range(editor, firstPath, lastPath);
  45531. var [commonNode] = Editor.node(editor, commonPath);
  45532. var depth = commonPath.length + 1;
  45533. var wrapperPath = Path.next(lastPath.slice(0, depth));
  45534. var wrapper = _objectSpread$7({}, element, {
  45535. children: []
  45536. });
  45537. Transforms.insertNodes(editor, wrapper, {
  45538. at: wrapperPath,
  45539. voids
  45540. });
  45541. Transforms.moveNodes(editor, {
  45542. at: range,
  45543. match: n => commonNode.children.includes(n),
  45544. to: wrapperPath.concat(0),
  45545. voids
  45546. });
  45547. })();
  45548. }
  45549. }
  45550. });
  45551. }
  45552. };
  45553. /**
  45554. * Convert a range into a point by deleting it's content.
  45555. */
  45556. var deleteRange = (editor, range) => {
  45557. if (Range.isCollapsed(range)) {
  45558. return range.anchor;
  45559. } else {
  45560. var [, end] = Range.edges(range);
  45561. var pointRef = Editor.pointRef(editor, end);
  45562. Transforms.delete(editor, {
  45563. at: range
  45564. });
  45565. return pointRef.unref();
  45566. }
  45567. };
  45568. var matchPath = (editor, path) => {
  45569. var [node] = Editor.node(editor, path);
  45570. return n => n === node;
  45571. };
  45572. var SelectionTransforms = {
  45573. /**
  45574. * Collapse the selection.
  45575. */
  45576. collapse(editor) {
  45577. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  45578. var {
  45579. edge = 'anchor'
  45580. } = options;
  45581. var {
  45582. selection
  45583. } = editor;
  45584. if (!selection) {
  45585. return;
  45586. } else if (edge === 'anchor') {
  45587. Transforms.select(editor, selection.anchor);
  45588. } else if (edge === 'focus') {
  45589. Transforms.select(editor, selection.focus);
  45590. } else if (edge === 'start') {
  45591. var [start] = Range.edges(selection);
  45592. Transforms.select(editor, start);
  45593. } else if (edge === 'end') {
  45594. var [, end] = Range.edges(selection);
  45595. Transforms.select(editor, end);
  45596. }
  45597. },
  45598. /**
  45599. * Unset the selection.
  45600. */
  45601. deselect(editor) {
  45602. var {
  45603. selection
  45604. } = editor;
  45605. if (selection) {
  45606. editor.apply({
  45607. type: 'set_selection',
  45608. properties: selection,
  45609. newProperties: null
  45610. });
  45611. }
  45612. },
  45613. /**
  45614. * Move the selection's point forward or backward.
  45615. */
  45616. move(editor) {
  45617. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  45618. var {
  45619. selection
  45620. } = editor;
  45621. var {
  45622. distance = 1,
  45623. unit = 'character',
  45624. reverse = false
  45625. } = options;
  45626. var {
  45627. edge = null
  45628. } = options;
  45629. if (!selection) {
  45630. return;
  45631. }
  45632. if (edge === 'start') {
  45633. edge = Range.isBackward(selection) ? 'focus' : 'anchor';
  45634. }
  45635. if (edge === 'end') {
  45636. edge = Range.isBackward(selection) ? 'anchor' : 'focus';
  45637. }
  45638. var {
  45639. anchor,
  45640. focus
  45641. } = selection;
  45642. var opts = {
  45643. distance,
  45644. unit
  45645. };
  45646. var props = {};
  45647. if (edge == null || edge === 'anchor') {
  45648. var point = reverse ? Editor.before(editor, anchor, opts) : Editor.after(editor, anchor, opts);
  45649. if (point) {
  45650. props.anchor = point;
  45651. }
  45652. }
  45653. if (edge == null || edge === 'focus') {
  45654. var _point = reverse ? Editor.before(editor, focus, opts) : Editor.after(editor, focus, opts);
  45655. if (_point) {
  45656. props.focus = _point;
  45657. }
  45658. }
  45659. Transforms.setSelection(editor, props);
  45660. },
  45661. /**
  45662. * Set the selection to a new value.
  45663. */
  45664. select(editor, target) {
  45665. var {
  45666. selection
  45667. } = editor;
  45668. target = Editor.range(editor, target);
  45669. if (selection) {
  45670. Transforms.setSelection(editor, target);
  45671. return;
  45672. }
  45673. if (!Range.isRange(target)) {
  45674. throw new Error("When setting the selection and the current selection is `null` you must provide at least an `anchor` and `focus`, but you passed: ".concat(JSON.stringify(target)));
  45675. }
  45676. editor.apply({
  45677. type: 'set_selection',
  45678. properties: selection,
  45679. newProperties: target
  45680. });
  45681. },
  45682. /**
  45683. * Set new properties on one of the selection's points.
  45684. */
  45685. setPoint(editor, props, options) {
  45686. var {
  45687. selection
  45688. } = editor;
  45689. var {
  45690. edge = 'both'
  45691. } = options;
  45692. if (!selection) {
  45693. return;
  45694. }
  45695. if (edge === 'start') {
  45696. edge = Range.isBackward(selection) ? 'focus' : 'anchor';
  45697. }
  45698. if (edge === 'end') {
  45699. edge = Range.isBackward(selection) ? 'anchor' : 'focus';
  45700. }
  45701. var {
  45702. anchor,
  45703. focus
  45704. } = selection;
  45705. var point = edge === 'anchor' ? anchor : focus;
  45706. var newPoint = Object.assign(point, props);
  45707. if (edge === 'anchor') {
  45708. Transforms.setSelection(editor, {
  45709. anchor: newPoint
  45710. });
  45711. } else {
  45712. Transforms.setSelection(editor, {
  45713. focus: newPoint
  45714. });
  45715. }
  45716. },
  45717. /**
  45718. * Set new properties on the selection.
  45719. */
  45720. setSelection(editor, props) {
  45721. var {
  45722. selection
  45723. } = editor;
  45724. var oldProps = {};
  45725. var newProps = {};
  45726. if (!selection) {
  45727. return;
  45728. }
  45729. for (var k in props) {
  45730. if (k === 'anchor' && props.anchor != null && !Point.equals(props.anchor, selection.anchor) || k === 'focus' && props.focus != null && !Point.equals(props.focus, selection.focus) || k !== 'anchor' && k !== 'focus' && props[k] !== selection[k]) {
  45731. oldProps[k] = selection[k];
  45732. newProps[k] = props[k];
  45733. }
  45734. }
  45735. if (Object.keys(oldProps).length > 0) {
  45736. editor.apply({
  45737. type: 'set_selection',
  45738. properties: oldProps,
  45739. newProperties: newProps
  45740. });
  45741. }
  45742. }
  45743. };
  45744. var TextTransforms = {
  45745. /**
  45746. * Delete content in the editor.
  45747. */
  45748. delete(editor) {
  45749. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  45750. Editor.withoutNormalizing(editor, () => {
  45751. var {
  45752. reverse = false,
  45753. unit = 'character',
  45754. distance = 1,
  45755. voids = false
  45756. } = options;
  45757. var {
  45758. at = editor.selection,
  45759. hanging = false
  45760. } = options;
  45761. if (!at) {
  45762. return;
  45763. }
  45764. if (Range.isRange(at) && Range.isCollapsed(at)) {
  45765. at = at.anchor;
  45766. }
  45767. if (Point.isPoint(at)) {
  45768. var furthestVoid = Editor.void(editor, {
  45769. at,
  45770. mode: 'highest'
  45771. });
  45772. if (!voids && furthestVoid) {
  45773. var [, voidPath] = furthestVoid;
  45774. at = voidPath;
  45775. } else {
  45776. var opts = {
  45777. unit,
  45778. distance
  45779. };
  45780. var target = reverse ? Editor.before(editor, at, opts) || Editor.start(editor, []) : Editor.after(editor, at, opts) || Editor.end(editor, []);
  45781. at = {
  45782. anchor: at,
  45783. focus: target
  45784. };
  45785. hanging = true;
  45786. }
  45787. }
  45788. if (Path.isPath(at)) {
  45789. Transforms.removeNodes(editor, {
  45790. at,
  45791. voids
  45792. });
  45793. return;
  45794. }
  45795. if (Range.isCollapsed(at)) {
  45796. return;
  45797. }
  45798. if (!hanging) {
  45799. at = Editor.unhangRange(editor, at, {
  45800. voids
  45801. });
  45802. }
  45803. var [start, end] = Range.edges(at);
  45804. var startBlock = Editor.above(editor, {
  45805. match: n => Editor.isBlock(editor, n),
  45806. at: start,
  45807. voids
  45808. });
  45809. var endBlock = Editor.above(editor, {
  45810. match: n => Editor.isBlock(editor, n),
  45811. at: end,
  45812. voids
  45813. });
  45814. var isAcrossBlocks = startBlock && endBlock && !Path.equals(startBlock[1], endBlock[1]);
  45815. var isSingleText = Path.equals(start.path, end.path);
  45816. var startVoid = voids ? null : Editor.void(editor, {
  45817. at: start,
  45818. mode: 'highest'
  45819. });
  45820. var endVoid = voids ? null : Editor.void(editor, {
  45821. at: end,
  45822. mode: 'highest'
  45823. }); // If the start or end points are inside an inline void, nudge them out.
  45824. if (startVoid) {
  45825. var before = Editor.before(editor, start);
  45826. if (before && startBlock && Path.isAncestor(startBlock[1], before.path)) {
  45827. start = before;
  45828. }
  45829. }
  45830. if (endVoid) {
  45831. var after = Editor.after(editor, end);
  45832. if (after && endBlock && Path.isAncestor(endBlock[1], after.path)) {
  45833. end = after;
  45834. }
  45835. } // Get the highest nodes that are completely inside the range, as well as
  45836. // the start and end nodes.
  45837. var matches = [];
  45838. var lastPath;
  45839. for (var entry of Editor.nodes(editor, {
  45840. at,
  45841. voids
  45842. })) {
  45843. var [node, path] = entry;
  45844. if (lastPath && Path.compare(path, lastPath) === 0) {
  45845. continue;
  45846. }
  45847. if (!voids && Editor.isVoid(editor, node) || !Path.isCommon(path, start.path) && !Path.isCommon(path, end.path)) {
  45848. matches.push(entry);
  45849. lastPath = path;
  45850. }
  45851. }
  45852. var pathRefs = Array.from(matches, (_ref) => {
  45853. var [, p] = _ref;
  45854. return Editor.pathRef(editor, p);
  45855. });
  45856. var startRef = Editor.pointRef(editor, start);
  45857. var endRef = Editor.pointRef(editor, end);
  45858. if (!isSingleText && !startVoid) {
  45859. var _point = startRef.current;
  45860. var [_node] = Editor.leaf(editor, _point);
  45861. var {
  45862. path: _path
  45863. } = _point;
  45864. var {
  45865. offset
  45866. } = start;
  45867. var text = _node.text.slice(offset);
  45868. editor.apply({
  45869. type: 'remove_text',
  45870. path: _path,
  45871. offset,
  45872. text
  45873. });
  45874. }
  45875. for (var pathRef of pathRefs) {
  45876. var _path2 = pathRef.unref();
  45877. Transforms.removeNodes(editor, {
  45878. at: _path2,
  45879. voids
  45880. });
  45881. }
  45882. if (!endVoid) {
  45883. var _point2 = endRef.current;
  45884. var [_node2] = Editor.leaf(editor, _point2);
  45885. var {
  45886. path: _path3
  45887. } = _point2;
  45888. var _offset = isSingleText ? start.offset : 0;
  45889. var _text = _node2.text.slice(_offset, end.offset);
  45890. editor.apply({
  45891. type: 'remove_text',
  45892. path: _path3,
  45893. offset: _offset,
  45894. text: _text
  45895. });
  45896. }
  45897. if (!isSingleText && isAcrossBlocks && endRef.current && startRef.current) {
  45898. Transforms.mergeNodes(editor, {
  45899. at: endRef.current,
  45900. hanging: true,
  45901. voids
  45902. });
  45903. }
  45904. var point = endRef.unref() || startRef.unref();
  45905. if (options.at == null && point) {
  45906. Transforms.select(editor, point);
  45907. }
  45908. });
  45909. },
  45910. /**
  45911. * Insert a fragment at a specific location in the editor.
  45912. */
  45913. insertFragment(editor, fragment) {
  45914. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  45915. Editor.withoutNormalizing(editor, () => {
  45916. var {
  45917. hanging = false,
  45918. voids = false
  45919. } = options;
  45920. var {
  45921. at = editor.selection
  45922. } = options;
  45923. if (!fragment.length) {
  45924. return;
  45925. }
  45926. if (!at) {
  45927. return;
  45928. } else if (Range.isRange(at)) {
  45929. if (!hanging) {
  45930. at = Editor.unhangRange(editor, at);
  45931. }
  45932. if (Range.isCollapsed(at)) {
  45933. at = at.anchor;
  45934. } else {
  45935. var [, end] = Range.edges(at);
  45936. if (!voids && Editor.void(editor, {
  45937. at: end
  45938. })) {
  45939. return;
  45940. }
  45941. var pointRef = Editor.pointRef(editor, end);
  45942. Transforms.delete(editor, {
  45943. at
  45944. });
  45945. at = pointRef.unref();
  45946. }
  45947. } else if (Path.isPath(at)) {
  45948. at = Editor.start(editor, at);
  45949. }
  45950. if (!voids && Editor.void(editor, {
  45951. at
  45952. })) {
  45953. return;
  45954. } // If the insert point is at the edge of an inline node, move it outside
  45955. // instead since it will need to be split otherwise.
  45956. var inlineElementMatch = Editor.above(editor, {
  45957. at,
  45958. match: n => Editor.isInline(editor, n),
  45959. mode: 'highest',
  45960. voids
  45961. });
  45962. if (inlineElementMatch) {
  45963. var [, _inlinePath] = inlineElementMatch;
  45964. if (Editor.isEnd(editor, at, _inlinePath)) {
  45965. var after = Editor.after(editor, _inlinePath);
  45966. at = after;
  45967. } else if (Editor.isStart(editor, at, _inlinePath)) {
  45968. var before = Editor.before(editor, _inlinePath);
  45969. at = before;
  45970. }
  45971. }
  45972. var blockMatch = Editor.above(editor, {
  45973. match: n => Editor.isBlock(editor, n),
  45974. at,
  45975. voids
  45976. });
  45977. var [, blockPath] = blockMatch;
  45978. var isBlockStart = Editor.isStart(editor, at, blockPath);
  45979. var isBlockEnd = Editor.isEnd(editor, at, blockPath);
  45980. var mergeStart = !isBlockStart || isBlockStart && isBlockEnd;
  45981. var mergeEnd = !isBlockEnd;
  45982. var [, firstPath] = Node.first({
  45983. children: fragment
  45984. }, []);
  45985. var [, lastPath] = Node.last({
  45986. children: fragment
  45987. }, []);
  45988. var matches = [];
  45989. var matcher = (_ref2) => {
  45990. var [n, p] = _ref2;
  45991. if (mergeStart && Path.isAncestor(p, firstPath) && Element.isElement(n) && !editor.isVoid(n) && !editor.isInline(n)) {
  45992. return false;
  45993. }
  45994. if (mergeEnd && Path.isAncestor(p, lastPath) && Element.isElement(n) && !editor.isVoid(n) && !editor.isInline(n)) {
  45995. return false;
  45996. }
  45997. return true;
  45998. };
  45999. for (var entry of Node.nodes({
  46000. children: fragment
  46001. }, {
  46002. pass: matcher
  46003. })) {
  46004. if (entry[1].length > 0 && matcher(entry)) {
  46005. matches.push(entry);
  46006. }
  46007. }
  46008. var starts = [];
  46009. var middles = [];
  46010. var ends = [];
  46011. var starting = true;
  46012. var hasBlocks = false;
  46013. for (var [node] of matches) {
  46014. if (Element.isElement(node) && !editor.isInline(node)) {
  46015. starting = false;
  46016. hasBlocks = true;
  46017. middles.push(node);
  46018. } else if (starting) {
  46019. starts.push(node);
  46020. } else {
  46021. ends.push(node);
  46022. }
  46023. }
  46024. var [inlineMatch] = Editor.nodes(editor, {
  46025. at,
  46026. match: n => Text.isText(n) || Editor.isInline(editor, n),
  46027. mode: 'highest',
  46028. voids
  46029. });
  46030. var [, inlinePath] = inlineMatch;
  46031. var isInlineStart = Editor.isStart(editor, at, inlinePath);
  46032. var isInlineEnd = Editor.isEnd(editor, at, inlinePath);
  46033. var middleRef = Editor.pathRef(editor, isBlockEnd ? Path.next(blockPath) : blockPath);
  46034. var endRef = Editor.pathRef(editor, isInlineEnd ? Path.next(inlinePath) : inlinePath);
  46035. Transforms.splitNodes(editor, {
  46036. at,
  46037. match: n => hasBlocks ? Editor.isBlock(editor, n) : Text.isText(n) || Editor.isInline(editor, n),
  46038. mode: hasBlocks ? 'lowest' : 'highest',
  46039. voids
  46040. });
  46041. var startRef = Editor.pathRef(editor, !isInlineStart || isInlineStart && isInlineEnd ? Path.next(inlinePath) : inlinePath);
  46042. Transforms.insertNodes(editor, starts, {
  46043. at: startRef.current,
  46044. match: n => Text.isText(n) || Editor.isInline(editor, n),
  46045. mode: 'highest',
  46046. voids
  46047. });
  46048. Transforms.insertNodes(editor, middles, {
  46049. at: middleRef.current,
  46050. match: n => Editor.isBlock(editor, n),
  46051. mode: 'lowest',
  46052. voids
  46053. });
  46054. Transforms.insertNodes(editor, ends, {
  46055. at: endRef.current,
  46056. match: n => Text.isText(n) || Editor.isInline(editor, n),
  46057. mode: 'highest',
  46058. voids
  46059. });
  46060. if (!options.at) {
  46061. var path;
  46062. if (ends.length > 0) {
  46063. path = Path.previous(endRef.current);
  46064. } else if (middles.length > 0) {
  46065. path = Path.previous(middleRef.current);
  46066. } else {
  46067. path = Path.previous(startRef.current);
  46068. }
  46069. var _end = Editor.end(editor, path);
  46070. Transforms.select(editor, _end);
  46071. }
  46072. startRef.unref();
  46073. middleRef.unref();
  46074. endRef.unref();
  46075. });
  46076. },
  46077. /**
  46078. * Insert a string of text in the Editor.
  46079. */
  46080. insertText(editor, text) {
  46081. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  46082. Editor.withoutNormalizing(editor, () => {
  46083. var {
  46084. voids = false
  46085. } = options;
  46086. var {
  46087. at = editor.selection
  46088. } = options;
  46089. if (!at) {
  46090. return;
  46091. }
  46092. if (Path.isPath(at)) {
  46093. at = Editor.range(editor, at);
  46094. }
  46095. if (Range.isRange(at)) {
  46096. if (Range.isCollapsed(at)) {
  46097. at = at.anchor;
  46098. } else {
  46099. var end = Range.end(at);
  46100. if (!voids && Editor.void(editor, {
  46101. at: end
  46102. })) {
  46103. return;
  46104. }
  46105. var pointRef = Editor.pointRef(editor, end);
  46106. Transforms.delete(editor, {
  46107. at,
  46108. voids
  46109. });
  46110. at = pointRef.unref();
  46111. Transforms.setSelection(editor, {
  46112. anchor: at,
  46113. focus: at
  46114. });
  46115. }
  46116. }
  46117. if (!voids && Editor.void(editor, {
  46118. at
  46119. })) {
  46120. return;
  46121. }
  46122. var {
  46123. path,
  46124. offset
  46125. } = at;
  46126. editor.apply({
  46127. type: 'insert_text',
  46128. path,
  46129. offset,
  46130. text
  46131. });
  46132. });
  46133. }
  46134. };
  46135. function ownKeys$8(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  46136. function _objectSpread$8(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$8(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$8(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  46137. var Transforms = _objectSpread$8({}, GeneralTransforms, {}, NodeTransforms, {}, SelectionTransforms, {}, TextTransforms);
  46138. exports.Editor = Editor;
  46139. exports.Element = Element;
  46140. exports.Location = Location;
  46141. exports.Node = Node;
  46142. exports.Operation = Operation;
  46143. exports.Path = Path;
  46144. exports.PathRef = PathRef;
  46145. exports.Point = Point;
  46146. exports.PointRef = PointRef;
  46147. exports.Range = Range;
  46148. exports.RangeRef = RangeRef;
  46149. exports.Span = Span;
  46150. exports.Text = Text;
  46151. exports.Transforms = Transforms;
  46152. exports.createEditor = createEditor;
  46153. });
  46154. unwrapExports(dist$5);
  46155. var dist_1$3 = dist$5.Editor;
  46156. var dist_2$3 = dist$5.Element;
  46157. var dist_3$3 = dist$5.Location;
  46158. var dist_4$1 = dist$5.Node;
  46159. var dist_5$1 = dist$5.Operation;
  46160. var dist_6$1 = dist$5.Path;
  46161. var dist_7 = dist$5.PathRef;
  46162. var dist_8 = dist$5.Point;
  46163. var dist_9 = dist$5.PointRef;
  46164. var dist_10 = dist$5.Range;
  46165. var dist_11 = dist$5.RangeRef;
  46166. var dist_12 = dist$5.Span;
  46167. var dist_13 = dist$5.Text;
  46168. var dist_14 = dist$5.Transforms;
  46169. var dist_15 = dist$5.createEditor;
  46170. /**
  46171. * Returns a function, that, as long as it continues to be invoked, will not
  46172. * be triggered. The function will be called after it stops being called for
  46173. * N milliseconds. If `immediate` is passed, trigger the function on the
  46174. * leading edge, instead of the trailing. The function also has a property 'clear'
  46175. * that is a function which will clear the timer to prevent previously scheduled executions.
  46176. *
  46177. * @source underscore.js
  46178. * @see http://unscriptable.com/2009/03/20/debouncing-javascript-methods/
  46179. * @param {Function} function to wrap
  46180. * @param {Number} timeout in ms (`100`)
  46181. * @param {Boolean} whether to execute at the beginning (`false`)
  46182. * @api public
  46183. */
  46184. function debounce(func, wait, immediate){
  46185. var timeout, args, context, timestamp, result;
  46186. if (null == wait) wait = 100;
  46187. function later() {
  46188. var last = Date.now() - timestamp;
  46189. if (last < wait && last >= 0) {
  46190. timeout = setTimeout(later, wait - last);
  46191. } else {
  46192. timeout = null;
  46193. if (!immediate) {
  46194. result = func.apply(context, args);
  46195. context = args = null;
  46196. }
  46197. }
  46198. }
  46199. var debounced = function(){
  46200. context = this;
  46201. args = arguments;
  46202. timestamp = Date.now();
  46203. var callNow = immediate && !timeout;
  46204. if (!timeout) timeout = setTimeout(later, wait);
  46205. if (callNow) {
  46206. result = func.apply(context, args);
  46207. context = args = null;
  46208. }
  46209. return result;
  46210. };
  46211. debounced.clear = function() {
  46212. if (timeout) {
  46213. clearTimeout(timeout);
  46214. timeout = null;
  46215. }
  46216. };
  46217. debounced.flush = function() {
  46218. if (timeout) {
  46219. result = func.apply(context, args);
  46220. context = args = null;
  46221. clearTimeout(timeout);
  46222. timeout = null;
  46223. }
  46224. };
  46225. return debounced;
  46226. }
  46227. // Adds compatibility for ES modules
  46228. debounce.debounce = debounce;
  46229. var debounce_1 = debounce;
  46230. var computeScrollIntoView = createCommonjsModule(function (module, exports) {
  46231. exports.__esModule = true;
  46232. exports["default"] = void 0;
  46233. function isElement(el) {
  46234. return el != null && typeof el === 'object' && el.nodeType === 1;
  46235. }
  46236. function canOverflow(overflow, skipOverflowHiddenElements) {
  46237. if (skipOverflowHiddenElements && overflow === 'hidden') {
  46238. return false;
  46239. }
  46240. return overflow !== 'visible' && overflow !== 'clip';
  46241. }
  46242. function getFrameElement(el) {
  46243. if (!el.ownerDocument || !el.ownerDocument.defaultView) {
  46244. return null;
  46245. }
  46246. return el.ownerDocument.defaultView.frameElement;
  46247. }
  46248. function isHiddenByFrame(el) {
  46249. var frame = getFrameElement(el);
  46250. if (!frame) {
  46251. return false;
  46252. }
  46253. return frame.clientHeight < el.scrollHeight || frame.clientWidth < el.scrollWidth;
  46254. }
  46255. function isScrollable(el, skipOverflowHiddenElements) {
  46256. if (el.clientHeight < el.scrollHeight || el.clientWidth < el.scrollWidth) {
  46257. var style = getComputedStyle(el, null);
  46258. return canOverflow(style.overflowY, skipOverflowHiddenElements) || canOverflow(style.overflowX, skipOverflowHiddenElements) || isHiddenByFrame(el);
  46259. }
  46260. return false;
  46261. }
  46262. function alignNearest(scrollingEdgeStart, scrollingEdgeEnd, scrollingSize, scrollingBorderStart, scrollingBorderEnd, elementEdgeStart, elementEdgeEnd, elementSize) {
  46263. if (elementEdgeStart < scrollingEdgeStart && elementEdgeEnd > scrollingEdgeEnd || elementEdgeStart > scrollingEdgeStart && elementEdgeEnd < scrollingEdgeEnd) {
  46264. return 0;
  46265. }
  46266. if (elementEdgeStart <= scrollingEdgeStart && elementSize <= scrollingSize || elementEdgeEnd >= scrollingEdgeEnd && elementSize >= scrollingSize) {
  46267. return elementEdgeStart - scrollingEdgeStart - scrollingBorderStart;
  46268. }
  46269. if (elementEdgeEnd > scrollingEdgeEnd && elementSize < scrollingSize || elementEdgeStart < scrollingEdgeStart && elementSize > scrollingSize) {
  46270. return elementEdgeEnd - scrollingEdgeEnd + scrollingBorderEnd;
  46271. }
  46272. return 0;
  46273. }
  46274. var _default = function _default(target, options) {
  46275. var scrollMode = options.scrollMode,
  46276. block = options.block,
  46277. inline = options.inline,
  46278. boundary = options.boundary,
  46279. skipOverflowHiddenElements = options.skipOverflowHiddenElements;
  46280. var checkBoundary = typeof boundary === 'function' ? boundary : function (node) {
  46281. return node !== boundary;
  46282. };
  46283. if (!isElement(target)) {
  46284. throw new TypeError('Invalid target');
  46285. }
  46286. var scrollingElement = document.scrollingElement || document.documentElement;
  46287. var frames = [];
  46288. var cursor = target;
  46289. while (isElement(cursor) && checkBoundary(cursor)) {
  46290. cursor = cursor.parentNode;
  46291. if (cursor === scrollingElement) {
  46292. frames.push(cursor);
  46293. break;
  46294. }
  46295. if (cursor === document.body && isScrollable(cursor) && !isScrollable(document.documentElement)) {
  46296. continue;
  46297. }
  46298. if (isScrollable(cursor, skipOverflowHiddenElements)) {
  46299. frames.push(cursor);
  46300. }
  46301. }
  46302. var viewportWidth = window.visualViewport ? visualViewport.width : innerWidth;
  46303. var viewportHeight = window.visualViewport ? visualViewport.height : innerHeight;
  46304. var viewportX = window.scrollX || pageXOffset;
  46305. var viewportY = window.scrollY || pageYOffset;
  46306. var _target$getBoundingCl = target.getBoundingClientRect(),
  46307. targetHeight = _target$getBoundingCl.height,
  46308. targetWidth = _target$getBoundingCl.width,
  46309. targetTop = _target$getBoundingCl.top,
  46310. targetRight = _target$getBoundingCl.right,
  46311. targetBottom = _target$getBoundingCl.bottom,
  46312. targetLeft = _target$getBoundingCl.left;
  46313. var targetBlock = block === 'start' || block === 'nearest' ? targetTop : block === 'end' ? targetBottom : targetTop + targetHeight / 2;
  46314. var targetInline = inline === 'center' ? targetLeft + targetWidth / 2 : inline === 'end' ? targetRight : targetLeft;
  46315. var computations = [];
  46316. for (var index = 0; index < frames.length; index++) {
  46317. var frame = frames[index];
  46318. var _frame$getBoundingCli = frame.getBoundingClientRect(),
  46319. height = _frame$getBoundingCli.height,
  46320. width = _frame$getBoundingCli.width,
  46321. top = _frame$getBoundingCli.top,
  46322. right = _frame$getBoundingCli.right,
  46323. bottom = _frame$getBoundingCli.bottom,
  46324. left = _frame$getBoundingCli.left;
  46325. if (scrollMode === 'if-needed' && targetTop >= 0 && targetLeft >= 0 && targetBottom <= viewportHeight && targetRight <= viewportWidth && targetTop >= top && targetBottom <= bottom && targetLeft >= left && targetRight <= right) {
  46326. return computations;
  46327. }
  46328. var frameStyle = getComputedStyle(frame);
  46329. var borderLeft = parseInt(frameStyle.borderLeftWidth, 10);
  46330. var borderTop = parseInt(frameStyle.borderTopWidth, 10);
  46331. var borderRight = parseInt(frameStyle.borderRightWidth, 10);
  46332. var borderBottom = parseInt(frameStyle.borderBottomWidth, 10);
  46333. var blockScroll = 0;
  46334. var inlineScroll = 0;
  46335. var scrollbarWidth = 'offsetWidth' in frame ? frame.offsetWidth - frame.clientWidth - borderLeft - borderRight : 0;
  46336. var scrollbarHeight = 'offsetHeight' in frame ? frame.offsetHeight - frame.clientHeight - borderTop - borderBottom : 0;
  46337. if (scrollingElement === frame) {
  46338. if (block === 'start') {
  46339. blockScroll = targetBlock;
  46340. } else if (block === 'end') {
  46341. blockScroll = targetBlock - viewportHeight;
  46342. } else if (block === 'nearest') {
  46343. blockScroll = alignNearest(viewportY, viewportY + viewportHeight, viewportHeight, borderTop, borderBottom, viewportY + targetBlock, viewportY + targetBlock + targetHeight, targetHeight);
  46344. } else {
  46345. blockScroll = targetBlock - viewportHeight / 2;
  46346. }
  46347. if (inline === 'start') {
  46348. inlineScroll = targetInline;
  46349. } else if (inline === 'center') {
  46350. inlineScroll = targetInline - viewportWidth / 2;
  46351. } else if (inline === 'end') {
  46352. inlineScroll = targetInline - viewportWidth;
  46353. } else {
  46354. inlineScroll = alignNearest(viewportX, viewportX + viewportWidth, viewportWidth, borderLeft, borderRight, viewportX + targetInline, viewportX + targetInline + targetWidth, targetWidth);
  46355. }
  46356. blockScroll = Math.max(0, blockScroll + viewportY);
  46357. inlineScroll = Math.max(0, inlineScroll + viewportX);
  46358. } else {
  46359. if (block === 'start') {
  46360. blockScroll = targetBlock - top - borderTop;
  46361. } else if (block === 'end') {
  46362. blockScroll = targetBlock - bottom + borderBottom + scrollbarHeight;
  46363. } else if (block === 'nearest') {
  46364. blockScroll = alignNearest(top, bottom, height, borderTop, borderBottom + scrollbarHeight, targetBlock, targetBlock + targetHeight, targetHeight);
  46365. } else {
  46366. blockScroll = targetBlock - (top + height / 2) + scrollbarHeight / 2;
  46367. }
  46368. if (inline === 'start') {
  46369. inlineScroll = targetInline - left - borderLeft;
  46370. } else if (inline === 'center') {
  46371. inlineScroll = targetInline - (left + width / 2) + scrollbarWidth / 2;
  46372. } else if (inline === 'end') {
  46373. inlineScroll = targetInline - right + borderRight + scrollbarWidth;
  46374. } else {
  46375. inlineScroll = alignNearest(left, right, width, borderLeft, borderRight + scrollbarWidth, targetInline, targetInline + targetWidth, targetWidth);
  46376. }
  46377. var scrollLeft = frame.scrollLeft,
  46378. scrollTop = frame.scrollTop;
  46379. blockScroll = Math.max(0, Math.min(scrollTop + blockScroll, frame.scrollHeight - height + scrollbarHeight));
  46380. inlineScroll = Math.max(0, Math.min(scrollLeft + inlineScroll, frame.scrollWidth - width + scrollbarWidth));
  46381. targetBlock += scrollTop - blockScroll;
  46382. targetInline += scrollLeft - inlineScroll;
  46383. }
  46384. computations.push({
  46385. el: frame,
  46386. top: blockScroll,
  46387. left: inlineScroll
  46388. });
  46389. }
  46390. return computations;
  46391. };
  46392. exports["default"] = _default;
  46393. module.exports = exports.default;
  46394. });
  46395. unwrapExports(computeScrollIntoView);
  46396. var scrollIntoViewIfNeeded = createCommonjsModule(function (module, exports) {
  46397. exports.__esModule = true;
  46398. exports["default"] = void 0;
  46399. var _computeScrollIntoView = _interopRequireDefault(computeScrollIntoView);
  46400. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  46401. function isOptionsObject(options) {
  46402. return options === Object(options) && Object.keys(options).length !== 0;
  46403. }
  46404. function defaultBehavior(actions, behavior) {
  46405. if (behavior === void 0) {
  46406. behavior = 'auto';
  46407. }
  46408. var canSmoothScroll = 'scrollBehavior' in document.body.style;
  46409. actions.forEach(function (_ref) {
  46410. var el = _ref.el,
  46411. top = _ref.top,
  46412. left = _ref.left;
  46413. if (el.scroll && canSmoothScroll) {
  46414. el.scroll({
  46415. top: top,
  46416. left: left,
  46417. behavior: behavior
  46418. });
  46419. } else {
  46420. el.scrollTop = top;
  46421. el.scrollLeft = left;
  46422. }
  46423. });
  46424. }
  46425. function getOptions(options) {
  46426. if (options === false) {
  46427. return {
  46428. block: 'end',
  46429. inline: 'nearest'
  46430. };
  46431. }
  46432. if (isOptionsObject(options)) {
  46433. return options;
  46434. }
  46435. return {
  46436. block: 'start',
  46437. inline: 'nearest'
  46438. };
  46439. }
  46440. function scrollIntoView(target, options) {
  46441. var targetIsDetached = !target.ownerDocument.documentElement.contains(target);
  46442. if (isOptionsObject(options) && typeof options.behavior === 'function') {
  46443. return options.behavior(targetIsDetached ? [] : (0, _computeScrollIntoView["default"])(target, options));
  46444. }
  46445. if (targetIsDetached) {
  46446. return;
  46447. }
  46448. var computeOptions = getOptions(options);
  46449. return defaultBehavior((0, _computeScrollIntoView["default"])(target, computeOptions), computeOptions.behavior);
  46450. }
  46451. var _default = scrollIntoView;
  46452. exports["default"] = _default;
  46453. module.exports = exports.default;
  46454. });
  46455. unwrapExports(scrollIntoViewIfNeeded);
  46456. var direction_1 = direction;
  46457. var RTL$1 = '\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC';
  46458. var LTR$1 =
  46459. 'A-Za-z\u00C0-\u00D6\u00D8-\u00F6' +
  46460. '\u00F8-\u02B8\u0300-\u0590\u0800-\u1FFF\u200E\u2C00-\uFB1C' +
  46461. '\uFE00-\uFE6F\uFEFD-\uFFFF';
  46462. var rtl = new RegExp('^[^' + LTR$1 + ']*[' + RTL$1 + ']');
  46463. var ltr = new RegExp('^[^' + RTL$1 + ']*[' + LTR$1 + ']');
  46464. function direction(value) {
  46465. value = String(value || '');
  46466. if (rtl.test(value)) {
  46467. return 'rtl'
  46468. }
  46469. if (ltr.test(value)) {
  46470. return 'ltr'
  46471. }
  46472. return 'neutral'
  46473. }
  46474. var lib$1 = createCommonjsModule(function (module, exports) {
  46475. Object.defineProperty(exports, "__esModule", {
  46476. value: true
  46477. });
  46478. /**
  46479. * Constants.
  46480. */
  46481. var IS_MAC = typeof window != 'undefined' && /Mac|iPod|iPhone|iPad/.test(window.navigator.platform);
  46482. var MODIFIERS = {
  46483. alt: 'altKey',
  46484. control: 'ctrlKey',
  46485. meta: 'metaKey',
  46486. shift: 'shiftKey'
  46487. };
  46488. var ALIASES = {
  46489. add: '+',
  46490. break: 'pause',
  46491. cmd: 'meta',
  46492. command: 'meta',
  46493. ctl: 'control',
  46494. ctrl: 'control',
  46495. del: 'delete',
  46496. down: 'arrowdown',
  46497. esc: 'escape',
  46498. ins: 'insert',
  46499. left: 'arrowleft',
  46500. mod: IS_MAC ? 'meta' : 'control',
  46501. opt: 'alt',
  46502. option: 'alt',
  46503. return: 'enter',
  46504. right: 'arrowright',
  46505. space: ' ',
  46506. spacebar: ' ',
  46507. up: 'arrowup',
  46508. win: 'meta',
  46509. windows: 'meta'
  46510. };
  46511. var CODES = {
  46512. backspace: 8,
  46513. tab: 9,
  46514. enter: 13,
  46515. shift: 16,
  46516. control: 17,
  46517. alt: 18,
  46518. pause: 19,
  46519. capslock: 20,
  46520. escape: 27,
  46521. ' ': 32,
  46522. pageup: 33,
  46523. pagedown: 34,
  46524. end: 35,
  46525. home: 36,
  46526. arrowleft: 37,
  46527. arrowup: 38,
  46528. arrowright: 39,
  46529. arrowdown: 40,
  46530. insert: 45,
  46531. delete: 46,
  46532. meta: 91,
  46533. numlock: 144,
  46534. scrolllock: 145,
  46535. ';': 186,
  46536. '=': 187,
  46537. ',': 188,
  46538. '-': 189,
  46539. '.': 190,
  46540. '/': 191,
  46541. '`': 192,
  46542. '[': 219,
  46543. '\\': 220,
  46544. ']': 221,
  46545. '\'': 222
  46546. };
  46547. for (var f = 1; f < 20; f++) {
  46548. CODES['f' + f] = 111 + f;
  46549. }
  46550. /**
  46551. * Is hotkey?
  46552. */
  46553. function isHotkey(hotkey, options, event) {
  46554. if (options && !('byKey' in options)) {
  46555. event = options;
  46556. options = null;
  46557. }
  46558. if (!Array.isArray(hotkey)) {
  46559. hotkey = [hotkey];
  46560. }
  46561. var array = hotkey.map(function (string) {
  46562. return parseHotkey(string, options);
  46563. });
  46564. var check = function check(e) {
  46565. return array.some(function (object) {
  46566. return compareHotkey(object, e);
  46567. });
  46568. };
  46569. var ret = event == null ? check : check(event);
  46570. return ret;
  46571. }
  46572. function isCodeHotkey(hotkey, event) {
  46573. return isHotkey(hotkey, event);
  46574. }
  46575. function isKeyHotkey(hotkey, event) {
  46576. return isHotkey(hotkey, { byKey: true }, event);
  46577. }
  46578. /**
  46579. * Parse.
  46580. */
  46581. function parseHotkey(hotkey, options) {
  46582. var byKey = options && options.byKey;
  46583. var ret = {};
  46584. // Special case to handle the `+` key since we use it as a separator.
  46585. hotkey = hotkey.replace('++', '+add');
  46586. var values = hotkey.split('+');
  46587. var length = values.length;
  46588. // Ensure that all the modifiers are set to false unless the hotkey has them.
  46589. for (var k in MODIFIERS) {
  46590. ret[MODIFIERS[k]] = false;
  46591. }
  46592. var _iteratorNormalCompletion = true;
  46593. var _didIteratorError = false;
  46594. var _iteratorError = undefined;
  46595. try {
  46596. for (var _iterator = values[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  46597. var value = _step.value;
  46598. var optional = value.endsWith('?') && value.length > 1;
  46599. if (optional) {
  46600. value = value.slice(0, -1);
  46601. }
  46602. var name = toKeyName(value);
  46603. var modifier = MODIFIERS[name];
  46604. if (length === 1 || !modifier) {
  46605. if (byKey) {
  46606. ret.key = name;
  46607. } else {
  46608. ret.which = toKeyCode(value);
  46609. }
  46610. }
  46611. if (modifier) {
  46612. ret[modifier] = optional ? null : true;
  46613. }
  46614. }
  46615. } catch (err) {
  46616. _didIteratorError = true;
  46617. _iteratorError = err;
  46618. } finally {
  46619. try {
  46620. if (!_iteratorNormalCompletion && _iterator.return) {
  46621. _iterator.return();
  46622. }
  46623. } finally {
  46624. if (_didIteratorError) {
  46625. throw _iteratorError;
  46626. }
  46627. }
  46628. }
  46629. return ret;
  46630. }
  46631. /**
  46632. * Compare.
  46633. */
  46634. function compareHotkey(object, event) {
  46635. for (var key in object) {
  46636. var expected = object[key];
  46637. var actual = void 0;
  46638. if (expected == null) {
  46639. continue;
  46640. }
  46641. if (key === 'key' && event.key != null) {
  46642. actual = event.key.toLowerCase();
  46643. } else if (key === 'which') {
  46644. actual = expected === 91 && event.which === 93 ? 91 : event.which;
  46645. } else {
  46646. actual = event[key];
  46647. }
  46648. if (actual == null && expected === false) {
  46649. continue;
  46650. }
  46651. if (actual !== expected) {
  46652. return false;
  46653. }
  46654. }
  46655. return true;
  46656. }
  46657. /**
  46658. * Utils.
  46659. */
  46660. function toKeyCode(name) {
  46661. name = toKeyName(name);
  46662. var code = CODES[name] || name.toUpperCase().charCodeAt(0);
  46663. return code;
  46664. }
  46665. function toKeyName(name) {
  46666. name = name.toLowerCase();
  46667. name = ALIASES[name] || name;
  46668. return name;
  46669. }
  46670. /**
  46671. * Export.
  46672. */
  46673. exports.default = isHotkey;
  46674. exports.isHotkey = isHotkey;
  46675. exports.isCodeHotkey = isCodeHotkey;
  46676. exports.isKeyHotkey = isKeyHotkey;
  46677. exports.parseHotkey = parseHotkey;
  46678. exports.compareHotkey = compareHotkey;
  46679. exports.toKeyCode = toKeyCode;
  46680. exports.toKeyName = toKeyName;
  46681. });
  46682. unwrapExports(lib$1);
  46683. var lib_1 = lib$1.isHotkey;
  46684. var lib_2 = lib$1.isCodeHotkey;
  46685. var lib_3 = lib$1.isKeyHotkey;
  46686. var lib_4 = lib$1.parseHotkey;
  46687. var lib_5 = lib$1.compareHotkey;
  46688. var lib_6 = lib$1.toKeyCode;
  46689. var lib_7 = lib$1.toKeyName;
  46690. var dist$6 = createCommonjsModule(function (module, exports) {
  46691. Object.defineProperty(exports, '__esModule', { value: true });
  46692. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  46693. var React__default = _interopDefault(React);
  46694. var debounce = _interopDefault(debounce_1);
  46695. var scrollIntoView = _interopDefault(scrollIntoViewIfNeeded);
  46696. var getDirection = _interopDefault(direction_1);
  46697. var ReactDOM = _interopDefault(reactDom);
  46698. /**
  46699. * Leaf content strings.
  46700. */
  46701. const String = (props) => {
  46702. const { isLast, leaf, parent, text } = props;
  46703. const editor = useEditor();
  46704. const path = ReactEditor.findPath(editor, text);
  46705. const parentPath = dist$5.Path.parent(path);
  46706. // COMPAT: Render text inside void nodes with a zero-width space.
  46707. // So the node can contain selection but the text is not visible.
  46708. if (editor.isVoid(parent)) {
  46709. return React__default.createElement(ZeroWidthString, { length: dist$5.Node.string(parent).length });
  46710. }
  46711. // COMPAT: If this is the last text node in an empty block, render a zero-
  46712. // width space that will convert into a line break when copying and pasting
  46713. // to support expected plain text.
  46714. if (leaf.text === '' &&
  46715. parent.children[parent.children.length - 1] === text &&
  46716. !editor.isInline(parent) &&
  46717. dist$5.Editor.string(editor, parentPath) === '') {
  46718. return React__default.createElement(ZeroWidthString, { isLineBreak: true });
  46719. }
  46720. // COMPAT: If the text is empty, it's because it's on the edge of an inline
  46721. // node, so we render a zero-width space so that the selection can be
  46722. // inserted next to it still.
  46723. if (leaf.text === '') {
  46724. return React__default.createElement(ZeroWidthString, null);
  46725. }
  46726. // COMPAT: Browsers will collapse trailing new lines at the end of blocks,
  46727. // so we need to add an extra trailing new lines to prevent that.
  46728. if (isLast && leaf.text.slice(-1) === '\n') {
  46729. return React__default.createElement(TextString, { isTrailing: true, text: leaf.text });
  46730. }
  46731. return React__default.createElement(TextString, { text: leaf.text });
  46732. };
  46733. /**
  46734. * Leaf strings with text in them.
  46735. */
  46736. const TextString = (props) => {
  46737. const { text, isTrailing = false } = props;
  46738. return (React__default.createElement("span", { "data-slate-string": true },
  46739. text,
  46740. isTrailing ? '\n' : null));
  46741. };
  46742. /**
  46743. * Leaf strings without text, render as zero-width strings.
  46744. */
  46745. const ZeroWidthString = (props) => {
  46746. const { length = 0, isLineBreak = false } = props;
  46747. return (React__default.createElement("span", { "data-slate-zero-width": isLineBreak ? 'n' : 'z', "data-slate-length": length },
  46748. '\uFEFF',
  46749. isLineBreak ? React__default.createElement("br", null) : null));
  46750. };
  46751. /**
  46752. * Two weak maps that allow us rebuild a path given a node. They are populated
  46753. * at render time such that after a render occurs we can always backtrack.
  46754. */
  46755. var NODE_TO_INDEX = new WeakMap();
  46756. var NODE_TO_PARENT = new WeakMap();
  46757. /**
  46758. * Weak maps that allow us to go between Slate nodes and DOM nodes. These
  46759. * are used to resolve DOM event-related logic into Slate actions.
  46760. */
  46761. var EDITOR_TO_ELEMENT = new WeakMap();
  46762. var ELEMENT_TO_NODE = new WeakMap();
  46763. var KEY_TO_ELEMENT = new WeakMap();
  46764. var NODE_TO_ELEMENT = new WeakMap();
  46765. var NODE_TO_KEY = new WeakMap();
  46766. /**
  46767. * Weak maps for storing editor-related state.
  46768. */
  46769. var IS_READ_ONLY = new WeakMap();
  46770. var IS_FOCUSED = new WeakMap();
  46771. /**
  46772. * Weak map for associating the context `onChange` context with the plugin.
  46773. */
  46774. var EDITOR_TO_ON_CHANGE = new WeakMap();
  46775. /**
  46776. * Symbols.
  46777. */
  46778. var PLACEHOLDER_SYMBOL = Symbol('placeholder');
  46779. /**
  46780. * Individual leaves in a text node with unique formatting.
  46781. */
  46782. const Leaf = (props) => {
  46783. const { leaf, isLast, text, parent, renderLeaf = (props) => React__default.createElement(DefaultLeaf, Object.assign({}, props)), } = props;
  46784. let children = (React__default.createElement(String, { isLast: isLast, leaf: leaf, parent: parent, text: text }));
  46785. if (leaf[PLACEHOLDER_SYMBOL]) {
  46786. children = (React__default.createElement(React__default.Fragment, null,
  46787. React__default.createElement("span", { contentEditable: false, style: {
  46788. pointerEvents: 'none',
  46789. display: 'inline-block',
  46790. verticalAlign: 'text-top',
  46791. width: '0',
  46792. maxWidth: '100%',
  46793. whiteSpace: 'nowrap',
  46794. opacity: '0.333',
  46795. } }, leaf.placeholder),
  46796. children));
  46797. }
  46798. // COMPAT: Having the `data-` attributes on these leaf elements ensures that
  46799. // in certain misbehaving browsers they aren't weirdly cloned/destroyed by
  46800. // contenteditable behaviors. (2019/05/08)
  46801. const attributes = {
  46802. 'data-slate-leaf': true,
  46803. };
  46804. return renderLeaf({ attributes, children, leaf, text });
  46805. };
  46806. const MemoizedLeaf = React__default.memo(Leaf, (prev, next) => {
  46807. return (next.parent === prev.parent &&
  46808. next.isLast === prev.isLast &&
  46809. next.renderLeaf === prev.renderLeaf &&
  46810. next.text === prev.text &&
  46811. dist$5.Text.matches(next.leaf, prev.leaf));
  46812. });
  46813. /**
  46814. * The default custom leaf renderer.
  46815. */
  46816. const DefaultLeaf = (props) => {
  46817. const { attributes, children } = props;
  46818. return React__default.createElement("span", Object.assign({}, attributes), children);
  46819. };
  46820. /**
  46821. * Prevent warning on SSR by falling back to useEffect when window is not defined
  46822. */
  46823. var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
  46824. /**
  46825. * Text.
  46826. */
  46827. const Text = (props) => {
  46828. const { decorations, isLast, parent, renderLeaf, text } = props;
  46829. const editor = useEditor();
  46830. const ref = React.useRef(null);
  46831. const leaves = dist$5.Text.decorations(text, decorations);
  46832. const key = ReactEditor.findKey(editor, text);
  46833. const children = [];
  46834. for (let i = 0; i < leaves.length; i++) {
  46835. const leaf = leaves[i];
  46836. children.push(React__default.createElement(MemoizedLeaf, { isLast: isLast && i === leaves.length - 1, key: `${key.id}-${i}`, leaf: leaf, text: text, parent: parent, renderLeaf: renderLeaf }));
  46837. }
  46838. // Update element-related weak maps with the DOM element ref.
  46839. useIsomorphicLayoutEffect(() => {
  46840. if (ref.current) {
  46841. KEY_TO_ELEMENT.set(key, ref.current);
  46842. NODE_TO_ELEMENT.set(text, ref.current);
  46843. ELEMENT_TO_NODE.set(ref.current, text);
  46844. }
  46845. else {
  46846. KEY_TO_ELEMENT.delete(key);
  46847. NODE_TO_ELEMENT.delete(text);
  46848. }
  46849. });
  46850. return (React__default.createElement("span", { "data-slate-node": "text", ref: ref }, children));
  46851. };
  46852. const MemoizedText = React__default.memo(Text, (prev, next) => {
  46853. return (next.parent === prev.parent &&
  46854. next.isLast === prev.isLast &&
  46855. next.renderLeaf === prev.renderLeaf &&
  46856. next.text === prev.text);
  46857. });
  46858. /**
  46859. * A React context for sharing the `selected` state of an element.
  46860. */
  46861. var SelectedContext = React.createContext(false);
  46862. /**
  46863. * Get the current `selected` state of an element.
  46864. */
  46865. var useSelected = () => {
  46866. return React.useContext(SelectedContext);
  46867. };
  46868. /**
  46869. * Element.
  46870. */
  46871. const Element = (props) => {
  46872. const { decorate, decorations, element, renderElement = (p) => React__default.createElement(DefaultElement, Object.assign({}, p)), renderLeaf, selection, } = props;
  46873. const ref = React.useRef(null);
  46874. const editor = useEditor();
  46875. const readOnly = useReadOnly();
  46876. const isInline = editor.isInline(element);
  46877. const key = ReactEditor.findKey(editor, element);
  46878. let children = (React__default.createElement(Children, { decorate: decorate, decorations: decorations, node: element, renderElement: renderElement, renderLeaf: renderLeaf, selection: selection }));
  46879. // Attributes that the developer must mix into the element in their
  46880. // custom node renderer component.
  46881. const attributes = {
  46882. 'data-slate-node': 'element',
  46883. ref,
  46884. };
  46885. if (isInline) {
  46886. attributes['data-slate-inline'] = true;
  46887. }
  46888. // If it's a block node with inline children, add the proper `dir` attribute
  46889. // for text direction.
  46890. if (!isInline && dist$5.Editor.hasInlines(editor, element)) {
  46891. const text = dist$5.Node.string(element);
  46892. const dir = getDirection(text);
  46893. if (dir === 'rtl') {
  46894. attributes.dir = dir;
  46895. }
  46896. }
  46897. // If it's a void node, wrap the children in extra void-specific elements.
  46898. if (dist$5.Editor.isVoid(editor, element)) {
  46899. attributes['data-slate-void'] = true;
  46900. if (!readOnly && isInline) {
  46901. attributes.contentEditable = false;
  46902. }
  46903. const Tag = isInline ? 'span' : 'div';
  46904. const [[text]] = dist$5.Node.texts(element);
  46905. children = readOnly ? null : (React__default.createElement(Tag, { "data-slate-spacer": true, style: {
  46906. height: '0',
  46907. color: 'transparent',
  46908. outline: 'none',
  46909. position: 'absolute',
  46910. } },
  46911. React__default.createElement(MemoizedText, { decorations: [], isLast: false, parent: element, text: text })));
  46912. NODE_TO_INDEX.set(text, 0);
  46913. NODE_TO_PARENT.set(text, element);
  46914. }
  46915. // Update element-related weak maps with the DOM element ref.
  46916. useIsomorphicLayoutEffect(() => {
  46917. if (ref.current) {
  46918. KEY_TO_ELEMENT.set(key, ref.current);
  46919. NODE_TO_ELEMENT.set(element, ref.current);
  46920. ELEMENT_TO_NODE.set(ref.current, element);
  46921. }
  46922. else {
  46923. KEY_TO_ELEMENT.delete(key);
  46924. NODE_TO_ELEMENT.delete(element);
  46925. }
  46926. });
  46927. return (React__default.createElement(SelectedContext.Provider, { value: !!selection }, renderElement({ attributes, children, element })));
  46928. };
  46929. const MemoizedElement = React__default.memo(Element, (prev, next) => {
  46930. return (prev.decorate === next.decorate &&
  46931. prev.element === next.element &&
  46932. prev.renderElement === next.renderElement &&
  46933. prev.renderLeaf === next.renderLeaf &&
  46934. isRangeListEqual(prev.decorations, next.decorations) &&
  46935. (prev.selection === next.selection ||
  46936. (!!prev.selection &&
  46937. !!next.selection &&
  46938. dist$5.Range.equals(prev.selection, next.selection))));
  46939. });
  46940. /**
  46941. * The default element renderer.
  46942. */
  46943. const DefaultElement = (props) => {
  46944. const { attributes, children, element } = props;
  46945. const editor = useEditor();
  46946. const Tag = editor.isInline(element) ? 'span' : 'div';
  46947. return (React__default.createElement(Tag, Object.assign({}, attributes, { style: { position: 'relative' } }), children));
  46948. };
  46949. /**
  46950. * Check if a list of ranges is equal to another.
  46951. *
  46952. * PERF: this requires the two lists to also have the ranges inside them in the
  46953. * same order, but this is an okay constraint for us since decorations are
  46954. * kept in order, and the odd case where they aren't is okay to re-render for.
  46955. */
  46956. const isRangeListEqual = (list, another) => {
  46957. if (list.length !== another.length) {
  46958. return false;
  46959. }
  46960. for (let i = 0; i < list.length; i++) {
  46961. const range = list[i];
  46962. const other = another[i];
  46963. if (!dist$5.Range.equals(range, other)) {
  46964. return false;
  46965. }
  46966. }
  46967. return true;
  46968. };
  46969. /**
  46970. * A React context for sharing the editor object.
  46971. */
  46972. const EditorContext = React.createContext(null);
  46973. /**
  46974. * Get the current editor object from the React context.
  46975. */
  46976. const useEditor = () => {
  46977. const editor = React.useContext(EditorContext);
  46978. if (!editor) {
  46979. throw new Error(`The \`useEditor\` hook must be used inside the <Slate> component's context.`);
  46980. }
  46981. return editor;
  46982. };
  46983. /**
  46984. * Children.
  46985. */
  46986. const Children = (props) => {
  46987. const { decorate, decorations, node, renderElement, renderLeaf, selection, } = props;
  46988. const editor = useEditor();
  46989. const path = ReactEditor.findPath(editor, node);
  46990. const children = [];
  46991. const isLeafBlock = dist$5.Element.isElement(node) &&
  46992. !editor.isInline(node) &&
  46993. dist$5.Editor.hasInlines(editor, node);
  46994. for (let i = 0; i < node.children.length; i++) {
  46995. const p = path.concat(i);
  46996. const n = node.children[i];
  46997. const key = ReactEditor.findKey(editor, n);
  46998. const range = dist$5.Editor.range(editor, p);
  46999. const sel = selection && dist$5.Range.intersection(range, selection);
  47000. const ds = decorate([n, p]);
  47001. for (const dec of decorations) {
  47002. const d = dist$5.Range.intersection(dec, range);
  47003. if (d) {
  47004. ds.push(d);
  47005. }
  47006. }
  47007. if (dist$5.Element.isElement(n)) {
  47008. children.push(React__default.createElement(MemoizedElement, { decorate: decorate, decorations: ds, element: n, key: key.id, renderElement: renderElement, renderLeaf: renderLeaf, selection: sel }));
  47009. }
  47010. else {
  47011. children.push(React__default.createElement(MemoizedText, { decorations: ds, key: key.id, isLast: isLeafBlock && i === node.children.length - 1, parent: node, renderLeaf: renderLeaf, text: n }));
  47012. }
  47013. NODE_TO_INDEX.set(n, i);
  47014. NODE_TO_PARENT.set(n, node);
  47015. }
  47016. return React__default.createElement(React__default.Fragment, null, children);
  47017. };
  47018. var IS_IOS = typeof navigator !== 'undefined' && typeof window !== 'undefined' && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
  47019. var IS_APPLE = typeof navigator !== 'undefined' && /Mac OS X/.test(navigator.userAgent);
  47020. var IS_FIREFOX = typeof navigator !== 'undefined' && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
  47021. var IS_SAFARI = typeof navigator !== 'undefined' && /Version\/[\d\.]+.*Safari/.test(navigator.userAgent);
  47022. /**
  47023. * Hotkey mappings for each platform.
  47024. */
  47025. var HOTKEYS = {
  47026. bold: 'mod+b',
  47027. compose: ['down', 'left', 'right', 'up', 'backspace', 'enter'],
  47028. moveBackward: 'left',
  47029. moveForward: 'right',
  47030. moveWordBackward: 'ctrl+left',
  47031. moveWordForward: 'ctrl+right',
  47032. deleteBackward: 'shift?+backspace',
  47033. deleteForward: 'shift?+delete',
  47034. extendBackward: 'shift+left',
  47035. extendForward: 'shift+right',
  47036. italic: 'mod+i',
  47037. splitBlock: 'shift?+enter',
  47038. undo: 'mod+z'
  47039. };
  47040. var APPLE_HOTKEYS = {
  47041. moveLineBackward: 'opt+up',
  47042. moveLineForward: 'opt+down',
  47043. moveWordBackward: 'opt+left',
  47044. moveWordForward: 'opt+right',
  47045. deleteBackward: ['ctrl+backspace', 'ctrl+h'],
  47046. deleteForward: ['ctrl+delete', 'ctrl+d'],
  47047. deleteLineBackward: 'cmd+shift?+backspace',
  47048. deleteLineForward: ['cmd+shift?+delete', 'ctrl+k'],
  47049. deleteWordBackward: 'opt+shift?+backspace',
  47050. deleteWordForward: 'opt+shift?+delete',
  47051. extendLineBackward: 'opt+shift+up',
  47052. extendLineForward: 'opt+shift+down',
  47053. redo: 'cmd+shift+z',
  47054. transposeCharacter: 'ctrl+t'
  47055. };
  47056. var WINDOWS_HOTKEYS = {
  47057. deleteWordBackward: 'ctrl+shift?+backspace',
  47058. deleteWordForward: 'ctrl+shift?+delete',
  47059. redo: ['ctrl+y', 'ctrl+shift+z']
  47060. };
  47061. /**
  47062. * Create a platform-aware hotkey checker.
  47063. */
  47064. var create = key => {
  47065. var generic = HOTKEYS[key];
  47066. var apple = APPLE_HOTKEYS[key];
  47067. var windows = WINDOWS_HOTKEYS[key];
  47068. var isGeneric = generic && lib$1.isKeyHotkey(generic);
  47069. var isApple = apple && lib$1.isKeyHotkey(apple);
  47070. var isWindows = windows && lib$1.isKeyHotkey(windows);
  47071. return event => {
  47072. if (isGeneric && isGeneric(event)) return true;
  47073. if (IS_APPLE && isApple && isApple(event)) return true;
  47074. if (!IS_APPLE && isWindows && isWindows(event)) return true;
  47075. return false;
  47076. };
  47077. };
  47078. /**
  47079. * Hotkeys.
  47080. */
  47081. var Hotkeys = {
  47082. isBold: create('bold'),
  47083. isCompose: create('compose'),
  47084. isMoveBackward: create('moveBackward'),
  47085. isMoveForward: create('moveForward'),
  47086. isDeleteBackward: create('deleteBackward'),
  47087. isDeleteForward: create('deleteForward'),
  47088. isDeleteLineBackward: create('deleteLineBackward'),
  47089. isDeleteLineForward: create('deleteLineForward'),
  47090. isDeleteWordBackward: create('deleteWordBackward'),
  47091. isDeleteWordForward: create('deleteWordForward'),
  47092. isExtendBackward: create('extendBackward'),
  47093. isExtendForward: create('extendForward'),
  47094. isExtendLineBackward: create('extendLineBackward'),
  47095. isExtendLineForward: create('extendLineForward'),
  47096. isItalic: create('italic'),
  47097. isMoveLineBackward: create('moveLineBackward'),
  47098. isMoveLineForward: create('moveLineForward'),
  47099. isMoveWordBackward: create('moveWordBackward'),
  47100. isMoveWordForward: create('moveWordForward'),
  47101. isRedo: create('redo'),
  47102. isSplitBlock: create('splitBlock'),
  47103. isTransposeCharacter: create('transposeCharacter'),
  47104. isUndo: create('undo')
  47105. };
  47106. /**
  47107. * A React context for sharing the `readOnly` state of the editor.
  47108. */
  47109. var ReadOnlyContext = React.createContext(false);
  47110. /**
  47111. * Get the current `readOnly` state of the editor.
  47112. */
  47113. var useReadOnly = () => {
  47114. return React.useContext(ReadOnlyContext);
  47115. };
  47116. /**
  47117. * A React context for sharing the editor object, in a way that re-renders the
  47118. * context whenever changes occur.
  47119. */
  47120. const SlateContext = React.createContext(null);
  47121. /**
  47122. * Get the current editor object from the React context.
  47123. */
  47124. const useSlate = () => {
  47125. const context = React.useContext(SlateContext);
  47126. if (!context) {
  47127. throw new Error(`The \`useSlate\` hook must be used inside the <SlateProvider> component's context.`);
  47128. }
  47129. const [editor] = context;
  47130. return editor;
  47131. };
  47132. /**
  47133. * Types.
  47134. */
  47135. /**
  47136. * Check if a DOM node is a comment node.
  47137. */
  47138. var isDOMComment = value => {
  47139. return isDOMNode(value) && value.nodeType === 8;
  47140. };
  47141. /**
  47142. * Check if a DOM node is an element node.
  47143. */
  47144. var isDOMElement = value => {
  47145. return isDOMNode(value) && value.nodeType === 1;
  47146. };
  47147. /**
  47148. * Check if a value is a DOM node.
  47149. */
  47150. var isDOMNode = value => {
  47151. return value instanceof Node;
  47152. };
  47153. /**
  47154. * Check if a DOM node is an element node.
  47155. */
  47156. var isDOMText = value => {
  47157. return isDOMNode(value) && value.nodeType === 3;
  47158. };
  47159. /**
  47160. * Normalize a DOM point so that it always refers to a text node.
  47161. */
  47162. var normalizeDOMPoint = domPoint => {
  47163. var [node, offset] = domPoint; // If it's an element node, its offset refers to the index of its children
  47164. // including comment nodes, so try to find the right text child node.
  47165. if (isDOMElement(node) && node.childNodes.length) {
  47166. var isLast = offset === node.childNodes.length;
  47167. var direction = isLast ? 'backward' : 'forward';
  47168. var index = isLast ? offset - 1 : offset;
  47169. node = getEditableChild(node, index, direction); // If the node has children, traverse until we have a leaf node. Leaf nodes
  47170. // can be either text nodes, or other void DOM nodes.
  47171. while (isDOMElement(node) && node.childNodes.length) {
  47172. var i = isLast ? node.childNodes.length - 1 : 0;
  47173. node = getEditableChild(node, i, direction);
  47174. } // Determine the new offset inside the text node.
  47175. offset = isLast && node.textContent != null ? node.textContent.length : 0;
  47176. } // Return the node and offset.
  47177. return [node, offset];
  47178. };
  47179. /**
  47180. * Get the nearest editable child at `index` in a `parent`, preferring
  47181. * `direction`.
  47182. */
  47183. var getEditableChild = (parent, index, direction) => {
  47184. var {
  47185. childNodes
  47186. } = parent;
  47187. var child = childNodes[index];
  47188. var i = index;
  47189. var triedForward = false;
  47190. var triedBackward = false; // While the child is a comment node, or an element node with no children,
  47191. // keep iterating to find a sibling non-void, non-comment node.
  47192. while (isDOMComment(child) || isDOMElement(child) && child.childNodes.length === 0 || isDOMElement(child) && child.getAttribute('contenteditable') === 'false') {
  47193. if (triedForward && triedBackward) {
  47194. break;
  47195. }
  47196. if (i >= childNodes.length) {
  47197. triedForward = true;
  47198. i = index - 1;
  47199. direction = 'backward';
  47200. continue;
  47201. }
  47202. if (i < 0) {
  47203. triedBackward = true;
  47204. i = index + 1;
  47205. direction = 'forward';
  47206. continue;
  47207. }
  47208. child = childNodes[i];
  47209. i += direction === 'forward' ? 1 : -1;
  47210. }
  47211. return child;
  47212. };
  47213. /**
  47214. * Editable.
  47215. */
  47216. const Editable = (props) => {
  47217. const { autoFocus, decorate = defaultDecorate, onDOMBeforeInput: propsOnDOMBeforeInput, placeholder, readOnly = false, renderElement, renderLeaf, style = {}, as: Component = 'div', ...attributes } = props;
  47218. const editor = useSlate();
  47219. const ref = React.useRef(null);
  47220. // Update internal state on each render.
  47221. IS_READ_ONLY.set(editor, readOnly);
  47222. // Keep track of some state for the event handler logic.
  47223. const state = React.useMemo(() => ({
  47224. isComposing: false,
  47225. isUpdatingSelection: false,
  47226. latestElement: null,
  47227. }), []);
  47228. // Update element-related weak maps with the DOM element ref.
  47229. useIsomorphicLayoutEffect(() => {
  47230. if (ref.current) {
  47231. EDITOR_TO_ELEMENT.set(editor, ref.current);
  47232. NODE_TO_ELEMENT.set(editor, ref.current);
  47233. ELEMENT_TO_NODE.set(ref.current, editor);
  47234. }
  47235. else {
  47236. NODE_TO_ELEMENT.delete(editor);
  47237. }
  47238. });
  47239. // Attach a native DOM event handler for `selectionchange`, because React's
  47240. // built-in `onSelect` handler doesn't fire for all selection changes. It's a
  47241. // leaky polyfill that only fires on keypresses or clicks. Instead, we want to
  47242. // fire for any change to the selection inside the editor. (2019/11/04)
  47243. // https://github.com/facebook/react/issues/5785
  47244. useIsomorphicLayoutEffect(() => {
  47245. window.document.addEventListener('selectionchange', onDOMSelectionChange);
  47246. return () => {
  47247. window.document.removeEventListener('selectionchange', onDOMSelectionChange);
  47248. };
  47249. }, []);
  47250. // Attach a native DOM event handler for `beforeinput` events, because React's
  47251. // built-in `onBeforeInput` is actually a leaky polyfill that doesn't expose
  47252. // real `beforeinput` events sadly... (2019/11/04)
  47253. // https://github.com/facebook/react/issues/11211
  47254. useIsomorphicLayoutEffect(() => {
  47255. if (ref.current) {
  47256. // @ts-ignore The `beforeinput` event isn't recognized.
  47257. ref.current.addEventListener('beforeinput', onDOMBeforeInput);
  47258. }
  47259. return () => {
  47260. if (ref.current) {
  47261. // @ts-ignore The `beforeinput` event isn't recognized.
  47262. ref.current.removeEventListener('beforeinput', onDOMBeforeInput);
  47263. }
  47264. };
  47265. }, []);
  47266. // Whenever the editor updates, make sure the DOM selection state is in sync.
  47267. useIsomorphicLayoutEffect(() => {
  47268. const { selection } = editor;
  47269. const domSelection = window.getSelection();
  47270. if (state.isComposing || !domSelection || !ReactEditor.isFocused(editor)) {
  47271. return;
  47272. }
  47273. const hasDomSelection = domSelection.type !== 'None';
  47274. // If the DOM selection is properly unset, we're done.
  47275. if (!selection && !hasDomSelection) {
  47276. return;
  47277. }
  47278. const newDomRange = selection && ReactEditor.toDOMRange(editor, selection);
  47279. // If the DOM selection is already correct, we're done.
  47280. if (hasDomSelection &&
  47281. newDomRange &&
  47282. isRangeEqual(domSelection.getRangeAt(0), newDomRange)) {
  47283. return;
  47284. }
  47285. // Otherwise the DOM selection is out of sync, so update it.
  47286. const el = ReactEditor.toDOMNode(editor, editor);
  47287. state.isUpdatingSelection = true;
  47288. domSelection.removeAllRanges();
  47289. if (newDomRange) {
  47290. domSelection.addRange(newDomRange);
  47291. const leafEl = newDomRange.startContainer.parentElement;
  47292. scrollIntoView(leafEl, { scrollMode: 'if-needed' });
  47293. }
  47294. setTimeout(() => {
  47295. // COMPAT: In Firefox, it's not enough to create a range, you also need
  47296. // to focus the contenteditable element too. (2016/11/16)
  47297. if (newDomRange && IS_FIREFOX) {
  47298. el.focus();
  47299. }
  47300. state.isUpdatingSelection = false;
  47301. });
  47302. });
  47303. // The autoFocus TextareaHTMLAttribute doesn't do anything on a div, so it
  47304. // needs to be manually focused.
  47305. React.useEffect(() => {
  47306. if (ref.current && autoFocus) {
  47307. ref.current.focus();
  47308. }
  47309. }, [autoFocus]);
  47310. // Listen on the native `beforeinput` event to get real "Level 2" events. This
  47311. // is required because React's `beforeinput` is fake and never really attaches
  47312. // to the real event sadly. (2019/11/01)
  47313. // https://github.com/facebook/react/issues/11211
  47314. const onDOMBeforeInput = React.useCallback((event) => {
  47315. if (!readOnly &&
  47316. hasEditableTarget(editor, event.target) &&
  47317. !isDOMEventHandled(event, propsOnDOMBeforeInput)) {
  47318. const { selection } = editor;
  47319. const { inputType: type } = event;
  47320. const data = event.dataTransfer || event.data || undefined;
  47321. // These two types occur while a user is composing text and can't be
  47322. // cancelled. Let them through and wait for the composition to end.
  47323. if (type === 'insertCompositionText' ||
  47324. type === 'deleteCompositionText') {
  47325. return;
  47326. }
  47327. event.preventDefault();
  47328. // COMPAT: For the deleting forward/backward input types we don't want
  47329. // to change the selection because it is the range that will be deleted,
  47330. // and those commands determine that for themselves.
  47331. if (!type.startsWith('delete') || type.startsWith('deleteBy')) {
  47332. const [targetRange] = event.getTargetRanges();
  47333. if (targetRange) {
  47334. const range = ReactEditor.toSlateRange(editor, targetRange);
  47335. if (!selection || !dist$5.Range.equals(selection, range)) {
  47336. dist$5.Transforms.select(editor, range);
  47337. }
  47338. }
  47339. }
  47340. // COMPAT: If the selection is expanded, even if the command seems like
  47341. // a delete forward/backward command it should delete the selection.
  47342. if (selection &&
  47343. dist$5.Range.isExpanded(selection) &&
  47344. type.startsWith('delete')) {
  47345. dist$5.Editor.deleteFragment(editor);
  47346. return;
  47347. }
  47348. switch (type) {
  47349. case 'deleteByComposition':
  47350. case 'deleteByCut':
  47351. case 'deleteByDrag': {
  47352. dist$5.Editor.deleteFragment(editor);
  47353. break;
  47354. }
  47355. case 'deleteContent':
  47356. case 'deleteContentForward': {
  47357. dist$5.Editor.deleteForward(editor);
  47358. break;
  47359. }
  47360. case 'deleteContentBackward': {
  47361. dist$5.Editor.deleteBackward(editor);
  47362. break;
  47363. }
  47364. case 'deleteEntireSoftLine': {
  47365. dist$5.Editor.deleteBackward(editor, { unit: 'line' });
  47366. dist$5.Editor.deleteForward(editor, { unit: 'line' });
  47367. break;
  47368. }
  47369. case 'deleteHardLineBackward': {
  47370. dist$5.Editor.deleteBackward(editor, { unit: 'block' });
  47371. break;
  47372. }
  47373. case 'deleteSoftLineBackward': {
  47374. dist$5.Editor.deleteBackward(editor, { unit: 'line' });
  47375. break;
  47376. }
  47377. case 'deleteHardLineForward': {
  47378. dist$5.Editor.deleteForward(editor, { unit: 'block' });
  47379. break;
  47380. }
  47381. case 'deleteSoftLineForward': {
  47382. dist$5.Editor.deleteForward(editor, { unit: 'line' });
  47383. break;
  47384. }
  47385. case 'deleteWordBackward': {
  47386. dist$5.Editor.deleteBackward(editor, { unit: 'word' });
  47387. break;
  47388. }
  47389. case 'deleteWordForward': {
  47390. dist$5.Editor.deleteForward(editor, { unit: 'word' });
  47391. break;
  47392. }
  47393. case 'insertLineBreak':
  47394. case 'insertParagraph': {
  47395. dist$5.Editor.insertBreak(editor);
  47396. break;
  47397. }
  47398. case 'insertFromComposition':
  47399. case 'insertFromDrop':
  47400. case 'insertFromPaste':
  47401. case 'insertFromYank':
  47402. case 'insertReplacementText':
  47403. case 'insertText': {
  47404. if (data instanceof DataTransfer) {
  47405. ReactEditor.insertData(editor, data);
  47406. }
  47407. else if (typeof data === 'string') {
  47408. dist$5.Editor.insertText(editor, data);
  47409. }
  47410. break;
  47411. }
  47412. }
  47413. }
  47414. }, []);
  47415. // Listen on the native `selectionchange` event to be able to update any time
  47416. // the selection changes. This is required because React's `onSelect` is leaky
  47417. // and non-standard so it doesn't fire until after a selection has been
  47418. // released. This causes issues in situations where another change happens
  47419. // while a selection is being dragged.
  47420. const onDOMSelectionChange = React.useCallback(debounce(() => {
  47421. if (!readOnly && !state.isComposing && !state.isUpdatingSelection) {
  47422. const { activeElement } = window.document;
  47423. const el = ReactEditor.toDOMNode(editor, editor);
  47424. const domSelection = window.getSelection();
  47425. const domRange = domSelection &&
  47426. domSelection.rangeCount > 0 &&
  47427. domSelection.getRangeAt(0);
  47428. if (activeElement === el) {
  47429. state.latestElement = activeElement;
  47430. IS_FOCUSED.set(editor, true);
  47431. }
  47432. else {
  47433. IS_FOCUSED.delete(editor);
  47434. }
  47435. if (domRange &&
  47436. hasEditableTarget(editor, domRange.startContainer) &&
  47437. hasEditableTarget(editor, domRange.endContainer)) {
  47438. const range = ReactEditor.toSlateRange(editor, domRange);
  47439. dist$5.Transforms.select(editor, range);
  47440. }
  47441. else {
  47442. dist$5.Transforms.deselect(editor);
  47443. }
  47444. }
  47445. }, 100), []);
  47446. const decorations = decorate([editor, []]);
  47447. if (placeholder &&
  47448. editor.children.length === 1 &&
  47449. Array.from(dist$5.Node.texts(editor)).length === 1 &&
  47450. dist$5.Node.string(editor) === '') {
  47451. const start = dist$5.Editor.start(editor, []);
  47452. decorations.push({
  47453. [PLACEHOLDER_SYMBOL]: true,
  47454. placeholder,
  47455. anchor: start,
  47456. focus: start,
  47457. });
  47458. }
  47459. return (React__default.createElement(ReadOnlyContext.Provider, { value: readOnly },
  47460. React__default.createElement(Component
  47461. // COMPAT: The Grammarly Chrome extension works by changing the DOM
  47462. // out from under `contenteditable` elements, which leads to weird
  47463. // behaviors so we have to disable it like editor. (2017/04/24)
  47464. , Object.assign({ "data-gramm": false, role: readOnly ? undefined : 'textbox' }, attributes, {
  47465. // COMPAT: Firefox doesn't support the `beforeinput` event, so we'd
  47466. // have to use hacks to make these replacement-based features work.
  47467. spellCheck: IS_FIREFOX ? undefined : attributes.spellCheck, autoCorrect: IS_FIREFOX ? undefined : attributes.autoCorrect, autoCapitalize: IS_FIREFOX ? undefined : attributes.autoCapitalize, "data-slate-editor": true, "data-slate-node": "value", contentEditable: readOnly ? undefined : true, suppressContentEditableWarning: true, ref: ref, style: {
  47468. // Prevent the default outline styles.
  47469. outline: 'none',
  47470. // Preserve adjacent whitespace and new lines.
  47471. whiteSpace: 'pre-wrap',
  47472. // Allow words to break if they are too long.
  47473. wordWrap: 'break-word',
  47474. // Allow for passed-in styles to override anything.
  47475. ...style,
  47476. }, onBeforeInput: React.useCallback((event) => {
  47477. // COMPAT: Firefox doesn't support the `beforeinput` event, so we
  47478. // fall back to React's leaky polyfill instead just for it. It
  47479. // only works for the `insertText` input type.
  47480. if (IS_FIREFOX && !readOnly) {
  47481. event.preventDefault();
  47482. const text = event.data;
  47483. dist$5.Editor.insertText(editor, text);
  47484. }
  47485. }, [readOnly]), onBlur: React.useCallback((event) => {
  47486. if (readOnly ||
  47487. state.isUpdatingSelection ||
  47488. !hasEditableTarget(editor, event.target) ||
  47489. isEventHandled(event, attributes.onBlur)) {
  47490. return;
  47491. }
  47492. // COMPAT: If the current `activeElement` is still the previous
  47493. // one, this is due to the window being blurred when the tab
  47494. // itself becomes unfocused, so we want to abort early to allow to
  47495. // editor to stay focused when the tab becomes focused again.
  47496. if (state.latestElement === window.document.activeElement) {
  47497. return;
  47498. }
  47499. const { relatedTarget } = event;
  47500. const el = ReactEditor.toDOMNode(editor, editor);
  47501. // COMPAT: The event should be ignored if the focus is returning
  47502. // to the editor from an embedded editable element (eg. an <input>
  47503. // element inside a void node).
  47504. if (relatedTarget === el) {
  47505. return;
  47506. }
  47507. // COMPAT: The event should be ignored if the focus is moving from
  47508. // the editor to inside a void node's spacer element.
  47509. if (isDOMElement(relatedTarget) &&
  47510. relatedTarget.hasAttribute('data-slate-spacer')) {
  47511. return;
  47512. }
  47513. // COMPAT: The event should be ignored if the focus is moving to a
  47514. // non- editable section of an element that isn't a void node (eg.
  47515. // a list item of the check list example).
  47516. if (relatedTarget != null &&
  47517. isDOMNode(relatedTarget) &&
  47518. ReactEditor.hasDOMNode(editor, relatedTarget)) {
  47519. const node = ReactEditor.toSlateNode(editor, relatedTarget);
  47520. if (dist$5.Element.isElement(node) && !editor.isVoid(node)) {
  47521. return;
  47522. }
  47523. }
  47524. IS_FOCUSED.delete(editor);
  47525. }, [readOnly, attributes.onBlur]), onClick: React.useCallback((event) => {
  47526. if (!readOnly &&
  47527. hasTarget(editor, event.target) &&
  47528. !isEventHandled(event, attributes.onClick) &&
  47529. isDOMNode(event.target)) {
  47530. const node = ReactEditor.toSlateNode(editor, event.target);
  47531. const path = ReactEditor.findPath(editor, node);
  47532. const start = dist$5.Editor.start(editor, path);
  47533. if (dist$5.Editor.void(editor, { at: start })) {
  47534. const range = dist$5.Editor.range(editor, start);
  47535. dist$5.Transforms.select(editor, range);
  47536. }
  47537. }
  47538. }, [readOnly, attributes.onClick]), onCompositionEnd: React.useCallback((event) => {
  47539. if (hasEditableTarget(editor, event.target) &&
  47540. !isEventHandled(event, attributes.onCompositionEnd)) {
  47541. state.isComposing = false;
  47542. // COMPAT: In Chrome, `beforeinput` events for compositions
  47543. // aren't correct and never fire the "insertFromComposition"
  47544. // type that we need. So instead, insert whenever a composition
  47545. // ends since it will already have been committed to the DOM.
  47546. if (!IS_SAFARI && !IS_FIREFOX && event.data) {
  47547. dist$5.Editor.insertText(editor, event.data);
  47548. }
  47549. }
  47550. }, [attributes.onCompositionEnd]), onCompositionStart: React.useCallback((event) => {
  47551. if (hasEditableTarget(editor, event.target) &&
  47552. !isEventHandled(event, attributes.onCompositionStart)) {
  47553. state.isComposing = true;
  47554. }
  47555. }, [attributes.onCompositionStart]), onCopy: React.useCallback((event) => {
  47556. if (hasEditableTarget(editor, event.target) &&
  47557. !isEventHandled(event, attributes.onCopy)) {
  47558. event.preventDefault();
  47559. setFragmentData(event.clipboardData, editor);
  47560. }
  47561. }, [attributes.onCopy]), onCut: React.useCallback((event) => {
  47562. if (!readOnly &&
  47563. hasEditableTarget(editor, event.target) &&
  47564. !isEventHandled(event, attributes.onCut)) {
  47565. event.preventDefault();
  47566. setFragmentData(event.clipboardData, editor);
  47567. const { selection } = editor;
  47568. if (selection && dist$5.Range.isExpanded(selection)) {
  47569. dist$5.Editor.deleteFragment(editor);
  47570. }
  47571. }
  47572. }, [readOnly, attributes.onCut]), onDragOver: React.useCallback((event) => {
  47573. if (hasTarget(editor, event.target) &&
  47574. !isEventHandled(event, attributes.onDragOver)) {
  47575. // Only when the target is void, call `preventDefault` to signal
  47576. // that drops are allowed. Editable content is droppable by
  47577. // default, and calling `preventDefault` hides the cursor.
  47578. const node = ReactEditor.toSlateNode(editor, event.target);
  47579. if (dist$5.Editor.isVoid(editor, node)) {
  47580. event.preventDefault();
  47581. }
  47582. }
  47583. }, [attributes.onDragOver]), onDragStart: React.useCallback((event) => {
  47584. if (hasTarget(editor, event.target) &&
  47585. !isEventHandled(event, attributes.onDragStart)) {
  47586. const node = ReactEditor.toSlateNode(editor, event.target);
  47587. const path = ReactEditor.findPath(editor, node);
  47588. const voidMatch = dist$5.Editor.void(editor, { at: path });
  47589. // If starting a drag on a void node, make sure it is selected
  47590. // so that it shows up in the selection's fragment.
  47591. if (voidMatch) {
  47592. const range = dist$5.Editor.range(editor, path);
  47593. dist$5.Transforms.select(editor, range);
  47594. }
  47595. setFragmentData(event.dataTransfer, editor);
  47596. }
  47597. }, [attributes.onDragStart]), onDrop: React.useCallback((event) => {
  47598. if (hasTarget(editor, event.target) &&
  47599. !readOnly &&
  47600. !isEventHandled(event, attributes.onDrop)) {
  47601. // COMPAT: Firefox doesn't fire `beforeinput` events at all, and
  47602. // Chromium browsers don't properly fire them for files being
  47603. // dropped into a `contenteditable`. (2019/11/26)
  47604. // https://bugs.chromium.org/p/chromium/issues/detail?id=1028668
  47605. if (IS_FIREFOX ||
  47606. (!IS_SAFARI && event.dataTransfer.files.length > 0)) {
  47607. event.preventDefault();
  47608. const range = ReactEditor.findEventRange(editor, event);
  47609. const data = event.dataTransfer;
  47610. dist$5.Transforms.select(editor, range);
  47611. ReactEditor.insertData(editor, data);
  47612. }
  47613. }
  47614. }, [readOnly, attributes.onDrop]), onFocus: React.useCallback((event) => {
  47615. if (!readOnly &&
  47616. !state.isUpdatingSelection &&
  47617. hasEditableTarget(editor, event.target) &&
  47618. !isEventHandled(event, attributes.onFocus)) {
  47619. const el = ReactEditor.toDOMNode(editor, editor);
  47620. state.latestElement = window.document.activeElement;
  47621. // COMPAT: If the editor has nested editable elements, the focus
  47622. // can go to them. In Firefox, this must be prevented because it
  47623. // results in issues with keyboard navigation. (2017/03/30)
  47624. if (IS_FIREFOX && event.target !== el) {
  47625. el.focus();
  47626. return;
  47627. }
  47628. IS_FOCUSED.set(editor, true);
  47629. }
  47630. }, [readOnly, attributes.onFocus]), onKeyDown: React.useCallback((event) => {
  47631. if (!readOnly &&
  47632. hasEditableTarget(editor, event.target) &&
  47633. !isEventHandled(event, attributes.onKeyDown)) {
  47634. const { nativeEvent } = event;
  47635. const { selection } = editor;
  47636. // COMPAT: Since we prevent the default behavior on
  47637. // `beforeinput` events, the browser doesn't think there's ever
  47638. // any history stack to undo or redo, so we have to manage these
  47639. // hotkeys ourselves. (2019/11/06)
  47640. if (Hotkeys.isRedo(nativeEvent)) {
  47641. event.preventDefault();
  47642. if (editor.redo) {
  47643. editor.redo();
  47644. }
  47645. return;
  47646. }
  47647. if (Hotkeys.isUndo(nativeEvent)) {
  47648. event.preventDefault();
  47649. if (editor.undo) {
  47650. editor.undo();
  47651. }
  47652. return;
  47653. }
  47654. // COMPAT: Certain browsers don't handle the selection updates
  47655. // properly. In Chrome, the selection isn't properly extended.
  47656. // And in Firefox, the selection isn't properly collapsed.
  47657. // (2017/10/17)
  47658. if (Hotkeys.isMoveLineBackward(nativeEvent)) {
  47659. event.preventDefault();
  47660. dist$5.Transforms.move(editor, { unit: 'line', reverse: true });
  47661. return;
  47662. }
  47663. if (Hotkeys.isMoveLineForward(nativeEvent)) {
  47664. event.preventDefault();
  47665. dist$5.Transforms.move(editor, { unit: 'line' });
  47666. return;
  47667. }
  47668. if (Hotkeys.isExtendLineBackward(nativeEvent)) {
  47669. event.preventDefault();
  47670. dist$5.Transforms.move(editor, {
  47671. unit: 'line',
  47672. edge: 'focus',
  47673. reverse: true,
  47674. });
  47675. return;
  47676. }
  47677. if (Hotkeys.isExtendLineForward(nativeEvent)) {
  47678. event.preventDefault();
  47679. dist$5.Transforms.move(editor, { unit: 'line', edge: 'focus' });
  47680. return;
  47681. }
  47682. // COMPAT: If a void node is selected, or a zero-width text node
  47683. // adjacent to an inline is selected, we need to handle these
  47684. // hotkeys manually because browsers won't be able to skip over
  47685. // the void node with the zero-width space not being an empty
  47686. // string.
  47687. if (Hotkeys.isMoveBackward(nativeEvent)) {
  47688. event.preventDefault();
  47689. if (selection && dist$5.Range.isCollapsed(selection)) {
  47690. dist$5.Transforms.move(editor, { reverse: true });
  47691. }
  47692. else {
  47693. dist$5.Transforms.collapse(editor, { edge: 'start' });
  47694. }
  47695. return;
  47696. }
  47697. if (Hotkeys.isMoveForward(nativeEvent)) {
  47698. event.preventDefault();
  47699. if (selection && dist$5.Range.isCollapsed(selection)) {
  47700. dist$5.Transforms.move(editor);
  47701. }
  47702. else {
  47703. dist$5.Transforms.collapse(editor, { edge: 'end' });
  47704. }
  47705. return;
  47706. }
  47707. if (Hotkeys.isMoveWordBackward(nativeEvent)) {
  47708. event.preventDefault();
  47709. dist$5.Transforms.move(editor, { unit: 'word', reverse: true });
  47710. return;
  47711. }
  47712. if (Hotkeys.isMoveWordForward(nativeEvent)) {
  47713. event.preventDefault();
  47714. dist$5.Transforms.move(editor, { unit: 'word' });
  47715. return;
  47716. }
  47717. // COMPAT: Firefox doesn't support the `beforeinput` event, so we
  47718. // fall back to guessing at the input intention for hotkeys.
  47719. // COMPAT: In iOS, some of these hotkeys are handled in the
  47720. if (IS_FIREFOX) {
  47721. // We don't have a core behavior for these, but they change the
  47722. // DOM if we don't prevent them, so we have to.
  47723. if (Hotkeys.isBold(nativeEvent) ||
  47724. Hotkeys.isItalic(nativeEvent) ||
  47725. Hotkeys.isTransposeCharacter(nativeEvent)) {
  47726. event.preventDefault();
  47727. return;
  47728. }
  47729. if (Hotkeys.isSplitBlock(nativeEvent)) {
  47730. event.preventDefault();
  47731. dist$5.Editor.insertBreak(editor);
  47732. return;
  47733. }
  47734. if (Hotkeys.isDeleteBackward(nativeEvent)) {
  47735. event.preventDefault();
  47736. if (selection && dist$5.Range.isExpanded(selection)) {
  47737. dist$5.Editor.deleteFragment(editor);
  47738. }
  47739. else {
  47740. dist$5.Editor.deleteBackward(editor);
  47741. }
  47742. return;
  47743. }
  47744. if (Hotkeys.isDeleteForward(nativeEvent)) {
  47745. event.preventDefault();
  47746. if (selection && dist$5.Range.isExpanded(selection)) {
  47747. dist$5.Editor.deleteFragment(editor);
  47748. }
  47749. else {
  47750. dist$5.Editor.deleteForward(editor);
  47751. }
  47752. return;
  47753. }
  47754. if (Hotkeys.isDeleteLineBackward(nativeEvent)) {
  47755. event.preventDefault();
  47756. if (selection && dist$5.Range.isExpanded(selection)) {
  47757. dist$5.Editor.deleteFragment(editor);
  47758. }
  47759. else {
  47760. dist$5.Editor.deleteBackward(editor, { unit: 'line' });
  47761. }
  47762. return;
  47763. }
  47764. if (Hotkeys.isDeleteLineForward(nativeEvent)) {
  47765. event.preventDefault();
  47766. if (selection && dist$5.Range.isExpanded(selection)) {
  47767. dist$5.Editor.deleteFragment(editor);
  47768. }
  47769. else {
  47770. dist$5.Editor.deleteForward(editor, { unit: 'line' });
  47771. }
  47772. return;
  47773. }
  47774. if (Hotkeys.isDeleteWordBackward(nativeEvent)) {
  47775. event.preventDefault();
  47776. if (selection && dist$5.Range.isExpanded(selection)) {
  47777. dist$5.Editor.deleteFragment(editor);
  47778. }
  47779. else {
  47780. dist$5.Editor.deleteBackward(editor, { unit: 'word' });
  47781. }
  47782. return;
  47783. }
  47784. if (Hotkeys.isDeleteWordForward(nativeEvent)) {
  47785. event.preventDefault();
  47786. if (selection && dist$5.Range.isExpanded(selection)) {
  47787. dist$5.Editor.deleteFragment(editor);
  47788. }
  47789. else {
  47790. dist$5.Editor.deleteForward(editor, { unit: 'word' });
  47791. }
  47792. return;
  47793. }
  47794. }
  47795. }
  47796. }, [readOnly, attributes.onKeyDown]), onPaste: React.useCallback((event) => {
  47797. // COMPAT: Firefox doesn't support the `beforeinput` event, so we
  47798. // fall back to React's `onPaste` here instead.
  47799. if (IS_FIREFOX &&
  47800. !readOnly &&
  47801. hasEditableTarget(editor, event.target) &&
  47802. !isEventHandled(event, attributes.onPaste)) {
  47803. event.preventDefault();
  47804. ReactEditor.insertData(editor, event.clipboardData);
  47805. }
  47806. }, [readOnly, attributes.onPaste]) }),
  47807. React__default.createElement(Children, { decorate: decorate, decorations: decorations, node: editor, renderElement: renderElement, renderLeaf: renderLeaf, selection: editor.selection }))));
  47808. };
  47809. /**
  47810. * A default memoized decorate function.
  47811. */
  47812. const defaultDecorate = () => [];
  47813. /**
  47814. * Check if two DOM range objects are equal.
  47815. */
  47816. const isRangeEqual = (a, b) => {
  47817. return ((a.startContainer === b.startContainer &&
  47818. a.startOffset === b.startOffset &&
  47819. a.endContainer === b.endContainer &&
  47820. a.endOffset === b.endOffset) ||
  47821. (a.startContainer === b.endContainer &&
  47822. a.startOffset === b.endOffset &&
  47823. a.endContainer === b.startContainer &&
  47824. a.endOffset === b.startOffset));
  47825. };
  47826. /**
  47827. * Check if the target is in the editor.
  47828. */
  47829. const hasTarget = (editor, target) => {
  47830. return isDOMNode(target) && ReactEditor.hasDOMNode(editor, target);
  47831. };
  47832. /**
  47833. * Check if the target is editable and in the editor.
  47834. */
  47835. const hasEditableTarget = (editor, target) => {
  47836. return (isDOMNode(target) &&
  47837. ReactEditor.hasDOMNode(editor, target, { editable: true }));
  47838. };
  47839. /**
  47840. * Check if an event is overrided by a handler.
  47841. */
  47842. const isEventHandled = (event, handler) => {
  47843. if (!handler) {
  47844. return false;
  47845. }
  47846. handler(event);
  47847. return event.isDefaultPrevented() || event.isPropagationStopped();
  47848. };
  47849. /**
  47850. * Check if a DOM event is overrided by a handler.
  47851. */
  47852. const isDOMEventHandled = (event, handler) => {
  47853. if (!handler) {
  47854. return false;
  47855. }
  47856. handler(event);
  47857. return event.defaultPrevented;
  47858. };
  47859. /**
  47860. * Set the currently selected fragment to the clipboard.
  47861. */
  47862. const setFragmentData = (dataTransfer, editor) => {
  47863. const { selection } = editor;
  47864. if (!selection) {
  47865. return;
  47866. }
  47867. const [start, end] = dist$5.Range.edges(selection);
  47868. const startVoid = dist$5.Editor.void(editor, { at: start.path });
  47869. const endVoid = dist$5.Editor.void(editor, { at: end.path });
  47870. if (dist$5.Range.isCollapsed(selection) && !startVoid) {
  47871. return;
  47872. }
  47873. // Create a fake selection so that we can add a Base64-encoded copy of the
  47874. // fragment to the HTML, to decode on future pastes.
  47875. const domRange = ReactEditor.toDOMRange(editor, selection);
  47876. let contents = domRange.cloneContents();
  47877. let attach = contents.childNodes[0];
  47878. // Make sure attach is non-empty, since empty nodes will not get copied.
  47879. contents.childNodes.forEach(node => {
  47880. if (node.textContent && node.textContent.trim() !== '') {
  47881. attach = node;
  47882. }
  47883. });
  47884. // COMPAT: If the end node is a void node, we need to move the end of the
  47885. // range from the void node's spacer span, to the end of the void node's
  47886. // content, since the spacer is before void's content in the DOM.
  47887. if (endVoid) {
  47888. const [voidNode] = endVoid;
  47889. const r = domRange.cloneRange();
  47890. const domNode = ReactEditor.toDOMNode(editor, voidNode);
  47891. r.setEndAfter(domNode);
  47892. contents = r.cloneContents();
  47893. }
  47894. // COMPAT: If the start node is a void node, we need to attach the encoded
  47895. // fragment to the void node's content node instead of the spacer, because
  47896. // attaching it to empty `<div>/<span>` nodes will end up having it erased by
  47897. // most browsers. (2018/04/27)
  47898. if (startVoid) {
  47899. attach = contents.querySelector('[data-slate-spacer]');
  47900. }
  47901. // Remove any zero-width space spans from the cloned DOM so that they don't
  47902. // show up elsewhere when pasted.
  47903. Array.from(contents.querySelectorAll('[data-slate-zero-width]')).forEach(zw => {
  47904. const isNewline = zw.getAttribute('data-slate-zero-width') === 'n';
  47905. zw.textContent = isNewline ? '\n' : '';
  47906. });
  47907. // Set a `data-slate-fragment` attribute on a non-empty node, so it shows up
  47908. // in the HTML, and can be used for intra-Slate pasting. If it's a text
  47909. // node, wrap it in a `<span>` so we have something to set an attribute on.
  47910. if (isDOMText(attach)) {
  47911. const span = document.createElement('span');
  47912. // COMPAT: In Chrome and Safari, if we don't add the `white-space` style
  47913. // then leading and trailing spaces will be ignored. (2017/09/21)
  47914. span.style.whiteSpace = 'pre';
  47915. span.appendChild(attach);
  47916. contents.appendChild(span);
  47917. attach = span;
  47918. }
  47919. const fragment = dist$5.Node.fragment(editor, selection);
  47920. const string = JSON.stringify(fragment);
  47921. const encoded = window.btoa(encodeURIComponent(string));
  47922. attach.setAttribute('data-slate-fragment', encoded);
  47923. dataTransfer.setData('application/x-slate-fragment', encoded);
  47924. // Add the content to a <div> so that we can get its inner HTML.
  47925. const div = document.createElement('div');
  47926. div.appendChild(contents);
  47927. dataTransfer.setData('text/html', div.innerHTML);
  47928. dataTransfer.setData('text/plain', getPlainText(div));
  47929. };
  47930. /**
  47931. * Get a plaintext representation of the content of a node, accounting for block
  47932. * elements which get a newline appended.
  47933. */
  47934. const getPlainText = (domNode) => {
  47935. let text = '';
  47936. if (isDOMText(domNode) && domNode.nodeValue) {
  47937. return domNode.nodeValue;
  47938. }
  47939. if (isDOMElement(domNode)) {
  47940. for (const childNode of Array.from(domNode.childNodes)) {
  47941. text += getPlainText(childNode);
  47942. }
  47943. const display = getComputedStyle(domNode).getPropertyValue('display');
  47944. if (display === 'block' || display === 'list' || domNode.tagName === 'BR') {
  47945. text += '\n';
  47946. }
  47947. }
  47948. return text;
  47949. };
  47950. /**
  47951. * An auto-incrementing identifier for keys.
  47952. */
  47953. var n = 0;
  47954. /**
  47955. * A class that keeps track of a key string. We use a full class here because we
  47956. * want to be able to use them as keys in `WeakMap` objects.
  47957. */
  47958. class Key {
  47959. constructor() {
  47960. this.id = "".concat(n++);
  47961. }
  47962. }
  47963. var ReactEditor = {
  47964. /**
  47965. * Find a key for a Slate node.
  47966. */
  47967. findKey(editor, node) {
  47968. var key = NODE_TO_KEY.get(node);
  47969. if (!key) {
  47970. key = new Key();
  47971. NODE_TO_KEY.set(node, key);
  47972. }
  47973. return key;
  47974. },
  47975. /**
  47976. * Find the path of Slate node.
  47977. */
  47978. findPath(editor, node) {
  47979. var path = [];
  47980. var child = node;
  47981. while (true) {
  47982. var parent = NODE_TO_PARENT.get(child);
  47983. if (parent == null) {
  47984. if (dist$5.Editor.isEditor(child)) {
  47985. return path;
  47986. } else {
  47987. break;
  47988. }
  47989. }
  47990. var i = NODE_TO_INDEX.get(child);
  47991. if (i == null) {
  47992. break;
  47993. }
  47994. path.unshift(i);
  47995. child = parent;
  47996. }
  47997. throw new Error("Unable to find the path for Slate node: ".concat(JSON.stringify(node)));
  47998. },
  47999. /**
  48000. * Check if the editor is focused.
  48001. */
  48002. isFocused(editor) {
  48003. return !!IS_FOCUSED.get(editor);
  48004. },
  48005. /**
  48006. * Check if the editor is in read-only mode.
  48007. */
  48008. isReadOnly(editor) {
  48009. return !!IS_READ_ONLY.get(editor);
  48010. },
  48011. /**
  48012. * Blur the editor.
  48013. */
  48014. blur(editor) {
  48015. var el = ReactEditor.toDOMNode(editor, editor);
  48016. IS_FOCUSED.set(editor, false);
  48017. if (window.document.activeElement === el) {
  48018. el.blur();
  48019. }
  48020. },
  48021. /**
  48022. * Focus the editor.
  48023. */
  48024. focus(editor) {
  48025. var el = ReactEditor.toDOMNode(editor, editor);
  48026. IS_FOCUSED.set(editor, true);
  48027. if (window.document.activeElement !== el) {
  48028. el.focus({
  48029. preventScroll: true
  48030. });
  48031. }
  48032. },
  48033. /**
  48034. * Deselect the editor.
  48035. */
  48036. deselect(editor) {
  48037. var {
  48038. selection
  48039. } = editor;
  48040. var domSelection = window.getSelection();
  48041. if (domSelection && domSelection.rangeCount > 0) {
  48042. domSelection.removeAllRanges();
  48043. }
  48044. if (selection) {
  48045. dist$5.Transforms.deselect(editor);
  48046. }
  48047. },
  48048. /**
  48049. * Check if a DOM node is within the editor.
  48050. */
  48051. hasDOMNode(editor, target) {
  48052. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  48053. var {
  48054. editable = false
  48055. } = options;
  48056. var el = ReactEditor.toDOMNode(editor, editor);
  48057. var element; // COMPAT: In Firefox, reading `target.nodeType` will throw an error if
  48058. // target is originating from an internal "restricted" element (e.g. a
  48059. // stepper arrow on a number input). (2018/05/04)
  48060. // https://github.com/ianstormtaylor/slate/issues/1819
  48061. try {
  48062. element = isDOMElement(target) ? target : target.parentElement;
  48063. } catch (err) {
  48064. if (!err.message.includes('Permission denied to access property "nodeType"')) {
  48065. throw err;
  48066. }
  48067. }
  48068. if (!element) {
  48069. return false;
  48070. }
  48071. return element.closest("[data-slate-editor]") === el && (!editable || el.isContentEditable);
  48072. },
  48073. /**
  48074. * Insert data from a `DataTransfer` into the editor.
  48075. */
  48076. insertData(editor, data) {
  48077. editor.insertData(data);
  48078. },
  48079. /**
  48080. * Find the native DOM element from a Slate node.
  48081. */
  48082. toDOMNode(editor, node) {
  48083. var domNode = dist$5.Editor.isEditor(node) ? EDITOR_TO_ELEMENT.get(editor) : KEY_TO_ELEMENT.get(ReactEditor.findKey(editor, node));
  48084. if (!domNode) {
  48085. throw new Error("Cannot resolve a DOM node from Slate node: ".concat(JSON.stringify(node)));
  48086. }
  48087. return domNode;
  48088. },
  48089. /**
  48090. * Find a native DOM selection point from a Slate point.
  48091. */
  48092. toDOMPoint(editor, point) {
  48093. var [node] = dist$5.Editor.node(editor, point.path);
  48094. var el = ReactEditor.toDOMNode(editor, node);
  48095. var domPoint; // If we're inside a void node, force the offset to 0, otherwise the zero
  48096. // width spacing character will result in an incorrect offset of 1
  48097. if (dist$5.Editor.void(editor, {
  48098. at: point
  48099. })) {
  48100. point = {
  48101. path: point.path,
  48102. offset: 0
  48103. };
  48104. } // For each leaf, we need to isolate its content, which means filtering
  48105. // to its direct text and zero-width spans. (We have to filter out any
  48106. // other siblings that may have been rendered alongside them.)
  48107. var selector = "[data-slate-string], [data-slate-zero-width]";
  48108. var texts = Array.from(el.querySelectorAll(selector));
  48109. var start = 0;
  48110. for (var text of texts) {
  48111. var domNode = text.childNodes[0];
  48112. if (domNode == null || domNode.textContent == null) {
  48113. continue;
  48114. }
  48115. var {
  48116. length
  48117. } = domNode.textContent;
  48118. var attr = text.getAttribute('data-slate-length');
  48119. var trueLength = attr == null ? length : parseInt(attr, 10);
  48120. var end = start + trueLength;
  48121. if (point.offset <= end) {
  48122. var offset = Math.min(length, Math.max(0, point.offset - start));
  48123. domPoint = [domNode, offset];
  48124. break;
  48125. }
  48126. start = end;
  48127. }
  48128. if (!domPoint) {
  48129. throw new Error("Cannot resolve a DOM point from Slate point: ".concat(JSON.stringify(point)));
  48130. }
  48131. return domPoint;
  48132. },
  48133. /**
  48134. * Find a native DOM range from a Slate `range`.
  48135. */
  48136. toDOMRange(editor, range) {
  48137. var {
  48138. anchor,
  48139. focus
  48140. } = range;
  48141. var domAnchor = ReactEditor.toDOMPoint(editor, anchor);
  48142. var domFocus = dist$5.Range.isCollapsed(range) ? domAnchor : ReactEditor.toDOMPoint(editor, focus);
  48143. var domRange = window.document.createRange();
  48144. var start = dist$5.Range.isBackward(range) ? domFocus : domAnchor;
  48145. var end = dist$5.Range.isBackward(range) ? domAnchor : domFocus;
  48146. domRange.setStart(start[0], start[1]);
  48147. domRange.setEnd(end[0], end[1]);
  48148. return domRange;
  48149. },
  48150. /**
  48151. * Find a Slate node from a native DOM `element`.
  48152. */
  48153. toSlateNode(editor, domNode) {
  48154. var domEl = isDOMElement(domNode) ? domNode : domNode.parentElement;
  48155. if (domEl && !domEl.hasAttribute('data-slate-node')) {
  48156. domEl = domEl.closest("[data-slate-node]");
  48157. }
  48158. var node = domEl ? ELEMENT_TO_NODE.get(domEl) : null;
  48159. if (!node) {
  48160. throw new Error("Cannot resolve a Slate node from DOM node: ".concat(domEl));
  48161. }
  48162. return node;
  48163. },
  48164. /**
  48165. * Get the target range from a DOM `event`.
  48166. */
  48167. findEventRange(editor, event) {
  48168. if ('nativeEvent' in event) {
  48169. event = event.nativeEvent;
  48170. }
  48171. var {
  48172. clientX: x,
  48173. clientY: y,
  48174. target
  48175. } = event;
  48176. if (x == null || y == null) {
  48177. throw new Error("Cannot resolve a Slate range from a DOM event: ".concat(event));
  48178. }
  48179. var node = ReactEditor.toSlateNode(editor, event.target);
  48180. var path = ReactEditor.findPath(editor, node); // If the drop target is inside a void node, move it into either the
  48181. // next or previous node, depending on which side the `x` and `y`
  48182. // coordinates are closest to.
  48183. if (dist$5.Editor.isVoid(editor, node)) {
  48184. var rect = target.getBoundingClientRect();
  48185. var isPrev = editor.isInline(node) ? x - rect.left < rect.left + rect.width - x : y - rect.top < rect.top + rect.height - y;
  48186. var edge = dist$5.Editor.point(editor, path, {
  48187. edge: isPrev ? 'start' : 'end'
  48188. });
  48189. var point = isPrev ? dist$5.Editor.before(editor, edge) : dist$5.Editor.after(editor, edge);
  48190. if (point) {
  48191. var _range = dist$5.Editor.range(editor, point);
  48192. return _range;
  48193. }
  48194. } // Else resolve a range from the caret position where the drop occured.
  48195. var domRange;
  48196. var {
  48197. document
  48198. } = window; // COMPAT: In Firefox, `caretRangeFromPoint` doesn't exist. (2016/07/25)
  48199. if (document.caretRangeFromPoint) {
  48200. domRange = document.caretRangeFromPoint(x, y);
  48201. } else {
  48202. var position = document.caretPositionFromPoint(x, y);
  48203. if (position) {
  48204. domRange = document.createRange();
  48205. domRange.setStart(position.offsetNode, position.offset);
  48206. domRange.setEnd(position.offsetNode, position.offset);
  48207. }
  48208. }
  48209. if (!domRange) {
  48210. throw new Error("Cannot resolve a Slate range from a DOM event: ".concat(event));
  48211. } // Resolve a Slate range from the DOM range.
  48212. var range = ReactEditor.toSlateRange(editor, domRange);
  48213. return range;
  48214. },
  48215. /**
  48216. * Find a Slate point from a DOM selection's `domNode` and `domOffset`.
  48217. */
  48218. toSlatePoint(editor, domPoint) {
  48219. var [nearestNode, nearestOffset] = normalizeDOMPoint(domPoint);
  48220. var parentNode = nearestNode.parentNode;
  48221. var textNode = null;
  48222. var offset = 0;
  48223. if (parentNode) {
  48224. var voidNode = parentNode.closest('[data-slate-void="true"]');
  48225. var leafNode = parentNode.closest('[data-slate-leaf]');
  48226. var domNode = null; // Calculate how far into the text node the `nearestNode` is, so that we
  48227. // can determine what the offset relative to the text node is.
  48228. if (leafNode) {
  48229. textNode = leafNode.closest('[data-slate-node="text"]');
  48230. var range = window.document.createRange();
  48231. range.setStart(textNode, 0);
  48232. range.setEnd(nearestNode, nearestOffset);
  48233. var contents = range.cloneContents();
  48234. var removals = [...contents.querySelectorAll('[data-slate-zero-width]'), ...contents.querySelectorAll('[contenteditable=false]')];
  48235. removals.forEach(el => {
  48236. el.parentNode.removeChild(el);
  48237. }); // COMPAT: Edge has a bug where Range.prototype.toString() will
  48238. // convert \n into \r\n. The bug causes a loop when slate-react
  48239. // attempts to reposition its cursor to match the native position. Use
  48240. // textContent.length instead.
  48241. // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10291116/
  48242. offset = contents.textContent.length;
  48243. domNode = textNode;
  48244. } else if (voidNode) {
  48245. // For void nodes, the element with the offset key will be a cousin, not an
  48246. // ancestor, so find it by going down from the nearest void parent.
  48247. leafNode = voidNode.querySelector('[data-slate-leaf]');
  48248. textNode = leafNode.closest('[data-slate-node="text"]');
  48249. domNode = leafNode;
  48250. offset = domNode.textContent.length;
  48251. } // COMPAT: If the parent node is a Slate zero-width space, editor is
  48252. // because the text node should have no characters. However, during IME
  48253. // composition the ASCII characters will be prepended to the zero-width
  48254. // space, so subtract 1 from the offset to account for the zero-width
  48255. // space character.
  48256. if (domNode && offset === domNode.textContent.length && parentNode.hasAttribute('data-slate-zero-width')) {
  48257. offset--;
  48258. }
  48259. }
  48260. if (!textNode) {
  48261. throw new Error("Cannot resolve a Slate point from DOM point: ".concat(domPoint));
  48262. } // COMPAT: If someone is clicking from one Slate editor into another,
  48263. // the select event fires twice, once for the old editor's `element`
  48264. // first, and then afterwards for the correct `element`. (2017/03/03)
  48265. var slateNode = ReactEditor.toSlateNode(editor, textNode);
  48266. var path = ReactEditor.findPath(editor, slateNode);
  48267. return {
  48268. path,
  48269. offset
  48270. };
  48271. },
  48272. /**
  48273. * Find a Slate range from a DOM range or selection.
  48274. */
  48275. toSlateRange(editor, domRange) {
  48276. var el = domRange instanceof Selection ? domRange.anchorNode : domRange.startContainer;
  48277. var anchorNode;
  48278. var anchorOffset;
  48279. var focusNode;
  48280. var focusOffset;
  48281. var isCollapsed;
  48282. if (el) {
  48283. if (domRange instanceof Selection) {
  48284. anchorNode = domRange.anchorNode;
  48285. anchorOffset = domRange.anchorOffset;
  48286. focusNode = domRange.focusNode;
  48287. focusOffset = domRange.focusOffset;
  48288. isCollapsed = domRange.isCollapsed;
  48289. } else {
  48290. anchorNode = domRange.startContainer;
  48291. anchorOffset = domRange.startOffset;
  48292. focusNode = domRange.endContainer;
  48293. focusOffset = domRange.endOffset;
  48294. isCollapsed = domRange.collapsed;
  48295. }
  48296. }
  48297. if (anchorNode == null || focusNode == null || anchorOffset == null || focusOffset == null) {
  48298. throw new Error("Cannot resolve a Slate range from DOM range: ".concat(domRange));
  48299. }
  48300. var anchor = ReactEditor.toSlatePoint(editor, [anchorNode, anchorOffset]);
  48301. var focus = isCollapsed ? anchor : ReactEditor.toSlatePoint(editor, [focusNode, focusOffset]);
  48302. return {
  48303. anchor,
  48304. focus
  48305. };
  48306. }
  48307. };
  48308. /**
  48309. * A React context for sharing the `focused` state of the editor.
  48310. */
  48311. var FocusedContext = React.createContext(false);
  48312. /**
  48313. * Get the current `focused` state of the editor.
  48314. */
  48315. var useFocused = () => {
  48316. return React.useContext(FocusedContext);
  48317. };
  48318. /**
  48319. * A wrapper around the provider to handle `onChange` events, because the editor
  48320. * is a mutable singleton so it won't ever register as "changed" otherwise.
  48321. */
  48322. const Slate = (props) => {
  48323. const { editor, children, onChange, value, ...rest } = props;
  48324. const [key, setKey] = React.useState(0);
  48325. const context = React.useMemo(() => {
  48326. editor.children = value;
  48327. Object.assign(editor, rest);
  48328. return [editor];
  48329. }, [key, value, ...Object.values(rest)]);
  48330. const onContextChange = React.useCallback(() => {
  48331. onChange(editor.children);
  48332. setKey(key + 1);
  48333. }, [key, onChange]);
  48334. EDITOR_TO_ON_CHANGE.set(editor, onContextChange);
  48335. return (React__default.createElement(SlateContext.Provider, { value: context },
  48336. React__default.createElement(EditorContext.Provider, { value: editor },
  48337. React__default.createElement(FocusedContext.Provider, { value: ReactEditor.isFocused(editor) }, children))));
  48338. };
  48339. /**
  48340. * `withReact` adds React and DOM specific behaviors to the editor.
  48341. */
  48342. var withReact = editor => {
  48343. var e = editor;
  48344. var {
  48345. apply,
  48346. onChange
  48347. } = e;
  48348. e.apply = op => {
  48349. var matches = [];
  48350. switch (op.type) {
  48351. case 'insert_text':
  48352. case 'remove_text':
  48353. case 'set_node':
  48354. {
  48355. for (var [node, path] of dist$5.Editor.levels(e, {
  48356. at: op.path
  48357. })) {
  48358. var key = ReactEditor.findKey(e, node);
  48359. matches.push([path, key]);
  48360. }
  48361. break;
  48362. }
  48363. case 'insert_node':
  48364. case 'remove_node':
  48365. case 'merge_node':
  48366. case 'split_node':
  48367. {
  48368. for (var [_node, _path] of dist$5.Editor.levels(e, {
  48369. at: dist$5.Path.parent(op.path)
  48370. })) {
  48371. var _key = ReactEditor.findKey(e, _node);
  48372. matches.push([_path, _key]);
  48373. }
  48374. break;
  48375. }
  48376. }
  48377. apply(op);
  48378. for (var [_path2, _key2] of matches) {
  48379. var [_node2] = dist$5.Editor.node(e, _path2);
  48380. NODE_TO_KEY.set(_node2, _key2);
  48381. }
  48382. };
  48383. e.insertData = data => {
  48384. var fragment = data.getData('application/x-slate-fragment');
  48385. if (fragment) {
  48386. var decoded = decodeURIComponent(window.atob(fragment));
  48387. var parsed = JSON.parse(decoded);
  48388. dist$5.Transforms.insertFragment(e, parsed);
  48389. return;
  48390. }
  48391. var text = data.getData('text/plain');
  48392. if (text) {
  48393. var lines = text.split('\n');
  48394. var split = false;
  48395. for (var line of lines) {
  48396. if (split) {
  48397. dist$5.Transforms.splitNodes(e);
  48398. }
  48399. dist$5.Transforms.insertText(e, line);
  48400. split = true;
  48401. }
  48402. }
  48403. };
  48404. e.onChange = () => {
  48405. // COMPAT: React doesn't batch `setState` hook calls, which means that the
  48406. // children and selection can get out of sync for one render pass. So we
  48407. // have to use this unstable API to ensure it batches them. (2019/12/03)
  48408. // https://github.com/facebook/react/issues/14259#issuecomment-439702367
  48409. ReactDOM.unstable_batchedUpdates(() => {
  48410. var onContextChange = EDITOR_TO_ON_CHANGE.get(e);
  48411. if (onContextChange) {
  48412. onContextChange();
  48413. }
  48414. onChange();
  48415. });
  48416. };
  48417. return e;
  48418. };
  48419. exports.DefaultElement = DefaultElement;
  48420. exports.DefaultLeaf = DefaultLeaf;
  48421. exports.Editable = Editable;
  48422. exports.ReactEditor = ReactEditor;
  48423. exports.Slate = Slate;
  48424. exports.useEditor = useEditor;
  48425. exports.useFocused = useFocused;
  48426. exports.useReadOnly = useReadOnly;
  48427. exports.useSelected = useSelected;
  48428. exports.useSlate = useSlate;
  48429. exports.withReact = withReact;
  48430. });
  48431. unwrapExports(dist$6);
  48432. var dist_1$4 = dist$6.DefaultElement;
  48433. var dist_2$4 = dist$6.DefaultLeaf;
  48434. var dist_3$4 = dist$6.Editable;
  48435. var dist_4$2 = dist$6.ReactEditor;
  48436. var dist_5$2 = dist$6.Slate;
  48437. var dist_6$2 = dist$6.useEditor;
  48438. var dist_7$1 = dist$6.useFocused;
  48439. var dist_8$1 = dist$6.useReadOnly;
  48440. var dist_9$1 = dist$6.useSelected;
  48441. var dist_10$1 = dist$6.useSlate;
  48442. var dist_11$1 = dist$6.withReact;
  48443. var RichTextEditorForSlate = function RichTextEditorForSlate() {
  48444. var editor = useMemo(function () {
  48445. return dist_11$1(dist_15());
  48446. }, []);
  48447. var _useState = useState([{
  48448. type: 'paragraph',
  48449. children: [{
  48450. text: 'A line of text in a paragraph.'
  48451. }]
  48452. }]),
  48453. _useState2 = _slicedToArray(_useState, 2),
  48454. value = _useState2[0],
  48455. setValue = _useState2[1];
  48456. return (// Add the editable component inside the context.
  48457. React.createElement(dist_5$2, {
  48458. editor: editor,
  48459. value: value,
  48460. onChange: function onChange(value) {
  48461. console.log('value: ', value);
  48462. setValue(value);
  48463. }
  48464. }, React.createElement(dist_3$4, null))
  48465. );
  48466. }; // class RichTextEditorForSlate extends React.Component<RichTextEditorForSlateProps, RichTextEditorForSlateState> {
  48467. export { BarftEditorPage as BraftEditor, RichTextEditor, RichTextEditorForSlate };
  48468. //# sourceMappingURL=index.js.map