No Description

index.js 1.8MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  4. var styleInject_es = require('../style-inject.es-7b2c2b1b.js');
  5. var React = require('react');
  6. var React__default = _interopDefault(React);
  7. var reactDom = _interopDefault(require('react-dom'));
  8. var server = _interopDefault(require('react-dom/server'));
  9. /*
  10. object-assign
  11. (c) Sindre Sorhus
  12. @license MIT
  13. */
  14. /* eslint-disable no-unused-vars */
  15. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  16. var hasOwnProperty = Object.prototype.hasOwnProperty;
  17. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  18. function toObject(val) {
  19. if (val === null || val === undefined) {
  20. throw new TypeError('Object.assign cannot be called with null or undefined');
  21. }
  22. return Object(val);
  23. }
  24. function shouldUseNative() {
  25. try {
  26. if (!Object.assign) {
  27. return false;
  28. }
  29. // Detect buggy property enumeration order in older V8 versions.
  30. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  31. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  32. test1[5] = 'de';
  33. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  34. return false;
  35. }
  36. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  37. var test2 = {};
  38. for (var i = 0; i < 10; i++) {
  39. test2['_' + String.fromCharCode(i)] = i;
  40. }
  41. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  42. return test2[n];
  43. });
  44. if (order2.join('') !== '0123456789') {
  45. return false;
  46. }
  47. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  48. var test3 = {};
  49. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  50. test3[letter] = letter;
  51. });
  52. if (Object.keys(Object.assign({}, test3)).join('') !==
  53. 'abcdefghijklmnopqrst') {
  54. return false;
  55. }
  56. return true;
  57. } catch (err) {
  58. // We don't expect any of the above to throw, but better to be safe.
  59. return false;
  60. }
  61. }
  62. var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
  63. var from;
  64. var to = toObject(target);
  65. var symbols;
  66. for (var s = 1; s < arguments.length; s++) {
  67. from = Object(arguments[s]);
  68. for (var key in from) {
  69. if (hasOwnProperty.call(from, key)) {
  70. to[key] = from[key];
  71. }
  72. }
  73. if (getOwnPropertySymbols) {
  74. symbols = getOwnPropertySymbols(from);
  75. for (var i = 0; i < symbols.length; i++) {
  76. if (propIsEnumerable.call(from, symbols[i])) {
  77. to[symbols[i]] = from[symbols[i]];
  78. }
  79. }
  80. }
  81. }
  82. return to;
  83. };
  84. var immutable = styleInject_es.createCommonjsModule(function (module, exports) {
  85. /**
  86. * Copyright (c) 2014-2015, Facebook, Inc.
  87. * All rights reserved.
  88. *
  89. * This source code is licensed under the BSD-style license found in the
  90. * LICENSE file in the root directory of this source tree. An additional grant
  91. * of patent rights can be found in the PATENTS file in the same directory.
  92. */
  93. (function (global, factory) {
  94. module.exports = factory() ;
  95. }(styleInject_es.commonjsGlobal, function () {var SLICE$0 = Array.prototype.slice;
  96. function createClass(ctor, superClass) {
  97. if (superClass) {
  98. ctor.prototype = Object.create(superClass.prototype);
  99. }
  100. ctor.prototype.constructor = ctor;
  101. }
  102. function Iterable(value) {
  103. return isIterable(value) ? value : Seq(value);
  104. }
  105. createClass(KeyedIterable, Iterable);
  106. function KeyedIterable(value) {
  107. return isKeyed(value) ? value : KeyedSeq(value);
  108. }
  109. createClass(IndexedIterable, Iterable);
  110. function IndexedIterable(value) {
  111. return isIndexed(value) ? value : IndexedSeq(value);
  112. }
  113. createClass(SetIterable, Iterable);
  114. function SetIterable(value) {
  115. return isIterable(value) && !isAssociative(value) ? value : SetSeq(value);
  116. }
  117. function isIterable(maybeIterable) {
  118. return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]);
  119. }
  120. function isKeyed(maybeKeyed) {
  121. return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
  122. }
  123. function isIndexed(maybeIndexed) {
  124. return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
  125. }
  126. function isAssociative(maybeAssociative) {
  127. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  128. }
  129. function isOrdered(maybeOrdered) {
  130. return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
  131. }
  132. Iterable.isIterable = isIterable;
  133. Iterable.isKeyed = isKeyed;
  134. Iterable.isIndexed = isIndexed;
  135. Iterable.isAssociative = isAssociative;
  136. Iterable.isOrdered = isOrdered;
  137. Iterable.Keyed = KeyedIterable;
  138. Iterable.Indexed = IndexedIterable;
  139. Iterable.Set = SetIterable;
  140. var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  141. var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  142. var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  143. var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  144. // Used for setting prototype methods that IE8 chokes on.
  145. var DELETE = 'delete';
  146. // Constants describing the size of trie nodes.
  147. var SHIFT = 5; // Resulted in best performance after ______?
  148. var SIZE = 1 << SHIFT;
  149. var MASK = SIZE - 1;
  150. // A consistent shared value representing "not set" which equals nothing other
  151. // than itself, and nothing that could be provided externally.
  152. var NOT_SET = {};
  153. // Boolean references, Rough equivalent of `bool &`.
  154. var CHANGE_LENGTH = { value: false };
  155. var DID_ALTER = { value: false };
  156. function MakeRef(ref) {
  157. ref.value = false;
  158. return ref;
  159. }
  160. function SetRef(ref) {
  161. ref && (ref.value = true);
  162. }
  163. // A function which returns a value representing an "owner" for transient writes
  164. // to tries. The return value will only ever equal itself, and will not equal
  165. // the return of any subsequent call of this function.
  166. function OwnerID() {}
  167. // http://jsperf.com/copy-array-inline
  168. function arrCopy(arr, offset) {
  169. offset = offset || 0;
  170. var len = Math.max(0, arr.length - offset);
  171. var newArr = new Array(len);
  172. for (var ii = 0; ii < len; ii++) {
  173. newArr[ii] = arr[ii + offset];
  174. }
  175. return newArr;
  176. }
  177. function ensureSize(iter) {
  178. if (iter.size === undefined) {
  179. iter.size = iter.__iterate(returnTrue);
  180. }
  181. return iter.size;
  182. }
  183. function wrapIndex(iter, index) {
  184. // This implements "is array index" which the ECMAString spec defines as:
  185. //
  186. // A String property name P is an array index if and only if
  187. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  188. // to 2^32−1.
  189. //
  190. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  191. if (typeof index !== 'number') {
  192. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  193. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  194. return NaN;
  195. }
  196. index = uint32Index;
  197. }
  198. return index < 0 ? ensureSize(iter) + index : index;
  199. }
  200. function returnTrue() {
  201. return true;
  202. }
  203. function wholeSlice(begin, end, size) {
  204. return (begin === 0 || (size !== undefined && begin <= -size)) &&
  205. (end === undefined || (size !== undefined && end >= size));
  206. }
  207. function resolveBegin(begin, size) {
  208. return resolveIndex(begin, size, 0);
  209. }
  210. function resolveEnd(end, size) {
  211. return resolveIndex(end, size, size);
  212. }
  213. function resolveIndex(index, size, defaultIndex) {
  214. return index === undefined ?
  215. defaultIndex :
  216. index < 0 ?
  217. Math.max(0, size + index) :
  218. size === undefined ?
  219. index :
  220. Math.min(size, index);
  221. }
  222. /* global Symbol */
  223. var ITERATE_KEYS = 0;
  224. var ITERATE_VALUES = 1;
  225. var ITERATE_ENTRIES = 2;
  226. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  227. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  228. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  229. function Iterator(next) {
  230. this.next = next;
  231. }
  232. Iterator.prototype.toString = function() {
  233. return '[Iterator]';
  234. };
  235. Iterator.KEYS = ITERATE_KEYS;
  236. Iterator.VALUES = ITERATE_VALUES;
  237. Iterator.ENTRIES = ITERATE_ENTRIES;
  238. Iterator.prototype.inspect =
  239. Iterator.prototype.toSource = function () { return this.toString(); };
  240. Iterator.prototype[ITERATOR_SYMBOL] = function () {
  241. return this;
  242. };
  243. function iteratorValue(type, k, v, iteratorResult) {
  244. var value = type === 0 ? k : type === 1 ? v : [k, v];
  245. iteratorResult ? (iteratorResult.value = value) : (iteratorResult = {
  246. value: value, done: false
  247. });
  248. return iteratorResult;
  249. }
  250. function iteratorDone() {
  251. return { value: undefined, done: true };
  252. }
  253. function hasIterator(maybeIterable) {
  254. return !!getIteratorFn(maybeIterable);
  255. }
  256. function isIterator(maybeIterator) {
  257. return maybeIterator && typeof maybeIterator.next === 'function';
  258. }
  259. function getIterator(iterable) {
  260. var iteratorFn = getIteratorFn(iterable);
  261. return iteratorFn && iteratorFn.call(iterable);
  262. }
  263. function getIteratorFn(iterable) {
  264. var iteratorFn = iterable && (
  265. (REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  266. iterable[FAUX_ITERATOR_SYMBOL]
  267. );
  268. if (typeof iteratorFn === 'function') {
  269. return iteratorFn;
  270. }
  271. }
  272. function isArrayLike(value) {
  273. return value && typeof value.length === 'number';
  274. }
  275. createClass(Seq, Iterable);
  276. function Seq(value) {
  277. return value === null || value === undefined ? emptySequence() :
  278. isIterable(value) ? value.toSeq() : seqFromValue(value);
  279. }
  280. Seq.of = function(/*...values*/) {
  281. return Seq(arguments);
  282. };
  283. Seq.prototype.toSeq = function() {
  284. return this;
  285. };
  286. Seq.prototype.toString = function() {
  287. return this.__toString('Seq {', '}');
  288. };
  289. Seq.prototype.cacheResult = function() {
  290. if (!this._cache && this.__iterateUncached) {
  291. this._cache = this.entrySeq().toArray();
  292. this.size = this._cache.length;
  293. }
  294. return this;
  295. };
  296. // abstract __iterateUncached(fn, reverse)
  297. Seq.prototype.__iterate = function(fn, reverse) {
  298. return seqIterate(this, fn, reverse, true);
  299. };
  300. // abstract __iteratorUncached(type, reverse)
  301. Seq.prototype.__iterator = function(type, reverse) {
  302. return seqIterator(this, type, reverse, true);
  303. };
  304. createClass(KeyedSeq, Seq);
  305. function KeyedSeq(value) {
  306. return value === null || value === undefined ?
  307. emptySequence().toKeyedSeq() :
  308. isIterable(value) ?
  309. (isKeyed(value) ? value.toSeq() : value.fromEntrySeq()) :
  310. keyedSeqFromValue(value);
  311. }
  312. KeyedSeq.prototype.toKeyedSeq = function() {
  313. return this;
  314. };
  315. createClass(IndexedSeq, Seq);
  316. function IndexedSeq(value) {
  317. return value === null || value === undefined ? emptySequence() :
  318. !isIterable(value) ? indexedSeqFromValue(value) :
  319. isKeyed(value) ? value.entrySeq() : value.toIndexedSeq();
  320. }
  321. IndexedSeq.of = function(/*...values*/) {
  322. return IndexedSeq(arguments);
  323. };
  324. IndexedSeq.prototype.toIndexedSeq = function() {
  325. return this;
  326. };
  327. IndexedSeq.prototype.toString = function() {
  328. return this.__toString('Seq [', ']');
  329. };
  330. IndexedSeq.prototype.__iterate = function(fn, reverse) {
  331. return seqIterate(this, fn, reverse, false);
  332. };
  333. IndexedSeq.prototype.__iterator = function(type, reverse) {
  334. return seqIterator(this, type, reverse, false);
  335. };
  336. createClass(SetSeq, Seq);
  337. function SetSeq(value) {
  338. return (
  339. value === null || value === undefined ? emptySequence() :
  340. !isIterable(value) ? indexedSeqFromValue(value) :
  341. isKeyed(value) ? value.entrySeq() : value
  342. ).toSetSeq();
  343. }
  344. SetSeq.of = function(/*...values*/) {
  345. return SetSeq(arguments);
  346. };
  347. SetSeq.prototype.toSetSeq = function() {
  348. return this;
  349. };
  350. Seq.isSeq = isSeq;
  351. Seq.Keyed = KeyedSeq;
  352. Seq.Set = SetSeq;
  353. Seq.Indexed = IndexedSeq;
  354. var IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
  355. Seq.prototype[IS_SEQ_SENTINEL] = true;
  356. createClass(ArraySeq, IndexedSeq);
  357. function ArraySeq(array) {
  358. this._array = array;
  359. this.size = array.length;
  360. }
  361. ArraySeq.prototype.get = function(index, notSetValue) {
  362. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  363. };
  364. ArraySeq.prototype.__iterate = function(fn, reverse) {
  365. var array = this._array;
  366. var maxIndex = array.length - 1;
  367. for (var ii = 0; ii <= maxIndex; ii++) {
  368. if (fn(array[reverse ? maxIndex - ii : ii], ii, this) === false) {
  369. return ii + 1;
  370. }
  371. }
  372. return ii;
  373. };
  374. ArraySeq.prototype.__iterator = function(type, reverse) {
  375. var array = this._array;
  376. var maxIndex = array.length - 1;
  377. var ii = 0;
  378. return new Iterator(function()
  379. {return ii > maxIndex ?
  380. iteratorDone() :
  381. iteratorValue(type, ii, array[reverse ? maxIndex - ii++ : ii++])}
  382. );
  383. };
  384. createClass(ObjectSeq, KeyedSeq);
  385. function ObjectSeq(object) {
  386. var keys = Object.keys(object);
  387. this._object = object;
  388. this._keys = keys;
  389. this.size = keys.length;
  390. }
  391. ObjectSeq.prototype.get = function(key, notSetValue) {
  392. if (notSetValue !== undefined && !this.has(key)) {
  393. return notSetValue;
  394. }
  395. return this._object[key];
  396. };
  397. ObjectSeq.prototype.has = function(key) {
  398. return this._object.hasOwnProperty(key);
  399. };
  400. ObjectSeq.prototype.__iterate = function(fn, reverse) {
  401. var object = this._object;
  402. var keys = this._keys;
  403. var maxIndex = keys.length - 1;
  404. for (var ii = 0; ii <= maxIndex; ii++) {
  405. var key = keys[reverse ? maxIndex - ii : ii];
  406. if (fn(object[key], key, this) === false) {
  407. return ii + 1;
  408. }
  409. }
  410. return ii;
  411. };
  412. ObjectSeq.prototype.__iterator = function(type, reverse) {
  413. var object = this._object;
  414. var keys = this._keys;
  415. var maxIndex = keys.length - 1;
  416. var ii = 0;
  417. return new Iterator(function() {
  418. var key = keys[reverse ? maxIndex - ii : ii];
  419. return ii++ > maxIndex ?
  420. iteratorDone() :
  421. iteratorValue(type, key, object[key]);
  422. });
  423. };
  424. ObjectSeq.prototype[IS_ORDERED_SENTINEL] = true;
  425. createClass(IterableSeq, IndexedSeq);
  426. function IterableSeq(iterable) {
  427. this._iterable = iterable;
  428. this.size = iterable.length || iterable.size;
  429. }
  430. IterableSeq.prototype.__iterateUncached = function(fn, reverse) {
  431. if (reverse) {
  432. return this.cacheResult().__iterate(fn, reverse);
  433. }
  434. var iterable = this._iterable;
  435. var iterator = getIterator(iterable);
  436. var iterations = 0;
  437. if (isIterator(iterator)) {
  438. var step;
  439. while (!(step = iterator.next()).done) {
  440. if (fn(step.value, iterations++, this) === false) {
  441. break;
  442. }
  443. }
  444. }
  445. return iterations;
  446. };
  447. IterableSeq.prototype.__iteratorUncached = function(type, reverse) {
  448. if (reverse) {
  449. return this.cacheResult().__iterator(type, reverse);
  450. }
  451. var iterable = this._iterable;
  452. var iterator = getIterator(iterable);
  453. if (!isIterator(iterator)) {
  454. return new Iterator(iteratorDone);
  455. }
  456. var iterations = 0;
  457. return new Iterator(function() {
  458. var step = iterator.next();
  459. return step.done ? step : iteratorValue(type, iterations++, step.value);
  460. });
  461. };
  462. createClass(IteratorSeq, IndexedSeq);
  463. function IteratorSeq(iterator) {
  464. this._iterator = iterator;
  465. this._iteratorCache = [];
  466. }
  467. IteratorSeq.prototype.__iterateUncached = function(fn, reverse) {
  468. if (reverse) {
  469. return this.cacheResult().__iterate(fn, reverse);
  470. }
  471. var iterator = this._iterator;
  472. var cache = this._iteratorCache;
  473. var iterations = 0;
  474. while (iterations < cache.length) {
  475. if (fn(cache[iterations], iterations++, this) === false) {
  476. return iterations;
  477. }
  478. }
  479. var step;
  480. while (!(step = iterator.next()).done) {
  481. var val = step.value;
  482. cache[iterations] = val;
  483. if (fn(val, iterations++, this) === false) {
  484. break;
  485. }
  486. }
  487. return iterations;
  488. };
  489. IteratorSeq.prototype.__iteratorUncached = function(type, reverse) {
  490. if (reverse) {
  491. return this.cacheResult().__iterator(type, reverse);
  492. }
  493. var iterator = this._iterator;
  494. var cache = this._iteratorCache;
  495. var iterations = 0;
  496. return new Iterator(function() {
  497. if (iterations >= cache.length) {
  498. var step = iterator.next();
  499. if (step.done) {
  500. return step;
  501. }
  502. cache[iterations] = step.value;
  503. }
  504. return iteratorValue(type, iterations, cache[iterations++]);
  505. });
  506. };
  507. // # pragma Helper functions
  508. function isSeq(maybeSeq) {
  509. return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]);
  510. }
  511. var EMPTY_SEQ;
  512. function emptySequence() {
  513. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  514. }
  515. function keyedSeqFromValue(value) {
  516. var seq =
  517. Array.isArray(value) ? new ArraySeq(value).fromEntrySeq() :
  518. isIterator(value) ? new IteratorSeq(value).fromEntrySeq() :
  519. hasIterator(value) ? new IterableSeq(value).fromEntrySeq() :
  520. typeof value === 'object' ? new ObjectSeq(value) :
  521. undefined;
  522. if (!seq) {
  523. throw new TypeError(
  524. 'Expected Array or iterable object of [k, v] entries, '+
  525. 'or keyed object: ' + value
  526. );
  527. }
  528. return seq;
  529. }
  530. function indexedSeqFromValue(value) {
  531. var seq = maybeIndexedSeqFromValue(value);
  532. if (!seq) {
  533. throw new TypeError(
  534. 'Expected Array or iterable object of values: ' + value
  535. );
  536. }
  537. return seq;
  538. }
  539. function seqFromValue(value) {
  540. var seq = maybeIndexedSeqFromValue(value) ||
  541. (typeof value === 'object' && new ObjectSeq(value));
  542. if (!seq) {
  543. throw new TypeError(
  544. 'Expected Array or iterable object of values, or keyed object: ' + value
  545. );
  546. }
  547. return seq;
  548. }
  549. function maybeIndexedSeqFromValue(value) {
  550. return (
  551. isArrayLike(value) ? new ArraySeq(value) :
  552. isIterator(value) ? new IteratorSeq(value) :
  553. hasIterator(value) ? new IterableSeq(value) :
  554. undefined
  555. );
  556. }
  557. function seqIterate(seq, fn, reverse, useKeys) {
  558. var cache = seq._cache;
  559. if (cache) {
  560. var maxIndex = cache.length - 1;
  561. for (var ii = 0; ii <= maxIndex; ii++) {
  562. var entry = cache[reverse ? maxIndex - ii : ii];
  563. if (fn(entry[1], useKeys ? entry[0] : ii, seq) === false) {
  564. return ii + 1;
  565. }
  566. }
  567. return ii;
  568. }
  569. return seq.__iterateUncached(fn, reverse);
  570. }
  571. function seqIterator(seq, type, reverse, useKeys) {
  572. var cache = seq._cache;
  573. if (cache) {
  574. var maxIndex = cache.length - 1;
  575. var ii = 0;
  576. return new Iterator(function() {
  577. var entry = cache[reverse ? maxIndex - ii : ii];
  578. return ii++ > maxIndex ?
  579. iteratorDone() :
  580. iteratorValue(type, useKeys ? entry[0] : ii - 1, entry[1]);
  581. });
  582. }
  583. return seq.__iteratorUncached(type, reverse);
  584. }
  585. function fromJS(json, converter) {
  586. return converter ?
  587. fromJSWith(converter, json, '', {'': json}) :
  588. fromJSDefault(json);
  589. }
  590. function fromJSWith(converter, json, key, parentJSON) {
  591. if (Array.isArray(json)) {
  592. return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  593. }
  594. if (isPlainObj(json)) {
  595. return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  596. }
  597. return json;
  598. }
  599. function fromJSDefault(json) {
  600. if (Array.isArray(json)) {
  601. return IndexedSeq(json).map(fromJSDefault).toList();
  602. }
  603. if (isPlainObj(json)) {
  604. return KeyedSeq(json).map(fromJSDefault).toMap();
  605. }
  606. return json;
  607. }
  608. function isPlainObj(value) {
  609. return value && (value.constructor === Object || value.constructor === undefined);
  610. }
  611. /**
  612. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  613. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  614. *
  615. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  616. * value, which is different from the algorithm described by
  617. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  618. *
  619. * This is extended further to allow Objects to describe the values they
  620. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  621. *
  622. * Note: because of this extension, the key equality of Immutable.Map and the
  623. * value equality of Immutable.Set will differ from ES6 Map and Set.
  624. *
  625. * ### Defining custom values
  626. *
  627. * The easiest way to describe the value an object represents is by implementing
  628. * `valueOf`. For example, `Date` represents a value by returning a unix
  629. * timestamp for `valueOf`:
  630. *
  631. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  632. * var date2 = new Date(1234567890000);
  633. * date1.valueOf(); // 1234567890000
  634. * assert( date1 !== date2 );
  635. * assert( Immutable.is( date1, date2 ) );
  636. *
  637. * Note: overriding `valueOf` may have other implications if you use this object
  638. * where JavaScript expects a primitive, such as implicit string coercion.
  639. *
  640. * For more complex types, especially collections, implementing `valueOf` may
  641. * not be performant. An alternative is to implement `equals` and `hashCode`.
  642. *
  643. * `equals` takes another object, presumably of similar type, and returns true
  644. * if the it is equal. Equality is symmetrical, so the same result should be
  645. * returned if this and the argument are flipped.
  646. *
  647. * assert( a.equals(b) === b.equals(a) );
  648. *
  649. * `hashCode` returns a 32bit integer number representing the object which will
  650. * be used to determine how to store the value object in a Map or Set. You must
  651. * provide both or neither methods, one must not exist without the other.
  652. *
  653. * Also, an important relationship between these methods must be upheld: if two
  654. * values are equal, they *must* return the same hashCode. If the values are not
  655. * equal, they might have the same hashCode; this is called a hash collision,
  656. * and while undesirable for performance reasons, it is acceptable.
  657. *
  658. * if (a.equals(b)) {
  659. * assert( a.hashCode() === b.hashCode() );
  660. * }
  661. *
  662. * All Immutable collections implement `equals` and `hashCode`.
  663. *
  664. */
  665. function is(valueA, valueB) {
  666. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  667. return true;
  668. }
  669. if (!valueA || !valueB) {
  670. return false;
  671. }
  672. if (typeof valueA.valueOf === 'function' &&
  673. typeof valueB.valueOf === 'function') {
  674. valueA = valueA.valueOf();
  675. valueB = valueB.valueOf();
  676. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  677. return true;
  678. }
  679. if (!valueA || !valueB) {
  680. return false;
  681. }
  682. }
  683. if (typeof valueA.equals === 'function' &&
  684. typeof valueB.equals === 'function' &&
  685. valueA.equals(valueB)) {
  686. return true;
  687. }
  688. return false;
  689. }
  690. function deepEqual(a, b) {
  691. if (a === b) {
  692. return true;
  693. }
  694. if (
  695. !isIterable(b) ||
  696. a.size !== undefined && b.size !== undefined && a.size !== b.size ||
  697. a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
  698. isKeyed(a) !== isKeyed(b) ||
  699. isIndexed(a) !== isIndexed(b) ||
  700. isOrdered(a) !== isOrdered(b)
  701. ) {
  702. return false;
  703. }
  704. if (a.size === 0 && b.size === 0) {
  705. return true;
  706. }
  707. var notAssociative = !isAssociative(a);
  708. if (isOrdered(a)) {
  709. var entries = a.entries();
  710. return b.every(function(v, k) {
  711. var entry = entries.next().value;
  712. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  713. }) && entries.next().done;
  714. }
  715. var flipped = false;
  716. if (a.size === undefined) {
  717. if (b.size === undefined) {
  718. if (typeof a.cacheResult === 'function') {
  719. a.cacheResult();
  720. }
  721. } else {
  722. flipped = true;
  723. var _ = a;
  724. a = b;
  725. b = _;
  726. }
  727. }
  728. var allEqual = true;
  729. var bSize = b.__iterate(function(v, k) {
  730. if (notAssociative ? !a.has(v) :
  731. flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
  732. allEqual = false;
  733. return false;
  734. }
  735. });
  736. return allEqual && a.size === bSize;
  737. }
  738. createClass(Repeat, IndexedSeq);
  739. function Repeat(value, times) {
  740. if (!(this instanceof Repeat)) {
  741. return new Repeat(value, times);
  742. }
  743. this._value = value;
  744. this.size = times === undefined ? Infinity : Math.max(0, times);
  745. if (this.size === 0) {
  746. if (EMPTY_REPEAT) {
  747. return EMPTY_REPEAT;
  748. }
  749. EMPTY_REPEAT = this;
  750. }
  751. }
  752. Repeat.prototype.toString = function() {
  753. if (this.size === 0) {
  754. return 'Repeat []';
  755. }
  756. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  757. };
  758. Repeat.prototype.get = function(index, notSetValue) {
  759. return this.has(index) ? this._value : notSetValue;
  760. };
  761. Repeat.prototype.includes = function(searchValue) {
  762. return is(this._value, searchValue);
  763. };
  764. Repeat.prototype.slice = function(begin, end) {
  765. var size = this.size;
  766. return wholeSlice(begin, end, size) ? this :
  767. new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
  768. };
  769. Repeat.prototype.reverse = function() {
  770. return this;
  771. };
  772. Repeat.prototype.indexOf = function(searchValue) {
  773. if (is(this._value, searchValue)) {
  774. return 0;
  775. }
  776. return -1;
  777. };
  778. Repeat.prototype.lastIndexOf = function(searchValue) {
  779. if (is(this._value, searchValue)) {
  780. return this.size;
  781. }
  782. return -1;
  783. };
  784. Repeat.prototype.__iterate = function(fn, reverse) {
  785. for (var ii = 0; ii < this.size; ii++) {
  786. if (fn(this._value, ii, this) === false) {
  787. return ii + 1;
  788. }
  789. }
  790. return ii;
  791. };
  792. Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
  793. var ii = 0;
  794. return new Iterator(function()
  795. {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
  796. );
  797. };
  798. Repeat.prototype.equals = function(other) {
  799. return other instanceof Repeat ?
  800. is(this._value, other._value) :
  801. deepEqual(other);
  802. };
  803. var EMPTY_REPEAT;
  804. function invariant(condition, error) {
  805. if (!condition) throw new Error(error);
  806. }
  807. createClass(Range, IndexedSeq);
  808. function Range(start, end, step) {
  809. if (!(this instanceof Range)) {
  810. return new Range(start, end, step);
  811. }
  812. invariant(step !== 0, 'Cannot step a Range by 0');
  813. start = start || 0;
  814. if (end === undefined) {
  815. end = Infinity;
  816. }
  817. step = step === undefined ? 1 : Math.abs(step);
  818. if (end < start) {
  819. step = -step;
  820. }
  821. this._start = start;
  822. this._end = end;
  823. this._step = step;
  824. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  825. if (this.size === 0) {
  826. if (EMPTY_RANGE) {
  827. return EMPTY_RANGE;
  828. }
  829. EMPTY_RANGE = this;
  830. }
  831. }
  832. Range.prototype.toString = function() {
  833. if (this.size === 0) {
  834. return 'Range []';
  835. }
  836. return 'Range [ ' +
  837. this._start + '...' + this._end +
  838. (this._step > 1 ? ' by ' + this._step : '') +
  839. ' ]';
  840. };
  841. Range.prototype.get = function(index, notSetValue) {
  842. return this.has(index) ?
  843. this._start + wrapIndex(this, index) * this._step :
  844. notSetValue;
  845. };
  846. Range.prototype.includes = function(searchValue) {
  847. var possibleIndex = (searchValue - this._start) / this._step;
  848. return possibleIndex >= 0 &&
  849. possibleIndex < this.size &&
  850. possibleIndex === Math.floor(possibleIndex);
  851. };
  852. Range.prototype.slice = function(begin, end) {
  853. if (wholeSlice(begin, end, this.size)) {
  854. return this;
  855. }
  856. begin = resolveBegin(begin, this.size);
  857. end = resolveEnd(end, this.size);
  858. if (end <= begin) {
  859. return new Range(0, 0);
  860. }
  861. return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
  862. };
  863. Range.prototype.indexOf = function(searchValue) {
  864. var offsetValue = searchValue - this._start;
  865. if (offsetValue % this._step === 0) {
  866. var index = offsetValue / this._step;
  867. if (index >= 0 && index < this.size) {
  868. return index
  869. }
  870. }
  871. return -1;
  872. };
  873. Range.prototype.lastIndexOf = function(searchValue) {
  874. return this.indexOf(searchValue);
  875. };
  876. Range.prototype.__iterate = function(fn, reverse) {
  877. var maxIndex = this.size - 1;
  878. var step = this._step;
  879. var value = reverse ? this._start + maxIndex * step : this._start;
  880. for (var ii = 0; ii <= maxIndex; ii++) {
  881. if (fn(value, ii, this) === false) {
  882. return ii + 1;
  883. }
  884. value += reverse ? -step : step;
  885. }
  886. return ii;
  887. };
  888. Range.prototype.__iterator = function(type, reverse) {
  889. var maxIndex = this.size - 1;
  890. var step = this._step;
  891. var value = reverse ? this._start + maxIndex * step : this._start;
  892. var ii = 0;
  893. return new Iterator(function() {
  894. var v = value;
  895. value += reverse ? -step : step;
  896. return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
  897. });
  898. };
  899. Range.prototype.equals = function(other) {
  900. return other instanceof Range ?
  901. this._start === other._start &&
  902. this._end === other._end &&
  903. this._step === other._step :
  904. deepEqual(this, other);
  905. };
  906. var EMPTY_RANGE;
  907. createClass(Collection, Iterable);
  908. function Collection() {
  909. throw TypeError('Abstract');
  910. }
  911. createClass(KeyedCollection, Collection);function KeyedCollection() {}
  912. createClass(IndexedCollection, Collection);function IndexedCollection() {}
  913. createClass(SetCollection, Collection);function SetCollection() {}
  914. Collection.Keyed = KeyedCollection;
  915. Collection.Indexed = IndexedCollection;
  916. Collection.Set = SetCollection;
  917. var imul =
  918. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
  919. Math.imul :
  920. function imul(a, b) {
  921. a = a | 0; // int
  922. b = b | 0; // int
  923. var c = a & 0xffff;
  924. var d = b & 0xffff;
  925. // Shift by 0 fixes the sign on the high part.
  926. return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int
  927. };
  928. // v8 has an optimization for storing 31-bit signed numbers.
  929. // Values which have either 00 or 11 as the high order bits qualify.
  930. // This function drops the highest order bit in a signed number, maintaining
  931. // the sign bit.
  932. function smi(i32) {
  933. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
  934. }
  935. function hash(o) {
  936. if (o === false || o === null || o === undefined) {
  937. return 0;
  938. }
  939. if (typeof o.valueOf === 'function') {
  940. o = o.valueOf();
  941. if (o === false || o === null || o === undefined) {
  942. return 0;
  943. }
  944. }
  945. if (o === true) {
  946. return 1;
  947. }
  948. var type = typeof o;
  949. if (type === 'number') {
  950. var h = o | 0;
  951. if (h !== o) {
  952. h ^= o * 0xFFFFFFFF;
  953. }
  954. while (o > 0xFFFFFFFF) {
  955. o /= 0xFFFFFFFF;
  956. h ^= o;
  957. }
  958. return smi(h);
  959. }
  960. if (type === 'string') {
  961. return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
  962. }
  963. if (typeof o.hashCode === 'function') {
  964. return o.hashCode();
  965. }
  966. if (type === 'object') {
  967. return hashJSObj(o);
  968. }
  969. if (typeof o.toString === 'function') {
  970. return hashString(o.toString());
  971. }
  972. throw new Error('Value type ' + type + ' cannot be hashed.');
  973. }
  974. function cachedHashString(string) {
  975. var hash = stringHashCache[string];
  976. if (hash === undefined) {
  977. hash = hashString(string);
  978. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  979. STRING_HASH_CACHE_SIZE = 0;
  980. stringHashCache = {};
  981. }
  982. STRING_HASH_CACHE_SIZE++;
  983. stringHashCache[string] = hash;
  984. }
  985. return hash;
  986. }
  987. // http://jsperf.com/hashing-strings
  988. function hashString(string) {
  989. // This is the hash from JVM
  990. // The hash code for a string is computed as
  991. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  992. // where s[i] is the ith character of the string and n is the length of
  993. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  994. // (exclusive) by dropping high bits.
  995. var hash = 0;
  996. for (var ii = 0; ii < string.length; ii++) {
  997. hash = 31 * hash + string.charCodeAt(ii) | 0;
  998. }
  999. return smi(hash);
  1000. }
  1001. function hashJSObj(obj) {
  1002. var hash;
  1003. if (usingWeakMap) {
  1004. hash = weakMap.get(obj);
  1005. if (hash !== undefined) {
  1006. return hash;
  1007. }
  1008. }
  1009. hash = obj[UID_HASH_KEY];
  1010. if (hash !== undefined) {
  1011. return hash;
  1012. }
  1013. if (!canDefineProperty) {
  1014. hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  1015. if (hash !== undefined) {
  1016. return hash;
  1017. }
  1018. hash = getIENodeHash(obj);
  1019. if (hash !== undefined) {
  1020. return hash;
  1021. }
  1022. }
  1023. hash = ++objHashUID;
  1024. if (objHashUID & 0x40000000) {
  1025. objHashUID = 0;
  1026. }
  1027. if (usingWeakMap) {
  1028. weakMap.set(obj, hash);
  1029. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  1030. throw new Error('Non-extensible objects are not allowed as keys.');
  1031. } else if (canDefineProperty) {
  1032. Object.defineProperty(obj, UID_HASH_KEY, {
  1033. 'enumerable': false,
  1034. 'configurable': false,
  1035. 'writable': false,
  1036. 'value': hash
  1037. });
  1038. } else if (obj.propertyIsEnumerable !== undefined &&
  1039. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
  1040. // Since we can't define a non-enumerable property on the object
  1041. // we'll hijack one of the less-used non-enumerable properties to
  1042. // save our hash on it. Since this is a function it will not show up in
  1043. // `JSON.stringify` which is what we want.
  1044. obj.propertyIsEnumerable = function() {
  1045. return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
  1046. };
  1047. obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
  1048. } else if (obj.nodeType !== undefined) {
  1049. // At this point we couldn't get the IE `uniqueID` to use as a hash
  1050. // and we couldn't use a non-enumerable property to exploit the
  1051. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  1052. // itself.
  1053. obj[UID_HASH_KEY] = hash;
  1054. } else {
  1055. throw new Error('Unable to set a non-enumerable property on object.');
  1056. }
  1057. return hash;
  1058. }
  1059. // Get references to ES5 object methods.
  1060. var isExtensible = Object.isExtensible;
  1061. // True if Object.defineProperty works as expected. IE8 fails this test.
  1062. var canDefineProperty = (function() {
  1063. try {
  1064. Object.defineProperty({}, '@', {});
  1065. return true;
  1066. } catch (e) {
  1067. return false;
  1068. }
  1069. }());
  1070. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  1071. // and avoid memory leaks from the IE cloneNode bug.
  1072. function getIENodeHash(node) {
  1073. if (node && node.nodeType > 0) {
  1074. switch (node.nodeType) {
  1075. case 1: // Element
  1076. return node.uniqueID;
  1077. case 9: // Document
  1078. return node.documentElement && node.documentElement.uniqueID;
  1079. }
  1080. }
  1081. }
  1082. // If possible, use a WeakMap.
  1083. var usingWeakMap = typeof WeakMap === 'function';
  1084. var weakMap;
  1085. if (usingWeakMap) {
  1086. weakMap = new WeakMap();
  1087. }
  1088. var objHashUID = 0;
  1089. var UID_HASH_KEY = '__immutablehash__';
  1090. if (typeof Symbol === 'function') {
  1091. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  1092. }
  1093. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  1094. var STRING_HASH_CACHE_MAX_SIZE = 255;
  1095. var STRING_HASH_CACHE_SIZE = 0;
  1096. var stringHashCache = {};
  1097. function assertNotInfinite(size) {
  1098. invariant(
  1099. size !== Infinity,
  1100. 'Cannot perform this action with an infinite size.'
  1101. );
  1102. }
  1103. createClass(Map, KeyedCollection);
  1104. // @pragma Construction
  1105. function Map(value) {
  1106. return value === null || value === undefined ? emptyMap() :
  1107. isMap(value) && !isOrdered(value) ? value :
  1108. emptyMap().withMutations(function(map ) {
  1109. var iter = KeyedIterable(value);
  1110. assertNotInfinite(iter.size);
  1111. iter.forEach(function(v, k) {return map.set(k, v)});
  1112. });
  1113. }
  1114. Map.prototype.toString = function() {
  1115. return this.__toString('Map {', '}');
  1116. };
  1117. // @pragma Access
  1118. Map.prototype.get = function(k, notSetValue) {
  1119. return this._root ?
  1120. this._root.get(0, undefined, k, notSetValue) :
  1121. notSetValue;
  1122. };
  1123. // @pragma Modification
  1124. Map.prototype.set = function(k, v) {
  1125. return updateMap(this, k, v);
  1126. };
  1127. Map.prototype.setIn = function(keyPath, v) {
  1128. return this.updateIn(keyPath, NOT_SET, function() {return v});
  1129. };
  1130. Map.prototype.remove = function(k) {
  1131. return updateMap(this, k, NOT_SET);
  1132. };
  1133. Map.prototype.deleteIn = function(keyPath) {
  1134. return this.updateIn(keyPath, function() {return NOT_SET});
  1135. };
  1136. Map.prototype.update = function(k, notSetValue, updater) {
  1137. return arguments.length === 1 ?
  1138. k(this) :
  1139. this.updateIn([k], notSetValue, updater);
  1140. };
  1141. Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
  1142. if (!updater) {
  1143. updater = notSetValue;
  1144. notSetValue = undefined;
  1145. }
  1146. var updatedValue = updateInDeepMap(
  1147. this,
  1148. forceIterator(keyPath),
  1149. notSetValue,
  1150. updater
  1151. );
  1152. return updatedValue === NOT_SET ? undefined : updatedValue;
  1153. };
  1154. Map.prototype.clear = function() {
  1155. if (this.size === 0) {
  1156. return this;
  1157. }
  1158. if (this.__ownerID) {
  1159. this.size = 0;
  1160. this._root = null;
  1161. this.__hash = undefined;
  1162. this.__altered = true;
  1163. return this;
  1164. }
  1165. return emptyMap();
  1166. };
  1167. // @pragma Composition
  1168. Map.prototype.merge = function(/*...iters*/) {
  1169. return mergeIntoMapWith(this, undefined, arguments);
  1170. };
  1171. Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1172. return mergeIntoMapWith(this, merger, iters);
  1173. };
  1174. Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  1175. return this.updateIn(
  1176. keyPath,
  1177. emptyMap(),
  1178. function(m ) {return typeof m.merge === 'function' ?
  1179. m.merge.apply(m, iters) :
  1180. iters[iters.length - 1]}
  1181. );
  1182. };
  1183. Map.prototype.mergeDeep = function(/*...iters*/) {
  1184. return mergeIntoMapWith(this, deepMerger, arguments);
  1185. };
  1186. Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1187. return mergeIntoMapWith(this, deepMergerWith(merger), iters);
  1188. };
  1189. Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  1190. return this.updateIn(
  1191. keyPath,
  1192. emptyMap(),
  1193. function(m ) {return typeof m.mergeDeep === 'function' ?
  1194. m.mergeDeep.apply(m, iters) :
  1195. iters[iters.length - 1]}
  1196. );
  1197. };
  1198. Map.prototype.sort = function(comparator) {
  1199. // Late binding
  1200. return OrderedMap(sortFactory(this, comparator));
  1201. };
  1202. Map.prototype.sortBy = function(mapper, comparator) {
  1203. // Late binding
  1204. return OrderedMap(sortFactory(this, comparator, mapper));
  1205. };
  1206. // @pragma Mutability
  1207. Map.prototype.withMutations = function(fn) {
  1208. var mutable = this.asMutable();
  1209. fn(mutable);
  1210. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  1211. };
  1212. Map.prototype.asMutable = function() {
  1213. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  1214. };
  1215. Map.prototype.asImmutable = function() {
  1216. return this.__ensureOwner();
  1217. };
  1218. Map.prototype.wasAltered = function() {
  1219. return this.__altered;
  1220. };
  1221. Map.prototype.__iterator = function(type, reverse) {
  1222. return new MapIterator(this, type, reverse);
  1223. };
  1224. Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  1225. var iterations = 0;
  1226. this._root && this._root.iterate(function(entry ) {
  1227. iterations++;
  1228. return fn(entry[1], entry[0], this$0);
  1229. }, reverse);
  1230. return iterations;
  1231. };
  1232. Map.prototype.__ensureOwner = function(ownerID) {
  1233. if (ownerID === this.__ownerID) {
  1234. return this;
  1235. }
  1236. if (!ownerID) {
  1237. this.__ownerID = ownerID;
  1238. this.__altered = false;
  1239. return this;
  1240. }
  1241. return makeMap(this.size, this._root, ownerID, this.__hash);
  1242. };
  1243. function isMap(maybeMap) {
  1244. return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
  1245. }
  1246. Map.isMap = isMap;
  1247. var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
  1248. var MapPrototype = Map.prototype;
  1249. MapPrototype[IS_MAP_SENTINEL] = true;
  1250. MapPrototype[DELETE] = MapPrototype.remove;
  1251. MapPrototype.removeIn = MapPrototype.deleteIn;
  1252. // #pragma Trie Nodes
  1253. function ArrayMapNode(ownerID, entries) {
  1254. this.ownerID = ownerID;
  1255. this.entries = entries;
  1256. }
  1257. ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1258. var entries = this.entries;
  1259. for (var ii = 0, len = entries.length; ii < len; ii++) {
  1260. if (is(key, entries[ii][0])) {
  1261. return entries[ii][1];
  1262. }
  1263. }
  1264. return notSetValue;
  1265. };
  1266. ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1267. var removed = value === NOT_SET;
  1268. var entries = this.entries;
  1269. var idx = 0;
  1270. for (var len = entries.length; idx < len; idx++) {
  1271. if (is(key, entries[idx][0])) {
  1272. break;
  1273. }
  1274. }
  1275. var exists = idx < len;
  1276. if (exists ? entries[idx][1] === value : removed) {
  1277. return this;
  1278. }
  1279. SetRef(didAlter);
  1280. (removed || !exists) && SetRef(didChangeSize);
  1281. if (removed && entries.length === 1) {
  1282. return; // undefined
  1283. }
  1284. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  1285. return createNodes(ownerID, entries, key, value);
  1286. }
  1287. var isEditable = ownerID && ownerID === this.ownerID;
  1288. var newEntries = isEditable ? entries : arrCopy(entries);
  1289. if (exists) {
  1290. if (removed) {
  1291. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  1292. } else {
  1293. newEntries[idx] = [key, value];
  1294. }
  1295. } else {
  1296. newEntries.push([key, value]);
  1297. }
  1298. if (isEditable) {
  1299. this.entries = newEntries;
  1300. return this;
  1301. }
  1302. return new ArrayMapNode(ownerID, newEntries);
  1303. };
  1304. function BitmapIndexedNode(ownerID, bitmap, nodes) {
  1305. this.ownerID = ownerID;
  1306. this.bitmap = bitmap;
  1307. this.nodes = nodes;
  1308. }
  1309. BitmapIndexedNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1310. if (keyHash === undefined) {
  1311. keyHash = hash(key);
  1312. }
  1313. var bit = (1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK));
  1314. var bitmap = this.bitmap;
  1315. return (bitmap & bit) === 0 ? notSetValue :
  1316. this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue);
  1317. };
  1318. BitmapIndexedNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1319. if (keyHash === undefined) {
  1320. keyHash = hash(key);
  1321. }
  1322. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1323. var bit = 1 << keyHashFrag;
  1324. var bitmap = this.bitmap;
  1325. var exists = (bitmap & bit) !== 0;
  1326. if (!exists && value === NOT_SET) {
  1327. return this;
  1328. }
  1329. var idx = popCount(bitmap & (bit - 1));
  1330. var nodes = this.nodes;
  1331. var node = exists ? nodes[idx] : undefined;
  1332. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  1333. if (newNode === node) {
  1334. return this;
  1335. }
  1336. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  1337. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  1338. }
  1339. if (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) {
  1340. return nodes[idx ^ 1];
  1341. }
  1342. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  1343. return newNode;
  1344. }
  1345. var isEditable = ownerID && ownerID === this.ownerID;
  1346. var newBitmap = exists ? newNode ? bitmap : bitmap ^ bit : bitmap | bit;
  1347. var newNodes = exists ? newNode ?
  1348. setIn(nodes, idx, newNode, isEditable) :
  1349. spliceOut(nodes, idx, isEditable) :
  1350. spliceIn(nodes, idx, newNode, isEditable);
  1351. if (isEditable) {
  1352. this.bitmap = newBitmap;
  1353. this.nodes = newNodes;
  1354. return this;
  1355. }
  1356. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  1357. };
  1358. function HashArrayMapNode(ownerID, count, nodes) {
  1359. this.ownerID = ownerID;
  1360. this.count = count;
  1361. this.nodes = nodes;
  1362. }
  1363. HashArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1364. if (keyHash === undefined) {
  1365. keyHash = hash(key);
  1366. }
  1367. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1368. var node = this.nodes[idx];
  1369. return node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue;
  1370. };
  1371. HashArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1372. if (keyHash === undefined) {
  1373. keyHash = hash(key);
  1374. }
  1375. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1376. var removed = value === NOT_SET;
  1377. var nodes = this.nodes;
  1378. var node = nodes[idx];
  1379. if (removed && !node) {
  1380. return this;
  1381. }
  1382. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  1383. if (newNode === node) {
  1384. return this;
  1385. }
  1386. var newCount = this.count;
  1387. if (!node) {
  1388. newCount++;
  1389. } else if (!newNode) {
  1390. newCount--;
  1391. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  1392. return packNodes(ownerID, nodes, newCount, idx);
  1393. }
  1394. }
  1395. var isEditable = ownerID && ownerID === this.ownerID;
  1396. var newNodes = setIn(nodes, idx, newNode, isEditable);
  1397. if (isEditable) {
  1398. this.count = newCount;
  1399. this.nodes = newNodes;
  1400. return this;
  1401. }
  1402. return new HashArrayMapNode(ownerID, newCount, newNodes);
  1403. };
  1404. function HashCollisionNode(ownerID, keyHash, entries) {
  1405. this.ownerID = ownerID;
  1406. this.keyHash = keyHash;
  1407. this.entries = entries;
  1408. }
  1409. HashCollisionNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1410. var entries = this.entries;
  1411. for (var ii = 0, len = entries.length; ii < len; ii++) {
  1412. if (is(key, entries[ii][0])) {
  1413. return entries[ii][1];
  1414. }
  1415. }
  1416. return notSetValue;
  1417. };
  1418. HashCollisionNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1419. if (keyHash === undefined) {
  1420. keyHash = hash(key);
  1421. }
  1422. var removed = value === NOT_SET;
  1423. if (keyHash !== this.keyHash) {
  1424. if (removed) {
  1425. return this;
  1426. }
  1427. SetRef(didAlter);
  1428. SetRef(didChangeSize);
  1429. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  1430. }
  1431. var entries = this.entries;
  1432. var idx = 0;
  1433. for (var len = entries.length; idx < len; idx++) {
  1434. if (is(key, entries[idx][0])) {
  1435. break;
  1436. }
  1437. }
  1438. var exists = idx < len;
  1439. if (exists ? entries[idx][1] === value : removed) {
  1440. return this;
  1441. }
  1442. SetRef(didAlter);
  1443. (removed || !exists) && SetRef(didChangeSize);
  1444. if (removed && len === 2) {
  1445. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  1446. }
  1447. var isEditable = ownerID && ownerID === this.ownerID;
  1448. var newEntries = isEditable ? entries : arrCopy(entries);
  1449. if (exists) {
  1450. if (removed) {
  1451. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  1452. } else {
  1453. newEntries[idx] = [key, value];
  1454. }
  1455. } else {
  1456. newEntries.push([key, value]);
  1457. }
  1458. if (isEditable) {
  1459. this.entries = newEntries;
  1460. return this;
  1461. }
  1462. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  1463. };
  1464. function ValueNode(ownerID, keyHash, entry) {
  1465. this.ownerID = ownerID;
  1466. this.keyHash = keyHash;
  1467. this.entry = entry;
  1468. }
  1469. ValueNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1470. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  1471. };
  1472. ValueNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1473. var removed = value === NOT_SET;
  1474. var keyMatch = is(key, this.entry[0]);
  1475. if (keyMatch ? value === this.entry[1] : removed) {
  1476. return this;
  1477. }
  1478. SetRef(didAlter);
  1479. if (removed) {
  1480. SetRef(didChangeSize);
  1481. return; // undefined
  1482. }
  1483. if (keyMatch) {
  1484. if (ownerID && ownerID === this.ownerID) {
  1485. this.entry[1] = value;
  1486. return this;
  1487. }
  1488. return new ValueNode(ownerID, this.keyHash, [key, value]);
  1489. }
  1490. SetRef(didChangeSize);
  1491. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  1492. };
  1493. // #pragma Iterators
  1494. ArrayMapNode.prototype.iterate =
  1495. HashCollisionNode.prototype.iterate = function (fn, reverse) {
  1496. var entries = this.entries;
  1497. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  1498. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  1499. return false;
  1500. }
  1501. }
  1502. };
  1503. BitmapIndexedNode.prototype.iterate =
  1504. HashArrayMapNode.prototype.iterate = function (fn, reverse) {
  1505. var nodes = this.nodes;
  1506. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  1507. var node = nodes[reverse ? maxIndex - ii : ii];
  1508. if (node && node.iterate(fn, reverse) === false) {
  1509. return false;
  1510. }
  1511. }
  1512. };
  1513. ValueNode.prototype.iterate = function (fn, reverse) {
  1514. return fn(this.entry);
  1515. };
  1516. createClass(MapIterator, Iterator);
  1517. function MapIterator(map, type, reverse) {
  1518. this._type = type;
  1519. this._reverse = reverse;
  1520. this._stack = map._root && mapIteratorFrame(map._root);
  1521. }
  1522. MapIterator.prototype.next = function() {
  1523. var type = this._type;
  1524. var stack = this._stack;
  1525. while (stack) {
  1526. var node = stack.node;
  1527. var index = stack.index++;
  1528. var maxIndex;
  1529. if (node.entry) {
  1530. if (index === 0) {
  1531. return mapIteratorValue(type, node.entry);
  1532. }
  1533. } else if (node.entries) {
  1534. maxIndex = node.entries.length - 1;
  1535. if (index <= maxIndex) {
  1536. return mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index]);
  1537. }
  1538. } else {
  1539. maxIndex = node.nodes.length - 1;
  1540. if (index <= maxIndex) {
  1541. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  1542. if (subNode) {
  1543. if (subNode.entry) {
  1544. return mapIteratorValue(type, subNode.entry);
  1545. }
  1546. stack = this._stack = mapIteratorFrame(subNode, stack);
  1547. }
  1548. continue;
  1549. }
  1550. }
  1551. stack = this._stack = this._stack.__prev;
  1552. }
  1553. return iteratorDone();
  1554. };
  1555. function mapIteratorValue(type, entry) {
  1556. return iteratorValue(type, entry[0], entry[1]);
  1557. }
  1558. function mapIteratorFrame(node, prev) {
  1559. return {
  1560. node: node,
  1561. index: 0,
  1562. __prev: prev
  1563. };
  1564. }
  1565. function makeMap(size, root, ownerID, hash) {
  1566. var map = Object.create(MapPrototype);
  1567. map.size = size;
  1568. map._root = root;
  1569. map.__ownerID = ownerID;
  1570. map.__hash = hash;
  1571. map.__altered = false;
  1572. return map;
  1573. }
  1574. var EMPTY_MAP;
  1575. function emptyMap() {
  1576. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  1577. }
  1578. function updateMap(map, k, v) {
  1579. var newRoot;
  1580. var newSize;
  1581. if (!map._root) {
  1582. if (v === NOT_SET) {
  1583. return map;
  1584. }
  1585. newSize = 1;
  1586. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  1587. } else {
  1588. var didChangeSize = MakeRef(CHANGE_LENGTH);
  1589. var didAlter = MakeRef(DID_ALTER);
  1590. newRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter);
  1591. if (!didAlter.value) {
  1592. return map;
  1593. }
  1594. newSize = map.size + (didChangeSize.value ? v === NOT_SET ? -1 : 1 : 0);
  1595. }
  1596. if (map.__ownerID) {
  1597. map.size = newSize;
  1598. map._root = newRoot;
  1599. map.__hash = undefined;
  1600. map.__altered = true;
  1601. return map;
  1602. }
  1603. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  1604. }
  1605. function updateNode(node, ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1606. if (!node) {
  1607. if (value === NOT_SET) {
  1608. return node;
  1609. }
  1610. SetRef(didAlter);
  1611. SetRef(didChangeSize);
  1612. return new ValueNode(ownerID, keyHash, [key, value]);
  1613. }
  1614. return node.update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter);
  1615. }
  1616. function isLeafNode(node) {
  1617. return node.constructor === ValueNode || node.constructor === HashCollisionNode;
  1618. }
  1619. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  1620. if (node.keyHash === keyHash) {
  1621. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  1622. }
  1623. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  1624. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1625. var newNode;
  1626. var nodes = idx1 === idx2 ?
  1627. [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)] :
  1628. ((newNode = new ValueNode(ownerID, keyHash, entry)), idx1 < idx2 ? [node, newNode] : [newNode, node]);
  1629. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  1630. }
  1631. function createNodes(ownerID, entries, key, value) {
  1632. if (!ownerID) {
  1633. ownerID = new OwnerID();
  1634. }
  1635. var node = new ValueNode(ownerID, hash(key), [key, value]);
  1636. for (var ii = 0; ii < entries.length; ii++) {
  1637. var entry = entries[ii];
  1638. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  1639. }
  1640. return node;
  1641. }
  1642. function packNodes(ownerID, nodes, count, excluding) {
  1643. var bitmap = 0;
  1644. var packedII = 0;
  1645. var packedNodes = new Array(count);
  1646. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  1647. var node = nodes[ii];
  1648. if (node !== undefined && ii !== excluding) {
  1649. bitmap |= bit;
  1650. packedNodes[packedII++] = node;
  1651. }
  1652. }
  1653. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  1654. }
  1655. function expandNodes(ownerID, nodes, bitmap, including, node) {
  1656. var count = 0;
  1657. var expandedNodes = new Array(SIZE);
  1658. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  1659. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  1660. }
  1661. expandedNodes[including] = node;
  1662. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  1663. }
  1664. function mergeIntoMapWith(map, merger, iterables) {
  1665. var iters = [];
  1666. for (var ii = 0; ii < iterables.length; ii++) {
  1667. var value = iterables[ii];
  1668. var iter = KeyedIterable(value);
  1669. if (!isIterable(value)) {
  1670. iter = iter.map(function(v ) {return fromJS(v)});
  1671. }
  1672. iters.push(iter);
  1673. }
  1674. return mergeIntoCollectionWith(map, merger, iters);
  1675. }
  1676. function deepMerger(existing, value, key) {
  1677. return existing && existing.mergeDeep && isIterable(value) ?
  1678. existing.mergeDeep(value) :
  1679. is(existing, value) ? existing : value;
  1680. }
  1681. function deepMergerWith(merger) {
  1682. return function(existing, value, key) {
  1683. if (existing && existing.mergeDeepWith && isIterable(value)) {
  1684. return existing.mergeDeepWith(merger, value);
  1685. }
  1686. var nextValue = merger(existing, value, key);
  1687. return is(existing, nextValue) ? existing : nextValue;
  1688. };
  1689. }
  1690. function mergeIntoCollectionWith(collection, merger, iters) {
  1691. iters = iters.filter(function(x ) {return x.size !== 0});
  1692. if (iters.length === 0) {
  1693. return collection;
  1694. }
  1695. if (collection.size === 0 && !collection.__ownerID && iters.length === 1) {
  1696. return collection.constructor(iters[0]);
  1697. }
  1698. return collection.withMutations(function(collection ) {
  1699. var mergeIntoMap = merger ?
  1700. function(value, key) {
  1701. collection.update(key, NOT_SET, function(existing )
  1702. {return existing === NOT_SET ? value : merger(existing, value, key)}
  1703. );
  1704. } :
  1705. function(value, key) {
  1706. collection.set(key, value);
  1707. };
  1708. for (var ii = 0; ii < iters.length; ii++) {
  1709. iters[ii].forEach(mergeIntoMap);
  1710. }
  1711. });
  1712. }
  1713. function updateInDeepMap(existing, keyPathIter, notSetValue, updater) {
  1714. var isNotSet = existing === NOT_SET;
  1715. var step = keyPathIter.next();
  1716. if (step.done) {
  1717. var existingValue = isNotSet ? notSetValue : existing;
  1718. var newValue = updater(existingValue);
  1719. return newValue === existingValue ? existing : newValue;
  1720. }
  1721. invariant(
  1722. isNotSet || (existing && existing.set),
  1723. 'invalid keyPath'
  1724. );
  1725. var key = step.value;
  1726. var nextExisting = isNotSet ? NOT_SET : existing.get(key, NOT_SET);
  1727. var nextUpdated = updateInDeepMap(
  1728. nextExisting,
  1729. keyPathIter,
  1730. notSetValue,
  1731. updater
  1732. );
  1733. return nextUpdated === nextExisting ? existing :
  1734. nextUpdated === NOT_SET ? existing.remove(key) :
  1735. (isNotSet ? emptyMap() : existing).set(key, nextUpdated);
  1736. }
  1737. function popCount(x) {
  1738. x = x - ((x >> 1) & 0x55555555);
  1739. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  1740. x = (x + (x >> 4)) & 0x0f0f0f0f;
  1741. x = x + (x >> 8);
  1742. x = x + (x >> 16);
  1743. return x & 0x7f;
  1744. }
  1745. function setIn(array, idx, val, canEdit) {
  1746. var newArray = canEdit ? array : arrCopy(array);
  1747. newArray[idx] = val;
  1748. return newArray;
  1749. }
  1750. function spliceIn(array, idx, val, canEdit) {
  1751. var newLen = array.length + 1;
  1752. if (canEdit && idx + 1 === newLen) {
  1753. array[idx] = val;
  1754. return array;
  1755. }
  1756. var newArray = new Array(newLen);
  1757. var after = 0;
  1758. for (var ii = 0; ii < newLen; ii++) {
  1759. if (ii === idx) {
  1760. newArray[ii] = val;
  1761. after = -1;
  1762. } else {
  1763. newArray[ii] = array[ii + after];
  1764. }
  1765. }
  1766. return newArray;
  1767. }
  1768. function spliceOut(array, idx, canEdit) {
  1769. var newLen = array.length - 1;
  1770. if (canEdit && idx === newLen) {
  1771. array.pop();
  1772. return array;
  1773. }
  1774. var newArray = new Array(newLen);
  1775. var after = 0;
  1776. for (var ii = 0; ii < newLen; ii++) {
  1777. if (ii === idx) {
  1778. after = 1;
  1779. }
  1780. newArray[ii] = array[ii + after];
  1781. }
  1782. return newArray;
  1783. }
  1784. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  1785. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  1786. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  1787. createClass(List, IndexedCollection);
  1788. // @pragma Construction
  1789. function List(value) {
  1790. var empty = emptyList();
  1791. if (value === null || value === undefined) {
  1792. return empty;
  1793. }
  1794. if (isList(value)) {
  1795. return value;
  1796. }
  1797. var iter = IndexedIterable(value);
  1798. var size = iter.size;
  1799. if (size === 0) {
  1800. return empty;
  1801. }
  1802. assertNotInfinite(size);
  1803. if (size > 0 && size < SIZE) {
  1804. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  1805. }
  1806. return empty.withMutations(function(list ) {
  1807. list.setSize(size);
  1808. iter.forEach(function(v, i) {return list.set(i, v)});
  1809. });
  1810. }
  1811. List.of = function(/*...values*/) {
  1812. return this(arguments);
  1813. };
  1814. List.prototype.toString = function() {
  1815. return this.__toString('List [', ']');
  1816. };
  1817. // @pragma Access
  1818. List.prototype.get = function(index, notSetValue) {
  1819. index = wrapIndex(this, index);
  1820. if (index >= 0 && index < this.size) {
  1821. index += this._origin;
  1822. var node = listNodeFor(this, index);
  1823. return node && node.array[index & MASK];
  1824. }
  1825. return notSetValue;
  1826. };
  1827. // @pragma Modification
  1828. List.prototype.set = function(index, value) {
  1829. return updateList(this, index, value);
  1830. };
  1831. List.prototype.remove = function(index) {
  1832. return !this.has(index) ? this :
  1833. index === 0 ? this.shift() :
  1834. index === this.size - 1 ? this.pop() :
  1835. this.splice(index, 1);
  1836. };
  1837. List.prototype.insert = function(index, value) {
  1838. return this.splice(index, 0, value);
  1839. };
  1840. List.prototype.clear = function() {
  1841. if (this.size === 0) {
  1842. return this;
  1843. }
  1844. if (this.__ownerID) {
  1845. this.size = this._origin = this._capacity = 0;
  1846. this._level = SHIFT;
  1847. this._root = this._tail = null;
  1848. this.__hash = undefined;
  1849. this.__altered = true;
  1850. return this;
  1851. }
  1852. return emptyList();
  1853. };
  1854. List.prototype.push = function(/*...values*/) {
  1855. var values = arguments;
  1856. var oldSize = this.size;
  1857. return this.withMutations(function(list ) {
  1858. setListBounds(list, 0, oldSize + values.length);
  1859. for (var ii = 0; ii < values.length; ii++) {
  1860. list.set(oldSize + ii, values[ii]);
  1861. }
  1862. });
  1863. };
  1864. List.prototype.pop = function() {
  1865. return setListBounds(this, 0, -1);
  1866. };
  1867. List.prototype.unshift = function(/*...values*/) {
  1868. var values = arguments;
  1869. return this.withMutations(function(list ) {
  1870. setListBounds(list, -values.length);
  1871. for (var ii = 0; ii < values.length; ii++) {
  1872. list.set(ii, values[ii]);
  1873. }
  1874. });
  1875. };
  1876. List.prototype.shift = function() {
  1877. return setListBounds(this, 1);
  1878. };
  1879. // @pragma Composition
  1880. List.prototype.merge = function(/*...iters*/) {
  1881. return mergeIntoListWith(this, undefined, arguments);
  1882. };
  1883. List.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1884. return mergeIntoListWith(this, merger, iters);
  1885. };
  1886. List.prototype.mergeDeep = function(/*...iters*/) {
  1887. return mergeIntoListWith(this, deepMerger, arguments);
  1888. };
  1889. List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1890. return mergeIntoListWith(this, deepMergerWith(merger), iters);
  1891. };
  1892. List.prototype.setSize = function(size) {
  1893. return setListBounds(this, 0, size);
  1894. };
  1895. // @pragma Iteration
  1896. List.prototype.slice = function(begin, end) {
  1897. var size = this.size;
  1898. if (wholeSlice(begin, end, size)) {
  1899. return this;
  1900. }
  1901. return setListBounds(
  1902. this,
  1903. resolveBegin(begin, size),
  1904. resolveEnd(end, size)
  1905. );
  1906. };
  1907. List.prototype.__iterator = function(type, reverse) {
  1908. var index = 0;
  1909. var values = iterateList(this, reverse);
  1910. return new Iterator(function() {
  1911. var value = values();
  1912. return value === DONE ?
  1913. iteratorDone() :
  1914. iteratorValue(type, index++, value);
  1915. });
  1916. };
  1917. List.prototype.__iterate = function(fn, reverse) {
  1918. var index = 0;
  1919. var values = iterateList(this, reverse);
  1920. var value;
  1921. while ((value = values()) !== DONE) {
  1922. if (fn(value, index++, this) === false) {
  1923. break;
  1924. }
  1925. }
  1926. return index;
  1927. };
  1928. List.prototype.__ensureOwner = function(ownerID) {
  1929. if (ownerID === this.__ownerID) {
  1930. return this;
  1931. }
  1932. if (!ownerID) {
  1933. this.__ownerID = ownerID;
  1934. return this;
  1935. }
  1936. return makeList(this._origin, this._capacity, this._level, this._root, this._tail, ownerID, this.__hash);
  1937. };
  1938. function isList(maybeList) {
  1939. return !!(maybeList && maybeList[IS_LIST_SENTINEL]);
  1940. }
  1941. List.isList = isList;
  1942. var IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
  1943. var ListPrototype = List.prototype;
  1944. ListPrototype[IS_LIST_SENTINEL] = true;
  1945. ListPrototype[DELETE] = ListPrototype.remove;
  1946. ListPrototype.setIn = MapPrototype.setIn;
  1947. ListPrototype.deleteIn =
  1948. ListPrototype.removeIn = MapPrototype.removeIn;
  1949. ListPrototype.update = MapPrototype.update;
  1950. ListPrototype.updateIn = MapPrototype.updateIn;
  1951. ListPrototype.mergeIn = MapPrototype.mergeIn;
  1952. ListPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  1953. ListPrototype.withMutations = MapPrototype.withMutations;
  1954. ListPrototype.asMutable = MapPrototype.asMutable;
  1955. ListPrototype.asImmutable = MapPrototype.asImmutable;
  1956. ListPrototype.wasAltered = MapPrototype.wasAltered;
  1957. function VNode(array, ownerID) {
  1958. this.array = array;
  1959. this.ownerID = ownerID;
  1960. }
  1961. // TODO: seems like these methods are very similar
  1962. VNode.prototype.removeBefore = function(ownerID, level, index) {
  1963. if (index === level ? 1 << level : this.array.length === 0) {
  1964. return this;
  1965. }
  1966. var originIndex = (index >>> level) & MASK;
  1967. if (originIndex >= this.array.length) {
  1968. return new VNode([], ownerID);
  1969. }
  1970. var removingFirst = originIndex === 0;
  1971. var newChild;
  1972. if (level > 0) {
  1973. var oldChild = this.array[originIndex];
  1974. newChild = oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  1975. if (newChild === oldChild && removingFirst) {
  1976. return this;
  1977. }
  1978. }
  1979. if (removingFirst && !newChild) {
  1980. return this;
  1981. }
  1982. var editable = editableVNode(this, ownerID);
  1983. if (!removingFirst) {
  1984. for (var ii = 0; ii < originIndex; ii++) {
  1985. editable.array[ii] = undefined;
  1986. }
  1987. }
  1988. if (newChild) {
  1989. editable.array[originIndex] = newChild;
  1990. }
  1991. return editable;
  1992. };
  1993. VNode.prototype.removeAfter = function(ownerID, level, index) {
  1994. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  1995. return this;
  1996. }
  1997. var sizeIndex = ((index - 1) >>> level) & MASK;
  1998. if (sizeIndex >= this.array.length) {
  1999. return this;
  2000. }
  2001. var newChild;
  2002. if (level > 0) {
  2003. var oldChild = this.array[sizeIndex];
  2004. newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  2005. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  2006. return this;
  2007. }
  2008. }
  2009. var editable = editableVNode(this, ownerID);
  2010. editable.array.splice(sizeIndex + 1);
  2011. if (newChild) {
  2012. editable.array[sizeIndex] = newChild;
  2013. }
  2014. return editable;
  2015. };
  2016. var DONE = {};
  2017. function iterateList(list, reverse) {
  2018. var left = list._origin;
  2019. var right = list._capacity;
  2020. var tailPos = getTailOffset(right);
  2021. var tail = list._tail;
  2022. return iterateNodeOrLeaf(list._root, list._level, 0);
  2023. function iterateNodeOrLeaf(node, level, offset) {
  2024. return level === 0 ?
  2025. iterateLeaf(node, offset) :
  2026. iterateNode(node, level, offset);
  2027. }
  2028. function iterateLeaf(node, offset) {
  2029. var array = offset === tailPos ? tail && tail.array : node && node.array;
  2030. var from = offset > left ? 0 : left - offset;
  2031. var to = right - offset;
  2032. if (to > SIZE) {
  2033. to = SIZE;
  2034. }
  2035. return function() {
  2036. if (from === to) {
  2037. return DONE;
  2038. }
  2039. var idx = reverse ? --to : from++;
  2040. return array && array[idx];
  2041. };
  2042. }
  2043. function iterateNode(node, level, offset) {
  2044. var values;
  2045. var array = node && node.array;
  2046. var from = offset > left ? 0 : (left - offset) >> level;
  2047. var to = ((right - offset) >> level) + 1;
  2048. if (to > SIZE) {
  2049. to = SIZE;
  2050. }
  2051. return function() {
  2052. do {
  2053. if (values) {
  2054. var value = values();
  2055. if (value !== DONE) {
  2056. return value;
  2057. }
  2058. values = null;
  2059. }
  2060. if (from === to) {
  2061. return DONE;
  2062. }
  2063. var idx = reverse ? --to : from++;
  2064. values = iterateNodeOrLeaf(
  2065. array && array[idx], level - SHIFT, offset + (idx << level)
  2066. );
  2067. } while (true);
  2068. };
  2069. }
  2070. }
  2071. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  2072. var list = Object.create(ListPrototype);
  2073. list.size = capacity - origin;
  2074. list._origin = origin;
  2075. list._capacity = capacity;
  2076. list._level = level;
  2077. list._root = root;
  2078. list._tail = tail;
  2079. list.__ownerID = ownerID;
  2080. list.__hash = hash;
  2081. list.__altered = false;
  2082. return list;
  2083. }
  2084. var EMPTY_LIST;
  2085. function emptyList() {
  2086. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  2087. }
  2088. function updateList(list, index, value) {
  2089. index = wrapIndex(list, index);
  2090. if (index !== index) {
  2091. return list;
  2092. }
  2093. if (index >= list.size || index < 0) {
  2094. return list.withMutations(function(list ) {
  2095. index < 0 ?
  2096. setListBounds(list, index).set(0, value) :
  2097. setListBounds(list, 0, index + 1).set(index, value);
  2098. });
  2099. }
  2100. index += list._origin;
  2101. var newTail = list._tail;
  2102. var newRoot = list._root;
  2103. var didAlter = MakeRef(DID_ALTER);
  2104. if (index >= getTailOffset(list._capacity)) {
  2105. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  2106. } else {
  2107. newRoot = updateVNode(newRoot, list.__ownerID, list._level, index, value, didAlter);
  2108. }
  2109. if (!didAlter.value) {
  2110. return list;
  2111. }
  2112. if (list.__ownerID) {
  2113. list._root = newRoot;
  2114. list._tail = newTail;
  2115. list.__hash = undefined;
  2116. list.__altered = true;
  2117. return list;
  2118. }
  2119. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  2120. }
  2121. function updateVNode(node, ownerID, level, index, value, didAlter) {
  2122. var idx = (index >>> level) & MASK;
  2123. var nodeHas = node && idx < node.array.length;
  2124. if (!nodeHas && value === undefined) {
  2125. return node;
  2126. }
  2127. var newNode;
  2128. if (level > 0) {
  2129. var lowerNode = node && node.array[idx];
  2130. var newLowerNode = updateVNode(lowerNode, ownerID, level - SHIFT, index, value, didAlter);
  2131. if (newLowerNode === lowerNode) {
  2132. return node;
  2133. }
  2134. newNode = editableVNode(node, ownerID);
  2135. newNode.array[idx] = newLowerNode;
  2136. return newNode;
  2137. }
  2138. if (nodeHas && node.array[idx] === value) {
  2139. return node;
  2140. }
  2141. SetRef(didAlter);
  2142. newNode = editableVNode(node, ownerID);
  2143. if (value === undefined && idx === newNode.array.length - 1) {
  2144. newNode.array.pop();
  2145. } else {
  2146. newNode.array[idx] = value;
  2147. }
  2148. return newNode;
  2149. }
  2150. function editableVNode(node, ownerID) {
  2151. if (ownerID && node && ownerID === node.ownerID) {
  2152. return node;
  2153. }
  2154. return new VNode(node ? node.array.slice() : [], ownerID);
  2155. }
  2156. function listNodeFor(list, rawIndex) {
  2157. if (rawIndex >= getTailOffset(list._capacity)) {
  2158. return list._tail;
  2159. }
  2160. if (rawIndex < 1 << (list._level + SHIFT)) {
  2161. var node = list._root;
  2162. var level = list._level;
  2163. while (node && level > 0) {
  2164. node = node.array[(rawIndex >>> level) & MASK];
  2165. level -= SHIFT;
  2166. }
  2167. return node;
  2168. }
  2169. }
  2170. function setListBounds(list, begin, end) {
  2171. // Sanitize begin & end using this shorthand for ToInt32(argument)
  2172. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  2173. if (begin !== undefined) {
  2174. begin = begin | 0;
  2175. }
  2176. if (end !== undefined) {
  2177. end = end | 0;
  2178. }
  2179. var owner = list.__ownerID || new OwnerID();
  2180. var oldOrigin = list._origin;
  2181. var oldCapacity = list._capacity;
  2182. var newOrigin = oldOrigin + begin;
  2183. var newCapacity = end === undefined ? oldCapacity : end < 0 ? oldCapacity + end : oldOrigin + end;
  2184. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  2185. return list;
  2186. }
  2187. // If it's going to end after it starts, it's empty.
  2188. if (newOrigin >= newCapacity) {
  2189. return list.clear();
  2190. }
  2191. var newLevel = list._level;
  2192. var newRoot = list._root;
  2193. // New origin might need creating a higher root.
  2194. var offsetShift = 0;
  2195. while (newOrigin + offsetShift < 0) {
  2196. newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner);
  2197. newLevel += SHIFT;
  2198. offsetShift += 1 << newLevel;
  2199. }
  2200. if (offsetShift) {
  2201. newOrigin += offsetShift;
  2202. oldOrigin += offsetShift;
  2203. newCapacity += offsetShift;
  2204. oldCapacity += offsetShift;
  2205. }
  2206. var oldTailOffset = getTailOffset(oldCapacity);
  2207. var newTailOffset = getTailOffset(newCapacity);
  2208. // New size might need creating a higher root.
  2209. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  2210. newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner);
  2211. newLevel += SHIFT;
  2212. }
  2213. // Locate or create the new tail.
  2214. var oldTail = list._tail;
  2215. var newTail = newTailOffset < oldTailOffset ?
  2216. listNodeFor(list, newCapacity - 1) :
  2217. newTailOffset > oldTailOffset ? new VNode([], owner) : oldTail;
  2218. // Merge Tail into tree.
  2219. if (oldTail && newTailOffset > oldTailOffset && newOrigin < oldCapacity && oldTail.array.length) {
  2220. newRoot = editableVNode(newRoot, owner);
  2221. var node = newRoot;
  2222. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  2223. var idx = (oldTailOffset >>> level) & MASK;
  2224. node = node.array[idx] = editableVNode(node.array[idx], owner);
  2225. }
  2226. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  2227. }
  2228. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  2229. if (newCapacity < oldCapacity) {
  2230. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  2231. }
  2232. // If the new origin is within the tail, then we do not need a root.
  2233. if (newOrigin >= newTailOffset) {
  2234. newOrigin -= newTailOffset;
  2235. newCapacity -= newTailOffset;
  2236. newLevel = SHIFT;
  2237. newRoot = null;
  2238. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  2239. // Otherwise, if the root has been trimmed, garbage collect.
  2240. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  2241. offsetShift = 0;
  2242. // Identify the new top root node of the subtree of the old root.
  2243. while (newRoot) {
  2244. var beginIndex = (newOrigin >>> newLevel) & MASK;
  2245. if (beginIndex !== (newTailOffset >>> newLevel) & MASK) {
  2246. break;
  2247. }
  2248. if (beginIndex) {
  2249. offsetShift += (1 << newLevel) * beginIndex;
  2250. }
  2251. newLevel -= SHIFT;
  2252. newRoot = newRoot.array[beginIndex];
  2253. }
  2254. // Trim the new sides of the new root.
  2255. if (newRoot && newOrigin > oldOrigin) {
  2256. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  2257. }
  2258. if (newRoot && newTailOffset < oldTailOffset) {
  2259. newRoot = newRoot.removeAfter(owner, newLevel, newTailOffset - offsetShift);
  2260. }
  2261. if (offsetShift) {
  2262. newOrigin -= offsetShift;
  2263. newCapacity -= offsetShift;
  2264. }
  2265. }
  2266. if (list.__ownerID) {
  2267. list.size = newCapacity - newOrigin;
  2268. list._origin = newOrigin;
  2269. list._capacity = newCapacity;
  2270. list._level = newLevel;
  2271. list._root = newRoot;
  2272. list._tail = newTail;
  2273. list.__hash = undefined;
  2274. list.__altered = true;
  2275. return list;
  2276. }
  2277. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  2278. }
  2279. function mergeIntoListWith(list, merger, iterables) {
  2280. var iters = [];
  2281. var maxSize = 0;
  2282. for (var ii = 0; ii < iterables.length; ii++) {
  2283. var value = iterables[ii];
  2284. var iter = IndexedIterable(value);
  2285. if (iter.size > maxSize) {
  2286. maxSize = iter.size;
  2287. }
  2288. if (!isIterable(value)) {
  2289. iter = iter.map(function(v ) {return fromJS(v)});
  2290. }
  2291. iters.push(iter);
  2292. }
  2293. if (maxSize > list.size) {
  2294. list = list.setSize(maxSize);
  2295. }
  2296. return mergeIntoCollectionWith(list, merger, iters);
  2297. }
  2298. function getTailOffset(size) {
  2299. return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
  2300. }
  2301. createClass(OrderedMap, Map);
  2302. // @pragma Construction
  2303. function OrderedMap(value) {
  2304. return value === null || value === undefined ? emptyOrderedMap() :
  2305. isOrderedMap(value) ? value :
  2306. emptyOrderedMap().withMutations(function(map ) {
  2307. var iter = KeyedIterable(value);
  2308. assertNotInfinite(iter.size);
  2309. iter.forEach(function(v, k) {return map.set(k, v)});
  2310. });
  2311. }
  2312. OrderedMap.of = function(/*...values*/) {
  2313. return this(arguments);
  2314. };
  2315. OrderedMap.prototype.toString = function() {
  2316. return this.__toString('OrderedMap {', '}');
  2317. };
  2318. // @pragma Access
  2319. OrderedMap.prototype.get = function(k, notSetValue) {
  2320. var index = this._map.get(k);
  2321. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  2322. };
  2323. // @pragma Modification
  2324. OrderedMap.prototype.clear = function() {
  2325. if (this.size === 0) {
  2326. return this;
  2327. }
  2328. if (this.__ownerID) {
  2329. this.size = 0;
  2330. this._map.clear();
  2331. this._list.clear();
  2332. return this;
  2333. }
  2334. return emptyOrderedMap();
  2335. };
  2336. OrderedMap.prototype.set = function(k, v) {
  2337. return updateOrderedMap(this, k, v);
  2338. };
  2339. OrderedMap.prototype.remove = function(k) {
  2340. return updateOrderedMap(this, k, NOT_SET);
  2341. };
  2342. OrderedMap.prototype.wasAltered = function() {
  2343. return this._map.wasAltered() || this._list.wasAltered();
  2344. };
  2345. OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2346. return this._list.__iterate(
  2347. function(entry ) {return entry && fn(entry[1], entry[0], this$0)},
  2348. reverse
  2349. );
  2350. };
  2351. OrderedMap.prototype.__iterator = function(type, reverse) {
  2352. return this._list.fromEntrySeq().__iterator(type, reverse);
  2353. };
  2354. OrderedMap.prototype.__ensureOwner = function(ownerID) {
  2355. if (ownerID === this.__ownerID) {
  2356. return this;
  2357. }
  2358. var newMap = this._map.__ensureOwner(ownerID);
  2359. var newList = this._list.__ensureOwner(ownerID);
  2360. if (!ownerID) {
  2361. this.__ownerID = ownerID;
  2362. this._map = newMap;
  2363. this._list = newList;
  2364. return this;
  2365. }
  2366. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  2367. };
  2368. function isOrderedMap(maybeOrderedMap) {
  2369. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  2370. }
  2371. OrderedMap.isOrderedMap = isOrderedMap;
  2372. OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
  2373. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  2374. function makeOrderedMap(map, list, ownerID, hash) {
  2375. var omap = Object.create(OrderedMap.prototype);
  2376. omap.size = map ? map.size : 0;
  2377. omap._map = map;
  2378. omap._list = list;
  2379. omap.__ownerID = ownerID;
  2380. omap.__hash = hash;
  2381. return omap;
  2382. }
  2383. var EMPTY_ORDERED_MAP;
  2384. function emptyOrderedMap() {
  2385. return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()));
  2386. }
  2387. function updateOrderedMap(omap, k, v) {
  2388. var map = omap._map;
  2389. var list = omap._list;
  2390. var i = map.get(k);
  2391. var has = i !== undefined;
  2392. var newMap;
  2393. var newList;
  2394. if (v === NOT_SET) { // removed
  2395. if (!has) {
  2396. return omap;
  2397. }
  2398. if (list.size >= SIZE && list.size >= map.size * 2) {
  2399. newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx});
  2400. newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap();
  2401. if (omap.__ownerID) {
  2402. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  2403. }
  2404. } else {
  2405. newMap = map.remove(k);
  2406. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  2407. }
  2408. } else {
  2409. if (has) {
  2410. if (v === list.get(i)[1]) {
  2411. return omap;
  2412. }
  2413. newMap = map;
  2414. newList = list.set(i, [k, v]);
  2415. } else {
  2416. newMap = map.set(k, list.size);
  2417. newList = list.set(list.size, [k, v]);
  2418. }
  2419. }
  2420. if (omap.__ownerID) {
  2421. omap.size = newMap.size;
  2422. omap._map = newMap;
  2423. omap._list = newList;
  2424. omap.__hash = undefined;
  2425. return omap;
  2426. }
  2427. return makeOrderedMap(newMap, newList);
  2428. }
  2429. createClass(ToKeyedSequence, KeyedSeq);
  2430. function ToKeyedSequence(indexed, useKeys) {
  2431. this._iter = indexed;
  2432. this._useKeys = useKeys;
  2433. this.size = indexed.size;
  2434. }
  2435. ToKeyedSequence.prototype.get = function(key, notSetValue) {
  2436. return this._iter.get(key, notSetValue);
  2437. };
  2438. ToKeyedSequence.prototype.has = function(key) {
  2439. return this._iter.has(key);
  2440. };
  2441. ToKeyedSequence.prototype.valueSeq = function() {
  2442. return this._iter.valueSeq();
  2443. };
  2444. ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
  2445. var reversedSequence = reverseFactory(this, true);
  2446. if (!this._useKeys) {
  2447. reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
  2448. }
  2449. return reversedSequence;
  2450. };
  2451. ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
  2452. var mappedSequence = mapFactory(this, mapper, context);
  2453. if (!this._useKeys) {
  2454. mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
  2455. }
  2456. return mappedSequence;
  2457. };
  2458. ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2459. var ii;
  2460. return this._iter.__iterate(
  2461. this._useKeys ?
  2462. function(v, k) {return fn(v, k, this$0)} :
  2463. ((ii = reverse ? resolveSize(this) : 0),
  2464. function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
  2465. reverse
  2466. );
  2467. };
  2468. ToKeyedSequence.prototype.__iterator = function(type, reverse) {
  2469. if (this._useKeys) {
  2470. return this._iter.__iterator(type, reverse);
  2471. }
  2472. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2473. var ii = reverse ? resolveSize(this) : 0;
  2474. return new Iterator(function() {
  2475. var step = iterator.next();
  2476. return step.done ? step :
  2477. iteratorValue(type, reverse ? --ii : ii++, step.value, step);
  2478. });
  2479. };
  2480. ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
  2481. createClass(ToIndexedSequence, IndexedSeq);
  2482. function ToIndexedSequence(iter) {
  2483. this._iter = iter;
  2484. this.size = iter.size;
  2485. }
  2486. ToIndexedSequence.prototype.includes = function(value) {
  2487. return this._iter.includes(value);
  2488. };
  2489. ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2490. var iterations = 0;
  2491. return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
  2492. };
  2493. ToIndexedSequence.prototype.__iterator = function(type, reverse) {
  2494. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2495. var iterations = 0;
  2496. return new Iterator(function() {
  2497. var step = iterator.next();
  2498. return step.done ? step :
  2499. iteratorValue(type, iterations++, step.value, step)
  2500. });
  2501. };
  2502. createClass(ToSetSequence, SetSeq);
  2503. function ToSetSequence(iter) {
  2504. this._iter = iter;
  2505. this.size = iter.size;
  2506. }
  2507. ToSetSequence.prototype.has = function(key) {
  2508. return this._iter.includes(key);
  2509. };
  2510. ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2511. return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
  2512. };
  2513. ToSetSequence.prototype.__iterator = function(type, reverse) {
  2514. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2515. return new Iterator(function() {
  2516. var step = iterator.next();
  2517. return step.done ? step :
  2518. iteratorValue(type, step.value, step.value, step);
  2519. });
  2520. };
  2521. createClass(FromEntriesSequence, KeyedSeq);
  2522. function FromEntriesSequence(entries) {
  2523. this._iter = entries;
  2524. this.size = entries.size;
  2525. }
  2526. FromEntriesSequence.prototype.entrySeq = function() {
  2527. return this._iter.toSeq();
  2528. };
  2529. FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2530. return this._iter.__iterate(function(entry ) {
  2531. // Check if entry exists first so array access doesn't throw for holes
  2532. // in the parent iteration.
  2533. if (entry) {
  2534. validateEntry(entry);
  2535. var indexedIterable = isIterable(entry);
  2536. return fn(
  2537. indexedIterable ? entry.get(1) : entry[1],
  2538. indexedIterable ? entry.get(0) : entry[0],
  2539. this$0
  2540. );
  2541. }
  2542. }, reverse);
  2543. };
  2544. FromEntriesSequence.prototype.__iterator = function(type, reverse) {
  2545. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2546. return new Iterator(function() {
  2547. while (true) {
  2548. var step = iterator.next();
  2549. if (step.done) {
  2550. return step;
  2551. }
  2552. var entry = step.value;
  2553. // Check if entry exists first so array access doesn't throw for holes
  2554. // in the parent iteration.
  2555. if (entry) {
  2556. validateEntry(entry);
  2557. var indexedIterable = isIterable(entry);
  2558. return iteratorValue(
  2559. type,
  2560. indexedIterable ? entry.get(0) : entry[0],
  2561. indexedIterable ? entry.get(1) : entry[1],
  2562. step
  2563. );
  2564. }
  2565. }
  2566. });
  2567. };
  2568. ToIndexedSequence.prototype.cacheResult =
  2569. ToKeyedSequence.prototype.cacheResult =
  2570. ToSetSequence.prototype.cacheResult =
  2571. FromEntriesSequence.prototype.cacheResult =
  2572. cacheResultThrough;
  2573. function flipFactory(iterable) {
  2574. var flipSequence = makeSequence(iterable);
  2575. flipSequence._iter = iterable;
  2576. flipSequence.size = iterable.size;
  2577. flipSequence.flip = function() {return iterable};
  2578. flipSequence.reverse = function () {
  2579. var reversedSequence = iterable.reverse.apply(this); // super.reverse()
  2580. reversedSequence.flip = function() {return iterable.reverse()};
  2581. return reversedSequence;
  2582. };
  2583. flipSequence.has = function(key ) {return iterable.includes(key)};
  2584. flipSequence.includes = function(key ) {return iterable.has(key)};
  2585. flipSequence.cacheResult = cacheResultThrough;
  2586. flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2587. return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
  2588. };
  2589. flipSequence.__iteratorUncached = function(type, reverse) {
  2590. if (type === ITERATE_ENTRIES) {
  2591. var iterator = iterable.__iterator(type, reverse);
  2592. return new Iterator(function() {
  2593. var step = iterator.next();
  2594. if (!step.done) {
  2595. var k = step.value[0];
  2596. step.value[0] = step.value[1];
  2597. step.value[1] = k;
  2598. }
  2599. return step;
  2600. });
  2601. }
  2602. return iterable.__iterator(
  2603. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  2604. reverse
  2605. );
  2606. };
  2607. return flipSequence;
  2608. }
  2609. function mapFactory(iterable, mapper, context) {
  2610. var mappedSequence = makeSequence(iterable);
  2611. mappedSequence.size = iterable.size;
  2612. mappedSequence.has = function(key ) {return iterable.has(key)};
  2613. mappedSequence.get = function(key, notSetValue) {
  2614. var v = iterable.get(key, NOT_SET);
  2615. return v === NOT_SET ?
  2616. notSetValue :
  2617. mapper.call(context, v, key, iterable);
  2618. };
  2619. mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2620. return iterable.__iterate(
  2621. function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
  2622. reverse
  2623. );
  2624. };
  2625. mappedSequence.__iteratorUncached = function (type, reverse) {
  2626. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2627. return new Iterator(function() {
  2628. var step = iterator.next();
  2629. if (step.done) {
  2630. return step;
  2631. }
  2632. var entry = step.value;
  2633. var key = entry[0];
  2634. return iteratorValue(
  2635. type,
  2636. key,
  2637. mapper.call(context, entry[1], key, iterable),
  2638. step
  2639. );
  2640. });
  2641. };
  2642. return mappedSequence;
  2643. }
  2644. function reverseFactory(iterable, useKeys) {
  2645. var reversedSequence = makeSequence(iterable);
  2646. reversedSequence._iter = iterable;
  2647. reversedSequence.size = iterable.size;
  2648. reversedSequence.reverse = function() {return iterable};
  2649. if (iterable.flip) {
  2650. reversedSequence.flip = function () {
  2651. var flipSequence = flipFactory(iterable);
  2652. flipSequence.reverse = function() {return iterable.flip()};
  2653. return flipSequence;
  2654. };
  2655. }
  2656. reversedSequence.get = function(key, notSetValue)
  2657. {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
  2658. reversedSequence.has = function(key )
  2659. {return iterable.has(useKeys ? key : -1 - key)};
  2660. reversedSequence.includes = function(value ) {return iterable.includes(value)};
  2661. reversedSequence.cacheResult = cacheResultThrough;
  2662. reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
  2663. return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
  2664. };
  2665. reversedSequence.__iterator =
  2666. function(type, reverse) {return iterable.__iterator(type, !reverse)};
  2667. return reversedSequence;
  2668. }
  2669. function filterFactory(iterable, predicate, context, useKeys) {
  2670. var filterSequence = makeSequence(iterable);
  2671. if (useKeys) {
  2672. filterSequence.has = function(key ) {
  2673. var v = iterable.get(key, NOT_SET);
  2674. return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
  2675. };
  2676. filterSequence.get = function(key, notSetValue) {
  2677. var v = iterable.get(key, NOT_SET);
  2678. return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
  2679. v : notSetValue;
  2680. };
  2681. }
  2682. filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2683. var iterations = 0;
  2684. iterable.__iterate(function(v, k, c) {
  2685. if (predicate.call(context, v, k, c)) {
  2686. iterations++;
  2687. return fn(v, useKeys ? k : iterations - 1, this$0);
  2688. }
  2689. }, reverse);
  2690. return iterations;
  2691. };
  2692. filterSequence.__iteratorUncached = function (type, reverse) {
  2693. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2694. var iterations = 0;
  2695. return new Iterator(function() {
  2696. while (true) {
  2697. var step = iterator.next();
  2698. if (step.done) {
  2699. return step;
  2700. }
  2701. var entry = step.value;
  2702. var key = entry[0];
  2703. var value = entry[1];
  2704. if (predicate.call(context, value, key, iterable)) {
  2705. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  2706. }
  2707. }
  2708. });
  2709. };
  2710. return filterSequence;
  2711. }
  2712. function countByFactory(iterable, grouper, context) {
  2713. var groups = Map().asMutable();
  2714. iterable.__iterate(function(v, k) {
  2715. groups.update(
  2716. grouper.call(context, v, k, iterable),
  2717. 0,
  2718. function(a ) {return a + 1}
  2719. );
  2720. });
  2721. return groups.asImmutable();
  2722. }
  2723. function groupByFactory(iterable, grouper, context) {
  2724. var isKeyedIter = isKeyed(iterable);
  2725. var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable();
  2726. iterable.__iterate(function(v, k) {
  2727. groups.update(
  2728. grouper.call(context, v, k, iterable),
  2729. function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
  2730. );
  2731. });
  2732. var coerce = iterableClass(iterable);
  2733. return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
  2734. }
  2735. function sliceFactory(iterable, begin, end, useKeys) {
  2736. var originalSize = iterable.size;
  2737. // Sanitize begin & end using this shorthand for ToInt32(argument)
  2738. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  2739. if (begin !== undefined) {
  2740. begin = begin | 0;
  2741. }
  2742. if (end !== undefined) {
  2743. end = end | 0;
  2744. }
  2745. if (wholeSlice(begin, end, originalSize)) {
  2746. return iterable;
  2747. }
  2748. var resolvedBegin = resolveBegin(begin, originalSize);
  2749. var resolvedEnd = resolveEnd(end, originalSize);
  2750. // begin or end will be NaN if they were provided as negative numbers and
  2751. // this iterable's size is unknown. In that case, cache first so there is
  2752. // a known size and these do not resolve to NaN.
  2753. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  2754. return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
  2755. }
  2756. // Note: resolvedEnd is undefined when the original sequence's length is
  2757. // unknown and this slice did not supply an end and should contain all
  2758. // elements after resolvedBegin.
  2759. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  2760. var resolvedSize = resolvedEnd - resolvedBegin;
  2761. var sliceSize;
  2762. if (resolvedSize === resolvedSize) {
  2763. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  2764. }
  2765. var sliceSeq = makeSequence(iterable);
  2766. // If iterable.size is undefined, the size of the realized sliceSeq is
  2767. // unknown at this point unless the number of items to slice is 0
  2768. sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
  2769. if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
  2770. sliceSeq.get = function (index, notSetValue) {
  2771. index = wrapIndex(this, index);
  2772. return index >= 0 && index < sliceSize ?
  2773. iterable.get(index + resolvedBegin, notSetValue) :
  2774. notSetValue;
  2775. };
  2776. }
  2777. sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
  2778. if (sliceSize === 0) {
  2779. return 0;
  2780. }
  2781. if (reverse) {
  2782. return this.cacheResult().__iterate(fn, reverse);
  2783. }
  2784. var skipped = 0;
  2785. var isSkipping = true;
  2786. var iterations = 0;
  2787. iterable.__iterate(function(v, k) {
  2788. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  2789. iterations++;
  2790. return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
  2791. iterations !== sliceSize;
  2792. }
  2793. });
  2794. return iterations;
  2795. };
  2796. sliceSeq.__iteratorUncached = function(type, reverse) {
  2797. if (sliceSize !== 0 && reverse) {
  2798. return this.cacheResult().__iterator(type, reverse);
  2799. }
  2800. // Don't bother instantiating parent iterator if taking 0.
  2801. var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
  2802. var skipped = 0;
  2803. var iterations = 0;
  2804. return new Iterator(function() {
  2805. while (skipped++ < resolvedBegin) {
  2806. iterator.next();
  2807. }
  2808. if (++iterations > sliceSize) {
  2809. return iteratorDone();
  2810. }
  2811. var step = iterator.next();
  2812. if (useKeys || type === ITERATE_VALUES) {
  2813. return step;
  2814. } else if (type === ITERATE_KEYS) {
  2815. return iteratorValue(type, iterations - 1, undefined, step);
  2816. } else {
  2817. return iteratorValue(type, iterations - 1, step.value[1], step);
  2818. }
  2819. });
  2820. };
  2821. return sliceSeq;
  2822. }
  2823. function takeWhileFactory(iterable, predicate, context) {
  2824. var takeSequence = makeSequence(iterable);
  2825. takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  2826. if (reverse) {
  2827. return this.cacheResult().__iterate(fn, reverse);
  2828. }
  2829. var iterations = 0;
  2830. iterable.__iterate(function(v, k, c)
  2831. {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
  2832. );
  2833. return iterations;
  2834. };
  2835. takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  2836. if (reverse) {
  2837. return this.cacheResult().__iterator(type, reverse);
  2838. }
  2839. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2840. var iterating = true;
  2841. return new Iterator(function() {
  2842. if (!iterating) {
  2843. return iteratorDone();
  2844. }
  2845. var step = iterator.next();
  2846. if (step.done) {
  2847. return step;
  2848. }
  2849. var entry = step.value;
  2850. var k = entry[0];
  2851. var v = entry[1];
  2852. if (!predicate.call(context, v, k, this$0)) {
  2853. iterating = false;
  2854. return iteratorDone();
  2855. }
  2856. return type === ITERATE_ENTRIES ? step :
  2857. iteratorValue(type, k, v, step);
  2858. });
  2859. };
  2860. return takeSequence;
  2861. }
  2862. function skipWhileFactory(iterable, predicate, context, useKeys) {
  2863. var skipSequence = makeSequence(iterable);
  2864. skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2865. if (reverse) {
  2866. return this.cacheResult().__iterate(fn, reverse);
  2867. }
  2868. var isSkipping = true;
  2869. var iterations = 0;
  2870. iterable.__iterate(function(v, k, c) {
  2871. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  2872. iterations++;
  2873. return fn(v, useKeys ? k : iterations - 1, this$0);
  2874. }
  2875. });
  2876. return iterations;
  2877. };
  2878. skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  2879. if (reverse) {
  2880. return this.cacheResult().__iterator(type, reverse);
  2881. }
  2882. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2883. var skipping = true;
  2884. var iterations = 0;
  2885. return new Iterator(function() {
  2886. var step, k, v;
  2887. do {
  2888. step = iterator.next();
  2889. if (step.done) {
  2890. if (useKeys || type === ITERATE_VALUES) {
  2891. return step;
  2892. } else if (type === ITERATE_KEYS) {
  2893. return iteratorValue(type, iterations++, undefined, step);
  2894. } else {
  2895. return iteratorValue(type, iterations++, step.value[1], step);
  2896. }
  2897. }
  2898. var entry = step.value;
  2899. k = entry[0];
  2900. v = entry[1];
  2901. skipping && (skipping = predicate.call(context, v, k, this$0));
  2902. } while (skipping);
  2903. return type === ITERATE_ENTRIES ? step :
  2904. iteratorValue(type, k, v, step);
  2905. });
  2906. };
  2907. return skipSequence;
  2908. }
  2909. function concatFactory(iterable, values) {
  2910. var isKeyedIterable = isKeyed(iterable);
  2911. var iters = [iterable].concat(values).map(function(v ) {
  2912. if (!isIterable(v)) {
  2913. v = isKeyedIterable ?
  2914. keyedSeqFromValue(v) :
  2915. indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  2916. } else if (isKeyedIterable) {
  2917. v = KeyedIterable(v);
  2918. }
  2919. return v;
  2920. }).filter(function(v ) {return v.size !== 0});
  2921. if (iters.length === 0) {
  2922. return iterable;
  2923. }
  2924. if (iters.length === 1) {
  2925. var singleton = iters[0];
  2926. if (singleton === iterable ||
  2927. isKeyedIterable && isKeyed(singleton) ||
  2928. isIndexed(iterable) && isIndexed(singleton)) {
  2929. return singleton;
  2930. }
  2931. }
  2932. var concatSeq = new ArraySeq(iters);
  2933. if (isKeyedIterable) {
  2934. concatSeq = concatSeq.toKeyedSeq();
  2935. } else if (!isIndexed(iterable)) {
  2936. concatSeq = concatSeq.toSetSeq();
  2937. }
  2938. concatSeq = concatSeq.flatten(true);
  2939. concatSeq.size = iters.reduce(
  2940. function(sum, seq) {
  2941. if (sum !== undefined) {
  2942. var size = seq.size;
  2943. if (size !== undefined) {
  2944. return sum + size;
  2945. }
  2946. }
  2947. },
  2948. 0
  2949. );
  2950. return concatSeq;
  2951. }
  2952. function flattenFactory(iterable, depth, useKeys) {
  2953. var flatSequence = makeSequence(iterable);
  2954. flatSequence.__iterateUncached = function(fn, reverse) {
  2955. var iterations = 0;
  2956. var stopped = false;
  2957. function flatDeep(iter, currentDepth) {var this$0 = this;
  2958. iter.__iterate(function(v, k) {
  2959. if ((!depth || currentDepth < depth) && isIterable(v)) {
  2960. flatDeep(v, currentDepth + 1);
  2961. } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
  2962. stopped = true;
  2963. }
  2964. return !stopped;
  2965. }, reverse);
  2966. }
  2967. flatDeep(iterable, 0);
  2968. return iterations;
  2969. };
  2970. flatSequence.__iteratorUncached = function(type, reverse) {
  2971. var iterator = iterable.__iterator(type, reverse);
  2972. var stack = [];
  2973. var iterations = 0;
  2974. return new Iterator(function() {
  2975. while (iterator) {
  2976. var step = iterator.next();
  2977. if (step.done !== false) {
  2978. iterator = stack.pop();
  2979. continue;
  2980. }
  2981. var v = step.value;
  2982. if (type === ITERATE_ENTRIES) {
  2983. v = v[1];
  2984. }
  2985. if ((!depth || stack.length < depth) && isIterable(v)) {
  2986. stack.push(iterator);
  2987. iterator = v.__iterator(type, reverse);
  2988. } else {
  2989. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  2990. }
  2991. }
  2992. return iteratorDone();
  2993. });
  2994. };
  2995. return flatSequence;
  2996. }
  2997. function flatMapFactory(iterable, mapper, context) {
  2998. var coerce = iterableClass(iterable);
  2999. return iterable.toSeq().map(
  3000. function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
  3001. ).flatten(true);
  3002. }
  3003. function interposeFactory(iterable, separator) {
  3004. var interposedSequence = makeSequence(iterable);
  3005. interposedSequence.size = iterable.size && iterable.size * 2 -1;
  3006. interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  3007. var iterations = 0;
  3008. iterable.__iterate(function(v, k)
  3009. {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
  3010. fn(v, iterations++, this$0) !== false},
  3011. reverse
  3012. );
  3013. return iterations;
  3014. };
  3015. interposedSequence.__iteratorUncached = function(type, reverse) {
  3016. var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
  3017. var iterations = 0;
  3018. var step;
  3019. return new Iterator(function() {
  3020. if (!step || iterations % 2) {
  3021. step = iterator.next();
  3022. if (step.done) {
  3023. return step;
  3024. }
  3025. }
  3026. return iterations % 2 ?
  3027. iteratorValue(type, iterations++, separator) :
  3028. iteratorValue(type, iterations++, step.value, step);
  3029. });
  3030. };
  3031. return interposedSequence;
  3032. }
  3033. function sortFactory(iterable, comparator, mapper) {
  3034. if (!comparator) {
  3035. comparator = defaultComparator;
  3036. }
  3037. var isKeyedIterable = isKeyed(iterable);
  3038. var index = 0;
  3039. var entries = iterable.toSeq().map(
  3040. function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
  3041. ).toArray();
  3042. entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
  3043. isKeyedIterable ?
  3044. function(v, i) { entries[i].length = 2; } :
  3045. function(v, i) { entries[i] = v[1]; }
  3046. );
  3047. return isKeyedIterable ? KeyedSeq(entries) :
  3048. isIndexed(iterable) ? IndexedSeq(entries) :
  3049. SetSeq(entries);
  3050. }
  3051. function maxFactory(iterable, comparator, mapper) {
  3052. if (!comparator) {
  3053. comparator = defaultComparator;
  3054. }
  3055. if (mapper) {
  3056. var entry = iterable.toSeq()
  3057. .map(function(v, k) {return [v, mapper(v, k, iterable)]})
  3058. .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
  3059. return entry && entry[0];
  3060. } else {
  3061. return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
  3062. }
  3063. }
  3064. function maxCompare(comparator, a, b) {
  3065. var comp = comparator(b, a);
  3066. // b is considered the new max if the comparator declares them equal, but
  3067. // they are not equal and b is in fact a nullish value.
  3068. return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
  3069. }
  3070. function zipWithFactory(keyIter, zipper, iters) {
  3071. var zipSequence = makeSequence(keyIter);
  3072. zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
  3073. // Note: this a generic base implementation of __iterate in terms of
  3074. // __iterator which may be more generically useful in the future.
  3075. zipSequence.__iterate = function(fn, reverse) {
  3076. /* generic:
  3077. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  3078. var step;
  3079. var iterations = 0;
  3080. while (!(step = iterator.next()).done) {
  3081. iterations++;
  3082. if (fn(step.value[1], step.value[0], this) === false) {
  3083. break;
  3084. }
  3085. }
  3086. return iterations;
  3087. */
  3088. // indexed:
  3089. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  3090. var step;
  3091. var iterations = 0;
  3092. while (!(step = iterator.next()).done) {
  3093. if (fn(step.value, iterations++, this) === false) {
  3094. break;
  3095. }
  3096. }
  3097. return iterations;
  3098. };
  3099. zipSequence.__iteratorUncached = function(type, reverse) {
  3100. var iterators = iters.map(function(i )
  3101. {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
  3102. );
  3103. var iterations = 0;
  3104. var isDone = false;
  3105. return new Iterator(function() {
  3106. var steps;
  3107. if (!isDone) {
  3108. steps = iterators.map(function(i ) {return i.next()});
  3109. isDone = steps.some(function(s ) {return s.done});
  3110. }
  3111. if (isDone) {
  3112. return iteratorDone();
  3113. }
  3114. return iteratorValue(
  3115. type,
  3116. iterations++,
  3117. zipper.apply(null, steps.map(function(s ) {return s.value}))
  3118. );
  3119. });
  3120. };
  3121. return zipSequence
  3122. }
  3123. // #pragma Helper Functions
  3124. function reify(iter, seq) {
  3125. return isSeq(iter) ? seq : iter.constructor(seq);
  3126. }
  3127. function validateEntry(entry) {
  3128. if (entry !== Object(entry)) {
  3129. throw new TypeError('Expected [K, V] tuple: ' + entry);
  3130. }
  3131. }
  3132. function resolveSize(iter) {
  3133. assertNotInfinite(iter.size);
  3134. return ensureSize(iter);
  3135. }
  3136. function iterableClass(iterable) {
  3137. return isKeyed(iterable) ? KeyedIterable :
  3138. isIndexed(iterable) ? IndexedIterable :
  3139. SetIterable;
  3140. }
  3141. function makeSequence(iterable) {
  3142. return Object.create(
  3143. (
  3144. isKeyed(iterable) ? KeyedSeq :
  3145. isIndexed(iterable) ? IndexedSeq :
  3146. SetSeq
  3147. ).prototype
  3148. );
  3149. }
  3150. function cacheResultThrough() {
  3151. if (this._iter.cacheResult) {
  3152. this._iter.cacheResult();
  3153. this.size = this._iter.size;
  3154. return this;
  3155. } else {
  3156. return Seq.prototype.cacheResult.call(this);
  3157. }
  3158. }
  3159. function defaultComparator(a, b) {
  3160. return a > b ? 1 : a < b ? -1 : 0;
  3161. }
  3162. function forceIterator(keyPath) {
  3163. var iter = getIterator(keyPath);
  3164. if (!iter) {
  3165. // Array might not be iterable in this environment, so we need a fallback
  3166. // to our wrapped type.
  3167. if (!isArrayLike(keyPath)) {
  3168. throw new TypeError('Expected iterable or array-like: ' + keyPath);
  3169. }
  3170. iter = getIterator(Iterable(keyPath));
  3171. }
  3172. return iter;
  3173. }
  3174. createClass(Record, KeyedCollection);
  3175. function Record(defaultValues, name) {
  3176. var hasInitialized;
  3177. var RecordType = function Record(values) {
  3178. if (values instanceof RecordType) {
  3179. return values;
  3180. }
  3181. if (!(this instanceof RecordType)) {
  3182. return new RecordType(values);
  3183. }
  3184. if (!hasInitialized) {
  3185. hasInitialized = true;
  3186. var keys = Object.keys(defaultValues);
  3187. setProps(RecordTypePrototype, keys);
  3188. RecordTypePrototype.size = keys.length;
  3189. RecordTypePrototype._name = name;
  3190. RecordTypePrototype._keys = keys;
  3191. RecordTypePrototype._defaultValues = defaultValues;
  3192. }
  3193. this._map = Map(values);
  3194. };
  3195. var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
  3196. RecordTypePrototype.constructor = RecordType;
  3197. return RecordType;
  3198. }
  3199. Record.prototype.toString = function() {
  3200. return this.__toString(recordName(this) + ' {', '}');
  3201. };
  3202. // @pragma Access
  3203. Record.prototype.has = function(k) {
  3204. return this._defaultValues.hasOwnProperty(k);
  3205. };
  3206. Record.prototype.get = function(k, notSetValue) {
  3207. if (!this.has(k)) {
  3208. return notSetValue;
  3209. }
  3210. var defaultVal = this._defaultValues[k];
  3211. return this._map ? this._map.get(k, defaultVal) : defaultVal;
  3212. };
  3213. // @pragma Modification
  3214. Record.prototype.clear = function() {
  3215. if (this.__ownerID) {
  3216. this._map && this._map.clear();
  3217. return this;
  3218. }
  3219. var RecordType = this.constructor;
  3220. return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap()));
  3221. };
  3222. Record.prototype.set = function(k, v) {
  3223. if (!this.has(k)) {
  3224. throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
  3225. }
  3226. var newMap = this._map && this._map.set(k, v);
  3227. if (this.__ownerID || newMap === this._map) {
  3228. return this;
  3229. }
  3230. return makeRecord(this, newMap);
  3231. };
  3232. Record.prototype.remove = function(k) {
  3233. if (!this.has(k)) {
  3234. return this;
  3235. }
  3236. var newMap = this._map && this._map.remove(k);
  3237. if (this.__ownerID || newMap === this._map) {
  3238. return this;
  3239. }
  3240. return makeRecord(this, newMap);
  3241. };
  3242. Record.prototype.wasAltered = function() {
  3243. return this._map.wasAltered();
  3244. };
  3245. Record.prototype.__iterator = function(type, reverse) {var this$0 = this;
  3246. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse);
  3247. };
  3248. Record.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  3249. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse);
  3250. };
  3251. Record.prototype.__ensureOwner = function(ownerID) {
  3252. if (ownerID === this.__ownerID) {
  3253. return this;
  3254. }
  3255. var newMap = this._map && this._map.__ensureOwner(ownerID);
  3256. if (!ownerID) {
  3257. this.__ownerID = ownerID;
  3258. this._map = newMap;
  3259. return this;
  3260. }
  3261. return makeRecord(this, newMap, ownerID);
  3262. };
  3263. var RecordPrototype = Record.prototype;
  3264. RecordPrototype[DELETE] = RecordPrototype.remove;
  3265. RecordPrototype.deleteIn =
  3266. RecordPrototype.removeIn = MapPrototype.removeIn;
  3267. RecordPrototype.merge = MapPrototype.merge;
  3268. RecordPrototype.mergeWith = MapPrototype.mergeWith;
  3269. RecordPrototype.mergeIn = MapPrototype.mergeIn;
  3270. RecordPrototype.mergeDeep = MapPrototype.mergeDeep;
  3271. RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith;
  3272. RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  3273. RecordPrototype.setIn = MapPrototype.setIn;
  3274. RecordPrototype.update = MapPrototype.update;
  3275. RecordPrototype.updateIn = MapPrototype.updateIn;
  3276. RecordPrototype.withMutations = MapPrototype.withMutations;
  3277. RecordPrototype.asMutable = MapPrototype.asMutable;
  3278. RecordPrototype.asImmutable = MapPrototype.asImmutable;
  3279. function makeRecord(likeRecord, map, ownerID) {
  3280. var record = Object.create(Object.getPrototypeOf(likeRecord));
  3281. record._map = map;
  3282. record.__ownerID = ownerID;
  3283. return record;
  3284. }
  3285. function recordName(record) {
  3286. return record._name || record.constructor.name || 'Record';
  3287. }
  3288. function setProps(prototype, names) {
  3289. try {
  3290. names.forEach(setProp.bind(undefined, prototype));
  3291. } catch (error) {
  3292. // Object.defineProperty failed. Probably IE8.
  3293. }
  3294. }
  3295. function setProp(prototype, name) {
  3296. Object.defineProperty(prototype, name, {
  3297. get: function() {
  3298. return this.get(name);
  3299. },
  3300. set: function(value) {
  3301. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  3302. this.set(name, value);
  3303. }
  3304. });
  3305. }
  3306. createClass(Set, SetCollection);
  3307. // @pragma Construction
  3308. function Set(value) {
  3309. return value === null || value === undefined ? emptySet() :
  3310. isSet(value) && !isOrdered(value) ? value :
  3311. emptySet().withMutations(function(set ) {
  3312. var iter = SetIterable(value);
  3313. assertNotInfinite(iter.size);
  3314. iter.forEach(function(v ) {return set.add(v)});
  3315. });
  3316. }
  3317. Set.of = function(/*...values*/) {
  3318. return this(arguments);
  3319. };
  3320. Set.fromKeys = function(value) {
  3321. return this(KeyedIterable(value).keySeq());
  3322. };
  3323. Set.prototype.toString = function() {
  3324. return this.__toString('Set {', '}');
  3325. };
  3326. // @pragma Access
  3327. Set.prototype.has = function(value) {
  3328. return this._map.has(value);
  3329. };
  3330. // @pragma Modification
  3331. Set.prototype.add = function(value) {
  3332. return updateSet(this, this._map.set(value, true));
  3333. };
  3334. Set.prototype.remove = function(value) {
  3335. return updateSet(this, this._map.remove(value));
  3336. };
  3337. Set.prototype.clear = function() {
  3338. return updateSet(this, this._map.clear());
  3339. };
  3340. // @pragma Composition
  3341. Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
  3342. iters = iters.filter(function(x ) {return x.size !== 0});
  3343. if (iters.length === 0) {
  3344. return this;
  3345. }
  3346. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  3347. return this.constructor(iters[0]);
  3348. }
  3349. return this.withMutations(function(set ) {
  3350. for (var ii = 0; ii < iters.length; ii++) {
  3351. SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)});
  3352. }
  3353. });
  3354. };
  3355. Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
  3356. if (iters.length === 0) {
  3357. return this;
  3358. }
  3359. iters = iters.map(function(iter ) {return SetIterable(iter)});
  3360. var originalSet = this;
  3361. return this.withMutations(function(set ) {
  3362. originalSet.forEach(function(value ) {
  3363. if (!iters.every(function(iter ) {return iter.includes(value)})) {
  3364. set.remove(value);
  3365. }
  3366. });
  3367. });
  3368. };
  3369. Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
  3370. if (iters.length === 0) {
  3371. return this;
  3372. }
  3373. iters = iters.map(function(iter ) {return SetIterable(iter)});
  3374. var originalSet = this;
  3375. return this.withMutations(function(set ) {
  3376. originalSet.forEach(function(value ) {
  3377. if (iters.some(function(iter ) {return iter.includes(value)})) {
  3378. set.remove(value);
  3379. }
  3380. });
  3381. });
  3382. };
  3383. Set.prototype.merge = function() {
  3384. return this.union.apply(this, arguments);
  3385. };
  3386. Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  3387. return this.union.apply(this, iters);
  3388. };
  3389. Set.prototype.sort = function(comparator) {
  3390. // Late binding
  3391. return OrderedSet(sortFactory(this, comparator));
  3392. };
  3393. Set.prototype.sortBy = function(mapper, comparator) {
  3394. // Late binding
  3395. return OrderedSet(sortFactory(this, comparator, mapper));
  3396. };
  3397. Set.prototype.wasAltered = function() {
  3398. return this._map.wasAltered();
  3399. };
  3400. Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  3401. return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
  3402. };
  3403. Set.prototype.__iterator = function(type, reverse) {
  3404. return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
  3405. };
  3406. Set.prototype.__ensureOwner = function(ownerID) {
  3407. if (ownerID === this.__ownerID) {
  3408. return this;
  3409. }
  3410. var newMap = this._map.__ensureOwner(ownerID);
  3411. if (!ownerID) {
  3412. this.__ownerID = ownerID;
  3413. this._map = newMap;
  3414. return this;
  3415. }
  3416. return this.__make(newMap, ownerID);
  3417. };
  3418. function isSet(maybeSet) {
  3419. return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
  3420. }
  3421. Set.isSet = isSet;
  3422. var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
  3423. var SetPrototype = Set.prototype;
  3424. SetPrototype[IS_SET_SENTINEL] = true;
  3425. SetPrototype[DELETE] = SetPrototype.remove;
  3426. SetPrototype.mergeDeep = SetPrototype.merge;
  3427. SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
  3428. SetPrototype.withMutations = MapPrototype.withMutations;
  3429. SetPrototype.asMutable = MapPrototype.asMutable;
  3430. SetPrototype.asImmutable = MapPrototype.asImmutable;
  3431. SetPrototype.__empty = emptySet;
  3432. SetPrototype.__make = makeSet;
  3433. function updateSet(set, newMap) {
  3434. if (set.__ownerID) {
  3435. set.size = newMap.size;
  3436. set._map = newMap;
  3437. return set;
  3438. }
  3439. return newMap === set._map ? set :
  3440. newMap.size === 0 ? set.__empty() :
  3441. set.__make(newMap);
  3442. }
  3443. function makeSet(map, ownerID) {
  3444. var set = Object.create(SetPrototype);
  3445. set.size = map ? map.size : 0;
  3446. set._map = map;
  3447. set.__ownerID = ownerID;
  3448. return set;
  3449. }
  3450. var EMPTY_SET;
  3451. function emptySet() {
  3452. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  3453. }
  3454. createClass(OrderedSet, Set);
  3455. // @pragma Construction
  3456. function OrderedSet(value) {
  3457. return value === null || value === undefined ? emptyOrderedSet() :
  3458. isOrderedSet(value) ? value :
  3459. emptyOrderedSet().withMutations(function(set ) {
  3460. var iter = SetIterable(value);
  3461. assertNotInfinite(iter.size);
  3462. iter.forEach(function(v ) {return set.add(v)});
  3463. });
  3464. }
  3465. OrderedSet.of = function(/*...values*/) {
  3466. return this(arguments);
  3467. };
  3468. OrderedSet.fromKeys = function(value) {
  3469. return this(KeyedIterable(value).keySeq());
  3470. };
  3471. OrderedSet.prototype.toString = function() {
  3472. return this.__toString('OrderedSet {', '}');
  3473. };
  3474. function isOrderedSet(maybeOrderedSet) {
  3475. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  3476. }
  3477. OrderedSet.isOrderedSet = isOrderedSet;
  3478. var OrderedSetPrototype = OrderedSet.prototype;
  3479. OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
  3480. OrderedSetPrototype.__empty = emptyOrderedSet;
  3481. OrderedSetPrototype.__make = makeOrderedSet;
  3482. function makeOrderedSet(map, ownerID) {
  3483. var set = Object.create(OrderedSetPrototype);
  3484. set.size = map ? map.size : 0;
  3485. set._map = map;
  3486. set.__ownerID = ownerID;
  3487. return set;
  3488. }
  3489. var EMPTY_ORDERED_SET;
  3490. function emptyOrderedSet() {
  3491. return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
  3492. }
  3493. createClass(Stack, IndexedCollection);
  3494. // @pragma Construction
  3495. function Stack(value) {
  3496. return value === null || value === undefined ? emptyStack() :
  3497. isStack(value) ? value :
  3498. emptyStack().unshiftAll(value);
  3499. }
  3500. Stack.of = function(/*...values*/) {
  3501. return this(arguments);
  3502. };
  3503. Stack.prototype.toString = function() {
  3504. return this.__toString('Stack [', ']');
  3505. };
  3506. // @pragma Access
  3507. Stack.prototype.get = function(index, notSetValue) {
  3508. var head = this._head;
  3509. index = wrapIndex(this, index);
  3510. while (head && index--) {
  3511. head = head.next;
  3512. }
  3513. return head ? head.value : notSetValue;
  3514. };
  3515. Stack.prototype.peek = function() {
  3516. return this._head && this._head.value;
  3517. };
  3518. // @pragma Modification
  3519. Stack.prototype.push = function(/*...values*/) {
  3520. if (arguments.length === 0) {
  3521. return this;
  3522. }
  3523. var newSize = this.size + arguments.length;
  3524. var head = this._head;
  3525. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  3526. head = {
  3527. value: arguments[ii],
  3528. next: head
  3529. };
  3530. }
  3531. if (this.__ownerID) {
  3532. this.size = newSize;
  3533. this._head = head;
  3534. this.__hash = undefined;
  3535. this.__altered = true;
  3536. return this;
  3537. }
  3538. return makeStack(newSize, head);
  3539. };
  3540. Stack.prototype.pushAll = function(iter) {
  3541. iter = IndexedIterable(iter);
  3542. if (iter.size === 0) {
  3543. return this;
  3544. }
  3545. assertNotInfinite(iter.size);
  3546. var newSize = this.size;
  3547. var head = this._head;
  3548. iter.reverse().forEach(function(value ) {
  3549. newSize++;
  3550. head = {
  3551. value: value,
  3552. next: head
  3553. };
  3554. });
  3555. if (this.__ownerID) {
  3556. this.size = newSize;
  3557. this._head = head;
  3558. this.__hash = undefined;
  3559. this.__altered = true;
  3560. return this;
  3561. }
  3562. return makeStack(newSize, head);
  3563. };
  3564. Stack.prototype.pop = function() {
  3565. return this.slice(1);
  3566. };
  3567. Stack.prototype.unshift = function(/*...values*/) {
  3568. return this.push.apply(this, arguments);
  3569. };
  3570. Stack.prototype.unshiftAll = function(iter) {
  3571. return this.pushAll(iter);
  3572. };
  3573. Stack.prototype.shift = function() {
  3574. return this.pop.apply(this, arguments);
  3575. };
  3576. Stack.prototype.clear = function() {
  3577. if (this.size === 0) {
  3578. return this;
  3579. }
  3580. if (this.__ownerID) {
  3581. this.size = 0;
  3582. this._head = undefined;
  3583. this.__hash = undefined;
  3584. this.__altered = true;
  3585. return this;
  3586. }
  3587. return emptyStack();
  3588. };
  3589. Stack.prototype.slice = function(begin, end) {
  3590. if (wholeSlice(begin, end, this.size)) {
  3591. return this;
  3592. }
  3593. var resolvedBegin = resolveBegin(begin, this.size);
  3594. var resolvedEnd = resolveEnd(end, this.size);
  3595. if (resolvedEnd !== this.size) {
  3596. // super.slice(begin, end);
  3597. return IndexedCollection.prototype.slice.call(this, begin, end);
  3598. }
  3599. var newSize = this.size - resolvedBegin;
  3600. var head = this._head;
  3601. while (resolvedBegin--) {
  3602. head = head.next;
  3603. }
  3604. if (this.__ownerID) {
  3605. this.size = newSize;
  3606. this._head = head;
  3607. this.__hash = undefined;
  3608. this.__altered = true;
  3609. return this;
  3610. }
  3611. return makeStack(newSize, head);
  3612. };
  3613. // @pragma Mutability
  3614. Stack.prototype.__ensureOwner = function(ownerID) {
  3615. if (ownerID === this.__ownerID) {
  3616. return this;
  3617. }
  3618. if (!ownerID) {
  3619. this.__ownerID = ownerID;
  3620. this.__altered = false;
  3621. return this;
  3622. }
  3623. return makeStack(this.size, this._head, ownerID, this.__hash);
  3624. };
  3625. // @pragma Iteration
  3626. Stack.prototype.__iterate = function(fn, reverse) {
  3627. if (reverse) {
  3628. return this.reverse().__iterate(fn);
  3629. }
  3630. var iterations = 0;
  3631. var node = this._head;
  3632. while (node) {
  3633. if (fn(node.value, iterations++, this) === false) {
  3634. break;
  3635. }
  3636. node = node.next;
  3637. }
  3638. return iterations;
  3639. };
  3640. Stack.prototype.__iterator = function(type, reverse) {
  3641. if (reverse) {
  3642. return this.reverse().__iterator(type);
  3643. }
  3644. var iterations = 0;
  3645. var node = this._head;
  3646. return new Iterator(function() {
  3647. if (node) {
  3648. var value = node.value;
  3649. node = node.next;
  3650. return iteratorValue(type, iterations++, value);
  3651. }
  3652. return iteratorDone();
  3653. });
  3654. };
  3655. function isStack(maybeStack) {
  3656. return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
  3657. }
  3658. Stack.isStack = isStack;
  3659. var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
  3660. var StackPrototype = Stack.prototype;
  3661. StackPrototype[IS_STACK_SENTINEL] = true;
  3662. StackPrototype.withMutations = MapPrototype.withMutations;
  3663. StackPrototype.asMutable = MapPrototype.asMutable;
  3664. StackPrototype.asImmutable = MapPrototype.asImmutable;
  3665. StackPrototype.wasAltered = MapPrototype.wasAltered;
  3666. function makeStack(size, head, ownerID, hash) {
  3667. var map = Object.create(StackPrototype);
  3668. map.size = size;
  3669. map._head = head;
  3670. map.__ownerID = ownerID;
  3671. map.__hash = hash;
  3672. map.__altered = false;
  3673. return map;
  3674. }
  3675. var EMPTY_STACK;
  3676. function emptyStack() {
  3677. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  3678. }
  3679. /**
  3680. * Contributes additional methods to a constructor
  3681. */
  3682. function mixin(ctor, methods) {
  3683. var keyCopier = function(key ) { ctor.prototype[key] = methods[key]; };
  3684. Object.keys(methods).forEach(keyCopier);
  3685. Object.getOwnPropertySymbols &&
  3686. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  3687. return ctor;
  3688. }
  3689. Iterable.Iterator = Iterator;
  3690. mixin(Iterable, {
  3691. // ### Conversion to other types
  3692. toArray: function() {
  3693. assertNotInfinite(this.size);
  3694. var array = new Array(this.size || 0);
  3695. this.valueSeq().__iterate(function(v, i) { array[i] = v; });
  3696. return array;
  3697. },
  3698. toIndexedSeq: function() {
  3699. return new ToIndexedSequence(this);
  3700. },
  3701. toJS: function() {
  3702. return this.toSeq().map(
  3703. function(value ) {return value && typeof value.toJS === 'function' ? value.toJS() : value}
  3704. ).__toJS();
  3705. },
  3706. toJSON: function() {
  3707. return this.toSeq().map(
  3708. function(value ) {return value && typeof value.toJSON === 'function' ? value.toJSON() : value}
  3709. ).__toJS();
  3710. },
  3711. toKeyedSeq: function() {
  3712. return new ToKeyedSequence(this, true);
  3713. },
  3714. toMap: function() {
  3715. // Use Late Binding here to solve the circular dependency.
  3716. return Map(this.toKeyedSeq());
  3717. },
  3718. toObject: function() {
  3719. assertNotInfinite(this.size);
  3720. var object = {};
  3721. this.__iterate(function(v, k) { object[k] = v; });
  3722. return object;
  3723. },
  3724. toOrderedMap: function() {
  3725. // Use Late Binding here to solve the circular dependency.
  3726. return OrderedMap(this.toKeyedSeq());
  3727. },
  3728. toOrderedSet: function() {
  3729. // Use Late Binding here to solve the circular dependency.
  3730. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  3731. },
  3732. toSet: function() {
  3733. // Use Late Binding here to solve the circular dependency.
  3734. return Set(isKeyed(this) ? this.valueSeq() : this);
  3735. },
  3736. toSetSeq: function() {
  3737. return new ToSetSequence(this);
  3738. },
  3739. toSeq: function() {
  3740. return isIndexed(this) ? this.toIndexedSeq() :
  3741. isKeyed(this) ? this.toKeyedSeq() :
  3742. this.toSetSeq();
  3743. },
  3744. toStack: function() {
  3745. // Use Late Binding here to solve the circular dependency.
  3746. return Stack(isKeyed(this) ? this.valueSeq() : this);
  3747. },
  3748. toList: function() {
  3749. // Use Late Binding here to solve the circular dependency.
  3750. return List(isKeyed(this) ? this.valueSeq() : this);
  3751. },
  3752. // ### Common JavaScript methods and properties
  3753. toString: function() {
  3754. return '[Iterable]';
  3755. },
  3756. __toString: function(head, tail) {
  3757. if (this.size === 0) {
  3758. return head + tail;
  3759. }
  3760. return head + ' ' + this.toSeq().map(this.__toStringMapper).join(', ') + ' ' + tail;
  3761. },
  3762. // ### ES6 Collection methods (ES6 Array and Map)
  3763. concat: function() {var values = SLICE$0.call(arguments, 0);
  3764. return reify(this, concatFactory(this, values));
  3765. },
  3766. includes: function(searchValue) {
  3767. return this.some(function(value ) {return is(value, searchValue)});
  3768. },
  3769. entries: function() {
  3770. return this.__iterator(ITERATE_ENTRIES);
  3771. },
  3772. every: function(predicate, context) {
  3773. assertNotInfinite(this.size);
  3774. var returnValue = true;
  3775. this.__iterate(function(v, k, c) {
  3776. if (!predicate.call(context, v, k, c)) {
  3777. returnValue = false;
  3778. return false;
  3779. }
  3780. });
  3781. return returnValue;
  3782. },
  3783. filter: function(predicate, context) {
  3784. return reify(this, filterFactory(this, predicate, context, true));
  3785. },
  3786. find: function(predicate, context, notSetValue) {
  3787. var entry = this.findEntry(predicate, context);
  3788. return entry ? entry[1] : notSetValue;
  3789. },
  3790. findEntry: function(predicate, context) {
  3791. var found;
  3792. this.__iterate(function(v, k, c) {
  3793. if (predicate.call(context, v, k, c)) {
  3794. found = [k, v];
  3795. return false;
  3796. }
  3797. });
  3798. return found;
  3799. },
  3800. findLastEntry: function(predicate, context) {
  3801. return this.toSeq().reverse().findEntry(predicate, context);
  3802. },
  3803. forEach: function(sideEffect, context) {
  3804. assertNotInfinite(this.size);
  3805. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  3806. },
  3807. join: function(separator) {
  3808. assertNotInfinite(this.size);
  3809. separator = separator !== undefined ? '' + separator : ',';
  3810. var joined = '';
  3811. var isFirst = true;
  3812. this.__iterate(function(v ) {
  3813. isFirst ? (isFirst = false) : (joined += separator);
  3814. joined += v !== null && v !== undefined ? v.toString() : '';
  3815. });
  3816. return joined;
  3817. },
  3818. keys: function() {
  3819. return this.__iterator(ITERATE_KEYS);
  3820. },
  3821. map: function(mapper, context) {
  3822. return reify(this, mapFactory(this, mapper, context));
  3823. },
  3824. reduce: function(reducer, initialReduction, context) {
  3825. assertNotInfinite(this.size);
  3826. var reduction;
  3827. var useFirst;
  3828. if (arguments.length < 2) {
  3829. useFirst = true;
  3830. } else {
  3831. reduction = initialReduction;
  3832. }
  3833. this.__iterate(function(v, k, c) {
  3834. if (useFirst) {
  3835. useFirst = false;
  3836. reduction = v;
  3837. } else {
  3838. reduction = reducer.call(context, reduction, v, k, c);
  3839. }
  3840. });
  3841. return reduction;
  3842. },
  3843. reduceRight: function(reducer, initialReduction, context) {
  3844. var reversed = this.toKeyedSeq().reverse();
  3845. return reversed.reduce.apply(reversed, arguments);
  3846. },
  3847. reverse: function() {
  3848. return reify(this, reverseFactory(this, true));
  3849. },
  3850. slice: function(begin, end) {
  3851. return reify(this, sliceFactory(this, begin, end, true));
  3852. },
  3853. some: function(predicate, context) {
  3854. return !this.every(not(predicate), context);
  3855. },
  3856. sort: function(comparator) {
  3857. return reify(this, sortFactory(this, comparator));
  3858. },
  3859. values: function() {
  3860. return this.__iterator(ITERATE_VALUES);
  3861. },
  3862. // ### More sequential methods
  3863. butLast: function() {
  3864. return this.slice(0, -1);
  3865. },
  3866. isEmpty: function() {
  3867. return this.size !== undefined ? this.size === 0 : !this.some(function() {return true});
  3868. },
  3869. count: function(predicate, context) {
  3870. return ensureSize(
  3871. predicate ? this.toSeq().filter(predicate, context) : this
  3872. );
  3873. },
  3874. countBy: function(grouper, context) {
  3875. return countByFactory(this, grouper, context);
  3876. },
  3877. equals: function(other) {
  3878. return deepEqual(this, other);
  3879. },
  3880. entrySeq: function() {
  3881. var iterable = this;
  3882. if (iterable._cache) {
  3883. // We cache as an entries array, so we can just return the cache!
  3884. return new ArraySeq(iterable._cache);
  3885. }
  3886. var entriesSequence = iterable.toSeq().map(entryMapper).toIndexedSeq();
  3887. entriesSequence.fromEntrySeq = function() {return iterable.toSeq()};
  3888. return entriesSequence;
  3889. },
  3890. filterNot: function(predicate, context) {
  3891. return this.filter(not(predicate), context);
  3892. },
  3893. findLast: function(predicate, context, notSetValue) {
  3894. return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
  3895. },
  3896. first: function() {
  3897. return this.find(returnTrue);
  3898. },
  3899. flatMap: function(mapper, context) {
  3900. return reify(this, flatMapFactory(this, mapper, context));
  3901. },
  3902. flatten: function(depth) {
  3903. return reify(this, flattenFactory(this, depth, true));
  3904. },
  3905. fromEntrySeq: function() {
  3906. return new FromEntriesSequence(this);
  3907. },
  3908. get: function(searchKey, notSetValue) {
  3909. return this.find(function(_, key) {return is(key, searchKey)}, undefined, notSetValue);
  3910. },
  3911. getIn: function(searchKeyPath, notSetValue) {
  3912. var nested = this;
  3913. // Note: in an ES6 environment, we would prefer:
  3914. // for (var key of searchKeyPath) {
  3915. var iter = forceIterator(searchKeyPath);
  3916. var step;
  3917. while (!(step = iter.next()).done) {
  3918. var key = step.value;
  3919. nested = nested && nested.get ? nested.get(key, NOT_SET) : NOT_SET;
  3920. if (nested === NOT_SET) {
  3921. return notSetValue;
  3922. }
  3923. }
  3924. return nested;
  3925. },
  3926. groupBy: function(grouper, context) {
  3927. return groupByFactory(this, grouper, context);
  3928. },
  3929. has: function(searchKey) {
  3930. return this.get(searchKey, NOT_SET) !== NOT_SET;
  3931. },
  3932. hasIn: function(searchKeyPath) {
  3933. return this.getIn(searchKeyPath, NOT_SET) !== NOT_SET;
  3934. },
  3935. isSubset: function(iter) {
  3936. iter = typeof iter.includes === 'function' ? iter : Iterable(iter);
  3937. return this.every(function(value ) {return iter.includes(value)});
  3938. },
  3939. isSuperset: function(iter) {
  3940. iter = typeof iter.isSubset === 'function' ? iter : Iterable(iter);
  3941. return iter.isSubset(this);
  3942. },
  3943. keySeq: function() {
  3944. return this.toSeq().map(keyMapper).toIndexedSeq();
  3945. },
  3946. last: function() {
  3947. return this.toSeq().reverse().first();
  3948. },
  3949. max: function(comparator) {
  3950. return maxFactory(this, comparator);
  3951. },
  3952. maxBy: function(mapper, comparator) {
  3953. return maxFactory(this, comparator, mapper);
  3954. },
  3955. min: function(comparator) {
  3956. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator);
  3957. },
  3958. minBy: function(mapper, comparator) {
  3959. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator, mapper);
  3960. },
  3961. rest: function() {
  3962. return this.slice(1);
  3963. },
  3964. skip: function(amount) {
  3965. return this.slice(Math.max(0, amount));
  3966. },
  3967. skipLast: function(amount) {
  3968. return reify(this, this.toSeq().reverse().skip(amount).reverse());
  3969. },
  3970. skipWhile: function(predicate, context) {
  3971. return reify(this, skipWhileFactory(this, predicate, context, true));
  3972. },
  3973. skipUntil: function(predicate, context) {
  3974. return this.skipWhile(not(predicate), context);
  3975. },
  3976. sortBy: function(mapper, comparator) {
  3977. return reify(this, sortFactory(this, comparator, mapper));
  3978. },
  3979. take: function(amount) {
  3980. return this.slice(0, Math.max(0, amount));
  3981. },
  3982. takeLast: function(amount) {
  3983. return reify(this, this.toSeq().reverse().take(amount).reverse());
  3984. },
  3985. takeWhile: function(predicate, context) {
  3986. return reify(this, takeWhileFactory(this, predicate, context));
  3987. },
  3988. takeUntil: function(predicate, context) {
  3989. return this.takeWhile(not(predicate), context);
  3990. },
  3991. valueSeq: function() {
  3992. return this.toIndexedSeq();
  3993. },
  3994. // ### Hashable Object
  3995. hashCode: function() {
  3996. return this.__hash || (this.__hash = hashIterable(this));
  3997. }
  3998. // ### Internal
  3999. // abstract __iterate(fn, reverse)
  4000. // abstract __iterator(type, reverse)
  4001. });
  4002. // var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  4003. // var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  4004. // var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  4005. // var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  4006. var IterablePrototype = Iterable.prototype;
  4007. IterablePrototype[IS_ITERABLE_SENTINEL] = true;
  4008. IterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.values;
  4009. IterablePrototype.__toJS = IterablePrototype.toArray;
  4010. IterablePrototype.__toStringMapper = quoteString;
  4011. IterablePrototype.inspect =
  4012. IterablePrototype.toSource = function() { return this.toString(); };
  4013. IterablePrototype.chain = IterablePrototype.flatMap;
  4014. IterablePrototype.contains = IterablePrototype.includes;
  4015. // Temporary warning about using length
  4016. (function () {
  4017. try {
  4018. Object.defineProperty(IterablePrototype, 'length', {
  4019. get: function () {
  4020. if (!Iterable.noLengthWarning) {
  4021. var stack;
  4022. try {
  4023. throw new Error();
  4024. } catch (error) {
  4025. stack = error.stack;
  4026. }
  4027. if (stack.indexOf('_wrapObject') === -1) {
  4028. console && console.warn && console.warn(
  4029. 'iterable.length has been deprecated, '+
  4030. 'use iterable.size or iterable.count(). '+
  4031. 'This warning will become a silent error in a future version. ' +
  4032. stack
  4033. );
  4034. return this.size;
  4035. }
  4036. }
  4037. }
  4038. });
  4039. } catch (e) {}
  4040. })();
  4041. mixin(KeyedIterable, {
  4042. // ### More sequential methods
  4043. flip: function() {
  4044. return reify(this, flipFactory(this));
  4045. },
  4046. findKey: function(predicate, context) {
  4047. var entry = this.findEntry(predicate, context);
  4048. return entry && entry[0];
  4049. },
  4050. findLastKey: function(predicate, context) {
  4051. return this.toSeq().reverse().findKey(predicate, context);
  4052. },
  4053. keyOf: function(searchValue) {
  4054. return this.findKey(function(value ) {return is(value, searchValue)});
  4055. },
  4056. lastKeyOf: function(searchValue) {
  4057. return this.findLastKey(function(value ) {return is(value, searchValue)});
  4058. },
  4059. mapEntries: function(mapper, context) {var this$0 = this;
  4060. var iterations = 0;
  4061. return reify(this,
  4062. this.toSeq().map(
  4063. function(v, k) {return mapper.call(context, [k, v], iterations++, this$0)}
  4064. ).fromEntrySeq()
  4065. );
  4066. },
  4067. mapKeys: function(mapper, context) {var this$0 = this;
  4068. return reify(this,
  4069. this.toSeq().flip().map(
  4070. function(k, v) {return mapper.call(context, k, v, this$0)}
  4071. ).flip()
  4072. );
  4073. }
  4074. });
  4075. var KeyedIterablePrototype = KeyedIterable.prototype;
  4076. KeyedIterablePrototype[IS_KEYED_SENTINEL] = true;
  4077. KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries;
  4078. KeyedIterablePrototype.__toJS = IterablePrototype.toObject;
  4079. KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)};
  4080. mixin(IndexedIterable, {
  4081. // ### Conversion to other types
  4082. toKeyedSeq: function() {
  4083. return new ToKeyedSequence(this, false);
  4084. },
  4085. // ### ES6 Collection methods (ES6 Array and Map)
  4086. filter: function(predicate, context) {
  4087. return reify(this, filterFactory(this, predicate, context, false));
  4088. },
  4089. findIndex: function(predicate, context) {
  4090. var entry = this.findEntry(predicate, context);
  4091. return entry ? entry[0] : -1;
  4092. },
  4093. indexOf: function(searchValue) {
  4094. var key = this.toKeyedSeq().keyOf(searchValue);
  4095. return key === undefined ? -1 : key;
  4096. },
  4097. lastIndexOf: function(searchValue) {
  4098. var key = this.toKeyedSeq().reverse().keyOf(searchValue);
  4099. return key === undefined ? -1 : key;
  4100. // var index =
  4101. // return this.toSeq().reverse().indexOf(searchValue);
  4102. },
  4103. reverse: function() {
  4104. return reify(this, reverseFactory(this, false));
  4105. },
  4106. slice: function(begin, end) {
  4107. return reify(this, sliceFactory(this, begin, end, false));
  4108. },
  4109. splice: function(index, removeNum /*, ...values*/) {
  4110. var numArgs = arguments.length;
  4111. removeNum = Math.max(removeNum | 0, 0);
  4112. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  4113. return this;
  4114. }
  4115. // If index is negative, it should resolve relative to the size of the
  4116. // collection. However size may be expensive to compute if not cached, so
  4117. // only call count() if the number is in fact negative.
  4118. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  4119. var spliced = this.slice(0, index);
  4120. return reify(
  4121. this,
  4122. numArgs === 1 ?
  4123. spliced :
  4124. spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  4125. );
  4126. },
  4127. // ### More collection methods
  4128. findLastIndex: function(predicate, context) {
  4129. var key = this.toKeyedSeq().findLastKey(predicate, context);
  4130. return key === undefined ? -1 : key;
  4131. },
  4132. first: function() {
  4133. return this.get(0);
  4134. },
  4135. flatten: function(depth) {
  4136. return reify(this, flattenFactory(this, depth, false));
  4137. },
  4138. get: function(index, notSetValue) {
  4139. index = wrapIndex(this, index);
  4140. return (index < 0 || (this.size === Infinity ||
  4141. (this.size !== undefined && index > this.size))) ?
  4142. notSetValue :
  4143. this.find(function(_, key) {return key === index}, undefined, notSetValue);
  4144. },
  4145. has: function(index) {
  4146. index = wrapIndex(this, index);
  4147. return index >= 0 && (this.size !== undefined ?
  4148. this.size === Infinity || index < this.size :
  4149. this.indexOf(index) !== -1
  4150. );
  4151. },
  4152. interpose: function(separator) {
  4153. return reify(this, interposeFactory(this, separator));
  4154. },
  4155. interleave: function(/*...iterables*/) {
  4156. var iterables = [this].concat(arrCopy(arguments));
  4157. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, iterables);
  4158. var interleaved = zipped.flatten(true);
  4159. if (zipped.size) {
  4160. interleaved.size = zipped.size * iterables.length;
  4161. }
  4162. return reify(this, interleaved);
  4163. },
  4164. last: function() {
  4165. return this.get(-1);
  4166. },
  4167. skipWhile: function(predicate, context) {
  4168. return reify(this, skipWhileFactory(this, predicate, context, false));
  4169. },
  4170. zip: function(/*, ...iterables */) {
  4171. var iterables = [this].concat(arrCopy(arguments));
  4172. return reify(this, zipWithFactory(this, defaultZipper, iterables));
  4173. },
  4174. zipWith: function(zipper/*, ...iterables */) {
  4175. var iterables = arrCopy(arguments);
  4176. iterables[0] = this;
  4177. return reify(this, zipWithFactory(this, zipper, iterables));
  4178. }
  4179. });
  4180. IndexedIterable.prototype[IS_INDEXED_SENTINEL] = true;
  4181. IndexedIterable.prototype[IS_ORDERED_SENTINEL] = true;
  4182. mixin(SetIterable, {
  4183. // ### ES6 Collection methods (ES6 Array and Map)
  4184. get: function(value, notSetValue) {
  4185. return this.has(value) ? value : notSetValue;
  4186. },
  4187. includes: function(value) {
  4188. return this.has(value);
  4189. },
  4190. // ### More sequential methods
  4191. keySeq: function() {
  4192. return this.valueSeq();
  4193. }
  4194. });
  4195. SetIterable.prototype.has = IterablePrototype.includes;
  4196. // Mixin subclasses
  4197. mixin(KeyedSeq, KeyedIterable.prototype);
  4198. mixin(IndexedSeq, IndexedIterable.prototype);
  4199. mixin(SetSeq, SetIterable.prototype);
  4200. mixin(KeyedCollection, KeyedIterable.prototype);
  4201. mixin(IndexedCollection, IndexedIterable.prototype);
  4202. mixin(SetCollection, SetIterable.prototype);
  4203. // #pragma Helper functions
  4204. function keyMapper(v, k) {
  4205. return k;
  4206. }
  4207. function entryMapper(v, k) {
  4208. return [k, v];
  4209. }
  4210. function not(predicate) {
  4211. return function() {
  4212. return !predicate.apply(this, arguments);
  4213. }
  4214. }
  4215. function neg(predicate) {
  4216. return function() {
  4217. return -predicate.apply(this, arguments);
  4218. }
  4219. }
  4220. function quoteString(value) {
  4221. return typeof value === 'string' ? JSON.stringify(value) : value;
  4222. }
  4223. function defaultZipper() {
  4224. return arrCopy(arguments);
  4225. }
  4226. function defaultNegComparator(a, b) {
  4227. return a < b ? 1 : a > b ? -1 : 0;
  4228. }
  4229. function hashIterable(iterable) {
  4230. if (iterable.size === Infinity) {
  4231. return 0;
  4232. }
  4233. var ordered = isOrdered(iterable);
  4234. var keyed = isKeyed(iterable);
  4235. var h = ordered ? 1 : 0;
  4236. var size = iterable.__iterate(
  4237. keyed ?
  4238. ordered ?
  4239. function(v, k) { h = 31 * h + hashMerge(hash(v), hash(k)) | 0; } :
  4240. function(v, k) { h = h + hashMerge(hash(v), hash(k)) | 0; } :
  4241. ordered ?
  4242. function(v ) { h = 31 * h + hash(v) | 0; } :
  4243. function(v ) { h = h + hash(v) | 0; }
  4244. );
  4245. return murmurHashOfSize(size, h);
  4246. }
  4247. function murmurHashOfSize(size, h) {
  4248. h = imul(h, 0xCC9E2D51);
  4249. h = imul(h << 15 | h >>> -15, 0x1B873593);
  4250. h = imul(h << 13 | h >>> -13, 5);
  4251. h = (h + 0xE6546B64 | 0) ^ size;
  4252. h = imul(h ^ h >>> 16, 0x85EBCA6B);
  4253. h = imul(h ^ h >>> 13, 0xC2B2AE35);
  4254. h = smi(h ^ h >>> 16);
  4255. return h;
  4256. }
  4257. function hashMerge(a, b) {
  4258. return a ^ b + 0x9E3779B9 + (a << 6) + (a >> 2) | 0; // int
  4259. }
  4260. var Immutable = {
  4261. Iterable: Iterable,
  4262. Seq: Seq,
  4263. Collection: Collection,
  4264. Map: Map,
  4265. OrderedMap: OrderedMap,
  4266. List: List,
  4267. Stack: Stack,
  4268. Set: Set,
  4269. OrderedSet: OrderedSet,
  4270. Record: Record,
  4271. Range: Range,
  4272. Repeat: Repeat,
  4273. is: is,
  4274. fromJS: fromJS
  4275. };
  4276. return Immutable;
  4277. }));
  4278. });
  4279. var OrderedMap = immutable.OrderedMap;
  4280. var BlockMapBuilder = {
  4281. createFromArray: function createFromArray(blocks) {
  4282. return OrderedMap(blocks.map(function (block) {
  4283. return [block.getKey(), block];
  4284. }));
  4285. }
  4286. };
  4287. var BlockMapBuilder_1 = BlockMapBuilder;
  4288. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4289. 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; }
  4290. 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; }
  4291. var Map$1 = immutable.Map,
  4292. OrderedSet = immutable.OrderedSet,
  4293. Record = immutable.Record;
  4294. // Immutable.map is typed such that the value for every key in the map
  4295. // must be the same type
  4296. var EMPTY_SET = OrderedSet();
  4297. var defaultRecord = {
  4298. style: EMPTY_SET,
  4299. entity: null
  4300. };
  4301. var CharacterMetadataRecord = Record(defaultRecord);
  4302. var CharacterMetadata = function (_CharacterMetadataRec) {
  4303. _inherits(CharacterMetadata, _CharacterMetadataRec);
  4304. function CharacterMetadata() {
  4305. _classCallCheck(this, CharacterMetadata);
  4306. return _possibleConstructorReturn(this, _CharacterMetadataRec.apply(this, arguments));
  4307. }
  4308. CharacterMetadata.prototype.getStyle = function getStyle() {
  4309. return this.get('style');
  4310. };
  4311. CharacterMetadata.prototype.getEntity = function getEntity() {
  4312. return this.get('entity');
  4313. };
  4314. CharacterMetadata.prototype.hasStyle = function hasStyle(style) {
  4315. return this.getStyle().includes(style);
  4316. };
  4317. CharacterMetadata.applyStyle = function applyStyle(record, style) {
  4318. var withStyle = record.set('style', record.getStyle().add(style));
  4319. return CharacterMetadata.create(withStyle);
  4320. };
  4321. CharacterMetadata.removeStyle = function removeStyle(record, style) {
  4322. var withoutStyle = record.set('style', record.getStyle().remove(style));
  4323. return CharacterMetadata.create(withoutStyle);
  4324. };
  4325. CharacterMetadata.applyEntity = function applyEntity(record, entityKey) {
  4326. var withEntity = record.getEntity() === entityKey ? record : record.set('entity', entityKey);
  4327. return CharacterMetadata.create(withEntity);
  4328. };
  4329. /**
  4330. * Use this function instead of the `CharacterMetadata` constructor.
  4331. * Since most content generally uses only a very small number of
  4332. * style/entity permutations, we can reuse these objects as often as
  4333. * possible.
  4334. */
  4335. CharacterMetadata.create = function create(config) {
  4336. if (!config) {
  4337. return EMPTY;
  4338. }
  4339. var defaultConfig = {
  4340. style: EMPTY_SET,
  4341. entity: null
  4342. };
  4343. // Fill in unspecified properties, if necessary.
  4344. var configMap = Map$1(defaultConfig).merge(config);
  4345. var existing = pool.get(configMap);
  4346. if (existing) {
  4347. return existing;
  4348. }
  4349. var newCharacter = new CharacterMetadata(configMap);
  4350. pool = pool.set(configMap, newCharacter);
  4351. return newCharacter;
  4352. };
  4353. return CharacterMetadata;
  4354. }(CharacterMetadataRecord);
  4355. var EMPTY = new CharacterMetadata();
  4356. var pool = Map$1([[Map$1(defaultRecord), EMPTY]]);
  4357. CharacterMetadata.EMPTY = EMPTY;
  4358. var CharacterMetadata_1 = CharacterMetadata;
  4359. /**
  4360. * Copyright (c) 2013-present, Facebook, Inc.
  4361. * All rights reserved.
  4362. *
  4363. * This source code is licensed under the BSD-style license found in the
  4364. * LICENSE file in the root directory of this source tree. An additional grant
  4365. * of patent rights can be found in the PATENTS file in the same directory.
  4366. *
  4367. * @providesModule findRangesImmutable
  4368. * @format
  4369. *
  4370. */
  4371. /**
  4372. * Search through an array to find contiguous stretches of elements that
  4373. * match a specified filter function.
  4374. *
  4375. * When ranges are found, execute a specified `found` function to supply
  4376. * the values to the caller.
  4377. */
  4378. function findRangesImmutable(haystack, areEqualFn, filterFn, foundFn) {
  4379. if (!haystack.size) {
  4380. return;
  4381. }
  4382. var cursor = 0;
  4383. haystack.reduce(function (value, nextValue, nextIndex) {
  4384. if (!areEqualFn(value, nextValue)) {
  4385. if (filterFn(value)) {
  4386. foundFn(cursor, nextIndex);
  4387. }
  4388. cursor = nextIndex;
  4389. }
  4390. return nextValue;
  4391. });
  4392. filterFn(haystack.last()) && foundFn(cursor, haystack.count());
  4393. }
  4394. var findRangesImmutable_1 = findRangesImmutable;
  4395. function _classCallCheck$1(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4396. 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; }
  4397. 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; }
  4398. var List = immutable.List,
  4399. Map$2 = immutable.Map,
  4400. OrderedSet$1 = immutable.OrderedSet,
  4401. Record$1 = immutable.Record,
  4402. Repeat = immutable.Repeat;
  4403. var EMPTY_SET$1 = OrderedSet$1();
  4404. var defaultRecord$1 = {
  4405. key: '',
  4406. type: 'unstyled',
  4407. text: '',
  4408. characterList: List(),
  4409. depth: 0,
  4410. data: Map$2()
  4411. };
  4412. var ContentBlockRecord = Record$1(defaultRecord$1);
  4413. var decorateCharacterList = function decorateCharacterList(config) {
  4414. if (!config) {
  4415. return config;
  4416. }
  4417. var characterList = config.characterList,
  4418. text = config.text;
  4419. if (text && !characterList) {
  4420. config.characterList = List(Repeat(CharacterMetadata_1.EMPTY, text.length));
  4421. }
  4422. return config;
  4423. };
  4424. var ContentBlock = function (_ContentBlockRecord) {
  4425. _inherits$1(ContentBlock, _ContentBlockRecord);
  4426. function ContentBlock(config) {
  4427. _classCallCheck$1(this, ContentBlock);
  4428. return _possibleConstructorReturn$1(this, _ContentBlockRecord.call(this, decorateCharacterList(config)));
  4429. }
  4430. ContentBlock.prototype.getKey = function getKey() {
  4431. return this.get('key');
  4432. };
  4433. ContentBlock.prototype.getType = function getType() {
  4434. return this.get('type');
  4435. };
  4436. ContentBlock.prototype.getText = function getText() {
  4437. return this.get('text');
  4438. };
  4439. ContentBlock.prototype.getCharacterList = function getCharacterList() {
  4440. return this.get('characterList');
  4441. };
  4442. ContentBlock.prototype.getLength = function getLength() {
  4443. return this.getText().length;
  4444. };
  4445. ContentBlock.prototype.getDepth = function getDepth() {
  4446. return this.get('depth');
  4447. };
  4448. ContentBlock.prototype.getData = function getData() {
  4449. return this.get('data');
  4450. };
  4451. ContentBlock.prototype.getInlineStyleAt = function getInlineStyleAt(offset) {
  4452. var character = this.getCharacterList().get(offset);
  4453. return character ? character.getStyle() : EMPTY_SET$1;
  4454. };
  4455. ContentBlock.prototype.getEntityAt = function getEntityAt(offset) {
  4456. var character = this.getCharacterList().get(offset);
  4457. return character ? character.getEntity() : null;
  4458. };
  4459. /**
  4460. * Execute a callback for every contiguous range of styles within the block.
  4461. */
  4462. ContentBlock.prototype.findStyleRanges = function findStyleRanges(filterFn, callback) {
  4463. findRangesImmutable_1(this.getCharacterList(), haveEqualStyle, filterFn, callback);
  4464. };
  4465. /**
  4466. * Execute a callback for every contiguous range of entities within the block.
  4467. */
  4468. ContentBlock.prototype.findEntityRanges = function findEntityRanges(filterFn, callback) {
  4469. findRangesImmutable_1(this.getCharacterList(), haveEqualEntity, filterFn, callback);
  4470. };
  4471. return ContentBlock;
  4472. }(ContentBlockRecord);
  4473. function haveEqualStyle(charA, charB) {
  4474. return charA.getStyle() === charB.getStyle();
  4475. }
  4476. function haveEqualEntity(charA, charB) {
  4477. return charA.getEntity() === charB.getEntity();
  4478. }
  4479. var ContentBlock_1 = ContentBlock;
  4480. function _classCallCheck$2(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4481. 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; }
  4482. 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; }
  4483. var List$1 = immutable.List,
  4484. Map$3 = immutable.Map,
  4485. OrderedSet$2 = immutable.OrderedSet,
  4486. Record$2 = immutable.Record,
  4487. Repeat$1 = immutable.Repeat;
  4488. var EMPTY_SET$2 = OrderedSet$2();
  4489. var defaultRecord$2 = {
  4490. parent: null,
  4491. characterList: List$1(),
  4492. data: Map$3(),
  4493. depth: 0,
  4494. key: '',
  4495. text: '',
  4496. type: 'unstyled',
  4497. children: List$1(),
  4498. prevSibling: null,
  4499. nextSibling: null
  4500. };
  4501. var haveEqualStyle$1 = function haveEqualStyle(charA, charB) {
  4502. return charA.getStyle() === charB.getStyle();
  4503. };
  4504. var haveEqualEntity$1 = function haveEqualEntity(charA, charB) {
  4505. return charA.getEntity() === charB.getEntity();
  4506. };
  4507. var decorateCharacterList$1 = function decorateCharacterList(config) {
  4508. if (!config) {
  4509. return config;
  4510. }
  4511. var characterList = config.characterList,
  4512. text = config.text;
  4513. if (text && !characterList) {
  4514. config.characterList = List$1(Repeat$1(CharacterMetadata_1.EMPTY, text.length));
  4515. }
  4516. return config;
  4517. };
  4518. var ContentBlockNode = function (_Record) {
  4519. _inherits$2(ContentBlockNode, _Record);
  4520. function ContentBlockNode() {
  4521. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultRecord$2;
  4522. _classCallCheck$2(this, ContentBlockNode);
  4523. return _possibleConstructorReturn$2(this, _Record.call(this, decorateCharacterList$1(props)));
  4524. }
  4525. ContentBlockNode.prototype.getKey = function getKey() {
  4526. return this.get('key');
  4527. };
  4528. ContentBlockNode.prototype.getType = function getType() {
  4529. return this.get('type');
  4530. };
  4531. ContentBlockNode.prototype.getText = function getText() {
  4532. return this.get('text');
  4533. };
  4534. ContentBlockNode.prototype.getCharacterList = function getCharacterList() {
  4535. return this.get('characterList');
  4536. };
  4537. ContentBlockNode.prototype.getLength = function getLength() {
  4538. return this.getText().length;
  4539. };
  4540. ContentBlockNode.prototype.getDepth = function getDepth() {
  4541. return this.get('depth');
  4542. };
  4543. ContentBlockNode.prototype.getData = function getData() {
  4544. return this.get('data');
  4545. };
  4546. ContentBlockNode.prototype.getInlineStyleAt = function getInlineStyleAt(offset) {
  4547. var character = this.getCharacterList().get(offset);
  4548. return character ? character.getStyle() : EMPTY_SET$2;
  4549. };
  4550. ContentBlockNode.prototype.getEntityAt = function getEntityAt(offset) {
  4551. var character = this.getCharacterList().get(offset);
  4552. return character ? character.getEntity() : null;
  4553. };
  4554. ContentBlockNode.prototype.getChildKeys = function getChildKeys() {
  4555. return this.get('children');
  4556. };
  4557. ContentBlockNode.prototype.getParentKey = function getParentKey() {
  4558. return this.get('parent');
  4559. };
  4560. ContentBlockNode.prototype.getPrevSiblingKey = function getPrevSiblingKey() {
  4561. return this.get('prevSibling');
  4562. };
  4563. ContentBlockNode.prototype.getNextSiblingKey = function getNextSiblingKey() {
  4564. return this.get('nextSibling');
  4565. };
  4566. ContentBlockNode.prototype.findStyleRanges = function findStyleRanges(filterFn, callback) {
  4567. findRangesImmutable_1(this.getCharacterList(), haveEqualStyle$1, filterFn, callback);
  4568. };
  4569. ContentBlockNode.prototype.findEntityRanges = function findEntityRanges(filterFn, callback) {
  4570. findRangesImmutable_1(this.getCharacterList(), haveEqualEntity$1, filterFn, callback);
  4571. };
  4572. return ContentBlockNode;
  4573. }(Record$2(defaultRecord$2));
  4574. var ContentBlockNode_1 = ContentBlockNode;
  4575. /**
  4576. * Copyright 2013-present, Facebook, Inc.
  4577. * All rights reserved.
  4578. *
  4579. * This source code is licensed under the BSD-style license found in the
  4580. * LICENSE file in the root directory of this source tree. An additional grant
  4581. * of patent rights can be found in the PATENTS file in the same directory.
  4582. *
  4583. * @providesModule DraftFeatureFlags-core
  4584. * @format
  4585. *
  4586. */
  4587. var DraftFeatureFlags = {
  4588. draft_killswitch_allow_nontextnodes: false,
  4589. draft_segmented_entities_behavior: false,
  4590. draft_handlebeforeinput_composed_text: false,
  4591. draft_tree_data_support: false
  4592. };
  4593. var DraftFeatureFlagsCore = DraftFeatureFlags;
  4594. var DraftFeatureFlags_1 = DraftFeatureFlagsCore;
  4595. var Map$4 = immutable.Map;
  4596. var ContentStateInlineStyle = {
  4597. add: function add(contentState, selectionState, inlineStyle) {
  4598. return modifyInlineStyle(contentState, selectionState, inlineStyle, true);
  4599. },
  4600. remove: function remove(contentState, selectionState, inlineStyle) {
  4601. return modifyInlineStyle(contentState, selectionState, inlineStyle, false);
  4602. }
  4603. };
  4604. function modifyInlineStyle(contentState, selectionState, inlineStyle, addOrRemove) {
  4605. var blockMap = contentState.getBlockMap();
  4606. var startKey = selectionState.getStartKey();
  4607. var startOffset = selectionState.getStartOffset();
  4608. var endKey = selectionState.getEndKey();
  4609. var endOffset = selectionState.getEndOffset();
  4610. var newBlocks = blockMap.skipUntil(function (_, k) {
  4611. return k === startKey;
  4612. }).takeUntil(function (_, k) {
  4613. return k === endKey;
  4614. }).concat(Map$4([[endKey, blockMap.get(endKey)]])).map(function (block, blockKey) {
  4615. var sliceStart;
  4616. var sliceEnd;
  4617. if (startKey === endKey) {
  4618. sliceStart = startOffset;
  4619. sliceEnd = endOffset;
  4620. } else {
  4621. sliceStart = blockKey === startKey ? startOffset : 0;
  4622. sliceEnd = blockKey === endKey ? endOffset : block.getLength();
  4623. }
  4624. var chars = block.getCharacterList();
  4625. var current;
  4626. while (sliceStart < sliceEnd) {
  4627. current = chars.get(sliceStart);
  4628. chars = chars.set(sliceStart, addOrRemove ? CharacterMetadata_1.applyStyle(current, inlineStyle) : CharacterMetadata_1.removeStyle(current, inlineStyle));
  4629. sliceStart++;
  4630. }
  4631. return block.set('characterList', chars);
  4632. });
  4633. return contentState.merge({
  4634. blockMap: blockMap.merge(newBlocks),
  4635. selectionBefore: selectionState,
  4636. selectionAfter: selectionState
  4637. });
  4638. }
  4639. var ContentStateInlineStyle_1 = ContentStateInlineStyle;
  4640. function applyEntityToContentBlock(contentBlock, start, end, entityKey) {
  4641. var characterList = contentBlock.getCharacterList();
  4642. while (start < end) {
  4643. characterList = characterList.set(start, CharacterMetadata_1.applyEntity(characterList.get(start), entityKey));
  4644. start++;
  4645. }
  4646. return contentBlock.set('characterList', characterList);
  4647. }
  4648. var applyEntityToContentBlock_1 = applyEntityToContentBlock;
  4649. function applyEntityToContentState(contentState, selectionState, entityKey) {
  4650. var blockMap = contentState.getBlockMap();
  4651. var startKey = selectionState.getStartKey();
  4652. var startOffset = selectionState.getStartOffset();
  4653. var endKey = selectionState.getEndKey();
  4654. var endOffset = selectionState.getEndOffset();
  4655. var newBlocks = blockMap.skipUntil(function (_, k) {
  4656. return k === startKey;
  4657. }).takeUntil(function (_, k) {
  4658. return k === endKey;
  4659. }).toOrderedMap().merge(immutable.OrderedMap([[endKey, blockMap.get(endKey)]])).map(function (block, blockKey) {
  4660. var sliceStart = blockKey === startKey ? startOffset : 0;
  4661. var sliceEnd = blockKey === endKey ? endOffset : block.getLength();
  4662. return applyEntityToContentBlock_1(block, sliceStart, sliceEnd, entityKey);
  4663. });
  4664. return contentState.merge({
  4665. blockMap: blockMap.merge(newBlocks),
  4666. selectionBefore: selectionState,
  4667. selectionAfter: selectionState
  4668. });
  4669. }
  4670. var applyEntityToContentState_1 = applyEntityToContentState;
  4671. /**
  4672. * Copyright (c) 2013-present, Facebook, Inc.
  4673. * All rights reserved.
  4674. *
  4675. * This source code is licensed under the BSD-style license found in the
  4676. * LICENSE file in the root directory of this source tree. An additional grant
  4677. * of patent rights can be found in the PATENTS file in the same directory.
  4678. *
  4679. * @providesModule DraftEntitySegments
  4680. * @format
  4681. *
  4682. */
  4683. /**
  4684. * Identify the range to delete from a segmented entity.
  4685. *
  4686. * Rules:
  4687. *
  4688. * Example: 'John F. Kennedy'
  4689. *
  4690. * - Deletion from within any non-whitespace (i.e. ['John', 'F.', 'Kennedy'])
  4691. * will return the range of that text.
  4692. *
  4693. * 'John F. Kennedy' -> 'John F.'
  4694. * ^
  4695. *
  4696. * - Forward deletion of whitespace will remove the following section:
  4697. *
  4698. * 'John F. Kennedy' -> 'John Kennedy'
  4699. * ^
  4700. *
  4701. * - Backward deletion of whitespace will remove the previous section:
  4702. *
  4703. * 'John F. Kennedy' -> 'F. Kennedy'
  4704. * ^
  4705. */
  4706. var DraftEntitySegments = {
  4707. getRemovalRange: function getRemovalRange(selectionStart, selectionEnd, text, entityStart, direction) {
  4708. var segments = text.split(' ');
  4709. segments = segments.map(function ( /*string*/segment, /*number*/ii) {
  4710. if (direction === 'forward') {
  4711. if (ii > 0) {
  4712. return ' ' + segment;
  4713. }
  4714. } else if (ii < segments.length - 1) {
  4715. return segment + ' ';
  4716. }
  4717. return segment;
  4718. });
  4719. var segmentStart = entityStart;
  4720. var segmentEnd;
  4721. var segment;
  4722. var removalStart = null;
  4723. var removalEnd = null;
  4724. for (var jj = 0; jj < segments.length; jj++) {
  4725. segment = segments[jj];
  4726. segmentEnd = segmentStart + segment.length;
  4727. // Our selection overlaps this segment.
  4728. if (selectionStart < segmentEnd && segmentStart < selectionEnd) {
  4729. if (removalStart !== null) {
  4730. removalEnd = segmentEnd;
  4731. } else {
  4732. removalStart = segmentStart;
  4733. removalEnd = segmentEnd;
  4734. }
  4735. } else if (removalStart !== null) {
  4736. break;
  4737. }
  4738. segmentStart = segmentEnd;
  4739. }
  4740. var entityEnd = entityStart + text.length;
  4741. var atStart = removalStart === entityStart;
  4742. var atEnd = removalEnd === entityEnd;
  4743. if (!atStart && atEnd || atStart && !atEnd) {
  4744. if (direction === 'forward') {
  4745. if (removalEnd !== entityEnd) {
  4746. removalEnd++;
  4747. }
  4748. } else if (removalStart !== entityStart) {
  4749. removalStart--;
  4750. }
  4751. }
  4752. return {
  4753. start: removalStart,
  4754. end: removalEnd
  4755. };
  4756. }
  4757. };
  4758. var DraftEntitySegments_1 = DraftEntitySegments;
  4759. /**
  4760. * Copyright (c) 2013-present, Facebook, Inc.
  4761. *
  4762. * This source code is licensed under the MIT license found in the
  4763. * LICENSE file in the root directory of this source tree.
  4764. *
  4765. */
  4766. /**
  4767. * Use invariant() to assert state which your program assumes to be true.
  4768. *
  4769. * Provide sprintf-style format (only %s is supported) and arguments
  4770. * to provide information about what broke and what you were
  4771. * expecting.
  4772. *
  4773. * The invariant message will be stripped in production, but the invariant
  4774. * will remain to ensure logic does not differ in production.
  4775. */
  4776. var validateFormat = function validateFormat(format) {};
  4777. if (process.env.NODE_ENV !== 'production') {
  4778. validateFormat = function validateFormat(format) {
  4779. if (format === undefined) {
  4780. throw new Error('invariant requires an error message argument');
  4781. }
  4782. };
  4783. }
  4784. function invariant(condition, format, a, b, c, d, e, f) {
  4785. validateFormat(format);
  4786. if (!condition) {
  4787. var error;
  4788. if (format === undefined) {
  4789. error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
  4790. } else {
  4791. var args = [a, b, c, d, e, f];
  4792. var argIndex = 0;
  4793. error = new Error(format.replace(/%s/g, function () {
  4794. return args[argIndex++];
  4795. }));
  4796. error.name = 'Invariant Violation';
  4797. }
  4798. error.framesToPop = 1; // we don't care about invariant's own frame
  4799. throw error;
  4800. }
  4801. }
  4802. var invariant_1 = invariant;
  4803. /**
  4804. * Obtain the start and end positions of the range that has the
  4805. * specified entity applied to it.
  4806. *
  4807. * Entity keys are applied only to contiguous stretches of text, so this
  4808. * method searches for the first instance of the entity key and returns
  4809. * the subsequent range.
  4810. */
  4811. function getRangesForDraftEntity(block, key) {
  4812. var ranges = [];
  4813. block.findEntityRanges(function (c) {
  4814. return c.getEntity() === key;
  4815. }, function (start, end) {
  4816. ranges.push({ start: start, end: end });
  4817. });
  4818. !!!ranges.length ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Entity key not found in this range.') : invariant_1(false) : void 0;
  4819. return ranges;
  4820. }
  4821. var getRangesForDraftEntity_1 = getRangesForDraftEntity;
  4822. /**
  4823. * Given a SelectionState and a removal direction, determine the entire range
  4824. * that should be removed from a ContentState. This is based on any entities
  4825. * within the target, with their `mutability` values taken into account.
  4826. *
  4827. * For instance, if we are attempting to remove part of an "immutable" entity
  4828. * range, the entire entity must be removed. The returned `SelectionState`
  4829. * will be adjusted accordingly.
  4830. */
  4831. function getCharacterRemovalRange(entityMap, startBlock, endBlock, selectionState, direction) {
  4832. var start = selectionState.getStartOffset();
  4833. var end = selectionState.getEndOffset();
  4834. var startEntityKey = startBlock.getEntityAt(start);
  4835. var endEntityKey = endBlock.getEntityAt(end - 1);
  4836. if (!startEntityKey && !endEntityKey) {
  4837. return selectionState;
  4838. }
  4839. var newSelectionState = selectionState;
  4840. if (startEntityKey && startEntityKey === endEntityKey) {
  4841. newSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, true, true);
  4842. } else if (startEntityKey && endEntityKey) {
  4843. var startSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, false, true);
  4844. var endSelectionState = getEntityRemovalRange(entityMap, endBlock, newSelectionState, direction, endEntityKey, false, false);
  4845. newSelectionState = newSelectionState.merge({
  4846. anchorOffset: startSelectionState.getAnchorOffset(),
  4847. focusOffset: endSelectionState.getFocusOffset(),
  4848. isBackward: false
  4849. });
  4850. } else if (startEntityKey) {
  4851. var _startSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, false, true);
  4852. newSelectionState = newSelectionState.merge({
  4853. anchorOffset: _startSelectionState.getStartOffset(),
  4854. isBackward: false
  4855. });
  4856. } else if (endEntityKey) {
  4857. var _endSelectionState = getEntityRemovalRange(entityMap, endBlock, newSelectionState, direction, endEntityKey, false, false);
  4858. newSelectionState = newSelectionState.merge({
  4859. focusOffset: _endSelectionState.getEndOffset(),
  4860. isBackward: false
  4861. });
  4862. }
  4863. return newSelectionState;
  4864. }
  4865. function getEntityRemovalRange(entityMap, block, selectionState, direction, entityKey, isEntireSelectionWithinEntity, isEntityAtStart) {
  4866. var start = selectionState.getStartOffset();
  4867. var end = selectionState.getEndOffset();
  4868. var entity = entityMap.__get(entityKey);
  4869. var mutability = entity.getMutability();
  4870. var sideToConsider = isEntityAtStart ? start : end;
  4871. // `MUTABLE` entities can just have the specified range of text removed
  4872. // directly. No adjustments are needed.
  4873. if (mutability === 'MUTABLE') {
  4874. return selectionState;
  4875. }
  4876. // Find the entity range that overlaps with our removal range.
  4877. var entityRanges = getRangesForDraftEntity_1(block, entityKey).filter(function (range) {
  4878. return sideToConsider <= range.end && sideToConsider >= range.start;
  4879. });
  4880. !(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;
  4881. var entityRange = entityRanges[0];
  4882. // For `IMMUTABLE` entity types, we will remove the entire entity range.
  4883. if (mutability === 'IMMUTABLE') {
  4884. return selectionState.merge({
  4885. anchorOffset: entityRange.start,
  4886. focusOffset: entityRange.end,
  4887. isBackward: false
  4888. });
  4889. }
  4890. // For `SEGMENTED` entity types, determine the appropriate segment to
  4891. // remove.
  4892. if (!isEntireSelectionWithinEntity) {
  4893. if (isEntityAtStart) {
  4894. end = entityRange.end;
  4895. } else {
  4896. start = entityRange.start;
  4897. }
  4898. }
  4899. var removalRange = DraftEntitySegments_1.getRemovalRange(start, end, block.getText().slice(entityRange.start, entityRange.end), entityRange.start, direction);
  4900. return selectionState.merge({
  4901. anchorOffset: removalRange.start,
  4902. focusOffset: removalRange.end,
  4903. isBackward: false
  4904. });
  4905. }
  4906. var getCharacterRemovalRange_1 = getCharacterRemovalRange;
  4907. /**
  4908. * Copyright (c) 2013-present, Facebook, Inc.
  4909. * All rights reserved.
  4910. *
  4911. * This source code is licensed under the BSD-style license found in the
  4912. * LICENSE file in the root directory of this source tree. An additional grant
  4913. * of patent rights can be found in the PATENTS file in the same directory.
  4914. *
  4915. * @providesModule generateRandomKey
  4916. * @format
  4917. *
  4918. */
  4919. var seenKeys = {};
  4920. var MULTIPLIER = Math.pow(2, 24);
  4921. function generateRandomKey() {
  4922. var key = void 0;
  4923. while (key === undefined || seenKeys.hasOwnProperty(key) || !isNaN(+key)) {
  4924. key = Math.floor(Math.random() * MULTIPLIER).toString(32);
  4925. }
  4926. seenKeys[key] = true;
  4927. return key;
  4928. }
  4929. var generateRandomKey_1 = generateRandomKey;
  4930. var OrderedMap$1 = immutable.OrderedMap;
  4931. var randomizeContentBlockNodeKeys = function randomizeContentBlockNodeKeys(blockMap) {
  4932. var newKeysRef = {};
  4933. // we keep track of root blocks in order to update subsequent sibling links
  4934. var lastRootBlock = void 0;
  4935. return OrderedMap$1(blockMap.withMutations(function (blockMapState) {
  4936. blockMapState.forEach(function (block, index) {
  4937. var oldKey = block.getKey();
  4938. var nextKey = block.getNextSiblingKey();
  4939. var prevKey = block.getPrevSiblingKey();
  4940. var childrenKeys = block.getChildKeys();
  4941. var parentKey = block.getParentKey();
  4942. // new key that we will use to build linking
  4943. var key = generateRandomKey_1();
  4944. // we will add it here to re-use it later
  4945. newKeysRef[oldKey] = key;
  4946. if (nextKey) {
  4947. var nextBlock = blockMapState.get(nextKey);
  4948. if (nextBlock) {
  4949. blockMapState.setIn([nextKey, 'prevSibling'], key);
  4950. } else {
  4951. // this can happen when generating random keys for fragments
  4952. blockMapState.setIn([oldKey, 'nextSibling'], null);
  4953. }
  4954. }
  4955. if (prevKey) {
  4956. var prevBlock = blockMapState.get(prevKey);
  4957. if (prevBlock) {
  4958. blockMapState.setIn([prevKey, 'nextSibling'], key);
  4959. } else {
  4960. // this can happen when generating random keys for fragments
  4961. blockMapState.setIn([oldKey, 'prevSibling'], null);
  4962. }
  4963. }
  4964. if (parentKey && blockMapState.get(parentKey)) {
  4965. var parentBlock = blockMapState.get(parentKey);
  4966. var parentChildrenList = parentBlock.getChildKeys();
  4967. blockMapState.setIn([parentKey, 'children'], parentChildrenList.set(parentChildrenList.indexOf(block.getKey()), key));
  4968. } else {
  4969. // blocks will then be treated as root block nodes
  4970. blockMapState.setIn([oldKey, 'parent'], null);
  4971. if (lastRootBlock) {
  4972. blockMapState.setIn([lastRootBlock.getKey(), 'nextSibling'], key);
  4973. blockMapState.setIn([oldKey, 'prevSibling'], newKeysRef[lastRootBlock.getKey()]);
  4974. }
  4975. lastRootBlock = blockMapState.get(oldKey);
  4976. }
  4977. childrenKeys.forEach(function (childKey) {
  4978. var childBlock = blockMapState.get(childKey);
  4979. if (childBlock) {
  4980. blockMapState.setIn([childKey, 'parent'], key);
  4981. } else {
  4982. blockMapState.setIn([oldKey, 'children'], block.getChildKeys().filter(function (child) {
  4983. return child !== childKey;
  4984. }));
  4985. }
  4986. });
  4987. });
  4988. }).toArray().map(function (block) {
  4989. return [newKeysRef[block.getKey()], block.set('key', newKeysRef[block.getKey()])];
  4990. }));
  4991. };
  4992. var randomizeContentBlockKeys = function randomizeContentBlockKeys(blockMap) {
  4993. return OrderedMap$1(blockMap.toArray().map(function (block) {
  4994. var key = generateRandomKey_1();
  4995. return [key, block.set('key', key)];
  4996. }));
  4997. };
  4998. var randomizeBlockMapKeys = function randomizeBlockMapKeys(blockMap) {
  4999. var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode_1;
  5000. if (!isTreeBasedBlockMap) {
  5001. return randomizeContentBlockKeys(blockMap);
  5002. }
  5003. return randomizeContentBlockNodeKeys(blockMap);
  5004. };
  5005. var randomizeBlockMapKeys_1 = randomizeBlockMapKeys;
  5006. function removeEntitiesAtEdges(contentState, selectionState) {
  5007. var blockMap = contentState.getBlockMap();
  5008. var entityMap = contentState.getEntityMap();
  5009. var updatedBlocks = {};
  5010. var startKey = selectionState.getStartKey();
  5011. var startOffset = selectionState.getStartOffset();
  5012. var startBlock = blockMap.get(startKey);
  5013. var updatedStart = removeForBlock(entityMap, startBlock, startOffset);
  5014. if (updatedStart !== startBlock) {
  5015. updatedBlocks[startKey] = updatedStart;
  5016. }
  5017. var endKey = selectionState.getEndKey();
  5018. var endOffset = selectionState.getEndOffset();
  5019. var endBlock = blockMap.get(endKey);
  5020. if (startKey === endKey) {
  5021. endBlock = updatedStart;
  5022. }
  5023. var updatedEnd = removeForBlock(entityMap, endBlock, endOffset);
  5024. if (updatedEnd !== endBlock) {
  5025. updatedBlocks[endKey] = updatedEnd;
  5026. }
  5027. if (!Object.keys(updatedBlocks).length) {
  5028. return contentState.set('selectionAfter', selectionState);
  5029. }
  5030. return contentState.merge({
  5031. blockMap: blockMap.merge(updatedBlocks),
  5032. selectionAfter: selectionState
  5033. });
  5034. }
  5035. function getRemovalRange(characters, key, offset) {
  5036. var removalRange;
  5037. findRangesImmutable_1(characters, function (a, b) {
  5038. return a.getEntity() === b.getEntity();
  5039. }, function (element) {
  5040. return element.getEntity() === key;
  5041. }, function (start, end) {
  5042. if (start <= offset && end >= offset) {
  5043. removalRange = { start: start, end: end };
  5044. }
  5045. });
  5046. !(typeof removalRange === 'object') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Removal range must exist within character list.') : invariant_1(false) : void 0;
  5047. return removalRange;
  5048. }
  5049. function removeForBlock(entityMap, block, offset) {
  5050. var chars = block.getCharacterList();
  5051. var charBefore = offset > 0 ? chars.get(offset - 1) : undefined;
  5052. var charAfter = offset < chars.count() ? chars.get(offset) : undefined;
  5053. var entityBeforeCursor = charBefore ? charBefore.getEntity() : undefined;
  5054. var entityAfterCursor = charAfter ? charAfter.getEntity() : undefined;
  5055. if (entityAfterCursor && entityAfterCursor === entityBeforeCursor) {
  5056. var entity = entityMap.__get(entityAfterCursor);
  5057. if (entity.getMutability() !== 'MUTABLE') {
  5058. var _getRemovalRange = getRemovalRange(chars, entityAfterCursor, offset),
  5059. start = _getRemovalRange.start,
  5060. end = _getRemovalRange.end;
  5061. var current;
  5062. while (start < end) {
  5063. current = chars.get(start);
  5064. chars = chars.set(start, CharacterMetadata_1.applyEntity(current, null));
  5065. start++;
  5066. }
  5067. return block.set('characterList', chars);
  5068. }
  5069. }
  5070. return block;
  5071. }
  5072. var removeEntitiesAtEdges_1 = removeEntitiesAtEdges;
  5073. var getContentStateFragment = function getContentStateFragment(contentState, selectionState) {
  5074. var startKey = selectionState.getStartKey();
  5075. var startOffset = selectionState.getStartOffset();
  5076. var endKey = selectionState.getEndKey();
  5077. var endOffset = selectionState.getEndOffset();
  5078. // Edge entities should be stripped to ensure that we don't preserve
  5079. // invalid partial entities when the fragment is reused. We do, however,
  5080. // preserve entities that are entirely within the selection range.
  5081. var contentWithoutEdgeEntities = removeEntitiesAtEdges_1(contentState, selectionState);
  5082. var blockMap = contentWithoutEdgeEntities.getBlockMap();
  5083. var blockKeys = blockMap.keySeq();
  5084. var startIndex = blockKeys.indexOf(startKey);
  5085. var endIndex = blockKeys.indexOf(endKey) + 1;
  5086. return randomizeBlockMapKeys_1(blockMap.slice(startIndex, endIndex).map(function (block, blockKey) {
  5087. var text = block.getText();
  5088. var chars = block.getCharacterList();
  5089. if (startKey === endKey) {
  5090. return block.merge({
  5091. text: text.slice(startOffset, endOffset),
  5092. characterList: chars.slice(startOffset, endOffset)
  5093. });
  5094. }
  5095. if (blockKey === startKey) {
  5096. return block.merge({
  5097. text: text.slice(startOffset),
  5098. characterList: chars.slice(startOffset)
  5099. });
  5100. }
  5101. if (blockKey === endKey) {
  5102. return block.merge({
  5103. text: text.slice(0, endOffset),
  5104. characterList: chars.slice(0, endOffset)
  5105. });
  5106. }
  5107. return block;
  5108. }));
  5109. };
  5110. var getContentStateFragment_1 = getContentStateFragment;
  5111. /**
  5112. * Copyright (c) 2013-present, Facebook, Inc.
  5113. * All rights reserved.
  5114. *
  5115. * This source code is licensed under the BSD-style license found in the
  5116. * LICENSE file in the root directory of this source tree. An additional grant
  5117. * of patent rights can be found in the PATENTS file in the same directory.
  5118. *
  5119. * @providesModule insertIntoList
  5120. * @format
  5121. *
  5122. */
  5123. /**
  5124. * Maintain persistence for target list when appending and prepending.
  5125. */
  5126. function insertIntoList(targetList, toInsert, offset) {
  5127. if (offset === targetList.count()) {
  5128. toInsert.forEach(function (c) {
  5129. targetList = targetList.push(c);
  5130. });
  5131. } else if (offset === 0) {
  5132. toInsert.reverse().forEach(function (c) {
  5133. targetList = targetList.unshift(c);
  5134. });
  5135. } else {
  5136. var head = targetList.slice(0, offset);
  5137. var tail = targetList.slice(offset);
  5138. targetList = head.concat(toInsert, tail).toList();
  5139. }
  5140. return targetList;
  5141. }
  5142. var insertIntoList_1 = insertIntoList;
  5143. var List$2 = immutable.List;
  5144. var updateExistingBlock = function updateExistingBlock(contentState, selectionState, blockMap, fragmentBlock, targetKey, targetOffset) {
  5145. var targetBlock = blockMap.get(targetKey);
  5146. var text = targetBlock.getText();
  5147. var chars = targetBlock.getCharacterList();
  5148. var finalKey = targetKey;
  5149. var finalOffset = targetOffset + fragmentBlock.getText().length;
  5150. var newBlock = targetBlock.merge({
  5151. text: text.slice(0, targetOffset) + fragmentBlock.getText() + text.slice(targetOffset),
  5152. characterList: insertIntoList_1(chars, fragmentBlock.getCharacterList(), targetOffset),
  5153. data: fragmentBlock.getData()
  5154. });
  5155. return contentState.merge({
  5156. blockMap: blockMap.set(targetKey, newBlock),
  5157. selectionBefore: selectionState,
  5158. selectionAfter: selectionState.merge({
  5159. anchorKey: finalKey,
  5160. anchorOffset: finalOffset,
  5161. focusKey: finalKey,
  5162. focusOffset: finalOffset,
  5163. isBackward: false
  5164. })
  5165. });
  5166. };
  5167. /**
  5168. * Appends text/characterList from the fragment first block to
  5169. * target block.
  5170. */
  5171. var updateHead = function updateHead(block, targetOffset, fragment) {
  5172. var text = block.getText();
  5173. var chars = block.getCharacterList();
  5174. // Modify head portion of block.
  5175. var headText = text.slice(0, targetOffset);
  5176. var headCharacters = chars.slice(0, targetOffset);
  5177. var appendToHead = fragment.first();
  5178. return block.merge({
  5179. text: headText + appendToHead.getText(),
  5180. characterList: headCharacters.concat(appendToHead.getCharacterList()),
  5181. type: headText ? block.getType() : appendToHead.getType(),
  5182. data: appendToHead.getData()
  5183. });
  5184. };
  5185. /**
  5186. * Appends offset text/characterList from the target block to the last
  5187. * fragment block.
  5188. */
  5189. var updateTail = function updateTail(block, targetOffset, fragment) {
  5190. // Modify tail portion of block.
  5191. var text = block.getText();
  5192. var chars = block.getCharacterList();
  5193. // Modify head portion of block.
  5194. var blockSize = text.length;
  5195. var tailText = text.slice(targetOffset, blockSize);
  5196. var tailCharacters = chars.slice(targetOffset, blockSize);
  5197. var prependToTail = fragment.last();
  5198. return prependToTail.merge({
  5199. text: prependToTail.getText() + tailText,
  5200. characterList: prependToTail.getCharacterList().concat(tailCharacters),
  5201. data: prependToTail.getData()
  5202. });
  5203. };
  5204. var getRootBlocks = function getRootBlocks(block, blockMap) {
  5205. var headKey = block.getKey();
  5206. var rootBlock = block;
  5207. var rootBlocks = [];
  5208. // sometimes the fragment head block will not be part of the blockMap itself this can happen when
  5209. // the fragment head is used to update the target block, however when this does not happen we need
  5210. // to make sure that we include it on the rootBlocks since the first block of a fragment is always a
  5211. // fragment root block
  5212. if (blockMap.get(headKey)) {
  5213. rootBlocks.push(headKey);
  5214. }
  5215. while (rootBlock && rootBlock.getNextSiblingKey()) {
  5216. var lastSiblingKey = rootBlock.getNextSiblingKey();
  5217. if (!lastSiblingKey) {
  5218. break;
  5219. }
  5220. rootBlocks.push(lastSiblingKey);
  5221. rootBlock = blockMap.get(lastSiblingKey);
  5222. }
  5223. return rootBlocks;
  5224. };
  5225. var updateBlockMapLinks = function updateBlockMapLinks(blockMap, originalBlockMap, targetBlock, fragmentHeadBlock) {
  5226. return blockMap.withMutations(function (blockMapState) {
  5227. var targetKey = targetBlock.getKey();
  5228. var headKey = fragmentHeadBlock.getKey();
  5229. var targetNextKey = targetBlock.getNextSiblingKey();
  5230. var targetParentKey = targetBlock.getParentKey();
  5231. var fragmentRootBlocks = getRootBlocks(fragmentHeadBlock, blockMap);
  5232. var lastRootFragmentBlockKey = fragmentRootBlocks[fragmentRootBlocks.length - 1];
  5233. if (blockMapState.get(headKey)) {
  5234. // update the fragment head when it is part of the blockMap otherwise
  5235. blockMapState.setIn([targetKey, 'nextSibling'], headKey);
  5236. blockMapState.setIn([headKey, 'prevSibling'], targetKey);
  5237. } else {
  5238. // update the target block that had the fragment head contents merged into it
  5239. blockMapState.setIn([targetKey, 'nextSibling'], fragmentHeadBlock.getNextSiblingKey());
  5240. blockMapState.setIn([fragmentHeadBlock.getNextSiblingKey(), 'prevSibling'], targetKey);
  5241. }
  5242. // update the last root block fragment
  5243. blockMapState.setIn([lastRootFragmentBlockKey, 'nextSibling'], targetNextKey);
  5244. // update the original target next block
  5245. if (targetNextKey) {
  5246. blockMapState.setIn([targetNextKey, 'prevSibling'], lastRootFragmentBlockKey);
  5247. }
  5248. // update fragment parent links
  5249. fragmentRootBlocks.forEach(function (blockKey) {
  5250. return blockMapState.setIn([blockKey, 'parent'], targetParentKey);
  5251. });
  5252. // update targetBlock parent child links
  5253. if (targetParentKey) {
  5254. var targetParent = blockMap.get(targetParentKey);
  5255. var originalTargetParentChildKeys = targetParent.getChildKeys();
  5256. var targetBlockIndex = originalTargetParentChildKeys.indexOf(targetKey);
  5257. var insertionIndex = targetBlockIndex + 1;
  5258. var newChildrenKeysArray = originalTargetParentChildKeys.toArray();
  5259. // insert fragment children
  5260. newChildrenKeysArray.splice.apply(newChildrenKeysArray, [insertionIndex, 0].concat(fragmentRootBlocks));
  5261. blockMapState.setIn([targetParentKey, 'children'], List$2(newChildrenKeysArray));
  5262. }
  5263. });
  5264. };
  5265. var insertFragment = function insertFragment(contentState, selectionState, blockMap, fragment, targetKey, targetOffset) {
  5266. var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode_1;
  5267. var newBlockArr = [];
  5268. var fragmentSize = fragment.size;
  5269. var target = blockMap.get(targetKey);
  5270. var head = fragment.first();
  5271. var tail = fragment.last();
  5272. var finalOffset = tail.getLength();
  5273. var finalKey = tail.getKey();
  5274. var shouldNotUpdateFromFragmentBlock = isTreeBasedBlockMap && (!target.getChildKeys().isEmpty() || !head.getChildKeys().isEmpty());
  5275. blockMap.forEach(function (block, blockKey) {
  5276. if (blockKey !== targetKey) {
  5277. newBlockArr.push(block);
  5278. return;
  5279. }
  5280. if (shouldNotUpdateFromFragmentBlock) {
  5281. newBlockArr.push(block);
  5282. } else {
  5283. newBlockArr.push(updateHead(block, targetOffset, fragment));
  5284. }
  5285. // Insert fragment blocks after the head and before the tail.
  5286. fragment
  5287. // when we are updating the target block with the head fragment block we skip the first fragment
  5288. // head since its contents have already been merged with the target block otherwise we include
  5289. // the whole fragment
  5290. .slice(shouldNotUpdateFromFragmentBlock ? 0 : 1, fragmentSize - 1).forEach(function (fragmentBlock) {
  5291. return newBlockArr.push(fragmentBlock);
  5292. });
  5293. // update tail
  5294. newBlockArr.push(updateTail(block, targetOffset, fragment));
  5295. });
  5296. var updatedBlockMap = BlockMapBuilder_1.createFromArray(newBlockArr);
  5297. if (isTreeBasedBlockMap) {
  5298. updatedBlockMap = updateBlockMapLinks(updatedBlockMap, blockMap, target, head);
  5299. }
  5300. return contentState.merge({
  5301. blockMap: updatedBlockMap,
  5302. selectionBefore: selectionState,
  5303. selectionAfter: selectionState.merge({
  5304. anchorKey: finalKey,
  5305. anchorOffset: finalOffset,
  5306. focusKey: finalKey,
  5307. focusOffset: finalOffset,
  5308. isBackward: false
  5309. })
  5310. });
  5311. };
  5312. var insertFragmentIntoContentState = function insertFragmentIntoContentState(contentState, selectionState, fragmentBlockMap) {
  5313. !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;
  5314. var blockMap = contentState.getBlockMap();
  5315. var fragment = randomizeBlockMapKeys_1(fragmentBlockMap);
  5316. var targetKey = selectionState.getStartKey();
  5317. var targetOffset = selectionState.getStartOffset();
  5318. var targetBlock = blockMap.get(targetKey);
  5319. if (targetBlock instanceof ContentBlockNode_1) {
  5320. !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;
  5321. }
  5322. // When we insert a fragment with a single block we simply update the target block
  5323. // with the contents of the inserted fragment block
  5324. if (fragment.size === 1) {
  5325. return updateExistingBlock(contentState, selectionState, blockMap, fragment.first(), targetKey, targetOffset);
  5326. }
  5327. return insertFragment(contentState, selectionState, blockMap, fragment, targetKey, targetOffset);
  5328. };
  5329. var insertFragmentIntoContentState_1 = insertFragmentIntoContentState;
  5330. var Repeat$2 = immutable.Repeat;
  5331. function insertTextIntoContentState(contentState, selectionState, text, characterMetadata) {
  5332. !selectionState.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`insertText` should only be called with a collapsed range.') : invariant_1(false) : void 0;
  5333. var len = text.length;
  5334. if (!len) {
  5335. return contentState;
  5336. }
  5337. var blockMap = contentState.getBlockMap();
  5338. var key = selectionState.getStartKey();
  5339. var offset = selectionState.getStartOffset();
  5340. var block = blockMap.get(key);
  5341. var blockText = block.getText();
  5342. var newBlock = block.merge({
  5343. text: blockText.slice(0, offset) + text + blockText.slice(offset, block.getLength()),
  5344. characterList: insertIntoList_1(block.getCharacterList(), Repeat$2(characterMetadata, len).toList(), offset)
  5345. });
  5346. var newOffset = offset + len;
  5347. return contentState.merge({
  5348. blockMap: blockMap.set(key, newBlock),
  5349. selectionAfter: selectionState.merge({
  5350. anchorOffset: newOffset,
  5351. focusOffset: newOffset
  5352. })
  5353. });
  5354. }
  5355. var insertTextIntoContentState_1 = insertTextIntoContentState;
  5356. var Map$5 = immutable.Map;
  5357. function modifyBlockForContentState(contentState, selectionState, operation) {
  5358. var startKey = selectionState.getStartKey();
  5359. var endKey = selectionState.getEndKey();
  5360. var blockMap = contentState.getBlockMap();
  5361. var newBlocks = blockMap.toSeq().skipUntil(function (_, k) {
  5362. return k === startKey;
  5363. }).takeUntil(function (_, k) {
  5364. return k === endKey;
  5365. }).concat(Map$5([[endKey, blockMap.get(endKey)]])).map(operation);
  5366. return contentState.merge({
  5367. blockMap: blockMap.merge(newBlocks),
  5368. selectionBefore: selectionState,
  5369. selectionAfter: selectionState
  5370. });
  5371. }
  5372. var modifyBlockForContentState_1 = modifyBlockForContentState;
  5373. /**
  5374. * Copyright (c) 2013-present, Facebook, Inc.
  5375. * All rights reserved.
  5376. *
  5377. * This source code is licensed under the BSD-style license found in the
  5378. * LICENSE file in the root directory of this source tree. An additional grant
  5379. * of patent rights can be found in the PATENTS file in the same directory.
  5380. *
  5381. * @providesModule getNextDelimiterBlockKey
  5382. * @format
  5383. *
  5384. *
  5385. * This is unstable and not part of the public API and should not be used by
  5386. * production systems. This file may be update/removed without notice.
  5387. */
  5388. var getNextDelimiterBlockKey = function getNextDelimiterBlockKey(block, blockMap) {
  5389. var isExperimentalTreeBlock = block instanceof ContentBlockNode_1;
  5390. if (!isExperimentalTreeBlock) {
  5391. return null;
  5392. }
  5393. var nextSiblingKey = block.getNextSiblingKey();
  5394. if (nextSiblingKey) {
  5395. return nextSiblingKey;
  5396. }
  5397. var parent = block.getParentKey();
  5398. if (!parent) {
  5399. return null;
  5400. }
  5401. var nextNonDescendantBlock = blockMap.get(parent);
  5402. while (nextNonDescendantBlock && !nextNonDescendantBlock.getNextSiblingKey()) {
  5403. var parentKey = nextNonDescendantBlock.getParentKey();
  5404. nextNonDescendantBlock = parentKey ? blockMap.get(parentKey) : null;
  5405. }
  5406. if (!nextNonDescendantBlock) {
  5407. return null;
  5408. }
  5409. return nextNonDescendantBlock.getNextSiblingKey();
  5410. };
  5411. var getNextDelimiterBlockKey_1 = getNextDelimiterBlockKey;
  5412. var List$3 = immutable.List,
  5413. Map$6 = immutable.Map;
  5414. var transformBlock = function transformBlock(key, blockMap, func) {
  5415. if (!key) {
  5416. return;
  5417. }
  5418. var block = blockMap.get(key);
  5419. if (!block) {
  5420. return;
  5421. }
  5422. blockMap.set(key, func(block));
  5423. };
  5424. /**
  5425. * Ancestors needs to be preserved when there are non selected
  5426. * children to make sure we do not leave any orphans behind
  5427. */
  5428. var getAncestorsKeys = function getAncestorsKeys(blockKey, blockMap) {
  5429. var parents = [];
  5430. if (!blockKey) {
  5431. return parents;
  5432. }
  5433. var blockNode = blockMap.get(blockKey);
  5434. while (blockNode && blockNode.getParentKey()) {
  5435. var parentKey = blockNode.getParentKey();
  5436. if (parentKey) {
  5437. parents.push(parentKey);
  5438. }
  5439. blockNode = parentKey ? blockMap.get(parentKey) : null;
  5440. }
  5441. return parents;
  5442. };
  5443. /**
  5444. * Get all next delimiter keys until we hit a root delimiter and return
  5445. * an array of key references
  5446. */
  5447. var getNextDelimitersBlockKeys = function getNextDelimitersBlockKeys(block, blockMap) {
  5448. var nextDelimiters = [];
  5449. if (!block) {
  5450. return nextDelimiters;
  5451. }
  5452. var nextDelimiter = getNextDelimiterBlockKey_1(block, blockMap);
  5453. while (nextDelimiter && blockMap.get(nextDelimiter)) {
  5454. var _block = blockMap.get(nextDelimiter);
  5455. nextDelimiters.push(nextDelimiter);
  5456. // we do not need to keep checking all root node siblings, just the first occurance
  5457. nextDelimiter = _block.getParentKey() ? getNextDelimiterBlockKey_1(_block, blockMap) : null;
  5458. }
  5459. return nextDelimiters;
  5460. };
  5461. var getNextValidSibling = function getNextValidSibling(block, blockMap, originalBlockMap) {
  5462. if (!block) {
  5463. return null;
  5464. }
  5465. // note that we need to make sure we refer to the original block since this
  5466. // function is called within a withMutations
  5467. var nextValidSiblingKey = originalBlockMap.get(block.getKey()).getNextSiblingKey();
  5468. while (nextValidSiblingKey && !blockMap.get(nextValidSiblingKey)) {
  5469. nextValidSiblingKey = originalBlockMap.get(nextValidSiblingKey).getNextSiblingKey() || null;
  5470. }
  5471. return nextValidSiblingKey;
  5472. };
  5473. var getPrevValidSibling = function getPrevValidSibling(block, blockMap, originalBlockMap) {
  5474. if (!block) {
  5475. return null;
  5476. }
  5477. // note that we need to make sure we refer to the original block since this
  5478. // function is called within a withMutations
  5479. var prevValidSiblingKey = originalBlockMap.get(block.getKey()).getPrevSiblingKey();
  5480. while (prevValidSiblingKey && !blockMap.get(prevValidSiblingKey)) {
  5481. prevValidSiblingKey = originalBlockMap.get(prevValidSiblingKey).getPrevSiblingKey() || null;
  5482. }
  5483. return prevValidSiblingKey;
  5484. };
  5485. var updateBlockMapLinks$1 = function updateBlockMapLinks(blockMap, startBlock, endBlock, originalBlockMap) {
  5486. return blockMap.withMutations(function (blocks) {
  5487. // update start block if its retained
  5488. transformBlock(startBlock.getKey(), blocks, function (block) {
  5489. return block.merge({
  5490. nextSibling: getNextValidSibling(startBlock, blocks, originalBlockMap),
  5491. prevSibling: getPrevValidSibling(startBlock, blocks, originalBlockMap)
  5492. });
  5493. });
  5494. // update endblock if its retained
  5495. transformBlock(endBlock.getKey(), blocks, function (block) {
  5496. return block.merge({
  5497. nextSibling: getNextValidSibling(endBlock, blocks, originalBlockMap),
  5498. prevSibling: getPrevValidSibling(endBlock, blocks, originalBlockMap)
  5499. });
  5500. });
  5501. // update start block parent ancestors
  5502. getAncestorsKeys(startBlock.getKey(), originalBlockMap).forEach(function (parentKey) {
  5503. return transformBlock(parentKey, blocks, function (block) {
  5504. return block.merge({
  5505. children: block.getChildKeys().filter(function (key) {
  5506. return blocks.get(key);
  5507. }),
  5508. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  5509. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  5510. });
  5511. });
  5512. });
  5513. // update start block next - can only happen if startBlock == endBlock
  5514. transformBlock(startBlock.getNextSiblingKey(), blocks, function (block) {
  5515. return block.merge({
  5516. prevSibling: startBlock.getPrevSiblingKey()
  5517. });
  5518. });
  5519. // update start block prev
  5520. transformBlock(startBlock.getPrevSiblingKey(), blocks, function (block) {
  5521. return block.merge({
  5522. nextSibling: getNextValidSibling(startBlock, blocks, originalBlockMap)
  5523. });
  5524. });
  5525. // update end block next
  5526. transformBlock(endBlock.getNextSiblingKey(), blocks, function (block) {
  5527. return block.merge({
  5528. prevSibling: getPrevValidSibling(endBlock, blocks, originalBlockMap)
  5529. });
  5530. });
  5531. // update end block prev
  5532. transformBlock(endBlock.getPrevSiblingKey(), blocks, function (block) {
  5533. return block.merge({
  5534. nextSibling: endBlock.getNextSiblingKey()
  5535. });
  5536. });
  5537. // update end block parent ancestors
  5538. getAncestorsKeys(endBlock.getKey(), originalBlockMap).forEach(function (parentKey) {
  5539. transformBlock(parentKey, blocks, function (block) {
  5540. return block.merge({
  5541. children: block.getChildKeys().filter(function (key) {
  5542. return blocks.get(key);
  5543. }),
  5544. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  5545. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  5546. });
  5547. });
  5548. });
  5549. // update next delimiters all the way to a root delimiter
  5550. getNextDelimitersBlockKeys(endBlock, originalBlockMap).forEach(function (delimiterKey) {
  5551. return transformBlock(delimiterKey, blocks, function (block) {
  5552. return block.merge({
  5553. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  5554. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  5555. });
  5556. });
  5557. });
  5558. });
  5559. };
  5560. var removeRangeFromContentState = function removeRangeFromContentState(contentState, selectionState) {
  5561. if (selectionState.isCollapsed()) {
  5562. return contentState;
  5563. }
  5564. var blockMap = contentState.getBlockMap();
  5565. var startKey = selectionState.getStartKey();
  5566. var startOffset = selectionState.getStartOffset();
  5567. var endKey = selectionState.getEndKey();
  5568. var endOffset = selectionState.getEndOffset();
  5569. var startBlock = blockMap.get(startKey);
  5570. var endBlock = blockMap.get(endKey);
  5571. // we assume that ContentBlockNode and ContentBlocks are not mixed together
  5572. var isExperimentalTreeBlock = startBlock instanceof ContentBlockNode_1;
  5573. // used to retain blocks that should not be deleted to avoid orphan children
  5574. var parentAncestors = [];
  5575. if (isExperimentalTreeBlock) {
  5576. var endBlockchildrenKeys = endBlock.getChildKeys();
  5577. var endBlockAncestors = getAncestorsKeys(endKey, blockMap);
  5578. // endBlock has unselected sibblings so we can not remove its ancestors parents
  5579. if (endBlock.getNextSiblingKey()) {
  5580. parentAncestors = parentAncestors.concat(endBlockAncestors);
  5581. }
  5582. // endBlock has children so can not remove this block or any of its ancestors
  5583. if (!endBlockchildrenKeys.isEmpty()) {
  5584. parentAncestors = parentAncestors.concat(endBlockAncestors.concat([endKey]));
  5585. }
  5586. // we need to retain all ancestors of the next delimiter block
  5587. parentAncestors = parentAncestors.concat(getAncestorsKeys(getNextDelimiterBlockKey_1(endBlock, blockMap), blockMap));
  5588. }
  5589. var characterList = void 0;
  5590. if (startBlock === endBlock) {
  5591. characterList = removeFromList(startBlock.getCharacterList(), startOffset, endOffset);
  5592. } else {
  5593. characterList = startBlock.getCharacterList().slice(0, startOffset).concat(endBlock.getCharacterList().slice(endOffset));
  5594. }
  5595. var modifiedStart = startBlock.merge({
  5596. text: startBlock.getText().slice(0, startOffset) + endBlock.getText().slice(endOffset),
  5597. characterList: characterList
  5598. });
  5599. var newBlocks = blockMap.toSeq().skipUntil(function (_, k) {
  5600. return k === startKey;
  5601. }).takeUntil(function (_, k) {
  5602. return k === endKey;
  5603. }).filter(function (_, k) {
  5604. return parentAncestors.indexOf(k) === -1;
  5605. }).concat(Map$6([[endKey, null]])).map(function (_, k) {
  5606. return k === startKey ? modifiedStart : null;
  5607. });
  5608. var updatedBlockMap = blockMap.merge(newBlocks).filter(function (block) {
  5609. return !!block;
  5610. });
  5611. if (isExperimentalTreeBlock) {
  5612. updatedBlockMap = updateBlockMapLinks$1(updatedBlockMap, startBlock, endBlock, blockMap);
  5613. }
  5614. return contentState.merge({
  5615. blockMap: updatedBlockMap,
  5616. selectionBefore: selectionState,
  5617. selectionAfter: selectionState.merge({
  5618. anchorKey: startKey,
  5619. anchorOffset: startOffset,
  5620. focusKey: startKey,
  5621. focusOffset: startOffset,
  5622. isBackward: false
  5623. })
  5624. });
  5625. };
  5626. /**
  5627. * Maintain persistence for target list when removing characters on the
  5628. * head and tail of the character list.
  5629. */
  5630. var removeFromList = function removeFromList(targetList, startOffset, endOffset) {
  5631. if (startOffset === 0) {
  5632. while (startOffset < endOffset) {
  5633. targetList = targetList.shift();
  5634. startOffset++;
  5635. }
  5636. } else if (endOffset === targetList.count()) {
  5637. while (endOffset > startOffset) {
  5638. targetList = targetList.pop();
  5639. endOffset--;
  5640. }
  5641. } else {
  5642. var head = targetList.slice(0, startOffset);
  5643. var tail = targetList.slice(endOffset);
  5644. targetList = head.concat(tail).toList();
  5645. }
  5646. return targetList;
  5647. };
  5648. var removeRangeFromContentState_1 = removeRangeFromContentState;
  5649. var List$4 = immutable.List,
  5650. Map$7 = immutable.Map;
  5651. var transformBlock$1 = function transformBlock(key, blockMap, func) {
  5652. if (!key) {
  5653. return;
  5654. }
  5655. var block = blockMap.get(key);
  5656. if (!block) {
  5657. return;
  5658. }
  5659. blockMap.set(key, func(block));
  5660. };
  5661. var updateBlockMapLinks$2 = function updateBlockMapLinks(blockMap, originalBlock, belowBlock) {
  5662. return blockMap.withMutations(function (blocks) {
  5663. var originalBlockKey = originalBlock.getKey();
  5664. var belowBlockKey = belowBlock.getKey();
  5665. // update block parent
  5666. transformBlock$1(originalBlock.getParentKey(), blocks, function (block) {
  5667. var parentChildrenList = block.getChildKeys();
  5668. var insertionIndex = parentChildrenList.indexOf(originalBlockKey) + 1;
  5669. var newChildrenArray = parentChildrenList.toArray();
  5670. newChildrenArray.splice(insertionIndex, 0, belowBlockKey);
  5671. return block.merge({
  5672. children: List$4(newChildrenArray)
  5673. });
  5674. });
  5675. // update original next block
  5676. transformBlock$1(originalBlock.getNextSiblingKey(), blocks, function (block) {
  5677. return block.merge({
  5678. prevSibling: belowBlockKey
  5679. });
  5680. });
  5681. // update original block
  5682. transformBlock$1(originalBlockKey, blocks, function (block) {
  5683. return block.merge({
  5684. nextSibling: belowBlockKey
  5685. });
  5686. });
  5687. // update below block
  5688. transformBlock$1(belowBlockKey, blocks, function (block) {
  5689. return block.merge({
  5690. prevSibling: originalBlockKey
  5691. });
  5692. });
  5693. });
  5694. };
  5695. var splitBlockInContentState = function splitBlockInContentState(contentState, selectionState) {
  5696. !selectionState.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Selection range must be collapsed.') : invariant_1(false) : void 0;
  5697. var key = selectionState.getAnchorKey();
  5698. var offset = selectionState.getAnchorOffset();
  5699. var blockMap = contentState.getBlockMap();
  5700. var blockToSplit = blockMap.get(key);
  5701. var text = blockToSplit.getText();
  5702. var chars = blockToSplit.getCharacterList();
  5703. var keyBelow = generateRandomKey_1();
  5704. var isExperimentalTreeBlock = blockToSplit instanceof ContentBlockNode_1;
  5705. var blockAbove = blockToSplit.merge({
  5706. text: text.slice(0, offset),
  5707. characterList: chars.slice(0, offset)
  5708. });
  5709. var blockBelow = blockAbove.merge({
  5710. key: keyBelow,
  5711. text: text.slice(offset),
  5712. characterList: chars.slice(offset),
  5713. data: Map$7()
  5714. });
  5715. var blocksBefore = blockMap.toSeq().takeUntil(function (v) {
  5716. return v === blockToSplit;
  5717. });
  5718. var blocksAfter = blockMap.toSeq().skipUntil(function (v) {
  5719. return v === blockToSplit;
  5720. }).rest();
  5721. var newBlocks = blocksBefore.concat([[key, blockAbove], [keyBelow, blockBelow]], blocksAfter).toOrderedMap();
  5722. if (isExperimentalTreeBlock) {
  5723. !blockToSplit.getChildKeys().isEmpty() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'ContentBlockNode must not have children') : invariant_1(false) : void 0;
  5724. newBlocks = updateBlockMapLinks$2(newBlocks, blockAbove, blockBelow);
  5725. }
  5726. return contentState.merge({
  5727. blockMap: newBlocks,
  5728. selectionBefore: selectionState,
  5729. selectionAfter: selectionState.merge({
  5730. anchorKey: keyBelow,
  5731. anchorOffset: 0,
  5732. focusKey: keyBelow,
  5733. focusOffset: 0,
  5734. isBackward: false
  5735. })
  5736. });
  5737. };
  5738. var splitBlockInContentState_1 = splitBlockInContentState;
  5739. var OrderedSet$3 = immutable.OrderedSet;
  5740. /**
  5741. * `DraftModifier` provides a set of convenience methods that apply
  5742. * modifications to a `ContentState` object based on a target `SelectionState`.
  5743. *
  5744. * Any change to a `ContentState` should be decomposable into a series of
  5745. * transaction functions that apply the required changes and return output
  5746. * `ContentState` objects.
  5747. *
  5748. * These functions encapsulate some of the most common transaction sequences.
  5749. */
  5750. var DraftModifier = {
  5751. replaceText: function replaceText(contentState, rangeToReplace, text, inlineStyle, entityKey) {
  5752. var withoutEntities = removeEntitiesAtEdges_1(contentState, rangeToReplace);
  5753. var withoutText = removeRangeFromContentState_1(withoutEntities, rangeToReplace);
  5754. var character = CharacterMetadata_1.create({
  5755. style: inlineStyle || OrderedSet$3(),
  5756. entity: entityKey || null
  5757. });
  5758. return insertTextIntoContentState_1(withoutText, withoutText.getSelectionAfter(), text, character);
  5759. },
  5760. insertText: function insertText(contentState, targetRange, text, inlineStyle, entityKey) {
  5761. !targetRange.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Target range must be collapsed for `insertText`.') : invariant_1(false) : void 0;
  5762. return DraftModifier.replaceText(contentState, targetRange, text, inlineStyle, entityKey);
  5763. },
  5764. moveText: function moveText(contentState, removalRange, targetRange) {
  5765. var movedFragment = getContentStateFragment_1(contentState, removalRange);
  5766. var afterRemoval = DraftModifier.removeRange(contentState, removalRange, 'backward');
  5767. return DraftModifier.replaceWithFragment(afterRemoval, targetRange, movedFragment);
  5768. },
  5769. replaceWithFragment: function replaceWithFragment(contentState, targetRange, fragment) {
  5770. var withoutEntities = removeEntitiesAtEdges_1(contentState, targetRange);
  5771. var withoutText = removeRangeFromContentState_1(withoutEntities, targetRange);
  5772. return insertFragmentIntoContentState_1(withoutText, withoutText.getSelectionAfter(), fragment);
  5773. },
  5774. removeRange: function removeRange(contentState, rangeToRemove, removalDirection) {
  5775. var startKey = void 0,
  5776. endKey = void 0,
  5777. startBlock = void 0,
  5778. endBlock = void 0;
  5779. if (rangeToRemove.getIsBackward()) {
  5780. rangeToRemove = rangeToRemove.merge({
  5781. anchorKey: rangeToRemove.getFocusKey(),
  5782. anchorOffset: rangeToRemove.getFocusOffset(),
  5783. focusKey: rangeToRemove.getAnchorKey(),
  5784. focusOffset: rangeToRemove.getAnchorOffset(),
  5785. isBackward: false
  5786. });
  5787. }
  5788. startKey = rangeToRemove.getAnchorKey();
  5789. endKey = rangeToRemove.getFocusKey();
  5790. startBlock = contentState.getBlockForKey(startKey);
  5791. endBlock = contentState.getBlockForKey(endKey);
  5792. var startOffset = rangeToRemove.getStartOffset();
  5793. var endOffset = rangeToRemove.getEndOffset();
  5794. var startEntityKey = startBlock.getEntityAt(startOffset);
  5795. var endEntityKey = endBlock.getEntityAt(endOffset - 1);
  5796. // Check whether the selection state overlaps with a single entity.
  5797. // If so, try to remove the appropriate substring of the entity text.
  5798. if (startKey === endKey) {
  5799. if (startEntityKey && startEntityKey === endEntityKey) {
  5800. var _adjustedRemovalRange = getCharacterRemovalRange_1(contentState.getEntityMap(), startBlock, endBlock, rangeToRemove, removalDirection);
  5801. return removeRangeFromContentState_1(contentState, _adjustedRemovalRange);
  5802. }
  5803. }
  5804. var adjustedRemovalRange = rangeToRemove;
  5805. var withoutEntities = removeEntitiesAtEdges_1(contentState, adjustedRemovalRange);
  5806. return removeRangeFromContentState_1(withoutEntities, adjustedRemovalRange);
  5807. },
  5808. splitBlock: function splitBlock(contentState, selectionState) {
  5809. var withoutEntities = removeEntitiesAtEdges_1(contentState, selectionState);
  5810. var withoutText = removeRangeFromContentState_1(withoutEntities, selectionState);
  5811. return splitBlockInContentState_1(withoutText, withoutText.getSelectionAfter());
  5812. },
  5813. applyInlineStyle: function applyInlineStyle(contentState, selectionState, inlineStyle) {
  5814. return ContentStateInlineStyle_1.add(contentState, selectionState, inlineStyle);
  5815. },
  5816. removeInlineStyle: function removeInlineStyle(contentState, selectionState, inlineStyle) {
  5817. return ContentStateInlineStyle_1.remove(contentState, selectionState, inlineStyle);
  5818. },
  5819. setBlockType: function setBlockType(contentState, selectionState, blockType) {
  5820. return modifyBlockForContentState_1(contentState, selectionState, function (block) {
  5821. return block.merge({ type: blockType, depth: 0 });
  5822. });
  5823. },
  5824. setBlockData: function setBlockData(contentState, selectionState, blockData) {
  5825. return modifyBlockForContentState_1(contentState, selectionState, function (block) {
  5826. return block.merge({ data: blockData });
  5827. });
  5828. },
  5829. mergeBlockData: function mergeBlockData(contentState, selectionState, blockData) {
  5830. return modifyBlockForContentState_1(contentState, selectionState, function (block) {
  5831. return block.merge({ data: block.getData().merge(blockData) });
  5832. });
  5833. },
  5834. applyEntity: function applyEntity(contentState, selectionState, entityKey) {
  5835. var withoutEntities = removeEntitiesAtEdges_1(contentState, selectionState);
  5836. return applyEntityToContentState_1(withoutEntities, selectionState, entityKey);
  5837. }
  5838. };
  5839. var DraftModifier_1 = DraftModifier;
  5840. /**
  5841. * Copyright (c) 2013-present, Facebook, Inc.
  5842. *
  5843. * This source code is licensed under the MIT license found in the
  5844. * LICENSE file in the root directory of this source tree.
  5845. *
  5846. *
  5847. */
  5848. function makeEmptyFunction(arg) {
  5849. return function () {
  5850. return arg;
  5851. };
  5852. }
  5853. /**
  5854. * This function accepts and discards inputs; it has no side effects. This is
  5855. * primarily useful idiomatically for overridable function endpoints which
  5856. * always need to be callable, since JS lacks a null-call idiom ala Cocoa.
  5857. */
  5858. var emptyFunction = function emptyFunction() {};
  5859. emptyFunction.thatReturns = makeEmptyFunction;
  5860. emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
  5861. emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
  5862. emptyFunction.thatReturnsNull = makeEmptyFunction(null);
  5863. emptyFunction.thatReturnsThis = function () {
  5864. return this;
  5865. };
  5866. emptyFunction.thatReturnsArgument = function (arg) {
  5867. return arg;
  5868. };
  5869. var emptyFunction_1 = emptyFunction;
  5870. var List$5 = immutable.List,
  5871. Repeat$3 = immutable.Repeat,
  5872. Record$3 = immutable.Record;
  5873. var returnTrue = emptyFunction_1.thatReturnsTrue;
  5874. var FINGERPRINT_DELIMITER = '-';
  5875. var defaultLeafRange = {
  5876. start: null,
  5877. end: null
  5878. };
  5879. var LeafRange = Record$3(defaultLeafRange);
  5880. var defaultDecoratorRange = {
  5881. start: null,
  5882. end: null,
  5883. decoratorKey: null,
  5884. leaves: null
  5885. };
  5886. var DecoratorRange = Record$3(defaultDecoratorRange);
  5887. var BlockTree = {
  5888. /**
  5889. * Generate a block tree for a given ContentBlock/decorator pair.
  5890. */
  5891. generate: function generate(contentState, block, decorator) {
  5892. var textLength = block.getLength();
  5893. if (!textLength) {
  5894. return List$5.of(new DecoratorRange({
  5895. start: 0,
  5896. end: 0,
  5897. decoratorKey: null,
  5898. leaves: List$5.of(new LeafRange({ start: 0, end: 0 }))
  5899. }));
  5900. }
  5901. var leafSets = [];
  5902. var decorations = decorator ? decorator.getDecorations(block, contentState) : List$5(Repeat$3(null, textLength));
  5903. var chars = block.getCharacterList();
  5904. findRangesImmutable_1(decorations, areEqual, returnTrue, function (start, end) {
  5905. leafSets.push(new DecoratorRange({
  5906. start: start,
  5907. end: end,
  5908. decoratorKey: decorations.get(start),
  5909. leaves: generateLeaves(chars.slice(start, end).toList(), start)
  5910. }));
  5911. });
  5912. return List$5(leafSets);
  5913. },
  5914. /**
  5915. * Create a string representation of the given tree map. This allows us
  5916. * to rapidly determine whether a tree has undergone a significant
  5917. * structural change.
  5918. */
  5919. getFingerprint: function getFingerprint(tree) {
  5920. return tree.map(function (leafSet) {
  5921. var decoratorKey = leafSet.get('decoratorKey');
  5922. var fingerprintString = decoratorKey !== null ? decoratorKey + '.' + (leafSet.get('end') - leafSet.get('start')) : '';
  5923. return '' + fingerprintString + '.' + leafSet.get('leaves').size;
  5924. }).join(FINGERPRINT_DELIMITER);
  5925. }
  5926. };
  5927. /**
  5928. * Generate LeafRange records for a given character list.
  5929. */
  5930. function generateLeaves(characters, offset) {
  5931. var leaves = [];
  5932. var inlineStyles = characters.map(function (c) {
  5933. return c.getStyle();
  5934. }).toList();
  5935. findRangesImmutable_1(inlineStyles, areEqual, returnTrue, function (start, end) {
  5936. leaves.push(new LeafRange({
  5937. start: start + offset,
  5938. end: end + offset
  5939. }));
  5940. });
  5941. return List$5(leaves);
  5942. }
  5943. function areEqual(a, b) {
  5944. return a === b;
  5945. }
  5946. var BlockTree_1 = BlockTree;
  5947. function _classCallCheck$3(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5948. 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; }
  5949. 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; }
  5950. var Record$4 = immutable.Record;
  5951. var DraftEntityInstanceRecord = Record$4({
  5952. type: 'TOKEN',
  5953. mutability: 'IMMUTABLE',
  5954. data: Object
  5955. });
  5956. /**
  5957. * An instance of a document entity, consisting of a `type` and relevant
  5958. * `data`, metadata about the entity.
  5959. *
  5960. * For instance, a "link" entity might provide a URI, and a "mention"
  5961. * entity might provide the mentioned user's ID. These pieces of data
  5962. * may be used when rendering the entity as part of a ContentBlock DOM
  5963. * representation. For a link, the data would be used as an href for
  5964. * the rendered anchor. For a mention, the ID could be used to retrieve
  5965. * a hovercard.
  5966. */
  5967. var DraftEntityInstance = function (_DraftEntityInstanceR) {
  5968. _inherits$3(DraftEntityInstance, _DraftEntityInstanceR);
  5969. function DraftEntityInstance() {
  5970. _classCallCheck$3(this, DraftEntityInstance);
  5971. return _possibleConstructorReturn$3(this, _DraftEntityInstanceR.apply(this, arguments));
  5972. }
  5973. DraftEntityInstance.prototype.getType = function getType() {
  5974. return this.get('type');
  5975. };
  5976. DraftEntityInstance.prototype.getMutability = function getMutability() {
  5977. return this.get('mutability');
  5978. };
  5979. DraftEntityInstance.prototype.getData = function getData() {
  5980. return this.get('data');
  5981. };
  5982. return DraftEntityInstance;
  5983. }(DraftEntityInstanceRecord);
  5984. var DraftEntityInstance_1 = DraftEntityInstance;
  5985. 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; };
  5986. /**
  5987. * Copyright (c) 2013-present, Facebook, Inc.
  5988. * All rights reserved.
  5989. *
  5990. * This source code is licensed under the BSD-style license found in the
  5991. * LICENSE file in the root directory of this source tree. An additional grant
  5992. * of patent rights can be found in the PATENTS file in the same directory.
  5993. *
  5994. * @providesModule DraftEntity
  5995. * @format
  5996. *
  5997. */
  5998. var Map$8 = immutable.Map;
  5999. var instances = Map$8();
  6000. var instanceKey = 0;
  6001. /**
  6002. * Temporary utility for generating the warnings
  6003. */
  6004. function logWarning(oldMethodCall, newMethodCall) {
  6005. console.warn('WARNING: ' + oldMethodCall + ' will be deprecated soon!\nPlease use "' + newMethodCall + '" instead.');
  6006. }
  6007. /**
  6008. * A "document entity" is an object containing metadata associated with a
  6009. * piece of text in a ContentBlock.
  6010. *
  6011. * For example, a `link` entity might include a `uri` property. When a
  6012. * ContentBlock is rendered in the browser, text that refers to that link
  6013. * entity may be rendered as an anchor, with the `uri` as the href value.
  6014. *
  6015. * In a ContentBlock, every position in the text may correspond to zero
  6016. * or one entities. This correspondence is tracked using a key string,
  6017. * generated via DraftEntity.create() and used to obtain entity metadata
  6018. * via DraftEntity.get().
  6019. */
  6020. var DraftEntity = {
  6021. /**
  6022. * WARNING: This method will be deprecated soon!
  6023. * Please use 'contentState.getLastCreatedEntityKey' instead.
  6024. * ---
  6025. * Get the random key string from whatever entity was last created.
  6026. * We need this to support the new API, as part of transitioning to put Entity
  6027. * storage in contentState.
  6028. */
  6029. getLastCreatedEntityKey: function getLastCreatedEntityKey() {
  6030. logWarning('DraftEntity.getLastCreatedEntityKey', 'contentState.getLastCreatedEntityKey');
  6031. return DraftEntity.__getLastCreatedEntityKey();
  6032. },
  6033. /**
  6034. * WARNING: This method will be deprecated soon!
  6035. * Please use 'contentState.createEntity' instead.
  6036. * ---
  6037. * Create a DraftEntityInstance and store it for later retrieval.
  6038. *
  6039. * A random key string will be generated and returned. This key may
  6040. * be used to track the entity's usage in a ContentBlock, and for
  6041. * retrieving data about the entity at render time.
  6042. */
  6043. create: function create(type, mutability, data) {
  6044. logWarning('DraftEntity.create', 'contentState.createEntity');
  6045. return DraftEntity.__create(type, mutability, data);
  6046. },
  6047. /**
  6048. * WARNING: This method will be deprecated soon!
  6049. * Please use 'contentState.addEntity' instead.
  6050. * ---
  6051. * Add an existing DraftEntityInstance to the DraftEntity map. This is
  6052. * useful when restoring instances from the server.
  6053. */
  6054. add: function add(instance) {
  6055. logWarning('DraftEntity.add', 'contentState.addEntity');
  6056. return DraftEntity.__add(instance);
  6057. },
  6058. /**
  6059. * WARNING: This method will be deprecated soon!
  6060. * Please use 'contentState.getEntity' instead.
  6061. * ---
  6062. * Retrieve the entity corresponding to the supplied key string.
  6063. */
  6064. get: function get(key) {
  6065. logWarning('DraftEntity.get', 'contentState.getEntity');
  6066. return DraftEntity.__get(key);
  6067. },
  6068. /**
  6069. * WARNING: This method will be deprecated soon!
  6070. * Please use 'contentState.mergeEntityData' instead.
  6071. * ---
  6072. * Entity instances are immutable. If you need to update the data for an
  6073. * instance, this method will merge your data updates and return a new
  6074. * instance.
  6075. */
  6076. mergeData: function mergeData(key, toMerge) {
  6077. logWarning('DraftEntity.mergeData', 'contentState.mergeEntityData');
  6078. return DraftEntity.__mergeData(key, toMerge);
  6079. },
  6080. /**
  6081. * WARNING: This method will be deprecated soon!
  6082. * Please use 'contentState.replaceEntityData' instead.
  6083. * ---
  6084. * Completely replace the data for a given instance.
  6085. */
  6086. replaceData: function replaceData(key, newData) {
  6087. logWarning('DraftEntity.replaceData', 'contentState.replaceEntityData');
  6088. return DraftEntity.__replaceData(key, newData);
  6089. },
  6090. // ***********************************WARNING******************************
  6091. // --- the above public API will be deprecated in the next version of Draft!
  6092. // The methods below this line are private - don't call them directly.
  6093. /**
  6094. * Get the random key string from whatever entity was last created.
  6095. * We need this to support the new API, as part of transitioning to put Entity
  6096. * storage in contentState.
  6097. */
  6098. __getLastCreatedEntityKey: function __getLastCreatedEntityKey() {
  6099. return '' + instanceKey;
  6100. },
  6101. /**
  6102. * Create a DraftEntityInstance and store it for later retrieval.
  6103. *
  6104. * A random key string will be generated and returned. This key may
  6105. * be used to track the entity's usage in a ContentBlock, and for
  6106. * retrieving data about the entity at render time.
  6107. */
  6108. __create: function __create(type, mutability, data) {
  6109. return DraftEntity.__add(new DraftEntityInstance_1({ type: type, mutability: mutability, data: data || {} }));
  6110. },
  6111. /**
  6112. * Add an existing DraftEntityInstance to the DraftEntity map. This is
  6113. * useful when restoring instances from the server.
  6114. */
  6115. __add: function __add(instance) {
  6116. var key = '' + ++instanceKey;
  6117. instances = instances.set(key, instance);
  6118. return key;
  6119. },
  6120. /**
  6121. * Retrieve the entity corresponding to the supplied key string.
  6122. */
  6123. __get: function __get(key) {
  6124. var instance = instances.get(key);
  6125. !!!instance ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Unknown DraftEntity key: %s.', key) : invariant_1(false) : void 0;
  6126. return instance;
  6127. },
  6128. /**
  6129. * Entity instances are immutable. If you need to update the data for an
  6130. * instance, this method will merge your data updates and return a new
  6131. * instance.
  6132. */
  6133. __mergeData: function __mergeData(key, toMerge) {
  6134. var instance = DraftEntity.__get(key);
  6135. var newData = _extends({}, instance.getData(), toMerge);
  6136. var newInstance = instance.set('data', newData);
  6137. instances = instances.set(key, newInstance);
  6138. return newInstance;
  6139. },
  6140. /**
  6141. * Completely replace the data for a given instance.
  6142. */
  6143. __replaceData: function __replaceData(key, newData) {
  6144. var instance = DraftEntity.__get(key);
  6145. var newInstance = instance.set('data', newData);
  6146. instances = instances.set(key, newInstance);
  6147. return newInstance;
  6148. }
  6149. };
  6150. var DraftEntity_1 = DraftEntity;
  6151. function _classCallCheck$4(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6152. 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; }
  6153. 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; }
  6154. var Record$5 = immutable.Record;
  6155. var defaultRecord$3 = {
  6156. anchorKey: '',
  6157. anchorOffset: 0,
  6158. focusKey: '',
  6159. focusOffset: 0,
  6160. isBackward: false,
  6161. hasFocus: false
  6162. };
  6163. var SelectionStateRecord = Record$5(defaultRecord$3);
  6164. var SelectionState = function (_SelectionStateRecord) {
  6165. _inherits$4(SelectionState, _SelectionStateRecord);
  6166. function SelectionState() {
  6167. _classCallCheck$4(this, SelectionState);
  6168. return _possibleConstructorReturn$4(this, _SelectionStateRecord.apply(this, arguments));
  6169. }
  6170. SelectionState.prototype.serialize = function serialize() {
  6171. return 'Anchor: ' + this.getAnchorKey() + ':' + this.getAnchorOffset() + ', ' + 'Focus: ' + this.getFocusKey() + ':' + this.getFocusOffset() + ', ' + 'Is Backward: ' + String(this.getIsBackward()) + ', ' + 'Has Focus: ' + String(this.getHasFocus());
  6172. };
  6173. SelectionState.prototype.getAnchorKey = function getAnchorKey() {
  6174. return this.get('anchorKey');
  6175. };
  6176. SelectionState.prototype.getAnchorOffset = function getAnchorOffset() {
  6177. return this.get('anchorOffset');
  6178. };
  6179. SelectionState.prototype.getFocusKey = function getFocusKey() {
  6180. return this.get('focusKey');
  6181. };
  6182. SelectionState.prototype.getFocusOffset = function getFocusOffset() {
  6183. return this.get('focusOffset');
  6184. };
  6185. SelectionState.prototype.getIsBackward = function getIsBackward() {
  6186. return this.get('isBackward');
  6187. };
  6188. SelectionState.prototype.getHasFocus = function getHasFocus() {
  6189. return this.get('hasFocus');
  6190. };
  6191. /**
  6192. * Return whether the specified range overlaps with an edge of the
  6193. * SelectionState.
  6194. */
  6195. SelectionState.prototype.hasEdgeWithin = function hasEdgeWithin(blockKey, start, end) {
  6196. var anchorKey = this.getAnchorKey();
  6197. var focusKey = this.getFocusKey();
  6198. if (anchorKey === focusKey && anchorKey === blockKey) {
  6199. var selectionStart = this.getStartOffset();
  6200. var selectionEnd = this.getEndOffset();
  6201. return start <= selectionEnd && selectionStart <= end;
  6202. }
  6203. if (blockKey !== anchorKey && blockKey !== focusKey) {
  6204. return false;
  6205. }
  6206. var offsetToCheck = blockKey === anchorKey ? this.getAnchorOffset() : this.getFocusOffset();
  6207. return start <= offsetToCheck && end >= offsetToCheck;
  6208. };
  6209. SelectionState.prototype.isCollapsed = function isCollapsed() {
  6210. return this.getAnchorKey() === this.getFocusKey() && this.getAnchorOffset() === this.getFocusOffset();
  6211. };
  6212. SelectionState.prototype.getStartKey = function getStartKey() {
  6213. return this.getIsBackward() ? this.getFocusKey() : this.getAnchorKey();
  6214. };
  6215. SelectionState.prototype.getStartOffset = function getStartOffset() {
  6216. return this.getIsBackward() ? this.getFocusOffset() : this.getAnchorOffset();
  6217. };
  6218. SelectionState.prototype.getEndKey = function getEndKey() {
  6219. return this.getIsBackward() ? this.getAnchorKey() : this.getFocusKey();
  6220. };
  6221. SelectionState.prototype.getEndOffset = function getEndOffset() {
  6222. return this.getIsBackward() ? this.getAnchorOffset() : this.getFocusOffset();
  6223. };
  6224. SelectionState.createEmpty = function createEmpty(key) {
  6225. return new SelectionState({
  6226. anchorKey: key,
  6227. anchorOffset: 0,
  6228. focusKey: key,
  6229. focusOffset: 0,
  6230. isBackward: false,
  6231. hasFocus: false
  6232. });
  6233. };
  6234. return SelectionState;
  6235. }(SelectionStateRecord);
  6236. var SelectionState_1 = SelectionState;
  6237. /**
  6238. * Copyright (c) 2013-present, Facebook, Inc.
  6239. * All rights reserved.
  6240. *
  6241. * This source code is licensed under the BSD-style license found in the
  6242. * LICENSE file in the root directory of this source tree. An additional grant
  6243. * of patent rights can be found in the PATENTS file in the same directory.
  6244. *
  6245. * @providesModule sanitizeDraftText
  6246. * @format
  6247. *
  6248. */
  6249. var REGEX_BLOCK_DELIMITER = new RegExp('\r', 'g');
  6250. function sanitizeDraftText(input) {
  6251. return input.replace(REGEX_BLOCK_DELIMITER, '');
  6252. }
  6253. var sanitizeDraftText_1 = sanitizeDraftText;
  6254. function _classCallCheck$5(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6255. 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; }
  6256. 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; }
  6257. var List$6 = immutable.List,
  6258. Record$6 = immutable.Record,
  6259. Repeat$4 = immutable.Repeat;
  6260. var defaultRecord$4 = {
  6261. entityMap: null,
  6262. blockMap: null,
  6263. selectionBefore: null,
  6264. selectionAfter: null
  6265. };
  6266. var ContentBlockNodeRecord = ContentBlock_1;
  6267. var ContentStateRecord = Record$6(defaultRecord$4);
  6268. var ContentState = function (_ContentStateRecord) {
  6269. _inherits$5(ContentState, _ContentStateRecord);
  6270. function ContentState() {
  6271. _classCallCheck$5(this, ContentState);
  6272. return _possibleConstructorReturn$5(this, _ContentStateRecord.apply(this, arguments));
  6273. }
  6274. ContentState.prototype.getEntityMap = function getEntityMap() {
  6275. // TODO: update this when we fully remove DraftEntity
  6276. return DraftEntity_1;
  6277. };
  6278. ContentState.prototype.getBlockMap = function getBlockMap() {
  6279. return this.get('blockMap');
  6280. };
  6281. ContentState.prototype.getSelectionBefore = function getSelectionBefore() {
  6282. return this.get('selectionBefore');
  6283. };
  6284. ContentState.prototype.getSelectionAfter = function getSelectionAfter() {
  6285. return this.get('selectionAfter');
  6286. };
  6287. ContentState.prototype.getBlockForKey = function getBlockForKey(key) {
  6288. var block = this.getBlockMap().get(key);
  6289. return block;
  6290. };
  6291. ContentState.prototype.getKeyBefore = function getKeyBefore(key) {
  6292. return this.getBlockMap().reverse().keySeq().skipUntil(function (v) {
  6293. return v === key;
  6294. }).skip(1).first();
  6295. };
  6296. ContentState.prototype.getKeyAfter = function getKeyAfter(key) {
  6297. return this.getBlockMap().keySeq().skipUntil(function (v) {
  6298. return v === key;
  6299. }).skip(1).first();
  6300. };
  6301. ContentState.prototype.getBlockAfter = function getBlockAfter(key) {
  6302. return this.getBlockMap().skipUntil(function (_, k) {
  6303. return k === key;
  6304. }).skip(1).first();
  6305. };
  6306. ContentState.prototype.getBlockBefore = function getBlockBefore(key) {
  6307. return this.getBlockMap().reverse().skipUntil(function (_, k) {
  6308. return k === key;
  6309. }).skip(1).first();
  6310. };
  6311. ContentState.prototype.getBlocksAsArray = function getBlocksAsArray() {
  6312. return this.getBlockMap().toArray();
  6313. };
  6314. ContentState.prototype.getFirstBlock = function getFirstBlock() {
  6315. return this.getBlockMap().first();
  6316. };
  6317. ContentState.prototype.getLastBlock = function getLastBlock() {
  6318. return this.getBlockMap().last();
  6319. };
  6320. ContentState.prototype.getPlainText = function getPlainText(delimiter) {
  6321. return this.getBlockMap().map(function (block) {
  6322. return block ? block.getText() : '';
  6323. }).join(delimiter || '\n');
  6324. };
  6325. ContentState.prototype.getLastCreatedEntityKey = function getLastCreatedEntityKey() {
  6326. // TODO: update this when we fully remove DraftEntity
  6327. return DraftEntity_1.__getLastCreatedEntityKey();
  6328. };
  6329. ContentState.prototype.hasText = function hasText() {
  6330. var blockMap = this.getBlockMap();
  6331. return blockMap.size > 1 || blockMap.first().getLength() > 0;
  6332. };
  6333. ContentState.prototype.createEntity = function createEntity(type, mutability, data) {
  6334. // TODO: update this when we fully remove DraftEntity
  6335. DraftEntity_1.__create(type, mutability, data);
  6336. return this;
  6337. };
  6338. ContentState.prototype.mergeEntityData = function mergeEntityData(key, toMerge) {
  6339. // TODO: update this when we fully remove DraftEntity
  6340. DraftEntity_1.__mergeData(key, toMerge);
  6341. return this;
  6342. };
  6343. ContentState.prototype.replaceEntityData = function replaceEntityData(key, newData) {
  6344. // TODO: update this when we fully remove DraftEntity
  6345. DraftEntity_1.__replaceData(key, newData);
  6346. return this;
  6347. };
  6348. ContentState.prototype.addEntity = function addEntity(instance) {
  6349. // TODO: update this when we fully remove DraftEntity
  6350. DraftEntity_1.__add(instance);
  6351. return this;
  6352. };
  6353. ContentState.prototype.getEntity = function getEntity(key) {
  6354. // TODO: update this when we fully remove DraftEntity
  6355. return DraftEntity_1.__get(key);
  6356. };
  6357. ContentState.createFromBlockArray = function createFromBlockArray(
  6358. // TODO: update flow type when we completely deprecate the old entity API
  6359. blocks, entityMap) {
  6360. // TODO: remove this when we completely deprecate the old entity API
  6361. var theBlocks = Array.isArray(blocks) ? blocks : blocks.contentBlocks;
  6362. var blockMap = BlockMapBuilder_1.createFromArray(theBlocks);
  6363. var selectionState = blockMap.isEmpty() ? new SelectionState_1() : SelectionState_1.createEmpty(blockMap.first().getKey());
  6364. return new ContentState({
  6365. blockMap: blockMap,
  6366. entityMap: entityMap || DraftEntity_1,
  6367. selectionBefore: selectionState,
  6368. selectionAfter: selectionState
  6369. });
  6370. };
  6371. ContentState.createFromText = function createFromText(text) {
  6372. var delimiter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : /\r\n?|\n/g;
  6373. var strings = text.split(delimiter);
  6374. var blocks = strings.map(function (block) {
  6375. block = sanitizeDraftText_1(block);
  6376. return new ContentBlockNodeRecord({
  6377. key: generateRandomKey_1(),
  6378. text: block,
  6379. type: 'unstyled',
  6380. characterList: List$6(Repeat$4(CharacterMetadata_1.EMPTY, block.length))
  6381. });
  6382. });
  6383. return ContentState.createFromBlockArray(blocks);
  6384. };
  6385. return ContentState;
  6386. }(ContentStateRecord);
  6387. var ContentState_1 = ContentState;
  6388. var NEUTRAL = 'NEUTRAL'; // No strong direction
  6389. var LTR = 'LTR'; // Left-to-Right direction
  6390. var RTL = 'RTL'; // Right-to-Left direction
  6391. var globalDir = null;
  6392. // == Helpers ==
  6393. /**
  6394. * Check if a directionality value is a Strong one
  6395. */
  6396. function isStrong(dir) {
  6397. return dir === LTR || dir === RTL;
  6398. }
  6399. /**
  6400. * Get string value to be used for `dir` HTML attribute or `direction` CSS
  6401. * property.
  6402. */
  6403. function getHTMLDir(dir) {
  6404. !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;
  6405. return dir === LTR ? 'ltr' : 'rtl';
  6406. }
  6407. /**
  6408. * Get string value to be used for `dir` HTML attribute or `direction` CSS
  6409. * property, but returns null if `dir` has same value as `otherDir`.
  6410. * `null`.
  6411. */
  6412. function getHTMLDirIfDifferent(dir, otherDir) {
  6413. !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;
  6414. !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;
  6415. return dir === otherDir ? null : getHTMLDir(dir);
  6416. }
  6417. // == Global Direction ==
  6418. /**
  6419. * Set the global direction.
  6420. */
  6421. function setGlobalDir(dir) {
  6422. globalDir = dir;
  6423. }
  6424. /**
  6425. * Initialize the global direction
  6426. */
  6427. function initGlobalDir() {
  6428. setGlobalDir(LTR);
  6429. }
  6430. /**
  6431. * Get the global direction
  6432. */
  6433. function getGlobalDir() {
  6434. if (!globalDir) {
  6435. this.initGlobalDir();
  6436. }
  6437. !globalDir ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Global direction not set.') : invariant_1(false) : void 0;
  6438. return globalDir;
  6439. }
  6440. var UnicodeBidiDirection = {
  6441. // Values
  6442. NEUTRAL: NEUTRAL,
  6443. LTR: LTR,
  6444. RTL: RTL,
  6445. // Helpers
  6446. isStrong: isStrong,
  6447. getHTMLDir: getHTMLDir,
  6448. getHTMLDirIfDifferent: getHTMLDirIfDifferent,
  6449. // Global Direction
  6450. setGlobalDir: setGlobalDir,
  6451. initGlobalDir: initGlobalDir,
  6452. getGlobalDir: getGlobalDir
  6453. };
  6454. var UnicodeBidiDirection_1 = UnicodeBidiDirection;
  6455. /**
  6456. * RegExp ranges of characters with a *Strong* Bidi_Class value.
  6457. *
  6458. * Data is based on DerivedBidiClass.txt in UCD version 7.0.0.
  6459. *
  6460. * NOTE: For performance reasons, we only support Unicode's
  6461. * Basic Multilingual Plane (BMP) for now.
  6462. */
  6463. var RANGE_BY_BIDI_TYPE = {
  6464. 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',
  6465. 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',
  6466. 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'
  6467. };
  6468. var REGEX_STRONG = new RegExp('[' + RANGE_BY_BIDI_TYPE.L + RANGE_BY_BIDI_TYPE.R + RANGE_BY_BIDI_TYPE.AL + ']');
  6469. var REGEX_RTL = new RegExp('[' + RANGE_BY_BIDI_TYPE.R + RANGE_BY_BIDI_TYPE.AL + ']');
  6470. /**
  6471. * Returns the first strong character (has Bidi_Class value of L, R, or AL).
  6472. *
  6473. * @param str A text block; e.g. paragraph, table cell, tag
  6474. * @return A character with strong bidi direction, or null if not found
  6475. */
  6476. function firstStrongChar(str) {
  6477. var match = REGEX_STRONG.exec(str);
  6478. return match == null ? null : match[0];
  6479. }
  6480. /**
  6481. * Returns the direction of a block of text, based on the direction of its
  6482. * first strong character (has Bidi_Class value of L, R, or AL).
  6483. *
  6484. * @param str A text block; e.g. paragraph, table cell, tag
  6485. * @return The resolved direction
  6486. */
  6487. function firstStrongCharDir(str) {
  6488. var strongChar = firstStrongChar(str);
  6489. if (strongChar == null) {
  6490. return UnicodeBidiDirection_1.NEUTRAL;
  6491. }
  6492. return REGEX_RTL.exec(strongChar) ? UnicodeBidiDirection_1.RTL : UnicodeBidiDirection_1.LTR;
  6493. }
  6494. /**
  6495. * Returns the direction of a block of text, based on the direction of its
  6496. * first strong character (has Bidi_Class value of L, R, or AL), or a fallback
  6497. * direction, if no strong character is found.
  6498. *
  6499. * This function is supposed to be used in respect to Higher-Level Protocol
  6500. * rule HL1. (http://www.unicode.org/reports/tr9/#HL1)
  6501. *
  6502. * @param str A text block; e.g. paragraph, table cell, tag
  6503. * @param fallback Fallback direction, used if no strong direction detected
  6504. * for the block (default = NEUTRAL)
  6505. * @return The resolved direction
  6506. */
  6507. function resolveBlockDir(str, fallback) {
  6508. fallback = fallback || UnicodeBidiDirection_1.NEUTRAL;
  6509. if (!str.length) {
  6510. return fallback;
  6511. }
  6512. var blockDir = firstStrongCharDir(str);
  6513. return blockDir === UnicodeBidiDirection_1.NEUTRAL ? fallback : blockDir;
  6514. }
  6515. /**
  6516. * Returns the direction of a block of text, based on the direction of its
  6517. * first strong character (has Bidi_Class value of L, R, or AL), or a fallback
  6518. * direction, if no strong character is found.
  6519. *
  6520. * NOTE: This function is similar to resolveBlockDir(), but uses the global
  6521. * direction as the fallback, so it *always* returns a Strong direction,
  6522. * making it useful for integration in places that you need to make the final
  6523. * decision, like setting some CSS class.
  6524. *
  6525. * This function is supposed to be used in respect to Higher-Level Protocol
  6526. * rule HL1. (http://www.unicode.org/reports/tr9/#HL1)
  6527. *
  6528. * @param str A text block; e.g. paragraph, table cell
  6529. * @param strongFallback Fallback direction, used if no strong direction
  6530. * detected for the block (default = global direction)
  6531. * @return The resolved Strong direction
  6532. */
  6533. function getDirection(str, strongFallback) {
  6534. if (!strongFallback) {
  6535. strongFallback = UnicodeBidiDirection_1.getGlobalDir();
  6536. }
  6537. !UnicodeBidiDirection_1.isStrong(strongFallback) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Fallback direction must be a strong direction') : invariant_1(false) : void 0;
  6538. return resolveBlockDir(str, strongFallback);
  6539. }
  6540. /**
  6541. * Returns true if getDirection(arguments...) returns LTR.
  6542. *
  6543. * @param str A text block; e.g. paragraph, table cell
  6544. * @param strongFallback Fallback direction, used if no strong direction
  6545. * detected for the block (default = global direction)
  6546. * @return True if the resolved direction is LTR
  6547. */
  6548. function isDirectionLTR(str, strongFallback) {
  6549. return getDirection(str, strongFallback) === UnicodeBidiDirection_1.LTR;
  6550. }
  6551. /**
  6552. * Returns true if getDirection(arguments...) returns RTL.
  6553. *
  6554. * @param str A text block; e.g. paragraph, table cell
  6555. * @param strongFallback Fallback direction, used if no strong direction
  6556. * detected for the block (default = global direction)
  6557. * @return True if the resolved direction is RTL
  6558. */
  6559. function isDirectionRTL(str, strongFallback) {
  6560. return getDirection(str, strongFallback) === UnicodeBidiDirection_1.RTL;
  6561. }
  6562. var UnicodeBidi = {
  6563. firstStrongChar: firstStrongChar,
  6564. firstStrongCharDir: firstStrongCharDir,
  6565. resolveBlockDir: resolveBlockDir,
  6566. getDirection: getDirection,
  6567. isDirectionLTR: isDirectionLTR,
  6568. isDirectionRTL: isDirectionRTL
  6569. };
  6570. var UnicodeBidi_1 = UnicodeBidi;
  6571. function _classCallCheck$6(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6572. var UnicodeBidiService = function () {
  6573. /**
  6574. * Stateful class for paragraph direction detection
  6575. *
  6576. * @param defaultDir Default direction of the service
  6577. */
  6578. function UnicodeBidiService(defaultDir) {
  6579. _classCallCheck$6(this, UnicodeBidiService);
  6580. if (!defaultDir) {
  6581. defaultDir = UnicodeBidiDirection_1.getGlobalDir();
  6582. } else {
  6583. !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;
  6584. }
  6585. this._defaultDir = defaultDir;
  6586. this.reset();
  6587. }
  6588. /**
  6589. * Reset the internal state
  6590. *
  6591. * Instead of creating a new instance, you can just reset() your instance
  6592. * everytime you start a new loop.
  6593. */
  6594. UnicodeBidiService.prototype.reset = function reset() {
  6595. this._lastDir = this._defaultDir;
  6596. };
  6597. /**
  6598. * Returns the direction of a block of text, and remembers it as the
  6599. * fall-back direction for the next paragraph.
  6600. *
  6601. * @param str A text block, e.g. paragraph, table cell, tag
  6602. * @return The resolved direction
  6603. */
  6604. UnicodeBidiService.prototype.getDirection = function getDirection(str) {
  6605. this._lastDir = UnicodeBidi_1.getDirection(str, this._lastDir);
  6606. return this._lastDir;
  6607. };
  6608. return UnicodeBidiService;
  6609. }();
  6610. var UnicodeBidiService_1 = UnicodeBidiService;
  6611. /**
  6612. * Copyright (c) 2013-present, Facebook, Inc.
  6613. *
  6614. * This source code is licensed under the MIT license found in the
  6615. * LICENSE file in the root directory of this source tree.
  6616. *
  6617. *
  6618. */
  6619. var nullthrows = function nullthrows(x) {
  6620. if (x != null) {
  6621. return x;
  6622. }
  6623. throw new Error("Got unexpected null or undefined");
  6624. };
  6625. var nullthrows_1 = nullthrows;
  6626. var OrderedMap$2 = immutable.OrderedMap;
  6627. var bidiService;
  6628. var EditorBidiService = {
  6629. getDirectionMap: function getDirectionMap(content, prevBidiMap) {
  6630. if (!bidiService) {
  6631. bidiService = new UnicodeBidiService_1();
  6632. } else {
  6633. bidiService.reset();
  6634. }
  6635. var blockMap = content.getBlockMap();
  6636. var nextBidi = blockMap.valueSeq().map(function (block) {
  6637. return nullthrows_1(bidiService).getDirection(block.getText());
  6638. });
  6639. var bidiMap = OrderedMap$2(blockMap.keySeq().zip(nextBidi));
  6640. if (prevBidiMap != null && immutable.is(prevBidiMap, bidiMap)) {
  6641. return prevBidiMap;
  6642. }
  6643. return bidiMap;
  6644. }
  6645. };
  6646. var EditorBidiService_1 = EditorBidiService;
  6647. 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; };
  6648. function _classCallCheck$7(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6649. var OrderedSet$4 = immutable.OrderedSet,
  6650. Record$7 = immutable.Record,
  6651. Stack = immutable.Stack;
  6652. var defaultRecord$5 = {
  6653. allowUndo: true,
  6654. currentContent: null,
  6655. decorator: null,
  6656. directionMap: null,
  6657. forceSelection: false,
  6658. inCompositionMode: false,
  6659. inlineStyleOverride: null,
  6660. lastChangeType: null,
  6661. nativelyRenderedContent: null,
  6662. redoStack: Stack(),
  6663. selection: null,
  6664. treeMap: null,
  6665. undoStack: Stack()
  6666. };
  6667. var EditorStateRecord = Record$7(defaultRecord$5);
  6668. var EditorState = function () {
  6669. EditorState.createEmpty = function createEmpty(decorator) {
  6670. return EditorState.createWithContent(ContentState_1.createFromText(''), decorator);
  6671. };
  6672. EditorState.createWithContent = function createWithContent(contentState, decorator) {
  6673. var firstKey = contentState.getBlockMap().first().getKey();
  6674. return EditorState.create({
  6675. currentContent: contentState,
  6676. undoStack: Stack(),
  6677. redoStack: Stack(),
  6678. decorator: decorator || null,
  6679. selection: SelectionState_1.createEmpty(firstKey)
  6680. });
  6681. };
  6682. EditorState.create = function create(config) {
  6683. var currentContent = config.currentContent,
  6684. decorator = config.decorator;
  6685. var recordConfig = _extends$1({}, config, {
  6686. treeMap: generateNewTreeMap(currentContent, decorator),
  6687. directionMap: EditorBidiService_1.getDirectionMap(currentContent)
  6688. });
  6689. return new EditorState(new EditorStateRecord(recordConfig));
  6690. };
  6691. EditorState.set = function set(editorState, put) {
  6692. var map = editorState.getImmutable().withMutations(function (state) {
  6693. var existingDecorator = state.get('decorator');
  6694. var decorator = existingDecorator;
  6695. if (put.decorator === null) {
  6696. decorator = null;
  6697. } else if (put.decorator) {
  6698. decorator = put.decorator;
  6699. }
  6700. var newContent = put.currentContent || editorState.getCurrentContent();
  6701. if (decorator !== existingDecorator) {
  6702. var treeMap = state.get('treeMap');
  6703. var newTreeMap;
  6704. if (decorator && existingDecorator) {
  6705. newTreeMap = regenerateTreeForNewDecorator(newContent, newContent.getBlockMap(), treeMap, decorator, existingDecorator);
  6706. } else {
  6707. newTreeMap = generateNewTreeMap(newContent, decorator);
  6708. }
  6709. state.merge({
  6710. decorator: decorator,
  6711. treeMap: newTreeMap,
  6712. nativelyRenderedContent: null
  6713. });
  6714. return;
  6715. }
  6716. var existingContent = editorState.getCurrentContent();
  6717. if (newContent !== existingContent) {
  6718. state.set('treeMap', regenerateTreeForNewBlocks(editorState, newContent.getBlockMap(), newContent.getEntityMap(), decorator));
  6719. }
  6720. state.merge(put);
  6721. });
  6722. return new EditorState(map);
  6723. };
  6724. EditorState.prototype.toJS = function toJS() {
  6725. return this.getImmutable().toJS();
  6726. };
  6727. EditorState.prototype.getAllowUndo = function getAllowUndo() {
  6728. return this.getImmutable().get('allowUndo');
  6729. };
  6730. EditorState.prototype.getCurrentContent = function getCurrentContent() {
  6731. return this.getImmutable().get('currentContent');
  6732. };
  6733. EditorState.prototype.getUndoStack = function getUndoStack() {
  6734. return this.getImmutable().get('undoStack');
  6735. };
  6736. EditorState.prototype.getRedoStack = function getRedoStack() {
  6737. return this.getImmutable().get('redoStack');
  6738. };
  6739. EditorState.prototype.getSelection = function getSelection() {
  6740. return this.getImmutable().get('selection');
  6741. };
  6742. EditorState.prototype.getDecorator = function getDecorator() {
  6743. return this.getImmutable().get('decorator');
  6744. };
  6745. EditorState.prototype.isInCompositionMode = function isInCompositionMode() {
  6746. return this.getImmutable().get('inCompositionMode');
  6747. };
  6748. EditorState.prototype.mustForceSelection = function mustForceSelection() {
  6749. return this.getImmutable().get('forceSelection');
  6750. };
  6751. EditorState.prototype.getNativelyRenderedContent = function getNativelyRenderedContent() {
  6752. return this.getImmutable().get('nativelyRenderedContent');
  6753. };
  6754. EditorState.prototype.getLastChangeType = function getLastChangeType() {
  6755. return this.getImmutable().get('lastChangeType');
  6756. };
  6757. /**
  6758. * While editing, the user may apply inline style commands with a collapsed
  6759. * cursor, intending to type text that adopts the specified style. In this
  6760. * case, we track the specified style as an "override" that takes precedence
  6761. * over the inline style of the text adjacent to the cursor.
  6762. *
  6763. * If null, there is no override in place.
  6764. */
  6765. EditorState.prototype.getInlineStyleOverride = function getInlineStyleOverride() {
  6766. return this.getImmutable().get('inlineStyleOverride');
  6767. };
  6768. EditorState.setInlineStyleOverride = function setInlineStyleOverride(editorState, inlineStyleOverride) {
  6769. return EditorState.set(editorState, { inlineStyleOverride: inlineStyleOverride });
  6770. };
  6771. /**
  6772. * Get the appropriate inline style for the editor state. If an
  6773. * override is in place, use it. Otherwise, the current style is
  6774. * based on the location of the selection state.
  6775. */
  6776. EditorState.prototype.getCurrentInlineStyle = function getCurrentInlineStyle() {
  6777. var override = this.getInlineStyleOverride();
  6778. if (override != null) {
  6779. return override;
  6780. }
  6781. var content = this.getCurrentContent();
  6782. var selection = this.getSelection();
  6783. if (selection.isCollapsed()) {
  6784. return getInlineStyleForCollapsedSelection(content, selection);
  6785. }
  6786. return getInlineStyleForNonCollapsedSelection(content, selection);
  6787. };
  6788. EditorState.prototype.getBlockTree = function getBlockTree(blockKey) {
  6789. return this.getImmutable().getIn(['treeMap', blockKey]);
  6790. };
  6791. EditorState.prototype.isSelectionAtStartOfContent = function isSelectionAtStartOfContent() {
  6792. var firstKey = this.getCurrentContent().getBlockMap().first().getKey();
  6793. return this.getSelection().hasEdgeWithin(firstKey, 0, 0);
  6794. };
  6795. EditorState.prototype.isSelectionAtEndOfContent = function isSelectionAtEndOfContent() {
  6796. var content = this.getCurrentContent();
  6797. var blockMap = content.getBlockMap();
  6798. var last = blockMap.last();
  6799. var end = last.getLength();
  6800. return this.getSelection().hasEdgeWithin(last.getKey(), end, end);
  6801. };
  6802. EditorState.prototype.getDirectionMap = function getDirectionMap() {
  6803. return this.getImmutable().get('directionMap');
  6804. };
  6805. /**
  6806. * Incorporate native DOM selection changes into the EditorState. This
  6807. * method can be used when we simply want to accept whatever the DOM
  6808. * has given us to represent selection, and we do not need to re-render
  6809. * the editor.
  6810. *
  6811. * To forcibly move the DOM selection, see `EditorState.forceSelection`.
  6812. */
  6813. EditorState.acceptSelection = function acceptSelection(editorState, selection) {
  6814. return updateSelection(editorState, selection, false);
  6815. };
  6816. /**
  6817. * At times, we need to force the DOM selection to be where we
  6818. * need it to be. This can occur when the anchor or focus nodes
  6819. * are non-text nodes, for instance. In this case, we want to trigger
  6820. * a re-render of the editor, which in turn forces selection into
  6821. * the correct place in the DOM. The `forceSelection` method
  6822. * accomplishes this.
  6823. *
  6824. * This method should be used in cases where you need to explicitly
  6825. * move the DOM selection from one place to another without a change
  6826. * in ContentState.
  6827. */
  6828. EditorState.forceSelection = function forceSelection(editorState, selection) {
  6829. if (!selection.getHasFocus()) {
  6830. selection = selection.set('hasFocus', true);
  6831. }
  6832. return updateSelection(editorState, selection, true);
  6833. };
  6834. /**
  6835. * Move selection to the end of the editor without forcing focus.
  6836. */
  6837. EditorState.moveSelectionToEnd = function moveSelectionToEnd(editorState) {
  6838. var content = editorState.getCurrentContent();
  6839. var lastBlock = content.getLastBlock();
  6840. var lastKey = lastBlock.getKey();
  6841. var length = lastBlock.getLength();
  6842. return EditorState.acceptSelection(editorState, new SelectionState_1({
  6843. anchorKey: lastKey,
  6844. anchorOffset: length,
  6845. focusKey: lastKey,
  6846. focusOffset: length,
  6847. isBackward: false
  6848. }));
  6849. };
  6850. /**
  6851. * Force focus to the end of the editor. This is useful in scenarios
  6852. * where we want to programmatically focus the input and it makes sense
  6853. * to allow the user to continue working seamlessly.
  6854. */
  6855. EditorState.moveFocusToEnd = function moveFocusToEnd(editorState) {
  6856. var afterSelectionMove = EditorState.moveSelectionToEnd(editorState);
  6857. return EditorState.forceSelection(afterSelectionMove, afterSelectionMove.getSelection());
  6858. };
  6859. /**
  6860. * Push the current ContentState onto the undo stack if it should be
  6861. * considered a boundary state, and set the provided ContentState as the
  6862. * new current content.
  6863. */
  6864. EditorState.push = function push(editorState, contentState, changeType) {
  6865. if (editorState.getCurrentContent() === contentState) {
  6866. return editorState;
  6867. }
  6868. var forceSelection = changeType !== 'insert-characters';
  6869. var directionMap = EditorBidiService_1.getDirectionMap(contentState, editorState.getDirectionMap());
  6870. if (!editorState.getAllowUndo()) {
  6871. return EditorState.set(editorState, {
  6872. currentContent: contentState,
  6873. directionMap: directionMap,
  6874. lastChangeType: changeType,
  6875. selection: contentState.getSelectionAfter(),
  6876. forceSelection: forceSelection,
  6877. inlineStyleOverride: null
  6878. });
  6879. }
  6880. var selection = editorState.getSelection();
  6881. var currentContent = editorState.getCurrentContent();
  6882. var undoStack = editorState.getUndoStack();
  6883. var newContent = contentState;
  6884. if (selection !== currentContent.getSelectionAfter() || mustBecomeBoundary(editorState, changeType)) {
  6885. undoStack = undoStack.push(currentContent);
  6886. newContent = newContent.set('selectionBefore', selection);
  6887. } else if (changeType === 'insert-characters' || changeType === 'backspace-character' || changeType === 'delete-character') {
  6888. // Preserve the previous selection.
  6889. newContent = newContent.set('selectionBefore', currentContent.getSelectionBefore());
  6890. }
  6891. var inlineStyleOverride = editorState.getInlineStyleOverride();
  6892. // Don't discard inline style overrides for the following change types:
  6893. var overrideChangeTypes = ['adjust-depth', 'change-block-type', 'split-block'];
  6894. if (overrideChangeTypes.indexOf(changeType) === -1) {
  6895. inlineStyleOverride = null;
  6896. }
  6897. var editorStateChanges = {
  6898. currentContent: newContent,
  6899. directionMap: directionMap,
  6900. undoStack: undoStack,
  6901. redoStack: Stack(),
  6902. lastChangeType: changeType,
  6903. selection: contentState.getSelectionAfter(),
  6904. forceSelection: forceSelection,
  6905. inlineStyleOverride: inlineStyleOverride
  6906. };
  6907. return EditorState.set(editorState, editorStateChanges);
  6908. };
  6909. /**
  6910. * Make the top ContentState in the undo stack the new current content and
  6911. * push the current content onto the redo stack.
  6912. */
  6913. EditorState.undo = function undo(editorState) {
  6914. if (!editorState.getAllowUndo()) {
  6915. return editorState;
  6916. }
  6917. var undoStack = editorState.getUndoStack();
  6918. var newCurrentContent = undoStack.peek();
  6919. if (!newCurrentContent) {
  6920. return editorState;
  6921. }
  6922. var currentContent = editorState.getCurrentContent();
  6923. var directionMap = EditorBidiService_1.getDirectionMap(newCurrentContent, editorState.getDirectionMap());
  6924. return EditorState.set(editorState, {
  6925. currentContent: newCurrentContent,
  6926. directionMap: directionMap,
  6927. undoStack: undoStack.shift(),
  6928. redoStack: editorState.getRedoStack().push(currentContent),
  6929. forceSelection: true,
  6930. inlineStyleOverride: null,
  6931. lastChangeType: 'undo',
  6932. nativelyRenderedContent: null,
  6933. selection: currentContent.getSelectionBefore()
  6934. });
  6935. };
  6936. /**
  6937. * Make the top ContentState in the redo stack the new current content and
  6938. * push the current content onto the undo stack.
  6939. */
  6940. EditorState.redo = function redo(editorState) {
  6941. if (!editorState.getAllowUndo()) {
  6942. return editorState;
  6943. }
  6944. var redoStack = editorState.getRedoStack();
  6945. var newCurrentContent = redoStack.peek();
  6946. if (!newCurrentContent) {
  6947. return editorState;
  6948. }
  6949. var currentContent = editorState.getCurrentContent();
  6950. var directionMap = EditorBidiService_1.getDirectionMap(newCurrentContent, editorState.getDirectionMap());
  6951. return EditorState.set(editorState, {
  6952. currentContent: newCurrentContent,
  6953. directionMap: directionMap,
  6954. undoStack: editorState.getUndoStack().push(currentContent),
  6955. redoStack: redoStack.shift(),
  6956. forceSelection: true,
  6957. inlineStyleOverride: null,
  6958. lastChangeType: 'redo',
  6959. nativelyRenderedContent: null,
  6960. selection: newCurrentContent.getSelectionAfter()
  6961. });
  6962. };
  6963. /**
  6964. * Not for public consumption.
  6965. */
  6966. function EditorState(immutable) {
  6967. _classCallCheck$7(this, EditorState);
  6968. this._immutable = immutable;
  6969. }
  6970. /**
  6971. * Not for public consumption.
  6972. */
  6973. EditorState.prototype.getImmutable = function getImmutable() {
  6974. return this._immutable;
  6975. };
  6976. return EditorState;
  6977. }();
  6978. /**
  6979. * Set the supplied SelectionState as the new current selection, and set
  6980. * the `force` flag to trigger manual selection placement by the view.
  6981. */
  6982. function updateSelection(editorState, selection, forceSelection) {
  6983. return EditorState.set(editorState, {
  6984. selection: selection,
  6985. forceSelection: forceSelection,
  6986. nativelyRenderedContent: null,
  6987. inlineStyleOverride: null
  6988. });
  6989. }
  6990. /**
  6991. * Regenerate the entire tree map for a given ContentState and decorator.
  6992. * Returns an OrderedMap that maps all available ContentBlock objects.
  6993. */
  6994. function generateNewTreeMap(contentState, decorator) {
  6995. return contentState.getBlockMap().map(function (block) {
  6996. return BlockTree_1.generate(contentState, block, decorator);
  6997. }).toOrderedMap();
  6998. }
  6999. /**
  7000. * Regenerate tree map objects for all ContentBlocks that have changed
  7001. * between the current editorState and newContent. Returns an OrderedMap
  7002. * with only changed regenerated tree map objects.
  7003. */
  7004. function regenerateTreeForNewBlocks(editorState, newBlockMap, newEntityMap, decorator) {
  7005. var contentState = editorState.getCurrentContent().set('entityMap', newEntityMap);
  7006. var prevBlockMap = contentState.getBlockMap();
  7007. var prevTreeMap = editorState.getImmutable().get('treeMap');
  7008. return prevTreeMap.merge(newBlockMap.toSeq().filter(function (block, key) {
  7009. return block !== prevBlockMap.get(key);
  7010. }).map(function (block) {
  7011. return BlockTree_1.generate(contentState, block, decorator);
  7012. }));
  7013. }
  7014. /**
  7015. * Generate tree map objects for a new decorator object, preserving any
  7016. * decorations that are unchanged from the previous decorator.
  7017. *
  7018. * Note that in order for this to perform optimally, decoration Lists for
  7019. * decorators should be preserved when possible to allow for direct immutable
  7020. * List comparison.
  7021. */
  7022. function regenerateTreeForNewDecorator(content, blockMap, previousTreeMap, decorator, existingDecorator) {
  7023. return previousTreeMap.merge(blockMap.toSeq().filter(function (block) {
  7024. return decorator.getDecorations(block, content) !== existingDecorator.getDecorations(block, content);
  7025. }).map(function (block) {
  7026. return BlockTree_1.generate(content, block, decorator);
  7027. }));
  7028. }
  7029. /**
  7030. * Return whether a change should be considered a boundary state, given
  7031. * the previous change type. Allows us to discard potential boundary states
  7032. * during standard typing or deletion behavior.
  7033. */
  7034. function mustBecomeBoundary(editorState, changeType) {
  7035. var lastChangeType = editorState.getLastChangeType();
  7036. return changeType !== lastChangeType || changeType !== 'insert-characters' && changeType !== 'backspace-character' && changeType !== 'delete-character';
  7037. }
  7038. function getInlineStyleForCollapsedSelection(content, selection) {
  7039. var startKey = selection.getStartKey();
  7040. var startOffset = selection.getStartOffset();
  7041. var startBlock = content.getBlockForKey(startKey);
  7042. // If the cursor is not at the start of the block, look backward to
  7043. // preserve the style of the preceding character.
  7044. if (startOffset > 0) {
  7045. return startBlock.getInlineStyleAt(startOffset - 1);
  7046. }
  7047. // The caret is at position zero in this block. If the block has any
  7048. // text at all, use the style of the first character.
  7049. if (startBlock.getLength()) {
  7050. return startBlock.getInlineStyleAt(0);
  7051. }
  7052. // Otherwise, look upward in the document to find the closest character.
  7053. return lookUpwardForInlineStyle(content, startKey);
  7054. }
  7055. function getInlineStyleForNonCollapsedSelection(content, selection) {
  7056. var startKey = selection.getStartKey();
  7057. var startOffset = selection.getStartOffset();
  7058. var startBlock = content.getBlockForKey(startKey);
  7059. // If there is a character just inside the selection, use its style.
  7060. if (startOffset < startBlock.getLength()) {
  7061. return startBlock.getInlineStyleAt(startOffset);
  7062. }
  7063. // Check if the selection at the end of a non-empty block. Use the last
  7064. // style in the block.
  7065. if (startOffset > 0) {
  7066. return startBlock.getInlineStyleAt(startOffset - 1);
  7067. }
  7068. // Otherwise, look upward in the document to find the closest character.
  7069. return lookUpwardForInlineStyle(content, startKey);
  7070. }
  7071. function lookUpwardForInlineStyle(content, fromKey) {
  7072. var lastNonEmpty = content.getBlockMap().reverse().skipUntil(function (_, k) {
  7073. return k === fromKey;
  7074. }).skip(1).skipUntil(function (block, _) {
  7075. return block.getLength();
  7076. }).first();
  7077. if (lastNonEmpty) return lastNonEmpty.getInlineStyleAt(lastNonEmpty.getLength() - 1);
  7078. return OrderedSet$4();
  7079. }
  7080. var EditorState_1 = EditorState;
  7081. var OrderedMap$3 = immutable.OrderedMap,
  7082. List$7 = immutable.List;
  7083. var transformBlock$2 = function transformBlock(key, blockMap, func) {
  7084. if (!key) {
  7085. return;
  7086. }
  7087. var block = blockMap.get(key);
  7088. if (!block) {
  7089. return;
  7090. }
  7091. blockMap.set(key, func(block));
  7092. };
  7093. var updateBlockMapLinks$3 = function updateBlockMapLinks(blockMap, originalBlockToBeMoved, originalTargetBlock, insertionMode, isExperimentalTreeBlock) {
  7094. if (!isExperimentalTreeBlock) {
  7095. return blockMap;
  7096. }
  7097. // possible values of 'insertionMode' are: 'after', 'before'
  7098. var isInsertedAfterTarget = insertionMode === 'after';
  7099. var originalBlockKey = originalBlockToBeMoved.getKey();
  7100. var originalTargetKey = originalTargetBlock.getKey();
  7101. var originalParentKey = originalBlockToBeMoved.getParentKey();
  7102. var originalNextSiblingKey = originalBlockToBeMoved.getNextSiblingKey();
  7103. var originalPrevSiblingKey = originalBlockToBeMoved.getPrevSiblingKey();
  7104. var newParentKey = originalTargetBlock.getParentKey();
  7105. var newNextSiblingKey = isInsertedAfterTarget ? originalTargetBlock.getNextSiblingKey() : originalTargetKey;
  7106. var newPrevSiblingKey = isInsertedAfterTarget ? originalTargetKey : originalTargetBlock.getPrevSiblingKey();
  7107. return blockMap.withMutations(function (blocks) {
  7108. // update old parent
  7109. transformBlock$2(originalParentKey, blocks, function (block) {
  7110. var parentChildrenList = block.getChildKeys();
  7111. return block.merge({
  7112. children: parentChildrenList['delete'](parentChildrenList.indexOf(originalBlockKey))
  7113. });
  7114. });
  7115. // update old prev
  7116. transformBlock$2(originalPrevSiblingKey, blocks, function (block) {
  7117. return block.merge({
  7118. nextSibling: originalNextSiblingKey
  7119. });
  7120. });
  7121. // update old next
  7122. transformBlock$2(originalNextSiblingKey, blocks, function (block) {
  7123. return block.merge({
  7124. prevSibling: originalPrevSiblingKey
  7125. });
  7126. });
  7127. // update new next
  7128. transformBlock$2(newNextSiblingKey, blocks, function (block) {
  7129. return block.merge({
  7130. prevSibling: originalBlockKey
  7131. });
  7132. });
  7133. // update new prev
  7134. transformBlock$2(newPrevSiblingKey, blocks, function (block) {
  7135. return block.merge({
  7136. nextSibling: originalBlockKey
  7137. });
  7138. });
  7139. // update new parent
  7140. transformBlock$2(newParentKey, blocks, function (block) {
  7141. var newParentChildrenList = block.getChildKeys();
  7142. var targetBlockIndex = newParentChildrenList.indexOf(originalTargetKey);
  7143. var insertionIndex = isInsertedAfterTarget ? targetBlockIndex + 1 : targetBlockIndex !== 0 ? targetBlockIndex - 1 : 0;
  7144. var newChildrenArray = newParentChildrenList.toArray();
  7145. newChildrenArray.splice(insertionIndex, 0, originalBlockKey);
  7146. return block.merge({
  7147. children: List$7(newChildrenArray)
  7148. });
  7149. });
  7150. // update block
  7151. transformBlock$2(originalBlockKey, blocks, function (block) {
  7152. return block.merge({
  7153. nextSibling: newNextSiblingKey,
  7154. prevSibling: newPrevSiblingKey,
  7155. parent: newParentKey
  7156. });
  7157. });
  7158. });
  7159. };
  7160. var moveBlockInContentState = function moveBlockInContentState(contentState, blockToBeMoved, targetBlock, insertionMode) {
  7161. !(insertionMode !== 'replace') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Replacing blocks is not supported.') : invariant_1(false) : void 0;
  7162. var targetKey = targetBlock.getKey();
  7163. var blockKey = blockToBeMoved.getKey();
  7164. !(blockKey !== targetKey) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Block cannot be moved next to itself.') : invariant_1(false) : void 0;
  7165. var blockMap = contentState.getBlockMap();
  7166. var isExperimentalTreeBlock = blockToBeMoved instanceof ContentBlockNode_1;
  7167. var blocksToBeMoved = [blockToBeMoved];
  7168. var blockMapWithoutBlocksToBeMoved = blockMap['delete'](blockKey);
  7169. if (isExperimentalTreeBlock) {
  7170. blocksToBeMoved = [];
  7171. blockMapWithoutBlocksToBeMoved = blockMap.withMutations(function (blocks) {
  7172. var nextSiblingKey = blockToBeMoved.getNextSiblingKey();
  7173. var nextDelimiterBlockKey = getNextDelimiterBlockKey_1(blockToBeMoved, blocks);
  7174. blocks.toSeq().skipUntil(function (block) {
  7175. return block.getKey() === blockKey;
  7176. }).takeWhile(function (block) {
  7177. var key = block.getKey();
  7178. var isBlockToBeMoved = key === blockKey;
  7179. var hasNextSiblingAndIsNotNextSibling = nextSiblingKey && key !== nextSiblingKey;
  7180. var doesNotHaveNextSiblingAndIsNotDelimiter = !nextSiblingKey && block.getParentKey() && (!nextDelimiterBlockKey || key !== nextDelimiterBlockKey);
  7181. return !!(isBlockToBeMoved || hasNextSiblingAndIsNotNextSibling || doesNotHaveNextSiblingAndIsNotDelimiter);
  7182. }).forEach(function (block) {
  7183. blocksToBeMoved.push(block);
  7184. blocks['delete'](block.getKey());
  7185. });
  7186. });
  7187. }
  7188. var blocksBefore = blockMapWithoutBlocksToBeMoved.toSeq().takeUntil(function (v) {
  7189. return v === targetBlock;
  7190. });
  7191. var blocksAfter = blockMapWithoutBlocksToBeMoved.toSeq().skipUntil(function (v) {
  7192. return v === targetBlock;
  7193. }).skip(1);
  7194. var slicedBlocks = blocksToBeMoved.map(function (block) {
  7195. return [block.getKey(), block];
  7196. });
  7197. var newBlocks = OrderedMap$3();
  7198. if (insertionMode === 'before') {
  7199. var blockBefore = contentState.getBlockBefore(targetKey);
  7200. !(!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;
  7201. newBlocks = blocksBefore.concat([].concat(slicedBlocks, [[targetKey, targetBlock]]), blocksAfter).toOrderedMap();
  7202. } else if (insertionMode === 'after') {
  7203. var blockAfter = contentState.getBlockAfter(targetKey);
  7204. !(!blockAfter || blockAfter.getKey() !== blockKey) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Block cannot be moved next to itself.') : invariant_1(false) : void 0;
  7205. newBlocks = blocksBefore.concat([[targetKey, targetBlock]].concat(slicedBlocks), blocksAfter).toOrderedMap();
  7206. }
  7207. return contentState.merge({
  7208. blockMap: updateBlockMapLinks$3(newBlocks, blockToBeMoved, targetBlock, insertionMode, isExperimentalTreeBlock),
  7209. selectionBefore: contentState.getSelectionAfter(),
  7210. selectionAfter: contentState.getSelectionAfter().merge({
  7211. anchorKey: blockKey,
  7212. focusKey: blockKey
  7213. })
  7214. });
  7215. };
  7216. var moveBlockInContentState_1 = moveBlockInContentState;
  7217. var ContentBlockRecord$1 = ContentBlock_1;
  7218. var List$8 = immutable.List,
  7219. Repeat$5 = immutable.Repeat;
  7220. var AtomicBlockUtils = {
  7221. insertAtomicBlock: function insertAtomicBlock(editorState, entityKey, character) {
  7222. var contentState = editorState.getCurrentContent();
  7223. var selectionState = editorState.getSelection();
  7224. var afterRemoval = DraftModifier_1.removeRange(contentState, selectionState, 'backward');
  7225. var targetSelection = afterRemoval.getSelectionAfter();
  7226. var afterSplit = DraftModifier_1.splitBlock(afterRemoval, targetSelection);
  7227. var insertionTarget = afterSplit.getSelectionAfter();
  7228. var asAtomicBlock = DraftModifier_1.setBlockType(afterSplit, insertionTarget, 'atomic');
  7229. var charData = CharacterMetadata_1.create({ entity: entityKey });
  7230. var atomicBlockConfig = {
  7231. key: generateRandomKey_1(),
  7232. type: 'atomic',
  7233. text: character,
  7234. characterList: List$8(Repeat$5(charData, character.length))
  7235. };
  7236. var atomicDividerBlockConfig = {
  7237. key: generateRandomKey_1(),
  7238. type: 'unstyled'
  7239. };
  7240. var fragmentArray = [new ContentBlockRecord$1(atomicBlockConfig), new ContentBlockRecord$1(atomicDividerBlockConfig)];
  7241. var fragment = BlockMapBuilder_1.createFromArray(fragmentArray);
  7242. var withAtomicBlock = DraftModifier_1.replaceWithFragment(asAtomicBlock, insertionTarget, fragment);
  7243. var newContent = withAtomicBlock.merge({
  7244. selectionBefore: selectionState,
  7245. selectionAfter: withAtomicBlock.getSelectionAfter().set('hasFocus', true)
  7246. });
  7247. return EditorState_1.push(editorState, newContent, 'insert-fragment');
  7248. },
  7249. moveAtomicBlock: function moveAtomicBlock(editorState, atomicBlock, targetRange, insertionMode) {
  7250. var contentState = editorState.getCurrentContent();
  7251. var selectionState = editorState.getSelection();
  7252. var withMovedAtomicBlock = void 0;
  7253. if (insertionMode === 'before' || insertionMode === 'after') {
  7254. var targetBlock = contentState.getBlockForKey(insertionMode === 'before' ? targetRange.getStartKey() : targetRange.getEndKey());
  7255. withMovedAtomicBlock = moveBlockInContentState_1(contentState, atomicBlock, targetBlock, insertionMode);
  7256. } else {
  7257. var afterRemoval = DraftModifier_1.removeRange(contentState, targetRange, 'backward');
  7258. var selectionAfterRemoval = afterRemoval.getSelectionAfter();
  7259. var _targetBlock = afterRemoval.getBlockForKey(selectionAfterRemoval.getFocusKey());
  7260. if (selectionAfterRemoval.getStartOffset() === 0) {
  7261. withMovedAtomicBlock = moveBlockInContentState_1(afterRemoval, atomicBlock, _targetBlock, 'before');
  7262. } else if (selectionAfterRemoval.getEndOffset() === _targetBlock.getLength()) {
  7263. withMovedAtomicBlock = moveBlockInContentState_1(afterRemoval, atomicBlock, _targetBlock, 'after');
  7264. } else {
  7265. var afterSplit = DraftModifier_1.splitBlock(afterRemoval, selectionAfterRemoval);
  7266. var selectionAfterSplit = afterSplit.getSelectionAfter();
  7267. var _targetBlock2 = afterSplit.getBlockForKey(selectionAfterSplit.getFocusKey());
  7268. withMovedAtomicBlock = moveBlockInContentState_1(afterSplit, atomicBlock, _targetBlock2, 'before');
  7269. }
  7270. }
  7271. var newContent = withMovedAtomicBlock.merge({
  7272. selectionBefore: selectionState,
  7273. selectionAfter: withMovedAtomicBlock.getSelectionAfter().set('hasFocus', true)
  7274. });
  7275. return EditorState_1.push(editorState, newContent, 'move-block');
  7276. }
  7277. };
  7278. var AtomicBlockUtils_1 = AtomicBlockUtils;
  7279. function _classCallCheck$8(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7280. var List$9 = immutable.List;
  7281. var DELIMITER = '.';
  7282. /**
  7283. * A CompositeDraftDecorator traverses through a list of DraftDecorator
  7284. * instances to identify sections of a ContentBlock that should be rendered
  7285. * in a "decorated" manner. For example, hashtags, mentions, and links may
  7286. * be intended to stand out visually, be rendered as anchors, etc.
  7287. *
  7288. * The list of decorators supplied to the constructor will be used in the
  7289. * order they are provided. This allows the caller to specify a priority for
  7290. * string matching, in case of match collisions among decorators.
  7291. *
  7292. * For instance, I may have a link with a `#` in its text. Though this section
  7293. * of text may match our hashtag decorator, it should not be treated as a
  7294. * hashtag. I should therefore list my link DraftDecorator
  7295. * before my hashtag DraftDecorator when constructing this composite
  7296. * decorator instance.
  7297. *
  7298. * Thus, when a collision like this is encountered, the earlier match is
  7299. * preserved and the new match is discarded.
  7300. */
  7301. var CompositeDraftDecorator = function () {
  7302. function CompositeDraftDecorator(decorators) {
  7303. _classCallCheck$8(this, CompositeDraftDecorator);
  7304. // Copy the decorator array, since we use this array order to determine
  7305. // precedence of decoration matching. If the array is mutated externally,
  7306. // we don't want to be affected here.
  7307. this._decorators = decorators.slice();
  7308. }
  7309. CompositeDraftDecorator.prototype.getDecorations = function getDecorations(block, contentState) {
  7310. var decorations = Array(block.getText().length).fill(null);
  7311. this._decorators.forEach(function ( /*object*/decorator, /*number*/ii) {
  7312. var counter = 0;
  7313. var strategy = decorator.strategy;
  7314. var callback = function callback( /*number*/start, /*number*/end) {
  7315. // Find out if any of our matching range is already occupied
  7316. // by another decorator. If so, discard the match. Otherwise, store
  7317. // the component key for rendering.
  7318. if (canOccupySlice(decorations, start, end)) {
  7319. occupySlice(decorations, start, end, ii + DELIMITER + counter);
  7320. counter++;
  7321. }
  7322. };
  7323. strategy(block, callback, contentState);
  7324. });
  7325. return List$9(decorations);
  7326. };
  7327. CompositeDraftDecorator.prototype.getComponentForKey = function getComponentForKey(key) {
  7328. var componentKey = parseInt(key.split(DELIMITER)[0], 10);
  7329. return this._decorators[componentKey].component;
  7330. };
  7331. CompositeDraftDecorator.prototype.getPropsForKey = function getPropsForKey(key) {
  7332. var componentKey = parseInt(key.split(DELIMITER)[0], 10);
  7333. return this._decorators[componentKey].props;
  7334. };
  7335. return CompositeDraftDecorator;
  7336. }();
  7337. /**
  7338. * Determine whether we can occupy the specified slice of the decorations
  7339. * array.
  7340. */
  7341. function canOccupySlice(decorations, start, end) {
  7342. for (var ii = start; ii < end; ii++) {
  7343. if (decorations[ii] != null) {
  7344. return false;
  7345. }
  7346. }
  7347. return true;
  7348. }
  7349. /**
  7350. * Splice the specified component into our decoration array at the desired
  7351. * range.
  7352. */
  7353. function occupySlice(targetArr, start, end, componentKey) {
  7354. for (var ii = start; ii < end; ii++) {
  7355. targetArr[ii] = componentKey;
  7356. }
  7357. }
  7358. var CompositeDraftDecorator_1 = CompositeDraftDecorator;
  7359. /**
  7360. * Copyright (c) 2013-present, Facebook, Inc.
  7361. *
  7362. * This source code is licensed under the MIT license found in the
  7363. * LICENSE file in the root directory of this source tree.
  7364. *
  7365. */
  7366. /**
  7367. * This function is used to mark string literals representing CSS class names
  7368. * so that they can be transformed statically. This allows for modularization
  7369. * and minification of CSS class names.
  7370. *
  7371. * In static_upstream, this function is actually implemented, but it should
  7372. * eventually be replaced with something more descriptive, and the transform
  7373. * that is used in the main stack should be ported for use elsewhere.
  7374. *
  7375. * @param string|object className to modularize, or an object of key/values.
  7376. * In the object case, the values are conditions that
  7377. * determine if the className keys should be included.
  7378. * @param [string ...] Variable list of classNames in the string case.
  7379. * @return string Renderable space-separated CSS className.
  7380. */
  7381. function cx(classNames) {
  7382. if (typeof classNames == 'object') {
  7383. return Object.keys(classNames).filter(function (className) {
  7384. return classNames[className];
  7385. }).map(replace).join(' ');
  7386. }
  7387. return Array.prototype.map.call(arguments, replace).join(' ');
  7388. }
  7389. function replace(str) {
  7390. return str.replace(/\//g, '-');
  7391. }
  7392. var cx_1 = cx;
  7393. var Map$9 = immutable.Map;
  7394. var UL_WRAP = React__default.createElement('ul', { className: cx_1('public/DraftStyleDefault/ul') });
  7395. var OL_WRAP = React__default.createElement('ol', { className: cx_1('public/DraftStyleDefault/ol') });
  7396. var PRE_WRAP = React__default.createElement('pre', { className: cx_1('public/DraftStyleDefault/pre') });
  7397. var DefaultDraftBlockRenderMap = Map$9({
  7398. 'header-one': {
  7399. element: 'h1'
  7400. },
  7401. 'header-two': {
  7402. element: 'h2'
  7403. },
  7404. 'header-three': {
  7405. element: 'h3'
  7406. },
  7407. 'header-four': {
  7408. element: 'h4'
  7409. },
  7410. 'header-five': {
  7411. element: 'h5'
  7412. },
  7413. 'header-six': {
  7414. element: 'h6'
  7415. },
  7416. 'unordered-list-item': {
  7417. element: 'li',
  7418. wrapper: UL_WRAP
  7419. },
  7420. 'ordered-list-item': {
  7421. element: 'li',
  7422. wrapper: OL_WRAP
  7423. },
  7424. blockquote: {
  7425. element: 'blockquote'
  7426. },
  7427. atomic: {
  7428. element: 'figure'
  7429. },
  7430. 'code-block': {
  7431. element: 'pre',
  7432. wrapper: PRE_WRAP
  7433. },
  7434. unstyled: {
  7435. element: 'div',
  7436. aliasedElements: ['p']
  7437. }
  7438. });
  7439. var DefaultDraftBlockRenderMap_1 = DefaultDraftBlockRenderMap;
  7440. /**
  7441. * Copyright (c) 2013-present, Facebook, Inc.
  7442. * All rights reserved.
  7443. *
  7444. * This source code is licensed under the BSD-style license found in the
  7445. * LICENSE file in the root directory of this source tree. An additional grant
  7446. * of patent rights can be found in the PATENTS file in the same directory.
  7447. *
  7448. * @providesModule DefaultDraftInlineStyle
  7449. * @format
  7450. *
  7451. */
  7452. var DefaultDraftInlineStyle = {
  7453. BOLD: {
  7454. fontWeight: 'bold'
  7455. },
  7456. CODE: {
  7457. fontFamily: 'monospace',
  7458. wordWrap: 'break-word'
  7459. },
  7460. ITALIC: {
  7461. fontStyle: 'italic'
  7462. },
  7463. STRIKETHROUGH: {
  7464. textDecoration: 'line-through'
  7465. },
  7466. UNDERLINE: {
  7467. textDecoration: 'underline'
  7468. }
  7469. };
  7470. /**
  7471. * Copyright (c) 2013-present, Facebook, Inc.
  7472. *
  7473. * This source code is licensed under the MIT license found in the
  7474. * LICENSE file in the root directory of this source tree.
  7475. *
  7476. */
  7477. var Keys = {
  7478. BACKSPACE: 8,
  7479. TAB: 9,
  7480. RETURN: 13,
  7481. ALT: 18,
  7482. ESC: 27,
  7483. SPACE: 32,
  7484. PAGE_UP: 33,
  7485. PAGE_DOWN: 34,
  7486. END: 35,
  7487. HOME: 36,
  7488. LEFT: 37,
  7489. UP: 38,
  7490. RIGHT: 39,
  7491. DOWN: 40,
  7492. DELETE: 46,
  7493. COMMA: 188,
  7494. PERIOD: 190,
  7495. A: 65,
  7496. Z: 90,
  7497. ZERO: 48,
  7498. NUMPAD_0: 96,
  7499. NUMPAD_9: 105
  7500. };
  7501. /**
  7502. * Copyright (c) 2013-present, Facebook, Inc.
  7503. * All rights reserved.
  7504. *
  7505. * This source code is licensed under the BSD-style license found in the
  7506. * LICENSE file in the root directory of this source tree. An additional grant
  7507. * of patent rights can be found in the PATENTS file in the same directory.
  7508. *
  7509. * @providesModule getEntityKeyForSelection
  7510. * @format
  7511. *
  7512. */
  7513. /**
  7514. * Return the entity key that should be used when inserting text for the
  7515. * specified target selection, only if the entity is `MUTABLE`. `IMMUTABLE`
  7516. * and `SEGMENTED` entities should not be used for insertion behavior.
  7517. */
  7518. function getEntityKeyForSelection(contentState, targetSelection) {
  7519. var entityKey;
  7520. if (targetSelection.isCollapsed()) {
  7521. var key = targetSelection.getAnchorKey();
  7522. var offset = targetSelection.getAnchorOffset();
  7523. if (offset > 0) {
  7524. entityKey = contentState.getBlockForKey(key).getEntityAt(offset - 1);
  7525. if (entityKey !== contentState.getBlockForKey(key).getEntityAt(offset)) {
  7526. return null;
  7527. }
  7528. return filterKey(contentState.getEntityMap(), entityKey);
  7529. }
  7530. return null;
  7531. }
  7532. var startKey = targetSelection.getStartKey();
  7533. var startOffset = targetSelection.getStartOffset();
  7534. var startBlock = contentState.getBlockForKey(startKey);
  7535. entityKey = startOffset === startBlock.getLength() ? null : startBlock.getEntityAt(startOffset);
  7536. return filterKey(contentState.getEntityMap(), entityKey);
  7537. }
  7538. /**
  7539. * Determine whether an entity key corresponds to a `MUTABLE` entity. If so,
  7540. * return it. If not, return null.
  7541. */
  7542. function filterKey(entityMap, entityKey) {
  7543. if (entityKey) {
  7544. var entity = entityMap.__get(entityKey);
  7545. return entity.getMutability() === 'MUTABLE' ? entityKey : null;
  7546. }
  7547. return null;
  7548. }
  7549. var getEntityKeyForSelection_1 = getEntityKeyForSelection;
  7550. /**
  7551. * Copyright (c) 2013-present, Facebook, Inc.
  7552. * All rights reserved.
  7553. *
  7554. * This source code is licensed under the BSD-style license found in the
  7555. * LICENSE file in the root directory of this source tree. An additional grant
  7556. * of patent rights can be found in the PATENTS file in the same directory.
  7557. *
  7558. * @providesModule isEventHandled
  7559. * @format
  7560. *
  7561. */
  7562. /**
  7563. * Utility method for determining whether or not the value returned
  7564. * from a handler indicates that it was handled.
  7565. */
  7566. function isEventHandled(value) {
  7567. return value === 'handled' || value === true;
  7568. }
  7569. var isEventHandled_1 = isEventHandled;
  7570. /**
  7571. * Copyright (c) 2013-present, Facebook, Inc.
  7572. * All rights reserved.
  7573. *
  7574. * This source code is licensed under the BSD-style license found in the
  7575. * LICENSE file in the root directory of this source tree. An additional grant
  7576. * of patent rights can be found in the PATENTS file in the same directory.
  7577. *
  7578. * @providesModule isSelectionAtLeafStart
  7579. * @format
  7580. *
  7581. */
  7582. function isSelectionAtLeafStart(editorState) {
  7583. var selection = editorState.getSelection();
  7584. var anchorKey = selection.getAnchorKey();
  7585. var blockTree = editorState.getBlockTree(anchorKey);
  7586. var offset = selection.getStartOffset();
  7587. var isAtStart = false;
  7588. blockTree.some(function (leafSet) {
  7589. if (offset === leafSet.get('start')) {
  7590. isAtStart = true;
  7591. return true;
  7592. }
  7593. if (offset < leafSet.get('end')) {
  7594. return leafSet.get('leaves').some(function (leaf) {
  7595. var leafStart = leaf.get('start');
  7596. if (offset === leafStart) {
  7597. isAtStart = true;
  7598. return true;
  7599. }
  7600. return false;
  7601. });
  7602. }
  7603. return false;
  7604. });
  7605. return isAtStart;
  7606. }
  7607. var isSelectionAtLeafStart_1 = isSelectionAtLeafStart;
  7608. /**
  7609. * Millisecond delay to allow `compositionstart` to fire again upon
  7610. * `compositionend`.
  7611. *
  7612. * This is used for Korean input to ensure that typing can continue without
  7613. * the editor trying to render too quickly. More specifically, Safari 7.1+
  7614. * triggers `compositionstart` a little slower than Chrome/FF, which
  7615. * leads to composed characters being resolved and re-render occurring
  7616. * sooner than we want.
  7617. */
  7618. var RESOLVE_DELAY = 20;
  7619. /**
  7620. * A handful of variables used to track the current composition and its
  7621. * resolution status. These exist at the module level because it is not
  7622. * possible to have compositions occurring in multiple editors simultaneously,
  7623. * and it simplifies state management with respect to the DraftEditor component.
  7624. */
  7625. var resolved = false;
  7626. var stillComposing = false;
  7627. var textInputData = '';
  7628. var DraftEditorCompositionHandler = {
  7629. onBeforeInput: function onBeforeInput(editor, e) {
  7630. textInputData = (textInputData || '') + e.data;
  7631. },
  7632. /**
  7633. * A `compositionstart` event has fired while we're still in composition
  7634. * mode. Continue the current composition session to prevent a re-render.
  7635. */
  7636. onCompositionStart: function onCompositionStart(editor) {
  7637. stillComposing = true;
  7638. },
  7639. /**
  7640. * Attempt to end the current composition session.
  7641. *
  7642. * Defer handling because browser will still insert the chars into active
  7643. * element after `compositionend`. If a `compositionstart` event fires
  7644. * before `resolveComposition` executes, our composition session will
  7645. * continue.
  7646. *
  7647. * The `resolved` flag is useful because certain IME interfaces fire the
  7648. * `compositionend` event multiple times, thus queueing up multiple attempts
  7649. * at handling the composition. Since handling the same composition event
  7650. * twice could break the DOM, we only use the first event. Example: Arabic
  7651. * Google Input Tools on Windows 8.1 fires `compositionend` three times.
  7652. */
  7653. onCompositionEnd: function onCompositionEnd(editor) {
  7654. resolved = false;
  7655. stillComposing = false;
  7656. setTimeout(function () {
  7657. if (!resolved) {
  7658. DraftEditorCompositionHandler.resolveComposition(editor);
  7659. }
  7660. }, RESOLVE_DELAY);
  7661. },
  7662. /**
  7663. * In Safari, keydown events may fire when committing compositions. If
  7664. * the arrow keys are used to commit, prevent default so that the cursor
  7665. * doesn't move, otherwise it will jump back noticeably on re-render.
  7666. */
  7667. onKeyDown: function onKeyDown(editor, e) {
  7668. if (!stillComposing) {
  7669. // If a keydown event is received after compositionend but before the
  7670. // 20ms timer expires (ex: type option-E then backspace, or type A then
  7671. // backspace in 2-Set Korean), we should immediately resolve the
  7672. // composition and reinterpret the key press in edit mode.
  7673. DraftEditorCompositionHandler.resolveComposition(editor);
  7674. editor._onKeyDown(e);
  7675. return;
  7676. }
  7677. if (e.which === Keys.RIGHT || e.which === Keys.LEFT) {
  7678. e.preventDefault();
  7679. }
  7680. },
  7681. /**
  7682. * Keypress events may fire when committing compositions. In Firefox,
  7683. * pressing RETURN commits the composition and inserts extra newline
  7684. * characters that we do not want. `preventDefault` allows the composition
  7685. * to be committed while preventing the extra characters.
  7686. */
  7687. onKeyPress: function onKeyPress(editor, e) {
  7688. if (e.which === Keys.RETURN) {
  7689. e.preventDefault();
  7690. }
  7691. },
  7692. /**
  7693. * Attempt to insert composed characters into the document.
  7694. *
  7695. * If we are still in a composition session, do nothing. Otherwise, insert
  7696. * the characters into the document and terminate the composition session.
  7697. *
  7698. * If no characters were composed -- for instance, the user
  7699. * deleted all composed characters and committed nothing new --
  7700. * force a re-render. We also re-render when the composition occurs
  7701. * at the beginning of a leaf, to ensure that if the browser has
  7702. * created a new text node for the composition, we will discard it.
  7703. *
  7704. * Resetting innerHTML will move focus to the beginning of the editor,
  7705. * so we update to force it back to the correct place.
  7706. */
  7707. resolveComposition: function resolveComposition(editor) {
  7708. if (stillComposing) {
  7709. return;
  7710. }
  7711. resolved = true;
  7712. var composedChars = textInputData;
  7713. textInputData = '';
  7714. var editorState = EditorState_1.set(editor._latestEditorState, {
  7715. inCompositionMode: false
  7716. });
  7717. var currentStyle = editorState.getCurrentInlineStyle();
  7718. var entityKey = getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection());
  7719. var mustReset = !composedChars || isSelectionAtLeafStart_1(editorState) || currentStyle.size > 0 || entityKey !== null;
  7720. if (mustReset) {
  7721. editor.restoreEditorDOM();
  7722. }
  7723. editor.exitCurrentMode();
  7724. if (composedChars) {
  7725. // If characters have been composed, re-rendering with the update
  7726. // is sufficient to reset the editor.
  7727. var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), composedChars, currentStyle, entityKey);
  7728. editor.update(EditorState_1.push(editorState, contentState, 'insert-characters'));
  7729. return;
  7730. }
  7731. if (mustReset) {
  7732. editor.update(EditorState_1.set(editorState, {
  7733. nativelyRenderedContent: null,
  7734. forceSelection: true
  7735. }));
  7736. }
  7737. }
  7738. };
  7739. var DraftEditorCompositionHandler_1 = DraftEditorCompositionHandler;
  7740. var uaParser = styleInject_es.createCommonjsModule(function (module, exports) {
  7741. /*!
  7742. * UAParser.js v0.7.21
  7743. * Lightweight JavaScript-based User-Agent string parser
  7744. * https://github.com/faisalman/ua-parser-js
  7745. *
  7746. * Copyright © 2012-2019 Faisal Salman <f@faisalman.com>
  7747. * Licensed under MIT License
  7748. */
  7749. (function (window, undefined$1) {
  7750. //////////////
  7751. // Constants
  7752. /////////////
  7753. var LIBVERSION = '0.7.21',
  7754. EMPTY = '',
  7755. UNKNOWN = '?',
  7756. FUNC_TYPE = 'function',
  7757. OBJ_TYPE = 'object',
  7758. STR_TYPE = 'string',
  7759. MAJOR = 'major', // deprecated
  7760. MODEL = 'model',
  7761. NAME = 'name',
  7762. TYPE = 'type',
  7763. VENDOR = 'vendor',
  7764. VERSION = 'version',
  7765. ARCHITECTURE= 'architecture',
  7766. CONSOLE = 'console',
  7767. MOBILE = 'mobile',
  7768. TABLET = 'tablet',
  7769. SMARTTV = 'smarttv',
  7770. WEARABLE = 'wearable',
  7771. EMBEDDED = 'embedded';
  7772. ///////////
  7773. // Helper
  7774. //////////
  7775. var util = {
  7776. extend : function (regexes, extensions) {
  7777. var mergedRegexes = {};
  7778. for (var i in regexes) {
  7779. if (extensions[i] && extensions[i].length % 2 === 0) {
  7780. mergedRegexes[i] = extensions[i].concat(regexes[i]);
  7781. } else {
  7782. mergedRegexes[i] = regexes[i];
  7783. }
  7784. }
  7785. return mergedRegexes;
  7786. },
  7787. has : function (str1, str2) {
  7788. if (typeof str1 === "string") {
  7789. return str2.toLowerCase().indexOf(str1.toLowerCase()) !== -1;
  7790. } else {
  7791. return false;
  7792. }
  7793. },
  7794. lowerize : function (str) {
  7795. return str.toLowerCase();
  7796. },
  7797. major : function (version) {
  7798. return typeof(version) === STR_TYPE ? version.replace(/[^\d\.]/g,'').split(".")[0] : undefined$1;
  7799. },
  7800. trim : function (str) {
  7801. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  7802. }
  7803. };
  7804. ///////////////
  7805. // Map helper
  7806. //////////////
  7807. var mapper = {
  7808. rgx : function (ua, arrays) {
  7809. var i = 0, j, k, p, q, matches, match;
  7810. // loop through all regexes maps
  7811. while (i < arrays.length && !matches) {
  7812. var regex = arrays[i], // even sequence (0,2,4,..)
  7813. props = arrays[i + 1]; // odd sequence (1,3,5,..)
  7814. j = k = 0;
  7815. // try matching uastring with regexes
  7816. while (j < regex.length && !matches) {
  7817. matches = regex[j++].exec(ua);
  7818. if (!!matches) {
  7819. for (p = 0; p < props.length; p++) {
  7820. match = matches[++k];
  7821. q = props[p];
  7822. // check if given property is actually array
  7823. if (typeof q === OBJ_TYPE && q.length > 0) {
  7824. if (q.length == 2) {
  7825. if (typeof q[1] == FUNC_TYPE) {
  7826. // assign modified match
  7827. this[q[0]] = q[1].call(this, match);
  7828. } else {
  7829. // assign given value, ignore regex match
  7830. this[q[0]] = q[1];
  7831. }
  7832. } else if (q.length == 3) {
  7833. // check whether function or regex
  7834. if (typeof q[1] === FUNC_TYPE && !(q[1].exec && q[1].test)) {
  7835. // call function (usually string mapper)
  7836. this[q[0]] = match ? q[1].call(this, match, q[2]) : undefined$1;
  7837. } else {
  7838. // sanitize match using given regex
  7839. this[q[0]] = match ? match.replace(q[1], q[2]) : undefined$1;
  7840. }
  7841. } else if (q.length == 4) {
  7842. this[q[0]] = match ? q[3].call(this, match.replace(q[1], q[2])) : undefined$1;
  7843. }
  7844. } else {
  7845. this[q] = match ? match : undefined$1;
  7846. }
  7847. }
  7848. }
  7849. }
  7850. i += 2;
  7851. }
  7852. },
  7853. str : function (str, map) {
  7854. for (var i in map) {
  7855. // check if array
  7856. if (typeof map[i] === OBJ_TYPE && map[i].length > 0) {
  7857. for (var j = 0; j < map[i].length; j++) {
  7858. if (util.has(map[i][j], str)) {
  7859. return (i === UNKNOWN) ? undefined$1 : i;
  7860. }
  7861. }
  7862. } else if (util.has(map[i], str)) {
  7863. return (i === UNKNOWN) ? undefined$1 : i;
  7864. }
  7865. }
  7866. return str;
  7867. }
  7868. };
  7869. ///////////////
  7870. // String map
  7871. //////////////
  7872. var maps = {
  7873. browser : {
  7874. oldsafari : {
  7875. version : {
  7876. '1.0' : '/8',
  7877. '1.2' : '/1',
  7878. '1.3' : '/3',
  7879. '2.0' : '/412',
  7880. '2.0.2' : '/416',
  7881. '2.0.3' : '/417',
  7882. '2.0.4' : '/419',
  7883. '?' : '/'
  7884. }
  7885. }
  7886. },
  7887. device : {
  7888. amazon : {
  7889. model : {
  7890. 'Fire Phone' : ['SD', 'KF']
  7891. }
  7892. },
  7893. sprint : {
  7894. model : {
  7895. 'Evo Shift 4G' : '7373KT'
  7896. },
  7897. vendor : {
  7898. 'HTC' : 'APA',
  7899. 'Sprint' : 'Sprint'
  7900. }
  7901. }
  7902. },
  7903. os : {
  7904. windows : {
  7905. version : {
  7906. 'ME' : '4.90',
  7907. 'NT 3.11' : 'NT3.51',
  7908. 'NT 4.0' : 'NT4.0',
  7909. '2000' : 'NT 5.0',
  7910. 'XP' : ['NT 5.1', 'NT 5.2'],
  7911. 'Vista' : 'NT 6.0',
  7912. '7' : 'NT 6.1',
  7913. '8' : 'NT 6.2',
  7914. '8.1' : 'NT 6.3',
  7915. '10' : ['NT 6.4', 'NT 10.0'],
  7916. 'RT' : 'ARM'
  7917. }
  7918. }
  7919. }
  7920. };
  7921. //////////////
  7922. // Regex map
  7923. /////////////
  7924. var regexes = {
  7925. browser : [[
  7926. // Presto based
  7927. /(opera\smini)\/([\w\.-]+)/i, // Opera Mini
  7928. /(opera\s[mobiletab]+).+version\/([\w\.-]+)/i, // Opera Mobi/Tablet
  7929. /(opera).+version\/([\w\.]+)/i, // Opera > 9.80
  7930. /(opera)[\/\s]+([\w\.]+)/i // Opera < 9.80
  7931. ], [NAME, VERSION], [
  7932. /(opios)[\/\s]+([\w\.]+)/i // Opera mini on iphone >= 8.0
  7933. ], [[NAME, 'Opera Mini'], VERSION], [
  7934. /\s(opr)\/([\w\.]+)/i // Opera Webkit
  7935. ], [[NAME, 'Opera'], VERSION], [
  7936. // Mixed
  7937. /(kindle)\/([\w\.]+)/i, // Kindle
  7938. /(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?([\w\.]*)/i,
  7939. // Lunascape/Maxthon/Netfront/Jasmine/Blazer
  7940. // Trident based
  7941. /(avant\s|iemobile|slim)(?:browser)?[\/\s]?([\w\.]*)/i,
  7942. // Avant/IEMobile/SlimBrowser
  7943. /(bidubrowser|baidubrowser)[\/\s]?([\w\.]+)/i, // Baidu Browser
  7944. /(?:ms|\()(ie)\s([\w\.]+)/i, // Internet Explorer
  7945. // Webkit/KHTML based
  7946. /(rekonq)\/([\w\.]*)/i, // Rekonq
  7947. /(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt|iron|vivaldi|iridium|phantomjs|bowser|quark|qupzilla|falkon)\/([\w\.-]+)/i
  7948. // Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt/Iron/Iridium/PhantomJS/Bowser/QupZilla/Falkon
  7949. ], [NAME, VERSION], [
  7950. /(konqueror)\/([\w\.]+)/i // Konqueror
  7951. ], [[NAME, 'Konqueror'], VERSION], [
  7952. /(trident).+rv[:\s]([\w\.]+).+like\sgecko/i // IE11
  7953. ], [[NAME, 'IE'], VERSION], [
  7954. /(edge|edgios|edga|edg)\/((\d+)?[\w\.]+)/i // Microsoft Edge
  7955. ], [[NAME, 'Edge'], VERSION], [
  7956. /(yabrowser)\/([\w\.]+)/i // Yandex
  7957. ], [[NAME, 'Yandex'], VERSION], [
  7958. /(Avast)\/([\w\.]+)/i // Avast Secure Browser
  7959. ], [[NAME, 'Avast Secure Browser'], VERSION], [
  7960. /(AVG)\/([\w\.]+)/i // AVG Secure Browser
  7961. ], [[NAME, 'AVG Secure Browser'], VERSION], [
  7962. /(puffin)\/([\w\.]+)/i // Puffin
  7963. ], [[NAME, 'Puffin'], VERSION], [
  7964. /(focus)\/([\w\.]+)/i // Firefox Focus
  7965. ], [[NAME, 'Firefox Focus'], VERSION], [
  7966. /(opt)\/([\w\.]+)/i // Opera Touch
  7967. ], [[NAME, 'Opera Touch'], VERSION], [
  7968. /((?:[\s\/])uc?\s?browser|(?:juc.+)ucweb)[\/\s]?([\w\.]+)/i // UCBrowser
  7969. ], [[NAME, 'UCBrowser'], VERSION], [
  7970. /(comodo_dragon)\/([\w\.]+)/i // Comodo Dragon
  7971. ], [[NAME, /_/g, ' '], VERSION], [
  7972. /(windowswechat qbcore)\/([\w\.]+)/i // WeChat Desktop for Windows Built-in Browser
  7973. ], [[NAME, 'WeChat(Win) Desktop'], VERSION], [
  7974. /(micromessenger)\/([\w\.]+)/i // WeChat
  7975. ], [[NAME, 'WeChat'], VERSION], [
  7976. /(brave)\/([\w\.]+)/i // Brave browser
  7977. ], [[NAME, 'Brave'], VERSION], [
  7978. /(qqbrowserlite)\/([\w\.]+)/i // QQBrowserLite
  7979. ], [NAME, VERSION], [
  7980. /(QQ)\/([\d\.]+)/i // QQ, aka ShouQ
  7981. ], [NAME, VERSION], [
  7982. /m?(qqbrowser)[\/\s]?([\w\.]+)/i // QQBrowser
  7983. ], [NAME, VERSION], [
  7984. /(baiduboxapp)[\/\s]?([\w\.]+)/i // Baidu App
  7985. ], [NAME, VERSION], [
  7986. /(2345Explorer)[\/\s]?([\w\.]+)/i // 2345 Browser
  7987. ], [NAME, VERSION], [
  7988. /(MetaSr)[\/\s]?([\w\.]+)/i // SouGouBrowser
  7989. ], [NAME], [
  7990. /(LBBROWSER)/i // LieBao Browser
  7991. ], [NAME], [
  7992. /xiaomi\/miuibrowser\/([\w\.]+)/i // MIUI Browser
  7993. ], [VERSION, [NAME, 'MIUI Browser']], [
  7994. /;fbav\/([\w\.]+);/i // Facebook App for iOS & Android
  7995. ], [VERSION, [NAME, 'Facebook']], [
  7996. /safari\s(line)\/([\w\.]+)/i, // Line App for iOS
  7997. /android.+(line)\/([\w\.]+)\/iab/i // Line App for Android
  7998. ], [NAME, VERSION], [
  7999. /headlesschrome(?:\/([\w\.]+)|\s)/i // Chrome Headless
  8000. ], [VERSION, [NAME, 'Chrome Headless']], [
  8001. /\swv\).+(chrome)\/([\w\.]+)/i // Chrome WebView
  8002. ], [[NAME, /(.+)/, '$1 WebView'], VERSION], [
  8003. /((?:oculus|samsung)browser)\/([\w\.]+)/i
  8004. ], [[NAME, /(.+(?:g|us))(.+)/, '$1 $2'], VERSION], [ // Oculus / Samsung Browser
  8005. /android.+version\/([\w\.]+)\s+(?:mobile\s?safari|safari)*/i // Android Browser
  8006. ], [VERSION, [NAME, 'Android Browser']], [
  8007. /(sailfishbrowser)\/([\w\.]+)/i // Sailfish Browser
  8008. ], [[NAME, 'Sailfish Browser'], VERSION], [
  8009. /(chrome|omniweb|arora|[tizenoka]{5}\s?browser)\/v?([\w\.]+)/i
  8010. // Chrome/OmniWeb/Arora/Tizen/Nokia
  8011. ], [NAME, VERSION], [
  8012. /(dolfin)\/([\w\.]+)/i // Dolphin
  8013. ], [[NAME, 'Dolphin'], VERSION], [
  8014. /(qihu|qhbrowser|qihoobrowser|360browser)/i // 360
  8015. ], [[NAME, '360 Browser']], [
  8016. /((?:android.+)crmo|crios)\/([\w\.]+)/i // Chrome for Android/iOS
  8017. ], [[NAME, 'Chrome'], VERSION], [
  8018. /(coast)\/([\w\.]+)/i // Opera Coast
  8019. ], [[NAME, 'Opera Coast'], VERSION], [
  8020. /fxios\/([\w\.-]+)/i // Firefox for iOS
  8021. ], [VERSION, [NAME, 'Firefox']], [
  8022. /version\/([\w\.]+).+?mobile\/\w+\s(safari)/i // Mobile Safari
  8023. ], [VERSION, [NAME, 'Mobile Safari']], [
  8024. /version\/([\w\.]+).+?(mobile\s?safari|safari)/i // Safari & Safari Mobile
  8025. ], [VERSION, NAME], [
  8026. /webkit.+?(gsa)\/([\w\.]+).+?(mobile\s?safari|safari)(\/[\w\.]+)/i // Google Search Appliance on iOS
  8027. ], [[NAME, 'GSA'], VERSION], [
  8028. /webkit.+?(mobile\s?safari|safari)(\/[\w\.]+)/i // Safari < 3.0
  8029. ], [NAME, [VERSION, mapper.str, maps.browser.oldsafari.version]], [
  8030. /(webkit|khtml)\/([\w\.]+)/i
  8031. ], [NAME, VERSION], [
  8032. // Gecko based
  8033. /(navigator|netscape)\/([\w\.-]+)/i // Netscape
  8034. ], [[NAME, 'Netscape'], VERSION], [
  8035. /(swiftfox)/i, // Swiftfox
  8036. /(icedragon|iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo|conkeror)[\/\s]?([\w\.\+]+)/i,
  8037. // IceDragon/Iceweasel/Camino/Chimera/Fennec/Maemo/Minimo/Conkeror
  8038. /(firefox|seamonkey|k-meleon|icecat|iceape|firebird|phoenix|palemoon|basilisk|waterfox)\/([\w\.-]+)$/i,
  8039. // Firefox/SeaMonkey/K-Meleon/IceCat/IceApe/Firebird/Phoenix
  8040. /(mozilla)\/([\w\.]+).+rv\:.+gecko\/\d+/i, // Mozilla
  8041. // Other
  8042. /(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|sleipnir)[\/\s]?([\w\.]+)/i,
  8043. // Polaris/Lynx/Dillo/iCab/Doris/Amaya/w3m/NetSurf/Sleipnir
  8044. /(links)\s\(([\w\.]+)/i, // Links
  8045. /(gobrowser)\/?([\w\.]*)/i, // GoBrowser
  8046. /(ice\s?browser)\/v?([\w\._]+)/i, // ICE Browser
  8047. /(mosaic)[\/\s]([\w\.]+)/i // Mosaic
  8048. ], [NAME, VERSION]
  8049. ],
  8050. cpu : [[
  8051. /(?:(amd|x(?:(?:86|64)[_-])?|wow|win)64)[;\)]/i // AMD64
  8052. ], [[ARCHITECTURE, 'amd64']], [
  8053. /(ia32(?=;))/i // IA32 (quicktime)
  8054. ], [[ARCHITECTURE, util.lowerize]], [
  8055. /((?:i[346]|x)86)[;\)]/i // IA32
  8056. ], [[ARCHITECTURE, 'ia32']], [
  8057. // PocketPC mistakenly identified as PowerPC
  8058. /windows\s(ce|mobile);\sppc;/i
  8059. ], [[ARCHITECTURE, 'arm']], [
  8060. /((?:ppc|powerpc)(?:64)?)(?:\smac|;|\))/i // PowerPC
  8061. ], [[ARCHITECTURE, /ower/, '', util.lowerize]], [
  8062. /(sun4\w)[;\)]/i // SPARC
  8063. ], [[ARCHITECTURE, 'sparc']], [
  8064. /((?:avr32|ia64(?=;))|68k(?=\))|arm(?:64|(?=v\d+[;l]))|(?=atmel\s)avr|(?:irix|mips|sparc)(?:64)?(?=;)|pa-risc)/i
  8065. // IA64, 68K, ARM/64, AVR/32, IRIX/64, MIPS/64, SPARC/64, PA-RISC
  8066. ], [[ARCHITECTURE, util.lowerize]]
  8067. ],
  8068. device : [[
  8069. /\((ipad|playbook);[\w\s\),;-]+(rim|apple)/i // iPad/PlayBook
  8070. ], [MODEL, VENDOR, [TYPE, TABLET]], [
  8071. /applecoremedia\/[\w\.]+ \((ipad)/ // iPad
  8072. ], [MODEL, [VENDOR, 'Apple'], [TYPE, TABLET]], [
  8073. /(apple\s{0,1}tv)/i // Apple TV
  8074. ], [[MODEL, 'Apple TV'], [VENDOR, 'Apple'], [TYPE, SMARTTV]], [
  8075. /(archos)\s(gamepad2?)/i, // Archos
  8076. /(hp).+(touchpad)/i, // HP TouchPad
  8077. /(hp).+(tablet)/i, // HP Tablet
  8078. /(kindle)\/([\w\.]+)/i, // Kindle
  8079. /\s(nook)[\w\s]+build\/(\w+)/i, // Nook
  8080. /(dell)\s(strea[kpr\s\d]*[\dko])/i // Dell Streak
  8081. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8082. /(kf[A-z]+)\sbuild\/.+silk\//i // Kindle Fire HD
  8083. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, TABLET]], [
  8084. /(sd|kf)[0349hijorstuw]+\sbuild\/.+silk\//i // Fire Phone
  8085. ], [[MODEL, mapper.str, maps.device.amazon.model], [VENDOR, 'Amazon'], [TYPE, MOBILE]], [
  8086. /android.+aft([bms])\sbuild/i // Fire TV
  8087. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, SMARTTV]], [
  8088. /\((ip[honed|\s\w*]+);.+(apple)/i // iPod/iPhone
  8089. ], [MODEL, VENDOR, [TYPE, MOBILE]], [
  8090. /\((ip[honed|\s\w*]+);/i // iPod/iPhone
  8091. ], [MODEL, [VENDOR, 'Apple'], [TYPE, MOBILE]], [
  8092. /(blackberry)[\s-]?(\w+)/i, // BlackBerry
  8093. /(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|meizu|motorola|polytron)[\s_-]?([\w-]*)/i,
  8094. // BenQ/Palm/Sony-Ericsson/Acer/Asus/Dell/Meizu/Motorola/Polytron
  8095. /(hp)\s([\w\s]+\w)/i, // HP iPAQ
  8096. /(asus)-?(\w+)/i // Asus
  8097. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8098. /\(bb10;\s(\w+)/i // BlackBerry 10
  8099. ], [MODEL, [VENDOR, 'BlackBerry'], [TYPE, MOBILE]], [
  8100. // Asus Tablets
  8101. /android.+(transfo[prime\s]{4,10}\s\w+|eeepc|slider\s\w+|nexus 7|padfone|p00c)/i
  8102. ], [MODEL, [VENDOR, 'Asus'], [TYPE, TABLET]], [
  8103. /(sony)\s(tablet\s[ps])\sbuild\//i, // Sony
  8104. /(sony)?(?:sgp.+)\sbuild\//i
  8105. ], [[VENDOR, 'Sony'], [MODEL, 'Xperia Tablet'], [TYPE, TABLET]], [
  8106. /android.+\s([c-g]\d{4}|so[-l]\w+)(?=\sbuild\/|\).+chrome\/(?![1-6]{0,1}\d\.))/i
  8107. ], [MODEL, [VENDOR, 'Sony'], [TYPE, MOBILE]], [
  8108. /\s(ouya)\s/i, // Ouya
  8109. /(nintendo)\s([wids3u]+)/i // Nintendo
  8110. ], [VENDOR, MODEL, [TYPE, CONSOLE]], [
  8111. /android.+;\s(shield)\sbuild/i // Nvidia
  8112. ], [MODEL, [VENDOR, 'Nvidia'], [TYPE, CONSOLE]], [
  8113. /(playstation\s[34portablevi]+)/i // Playstation
  8114. ], [MODEL, [VENDOR, 'Sony'], [TYPE, CONSOLE]], [
  8115. /(sprint\s(\w+))/i // Sprint Phones
  8116. ], [[VENDOR, mapper.str, maps.device.sprint.vendor], [MODEL, mapper.str, maps.device.sprint.model], [TYPE, MOBILE]], [
  8117. /(htc)[;_\s-]+([\w\s]+(?=\)|\sbuild)|\w+)/i, // HTC
  8118. /(zte)-(\w*)/i, // ZTE
  8119. /(alcatel|geeksphone|nexian|panasonic|(?=;\s)sony)[_\s-]?([\w-]*)/i
  8120. // Alcatel/GeeksPhone/Nexian/Panasonic/Sony
  8121. ], [VENDOR, [MODEL, /_/g, ' '], [TYPE, MOBILE]], [
  8122. /(nexus\s9)/i // HTC Nexus 9
  8123. ], [MODEL, [VENDOR, 'HTC'], [TYPE, TABLET]], [
  8124. /d\/huawei([\w\s-]+)[;\)]/i,
  8125. /(nexus\s6p|vog-l29|ane-lx1|eml-l29)/i // Huawei
  8126. ], [MODEL, [VENDOR, 'Huawei'], [TYPE, MOBILE]], [
  8127. /android.+(bah2?-a?[lw]\d{2})/i // Huawei MediaPad
  8128. ], [MODEL, [VENDOR, 'Huawei'], [TYPE, TABLET]], [
  8129. /(microsoft);\s(lumia[\s\w]+)/i // Microsoft Lumia
  8130. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8131. /[\s\(;](xbox(?:\sone)?)[\s\);]/i // Microsoft Xbox
  8132. ], [MODEL, [VENDOR, 'Microsoft'], [TYPE, CONSOLE]], [
  8133. /(kin\.[onetw]{3})/i // Microsoft Kin
  8134. ], [[MODEL, /\./g, ' '], [VENDOR, 'Microsoft'], [TYPE, MOBILE]], [
  8135. // Motorola
  8136. /\s(milestone|droid(?:[2-4x]|\s(?:bionic|x2|pro|razr))?:?(\s4g)?)[\w\s]+build\//i,
  8137. /mot[\s-]?(\w*)/i,
  8138. /(XT\d{3,4}) build\//i,
  8139. /(nexus\s6)/i
  8140. ], [MODEL, [VENDOR, 'Motorola'], [TYPE, MOBILE]], [
  8141. /android.+\s(mz60\d|xoom[\s2]{0,2})\sbuild\//i
  8142. ], [MODEL, [VENDOR, 'Motorola'], [TYPE, TABLET]], [
  8143. /hbbtv\/\d+\.\d+\.\d+\s+\([\w\s]*;\s*(\w[^;]*);([^;]*)/i // HbbTV devices
  8144. ], [[VENDOR, util.trim], [MODEL, util.trim], [TYPE, SMARTTV]], [
  8145. /hbbtv.+maple;(\d+)/i
  8146. ], [[MODEL, /^/, 'SmartTV'], [VENDOR, 'Samsung'], [TYPE, SMARTTV]], [
  8147. /\(dtv[\);].+(aquos)/i // Sharp
  8148. ], [MODEL, [VENDOR, 'Sharp'], [TYPE, SMARTTV]], [
  8149. /android.+((sch-i[89]0\d|shw-m380s|gt-p\d{4}|gt-n\d+|sgh-t8[56]9|nexus 10))/i,
  8150. /((SM-T\w+))/i
  8151. ], [[VENDOR, 'Samsung'], MODEL, [TYPE, TABLET]], [ // Samsung
  8152. /smart-tv.+(samsung)/i
  8153. ], [VENDOR, [TYPE, SMARTTV], MODEL], [
  8154. /((s[cgp]h-\w+|gt-\w+|galaxy\snexus|sm-\w[\w\d]+))/i,
  8155. /(sam[sung]*)[\s-]*(\w+-?[\w-]*)/i,
  8156. /sec-((sgh\w+))/i
  8157. ], [[VENDOR, 'Samsung'], MODEL, [TYPE, MOBILE]], [
  8158. /sie-(\w*)/i // Siemens
  8159. ], [MODEL, [VENDOR, 'Siemens'], [TYPE, MOBILE]], [
  8160. /(maemo|nokia).*(n900|lumia\s\d+)/i, // Nokia
  8161. /(nokia)[\s_-]?([\w-]*)/i
  8162. ], [[VENDOR, 'Nokia'], MODEL, [TYPE, MOBILE]], [
  8163. /android[x\d\.\s;]+\s([ab][1-7]\-?[0178a]\d\d?)/i // Acer
  8164. ], [MODEL, [VENDOR, 'Acer'], [TYPE, TABLET]], [
  8165. /android.+([vl]k\-?\d{3})\s+build/i // LG Tablet
  8166. ], [MODEL, [VENDOR, 'LG'], [TYPE, TABLET]], [
  8167. /android\s3\.[\s\w;-]{10}(lg?)-([06cv9]{3,4})/i // LG Tablet
  8168. ], [[VENDOR, 'LG'], MODEL, [TYPE, TABLET]], [
  8169. /(lg) netcast\.tv/i // LG SmartTV
  8170. ], [VENDOR, MODEL, [TYPE, SMARTTV]], [
  8171. /(nexus\s[45])/i, // LG
  8172. /lg[e;\s\/-]+(\w*)/i,
  8173. /android.+lg(\-?[\d\w]+)\s+build/i
  8174. ], [MODEL, [VENDOR, 'LG'], [TYPE, MOBILE]], [
  8175. /(lenovo)\s?(s(?:5000|6000)(?:[\w-]+)|tab(?:[\s\w]+))/i // Lenovo tablets
  8176. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8177. /android.+(ideatab[a-z0-9\-\s]+)/i // Lenovo
  8178. ], [MODEL, [VENDOR, 'Lenovo'], [TYPE, TABLET]], [
  8179. /(lenovo)[_\s-]?([\w-]+)/i
  8180. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8181. /linux;.+((jolla));/i // Jolla
  8182. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8183. /((pebble))app\/[\d\.]+\s/i // Pebble
  8184. ], [VENDOR, MODEL, [TYPE, WEARABLE]], [
  8185. /android.+;\s(oppo)\s?([\w\s]+)\sbuild/i // OPPO
  8186. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8187. /crkey/i // Google Chromecast
  8188. ], [[MODEL, 'Chromecast'], [VENDOR, 'Google'], [TYPE, SMARTTV]], [
  8189. /android.+;\s(glass)\s\d/i // Google Glass
  8190. ], [MODEL, [VENDOR, 'Google'], [TYPE, WEARABLE]], [
  8191. /android.+;\s(pixel c)[\s)]/i // Google Pixel C
  8192. ], [MODEL, [VENDOR, 'Google'], [TYPE, TABLET]], [
  8193. /android.+;\s(pixel( [23])?( xl)?)[\s)]/i // Google Pixel
  8194. ], [MODEL, [VENDOR, 'Google'], [TYPE, MOBILE]], [
  8195. /android.+;\s(\w+)\s+build\/hm\1/i, // Xiaomi Hongmi 'numeric' models
  8196. /android.+(hm[\s\-_]*note?[\s_]*(?:\d\w)?)\s+build/i, // Xiaomi Hongmi
  8197. /android.+(mi[\s\-_]*(?:a\d|one|one[\s_]plus|note lte)?[\s_]*(?:\d?\w?)[\s_]*(?:plus)?)\s+build/i,
  8198. // Xiaomi Mi
  8199. /android.+(redmi[\s\-_]*(?:note)?(?:[\s_]*[\w\s]+))\s+build/i // Redmi Phones
  8200. ], [[MODEL, /_/g, ' '], [VENDOR, 'Xiaomi'], [TYPE, MOBILE]], [
  8201. /android.+(mi[\s\-_]*(?:pad)(?:[\s_]*[\w\s]+))\s+build/i // Mi Pad tablets
  8202. ],[[MODEL, /_/g, ' '], [VENDOR, 'Xiaomi'], [TYPE, TABLET]], [
  8203. /android.+;\s(m[1-5]\snote)\sbuild/i // Meizu
  8204. ], [MODEL, [VENDOR, 'Meizu'], [TYPE, MOBILE]], [
  8205. /(mz)-([\w-]{2,})/i
  8206. ], [[VENDOR, 'Meizu'], MODEL, [TYPE, MOBILE]], [
  8207. /android.+a000(1)\s+build/i, // OnePlus
  8208. /android.+oneplus\s(a\d{4})[\s)]/i
  8209. ], [MODEL, [VENDOR, 'OnePlus'], [TYPE, MOBILE]], [
  8210. /android.+[;\/]\s*(RCT[\d\w]+)\s+build/i // RCA Tablets
  8211. ], [MODEL, [VENDOR, 'RCA'], [TYPE, TABLET]], [
  8212. /android.+[;\/\s]+(Venue[\d\s]{2,7})\s+build/i // Dell Venue Tablets
  8213. ], [MODEL, [VENDOR, 'Dell'], [TYPE, TABLET]], [
  8214. /android.+[;\/]\s*(Q[T|M][\d\w]+)\s+build/i // Verizon Tablet
  8215. ], [MODEL, [VENDOR, 'Verizon'], [TYPE, TABLET]], [
  8216. /android.+[;\/]\s+(Barnes[&\s]+Noble\s+|BN[RT])(V?.*)\s+build/i // Barnes & Noble Tablet
  8217. ], [[VENDOR, 'Barnes & Noble'], MODEL, [TYPE, TABLET]], [
  8218. /android.+[;\/]\s+(TM\d{3}.*\b)\s+build/i // Barnes & Noble Tablet
  8219. ], [MODEL, [VENDOR, 'NuVision'], [TYPE, TABLET]], [
  8220. /android.+;\s(k88)\sbuild/i // ZTE K Series Tablet
  8221. ], [MODEL, [VENDOR, 'ZTE'], [TYPE, TABLET]], [
  8222. /android.+[;\/]\s*(gen\d{3})\s+build.*49h/i // Swiss GEN Mobile
  8223. ], [MODEL, [VENDOR, 'Swiss'], [TYPE, MOBILE]], [
  8224. /android.+[;\/]\s*(zur\d{3})\s+build/i // Swiss ZUR Tablet
  8225. ], [MODEL, [VENDOR, 'Swiss'], [TYPE, TABLET]], [
  8226. /android.+[;\/]\s*((Zeki)?TB.*\b)\s+build/i // Zeki Tablets
  8227. ], [MODEL, [VENDOR, 'Zeki'], [TYPE, TABLET]], [
  8228. /(android).+[;\/]\s+([YR]\d{2})\s+build/i,
  8229. /android.+[;\/]\s+(Dragon[\-\s]+Touch\s+|DT)(\w{5})\sbuild/i // Dragon Touch Tablet
  8230. ], [[VENDOR, 'Dragon Touch'], MODEL, [TYPE, TABLET]], [
  8231. /android.+[;\/]\s*(NS-?\w{0,9})\sbuild/i // Insignia Tablets
  8232. ], [MODEL, [VENDOR, 'Insignia'], [TYPE, TABLET]], [
  8233. /android.+[;\/]\s*((NX|Next)-?\w{0,9})\s+build/i // NextBook Tablets
  8234. ], [MODEL, [VENDOR, 'NextBook'], [TYPE, TABLET]], [
  8235. /android.+[;\/]\s*(Xtreme\_)?(V(1[045]|2[015]|30|40|60|7[05]|90))\s+build/i
  8236. ], [[VENDOR, 'Voice'], MODEL, [TYPE, MOBILE]], [ // Voice Xtreme Phones
  8237. /android.+[;\/]\s*(LVTEL\-)?(V1[12])\s+build/i // LvTel Phones
  8238. ], [[VENDOR, 'LvTel'], MODEL, [TYPE, MOBILE]], [
  8239. /android.+;\s(PH-1)\s/i
  8240. ], [MODEL, [VENDOR, 'Essential'], [TYPE, MOBILE]], [ // Essential PH-1
  8241. /android.+[;\/]\s*(V(100MD|700NA|7011|917G).*\b)\s+build/i // Envizen Tablets
  8242. ], [MODEL, [VENDOR, 'Envizen'], [TYPE, TABLET]], [
  8243. /android.+[;\/]\s*(Le[\s\-]+Pan)[\s\-]+(\w{1,9})\s+build/i // Le Pan Tablets
  8244. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8245. /android.+[;\/]\s*(Trio[\s\-]*.*)\s+build/i // MachSpeed Tablets
  8246. ], [MODEL, [VENDOR, 'MachSpeed'], [TYPE, TABLET]], [
  8247. /android.+[;\/]\s*(Trinity)[\-\s]*(T\d{3})\s+build/i // Trinity Tablets
  8248. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8249. /android.+[;\/]\s*TU_(1491)\s+build/i // Rotor Tablets
  8250. ], [MODEL, [VENDOR, 'Rotor'], [TYPE, TABLET]], [
  8251. /android.+(KS(.+))\s+build/i // Amazon Kindle Tablets
  8252. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, TABLET]], [
  8253. /android.+(Gigaset)[\s\-]+(Q\w{1,9})\s+build/i // Gigaset Tablets
  8254. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8255. /\s(tablet|tab)[;\/]/i, // Unidentifiable Tablet
  8256. /\s(mobile)(?:[;\/]|\ssafari)/i // Unidentifiable Mobile
  8257. ], [[TYPE, util.lowerize], VENDOR, MODEL], [
  8258. /[\s\/\(](smart-?tv)[;\)]/i // SmartTV
  8259. ], [[TYPE, SMARTTV]], [
  8260. /(android[\w\.\s\-]{0,9});.+build/i // Generic Android Device
  8261. ], [MODEL, [VENDOR, 'Generic']]
  8262. ],
  8263. engine : [[
  8264. /windows.+\sedge\/([\w\.]+)/i // EdgeHTML
  8265. ], [VERSION, [NAME, 'EdgeHTML']], [
  8266. /webkit\/537\.36.+chrome\/(?!27)([\w\.]+)/i // Blink
  8267. ], [VERSION, [NAME, 'Blink']], [
  8268. /(presto)\/([\w\.]+)/i, // Presto
  8269. /(webkit|trident|netfront|netsurf|amaya|lynx|w3m|goanna)\/([\w\.]+)/i,
  8270. // WebKit/Trident/NetFront/NetSurf/Amaya/Lynx/w3m/Goanna
  8271. /(khtml|tasman|links)[\/\s]\(?([\w\.]+)/i, // KHTML/Tasman/Links
  8272. /(icab)[\/\s]([23]\.[\d\.]+)/i // iCab
  8273. ], [NAME, VERSION], [
  8274. /rv\:([\w\.]{1,9}).+(gecko)/i // Gecko
  8275. ], [VERSION, NAME]
  8276. ],
  8277. os : [[
  8278. // Windows based
  8279. /microsoft\s(windows)\s(vista|xp)/i // Windows (iTunes)
  8280. ], [NAME, VERSION], [
  8281. /(windows)\snt\s6\.2;\s(arm)/i, // Windows RT
  8282. /(windows\sphone(?:\sos)*)[\s\/]?([\d\.\s\w]*)/i, // Windows Phone
  8283. /(windows\smobile|windows)[\s\/]?([ntce\d\.\s]+\w)/i
  8284. ], [NAME, [VERSION, mapper.str, maps.os.windows.version]], [
  8285. /(win(?=3|9|n)|win\s9x\s)([nt\d\.]+)/i
  8286. ], [[NAME, 'Windows'], [VERSION, mapper.str, maps.os.windows.version]], [
  8287. // Mobile/Embedded OS
  8288. /\((bb)(10);/i // BlackBerry 10
  8289. ], [[NAME, 'BlackBerry'], VERSION], [
  8290. /(blackberry)\w*\/?([\w\.]*)/i, // Blackberry
  8291. /(tizen|kaios)[\/\s]([\w\.]+)/i, // Tizen/KaiOS
  8292. /(android|webos|palm\sos|qnx|bada|rim\stablet\sos|meego|sailfish|contiki)[\/\s-]?([\w\.]*)/i
  8293. // Android/WebOS/Palm/QNX/Bada/RIM/MeeGo/Contiki/Sailfish OS
  8294. ], [NAME, VERSION], [
  8295. /(symbian\s?os|symbos|s60(?=;))[\/\s-]?([\w\.]*)/i // Symbian
  8296. ], [[NAME, 'Symbian'], VERSION], [
  8297. /\((series40);/i // Series 40
  8298. ], [NAME], [
  8299. /mozilla.+\(mobile;.+gecko.+firefox/i // Firefox OS
  8300. ], [[NAME, 'Firefox OS'], VERSION], [
  8301. // Console
  8302. /(nintendo|playstation)\s([wids34portablevu]+)/i, // Nintendo/Playstation
  8303. // GNU/Linux based
  8304. /(mint)[\/\s\(]?(\w*)/i, // Mint
  8305. /(mageia|vectorlinux)[;\s]/i, // Mageia/VectorLinux
  8306. /(joli|[kxln]?ubuntu|debian|suse|opensuse|gentoo|(?=\s)arch|slackware|fedora|mandriva|centos|pclinuxos|redhat|zenwalk|linpus)[\/\s-]?(?!chrom)([\w\.-]*)/i,
  8307. // Joli/Ubuntu/Debian/SUSE/Gentoo/Arch/Slackware
  8308. // Fedora/Mandriva/CentOS/PCLinuxOS/RedHat/Zenwalk/Linpus
  8309. /(hurd|linux)\s?([\w\.]*)/i, // Hurd/Linux
  8310. /(gnu)\s?([\w\.]*)/i // GNU
  8311. ], [NAME, VERSION], [
  8312. /(cros)\s[\w]+\s([\w\.]+\w)/i // Chromium OS
  8313. ], [[NAME, 'Chromium OS'], VERSION],[
  8314. // Solaris
  8315. /(sunos)\s?([\w\.\d]*)/i // Solaris
  8316. ], [[NAME, 'Solaris'], VERSION], [
  8317. // BSD based
  8318. /\s([frentopc-]{0,4}bsd|dragonfly)\s?([\w\.]*)/i // FreeBSD/NetBSD/OpenBSD/PC-BSD/DragonFly
  8319. ], [NAME, VERSION],[
  8320. /(haiku)\s(\w+)/i // Haiku
  8321. ], [NAME, VERSION],[
  8322. /cfnetwork\/.+darwin/i,
  8323. /ip[honead]{2,4}(?:.*os\s([\w]+)\slike\smac|;\sopera)/i // iOS
  8324. ], [[VERSION, /_/g, '.'], [NAME, 'iOS']], [
  8325. /(mac\sos\sx)\s?([\w\s\.]*)/i,
  8326. /(macintosh|mac(?=_powerpc)\s)/i // Mac OS
  8327. ], [[NAME, 'Mac OS'], [VERSION, /_/g, '.']], [
  8328. // Other
  8329. /((?:open)?solaris)[\/\s-]?([\w\.]*)/i, // Solaris
  8330. /(aix)\s((\d)(?=\.|\)|\s)[\w\.])*/i, // AIX
  8331. /(plan\s9|minix|beos|os\/2|amigaos|morphos|risc\sos|openvms|fuchsia)/i,
  8332. // Plan9/Minix/BeOS/OS2/AmigaOS/MorphOS/RISCOS/OpenVMS/Fuchsia
  8333. /(unix)\s?([\w\.]*)/i // UNIX
  8334. ], [NAME, VERSION]
  8335. ]
  8336. };
  8337. /////////////////
  8338. // Constructor
  8339. ////////////////
  8340. var UAParser = function (uastring, extensions) {
  8341. if (typeof uastring === 'object') {
  8342. extensions = uastring;
  8343. uastring = undefined$1;
  8344. }
  8345. if (!(this instanceof UAParser)) {
  8346. return new UAParser(uastring, extensions).getResult();
  8347. }
  8348. var ua = uastring || ((window && window.navigator && window.navigator.userAgent) ? window.navigator.userAgent : EMPTY);
  8349. var rgxmap = extensions ? util.extend(regexes, extensions) : regexes;
  8350. this.getBrowser = function () {
  8351. var browser = { name: undefined$1, version: undefined$1 };
  8352. mapper.rgx.call(browser, ua, rgxmap.browser);
  8353. browser.major = util.major(browser.version); // deprecated
  8354. return browser;
  8355. };
  8356. this.getCPU = function () {
  8357. var cpu = { architecture: undefined$1 };
  8358. mapper.rgx.call(cpu, ua, rgxmap.cpu);
  8359. return cpu;
  8360. };
  8361. this.getDevice = function () {
  8362. var device = { vendor: undefined$1, model: undefined$1, type: undefined$1 };
  8363. mapper.rgx.call(device, ua, rgxmap.device);
  8364. return device;
  8365. };
  8366. this.getEngine = function () {
  8367. var engine = { name: undefined$1, version: undefined$1 };
  8368. mapper.rgx.call(engine, ua, rgxmap.engine);
  8369. return engine;
  8370. };
  8371. this.getOS = function () {
  8372. var os = { name: undefined$1, version: undefined$1 };
  8373. mapper.rgx.call(os, ua, rgxmap.os);
  8374. return os;
  8375. };
  8376. this.getResult = function () {
  8377. return {
  8378. ua : this.getUA(),
  8379. browser : this.getBrowser(),
  8380. engine : this.getEngine(),
  8381. os : this.getOS(),
  8382. device : this.getDevice(),
  8383. cpu : this.getCPU()
  8384. };
  8385. };
  8386. this.getUA = function () {
  8387. return ua;
  8388. };
  8389. this.setUA = function (uastring) {
  8390. ua = uastring;
  8391. return this;
  8392. };
  8393. return this;
  8394. };
  8395. UAParser.VERSION = LIBVERSION;
  8396. UAParser.BROWSER = {
  8397. NAME : NAME,
  8398. MAJOR : MAJOR, // deprecated
  8399. VERSION : VERSION
  8400. };
  8401. UAParser.CPU = {
  8402. ARCHITECTURE : ARCHITECTURE
  8403. };
  8404. UAParser.DEVICE = {
  8405. MODEL : MODEL,
  8406. VENDOR : VENDOR,
  8407. TYPE : TYPE,
  8408. CONSOLE : CONSOLE,
  8409. MOBILE : MOBILE,
  8410. SMARTTV : SMARTTV,
  8411. TABLET : TABLET,
  8412. WEARABLE: WEARABLE,
  8413. EMBEDDED: EMBEDDED
  8414. };
  8415. UAParser.ENGINE = {
  8416. NAME : NAME,
  8417. VERSION : VERSION
  8418. };
  8419. UAParser.OS = {
  8420. NAME : NAME,
  8421. VERSION : VERSION
  8422. };
  8423. ///////////
  8424. // Export
  8425. //////////
  8426. // check js environment
  8427. {
  8428. // nodejs env
  8429. if ( module.exports) {
  8430. exports = module.exports = UAParser;
  8431. }
  8432. exports.UAParser = UAParser;
  8433. }
  8434. // jQuery/Zepto specific (optional)
  8435. // Note:
  8436. // In AMD env the global scope should be kept clean, but jQuery is an exception.
  8437. // jQuery always exports to global scope, unless jQuery.noConflict(true) is used,
  8438. // and we should catch that.
  8439. var $ = window && (window.jQuery || window.Zepto);
  8440. if ($ && !$.ua) {
  8441. var parser = new UAParser();
  8442. $.ua = parser.getResult();
  8443. $.ua.get = function () {
  8444. return parser.getUA();
  8445. };
  8446. $.ua.set = function (uastring) {
  8447. parser.setUA(uastring);
  8448. var result = parser.getResult();
  8449. for (var prop in result) {
  8450. $.ua[prop] = result[prop];
  8451. }
  8452. };
  8453. }
  8454. })(typeof window === 'object' ? window : styleInject_es.commonjsGlobal);
  8455. });
  8456. var uaParser_1 = uaParser.UAParser;
  8457. var UNKNOWN = 'Unknown';
  8458. var PLATFORM_MAP = {
  8459. 'Mac OS': 'Mac OS X'
  8460. };
  8461. /**
  8462. * Convert from UAParser platform name to what we expect.
  8463. */
  8464. function convertPlatformName(name) {
  8465. return PLATFORM_MAP[name] || name;
  8466. }
  8467. /**
  8468. * Get the version number in parts. This is very naive. We actually get major
  8469. * version as a part of UAParser already, which is generally good enough, but
  8470. * let's get the minor just in case.
  8471. */
  8472. function getBrowserVersion(version) {
  8473. if (!version) {
  8474. return {
  8475. major: '',
  8476. minor: ''
  8477. };
  8478. }
  8479. var parts = version.split('.');
  8480. return {
  8481. major: parts[0],
  8482. minor: parts[1]
  8483. };
  8484. }
  8485. /**
  8486. * Get the UA data fom UAParser and then convert it to the format we're
  8487. * expecting for our APIS.
  8488. */
  8489. var parser = new uaParser();
  8490. var results = parser.getResult();
  8491. // Do some conversion first.
  8492. var browserVersionData = getBrowserVersion(results.browser.version);
  8493. var uaData = {
  8494. browserArchitecture: results.cpu.architecture || UNKNOWN,
  8495. browserFullVersion: results.browser.version || UNKNOWN,
  8496. browserMinorVersion: browserVersionData.minor || UNKNOWN,
  8497. browserName: results.browser.name || UNKNOWN,
  8498. browserVersion: results.browser.major || UNKNOWN,
  8499. deviceName: results.device.model || UNKNOWN,
  8500. engineName: results.engine.name || UNKNOWN,
  8501. engineVersion: results.engine.version || UNKNOWN,
  8502. platformArchitecture: results.cpu.architecture || UNKNOWN,
  8503. platformName: convertPlatformName(results.os.name) || UNKNOWN,
  8504. platformVersion: results.os.version || UNKNOWN,
  8505. platformFullVersion: results.os.version || UNKNOWN
  8506. };
  8507. var UserAgentData = uaData;
  8508. var componentRegex = /\./;
  8509. var orRegex = /\|\|/;
  8510. var rangeRegex = /\s+\-\s+/;
  8511. var modifierRegex = /^(<=|<|=|>=|~>|~|>|)?\s*(.+)/;
  8512. var numericRegex = /^(\d*)(.*)/;
  8513. /**
  8514. * Splits input `range` on "||" and returns true if any subrange matches
  8515. * `version`.
  8516. *
  8517. * @param {string} range
  8518. * @param {string} version
  8519. * @returns {boolean}
  8520. */
  8521. function checkOrExpression(range, version) {
  8522. var expressions = range.split(orRegex);
  8523. if (expressions.length > 1) {
  8524. return expressions.some(function (range) {
  8525. return VersionRange.contains(range, version);
  8526. });
  8527. } else {
  8528. range = expressions[0].trim();
  8529. return checkRangeExpression(range, version);
  8530. }
  8531. }
  8532. /**
  8533. * Splits input `range` on " - " (the surrounding whitespace is required) and
  8534. * returns true if version falls between the two operands.
  8535. *
  8536. * @param {string} range
  8537. * @param {string} version
  8538. * @returns {boolean}
  8539. */
  8540. function checkRangeExpression(range, version) {
  8541. var expressions = range.split(rangeRegex);
  8542. !(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;
  8543. if (expressions.length === 1) {
  8544. return checkSimpleExpression(expressions[0], version);
  8545. } else {
  8546. var startVersion = expressions[0],
  8547. endVersion = expressions[1];
  8548. !(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;
  8549. return checkSimpleExpression('>=' + startVersion, version) && checkSimpleExpression('<=' + endVersion, version);
  8550. }
  8551. }
  8552. /**
  8553. * Checks if `range` matches `version`. `range` should be a "simple" range (ie.
  8554. * not a compound range using the " - " or "||" operators).
  8555. *
  8556. * @param {string} range
  8557. * @param {string} version
  8558. * @returns {boolean}
  8559. */
  8560. function checkSimpleExpression(range, version) {
  8561. range = range.trim();
  8562. if (range === '') {
  8563. return true;
  8564. }
  8565. var versionComponents = version.split(componentRegex);
  8566. var _getModifierAndCompon = getModifierAndComponents(range),
  8567. modifier = _getModifierAndCompon.modifier,
  8568. rangeComponents = _getModifierAndCompon.rangeComponents;
  8569. switch (modifier) {
  8570. case '<':
  8571. return checkLessThan(versionComponents, rangeComponents);
  8572. case '<=':
  8573. return checkLessThanOrEqual(versionComponents, rangeComponents);
  8574. case '>=':
  8575. return checkGreaterThanOrEqual(versionComponents, rangeComponents);
  8576. case '>':
  8577. return checkGreaterThan(versionComponents, rangeComponents);
  8578. case '~':
  8579. case '~>':
  8580. return checkApproximateVersion(versionComponents, rangeComponents);
  8581. default:
  8582. return checkEqual(versionComponents, rangeComponents);
  8583. }
  8584. }
  8585. /**
  8586. * Checks whether `a` is less than `b`.
  8587. *
  8588. * @param {array<string>} a
  8589. * @param {array<string>} b
  8590. * @returns {boolean}
  8591. */
  8592. function checkLessThan(a, b) {
  8593. return compareComponents(a, b) === -1;
  8594. }
  8595. /**
  8596. * Checks whether `a` is less than or equal to `b`.
  8597. *
  8598. * @param {array<string>} a
  8599. * @param {array<string>} b
  8600. * @returns {boolean}
  8601. */
  8602. function checkLessThanOrEqual(a, b) {
  8603. var result = compareComponents(a, b);
  8604. return result === -1 || result === 0;
  8605. }
  8606. /**
  8607. * Checks whether `a` is equal to `b`.
  8608. *
  8609. * @param {array<string>} a
  8610. * @param {array<string>} b
  8611. * @returns {boolean}
  8612. */
  8613. function checkEqual(a, b) {
  8614. return compareComponents(a, b) === 0;
  8615. }
  8616. /**
  8617. * Checks whether `a` is greater than or equal to `b`.
  8618. *
  8619. * @param {array<string>} a
  8620. * @param {array<string>} b
  8621. * @returns {boolean}
  8622. */
  8623. function checkGreaterThanOrEqual(a, b) {
  8624. var result = compareComponents(a, b);
  8625. return result === 1 || result === 0;
  8626. }
  8627. /**
  8628. * Checks whether `a` is greater than `b`.
  8629. *
  8630. * @param {array<string>} a
  8631. * @param {array<string>} b
  8632. * @returns {boolean}
  8633. */
  8634. function checkGreaterThan(a, b) {
  8635. return compareComponents(a, b) === 1;
  8636. }
  8637. /**
  8638. * Checks whether `a` is "reasonably close" to `b` (as described in
  8639. * https://www.npmjs.org/doc/misc/semver.html). For example, if `b` is "1.3.1"
  8640. * then "reasonably close" is defined as ">= 1.3.1 and < 1.4".
  8641. *
  8642. * @param {array<string>} a
  8643. * @param {array<string>} b
  8644. * @returns {boolean}
  8645. */
  8646. function checkApproximateVersion(a, b) {
  8647. var lowerBound = b.slice();
  8648. var upperBound = b.slice();
  8649. if (upperBound.length > 1) {
  8650. upperBound.pop();
  8651. }
  8652. var lastIndex = upperBound.length - 1;
  8653. var numeric = parseInt(upperBound[lastIndex], 10);
  8654. if (isNumber(numeric)) {
  8655. upperBound[lastIndex] = numeric + 1 + '';
  8656. }
  8657. return checkGreaterThanOrEqual(a, lowerBound) && checkLessThan(a, upperBound);
  8658. }
  8659. /**
  8660. * Extracts the optional modifier (<, <=, =, >=, >, ~, ~>) and version
  8661. * components from `range`.
  8662. *
  8663. * For example, given `range` ">= 1.2.3" returns an object with a `modifier` of
  8664. * `">="` and `components` of `[1, 2, 3]`.
  8665. *
  8666. * @param {string} range
  8667. * @returns {object}
  8668. */
  8669. function getModifierAndComponents(range) {
  8670. var rangeComponents = range.split(componentRegex);
  8671. var matches = rangeComponents[0].match(modifierRegex);
  8672. !matches ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'expected regex to match but it did not') : invariant_1(false) : void 0;
  8673. return {
  8674. modifier: matches[1],
  8675. rangeComponents: [matches[2]].concat(rangeComponents.slice(1))
  8676. };
  8677. }
  8678. /**
  8679. * Determines if `number` is a number.
  8680. *
  8681. * @param {mixed} number
  8682. * @returns {boolean}
  8683. */
  8684. function isNumber(number) {
  8685. return !isNaN(number) && isFinite(number);
  8686. }
  8687. /**
  8688. * Tests whether `range` is a "simple" version number without any modifiers
  8689. * (">", "~" etc).
  8690. *
  8691. * @param {string} range
  8692. * @returns {boolean}
  8693. */
  8694. function isSimpleVersion(range) {
  8695. return !getModifierAndComponents(range).modifier;
  8696. }
  8697. /**
  8698. * Zero-pads array `array` until it is at least `length` long.
  8699. *
  8700. * @param {array} array
  8701. * @param {number} length
  8702. */
  8703. function zeroPad(array, length) {
  8704. for (var i = array.length; i < length; i++) {
  8705. array[i] = '0';
  8706. }
  8707. }
  8708. /**
  8709. * Normalizes `a` and `b` in preparation for comparison by doing the following:
  8710. *
  8711. * - zero-pads `a` and `b`
  8712. * - marks any "x", "X" or "*" component in `b` as equivalent by zero-ing it out
  8713. * in both `a` and `b`
  8714. * - marks any final "*" component in `b` as a greedy wildcard by zero-ing it
  8715. * and all of its successors in `a`
  8716. *
  8717. * @param {array<string>} a
  8718. * @param {array<string>} b
  8719. * @returns {array<array<string>>}
  8720. */
  8721. function normalizeVersions(a, b) {
  8722. a = a.slice();
  8723. b = b.slice();
  8724. zeroPad(a, b.length);
  8725. // mark "x" and "*" components as equal
  8726. for (var i = 0; i < b.length; i++) {
  8727. var matches = b[i].match(/^[x*]$/i);
  8728. if (matches) {
  8729. b[i] = a[i] = '0';
  8730. // final "*" greedily zeros all remaining components
  8731. if (matches[0] === '*' && i === b.length - 1) {
  8732. for (var j = i; j < a.length; j++) {
  8733. a[j] = '0';
  8734. }
  8735. }
  8736. }
  8737. }
  8738. zeroPad(b, a.length);
  8739. return [a, b];
  8740. }
  8741. /**
  8742. * Returns the numerical -- not the lexicographical -- ordering of `a` and `b`.
  8743. *
  8744. * For example, `10-alpha` is greater than `2-beta`.
  8745. *
  8746. * @param {string} a
  8747. * @param {string} b
  8748. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  8749. * or greater than `b`, respectively
  8750. */
  8751. function compareNumeric(a, b) {
  8752. var aPrefix = a.match(numericRegex)[1];
  8753. var bPrefix = b.match(numericRegex)[1];
  8754. var aNumeric = parseInt(aPrefix, 10);
  8755. var bNumeric = parseInt(bPrefix, 10);
  8756. if (isNumber(aNumeric) && isNumber(bNumeric) && aNumeric !== bNumeric) {
  8757. return compare(aNumeric, bNumeric);
  8758. } else {
  8759. return compare(a, b);
  8760. }
  8761. }
  8762. /**
  8763. * Returns the ordering of `a` and `b`.
  8764. *
  8765. * @param {string|number} a
  8766. * @param {string|number} b
  8767. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  8768. * or greater than `b`, respectively
  8769. */
  8770. function compare(a, b) {
  8771. !(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;
  8772. if (a > b) {
  8773. return 1;
  8774. } else if (a < b) {
  8775. return -1;
  8776. } else {
  8777. return 0;
  8778. }
  8779. }
  8780. /**
  8781. * Compares arrays of version components.
  8782. *
  8783. * @param {array<string>} a
  8784. * @param {array<string>} b
  8785. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  8786. * or greater than `b`, respectively
  8787. */
  8788. function compareComponents(a, b) {
  8789. var _normalizeVersions = normalizeVersions(a, b),
  8790. aNormalized = _normalizeVersions[0],
  8791. bNormalized = _normalizeVersions[1];
  8792. for (var i = 0; i < bNormalized.length; i++) {
  8793. var result = compareNumeric(aNormalized[i], bNormalized[i]);
  8794. if (result) {
  8795. return result;
  8796. }
  8797. }
  8798. return 0;
  8799. }
  8800. var VersionRange = {
  8801. /**
  8802. * Checks whether `version` satisfies the `range` specification.
  8803. *
  8804. * We support a subset of the expressions defined in
  8805. * https://www.npmjs.org/doc/misc/semver.html:
  8806. *
  8807. * version Must match version exactly
  8808. * =version Same as just version
  8809. * >version Must be greater than version
  8810. * >=version Must be greater than or equal to version
  8811. * <version Must be less than version
  8812. * <=version Must be less than or equal to version
  8813. * ~version Must be at least version, but less than the next significant
  8814. * revision above version:
  8815. * "~1.2.3" is equivalent to ">= 1.2.3 and < 1.3"
  8816. * ~>version Equivalent to ~version
  8817. * 1.2.x Must match "1.2.x", where "x" is a wildcard that matches
  8818. * anything
  8819. * 1.2.* Similar to "1.2.x", but "*" in the trailing position is a
  8820. * "greedy" wildcard, so will match any number of additional
  8821. * components:
  8822. * "1.2.*" will match "1.2.1", "1.2.1.1", "1.2.1.1.1" etc
  8823. * * Any version
  8824. * "" (Empty string) Same as *
  8825. * v1 - v2 Equivalent to ">= v1 and <= v2"
  8826. * r1 || r2 Passes if either r1 or r2 are satisfied
  8827. *
  8828. * @param {string} range
  8829. * @param {string} version
  8830. * @returns {boolean}
  8831. */
  8832. contains: function contains(range, version) {
  8833. return checkOrExpression(range.trim(), version.trim());
  8834. }
  8835. };
  8836. var VersionRange_1 = VersionRange;
  8837. /**
  8838. * Copyright (c) 2013-present, Facebook, Inc.
  8839. *
  8840. * This source code is licensed under the MIT license found in the
  8841. * LICENSE file in the root directory of this source tree.
  8842. *
  8843. */
  8844. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  8845. /**
  8846. * Executes the provided `callback` once for each enumerable own property in the
  8847. * object and constructs a new object from the results. The `callback` is
  8848. * invoked with three arguments:
  8849. *
  8850. * - the property value
  8851. * - the property name
  8852. * - the object being traversed
  8853. *
  8854. * Properties that are added after the call to `mapObject` will not be visited
  8855. * by `callback`. If the values of existing properties are changed, the value
  8856. * passed to `callback` will be the value at the time `mapObject` visits them.
  8857. * Properties that are deleted before being visited are not visited.
  8858. *
  8859. * @grep function objectMap()
  8860. * @grep function objMap()
  8861. *
  8862. * @param {?object} object
  8863. * @param {function} callback
  8864. * @param {*} context
  8865. * @return {?object}
  8866. */
  8867. function mapObject(object, callback, context) {
  8868. if (!object) {
  8869. return null;
  8870. }
  8871. var result = {};
  8872. for (var name in object) {
  8873. if (hasOwnProperty$1.call(object, name)) {
  8874. result[name] = callback.call(context, object[name], name, object);
  8875. }
  8876. }
  8877. return result;
  8878. }
  8879. var mapObject_1 = mapObject;
  8880. /**
  8881. * Copyright (c) 2013-present, Facebook, Inc.
  8882. *
  8883. * This source code is licensed under the MIT license found in the
  8884. * LICENSE file in the root directory of this source tree.
  8885. *
  8886. *
  8887. * @typechecks static-only
  8888. */
  8889. /**
  8890. * Memoizes the return value of a function that accepts one string argument.
  8891. */
  8892. function memoizeStringOnly(callback) {
  8893. var cache = {};
  8894. return function (string) {
  8895. if (!cache.hasOwnProperty(string)) {
  8896. cache[string] = callback.call(this, string);
  8897. }
  8898. return cache[string];
  8899. };
  8900. }
  8901. var memoizeStringOnly_1 = memoizeStringOnly;
  8902. /**
  8903. * Checks to see whether `name` and `version` satisfy `query`.
  8904. *
  8905. * @param {string} name Name of the browser, device, engine or platform
  8906. * @param {?string} version Version of the browser, engine or platform
  8907. * @param {string} query Query of form "Name [range expression]"
  8908. * @param {?function} normalizer Optional pre-processor for range expression
  8909. * @return {boolean}
  8910. */
  8911. function compare$1(name, version, query, normalizer) {
  8912. // check for exact match with no version
  8913. if (name === query) {
  8914. return true;
  8915. }
  8916. // check for non-matching names
  8917. if (!query.startsWith(name)) {
  8918. return false;
  8919. }
  8920. // full comparison with version
  8921. var range = query.slice(name.length);
  8922. if (version) {
  8923. range = normalizer ? normalizer(range) : range;
  8924. return VersionRange_1.contains(range, version);
  8925. }
  8926. return false;
  8927. }
  8928. /**
  8929. * Normalizes `version` by stripping any "NT" prefix, but only on the Windows
  8930. * platform.
  8931. *
  8932. * Mimics the stripping performed by the `UserAgentWindowsPlatform` PHP class.
  8933. *
  8934. * @param {string} version
  8935. * @return {string}
  8936. */
  8937. function normalizePlatformVersion(version) {
  8938. if (UserAgentData.platformName === 'Windows') {
  8939. return version.replace(/^\s*NT/, '');
  8940. }
  8941. return version;
  8942. }
  8943. /**
  8944. * Provides client-side access to the authoritative PHP-generated User Agent
  8945. * information supplied by the server.
  8946. */
  8947. var UserAgent = {
  8948. /**
  8949. * Check if the User Agent browser matches `query`.
  8950. *
  8951. * `query` should be a string like "Chrome" or "Chrome > 33".
  8952. *
  8953. * Valid browser names include:
  8954. *
  8955. * - ACCESS NetFront
  8956. * - AOL
  8957. * - Amazon Silk
  8958. * - Android
  8959. * - BlackBerry
  8960. * - BlackBerry PlayBook
  8961. * - Chrome
  8962. * - Chrome for iOS
  8963. * - Chrome frame
  8964. * - Facebook PHP SDK
  8965. * - Facebook for iOS
  8966. * - Firefox
  8967. * - IE
  8968. * - IE Mobile
  8969. * - Mobile Safari
  8970. * - Motorola Internet Browser
  8971. * - Nokia
  8972. * - Openwave Mobile Browser
  8973. * - Opera
  8974. * - Opera Mini
  8975. * - Opera Mobile
  8976. * - Safari
  8977. * - UIWebView
  8978. * - Unknown
  8979. * - webOS
  8980. * - etc...
  8981. *
  8982. * An authoritative list can be found in the PHP `BrowserDetector` class and
  8983. * related classes in the same file (see calls to `new UserAgentBrowser` here:
  8984. * https://fburl.com/50728104).
  8985. *
  8986. * @note Function results are memoized
  8987. *
  8988. * @param {string} query Query of the form "Name [range expression]"
  8989. * @return {boolean}
  8990. */
  8991. isBrowser: function isBrowser(query) {
  8992. return compare$1(UserAgentData.browserName, UserAgentData.browserFullVersion, query);
  8993. },
  8994. /**
  8995. * Check if the User Agent browser uses a 32 or 64 bit architecture.
  8996. *
  8997. * @note Function results are memoized
  8998. *
  8999. * @param {string} query Query of the form "32" or "64".
  9000. * @return {boolean}
  9001. */
  9002. isBrowserArchitecture: function isBrowserArchitecture(query) {
  9003. return compare$1(UserAgentData.browserArchitecture, null, query);
  9004. },
  9005. /**
  9006. * Check if the User Agent device matches `query`.
  9007. *
  9008. * `query` should be a string like "iPhone" or "iPad".
  9009. *
  9010. * Valid device names include:
  9011. *
  9012. * - Kindle
  9013. * - Kindle Fire
  9014. * - Unknown
  9015. * - iPad
  9016. * - iPhone
  9017. * - iPod
  9018. * - etc...
  9019. *
  9020. * An authoritative list can be found in the PHP `DeviceDetector` class and
  9021. * related classes in the same file (see calls to `new UserAgentDevice` here:
  9022. * https://fburl.com/50728332).
  9023. *
  9024. * @note Function results are memoized
  9025. *
  9026. * @param {string} query Query of the form "Name"
  9027. * @return {boolean}
  9028. */
  9029. isDevice: function isDevice(query) {
  9030. return compare$1(UserAgentData.deviceName, null, query);
  9031. },
  9032. /**
  9033. * Check if the User Agent rendering engine matches `query`.
  9034. *
  9035. * `query` should be a string like "WebKit" or "WebKit >= 537".
  9036. *
  9037. * Valid engine names include:
  9038. *
  9039. * - Gecko
  9040. * - Presto
  9041. * - Trident
  9042. * - WebKit
  9043. * - etc...
  9044. *
  9045. * An authoritative list can be found in the PHP `RenderingEngineDetector`
  9046. * class related classes in the same file (see calls to `new
  9047. * UserAgentRenderingEngine` here: https://fburl.com/50728617).
  9048. *
  9049. * @note Function results are memoized
  9050. *
  9051. * @param {string} query Query of the form "Name [range expression]"
  9052. * @return {boolean}
  9053. */
  9054. isEngine: function isEngine(query) {
  9055. return compare$1(UserAgentData.engineName, UserAgentData.engineVersion, query);
  9056. },
  9057. /**
  9058. * Check if the User Agent platform matches `query`.
  9059. *
  9060. * `query` should be a string like "Windows" or "iOS 5 - 6".
  9061. *
  9062. * Valid platform names include:
  9063. *
  9064. * - Android
  9065. * - BlackBerry OS
  9066. * - Java ME
  9067. * - Linux
  9068. * - Mac OS X
  9069. * - Mac OS X Calendar
  9070. * - Mac OS X Internet Account
  9071. * - Symbian
  9072. * - SymbianOS
  9073. * - Windows
  9074. * - Windows Mobile
  9075. * - Windows Phone
  9076. * - iOS
  9077. * - iOS Facebook Integration Account
  9078. * - iOS Facebook Social Sharing UI
  9079. * - webOS
  9080. * - Chrome OS
  9081. * - etc...
  9082. *
  9083. * An authoritative list can be found in the PHP `PlatformDetector` class and
  9084. * related classes in the same file (see calls to `new UserAgentPlatform`
  9085. * here: https://fburl.com/50729226).
  9086. *
  9087. * @note Function results are memoized
  9088. *
  9089. * @param {string} query Query of the form "Name [range expression]"
  9090. * @return {boolean}
  9091. */
  9092. isPlatform: function isPlatform(query) {
  9093. return compare$1(UserAgentData.platformName, UserAgentData.platformFullVersion, query, normalizePlatformVersion);
  9094. },
  9095. /**
  9096. * Check if the User Agent platform is a 32 or 64 bit architecture.
  9097. *
  9098. * @note Function results are memoized
  9099. *
  9100. * @param {string} query Query of the form "32" or "64".
  9101. * @return {boolean}
  9102. */
  9103. isPlatformArchitecture: function isPlatformArchitecture(query) {
  9104. return compare$1(UserAgentData.platformArchitecture, null, query);
  9105. }
  9106. };
  9107. var UserAgent_1 = mapObject_1(UserAgent, memoizeStringOnly_1);
  9108. function _classCallCheck$9(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9109. 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; }
  9110. 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; }
  9111. // In IE, spans with <br> tags render as two newlines. By rendering a span
  9112. // with only a newline character, we can be sure to render a single line.
  9113. var useNewlineChar = UserAgent_1.isBrowser('IE <= 11');
  9114. /**
  9115. * Check whether the node should be considered a newline.
  9116. */
  9117. function isNewline(node) {
  9118. return useNewlineChar ? node.textContent === '\n' : node.tagName === 'BR';
  9119. }
  9120. /**
  9121. * Placeholder elements for empty text content.
  9122. *
  9123. * What is this `data-text` attribute, anyway? It turns out that we need to
  9124. * put an attribute on the lowest-level text node in order to preserve correct
  9125. * spellcheck handling. If the <span> is naked, Chrome and Safari may do
  9126. * bizarre things to do the DOM -- split text nodes, create extra spans, etc.
  9127. * If the <span> has an attribute, this appears not to happen.
  9128. * See http://jsfiddle.net/9khdavod/ for the failure case, and
  9129. * http://jsfiddle.net/7pg143f7/ for the fixed case.
  9130. */
  9131. var NEWLINE_A = useNewlineChar ? React__default.createElement(
  9132. 'span',
  9133. { key: 'A', 'data-text': 'true' },
  9134. '\n'
  9135. ) : React__default.createElement('br', { key: 'A', 'data-text': 'true' });
  9136. var NEWLINE_B = useNewlineChar ? React__default.createElement(
  9137. 'span',
  9138. { key: 'B', 'data-text': 'true' },
  9139. '\n'
  9140. ) : React__default.createElement('br', { key: 'B', 'data-text': 'true' });
  9141. /**
  9142. * The lowest-level component in a `DraftEditor`, the text node component
  9143. * replaces the default React text node implementation. This allows us to
  9144. * perform custom handling of newline behavior and avoid re-rendering text
  9145. * nodes with DOM state that already matches the expectations of our immutable
  9146. * editor state.
  9147. */
  9148. var DraftEditorTextNode = function (_React$Component) {
  9149. _inherits$6(DraftEditorTextNode, _React$Component);
  9150. function DraftEditorTextNode(props) {
  9151. _classCallCheck$9(this, DraftEditorTextNode);
  9152. // By flipping this flag, we also keep flipping keys which forces
  9153. // React to remount this node every time it rerenders.
  9154. var _this = _possibleConstructorReturn$6(this, _React$Component.call(this, props));
  9155. _this._forceFlag = false;
  9156. return _this;
  9157. }
  9158. DraftEditorTextNode.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  9159. var node = reactDom.findDOMNode(this);
  9160. var shouldBeNewline = nextProps.children === '';
  9161. !(node instanceof Element) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'node is not an Element') : invariant_1(false) : void 0;
  9162. if (shouldBeNewline) {
  9163. return !isNewline(node);
  9164. }
  9165. return node.textContent !== nextProps.children;
  9166. };
  9167. DraftEditorTextNode.prototype.componentDidMount = function componentDidMount() {
  9168. this._forceFlag = !this._forceFlag;
  9169. };
  9170. DraftEditorTextNode.prototype.componentDidUpdate = function componentDidUpdate() {
  9171. this._forceFlag = !this._forceFlag;
  9172. };
  9173. DraftEditorTextNode.prototype.render = function render() {
  9174. if (this.props.children === '') {
  9175. return this._forceFlag ? NEWLINE_A : NEWLINE_B;
  9176. }
  9177. return React__default.createElement(
  9178. 'span',
  9179. { key: this._forceFlag ? 'A' : 'B', 'data-text': 'true' },
  9180. this.props.children
  9181. );
  9182. };
  9183. return DraftEditorTextNode;
  9184. }(React__default.Component);
  9185. var DraftEditorTextNode_react = DraftEditorTextNode;
  9186. /**
  9187. * Copyright (c) 2013-present, Facebook, Inc.
  9188. * All rights reserved.
  9189. *
  9190. * This source code is licensed under the BSD-style license found in the
  9191. * LICENSE file in the root directory of this source tree. An additional grant
  9192. * of patent rights can be found in the PATENTS file in the same directory.
  9193. *
  9194. * @providesModule DraftJsDebugLogging
  9195. */
  9196. var DraftJsDebugLogging = {
  9197. logSelectionStateFailure: function logSelectionStateFailure() {
  9198. return null;
  9199. }
  9200. };
  9201. /**
  9202. * Copyright (c) 2013-present, Facebook, Inc.
  9203. *
  9204. * This source code is licensed under the MIT license found in the
  9205. * LICENSE file in the root directory of this source tree.
  9206. *
  9207. * @typechecks
  9208. */
  9209. /**
  9210. * @param {*} object The object to check.
  9211. * @return {boolean} Whether or not the object is a DOM node.
  9212. */
  9213. function isNode(object) {
  9214. var doc = object ? object.ownerDocument || object : document;
  9215. var defaultView = doc.defaultView || window;
  9216. return !!(object && (typeof defaultView.Node === 'function' ? object instanceof defaultView.Node : typeof object === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string'));
  9217. }
  9218. var isNode_1 = isNode;
  9219. /**
  9220. * Copyright (c) 2013-present, Facebook, Inc.
  9221. *
  9222. * This source code is licensed under the MIT license found in the
  9223. * LICENSE file in the root directory of this source tree.
  9224. *
  9225. * @typechecks
  9226. */
  9227. /**
  9228. * @param {*} object The object to check.
  9229. * @return {boolean} Whether or not the object is a DOM text node.
  9230. */
  9231. function isTextNode(object) {
  9232. return isNode_1(object) && object.nodeType == 3;
  9233. }
  9234. var isTextNode_1 = isTextNode;
  9235. /**
  9236. * Copyright (c) 2013-present, Facebook, Inc.
  9237. *
  9238. * This source code is licensed under the MIT license found in the
  9239. * LICENSE file in the root directory of this source tree.
  9240. *
  9241. *
  9242. */
  9243. /*eslint-disable no-bitwise */
  9244. /**
  9245. * Checks if a given DOM node contains or is another DOM node.
  9246. */
  9247. function containsNode(outerNode, innerNode) {
  9248. if (!outerNode || !innerNode) {
  9249. return false;
  9250. } else if (outerNode === innerNode) {
  9251. return true;
  9252. } else if (isTextNode_1(outerNode)) {
  9253. return false;
  9254. } else if (isTextNode_1(innerNode)) {
  9255. return containsNode(outerNode, innerNode.parentNode);
  9256. } else if ('contains' in outerNode) {
  9257. return outerNode.contains(innerNode);
  9258. } else if (outerNode.compareDocumentPosition) {
  9259. return !!(outerNode.compareDocumentPosition(innerNode) & 16);
  9260. } else {
  9261. return false;
  9262. }
  9263. }
  9264. var containsNode_1 = containsNode;
  9265. /**
  9266. * Copyright (c) 2013-present, Facebook, Inc.
  9267. *
  9268. * This source code is licensed under the MIT license found in the
  9269. * LICENSE file in the root directory of this source tree.
  9270. *
  9271. * @typechecks
  9272. */
  9273. /* eslint-disable fb-www/typeof-undefined */
  9274. /**
  9275. * Same as document.activeElement but wraps in a try-catch block. In IE it is
  9276. * not safe to call document.activeElement if there is nothing focused.
  9277. *
  9278. * The activeElement will be null only if the document or document body is not
  9279. * yet defined.
  9280. *
  9281. * @param {?DOMDocument} doc Defaults to current document.
  9282. * @return {?DOMElement}
  9283. */
  9284. function getActiveElement(doc) /*?DOMElement*/{
  9285. doc = doc || (typeof document !== 'undefined' ? document : undefined);
  9286. if (typeof doc === 'undefined') {
  9287. return null;
  9288. }
  9289. try {
  9290. return doc.activeElement || doc.body;
  9291. } catch (e) {
  9292. return doc.body;
  9293. }
  9294. }
  9295. var getActiveElement_1 = getActiveElement;
  9296. function getAnonymizedDOM(node, getNodeLabels) {
  9297. if (!node) {
  9298. return '[empty]';
  9299. }
  9300. var anonymized = anonymizeTextWithin(node, getNodeLabels);
  9301. if (anonymized.nodeType === Node.TEXT_NODE) {
  9302. return anonymized.textContent;
  9303. }
  9304. !(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;
  9305. return anonymized.outerHTML;
  9306. }
  9307. function anonymizeTextWithin(node, getNodeLabels) {
  9308. var labels = getNodeLabels !== undefined ? getNodeLabels(node) : [];
  9309. if (node.nodeType === Node.TEXT_NODE) {
  9310. var length = node.textContent.length;
  9311. return document.createTextNode('[text ' + length + (labels.length ? ' | ' + labels.join(', ') : '') + ']');
  9312. }
  9313. var clone = node.cloneNode();
  9314. if (clone.nodeType === 1 && labels.length) {
  9315. clone.setAttribute('data-labels', labels.join(', '));
  9316. }
  9317. var childNodes = node.childNodes;
  9318. for (var ii = 0; ii < childNodes.length; ii++) {
  9319. clone.appendChild(anonymizeTextWithin(childNodes[ii], getNodeLabels));
  9320. }
  9321. return clone;
  9322. }
  9323. function getAnonymizedEditorDOM(node, getNodeLabels) {
  9324. // grabbing the DOM content of the Draft editor
  9325. var currentNode = node;
  9326. while (currentNode) {
  9327. if (currentNode instanceof Element && currentNode.hasAttribute('contenteditable')) {
  9328. // found the Draft editor container
  9329. return getAnonymizedDOM(currentNode, getNodeLabels);
  9330. } else {
  9331. currentNode = currentNode.parentNode;
  9332. }
  9333. }
  9334. return 'Could not find contentEditable parent of node';
  9335. }
  9336. function getNodeLength(node) {
  9337. return node.nodeValue === null ? node.childNodes.length : node.nodeValue.length;
  9338. }
  9339. /**
  9340. * In modern non-IE browsers, we can support both forward and backward
  9341. * selections.
  9342. *
  9343. * Note: IE10+ supports the Selection object, but it does not support
  9344. * the `extend` method, which means that even in modern IE, it's not possible
  9345. * to programatically create a backward selection. Thus, for all IE
  9346. * versions, we use the old IE API to create our selections.
  9347. */
  9348. function setDraftEditorSelection(selectionState, node, blockKey, nodeStart, nodeEnd) {
  9349. // It's possible that the editor has been removed from the DOM but
  9350. // our selection code doesn't know it yet. Forcing selection in
  9351. // this case may lead to errors, so just bail now.
  9352. if (!containsNode_1(document.documentElement, node)) {
  9353. return;
  9354. }
  9355. var selection = styleInject_es.commonjsGlobal.getSelection();
  9356. var anchorKey = selectionState.getAnchorKey();
  9357. var anchorOffset = selectionState.getAnchorOffset();
  9358. var focusKey = selectionState.getFocusKey();
  9359. var focusOffset = selectionState.getFocusOffset();
  9360. var isBackward = selectionState.getIsBackward();
  9361. // IE doesn't support backward selection. Swap key/offset pairs.
  9362. if (!selection.extend && isBackward) {
  9363. var tempKey = anchorKey;
  9364. var tempOffset = anchorOffset;
  9365. anchorKey = focusKey;
  9366. anchorOffset = focusOffset;
  9367. focusKey = tempKey;
  9368. focusOffset = tempOffset;
  9369. isBackward = false;
  9370. }
  9371. var hasAnchor = anchorKey === blockKey && nodeStart <= anchorOffset && nodeEnd >= anchorOffset;
  9372. var hasFocus = focusKey === blockKey && nodeStart <= focusOffset && nodeEnd >= focusOffset;
  9373. // If the selection is entirely bound within this node, set the selection
  9374. // and be done.
  9375. if (hasAnchor && hasFocus) {
  9376. selection.removeAllRanges();
  9377. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  9378. addFocusToSelection(selection, node, focusOffset - nodeStart, selectionState);
  9379. return;
  9380. }
  9381. if (!isBackward) {
  9382. // If the anchor is within this node, set the range start.
  9383. if (hasAnchor) {
  9384. selection.removeAllRanges();
  9385. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  9386. }
  9387. // If the focus is within this node, we can assume that we have
  9388. // already set the appropriate start range on the selection, and
  9389. // can simply extend the selection.
  9390. if (hasFocus) {
  9391. addFocusToSelection(selection, node, focusOffset - nodeStart, selectionState);
  9392. }
  9393. } else {
  9394. // If this node has the focus, set the selection range to be a
  9395. // collapsed range beginning here. Later, when we encounter the anchor,
  9396. // we'll use this information to extend the selection.
  9397. if (hasFocus) {
  9398. selection.removeAllRanges();
  9399. addPointToSelection(selection, node, focusOffset - nodeStart, selectionState);
  9400. }
  9401. // If this node has the anchor, we may assume that the correct
  9402. // focus information is already stored on the selection object.
  9403. // We keep track of it, reset the selection range, and extend it
  9404. // back to the focus point.
  9405. if (hasAnchor) {
  9406. var storedFocusNode = selection.focusNode;
  9407. var storedFocusOffset = selection.focusOffset;
  9408. selection.removeAllRanges();
  9409. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  9410. addFocusToSelection(selection, storedFocusNode, storedFocusOffset, selectionState);
  9411. }
  9412. }
  9413. }
  9414. /**
  9415. * Extend selection towards focus point.
  9416. */
  9417. function addFocusToSelection(selection, node, offset, selectionState) {
  9418. var activeElement = getActiveElement_1();
  9419. if (selection.extend && containsNode_1(activeElement, node)) {
  9420. // If `extend` is called while another element has focus, an error is
  9421. // thrown. We therefore disable `extend` if the active element is somewhere
  9422. // other than the node we are selecting. This should only occur in Firefox,
  9423. // since it is the only browser to support multiple selections.
  9424. // See https://bugzilla.mozilla.org/show_bug.cgi?id=921444.
  9425. // logging to catch bug that is being reported in t16250795
  9426. if (offset > getNodeLength(node)) {
  9427. // the call to 'selection.extend' is about to throw
  9428. DraftJsDebugLogging.logSelectionStateFailure({
  9429. anonymizedDom: getAnonymizedEditorDOM(node),
  9430. extraParams: JSON.stringify({ offset: offset }),
  9431. selectionState: JSON.stringify(selectionState.toJS())
  9432. });
  9433. }
  9434. // logging to catch bug that is being reported in t18110632
  9435. var nodeWasFocus = node === selection.focusNode;
  9436. try {
  9437. selection.extend(node, offset);
  9438. } catch (e) {
  9439. DraftJsDebugLogging.logSelectionStateFailure({
  9440. anonymizedDom: getAnonymizedEditorDOM(node, function (n) {
  9441. var labels = [];
  9442. if (n === activeElement) {
  9443. labels.push('active element');
  9444. }
  9445. if (n === selection.anchorNode) {
  9446. labels.push('selection anchor node');
  9447. }
  9448. if (n === selection.focusNode) {
  9449. labels.push('selection focus node');
  9450. }
  9451. return labels;
  9452. }),
  9453. extraParams: JSON.stringify({
  9454. activeElementName: activeElement ? activeElement.nodeName : null,
  9455. nodeIsFocus: node === selection.focusNode,
  9456. nodeWasFocus: nodeWasFocus,
  9457. selectionRangeCount: selection.rangeCount,
  9458. selectionAnchorNodeName: selection.anchorNode ? selection.anchorNode.nodeName : null,
  9459. selectionAnchorOffset: selection.anchorOffset,
  9460. selectionFocusNodeName: selection.focusNode ? selection.focusNode.nodeName : null,
  9461. selectionFocusOffset: selection.focusOffset,
  9462. message: e ? '' + e : null,
  9463. offset: offset
  9464. }, null, 2),
  9465. selectionState: JSON.stringify(selectionState.toJS(), null, 2)
  9466. });
  9467. // allow the error to be thrown -
  9468. // better than continuing in a broken state
  9469. throw e;
  9470. }
  9471. } else {
  9472. // IE doesn't support extend. This will mean no backward selection.
  9473. // Extract the existing selection range and add focus to it.
  9474. // Additionally, clone the selection range. IE11 throws an
  9475. // InvalidStateError when attempting to access selection properties
  9476. // after the range is detached.
  9477. var range = selection.getRangeAt(0);
  9478. range.setEnd(node, offset);
  9479. selection.addRange(range.cloneRange());
  9480. }
  9481. }
  9482. function addPointToSelection(selection, node, offset, selectionState) {
  9483. var range = document.createRange();
  9484. // logging to catch bug that is being reported in t16250795
  9485. if (offset > getNodeLength(node)) {
  9486. // in this case we know that the call to 'range.setStart' is about to throw
  9487. DraftJsDebugLogging.logSelectionStateFailure({
  9488. anonymizedDom: getAnonymizedEditorDOM(node),
  9489. extraParams: JSON.stringify({ offset: offset }),
  9490. selectionState: JSON.stringify(selectionState.toJS())
  9491. });
  9492. }
  9493. range.setStart(node, offset);
  9494. selection.addRange(range);
  9495. }
  9496. var setDraftEditorSelection_1 = setDraftEditorSelection;
  9497. function _classCallCheck$a(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9498. 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; }
  9499. 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; }
  9500. /**
  9501. * All leaf nodes in the editor are spans with single text nodes. Leaf
  9502. * elements are styled based on the merging of an optional custom style map
  9503. * and a default style map.
  9504. *
  9505. * `DraftEditorLeaf` also provides a wrapper for calling into the imperative
  9506. * DOM Selection API. In this way, top-level components can declaratively
  9507. * maintain the selection state.
  9508. */
  9509. var DraftEditorLeaf = function (_React$Component) {
  9510. _inherits$7(DraftEditorLeaf, _React$Component);
  9511. function DraftEditorLeaf() {
  9512. _classCallCheck$a(this, DraftEditorLeaf);
  9513. return _possibleConstructorReturn$7(this, _React$Component.apply(this, arguments));
  9514. }
  9515. DraftEditorLeaf.prototype._setSelection = function _setSelection() {
  9516. var selection = this.props.selection;
  9517. // If selection state is irrelevant to the parent block, no-op.
  9518. if (selection == null || !selection.getHasFocus()) {
  9519. return;
  9520. }
  9521. var _props = this.props,
  9522. block = _props.block,
  9523. start = _props.start,
  9524. text = _props.text;
  9525. var blockKey = block.getKey();
  9526. var end = start + text.length;
  9527. if (!selection.hasEdgeWithin(blockKey, start, end)) {
  9528. return;
  9529. }
  9530. // Determine the appropriate target node for selection. If the child
  9531. // is not a text node, it is a <br /> spacer. In this case, use the
  9532. // <span> itself as the selection target.
  9533. var node = reactDom.findDOMNode(this);
  9534. !node ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing node') : invariant_1(false) : void 0;
  9535. var child = node.firstChild;
  9536. !child ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing child') : invariant_1(false) : void 0;
  9537. var targetNode = void 0;
  9538. if (child.nodeType === Node.TEXT_NODE) {
  9539. targetNode = child;
  9540. } else if (child.tagName === 'BR') {
  9541. targetNode = node;
  9542. } else {
  9543. targetNode = child.firstChild;
  9544. !targetNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing targetNode') : invariant_1(false) : void 0;
  9545. }
  9546. setDraftEditorSelection_1(selection, targetNode, blockKey, start, end);
  9547. };
  9548. /**
  9549. * By making individual leaf instances aware of their context within
  9550. * the text of the editor, we can set our selection range more
  9551. * easily than we could in the non-React world.
  9552. *
  9553. * Note that this depends on our maintaining tight control over the
  9554. * DOM structure of the DraftEditor component. If leaves had multiple
  9555. * text nodes, this would be harder.
  9556. */
  9557. DraftEditorLeaf.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  9558. var leafNode = reactDom.findDOMNode(this.leaf);
  9559. !leafNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing leafNode') : invariant_1(false) : void 0;
  9560. return leafNode.textContent !== nextProps.text || nextProps.styleSet !== this.props.styleSet || nextProps.forceSelection;
  9561. };
  9562. DraftEditorLeaf.prototype.componentDidUpdate = function componentDidUpdate() {
  9563. this._setSelection();
  9564. };
  9565. DraftEditorLeaf.prototype.componentDidMount = function componentDidMount() {
  9566. this._setSelection();
  9567. };
  9568. DraftEditorLeaf.prototype.render = function render() {
  9569. var _this2 = this;
  9570. var block = this.props.block;
  9571. var text = this.props.text;
  9572. // If the leaf is at the end of its block and ends in a soft newline, append
  9573. // an extra line feed character. Browsers collapse trailing newline
  9574. // characters, which leaves the cursor in the wrong place after a
  9575. // shift+enter. The extra character repairs this.
  9576. if (text.endsWith('\n') && this.props.isLast) {
  9577. text += '\n';
  9578. }
  9579. var _props2 = this.props,
  9580. customStyleMap = _props2.customStyleMap,
  9581. customStyleFn = _props2.customStyleFn,
  9582. offsetKey = _props2.offsetKey,
  9583. styleSet = _props2.styleSet;
  9584. var styleObj = styleSet.reduce(function (map, styleName) {
  9585. var mergedStyles = {};
  9586. var style = customStyleMap[styleName];
  9587. if (style !== undefined && map.textDecoration !== style.textDecoration) {
  9588. // .trim() is necessary for IE9/10/11 and Edge
  9589. mergedStyles.textDecoration = [map.textDecoration, style.textDecoration].join(' ').trim();
  9590. }
  9591. return objectAssign(map, style, mergedStyles);
  9592. }, {});
  9593. if (customStyleFn) {
  9594. var newStyles = customStyleFn(styleSet, block);
  9595. styleObj = objectAssign(styleObj, newStyles);
  9596. }
  9597. return React__default.createElement(
  9598. 'span',
  9599. {
  9600. 'data-offset-key': offsetKey,
  9601. ref: function ref(_ref) {
  9602. return _this2.leaf = _ref;
  9603. },
  9604. style: styleObj },
  9605. React__default.createElement(
  9606. DraftEditorTextNode_react,
  9607. null,
  9608. text
  9609. )
  9610. );
  9611. };
  9612. return DraftEditorLeaf;
  9613. }(React__default.Component);
  9614. var DraftEditorLeaf_react = DraftEditorLeaf;
  9615. /**
  9616. * Copyright (c) 2013-present, Facebook, Inc.
  9617. * All rights reserved.
  9618. *
  9619. * This source code is licensed under the BSD-style license found in the
  9620. * LICENSE file in the root directory of this source tree. An additional grant
  9621. * of patent rights can be found in the PATENTS file in the same directory.
  9622. *
  9623. * @providesModule DraftOffsetKey
  9624. * @format
  9625. *
  9626. */
  9627. var KEY_DELIMITER = '-';
  9628. var DraftOffsetKey = {
  9629. encode: function encode(blockKey, decoratorKey, leafKey) {
  9630. return blockKey + KEY_DELIMITER + decoratorKey + KEY_DELIMITER + leafKey;
  9631. },
  9632. decode: function decode(offsetKey) {
  9633. var _offsetKey$split = offsetKey.split(KEY_DELIMITER),
  9634. blockKey = _offsetKey$split[0],
  9635. decoratorKey = _offsetKey$split[1],
  9636. leafKey = _offsetKey$split[2];
  9637. return {
  9638. blockKey: blockKey,
  9639. decoratorKey: parseInt(decoratorKey, 10),
  9640. leafKey: parseInt(leafKey, 10)
  9641. };
  9642. }
  9643. };
  9644. var DraftOffsetKey_1 = DraftOffsetKey;
  9645. /**
  9646. * Copyright (c) 2013-present, Facebook, Inc.
  9647. *
  9648. * This source code is licensed under the MIT license found in the
  9649. * LICENSE file in the root directory of this source tree.
  9650. *
  9651. */
  9652. /**
  9653. * @param {DOMElement} element
  9654. * @param {DOMDocument} doc
  9655. * @return {boolean}
  9656. */
  9657. function _isViewportScrollElement(element, doc) {
  9658. return !!doc && (element === doc.documentElement || element === doc.body);
  9659. }
  9660. /**
  9661. * Scroll Module. This class contains 4 simple static functions
  9662. * to be used to access Element.scrollTop/scrollLeft properties.
  9663. * To solve the inconsistencies between browsers when either
  9664. * document.body or document.documentElement is supplied,
  9665. * below logic will be used to alleviate the issue:
  9666. *
  9667. * 1. If 'element' is either 'document.body' or 'document.documentElement,
  9668. * get whichever element's 'scroll{Top,Left}' is larger.
  9669. * 2. If 'element' is either 'document.body' or 'document.documentElement',
  9670. * set the 'scroll{Top,Left}' on both elements.
  9671. */
  9672. var Scroll = {
  9673. /**
  9674. * @param {DOMElement} element
  9675. * @return {number}
  9676. */
  9677. getTop: function getTop(element) {
  9678. var doc = element.ownerDocument;
  9679. return _isViewportScrollElement(element, doc) ?
  9680. // In practice, they will either both have the same value,
  9681. // or one will be zero and the other will be the scroll position
  9682. // of the viewport. So we can use `X || Y` instead of `Math.max(X, Y)`
  9683. doc.body.scrollTop || doc.documentElement.scrollTop : element.scrollTop;
  9684. },
  9685. /**
  9686. * @param {DOMElement} element
  9687. * @param {number} newTop
  9688. */
  9689. setTop: function setTop(element, newTop) {
  9690. var doc = element.ownerDocument;
  9691. if (_isViewportScrollElement(element, doc)) {
  9692. doc.body.scrollTop = doc.documentElement.scrollTop = newTop;
  9693. } else {
  9694. element.scrollTop = newTop;
  9695. }
  9696. },
  9697. /**
  9698. * @param {DOMElement} element
  9699. * @return {number}
  9700. */
  9701. getLeft: function getLeft(element) {
  9702. var doc = element.ownerDocument;
  9703. return _isViewportScrollElement(element, doc) ? doc.body.scrollLeft || doc.documentElement.scrollLeft : element.scrollLeft;
  9704. },
  9705. /**
  9706. * @param {DOMElement} element
  9707. * @param {number} newLeft
  9708. */
  9709. setLeft: function setLeft(element, newLeft) {
  9710. var doc = element.ownerDocument;
  9711. if (_isViewportScrollElement(element, doc)) {
  9712. doc.body.scrollLeft = doc.documentElement.scrollLeft = newLeft;
  9713. } else {
  9714. element.scrollLeft = newLeft;
  9715. }
  9716. }
  9717. };
  9718. var Scroll_1 = Scroll;
  9719. /**
  9720. * Copyright (c) 2013-present, Facebook, Inc.
  9721. *
  9722. * This source code is licensed under the MIT license found in the
  9723. * LICENSE file in the root directory of this source tree.
  9724. *
  9725. * @typechecks
  9726. */
  9727. var _hyphenPattern = /-(.)/g;
  9728. /**
  9729. * Camelcases a hyphenated string, for example:
  9730. *
  9731. * > camelize('background-color')
  9732. * < "backgroundColor"
  9733. *
  9734. * @param {string} string
  9735. * @return {string}
  9736. */
  9737. function camelize(string) {
  9738. return string.replace(_hyphenPattern, function (_, character) {
  9739. return character.toUpperCase();
  9740. });
  9741. }
  9742. var camelize_1 = camelize;
  9743. /**
  9744. * Copyright (c) 2013-present, Facebook, Inc.
  9745. *
  9746. * This source code is licensed under the MIT license found in the
  9747. * LICENSE file in the root directory of this source tree.
  9748. *
  9749. * @typechecks
  9750. */
  9751. var _uppercasePattern = /([A-Z])/g;
  9752. /**
  9753. * Hyphenates a camelcased string, for example:
  9754. *
  9755. * > hyphenate('backgroundColor')
  9756. * < "background-color"
  9757. *
  9758. * For CSS style names, use `hyphenateStyleName` instead which works properly
  9759. * with all vendor prefixes, including `ms`.
  9760. *
  9761. * @param {string} string
  9762. * @return {string}
  9763. */
  9764. function hyphenate(string) {
  9765. return string.replace(_uppercasePattern, '-$1').toLowerCase();
  9766. }
  9767. var hyphenate_1 = hyphenate;
  9768. /**
  9769. * Copyright (c) 2013-present, Facebook, Inc.
  9770. *
  9771. * This source code is licensed under the MIT license found in the
  9772. * LICENSE file in the root directory of this source tree.
  9773. *
  9774. * @typechecks
  9775. */
  9776. function asString(value) /*?string*/{
  9777. return value == null ? value : String(value);
  9778. }
  9779. function getStyleProperty( /*DOMNode*/node, /*string*/name) /*?string*/{
  9780. var computedStyle = void 0;
  9781. // W3C Standard
  9782. if (window.getComputedStyle) {
  9783. // In certain cases such as within an iframe in FF3, this returns null.
  9784. computedStyle = window.getComputedStyle(node, null);
  9785. if (computedStyle) {
  9786. return asString(computedStyle.getPropertyValue(hyphenate_1(name)));
  9787. }
  9788. }
  9789. // Safari
  9790. if (document.defaultView && document.defaultView.getComputedStyle) {
  9791. computedStyle = document.defaultView.getComputedStyle(node, null);
  9792. // A Safari bug causes this to return null for `display: none` elements.
  9793. if (computedStyle) {
  9794. return asString(computedStyle.getPropertyValue(hyphenate_1(name)));
  9795. }
  9796. if (name === 'display') {
  9797. return 'none';
  9798. }
  9799. }
  9800. // Internet Explorer
  9801. if (node.currentStyle) {
  9802. if (name === 'float') {
  9803. return asString(node.currentStyle.cssFloat || node.currentStyle.styleFloat);
  9804. }
  9805. return asString(node.currentStyle[camelize_1(name)]);
  9806. }
  9807. return asString(node.style && node.style[camelize_1(name)]);
  9808. }
  9809. var getStyleProperty_1 = getStyleProperty;
  9810. /**
  9811. * Copyright (c) 2013-present, Facebook, Inc.
  9812. *
  9813. * This source code is licensed under the MIT license found in the
  9814. * LICENSE file in the root directory of this source tree.
  9815. *
  9816. * @typechecks
  9817. */
  9818. /**
  9819. * @param {DOMNode} element [description]
  9820. * @param {string} name Overflow style property name.
  9821. * @return {boolean} True if the supplied ndoe is scrollable.
  9822. */
  9823. function _isNodeScrollable(element, name) {
  9824. var overflow = Style.get(element, name);
  9825. return overflow === 'auto' || overflow === 'scroll';
  9826. }
  9827. /**
  9828. * Utilities for querying and mutating style properties.
  9829. */
  9830. var Style = {
  9831. /**
  9832. * Gets the style property for the supplied node. This will return either the
  9833. * computed style, if available, or the declared style.
  9834. *
  9835. * @param {DOMNode} node
  9836. * @param {string} name Style property name.
  9837. * @return {?string} Style property value.
  9838. */
  9839. get: getStyleProperty_1,
  9840. /**
  9841. * Determines the nearest ancestor of a node that is scrollable.
  9842. *
  9843. * NOTE: This can be expensive if used repeatedly or on a node nested deeply.
  9844. *
  9845. * @param {?DOMNode} node Node from which to start searching.
  9846. * @return {?DOMWindow|DOMElement} Scroll parent of the supplied node.
  9847. */
  9848. getScrollParent: function getScrollParent(node) {
  9849. if (!node) {
  9850. return null;
  9851. }
  9852. var ownerDocument = node.ownerDocument;
  9853. while (node && node !== ownerDocument.body) {
  9854. if (_isNodeScrollable(node, 'overflow') || _isNodeScrollable(node, 'overflowY') || _isNodeScrollable(node, 'overflowX')) {
  9855. return node;
  9856. }
  9857. node = node.parentNode;
  9858. }
  9859. return ownerDocument.defaultView || ownerDocument.parentWindow;
  9860. }
  9861. };
  9862. var Style_1 = Style;
  9863. /**
  9864. * Copyright (c) 2013-present, Facebook, Inc.
  9865. *
  9866. * This source code is licensed under the MIT license found in the
  9867. * LICENSE file in the root directory of this source tree.
  9868. *
  9869. * @typechecks
  9870. */
  9871. /**
  9872. * Gets an element's bounding rect in pixels relative to the viewport.
  9873. *
  9874. * @param {DOMElement} elem
  9875. * @return {object}
  9876. */
  9877. function getElementRect(elem) {
  9878. var docElem = elem.ownerDocument.documentElement;
  9879. // FF 2, Safari 3 and Opera 9.5- do not support getBoundingClientRect().
  9880. // IE9- will throw if the element is not in the document.
  9881. if (!('getBoundingClientRect' in elem) || !containsNode_1(docElem, elem)) {
  9882. return {
  9883. left: 0,
  9884. right: 0,
  9885. top: 0,
  9886. bottom: 0
  9887. };
  9888. }
  9889. // Subtracts clientTop/Left because IE8- added a 2px border to the
  9890. // <html> element (see http://fburl.com/1493213). IE 7 in
  9891. // Quicksmode does not report clientLeft/clientTop so there
  9892. // will be an unaccounted offset of 2px when in quirksmode
  9893. var rect = elem.getBoundingClientRect();
  9894. return {
  9895. left: Math.round(rect.left) - docElem.clientLeft,
  9896. right: Math.round(rect.right) - docElem.clientLeft,
  9897. top: Math.round(rect.top) - docElem.clientTop,
  9898. bottom: Math.round(rect.bottom) - docElem.clientTop
  9899. };
  9900. }
  9901. var getElementRect_1 = getElementRect;
  9902. /**
  9903. * Copyright (c) 2013-present, Facebook, Inc.
  9904. *
  9905. * This source code is licensed under the MIT license found in the
  9906. * LICENSE file in the root directory of this source tree.
  9907. *
  9908. * @typechecks
  9909. */
  9910. /**
  9911. * Gets an element's position in pixels relative to the viewport. The returned
  9912. * object represents the position of the element's top left corner.
  9913. *
  9914. * @param {DOMElement} element
  9915. * @return {object}
  9916. */
  9917. function getElementPosition(element) {
  9918. var rect = getElementRect_1(element);
  9919. return {
  9920. x: rect.left,
  9921. y: rect.top,
  9922. width: rect.right - rect.left,
  9923. height: rect.bottom - rect.top
  9924. };
  9925. }
  9926. var getElementPosition_1 = getElementPosition;
  9927. /**
  9928. * Copyright (c) 2013-present, Facebook, Inc.
  9929. *
  9930. * This source code is licensed under the MIT license found in the
  9931. * LICENSE file in the root directory of this source tree.
  9932. *
  9933. * @typechecks
  9934. */
  9935. var isWebkit = typeof navigator !== 'undefined' && navigator.userAgent.indexOf('AppleWebKit') > -1;
  9936. /**
  9937. * Gets the element with the document scroll properties such as `scrollLeft` and
  9938. * `scrollHeight`. This may differ across different browsers.
  9939. *
  9940. * NOTE: The return value can be null if the DOM is not yet ready.
  9941. *
  9942. * @param {?DOMDocument} doc Defaults to current document.
  9943. * @return {?DOMElement}
  9944. */
  9945. function getDocumentScrollElement(doc) {
  9946. doc = doc || document;
  9947. if (doc.scrollingElement) {
  9948. return doc.scrollingElement;
  9949. }
  9950. return !isWebkit && doc.compatMode === 'CSS1Compat' ? doc.documentElement : doc.body;
  9951. }
  9952. var getDocumentScrollElement_1 = getDocumentScrollElement;
  9953. /**
  9954. * Copyright (c) 2013-present, Facebook, Inc.
  9955. *
  9956. * This source code is licensed under the MIT license found in the
  9957. * LICENSE file in the root directory of this source tree.
  9958. *
  9959. * @typechecks
  9960. */
  9961. /**
  9962. * Gets the scroll position of the supplied element or window.
  9963. *
  9964. * The return values are unbounded, unlike `getScrollPosition`. This means they
  9965. * may be negative or exceed the element boundaries (which is possible using
  9966. * inertial scrolling).
  9967. *
  9968. * @param {DOMWindow|DOMElement} scrollable
  9969. * @return {object} Map with `x` and `y` keys.
  9970. */
  9971. function getUnboundedScrollPosition(scrollable) {
  9972. if (scrollable.Window && scrollable instanceof scrollable.Window) {
  9973. return {
  9974. x: scrollable.pageXOffset || scrollable.document.documentElement.scrollLeft,
  9975. y: scrollable.pageYOffset || scrollable.document.documentElement.scrollTop
  9976. };
  9977. }
  9978. return {
  9979. x: scrollable.scrollLeft,
  9980. y: scrollable.scrollTop
  9981. };
  9982. }
  9983. var getUnboundedScrollPosition_1 = getUnboundedScrollPosition;
  9984. /**
  9985. * Gets the scroll position of the supplied element or window.
  9986. *
  9987. * The return values are bounded. This means that if the scroll position is
  9988. * negative or exceeds the element boundaries (which is possible using inertial
  9989. * scrolling), you will get zero or the maximum scroll position, respectively.
  9990. *
  9991. * If you need the unbound scroll position, use `getUnboundedScrollPosition`.
  9992. *
  9993. * @param {DOMWindow|DOMElement} scrollable
  9994. * @return {object} Map with `x` and `y` keys.
  9995. */
  9996. function getScrollPosition(scrollable) {
  9997. var documentScrollElement = getDocumentScrollElement_1(scrollable.ownerDocument || scrollable.document);
  9998. if (scrollable.Window && scrollable instanceof scrollable.Window) {
  9999. scrollable = documentScrollElement;
  10000. }
  10001. var scrollPosition = getUnboundedScrollPosition_1(scrollable);
  10002. var viewport = scrollable === documentScrollElement ? scrollable.ownerDocument.documentElement : scrollable;
  10003. var xMax = scrollable.scrollWidth - viewport.clientWidth;
  10004. var yMax = scrollable.scrollHeight - viewport.clientHeight;
  10005. scrollPosition.x = Math.max(0, Math.min(scrollPosition.x, xMax));
  10006. scrollPosition.y = Math.max(0, Math.min(scrollPosition.y, yMax));
  10007. return scrollPosition;
  10008. }
  10009. var getScrollPosition_1 = getScrollPosition;
  10010. function getViewportWidth() {
  10011. var width = void 0;
  10012. if (document.documentElement) {
  10013. width = document.documentElement.clientWidth;
  10014. }
  10015. if (!width && document.body) {
  10016. width = document.body.clientWidth;
  10017. }
  10018. return width || 0;
  10019. } /**
  10020. * Copyright (c) 2013-present, Facebook, Inc.
  10021. *
  10022. * This source code is licensed under the MIT license found in the
  10023. * LICENSE file in the root directory of this source tree.
  10024. *
  10025. *
  10026. * @typechecks
  10027. */
  10028. function getViewportHeight() {
  10029. var height = void 0;
  10030. if (document.documentElement) {
  10031. height = document.documentElement.clientHeight;
  10032. }
  10033. if (!height && document.body) {
  10034. height = document.body.clientHeight;
  10035. }
  10036. return height || 0;
  10037. }
  10038. /**
  10039. * Gets the viewport dimensions including any scrollbars.
  10040. */
  10041. function getViewportDimensions() {
  10042. return {
  10043. width: window.innerWidth || getViewportWidth(),
  10044. height: window.innerHeight || getViewportHeight()
  10045. };
  10046. }
  10047. /**
  10048. * Gets the viewport dimensions excluding any scrollbars.
  10049. */
  10050. getViewportDimensions.withoutScrollbars = function () {
  10051. return {
  10052. width: getViewportWidth(),
  10053. height: getViewportHeight()
  10054. };
  10055. };
  10056. var getViewportDimensions_1 = getViewportDimensions;
  10057. 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; };
  10058. function _classCallCheck$b(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10059. 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; }
  10060. 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; }
  10061. var SCROLL_BUFFER = 10;
  10062. /**
  10063. * Return whether a block overlaps with either edge of the `SelectionState`.
  10064. */
  10065. var isBlockOnSelectionEdge = function isBlockOnSelectionEdge(selection, key) {
  10066. return selection.getAnchorKey() === key || selection.getFocusKey() === key;
  10067. };
  10068. /**
  10069. * The default block renderer for a `DraftEditor` component.
  10070. *
  10071. * A `DraftEditorBlock` is able to render a given `ContentBlock` to its
  10072. * appropriate decorator and inline style components.
  10073. */
  10074. var DraftEditorBlock = function (_React$Component) {
  10075. _inherits$8(DraftEditorBlock, _React$Component);
  10076. function DraftEditorBlock() {
  10077. _classCallCheck$b(this, DraftEditorBlock);
  10078. return _possibleConstructorReturn$8(this, _React$Component.apply(this, arguments));
  10079. }
  10080. DraftEditorBlock.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  10081. return this.props.block !== nextProps.block || this.props.tree !== nextProps.tree || this.props.direction !== nextProps.direction || isBlockOnSelectionEdge(nextProps.selection, nextProps.block.getKey()) && nextProps.forceSelection;
  10082. };
  10083. /**
  10084. * When a block is mounted and overlaps the selection state, we need to make
  10085. * sure that the cursor is visible to match native behavior. This may not
  10086. * be the case if the user has pressed `RETURN` or pasted some content, since
  10087. * programatically creating these new blocks and setting the DOM selection
  10088. * will miss out on the browser natively scrolling to that position.
  10089. *
  10090. * To replicate native behavior, if the block overlaps the selection state
  10091. * on mount, force the scroll position. Check the scroll state of the scroll
  10092. * parent, and adjust it to align the entire block to the bottom of the
  10093. * scroll parent.
  10094. */
  10095. DraftEditorBlock.prototype.componentDidMount = function componentDidMount() {
  10096. var selection = this.props.selection;
  10097. var endKey = selection.getEndKey();
  10098. if (!selection.getHasFocus() || endKey !== this.props.block.getKey()) {
  10099. return;
  10100. }
  10101. var blockNode = reactDom.findDOMNode(this);
  10102. var scrollParent = Style_1.getScrollParent(blockNode);
  10103. var scrollPosition = getScrollPosition_1(scrollParent);
  10104. var scrollDelta = void 0;
  10105. if (scrollParent === window) {
  10106. var nodePosition = getElementPosition_1(blockNode);
  10107. var nodeBottom = nodePosition.y + nodePosition.height;
  10108. var viewportHeight = getViewportDimensions_1().height;
  10109. scrollDelta = nodeBottom - viewportHeight;
  10110. if (scrollDelta > 0) {
  10111. window.scrollTo(scrollPosition.x, scrollPosition.y + scrollDelta + SCROLL_BUFFER);
  10112. }
  10113. } else {
  10114. !(blockNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'blockNode is not an HTMLElement') : invariant_1(false) : void 0;
  10115. var blockBottom = blockNode.offsetHeight + blockNode.offsetTop;
  10116. var scrollBottom = scrollParent.offsetHeight + scrollPosition.y;
  10117. scrollDelta = blockBottom - scrollBottom;
  10118. if (scrollDelta > 0) {
  10119. Scroll_1.setTop(scrollParent, Scroll_1.getTop(scrollParent) + scrollDelta + SCROLL_BUFFER);
  10120. }
  10121. }
  10122. };
  10123. DraftEditorBlock.prototype._renderChildren = function _renderChildren() {
  10124. var _this2 = this;
  10125. var block = this.props.block;
  10126. var blockKey = block.getKey();
  10127. var text = block.getText();
  10128. var lastLeafSet = this.props.tree.size - 1;
  10129. var hasSelection = isBlockOnSelectionEdge(this.props.selection, blockKey);
  10130. return this.props.tree.map(function (leafSet, ii) {
  10131. var leavesForLeafSet = leafSet.get('leaves');
  10132. var lastLeaf = leavesForLeafSet.size - 1;
  10133. var leaves = leavesForLeafSet.map(function (leaf, jj) {
  10134. var offsetKey = DraftOffsetKey_1.encode(blockKey, ii, jj);
  10135. var start = leaf.get('start');
  10136. var end = leaf.get('end');
  10137. return React__default.createElement(DraftEditorLeaf_react, {
  10138. key: offsetKey,
  10139. offsetKey: offsetKey,
  10140. block: block,
  10141. start: start,
  10142. selection: hasSelection ? _this2.props.selection : null,
  10143. forceSelection: _this2.props.forceSelection,
  10144. text: text.slice(start, end),
  10145. styleSet: block.getInlineStyleAt(start),
  10146. customStyleMap: _this2.props.customStyleMap,
  10147. customStyleFn: _this2.props.customStyleFn,
  10148. isLast: ii === lastLeafSet && jj === lastLeaf
  10149. });
  10150. }).toArray();
  10151. var decoratorKey = leafSet.get('decoratorKey');
  10152. if (decoratorKey == null) {
  10153. return leaves;
  10154. }
  10155. if (!_this2.props.decorator) {
  10156. return leaves;
  10157. }
  10158. var decorator = nullthrows_1(_this2.props.decorator);
  10159. var DecoratorComponent = decorator.getComponentForKey(decoratorKey);
  10160. if (!DecoratorComponent) {
  10161. return leaves;
  10162. }
  10163. var decoratorProps = decorator.getPropsForKey(decoratorKey);
  10164. var decoratorOffsetKey = DraftOffsetKey_1.encode(blockKey, ii, 0);
  10165. var decoratedText = text.slice(leavesForLeafSet.first().get('start'), leavesForLeafSet.last().get('end'));
  10166. // Resetting dir to the same value on a child node makes Chrome/Firefox
  10167. // confused on cursor movement. See http://jsfiddle.net/d157kLck/3/
  10168. var dir = UnicodeBidiDirection_1.getHTMLDirIfDifferent(UnicodeBidi_1.getDirection(decoratedText), _this2.props.direction);
  10169. return React__default.createElement(
  10170. DecoratorComponent,
  10171. _extends$2({}, decoratorProps, {
  10172. contentState: _this2.props.contentState,
  10173. decoratedText: decoratedText,
  10174. dir: dir,
  10175. key: decoratorOffsetKey,
  10176. entityKey: block.getEntityAt(leafSet.get('start')),
  10177. offsetKey: decoratorOffsetKey }),
  10178. leaves
  10179. );
  10180. }).toArray();
  10181. };
  10182. DraftEditorBlock.prototype.render = function render() {
  10183. var _props = this.props,
  10184. direction = _props.direction,
  10185. offsetKey = _props.offsetKey;
  10186. var className = cx_1({
  10187. 'public/DraftStyleDefault/block': true,
  10188. 'public/DraftStyleDefault/ltr': direction === 'LTR',
  10189. 'public/DraftStyleDefault/rtl': direction === 'RTL'
  10190. });
  10191. return React__default.createElement(
  10192. 'div',
  10193. { 'data-offset-key': offsetKey, className: className },
  10194. this._renderChildren()
  10195. );
  10196. };
  10197. return DraftEditorBlock;
  10198. }(React__default.Component);
  10199. var DraftEditorBlock_react = DraftEditorBlock;
  10200. /**
  10201. * Copyright (c) 2013-present, Facebook, Inc.
  10202. *
  10203. * This source code is licensed under the MIT license found in the
  10204. * LICENSE file in the root directory of this source tree.
  10205. *
  10206. * @typechecks static-only
  10207. */
  10208. /**
  10209. * Combines multiple className strings into one.
  10210. * http://jsperf.com/joinclasses-args-vs-array
  10211. *
  10212. * @param {...?string} className
  10213. * @return {string}
  10214. */
  10215. function joinClasses(className /*, ... */) {
  10216. if (!className) {
  10217. className = '';
  10218. }
  10219. var nextClass = void 0;
  10220. var argLength = arguments.length;
  10221. if (argLength > 1) {
  10222. for (var ii = 1; ii < argLength; ii++) {
  10223. nextClass = arguments[ii];
  10224. if (nextClass) {
  10225. className = (className ? className + ' ' : '') + nextClass;
  10226. }
  10227. }
  10228. }
  10229. return className;
  10230. }
  10231. var joinClasses_1 = joinClasses;
  10232. 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; };
  10233. function _classCallCheck$c(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10234. 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; }
  10235. 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; }
  10236. /**
  10237. * Provide default styling for list items. This way, lists will be styled with
  10238. * proper counters and indentation even if the caller does not specify
  10239. * their own styling at all. If more than five levels of nesting are needed,
  10240. * the necessary CSS classes can be provided via `blockStyleFn` configuration.
  10241. */
  10242. var getListItemClasses = function getListItemClasses(type, depth, shouldResetCount, direction) {
  10243. return cx_1({
  10244. 'public/DraftStyleDefault/unorderedListItem': type === 'unordered-list-item',
  10245. 'public/DraftStyleDefault/orderedListItem': type === 'ordered-list-item',
  10246. 'public/DraftStyleDefault/reset': shouldResetCount,
  10247. 'public/DraftStyleDefault/depth0': depth === 0,
  10248. 'public/DraftStyleDefault/depth1': depth === 1,
  10249. 'public/DraftStyleDefault/depth2': depth === 2,
  10250. 'public/DraftStyleDefault/depth3': depth === 3,
  10251. 'public/DraftStyleDefault/depth4': depth === 4,
  10252. 'public/DraftStyleDefault/listLTR': direction === 'LTR',
  10253. 'public/DraftStyleDefault/listRTL': direction === 'RTL'
  10254. });
  10255. };
  10256. /**
  10257. * `DraftEditorContents` is the container component for all block components
  10258. * rendered for a `DraftEditor`. It is optimized to aggressively avoid
  10259. * re-rendering blocks whenever possible.
  10260. *
  10261. * This component is separate from `DraftEditor` because certain props
  10262. * (for instance, ARIA props) must be allowed to update without affecting
  10263. * the contents of the editor.
  10264. */
  10265. var DraftEditorContents = function (_React$Component) {
  10266. _inherits$9(DraftEditorContents, _React$Component);
  10267. function DraftEditorContents() {
  10268. _classCallCheck$c(this, DraftEditorContents);
  10269. return _possibleConstructorReturn$9(this, _React$Component.apply(this, arguments));
  10270. }
  10271. DraftEditorContents.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  10272. var prevEditorState = this.props.editorState;
  10273. var nextEditorState = nextProps.editorState;
  10274. var prevDirectionMap = prevEditorState.getDirectionMap();
  10275. var nextDirectionMap = nextEditorState.getDirectionMap();
  10276. // Text direction has changed for one or more blocks. We must re-render.
  10277. if (prevDirectionMap !== nextDirectionMap) {
  10278. return true;
  10279. }
  10280. var didHaveFocus = prevEditorState.getSelection().getHasFocus();
  10281. var nowHasFocus = nextEditorState.getSelection().getHasFocus();
  10282. if (didHaveFocus !== nowHasFocus) {
  10283. return true;
  10284. }
  10285. var nextNativeContent = nextEditorState.getNativelyRenderedContent();
  10286. var wasComposing = prevEditorState.isInCompositionMode();
  10287. var nowComposing = nextEditorState.isInCompositionMode();
  10288. // If the state is unchanged or we're currently rendering a natively
  10289. // rendered state, there's nothing new to be done.
  10290. if (prevEditorState === nextEditorState || nextNativeContent !== null && nextEditorState.getCurrentContent() === nextNativeContent || wasComposing && nowComposing) {
  10291. return false;
  10292. }
  10293. var prevContent = prevEditorState.getCurrentContent();
  10294. var nextContent = nextEditorState.getCurrentContent();
  10295. var prevDecorator = prevEditorState.getDecorator();
  10296. var nextDecorator = nextEditorState.getDecorator();
  10297. return wasComposing !== nowComposing || prevContent !== nextContent || prevDecorator !== nextDecorator || nextEditorState.mustForceSelection();
  10298. };
  10299. DraftEditorContents.prototype.render = function render() {
  10300. var _props = this.props,
  10301. blockRenderMap = _props.blockRenderMap,
  10302. blockRendererFn = _props.blockRendererFn,
  10303. blockStyleFn = _props.blockStyleFn,
  10304. customStyleMap = _props.customStyleMap,
  10305. customStyleFn = _props.customStyleFn,
  10306. editorState = _props.editorState,
  10307. editorKey = _props.editorKey,
  10308. textDirectionality = _props.textDirectionality;
  10309. var content = editorState.getCurrentContent();
  10310. var selection = editorState.getSelection();
  10311. var forceSelection = editorState.mustForceSelection();
  10312. var decorator = editorState.getDecorator();
  10313. var directionMap = nullthrows_1(editorState.getDirectionMap());
  10314. var blocksAsArray = content.getBlocksAsArray();
  10315. var processedBlocks = [];
  10316. var currentDepth = null;
  10317. var lastWrapperTemplate = null;
  10318. for (var ii = 0; ii < blocksAsArray.length; ii++) {
  10319. var _block = blocksAsArray[ii];
  10320. var key = _block.getKey();
  10321. var blockType = _block.getType();
  10322. var customRenderer = blockRendererFn(_block);
  10323. var CustomComponent = void 0,
  10324. customProps = void 0,
  10325. customEditable = void 0;
  10326. if (customRenderer) {
  10327. CustomComponent = customRenderer.component;
  10328. customProps = customRenderer.props;
  10329. customEditable = customRenderer.editable;
  10330. }
  10331. var direction = textDirectionality ? textDirectionality : directionMap.get(key);
  10332. var offsetKey = DraftOffsetKey_1.encode(key, 0, 0);
  10333. var componentProps = {
  10334. contentState: content,
  10335. block: _block,
  10336. blockProps: customProps,
  10337. blockStyleFn: blockStyleFn,
  10338. customStyleMap: customStyleMap,
  10339. customStyleFn: customStyleFn,
  10340. decorator: decorator,
  10341. direction: direction,
  10342. forceSelection: forceSelection,
  10343. key: key,
  10344. offsetKey: offsetKey,
  10345. selection: selection,
  10346. tree: editorState.getBlockTree(key)
  10347. };
  10348. var configForType = blockRenderMap.get(blockType) || blockRenderMap.get('unstyled');
  10349. var wrapperTemplate = configForType.wrapper;
  10350. var Element = configForType.element || blockRenderMap.get('unstyled').element;
  10351. var depth = _block.getDepth();
  10352. var className = '';
  10353. if (blockStyleFn) {
  10354. className = blockStyleFn(_block);
  10355. }
  10356. // List items are special snowflakes, since we handle nesting and
  10357. // counters manually.
  10358. if (Element === 'li') {
  10359. var shouldResetCount = lastWrapperTemplate !== wrapperTemplate || currentDepth === null || depth > currentDepth;
  10360. className = joinClasses_1(className, getListItemClasses(blockType, depth, shouldResetCount, direction));
  10361. }
  10362. var Component = CustomComponent || DraftEditorBlock_react;
  10363. var childProps = {
  10364. className: className,
  10365. 'data-block': true,
  10366. 'data-editor': editorKey,
  10367. 'data-offset-key': offsetKey,
  10368. key: key
  10369. };
  10370. if (customEditable !== undefined) {
  10371. childProps = _extends$3({}, childProps, {
  10372. contentEditable: customEditable,
  10373. suppressContentEditableWarning: true
  10374. });
  10375. }
  10376. var child = React__default.createElement(Element, childProps, React__default.createElement(Component, componentProps));
  10377. processedBlocks.push({
  10378. block: child,
  10379. wrapperTemplate: wrapperTemplate,
  10380. key: key,
  10381. offsetKey: offsetKey
  10382. });
  10383. if (wrapperTemplate) {
  10384. currentDepth = _block.getDepth();
  10385. } else {
  10386. currentDepth = null;
  10387. }
  10388. lastWrapperTemplate = wrapperTemplate;
  10389. }
  10390. // Group contiguous runs of blocks that have the same wrapperTemplate
  10391. var outputBlocks = [];
  10392. for (var _ii = 0; _ii < processedBlocks.length;) {
  10393. var info = processedBlocks[_ii];
  10394. if (info.wrapperTemplate) {
  10395. var blocks = [];
  10396. do {
  10397. blocks.push(processedBlocks[_ii].block);
  10398. _ii++;
  10399. } while (_ii < processedBlocks.length && processedBlocks[_ii].wrapperTemplate === info.wrapperTemplate);
  10400. var wrapperElement = React__default.cloneElement(info.wrapperTemplate, {
  10401. key: info.key + '-wrap',
  10402. 'data-offset-key': info.offsetKey
  10403. }, blocks);
  10404. outputBlocks.push(wrapperElement);
  10405. } else {
  10406. outputBlocks.push(info.block);
  10407. _ii++;
  10408. }
  10409. }
  10410. return React__default.createElement(
  10411. 'div',
  10412. { 'data-contents': 'true' },
  10413. outputBlocks
  10414. );
  10415. };
  10416. return DraftEditorContents;
  10417. }(React__default.Component);
  10418. var DraftEditorContentsCore_react = DraftEditorContents;
  10419. var DraftEditorContents_react = DraftEditorContentsCore_react;
  10420. /**
  10421. * Copyright (c) 2013-present, Facebook, Inc.
  10422. *
  10423. * This source code is licensed under the MIT license found in the
  10424. * LICENSE file in the root directory of this source tree.
  10425. *
  10426. */
  10427. var PhotosMimeType = {
  10428. isImage: function isImage(mimeString) {
  10429. return getParts(mimeString)[0] === 'image';
  10430. },
  10431. isJpeg: function isJpeg(mimeString) {
  10432. var parts = getParts(mimeString);
  10433. return PhotosMimeType.isImage(mimeString) && (
  10434. // see http://fburl.com/10972194
  10435. parts[1] === 'jpeg' || parts[1] === 'pjpeg');
  10436. }
  10437. };
  10438. function getParts(mimeString) {
  10439. return mimeString.split('/');
  10440. }
  10441. var PhotosMimeType_1 = PhotosMimeType;
  10442. /**
  10443. * Copyright (c) 2013-present, Facebook, Inc.
  10444. *
  10445. * This source code is licensed under the MIT license found in the
  10446. * LICENSE file in the root directory of this source tree.
  10447. *
  10448. * @typechecks
  10449. */
  10450. /**
  10451. * Convert array-like objects to arrays.
  10452. *
  10453. * This API assumes the caller knows the contents of the data type. For less
  10454. * well defined inputs use createArrayFromMixed.
  10455. *
  10456. * @param {object|function|filelist} obj
  10457. * @return {array}
  10458. */
  10459. function toArray(obj) {
  10460. var length = obj.length;
  10461. // Some browsers builtin objects can report typeof 'function' (e.g. NodeList
  10462. // in old versions of Safari).
  10463. !(!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;
  10464. !(typeof length === 'number') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'toArray: Object needs a length property') : invariant_1(false) : void 0;
  10465. !(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;
  10466. !(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;
  10467. // Old IE doesn't give collections access to hasOwnProperty. Assume inputs
  10468. // without method will throw during the slice call and skip straight to the
  10469. // fallback.
  10470. if (obj.hasOwnProperty) {
  10471. try {
  10472. return Array.prototype.slice.call(obj);
  10473. } catch (e) {
  10474. // IE < 9 does not support Array#slice on collections objects
  10475. }
  10476. }
  10477. // Fall back to copying key by key. This assumes all keys have a value,
  10478. // so will not preserve sparsely populated inputs.
  10479. var ret = Array(length);
  10480. for (var ii = 0; ii < length; ii++) {
  10481. ret[ii] = obj[ii];
  10482. }
  10483. return ret;
  10484. }
  10485. /**
  10486. * Perform a heuristic test to determine if an object is "array-like".
  10487. *
  10488. * A monk asked Joshu, a Zen master, "Has a dog Buddha nature?"
  10489. * Joshu replied: "Mu."
  10490. *
  10491. * This function determines if its argument has "array nature": it returns
  10492. * true if the argument is an actual array, an `arguments' object, or an
  10493. * HTMLCollection (e.g. node.childNodes or node.getElementsByTagName()).
  10494. *
  10495. * It will return false for other array-like objects like Filelist.
  10496. *
  10497. * @param {*} obj
  10498. * @return {boolean}
  10499. */
  10500. function hasArrayNature(obj) {
  10501. return (
  10502. // not null/false
  10503. !!obj && (
  10504. // arrays are objects, NodeLists are functions in Safari
  10505. typeof obj == 'object' || typeof obj == 'function') &&
  10506. // quacks like an array
  10507. 'length' in obj &&
  10508. // not window
  10509. !('setInterval' in obj) &&
  10510. // no DOM node should be considered an array-like
  10511. // a 'select' element has 'length' and 'item' properties on IE8
  10512. typeof obj.nodeType != 'number' && (
  10513. // a real array
  10514. Array.isArray(obj) ||
  10515. // arguments
  10516. 'callee' in obj ||
  10517. // HTMLCollection/NodeList
  10518. 'item' in obj)
  10519. );
  10520. }
  10521. /**
  10522. * Ensure that the argument is an array by wrapping it in an array if it is not.
  10523. * Creates a copy of the argument if it is already an array.
  10524. *
  10525. * This is mostly useful idiomatically:
  10526. *
  10527. * var createArrayFromMixed = require('createArrayFromMixed');
  10528. *
  10529. * function takesOneOrMoreThings(things) {
  10530. * things = createArrayFromMixed(things);
  10531. * ...
  10532. * }
  10533. *
  10534. * This allows you to treat `things' as an array, but accept scalars in the API.
  10535. *
  10536. * If you need to convert an array-like object, like `arguments`, into an array
  10537. * use toArray instead.
  10538. *
  10539. * @param {*} obj
  10540. * @return {array}
  10541. */
  10542. function createArrayFromMixed(obj) {
  10543. if (!hasArrayNature(obj)) {
  10544. return [obj];
  10545. } else if (Array.isArray(obj)) {
  10546. return obj.slice();
  10547. } else {
  10548. return toArray(obj);
  10549. }
  10550. }
  10551. var createArrayFromMixed_1 = createArrayFromMixed;
  10552. function _classCallCheck$d(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10553. /**
  10554. * Copyright (c) 2013-present, Facebook, Inc.
  10555. *
  10556. * This source code is licensed under the MIT license found in the
  10557. * LICENSE file in the root directory of this source tree.
  10558. *
  10559. * @typechecks
  10560. */
  10561. var CR_LF_REGEX = new RegExp('\r\n', 'g');
  10562. var LF_ONLY = '\n';
  10563. var RICH_TEXT_TYPES = {
  10564. 'text/rtf': 1,
  10565. 'text/html': 1
  10566. };
  10567. /**
  10568. * If DataTransferItem is a file then return the Blob of data.
  10569. *
  10570. * @param {object} item
  10571. * @return {?blob}
  10572. */
  10573. function getFileFromDataTransfer(item) {
  10574. if (item.kind == 'file') {
  10575. return item.getAsFile();
  10576. }
  10577. }
  10578. var DataTransfer$1 = function () {
  10579. /**
  10580. * @param {object} data
  10581. */
  10582. function DataTransfer(data) {
  10583. _classCallCheck$d(this, DataTransfer);
  10584. this.data = data;
  10585. // Types could be DOMStringList or array
  10586. this.types = data.types ? createArrayFromMixed_1(data.types) : [];
  10587. }
  10588. /**
  10589. * Is this likely to be a rich text data transfer?
  10590. *
  10591. * @return {boolean}
  10592. */
  10593. DataTransfer.prototype.isRichText = function isRichText() {
  10594. // If HTML is available, treat this data as rich text. This way, we avoid
  10595. // using a pasted image if it is packaged with HTML -- this may occur with
  10596. // pastes from MS Word, for example. However this is only rich text if
  10597. // there's accompanying text.
  10598. if (this.getHTML() && this.getText()) {
  10599. return true;
  10600. }
  10601. // When an image is copied from a preview window, you end up with two
  10602. // DataTransferItems one of which is a file's metadata as text. Skip those.
  10603. if (this.isImage()) {
  10604. return false;
  10605. }
  10606. return this.types.some(function (type) {
  10607. return RICH_TEXT_TYPES[type];
  10608. });
  10609. };
  10610. /**
  10611. * Get raw text.
  10612. *
  10613. * @return {?string}
  10614. */
  10615. DataTransfer.prototype.getText = function getText() {
  10616. var text;
  10617. if (this.data.getData) {
  10618. if (!this.types.length) {
  10619. text = this.data.getData('Text');
  10620. } else if (this.types.indexOf('text/plain') != -1) {
  10621. text = this.data.getData('text/plain');
  10622. }
  10623. }
  10624. return text ? text.replace(CR_LF_REGEX, LF_ONLY) : null;
  10625. };
  10626. /**
  10627. * Get HTML paste data
  10628. *
  10629. * @return {?string}
  10630. */
  10631. DataTransfer.prototype.getHTML = function getHTML() {
  10632. if (this.data.getData) {
  10633. if (!this.types.length) {
  10634. return this.data.getData('Text');
  10635. } else if (this.types.indexOf('text/html') != -1) {
  10636. return this.data.getData('text/html');
  10637. }
  10638. }
  10639. };
  10640. /**
  10641. * Is this a link data transfer?
  10642. *
  10643. * @return {boolean}
  10644. */
  10645. DataTransfer.prototype.isLink = function isLink() {
  10646. return this.types.some(function (type) {
  10647. return type.indexOf('Url') != -1 || type.indexOf('text/uri-list') != -1 || type.indexOf('text/x-moz-url');
  10648. });
  10649. };
  10650. /**
  10651. * Get a link url.
  10652. *
  10653. * @return {?string}
  10654. */
  10655. DataTransfer.prototype.getLink = function getLink() {
  10656. if (this.data.getData) {
  10657. if (this.types.indexOf('text/x-moz-url') != -1) {
  10658. var url = this.data.getData('text/x-moz-url').split('\n');
  10659. return url[0];
  10660. }
  10661. return this.types.indexOf('text/uri-list') != -1 ? this.data.getData('text/uri-list') : this.data.getData('url');
  10662. }
  10663. return null;
  10664. };
  10665. /**
  10666. * Is this an image data transfer?
  10667. *
  10668. * @return {boolean}
  10669. */
  10670. DataTransfer.prototype.isImage = function isImage() {
  10671. var isImage = this.types.some(function (type) {
  10672. // Firefox will have a type of application/x-moz-file for images during
  10673. // dragging
  10674. return type.indexOf('application/x-moz-file') != -1;
  10675. });
  10676. if (isImage) {
  10677. return true;
  10678. }
  10679. var items = this.getFiles();
  10680. for (var i = 0; i < items.length; i++) {
  10681. var type = items[i].type;
  10682. if (!PhotosMimeType_1.isImage(type)) {
  10683. return false;
  10684. }
  10685. }
  10686. return true;
  10687. };
  10688. DataTransfer.prototype.getCount = function getCount() {
  10689. if (this.data.hasOwnProperty('items')) {
  10690. return this.data.items.length;
  10691. } else if (this.data.hasOwnProperty('mozItemCount')) {
  10692. return this.data.mozItemCount;
  10693. } else if (this.data.files) {
  10694. return this.data.files.length;
  10695. }
  10696. return null;
  10697. };
  10698. /**
  10699. * Get files.
  10700. *
  10701. * @return {array}
  10702. */
  10703. DataTransfer.prototype.getFiles = function getFiles() {
  10704. if (this.data.items) {
  10705. // createArrayFromMixed doesn't properly handle DataTransferItemLists.
  10706. return Array.prototype.slice.call(this.data.items).map(getFileFromDataTransfer).filter(emptyFunction_1.thatReturnsArgument);
  10707. } else if (this.data.files) {
  10708. return Array.prototype.slice.call(this.data.files);
  10709. } else {
  10710. return [];
  10711. }
  10712. };
  10713. /**
  10714. * Are there any files to fetch?
  10715. *
  10716. * @return {boolean}
  10717. */
  10718. DataTransfer.prototype.hasFiles = function hasFiles() {
  10719. return this.getFiles().length > 0;
  10720. };
  10721. return DataTransfer;
  10722. }();
  10723. var DataTransfer_1 = DataTransfer$1;
  10724. /**
  10725. * Copyright (c) 2013-present, Facebook, Inc.
  10726. * All rights reserved.
  10727. *
  10728. * This source code is licensed under the BSD-style license found in the
  10729. * LICENSE file in the root directory of this source tree. An additional grant
  10730. * of patent rights can be found in the PATENTS file in the same directory.
  10731. *
  10732. * @providesModule getSelectionOffsetKeyForNode
  10733. * @format
  10734. *
  10735. */
  10736. /**
  10737. * Get offset key from a node or it's child nodes. Return the first offset key
  10738. * found on the DOM tree of given node.
  10739. */
  10740. function getSelectionOffsetKeyForNode(node) {
  10741. if (node instanceof Element) {
  10742. var offsetKey = node.getAttribute('data-offset-key');
  10743. if (offsetKey) {
  10744. return offsetKey;
  10745. }
  10746. for (var ii = 0; ii < node.childNodes.length; ii++) {
  10747. var childOffsetKey = getSelectionOffsetKeyForNode(node.childNodes[ii]);
  10748. if (childOffsetKey) {
  10749. return childOffsetKey;
  10750. }
  10751. }
  10752. }
  10753. return null;
  10754. }
  10755. var getSelectionOffsetKeyForNode_1 = getSelectionOffsetKeyForNode;
  10756. /**
  10757. * Get the key from the node's nearest offset-aware ancestor.
  10758. */
  10759. function findAncestorOffsetKey(node) {
  10760. var searchNode = node;
  10761. while (searchNode && searchNode !== document.documentElement) {
  10762. var key = getSelectionOffsetKeyForNode_1(searchNode);
  10763. if (key != null) {
  10764. return key;
  10765. }
  10766. searchNode = searchNode.parentNode;
  10767. }
  10768. return null;
  10769. }
  10770. var findAncestorOffsetKey_1 = findAncestorOffsetKey;
  10771. var TEXT_CLIPPING_REGEX = /\.textClipping$/;
  10772. var TEXT_TYPES = {
  10773. 'text/plain': true,
  10774. 'text/html': true,
  10775. 'text/rtf': true
  10776. };
  10777. // Somewhat arbitrary upper bound on text size. Let's not lock up the browser.
  10778. var TEXT_SIZE_UPPER_BOUND = 5000;
  10779. /**
  10780. * Extract the text content from a file list.
  10781. */
  10782. function getTextContentFromFiles(files, callback) {
  10783. var readCount = 0;
  10784. var results = [];
  10785. files.forEach(function ( /*blob*/file) {
  10786. readFile(file, function ( /*string*/text) {
  10787. readCount++;
  10788. text && results.push(text.slice(0, TEXT_SIZE_UPPER_BOUND));
  10789. if (readCount == files.length) {
  10790. callback(results.join('\r'));
  10791. }
  10792. });
  10793. });
  10794. }
  10795. /**
  10796. * todo isaac: Do work to turn html/rtf into a content fragment.
  10797. */
  10798. function readFile(file, callback) {
  10799. if (!styleInject_es.commonjsGlobal.FileReader || file.type && !(file.type in TEXT_TYPES)) {
  10800. callback('');
  10801. return;
  10802. }
  10803. if (file.type === '') {
  10804. var contents = '';
  10805. // Special-case text clippings, which have an empty type but include
  10806. // `.textClipping` in the file name. `readAsText` results in an empty
  10807. // string for text clippings, so we force the file name to serve
  10808. // as the text value for the file.
  10809. if (TEXT_CLIPPING_REGEX.test(file.name)) {
  10810. contents = file.name.replace(TEXT_CLIPPING_REGEX, '');
  10811. }
  10812. callback(contents);
  10813. return;
  10814. }
  10815. var reader = new FileReader();
  10816. reader.onload = function () {
  10817. var result = reader.result;
  10818. !(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;
  10819. callback(result);
  10820. };
  10821. reader.onerror = function () {
  10822. callback('');
  10823. };
  10824. reader.readAsText(file);
  10825. }
  10826. var getTextContentFromFiles_1 = getTextContentFromFiles;
  10827. function getUpdatedSelectionState(editorState, anchorKey, anchorOffset, focusKey, focusOffset) {
  10828. var selection = nullthrows_1(editorState.getSelection());
  10829. if (process.env.NODE_ENV !== 'production') {
  10830. if (!anchorKey || !focusKey) {
  10831. /*eslint-disable no-console */
  10832. console.warn('Invalid selection state.', arguments, editorState.toJS());
  10833. /*eslint-enable no-console */
  10834. return selection;
  10835. }
  10836. }
  10837. var anchorPath = DraftOffsetKey_1.decode(anchorKey);
  10838. var anchorBlockKey = anchorPath.blockKey;
  10839. var anchorLeaf = editorState.getBlockTree(anchorBlockKey).getIn([anchorPath.decoratorKey, 'leaves', anchorPath.leafKey]);
  10840. var focusPath = DraftOffsetKey_1.decode(focusKey);
  10841. var focusBlockKey = focusPath.blockKey;
  10842. var focusLeaf = editorState.getBlockTree(focusBlockKey).getIn([focusPath.decoratorKey, 'leaves', focusPath.leafKey]);
  10843. var anchorLeafStart = anchorLeaf.get('start');
  10844. var focusLeafStart = focusLeaf.get('start');
  10845. var anchorBlockOffset = anchorLeaf ? anchorLeafStart + anchorOffset : null;
  10846. var focusBlockOffset = focusLeaf ? focusLeafStart + focusOffset : null;
  10847. var areEqual = selection.getAnchorKey() === anchorBlockKey && selection.getAnchorOffset() === anchorBlockOffset && selection.getFocusKey() === focusBlockKey && selection.getFocusOffset() === focusBlockOffset;
  10848. if (areEqual) {
  10849. return selection;
  10850. }
  10851. var isBackward = false;
  10852. if (anchorBlockKey === focusBlockKey) {
  10853. var anchorLeafEnd = anchorLeaf.get('end');
  10854. var focusLeafEnd = focusLeaf.get('end');
  10855. if (focusLeafStart === anchorLeafStart && focusLeafEnd === anchorLeafEnd) {
  10856. isBackward = focusOffset < anchorOffset;
  10857. } else {
  10858. isBackward = focusLeafStart < anchorLeafStart;
  10859. }
  10860. } else {
  10861. var startKey = editorState.getCurrentContent().getBlockMap().keySeq().skipUntil(function (v) {
  10862. return v === anchorBlockKey || v === focusBlockKey;
  10863. }).first();
  10864. isBackward = startKey === focusBlockKey;
  10865. }
  10866. return selection.merge({
  10867. anchorKey: anchorBlockKey,
  10868. anchorOffset: anchorBlockOffset,
  10869. focusKey: focusBlockKey,
  10870. focusOffset: focusBlockOffset,
  10871. isBackward: isBackward
  10872. });
  10873. }
  10874. var getUpdatedSelectionState_1 = getUpdatedSelectionState;
  10875. /**
  10876. * Get a SelectionState for the supplied mouse event.
  10877. */
  10878. function getSelectionForEvent(event, editorState) {
  10879. var node = null;
  10880. var offset = null;
  10881. if (typeof document.caretRangeFromPoint === 'function') {
  10882. var dropRange = document.caretRangeFromPoint(event.x, event.y);
  10883. node = dropRange.startContainer;
  10884. offset = dropRange.startOffset;
  10885. } else if (event.rangeParent) {
  10886. node = event.rangeParent;
  10887. offset = event.rangeOffset;
  10888. } else {
  10889. return null;
  10890. }
  10891. node = nullthrows_1(node);
  10892. offset = nullthrows_1(offset);
  10893. var offsetKey = nullthrows_1(findAncestorOffsetKey_1(node));
  10894. return getUpdatedSelectionState_1(editorState, offsetKey, offset, offsetKey, offset);
  10895. }
  10896. var DraftEditorDragHandler = {
  10897. /**
  10898. * Drag originating from input terminated.
  10899. */
  10900. onDragEnd: function onDragEnd(editor) {
  10901. editor.exitCurrentMode();
  10902. },
  10903. /**
  10904. * Handle data being dropped.
  10905. */
  10906. onDrop: function onDrop(editor, e) {
  10907. var data = new DataTransfer_1(e.nativeEvent.dataTransfer);
  10908. var editorState = editor._latestEditorState;
  10909. var dropSelection = getSelectionForEvent(e.nativeEvent, editorState);
  10910. e.preventDefault();
  10911. editor.exitCurrentMode();
  10912. if (dropSelection == null) {
  10913. return;
  10914. }
  10915. var files = data.getFiles();
  10916. if (files.length > 0) {
  10917. if (editor.props.handleDroppedFiles && isEventHandled_1(editor.props.handleDroppedFiles(dropSelection, files))) {
  10918. return;
  10919. }
  10920. getTextContentFromFiles_1(files, function (fileText) {
  10921. fileText && editor.update(insertTextAtSelection(editorState, dropSelection, fileText));
  10922. });
  10923. return;
  10924. }
  10925. var dragType = editor._internalDrag ? 'internal' : 'external';
  10926. if (editor.props.handleDrop && isEventHandled_1(editor.props.handleDrop(dropSelection, data, dragType))) {
  10927. return;
  10928. }
  10929. if (editor._internalDrag) {
  10930. editor.update(moveText(editorState, dropSelection));
  10931. return;
  10932. }
  10933. editor.update(insertTextAtSelection(editorState, dropSelection, data.getText()));
  10934. }
  10935. };
  10936. function moveText(editorState, targetSelection) {
  10937. var newContentState = DraftModifier_1.moveText(editorState.getCurrentContent(), editorState.getSelection(), targetSelection);
  10938. return EditorState_1.push(editorState, newContentState, 'insert-fragment');
  10939. }
  10940. /**
  10941. * Insert text at a specified selection.
  10942. */
  10943. function insertTextAtSelection(editorState, selection, text) {
  10944. var newContentState = DraftModifier_1.insertText(editorState.getCurrentContent(), selection, text, editorState.getCurrentInlineStyle());
  10945. return EditorState_1.push(editorState, newContentState, 'insert-fragment');
  10946. }
  10947. var DraftEditorDragHandler_1 = DraftEditorDragHandler;
  10948. (function (global, undefined$1) {
  10949. if (global.setImmediate) {
  10950. return;
  10951. }
  10952. var nextHandle = 1; // Spec says greater than zero
  10953. var tasksByHandle = {};
  10954. var currentlyRunningATask = false;
  10955. var doc = global.document;
  10956. var registerImmediate;
  10957. function setImmediate(callback) {
  10958. // Callback can either be a function or a string
  10959. if (typeof callback !== "function") {
  10960. callback = new Function("" + callback);
  10961. }
  10962. // Copy function arguments
  10963. var args = new Array(arguments.length - 1);
  10964. for (var i = 0; i < args.length; i++) {
  10965. args[i] = arguments[i + 1];
  10966. }
  10967. // Store and register the task
  10968. var task = { callback: callback, args: args };
  10969. tasksByHandle[nextHandle] = task;
  10970. registerImmediate(nextHandle);
  10971. return nextHandle++;
  10972. }
  10973. function clearImmediate(handle) {
  10974. delete tasksByHandle[handle];
  10975. }
  10976. function run(task) {
  10977. var callback = task.callback;
  10978. var args = task.args;
  10979. switch (args.length) {
  10980. case 0:
  10981. callback();
  10982. break;
  10983. case 1:
  10984. callback(args[0]);
  10985. break;
  10986. case 2:
  10987. callback(args[0], args[1]);
  10988. break;
  10989. case 3:
  10990. callback(args[0], args[1], args[2]);
  10991. break;
  10992. default:
  10993. callback.apply(undefined$1, args);
  10994. break;
  10995. }
  10996. }
  10997. function runIfPresent(handle) {
  10998. // From the spec: "Wait until any invocations of this algorithm started before this one have completed."
  10999. // So if we're currently running a task, we'll need to delay this invocation.
  11000. if (currentlyRunningATask) {
  11001. // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a
  11002. // "too much recursion" error.
  11003. setTimeout(runIfPresent, 0, handle);
  11004. } else {
  11005. var task = tasksByHandle[handle];
  11006. if (task) {
  11007. currentlyRunningATask = true;
  11008. try {
  11009. run(task);
  11010. } finally {
  11011. clearImmediate(handle);
  11012. currentlyRunningATask = false;
  11013. }
  11014. }
  11015. }
  11016. }
  11017. function installNextTickImplementation() {
  11018. registerImmediate = function(handle) {
  11019. process.nextTick(function () { runIfPresent(handle); });
  11020. };
  11021. }
  11022. function canUsePostMessage() {
  11023. // The test against `importScripts` prevents this implementation from being installed inside a web worker,
  11024. // where `global.postMessage` means something completely different and can't be used for this purpose.
  11025. if (global.postMessage && !global.importScripts) {
  11026. var postMessageIsAsynchronous = true;
  11027. var oldOnMessage = global.onmessage;
  11028. global.onmessage = function() {
  11029. postMessageIsAsynchronous = false;
  11030. };
  11031. global.postMessage("", "*");
  11032. global.onmessage = oldOnMessage;
  11033. return postMessageIsAsynchronous;
  11034. }
  11035. }
  11036. function installPostMessageImplementation() {
  11037. // Installs an event handler on `global` for the `message` event: see
  11038. // * https://developer.mozilla.org/en/DOM/window.postMessage
  11039. // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
  11040. var messagePrefix = "setImmediate$" + Math.random() + "$";
  11041. var onGlobalMessage = function(event) {
  11042. if (event.source === global &&
  11043. typeof event.data === "string" &&
  11044. event.data.indexOf(messagePrefix) === 0) {
  11045. runIfPresent(+event.data.slice(messagePrefix.length));
  11046. }
  11047. };
  11048. if (global.addEventListener) {
  11049. global.addEventListener("message", onGlobalMessage, false);
  11050. } else {
  11051. global.attachEvent("onmessage", onGlobalMessage);
  11052. }
  11053. registerImmediate = function(handle) {
  11054. global.postMessage(messagePrefix + handle, "*");
  11055. };
  11056. }
  11057. function installMessageChannelImplementation() {
  11058. var channel = new MessageChannel();
  11059. channel.port1.onmessage = function(event) {
  11060. var handle = event.data;
  11061. runIfPresent(handle);
  11062. };
  11063. registerImmediate = function(handle) {
  11064. channel.port2.postMessage(handle);
  11065. };
  11066. }
  11067. function installReadyStateChangeImplementation() {
  11068. var html = doc.documentElement;
  11069. registerImmediate = function(handle) {
  11070. // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
  11071. // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
  11072. var script = doc.createElement("script");
  11073. script.onreadystatechange = function () {
  11074. runIfPresent(handle);
  11075. script.onreadystatechange = null;
  11076. html.removeChild(script);
  11077. script = null;
  11078. };
  11079. html.appendChild(script);
  11080. };
  11081. }
  11082. function installSetTimeoutImplementation() {
  11083. registerImmediate = function(handle) {
  11084. setTimeout(runIfPresent, 0, handle);
  11085. };
  11086. }
  11087. // If supported, we should attach to the prototype of global, since that is where setTimeout et al. live.
  11088. var attachTo = Object.getPrototypeOf && Object.getPrototypeOf(global);
  11089. attachTo = attachTo && attachTo.setTimeout ? attachTo : global;
  11090. // Don't get fooled by e.g. browserify environments.
  11091. if ({}.toString.call(global.process) === "[object process]") {
  11092. // For Node.js before 0.9
  11093. installNextTickImplementation();
  11094. } else if (canUsePostMessage()) {
  11095. // For non-IE10 modern browsers
  11096. installPostMessageImplementation();
  11097. } else if (global.MessageChannel) {
  11098. // For web workers, where supported
  11099. installMessageChannelImplementation();
  11100. } else if (doc && "onreadystatechange" in doc.createElement("script")) {
  11101. // For IE 6–8
  11102. installReadyStateChangeImplementation();
  11103. } else {
  11104. // For older browsers
  11105. installSetTimeoutImplementation();
  11106. }
  11107. attachTo.setImmediate = setImmediate;
  11108. attachTo.clearImmediate = clearImmediate;
  11109. }(typeof self === "undefined" ? typeof styleInject_es.commonjsGlobal === "undefined" ? styleInject_es.commonjsGlobal : styleInject_es.commonjsGlobal : self));
  11110. // setimmediate adds setImmediate to the global. We want to make sure we export
  11111. // the actual function.
  11112. var setImmediate = styleInject_es.commonjsGlobal.setImmediate;
  11113. // When nothing is focused, Firefox regards two characters, `'` and `/`, as
  11114. // commands that should open and focus the "quickfind" search bar. This should
  11115. // *never* happen while a contenteditable is focused, but as of v28, it
  11116. // sometimes does, even when the keypress event target is the contenteditable.
  11117. // This breaks the input. Special case these characters to ensure that when
  11118. // they are typed, we prevent default on the event to make sure not to
  11119. // trigger quickfind.
  11120. var FF_QUICKFIND_CHAR = "'";
  11121. var FF_QUICKFIND_LINK_CHAR = '/';
  11122. var isFirefox = UserAgent_1.isBrowser('Firefox');
  11123. function mustPreventDefaultForCharacter(character) {
  11124. return isFirefox && (character == FF_QUICKFIND_CHAR || character == FF_QUICKFIND_LINK_CHAR);
  11125. }
  11126. /**
  11127. * Replace the current selection with the specified text string, with the
  11128. * inline style and entity key applied to the newly inserted text.
  11129. */
  11130. function replaceText(editorState, text, inlineStyle, entityKey) {
  11131. var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), text, inlineStyle, entityKey);
  11132. return EditorState_1.push(editorState, contentState, 'insert-characters');
  11133. }
  11134. /**
  11135. * When `onBeforeInput` executes, the browser is attempting to insert a
  11136. * character into the editor. Apply this character data to the document,
  11137. * allowing native insertion if possible.
  11138. *
  11139. * Native insertion is encouraged in order to limit re-rendering and to
  11140. * preserve spellcheck highlighting, which disappears or flashes if re-render
  11141. * occurs on the relevant text nodes.
  11142. */
  11143. function editOnBeforeInput(editor, e) {
  11144. if (editor._pendingStateFromBeforeInput !== undefined) {
  11145. editor.update(editor._pendingStateFromBeforeInput);
  11146. editor._pendingStateFromBeforeInput = undefined;
  11147. }
  11148. var editorState = editor._latestEditorState;
  11149. var chars = e.data;
  11150. // In some cases (ex: IE ideographic space insertion) no character data
  11151. // is provided. There's nothing to do when this happens.
  11152. if (!chars) {
  11153. return;
  11154. }
  11155. // Allow the top-level component to handle the insertion manually. This is
  11156. // useful when triggering interesting behaviors for a character insertion,
  11157. // Simple examples: replacing a raw text ':)' with a smile emoji or image
  11158. // decorator, or setting a block to be a list item after typing '- ' at the
  11159. // start of the block.
  11160. if (editor.props.handleBeforeInput && isEventHandled_1(editor.props.handleBeforeInput(chars, editorState))) {
  11161. e.preventDefault();
  11162. return;
  11163. }
  11164. // If selection is collapsed, conditionally allow native behavior. This
  11165. // reduces re-renders and preserves spellcheck highlighting. If the selection
  11166. // is not collapsed, we will re-render.
  11167. var selection = editorState.getSelection();
  11168. var selectionStart = selection.getStartOffset();
  11169. var selectionEnd = selection.getEndOffset();
  11170. var anchorKey = selection.getAnchorKey();
  11171. if (!selection.isCollapsed()) {
  11172. e.preventDefault();
  11173. // If the currently selected text matches what the user is trying to
  11174. // replace it with, let's just update the `SelectionState`. If not, update
  11175. // the `ContentState` with the new text.
  11176. var currentlySelectedChars = editorState.getCurrentContent().getPlainText().slice(selectionStart, selectionEnd);
  11177. if (chars === currentlySelectedChars) {
  11178. editor.update(EditorState_1.forceSelection(editorState, selection.merge({
  11179. focusOffset: selectionEnd
  11180. })));
  11181. } else {
  11182. editor.update(replaceText(editorState, chars, editorState.getCurrentInlineStyle(), getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())));
  11183. }
  11184. return;
  11185. }
  11186. var newEditorState = replaceText(editorState, chars, editorState.getCurrentInlineStyle(), getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection()));
  11187. // Bunch of different cases follow where we need to prevent native insertion.
  11188. var mustPreventNative = false;
  11189. if (!mustPreventNative) {
  11190. // Browsers tend to insert text in weird places in the DOM when typing at
  11191. // the start of a leaf, so we'll handle it ourselves.
  11192. mustPreventNative = isSelectionAtLeafStart_1(editor._latestCommittedEditorState);
  11193. }
  11194. if (!mustPreventNative) {
  11195. // Chrome will also split up a node into two pieces if it contains a Tab
  11196. // char, for no explicable reason. Seemingly caused by this commit:
  11197. // https://chromium.googlesource.com/chromium/src/+/013ac5eaf3%5E%21/
  11198. var nativeSelection = styleInject_es.commonjsGlobal.getSelection();
  11199. // Selection is necessarily collapsed at this point due to earlier check.
  11200. if (nativeSelection.anchorNode && nativeSelection.anchorNode.nodeType === Node.TEXT_NODE) {
  11201. // See isTabHTMLSpanElement in chromium EditingUtilities.cpp.
  11202. var parentNode = nativeSelection.anchorNode.parentNode;
  11203. mustPreventNative = parentNode.nodeName === 'SPAN' && parentNode.firstChild.nodeType === Node.TEXT_NODE && parentNode.firstChild.nodeValue.indexOf('\t') !== -1;
  11204. }
  11205. }
  11206. if (!mustPreventNative) {
  11207. // Check the old and new "fingerprints" of the current block to determine
  11208. // whether this insertion requires any addition or removal of text nodes,
  11209. // in which case we would prevent the native character insertion.
  11210. var originalFingerprint = BlockTree_1.getFingerprint(editorState.getBlockTree(anchorKey));
  11211. var newFingerprint = BlockTree_1.getFingerprint(newEditorState.getBlockTree(anchorKey));
  11212. mustPreventNative = originalFingerprint !== newFingerprint;
  11213. }
  11214. if (!mustPreventNative) {
  11215. mustPreventNative = mustPreventDefaultForCharacter(chars);
  11216. }
  11217. if (!mustPreventNative) {
  11218. mustPreventNative = nullthrows_1(newEditorState.getDirectionMap()).get(anchorKey) !== nullthrows_1(editorState.getDirectionMap()).get(anchorKey);
  11219. }
  11220. if (mustPreventNative) {
  11221. e.preventDefault();
  11222. editor.update(newEditorState);
  11223. return;
  11224. }
  11225. // We made it all the way! Let the browser do its thing and insert the char.
  11226. newEditorState = EditorState_1.set(newEditorState, {
  11227. nativelyRenderedContent: newEditorState.getCurrentContent()
  11228. });
  11229. // The native event is allowed to occur. To allow user onChange handlers to
  11230. // change the inserted text, we wait until the text is actually inserted
  11231. // before we actually update our state. That way when we rerender, the text
  11232. // we see in the DOM will already have been inserted properly.
  11233. editor._pendingStateFromBeforeInput = newEditorState;
  11234. setImmediate(function () {
  11235. if (editor._pendingStateFromBeforeInput !== undefined) {
  11236. editor.update(editor._pendingStateFromBeforeInput);
  11237. editor._pendingStateFromBeforeInput = undefined;
  11238. }
  11239. });
  11240. }
  11241. var editOnBeforeInput_1 = editOnBeforeInput;
  11242. function editOnBlur(editor, e) {
  11243. // In a contentEditable element, when you select a range and then click
  11244. // another active element, this does trigger a `blur` event but will not
  11245. // remove the DOM selection from the contenteditable.
  11246. // This is consistent across all browsers, but we prefer that the editor
  11247. // behave like a textarea, where a `blur` event clears the DOM selection.
  11248. // We therefore force the issue to be certain, checking whether the active
  11249. // element is `body` to force it when blurring occurs within the window (as
  11250. // opposed to clicking to another tab or window).
  11251. if (getActiveElement_1() === document.body) {
  11252. var _selection = styleInject_es.commonjsGlobal.getSelection();
  11253. var editorNode = editor.editor;
  11254. if (_selection.rangeCount === 1 && containsNode_1(editorNode, _selection.anchorNode) && containsNode_1(editorNode, _selection.focusNode)) {
  11255. _selection.removeAllRanges();
  11256. }
  11257. }
  11258. var editorState = editor._latestEditorState;
  11259. var currentSelection = editorState.getSelection();
  11260. if (!currentSelection.getHasFocus()) {
  11261. return;
  11262. }
  11263. var selection = currentSelection.set('hasFocus', false);
  11264. editor.props.onBlur && editor.props.onBlur(e);
  11265. editor.update(EditorState_1.acceptSelection(editorState, selection));
  11266. }
  11267. var editOnBlur_1 = editOnBlur;
  11268. /**
  11269. * The user has begun using an IME input system. Switching to `composite` mode
  11270. * allows handling composition input and disables other edit behavior.
  11271. */
  11272. function editOnCompositionStart(editor, e) {
  11273. editor.setMode('composite');
  11274. editor.update(EditorState_1.set(editor._latestEditorState, { inCompositionMode: true }));
  11275. // Allow composition handler to interpret the compositionstart event
  11276. editor._onCompositionStart(e);
  11277. }
  11278. var editOnCompositionStart_1 = editOnCompositionStart;
  11279. function getFragmentFromSelection(editorState) {
  11280. var selectionState = editorState.getSelection();
  11281. if (selectionState.isCollapsed()) {
  11282. return null;
  11283. }
  11284. return getContentStateFragment_1(editorState.getCurrentContent(), selectionState);
  11285. }
  11286. var getFragmentFromSelection_1 = getFragmentFromSelection;
  11287. /**
  11288. * If we have a selection, create a ContentState fragment and store
  11289. * it in our internal clipboard. Subsequent paste events will use this
  11290. * fragment if no external clipboard data is supplied.
  11291. */
  11292. function editOnCopy(editor, e) {
  11293. var editorState = editor._latestEditorState;
  11294. var selection = editorState.getSelection();
  11295. // No selection, so there's nothing to copy.
  11296. if (selection.isCollapsed()) {
  11297. e.preventDefault();
  11298. return;
  11299. }
  11300. editor.setClipboard(getFragmentFromSelection_1(editor._latestEditorState));
  11301. }
  11302. var editOnCopy_1 = editOnCopy;
  11303. /**
  11304. * On `cut` events, native behavior is allowed to occur so that the system
  11305. * clipboard is set properly. This means that we need to take steps to recover
  11306. * the editor DOM state after the `cut` has occurred in order to maintain
  11307. * control of the component.
  11308. *
  11309. * In addition, we can keep a copy of the removed fragment, including all
  11310. * styles and entities, for use as an internal paste.
  11311. */
  11312. function editOnCut(editor, e) {
  11313. var editorState = editor._latestEditorState;
  11314. var selection = editorState.getSelection();
  11315. var element = e.target;
  11316. var scrollPosition = void 0;
  11317. // No selection, so there's nothing to cut.
  11318. if (selection.isCollapsed()) {
  11319. e.preventDefault();
  11320. return;
  11321. }
  11322. // Track the current scroll position so that it can be forced back in place
  11323. // after the editor regains control of the DOM.
  11324. if (element instanceof Node) {
  11325. scrollPosition = getScrollPosition_1(Style_1.getScrollParent(element));
  11326. }
  11327. var fragment = getFragmentFromSelection_1(editorState);
  11328. editor.setClipboard(fragment);
  11329. // Set `cut` mode to disable all event handling temporarily.
  11330. editor.setMode('cut');
  11331. // Let native `cut` behavior occur, then recover control.
  11332. setTimeout(function () {
  11333. editor.restoreEditorDOM(scrollPosition);
  11334. editor.exitCurrentMode();
  11335. editor.update(removeFragment(editorState));
  11336. }, 0);
  11337. }
  11338. function removeFragment(editorState) {
  11339. var newContent = DraftModifier_1.removeRange(editorState.getCurrentContent(), editorState.getSelection(), 'forward');
  11340. return EditorState_1.push(editorState, newContent, 'remove-range');
  11341. }
  11342. var editOnCut_1 = editOnCut;
  11343. /**
  11344. * Copyright (c) 2013-present, Facebook, Inc.
  11345. * All rights reserved.
  11346. *
  11347. * This source code is licensed under the BSD-style license found in the
  11348. * LICENSE file in the root directory of this source tree. An additional grant
  11349. * of patent rights can be found in the PATENTS file in the same directory.
  11350. *
  11351. * @providesModule editOnDragOver
  11352. * @format
  11353. *
  11354. */
  11355. /**
  11356. * Drag behavior has begun from outside the editor element.
  11357. */
  11358. function editOnDragOver(editor, e) {
  11359. editor._internalDrag = false;
  11360. editor.setMode('drag');
  11361. e.preventDefault();
  11362. }
  11363. var editOnDragOver_1 = editOnDragOver;
  11364. /**
  11365. * Copyright (c) 2013-present, Facebook, Inc.
  11366. * All rights reserved.
  11367. *
  11368. * This source code is licensed under the BSD-style license found in the
  11369. * LICENSE file in the root directory of this source tree. An additional grant
  11370. * of patent rights can be found in the PATENTS file in the same directory.
  11371. *
  11372. * @providesModule editOnDragStart
  11373. * @format
  11374. *
  11375. */
  11376. /**
  11377. * A `dragstart` event has begun within the text editor component.
  11378. */
  11379. function editOnDragStart(editor) {
  11380. editor._internalDrag = true;
  11381. editor.setMode('drag');
  11382. }
  11383. var editOnDragStart_1 = editOnDragStart;
  11384. function editOnFocus(editor, e) {
  11385. var editorState = editor._latestEditorState;
  11386. var currentSelection = editorState.getSelection();
  11387. if (currentSelection.getHasFocus()) {
  11388. return;
  11389. }
  11390. var selection = currentSelection.set('hasFocus', true);
  11391. editor.props.onFocus && editor.props.onFocus(e);
  11392. // When the tab containing this text editor is hidden and the user does a
  11393. // find-in-page in a _different_ tab, Chrome on Mac likes to forget what the
  11394. // selection was right after sending this focus event and (if you let it)
  11395. // moves the cursor back to the beginning of the editor, so we force the
  11396. // selection here instead of simply accepting it in order to preserve the
  11397. // old cursor position. See https://crbug.com/540004.
  11398. // But it looks like this is fixed in Chrome 60.0.3081.0.
  11399. // Other browsers also don't have this bug, so we prefer to acceptSelection
  11400. // when possible, to ensure that unfocusing and refocusing a Draft editor
  11401. // doesn't preserve the selection, matching how textareas work.
  11402. if (UserAgent_1.isBrowser('Chrome < 60.0.3081.0')) {
  11403. editor.update(EditorState_1.forceSelection(editorState, selection));
  11404. } else {
  11405. editor.update(EditorState_1.acceptSelection(editorState, selection));
  11406. }
  11407. }
  11408. var editOnFocus_1 = editOnFocus;
  11409. var isGecko = UserAgent_1.isEngine('Gecko');
  11410. var DOUBLE_NEWLINE = '\n\n';
  11411. /**
  11412. * This function is intended to handle spellcheck and autocorrect changes,
  11413. * which occur in the DOM natively without any opportunity to observe or
  11414. * interpret the changes before they occur.
  11415. *
  11416. * The `input` event fires in contentEditable elements reliably for non-IE
  11417. * browsers, immediately after changes occur to the editor DOM. Since our other
  11418. * handlers override or otherwise handle cover other varieties of text input,
  11419. * the DOM state should match the model in all controlled input cases. Thus,
  11420. * when an `input` change leads to a DOM/model mismatch, the change should be
  11421. * due to a spellcheck change, and we can incorporate it into our model.
  11422. */
  11423. function editOnInput(editor) {
  11424. if (editor._pendingStateFromBeforeInput !== undefined) {
  11425. editor.update(editor._pendingStateFromBeforeInput);
  11426. editor._pendingStateFromBeforeInput = undefined;
  11427. }
  11428. var domSelection = styleInject_es.commonjsGlobal.getSelection();
  11429. var anchorNode = domSelection.anchorNode,
  11430. isCollapsed = domSelection.isCollapsed;
  11431. var isNotTextNode = anchorNode.nodeType !== Node.TEXT_NODE;
  11432. var isNotTextOrElementNode = anchorNode.nodeType !== Node.TEXT_NODE && anchorNode.nodeType !== Node.ELEMENT_NODE;
  11433. {
  11434. if (isNotTextOrElementNode) {
  11435. // TODO: (t16149272) figure out context for this change
  11436. return;
  11437. }
  11438. }
  11439. if (anchorNode.nodeType === Node.TEXT_NODE && (anchorNode.previousSibling !== null || anchorNode.nextSibling !== null)) {
  11440. // When typing at the beginning of a visual line, Chrome splits the text
  11441. // nodes into two. Why? No one knows. This commit is suspicious:
  11442. // https://chromium.googlesource.com/chromium/src/+/a3b600981286b135632371477f902214c55a1724
  11443. // To work around, we'll merge the sibling text nodes back into this one.
  11444. var span = anchorNode.parentNode;
  11445. anchorNode.nodeValue = span.textContent;
  11446. for (var child = span.firstChild; child !== null; child = child.nextSibling) {
  11447. if (child !== anchorNode) {
  11448. span.removeChild(child);
  11449. }
  11450. }
  11451. }
  11452. var domText = anchorNode.textContent;
  11453. var editorState = editor._latestEditorState;
  11454. var offsetKey = nullthrows_1(findAncestorOffsetKey_1(anchorNode));
  11455. var _DraftOffsetKey$decod = DraftOffsetKey_1.decode(offsetKey),
  11456. blockKey = _DraftOffsetKey$decod.blockKey,
  11457. decoratorKey = _DraftOffsetKey$decod.decoratorKey,
  11458. leafKey = _DraftOffsetKey$decod.leafKey;
  11459. var _editorState$getBlock = editorState.getBlockTree(blockKey).getIn([decoratorKey, 'leaves', leafKey]),
  11460. start = _editorState$getBlock.start,
  11461. end = _editorState$getBlock.end;
  11462. var content = editorState.getCurrentContent();
  11463. var block = content.getBlockForKey(blockKey);
  11464. var modelText = block.getText().slice(start, end);
  11465. // Special-case soft newlines here. If the DOM text ends in a soft newline,
  11466. // we will have manually inserted an extra soft newline in DraftEditorLeaf.
  11467. // We want to remove this extra newline for the purpose of our comparison
  11468. // of DOM and model text.
  11469. if (domText.endsWith(DOUBLE_NEWLINE)) {
  11470. domText = domText.slice(0, -1);
  11471. }
  11472. // No change -- the DOM is up to date. Nothing to do here.
  11473. if (domText === modelText) {
  11474. // This can be buggy for some Android keyboards because they don't fire
  11475. // standard onkeydown/pressed events and only fired editOnInput
  11476. // so domText is already changed by the browser and ends up being equal
  11477. // to modelText unexpectedly
  11478. return;
  11479. }
  11480. var selection = editorState.getSelection();
  11481. // We'll replace the entire leaf with the text content of the target.
  11482. var targetRange = selection.merge({
  11483. anchorOffset: start,
  11484. focusOffset: end,
  11485. isBackward: false
  11486. });
  11487. var entityKey = block.getEntityAt(start);
  11488. var entity = entityKey && content.getEntity(entityKey);
  11489. var entityType = entity && entity.getMutability();
  11490. var preserveEntity = entityType === 'MUTABLE';
  11491. // Immutable or segmented entities cannot properly be handled by the
  11492. // default browser undo, so we have to use a different change type to
  11493. // force using our internal undo method instead of falling through to the
  11494. // native browser undo.
  11495. var changeType = preserveEntity ? 'spellcheck-change' : 'apply-entity';
  11496. var newContent = DraftModifier_1.replaceText(content, targetRange, domText, block.getInlineStyleAt(start), preserveEntity ? block.getEntityAt(start) : null);
  11497. var anchorOffset, focusOffset, startOffset, endOffset;
  11498. if (isGecko) {
  11499. // Firefox selection does not change while the context menu is open, so
  11500. // we preserve the anchor and focus values of the DOM selection.
  11501. anchorOffset = domSelection.anchorOffset;
  11502. focusOffset = domSelection.focusOffset;
  11503. startOffset = start + Math.min(anchorOffset, focusOffset);
  11504. endOffset = startOffset + Math.abs(anchorOffset - focusOffset);
  11505. anchorOffset = startOffset;
  11506. focusOffset = endOffset;
  11507. } else {
  11508. // Browsers other than Firefox may adjust DOM selection while the context
  11509. // menu is open, and Safari autocorrect is prone to providing an inaccurate
  11510. // DOM selection. Don't trust it. Instead, use our existing SelectionState
  11511. // and adjust it based on the number of characters changed during the
  11512. // mutation.
  11513. var charDelta = domText.length - modelText.length;
  11514. startOffset = selection.getStartOffset();
  11515. endOffset = selection.getEndOffset();
  11516. anchorOffset = isCollapsed ? endOffset + charDelta : startOffset;
  11517. focusOffset = endOffset + charDelta;
  11518. }
  11519. // Segmented entities are completely or partially removed when their
  11520. // text content changes. For this case we do not want any text to be selected
  11521. // after the change, so we are not merging the selection.
  11522. var contentWithAdjustedDOMSelection = newContent.merge({
  11523. selectionBefore: content.getSelectionAfter(),
  11524. selectionAfter: selection.merge({ anchorOffset: anchorOffset, focusOffset: focusOffset })
  11525. });
  11526. editor.update(EditorState_1.push(editorState, contentWithAdjustedDOMSelection, changeType));
  11527. }
  11528. var editOnInput_1 = editOnInput;
  11529. var isOSX = UserAgent_1.isPlatform('Mac OS X');
  11530. var KeyBindingUtil = {
  11531. /**
  11532. * Check whether the ctrlKey modifier is *not* being used in conjunction with
  11533. * the altKey modifier. If they are combined, the result is an `altGraph`
  11534. * key modifier, which should not be handled by this set of key bindings.
  11535. */
  11536. isCtrlKeyCommand: function isCtrlKeyCommand(e) {
  11537. return !!e.ctrlKey && !e.altKey;
  11538. },
  11539. isOptionKeyCommand: function isOptionKeyCommand(e) {
  11540. return isOSX && e.altKey;
  11541. },
  11542. hasCommandModifier: function hasCommandModifier(e) {
  11543. return isOSX ? !!e.metaKey && !e.altKey : KeyBindingUtil.isCtrlKeyCommand(e);
  11544. }
  11545. };
  11546. var KeyBindingUtil_1 = KeyBindingUtil;
  11547. var clipboard = null;
  11548. /**
  11549. * Some systems offer a "secondary" clipboard to allow quick internal cut
  11550. * and paste behavior. For instance, Ctrl+K (cut) and Ctrl+Y (paste).
  11551. */
  11552. var SecondaryClipboard = {
  11553. cut: function cut(editorState) {
  11554. var content = editorState.getCurrentContent();
  11555. var selection = editorState.getSelection();
  11556. var targetRange = null;
  11557. if (selection.isCollapsed()) {
  11558. var anchorKey = selection.getAnchorKey();
  11559. var blockEnd = content.getBlockForKey(anchorKey).getLength();
  11560. if (blockEnd === selection.getAnchorOffset()) {
  11561. return editorState;
  11562. }
  11563. targetRange = selection.set('focusOffset', blockEnd);
  11564. } else {
  11565. targetRange = selection;
  11566. }
  11567. targetRange = nullthrows_1(targetRange);
  11568. clipboard = getContentStateFragment_1(content, targetRange);
  11569. var afterRemoval = DraftModifier_1.removeRange(content, targetRange, 'forward');
  11570. if (afterRemoval === content) {
  11571. return editorState;
  11572. }
  11573. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  11574. },
  11575. paste: function paste(editorState) {
  11576. if (!clipboard) {
  11577. return editorState;
  11578. }
  11579. var newContent = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), clipboard);
  11580. return EditorState_1.push(editorState, newContent, 'insert-fragment');
  11581. }
  11582. };
  11583. var SecondaryClipboard_1 = SecondaryClipboard;
  11584. // These two ranges are consecutive so anything in [HIGH_START, LOW_END] is a
  11585. // surrogate code unit.
  11586. var SURROGATE_HIGH_START = 0xD800;
  11587. var SURROGATE_HIGH_END = 0xDBFF;
  11588. var SURROGATE_LOW_START = 0xDC00;
  11589. var SURROGATE_LOW_END = 0xDFFF;
  11590. var SURROGATE_UNITS_REGEX = /[\uD800-\uDFFF]/;
  11591. /**
  11592. * @param {number} codeUnit A Unicode code-unit, in range [0, 0x10FFFF]
  11593. * @return {boolean} Whether code-unit is in a surrogate (hi/low) range
  11594. */
  11595. function isCodeUnitInSurrogateRange(codeUnit) {
  11596. return SURROGATE_HIGH_START <= codeUnit && codeUnit <= SURROGATE_LOW_END;
  11597. }
  11598. /**
  11599. * Returns whether the two characters starting at `index` form a surrogate pair.
  11600. * For example, given the string s = "\uD83D\uDE0A", (s, 0) returns true and
  11601. * (s, 1) returns false.
  11602. *
  11603. * @param {string} str
  11604. * @param {number} index
  11605. * @return {boolean}
  11606. */
  11607. function isSurrogatePair(str, index) {
  11608. !(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;
  11609. if (index + 1 === str.length) {
  11610. return false;
  11611. }
  11612. var first = str.charCodeAt(index);
  11613. var second = str.charCodeAt(index + 1);
  11614. return SURROGATE_HIGH_START <= first && first <= SURROGATE_HIGH_END && SURROGATE_LOW_START <= second && second <= SURROGATE_LOW_END;
  11615. }
  11616. /**
  11617. * @param {string} str Non-empty string
  11618. * @return {boolean} True if the input includes any surrogate code units
  11619. */
  11620. function hasSurrogateUnit(str) {
  11621. return SURROGATE_UNITS_REGEX.test(str);
  11622. }
  11623. /**
  11624. * Return the length of the original Unicode character at given position in the
  11625. * String by looking into the UTF-16 code unit; that is equal to 1 for any
  11626. * non-surrogate characters in BMP ([U+0000..U+D7FF] and [U+E000, U+FFFF]); and
  11627. * returns 2 for the hi/low surrogates ([U+D800..U+DFFF]), which are in fact
  11628. * representing non-BMP characters ([U+10000..U+10FFFF]).
  11629. *
  11630. * Examples:
  11631. * - '\u0020' => 1
  11632. * - '\u3020' => 1
  11633. * - '\uD835' => 2
  11634. * - '\uD835\uDDEF' => 2
  11635. * - '\uDDEF' => 2
  11636. *
  11637. * @param {string} str Non-empty string
  11638. * @param {number} pos Position in the string to look for one code unit
  11639. * @return {number} Number 1 or 2
  11640. */
  11641. function getUTF16Length(str, pos) {
  11642. return 1 + isCodeUnitInSurrogateRange(str.charCodeAt(pos));
  11643. }
  11644. /**
  11645. * Fully Unicode-enabled replacement for String#length
  11646. *
  11647. * @param {string} str Valid Unicode string
  11648. * @return {number} The number of Unicode characters in the string
  11649. */
  11650. function strlen(str) {
  11651. // Call the native functions if there's no surrogate char
  11652. if (!hasSurrogateUnit(str)) {
  11653. return str.length;
  11654. }
  11655. var len = 0;
  11656. for (var pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
  11657. len++;
  11658. }
  11659. return len;
  11660. }
  11661. /**
  11662. * Fully Unicode-enabled replacement for String#substr()
  11663. *
  11664. * @param {string} str Valid Unicode string
  11665. * @param {number} start Location in Unicode sequence to begin extracting
  11666. * @param {?number} length The number of Unicode characters to extract
  11667. * (default: to the end of the string)
  11668. * @return {string} Extracted sub-string
  11669. */
  11670. function substr(str, start, length) {
  11671. start = start || 0;
  11672. length = length === undefined ? Infinity : length || 0;
  11673. // Call the native functions if there's no surrogate char
  11674. if (!hasSurrogateUnit(str)) {
  11675. return str.substr(start, length);
  11676. }
  11677. // Obvious cases
  11678. var size = str.length;
  11679. if (size <= 0 || start > size || length <= 0) {
  11680. return '';
  11681. }
  11682. // Find the actual starting position
  11683. var posA = 0;
  11684. if (start > 0) {
  11685. for (; start > 0 && posA < size; start--) {
  11686. posA += getUTF16Length(str, posA);
  11687. }
  11688. if (posA >= size) {
  11689. return '';
  11690. }
  11691. } else if (start < 0) {
  11692. for (posA = size; start < 0 && 0 < posA; start++) {
  11693. posA -= getUTF16Length(str, posA - 1);
  11694. }
  11695. if (posA < 0) {
  11696. posA = 0;
  11697. }
  11698. }
  11699. // Find the actual ending position
  11700. var posB = size;
  11701. if (length < size) {
  11702. for (posB = posA; length > 0 && posB < size; length--) {
  11703. posB += getUTF16Length(str, posB);
  11704. }
  11705. }
  11706. return str.substring(posA, posB);
  11707. }
  11708. /**
  11709. * Fully Unicode-enabled replacement for String#substring()
  11710. *
  11711. * @param {string} str Valid Unicode string
  11712. * @param {number} start Location in Unicode sequence to begin extracting
  11713. * @param {?number} end Location in Unicode sequence to end extracting
  11714. * (default: end of the string)
  11715. * @return {string} Extracted sub-string
  11716. */
  11717. function substring(str, start, end) {
  11718. start = start || 0;
  11719. end = end === undefined ? Infinity : end || 0;
  11720. if (start < 0) {
  11721. start = 0;
  11722. }
  11723. if (end < 0) {
  11724. end = 0;
  11725. }
  11726. var length = Math.abs(end - start);
  11727. start = start < end ? start : end;
  11728. return substr(str, start, length);
  11729. }
  11730. /**
  11731. * Get a list of Unicode code-points from a String
  11732. *
  11733. * @param {string} str Valid Unicode string
  11734. * @return {array<number>} A list of code-points in [0..0x10FFFF]
  11735. */
  11736. function getCodePoints(str) {
  11737. var codePoints = [];
  11738. for (var pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
  11739. codePoints.push(str.codePointAt(pos));
  11740. }
  11741. return codePoints;
  11742. }
  11743. var UnicodeUtils = {
  11744. getCodePoints: getCodePoints,
  11745. getUTF16Length: getUTF16Length,
  11746. hasSurrogateUnit: hasSurrogateUnit,
  11747. isCodeUnitInSurrogateRange: isCodeUnitInSurrogateRange,
  11748. isSurrogatePair: isSurrogatePair,
  11749. strlen: strlen,
  11750. substring: substring,
  11751. substr: substr
  11752. };
  11753. var UnicodeUtils_1 = UnicodeUtils;
  11754. var isChrome = UserAgent_1.isBrowser('Chrome');
  11755. // In Chrome, the client rects will include the entire bounds of all nodes that
  11756. // begin (have a start tag) within the selection, even if the selection does
  11757. // not overlap the entire node. To resolve this, we split the range at each
  11758. // start tag and join the client rects together.
  11759. // https://code.google.com/p/chromium/issues/detail?id=324437
  11760. /* eslint-disable consistent-return */
  11761. function getRangeClientRectsChrome(range) {
  11762. var tempRange = range.cloneRange();
  11763. var clientRects = [];
  11764. for (var ancestor = range.endContainer; ancestor != null; ancestor = ancestor.parentNode) {
  11765. // If we've climbed up to the common ancestor, we can now use the
  11766. // original start point and stop climbing the tree.
  11767. var atCommonAncestor = ancestor === range.commonAncestorContainer;
  11768. if (atCommonAncestor) {
  11769. tempRange.setStart(range.startContainer, range.startOffset);
  11770. } else {
  11771. tempRange.setStart(tempRange.endContainer, 0);
  11772. }
  11773. var rects = Array.from(tempRange.getClientRects());
  11774. clientRects.push(rects);
  11775. if (atCommonAncestor) {
  11776. var _ref;
  11777. clientRects.reverse();
  11778. return (_ref = []).concat.apply(_ref, clientRects);
  11779. }
  11780. tempRange.setEndBefore(ancestor);
  11781. }
  11782. process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Found an unexpected detached subtree when getting range client rects.') : invariant_1(false) ;
  11783. }
  11784. /* eslint-enable consistent-return */
  11785. /**
  11786. * Like range.getClientRects() but normalizes for browser bugs.
  11787. */
  11788. var getRangeClientRects = isChrome ? getRangeClientRectsChrome : function (range) {
  11789. return Array.from(range.getClientRects());
  11790. };
  11791. var getRangeClientRects_1 = getRangeClientRects;
  11792. /**
  11793. * Copyright (c) 2013-present, Facebook, Inc.
  11794. * All rights reserved.
  11795. *
  11796. * This source code is licensed under the BSD-style license found in the
  11797. * LICENSE file in the root directory of this source tree. An additional grant
  11798. * of patent rights can be found in the PATENTS file in the same directory.
  11799. *
  11800. * @providesModule expandRangeToStartOfLine
  11801. * @format
  11802. *
  11803. */
  11804. /**
  11805. * Return the computed line height, in pixels, for the provided element.
  11806. */
  11807. function getLineHeightPx(element) {
  11808. var computed = getComputedStyle(element);
  11809. var div = document.createElement('div');
  11810. div.style.fontFamily = computed.fontFamily;
  11811. div.style.fontSize = computed.fontSize;
  11812. div.style.fontStyle = computed.fontStyle;
  11813. div.style.fontWeight = computed.fontWeight;
  11814. div.style.lineHeight = computed.lineHeight;
  11815. div.style.position = 'absolute';
  11816. div.textContent = 'M';
  11817. var documentBody = document.body;
  11818. !documentBody ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing document.body') : invariant_1(false) : void 0;
  11819. // forced layout here
  11820. documentBody.appendChild(div);
  11821. var rect = div.getBoundingClientRect();
  11822. documentBody.removeChild(div);
  11823. return rect.height;
  11824. }
  11825. /**
  11826. * Return whether every ClientRect in the provided list lies on the same line.
  11827. *
  11828. * We assume that the rects on the same line all contain the baseline, so the
  11829. * lowest top line needs to be above the highest bottom line (i.e., if you were
  11830. * to project the rects onto the y-axis, their intersection would be nonempty).
  11831. *
  11832. * In addition, we require that no two boxes are lineHeight (or more) apart at
  11833. * either top or bottom, which helps protect against false positives for fonts
  11834. * with extremely large glyph heights (e.g., with a font size of 17px, Zapfino
  11835. * produces rects of height 58px!).
  11836. */
  11837. function areRectsOnOneLine(rects, lineHeight) {
  11838. var minTop = Infinity;
  11839. var minBottom = Infinity;
  11840. var maxTop = -Infinity;
  11841. var maxBottom = -Infinity;
  11842. for (var ii = 0; ii < rects.length; ii++) {
  11843. var rect = rects[ii];
  11844. if (rect.width === 0 || rect.width === 1) {
  11845. // When a range starts or ends a soft wrap, many browsers (Chrome, IE,
  11846. // Safari) include an empty rect on the previous or next line. When the
  11847. // text lies in a container whose position is not integral (e.g., from
  11848. // margin: auto), Safari makes these empty rects have width 1 (instead of
  11849. // 0). Having one-pixel-wide characters seems unlikely (and most browsers
  11850. // report widths in subpixel precision anyway) so it's relatively safe to
  11851. // skip over them.
  11852. continue;
  11853. }
  11854. minTop = Math.min(minTop, rect.top);
  11855. minBottom = Math.min(minBottom, rect.bottom);
  11856. maxTop = Math.max(maxTop, rect.top);
  11857. maxBottom = Math.max(maxBottom, rect.bottom);
  11858. }
  11859. return maxTop <= minBottom && maxTop - minTop < lineHeight && maxBottom - minBottom < lineHeight;
  11860. }
  11861. /**
  11862. * Return the length of a node, as used by Range offsets.
  11863. */
  11864. function getNodeLength$1(node) {
  11865. // http://www.w3.org/TR/dom/#concept-node-length
  11866. switch (node.nodeType) {
  11867. case Node.DOCUMENT_TYPE_NODE:
  11868. return 0;
  11869. case Node.TEXT_NODE:
  11870. case Node.PROCESSING_INSTRUCTION_NODE:
  11871. case Node.COMMENT_NODE:
  11872. return node.length;
  11873. default:
  11874. return node.childNodes.length;
  11875. }
  11876. }
  11877. /**
  11878. * Given a collapsed range, move the start position backwards as far as
  11879. * possible while the range still spans only a single line.
  11880. */
  11881. function expandRangeToStartOfLine(range) {
  11882. !range.collapsed ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'expandRangeToStartOfLine: Provided range is not collapsed.') : invariant_1(false) : void 0;
  11883. range = range.cloneRange();
  11884. var containingElement = range.startContainer;
  11885. if (containingElement.nodeType !== 1) {
  11886. containingElement = containingElement.parentNode;
  11887. }
  11888. var lineHeight = getLineHeightPx(containingElement);
  11889. // Imagine our text looks like:
  11890. // <div><span>once upon a time, there was a <em>boy
  11891. // who lived</em> </span><q><strong>under^ the
  11892. // stairs</strong> in a small closet.</q></div>
  11893. // where the caret represents the cursor. First, we crawl up the tree until
  11894. // the range spans multiple lines (setting the start point to before
  11895. // "<strong>", then before "<div>"), then at each level we do a search to
  11896. // find the latest point which is still on a previous line. We'll find that
  11897. // the break point is inside the span, then inside the <em>, then in its text
  11898. // node child, the actual break point before "who".
  11899. var bestContainer = range.endContainer;
  11900. var bestOffset = range.endOffset;
  11901. range.setStart(range.startContainer, 0);
  11902. while (areRectsOnOneLine(getRangeClientRects_1(range), lineHeight)) {
  11903. bestContainer = range.startContainer;
  11904. bestOffset = range.startOffset;
  11905. !bestContainer.parentNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Found unexpected detached subtree when traversing.') : invariant_1(false) : void 0;
  11906. range.setStartBefore(bestContainer);
  11907. if (bestContainer.nodeType === 1 && getComputedStyle(bestContainer).display !== 'inline') {
  11908. // The start of the line is never in a different block-level container.
  11909. break;
  11910. }
  11911. }
  11912. // In the above example, range now spans from "<div>" to "under",
  11913. // bestContainer is <div>, and bestOffset is 1 (index of <q> inside <div>)].
  11914. // Picking out which child to recurse into here is a special case since we
  11915. // don't want to check past <q> -- once we find that the final range starts
  11916. // in <span>, we can look at all of its children (and all of their children)
  11917. // to find the break point.
  11918. // At all times, (bestContainer, bestOffset) is the latest single-line start
  11919. // point that we know of.
  11920. var currentContainer = bestContainer;
  11921. var maxIndexToConsider = bestOffset - 1;
  11922. do {
  11923. var nodeValue = currentContainer.nodeValue;
  11924. for (var ii = maxIndexToConsider; ii >= 0; ii--) {
  11925. if (nodeValue != null && ii > 0 && UnicodeUtils_1.isSurrogatePair(nodeValue, ii - 1)) {
  11926. // We're in the middle of a surrogate pair -- skip over so we never
  11927. // return a range with an endpoint in the middle of a code point.
  11928. continue;
  11929. }
  11930. range.setStart(currentContainer, ii);
  11931. if (areRectsOnOneLine(getRangeClientRects_1(range), lineHeight)) {
  11932. bestContainer = currentContainer;
  11933. bestOffset = ii;
  11934. } else {
  11935. break;
  11936. }
  11937. }
  11938. if (ii === -1 || currentContainer.childNodes.length === 0) {
  11939. // If ii === -1, then (bestContainer, bestOffset), which is equal to
  11940. // (currentContainer, 0), was a single-line start point but a start
  11941. // point before currentContainer wasn't, so the line break seems to
  11942. // have occurred immediately after currentContainer's start tag
  11943. //
  11944. // If currentContainer.childNodes.length === 0, we're already at a
  11945. // terminal node (e.g., text node) and should return our current best.
  11946. break;
  11947. }
  11948. currentContainer = currentContainer.childNodes[ii];
  11949. maxIndexToConsider = getNodeLength$1(currentContainer);
  11950. } while (true);
  11951. range.setStart(bestContainer, bestOffset);
  11952. return range;
  11953. }
  11954. var expandRangeToStartOfLine_1 = expandRangeToStartOfLine;
  11955. /**
  11956. * Convert the current selection range to an anchor/focus pair of offset keys
  11957. * and values that can be interpreted by components.
  11958. */
  11959. function getDraftEditorSelectionWithNodes(editorState, root, anchorNode, anchorOffset, focusNode, focusOffset) {
  11960. var anchorIsTextNode = anchorNode.nodeType === Node.TEXT_NODE;
  11961. var focusIsTextNode = focusNode.nodeType === Node.TEXT_NODE;
  11962. // If the selection range lies only on text nodes, the task is simple.
  11963. // Find the nearest offset-aware elements and use the
  11964. // offset values supplied by the selection range.
  11965. if (anchorIsTextNode && focusIsTextNode) {
  11966. return {
  11967. selectionState: getUpdatedSelectionState_1(editorState, nullthrows_1(findAncestorOffsetKey_1(anchorNode)), anchorOffset, nullthrows_1(findAncestorOffsetKey_1(focusNode)), focusOffset),
  11968. needsRecovery: false
  11969. };
  11970. }
  11971. var anchorPoint = null;
  11972. var focusPoint = null;
  11973. var needsRecovery = true;
  11974. // An element is selected. Convert this selection range into leaf offset
  11975. // keys and offset values for consumption at the component level. This
  11976. // is common in Firefox, where select-all and triple click behavior leads
  11977. // to entire elements being selected.
  11978. //
  11979. // Note that we use the `needsRecovery` parameter in the callback here. This
  11980. // is because when certain elements are selected, the behavior for subsequent
  11981. // cursor movement (e.g. via arrow keys) is uncertain and may not match
  11982. // expectations at the component level. For example, if an entire <div> is
  11983. // selected and the user presses the right arrow, Firefox keeps the selection
  11984. // on the <div>. If we allow subsequent keypresses to insert characters
  11985. // natively, they will be inserted into a browser-created text node to the
  11986. // right of that <div>. This is obviously undesirable.
  11987. //
  11988. // With the `needsRecovery` flag, we inform the caller that it is responsible
  11989. // for manually setting the selection state on the rendered document to
  11990. // ensure proper selection state maintenance.
  11991. if (anchorIsTextNode) {
  11992. anchorPoint = {
  11993. key: nullthrows_1(findAncestorOffsetKey_1(anchorNode)),
  11994. offset: anchorOffset
  11995. };
  11996. focusPoint = getPointForNonTextNode(root, focusNode, focusOffset);
  11997. } else if (focusIsTextNode) {
  11998. focusPoint = {
  11999. key: nullthrows_1(findAncestorOffsetKey_1(focusNode)),
  12000. offset: focusOffset
  12001. };
  12002. anchorPoint = getPointForNonTextNode(root, anchorNode, anchorOffset);
  12003. } else {
  12004. anchorPoint = getPointForNonTextNode(root, anchorNode, anchorOffset);
  12005. focusPoint = getPointForNonTextNode(root, focusNode, focusOffset);
  12006. // If the selection is collapsed on an empty block, don't force recovery.
  12007. // This way, on arrow key selection changes, the browser can move the
  12008. // cursor from a non-zero offset on one block, through empty blocks,
  12009. // to a matching non-zero offset on other text blocks.
  12010. if (anchorNode === focusNode && anchorOffset === focusOffset) {
  12011. needsRecovery = !!anchorNode.firstChild && anchorNode.firstChild.nodeName !== 'BR';
  12012. }
  12013. }
  12014. return {
  12015. selectionState: getUpdatedSelectionState_1(editorState, anchorPoint.key, anchorPoint.offset, focusPoint.key, focusPoint.offset),
  12016. needsRecovery: needsRecovery
  12017. };
  12018. }
  12019. /**
  12020. * Identify the first leaf descendant for the given node.
  12021. */
  12022. function getFirstLeaf(node) {
  12023. while (node.firstChild && (
  12024. // data-blocks has no offset
  12025. node.firstChild instanceof Element && node.firstChild.getAttribute('data-blocks') === 'true' || getSelectionOffsetKeyForNode_1(node.firstChild))) {
  12026. node = node.firstChild;
  12027. }
  12028. return node;
  12029. }
  12030. /**
  12031. * Identify the last leaf descendant for the given node.
  12032. */
  12033. function getLastLeaf(node) {
  12034. while (node.lastChild && (
  12035. // data-blocks has no offset
  12036. node.lastChild instanceof Element && node.lastChild.getAttribute('data-blocks') === 'true' || getSelectionOffsetKeyForNode_1(node.lastChild))) {
  12037. node = node.lastChild;
  12038. }
  12039. return node;
  12040. }
  12041. function getPointForNonTextNode(editorRoot, startNode, childOffset) {
  12042. var node = startNode;
  12043. var offsetKey = findAncestorOffsetKey_1(node);
  12044. !(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;
  12045. // If the editorRoot is the selection, step downward into the content
  12046. // wrapper.
  12047. if (editorRoot === node) {
  12048. node = node.firstChild;
  12049. !(node instanceof Element && node.getAttribute('data-contents') === 'true') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid DraftEditorContents structure.') : invariant_1(false) : void 0;
  12050. if (childOffset > 0) {
  12051. childOffset = node.childNodes.length;
  12052. }
  12053. }
  12054. // If the child offset is zero and we have an offset key, we're done.
  12055. // If there's no offset key because the entire editor is selected,
  12056. // find the leftmost ("first") leaf in the tree and use that as the offset
  12057. // key.
  12058. if (childOffset === 0) {
  12059. var key = null;
  12060. if (offsetKey != null) {
  12061. key = offsetKey;
  12062. } else {
  12063. var firstLeaf = getFirstLeaf(node);
  12064. key = nullthrows_1(getSelectionOffsetKeyForNode_1(firstLeaf));
  12065. }
  12066. return { key: key, offset: 0 };
  12067. }
  12068. var nodeBeforeCursor = node.childNodes[childOffset - 1];
  12069. var leafKey = null;
  12070. var textLength = null;
  12071. if (!getSelectionOffsetKeyForNode_1(nodeBeforeCursor)) {
  12072. // Our target node may be a leaf or a text node, in which case we're
  12073. // already where we want to be and can just use the child's length as
  12074. // our offset.
  12075. leafKey = nullthrows_1(offsetKey);
  12076. textLength = getTextContentLength(nodeBeforeCursor);
  12077. } else {
  12078. // Otherwise, we'll look at the child to the left of the cursor and find
  12079. // the last leaf node in its subtree.
  12080. var lastLeaf = getLastLeaf(nodeBeforeCursor);
  12081. leafKey = nullthrows_1(getSelectionOffsetKeyForNode_1(lastLeaf));
  12082. textLength = getTextContentLength(lastLeaf);
  12083. }
  12084. return {
  12085. key: leafKey,
  12086. offset: textLength
  12087. };
  12088. }
  12089. /**
  12090. * Return the length of a node's textContent, regarding single newline
  12091. * characters as zero-length. This allows us to avoid problems with identifying
  12092. * the correct selection offset for empty blocks in IE, in which we
  12093. * render newlines instead of break tags.
  12094. */
  12095. function getTextContentLength(node) {
  12096. var textContent = node.textContent;
  12097. return textContent === '\n' ? 0 : textContent.length;
  12098. }
  12099. var getDraftEditorSelectionWithNodes_1 = getDraftEditorSelectionWithNodes;
  12100. /**
  12101. * Copyright (c) 2013-present, Facebook, Inc.
  12102. * All rights reserved.
  12103. *
  12104. * This source code is licensed under the BSD-style license found in the
  12105. * LICENSE file in the root directory of this source tree. An additional grant
  12106. * of patent rights can be found in the PATENTS file in the same directory.
  12107. *
  12108. * @providesModule moveSelectionBackward
  12109. * @format
  12110. *
  12111. */
  12112. /**
  12113. * Given a collapsed selection, move the focus `maxDistance` backward within
  12114. * the selected block. If the selection will go beyond the start of the block,
  12115. * move focus to the end of the previous block, but no further.
  12116. *
  12117. * This function is not Unicode-aware, so surrogate pairs will be treated
  12118. * as having length 2.
  12119. */
  12120. function moveSelectionBackward(editorState, maxDistance) {
  12121. var selection = editorState.getSelection();
  12122. var content = editorState.getCurrentContent();
  12123. var key = selection.getStartKey();
  12124. var offset = selection.getStartOffset();
  12125. var focusKey = key;
  12126. var focusOffset = 0;
  12127. if (maxDistance > offset) {
  12128. var keyBefore = content.getKeyBefore(key);
  12129. if (keyBefore == null) {
  12130. focusKey = key;
  12131. } else {
  12132. focusKey = keyBefore;
  12133. var blockBefore = content.getBlockForKey(keyBefore);
  12134. focusOffset = blockBefore.getText().length;
  12135. }
  12136. } else {
  12137. focusOffset = offset - maxDistance;
  12138. }
  12139. return selection.merge({
  12140. focusKey: focusKey,
  12141. focusOffset: focusOffset,
  12142. isBackward: true
  12143. });
  12144. }
  12145. var moveSelectionBackward_1 = moveSelectionBackward;
  12146. /**
  12147. * For a collapsed selection state, remove text based on the specified strategy.
  12148. * If the selection state is not collapsed, remove the entire selected range.
  12149. */
  12150. function removeTextWithStrategy(editorState, strategy, direction) {
  12151. var selection = editorState.getSelection();
  12152. var content = editorState.getCurrentContent();
  12153. var target = selection;
  12154. if (selection.isCollapsed()) {
  12155. if (direction === 'forward') {
  12156. if (editorState.isSelectionAtEndOfContent()) {
  12157. return content;
  12158. }
  12159. } else if (editorState.isSelectionAtStartOfContent()) {
  12160. return content;
  12161. }
  12162. target = strategy(editorState);
  12163. if (target === selection) {
  12164. return content;
  12165. }
  12166. }
  12167. return DraftModifier_1.removeRange(content, target, direction);
  12168. }
  12169. var removeTextWithStrategy_1 = removeTextWithStrategy;
  12170. function keyCommandBackspaceToStartOfLine(editorState) {
  12171. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12172. var selection = strategyState.getSelection();
  12173. if (selection.isCollapsed() && selection.getAnchorOffset() === 0) {
  12174. return moveSelectionBackward_1(strategyState, 1);
  12175. }
  12176. var domSelection = styleInject_es.commonjsGlobal.getSelection();
  12177. var range = domSelection.getRangeAt(0);
  12178. range = expandRangeToStartOfLine_1(range);
  12179. return getDraftEditorSelectionWithNodes_1(strategyState, null, range.endContainer, range.endOffset, range.startContainer, range.startOffset).selectionState;
  12180. }, 'backward');
  12181. if (afterRemoval === editorState.getCurrentContent()) {
  12182. return editorState;
  12183. }
  12184. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  12185. }
  12186. var keyCommandBackspaceToStartOfLine_1 = keyCommandBackspaceToStartOfLine;
  12187. /**
  12188. * Copyright (c) 2013-present, Facebook, Inc.
  12189. *
  12190. * This source code is licensed under the MIT license found in the
  12191. * LICENSE file in the root directory of this source tree.
  12192. *
  12193. * @typechecks
  12194. * @stub
  12195. *
  12196. */
  12197. // \u00a1-\u00b1\u00b4-\u00b8\u00ba\u00bb\u00bf
  12198. // is latin supplement punctuation except fractions and superscript
  12199. // numbers
  12200. // \u2010-\u2027\u2030-\u205e
  12201. // is punctuation from the general punctuation block:
  12202. // weird quotes, commas, bullets, dashes, etc.
  12203. // \u30fb\u3001\u3002\u3008-\u3011\u3014-\u301f
  12204. // is CJK punctuation
  12205. // \uff1a-\uff1f\uff01-\uff0f\uff3b-\uff40\uff5b-\uff65
  12206. // is some full-width/half-width punctuation
  12207. // \u2E2E\u061f\u066a-\u066c\u061b\u060c\u060d\uFD3e\uFD3F
  12208. // is some Arabic punctuation marks
  12209. // \u1801\u0964\u104a\u104b
  12210. // is misc. other language punctuation marks
  12211. 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]';
  12212. var TokenizeUtil = {
  12213. getPunctuation: function getPunctuation() {
  12214. return PUNCTUATION;
  12215. }
  12216. };
  12217. var punctuation = TokenizeUtil.getPunctuation();
  12218. // The apostrophe and curly single quotes behave in a curious way: when
  12219. // surrounded on both sides by word characters, they behave as word chars; when
  12220. // either neighbor is punctuation or an end of the string, they behave as
  12221. // punctuation.
  12222. var CHAMELEON_CHARS = '[\'\u2018\u2019]';
  12223. // Remove the underscore, which should count as part of the removable word. The
  12224. // "chameleon chars" also count as punctuation in this regex.
  12225. var WHITESPACE_AND_PUNCTUATION = '\\s|(?![_])' + punctuation;
  12226. var DELETE_STRING = '^' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)';
  12227. var DELETE_REGEX = new RegExp(DELETE_STRING);
  12228. var BACKSPACE_STRING = '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '$';
  12229. var BACKSPACE_REGEX = new RegExp(BACKSPACE_STRING);
  12230. function getRemovableWord(text, isBackward) {
  12231. var matches = isBackward ? BACKSPACE_REGEX.exec(text) : DELETE_REGEX.exec(text);
  12232. return matches ? matches[0] : text;
  12233. }
  12234. var DraftRemovableWord = {
  12235. getBackward: function getBackward(text) {
  12236. return getRemovableWord(text, true);
  12237. },
  12238. getForward: function getForward(text) {
  12239. return getRemovableWord(text, false);
  12240. }
  12241. };
  12242. var DraftRemovableWord_1 = DraftRemovableWord;
  12243. /**
  12244. * Delete the word that is left of the cursor, as well as any spaces or
  12245. * punctuation after the word.
  12246. */
  12247. function keyCommandBackspaceWord(editorState) {
  12248. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12249. var selection = strategyState.getSelection();
  12250. var offset = selection.getStartOffset();
  12251. // If there are no words before the cursor, remove the preceding newline.
  12252. if (offset === 0) {
  12253. return moveSelectionBackward_1(strategyState, 1);
  12254. }
  12255. var key = selection.getStartKey();
  12256. var content = strategyState.getCurrentContent();
  12257. var text = content.getBlockForKey(key).getText().slice(0, offset);
  12258. var toRemove = DraftRemovableWord_1.getBackward(text);
  12259. return moveSelectionBackward_1(strategyState, toRemove.length || 1);
  12260. }, 'backward');
  12261. if (afterRemoval === editorState.getCurrentContent()) {
  12262. return editorState;
  12263. }
  12264. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  12265. }
  12266. var keyCommandBackspaceWord_1 = keyCommandBackspaceWord;
  12267. /**
  12268. * Copyright (c) 2013-present, Facebook, Inc.
  12269. * All rights reserved.
  12270. *
  12271. * This source code is licensed under the BSD-style license found in the
  12272. * LICENSE file in the root directory of this source tree. An additional grant
  12273. * of patent rights can be found in the PATENTS file in the same directory.
  12274. *
  12275. * @providesModule moveSelectionForward
  12276. * @format
  12277. *
  12278. */
  12279. /**
  12280. * Given a collapsed selection, move the focus `maxDistance` forward within
  12281. * the selected block. If the selection will go beyond the end of the block,
  12282. * move focus to the start of the next block, but no further.
  12283. *
  12284. * This function is not Unicode-aware, so surrogate pairs will be treated
  12285. * as having length 2.
  12286. */
  12287. function moveSelectionForward(editorState, maxDistance) {
  12288. var selection = editorState.getSelection();
  12289. var key = selection.getStartKey();
  12290. var offset = selection.getStartOffset();
  12291. var content = editorState.getCurrentContent();
  12292. var focusKey = key;
  12293. var focusOffset;
  12294. var block = content.getBlockForKey(key);
  12295. if (maxDistance > block.getText().length - offset) {
  12296. focusKey = content.getKeyAfter(key);
  12297. focusOffset = 0;
  12298. } else {
  12299. focusOffset = offset + maxDistance;
  12300. }
  12301. return selection.merge({ focusKey: focusKey, focusOffset: focusOffset });
  12302. }
  12303. var moveSelectionForward_1 = moveSelectionForward;
  12304. /**
  12305. * Delete the word that is right of the cursor, as well as any spaces or
  12306. * punctuation before the word.
  12307. */
  12308. function keyCommandDeleteWord(editorState) {
  12309. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12310. var selection = strategyState.getSelection();
  12311. var offset = selection.getStartOffset();
  12312. var key = selection.getStartKey();
  12313. var content = strategyState.getCurrentContent();
  12314. var text = content.getBlockForKey(key).getText().slice(offset);
  12315. var toRemove = DraftRemovableWord_1.getForward(text);
  12316. // If there are no words in front of the cursor, remove the newline.
  12317. return moveSelectionForward_1(strategyState, toRemove.length || 1);
  12318. }, 'forward');
  12319. if (afterRemoval === editorState.getCurrentContent()) {
  12320. return editorState;
  12321. }
  12322. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  12323. }
  12324. var keyCommandDeleteWord_1 = keyCommandDeleteWord;
  12325. function keyCommandInsertNewline(editorState) {
  12326. var contentState = DraftModifier_1.splitBlock(editorState.getCurrentContent(), editorState.getSelection());
  12327. return EditorState_1.push(editorState, contentState, 'split-block');
  12328. }
  12329. var keyCommandInsertNewline_1 = keyCommandInsertNewline;
  12330. /**
  12331. * See comment for `moveSelectionToStartOfBlock`.
  12332. */
  12333. function keyCommandMoveSelectionToEndOfBlock(editorState) {
  12334. var selection = editorState.getSelection();
  12335. var endKey = selection.getEndKey();
  12336. var content = editorState.getCurrentContent();
  12337. var textLength = content.getBlockForKey(endKey).getLength();
  12338. return EditorState_1.set(editorState, {
  12339. selection: selection.merge({
  12340. anchorKey: endKey,
  12341. anchorOffset: textLength,
  12342. focusKey: endKey,
  12343. focusOffset: textLength,
  12344. isBackward: false
  12345. }),
  12346. forceSelection: true
  12347. });
  12348. }
  12349. var keyCommandMoveSelectionToEndOfBlock_1 = keyCommandMoveSelectionToEndOfBlock;
  12350. /**
  12351. * Collapse selection at the start of the first selected block. This is used
  12352. * for Firefox versions that attempt to navigate forward/backward instead of
  12353. * moving the cursor. Other browsers are able to move the cursor natively.
  12354. */
  12355. function keyCommandMoveSelectionToStartOfBlock(editorState) {
  12356. var selection = editorState.getSelection();
  12357. var startKey = selection.getStartKey();
  12358. return EditorState_1.set(editorState, {
  12359. selection: selection.merge({
  12360. anchorKey: startKey,
  12361. anchorOffset: 0,
  12362. focusKey: startKey,
  12363. focusOffset: 0,
  12364. isBackward: false
  12365. }),
  12366. forceSelection: true
  12367. });
  12368. }
  12369. var keyCommandMoveSelectionToStartOfBlock_1 = keyCommandMoveSelectionToStartOfBlock;
  12370. /**
  12371. * Remove the selected range. If the cursor is collapsed, remove the preceding
  12372. * character. This operation is Unicode-aware, so removing a single character
  12373. * will remove a surrogate pair properly as well.
  12374. */
  12375. function keyCommandPlainBackspace(editorState) {
  12376. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12377. var selection = strategyState.getSelection();
  12378. var content = strategyState.getCurrentContent();
  12379. var key = selection.getAnchorKey();
  12380. var offset = selection.getAnchorOffset();
  12381. var charBehind = content.getBlockForKey(key).getText()[offset - 1];
  12382. return moveSelectionBackward_1(strategyState, charBehind ? UnicodeUtils_1.getUTF16Length(charBehind, 0) : 1);
  12383. }, 'backward');
  12384. if (afterRemoval === editorState.getCurrentContent()) {
  12385. return editorState;
  12386. }
  12387. var selection = editorState.getSelection();
  12388. return EditorState_1.push(editorState, afterRemoval.set('selectionBefore', selection), selection.isCollapsed() ? 'backspace-character' : 'remove-range');
  12389. }
  12390. var keyCommandPlainBackspace_1 = keyCommandPlainBackspace;
  12391. /**
  12392. * Remove the selected range. If the cursor is collapsed, remove the following
  12393. * character. This operation is Unicode-aware, so removing a single character
  12394. * will remove a surrogate pair properly as well.
  12395. */
  12396. function keyCommandPlainDelete(editorState) {
  12397. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12398. var selection = strategyState.getSelection();
  12399. var content = strategyState.getCurrentContent();
  12400. var key = selection.getAnchorKey();
  12401. var offset = selection.getAnchorOffset();
  12402. var charAhead = content.getBlockForKey(key).getText()[offset];
  12403. return moveSelectionForward_1(strategyState, charAhead ? UnicodeUtils_1.getUTF16Length(charAhead, 0) : 1);
  12404. }, 'forward');
  12405. if (afterRemoval === editorState.getCurrentContent()) {
  12406. return editorState;
  12407. }
  12408. var selection = editorState.getSelection();
  12409. return EditorState_1.push(editorState, afterRemoval.set('selectionBefore', selection), selection.isCollapsed() ? 'delete-character' : 'remove-range');
  12410. }
  12411. var keyCommandPlainDelete_1 = keyCommandPlainDelete;
  12412. /**
  12413. * Transpose the characters on either side of a collapsed cursor, or
  12414. * if the cursor is at the end of the block, transpose the last two
  12415. * characters.
  12416. */
  12417. function keyCommandTransposeCharacters(editorState) {
  12418. var selection = editorState.getSelection();
  12419. if (!selection.isCollapsed()) {
  12420. return editorState;
  12421. }
  12422. var offset = selection.getAnchorOffset();
  12423. if (offset === 0) {
  12424. return editorState;
  12425. }
  12426. var blockKey = selection.getAnchorKey();
  12427. var content = editorState.getCurrentContent();
  12428. var block = content.getBlockForKey(blockKey);
  12429. var length = block.getLength();
  12430. // Nothing to transpose if there aren't two characters.
  12431. if (length <= 1) {
  12432. return editorState;
  12433. }
  12434. var removalRange;
  12435. var finalSelection;
  12436. if (offset === length) {
  12437. // The cursor is at the end of the block. Swap the last two characters.
  12438. removalRange = selection.set('anchorOffset', offset - 1);
  12439. finalSelection = selection;
  12440. } else {
  12441. removalRange = selection.set('focusOffset', offset + 1);
  12442. finalSelection = removalRange.set('anchorOffset', offset + 1);
  12443. }
  12444. // Extract the character to move as a fragment. This preserves its
  12445. // styling and entity, if any.
  12446. var movedFragment = getContentStateFragment_1(content, removalRange);
  12447. var afterRemoval = DraftModifier_1.removeRange(content, removalRange, 'backward');
  12448. // After the removal, the insertion target is one character back.
  12449. var selectionAfter = afterRemoval.getSelectionAfter();
  12450. var targetOffset = selectionAfter.getAnchorOffset() - 1;
  12451. var targetRange = selectionAfter.merge({
  12452. anchorOffset: targetOffset,
  12453. focusOffset: targetOffset
  12454. });
  12455. var afterInsert = DraftModifier_1.replaceWithFragment(afterRemoval, targetRange, movedFragment);
  12456. var newEditorState = EditorState_1.push(editorState, afterInsert, 'insert-fragment');
  12457. return EditorState_1.acceptSelection(newEditorState, finalSelection);
  12458. }
  12459. var keyCommandTransposeCharacters_1 = keyCommandTransposeCharacters;
  12460. function keyCommandUndo(e, editorState, updateFn) {
  12461. var undoneState = EditorState_1.undo(editorState);
  12462. // If the last change to occur was a spellcheck change, allow the undo
  12463. // event to fall through to the browser. This allows the browser to record
  12464. // the unwanted change, which should soon lead it to learn not to suggest
  12465. // the correction again.
  12466. if (editorState.getLastChangeType() === 'spellcheck-change') {
  12467. var nativelyRenderedContent = undoneState.getCurrentContent();
  12468. updateFn(EditorState_1.set(undoneState, { nativelyRenderedContent: nativelyRenderedContent }));
  12469. return;
  12470. }
  12471. // Otheriwse, manage the undo behavior manually.
  12472. e.preventDefault();
  12473. if (!editorState.getNativelyRenderedContent()) {
  12474. updateFn(undoneState);
  12475. return;
  12476. }
  12477. // Trigger a re-render with the current content state to ensure that the
  12478. // component tree has up-to-date props for comparison.
  12479. updateFn(EditorState_1.set(editorState, { nativelyRenderedContent: null }));
  12480. // Wait to ensure that the re-render has occurred before performing
  12481. // the undo action.
  12482. setTimeout(function () {
  12483. updateFn(undoneState);
  12484. }, 0);
  12485. }
  12486. var keyCommandUndo_1 = keyCommandUndo;
  12487. var isOptionKeyCommand = KeyBindingUtil_1.isOptionKeyCommand;
  12488. var isChrome$1 = UserAgent_1.isBrowser('Chrome');
  12489. /**
  12490. * Map a `DraftEditorCommand` command value to a corresponding function.
  12491. */
  12492. function onKeyCommand(command, editorState) {
  12493. switch (command) {
  12494. case 'redo':
  12495. return EditorState_1.redo(editorState);
  12496. case 'delete':
  12497. return keyCommandPlainDelete_1(editorState);
  12498. case 'delete-word':
  12499. return keyCommandDeleteWord_1(editorState);
  12500. case 'backspace':
  12501. return keyCommandPlainBackspace_1(editorState);
  12502. case 'backspace-word':
  12503. return keyCommandBackspaceWord_1(editorState);
  12504. case 'backspace-to-start-of-line':
  12505. return keyCommandBackspaceToStartOfLine_1(editorState);
  12506. case 'split-block':
  12507. return keyCommandInsertNewline_1(editorState);
  12508. case 'transpose-characters':
  12509. return keyCommandTransposeCharacters_1(editorState);
  12510. case 'move-selection-to-start-of-block':
  12511. return keyCommandMoveSelectionToStartOfBlock_1(editorState);
  12512. case 'move-selection-to-end-of-block':
  12513. return keyCommandMoveSelectionToEndOfBlock_1(editorState);
  12514. case 'secondary-cut':
  12515. return SecondaryClipboard_1.cut(editorState);
  12516. case 'secondary-paste':
  12517. return SecondaryClipboard_1.paste(editorState);
  12518. default:
  12519. return editorState;
  12520. }
  12521. }
  12522. /**
  12523. * Intercept keydown behavior to handle keys and commands manually, if desired.
  12524. *
  12525. * Keydown combinations may be mapped to `DraftCommand` values, which may
  12526. * correspond to command functions that modify the editor or its contents.
  12527. *
  12528. * See `getDefaultKeyBinding` for defaults. Alternatively, the top-level
  12529. * component may provide a custom mapping via the `keyBindingFn` prop.
  12530. */
  12531. function editOnKeyDown(editor, e) {
  12532. var keyCode = e.which;
  12533. var editorState = editor._latestEditorState;
  12534. switch (keyCode) {
  12535. case Keys.RETURN:
  12536. e.preventDefault();
  12537. // The top-level component may manually handle newline insertion. If
  12538. // no special handling is performed, fall through to command handling.
  12539. if (editor.props.handleReturn && isEventHandled_1(editor.props.handleReturn(e, editorState))) {
  12540. return;
  12541. }
  12542. break;
  12543. case Keys.ESC:
  12544. e.preventDefault();
  12545. editor.props.onEscape && editor.props.onEscape(e);
  12546. return;
  12547. case Keys.TAB:
  12548. editor.props.onTab && editor.props.onTab(e);
  12549. return;
  12550. case Keys.UP:
  12551. editor.props.onUpArrow && editor.props.onUpArrow(e);
  12552. return;
  12553. case Keys.RIGHT:
  12554. editor.props.onRightArrow && editor.props.onRightArrow(e);
  12555. return;
  12556. case Keys.DOWN:
  12557. editor.props.onDownArrow && editor.props.onDownArrow(e);
  12558. return;
  12559. case Keys.LEFT:
  12560. editor.props.onLeftArrow && editor.props.onLeftArrow(e);
  12561. return;
  12562. case Keys.SPACE:
  12563. // Handling for OSX where option + space scrolls.
  12564. if (isChrome$1 && isOptionKeyCommand(e)) {
  12565. e.preventDefault();
  12566. // Insert a nbsp into the editor.
  12567. var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), '\xA0');
  12568. editor.update(EditorState_1.push(editorState, contentState, 'insert-characters'));
  12569. return;
  12570. }
  12571. }
  12572. var command = editor.props.keyBindingFn(e);
  12573. // If no command is specified, allow keydown event to continue.
  12574. if (!command) {
  12575. return;
  12576. }
  12577. if (command === 'undo') {
  12578. // Since undo requires some special updating behavior to keep the editor
  12579. // in sync, handle it separately.
  12580. keyCommandUndo_1(e, editorState, editor.update);
  12581. return;
  12582. }
  12583. // At this point, we know that we're handling a command of some kind, so
  12584. // we don't want to insert a character following the keydown.
  12585. e.preventDefault();
  12586. // Allow components higher up the tree to handle the command first.
  12587. if (editor.props.handleKeyCommand && isEventHandled_1(editor.props.handleKeyCommand(command, editorState))) {
  12588. return;
  12589. }
  12590. var newState = onKeyCommand(command, editorState);
  12591. if (newState !== editorState) {
  12592. editor.update(newState);
  12593. }
  12594. }
  12595. var editOnKeyDown_1 = editOnKeyDown;
  12596. /**
  12597. * Copyright (c) 2013-present, Facebook, Inc.
  12598. *
  12599. * This source code is licensed under the MIT license found in the
  12600. * LICENSE file in the root directory of this source tree.
  12601. *
  12602. *
  12603. */
  12604. function _classCallCheck$e(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12605. var URI = function () {
  12606. function URI(uri) {
  12607. _classCallCheck$e(this, URI);
  12608. this._uri = uri;
  12609. }
  12610. URI.prototype.toString = function toString() {
  12611. return this._uri;
  12612. };
  12613. return URI;
  12614. }();
  12615. var URI_1 = URI;
  12616. var isOldIE = UserAgent_1.isBrowser('IE <= 9');
  12617. // Provides a dom node that will not execute scripts
  12618. // https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation.createHTMLDocument
  12619. // https://developer.mozilla.org/en-US/Add-ons/Code_snippets/HTML_to_DOM
  12620. function getSafeBodyFromHTML(html) {
  12621. var doc;
  12622. var root = null;
  12623. // Provides a safe context
  12624. if (!isOldIE && document.implementation && document.implementation.createHTMLDocument) {
  12625. doc = document.implementation.createHTMLDocument('foo');
  12626. !doc.documentElement ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing doc.documentElement') : invariant_1(false) : void 0;
  12627. doc.documentElement.innerHTML = html;
  12628. root = doc.getElementsByTagName('body')[0];
  12629. }
  12630. return root;
  12631. }
  12632. var getSafeBodyFromHTML_1 = getSafeBodyFromHTML;
  12633. 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; };
  12634. var _knownListItemDepthCl;
  12635. 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; }
  12636. var _require = immutable,
  12637. Set$1 = _require.Set;
  12638. var experimentalTreeDataSupport = DraftFeatureFlags_1.draft_tree_data_support;
  12639. var List$a = immutable.List,
  12640. OrderedSet$5 = immutable.OrderedSet;
  12641. var NBSP = '&nbsp;';
  12642. var SPACE = ' ';
  12643. // Arbitrary max indent
  12644. var MAX_DEPTH = 4;
  12645. // used for replacing characters in HTML
  12646. var REGEX_CR = new RegExp('\r', 'g');
  12647. var REGEX_LF = new RegExp('\n', 'g');
  12648. var REGEX_NBSP = new RegExp(NBSP, 'g');
  12649. var REGEX_CARRIAGE = new RegExp('&#13;?', 'g');
  12650. var REGEX_ZWS = new RegExp('&#8203;?', 'g');
  12651. // https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight
  12652. var boldValues = ['bold', 'bolder', '500', '600', '700', '800', '900'];
  12653. var notBoldValues = ['light', 'lighter', '100', '200', '300', '400'];
  12654. // Block tag flow is different because LIs do not have
  12655. // a deterministic style ;_;
  12656. var inlineTags = {
  12657. b: 'BOLD',
  12658. code: 'CODE',
  12659. del: 'STRIKETHROUGH',
  12660. em: 'ITALIC',
  12661. i: 'ITALIC',
  12662. s: 'STRIKETHROUGH',
  12663. strike: 'STRIKETHROUGH',
  12664. strong: 'BOLD',
  12665. u: 'UNDERLINE'
  12666. };
  12667. 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);
  12668. var anchorAttr = ['className', 'href', 'rel', 'target', 'title'];
  12669. var imgAttr = ['alt', 'className', 'height', 'src', 'width'];
  12670. var lastBlock = void 0;
  12671. var EMPTY_CHUNK = {
  12672. text: '',
  12673. inlines: [],
  12674. entities: [],
  12675. blocks: []
  12676. };
  12677. var EMPTY_BLOCK = {
  12678. children: List$a(),
  12679. depth: 0,
  12680. key: '',
  12681. type: ''
  12682. };
  12683. var getListBlockType = function getListBlockType(tag, lastList) {
  12684. if (tag === 'li') {
  12685. return lastList === 'ol' ? 'ordered-list-item' : 'unordered-list-item';
  12686. }
  12687. return null;
  12688. };
  12689. var getBlockMapSupportedTags = function getBlockMapSupportedTags(blockRenderMap) {
  12690. var unstyledElement = blockRenderMap.get('unstyled').element;
  12691. var tags = Set$1([]);
  12692. blockRenderMap.forEach(function (draftBlock) {
  12693. if (draftBlock.aliasedElements) {
  12694. draftBlock.aliasedElements.forEach(function (tag) {
  12695. tags = tags.add(tag);
  12696. });
  12697. }
  12698. tags = tags.add(draftBlock.element);
  12699. });
  12700. return tags.filter(function (tag) {
  12701. return tag && tag !== unstyledElement;
  12702. }).toArray().sort();
  12703. };
  12704. // custom element conversions
  12705. var getMultiMatchedType = function getMultiMatchedType(tag, lastList, multiMatchExtractor) {
  12706. for (var ii = 0; ii < multiMatchExtractor.length; ii++) {
  12707. var matchType = multiMatchExtractor[ii](tag, lastList);
  12708. if (matchType) {
  12709. return matchType;
  12710. }
  12711. }
  12712. return null;
  12713. };
  12714. var getBlockTypeForTag = function getBlockTypeForTag(tag, lastList, blockRenderMap) {
  12715. var matchedTypes = blockRenderMap.filter(function (draftBlock) {
  12716. return draftBlock.element === tag || draftBlock.wrapper === tag || draftBlock.aliasedElements && draftBlock.aliasedElements.some(function (alias) {
  12717. return alias === tag;
  12718. });
  12719. }).keySeq().toSet().toArray().sort();
  12720. // if we dont have any matched type, return unstyled
  12721. // if we have one matched type return it
  12722. // if we have multi matched types use the multi-match function to gather type
  12723. switch (matchedTypes.length) {
  12724. case 0:
  12725. return 'unstyled';
  12726. case 1:
  12727. return matchedTypes[0];
  12728. default:
  12729. return getMultiMatchedType(tag, lastList, [getListBlockType]) || 'unstyled';
  12730. }
  12731. };
  12732. var processInlineTag = function processInlineTag(tag, node, currentStyle) {
  12733. var styleToCheck = inlineTags[tag];
  12734. if (styleToCheck) {
  12735. currentStyle = currentStyle.add(styleToCheck).toOrderedSet();
  12736. } else if (node instanceof HTMLElement) {
  12737. var htmlElement = node;
  12738. currentStyle = currentStyle.withMutations(function (style) {
  12739. var fontWeight = htmlElement.style.fontWeight;
  12740. var fontStyle = htmlElement.style.fontStyle;
  12741. var textDecoration = htmlElement.style.textDecoration;
  12742. if (boldValues.indexOf(fontWeight) >= 0) {
  12743. style.add('BOLD');
  12744. } else if (notBoldValues.indexOf(fontWeight) >= 0) {
  12745. style.remove('BOLD');
  12746. }
  12747. if (fontStyle === 'italic') {
  12748. style.add('ITALIC');
  12749. } else if (fontStyle === 'normal') {
  12750. style.remove('ITALIC');
  12751. }
  12752. if (textDecoration === 'underline') {
  12753. style.add('UNDERLINE');
  12754. }
  12755. if (textDecoration === 'line-through') {
  12756. style.add('STRIKETHROUGH');
  12757. }
  12758. if (textDecoration === 'none') {
  12759. style.remove('UNDERLINE');
  12760. style.remove('STRIKETHROUGH');
  12761. }
  12762. }).toOrderedSet();
  12763. }
  12764. return currentStyle;
  12765. };
  12766. var joinChunks = function joinChunks(A, B, experimentalHasNestedBlocks) {
  12767. // Sometimes two blocks will touch in the DOM and we need to strip the
  12768. // extra delimiter to preserve niceness.
  12769. var lastInA = A.text.slice(-1);
  12770. var firstInB = B.text.slice(0, 1);
  12771. if (lastInA === '\r' && firstInB === '\r' && !experimentalHasNestedBlocks) {
  12772. A.text = A.text.slice(0, -1);
  12773. A.inlines.pop();
  12774. A.entities.pop();
  12775. A.blocks.pop();
  12776. }
  12777. // Kill whitespace after blocks
  12778. if (lastInA === '\r') {
  12779. if (B.text === SPACE || B.text === '\n') {
  12780. return A;
  12781. } else if (firstInB === SPACE || firstInB === '\n') {
  12782. B.text = B.text.slice(1);
  12783. B.inlines.shift();
  12784. B.entities.shift();
  12785. }
  12786. }
  12787. return {
  12788. text: A.text + B.text,
  12789. inlines: A.inlines.concat(B.inlines),
  12790. entities: A.entities.concat(B.entities),
  12791. blocks: A.blocks.concat(B.blocks)
  12792. };
  12793. };
  12794. /**
  12795. * Check to see if we have anything like <p> <blockquote> <h1>... to create
  12796. * block tags from. If we do, we can use those and ignore <div> tags. If we
  12797. * don't, we can treat <div> tags as meaningful (unstyled) blocks.
  12798. */
  12799. var containsSemanticBlockMarkup = function containsSemanticBlockMarkup(html, blockTags) {
  12800. return blockTags.some(function (tag) {
  12801. return html.indexOf('<' + tag) !== -1;
  12802. });
  12803. };
  12804. var hasValidLinkText = function hasValidLinkText(link) {
  12805. !(link instanceof HTMLAnchorElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Link must be an HTMLAnchorElement.') : invariant_1(false) : void 0;
  12806. var protocol = link.protocol;
  12807. return protocol === 'http:' || protocol === 'https:' || protocol === 'mailto:';
  12808. };
  12809. var getWhitespaceChunk = function getWhitespaceChunk(inEntity) {
  12810. var entities = new Array(1);
  12811. if (inEntity) {
  12812. entities[0] = inEntity;
  12813. }
  12814. return _extends$4({}, EMPTY_CHUNK, {
  12815. text: SPACE,
  12816. inlines: [OrderedSet$5()],
  12817. entities: entities
  12818. });
  12819. };
  12820. var getSoftNewlineChunk = function getSoftNewlineChunk() {
  12821. return _extends$4({}, EMPTY_CHUNK, {
  12822. text: '\n',
  12823. inlines: [OrderedSet$5()],
  12824. entities: new Array(1)
  12825. });
  12826. };
  12827. var getChunkedBlock = function getChunkedBlock() {
  12828. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  12829. return _extends$4({}, EMPTY_BLOCK, props);
  12830. };
  12831. var getBlockDividerChunk = function getBlockDividerChunk(block, depth) {
  12832. var parentKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  12833. return {
  12834. text: '\r',
  12835. inlines: [OrderedSet$5()],
  12836. entities: new Array(1),
  12837. blocks: [getChunkedBlock({
  12838. parent: parentKey,
  12839. key: generateRandomKey_1(),
  12840. type: block,
  12841. depth: Math.max(0, Math.min(MAX_DEPTH, depth))
  12842. })]
  12843. };
  12844. };
  12845. /**
  12846. * If we're pasting from one DraftEditor to another we can check to see if
  12847. * existing list item depth classes are being used and preserve this style
  12848. */
  12849. var getListItemDepth = function getListItemDepth(node) {
  12850. var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  12851. Object.keys(knownListItemDepthClasses).some(function (depthClass) {
  12852. if (node.classList.contains(depthClass)) {
  12853. depth = knownListItemDepthClasses[depthClass];
  12854. }
  12855. });
  12856. return depth;
  12857. };
  12858. var genFragment = function genFragment(entityMap, node, inlineStyle, lastList, inBlock, blockTags, depth, blockRenderMap, inEntity, parentKey) {
  12859. var lastLastBlock = lastBlock;
  12860. var nodeName = node.nodeName.toLowerCase();
  12861. var newEntityMap = entityMap;
  12862. var nextBlockType = 'unstyled';
  12863. var newBlock = false;
  12864. var inBlockType = inBlock && getBlockTypeForTag(inBlock, lastList, blockRenderMap);
  12865. var chunk = _extends$4({}, EMPTY_CHUNK);
  12866. var newChunk = null;
  12867. var blockKey = void 0;
  12868. // Base Case
  12869. if (nodeName === '#text') {
  12870. var _text = node.textContent;
  12871. var nodeTextContent = _text.trim();
  12872. // We should not create blocks for leading spaces that are
  12873. // existing around ol/ul and their children list items
  12874. if (lastList && nodeTextContent === '' && node.parentElement) {
  12875. var parentNodeName = node.parentElement.nodeName.toLowerCase();
  12876. if (parentNodeName === 'ol' || parentNodeName === 'ul') {
  12877. return { chunk: _extends$4({}, EMPTY_CHUNK), entityMap: entityMap };
  12878. }
  12879. }
  12880. if (nodeTextContent === '' && inBlock !== 'pre') {
  12881. return { chunk: getWhitespaceChunk(inEntity), entityMap: entityMap };
  12882. }
  12883. if (inBlock !== 'pre') {
  12884. // Can't use empty string because MSWord
  12885. _text = _text.replace(REGEX_LF, SPACE);
  12886. }
  12887. // save the last block so we can use it later
  12888. lastBlock = nodeName;
  12889. return {
  12890. chunk: {
  12891. text: _text,
  12892. inlines: Array(_text.length).fill(inlineStyle),
  12893. entities: Array(_text.length).fill(inEntity),
  12894. blocks: []
  12895. },
  12896. entityMap: entityMap
  12897. };
  12898. }
  12899. // save the last block so we can use it later
  12900. lastBlock = nodeName;
  12901. // BR tags
  12902. if (nodeName === 'br') {
  12903. if (lastLastBlock === 'br' && (!inBlock || inBlockType === 'unstyled')) {
  12904. return {
  12905. chunk: getBlockDividerChunk('unstyled', depth, parentKey),
  12906. entityMap: entityMap
  12907. };
  12908. }
  12909. return { chunk: getSoftNewlineChunk(), entityMap: entityMap };
  12910. }
  12911. // IMG tags
  12912. if (nodeName === 'img' && node instanceof HTMLImageElement && node.attributes.getNamedItem('src') && node.attributes.getNamedItem('src').value) {
  12913. var image = node;
  12914. var entityConfig = {};
  12915. imgAttr.forEach(function (attr) {
  12916. var imageAttribute = image.getAttribute(attr);
  12917. if (imageAttribute) {
  12918. entityConfig[attr] = imageAttribute;
  12919. }
  12920. });
  12921. // Forcing this node to have children because otherwise no entity will be
  12922. // created for this node.
  12923. // The child text node cannot just have a space or return as content -
  12924. // we strip those out.
  12925. // See https://github.com/facebook/draft-js/issues/231 for some context.
  12926. node.textContent = '\uD83D\uDCF7';
  12927. // TODO: update this when we remove DraftEntity entirely
  12928. inEntity = DraftEntity_1.__create('IMAGE', 'MUTABLE', entityConfig || {});
  12929. }
  12930. // Inline tags
  12931. inlineStyle = processInlineTag(nodeName, node, inlineStyle);
  12932. // Handle lists
  12933. if (nodeName === 'ul' || nodeName === 'ol') {
  12934. if (lastList) {
  12935. depth += 1;
  12936. }
  12937. lastList = nodeName;
  12938. }
  12939. if ( nodeName === 'li' && node instanceof HTMLElement) {
  12940. depth = getListItemDepth(node, depth);
  12941. }
  12942. var blockType = getBlockTypeForTag(nodeName, lastList, blockRenderMap);
  12943. var inListBlock = lastList && inBlock === 'li' && nodeName === 'li';
  12944. var inBlockOrHasNestedBlocks = (!inBlock || experimentalTreeDataSupport) && blockTags.indexOf(nodeName) !== -1;
  12945. // Block Tags
  12946. if (inListBlock || inBlockOrHasNestedBlocks) {
  12947. chunk = getBlockDividerChunk(blockType, depth, parentKey);
  12948. blockKey = chunk.blocks[0].key;
  12949. inBlock = nodeName;
  12950. newBlock = !experimentalTreeDataSupport;
  12951. }
  12952. // this is required so that we can handle 'ul' and 'ol'
  12953. if (inListBlock) {
  12954. nextBlockType = lastList === 'ul' ? 'unordered-list-item' : 'ordered-list-item';
  12955. }
  12956. // Recurse through children
  12957. var child = node.firstChild;
  12958. if (child != null) {
  12959. nodeName = child.nodeName.toLowerCase();
  12960. }
  12961. var entityId = null;
  12962. while (child) {
  12963. if (child instanceof HTMLAnchorElement && child.href && hasValidLinkText(child)) {
  12964. (function () {
  12965. var anchor = child;
  12966. var entityConfig = {};
  12967. anchorAttr.forEach(function (attr) {
  12968. var anchorAttribute = anchor.getAttribute(attr);
  12969. if (anchorAttribute) {
  12970. entityConfig[attr] = anchorAttribute;
  12971. }
  12972. });
  12973. entityConfig.url = new URI_1(anchor.href).toString();
  12974. // TODO: update this when we remove DraftEntity completely
  12975. entityId = DraftEntity_1.__create('LINK', 'MUTABLE', entityConfig || {});
  12976. })();
  12977. } else {
  12978. entityId = undefined;
  12979. }
  12980. var _genFragment = genFragment(newEntityMap, child, inlineStyle, lastList, inBlock, blockTags, depth, blockRenderMap, entityId || inEntity, null),
  12981. generatedChunk = _genFragment.chunk,
  12982. maybeUpdatedEntityMap = _genFragment.entityMap;
  12983. newChunk = generatedChunk;
  12984. newEntityMap = maybeUpdatedEntityMap;
  12985. chunk = joinChunks(chunk, newChunk, experimentalTreeDataSupport);
  12986. var sibling = child.nextSibling;
  12987. // Put in a newline to break up blocks inside blocks
  12988. if (!parentKey && sibling && blockTags.indexOf(nodeName) >= 0 && inBlock) {
  12989. chunk = joinChunks(chunk, getSoftNewlineChunk());
  12990. }
  12991. if (sibling) {
  12992. nodeName = sibling.nodeName.toLowerCase();
  12993. }
  12994. child = sibling;
  12995. }
  12996. if (newBlock) {
  12997. chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, parentKey));
  12998. }
  12999. return { chunk: chunk, entityMap: newEntityMap };
  13000. };
  13001. var getChunkForHTML = function getChunkForHTML(html, DOMBuilder, blockRenderMap, entityMap) {
  13002. html = html.trim().replace(REGEX_CR, '').replace(REGEX_NBSP, SPACE).replace(REGEX_CARRIAGE, '').replace(REGEX_ZWS, '');
  13003. var supportedBlockTags = getBlockMapSupportedTags(blockRenderMap);
  13004. var safeBody = DOMBuilder(html);
  13005. if (!safeBody) {
  13006. return null;
  13007. }
  13008. lastBlock = null;
  13009. // Sometimes we aren't dealing with content that contains nice semantic
  13010. // tags. In this case, use divs to separate everything out into paragraphs
  13011. // and hope for the best.
  13012. var workingBlocks = containsSemanticBlockMarkup(html, supportedBlockTags) ? supportedBlockTags : ['div'];
  13013. // Start with -1 block depth to offset the fact that we are passing in a fake
  13014. // UL block to start with.
  13015. var fragment = genFragment(entityMap, safeBody, OrderedSet$5(), 'ul', null, workingBlocks, -1, blockRenderMap);
  13016. var chunk = fragment.chunk;
  13017. var newEntityMap = fragment.entityMap;
  13018. // join with previous block to prevent weirdness on paste
  13019. if (chunk.text.indexOf('\r') === 0) {
  13020. chunk = {
  13021. text: chunk.text.slice(1),
  13022. inlines: chunk.inlines.slice(1),
  13023. entities: chunk.entities.slice(1),
  13024. blocks: chunk.blocks
  13025. };
  13026. }
  13027. // Kill block delimiter at the end
  13028. if (chunk.text.slice(-1) === '\r') {
  13029. chunk.text = chunk.text.slice(0, -1);
  13030. chunk.inlines = chunk.inlines.slice(0, -1);
  13031. chunk.entities = chunk.entities.slice(0, -1);
  13032. chunk.blocks.pop();
  13033. }
  13034. // If we saw no block tags, put an unstyled one in
  13035. if (chunk.blocks.length === 0) {
  13036. chunk.blocks.push(_extends$4({}, EMPTY_CHUNK, {
  13037. type: 'unstyled',
  13038. depth: 0
  13039. }));
  13040. }
  13041. // Sometimes we start with text that isn't in a block, which is then
  13042. // followed by blocks. Need to fix up the blocks to add in
  13043. // an unstyled block for this content
  13044. if (chunk.text.split('\r').length === chunk.blocks.length + 1) {
  13045. chunk.blocks.unshift({ type: 'unstyled', depth: 0 });
  13046. }
  13047. return { chunk: chunk, entityMap: newEntityMap };
  13048. };
  13049. var convertChunkToContentBlocks = function convertChunkToContentBlocks(chunk) {
  13050. if (!chunk || !chunk.text || !Array.isArray(chunk.blocks)) {
  13051. return null;
  13052. }
  13053. var initialState = {
  13054. cacheRef: {},
  13055. contentBlocks: []
  13056. };
  13057. var start = 0;
  13058. var rawBlocks = chunk.blocks,
  13059. rawInlines = chunk.inlines,
  13060. rawEntities = chunk.entities;
  13061. var BlockNodeRecord = ContentBlock_1;
  13062. return chunk.text.split('\r').reduce(function (acc, textBlock, index) {
  13063. // Make absolutely certain that our text is acceptable.
  13064. textBlock = sanitizeDraftText_1(textBlock);
  13065. var block = rawBlocks[index];
  13066. var end = start + textBlock.length;
  13067. var inlines = rawInlines.slice(start, end);
  13068. var entities = rawEntities.slice(start, end);
  13069. var characterList = List$a(inlines.map(function (style, index) {
  13070. var data = { style: style, entity: null };
  13071. if (entities[index]) {
  13072. data.entity = entities[index];
  13073. }
  13074. return CharacterMetadata_1.create(data);
  13075. }));
  13076. start = end + 1;
  13077. var depth = block.depth,
  13078. type = block.type,
  13079. parent = block.parent;
  13080. var key = block.key || generateRandomKey_1();
  13081. var parentTextNodeKey = null; // will be used to store container text nodes
  13082. // childrens add themselves to their parents since we are iterating in order
  13083. if (parent) {
  13084. var parentIndex = acc.cacheRef[parent];
  13085. var parentRecord = acc.contentBlocks[parentIndex];
  13086. // if parent has text we need to split it into a separate unstyled element
  13087. if (parentRecord.getChildKeys().isEmpty() && parentRecord.getText()) {
  13088. var parentCharacterList = parentRecord.getCharacterList();
  13089. var parentText = parentRecord.getText();
  13090. parentTextNodeKey = generateRandomKey_1();
  13091. var textNode = new ContentBlockNode_1({
  13092. key: parentTextNodeKey,
  13093. text: parentText,
  13094. characterList: parentCharacterList,
  13095. parent: parent,
  13096. nextSibling: key
  13097. });
  13098. acc.contentBlocks.push(textNode);
  13099. parentRecord = parentRecord.withMutations(function (block) {
  13100. block.set('characterList', List$a()).set('text', '').set('children', parentRecord.children.push(textNode.getKey()));
  13101. });
  13102. }
  13103. acc.contentBlocks[parentIndex] = parentRecord.set('children', parentRecord.children.push(key));
  13104. }
  13105. var blockNode = new BlockNodeRecord({
  13106. key: key,
  13107. parent: parent,
  13108. type: type,
  13109. depth: depth,
  13110. text: textBlock,
  13111. characterList: characterList,
  13112. prevSibling: parentTextNodeKey || (index === 0 || rawBlocks[index - 1].parent !== parent ? null : rawBlocks[index - 1].key),
  13113. nextSibling: index === rawBlocks.length - 1 || rawBlocks[index + 1].parent !== parent ? null : rawBlocks[index + 1].key
  13114. });
  13115. // insert node
  13116. acc.contentBlocks.push(blockNode);
  13117. // cache ref for building links
  13118. acc.cacheRef[blockNode.key] = index;
  13119. return acc;
  13120. }, initialState).contentBlocks;
  13121. };
  13122. var convertFromHTMLtoContentBlocks = function convertFromHTMLtoContentBlocks(html) {
  13123. var DOMBuilder = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getSafeBodyFromHTML_1;
  13124. var blockRenderMap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DefaultDraftBlockRenderMap_1;
  13125. // Be ABSOLUTELY SURE that the dom builder you pass here won't execute
  13126. // arbitrary code in whatever environment you're running this in. For an
  13127. // example of how we try to do this in-browser, see getSafeBodyFromHTML.
  13128. // TODO: replace DraftEntity with an OrderedMap here
  13129. var chunkData = getChunkForHTML(html, DOMBuilder, blockRenderMap, DraftEntity_1);
  13130. if (chunkData == null) {
  13131. return null;
  13132. }
  13133. var chunk = chunkData.chunk,
  13134. entityMap = chunkData.entityMap;
  13135. var contentBlocks = convertChunkToContentBlocks(chunk);
  13136. return {
  13137. contentBlocks: contentBlocks,
  13138. entityMap: entityMap
  13139. };
  13140. };
  13141. var convertFromHTMLToContentBlocks = convertFromHTMLtoContentBlocks;
  13142. var List$b = immutable.List,
  13143. Repeat$6 = immutable.Repeat;
  13144. var ContentBlockRecord$2 = ContentBlock_1;
  13145. var DraftPasteProcessor = {
  13146. processHTML: function processHTML(html, blockRenderMap) {
  13147. return convertFromHTMLToContentBlocks(html, getSafeBodyFromHTML_1, blockRenderMap);
  13148. },
  13149. processText: function processText(textBlocks, character, type) {
  13150. return textBlocks.reduce(function (acc, textLine, index) {
  13151. textLine = sanitizeDraftText_1(textLine);
  13152. var key = generateRandomKey_1();
  13153. var blockNodeConfig = {
  13154. key: key,
  13155. type: type,
  13156. text: textLine,
  13157. characterList: List$b(Repeat$6(character, textLine.length))
  13158. };
  13159. acc.push(new ContentBlockRecord$2(blockNodeConfig));
  13160. return acc;
  13161. }, []);
  13162. }
  13163. };
  13164. var DraftPasteProcessor_1 = DraftPasteProcessor;
  13165. /**
  13166. * Copyright (c) 2013-present, Facebook, Inc.
  13167. * All rights reserved.
  13168. *
  13169. * This source code is licensed under the BSD-style license found in the
  13170. * LICENSE file in the root directory of this source tree. An additional grant
  13171. * of patent rights can be found in the PATENTS file in the same directory.
  13172. *
  13173. * @providesModule adjustBlockDepthForContentState
  13174. * @format
  13175. *
  13176. */
  13177. function adjustBlockDepthForContentState(contentState, selectionState, adjustment, maxDepth) {
  13178. var startKey = selectionState.getStartKey();
  13179. var endKey = selectionState.getEndKey();
  13180. var blockMap = contentState.getBlockMap();
  13181. var blocks = blockMap.toSeq().skipUntil(function (_, k) {
  13182. return k === startKey;
  13183. }).takeUntil(function (_, k) {
  13184. return k === endKey;
  13185. }).concat([[endKey, blockMap.get(endKey)]]).map(function (block) {
  13186. var depth = block.getDepth() + adjustment;
  13187. depth = Math.max(0, Math.min(depth, maxDepth));
  13188. return block.set('depth', depth);
  13189. });
  13190. blockMap = blockMap.merge(blocks);
  13191. return contentState.merge({
  13192. blockMap: blockMap,
  13193. selectionBefore: selectionState,
  13194. selectionAfter: selectionState
  13195. });
  13196. }
  13197. var adjustBlockDepthForContentState_1 = adjustBlockDepthForContentState;
  13198. var RichTextEditorUtil = {
  13199. currentBlockContainsLink: function currentBlockContainsLink(editorState) {
  13200. var selection = editorState.getSelection();
  13201. var contentState = editorState.getCurrentContent();
  13202. var entityMap = contentState.getEntityMap();
  13203. return contentState.getBlockForKey(selection.getAnchorKey()).getCharacterList().slice(selection.getStartOffset(), selection.getEndOffset()).some(function (v) {
  13204. var entity = v.getEntity();
  13205. return !!entity && entityMap.__get(entity).getType() === 'LINK';
  13206. });
  13207. },
  13208. getCurrentBlockType: function getCurrentBlockType(editorState) {
  13209. var selection = editorState.getSelection();
  13210. return editorState.getCurrentContent().getBlockForKey(selection.getStartKey()).getType();
  13211. },
  13212. getDataObjectForLinkURL: function getDataObjectForLinkURL(uri) {
  13213. return { url: uri.toString() };
  13214. },
  13215. handleKeyCommand: function handleKeyCommand(editorState, command) {
  13216. switch (command) {
  13217. case 'bold':
  13218. return RichTextEditorUtil.toggleInlineStyle(editorState, 'BOLD');
  13219. case 'italic':
  13220. return RichTextEditorUtil.toggleInlineStyle(editorState, 'ITALIC');
  13221. case 'underline':
  13222. return RichTextEditorUtil.toggleInlineStyle(editorState, 'UNDERLINE');
  13223. case 'code':
  13224. return RichTextEditorUtil.toggleCode(editorState);
  13225. case 'backspace':
  13226. case 'backspace-word':
  13227. case 'backspace-to-start-of-line':
  13228. return RichTextEditorUtil.onBackspace(editorState);
  13229. case 'delete':
  13230. case 'delete-word':
  13231. case 'delete-to-end-of-block':
  13232. return RichTextEditorUtil.onDelete(editorState);
  13233. default:
  13234. // they may have custom editor commands; ignore those
  13235. return null;
  13236. }
  13237. },
  13238. insertSoftNewline: function insertSoftNewline(editorState) {
  13239. var contentState = DraftModifier_1.insertText(editorState.getCurrentContent(), editorState.getSelection(), '\n', editorState.getCurrentInlineStyle(), null);
  13240. var newEditorState = EditorState_1.push(editorState, contentState, 'insert-characters');
  13241. return EditorState_1.forceSelection(newEditorState, contentState.getSelectionAfter());
  13242. },
  13243. /**
  13244. * For collapsed selections at the start of styled blocks, backspace should
  13245. * just remove the existing style.
  13246. */
  13247. onBackspace: function onBackspace(editorState) {
  13248. var selection = editorState.getSelection();
  13249. if (!selection.isCollapsed() || selection.getAnchorOffset() || selection.getFocusOffset()) {
  13250. return null;
  13251. }
  13252. // First, try to remove a preceding atomic block.
  13253. var content = editorState.getCurrentContent();
  13254. var startKey = selection.getStartKey();
  13255. var blockBefore = content.getBlockBefore(startKey);
  13256. if (blockBefore && blockBefore.getType() === 'atomic') {
  13257. var blockMap = content.getBlockMap()['delete'](blockBefore.getKey());
  13258. var withoutAtomicBlock = content.merge({
  13259. blockMap: blockMap,
  13260. selectionAfter: selection
  13261. });
  13262. if (withoutAtomicBlock !== content) {
  13263. return EditorState_1.push(editorState, withoutAtomicBlock, 'remove-range');
  13264. }
  13265. }
  13266. // If that doesn't succeed, try to remove the current block style.
  13267. var withoutBlockStyle = RichTextEditorUtil.tryToRemoveBlockStyle(editorState);
  13268. if (withoutBlockStyle) {
  13269. return EditorState_1.push(editorState, withoutBlockStyle, 'change-block-type');
  13270. }
  13271. return null;
  13272. },
  13273. onDelete: function onDelete(editorState) {
  13274. var selection = editorState.getSelection();
  13275. if (!selection.isCollapsed()) {
  13276. return null;
  13277. }
  13278. var content = editorState.getCurrentContent();
  13279. var startKey = selection.getStartKey();
  13280. var block = content.getBlockForKey(startKey);
  13281. var length = block.getLength();
  13282. // The cursor is somewhere within the text. Behave normally.
  13283. if (selection.getStartOffset() < length) {
  13284. return null;
  13285. }
  13286. var blockAfter = content.getBlockAfter(startKey);
  13287. if (!blockAfter || blockAfter.getType() !== 'atomic') {
  13288. return null;
  13289. }
  13290. var atomicBlockTarget = selection.merge({
  13291. focusKey: blockAfter.getKey(),
  13292. focusOffset: blockAfter.getLength()
  13293. });
  13294. var withoutAtomicBlock = DraftModifier_1.removeRange(content, atomicBlockTarget, 'forward');
  13295. if (withoutAtomicBlock !== content) {
  13296. return EditorState_1.push(editorState, withoutAtomicBlock, 'remove-range');
  13297. }
  13298. return null;
  13299. },
  13300. onTab: function onTab(event, editorState, maxDepth) {
  13301. var selection = editorState.getSelection();
  13302. var key = selection.getAnchorKey();
  13303. if (key !== selection.getFocusKey()) {
  13304. return editorState;
  13305. }
  13306. var content = editorState.getCurrentContent();
  13307. var block = content.getBlockForKey(key);
  13308. var type = block.getType();
  13309. if (type !== 'unordered-list-item' && type !== 'ordered-list-item') {
  13310. return editorState;
  13311. }
  13312. event.preventDefault();
  13313. // Only allow indenting one level beyond the block above, and only if
  13314. // the block above is a list item as well.
  13315. var blockAbove = content.getBlockBefore(key);
  13316. if (!blockAbove) {
  13317. return editorState;
  13318. }
  13319. var typeAbove = blockAbove.getType();
  13320. if (typeAbove !== 'unordered-list-item' && typeAbove !== 'ordered-list-item') {
  13321. return editorState;
  13322. }
  13323. var depth = block.getDepth();
  13324. if (!event.shiftKey && depth === maxDepth) {
  13325. return editorState;
  13326. }
  13327. maxDepth = Math.min(blockAbove.getDepth() + 1, maxDepth);
  13328. var withAdjustment = adjustBlockDepthForContentState_1(content, selection, event.shiftKey ? -1 : 1, maxDepth);
  13329. return EditorState_1.push(editorState, withAdjustment, 'adjust-depth');
  13330. },
  13331. toggleBlockType: function toggleBlockType(editorState, blockType) {
  13332. var selection = editorState.getSelection();
  13333. var startKey = selection.getStartKey();
  13334. var endKey = selection.getEndKey();
  13335. var content = editorState.getCurrentContent();
  13336. var target = selection;
  13337. // Triple-click can lead to a selection that includes offset 0 of the
  13338. // following block. The `SelectionState` for this case is accurate, but
  13339. // we should avoid toggling block type for the trailing block because it
  13340. // is a confusing interaction.
  13341. if (startKey !== endKey && selection.getEndOffset() === 0) {
  13342. var blockBefore = nullthrows_1(content.getBlockBefore(endKey));
  13343. endKey = blockBefore.getKey();
  13344. target = target.merge({
  13345. anchorKey: startKey,
  13346. anchorOffset: selection.getStartOffset(),
  13347. focusKey: endKey,
  13348. focusOffset: blockBefore.getLength(),
  13349. isBackward: false
  13350. });
  13351. }
  13352. var hasAtomicBlock = content.getBlockMap().skipWhile(function (_, k) {
  13353. return k !== startKey;
  13354. }).reverse().skipWhile(function (_, k) {
  13355. return k !== endKey;
  13356. }).some(function (v) {
  13357. return v.getType() === 'atomic';
  13358. });
  13359. if (hasAtomicBlock) {
  13360. return editorState;
  13361. }
  13362. var typeToSet = content.getBlockForKey(startKey).getType() === blockType ? 'unstyled' : blockType;
  13363. return EditorState_1.push(editorState, DraftModifier_1.setBlockType(content, target, typeToSet), 'change-block-type');
  13364. },
  13365. toggleCode: function toggleCode(editorState) {
  13366. var selection = editorState.getSelection();
  13367. var anchorKey = selection.getAnchorKey();
  13368. var focusKey = selection.getFocusKey();
  13369. if (selection.isCollapsed() || anchorKey !== focusKey) {
  13370. return RichTextEditorUtil.toggleBlockType(editorState, 'code-block');
  13371. }
  13372. return RichTextEditorUtil.toggleInlineStyle(editorState, 'CODE');
  13373. },
  13374. /**
  13375. * Toggle the specified inline style for the selection. If the
  13376. * user's selection is collapsed, apply or remove the style for the
  13377. * internal state. If it is not collapsed, apply the change directly
  13378. * to the document state.
  13379. */
  13380. toggleInlineStyle: function toggleInlineStyle(editorState, inlineStyle) {
  13381. var selection = editorState.getSelection();
  13382. var currentStyle = editorState.getCurrentInlineStyle();
  13383. // If the selection is collapsed, toggle the specified style on or off and
  13384. // set the result as the new inline style override. This will then be
  13385. // used as the inline style for the next character to be inserted.
  13386. if (selection.isCollapsed()) {
  13387. return EditorState_1.setInlineStyleOverride(editorState, currentStyle.has(inlineStyle) ? currentStyle.remove(inlineStyle) : currentStyle.add(inlineStyle));
  13388. }
  13389. // If characters are selected, immediately apply or remove the
  13390. // inline style on the document state itself.
  13391. var content = editorState.getCurrentContent();
  13392. var newContent;
  13393. // If the style is already present for the selection range, remove it.
  13394. // Otherwise, apply it.
  13395. if (currentStyle.has(inlineStyle)) {
  13396. newContent = DraftModifier_1.removeInlineStyle(content, selection, inlineStyle);
  13397. } else {
  13398. newContent = DraftModifier_1.applyInlineStyle(content, selection, inlineStyle);
  13399. }
  13400. return EditorState_1.push(editorState, newContent, 'change-inline-style');
  13401. },
  13402. toggleLink: function toggleLink(editorState, targetSelection, entityKey) {
  13403. var withoutLink = DraftModifier_1.applyEntity(editorState.getCurrentContent(), targetSelection, entityKey);
  13404. return EditorState_1.push(editorState, withoutLink, 'apply-entity');
  13405. },
  13406. /**
  13407. * When a collapsed cursor is at the start of the first styled block, or
  13408. * an empty styled block, changes block to 'unstyled'. Returns null if
  13409. * block or selection does not meet that criteria.
  13410. */
  13411. tryToRemoveBlockStyle: function tryToRemoveBlockStyle(editorState) {
  13412. var selection = editorState.getSelection();
  13413. var offset = selection.getAnchorOffset();
  13414. if (selection.isCollapsed() && offset === 0) {
  13415. var key = selection.getAnchorKey();
  13416. var content = editorState.getCurrentContent();
  13417. var block = content.getBlockForKey(key);
  13418. var firstBlock = content.getFirstBlock();
  13419. if (block.getLength() > 0 && block !== firstBlock) {
  13420. return null;
  13421. }
  13422. var type = block.getType();
  13423. var blockBefore = content.getBlockBefore(key);
  13424. if (type === 'code-block' && blockBefore && blockBefore.getType() === 'code-block' && blockBefore.getLength() !== 0) {
  13425. return null;
  13426. }
  13427. if (type !== 'unstyled') {
  13428. return DraftModifier_1.setBlockType(content, selection, 'unstyled');
  13429. }
  13430. }
  13431. return null;
  13432. }
  13433. };
  13434. var RichTextEditorUtil_1 = RichTextEditorUtil;
  13435. /**
  13436. * Copyright (c) 2013-present, Facebook, Inc.
  13437. * All rights reserved.
  13438. *
  13439. * This source code is licensed under the BSD-style license found in the
  13440. * LICENSE file in the root directory of this source tree. An additional grant
  13441. * of patent rights can be found in the PATENTS file in the same directory.
  13442. *
  13443. * @providesModule splitTextIntoTextBlocks
  13444. * @format
  13445. *
  13446. */
  13447. var NEWLINE_REGEX = /\r\n?|\n/g;
  13448. function splitTextIntoTextBlocks(text) {
  13449. return text.split(NEWLINE_REGEX);
  13450. }
  13451. var splitTextIntoTextBlocks_1 = splitTextIntoTextBlocks;
  13452. /**
  13453. * Paste content.
  13454. */
  13455. function editOnPaste(editor, e) {
  13456. e.preventDefault();
  13457. var data = new DataTransfer_1(e.clipboardData);
  13458. // Get files, unless this is likely to be a string the user wants inline.
  13459. if (!data.isRichText()) {
  13460. var files = data.getFiles();
  13461. var defaultFileText = data.getText();
  13462. if (files.length > 0) {
  13463. // Allow customized paste handling for images, etc. Otherwise, fall
  13464. // through to insert text contents into the editor.
  13465. if (editor.props.handlePastedFiles && isEventHandled_1(editor.props.handlePastedFiles(files))) {
  13466. return;
  13467. }
  13468. getTextContentFromFiles_1(files, function ( /*string*/fileText) {
  13469. fileText = fileText || defaultFileText;
  13470. if (!fileText) {
  13471. return;
  13472. }
  13473. var editorState = editor._latestEditorState;
  13474. var blocks = splitTextIntoTextBlocks_1(fileText);
  13475. var character = CharacterMetadata_1.create({
  13476. style: editorState.getCurrentInlineStyle(),
  13477. entity: getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())
  13478. });
  13479. var currentBlockType = RichTextEditorUtil_1.getCurrentBlockType(editorState);
  13480. var text = DraftPasteProcessor_1.processText(blocks, character, currentBlockType);
  13481. var fragment = BlockMapBuilder_1.createFromArray(text);
  13482. var withInsertedText = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), fragment);
  13483. editor.update(EditorState_1.push(editorState, withInsertedText, 'insert-fragment'));
  13484. });
  13485. return;
  13486. }
  13487. }
  13488. var textBlocks = [];
  13489. var text = data.getText();
  13490. var html = data.getHTML();
  13491. var editorState = editor._latestEditorState;
  13492. if (editor.props.handlePastedText && isEventHandled_1(editor.props.handlePastedText(text, html, editorState))) {
  13493. return;
  13494. }
  13495. if (text) {
  13496. textBlocks = splitTextIntoTextBlocks_1(text);
  13497. }
  13498. if (!editor.props.stripPastedStyles) {
  13499. // If the text from the paste event is rich content that matches what we
  13500. // already have on the internal clipboard, assume that we should just use
  13501. // the clipboard fragment for the paste. This will allow us to preserve
  13502. // styling and entities, if any are present. Note that newlines are
  13503. // stripped during comparison -- this is because copy/paste within the
  13504. // editor in Firefox and IE will not include empty lines. The resulting
  13505. // paste will preserve the newlines correctly.
  13506. var internalClipboard = editor.getClipboard();
  13507. if (data.isRichText() && internalClipboard) {
  13508. if (
  13509. // If the editorKey is present in the pasted HTML, it should be safe to
  13510. // assume this is an internal paste.
  13511. html.indexOf(editor.getEditorKey()) !== -1 ||
  13512. // The copy may have been made within a single block, in which case the
  13513. // editor key won't be part of the paste. In this case, just check
  13514. // whether the pasted text matches the internal clipboard.
  13515. textBlocks.length === 1 && internalClipboard.size === 1 && internalClipboard.first().getText() === text) {
  13516. editor.update(insertFragment$1(editor._latestEditorState, internalClipboard));
  13517. return;
  13518. }
  13519. } else if (internalClipboard && data.types.includes('com.apple.webarchive') && !data.types.includes('text/html') && areTextBlocksAndClipboardEqual(textBlocks, internalClipboard)) {
  13520. // Safari does not properly store text/html in some cases.
  13521. // Use the internalClipboard if present and equal to what is on
  13522. // the clipboard. See https://bugs.webkit.org/show_bug.cgi?id=19893.
  13523. editor.update(insertFragment$1(editor._latestEditorState, internalClipboard));
  13524. return;
  13525. }
  13526. // If there is html paste data, try to parse that.
  13527. if (html) {
  13528. var htmlFragment = DraftPasteProcessor_1.processHTML(html, editor.props.blockRenderMap);
  13529. if (htmlFragment) {
  13530. var contentBlocks = htmlFragment.contentBlocks,
  13531. entityMap = htmlFragment.entityMap;
  13532. if (contentBlocks) {
  13533. var htmlMap = BlockMapBuilder_1.createFromArray(contentBlocks);
  13534. editor.update(insertFragment$1(editor._latestEditorState, htmlMap, entityMap));
  13535. return;
  13536. }
  13537. }
  13538. }
  13539. // Otherwise, create a new fragment from our pasted text. Also
  13540. // empty the internal clipboard, since it's no longer valid.
  13541. editor.setClipboard(null);
  13542. }
  13543. if (textBlocks.length) {
  13544. var character = CharacterMetadata_1.create({
  13545. style: editorState.getCurrentInlineStyle(),
  13546. entity: getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())
  13547. });
  13548. var currentBlockType = RichTextEditorUtil_1.getCurrentBlockType(editorState);
  13549. var textFragment = DraftPasteProcessor_1.processText(textBlocks, character, currentBlockType);
  13550. var textMap = BlockMapBuilder_1.createFromArray(textFragment);
  13551. editor.update(insertFragment$1(editor._latestEditorState, textMap));
  13552. }
  13553. }
  13554. function insertFragment$1(editorState, fragment, entityMap) {
  13555. var newContent = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), fragment);
  13556. // TODO: merge the entity map once we stop using DraftEntity
  13557. // like this:
  13558. // const mergedEntityMap = newContent.getEntityMap().merge(entityMap);
  13559. return EditorState_1.push(editorState, newContent.set('entityMap', entityMap), 'insert-fragment');
  13560. }
  13561. function areTextBlocksAndClipboardEqual(textBlocks, blockMap) {
  13562. return textBlocks.length === blockMap.size && blockMap.valueSeq().every(function (block, ii) {
  13563. return block.getText() === textBlocks[ii];
  13564. });
  13565. }
  13566. var editOnPaste_1 = editOnPaste;
  13567. /**
  13568. * Convert the current selection range to an anchor/focus pair of offset keys
  13569. * and values that can be interpreted by components.
  13570. */
  13571. function getDraftEditorSelection(editorState, root) {
  13572. var selection = styleInject_es.commonjsGlobal.getSelection();
  13573. // No active selection.
  13574. if (selection.rangeCount === 0) {
  13575. return {
  13576. selectionState: editorState.getSelection().set('hasFocus', false),
  13577. needsRecovery: false
  13578. };
  13579. }
  13580. return getDraftEditorSelectionWithNodes_1(editorState, root, selection.anchorNode, selection.anchorOffset, selection.focusNode, selection.focusOffset);
  13581. }
  13582. var getDraftEditorSelection_1 = getDraftEditorSelection;
  13583. function editOnSelect(editor) {
  13584. if (editor._blockSelectEvents || editor._latestEditorState !== editor.props.editorState) {
  13585. return;
  13586. }
  13587. var editorState = editor.props.editorState;
  13588. var editorNode = reactDom.findDOMNode(editor.editorContainer);
  13589. !editorNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing editorNode') : invariant_1(false) : void 0;
  13590. !(editorNode.firstChild instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode.firstChild is not an HTMLElement') : invariant_1(false) : void 0;
  13591. var documentSelection = getDraftEditorSelection_1(editorState, editorNode.firstChild);
  13592. var updatedSelectionState = documentSelection.selectionState;
  13593. if (updatedSelectionState !== editorState.getSelection()) {
  13594. if (documentSelection.needsRecovery) {
  13595. editorState = EditorState_1.forceSelection(editorState, updatedSelectionState);
  13596. } else {
  13597. editorState = EditorState_1.acceptSelection(editorState, updatedSelectionState);
  13598. }
  13599. editor.update(editorState);
  13600. }
  13601. }
  13602. var editOnSelect_1 = editOnSelect;
  13603. var DraftEditorEditHandler = {
  13604. onBeforeInput: editOnBeforeInput_1,
  13605. onBlur: editOnBlur_1,
  13606. onCompositionStart: editOnCompositionStart_1,
  13607. onCopy: editOnCopy_1,
  13608. onCut: editOnCut_1,
  13609. onDragOver: editOnDragOver_1,
  13610. onDragStart: editOnDragStart_1,
  13611. onFocus: editOnFocus_1,
  13612. onInput: editOnInput_1,
  13613. onKeyDown: editOnKeyDown_1,
  13614. onPaste: editOnPaste_1,
  13615. onSelect: editOnSelect_1
  13616. };
  13617. var DraftEditorEditHandler_1 = DraftEditorEditHandler;
  13618. function _classCallCheck$f(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13619. 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; }
  13620. 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; }
  13621. /**
  13622. * This component is responsible for rendering placeholder text for the
  13623. * `DraftEditor` component.
  13624. *
  13625. * Override placeholder style via CSS.
  13626. */
  13627. var DraftEditorPlaceholder = function (_React$Component) {
  13628. _inherits$a(DraftEditorPlaceholder, _React$Component);
  13629. function DraftEditorPlaceholder() {
  13630. _classCallCheck$f(this, DraftEditorPlaceholder);
  13631. return _possibleConstructorReturn$a(this, _React$Component.apply(this, arguments));
  13632. }
  13633. DraftEditorPlaceholder.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  13634. return this.props.text !== nextProps.text || this.props.editorState.getSelection().getHasFocus() !== nextProps.editorState.getSelection().getHasFocus();
  13635. };
  13636. DraftEditorPlaceholder.prototype.render = function render() {
  13637. var hasFocus = this.props.editorState.getSelection().getHasFocus();
  13638. var className = cx_1({
  13639. 'public/DraftEditorPlaceholder/root': true,
  13640. 'public/DraftEditorPlaceholder/hasFocus': hasFocus
  13641. });
  13642. var contentStyle = {
  13643. whiteSpace: 'pre-wrap'
  13644. };
  13645. return React__default.createElement(
  13646. 'div',
  13647. { className: className },
  13648. React__default.createElement(
  13649. 'div',
  13650. {
  13651. className: cx_1('public/DraftEditorPlaceholder/inner'),
  13652. id: this.props.accessibilityID,
  13653. style: contentStyle },
  13654. this.props.text
  13655. )
  13656. );
  13657. };
  13658. return DraftEditorPlaceholder;
  13659. }(React__default.Component);
  13660. var DraftEditorPlaceholder_react = DraftEditorPlaceholder;
  13661. var isOSX$1 = UserAgent_1.isPlatform('Mac OS X');
  13662. var isWindows = UserAgent_1.isPlatform('Windows');
  13663. // Firefox on OSX had a bug resulting in navigation instead of cursor movement.
  13664. // This bug was fixed in Firefox 29. Feature detection is virtually impossible
  13665. // so we just check the version number. See #342765.
  13666. var shouldFixFirefoxMovement = isOSX$1 && UserAgent_1.isBrowser('Firefox < 29');
  13667. var hasCommandModifier = KeyBindingUtil_1.hasCommandModifier,
  13668. isCtrlKeyCommand = KeyBindingUtil_1.isCtrlKeyCommand;
  13669. function shouldRemoveWord(e) {
  13670. return isOSX$1 && e.altKey || isCtrlKeyCommand(e);
  13671. }
  13672. /**
  13673. * Get the appropriate undo/redo command for a Z key command.
  13674. */
  13675. function getZCommand(e) {
  13676. if (!hasCommandModifier(e)) {
  13677. return null;
  13678. }
  13679. return e.shiftKey ? 'redo' : 'undo';
  13680. }
  13681. function getDeleteCommand(e) {
  13682. // Allow default "cut" behavior for Windows on Shift + Delete.
  13683. if (isWindows && e.shiftKey) {
  13684. return null;
  13685. }
  13686. return shouldRemoveWord(e) ? 'delete-word' : 'delete';
  13687. }
  13688. function getBackspaceCommand(e) {
  13689. if (hasCommandModifier(e) && isOSX$1) {
  13690. return 'backspace-to-start-of-line';
  13691. }
  13692. return shouldRemoveWord(e) ? 'backspace-word' : 'backspace';
  13693. }
  13694. /**
  13695. * Retrieve a bound key command for the given event.
  13696. */
  13697. function getDefaultKeyBinding(e) {
  13698. switch (e.keyCode) {
  13699. case 66:
  13700. // B
  13701. return hasCommandModifier(e) ? 'bold' : null;
  13702. case 68:
  13703. // D
  13704. return isCtrlKeyCommand(e) ? 'delete' : null;
  13705. case 72:
  13706. // H
  13707. return isCtrlKeyCommand(e) ? 'backspace' : null;
  13708. case 73:
  13709. // I
  13710. return hasCommandModifier(e) ? 'italic' : null;
  13711. case 74:
  13712. // J
  13713. return hasCommandModifier(e) ? 'code' : null;
  13714. case 75:
  13715. // K
  13716. return !isWindows && isCtrlKeyCommand(e) ? 'secondary-cut' : null;
  13717. case 77:
  13718. // M
  13719. return isCtrlKeyCommand(e) ? 'split-block' : null;
  13720. case 79:
  13721. // O
  13722. return isCtrlKeyCommand(e) ? 'split-block' : null;
  13723. case 84:
  13724. // T
  13725. return isOSX$1 && isCtrlKeyCommand(e) ? 'transpose-characters' : null;
  13726. case 85:
  13727. // U
  13728. return hasCommandModifier(e) ? 'underline' : null;
  13729. case 87:
  13730. // W
  13731. return isOSX$1 && isCtrlKeyCommand(e) ? 'backspace-word' : null;
  13732. case 89:
  13733. // Y
  13734. if (isCtrlKeyCommand(e)) {
  13735. return isWindows ? 'redo' : 'secondary-paste';
  13736. }
  13737. return null;
  13738. case 90:
  13739. // Z
  13740. return getZCommand(e) || null;
  13741. case Keys.RETURN:
  13742. return 'split-block';
  13743. case Keys.DELETE:
  13744. return getDeleteCommand(e);
  13745. case Keys.BACKSPACE:
  13746. return getBackspaceCommand(e);
  13747. // LEFT/RIGHT handlers serve as a workaround for a Firefox bug.
  13748. case Keys.LEFT:
  13749. return shouldFixFirefoxMovement && hasCommandModifier(e) ? 'move-selection-to-start-of-block' : null;
  13750. case Keys.RIGHT:
  13751. return shouldFixFirefoxMovement && hasCommandModifier(e) ? 'move-selection-to-end-of-block' : null;
  13752. default:
  13753. return null;
  13754. }
  13755. }
  13756. var getDefaultKeyBinding_1 = getDefaultKeyBinding;
  13757. 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; };
  13758. function _classCallCheck$g(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13759. 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; }
  13760. 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; }
  13761. var isIE = UserAgent_1.isBrowser('IE');
  13762. // IE does not support the `input` event on contentEditable, so we can't
  13763. // observe spellcheck behavior.
  13764. var allowSpellCheck = !isIE;
  13765. // Define a set of handler objects to correspond to each possible `mode`
  13766. // of editor behavior.
  13767. var handlerMap = {
  13768. edit: DraftEditorEditHandler_1,
  13769. composite: DraftEditorCompositionHandler_1,
  13770. drag: DraftEditorDragHandler_1,
  13771. cut: null,
  13772. render: null
  13773. };
  13774. /**
  13775. * `DraftEditor` is the root editor component. It composes a `contentEditable`
  13776. * div, and provides a wide variety of useful function props for managing the
  13777. * state of the editor. See `DraftEditorProps` for details.
  13778. */
  13779. var DraftEditor = function (_React$Component) {
  13780. _inherits$b(DraftEditor, _React$Component);
  13781. function DraftEditor(props) {
  13782. _classCallCheck$g(this, DraftEditor);
  13783. var _this = _possibleConstructorReturn$b(this, _React$Component.call(this, props));
  13784. _this.focus = function (scrollPosition) {
  13785. var editorState = _this.props.editorState;
  13786. var alreadyHasFocus = editorState.getSelection().getHasFocus();
  13787. var editorNode = reactDom.findDOMNode(_this.editor);
  13788. if (!editorNode) {
  13789. // once in a while people call 'focus' in a setTimeout, and the node has
  13790. // been deleted, so it can be null in that case.
  13791. return;
  13792. }
  13793. var scrollParent = Style_1.getScrollParent(editorNode);
  13794. var _ref = scrollPosition || getScrollPosition_1(scrollParent),
  13795. x = _ref.x,
  13796. y = _ref.y;
  13797. !(editorNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode is not an HTMLElement') : invariant_1(false) : void 0;
  13798. editorNode.focus();
  13799. // Restore scroll position
  13800. if (scrollParent === window) {
  13801. window.scrollTo(x, y);
  13802. } else {
  13803. Scroll_1.setTop(scrollParent, y);
  13804. }
  13805. // On Chrome and Safari, calling focus on contenteditable focuses the
  13806. // cursor at the first character. This is something you don't expect when
  13807. // you're clicking on an input element but not directly on a character.
  13808. // Put the cursor back where it was before the blur.
  13809. if (!alreadyHasFocus) {
  13810. _this.update(EditorState_1.forceSelection(editorState, editorState.getSelection()));
  13811. }
  13812. };
  13813. _this.blur = function () {
  13814. var editorNode = reactDom.findDOMNode(_this.editor);
  13815. !(editorNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode is not an HTMLElement') : invariant_1(false) : void 0;
  13816. editorNode.blur();
  13817. };
  13818. _this.setMode = function (mode) {
  13819. _this._handler = handlerMap[mode];
  13820. };
  13821. _this.exitCurrentMode = function () {
  13822. _this.setMode('edit');
  13823. };
  13824. _this.restoreEditorDOM = function (scrollPosition) {
  13825. _this.setState({ contentsKey: _this.state.contentsKey + 1 }, function () {
  13826. _this.focus(scrollPosition);
  13827. });
  13828. };
  13829. _this.setClipboard = function (clipboard) {
  13830. _this._clipboard = clipboard;
  13831. };
  13832. _this.getClipboard = function () {
  13833. return _this._clipboard;
  13834. };
  13835. _this.update = function (editorState) {
  13836. _this._latestEditorState = editorState;
  13837. _this.props.onChange(editorState);
  13838. };
  13839. _this.onDragEnter = function () {
  13840. _this._dragCount++;
  13841. };
  13842. _this.onDragLeave = function () {
  13843. _this._dragCount--;
  13844. if (_this._dragCount === 0) {
  13845. _this.exitCurrentMode();
  13846. }
  13847. };
  13848. _this._blockSelectEvents = false;
  13849. _this._clipboard = null;
  13850. _this._handler = null;
  13851. _this._dragCount = 0;
  13852. _this._editorKey = props.editorKey || generateRandomKey_1();
  13853. _this._placeholderAccessibilityID = 'placeholder-' + _this._editorKey;
  13854. _this._latestEditorState = props.editorState;
  13855. _this._latestCommittedEditorState = props.editorState;
  13856. _this._onBeforeInput = _this._buildHandler('onBeforeInput');
  13857. _this._onBlur = _this._buildHandler('onBlur');
  13858. _this._onCharacterData = _this._buildHandler('onCharacterData');
  13859. _this._onCompositionEnd = _this._buildHandler('onCompositionEnd');
  13860. _this._onCompositionStart = _this._buildHandler('onCompositionStart');
  13861. _this._onCopy = _this._buildHandler('onCopy');
  13862. _this._onCut = _this._buildHandler('onCut');
  13863. _this._onDragEnd = _this._buildHandler('onDragEnd');
  13864. _this._onDragOver = _this._buildHandler('onDragOver');
  13865. _this._onDragStart = _this._buildHandler('onDragStart');
  13866. _this._onDrop = _this._buildHandler('onDrop');
  13867. _this._onInput = _this._buildHandler('onInput');
  13868. _this._onFocus = _this._buildHandler('onFocus');
  13869. _this._onKeyDown = _this._buildHandler('onKeyDown');
  13870. _this._onKeyPress = _this._buildHandler('onKeyPress');
  13871. _this._onKeyUp = _this._buildHandler('onKeyUp');
  13872. _this._onMouseDown = _this._buildHandler('onMouseDown');
  13873. _this._onMouseUp = _this._buildHandler('onMouseUp');
  13874. _this._onPaste = _this._buildHandler('onPaste');
  13875. _this._onSelect = _this._buildHandler('onSelect');
  13876. _this.getEditorKey = function () {
  13877. return _this._editorKey;
  13878. };
  13879. // See `restoreEditorDOM()`.
  13880. _this.state = { contentsKey: 0 };
  13881. return _this;
  13882. }
  13883. /**
  13884. * Build a method that will pass the event to the specified handler method.
  13885. * This allows us to look up the correct handler function for the current
  13886. * editor mode, if any has been specified.
  13887. */
  13888. /**
  13889. * Define proxies that can route events to the current handler.
  13890. */
  13891. DraftEditor.prototype._buildHandler = function _buildHandler(eventName) {
  13892. var _this2 = this;
  13893. return function (e) {
  13894. if (!_this2.props.readOnly) {
  13895. var method = _this2._handler && _this2._handler[eventName];
  13896. method && method(_this2, e);
  13897. }
  13898. };
  13899. };
  13900. DraftEditor.prototype._showPlaceholder = function _showPlaceholder() {
  13901. return !!this.props.placeholder && !this.props.editorState.isInCompositionMode() && !this.props.editorState.getCurrentContent().hasText();
  13902. };
  13903. DraftEditor.prototype._renderPlaceholder = function _renderPlaceholder() {
  13904. if (this._showPlaceholder()) {
  13905. var placeHolderProps = {
  13906. text: nullthrows_1(this.props.placeholder),
  13907. editorState: this.props.editorState,
  13908. textAlignment: this.props.textAlignment,
  13909. accessibilityID: this._placeholderAccessibilityID
  13910. };
  13911. return React__default.createElement(DraftEditorPlaceholder_react, placeHolderProps);
  13912. }
  13913. return null;
  13914. };
  13915. DraftEditor.prototype.render = function render() {
  13916. var _this3 = this;
  13917. var _props = this.props,
  13918. blockRenderMap = _props.blockRenderMap,
  13919. blockRendererFn = _props.blockRendererFn,
  13920. blockStyleFn = _props.blockStyleFn,
  13921. customStyleFn = _props.customStyleFn,
  13922. customStyleMap = _props.customStyleMap,
  13923. editorState = _props.editorState,
  13924. readOnly = _props.readOnly,
  13925. textAlignment = _props.textAlignment,
  13926. textDirectionality = _props.textDirectionality;
  13927. var rootClass = cx_1({
  13928. 'DraftEditor/root': true,
  13929. 'DraftEditor/alignLeft': textAlignment === 'left',
  13930. 'DraftEditor/alignRight': textAlignment === 'right',
  13931. 'DraftEditor/alignCenter': textAlignment === 'center'
  13932. });
  13933. var contentStyle = {
  13934. outline: 'none',
  13935. // fix parent-draggable Safari bug. #1326
  13936. userSelect: 'text',
  13937. WebkitUserSelect: 'text',
  13938. whiteSpace: 'pre-wrap',
  13939. wordWrap: 'break-word'
  13940. };
  13941. // The aria-expanded and aria-haspopup properties should only be rendered
  13942. // for a combobox.
  13943. var ariaRole = this.props.role || 'textbox';
  13944. var ariaExpanded = ariaRole === 'combobox' ? !!this.props.ariaExpanded : null;
  13945. var editorContentsProps = {
  13946. blockRenderMap: blockRenderMap,
  13947. blockRendererFn: blockRendererFn,
  13948. blockStyleFn: blockStyleFn,
  13949. customStyleMap: _extends$5({}, DefaultDraftInlineStyle, customStyleMap),
  13950. customStyleFn: customStyleFn,
  13951. editorKey: this._editorKey,
  13952. editorState: editorState,
  13953. key: 'contents' + this.state.contentsKey,
  13954. textDirectionality: textDirectionality
  13955. };
  13956. return React__default.createElement(
  13957. 'div',
  13958. { className: rootClass },
  13959. this._renderPlaceholder(),
  13960. React__default.createElement(
  13961. 'div',
  13962. {
  13963. className: cx_1('DraftEditor/editorContainer'),
  13964. ref: function ref(_ref3) {
  13965. return _this3.editorContainer = _ref3;
  13966. } },
  13967. React__default.createElement(
  13968. 'div',
  13969. {
  13970. 'aria-activedescendant': readOnly ? null : this.props.ariaActiveDescendantID,
  13971. 'aria-autocomplete': readOnly ? null : this.props.ariaAutoComplete,
  13972. 'aria-controls': readOnly ? null : this.props.ariaControls,
  13973. 'aria-describedby': this.props.ariaDescribedBy || this._placeholderAccessibilityID,
  13974. 'aria-expanded': readOnly ? null : ariaExpanded,
  13975. 'aria-label': this.props.ariaLabel,
  13976. 'aria-labelledby': this.props.ariaLabelledBy,
  13977. 'aria-multiline': this.props.ariaMultiline,
  13978. autoCapitalize: this.props.autoCapitalize,
  13979. autoComplete: this.props.autoComplete,
  13980. autoCorrect: this.props.autoCorrect,
  13981. className: cx_1({
  13982. // Chrome's built-in translation feature mutates the DOM in ways
  13983. // that Draft doesn't expect (ex: adding <font> tags inside
  13984. // DraftEditorLeaf spans) and causes problems. We add notranslate
  13985. // here which makes its autotranslation skip over this subtree.
  13986. notranslate: !readOnly,
  13987. 'public/DraftEditor/content': true
  13988. }),
  13989. contentEditable: !readOnly,
  13990. 'data-testid': this.props.webDriverTestID,
  13991. onBeforeInput: this._onBeforeInput,
  13992. onBlur: this._onBlur,
  13993. onCompositionEnd: this._onCompositionEnd,
  13994. onCompositionStart: this._onCompositionStart,
  13995. onCopy: this._onCopy,
  13996. onCut: this._onCut,
  13997. onDragEnd: this._onDragEnd,
  13998. onDragEnter: this.onDragEnter,
  13999. onDragLeave: this.onDragLeave,
  14000. onDragOver: this._onDragOver,
  14001. onDragStart: this._onDragStart,
  14002. onDrop: this._onDrop,
  14003. onFocus: this._onFocus,
  14004. onInput: this._onInput,
  14005. onKeyDown: this._onKeyDown,
  14006. onKeyPress: this._onKeyPress,
  14007. onKeyUp: this._onKeyUp,
  14008. onMouseUp: this._onMouseUp,
  14009. onPaste: this._onPaste,
  14010. onSelect: this._onSelect,
  14011. ref: function ref(_ref2) {
  14012. return _this3.editor = _ref2;
  14013. },
  14014. role: readOnly ? null : ariaRole,
  14015. spellCheck: allowSpellCheck && this.props.spellCheck,
  14016. style: contentStyle,
  14017. suppressContentEditableWarning: true,
  14018. tabIndex: this.props.tabIndex },
  14019. React__default.createElement(DraftEditorContents_react, editorContentsProps)
  14020. )
  14021. )
  14022. );
  14023. };
  14024. DraftEditor.prototype.componentDidMount = function componentDidMount() {
  14025. this.setMode('edit');
  14026. /**
  14027. * IE has a hardcoded "feature" that attempts to convert link text into
  14028. * anchors in contentEditable DOM. This breaks the editor's expectations of
  14029. * the DOM, and control is lost. Disable it to make IE behave.
  14030. * See: http://blogs.msdn.com/b/ieinternals/archive/2010/09/15/
  14031. * ie9-beta-minor-change-list.aspx
  14032. */
  14033. if (isIE) {
  14034. document.execCommand('AutoUrlDetect', false, false);
  14035. }
  14036. };
  14037. /**
  14038. * Prevent selection events from affecting the current editor state. This
  14039. * is mostly intended to defend against IE, which fires off `selectionchange`
  14040. * events regardless of whether the selection is set via the browser or
  14041. * programmatically. We only care about selection events that occur because
  14042. * of browser interaction, not re-renders and forced selections.
  14043. */
  14044. DraftEditor.prototype.componentWillUpdate = function componentWillUpdate(nextProps) {
  14045. this._blockSelectEvents = true;
  14046. this._latestEditorState = nextProps.editorState;
  14047. };
  14048. DraftEditor.prototype.componentDidUpdate = function componentDidUpdate() {
  14049. this._blockSelectEvents = false;
  14050. this._latestCommittedEditorState = this.props.editorState;
  14051. };
  14052. /**
  14053. * Used via `this.focus()`.
  14054. *
  14055. * Force focus back onto the editor node.
  14056. *
  14057. * We attempt to preserve scroll position when focusing. You can also pass
  14058. * a specified scroll position (for cases like `cut` behavior where it should
  14059. * be restored to a known position).
  14060. */
  14061. /**
  14062. * Used via `this.setMode(...)`.
  14063. *
  14064. * Set the behavior mode for the editor component. This switches the current
  14065. * handler module to ensure that DOM events are managed appropriately for
  14066. * the active mode.
  14067. */
  14068. /**
  14069. * Used via `this.restoreEditorDOM()`.
  14070. *
  14071. * Force a complete re-render of the DraftEditorContents based on the current
  14072. * EditorState. This is useful when we know we are going to lose control of
  14073. * the DOM state (cut command, IME) and we want to make sure that
  14074. * reconciliation occurs on a version of the DOM that is synchronized with
  14075. * our EditorState.
  14076. */
  14077. /**
  14078. * Used via `this.setClipboard(...)`.
  14079. *
  14080. * Set the clipboard state for a cut/copy event.
  14081. */
  14082. /**
  14083. * Used via `this.getClipboard()`.
  14084. *
  14085. * Retrieve the clipboard state for a cut/copy event.
  14086. */
  14087. /**
  14088. * Used via `this.update(...)`.
  14089. *
  14090. * Propagate a new `EditorState` object to higher-level components. This is
  14091. * the method by which event handlers inform the `DraftEditor` component of
  14092. * state changes. A component that composes a `DraftEditor` **must** provide
  14093. * an `onChange` prop to receive state updates passed along from this
  14094. * function.
  14095. */
  14096. /**
  14097. * Used in conjunction with `onDragLeave()`, by counting the number of times
  14098. * a dragged element enters and leaves the editor (or any of its children),
  14099. * to determine when the dragged element absolutely leaves the editor.
  14100. */
  14101. /**
  14102. * See `onDragEnter()`.
  14103. */
  14104. return DraftEditor;
  14105. }(React__default.Component);
  14106. DraftEditor.defaultProps = {
  14107. blockRenderMap: DefaultDraftBlockRenderMap_1,
  14108. blockRendererFn: emptyFunction_1.thatReturnsNull,
  14109. blockStyleFn: emptyFunction_1.thatReturns(''),
  14110. keyBindingFn: getDefaultKeyBinding_1,
  14111. readOnly: false,
  14112. spellCheck: false,
  14113. stripPastedStyles: false
  14114. };
  14115. var DraftEditor_react = DraftEditor;
  14116. /**
  14117. * Copyright (c) 2013-present, Facebook, Inc.
  14118. * All rights reserved.
  14119. *
  14120. * This source code is licensed under the BSD-style license found in the
  14121. * LICENSE file in the root directory of this source tree. An additional grant
  14122. * of patent rights can be found in the PATENTS file in the same directory.
  14123. *
  14124. * @providesModule DraftStringKey
  14125. * @format
  14126. *
  14127. */
  14128. var DraftStringKey = {
  14129. stringify: function stringify(key) {
  14130. return '_' + String(key);
  14131. },
  14132. unstringify: function unstringify(key) {
  14133. return key.slice(1);
  14134. }
  14135. };
  14136. var DraftStringKey_1 = DraftStringKey;
  14137. var strlen$1 = UnicodeUtils_1.strlen;
  14138. /**
  14139. * Convert to UTF-8 character counts for storage.
  14140. */
  14141. function encodeEntityRanges(block, storageMap) {
  14142. var encoded = [];
  14143. block.findEntityRanges(function (character) {
  14144. return !!character.getEntity();
  14145. }, function ( /*number*/start, /*number*/end) {
  14146. var text = block.getText();
  14147. var key = block.getEntityAt(start);
  14148. encoded.push({
  14149. offset: strlen$1(text.slice(0, start)),
  14150. length: strlen$1(text.slice(start, end)),
  14151. // Encode the key as a number for range storage.
  14152. key: Number(storageMap[DraftStringKey_1.stringify(key)])
  14153. });
  14154. });
  14155. return encoded;
  14156. }
  14157. var encodeEntityRanges_1 = encodeEntityRanges;
  14158. var areEqual$1 = function areEqual(a, b) {
  14159. return a === b;
  14160. };
  14161. var isTruthy = function isTruthy(a) {
  14162. return !!a;
  14163. };
  14164. var EMPTY_ARRAY = [];
  14165. /**
  14166. * Helper function for getting encoded styles for each inline style. Convert
  14167. * to UTF-8 character counts for storage.
  14168. */
  14169. function getEncodedInlinesForType(block, styleList, styleToEncode) {
  14170. var ranges = [];
  14171. // Obtain an array with ranges for only the specified style.
  14172. var filteredInlines = styleList.map(function (style) {
  14173. return style.has(styleToEncode);
  14174. }).toList();
  14175. findRangesImmutable_1(filteredInlines, areEqual$1,
  14176. // We only want to keep ranges with nonzero style values.
  14177. isTruthy, function (start, end) {
  14178. var text = block.getText();
  14179. ranges.push({
  14180. offset: UnicodeUtils_1.strlen(text.slice(0, start)),
  14181. length: UnicodeUtils_1.strlen(text.slice(start, end)),
  14182. style: styleToEncode
  14183. });
  14184. });
  14185. return ranges;
  14186. }
  14187. /*
  14188. * Retrieve the encoded arrays of inline styles, with each individual style
  14189. * treated separately.
  14190. */
  14191. function encodeInlineStyleRanges(block) {
  14192. var styleList = block.getCharacterList().map(function (c) {
  14193. return c.getStyle();
  14194. }).toList();
  14195. var ranges = styleList.flatten().toSet().map(function (style) {
  14196. return getEncodedInlinesForType(block, styleList, style);
  14197. });
  14198. return Array.prototype.concat.apply(EMPTY_ARRAY, ranges.toJS());
  14199. }
  14200. var encodeInlineStyleRanges_1 = encodeInlineStyleRanges;
  14201. 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; };
  14202. var createRawBlock = function createRawBlock(block, entityStorageMap) {
  14203. return {
  14204. key: block.getKey(),
  14205. text: block.getText(),
  14206. type: block.getType(),
  14207. depth: block.getDepth(),
  14208. inlineStyleRanges: encodeInlineStyleRanges_1(block),
  14209. entityRanges: encodeEntityRanges_1(block, entityStorageMap),
  14210. data: block.getData().toObject()
  14211. };
  14212. };
  14213. var insertRawBlock = function insertRawBlock(block, entityMap, rawBlocks, blockCacheRef) {
  14214. if (block instanceof ContentBlock_1) {
  14215. rawBlocks.push(createRawBlock(block, entityMap));
  14216. return;
  14217. }
  14218. !(block instanceof ContentBlockNode_1) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'block is not a BlockNode') : invariant_1(false) : void 0;
  14219. var parentKey = block.getParentKey();
  14220. var rawBlock = blockCacheRef[block.getKey()] = _extends$6({}, createRawBlock(block, entityMap), {
  14221. children: []
  14222. });
  14223. if (parentKey) {
  14224. blockCacheRef[parentKey].children.push(rawBlock);
  14225. return;
  14226. }
  14227. rawBlocks.push(rawBlock);
  14228. };
  14229. var encodeRawBlocks = function encodeRawBlocks(contentState, rawState) {
  14230. var entityMap = rawState.entityMap;
  14231. var rawBlocks = [];
  14232. var blockCacheRef = {};
  14233. var entityCacheRef = {};
  14234. var entityStorageKey = 0;
  14235. contentState.getBlockMap().forEach(function (block) {
  14236. block.findEntityRanges(function (character) {
  14237. return character.getEntity() !== null;
  14238. }, function (start) {
  14239. var entityKey = block.getEntityAt(start);
  14240. // Stringify to maintain order of otherwise numeric keys.
  14241. var stringifiedEntityKey = DraftStringKey_1.stringify(entityKey);
  14242. // This makes this function resilient to two entities
  14243. // erroneously having the same key
  14244. if (entityCacheRef[stringifiedEntityKey]) {
  14245. return;
  14246. }
  14247. entityCacheRef[stringifiedEntityKey] = entityKey;
  14248. // we need the `any` casting here since this is a temporary state
  14249. // where we will later on flip the entity map and populate it with
  14250. // real entity, at this stage we just need to map back the entity
  14251. // key used by the BlockNode
  14252. entityMap[stringifiedEntityKey] = '' + entityStorageKey;
  14253. entityStorageKey++;
  14254. });
  14255. insertRawBlock(block, entityMap, rawBlocks, blockCacheRef);
  14256. });
  14257. return {
  14258. blocks: rawBlocks,
  14259. entityMap: entityMap
  14260. };
  14261. };
  14262. // Flip storage map so that our storage keys map to global
  14263. // DraftEntity keys.
  14264. var encodeRawEntityMap = function encodeRawEntityMap(contentState, rawState) {
  14265. var blocks = rawState.blocks,
  14266. entityMap = rawState.entityMap;
  14267. var rawEntityMap = {};
  14268. Object.keys(entityMap).forEach(function (key, index) {
  14269. var entity = contentState.getEntity(DraftStringKey_1.unstringify(key));
  14270. rawEntityMap[index] = {
  14271. type: entity.getType(),
  14272. mutability: entity.getMutability(),
  14273. data: entity.getData()
  14274. };
  14275. });
  14276. return {
  14277. blocks: blocks,
  14278. entityMap: rawEntityMap
  14279. };
  14280. };
  14281. var convertFromDraftStateToRaw = function convertFromDraftStateToRaw(contentState) {
  14282. var rawDraftContentState = {
  14283. entityMap: {},
  14284. blocks: []
  14285. };
  14286. // add blocks
  14287. rawDraftContentState = encodeRawBlocks(contentState, rawDraftContentState);
  14288. // add entities
  14289. rawDraftContentState = encodeRawEntityMap(contentState, rawDraftContentState);
  14290. return rawDraftContentState;
  14291. };
  14292. var convertFromDraftStateToRaw_1 = convertFromDraftStateToRaw;
  14293. 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; };
  14294. /**
  14295. * Copyright (c) 2013-present, Facebook, Inc.
  14296. * All rights reserved.
  14297. *
  14298. * This source code is licensed under the BSD-style license found in the
  14299. * LICENSE file in the root directory of this source tree. An additional grant
  14300. * of patent rights can be found in the PATENTS file in the same directory.
  14301. *
  14302. * @providesModule DraftTreeAdapter
  14303. * @format
  14304. *
  14305. *
  14306. * This is unstable and not part of the public API and should not be used by
  14307. * production systems. This file may be update/removed without notice.
  14308. */
  14309. var traverseInDepthOrder = function traverseInDepthOrder(blocks, fn) {
  14310. var stack = [].concat(blocks).reverse();
  14311. while (stack.length) {
  14312. var _block = stack.pop();
  14313. fn(_block);
  14314. var children = _block.children;
  14315. !Array.isArray(children) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid tree raw block') : invariant_1(false) : void 0;
  14316. stack = stack.concat([].concat(children.reverse()));
  14317. }
  14318. };
  14319. var isListBlock = function isListBlock(block) {
  14320. if (!(block && block.type)) {
  14321. return false;
  14322. }
  14323. var type = block.type;
  14324. return type === 'unordered-list-item' || type === 'ordered-list-item';
  14325. };
  14326. var addDepthToChildren = function addDepthToChildren(block) {
  14327. if (Array.isArray(block.children)) {
  14328. block.children = block.children.map(function (child) {
  14329. return child.type === block.type ? _extends$7({}, child, { depth: (block.depth || 0) + 1 }) : child;
  14330. });
  14331. }
  14332. };
  14333. /**
  14334. * This adapter is intended to be be used as an adapter to draft tree data
  14335. *
  14336. * draft state <=====> draft tree state
  14337. */
  14338. var DraftTreeAdapter = {
  14339. /**
  14340. * Converts from a tree raw state back to draft raw state
  14341. */
  14342. fromRawTreeStateToRawState: function fromRawTreeStateToRawState(draftTreeState) {
  14343. var blocks = draftTreeState.blocks;
  14344. var transformedBlocks = [];
  14345. !Array.isArray(blocks) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid raw state') : invariant_1(false) : void 0;
  14346. if (!Array.isArray(blocks) || !blocks.length) {
  14347. return draftTreeState;
  14348. }
  14349. traverseInDepthOrder(blocks, function (block) {
  14350. var newBlock = _extends$7({}, block);
  14351. if (isListBlock(block)) {
  14352. newBlock.depth = newBlock.depth || 0;
  14353. addDepthToChildren(block);
  14354. }
  14355. delete newBlock.children;
  14356. transformedBlocks.push(newBlock);
  14357. });
  14358. draftTreeState.blocks = transformedBlocks;
  14359. return _extends$7({}, draftTreeState, {
  14360. blocks: transformedBlocks
  14361. });
  14362. },
  14363. /**
  14364. * Converts from draft raw state to tree draft state
  14365. */
  14366. fromRawStateToRawTreeState: function fromRawStateToRawTreeState(draftState) {
  14367. var lastListDepthCacheRef = {};
  14368. var transformedBlocks = [];
  14369. draftState.blocks.forEach(function (block) {
  14370. var isList = isListBlock(block);
  14371. var depth = block.depth || 0;
  14372. var treeBlock = _extends$7({}, block, {
  14373. children: []
  14374. });
  14375. if (!isList) {
  14376. // reset the cache path
  14377. lastListDepthCacheRef = {};
  14378. transformedBlocks.push(treeBlock);
  14379. return;
  14380. }
  14381. // update our depth cache reference path
  14382. lastListDepthCacheRef[depth] = treeBlock;
  14383. // if we are greater than zero we must have seen a parent already
  14384. if (depth > 0) {
  14385. var parent = lastListDepthCacheRef[depth - 1];
  14386. !parent ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid depth for RawDraftContentBlock') : invariant_1(false) : void 0;
  14387. // push nested list blocks
  14388. parent.children.push(treeBlock);
  14389. return;
  14390. }
  14391. // push root list blocks
  14392. transformedBlocks.push(treeBlock);
  14393. });
  14394. return _extends$7({}, draftState, {
  14395. blocks: transformedBlocks
  14396. });
  14397. }
  14398. };
  14399. var DraftTreeAdapter_1 = DraftTreeAdapter;
  14400. var List$c = immutable.List;
  14401. function createCharacterList(inlineStyles, entities) {
  14402. var characterArray = inlineStyles.map(function (style, ii) {
  14403. var entity = entities[ii];
  14404. return CharacterMetadata_1.create({ style: style, entity: entity });
  14405. });
  14406. return List$c(characterArray);
  14407. }
  14408. var createCharacterList_1 = createCharacterList;
  14409. var substr$1 = UnicodeUtils_1.substr;
  14410. /**
  14411. * Convert to native JavaScript string lengths to determine ranges.
  14412. */
  14413. function decodeEntityRanges(text, ranges) {
  14414. var entities = Array(text.length).fill(null);
  14415. if (ranges) {
  14416. ranges.forEach(function (range) {
  14417. // Using Unicode-enabled substrings converted to JavaScript lengths,
  14418. // fill the output array with entity keys.
  14419. var start = substr$1(text, 0, range.offset).length;
  14420. var end = start + substr$1(text, range.offset, range.length).length;
  14421. for (var ii = start; ii < end; ii++) {
  14422. entities[ii] = range.key;
  14423. }
  14424. });
  14425. }
  14426. return entities;
  14427. }
  14428. var decodeEntityRanges_1 = decodeEntityRanges;
  14429. var OrderedSet$6 = immutable.OrderedSet;
  14430. var substr$2 = UnicodeUtils_1.substr;
  14431. var EMPTY_SET$3 = OrderedSet$6();
  14432. /**
  14433. * Convert to native JavaScript string lengths to determine ranges.
  14434. */
  14435. function decodeInlineStyleRanges(text, ranges) {
  14436. var styles = Array(text.length).fill(EMPTY_SET$3);
  14437. if (ranges) {
  14438. ranges.forEach(function ( /*object*/range) {
  14439. var cursor = substr$2(text, 0, range.offset).length;
  14440. var end = cursor + substr$2(text, range.offset, range.length).length;
  14441. while (cursor < end) {
  14442. styles[cursor] = styles[cursor].add(range.style);
  14443. cursor++;
  14444. }
  14445. });
  14446. }
  14447. return styles;
  14448. }
  14449. var decodeInlineStyleRanges_1 = decodeInlineStyleRanges;
  14450. 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; };
  14451. var List$d = immutable.List,
  14452. Map$a = immutable.Map,
  14453. OrderedMap$4 = immutable.OrderedMap;
  14454. var decodeBlockNodeConfig = function decodeBlockNodeConfig(block, entityMap) {
  14455. var key = block.key,
  14456. type = block.type,
  14457. data = block.data,
  14458. text = block.text,
  14459. depth = block.depth;
  14460. var blockNodeConfig = {
  14461. text: text,
  14462. depth: depth || 0,
  14463. type: type || 'unstyled',
  14464. key: key || generateRandomKey_1(),
  14465. data: Map$a(data),
  14466. characterList: decodeCharacterList(block, entityMap)
  14467. };
  14468. return blockNodeConfig;
  14469. };
  14470. var decodeCharacterList = function decodeCharacterList(block, entityMap) {
  14471. var text = block.text,
  14472. rawEntityRanges = block.entityRanges,
  14473. rawInlineStyleRanges = block.inlineStyleRanges;
  14474. var entityRanges = rawEntityRanges || [];
  14475. var inlineStyleRanges = rawInlineStyleRanges || [];
  14476. // Translate entity range keys to the DraftEntity map.
  14477. return createCharacterList_1(decodeInlineStyleRanges_1(text, inlineStyleRanges), decodeEntityRanges_1(text, entityRanges.filter(function (range) {
  14478. return entityMap.hasOwnProperty(range.key);
  14479. }).map(function (range) {
  14480. return _extends$8({}, range, { key: entityMap[range.key] });
  14481. })));
  14482. };
  14483. var decodeContentBlocks = function decodeContentBlocks(blocks, entityMap) {
  14484. return OrderedMap$4(blocks.map(function (block) {
  14485. var contentBlock = new ContentBlock_1(decodeBlockNodeConfig(block, entityMap));
  14486. return [contentBlock.getKey(), contentBlock];
  14487. }));
  14488. };
  14489. var decodeRawBlocks = function decodeRawBlocks(rawState, entityMap) {
  14490. var isTreeRawBlock = Array.isArray(rawState.blocks[0].children);
  14491. var rawBlocks = rawState.blocks;
  14492. {
  14493. return decodeContentBlocks(isTreeRawBlock ? DraftTreeAdapter_1.fromRawTreeStateToRawState(rawState).blocks : rawBlocks, entityMap);
  14494. }
  14495. };
  14496. var decodeRawEntityMap = function decodeRawEntityMap(rawState) {
  14497. var rawEntityMap = rawState.entityMap;
  14498. var entityMap = {};
  14499. // TODO: Update this once we completely remove DraftEntity
  14500. Object.keys(rawEntityMap).forEach(function (rawEntityKey) {
  14501. var _rawEntityMap$rawEnti = rawEntityMap[rawEntityKey],
  14502. type = _rawEntityMap$rawEnti.type,
  14503. mutability = _rawEntityMap$rawEnti.mutability,
  14504. data = _rawEntityMap$rawEnti.data;
  14505. // get the key reference to created entity
  14506. entityMap[rawEntityKey] = DraftEntity_1.__create(type, mutability, data || {});
  14507. });
  14508. return entityMap;
  14509. };
  14510. var convertFromRawToDraftState = function convertFromRawToDraftState(rawState) {
  14511. !Array.isArray(rawState.blocks) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'invalid RawDraftContentState') : invariant_1(false) : void 0;
  14512. // decode entities
  14513. var entityMap = decodeRawEntityMap(rawState);
  14514. // decode blockMap
  14515. var blockMap = decodeRawBlocks(rawState, entityMap);
  14516. // create initial selection
  14517. var selectionState = blockMap.isEmpty() ? new SelectionState_1() : SelectionState_1.createEmpty(blockMap.first().getKey());
  14518. return new ContentState_1({
  14519. blockMap: blockMap,
  14520. entityMap: entityMap,
  14521. selectionBefore: selectionState,
  14522. selectionAfter: selectionState
  14523. });
  14524. };
  14525. var convertFromRawToDraftState_1 = convertFromRawToDraftState;
  14526. /**
  14527. * Like range.getBoundingClientRect() but normalizes for browser bugs.
  14528. */
  14529. function getRangeBoundingClientRect(range) {
  14530. // "Return a DOMRect object describing the smallest rectangle that includes
  14531. // the first rectangle in list and all of the remaining rectangles of which
  14532. // the height or width is not zero."
  14533. // http://www.w3.org/TR/cssom-view/#dom-range-getboundingclientrect
  14534. var rects = getRangeClientRects_1(range);
  14535. var top = 0;
  14536. var right = 0;
  14537. var bottom = 0;
  14538. var left = 0;
  14539. if (rects.length) {
  14540. // If the first rectangle has 0 width, we use the second, this is needed
  14541. // because Chrome renders a 0 width rectangle when the selection contains
  14542. // a line break.
  14543. if (rects.length > 1 && rects[0].width === 0) {
  14544. var _rects$ = rects[1];
  14545. top = _rects$.top;
  14546. right = _rects$.right;
  14547. bottom = _rects$.bottom;
  14548. left = _rects$.left;
  14549. } else {
  14550. var _rects$2 = rects[0];
  14551. top = _rects$2.top;
  14552. right = _rects$2.right;
  14553. bottom = _rects$2.bottom;
  14554. left = _rects$2.left;
  14555. }
  14556. for (var ii = 1; ii < rects.length; ii++) {
  14557. var rect = rects[ii];
  14558. if (rect.height !== 0 && rect.width !== 0) {
  14559. top = Math.min(top, rect.top);
  14560. right = Math.max(right, rect.right);
  14561. bottom = Math.max(bottom, rect.bottom);
  14562. left = Math.min(left, rect.left);
  14563. }
  14564. }
  14565. }
  14566. return {
  14567. top: top,
  14568. right: right,
  14569. bottom: bottom,
  14570. left: left,
  14571. width: right - left,
  14572. height: bottom - top
  14573. };
  14574. }
  14575. var getRangeBoundingClientRect_1 = getRangeBoundingClientRect;
  14576. /**
  14577. * Return the bounding ClientRect for the visible DOM selection, if any.
  14578. * In cases where there are no selected ranges or the bounding rect is
  14579. * temporarily invalid, return null.
  14580. */
  14581. function getVisibleSelectionRect(global) {
  14582. var selection = global.getSelection();
  14583. if (!selection.rangeCount) {
  14584. return null;
  14585. }
  14586. var range = selection.getRangeAt(0);
  14587. var boundingRect = getRangeBoundingClientRect_1(range);
  14588. var top = boundingRect.top,
  14589. right = boundingRect.right,
  14590. bottom = boundingRect.bottom,
  14591. left = boundingRect.left;
  14592. // When a re-render leads to a node being removed, the DOM selection will
  14593. // temporarily be placed on an ancestor node, which leads to an invalid
  14594. // bounding rect. Discard this state.
  14595. if (top === 0 && right === 0 && bottom === 0 && left === 0) {
  14596. return null;
  14597. }
  14598. return boundingRect;
  14599. }
  14600. var getVisibleSelectionRect_1 = getVisibleSelectionRect;
  14601. var DraftPublic = {
  14602. Editor: DraftEditor_react,
  14603. EditorBlock: DraftEditorBlock_react,
  14604. EditorState: EditorState_1,
  14605. CompositeDecorator: CompositeDraftDecorator_1,
  14606. Entity: DraftEntity_1,
  14607. EntityInstance: DraftEntityInstance_1,
  14608. BlockMapBuilder: BlockMapBuilder_1,
  14609. CharacterMetadata: CharacterMetadata_1,
  14610. ContentBlock: ContentBlock_1,
  14611. ContentState: ContentState_1,
  14612. SelectionState: SelectionState_1,
  14613. AtomicBlockUtils: AtomicBlockUtils_1,
  14614. KeyBindingUtil: KeyBindingUtil_1,
  14615. Modifier: DraftModifier_1,
  14616. RichUtils: RichTextEditorUtil_1,
  14617. DefaultDraftBlockRenderMap: DefaultDraftBlockRenderMap_1,
  14618. DefaultDraftInlineStyle: DefaultDraftInlineStyle,
  14619. convertFromHTML: convertFromHTMLToContentBlocks,
  14620. convertFromRaw: convertFromRawToDraftState_1,
  14621. convertToRaw: convertFromDraftStateToRaw_1,
  14622. genKey: generateRandomKey_1,
  14623. getDefaultKeyBinding: getDefaultKeyBinding_1,
  14624. getVisibleSelectionRect: getVisibleSelectionRect_1
  14625. };
  14626. var Draft = DraftPublic;
  14627. var Draft_1 = Draft.Editor;
  14628. var Draft_3 = Draft.EditorState;
  14629. var Draft_4 = Draft.CompositeDecorator;
  14630. var Draft_14 = Draft.Modifier;
  14631. var Draft_15 = Draft.RichUtils;
  14632. var Draft_20 = Draft.convertToRaw;
  14633. var immutable$1 = styleInject_es.createCommonjsModule(function (module, exports) {
  14634. /**
  14635. * Copyright (c) 2014-2015, Facebook, Inc.
  14636. * All rights reserved.
  14637. *
  14638. * This source code is licensed under the BSD-style license found in the
  14639. * LICENSE file in the root directory of this source tree. An additional grant
  14640. * of patent rights can be found in the PATENTS file in the same directory.
  14641. */
  14642. (function (global, factory) {
  14643. module.exports = factory() ;
  14644. }(styleInject_es.commonjsGlobal, function () {var SLICE$0 = Array.prototype.slice;
  14645. function createClass(ctor, superClass) {
  14646. if (superClass) {
  14647. ctor.prototype = Object.create(superClass.prototype);
  14648. }
  14649. ctor.prototype.constructor = ctor;
  14650. }
  14651. function Iterable(value) {
  14652. return isIterable(value) ? value : Seq(value);
  14653. }
  14654. createClass(KeyedIterable, Iterable);
  14655. function KeyedIterable(value) {
  14656. return isKeyed(value) ? value : KeyedSeq(value);
  14657. }
  14658. createClass(IndexedIterable, Iterable);
  14659. function IndexedIterable(value) {
  14660. return isIndexed(value) ? value : IndexedSeq(value);
  14661. }
  14662. createClass(SetIterable, Iterable);
  14663. function SetIterable(value) {
  14664. return isIterable(value) && !isAssociative(value) ? value : SetSeq(value);
  14665. }
  14666. function isIterable(maybeIterable) {
  14667. return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]);
  14668. }
  14669. function isKeyed(maybeKeyed) {
  14670. return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
  14671. }
  14672. function isIndexed(maybeIndexed) {
  14673. return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
  14674. }
  14675. function isAssociative(maybeAssociative) {
  14676. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  14677. }
  14678. function isOrdered(maybeOrdered) {
  14679. return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
  14680. }
  14681. Iterable.isIterable = isIterable;
  14682. Iterable.isKeyed = isKeyed;
  14683. Iterable.isIndexed = isIndexed;
  14684. Iterable.isAssociative = isAssociative;
  14685. Iterable.isOrdered = isOrdered;
  14686. Iterable.Keyed = KeyedIterable;
  14687. Iterable.Indexed = IndexedIterable;
  14688. Iterable.Set = SetIterable;
  14689. var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  14690. var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  14691. var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  14692. var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  14693. // Used for setting prototype methods that IE8 chokes on.
  14694. var DELETE = 'delete';
  14695. // Constants describing the size of trie nodes.
  14696. var SHIFT = 5; // Resulted in best performance after ______?
  14697. var SIZE = 1 << SHIFT;
  14698. var MASK = SIZE - 1;
  14699. // A consistent shared value representing "not set" which equals nothing other
  14700. // than itself, and nothing that could be provided externally.
  14701. var NOT_SET = {};
  14702. // Boolean references, Rough equivalent of `bool &`.
  14703. var CHANGE_LENGTH = { value: false };
  14704. var DID_ALTER = { value: false };
  14705. function MakeRef(ref) {
  14706. ref.value = false;
  14707. return ref;
  14708. }
  14709. function SetRef(ref) {
  14710. ref && (ref.value = true);
  14711. }
  14712. // A function which returns a value representing an "owner" for transient writes
  14713. // to tries. The return value will only ever equal itself, and will not equal
  14714. // the return of any subsequent call of this function.
  14715. function OwnerID() {}
  14716. // http://jsperf.com/copy-array-inline
  14717. function arrCopy(arr, offset) {
  14718. offset = offset || 0;
  14719. var len = Math.max(0, arr.length - offset);
  14720. var newArr = new Array(len);
  14721. for (var ii = 0; ii < len; ii++) {
  14722. newArr[ii] = arr[ii + offset];
  14723. }
  14724. return newArr;
  14725. }
  14726. function ensureSize(iter) {
  14727. if (iter.size === undefined) {
  14728. iter.size = iter.__iterate(returnTrue);
  14729. }
  14730. return iter.size;
  14731. }
  14732. function wrapIndex(iter, index) {
  14733. // This implements "is array index" which the ECMAString spec defines as:
  14734. //
  14735. // A String property name P is an array index if and only if
  14736. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  14737. // to 2^32−1.
  14738. //
  14739. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  14740. if (typeof index !== 'number') {
  14741. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  14742. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  14743. return NaN;
  14744. }
  14745. index = uint32Index;
  14746. }
  14747. return index < 0 ? ensureSize(iter) + index : index;
  14748. }
  14749. function returnTrue() {
  14750. return true;
  14751. }
  14752. function wholeSlice(begin, end, size) {
  14753. return (begin === 0 || (size !== undefined && begin <= -size)) &&
  14754. (end === undefined || (size !== undefined && end >= size));
  14755. }
  14756. function resolveBegin(begin, size) {
  14757. return resolveIndex(begin, size, 0);
  14758. }
  14759. function resolveEnd(end, size) {
  14760. return resolveIndex(end, size, size);
  14761. }
  14762. function resolveIndex(index, size, defaultIndex) {
  14763. return index === undefined ?
  14764. defaultIndex :
  14765. index < 0 ?
  14766. Math.max(0, size + index) :
  14767. size === undefined ?
  14768. index :
  14769. Math.min(size, index);
  14770. }
  14771. /* global Symbol */
  14772. var ITERATE_KEYS = 0;
  14773. var ITERATE_VALUES = 1;
  14774. var ITERATE_ENTRIES = 2;
  14775. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  14776. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  14777. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  14778. function Iterator(next) {
  14779. this.next = next;
  14780. }
  14781. Iterator.prototype.toString = function() {
  14782. return '[Iterator]';
  14783. };
  14784. Iterator.KEYS = ITERATE_KEYS;
  14785. Iterator.VALUES = ITERATE_VALUES;
  14786. Iterator.ENTRIES = ITERATE_ENTRIES;
  14787. Iterator.prototype.inspect =
  14788. Iterator.prototype.toSource = function () { return this.toString(); };
  14789. Iterator.prototype[ITERATOR_SYMBOL] = function () {
  14790. return this;
  14791. };
  14792. function iteratorValue(type, k, v, iteratorResult) {
  14793. var value = type === 0 ? k : type === 1 ? v : [k, v];
  14794. iteratorResult ? (iteratorResult.value = value) : (iteratorResult = {
  14795. value: value, done: false
  14796. });
  14797. return iteratorResult;
  14798. }
  14799. function iteratorDone() {
  14800. return { value: undefined, done: true };
  14801. }
  14802. function hasIterator(maybeIterable) {
  14803. return !!getIteratorFn(maybeIterable);
  14804. }
  14805. function isIterator(maybeIterator) {
  14806. return maybeIterator && typeof maybeIterator.next === 'function';
  14807. }
  14808. function getIterator(iterable) {
  14809. var iteratorFn = getIteratorFn(iterable);
  14810. return iteratorFn && iteratorFn.call(iterable);
  14811. }
  14812. function getIteratorFn(iterable) {
  14813. var iteratorFn = iterable && (
  14814. (REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  14815. iterable[FAUX_ITERATOR_SYMBOL]
  14816. );
  14817. if (typeof iteratorFn === 'function') {
  14818. return iteratorFn;
  14819. }
  14820. }
  14821. function isArrayLike(value) {
  14822. return value && typeof value.length === 'number';
  14823. }
  14824. createClass(Seq, Iterable);
  14825. function Seq(value) {
  14826. return value === null || value === undefined ? emptySequence() :
  14827. isIterable(value) ? value.toSeq() : seqFromValue(value);
  14828. }
  14829. Seq.of = function(/*...values*/) {
  14830. return Seq(arguments);
  14831. };
  14832. Seq.prototype.toSeq = function() {
  14833. return this;
  14834. };
  14835. Seq.prototype.toString = function() {
  14836. return this.__toString('Seq {', '}');
  14837. };
  14838. Seq.prototype.cacheResult = function() {
  14839. if (!this._cache && this.__iterateUncached) {
  14840. this._cache = this.entrySeq().toArray();
  14841. this.size = this._cache.length;
  14842. }
  14843. return this;
  14844. };
  14845. // abstract __iterateUncached(fn, reverse)
  14846. Seq.prototype.__iterate = function(fn, reverse) {
  14847. return seqIterate(this, fn, reverse, true);
  14848. };
  14849. // abstract __iteratorUncached(type, reverse)
  14850. Seq.prototype.__iterator = function(type, reverse) {
  14851. return seqIterator(this, type, reverse, true);
  14852. };
  14853. createClass(KeyedSeq, Seq);
  14854. function KeyedSeq(value) {
  14855. return value === null || value === undefined ?
  14856. emptySequence().toKeyedSeq() :
  14857. isIterable(value) ?
  14858. (isKeyed(value) ? value.toSeq() : value.fromEntrySeq()) :
  14859. keyedSeqFromValue(value);
  14860. }
  14861. KeyedSeq.prototype.toKeyedSeq = function() {
  14862. return this;
  14863. };
  14864. createClass(IndexedSeq, Seq);
  14865. function IndexedSeq(value) {
  14866. return value === null || value === undefined ? emptySequence() :
  14867. !isIterable(value) ? indexedSeqFromValue(value) :
  14868. isKeyed(value) ? value.entrySeq() : value.toIndexedSeq();
  14869. }
  14870. IndexedSeq.of = function(/*...values*/) {
  14871. return IndexedSeq(arguments);
  14872. };
  14873. IndexedSeq.prototype.toIndexedSeq = function() {
  14874. return this;
  14875. };
  14876. IndexedSeq.prototype.toString = function() {
  14877. return this.__toString('Seq [', ']');
  14878. };
  14879. IndexedSeq.prototype.__iterate = function(fn, reverse) {
  14880. return seqIterate(this, fn, reverse, false);
  14881. };
  14882. IndexedSeq.prototype.__iterator = function(type, reverse) {
  14883. return seqIterator(this, type, reverse, false);
  14884. };
  14885. createClass(SetSeq, Seq);
  14886. function SetSeq(value) {
  14887. return (
  14888. value === null || value === undefined ? emptySequence() :
  14889. !isIterable(value) ? indexedSeqFromValue(value) :
  14890. isKeyed(value) ? value.entrySeq() : value
  14891. ).toSetSeq();
  14892. }
  14893. SetSeq.of = function(/*...values*/) {
  14894. return SetSeq(arguments);
  14895. };
  14896. SetSeq.prototype.toSetSeq = function() {
  14897. return this;
  14898. };
  14899. Seq.isSeq = isSeq;
  14900. Seq.Keyed = KeyedSeq;
  14901. Seq.Set = SetSeq;
  14902. Seq.Indexed = IndexedSeq;
  14903. var IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
  14904. Seq.prototype[IS_SEQ_SENTINEL] = true;
  14905. createClass(ArraySeq, IndexedSeq);
  14906. function ArraySeq(array) {
  14907. this._array = array;
  14908. this.size = array.length;
  14909. }
  14910. ArraySeq.prototype.get = function(index, notSetValue) {
  14911. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  14912. };
  14913. ArraySeq.prototype.__iterate = function(fn, reverse) {
  14914. var array = this._array;
  14915. var maxIndex = array.length - 1;
  14916. for (var ii = 0; ii <= maxIndex; ii++) {
  14917. if (fn(array[reverse ? maxIndex - ii : ii], ii, this) === false) {
  14918. return ii + 1;
  14919. }
  14920. }
  14921. return ii;
  14922. };
  14923. ArraySeq.prototype.__iterator = function(type, reverse) {
  14924. var array = this._array;
  14925. var maxIndex = array.length - 1;
  14926. var ii = 0;
  14927. return new Iterator(function()
  14928. {return ii > maxIndex ?
  14929. iteratorDone() :
  14930. iteratorValue(type, ii, array[reverse ? maxIndex - ii++ : ii++])}
  14931. );
  14932. };
  14933. createClass(ObjectSeq, KeyedSeq);
  14934. function ObjectSeq(object) {
  14935. var keys = Object.keys(object);
  14936. this._object = object;
  14937. this._keys = keys;
  14938. this.size = keys.length;
  14939. }
  14940. ObjectSeq.prototype.get = function(key, notSetValue) {
  14941. if (notSetValue !== undefined && !this.has(key)) {
  14942. return notSetValue;
  14943. }
  14944. return this._object[key];
  14945. };
  14946. ObjectSeq.prototype.has = function(key) {
  14947. return this._object.hasOwnProperty(key);
  14948. };
  14949. ObjectSeq.prototype.__iterate = function(fn, reverse) {
  14950. var object = this._object;
  14951. var keys = this._keys;
  14952. var maxIndex = keys.length - 1;
  14953. for (var ii = 0; ii <= maxIndex; ii++) {
  14954. var key = keys[reverse ? maxIndex - ii : ii];
  14955. if (fn(object[key], key, this) === false) {
  14956. return ii + 1;
  14957. }
  14958. }
  14959. return ii;
  14960. };
  14961. ObjectSeq.prototype.__iterator = function(type, reverse) {
  14962. var object = this._object;
  14963. var keys = this._keys;
  14964. var maxIndex = keys.length - 1;
  14965. var ii = 0;
  14966. return new Iterator(function() {
  14967. var key = keys[reverse ? maxIndex - ii : ii];
  14968. return ii++ > maxIndex ?
  14969. iteratorDone() :
  14970. iteratorValue(type, key, object[key]);
  14971. });
  14972. };
  14973. ObjectSeq.prototype[IS_ORDERED_SENTINEL] = true;
  14974. createClass(IterableSeq, IndexedSeq);
  14975. function IterableSeq(iterable) {
  14976. this._iterable = iterable;
  14977. this.size = iterable.length || iterable.size;
  14978. }
  14979. IterableSeq.prototype.__iterateUncached = function(fn, reverse) {
  14980. if (reverse) {
  14981. return this.cacheResult().__iterate(fn, reverse);
  14982. }
  14983. var iterable = this._iterable;
  14984. var iterator = getIterator(iterable);
  14985. var iterations = 0;
  14986. if (isIterator(iterator)) {
  14987. var step;
  14988. while (!(step = iterator.next()).done) {
  14989. if (fn(step.value, iterations++, this) === false) {
  14990. break;
  14991. }
  14992. }
  14993. }
  14994. return iterations;
  14995. };
  14996. IterableSeq.prototype.__iteratorUncached = function(type, reverse) {
  14997. if (reverse) {
  14998. return this.cacheResult().__iterator(type, reverse);
  14999. }
  15000. var iterable = this._iterable;
  15001. var iterator = getIterator(iterable);
  15002. if (!isIterator(iterator)) {
  15003. return new Iterator(iteratorDone);
  15004. }
  15005. var iterations = 0;
  15006. return new Iterator(function() {
  15007. var step = iterator.next();
  15008. return step.done ? step : iteratorValue(type, iterations++, step.value);
  15009. });
  15010. };
  15011. createClass(IteratorSeq, IndexedSeq);
  15012. function IteratorSeq(iterator) {
  15013. this._iterator = iterator;
  15014. this._iteratorCache = [];
  15015. }
  15016. IteratorSeq.prototype.__iterateUncached = function(fn, reverse) {
  15017. if (reverse) {
  15018. return this.cacheResult().__iterate(fn, reverse);
  15019. }
  15020. var iterator = this._iterator;
  15021. var cache = this._iteratorCache;
  15022. var iterations = 0;
  15023. while (iterations < cache.length) {
  15024. if (fn(cache[iterations], iterations++, this) === false) {
  15025. return iterations;
  15026. }
  15027. }
  15028. var step;
  15029. while (!(step = iterator.next()).done) {
  15030. var val = step.value;
  15031. cache[iterations] = val;
  15032. if (fn(val, iterations++, this) === false) {
  15033. break;
  15034. }
  15035. }
  15036. return iterations;
  15037. };
  15038. IteratorSeq.prototype.__iteratorUncached = function(type, reverse) {
  15039. if (reverse) {
  15040. return this.cacheResult().__iterator(type, reverse);
  15041. }
  15042. var iterator = this._iterator;
  15043. var cache = this._iteratorCache;
  15044. var iterations = 0;
  15045. return new Iterator(function() {
  15046. if (iterations >= cache.length) {
  15047. var step = iterator.next();
  15048. if (step.done) {
  15049. return step;
  15050. }
  15051. cache[iterations] = step.value;
  15052. }
  15053. return iteratorValue(type, iterations, cache[iterations++]);
  15054. });
  15055. };
  15056. // # pragma Helper functions
  15057. function isSeq(maybeSeq) {
  15058. return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]);
  15059. }
  15060. var EMPTY_SEQ;
  15061. function emptySequence() {
  15062. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  15063. }
  15064. function keyedSeqFromValue(value) {
  15065. var seq =
  15066. Array.isArray(value) ? new ArraySeq(value).fromEntrySeq() :
  15067. isIterator(value) ? new IteratorSeq(value).fromEntrySeq() :
  15068. hasIterator(value) ? new IterableSeq(value).fromEntrySeq() :
  15069. typeof value === 'object' ? new ObjectSeq(value) :
  15070. undefined;
  15071. if (!seq) {
  15072. throw new TypeError(
  15073. 'Expected Array or iterable object of [k, v] entries, '+
  15074. 'or keyed object: ' + value
  15075. );
  15076. }
  15077. return seq;
  15078. }
  15079. function indexedSeqFromValue(value) {
  15080. var seq = maybeIndexedSeqFromValue(value);
  15081. if (!seq) {
  15082. throw new TypeError(
  15083. 'Expected Array or iterable object of values: ' + value
  15084. );
  15085. }
  15086. return seq;
  15087. }
  15088. function seqFromValue(value) {
  15089. var seq = maybeIndexedSeqFromValue(value) ||
  15090. (typeof value === 'object' && new ObjectSeq(value));
  15091. if (!seq) {
  15092. throw new TypeError(
  15093. 'Expected Array or iterable object of values, or keyed object: ' + value
  15094. );
  15095. }
  15096. return seq;
  15097. }
  15098. function maybeIndexedSeqFromValue(value) {
  15099. return (
  15100. isArrayLike(value) ? new ArraySeq(value) :
  15101. isIterator(value) ? new IteratorSeq(value) :
  15102. hasIterator(value) ? new IterableSeq(value) :
  15103. undefined
  15104. );
  15105. }
  15106. function seqIterate(seq, fn, reverse, useKeys) {
  15107. var cache = seq._cache;
  15108. if (cache) {
  15109. var maxIndex = cache.length - 1;
  15110. for (var ii = 0; ii <= maxIndex; ii++) {
  15111. var entry = cache[reverse ? maxIndex - ii : ii];
  15112. if (fn(entry[1], useKeys ? entry[0] : ii, seq) === false) {
  15113. return ii + 1;
  15114. }
  15115. }
  15116. return ii;
  15117. }
  15118. return seq.__iterateUncached(fn, reverse);
  15119. }
  15120. function seqIterator(seq, type, reverse, useKeys) {
  15121. var cache = seq._cache;
  15122. if (cache) {
  15123. var maxIndex = cache.length - 1;
  15124. var ii = 0;
  15125. return new Iterator(function() {
  15126. var entry = cache[reverse ? maxIndex - ii : ii];
  15127. return ii++ > maxIndex ?
  15128. iteratorDone() :
  15129. iteratorValue(type, useKeys ? entry[0] : ii - 1, entry[1]);
  15130. });
  15131. }
  15132. return seq.__iteratorUncached(type, reverse);
  15133. }
  15134. function fromJS(json, converter) {
  15135. return converter ?
  15136. fromJSWith(converter, json, '', {'': json}) :
  15137. fromJSDefault(json);
  15138. }
  15139. function fromJSWith(converter, json, key, parentJSON) {
  15140. if (Array.isArray(json)) {
  15141. return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  15142. }
  15143. if (isPlainObj(json)) {
  15144. return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  15145. }
  15146. return json;
  15147. }
  15148. function fromJSDefault(json) {
  15149. if (Array.isArray(json)) {
  15150. return IndexedSeq(json).map(fromJSDefault).toList();
  15151. }
  15152. if (isPlainObj(json)) {
  15153. return KeyedSeq(json).map(fromJSDefault).toMap();
  15154. }
  15155. return json;
  15156. }
  15157. function isPlainObj(value) {
  15158. return value && (value.constructor === Object || value.constructor === undefined);
  15159. }
  15160. /**
  15161. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  15162. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  15163. *
  15164. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  15165. * value, which is different from the algorithm described by
  15166. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  15167. *
  15168. * This is extended further to allow Objects to describe the values they
  15169. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  15170. *
  15171. * Note: because of this extension, the key equality of Immutable.Map and the
  15172. * value equality of Immutable.Set will differ from ES6 Map and Set.
  15173. *
  15174. * ### Defining custom values
  15175. *
  15176. * The easiest way to describe the value an object represents is by implementing
  15177. * `valueOf`. For example, `Date` represents a value by returning a unix
  15178. * timestamp for `valueOf`:
  15179. *
  15180. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  15181. * var date2 = new Date(1234567890000);
  15182. * date1.valueOf(); // 1234567890000
  15183. * assert( date1 !== date2 );
  15184. * assert( Immutable.is( date1, date2 ) );
  15185. *
  15186. * Note: overriding `valueOf` may have other implications if you use this object
  15187. * where JavaScript expects a primitive, such as implicit string coercion.
  15188. *
  15189. * For more complex types, especially collections, implementing `valueOf` may
  15190. * not be performant. An alternative is to implement `equals` and `hashCode`.
  15191. *
  15192. * `equals` takes another object, presumably of similar type, and returns true
  15193. * if the it is equal. Equality is symmetrical, so the same result should be
  15194. * returned if this and the argument are flipped.
  15195. *
  15196. * assert( a.equals(b) === b.equals(a) );
  15197. *
  15198. * `hashCode` returns a 32bit integer number representing the object which will
  15199. * be used to determine how to store the value object in a Map or Set. You must
  15200. * provide both or neither methods, one must not exist without the other.
  15201. *
  15202. * Also, an important relationship between these methods must be upheld: if two
  15203. * values are equal, they *must* return the same hashCode. If the values are not
  15204. * equal, they might have the same hashCode; this is called a hash collision,
  15205. * and while undesirable for performance reasons, it is acceptable.
  15206. *
  15207. * if (a.equals(b)) {
  15208. * assert( a.hashCode() === b.hashCode() );
  15209. * }
  15210. *
  15211. * All Immutable collections implement `equals` and `hashCode`.
  15212. *
  15213. */
  15214. function is(valueA, valueB) {
  15215. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  15216. return true;
  15217. }
  15218. if (!valueA || !valueB) {
  15219. return false;
  15220. }
  15221. if (typeof valueA.valueOf === 'function' &&
  15222. typeof valueB.valueOf === 'function') {
  15223. valueA = valueA.valueOf();
  15224. valueB = valueB.valueOf();
  15225. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  15226. return true;
  15227. }
  15228. if (!valueA || !valueB) {
  15229. return false;
  15230. }
  15231. }
  15232. if (typeof valueA.equals === 'function' &&
  15233. typeof valueB.equals === 'function' &&
  15234. valueA.equals(valueB)) {
  15235. return true;
  15236. }
  15237. return false;
  15238. }
  15239. function deepEqual(a, b) {
  15240. if (a === b) {
  15241. return true;
  15242. }
  15243. if (
  15244. !isIterable(b) ||
  15245. a.size !== undefined && b.size !== undefined && a.size !== b.size ||
  15246. a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
  15247. isKeyed(a) !== isKeyed(b) ||
  15248. isIndexed(a) !== isIndexed(b) ||
  15249. isOrdered(a) !== isOrdered(b)
  15250. ) {
  15251. return false;
  15252. }
  15253. if (a.size === 0 && b.size === 0) {
  15254. return true;
  15255. }
  15256. var notAssociative = !isAssociative(a);
  15257. if (isOrdered(a)) {
  15258. var entries = a.entries();
  15259. return b.every(function(v, k) {
  15260. var entry = entries.next().value;
  15261. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  15262. }) && entries.next().done;
  15263. }
  15264. var flipped = false;
  15265. if (a.size === undefined) {
  15266. if (b.size === undefined) {
  15267. if (typeof a.cacheResult === 'function') {
  15268. a.cacheResult();
  15269. }
  15270. } else {
  15271. flipped = true;
  15272. var _ = a;
  15273. a = b;
  15274. b = _;
  15275. }
  15276. }
  15277. var allEqual = true;
  15278. var bSize = b.__iterate(function(v, k) {
  15279. if (notAssociative ? !a.has(v) :
  15280. flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
  15281. allEqual = false;
  15282. return false;
  15283. }
  15284. });
  15285. return allEqual && a.size === bSize;
  15286. }
  15287. createClass(Repeat, IndexedSeq);
  15288. function Repeat(value, times) {
  15289. if (!(this instanceof Repeat)) {
  15290. return new Repeat(value, times);
  15291. }
  15292. this._value = value;
  15293. this.size = times === undefined ? Infinity : Math.max(0, times);
  15294. if (this.size === 0) {
  15295. if (EMPTY_REPEAT) {
  15296. return EMPTY_REPEAT;
  15297. }
  15298. EMPTY_REPEAT = this;
  15299. }
  15300. }
  15301. Repeat.prototype.toString = function() {
  15302. if (this.size === 0) {
  15303. return 'Repeat []';
  15304. }
  15305. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  15306. };
  15307. Repeat.prototype.get = function(index, notSetValue) {
  15308. return this.has(index) ? this._value : notSetValue;
  15309. };
  15310. Repeat.prototype.includes = function(searchValue) {
  15311. return is(this._value, searchValue);
  15312. };
  15313. Repeat.prototype.slice = function(begin, end) {
  15314. var size = this.size;
  15315. return wholeSlice(begin, end, size) ? this :
  15316. new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
  15317. };
  15318. Repeat.prototype.reverse = function() {
  15319. return this;
  15320. };
  15321. Repeat.prototype.indexOf = function(searchValue) {
  15322. if (is(this._value, searchValue)) {
  15323. return 0;
  15324. }
  15325. return -1;
  15326. };
  15327. Repeat.prototype.lastIndexOf = function(searchValue) {
  15328. if (is(this._value, searchValue)) {
  15329. return this.size;
  15330. }
  15331. return -1;
  15332. };
  15333. Repeat.prototype.__iterate = function(fn, reverse) {
  15334. for (var ii = 0; ii < this.size; ii++) {
  15335. if (fn(this._value, ii, this) === false) {
  15336. return ii + 1;
  15337. }
  15338. }
  15339. return ii;
  15340. };
  15341. Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
  15342. var ii = 0;
  15343. return new Iterator(function()
  15344. {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
  15345. );
  15346. };
  15347. Repeat.prototype.equals = function(other) {
  15348. return other instanceof Repeat ?
  15349. is(this._value, other._value) :
  15350. deepEqual(other);
  15351. };
  15352. var EMPTY_REPEAT;
  15353. function invariant(condition, error) {
  15354. if (!condition) throw new Error(error);
  15355. }
  15356. createClass(Range, IndexedSeq);
  15357. function Range(start, end, step) {
  15358. if (!(this instanceof Range)) {
  15359. return new Range(start, end, step);
  15360. }
  15361. invariant(step !== 0, 'Cannot step a Range by 0');
  15362. start = start || 0;
  15363. if (end === undefined) {
  15364. end = Infinity;
  15365. }
  15366. step = step === undefined ? 1 : Math.abs(step);
  15367. if (end < start) {
  15368. step = -step;
  15369. }
  15370. this._start = start;
  15371. this._end = end;
  15372. this._step = step;
  15373. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  15374. if (this.size === 0) {
  15375. if (EMPTY_RANGE) {
  15376. return EMPTY_RANGE;
  15377. }
  15378. EMPTY_RANGE = this;
  15379. }
  15380. }
  15381. Range.prototype.toString = function() {
  15382. if (this.size === 0) {
  15383. return 'Range []';
  15384. }
  15385. return 'Range [ ' +
  15386. this._start + '...' + this._end +
  15387. (this._step > 1 ? ' by ' + this._step : '') +
  15388. ' ]';
  15389. };
  15390. Range.prototype.get = function(index, notSetValue) {
  15391. return this.has(index) ?
  15392. this._start + wrapIndex(this, index) * this._step :
  15393. notSetValue;
  15394. };
  15395. Range.prototype.includes = function(searchValue) {
  15396. var possibleIndex = (searchValue - this._start) / this._step;
  15397. return possibleIndex >= 0 &&
  15398. possibleIndex < this.size &&
  15399. possibleIndex === Math.floor(possibleIndex);
  15400. };
  15401. Range.prototype.slice = function(begin, end) {
  15402. if (wholeSlice(begin, end, this.size)) {
  15403. return this;
  15404. }
  15405. begin = resolveBegin(begin, this.size);
  15406. end = resolveEnd(end, this.size);
  15407. if (end <= begin) {
  15408. return new Range(0, 0);
  15409. }
  15410. return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
  15411. };
  15412. Range.prototype.indexOf = function(searchValue) {
  15413. var offsetValue = searchValue - this._start;
  15414. if (offsetValue % this._step === 0) {
  15415. var index = offsetValue / this._step;
  15416. if (index >= 0 && index < this.size) {
  15417. return index
  15418. }
  15419. }
  15420. return -1;
  15421. };
  15422. Range.prototype.lastIndexOf = function(searchValue) {
  15423. return this.indexOf(searchValue);
  15424. };
  15425. Range.prototype.__iterate = function(fn, reverse) {
  15426. var maxIndex = this.size - 1;
  15427. var step = this._step;
  15428. var value = reverse ? this._start + maxIndex * step : this._start;
  15429. for (var ii = 0; ii <= maxIndex; ii++) {
  15430. if (fn(value, ii, this) === false) {
  15431. return ii + 1;
  15432. }
  15433. value += reverse ? -step : step;
  15434. }
  15435. return ii;
  15436. };
  15437. Range.prototype.__iterator = function(type, reverse) {
  15438. var maxIndex = this.size - 1;
  15439. var step = this._step;
  15440. var value = reverse ? this._start + maxIndex * step : this._start;
  15441. var ii = 0;
  15442. return new Iterator(function() {
  15443. var v = value;
  15444. value += reverse ? -step : step;
  15445. return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
  15446. });
  15447. };
  15448. Range.prototype.equals = function(other) {
  15449. return other instanceof Range ?
  15450. this._start === other._start &&
  15451. this._end === other._end &&
  15452. this._step === other._step :
  15453. deepEqual(this, other);
  15454. };
  15455. var EMPTY_RANGE;
  15456. createClass(Collection, Iterable);
  15457. function Collection() {
  15458. throw TypeError('Abstract');
  15459. }
  15460. createClass(KeyedCollection, Collection);function KeyedCollection() {}
  15461. createClass(IndexedCollection, Collection);function IndexedCollection() {}
  15462. createClass(SetCollection, Collection);function SetCollection() {}
  15463. Collection.Keyed = KeyedCollection;
  15464. Collection.Indexed = IndexedCollection;
  15465. Collection.Set = SetCollection;
  15466. var imul =
  15467. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
  15468. Math.imul :
  15469. function imul(a, b) {
  15470. a = a | 0; // int
  15471. b = b | 0; // int
  15472. var c = a & 0xffff;
  15473. var d = b & 0xffff;
  15474. // Shift by 0 fixes the sign on the high part.
  15475. return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int
  15476. };
  15477. // v8 has an optimization for storing 31-bit signed numbers.
  15478. // Values which have either 00 or 11 as the high order bits qualify.
  15479. // This function drops the highest order bit in a signed number, maintaining
  15480. // the sign bit.
  15481. function smi(i32) {
  15482. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
  15483. }
  15484. function hash(o) {
  15485. if (o === false || o === null || o === undefined) {
  15486. return 0;
  15487. }
  15488. if (typeof o.valueOf === 'function') {
  15489. o = o.valueOf();
  15490. if (o === false || o === null || o === undefined) {
  15491. return 0;
  15492. }
  15493. }
  15494. if (o === true) {
  15495. return 1;
  15496. }
  15497. var type = typeof o;
  15498. if (type === 'number') {
  15499. var h = o | 0;
  15500. if (h !== o) {
  15501. h ^= o * 0xFFFFFFFF;
  15502. }
  15503. while (o > 0xFFFFFFFF) {
  15504. o /= 0xFFFFFFFF;
  15505. h ^= o;
  15506. }
  15507. return smi(h);
  15508. }
  15509. if (type === 'string') {
  15510. return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
  15511. }
  15512. if (typeof o.hashCode === 'function') {
  15513. return o.hashCode();
  15514. }
  15515. if (type === 'object') {
  15516. return hashJSObj(o);
  15517. }
  15518. if (typeof o.toString === 'function') {
  15519. return hashString(o.toString());
  15520. }
  15521. throw new Error('Value type ' + type + ' cannot be hashed.');
  15522. }
  15523. function cachedHashString(string) {
  15524. var hash = stringHashCache[string];
  15525. if (hash === undefined) {
  15526. hash = hashString(string);
  15527. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  15528. STRING_HASH_CACHE_SIZE = 0;
  15529. stringHashCache = {};
  15530. }
  15531. STRING_HASH_CACHE_SIZE++;
  15532. stringHashCache[string] = hash;
  15533. }
  15534. return hash;
  15535. }
  15536. // http://jsperf.com/hashing-strings
  15537. function hashString(string) {
  15538. // This is the hash from JVM
  15539. // The hash code for a string is computed as
  15540. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  15541. // where s[i] is the ith character of the string and n is the length of
  15542. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  15543. // (exclusive) by dropping high bits.
  15544. var hash = 0;
  15545. for (var ii = 0; ii < string.length; ii++) {
  15546. hash = 31 * hash + string.charCodeAt(ii) | 0;
  15547. }
  15548. return smi(hash);
  15549. }
  15550. function hashJSObj(obj) {
  15551. var hash;
  15552. if (usingWeakMap) {
  15553. hash = weakMap.get(obj);
  15554. if (hash !== undefined) {
  15555. return hash;
  15556. }
  15557. }
  15558. hash = obj[UID_HASH_KEY];
  15559. if (hash !== undefined) {
  15560. return hash;
  15561. }
  15562. if (!canDefineProperty) {
  15563. hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  15564. if (hash !== undefined) {
  15565. return hash;
  15566. }
  15567. hash = getIENodeHash(obj);
  15568. if (hash !== undefined) {
  15569. return hash;
  15570. }
  15571. }
  15572. hash = ++objHashUID;
  15573. if (objHashUID & 0x40000000) {
  15574. objHashUID = 0;
  15575. }
  15576. if (usingWeakMap) {
  15577. weakMap.set(obj, hash);
  15578. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  15579. throw new Error('Non-extensible objects are not allowed as keys.');
  15580. } else if (canDefineProperty) {
  15581. Object.defineProperty(obj, UID_HASH_KEY, {
  15582. 'enumerable': false,
  15583. 'configurable': false,
  15584. 'writable': false,
  15585. 'value': hash
  15586. });
  15587. } else if (obj.propertyIsEnumerable !== undefined &&
  15588. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
  15589. // Since we can't define a non-enumerable property on the object
  15590. // we'll hijack one of the less-used non-enumerable properties to
  15591. // save our hash on it. Since this is a function it will not show up in
  15592. // `JSON.stringify` which is what we want.
  15593. obj.propertyIsEnumerable = function() {
  15594. return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
  15595. };
  15596. obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
  15597. } else if (obj.nodeType !== undefined) {
  15598. // At this point we couldn't get the IE `uniqueID` to use as a hash
  15599. // and we couldn't use a non-enumerable property to exploit the
  15600. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  15601. // itself.
  15602. obj[UID_HASH_KEY] = hash;
  15603. } else {
  15604. throw new Error('Unable to set a non-enumerable property on object.');
  15605. }
  15606. return hash;
  15607. }
  15608. // Get references to ES5 object methods.
  15609. var isExtensible = Object.isExtensible;
  15610. // True if Object.defineProperty works as expected. IE8 fails this test.
  15611. var canDefineProperty = (function() {
  15612. try {
  15613. Object.defineProperty({}, '@', {});
  15614. return true;
  15615. } catch (e) {
  15616. return false;
  15617. }
  15618. }());
  15619. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  15620. // and avoid memory leaks from the IE cloneNode bug.
  15621. function getIENodeHash(node) {
  15622. if (node && node.nodeType > 0) {
  15623. switch (node.nodeType) {
  15624. case 1: // Element
  15625. return node.uniqueID;
  15626. case 9: // Document
  15627. return node.documentElement && node.documentElement.uniqueID;
  15628. }
  15629. }
  15630. }
  15631. // If possible, use a WeakMap.
  15632. var usingWeakMap = typeof WeakMap === 'function';
  15633. var weakMap;
  15634. if (usingWeakMap) {
  15635. weakMap = new WeakMap();
  15636. }
  15637. var objHashUID = 0;
  15638. var UID_HASH_KEY = '__immutablehash__';
  15639. if (typeof Symbol === 'function') {
  15640. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  15641. }
  15642. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  15643. var STRING_HASH_CACHE_MAX_SIZE = 255;
  15644. var STRING_HASH_CACHE_SIZE = 0;
  15645. var stringHashCache = {};
  15646. function assertNotInfinite(size) {
  15647. invariant(
  15648. size !== Infinity,
  15649. 'Cannot perform this action with an infinite size.'
  15650. );
  15651. }
  15652. createClass(Map, KeyedCollection);
  15653. // @pragma Construction
  15654. function Map(value) {
  15655. return value === null || value === undefined ? emptyMap() :
  15656. isMap(value) && !isOrdered(value) ? value :
  15657. emptyMap().withMutations(function(map ) {
  15658. var iter = KeyedIterable(value);
  15659. assertNotInfinite(iter.size);
  15660. iter.forEach(function(v, k) {return map.set(k, v)});
  15661. });
  15662. }
  15663. Map.prototype.toString = function() {
  15664. return this.__toString('Map {', '}');
  15665. };
  15666. // @pragma Access
  15667. Map.prototype.get = function(k, notSetValue) {
  15668. return this._root ?
  15669. this._root.get(0, undefined, k, notSetValue) :
  15670. notSetValue;
  15671. };
  15672. // @pragma Modification
  15673. Map.prototype.set = function(k, v) {
  15674. return updateMap(this, k, v);
  15675. };
  15676. Map.prototype.setIn = function(keyPath, v) {
  15677. return this.updateIn(keyPath, NOT_SET, function() {return v});
  15678. };
  15679. Map.prototype.remove = function(k) {
  15680. return updateMap(this, k, NOT_SET);
  15681. };
  15682. Map.prototype.deleteIn = function(keyPath) {
  15683. return this.updateIn(keyPath, function() {return NOT_SET});
  15684. };
  15685. Map.prototype.update = function(k, notSetValue, updater) {
  15686. return arguments.length === 1 ?
  15687. k(this) :
  15688. this.updateIn([k], notSetValue, updater);
  15689. };
  15690. Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
  15691. if (!updater) {
  15692. updater = notSetValue;
  15693. notSetValue = undefined;
  15694. }
  15695. var updatedValue = updateInDeepMap(
  15696. this,
  15697. forceIterator(keyPath),
  15698. notSetValue,
  15699. updater
  15700. );
  15701. return updatedValue === NOT_SET ? undefined : updatedValue;
  15702. };
  15703. Map.prototype.clear = function() {
  15704. if (this.size === 0) {
  15705. return this;
  15706. }
  15707. if (this.__ownerID) {
  15708. this.size = 0;
  15709. this._root = null;
  15710. this.__hash = undefined;
  15711. this.__altered = true;
  15712. return this;
  15713. }
  15714. return emptyMap();
  15715. };
  15716. // @pragma Composition
  15717. Map.prototype.merge = function(/*...iters*/) {
  15718. return mergeIntoMapWith(this, undefined, arguments);
  15719. };
  15720. Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  15721. return mergeIntoMapWith(this, merger, iters);
  15722. };
  15723. Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  15724. return this.updateIn(
  15725. keyPath,
  15726. emptyMap(),
  15727. function(m ) {return typeof m.merge === 'function' ?
  15728. m.merge.apply(m, iters) :
  15729. iters[iters.length - 1]}
  15730. );
  15731. };
  15732. Map.prototype.mergeDeep = function(/*...iters*/) {
  15733. return mergeIntoMapWith(this, deepMerger, arguments);
  15734. };
  15735. Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  15736. return mergeIntoMapWith(this, deepMergerWith(merger), iters);
  15737. };
  15738. Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  15739. return this.updateIn(
  15740. keyPath,
  15741. emptyMap(),
  15742. function(m ) {return typeof m.mergeDeep === 'function' ?
  15743. m.mergeDeep.apply(m, iters) :
  15744. iters[iters.length - 1]}
  15745. );
  15746. };
  15747. Map.prototype.sort = function(comparator) {
  15748. // Late binding
  15749. return OrderedMap(sortFactory(this, comparator));
  15750. };
  15751. Map.prototype.sortBy = function(mapper, comparator) {
  15752. // Late binding
  15753. return OrderedMap(sortFactory(this, comparator, mapper));
  15754. };
  15755. // @pragma Mutability
  15756. Map.prototype.withMutations = function(fn) {
  15757. var mutable = this.asMutable();
  15758. fn(mutable);
  15759. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  15760. };
  15761. Map.prototype.asMutable = function() {
  15762. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  15763. };
  15764. Map.prototype.asImmutable = function() {
  15765. return this.__ensureOwner();
  15766. };
  15767. Map.prototype.wasAltered = function() {
  15768. return this.__altered;
  15769. };
  15770. Map.prototype.__iterator = function(type, reverse) {
  15771. return new MapIterator(this, type, reverse);
  15772. };
  15773. Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  15774. var iterations = 0;
  15775. this._root && this._root.iterate(function(entry ) {
  15776. iterations++;
  15777. return fn(entry[1], entry[0], this$0);
  15778. }, reverse);
  15779. return iterations;
  15780. };
  15781. Map.prototype.__ensureOwner = function(ownerID) {
  15782. if (ownerID === this.__ownerID) {
  15783. return this;
  15784. }
  15785. if (!ownerID) {
  15786. this.__ownerID = ownerID;
  15787. this.__altered = false;
  15788. return this;
  15789. }
  15790. return makeMap(this.size, this._root, ownerID, this.__hash);
  15791. };
  15792. function isMap(maybeMap) {
  15793. return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
  15794. }
  15795. Map.isMap = isMap;
  15796. var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
  15797. var MapPrototype = Map.prototype;
  15798. MapPrototype[IS_MAP_SENTINEL] = true;
  15799. MapPrototype[DELETE] = MapPrototype.remove;
  15800. MapPrototype.removeIn = MapPrototype.deleteIn;
  15801. // #pragma Trie Nodes
  15802. function ArrayMapNode(ownerID, entries) {
  15803. this.ownerID = ownerID;
  15804. this.entries = entries;
  15805. }
  15806. ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  15807. var entries = this.entries;
  15808. for (var ii = 0, len = entries.length; ii < len; ii++) {
  15809. if (is(key, entries[ii][0])) {
  15810. return entries[ii][1];
  15811. }
  15812. }
  15813. return notSetValue;
  15814. };
  15815. ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  15816. var removed = value === NOT_SET;
  15817. var entries = this.entries;
  15818. var idx = 0;
  15819. for (var len = entries.length; idx < len; idx++) {
  15820. if (is(key, entries[idx][0])) {
  15821. break;
  15822. }
  15823. }
  15824. var exists = idx < len;
  15825. if (exists ? entries[idx][1] === value : removed) {
  15826. return this;
  15827. }
  15828. SetRef(didAlter);
  15829. (removed || !exists) && SetRef(didChangeSize);
  15830. if (removed && entries.length === 1) {
  15831. return; // undefined
  15832. }
  15833. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  15834. return createNodes(ownerID, entries, key, value);
  15835. }
  15836. var isEditable = ownerID && ownerID === this.ownerID;
  15837. var newEntries = isEditable ? entries : arrCopy(entries);
  15838. if (exists) {
  15839. if (removed) {
  15840. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  15841. } else {
  15842. newEntries[idx] = [key, value];
  15843. }
  15844. } else {
  15845. newEntries.push([key, value]);
  15846. }
  15847. if (isEditable) {
  15848. this.entries = newEntries;
  15849. return this;
  15850. }
  15851. return new ArrayMapNode(ownerID, newEntries);
  15852. };
  15853. function BitmapIndexedNode(ownerID, bitmap, nodes) {
  15854. this.ownerID = ownerID;
  15855. this.bitmap = bitmap;
  15856. this.nodes = nodes;
  15857. }
  15858. BitmapIndexedNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  15859. if (keyHash === undefined) {
  15860. keyHash = hash(key);
  15861. }
  15862. var bit = (1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK));
  15863. var bitmap = this.bitmap;
  15864. return (bitmap & bit) === 0 ? notSetValue :
  15865. this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue);
  15866. };
  15867. BitmapIndexedNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  15868. if (keyHash === undefined) {
  15869. keyHash = hash(key);
  15870. }
  15871. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  15872. var bit = 1 << keyHashFrag;
  15873. var bitmap = this.bitmap;
  15874. var exists = (bitmap & bit) !== 0;
  15875. if (!exists && value === NOT_SET) {
  15876. return this;
  15877. }
  15878. var idx = popCount(bitmap & (bit - 1));
  15879. var nodes = this.nodes;
  15880. var node = exists ? nodes[idx] : undefined;
  15881. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  15882. if (newNode === node) {
  15883. return this;
  15884. }
  15885. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  15886. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  15887. }
  15888. if (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) {
  15889. return nodes[idx ^ 1];
  15890. }
  15891. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  15892. return newNode;
  15893. }
  15894. var isEditable = ownerID && ownerID === this.ownerID;
  15895. var newBitmap = exists ? newNode ? bitmap : bitmap ^ bit : bitmap | bit;
  15896. var newNodes = exists ? newNode ?
  15897. setIn(nodes, idx, newNode, isEditable) :
  15898. spliceOut(nodes, idx, isEditable) :
  15899. spliceIn(nodes, idx, newNode, isEditable);
  15900. if (isEditable) {
  15901. this.bitmap = newBitmap;
  15902. this.nodes = newNodes;
  15903. return this;
  15904. }
  15905. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  15906. };
  15907. function HashArrayMapNode(ownerID, count, nodes) {
  15908. this.ownerID = ownerID;
  15909. this.count = count;
  15910. this.nodes = nodes;
  15911. }
  15912. HashArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  15913. if (keyHash === undefined) {
  15914. keyHash = hash(key);
  15915. }
  15916. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  15917. var node = this.nodes[idx];
  15918. return node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue;
  15919. };
  15920. HashArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  15921. if (keyHash === undefined) {
  15922. keyHash = hash(key);
  15923. }
  15924. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  15925. var removed = value === NOT_SET;
  15926. var nodes = this.nodes;
  15927. var node = nodes[idx];
  15928. if (removed && !node) {
  15929. return this;
  15930. }
  15931. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  15932. if (newNode === node) {
  15933. return this;
  15934. }
  15935. var newCount = this.count;
  15936. if (!node) {
  15937. newCount++;
  15938. } else if (!newNode) {
  15939. newCount--;
  15940. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  15941. return packNodes(ownerID, nodes, newCount, idx);
  15942. }
  15943. }
  15944. var isEditable = ownerID && ownerID === this.ownerID;
  15945. var newNodes = setIn(nodes, idx, newNode, isEditable);
  15946. if (isEditable) {
  15947. this.count = newCount;
  15948. this.nodes = newNodes;
  15949. return this;
  15950. }
  15951. return new HashArrayMapNode(ownerID, newCount, newNodes);
  15952. };
  15953. function HashCollisionNode(ownerID, keyHash, entries) {
  15954. this.ownerID = ownerID;
  15955. this.keyHash = keyHash;
  15956. this.entries = entries;
  15957. }
  15958. HashCollisionNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  15959. var entries = this.entries;
  15960. for (var ii = 0, len = entries.length; ii < len; ii++) {
  15961. if (is(key, entries[ii][0])) {
  15962. return entries[ii][1];
  15963. }
  15964. }
  15965. return notSetValue;
  15966. };
  15967. HashCollisionNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  15968. if (keyHash === undefined) {
  15969. keyHash = hash(key);
  15970. }
  15971. var removed = value === NOT_SET;
  15972. if (keyHash !== this.keyHash) {
  15973. if (removed) {
  15974. return this;
  15975. }
  15976. SetRef(didAlter);
  15977. SetRef(didChangeSize);
  15978. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  15979. }
  15980. var entries = this.entries;
  15981. var idx = 0;
  15982. for (var len = entries.length; idx < len; idx++) {
  15983. if (is(key, entries[idx][0])) {
  15984. break;
  15985. }
  15986. }
  15987. var exists = idx < len;
  15988. if (exists ? entries[idx][1] === value : removed) {
  15989. return this;
  15990. }
  15991. SetRef(didAlter);
  15992. (removed || !exists) && SetRef(didChangeSize);
  15993. if (removed && len === 2) {
  15994. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  15995. }
  15996. var isEditable = ownerID && ownerID === this.ownerID;
  15997. var newEntries = isEditable ? entries : arrCopy(entries);
  15998. if (exists) {
  15999. if (removed) {
  16000. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  16001. } else {
  16002. newEntries[idx] = [key, value];
  16003. }
  16004. } else {
  16005. newEntries.push([key, value]);
  16006. }
  16007. if (isEditable) {
  16008. this.entries = newEntries;
  16009. return this;
  16010. }
  16011. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  16012. };
  16013. function ValueNode(ownerID, keyHash, entry) {
  16014. this.ownerID = ownerID;
  16015. this.keyHash = keyHash;
  16016. this.entry = entry;
  16017. }
  16018. ValueNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  16019. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  16020. };
  16021. ValueNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  16022. var removed = value === NOT_SET;
  16023. var keyMatch = is(key, this.entry[0]);
  16024. if (keyMatch ? value === this.entry[1] : removed) {
  16025. return this;
  16026. }
  16027. SetRef(didAlter);
  16028. if (removed) {
  16029. SetRef(didChangeSize);
  16030. return; // undefined
  16031. }
  16032. if (keyMatch) {
  16033. if (ownerID && ownerID === this.ownerID) {
  16034. this.entry[1] = value;
  16035. return this;
  16036. }
  16037. return new ValueNode(ownerID, this.keyHash, [key, value]);
  16038. }
  16039. SetRef(didChangeSize);
  16040. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  16041. };
  16042. // #pragma Iterators
  16043. ArrayMapNode.prototype.iterate =
  16044. HashCollisionNode.prototype.iterate = function (fn, reverse) {
  16045. var entries = this.entries;
  16046. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  16047. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  16048. return false;
  16049. }
  16050. }
  16051. };
  16052. BitmapIndexedNode.prototype.iterate =
  16053. HashArrayMapNode.prototype.iterate = function (fn, reverse) {
  16054. var nodes = this.nodes;
  16055. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  16056. var node = nodes[reverse ? maxIndex - ii : ii];
  16057. if (node && node.iterate(fn, reverse) === false) {
  16058. return false;
  16059. }
  16060. }
  16061. };
  16062. ValueNode.prototype.iterate = function (fn, reverse) {
  16063. return fn(this.entry);
  16064. };
  16065. createClass(MapIterator, Iterator);
  16066. function MapIterator(map, type, reverse) {
  16067. this._type = type;
  16068. this._reverse = reverse;
  16069. this._stack = map._root && mapIteratorFrame(map._root);
  16070. }
  16071. MapIterator.prototype.next = function() {
  16072. var type = this._type;
  16073. var stack = this._stack;
  16074. while (stack) {
  16075. var node = stack.node;
  16076. var index = stack.index++;
  16077. var maxIndex;
  16078. if (node.entry) {
  16079. if (index === 0) {
  16080. return mapIteratorValue(type, node.entry);
  16081. }
  16082. } else if (node.entries) {
  16083. maxIndex = node.entries.length - 1;
  16084. if (index <= maxIndex) {
  16085. return mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index]);
  16086. }
  16087. } else {
  16088. maxIndex = node.nodes.length - 1;
  16089. if (index <= maxIndex) {
  16090. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  16091. if (subNode) {
  16092. if (subNode.entry) {
  16093. return mapIteratorValue(type, subNode.entry);
  16094. }
  16095. stack = this._stack = mapIteratorFrame(subNode, stack);
  16096. }
  16097. continue;
  16098. }
  16099. }
  16100. stack = this._stack = this._stack.__prev;
  16101. }
  16102. return iteratorDone();
  16103. };
  16104. function mapIteratorValue(type, entry) {
  16105. return iteratorValue(type, entry[0], entry[1]);
  16106. }
  16107. function mapIteratorFrame(node, prev) {
  16108. return {
  16109. node: node,
  16110. index: 0,
  16111. __prev: prev
  16112. };
  16113. }
  16114. function makeMap(size, root, ownerID, hash) {
  16115. var map = Object.create(MapPrototype);
  16116. map.size = size;
  16117. map._root = root;
  16118. map.__ownerID = ownerID;
  16119. map.__hash = hash;
  16120. map.__altered = false;
  16121. return map;
  16122. }
  16123. var EMPTY_MAP;
  16124. function emptyMap() {
  16125. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  16126. }
  16127. function updateMap(map, k, v) {
  16128. var newRoot;
  16129. var newSize;
  16130. if (!map._root) {
  16131. if (v === NOT_SET) {
  16132. return map;
  16133. }
  16134. newSize = 1;
  16135. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  16136. } else {
  16137. var didChangeSize = MakeRef(CHANGE_LENGTH);
  16138. var didAlter = MakeRef(DID_ALTER);
  16139. newRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter);
  16140. if (!didAlter.value) {
  16141. return map;
  16142. }
  16143. newSize = map.size + (didChangeSize.value ? v === NOT_SET ? -1 : 1 : 0);
  16144. }
  16145. if (map.__ownerID) {
  16146. map.size = newSize;
  16147. map._root = newRoot;
  16148. map.__hash = undefined;
  16149. map.__altered = true;
  16150. return map;
  16151. }
  16152. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  16153. }
  16154. function updateNode(node, ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  16155. if (!node) {
  16156. if (value === NOT_SET) {
  16157. return node;
  16158. }
  16159. SetRef(didAlter);
  16160. SetRef(didChangeSize);
  16161. return new ValueNode(ownerID, keyHash, [key, value]);
  16162. }
  16163. return node.update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter);
  16164. }
  16165. function isLeafNode(node) {
  16166. return node.constructor === ValueNode || node.constructor === HashCollisionNode;
  16167. }
  16168. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  16169. if (node.keyHash === keyHash) {
  16170. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  16171. }
  16172. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  16173. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  16174. var newNode;
  16175. var nodes = idx1 === idx2 ?
  16176. [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)] :
  16177. ((newNode = new ValueNode(ownerID, keyHash, entry)), idx1 < idx2 ? [node, newNode] : [newNode, node]);
  16178. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  16179. }
  16180. function createNodes(ownerID, entries, key, value) {
  16181. if (!ownerID) {
  16182. ownerID = new OwnerID();
  16183. }
  16184. var node = new ValueNode(ownerID, hash(key), [key, value]);
  16185. for (var ii = 0; ii < entries.length; ii++) {
  16186. var entry = entries[ii];
  16187. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  16188. }
  16189. return node;
  16190. }
  16191. function packNodes(ownerID, nodes, count, excluding) {
  16192. var bitmap = 0;
  16193. var packedII = 0;
  16194. var packedNodes = new Array(count);
  16195. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  16196. var node = nodes[ii];
  16197. if (node !== undefined && ii !== excluding) {
  16198. bitmap |= bit;
  16199. packedNodes[packedII++] = node;
  16200. }
  16201. }
  16202. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  16203. }
  16204. function expandNodes(ownerID, nodes, bitmap, including, node) {
  16205. var count = 0;
  16206. var expandedNodes = new Array(SIZE);
  16207. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  16208. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  16209. }
  16210. expandedNodes[including] = node;
  16211. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  16212. }
  16213. function mergeIntoMapWith(map, merger, iterables) {
  16214. var iters = [];
  16215. for (var ii = 0; ii < iterables.length; ii++) {
  16216. var value = iterables[ii];
  16217. var iter = KeyedIterable(value);
  16218. if (!isIterable(value)) {
  16219. iter = iter.map(function(v ) {return fromJS(v)});
  16220. }
  16221. iters.push(iter);
  16222. }
  16223. return mergeIntoCollectionWith(map, merger, iters);
  16224. }
  16225. function deepMerger(existing, value, key) {
  16226. return existing && existing.mergeDeep && isIterable(value) ?
  16227. existing.mergeDeep(value) :
  16228. is(existing, value) ? existing : value;
  16229. }
  16230. function deepMergerWith(merger) {
  16231. return function(existing, value, key) {
  16232. if (existing && existing.mergeDeepWith && isIterable(value)) {
  16233. return existing.mergeDeepWith(merger, value);
  16234. }
  16235. var nextValue = merger(existing, value, key);
  16236. return is(existing, nextValue) ? existing : nextValue;
  16237. };
  16238. }
  16239. function mergeIntoCollectionWith(collection, merger, iters) {
  16240. iters = iters.filter(function(x ) {return x.size !== 0});
  16241. if (iters.length === 0) {
  16242. return collection;
  16243. }
  16244. if (collection.size === 0 && !collection.__ownerID && iters.length === 1) {
  16245. return collection.constructor(iters[0]);
  16246. }
  16247. return collection.withMutations(function(collection ) {
  16248. var mergeIntoMap = merger ?
  16249. function(value, key) {
  16250. collection.update(key, NOT_SET, function(existing )
  16251. {return existing === NOT_SET ? value : merger(existing, value, key)}
  16252. );
  16253. } :
  16254. function(value, key) {
  16255. collection.set(key, value);
  16256. };
  16257. for (var ii = 0; ii < iters.length; ii++) {
  16258. iters[ii].forEach(mergeIntoMap);
  16259. }
  16260. });
  16261. }
  16262. function updateInDeepMap(existing, keyPathIter, notSetValue, updater) {
  16263. var isNotSet = existing === NOT_SET;
  16264. var step = keyPathIter.next();
  16265. if (step.done) {
  16266. var existingValue = isNotSet ? notSetValue : existing;
  16267. var newValue = updater(existingValue);
  16268. return newValue === existingValue ? existing : newValue;
  16269. }
  16270. invariant(
  16271. isNotSet || (existing && existing.set),
  16272. 'invalid keyPath'
  16273. );
  16274. var key = step.value;
  16275. var nextExisting = isNotSet ? NOT_SET : existing.get(key, NOT_SET);
  16276. var nextUpdated = updateInDeepMap(
  16277. nextExisting,
  16278. keyPathIter,
  16279. notSetValue,
  16280. updater
  16281. );
  16282. return nextUpdated === nextExisting ? existing :
  16283. nextUpdated === NOT_SET ? existing.remove(key) :
  16284. (isNotSet ? emptyMap() : existing).set(key, nextUpdated);
  16285. }
  16286. function popCount(x) {
  16287. x = x - ((x >> 1) & 0x55555555);
  16288. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  16289. x = (x + (x >> 4)) & 0x0f0f0f0f;
  16290. x = x + (x >> 8);
  16291. x = x + (x >> 16);
  16292. return x & 0x7f;
  16293. }
  16294. function setIn(array, idx, val, canEdit) {
  16295. var newArray = canEdit ? array : arrCopy(array);
  16296. newArray[idx] = val;
  16297. return newArray;
  16298. }
  16299. function spliceIn(array, idx, val, canEdit) {
  16300. var newLen = array.length + 1;
  16301. if (canEdit && idx + 1 === newLen) {
  16302. array[idx] = val;
  16303. return array;
  16304. }
  16305. var newArray = new Array(newLen);
  16306. var after = 0;
  16307. for (var ii = 0; ii < newLen; ii++) {
  16308. if (ii === idx) {
  16309. newArray[ii] = val;
  16310. after = -1;
  16311. } else {
  16312. newArray[ii] = array[ii + after];
  16313. }
  16314. }
  16315. return newArray;
  16316. }
  16317. function spliceOut(array, idx, canEdit) {
  16318. var newLen = array.length - 1;
  16319. if (canEdit && idx === newLen) {
  16320. array.pop();
  16321. return array;
  16322. }
  16323. var newArray = new Array(newLen);
  16324. var after = 0;
  16325. for (var ii = 0; ii < newLen; ii++) {
  16326. if (ii === idx) {
  16327. after = 1;
  16328. }
  16329. newArray[ii] = array[ii + after];
  16330. }
  16331. return newArray;
  16332. }
  16333. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  16334. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  16335. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  16336. createClass(List, IndexedCollection);
  16337. // @pragma Construction
  16338. function List(value) {
  16339. var empty = emptyList();
  16340. if (value === null || value === undefined) {
  16341. return empty;
  16342. }
  16343. if (isList(value)) {
  16344. return value;
  16345. }
  16346. var iter = IndexedIterable(value);
  16347. var size = iter.size;
  16348. if (size === 0) {
  16349. return empty;
  16350. }
  16351. assertNotInfinite(size);
  16352. if (size > 0 && size < SIZE) {
  16353. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  16354. }
  16355. return empty.withMutations(function(list ) {
  16356. list.setSize(size);
  16357. iter.forEach(function(v, i) {return list.set(i, v)});
  16358. });
  16359. }
  16360. List.of = function(/*...values*/) {
  16361. return this(arguments);
  16362. };
  16363. List.prototype.toString = function() {
  16364. return this.__toString('List [', ']');
  16365. };
  16366. // @pragma Access
  16367. List.prototype.get = function(index, notSetValue) {
  16368. index = wrapIndex(this, index);
  16369. if (index >= 0 && index < this.size) {
  16370. index += this._origin;
  16371. var node = listNodeFor(this, index);
  16372. return node && node.array[index & MASK];
  16373. }
  16374. return notSetValue;
  16375. };
  16376. // @pragma Modification
  16377. List.prototype.set = function(index, value) {
  16378. return updateList(this, index, value);
  16379. };
  16380. List.prototype.remove = function(index) {
  16381. return !this.has(index) ? this :
  16382. index === 0 ? this.shift() :
  16383. index === this.size - 1 ? this.pop() :
  16384. this.splice(index, 1);
  16385. };
  16386. List.prototype.insert = function(index, value) {
  16387. return this.splice(index, 0, value);
  16388. };
  16389. List.prototype.clear = function() {
  16390. if (this.size === 0) {
  16391. return this;
  16392. }
  16393. if (this.__ownerID) {
  16394. this.size = this._origin = this._capacity = 0;
  16395. this._level = SHIFT;
  16396. this._root = this._tail = null;
  16397. this.__hash = undefined;
  16398. this.__altered = true;
  16399. return this;
  16400. }
  16401. return emptyList();
  16402. };
  16403. List.prototype.push = function(/*...values*/) {
  16404. var values = arguments;
  16405. var oldSize = this.size;
  16406. return this.withMutations(function(list ) {
  16407. setListBounds(list, 0, oldSize + values.length);
  16408. for (var ii = 0; ii < values.length; ii++) {
  16409. list.set(oldSize + ii, values[ii]);
  16410. }
  16411. });
  16412. };
  16413. List.prototype.pop = function() {
  16414. return setListBounds(this, 0, -1);
  16415. };
  16416. List.prototype.unshift = function(/*...values*/) {
  16417. var values = arguments;
  16418. return this.withMutations(function(list ) {
  16419. setListBounds(list, -values.length);
  16420. for (var ii = 0; ii < values.length; ii++) {
  16421. list.set(ii, values[ii]);
  16422. }
  16423. });
  16424. };
  16425. List.prototype.shift = function() {
  16426. return setListBounds(this, 1);
  16427. };
  16428. // @pragma Composition
  16429. List.prototype.merge = function(/*...iters*/) {
  16430. return mergeIntoListWith(this, undefined, arguments);
  16431. };
  16432. List.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  16433. return mergeIntoListWith(this, merger, iters);
  16434. };
  16435. List.prototype.mergeDeep = function(/*...iters*/) {
  16436. return mergeIntoListWith(this, deepMerger, arguments);
  16437. };
  16438. List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  16439. return mergeIntoListWith(this, deepMergerWith(merger), iters);
  16440. };
  16441. List.prototype.setSize = function(size) {
  16442. return setListBounds(this, 0, size);
  16443. };
  16444. // @pragma Iteration
  16445. List.prototype.slice = function(begin, end) {
  16446. var size = this.size;
  16447. if (wholeSlice(begin, end, size)) {
  16448. return this;
  16449. }
  16450. return setListBounds(
  16451. this,
  16452. resolveBegin(begin, size),
  16453. resolveEnd(end, size)
  16454. );
  16455. };
  16456. List.prototype.__iterator = function(type, reverse) {
  16457. var index = 0;
  16458. var values = iterateList(this, reverse);
  16459. return new Iterator(function() {
  16460. var value = values();
  16461. return value === DONE ?
  16462. iteratorDone() :
  16463. iteratorValue(type, index++, value);
  16464. });
  16465. };
  16466. List.prototype.__iterate = function(fn, reverse) {
  16467. var index = 0;
  16468. var values = iterateList(this, reverse);
  16469. var value;
  16470. while ((value = values()) !== DONE) {
  16471. if (fn(value, index++, this) === false) {
  16472. break;
  16473. }
  16474. }
  16475. return index;
  16476. };
  16477. List.prototype.__ensureOwner = function(ownerID) {
  16478. if (ownerID === this.__ownerID) {
  16479. return this;
  16480. }
  16481. if (!ownerID) {
  16482. this.__ownerID = ownerID;
  16483. return this;
  16484. }
  16485. return makeList(this._origin, this._capacity, this._level, this._root, this._tail, ownerID, this.__hash);
  16486. };
  16487. function isList(maybeList) {
  16488. return !!(maybeList && maybeList[IS_LIST_SENTINEL]);
  16489. }
  16490. List.isList = isList;
  16491. var IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
  16492. var ListPrototype = List.prototype;
  16493. ListPrototype[IS_LIST_SENTINEL] = true;
  16494. ListPrototype[DELETE] = ListPrototype.remove;
  16495. ListPrototype.setIn = MapPrototype.setIn;
  16496. ListPrototype.deleteIn =
  16497. ListPrototype.removeIn = MapPrototype.removeIn;
  16498. ListPrototype.update = MapPrototype.update;
  16499. ListPrototype.updateIn = MapPrototype.updateIn;
  16500. ListPrototype.mergeIn = MapPrototype.mergeIn;
  16501. ListPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  16502. ListPrototype.withMutations = MapPrototype.withMutations;
  16503. ListPrototype.asMutable = MapPrototype.asMutable;
  16504. ListPrototype.asImmutable = MapPrototype.asImmutable;
  16505. ListPrototype.wasAltered = MapPrototype.wasAltered;
  16506. function VNode(array, ownerID) {
  16507. this.array = array;
  16508. this.ownerID = ownerID;
  16509. }
  16510. // TODO: seems like these methods are very similar
  16511. VNode.prototype.removeBefore = function(ownerID, level, index) {
  16512. if (index === level ? 1 << level : this.array.length === 0) {
  16513. return this;
  16514. }
  16515. var originIndex = (index >>> level) & MASK;
  16516. if (originIndex >= this.array.length) {
  16517. return new VNode([], ownerID);
  16518. }
  16519. var removingFirst = originIndex === 0;
  16520. var newChild;
  16521. if (level > 0) {
  16522. var oldChild = this.array[originIndex];
  16523. newChild = oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  16524. if (newChild === oldChild && removingFirst) {
  16525. return this;
  16526. }
  16527. }
  16528. if (removingFirst && !newChild) {
  16529. return this;
  16530. }
  16531. var editable = editableVNode(this, ownerID);
  16532. if (!removingFirst) {
  16533. for (var ii = 0; ii < originIndex; ii++) {
  16534. editable.array[ii] = undefined;
  16535. }
  16536. }
  16537. if (newChild) {
  16538. editable.array[originIndex] = newChild;
  16539. }
  16540. return editable;
  16541. };
  16542. VNode.prototype.removeAfter = function(ownerID, level, index) {
  16543. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  16544. return this;
  16545. }
  16546. var sizeIndex = ((index - 1) >>> level) & MASK;
  16547. if (sizeIndex >= this.array.length) {
  16548. return this;
  16549. }
  16550. var newChild;
  16551. if (level > 0) {
  16552. var oldChild = this.array[sizeIndex];
  16553. newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  16554. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  16555. return this;
  16556. }
  16557. }
  16558. var editable = editableVNode(this, ownerID);
  16559. editable.array.splice(sizeIndex + 1);
  16560. if (newChild) {
  16561. editable.array[sizeIndex] = newChild;
  16562. }
  16563. return editable;
  16564. };
  16565. var DONE = {};
  16566. function iterateList(list, reverse) {
  16567. var left = list._origin;
  16568. var right = list._capacity;
  16569. var tailPos = getTailOffset(right);
  16570. var tail = list._tail;
  16571. return iterateNodeOrLeaf(list._root, list._level, 0);
  16572. function iterateNodeOrLeaf(node, level, offset) {
  16573. return level === 0 ?
  16574. iterateLeaf(node, offset) :
  16575. iterateNode(node, level, offset);
  16576. }
  16577. function iterateLeaf(node, offset) {
  16578. var array = offset === tailPos ? tail && tail.array : node && node.array;
  16579. var from = offset > left ? 0 : left - offset;
  16580. var to = right - offset;
  16581. if (to > SIZE) {
  16582. to = SIZE;
  16583. }
  16584. return function() {
  16585. if (from === to) {
  16586. return DONE;
  16587. }
  16588. var idx = reverse ? --to : from++;
  16589. return array && array[idx];
  16590. };
  16591. }
  16592. function iterateNode(node, level, offset) {
  16593. var values;
  16594. var array = node && node.array;
  16595. var from = offset > left ? 0 : (left - offset) >> level;
  16596. var to = ((right - offset) >> level) + 1;
  16597. if (to > SIZE) {
  16598. to = SIZE;
  16599. }
  16600. return function() {
  16601. do {
  16602. if (values) {
  16603. var value = values();
  16604. if (value !== DONE) {
  16605. return value;
  16606. }
  16607. values = null;
  16608. }
  16609. if (from === to) {
  16610. return DONE;
  16611. }
  16612. var idx = reverse ? --to : from++;
  16613. values = iterateNodeOrLeaf(
  16614. array && array[idx], level - SHIFT, offset + (idx << level)
  16615. );
  16616. } while (true);
  16617. };
  16618. }
  16619. }
  16620. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  16621. var list = Object.create(ListPrototype);
  16622. list.size = capacity - origin;
  16623. list._origin = origin;
  16624. list._capacity = capacity;
  16625. list._level = level;
  16626. list._root = root;
  16627. list._tail = tail;
  16628. list.__ownerID = ownerID;
  16629. list.__hash = hash;
  16630. list.__altered = false;
  16631. return list;
  16632. }
  16633. var EMPTY_LIST;
  16634. function emptyList() {
  16635. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  16636. }
  16637. function updateList(list, index, value) {
  16638. index = wrapIndex(list, index);
  16639. if (index !== index) {
  16640. return list;
  16641. }
  16642. if (index >= list.size || index < 0) {
  16643. return list.withMutations(function(list ) {
  16644. index < 0 ?
  16645. setListBounds(list, index).set(0, value) :
  16646. setListBounds(list, 0, index + 1).set(index, value);
  16647. });
  16648. }
  16649. index += list._origin;
  16650. var newTail = list._tail;
  16651. var newRoot = list._root;
  16652. var didAlter = MakeRef(DID_ALTER);
  16653. if (index >= getTailOffset(list._capacity)) {
  16654. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  16655. } else {
  16656. newRoot = updateVNode(newRoot, list.__ownerID, list._level, index, value, didAlter);
  16657. }
  16658. if (!didAlter.value) {
  16659. return list;
  16660. }
  16661. if (list.__ownerID) {
  16662. list._root = newRoot;
  16663. list._tail = newTail;
  16664. list.__hash = undefined;
  16665. list.__altered = true;
  16666. return list;
  16667. }
  16668. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  16669. }
  16670. function updateVNode(node, ownerID, level, index, value, didAlter) {
  16671. var idx = (index >>> level) & MASK;
  16672. var nodeHas = node && idx < node.array.length;
  16673. if (!nodeHas && value === undefined) {
  16674. return node;
  16675. }
  16676. var newNode;
  16677. if (level > 0) {
  16678. var lowerNode = node && node.array[idx];
  16679. var newLowerNode = updateVNode(lowerNode, ownerID, level - SHIFT, index, value, didAlter);
  16680. if (newLowerNode === lowerNode) {
  16681. return node;
  16682. }
  16683. newNode = editableVNode(node, ownerID);
  16684. newNode.array[idx] = newLowerNode;
  16685. return newNode;
  16686. }
  16687. if (nodeHas && node.array[idx] === value) {
  16688. return node;
  16689. }
  16690. SetRef(didAlter);
  16691. newNode = editableVNode(node, ownerID);
  16692. if (value === undefined && idx === newNode.array.length - 1) {
  16693. newNode.array.pop();
  16694. } else {
  16695. newNode.array[idx] = value;
  16696. }
  16697. return newNode;
  16698. }
  16699. function editableVNode(node, ownerID) {
  16700. if (ownerID && node && ownerID === node.ownerID) {
  16701. return node;
  16702. }
  16703. return new VNode(node ? node.array.slice() : [], ownerID);
  16704. }
  16705. function listNodeFor(list, rawIndex) {
  16706. if (rawIndex >= getTailOffset(list._capacity)) {
  16707. return list._tail;
  16708. }
  16709. if (rawIndex < 1 << (list._level + SHIFT)) {
  16710. var node = list._root;
  16711. var level = list._level;
  16712. while (node && level > 0) {
  16713. node = node.array[(rawIndex >>> level) & MASK];
  16714. level -= SHIFT;
  16715. }
  16716. return node;
  16717. }
  16718. }
  16719. function setListBounds(list, begin, end) {
  16720. // Sanitize begin & end using this shorthand for ToInt32(argument)
  16721. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  16722. if (begin !== undefined) {
  16723. begin = begin | 0;
  16724. }
  16725. if (end !== undefined) {
  16726. end = end | 0;
  16727. }
  16728. var owner = list.__ownerID || new OwnerID();
  16729. var oldOrigin = list._origin;
  16730. var oldCapacity = list._capacity;
  16731. var newOrigin = oldOrigin + begin;
  16732. var newCapacity = end === undefined ? oldCapacity : end < 0 ? oldCapacity + end : oldOrigin + end;
  16733. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  16734. return list;
  16735. }
  16736. // If it's going to end after it starts, it's empty.
  16737. if (newOrigin >= newCapacity) {
  16738. return list.clear();
  16739. }
  16740. var newLevel = list._level;
  16741. var newRoot = list._root;
  16742. // New origin might need creating a higher root.
  16743. var offsetShift = 0;
  16744. while (newOrigin + offsetShift < 0) {
  16745. newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner);
  16746. newLevel += SHIFT;
  16747. offsetShift += 1 << newLevel;
  16748. }
  16749. if (offsetShift) {
  16750. newOrigin += offsetShift;
  16751. oldOrigin += offsetShift;
  16752. newCapacity += offsetShift;
  16753. oldCapacity += offsetShift;
  16754. }
  16755. var oldTailOffset = getTailOffset(oldCapacity);
  16756. var newTailOffset = getTailOffset(newCapacity);
  16757. // New size might need creating a higher root.
  16758. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  16759. newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner);
  16760. newLevel += SHIFT;
  16761. }
  16762. // Locate or create the new tail.
  16763. var oldTail = list._tail;
  16764. var newTail = newTailOffset < oldTailOffset ?
  16765. listNodeFor(list, newCapacity - 1) :
  16766. newTailOffset > oldTailOffset ? new VNode([], owner) : oldTail;
  16767. // Merge Tail into tree.
  16768. if (oldTail && newTailOffset > oldTailOffset && newOrigin < oldCapacity && oldTail.array.length) {
  16769. newRoot = editableVNode(newRoot, owner);
  16770. var node = newRoot;
  16771. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  16772. var idx = (oldTailOffset >>> level) & MASK;
  16773. node = node.array[idx] = editableVNode(node.array[idx], owner);
  16774. }
  16775. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  16776. }
  16777. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  16778. if (newCapacity < oldCapacity) {
  16779. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  16780. }
  16781. // If the new origin is within the tail, then we do not need a root.
  16782. if (newOrigin >= newTailOffset) {
  16783. newOrigin -= newTailOffset;
  16784. newCapacity -= newTailOffset;
  16785. newLevel = SHIFT;
  16786. newRoot = null;
  16787. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  16788. // Otherwise, if the root has been trimmed, garbage collect.
  16789. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  16790. offsetShift = 0;
  16791. // Identify the new top root node of the subtree of the old root.
  16792. while (newRoot) {
  16793. var beginIndex = (newOrigin >>> newLevel) & MASK;
  16794. if (beginIndex !== (newTailOffset >>> newLevel) & MASK) {
  16795. break;
  16796. }
  16797. if (beginIndex) {
  16798. offsetShift += (1 << newLevel) * beginIndex;
  16799. }
  16800. newLevel -= SHIFT;
  16801. newRoot = newRoot.array[beginIndex];
  16802. }
  16803. // Trim the new sides of the new root.
  16804. if (newRoot && newOrigin > oldOrigin) {
  16805. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  16806. }
  16807. if (newRoot && newTailOffset < oldTailOffset) {
  16808. newRoot = newRoot.removeAfter(owner, newLevel, newTailOffset - offsetShift);
  16809. }
  16810. if (offsetShift) {
  16811. newOrigin -= offsetShift;
  16812. newCapacity -= offsetShift;
  16813. }
  16814. }
  16815. if (list.__ownerID) {
  16816. list.size = newCapacity - newOrigin;
  16817. list._origin = newOrigin;
  16818. list._capacity = newCapacity;
  16819. list._level = newLevel;
  16820. list._root = newRoot;
  16821. list._tail = newTail;
  16822. list.__hash = undefined;
  16823. list.__altered = true;
  16824. return list;
  16825. }
  16826. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  16827. }
  16828. function mergeIntoListWith(list, merger, iterables) {
  16829. var iters = [];
  16830. var maxSize = 0;
  16831. for (var ii = 0; ii < iterables.length; ii++) {
  16832. var value = iterables[ii];
  16833. var iter = IndexedIterable(value);
  16834. if (iter.size > maxSize) {
  16835. maxSize = iter.size;
  16836. }
  16837. if (!isIterable(value)) {
  16838. iter = iter.map(function(v ) {return fromJS(v)});
  16839. }
  16840. iters.push(iter);
  16841. }
  16842. if (maxSize > list.size) {
  16843. list = list.setSize(maxSize);
  16844. }
  16845. return mergeIntoCollectionWith(list, merger, iters);
  16846. }
  16847. function getTailOffset(size) {
  16848. return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
  16849. }
  16850. createClass(OrderedMap, Map);
  16851. // @pragma Construction
  16852. function OrderedMap(value) {
  16853. return value === null || value === undefined ? emptyOrderedMap() :
  16854. isOrderedMap(value) ? value :
  16855. emptyOrderedMap().withMutations(function(map ) {
  16856. var iter = KeyedIterable(value);
  16857. assertNotInfinite(iter.size);
  16858. iter.forEach(function(v, k) {return map.set(k, v)});
  16859. });
  16860. }
  16861. OrderedMap.of = function(/*...values*/) {
  16862. return this(arguments);
  16863. };
  16864. OrderedMap.prototype.toString = function() {
  16865. return this.__toString('OrderedMap {', '}');
  16866. };
  16867. // @pragma Access
  16868. OrderedMap.prototype.get = function(k, notSetValue) {
  16869. var index = this._map.get(k);
  16870. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  16871. };
  16872. // @pragma Modification
  16873. OrderedMap.prototype.clear = function() {
  16874. if (this.size === 0) {
  16875. return this;
  16876. }
  16877. if (this.__ownerID) {
  16878. this.size = 0;
  16879. this._map.clear();
  16880. this._list.clear();
  16881. return this;
  16882. }
  16883. return emptyOrderedMap();
  16884. };
  16885. OrderedMap.prototype.set = function(k, v) {
  16886. return updateOrderedMap(this, k, v);
  16887. };
  16888. OrderedMap.prototype.remove = function(k) {
  16889. return updateOrderedMap(this, k, NOT_SET);
  16890. };
  16891. OrderedMap.prototype.wasAltered = function() {
  16892. return this._map.wasAltered() || this._list.wasAltered();
  16893. };
  16894. OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  16895. return this._list.__iterate(
  16896. function(entry ) {return entry && fn(entry[1], entry[0], this$0)},
  16897. reverse
  16898. );
  16899. };
  16900. OrderedMap.prototype.__iterator = function(type, reverse) {
  16901. return this._list.fromEntrySeq().__iterator(type, reverse);
  16902. };
  16903. OrderedMap.prototype.__ensureOwner = function(ownerID) {
  16904. if (ownerID === this.__ownerID) {
  16905. return this;
  16906. }
  16907. var newMap = this._map.__ensureOwner(ownerID);
  16908. var newList = this._list.__ensureOwner(ownerID);
  16909. if (!ownerID) {
  16910. this.__ownerID = ownerID;
  16911. this._map = newMap;
  16912. this._list = newList;
  16913. return this;
  16914. }
  16915. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  16916. };
  16917. function isOrderedMap(maybeOrderedMap) {
  16918. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  16919. }
  16920. OrderedMap.isOrderedMap = isOrderedMap;
  16921. OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
  16922. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  16923. function makeOrderedMap(map, list, ownerID, hash) {
  16924. var omap = Object.create(OrderedMap.prototype);
  16925. omap.size = map ? map.size : 0;
  16926. omap._map = map;
  16927. omap._list = list;
  16928. omap.__ownerID = ownerID;
  16929. omap.__hash = hash;
  16930. return omap;
  16931. }
  16932. var EMPTY_ORDERED_MAP;
  16933. function emptyOrderedMap() {
  16934. return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()));
  16935. }
  16936. function updateOrderedMap(omap, k, v) {
  16937. var map = omap._map;
  16938. var list = omap._list;
  16939. var i = map.get(k);
  16940. var has = i !== undefined;
  16941. var newMap;
  16942. var newList;
  16943. if (v === NOT_SET) { // removed
  16944. if (!has) {
  16945. return omap;
  16946. }
  16947. if (list.size >= SIZE && list.size >= map.size * 2) {
  16948. newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx});
  16949. newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap();
  16950. if (omap.__ownerID) {
  16951. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  16952. }
  16953. } else {
  16954. newMap = map.remove(k);
  16955. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  16956. }
  16957. } else {
  16958. if (has) {
  16959. if (v === list.get(i)[1]) {
  16960. return omap;
  16961. }
  16962. newMap = map;
  16963. newList = list.set(i, [k, v]);
  16964. } else {
  16965. newMap = map.set(k, list.size);
  16966. newList = list.set(list.size, [k, v]);
  16967. }
  16968. }
  16969. if (omap.__ownerID) {
  16970. omap.size = newMap.size;
  16971. omap._map = newMap;
  16972. omap._list = newList;
  16973. omap.__hash = undefined;
  16974. return omap;
  16975. }
  16976. return makeOrderedMap(newMap, newList);
  16977. }
  16978. createClass(ToKeyedSequence, KeyedSeq);
  16979. function ToKeyedSequence(indexed, useKeys) {
  16980. this._iter = indexed;
  16981. this._useKeys = useKeys;
  16982. this.size = indexed.size;
  16983. }
  16984. ToKeyedSequence.prototype.get = function(key, notSetValue) {
  16985. return this._iter.get(key, notSetValue);
  16986. };
  16987. ToKeyedSequence.prototype.has = function(key) {
  16988. return this._iter.has(key);
  16989. };
  16990. ToKeyedSequence.prototype.valueSeq = function() {
  16991. return this._iter.valueSeq();
  16992. };
  16993. ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
  16994. var reversedSequence = reverseFactory(this, true);
  16995. if (!this._useKeys) {
  16996. reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
  16997. }
  16998. return reversedSequence;
  16999. };
  17000. ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
  17001. var mappedSequence = mapFactory(this, mapper, context);
  17002. if (!this._useKeys) {
  17003. mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
  17004. }
  17005. return mappedSequence;
  17006. };
  17007. ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17008. var ii;
  17009. return this._iter.__iterate(
  17010. this._useKeys ?
  17011. function(v, k) {return fn(v, k, this$0)} :
  17012. ((ii = reverse ? resolveSize(this) : 0),
  17013. function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
  17014. reverse
  17015. );
  17016. };
  17017. ToKeyedSequence.prototype.__iterator = function(type, reverse) {
  17018. if (this._useKeys) {
  17019. return this._iter.__iterator(type, reverse);
  17020. }
  17021. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  17022. var ii = reverse ? resolveSize(this) : 0;
  17023. return new Iterator(function() {
  17024. var step = iterator.next();
  17025. return step.done ? step :
  17026. iteratorValue(type, reverse ? --ii : ii++, step.value, step);
  17027. });
  17028. };
  17029. ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
  17030. createClass(ToIndexedSequence, IndexedSeq);
  17031. function ToIndexedSequence(iter) {
  17032. this._iter = iter;
  17033. this.size = iter.size;
  17034. }
  17035. ToIndexedSequence.prototype.includes = function(value) {
  17036. return this._iter.includes(value);
  17037. };
  17038. ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17039. var iterations = 0;
  17040. return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
  17041. };
  17042. ToIndexedSequence.prototype.__iterator = function(type, reverse) {
  17043. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  17044. var iterations = 0;
  17045. return new Iterator(function() {
  17046. var step = iterator.next();
  17047. return step.done ? step :
  17048. iteratorValue(type, iterations++, step.value, step)
  17049. });
  17050. };
  17051. createClass(ToSetSequence, SetSeq);
  17052. function ToSetSequence(iter) {
  17053. this._iter = iter;
  17054. this.size = iter.size;
  17055. }
  17056. ToSetSequence.prototype.has = function(key) {
  17057. return this._iter.includes(key);
  17058. };
  17059. ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17060. return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
  17061. };
  17062. ToSetSequence.prototype.__iterator = function(type, reverse) {
  17063. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  17064. return new Iterator(function() {
  17065. var step = iterator.next();
  17066. return step.done ? step :
  17067. iteratorValue(type, step.value, step.value, step);
  17068. });
  17069. };
  17070. createClass(FromEntriesSequence, KeyedSeq);
  17071. function FromEntriesSequence(entries) {
  17072. this._iter = entries;
  17073. this.size = entries.size;
  17074. }
  17075. FromEntriesSequence.prototype.entrySeq = function() {
  17076. return this._iter.toSeq();
  17077. };
  17078. FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17079. return this._iter.__iterate(function(entry ) {
  17080. // Check if entry exists first so array access doesn't throw for holes
  17081. // in the parent iteration.
  17082. if (entry) {
  17083. validateEntry(entry);
  17084. var indexedIterable = isIterable(entry);
  17085. return fn(
  17086. indexedIterable ? entry.get(1) : entry[1],
  17087. indexedIterable ? entry.get(0) : entry[0],
  17088. this$0
  17089. );
  17090. }
  17091. }, reverse);
  17092. };
  17093. FromEntriesSequence.prototype.__iterator = function(type, reverse) {
  17094. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  17095. return new Iterator(function() {
  17096. while (true) {
  17097. var step = iterator.next();
  17098. if (step.done) {
  17099. return step;
  17100. }
  17101. var entry = step.value;
  17102. // Check if entry exists first so array access doesn't throw for holes
  17103. // in the parent iteration.
  17104. if (entry) {
  17105. validateEntry(entry);
  17106. var indexedIterable = isIterable(entry);
  17107. return iteratorValue(
  17108. type,
  17109. indexedIterable ? entry.get(0) : entry[0],
  17110. indexedIterable ? entry.get(1) : entry[1],
  17111. step
  17112. );
  17113. }
  17114. }
  17115. });
  17116. };
  17117. ToIndexedSequence.prototype.cacheResult =
  17118. ToKeyedSequence.prototype.cacheResult =
  17119. ToSetSequence.prototype.cacheResult =
  17120. FromEntriesSequence.prototype.cacheResult =
  17121. cacheResultThrough;
  17122. function flipFactory(iterable) {
  17123. var flipSequence = makeSequence(iterable);
  17124. flipSequence._iter = iterable;
  17125. flipSequence.size = iterable.size;
  17126. flipSequence.flip = function() {return iterable};
  17127. flipSequence.reverse = function () {
  17128. var reversedSequence = iterable.reverse.apply(this); // super.reverse()
  17129. reversedSequence.flip = function() {return iterable.reverse()};
  17130. return reversedSequence;
  17131. };
  17132. flipSequence.has = function(key ) {return iterable.includes(key)};
  17133. flipSequence.includes = function(key ) {return iterable.has(key)};
  17134. flipSequence.cacheResult = cacheResultThrough;
  17135. flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  17136. return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
  17137. };
  17138. flipSequence.__iteratorUncached = function(type, reverse) {
  17139. if (type === ITERATE_ENTRIES) {
  17140. var iterator = iterable.__iterator(type, reverse);
  17141. return new Iterator(function() {
  17142. var step = iterator.next();
  17143. if (!step.done) {
  17144. var k = step.value[0];
  17145. step.value[0] = step.value[1];
  17146. step.value[1] = k;
  17147. }
  17148. return step;
  17149. });
  17150. }
  17151. return iterable.__iterator(
  17152. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  17153. reverse
  17154. );
  17155. };
  17156. return flipSequence;
  17157. }
  17158. function mapFactory(iterable, mapper, context) {
  17159. var mappedSequence = makeSequence(iterable);
  17160. mappedSequence.size = iterable.size;
  17161. mappedSequence.has = function(key ) {return iterable.has(key)};
  17162. mappedSequence.get = function(key, notSetValue) {
  17163. var v = iterable.get(key, NOT_SET);
  17164. return v === NOT_SET ?
  17165. notSetValue :
  17166. mapper.call(context, v, key, iterable);
  17167. };
  17168. mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  17169. return iterable.__iterate(
  17170. function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
  17171. reverse
  17172. );
  17173. };
  17174. mappedSequence.__iteratorUncached = function (type, reverse) {
  17175. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  17176. return new Iterator(function() {
  17177. var step = iterator.next();
  17178. if (step.done) {
  17179. return step;
  17180. }
  17181. var entry = step.value;
  17182. var key = entry[0];
  17183. return iteratorValue(
  17184. type,
  17185. key,
  17186. mapper.call(context, entry[1], key, iterable),
  17187. step
  17188. );
  17189. });
  17190. };
  17191. return mappedSequence;
  17192. }
  17193. function reverseFactory(iterable, useKeys) {
  17194. var reversedSequence = makeSequence(iterable);
  17195. reversedSequence._iter = iterable;
  17196. reversedSequence.size = iterable.size;
  17197. reversedSequence.reverse = function() {return iterable};
  17198. if (iterable.flip) {
  17199. reversedSequence.flip = function () {
  17200. var flipSequence = flipFactory(iterable);
  17201. flipSequence.reverse = function() {return iterable.flip()};
  17202. return flipSequence;
  17203. };
  17204. }
  17205. reversedSequence.get = function(key, notSetValue)
  17206. {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
  17207. reversedSequence.has = function(key )
  17208. {return iterable.has(useKeys ? key : -1 - key)};
  17209. reversedSequence.includes = function(value ) {return iterable.includes(value)};
  17210. reversedSequence.cacheResult = cacheResultThrough;
  17211. reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
  17212. return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
  17213. };
  17214. reversedSequence.__iterator =
  17215. function(type, reverse) {return iterable.__iterator(type, !reverse)};
  17216. return reversedSequence;
  17217. }
  17218. function filterFactory(iterable, predicate, context, useKeys) {
  17219. var filterSequence = makeSequence(iterable);
  17220. if (useKeys) {
  17221. filterSequence.has = function(key ) {
  17222. var v = iterable.get(key, NOT_SET);
  17223. return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
  17224. };
  17225. filterSequence.get = function(key, notSetValue) {
  17226. var v = iterable.get(key, NOT_SET);
  17227. return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
  17228. v : notSetValue;
  17229. };
  17230. }
  17231. filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  17232. var iterations = 0;
  17233. iterable.__iterate(function(v, k, c) {
  17234. if (predicate.call(context, v, k, c)) {
  17235. iterations++;
  17236. return fn(v, useKeys ? k : iterations - 1, this$0);
  17237. }
  17238. }, reverse);
  17239. return iterations;
  17240. };
  17241. filterSequence.__iteratorUncached = function (type, reverse) {
  17242. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  17243. var iterations = 0;
  17244. return new Iterator(function() {
  17245. while (true) {
  17246. var step = iterator.next();
  17247. if (step.done) {
  17248. return step;
  17249. }
  17250. var entry = step.value;
  17251. var key = entry[0];
  17252. var value = entry[1];
  17253. if (predicate.call(context, value, key, iterable)) {
  17254. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  17255. }
  17256. }
  17257. });
  17258. };
  17259. return filterSequence;
  17260. }
  17261. function countByFactory(iterable, grouper, context) {
  17262. var groups = Map().asMutable();
  17263. iterable.__iterate(function(v, k) {
  17264. groups.update(
  17265. grouper.call(context, v, k, iterable),
  17266. 0,
  17267. function(a ) {return a + 1}
  17268. );
  17269. });
  17270. return groups.asImmutable();
  17271. }
  17272. function groupByFactory(iterable, grouper, context) {
  17273. var isKeyedIter = isKeyed(iterable);
  17274. var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable();
  17275. iterable.__iterate(function(v, k) {
  17276. groups.update(
  17277. grouper.call(context, v, k, iterable),
  17278. function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
  17279. );
  17280. });
  17281. var coerce = iterableClass(iterable);
  17282. return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
  17283. }
  17284. function sliceFactory(iterable, begin, end, useKeys) {
  17285. var originalSize = iterable.size;
  17286. // Sanitize begin & end using this shorthand for ToInt32(argument)
  17287. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  17288. if (begin !== undefined) {
  17289. begin = begin | 0;
  17290. }
  17291. if (end !== undefined) {
  17292. end = end | 0;
  17293. }
  17294. if (wholeSlice(begin, end, originalSize)) {
  17295. return iterable;
  17296. }
  17297. var resolvedBegin = resolveBegin(begin, originalSize);
  17298. var resolvedEnd = resolveEnd(end, originalSize);
  17299. // begin or end will be NaN if they were provided as negative numbers and
  17300. // this iterable's size is unknown. In that case, cache first so there is
  17301. // a known size and these do not resolve to NaN.
  17302. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  17303. return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
  17304. }
  17305. // Note: resolvedEnd is undefined when the original sequence's length is
  17306. // unknown and this slice did not supply an end and should contain all
  17307. // elements after resolvedBegin.
  17308. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  17309. var resolvedSize = resolvedEnd - resolvedBegin;
  17310. var sliceSize;
  17311. if (resolvedSize === resolvedSize) {
  17312. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  17313. }
  17314. var sliceSeq = makeSequence(iterable);
  17315. // If iterable.size is undefined, the size of the realized sliceSeq is
  17316. // unknown at this point unless the number of items to slice is 0
  17317. sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
  17318. if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
  17319. sliceSeq.get = function (index, notSetValue) {
  17320. index = wrapIndex(this, index);
  17321. return index >= 0 && index < sliceSize ?
  17322. iterable.get(index + resolvedBegin, notSetValue) :
  17323. notSetValue;
  17324. };
  17325. }
  17326. sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
  17327. if (sliceSize === 0) {
  17328. return 0;
  17329. }
  17330. if (reverse) {
  17331. return this.cacheResult().__iterate(fn, reverse);
  17332. }
  17333. var skipped = 0;
  17334. var isSkipping = true;
  17335. var iterations = 0;
  17336. iterable.__iterate(function(v, k) {
  17337. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  17338. iterations++;
  17339. return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
  17340. iterations !== sliceSize;
  17341. }
  17342. });
  17343. return iterations;
  17344. };
  17345. sliceSeq.__iteratorUncached = function(type, reverse) {
  17346. if (sliceSize !== 0 && reverse) {
  17347. return this.cacheResult().__iterator(type, reverse);
  17348. }
  17349. // Don't bother instantiating parent iterator if taking 0.
  17350. var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
  17351. var skipped = 0;
  17352. var iterations = 0;
  17353. return new Iterator(function() {
  17354. while (skipped++ < resolvedBegin) {
  17355. iterator.next();
  17356. }
  17357. if (++iterations > sliceSize) {
  17358. return iteratorDone();
  17359. }
  17360. var step = iterator.next();
  17361. if (useKeys || type === ITERATE_VALUES) {
  17362. return step;
  17363. } else if (type === ITERATE_KEYS) {
  17364. return iteratorValue(type, iterations - 1, undefined, step);
  17365. } else {
  17366. return iteratorValue(type, iterations - 1, step.value[1], step);
  17367. }
  17368. });
  17369. };
  17370. return sliceSeq;
  17371. }
  17372. function takeWhileFactory(iterable, predicate, context) {
  17373. var takeSequence = makeSequence(iterable);
  17374. takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  17375. if (reverse) {
  17376. return this.cacheResult().__iterate(fn, reverse);
  17377. }
  17378. var iterations = 0;
  17379. iterable.__iterate(function(v, k, c)
  17380. {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
  17381. );
  17382. return iterations;
  17383. };
  17384. takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  17385. if (reverse) {
  17386. return this.cacheResult().__iterator(type, reverse);
  17387. }
  17388. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  17389. var iterating = true;
  17390. return new Iterator(function() {
  17391. if (!iterating) {
  17392. return iteratorDone();
  17393. }
  17394. var step = iterator.next();
  17395. if (step.done) {
  17396. return step;
  17397. }
  17398. var entry = step.value;
  17399. var k = entry[0];
  17400. var v = entry[1];
  17401. if (!predicate.call(context, v, k, this$0)) {
  17402. iterating = false;
  17403. return iteratorDone();
  17404. }
  17405. return type === ITERATE_ENTRIES ? step :
  17406. iteratorValue(type, k, v, step);
  17407. });
  17408. };
  17409. return takeSequence;
  17410. }
  17411. function skipWhileFactory(iterable, predicate, context, useKeys) {
  17412. var skipSequence = makeSequence(iterable);
  17413. skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  17414. if (reverse) {
  17415. return this.cacheResult().__iterate(fn, reverse);
  17416. }
  17417. var isSkipping = true;
  17418. var iterations = 0;
  17419. iterable.__iterate(function(v, k, c) {
  17420. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  17421. iterations++;
  17422. return fn(v, useKeys ? k : iterations - 1, this$0);
  17423. }
  17424. });
  17425. return iterations;
  17426. };
  17427. skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  17428. if (reverse) {
  17429. return this.cacheResult().__iterator(type, reverse);
  17430. }
  17431. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  17432. var skipping = true;
  17433. var iterations = 0;
  17434. return new Iterator(function() {
  17435. var step, k, v;
  17436. do {
  17437. step = iterator.next();
  17438. if (step.done) {
  17439. if (useKeys || type === ITERATE_VALUES) {
  17440. return step;
  17441. } else if (type === ITERATE_KEYS) {
  17442. return iteratorValue(type, iterations++, undefined, step);
  17443. } else {
  17444. return iteratorValue(type, iterations++, step.value[1], step);
  17445. }
  17446. }
  17447. var entry = step.value;
  17448. k = entry[0];
  17449. v = entry[1];
  17450. skipping && (skipping = predicate.call(context, v, k, this$0));
  17451. } while (skipping);
  17452. return type === ITERATE_ENTRIES ? step :
  17453. iteratorValue(type, k, v, step);
  17454. });
  17455. };
  17456. return skipSequence;
  17457. }
  17458. function concatFactory(iterable, values) {
  17459. var isKeyedIterable = isKeyed(iterable);
  17460. var iters = [iterable].concat(values).map(function(v ) {
  17461. if (!isIterable(v)) {
  17462. v = isKeyedIterable ?
  17463. keyedSeqFromValue(v) :
  17464. indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  17465. } else if (isKeyedIterable) {
  17466. v = KeyedIterable(v);
  17467. }
  17468. return v;
  17469. }).filter(function(v ) {return v.size !== 0});
  17470. if (iters.length === 0) {
  17471. return iterable;
  17472. }
  17473. if (iters.length === 1) {
  17474. var singleton = iters[0];
  17475. if (singleton === iterable ||
  17476. isKeyedIterable && isKeyed(singleton) ||
  17477. isIndexed(iterable) && isIndexed(singleton)) {
  17478. return singleton;
  17479. }
  17480. }
  17481. var concatSeq = new ArraySeq(iters);
  17482. if (isKeyedIterable) {
  17483. concatSeq = concatSeq.toKeyedSeq();
  17484. } else if (!isIndexed(iterable)) {
  17485. concatSeq = concatSeq.toSetSeq();
  17486. }
  17487. concatSeq = concatSeq.flatten(true);
  17488. concatSeq.size = iters.reduce(
  17489. function(sum, seq) {
  17490. if (sum !== undefined) {
  17491. var size = seq.size;
  17492. if (size !== undefined) {
  17493. return sum + size;
  17494. }
  17495. }
  17496. },
  17497. 0
  17498. );
  17499. return concatSeq;
  17500. }
  17501. function flattenFactory(iterable, depth, useKeys) {
  17502. var flatSequence = makeSequence(iterable);
  17503. flatSequence.__iterateUncached = function(fn, reverse) {
  17504. var iterations = 0;
  17505. var stopped = false;
  17506. function flatDeep(iter, currentDepth) {var this$0 = this;
  17507. iter.__iterate(function(v, k) {
  17508. if ((!depth || currentDepth < depth) && isIterable(v)) {
  17509. flatDeep(v, currentDepth + 1);
  17510. } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
  17511. stopped = true;
  17512. }
  17513. return !stopped;
  17514. }, reverse);
  17515. }
  17516. flatDeep(iterable, 0);
  17517. return iterations;
  17518. };
  17519. flatSequence.__iteratorUncached = function(type, reverse) {
  17520. var iterator = iterable.__iterator(type, reverse);
  17521. var stack = [];
  17522. var iterations = 0;
  17523. return new Iterator(function() {
  17524. while (iterator) {
  17525. var step = iterator.next();
  17526. if (step.done !== false) {
  17527. iterator = stack.pop();
  17528. continue;
  17529. }
  17530. var v = step.value;
  17531. if (type === ITERATE_ENTRIES) {
  17532. v = v[1];
  17533. }
  17534. if ((!depth || stack.length < depth) && isIterable(v)) {
  17535. stack.push(iterator);
  17536. iterator = v.__iterator(type, reverse);
  17537. } else {
  17538. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  17539. }
  17540. }
  17541. return iteratorDone();
  17542. });
  17543. };
  17544. return flatSequence;
  17545. }
  17546. function flatMapFactory(iterable, mapper, context) {
  17547. var coerce = iterableClass(iterable);
  17548. return iterable.toSeq().map(
  17549. function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
  17550. ).flatten(true);
  17551. }
  17552. function interposeFactory(iterable, separator) {
  17553. var interposedSequence = makeSequence(iterable);
  17554. interposedSequence.size = iterable.size && iterable.size * 2 -1;
  17555. interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  17556. var iterations = 0;
  17557. iterable.__iterate(function(v, k)
  17558. {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
  17559. fn(v, iterations++, this$0) !== false},
  17560. reverse
  17561. );
  17562. return iterations;
  17563. };
  17564. interposedSequence.__iteratorUncached = function(type, reverse) {
  17565. var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
  17566. var iterations = 0;
  17567. var step;
  17568. return new Iterator(function() {
  17569. if (!step || iterations % 2) {
  17570. step = iterator.next();
  17571. if (step.done) {
  17572. return step;
  17573. }
  17574. }
  17575. return iterations % 2 ?
  17576. iteratorValue(type, iterations++, separator) :
  17577. iteratorValue(type, iterations++, step.value, step);
  17578. });
  17579. };
  17580. return interposedSequence;
  17581. }
  17582. function sortFactory(iterable, comparator, mapper) {
  17583. if (!comparator) {
  17584. comparator = defaultComparator;
  17585. }
  17586. var isKeyedIterable = isKeyed(iterable);
  17587. var index = 0;
  17588. var entries = iterable.toSeq().map(
  17589. function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
  17590. ).toArray();
  17591. entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
  17592. isKeyedIterable ?
  17593. function(v, i) { entries[i].length = 2; } :
  17594. function(v, i) { entries[i] = v[1]; }
  17595. );
  17596. return isKeyedIterable ? KeyedSeq(entries) :
  17597. isIndexed(iterable) ? IndexedSeq(entries) :
  17598. SetSeq(entries);
  17599. }
  17600. function maxFactory(iterable, comparator, mapper) {
  17601. if (!comparator) {
  17602. comparator = defaultComparator;
  17603. }
  17604. if (mapper) {
  17605. var entry = iterable.toSeq()
  17606. .map(function(v, k) {return [v, mapper(v, k, iterable)]})
  17607. .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
  17608. return entry && entry[0];
  17609. } else {
  17610. return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
  17611. }
  17612. }
  17613. function maxCompare(comparator, a, b) {
  17614. var comp = comparator(b, a);
  17615. // b is considered the new max if the comparator declares them equal, but
  17616. // they are not equal and b is in fact a nullish value.
  17617. return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
  17618. }
  17619. function zipWithFactory(keyIter, zipper, iters) {
  17620. var zipSequence = makeSequence(keyIter);
  17621. zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
  17622. // Note: this a generic base implementation of __iterate in terms of
  17623. // __iterator which may be more generically useful in the future.
  17624. zipSequence.__iterate = function(fn, reverse) {
  17625. /* generic:
  17626. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  17627. var step;
  17628. var iterations = 0;
  17629. while (!(step = iterator.next()).done) {
  17630. iterations++;
  17631. if (fn(step.value[1], step.value[0], this) === false) {
  17632. break;
  17633. }
  17634. }
  17635. return iterations;
  17636. */
  17637. // indexed:
  17638. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  17639. var step;
  17640. var iterations = 0;
  17641. while (!(step = iterator.next()).done) {
  17642. if (fn(step.value, iterations++, this) === false) {
  17643. break;
  17644. }
  17645. }
  17646. return iterations;
  17647. };
  17648. zipSequence.__iteratorUncached = function(type, reverse) {
  17649. var iterators = iters.map(function(i )
  17650. {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
  17651. );
  17652. var iterations = 0;
  17653. var isDone = false;
  17654. return new Iterator(function() {
  17655. var steps;
  17656. if (!isDone) {
  17657. steps = iterators.map(function(i ) {return i.next()});
  17658. isDone = steps.some(function(s ) {return s.done});
  17659. }
  17660. if (isDone) {
  17661. return iteratorDone();
  17662. }
  17663. return iteratorValue(
  17664. type,
  17665. iterations++,
  17666. zipper.apply(null, steps.map(function(s ) {return s.value}))
  17667. );
  17668. });
  17669. };
  17670. return zipSequence
  17671. }
  17672. // #pragma Helper Functions
  17673. function reify(iter, seq) {
  17674. return isSeq(iter) ? seq : iter.constructor(seq);
  17675. }
  17676. function validateEntry(entry) {
  17677. if (entry !== Object(entry)) {
  17678. throw new TypeError('Expected [K, V] tuple: ' + entry);
  17679. }
  17680. }
  17681. function resolveSize(iter) {
  17682. assertNotInfinite(iter.size);
  17683. return ensureSize(iter);
  17684. }
  17685. function iterableClass(iterable) {
  17686. return isKeyed(iterable) ? KeyedIterable :
  17687. isIndexed(iterable) ? IndexedIterable :
  17688. SetIterable;
  17689. }
  17690. function makeSequence(iterable) {
  17691. return Object.create(
  17692. (
  17693. isKeyed(iterable) ? KeyedSeq :
  17694. isIndexed(iterable) ? IndexedSeq :
  17695. SetSeq
  17696. ).prototype
  17697. );
  17698. }
  17699. function cacheResultThrough() {
  17700. if (this._iter.cacheResult) {
  17701. this._iter.cacheResult();
  17702. this.size = this._iter.size;
  17703. return this;
  17704. } else {
  17705. return Seq.prototype.cacheResult.call(this);
  17706. }
  17707. }
  17708. function defaultComparator(a, b) {
  17709. return a > b ? 1 : a < b ? -1 : 0;
  17710. }
  17711. function forceIterator(keyPath) {
  17712. var iter = getIterator(keyPath);
  17713. if (!iter) {
  17714. // Array might not be iterable in this environment, so we need a fallback
  17715. // to our wrapped type.
  17716. if (!isArrayLike(keyPath)) {
  17717. throw new TypeError('Expected iterable or array-like: ' + keyPath);
  17718. }
  17719. iter = getIterator(Iterable(keyPath));
  17720. }
  17721. return iter;
  17722. }
  17723. createClass(Record, KeyedCollection);
  17724. function Record(defaultValues, name) {
  17725. var hasInitialized;
  17726. var RecordType = function Record(values) {
  17727. if (values instanceof RecordType) {
  17728. return values;
  17729. }
  17730. if (!(this instanceof RecordType)) {
  17731. return new RecordType(values);
  17732. }
  17733. if (!hasInitialized) {
  17734. hasInitialized = true;
  17735. var keys = Object.keys(defaultValues);
  17736. setProps(RecordTypePrototype, keys);
  17737. RecordTypePrototype.size = keys.length;
  17738. RecordTypePrototype._name = name;
  17739. RecordTypePrototype._keys = keys;
  17740. RecordTypePrototype._defaultValues = defaultValues;
  17741. }
  17742. this._map = Map(values);
  17743. };
  17744. var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
  17745. RecordTypePrototype.constructor = RecordType;
  17746. return RecordType;
  17747. }
  17748. Record.prototype.toString = function() {
  17749. return this.__toString(recordName(this) + ' {', '}');
  17750. };
  17751. // @pragma Access
  17752. Record.prototype.has = function(k) {
  17753. return this._defaultValues.hasOwnProperty(k);
  17754. };
  17755. Record.prototype.get = function(k, notSetValue) {
  17756. if (!this.has(k)) {
  17757. return notSetValue;
  17758. }
  17759. var defaultVal = this._defaultValues[k];
  17760. return this._map ? this._map.get(k, defaultVal) : defaultVal;
  17761. };
  17762. // @pragma Modification
  17763. Record.prototype.clear = function() {
  17764. if (this.__ownerID) {
  17765. this._map && this._map.clear();
  17766. return this;
  17767. }
  17768. var RecordType = this.constructor;
  17769. return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap()));
  17770. };
  17771. Record.prototype.set = function(k, v) {
  17772. if (!this.has(k)) {
  17773. throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
  17774. }
  17775. var newMap = this._map && this._map.set(k, v);
  17776. if (this.__ownerID || newMap === this._map) {
  17777. return this;
  17778. }
  17779. return makeRecord(this, newMap);
  17780. };
  17781. Record.prototype.remove = function(k) {
  17782. if (!this.has(k)) {
  17783. return this;
  17784. }
  17785. var newMap = this._map && this._map.remove(k);
  17786. if (this.__ownerID || newMap === this._map) {
  17787. return this;
  17788. }
  17789. return makeRecord(this, newMap);
  17790. };
  17791. Record.prototype.wasAltered = function() {
  17792. return this._map.wasAltered();
  17793. };
  17794. Record.prototype.__iterator = function(type, reverse) {var this$0 = this;
  17795. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse);
  17796. };
  17797. Record.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17798. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse);
  17799. };
  17800. Record.prototype.__ensureOwner = function(ownerID) {
  17801. if (ownerID === this.__ownerID) {
  17802. return this;
  17803. }
  17804. var newMap = this._map && this._map.__ensureOwner(ownerID);
  17805. if (!ownerID) {
  17806. this.__ownerID = ownerID;
  17807. this._map = newMap;
  17808. return this;
  17809. }
  17810. return makeRecord(this, newMap, ownerID);
  17811. };
  17812. var RecordPrototype = Record.prototype;
  17813. RecordPrototype[DELETE] = RecordPrototype.remove;
  17814. RecordPrototype.deleteIn =
  17815. RecordPrototype.removeIn = MapPrototype.removeIn;
  17816. RecordPrototype.merge = MapPrototype.merge;
  17817. RecordPrototype.mergeWith = MapPrototype.mergeWith;
  17818. RecordPrototype.mergeIn = MapPrototype.mergeIn;
  17819. RecordPrototype.mergeDeep = MapPrototype.mergeDeep;
  17820. RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith;
  17821. RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  17822. RecordPrototype.setIn = MapPrototype.setIn;
  17823. RecordPrototype.update = MapPrototype.update;
  17824. RecordPrototype.updateIn = MapPrototype.updateIn;
  17825. RecordPrototype.withMutations = MapPrototype.withMutations;
  17826. RecordPrototype.asMutable = MapPrototype.asMutable;
  17827. RecordPrototype.asImmutable = MapPrototype.asImmutable;
  17828. function makeRecord(likeRecord, map, ownerID) {
  17829. var record = Object.create(Object.getPrototypeOf(likeRecord));
  17830. record._map = map;
  17831. record.__ownerID = ownerID;
  17832. return record;
  17833. }
  17834. function recordName(record) {
  17835. return record._name || record.constructor.name || 'Record';
  17836. }
  17837. function setProps(prototype, names) {
  17838. try {
  17839. names.forEach(setProp.bind(undefined, prototype));
  17840. } catch (error) {
  17841. // Object.defineProperty failed. Probably IE8.
  17842. }
  17843. }
  17844. function setProp(prototype, name) {
  17845. Object.defineProperty(prototype, name, {
  17846. get: function() {
  17847. return this.get(name);
  17848. },
  17849. set: function(value) {
  17850. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  17851. this.set(name, value);
  17852. }
  17853. });
  17854. }
  17855. createClass(Set, SetCollection);
  17856. // @pragma Construction
  17857. function Set(value) {
  17858. return value === null || value === undefined ? emptySet() :
  17859. isSet(value) && !isOrdered(value) ? value :
  17860. emptySet().withMutations(function(set ) {
  17861. var iter = SetIterable(value);
  17862. assertNotInfinite(iter.size);
  17863. iter.forEach(function(v ) {return set.add(v)});
  17864. });
  17865. }
  17866. Set.of = function(/*...values*/) {
  17867. return this(arguments);
  17868. };
  17869. Set.fromKeys = function(value) {
  17870. return this(KeyedIterable(value).keySeq());
  17871. };
  17872. Set.prototype.toString = function() {
  17873. return this.__toString('Set {', '}');
  17874. };
  17875. // @pragma Access
  17876. Set.prototype.has = function(value) {
  17877. return this._map.has(value);
  17878. };
  17879. // @pragma Modification
  17880. Set.prototype.add = function(value) {
  17881. return updateSet(this, this._map.set(value, true));
  17882. };
  17883. Set.prototype.remove = function(value) {
  17884. return updateSet(this, this._map.remove(value));
  17885. };
  17886. Set.prototype.clear = function() {
  17887. return updateSet(this, this._map.clear());
  17888. };
  17889. // @pragma Composition
  17890. Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
  17891. iters = iters.filter(function(x ) {return x.size !== 0});
  17892. if (iters.length === 0) {
  17893. return this;
  17894. }
  17895. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  17896. return this.constructor(iters[0]);
  17897. }
  17898. return this.withMutations(function(set ) {
  17899. for (var ii = 0; ii < iters.length; ii++) {
  17900. SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)});
  17901. }
  17902. });
  17903. };
  17904. Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
  17905. if (iters.length === 0) {
  17906. return this;
  17907. }
  17908. iters = iters.map(function(iter ) {return SetIterable(iter)});
  17909. var originalSet = this;
  17910. return this.withMutations(function(set ) {
  17911. originalSet.forEach(function(value ) {
  17912. if (!iters.every(function(iter ) {return iter.includes(value)})) {
  17913. set.remove(value);
  17914. }
  17915. });
  17916. });
  17917. };
  17918. Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
  17919. if (iters.length === 0) {
  17920. return this;
  17921. }
  17922. iters = iters.map(function(iter ) {return SetIterable(iter)});
  17923. var originalSet = this;
  17924. return this.withMutations(function(set ) {
  17925. originalSet.forEach(function(value ) {
  17926. if (iters.some(function(iter ) {return iter.includes(value)})) {
  17927. set.remove(value);
  17928. }
  17929. });
  17930. });
  17931. };
  17932. Set.prototype.merge = function() {
  17933. return this.union.apply(this, arguments);
  17934. };
  17935. Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  17936. return this.union.apply(this, iters);
  17937. };
  17938. Set.prototype.sort = function(comparator) {
  17939. // Late binding
  17940. return OrderedSet(sortFactory(this, comparator));
  17941. };
  17942. Set.prototype.sortBy = function(mapper, comparator) {
  17943. // Late binding
  17944. return OrderedSet(sortFactory(this, comparator, mapper));
  17945. };
  17946. Set.prototype.wasAltered = function() {
  17947. return this._map.wasAltered();
  17948. };
  17949. Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  17950. return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
  17951. };
  17952. Set.prototype.__iterator = function(type, reverse) {
  17953. return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
  17954. };
  17955. Set.prototype.__ensureOwner = function(ownerID) {
  17956. if (ownerID === this.__ownerID) {
  17957. return this;
  17958. }
  17959. var newMap = this._map.__ensureOwner(ownerID);
  17960. if (!ownerID) {
  17961. this.__ownerID = ownerID;
  17962. this._map = newMap;
  17963. return this;
  17964. }
  17965. return this.__make(newMap, ownerID);
  17966. };
  17967. function isSet(maybeSet) {
  17968. return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
  17969. }
  17970. Set.isSet = isSet;
  17971. var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
  17972. var SetPrototype = Set.prototype;
  17973. SetPrototype[IS_SET_SENTINEL] = true;
  17974. SetPrototype[DELETE] = SetPrototype.remove;
  17975. SetPrototype.mergeDeep = SetPrototype.merge;
  17976. SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
  17977. SetPrototype.withMutations = MapPrototype.withMutations;
  17978. SetPrototype.asMutable = MapPrototype.asMutable;
  17979. SetPrototype.asImmutable = MapPrototype.asImmutable;
  17980. SetPrototype.__empty = emptySet;
  17981. SetPrototype.__make = makeSet;
  17982. function updateSet(set, newMap) {
  17983. if (set.__ownerID) {
  17984. set.size = newMap.size;
  17985. set._map = newMap;
  17986. return set;
  17987. }
  17988. return newMap === set._map ? set :
  17989. newMap.size === 0 ? set.__empty() :
  17990. set.__make(newMap);
  17991. }
  17992. function makeSet(map, ownerID) {
  17993. var set = Object.create(SetPrototype);
  17994. set.size = map ? map.size : 0;
  17995. set._map = map;
  17996. set.__ownerID = ownerID;
  17997. return set;
  17998. }
  17999. var EMPTY_SET;
  18000. function emptySet() {
  18001. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  18002. }
  18003. createClass(OrderedSet, Set);
  18004. // @pragma Construction
  18005. function OrderedSet(value) {
  18006. return value === null || value === undefined ? emptyOrderedSet() :
  18007. isOrderedSet(value) ? value :
  18008. emptyOrderedSet().withMutations(function(set ) {
  18009. var iter = SetIterable(value);
  18010. assertNotInfinite(iter.size);
  18011. iter.forEach(function(v ) {return set.add(v)});
  18012. });
  18013. }
  18014. OrderedSet.of = function(/*...values*/) {
  18015. return this(arguments);
  18016. };
  18017. OrderedSet.fromKeys = function(value) {
  18018. return this(KeyedIterable(value).keySeq());
  18019. };
  18020. OrderedSet.prototype.toString = function() {
  18021. return this.__toString('OrderedSet {', '}');
  18022. };
  18023. function isOrderedSet(maybeOrderedSet) {
  18024. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  18025. }
  18026. OrderedSet.isOrderedSet = isOrderedSet;
  18027. var OrderedSetPrototype = OrderedSet.prototype;
  18028. OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
  18029. OrderedSetPrototype.__empty = emptyOrderedSet;
  18030. OrderedSetPrototype.__make = makeOrderedSet;
  18031. function makeOrderedSet(map, ownerID) {
  18032. var set = Object.create(OrderedSetPrototype);
  18033. set.size = map ? map.size : 0;
  18034. set._map = map;
  18035. set.__ownerID = ownerID;
  18036. return set;
  18037. }
  18038. var EMPTY_ORDERED_SET;
  18039. function emptyOrderedSet() {
  18040. return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
  18041. }
  18042. createClass(Stack, IndexedCollection);
  18043. // @pragma Construction
  18044. function Stack(value) {
  18045. return value === null || value === undefined ? emptyStack() :
  18046. isStack(value) ? value :
  18047. emptyStack().unshiftAll(value);
  18048. }
  18049. Stack.of = function(/*...values*/) {
  18050. return this(arguments);
  18051. };
  18052. Stack.prototype.toString = function() {
  18053. return this.__toString('Stack [', ']');
  18054. };
  18055. // @pragma Access
  18056. Stack.prototype.get = function(index, notSetValue) {
  18057. var head = this._head;
  18058. index = wrapIndex(this, index);
  18059. while (head && index--) {
  18060. head = head.next;
  18061. }
  18062. return head ? head.value : notSetValue;
  18063. };
  18064. Stack.prototype.peek = function() {
  18065. return this._head && this._head.value;
  18066. };
  18067. // @pragma Modification
  18068. Stack.prototype.push = function(/*...values*/) {
  18069. if (arguments.length === 0) {
  18070. return this;
  18071. }
  18072. var newSize = this.size + arguments.length;
  18073. var head = this._head;
  18074. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  18075. head = {
  18076. value: arguments[ii],
  18077. next: head
  18078. };
  18079. }
  18080. if (this.__ownerID) {
  18081. this.size = newSize;
  18082. this._head = head;
  18083. this.__hash = undefined;
  18084. this.__altered = true;
  18085. return this;
  18086. }
  18087. return makeStack(newSize, head);
  18088. };
  18089. Stack.prototype.pushAll = function(iter) {
  18090. iter = IndexedIterable(iter);
  18091. if (iter.size === 0) {
  18092. return this;
  18093. }
  18094. assertNotInfinite(iter.size);
  18095. var newSize = this.size;
  18096. var head = this._head;
  18097. iter.reverse().forEach(function(value ) {
  18098. newSize++;
  18099. head = {
  18100. value: value,
  18101. next: head
  18102. };
  18103. });
  18104. if (this.__ownerID) {
  18105. this.size = newSize;
  18106. this._head = head;
  18107. this.__hash = undefined;
  18108. this.__altered = true;
  18109. return this;
  18110. }
  18111. return makeStack(newSize, head);
  18112. };
  18113. Stack.prototype.pop = function() {
  18114. return this.slice(1);
  18115. };
  18116. Stack.prototype.unshift = function(/*...values*/) {
  18117. return this.push.apply(this, arguments);
  18118. };
  18119. Stack.prototype.unshiftAll = function(iter) {
  18120. return this.pushAll(iter);
  18121. };
  18122. Stack.prototype.shift = function() {
  18123. return this.pop.apply(this, arguments);
  18124. };
  18125. Stack.prototype.clear = function() {
  18126. if (this.size === 0) {
  18127. return this;
  18128. }
  18129. if (this.__ownerID) {
  18130. this.size = 0;
  18131. this._head = undefined;
  18132. this.__hash = undefined;
  18133. this.__altered = true;
  18134. return this;
  18135. }
  18136. return emptyStack();
  18137. };
  18138. Stack.prototype.slice = function(begin, end) {
  18139. if (wholeSlice(begin, end, this.size)) {
  18140. return this;
  18141. }
  18142. var resolvedBegin = resolveBegin(begin, this.size);
  18143. var resolvedEnd = resolveEnd(end, this.size);
  18144. if (resolvedEnd !== this.size) {
  18145. // super.slice(begin, end);
  18146. return IndexedCollection.prototype.slice.call(this, begin, end);
  18147. }
  18148. var newSize = this.size - resolvedBegin;
  18149. var head = this._head;
  18150. while (resolvedBegin--) {
  18151. head = head.next;
  18152. }
  18153. if (this.__ownerID) {
  18154. this.size = newSize;
  18155. this._head = head;
  18156. this.__hash = undefined;
  18157. this.__altered = true;
  18158. return this;
  18159. }
  18160. return makeStack(newSize, head);
  18161. };
  18162. // @pragma Mutability
  18163. Stack.prototype.__ensureOwner = function(ownerID) {
  18164. if (ownerID === this.__ownerID) {
  18165. return this;
  18166. }
  18167. if (!ownerID) {
  18168. this.__ownerID = ownerID;
  18169. this.__altered = false;
  18170. return this;
  18171. }
  18172. return makeStack(this.size, this._head, ownerID, this.__hash);
  18173. };
  18174. // @pragma Iteration
  18175. Stack.prototype.__iterate = function(fn, reverse) {
  18176. if (reverse) {
  18177. return this.reverse().__iterate(fn);
  18178. }
  18179. var iterations = 0;
  18180. var node = this._head;
  18181. while (node) {
  18182. if (fn(node.value, iterations++, this) === false) {
  18183. break;
  18184. }
  18185. node = node.next;
  18186. }
  18187. return iterations;
  18188. };
  18189. Stack.prototype.__iterator = function(type, reverse) {
  18190. if (reverse) {
  18191. return this.reverse().__iterator(type);
  18192. }
  18193. var iterations = 0;
  18194. var node = this._head;
  18195. return new Iterator(function() {
  18196. if (node) {
  18197. var value = node.value;
  18198. node = node.next;
  18199. return iteratorValue(type, iterations++, value);
  18200. }
  18201. return iteratorDone();
  18202. });
  18203. };
  18204. function isStack(maybeStack) {
  18205. return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
  18206. }
  18207. Stack.isStack = isStack;
  18208. var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
  18209. var StackPrototype = Stack.prototype;
  18210. StackPrototype[IS_STACK_SENTINEL] = true;
  18211. StackPrototype.withMutations = MapPrototype.withMutations;
  18212. StackPrototype.asMutable = MapPrototype.asMutable;
  18213. StackPrototype.asImmutable = MapPrototype.asImmutable;
  18214. StackPrototype.wasAltered = MapPrototype.wasAltered;
  18215. function makeStack(size, head, ownerID, hash) {
  18216. var map = Object.create(StackPrototype);
  18217. map.size = size;
  18218. map._head = head;
  18219. map.__ownerID = ownerID;
  18220. map.__hash = hash;
  18221. map.__altered = false;
  18222. return map;
  18223. }
  18224. var EMPTY_STACK;
  18225. function emptyStack() {
  18226. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  18227. }
  18228. /**
  18229. * Contributes additional methods to a constructor
  18230. */
  18231. function mixin(ctor, methods) {
  18232. var keyCopier = function(key ) { ctor.prototype[key] = methods[key]; };
  18233. Object.keys(methods).forEach(keyCopier);
  18234. Object.getOwnPropertySymbols &&
  18235. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  18236. return ctor;
  18237. }
  18238. Iterable.Iterator = Iterator;
  18239. mixin(Iterable, {
  18240. // ### Conversion to other types
  18241. toArray: function() {
  18242. assertNotInfinite(this.size);
  18243. var array = new Array(this.size || 0);
  18244. this.valueSeq().__iterate(function(v, i) { array[i] = v; });
  18245. return array;
  18246. },
  18247. toIndexedSeq: function() {
  18248. return new ToIndexedSequence(this);
  18249. },
  18250. toJS: function() {
  18251. return this.toSeq().map(
  18252. function(value ) {return value && typeof value.toJS === 'function' ? value.toJS() : value}
  18253. ).__toJS();
  18254. },
  18255. toJSON: function() {
  18256. return this.toSeq().map(
  18257. function(value ) {return value && typeof value.toJSON === 'function' ? value.toJSON() : value}
  18258. ).__toJS();
  18259. },
  18260. toKeyedSeq: function() {
  18261. return new ToKeyedSequence(this, true);
  18262. },
  18263. toMap: function() {
  18264. // Use Late Binding here to solve the circular dependency.
  18265. return Map(this.toKeyedSeq());
  18266. },
  18267. toObject: function() {
  18268. assertNotInfinite(this.size);
  18269. var object = {};
  18270. this.__iterate(function(v, k) { object[k] = v; });
  18271. return object;
  18272. },
  18273. toOrderedMap: function() {
  18274. // Use Late Binding here to solve the circular dependency.
  18275. return OrderedMap(this.toKeyedSeq());
  18276. },
  18277. toOrderedSet: function() {
  18278. // Use Late Binding here to solve the circular dependency.
  18279. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  18280. },
  18281. toSet: function() {
  18282. // Use Late Binding here to solve the circular dependency.
  18283. return Set(isKeyed(this) ? this.valueSeq() : this);
  18284. },
  18285. toSetSeq: function() {
  18286. return new ToSetSequence(this);
  18287. },
  18288. toSeq: function() {
  18289. return isIndexed(this) ? this.toIndexedSeq() :
  18290. isKeyed(this) ? this.toKeyedSeq() :
  18291. this.toSetSeq();
  18292. },
  18293. toStack: function() {
  18294. // Use Late Binding here to solve the circular dependency.
  18295. return Stack(isKeyed(this) ? this.valueSeq() : this);
  18296. },
  18297. toList: function() {
  18298. // Use Late Binding here to solve the circular dependency.
  18299. return List(isKeyed(this) ? this.valueSeq() : this);
  18300. },
  18301. // ### Common JavaScript methods and properties
  18302. toString: function() {
  18303. return '[Iterable]';
  18304. },
  18305. __toString: function(head, tail) {
  18306. if (this.size === 0) {
  18307. return head + tail;
  18308. }
  18309. return head + ' ' + this.toSeq().map(this.__toStringMapper).join(', ') + ' ' + tail;
  18310. },
  18311. // ### ES6 Collection methods (ES6 Array and Map)
  18312. concat: function() {var values = SLICE$0.call(arguments, 0);
  18313. return reify(this, concatFactory(this, values));
  18314. },
  18315. includes: function(searchValue) {
  18316. return this.some(function(value ) {return is(value, searchValue)});
  18317. },
  18318. entries: function() {
  18319. return this.__iterator(ITERATE_ENTRIES);
  18320. },
  18321. every: function(predicate, context) {
  18322. assertNotInfinite(this.size);
  18323. var returnValue = true;
  18324. this.__iterate(function(v, k, c) {
  18325. if (!predicate.call(context, v, k, c)) {
  18326. returnValue = false;
  18327. return false;
  18328. }
  18329. });
  18330. return returnValue;
  18331. },
  18332. filter: function(predicate, context) {
  18333. return reify(this, filterFactory(this, predicate, context, true));
  18334. },
  18335. find: function(predicate, context, notSetValue) {
  18336. var entry = this.findEntry(predicate, context);
  18337. return entry ? entry[1] : notSetValue;
  18338. },
  18339. findEntry: function(predicate, context) {
  18340. var found;
  18341. this.__iterate(function(v, k, c) {
  18342. if (predicate.call(context, v, k, c)) {
  18343. found = [k, v];
  18344. return false;
  18345. }
  18346. });
  18347. return found;
  18348. },
  18349. findLastEntry: function(predicate, context) {
  18350. return this.toSeq().reverse().findEntry(predicate, context);
  18351. },
  18352. forEach: function(sideEffect, context) {
  18353. assertNotInfinite(this.size);
  18354. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  18355. },
  18356. join: function(separator) {
  18357. assertNotInfinite(this.size);
  18358. separator = separator !== undefined ? '' + separator : ',';
  18359. var joined = '';
  18360. var isFirst = true;
  18361. this.__iterate(function(v ) {
  18362. isFirst ? (isFirst = false) : (joined += separator);
  18363. joined += v !== null && v !== undefined ? v.toString() : '';
  18364. });
  18365. return joined;
  18366. },
  18367. keys: function() {
  18368. return this.__iterator(ITERATE_KEYS);
  18369. },
  18370. map: function(mapper, context) {
  18371. return reify(this, mapFactory(this, mapper, context));
  18372. },
  18373. reduce: function(reducer, initialReduction, context) {
  18374. assertNotInfinite(this.size);
  18375. var reduction;
  18376. var useFirst;
  18377. if (arguments.length < 2) {
  18378. useFirst = true;
  18379. } else {
  18380. reduction = initialReduction;
  18381. }
  18382. this.__iterate(function(v, k, c) {
  18383. if (useFirst) {
  18384. useFirst = false;
  18385. reduction = v;
  18386. } else {
  18387. reduction = reducer.call(context, reduction, v, k, c);
  18388. }
  18389. });
  18390. return reduction;
  18391. },
  18392. reduceRight: function(reducer, initialReduction, context) {
  18393. var reversed = this.toKeyedSeq().reverse();
  18394. return reversed.reduce.apply(reversed, arguments);
  18395. },
  18396. reverse: function() {
  18397. return reify(this, reverseFactory(this, true));
  18398. },
  18399. slice: function(begin, end) {
  18400. return reify(this, sliceFactory(this, begin, end, true));
  18401. },
  18402. some: function(predicate, context) {
  18403. return !this.every(not(predicate), context);
  18404. },
  18405. sort: function(comparator) {
  18406. return reify(this, sortFactory(this, comparator));
  18407. },
  18408. values: function() {
  18409. return this.__iterator(ITERATE_VALUES);
  18410. },
  18411. // ### More sequential methods
  18412. butLast: function() {
  18413. return this.slice(0, -1);
  18414. },
  18415. isEmpty: function() {
  18416. return this.size !== undefined ? this.size === 0 : !this.some(function() {return true});
  18417. },
  18418. count: function(predicate, context) {
  18419. return ensureSize(
  18420. predicate ? this.toSeq().filter(predicate, context) : this
  18421. );
  18422. },
  18423. countBy: function(grouper, context) {
  18424. return countByFactory(this, grouper, context);
  18425. },
  18426. equals: function(other) {
  18427. return deepEqual(this, other);
  18428. },
  18429. entrySeq: function() {
  18430. var iterable = this;
  18431. if (iterable._cache) {
  18432. // We cache as an entries array, so we can just return the cache!
  18433. return new ArraySeq(iterable._cache);
  18434. }
  18435. var entriesSequence = iterable.toSeq().map(entryMapper).toIndexedSeq();
  18436. entriesSequence.fromEntrySeq = function() {return iterable.toSeq()};
  18437. return entriesSequence;
  18438. },
  18439. filterNot: function(predicate, context) {
  18440. return this.filter(not(predicate), context);
  18441. },
  18442. findLast: function(predicate, context, notSetValue) {
  18443. return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
  18444. },
  18445. first: function() {
  18446. return this.find(returnTrue);
  18447. },
  18448. flatMap: function(mapper, context) {
  18449. return reify(this, flatMapFactory(this, mapper, context));
  18450. },
  18451. flatten: function(depth) {
  18452. return reify(this, flattenFactory(this, depth, true));
  18453. },
  18454. fromEntrySeq: function() {
  18455. return new FromEntriesSequence(this);
  18456. },
  18457. get: function(searchKey, notSetValue) {
  18458. return this.find(function(_, key) {return is(key, searchKey)}, undefined, notSetValue);
  18459. },
  18460. getIn: function(searchKeyPath, notSetValue) {
  18461. var nested = this;
  18462. // Note: in an ES6 environment, we would prefer:
  18463. // for (var key of searchKeyPath) {
  18464. var iter = forceIterator(searchKeyPath);
  18465. var step;
  18466. while (!(step = iter.next()).done) {
  18467. var key = step.value;
  18468. nested = nested && nested.get ? nested.get(key, NOT_SET) : NOT_SET;
  18469. if (nested === NOT_SET) {
  18470. return notSetValue;
  18471. }
  18472. }
  18473. return nested;
  18474. },
  18475. groupBy: function(grouper, context) {
  18476. return groupByFactory(this, grouper, context);
  18477. },
  18478. has: function(searchKey) {
  18479. return this.get(searchKey, NOT_SET) !== NOT_SET;
  18480. },
  18481. hasIn: function(searchKeyPath) {
  18482. return this.getIn(searchKeyPath, NOT_SET) !== NOT_SET;
  18483. },
  18484. isSubset: function(iter) {
  18485. iter = typeof iter.includes === 'function' ? iter : Iterable(iter);
  18486. return this.every(function(value ) {return iter.includes(value)});
  18487. },
  18488. isSuperset: function(iter) {
  18489. iter = typeof iter.isSubset === 'function' ? iter : Iterable(iter);
  18490. return iter.isSubset(this);
  18491. },
  18492. keySeq: function() {
  18493. return this.toSeq().map(keyMapper).toIndexedSeq();
  18494. },
  18495. last: function() {
  18496. return this.toSeq().reverse().first();
  18497. },
  18498. max: function(comparator) {
  18499. return maxFactory(this, comparator);
  18500. },
  18501. maxBy: function(mapper, comparator) {
  18502. return maxFactory(this, comparator, mapper);
  18503. },
  18504. min: function(comparator) {
  18505. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator);
  18506. },
  18507. minBy: function(mapper, comparator) {
  18508. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator, mapper);
  18509. },
  18510. rest: function() {
  18511. return this.slice(1);
  18512. },
  18513. skip: function(amount) {
  18514. return this.slice(Math.max(0, amount));
  18515. },
  18516. skipLast: function(amount) {
  18517. return reify(this, this.toSeq().reverse().skip(amount).reverse());
  18518. },
  18519. skipWhile: function(predicate, context) {
  18520. return reify(this, skipWhileFactory(this, predicate, context, true));
  18521. },
  18522. skipUntil: function(predicate, context) {
  18523. return this.skipWhile(not(predicate), context);
  18524. },
  18525. sortBy: function(mapper, comparator) {
  18526. return reify(this, sortFactory(this, comparator, mapper));
  18527. },
  18528. take: function(amount) {
  18529. return this.slice(0, Math.max(0, amount));
  18530. },
  18531. takeLast: function(amount) {
  18532. return reify(this, this.toSeq().reverse().take(amount).reverse());
  18533. },
  18534. takeWhile: function(predicate, context) {
  18535. return reify(this, takeWhileFactory(this, predicate, context));
  18536. },
  18537. takeUntil: function(predicate, context) {
  18538. return this.takeWhile(not(predicate), context);
  18539. },
  18540. valueSeq: function() {
  18541. return this.toIndexedSeq();
  18542. },
  18543. // ### Hashable Object
  18544. hashCode: function() {
  18545. return this.__hash || (this.__hash = hashIterable(this));
  18546. }
  18547. // ### Internal
  18548. // abstract __iterate(fn, reverse)
  18549. // abstract __iterator(type, reverse)
  18550. });
  18551. // var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  18552. // var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  18553. // var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  18554. // var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  18555. var IterablePrototype = Iterable.prototype;
  18556. IterablePrototype[IS_ITERABLE_SENTINEL] = true;
  18557. IterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.values;
  18558. IterablePrototype.__toJS = IterablePrototype.toArray;
  18559. IterablePrototype.__toStringMapper = quoteString;
  18560. IterablePrototype.inspect =
  18561. IterablePrototype.toSource = function() { return this.toString(); };
  18562. IterablePrototype.chain = IterablePrototype.flatMap;
  18563. IterablePrototype.contains = IterablePrototype.includes;
  18564. // Temporary warning about using length
  18565. (function () {
  18566. try {
  18567. Object.defineProperty(IterablePrototype, 'length', {
  18568. get: function () {
  18569. if (!Iterable.noLengthWarning) {
  18570. var stack;
  18571. try {
  18572. throw new Error();
  18573. } catch (error) {
  18574. stack = error.stack;
  18575. }
  18576. if (stack.indexOf('_wrapObject') === -1) {
  18577. console && console.warn && console.warn(
  18578. 'iterable.length has been deprecated, '+
  18579. 'use iterable.size or iterable.count(). '+
  18580. 'This warning will become a silent error in a future version. ' +
  18581. stack
  18582. );
  18583. return this.size;
  18584. }
  18585. }
  18586. }
  18587. });
  18588. } catch (e) {}
  18589. })();
  18590. mixin(KeyedIterable, {
  18591. // ### More sequential methods
  18592. flip: function() {
  18593. return reify(this, flipFactory(this));
  18594. },
  18595. findKey: function(predicate, context) {
  18596. var entry = this.findEntry(predicate, context);
  18597. return entry && entry[0];
  18598. },
  18599. findLastKey: function(predicate, context) {
  18600. return this.toSeq().reverse().findKey(predicate, context);
  18601. },
  18602. keyOf: function(searchValue) {
  18603. return this.findKey(function(value ) {return is(value, searchValue)});
  18604. },
  18605. lastKeyOf: function(searchValue) {
  18606. return this.findLastKey(function(value ) {return is(value, searchValue)});
  18607. },
  18608. mapEntries: function(mapper, context) {var this$0 = this;
  18609. var iterations = 0;
  18610. return reify(this,
  18611. this.toSeq().map(
  18612. function(v, k) {return mapper.call(context, [k, v], iterations++, this$0)}
  18613. ).fromEntrySeq()
  18614. );
  18615. },
  18616. mapKeys: function(mapper, context) {var this$0 = this;
  18617. return reify(this,
  18618. this.toSeq().flip().map(
  18619. function(k, v) {return mapper.call(context, k, v, this$0)}
  18620. ).flip()
  18621. );
  18622. }
  18623. });
  18624. var KeyedIterablePrototype = KeyedIterable.prototype;
  18625. KeyedIterablePrototype[IS_KEYED_SENTINEL] = true;
  18626. KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries;
  18627. KeyedIterablePrototype.__toJS = IterablePrototype.toObject;
  18628. KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)};
  18629. mixin(IndexedIterable, {
  18630. // ### Conversion to other types
  18631. toKeyedSeq: function() {
  18632. return new ToKeyedSequence(this, false);
  18633. },
  18634. // ### ES6 Collection methods (ES6 Array and Map)
  18635. filter: function(predicate, context) {
  18636. return reify(this, filterFactory(this, predicate, context, false));
  18637. },
  18638. findIndex: function(predicate, context) {
  18639. var entry = this.findEntry(predicate, context);
  18640. return entry ? entry[0] : -1;
  18641. },
  18642. indexOf: function(searchValue) {
  18643. var key = this.toKeyedSeq().keyOf(searchValue);
  18644. return key === undefined ? -1 : key;
  18645. },
  18646. lastIndexOf: function(searchValue) {
  18647. var key = this.toKeyedSeq().reverse().keyOf(searchValue);
  18648. return key === undefined ? -1 : key;
  18649. // var index =
  18650. // return this.toSeq().reverse().indexOf(searchValue);
  18651. },
  18652. reverse: function() {
  18653. return reify(this, reverseFactory(this, false));
  18654. },
  18655. slice: function(begin, end) {
  18656. return reify(this, sliceFactory(this, begin, end, false));
  18657. },
  18658. splice: function(index, removeNum /*, ...values*/) {
  18659. var numArgs = arguments.length;
  18660. removeNum = Math.max(removeNum | 0, 0);
  18661. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  18662. return this;
  18663. }
  18664. // If index is negative, it should resolve relative to the size of the
  18665. // collection. However size may be expensive to compute if not cached, so
  18666. // only call count() if the number is in fact negative.
  18667. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  18668. var spliced = this.slice(0, index);
  18669. return reify(
  18670. this,
  18671. numArgs === 1 ?
  18672. spliced :
  18673. spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  18674. );
  18675. },
  18676. // ### More collection methods
  18677. findLastIndex: function(predicate, context) {
  18678. var key = this.toKeyedSeq().findLastKey(predicate, context);
  18679. return key === undefined ? -1 : key;
  18680. },
  18681. first: function() {
  18682. return this.get(0);
  18683. },
  18684. flatten: function(depth) {
  18685. return reify(this, flattenFactory(this, depth, false));
  18686. },
  18687. get: function(index, notSetValue) {
  18688. index = wrapIndex(this, index);
  18689. return (index < 0 || (this.size === Infinity ||
  18690. (this.size !== undefined && index > this.size))) ?
  18691. notSetValue :
  18692. this.find(function(_, key) {return key === index}, undefined, notSetValue);
  18693. },
  18694. has: function(index) {
  18695. index = wrapIndex(this, index);
  18696. return index >= 0 && (this.size !== undefined ?
  18697. this.size === Infinity || index < this.size :
  18698. this.indexOf(index) !== -1
  18699. );
  18700. },
  18701. interpose: function(separator) {
  18702. return reify(this, interposeFactory(this, separator));
  18703. },
  18704. interleave: function(/*...iterables*/) {
  18705. var iterables = [this].concat(arrCopy(arguments));
  18706. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, iterables);
  18707. var interleaved = zipped.flatten(true);
  18708. if (zipped.size) {
  18709. interleaved.size = zipped.size * iterables.length;
  18710. }
  18711. return reify(this, interleaved);
  18712. },
  18713. last: function() {
  18714. return this.get(-1);
  18715. },
  18716. skipWhile: function(predicate, context) {
  18717. return reify(this, skipWhileFactory(this, predicate, context, false));
  18718. },
  18719. zip: function(/*, ...iterables */) {
  18720. var iterables = [this].concat(arrCopy(arguments));
  18721. return reify(this, zipWithFactory(this, defaultZipper, iterables));
  18722. },
  18723. zipWith: function(zipper/*, ...iterables */) {
  18724. var iterables = arrCopy(arguments);
  18725. iterables[0] = this;
  18726. return reify(this, zipWithFactory(this, zipper, iterables));
  18727. }
  18728. });
  18729. IndexedIterable.prototype[IS_INDEXED_SENTINEL] = true;
  18730. IndexedIterable.prototype[IS_ORDERED_SENTINEL] = true;
  18731. mixin(SetIterable, {
  18732. // ### ES6 Collection methods (ES6 Array and Map)
  18733. get: function(value, notSetValue) {
  18734. return this.has(value) ? value : notSetValue;
  18735. },
  18736. includes: function(value) {
  18737. return this.has(value);
  18738. },
  18739. // ### More sequential methods
  18740. keySeq: function() {
  18741. return this.valueSeq();
  18742. }
  18743. });
  18744. SetIterable.prototype.has = IterablePrototype.includes;
  18745. // Mixin subclasses
  18746. mixin(KeyedSeq, KeyedIterable.prototype);
  18747. mixin(IndexedSeq, IndexedIterable.prototype);
  18748. mixin(SetSeq, SetIterable.prototype);
  18749. mixin(KeyedCollection, KeyedIterable.prototype);
  18750. mixin(IndexedCollection, IndexedIterable.prototype);
  18751. mixin(SetCollection, SetIterable.prototype);
  18752. // #pragma Helper functions
  18753. function keyMapper(v, k) {
  18754. return k;
  18755. }
  18756. function entryMapper(v, k) {
  18757. return [k, v];
  18758. }
  18759. function not(predicate) {
  18760. return function() {
  18761. return !predicate.apply(this, arguments);
  18762. }
  18763. }
  18764. function neg(predicate) {
  18765. return function() {
  18766. return -predicate.apply(this, arguments);
  18767. }
  18768. }
  18769. function quoteString(value) {
  18770. return typeof value === 'string' ? JSON.stringify(value) : value;
  18771. }
  18772. function defaultZipper() {
  18773. return arrCopy(arguments);
  18774. }
  18775. function defaultNegComparator(a, b) {
  18776. return a < b ? 1 : a > b ? -1 : 0;
  18777. }
  18778. function hashIterable(iterable) {
  18779. if (iterable.size === Infinity) {
  18780. return 0;
  18781. }
  18782. var ordered = isOrdered(iterable);
  18783. var keyed = isKeyed(iterable);
  18784. var h = ordered ? 1 : 0;
  18785. var size = iterable.__iterate(
  18786. keyed ?
  18787. ordered ?
  18788. function(v, k) { h = 31 * h + hashMerge(hash(v), hash(k)) | 0; } :
  18789. function(v, k) { h = h + hashMerge(hash(v), hash(k)) | 0; } :
  18790. ordered ?
  18791. function(v ) { h = 31 * h + hash(v) | 0; } :
  18792. function(v ) { h = h + hash(v) | 0; }
  18793. );
  18794. return murmurHashOfSize(size, h);
  18795. }
  18796. function murmurHashOfSize(size, h) {
  18797. h = imul(h, 0xCC9E2D51);
  18798. h = imul(h << 15 | h >>> -15, 0x1B873593);
  18799. h = imul(h << 13 | h >>> -13, 5);
  18800. h = (h + 0xE6546B64 | 0) ^ size;
  18801. h = imul(h ^ h >>> 16, 0x85EBCA6B);
  18802. h = imul(h ^ h >>> 13, 0xC2B2AE35);
  18803. h = smi(h ^ h >>> 16);
  18804. return h;
  18805. }
  18806. function hashMerge(a, b) {
  18807. return a ^ b + 0x9E3779B9 + (a << 6) + (a >> 2) | 0; // int
  18808. }
  18809. var Immutable = {
  18810. Iterable: Iterable,
  18811. Seq: Seq,
  18812. Collection: Collection,
  18813. Map: Map,
  18814. OrderedMap: OrderedMap,
  18815. List: List,
  18816. Stack: Stack,
  18817. Set: Set,
  18818. OrderedSet: OrderedSet,
  18819. Record: Record,
  18820. Range: Range,
  18821. Repeat: Repeat,
  18822. is: is,
  18823. fromJS: fromJS
  18824. };
  18825. return Immutable;
  18826. }));
  18827. });
  18828. var draftjsUtils = styleInject_es.createCommonjsModule(function (module, exports) {
  18829. !function(e,t){module.exports=t(Draft,immutable$1);}("undefined"!=typeof self?self:styleInject_es.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);}])});
  18830. });
  18831. styleInject_es.unwrapExports(draftjsUtils);
  18832. var draftjsUtils_1 = draftjsUtils.draftjsUtils;
  18833. var interopRequireDefault = styleInject_es.createCommonjsModule(function (module) {
  18834. function _interopRequireDefault(obj) {
  18835. return obj && obj.__esModule ? obj : {
  18836. "default": obj
  18837. };
  18838. }
  18839. module.exports = _interopRequireDefault;
  18840. });
  18841. styleInject_es.unwrapExports(interopRequireDefault);
  18842. /**
  18843. * Copyright (c) 2013-present, Facebook, Inc.
  18844. *
  18845. * This source code is licensed under the MIT license found in the
  18846. * LICENSE file in the root directory of this source tree.
  18847. */
  18848. /**
  18849. * Use invariant() to assert state which your program assumes to be true.
  18850. *
  18851. * Provide sprintf-style format (only %s is supported) and arguments
  18852. * to provide information about what broke and what you were
  18853. * expecting.
  18854. *
  18855. * The invariant message will be stripped in production, but the invariant
  18856. * will remain to ensure logic does not differ in production.
  18857. */
  18858. var invariant$1 = function(condition, format, a, b, c, d, e, f) {
  18859. if (process.env.NODE_ENV !== 'production') {
  18860. if (format === undefined) {
  18861. throw new Error('invariant requires an error message argument');
  18862. }
  18863. }
  18864. if (!condition) {
  18865. var error;
  18866. if (format === undefined) {
  18867. error = new Error(
  18868. 'Minified exception occurred; use the non-minified dev environment ' +
  18869. 'for the full error message and additional helpful warnings.'
  18870. );
  18871. } else {
  18872. var args = [a, b, c, d, e, f];
  18873. var argIndex = 0;
  18874. error = new Error(
  18875. format.replace(/%s/g, function() { return args[argIndex++]; })
  18876. );
  18877. error.name = 'Invariant Violation';
  18878. }
  18879. error.framesToPop = 1; // we don't care about invariant's own frame
  18880. throw error;
  18881. }
  18882. };
  18883. var browser = invariant$1;
  18884. function _arrayWithoutHoles(arr) {
  18885. if (Array.isArray(arr)) {
  18886. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
  18887. arr2[i] = arr[i];
  18888. }
  18889. return arr2;
  18890. }
  18891. }
  18892. var arrayWithoutHoles = _arrayWithoutHoles;
  18893. function _iterableToArray(iter) {
  18894. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  18895. }
  18896. var iterableToArray = _iterableToArray;
  18897. function _nonIterableSpread() {
  18898. throw new TypeError("Invalid attempt to spread non-iterable instance");
  18899. }
  18900. var nonIterableSpread = _nonIterableSpread;
  18901. function _toConsumableArray(arr) {
  18902. return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread();
  18903. }
  18904. var toConsumableArray = _toConsumableArray;
  18905. var updateMutation_1 = styleInject_es.createCommonjsModule(function (module, exports) {
  18906. Object.defineProperty(exports, "__esModule", {
  18907. value: true
  18908. });
  18909. exports["default"] = updateMutation;
  18910. function updateMutation(mutation, originalOffset, originalLength, newLength, prefixLength, suffixLength) {
  18911. // three cases we can reasonably adjust - disjoint mutations that
  18912. // happen later on where the offset will need to be changed,
  18913. // mutations that completely contain the new one where we can adjust
  18914. // the length, and mutations that occur partially within the new one.
  18915. var lengthDiff = newLength - originalLength;
  18916. var mutationAfterChange = originalOffset + originalLength <= mutation.offset;
  18917. if (mutationAfterChange) {
  18918. return Object.assign({}, mutation, {
  18919. offset: mutation.offset + lengthDiff
  18920. });
  18921. }
  18922. var mutationContainsChange = originalOffset >= mutation.offset && originalOffset + originalLength <= mutation.offset + mutation.length;
  18923. if (mutationContainsChange) {
  18924. return Object.assign({}, mutation, {
  18925. length: mutation.length + lengthDiff
  18926. });
  18927. }
  18928. var mutationWithinPrefixChange = mutation.offset >= originalOffset && mutation.offset + mutation.length <= originalOffset + originalLength && prefixLength > 0;
  18929. if (mutationWithinPrefixChange) {
  18930. return Object.assign({}, mutation, {
  18931. offset: mutation.offset + prefixLength
  18932. });
  18933. }
  18934. var mutationContainsPrefix = mutation.offset < originalOffset && mutation.offset + mutation.length <= originalOffset + originalLength && mutation.offset + mutation.length > originalOffset && prefixLength > 0;
  18935. if (mutationContainsPrefix) {
  18936. return [Object.assign({}, mutation, {
  18937. length: originalOffset - mutation.offset
  18938. }), Object.assign({}, mutation, {
  18939. offset: originalOffset + prefixLength,
  18940. length: mutation.offset - originalOffset + mutation.length
  18941. })];
  18942. }
  18943. var mutationContainsSuffix = mutation.offset >= originalOffset && mutation.offset + mutation.length > originalOffset + originalLength && originalOffset + originalLength > mutation.offset && suffixLength > 0;
  18944. if (mutationContainsSuffix) {
  18945. return [Object.assign({}, mutation, {
  18946. offset: mutation.offset + prefixLength,
  18947. length: originalOffset + originalLength - mutation.offset
  18948. }), Object.assign({}, mutation, {
  18949. offset: originalOffset + originalLength + prefixLength + suffixLength,
  18950. length: mutation.offset + mutation.length - (originalOffset + originalLength)
  18951. })];
  18952. }
  18953. return mutation;
  18954. }
  18955. });
  18956. styleInject_es.unwrapExports(updateMutation_1);
  18957. var rangeSort = styleInject_es.createCommonjsModule(function (module, exports) {
  18958. Object.defineProperty(exports, "__esModule", {
  18959. value: true
  18960. });
  18961. exports["default"] = void 0;
  18962. var _default = function _default(r1, r2) {
  18963. if (r1.offset === r2.offset) {
  18964. return r2.length - r1.length;
  18965. }
  18966. return r1.offset - r2.offset;
  18967. };
  18968. exports["default"] = _default;
  18969. });
  18970. styleInject_es.unwrapExports(rangeSort);
  18971. var encodeBlock = styleInject_es.createCommonjsModule(function (module, exports) {
  18972. Object.defineProperty(exports, "__esModule", {
  18973. value: true
  18974. });
  18975. exports["default"] = void 0;
  18976. var _toConsumableArray2 = interopRequireDefault(toConsumableArray);
  18977. var _updateMutation = interopRequireDefault(updateMutation_1);
  18978. var _rangeSort = interopRequireDefault(rangeSort);
  18979. var ENTITY_MAP = {
  18980. '&': '&amp;',
  18981. '<': '&lt;',
  18982. '>': '&gt;',
  18983. '"': '&quot;',
  18984. "'": '&#x27;',
  18985. '`': '&#x60;',
  18986. '\n': '<br/>'
  18987. };
  18988. var _default = function _default(block) {
  18989. var blockText = (0, _toConsumableArray2["default"])(block.text);
  18990. var entities = block.entityRanges.sort(_rangeSort["default"]);
  18991. var styles = block.inlineStyleRanges.sort(_rangeSort["default"]);
  18992. var resultText = '';
  18993. var _loop = function _loop(index) {
  18994. var _char = blockText[index];
  18995. if (ENTITY_MAP[_char] !== undefined) {
  18996. var encoded = ENTITY_MAP[_char];
  18997. var resultIndex = (0, _toConsumableArray2["default"])(resultText).length;
  18998. resultText += encoded;
  18999. var updateForChar = function updateForChar(mutation) {
  19000. return (0, _updateMutation["default"])(mutation, resultIndex, _char.length, encoded.length, 0, 0);
  19001. };
  19002. entities = entities.map(updateForChar);
  19003. styles = styles.map(updateForChar);
  19004. } else {
  19005. resultText += _char;
  19006. }
  19007. };
  19008. for (var index = 0; index < blockText.length; index++) {
  19009. _loop(index);
  19010. }
  19011. return Object.assign({}, block, {
  19012. text: resultText,
  19013. inlineStyleRanges: styles,
  19014. entityRanges: entities
  19015. });
  19016. };
  19017. exports["default"] = _default;
  19018. });
  19019. styleInject_es.unwrapExports(encodeBlock);
  19020. var _typeof_1 = styleInject_es.createCommonjsModule(function (module) {
  19021. function _typeof(obj) {
  19022. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  19023. module.exports = _typeof = function _typeof(obj) {
  19024. return typeof obj;
  19025. };
  19026. } else {
  19027. module.exports = _typeof = function _typeof(obj) {
  19028. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  19029. };
  19030. }
  19031. return _typeof(obj);
  19032. }
  19033. module.exports = _typeof;
  19034. });
  19035. var splitReactElement_1 = styleInject_es.createCommonjsModule(function (module, exports) {
  19036. Object.defineProperty(exports, "__esModule", {
  19037. value: true
  19038. });
  19039. exports["default"] = splitReactElement;
  19040. var _invariant = interopRequireDefault(browser);
  19041. var _react = interopRequireDefault(React__default);
  19042. var _server = interopRequireDefault(server);
  19043. // see http://w3c.github.io/html/syntax.html#writing-html-documents-elements
  19044. var VOID_TAGS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
  19045. function splitReactElement(element) {
  19046. if (VOID_TAGS.indexOf(element.type) !== -1) {
  19047. return _server["default"].renderToStaticMarkup(element);
  19048. }
  19049. var tags = _server["default"].renderToStaticMarkup(_react["default"].cloneElement(element, {}, '\r')).split('\r');
  19050. (0, _invariant["default"])(tags.length > 1, "convertToHTML: Element of type ".concat(element.type, " must render children"));
  19051. (0, _invariant["default"])(tags.length < 3, "convertToHTML: Element of type ".concat(element.type, " cannot use carriage return character"));
  19052. return {
  19053. start: tags[0],
  19054. end: tags[1]
  19055. };
  19056. }
  19057. });
  19058. styleInject_es.unwrapExports(splitReactElement_1);
  19059. var getElementHTML_1 = styleInject_es.createCommonjsModule(function (module, exports) {
  19060. Object.defineProperty(exports, "__esModule", {
  19061. value: true
  19062. });
  19063. exports["default"] = getElementHTML;
  19064. var _typeof2 = interopRequireDefault(_typeof_1);
  19065. var _invariant = interopRequireDefault(browser);
  19066. var _react = interopRequireDefault(React__default);
  19067. var _server = interopRequireDefault(server);
  19068. var _splitReactElement = interopRequireDefault(splitReactElement_1);
  19069. function hasChildren(element) {
  19070. return _react["default"].isValidElement(element) && _react["default"].Children.count(element.props.children) > 0;
  19071. }
  19072. function getElementHTML(element) {
  19073. var text = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  19074. if (element === undefined || element === null) {
  19075. return element;
  19076. }
  19077. if (typeof element === 'string') {
  19078. return element;
  19079. }
  19080. if (_react["default"].isValidElement(element)) {
  19081. if (hasChildren(element)) {
  19082. return _server["default"].renderToStaticMarkup(element);
  19083. }
  19084. var tags = (0, _splitReactElement["default"])(element);
  19085. if (text !== null && (0, _typeof2["default"])(tags) === 'object') {
  19086. var start = tags.start,
  19087. end = tags.end;
  19088. return start + text + end;
  19089. }
  19090. return tags;
  19091. }
  19092. (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');
  19093. if (text !== null) {
  19094. var _start = element.start,
  19095. _end = element.end;
  19096. return _start + text + _end;
  19097. }
  19098. return element;
  19099. }
  19100. });
  19101. styleInject_es.unwrapExports(getElementHTML_1);
  19102. var getElementTagLength_1 = styleInject_es.createCommonjsModule(function (module, exports) {
  19103. Object.defineProperty(exports, "__esModule", {
  19104. value: true
  19105. });
  19106. exports["default"] = void 0;
  19107. var _typeof2 = interopRequireDefault(_typeof_1);
  19108. var _react = interopRequireDefault(React__default);
  19109. var _splitReactElement = interopRequireDefault(splitReactElement_1);
  19110. var getElementTagLength = function getElementTagLength(element) {
  19111. var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'start';
  19112. if (_react["default"].isValidElement(element)) {
  19113. var splitElement = (0, _splitReactElement["default"])(element);
  19114. if (typeof splitElement === 'string') {
  19115. return 0;
  19116. }
  19117. var length = splitElement[type].length;
  19118. var child = _react["default"].Children.toArray(element.props.children)[0];
  19119. return length + (child && _react["default"].isValidElement(child) ? getElementTagLength(child, type) : 0);
  19120. }
  19121. if ((0, _typeof2["default"])(element) === 'object') {
  19122. return element[type] ? element[type].length : 0;
  19123. }
  19124. return 0;
  19125. };
  19126. var _default = getElementTagLength;
  19127. exports["default"] = _default;
  19128. });
  19129. styleInject_es.unwrapExports(getElementTagLength_1);
  19130. var blockEntities = styleInject_es.createCommonjsModule(function (module, exports) {
  19131. Object.defineProperty(exports, "__esModule", {
  19132. value: true
  19133. });
  19134. exports["default"] = void 0;
  19135. var _toConsumableArray2 = interopRequireDefault(toConsumableArray);
  19136. var _updateMutation = interopRequireDefault(updateMutation_1);
  19137. var _rangeSort = interopRequireDefault(rangeSort);
  19138. var _getElementHTML = interopRequireDefault(getElementHTML_1);
  19139. var _getElementTagLength = interopRequireDefault(getElementTagLength_1);
  19140. var converter = function converter() {
  19141. var originalText = arguments.length > 1 ? arguments[1] : undefined;
  19142. return originalText;
  19143. };
  19144. var _default = function _default(block, entityMap) {
  19145. var entityConverter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : converter;
  19146. var resultText = (0, _toConsumableArray2["default"])(block.text);
  19147. var getEntityHTML = entityConverter;
  19148. if (entityConverter.__isMiddleware) {
  19149. getEntityHTML = entityConverter(converter);
  19150. }
  19151. if (Object.prototype.hasOwnProperty.call(block, 'entityRanges') && block.entityRanges.length > 0) {
  19152. var entities = block.entityRanges.sort(_rangeSort["default"]);
  19153. var styles = block.inlineStyleRanges;
  19154. var _loop = function _loop(index) {
  19155. var entityRange = entities[index];
  19156. var entity = entityMap[entityRange.key];
  19157. var originalText = resultText.slice(entityRange.offset, entityRange.offset + entityRange.length).join('');
  19158. var entityHTML = getEntityHTML(entity, originalText);
  19159. var converted = (0, _toConsumableArray2["default"])((0, _getElementHTML["default"])(entityHTML, originalText) || originalText);
  19160. var prefixLength = (0, _getElementTagLength["default"])(entityHTML, 'start');
  19161. var suffixLength = (0, _getElementTagLength["default"])(entityHTML, 'end');
  19162. var updateLaterMutation = function updateLaterMutation(mutation, mutationIndex) {
  19163. if (mutationIndex > index || Object.prototype.hasOwnProperty.call(mutation, 'style')) {
  19164. return (0, _updateMutation["default"])(mutation, entityRange.offset, entityRange.length, converted.length, prefixLength, suffixLength);
  19165. }
  19166. return mutation;
  19167. };
  19168. var updateLaterMutations = function updateLaterMutations(mutationList) {
  19169. return mutationList.reduce(function (acc, mutation, mutationIndex) {
  19170. var updatedMutation = updateLaterMutation(mutation, mutationIndex);
  19171. if (Array.isArray(updatedMutation)) {
  19172. return acc.concat(updatedMutation);
  19173. }
  19174. return acc.concat([updatedMutation]);
  19175. }, []);
  19176. };
  19177. entities = updateLaterMutations(entities);
  19178. styles = updateLaterMutations(styles);
  19179. resultText = [].concat((0, _toConsumableArray2["default"])(resultText.slice(0, entityRange.offset)), (0, _toConsumableArray2["default"])(converted), (0, _toConsumableArray2["default"])(resultText.slice(entityRange.offset + entityRange.length)));
  19180. };
  19181. for (var index = 0; index < entities.length; index++) {
  19182. _loop(index);
  19183. }
  19184. return Object.assign({}, block, {
  19185. text: resultText.join(''),
  19186. inlineStyleRanges: styles,
  19187. entityRanges: entities
  19188. });
  19189. }
  19190. return block;
  19191. };
  19192. exports["default"] = _default;
  19193. });
  19194. styleInject_es.unwrapExports(blockEntities);
  19195. var styleObjectFunction = styleInject_es.createCommonjsModule(function (module, exports) {
  19196. Object.defineProperty(exports, "__esModule", {
  19197. value: true
  19198. });
  19199. exports["default"] = void 0;
  19200. var _default = function _default(object) {
  19201. return function (style) {
  19202. if (typeof object === 'function') {
  19203. return object(style);
  19204. }
  19205. return object[style];
  19206. };
  19207. };
  19208. exports["default"] = _default;
  19209. });
  19210. styleInject_es.unwrapExports(styleObjectFunction);
  19211. var accumulateFunction = styleInject_es.createCommonjsModule(function (module, exports) {
  19212. Object.defineProperty(exports, "__esModule", {
  19213. value: true
  19214. });
  19215. exports["default"] = void 0;
  19216. var _default = function _default(newFn, rest) {
  19217. return function () {
  19218. var newResult = newFn.apply(void 0, arguments);
  19219. if (newResult !== undefined && newResult !== null) {
  19220. return newResult;
  19221. }
  19222. return rest.apply(void 0, arguments);
  19223. };
  19224. };
  19225. exports["default"] = _default;
  19226. });
  19227. styleInject_es.unwrapExports(accumulateFunction);
  19228. var defaultInlineHTML_1 = styleInject_es.createCommonjsModule(function (module, exports) {
  19229. Object.defineProperty(exports, "__esModule", {
  19230. value: true
  19231. });
  19232. exports["default"] = defaultInlineHTML;
  19233. var _react = interopRequireDefault(React__default);
  19234. function defaultInlineHTML(style) {
  19235. switch (style) {
  19236. case 'BOLD':
  19237. return _react["default"].createElement("strong", null);
  19238. case 'ITALIC':
  19239. return _react["default"].createElement("em", null);
  19240. case 'UNDERLINE':
  19241. return _react["default"].createElement("u", null);
  19242. case 'CODE':
  19243. return _react["default"].createElement("code", null);
  19244. default:
  19245. return {
  19246. start: '',
  19247. end: ''
  19248. };
  19249. }
  19250. }
  19251. });
  19252. styleInject_es.unwrapExports(defaultInlineHTML_1);
  19253. var blockInlineStyles = styleInject_es.createCommonjsModule(function (module, exports) {
  19254. Object.defineProperty(exports, "__esModule", {
  19255. value: true
  19256. });
  19257. exports["default"] = void 0;
  19258. var _toConsumableArray2 = interopRequireDefault(toConsumableArray);
  19259. var _invariant = interopRequireDefault(browser);
  19260. var _styleObjectFunction = interopRequireDefault(styleObjectFunction);
  19261. var _accumulateFunction = interopRequireDefault(accumulateFunction);
  19262. var _getElementHTML = interopRequireDefault(getElementHTML_1);
  19263. var _rangeSort = interopRequireDefault(rangeSort);
  19264. var _defaultInlineHTML = interopRequireDefault(defaultInlineHTML_1);
  19265. var subtractStyles = function subtractStyles(original, toRemove) {
  19266. return original.filter(function (el) {
  19267. return !toRemove.some(function (elToRemove) {
  19268. return elToRemove.style === el.style;
  19269. });
  19270. });
  19271. };
  19272. var popEndingStyles = function popEndingStyles(styleStack, endingStyles) {
  19273. return endingStyles.reduceRight(function (stack, style) {
  19274. var styleToRemove = stack[stack.length - 1];
  19275. (0, _invariant["default"])(styleToRemove.style === style.style, "Style ".concat(styleToRemove.style, " to be removed doesn't match expected ").concat(style.style));
  19276. return stack.slice(0, -1);
  19277. }, styleStack);
  19278. };
  19279. var characterStyles = function characterStyles(offset, ranges) {
  19280. return ranges.filter(function (range) {
  19281. return offset >= range.offset && offset < range.offset + range.length;
  19282. });
  19283. };
  19284. var rangeIsSubset = function rangeIsSubset(firstRange, secondRange) {
  19285. // returns true if the second range is a subset of the first
  19286. var secondStartWithinFirst = firstRange.offset <= secondRange.offset;
  19287. var secondEndWithinFirst = firstRange.offset + firstRange.length >= secondRange.offset + secondRange.length;
  19288. return secondStartWithinFirst && secondEndWithinFirst;
  19289. };
  19290. var latestStyleLast = function latestStyleLast(s1, s2) {
  19291. // make sure longer-lasting styles are added first
  19292. var s2endIndex = s2.offset + s2.length;
  19293. var s1endIndex = s1.offset + s1.length;
  19294. return s2endIndex - s1endIndex;
  19295. };
  19296. var getStylesToReset = function getStylesToReset(remainingStyles, newStyles) {
  19297. var i = 0;
  19298. while (i < remainingStyles.length) {
  19299. if (newStyles.every(rangeIsSubset.bind(null, remainingStyles[i]))) {
  19300. i++;
  19301. } else {
  19302. return remainingStyles.slice(i);
  19303. }
  19304. }
  19305. return [];
  19306. };
  19307. var appendStartMarkup = function appendStartMarkup(inlineHTML, string, styleRange) {
  19308. return string + (0, _getElementHTML["default"])(inlineHTML(styleRange.style)).start;
  19309. };
  19310. var prependEndMarkup = function prependEndMarkup(inlineHTML, string, styleRange) {
  19311. return (0, _getElementHTML["default"])(inlineHTML(styleRange.style)).end + string;
  19312. };
  19313. var defaultCustomInlineHTML = function defaultCustomInlineHTML(next) {
  19314. return function (style) {
  19315. return next(style);
  19316. };
  19317. };
  19318. defaultCustomInlineHTML.__isMiddleware = true;
  19319. var _default = function _default(rawBlock) {
  19320. var customInlineHTML = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultCustomInlineHTML;
  19321. (0, _invariant["default"])(rawBlock !== null && rawBlock !== undefined, 'Expected raw block to be non-null');
  19322. var inlineHTML;
  19323. if (customInlineHTML.__isMiddleware === true) {
  19324. inlineHTML = customInlineHTML(_defaultInlineHTML["default"]);
  19325. } else {
  19326. inlineHTML = (0, _accumulateFunction["default"])((0, _styleObjectFunction["default"])(customInlineHTML), (0, _styleObjectFunction["default"])(_defaultInlineHTML["default"]));
  19327. }
  19328. var result = '';
  19329. var styleStack = [];
  19330. var sortedRanges = rawBlock.inlineStyleRanges.sort(_rangeSort["default"]);
  19331. var originalTextArray = (0, _toConsumableArray2["default"])(rawBlock.text);
  19332. for (var i = 0; i < originalTextArray.length; i++) {
  19333. var styles = characterStyles(i, sortedRanges);
  19334. var endingStyles = subtractStyles(styleStack, styles);
  19335. var newStyles = subtractStyles(styles, styleStack);
  19336. var remainingStyles = subtractStyles(styleStack, endingStyles); // reset styles: look for any already existing styles that will need to
  19337. // end before styles that are being added on this character. to solve this
  19338. // close out those current tags and all nested children,
  19339. // then open new ones nested within the new styles.
  19340. var resetStyles = getStylesToReset(remainingStyles, newStyles);
  19341. var openingStyles = resetStyles.concat(newStyles).sort(latestStyleLast);
  19342. var openingStyleTags = openingStyles.reduce(appendStartMarkup.bind(null, inlineHTML), '');
  19343. var endingStyleTags = endingStyles.concat(resetStyles).reduce(prependEndMarkup.bind(null, inlineHTML), '');
  19344. result += endingStyleTags + openingStyleTags + originalTextArray[i];
  19345. styleStack = popEndingStyles(styleStack, resetStyles.concat(endingStyles));
  19346. styleStack = styleStack.concat(openingStyles);
  19347. (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"));
  19348. }
  19349. result = styleStack.reduceRight(function (res, openStyle) {
  19350. return res + (0, _getElementHTML["default"])(inlineHTML(openStyle.style)).end;
  19351. }, result);
  19352. return result;
  19353. };
  19354. exports["default"] = _default;
  19355. });
  19356. styleInject_es.unwrapExports(blockInlineStyles);
  19357. var blockTypeObjectFunction = styleInject_es.createCommonjsModule(function (module, exports) {
  19358. Object.defineProperty(exports, "__esModule", {
  19359. value: true
  19360. });
  19361. exports["default"] = void 0;
  19362. var _default = function _default(typeObject) {
  19363. return function (block) {
  19364. if (typeof typeObject === 'function') {
  19365. // handle case where typeObject is already a function
  19366. return typeObject(block);
  19367. }
  19368. return typeObject[block.type];
  19369. };
  19370. };
  19371. exports["default"] = _default;
  19372. });
  19373. styleInject_es.unwrapExports(blockTypeObjectFunction);
  19374. var getBlockTags_1 = styleInject_es.createCommonjsModule(function (module, exports) {
  19375. Object.defineProperty(exports, "__esModule", {
  19376. value: true
  19377. });
  19378. exports["default"] = getBlockTags;
  19379. var _invariant = interopRequireDefault(browser);
  19380. var _react = interopRequireDefault(React__default);
  19381. var _server = interopRequireDefault(server);
  19382. var _splitReactElement = interopRequireDefault(splitReactElement_1);
  19383. function hasChildren(element) {
  19384. return _react["default"].isValidElement(element) && _react["default"].Children.count(element.props.children) > 0;
  19385. }
  19386. function getBlockTags(blockHTML) {
  19387. (0, _invariant["default"])(blockHTML !== null && blockHTML !== undefined, 'Expected block HTML value to be non-null');
  19388. if (typeof blockHTML === 'string') {
  19389. return blockHTML;
  19390. }
  19391. if (_react["default"].isValidElement(blockHTML)) {
  19392. if (hasChildren(blockHTML)) {
  19393. return _server["default"].renderToStaticMarkup(blockHTML);
  19394. }
  19395. return (0, _splitReactElement["default"])(blockHTML);
  19396. }
  19397. if (Object.prototype.hasOwnProperty.call(blockHTML, 'element') && _react["default"].isValidElement(blockHTML.element)) {
  19398. return Object.assign({}, blockHTML, (0, _splitReactElement["default"])(blockHTML.element));
  19399. }
  19400. (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');
  19401. return blockHTML;
  19402. }
  19403. });
  19404. styleInject_es.unwrapExports(getBlockTags_1);
  19405. var getNestedBlockTags_1 = styleInject_es.createCommonjsModule(function (module, exports) {
  19406. Object.defineProperty(exports, "__esModule", {
  19407. value: true
  19408. });
  19409. exports["default"] = getNestedBlockTags;
  19410. var _invariant = interopRequireDefault(browser);
  19411. var _react = interopRequireDefault(React__default);
  19412. var _splitReactElement2 = interopRequireDefault(splitReactElement_1);
  19413. function getNestedBlockTags(blockHTML) {
  19414. (0, _invariant["default"])(blockHTML !== null && blockHTML !== undefined, 'Expected block HTML value to be non-null');
  19415. if (_react["default"].isValidElement(blockHTML.nest)) {
  19416. var _splitReactElement = (0, _splitReactElement2["default"])(blockHTML.nest),
  19417. start = _splitReactElement.start,
  19418. end = _splitReactElement.end;
  19419. return Object.assign({}, blockHTML, {
  19420. nestStart: start,
  19421. nestEnd: end
  19422. });
  19423. }
  19424. (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');
  19425. return blockHTML;
  19426. }
  19427. });
  19428. styleInject_es.unwrapExports(getNestedBlockTags_1);
  19429. var defaultBlockHTML = styleInject_es.createCommonjsModule(function (module, exports) {
  19430. Object.defineProperty(exports, "__esModule", {
  19431. value: true
  19432. });
  19433. exports["default"] = void 0;
  19434. var _react = interopRequireDefault(React__default);
  19435. var _default = {
  19436. unstyled: _react["default"].createElement("p", null),
  19437. paragraph: _react["default"].createElement("p", null),
  19438. 'header-one': _react["default"].createElement("h1", null),
  19439. 'header-two': _react["default"].createElement("h2", null),
  19440. 'header-three': _react["default"].createElement("h3", null),
  19441. 'header-four': _react["default"].createElement("h4", null),
  19442. 'header-five': _react["default"].createElement("h5", null),
  19443. 'header-six': _react["default"].createElement("h6", null),
  19444. blockquote: _react["default"].createElement("blockquote", null),
  19445. 'unordered-list-item': {
  19446. element: _react["default"].createElement("li", null),
  19447. nest: _react["default"].createElement("ul", null)
  19448. },
  19449. 'ordered-list-item': {
  19450. element: _react["default"].createElement("li", null),
  19451. nest: _react["default"].createElement("ol", null)
  19452. },
  19453. media: _react["default"].createElement("figure", null),
  19454. atomic: _react["default"].createElement("figure", null)
  19455. };
  19456. exports["default"] = _default;
  19457. });
  19458. styleInject_es.unwrapExports(defaultBlockHTML);
  19459. var convertToHTML_1 = styleInject_es.createCommonjsModule(function (module, exports) {
  19460. Object.defineProperty(exports, "__esModule", {
  19461. value: true
  19462. });
  19463. exports["default"] = void 0;
  19464. var _invariant = interopRequireDefault(browser);
  19465. var _react = interopRequireDefault(React__default);
  19466. var _server = interopRequireDefault(server);
  19467. var _encodeBlock = interopRequireDefault(encodeBlock);
  19468. var _blockEntities = interopRequireDefault(blockEntities);
  19469. var _blockInlineStyles = interopRequireDefault(blockInlineStyles);
  19470. var _accumulateFunction = interopRequireDefault(accumulateFunction);
  19471. var _blockTypeObjectFunction = interopRequireDefault(blockTypeObjectFunction);
  19472. var _getBlockTags = interopRequireDefault(getBlockTags_1);
  19473. var _getNestedBlockTags = interopRequireDefault(getNestedBlockTags_1);
  19474. var _defaultBlockHTML = interopRequireDefault(defaultBlockHTML);
  19475. // import Immutable from 'immutable'; // eslint-disable-line no-unused-vars
  19476. var defaultEntityToHTML = function defaultEntityToHTML(entity, originalText) {
  19477. return originalText;
  19478. };
  19479. var convertToHTML = function convertToHTML(_ref) {
  19480. var _ref$styleToHTML = _ref.styleToHTML,
  19481. styleToHTML = _ref$styleToHTML === void 0 ? {} : _ref$styleToHTML,
  19482. _ref$blockToHTML = _ref.blockToHTML,
  19483. blockToHTML = _ref$blockToHTML === void 0 ? {} : _ref$blockToHTML,
  19484. _ref$entityToHTML = _ref.entityToHTML,
  19485. entityToHTML = _ref$entityToHTML === void 0 ? defaultEntityToHTML : _ref$entityToHTML;
  19486. return function (contentState) {
  19487. (0, _invariant["default"])(contentState !== null && contentState !== undefined, 'Expected contentState to be non-null');
  19488. var getBlockHTML;
  19489. if (blockToHTML.__isMiddleware === true) {
  19490. getBlockHTML = blockToHTML((0, _blockTypeObjectFunction["default"])(_defaultBlockHTML["default"]));
  19491. } else {
  19492. getBlockHTML = (0, _accumulateFunction["default"])((0, _blockTypeObjectFunction["default"])(blockToHTML), (0, _blockTypeObjectFunction["default"])(_defaultBlockHTML["default"]));
  19493. }
  19494. var rawState = (0, Draft.convertToRaw)(contentState);
  19495. var listStack = [];
  19496. var result = rawState.blocks.map(function (block) {
  19497. var type = block.type,
  19498. depth = block.depth;
  19499. var closeNestTags = '';
  19500. var openNestTags = '';
  19501. var blockHTMLResult = getBlockHTML(block);
  19502. if (!blockHTMLResult) {
  19503. throw new Error("convertToHTML: missing HTML definition for block with type ".concat(block.type));
  19504. }
  19505. if (!blockHTMLResult.nest) {
  19506. // this block can't be nested, so reset all nesting if necessary
  19507. closeNestTags = listStack.reduceRight(function (string, nestedBlock) {
  19508. return string + (0, _getNestedBlockTags["default"])(getBlockHTML(nestedBlock)).nestEnd;
  19509. }, '');
  19510. listStack = [];
  19511. } else {
  19512. while (depth + 1 !== listStack.length || type !== listStack[depth].type) {
  19513. if (depth + 1 === listStack.length) {
  19514. // depth is right but doesn't match type
  19515. var blockToClose = listStack[depth];
  19516. closeNestTags += (0, _getNestedBlockTags["default"])(getBlockHTML(blockToClose)).nestEnd;
  19517. openNestTags += (0, _getNestedBlockTags["default"])(getBlockHTML(block)).nestStart;
  19518. listStack[depth] = block;
  19519. } else if (depth + 1 < listStack.length) {
  19520. var _blockToClose = listStack[listStack.length - 1];
  19521. closeNestTags += (0, _getNestedBlockTags["default"])(getBlockHTML(_blockToClose)).nestEnd;
  19522. listStack = listStack.slice(0, -1);
  19523. } else {
  19524. openNestTags += (0, _getNestedBlockTags["default"])(getBlockHTML(block)).nestStart;
  19525. listStack.push(block);
  19526. }
  19527. }
  19528. }
  19529. var innerHTML = (0, _blockInlineStyles["default"])((0, _blockEntities["default"])((0, _encodeBlock["default"])(block), rawState.entityMap, entityToHTML), styleToHTML);
  19530. var blockHTML = (0, _getBlockTags["default"])(getBlockHTML(block));
  19531. var html;
  19532. if (typeof blockHTML === 'string') {
  19533. html = blockHTML;
  19534. } else {
  19535. html = blockHTML.start + innerHTML + blockHTML.end;
  19536. }
  19537. if (innerHTML.length === 0 && Object.prototype.hasOwnProperty.call(blockHTML, 'empty')) {
  19538. if (_react["default"].isValidElement(blockHTML.empty)) {
  19539. html = _server["default"].renderToStaticMarkup(blockHTML.empty);
  19540. } else {
  19541. html = blockHTML.empty;
  19542. }
  19543. }
  19544. return closeNestTags + openNestTags + html;
  19545. }).join('');
  19546. result = listStack.reduce(function (res, nestBlock) {
  19547. return res + (0, _getNestedBlockTags["default"])(getBlockHTML(nestBlock)).nestEnd;
  19548. }, result);
  19549. return result;
  19550. };
  19551. };
  19552. var _default = function _default() {
  19553. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  19554. args[_key] = arguments[_key];
  19555. }
  19556. if (args.length === 1 && Object.prototype.hasOwnProperty.call(args[0], '_map') && args[0].getBlockMap != null) {
  19557. // skip higher-order function and use defaults
  19558. return convertToHTML({}).apply(void 0, args);
  19559. }
  19560. return convertToHTML.apply(void 0, args);
  19561. };
  19562. exports["default"] = _default;
  19563. });
  19564. styleInject_es.unwrapExports(convertToHTML_1);
  19565. var immutable$2 = styleInject_es.createCommonjsModule(function (module, exports) {
  19566. /**
  19567. * Copyright (c) 2014-2015, Facebook, Inc.
  19568. * All rights reserved.
  19569. *
  19570. * This source code is licensed under the BSD-style license found in the
  19571. * LICENSE file in the root directory of this source tree. An additional grant
  19572. * of patent rights can be found in the PATENTS file in the same directory.
  19573. */
  19574. (function (global, factory) {
  19575. module.exports = factory() ;
  19576. }(styleInject_es.commonjsGlobal, function () {var SLICE$0 = Array.prototype.slice;
  19577. function createClass(ctor, superClass) {
  19578. if (superClass) {
  19579. ctor.prototype = Object.create(superClass.prototype);
  19580. }
  19581. ctor.prototype.constructor = ctor;
  19582. }
  19583. function Iterable(value) {
  19584. return isIterable(value) ? value : Seq(value);
  19585. }
  19586. createClass(KeyedIterable, Iterable);
  19587. function KeyedIterable(value) {
  19588. return isKeyed(value) ? value : KeyedSeq(value);
  19589. }
  19590. createClass(IndexedIterable, Iterable);
  19591. function IndexedIterable(value) {
  19592. return isIndexed(value) ? value : IndexedSeq(value);
  19593. }
  19594. createClass(SetIterable, Iterable);
  19595. function SetIterable(value) {
  19596. return isIterable(value) && !isAssociative(value) ? value : SetSeq(value);
  19597. }
  19598. function isIterable(maybeIterable) {
  19599. return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]);
  19600. }
  19601. function isKeyed(maybeKeyed) {
  19602. return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
  19603. }
  19604. function isIndexed(maybeIndexed) {
  19605. return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
  19606. }
  19607. function isAssociative(maybeAssociative) {
  19608. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  19609. }
  19610. function isOrdered(maybeOrdered) {
  19611. return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
  19612. }
  19613. Iterable.isIterable = isIterable;
  19614. Iterable.isKeyed = isKeyed;
  19615. Iterable.isIndexed = isIndexed;
  19616. Iterable.isAssociative = isAssociative;
  19617. Iterable.isOrdered = isOrdered;
  19618. Iterable.Keyed = KeyedIterable;
  19619. Iterable.Indexed = IndexedIterable;
  19620. Iterable.Set = SetIterable;
  19621. var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  19622. var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  19623. var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  19624. var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  19625. // Used for setting prototype methods that IE8 chokes on.
  19626. var DELETE = 'delete';
  19627. // Constants describing the size of trie nodes.
  19628. var SHIFT = 5; // Resulted in best performance after ______?
  19629. var SIZE = 1 << SHIFT;
  19630. var MASK = SIZE - 1;
  19631. // A consistent shared value representing "not set" which equals nothing other
  19632. // than itself, and nothing that could be provided externally.
  19633. var NOT_SET = {};
  19634. // Boolean references, Rough equivalent of `bool &`.
  19635. var CHANGE_LENGTH = { value: false };
  19636. var DID_ALTER = { value: false };
  19637. function MakeRef(ref) {
  19638. ref.value = false;
  19639. return ref;
  19640. }
  19641. function SetRef(ref) {
  19642. ref && (ref.value = true);
  19643. }
  19644. // A function which returns a value representing an "owner" for transient writes
  19645. // to tries. The return value will only ever equal itself, and will not equal
  19646. // the return of any subsequent call of this function.
  19647. function OwnerID() {}
  19648. // http://jsperf.com/copy-array-inline
  19649. function arrCopy(arr, offset) {
  19650. offset = offset || 0;
  19651. var len = Math.max(0, arr.length - offset);
  19652. var newArr = new Array(len);
  19653. for (var ii = 0; ii < len; ii++) {
  19654. newArr[ii] = arr[ii + offset];
  19655. }
  19656. return newArr;
  19657. }
  19658. function ensureSize(iter) {
  19659. if (iter.size === undefined) {
  19660. iter.size = iter.__iterate(returnTrue);
  19661. }
  19662. return iter.size;
  19663. }
  19664. function wrapIndex(iter, index) {
  19665. // This implements "is array index" which the ECMAString spec defines as:
  19666. //
  19667. // A String property name P is an array index if and only if
  19668. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  19669. // to 2^32−1.
  19670. //
  19671. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  19672. if (typeof index !== 'number') {
  19673. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  19674. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  19675. return NaN;
  19676. }
  19677. index = uint32Index;
  19678. }
  19679. return index < 0 ? ensureSize(iter) + index : index;
  19680. }
  19681. function returnTrue() {
  19682. return true;
  19683. }
  19684. function wholeSlice(begin, end, size) {
  19685. return (begin === 0 || (size !== undefined && begin <= -size)) &&
  19686. (end === undefined || (size !== undefined && end >= size));
  19687. }
  19688. function resolveBegin(begin, size) {
  19689. return resolveIndex(begin, size, 0);
  19690. }
  19691. function resolveEnd(end, size) {
  19692. return resolveIndex(end, size, size);
  19693. }
  19694. function resolveIndex(index, size, defaultIndex) {
  19695. return index === undefined ?
  19696. defaultIndex :
  19697. index < 0 ?
  19698. Math.max(0, size + index) :
  19699. size === undefined ?
  19700. index :
  19701. Math.min(size, index);
  19702. }
  19703. /* global Symbol */
  19704. var ITERATE_KEYS = 0;
  19705. var ITERATE_VALUES = 1;
  19706. var ITERATE_ENTRIES = 2;
  19707. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  19708. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  19709. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  19710. function Iterator(next) {
  19711. this.next = next;
  19712. }
  19713. Iterator.prototype.toString = function() {
  19714. return '[Iterator]';
  19715. };
  19716. Iterator.KEYS = ITERATE_KEYS;
  19717. Iterator.VALUES = ITERATE_VALUES;
  19718. Iterator.ENTRIES = ITERATE_ENTRIES;
  19719. Iterator.prototype.inspect =
  19720. Iterator.prototype.toSource = function () { return this.toString(); };
  19721. Iterator.prototype[ITERATOR_SYMBOL] = function () {
  19722. return this;
  19723. };
  19724. function iteratorValue(type, k, v, iteratorResult) {
  19725. var value = type === 0 ? k : type === 1 ? v : [k, v];
  19726. iteratorResult ? (iteratorResult.value = value) : (iteratorResult = {
  19727. value: value, done: false
  19728. });
  19729. return iteratorResult;
  19730. }
  19731. function iteratorDone() {
  19732. return { value: undefined, done: true };
  19733. }
  19734. function hasIterator(maybeIterable) {
  19735. return !!getIteratorFn(maybeIterable);
  19736. }
  19737. function isIterator(maybeIterator) {
  19738. return maybeIterator && typeof maybeIterator.next === 'function';
  19739. }
  19740. function getIterator(iterable) {
  19741. var iteratorFn = getIteratorFn(iterable);
  19742. return iteratorFn && iteratorFn.call(iterable);
  19743. }
  19744. function getIteratorFn(iterable) {
  19745. var iteratorFn = iterable && (
  19746. (REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  19747. iterable[FAUX_ITERATOR_SYMBOL]
  19748. );
  19749. if (typeof iteratorFn === 'function') {
  19750. return iteratorFn;
  19751. }
  19752. }
  19753. function isArrayLike(value) {
  19754. return value && typeof value.length === 'number';
  19755. }
  19756. createClass(Seq, Iterable);
  19757. function Seq(value) {
  19758. return value === null || value === undefined ? emptySequence() :
  19759. isIterable(value) ? value.toSeq() : seqFromValue(value);
  19760. }
  19761. Seq.of = function(/*...values*/) {
  19762. return Seq(arguments);
  19763. };
  19764. Seq.prototype.toSeq = function() {
  19765. return this;
  19766. };
  19767. Seq.prototype.toString = function() {
  19768. return this.__toString('Seq {', '}');
  19769. };
  19770. Seq.prototype.cacheResult = function() {
  19771. if (!this._cache && this.__iterateUncached) {
  19772. this._cache = this.entrySeq().toArray();
  19773. this.size = this._cache.length;
  19774. }
  19775. return this;
  19776. };
  19777. // abstract __iterateUncached(fn, reverse)
  19778. Seq.prototype.__iterate = function(fn, reverse) {
  19779. return seqIterate(this, fn, reverse, true);
  19780. };
  19781. // abstract __iteratorUncached(type, reverse)
  19782. Seq.prototype.__iterator = function(type, reverse) {
  19783. return seqIterator(this, type, reverse, true);
  19784. };
  19785. createClass(KeyedSeq, Seq);
  19786. function KeyedSeq(value) {
  19787. return value === null || value === undefined ?
  19788. emptySequence().toKeyedSeq() :
  19789. isIterable(value) ?
  19790. (isKeyed(value) ? value.toSeq() : value.fromEntrySeq()) :
  19791. keyedSeqFromValue(value);
  19792. }
  19793. KeyedSeq.prototype.toKeyedSeq = function() {
  19794. return this;
  19795. };
  19796. createClass(IndexedSeq, Seq);
  19797. function IndexedSeq(value) {
  19798. return value === null || value === undefined ? emptySequence() :
  19799. !isIterable(value) ? indexedSeqFromValue(value) :
  19800. isKeyed(value) ? value.entrySeq() : value.toIndexedSeq();
  19801. }
  19802. IndexedSeq.of = function(/*...values*/) {
  19803. return IndexedSeq(arguments);
  19804. };
  19805. IndexedSeq.prototype.toIndexedSeq = function() {
  19806. return this;
  19807. };
  19808. IndexedSeq.prototype.toString = function() {
  19809. return this.__toString('Seq [', ']');
  19810. };
  19811. IndexedSeq.prototype.__iterate = function(fn, reverse) {
  19812. return seqIterate(this, fn, reverse, false);
  19813. };
  19814. IndexedSeq.prototype.__iterator = function(type, reverse) {
  19815. return seqIterator(this, type, reverse, false);
  19816. };
  19817. createClass(SetSeq, Seq);
  19818. function SetSeq(value) {
  19819. return (
  19820. value === null || value === undefined ? emptySequence() :
  19821. !isIterable(value) ? indexedSeqFromValue(value) :
  19822. isKeyed(value) ? value.entrySeq() : value
  19823. ).toSetSeq();
  19824. }
  19825. SetSeq.of = function(/*...values*/) {
  19826. return SetSeq(arguments);
  19827. };
  19828. SetSeq.prototype.toSetSeq = function() {
  19829. return this;
  19830. };
  19831. Seq.isSeq = isSeq;
  19832. Seq.Keyed = KeyedSeq;
  19833. Seq.Set = SetSeq;
  19834. Seq.Indexed = IndexedSeq;
  19835. var IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
  19836. Seq.prototype[IS_SEQ_SENTINEL] = true;
  19837. createClass(ArraySeq, IndexedSeq);
  19838. function ArraySeq(array) {
  19839. this._array = array;
  19840. this.size = array.length;
  19841. }
  19842. ArraySeq.prototype.get = function(index, notSetValue) {
  19843. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  19844. };
  19845. ArraySeq.prototype.__iterate = function(fn, reverse) {
  19846. var array = this._array;
  19847. var maxIndex = array.length - 1;
  19848. for (var ii = 0; ii <= maxIndex; ii++) {
  19849. if (fn(array[reverse ? maxIndex - ii : ii], ii, this) === false) {
  19850. return ii + 1;
  19851. }
  19852. }
  19853. return ii;
  19854. };
  19855. ArraySeq.prototype.__iterator = function(type, reverse) {
  19856. var array = this._array;
  19857. var maxIndex = array.length - 1;
  19858. var ii = 0;
  19859. return new Iterator(function()
  19860. {return ii > maxIndex ?
  19861. iteratorDone() :
  19862. iteratorValue(type, ii, array[reverse ? maxIndex - ii++ : ii++])}
  19863. );
  19864. };
  19865. createClass(ObjectSeq, KeyedSeq);
  19866. function ObjectSeq(object) {
  19867. var keys = Object.keys(object);
  19868. this._object = object;
  19869. this._keys = keys;
  19870. this.size = keys.length;
  19871. }
  19872. ObjectSeq.prototype.get = function(key, notSetValue) {
  19873. if (notSetValue !== undefined && !this.has(key)) {
  19874. return notSetValue;
  19875. }
  19876. return this._object[key];
  19877. };
  19878. ObjectSeq.prototype.has = function(key) {
  19879. return this._object.hasOwnProperty(key);
  19880. };
  19881. ObjectSeq.prototype.__iterate = function(fn, reverse) {
  19882. var object = this._object;
  19883. var keys = this._keys;
  19884. var maxIndex = keys.length - 1;
  19885. for (var ii = 0; ii <= maxIndex; ii++) {
  19886. var key = keys[reverse ? maxIndex - ii : ii];
  19887. if (fn(object[key], key, this) === false) {
  19888. return ii + 1;
  19889. }
  19890. }
  19891. return ii;
  19892. };
  19893. ObjectSeq.prototype.__iterator = function(type, reverse) {
  19894. var object = this._object;
  19895. var keys = this._keys;
  19896. var maxIndex = keys.length - 1;
  19897. var ii = 0;
  19898. return new Iterator(function() {
  19899. var key = keys[reverse ? maxIndex - ii : ii];
  19900. return ii++ > maxIndex ?
  19901. iteratorDone() :
  19902. iteratorValue(type, key, object[key]);
  19903. });
  19904. };
  19905. ObjectSeq.prototype[IS_ORDERED_SENTINEL] = true;
  19906. createClass(IterableSeq, IndexedSeq);
  19907. function IterableSeq(iterable) {
  19908. this._iterable = iterable;
  19909. this.size = iterable.length || iterable.size;
  19910. }
  19911. IterableSeq.prototype.__iterateUncached = function(fn, reverse) {
  19912. if (reverse) {
  19913. return this.cacheResult().__iterate(fn, reverse);
  19914. }
  19915. var iterable = this._iterable;
  19916. var iterator = getIterator(iterable);
  19917. var iterations = 0;
  19918. if (isIterator(iterator)) {
  19919. var step;
  19920. while (!(step = iterator.next()).done) {
  19921. if (fn(step.value, iterations++, this) === false) {
  19922. break;
  19923. }
  19924. }
  19925. }
  19926. return iterations;
  19927. };
  19928. IterableSeq.prototype.__iteratorUncached = function(type, reverse) {
  19929. if (reverse) {
  19930. return this.cacheResult().__iterator(type, reverse);
  19931. }
  19932. var iterable = this._iterable;
  19933. var iterator = getIterator(iterable);
  19934. if (!isIterator(iterator)) {
  19935. return new Iterator(iteratorDone);
  19936. }
  19937. var iterations = 0;
  19938. return new Iterator(function() {
  19939. var step = iterator.next();
  19940. return step.done ? step : iteratorValue(type, iterations++, step.value);
  19941. });
  19942. };
  19943. createClass(IteratorSeq, IndexedSeq);
  19944. function IteratorSeq(iterator) {
  19945. this._iterator = iterator;
  19946. this._iteratorCache = [];
  19947. }
  19948. IteratorSeq.prototype.__iterateUncached = function(fn, reverse) {
  19949. if (reverse) {
  19950. return this.cacheResult().__iterate(fn, reverse);
  19951. }
  19952. var iterator = this._iterator;
  19953. var cache = this._iteratorCache;
  19954. var iterations = 0;
  19955. while (iterations < cache.length) {
  19956. if (fn(cache[iterations], iterations++, this) === false) {
  19957. return iterations;
  19958. }
  19959. }
  19960. var step;
  19961. while (!(step = iterator.next()).done) {
  19962. var val = step.value;
  19963. cache[iterations] = val;
  19964. if (fn(val, iterations++, this) === false) {
  19965. break;
  19966. }
  19967. }
  19968. return iterations;
  19969. };
  19970. IteratorSeq.prototype.__iteratorUncached = function(type, reverse) {
  19971. if (reverse) {
  19972. return this.cacheResult().__iterator(type, reverse);
  19973. }
  19974. var iterator = this._iterator;
  19975. var cache = this._iteratorCache;
  19976. var iterations = 0;
  19977. return new Iterator(function() {
  19978. if (iterations >= cache.length) {
  19979. var step = iterator.next();
  19980. if (step.done) {
  19981. return step;
  19982. }
  19983. cache[iterations] = step.value;
  19984. }
  19985. return iteratorValue(type, iterations, cache[iterations++]);
  19986. });
  19987. };
  19988. // # pragma Helper functions
  19989. function isSeq(maybeSeq) {
  19990. return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]);
  19991. }
  19992. var EMPTY_SEQ;
  19993. function emptySequence() {
  19994. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  19995. }
  19996. function keyedSeqFromValue(value) {
  19997. var seq =
  19998. Array.isArray(value) ? new ArraySeq(value).fromEntrySeq() :
  19999. isIterator(value) ? new IteratorSeq(value).fromEntrySeq() :
  20000. hasIterator(value) ? new IterableSeq(value).fromEntrySeq() :
  20001. typeof value === 'object' ? new ObjectSeq(value) :
  20002. undefined;
  20003. if (!seq) {
  20004. throw new TypeError(
  20005. 'Expected Array or iterable object of [k, v] entries, '+
  20006. 'or keyed object: ' + value
  20007. );
  20008. }
  20009. return seq;
  20010. }
  20011. function indexedSeqFromValue(value) {
  20012. var seq = maybeIndexedSeqFromValue(value);
  20013. if (!seq) {
  20014. throw new TypeError(
  20015. 'Expected Array or iterable object of values: ' + value
  20016. );
  20017. }
  20018. return seq;
  20019. }
  20020. function seqFromValue(value) {
  20021. var seq = maybeIndexedSeqFromValue(value) ||
  20022. (typeof value === 'object' && new ObjectSeq(value));
  20023. if (!seq) {
  20024. throw new TypeError(
  20025. 'Expected Array or iterable object of values, or keyed object: ' + value
  20026. );
  20027. }
  20028. return seq;
  20029. }
  20030. function maybeIndexedSeqFromValue(value) {
  20031. return (
  20032. isArrayLike(value) ? new ArraySeq(value) :
  20033. isIterator(value) ? new IteratorSeq(value) :
  20034. hasIterator(value) ? new IterableSeq(value) :
  20035. undefined
  20036. );
  20037. }
  20038. function seqIterate(seq, fn, reverse, useKeys) {
  20039. var cache = seq._cache;
  20040. if (cache) {
  20041. var maxIndex = cache.length - 1;
  20042. for (var ii = 0; ii <= maxIndex; ii++) {
  20043. var entry = cache[reverse ? maxIndex - ii : ii];
  20044. if (fn(entry[1], useKeys ? entry[0] : ii, seq) === false) {
  20045. return ii + 1;
  20046. }
  20047. }
  20048. return ii;
  20049. }
  20050. return seq.__iterateUncached(fn, reverse);
  20051. }
  20052. function seqIterator(seq, type, reverse, useKeys) {
  20053. var cache = seq._cache;
  20054. if (cache) {
  20055. var maxIndex = cache.length - 1;
  20056. var ii = 0;
  20057. return new Iterator(function() {
  20058. var entry = cache[reverse ? maxIndex - ii : ii];
  20059. return ii++ > maxIndex ?
  20060. iteratorDone() :
  20061. iteratorValue(type, useKeys ? entry[0] : ii - 1, entry[1]);
  20062. });
  20063. }
  20064. return seq.__iteratorUncached(type, reverse);
  20065. }
  20066. function fromJS(json, converter) {
  20067. return converter ?
  20068. fromJSWith(converter, json, '', {'': json}) :
  20069. fromJSDefault(json);
  20070. }
  20071. function fromJSWith(converter, json, key, parentJSON) {
  20072. if (Array.isArray(json)) {
  20073. return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  20074. }
  20075. if (isPlainObj(json)) {
  20076. return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  20077. }
  20078. return json;
  20079. }
  20080. function fromJSDefault(json) {
  20081. if (Array.isArray(json)) {
  20082. return IndexedSeq(json).map(fromJSDefault).toList();
  20083. }
  20084. if (isPlainObj(json)) {
  20085. return KeyedSeq(json).map(fromJSDefault).toMap();
  20086. }
  20087. return json;
  20088. }
  20089. function isPlainObj(value) {
  20090. return value && (value.constructor === Object || value.constructor === undefined);
  20091. }
  20092. /**
  20093. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  20094. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  20095. *
  20096. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  20097. * value, which is different from the algorithm described by
  20098. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  20099. *
  20100. * This is extended further to allow Objects to describe the values they
  20101. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  20102. *
  20103. * Note: because of this extension, the key equality of Immutable.Map and the
  20104. * value equality of Immutable.Set will differ from ES6 Map and Set.
  20105. *
  20106. * ### Defining custom values
  20107. *
  20108. * The easiest way to describe the value an object represents is by implementing
  20109. * `valueOf`. For example, `Date` represents a value by returning a unix
  20110. * timestamp for `valueOf`:
  20111. *
  20112. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  20113. * var date2 = new Date(1234567890000);
  20114. * date1.valueOf(); // 1234567890000
  20115. * assert( date1 !== date2 );
  20116. * assert( Immutable.is( date1, date2 ) );
  20117. *
  20118. * Note: overriding `valueOf` may have other implications if you use this object
  20119. * where JavaScript expects a primitive, such as implicit string coercion.
  20120. *
  20121. * For more complex types, especially collections, implementing `valueOf` may
  20122. * not be performant. An alternative is to implement `equals` and `hashCode`.
  20123. *
  20124. * `equals` takes another object, presumably of similar type, and returns true
  20125. * if the it is equal. Equality is symmetrical, so the same result should be
  20126. * returned if this and the argument are flipped.
  20127. *
  20128. * assert( a.equals(b) === b.equals(a) );
  20129. *
  20130. * `hashCode` returns a 32bit integer number representing the object which will
  20131. * be used to determine how to store the value object in a Map or Set. You must
  20132. * provide both or neither methods, one must not exist without the other.
  20133. *
  20134. * Also, an important relationship between these methods must be upheld: if two
  20135. * values are equal, they *must* return the same hashCode. If the values are not
  20136. * equal, they might have the same hashCode; this is called a hash collision,
  20137. * and while undesirable for performance reasons, it is acceptable.
  20138. *
  20139. * if (a.equals(b)) {
  20140. * assert( a.hashCode() === b.hashCode() );
  20141. * }
  20142. *
  20143. * All Immutable collections implement `equals` and `hashCode`.
  20144. *
  20145. */
  20146. function is(valueA, valueB) {
  20147. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  20148. return true;
  20149. }
  20150. if (!valueA || !valueB) {
  20151. return false;
  20152. }
  20153. if (typeof valueA.valueOf === 'function' &&
  20154. typeof valueB.valueOf === 'function') {
  20155. valueA = valueA.valueOf();
  20156. valueB = valueB.valueOf();
  20157. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  20158. return true;
  20159. }
  20160. if (!valueA || !valueB) {
  20161. return false;
  20162. }
  20163. }
  20164. if (typeof valueA.equals === 'function' &&
  20165. typeof valueB.equals === 'function' &&
  20166. valueA.equals(valueB)) {
  20167. return true;
  20168. }
  20169. return false;
  20170. }
  20171. function deepEqual(a, b) {
  20172. if (a === b) {
  20173. return true;
  20174. }
  20175. if (
  20176. !isIterable(b) ||
  20177. a.size !== undefined && b.size !== undefined && a.size !== b.size ||
  20178. a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
  20179. isKeyed(a) !== isKeyed(b) ||
  20180. isIndexed(a) !== isIndexed(b) ||
  20181. isOrdered(a) !== isOrdered(b)
  20182. ) {
  20183. return false;
  20184. }
  20185. if (a.size === 0 && b.size === 0) {
  20186. return true;
  20187. }
  20188. var notAssociative = !isAssociative(a);
  20189. if (isOrdered(a)) {
  20190. var entries = a.entries();
  20191. return b.every(function(v, k) {
  20192. var entry = entries.next().value;
  20193. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  20194. }) && entries.next().done;
  20195. }
  20196. var flipped = false;
  20197. if (a.size === undefined) {
  20198. if (b.size === undefined) {
  20199. if (typeof a.cacheResult === 'function') {
  20200. a.cacheResult();
  20201. }
  20202. } else {
  20203. flipped = true;
  20204. var _ = a;
  20205. a = b;
  20206. b = _;
  20207. }
  20208. }
  20209. var allEqual = true;
  20210. var bSize = b.__iterate(function(v, k) {
  20211. if (notAssociative ? !a.has(v) :
  20212. flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
  20213. allEqual = false;
  20214. return false;
  20215. }
  20216. });
  20217. return allEqual && a.size === bSize;
  20218. }
  20219. createClass(Repeat, IndexedSeq);
  20220. function Repeat(value, times) {
  20221. if (!(this instanceof Repeat)) {
  20222. return new Repeat(value, times);
  20223. }
  20224. this._value = value;
  20225. this.size = times === undefined ? Infinity : Math.max(0, times);
  20226. if (this.size === 0) {
  20227. if (EMPTY_REPEAT) {
  20228. return EMPTY_REPEAT;
  20229. }
  20230. EMPTY_REPEAT = this;
  20231. }
  20232. }
  20233. Repeat.prototype.toString = function() {
  20234. if (this.size === 0) {
  20235. return 'Repeat []';
  20236. }
  20237. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  20238. };
  20239. Repeat.prototype.get = function(index, notSetValue) {
  20240. return this.has(index) ? this._value : notSetValue;
  20241. };
  20242. Repeat.prototype.includes = function(searchValue) {
  20243. return is(this._value, searchValue);
  20244. };
  20245. Repeat.prototype.slice = function(begin, end) {
  20246. var size = this.size;
  20247. return wholeSlice(begin, end, size) ? this :
  20248. new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
  20249. };
  20250. Repeat.prototype.reverse = function() {
  20251. return this;
  20252. };
  20253. Repeat.prototype.indexOf = function(searchValue) {
  20254. if (is(this._value, searchValue)) {
  20255. return 0;
  20256. }
  20257. return -1;
  20258. };
  20259. Repeat.prototype.lastIndexOf = function(searchValue) {
  20260. if (is(this._value, searchValue)) {
  20261. return this.size;
  20262. }
  20263. return -1;
  20264. };
  20265. Repeat.prototype.__iterate = function(fn, reverse) {
  20266. for (var ii = 0; ii < this.size; ii++) {
  20267. if (fn(this._value, ii, this) === false) {
  20268. return ii + 1;
  20269. }
  20270. }
  20271. return ii;
  20272. };
  20273. Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
  20274. var ii = 0;
  20275. return new Iterator(function()
  20276. {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
  20277. );
  20278. };
  20279. Repeat.prototype.equals = function(other) {
  20280. return other instanceof Repeat ?
  20281. is(this._value, other._value) :
  20282. deepEqual(other);
  20283. };
  20284. var EMPTY_REPEAT;
  20285. function invariant(condition, error) {
  20286. if (!condition) throw new Error(error);
  20287. }
  20288. createClass(Range, IndexedSeq);
  20289. function Range(start, end, step) {
  20290. if (!(this instanceof Range)) {
  20291. return new Range(start, end, step);
  20292. }
  20293. invariant(step !== 0, 'Cannot step a Range by 0');
  20294. start = start || 0;
  20295. if (end === undefined) {
  20296. end = Infinity;
  20297. }
  20298. step = step === undefined ? 1 : Math.abs(step);
  20299. if (end < start) {
  20300. step = -step;
  20301. }
  20302. this._start = start;
  20303. this._end = end;
  20304. this._step = step;
  20305. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  20306. if (this.size === 0) {
  20307. if (EMPTY_RANGE) {
  20308. return EMPTY_RANGE;
  20309. }
  20310. EMPTY_RANGE = this;
  20311. }
  20312. }
  20313. Range.prototype.toString = function() {
  20314. if (this.size === 0) {
  20315. return 'Range []';
  20316. }
  20317. return 'Range [ ' +
  20318. this._start + '...' + this._end +
  20319. (this._step > 1 ? ' by ' + this._step : '') +
  20320. ' ]';
  20321. };
  20322. Range.prototype.get = function(index, notSetValue) {
  20323. return this.has(index) ?
  20324. this._start + wrapIndex(this, index) * this._step :
  20325. notSetValue;
  20326. };
  20327. Range.prototype.includes = function(searchValue) {
  20328. var possibleIndex = (searchValue - this._start) / this._step;
  20329. return possibleIndex >= 0 &&
  20330. possibleIndex < this.size &&
  20331. possibleIndex === Math.floor(possibleIndex);
  20332. };
  20333. Range.prototype.slice = function(begin, end) {
  20334. if (wholeSlice(begin, end, this.size)) {
  20335. return this;
  20336. }
  20337. begin = resolveBegin(begin, this.size);
  20338. end = resolveEnd(end, this.size);
  20339. if (end <= begin) {
  20340. return new Range(0, 0);
  20341. }
  20342. return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
  20343. };
  20344. Range.prototype.indexOf = function(searchValue) {
  20345. var offsetValue = searchValue - this._start;
  20346. if (offsetValue % this._step === 0) {
  20347. var index = offsetValue / this._step;
  20348. if (index >= 0 && index < this.size) {
  20349. return index
  20350. }
  20351. }
  20352. return -1;
  20353. };
  20354. Range.prototype.lastIndexOf = function(searchValue) {
  20355. return this.indexOf(searchValue);
  20356. };
  20357. Range.prototype.__iterate = function(fn, reverse) {
  20358. var maxIndex = this.size - 1;
  20359. var step = this._step;
  20360. var value = reverse ? this._start + maxIndex * step : this._start;
  20361. for (var ii = 0; ii <= maxIndex; ii++) {
  20362. if (fn(value, ii, this) === false) {
  20363. return ii + 1;
  20364. }
  20365. value += reverse ? -step : step;
  20366. }
  20367. return ii;
  20368. };
  20369. Range.prototype.__iterator = function(type, reverse) {
  20370. var maxIndex = this.size - 1;
  20371. var step = this._step;
  20372. var value = reverse ? this._start + maxIndex * step : this._start;
  20373. var ii = 0;
  20374. return new Iterator(function() {
  20375. var v = value;
  20376. value += reverse ? -step : step;
  20377. return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
  20378. });
  20379. };
  20380. Range.prototype.equals = function(other) {
  20381. return other instanceof Range ?
  20382. this._start === other._start &&
  20383. this._end === other._end &&
  20384. this._step === other._step :
  20385. deepEqual(this, other);
  20386. };
  20387. var EMPTY_RANGE;
  20388. createClass(Collection, Iterable);
  20389. function Collection() {
  20390. throw TypeError('Abstract');
  20391. }
  20392. createClass(KeyedCollection, Collection);function KeyedCollection() {}
  20393. createClass(IndexedCollection, Collection);function IndexedCollection() {}
  20394. createClass(SetCollection, Collection);function SetCollection() {}
  20395. Collection.Keyed = KeyedCollection;
  20396. Collection.Indexed = IndexedCollection;
  20397. Collection.Set = SetCollection;
  20398. var imul =
  20399. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
  20400. Math.imul :
  20401. function imul(a, b) {
  20402. a = a | 0; // int
  20403. b = b | 0; // int
  20404. var c = a & 0xffff;
  20405. var d = b & 0xffff;
  20406. // Shift by 0 fixes the sign on the high part.
  20407. return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int
  20408. };
  20409. // v8 has an optimization for storing 31-bit signed numbers.
  20410. // Values which have either 00 or 11 as the high order bits qualify.
  20411. // This function drops the highest order bit in a signed number, maintaining
  20412. // the sign bit.
  20413. function smi(i32) {
  20414. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
  20415. }
  20416. function hash(o) {
  20417. if (o === false || o === null || o === undefined) {
  20418. return 0;
  20419. }
  20420. if (typeof o.valueOf === 'function') {
  20421. o = o.valueOf();
  20422. if (o === false || o === null || o === undefined) {
  20423. return 0;
  20424. }
  20425. }
  20426. if (o === true) {
  20427. return 1;
  20428. }
  20429. var type = typeof o;
  20430. if (type === 'number') {
  20431. var h = o | 0;
  20432. if (h !== o) {
  20433. h ^= o * 0xFFFFFFFF;
  20434. }
  20435. while (o > 0xFFFFFFFF) {
  20436. o /= 0xFFFFFFFF;
  20437. h ^= o;
  20438. }
  20439. return smi(h);
  20440. }
  20441. if (type === 'string') {
  20442. return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
  20443. }
  20444. if (typeof o.hashCode === 'function') {
  20445. return o.hashCode();
  20446. }
  20447. if (type === 'object') {
  20448. return hashJSObj(o);
  20449. }
  20450. if (typeof o.toString === 'function') {
  20451. return hashString(o.toString());
  20452. }
  20453. throw new Error('Value type ' + type + ' cannot be hashed.');
  20454. }
  20455. function cachedHashString(string) {
  20456. var hash = stringHashCache[string];
  20457. if (hash === undefined) {
  20458. hash = hashString(string);
  20459. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  20460. STRING_HASH_CACHE_SIZE = 0;
  20461. stringHashCache = {};
  20462. }
  20463. STRING_HASH_CACHE_SIZE++;
  20464. stringHashCache[string] = hash;
  20465. }
  20466. return hash;
  20467. }
  20468. // http://jsperf.com/hashing-strings
  20469. function hashString(string) {
  20470. // This is the hash from JVM
  20471. // The hash code for a string is computed as
  20472. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  20473. // where s[i] is the ith character of the string and n is the length of
  20474. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  20475. // (exclusive) by dropping high bits.
  20476. var hash = 0;
  20477. for (var ii = 0; ii < string.length; ii++) {
  20478. hash = 31 * hash + string.charCodeAt(ii) | 0;
  20479. }
  20480. return smi(hash);
  20481. }
  20482. function hashJSObj(obj) {
  20483. var hash;
  20484. if (usingWeakMap) {
  20485. hash = weakMap.get(obj);
  20486. if (hash !== undefined) {
  20487. return hash;
  20488. }
  20489. }
  20490. hash = obj[UID_HASH_KEY];
  20491. if (hash !== undefined) {
  20492. return hash;
  20493. }
  20494. if (!canDefineProperty) {
  20495. hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  20496. if (hash !== undefined) {
  20497. return hash;
  20498. }
  20499. hash = getIENodeHash(obj);
  20500. if (hash !== undefined) {
  20501. return hash;
  20502. }
  20503. }
  20504. hash = ++objHashUID;
  20505. if (objHashUID & 0x40000000) {
  20506. objHashUID = 0;
  20507. }
  20508. if (usingWeakMap) {
  20509. weakMap.set(obj, hash);
  20510. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  20511. throw new Error('Non-extensible objects are not allowed as keys.');
  20512. } else if (canDefineProperty) {
  20513. Object.defineProperty(obj, UID_HASH_KEY, {
  20514. 'enumerable': false,
  20515. 'configurable': false,
  20516. 'writable': false,
  20517. 'value': hash
  20518. });
  20519. } else if (obj.propertyIsEnumerable !== undefined &&
  20520. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
  20521. // Since we can't define a non-enumerable property on the object
  20522. // we'll hijack one of the less-used non-enumerable properties to
  20523. // save our hash on it. Since this is a function it will not show up in
  20524. // `JSON.stringify` which is what we want.
  20525. obj.propertyIsEnumerable = function() {
  20526. return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
  20527. };
  20528. obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
  20529. } else if (obj.nodeType !== undefined) {
  20530. // At this point we couldn't get the IE `uniqueID` to use as a hash
  20531. // and we couldn't use a non-enumerable property to exploit the
  20532. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  20533. // itself.
  20534. obj[UID_HASH_KEY] = hash;
  20535. } else {
  20536. throw new Error('Unable to set a non-enumerable property on object.');
  20537. }
  20538. return hash;
  20539. }
  20540. // Get references to ES5 object methods.
  20541. var isExtensible = Object.isExtensible;
  20542. // True if Object.defineProperty works as expected. IE8 fails this test.
  20543. var canDefineProperty = (function() {
  20544. try {
  20545. Object.defineProperty({}, '@', {});
  20546. return true;
  20547. } catch (e) {
  20548. return false;
  20549. }
  20550. }());
  20551. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  20552. // and avoid memory leaks from the IE cloneNode bug.
  20553. function getIENodeHash(node) {
  20554. if (node && node.nodeType > 0) {
  20555. switch (node.nodeType) {
  20556. case 1: // Element
  20557. return node.uniqueID;
  20558. case 9: // Document
  20559. return node.documentElement && node.documentElement.uniqueID;
  20560. }
  20561. }
  20562. }
  20563. // If possible, use a WeakMap.
  20564. var usingWeakMap = typeof WeakMap === 'function';
  20565. var weakMap;
  20566. if (usingWeakMap) {
  20567. weakMap = new WeakMap();
  20568. }
  20569. var objHashUID = 0;
  20570. var UID_HASH_KEY = '__immutablehash__';
  20571. if (typeof Symbol === 'function') {
  20572. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  20573. }
  20574. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  20575. var STRING_HASH_CACHE_MAX_SIZE = 255;
  20576. var STRING_HASH_CACHE_SIZE = 0;
  20577. var stringHashCache = {};
  20578. function assertNotInfinite(size) {
  20579. invariant(
  20580. size !== Infinity,
  20581. 'Cannot perform this action with an infinite size.'
  20582. );
  20583. }
  20584. createClass(Map, KeyedCollection);
  20585. // @pragma Construction
  20586. function Map(value) {
  20587. return value === null || value === undefined ? emptyMap() :
  20588. isMap(value) && !isOrdered(value) ? value :
  20589. emptyMap().withMutations(function(map ) {
  20590. var iter = KeyedIterable(value);
  20591. assertNotInfinite(iter.size);
  20592. iter.forEach(function(v, k) {return map.set(k, v)});
  20593. });
  20594. }
  20595. Map.prototype.toString = function() {
  20596. return this.__toString('Map {', '}');
  20597. };
  20598. // @pragma Access
  20599. Map.prototype.get = function(k, notSetValue) {
  20600. return this._root ?
  20601. this._root.get(0, undefined, k, notSetValue) :
  20602. notSetValue;
  20603. };
  20604. // @pragma Modification
  20605. Map.prototype.set = function(k, v) {
  20606. return updateMap(this, k, v);
  20607. };
  20608. Map.prototype.setIn = function(keyPath, v) {
  20609. return this.updateIn(keyPath, NOT_SET, function() {return v});
  20610. };
  20611. Map.prototype.remove = function(k) {
  20612. return updateMap(this, k, NOT_SET);
  20613. };
  20614. Map.prototype.deleteIn = function(keyPath) {
  20615. return this.updateIn(keyPath, function() {return NOT_SET});
  20616. };
  20617. Map.prototype.update = function(k, notSetValue, updater) {
  20618. return arguments.length === 1 ?
  20619. k(this) :
  20620. this.updateIn([k], notSetValue, updater);
  20621. };
  20622. Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
  20623. if (!updater) {
  20624. updater = notSetValue;
  20625. notSetValue = undefined;
  20626. }
  20627. var updatedValue = updateInDeepMap(
  20628. this,
  20629. forceIterator(keyPath),
  20630. notSetValue,
  20631. updater
  20632. );
  20633. return updatedValue === NOT_SET ? undefined : updatedValue;
  20634. };
  20635. Map.prototype.clear = function() {
  20636. if (this.size === 0) {
  20637. return this;
  20638. }
  20639. if (this.__ownerID) {
  20640. this.size = 0;
  20641. this._root = null;
  20642. this.__hash = undefined;
  20643. this.__altered = true;
  20644. return this;
  20645. }
  20646. return emptyMap();
  20647. };
  20648. // @pragma Composition
  20649. Map.prototype.merge = function(/*...iters*/) {
  20650. return mergeIntoMapWith(this, undefined, arguments);
  20651. };
  20652. Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  20653. return mergeIntoMapWith(this, merger, iters);
  20654. };
  20655. Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  20656. return this.updateIn(
  20657. keyPath,
  20658. emptyMap(),
  20659. function(m ) {return typeof m.merge === 'function' ?
  20660. m.merge.apply(m, iters) :
  20661. iters[iters.length - 1]}
  20662. );
  20663. };
  20664. Map.prototype.mergeDeep = function(/*...iters*/) {
  20665. return mergeIntoMapWith(this, deepMerger, arguments);
  20666. };
  20667. Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  20668. return mergeIntoMapWith(this, deepMergerWith(merger), iters);
  20669. };
  20670. Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  20671. return this.updateIn(
  20672. keyPath,
  20673. emptyMap(),
  20674. function(m ) {return typeof m.mergeDeep === 'function' ?
  20675. m.mergeDeep.apply(m, iters) :
  20676. iters[iters.length - 1]}
  20677. );
  20678. };
  20679. Map.prototype.sort = function(comparator) {
  20680. // Late binding
  20681. return OrderedMap(sortFactory(this, comparator));
  20682. };
  20683. Map.prototype.sortBy = function(mapper, comparator) {
  20684. // Late binding
  20685. return OrderedMap(sortFactory(this, comparator, mapper));
  20686. };
  20687. // @pragma Mutability
  20688. Map.prototype.withMutations = function(fn) {
  20689. var mutable = this.asMutable();
  20690. fn(mutable);
  20691. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  20692. };
  20693. Map.prototype.asMutable = function() {
  20694. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  20695. };
  20696. Map.prototype.asImmutable = function() {
  20697. return this.__ensureOwner();
  20698. };
  20699. Map.prototype.wasAltered = function() {
  20700. return this.__altered;
  20701. };
  20702. Map.prototype.__iterator = function(type, reverse) {
  20703. return new MapIterator(this, type, reverse);
  20704. };
  20705. Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  20706. var iterations = 0;
  20707. this._root && this._root.iterate(function(entry ) {
  20708. iterations++;
  20709. return fn(entry[1], entry[0], this$0);
  20710. }, reverse);
  20711. return iterations;
  20712. };
  20713. Map.prototype.__ensureOwner = function(ownerID) {
  20714. if (ownerID === this.__ownerID) {
  20715. return this;
  20716. }
  20717. if (!ownerID) {
  20718. this.__ownerID = ownerID;
  20719. this.__altered = false;
  20720. return this;
  20721. }
  20722. return makeMap(this.size, this._root, ownerID, this.__hash);
  20723. };
  20724. function isMap(maybeMap) {
  20725. return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
  20726. }
  20727. Map.isMap = isMap;
  20728. var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
  20729. var MapPrototype = Map.prototype;
  20730. MapPrototype[IS_MAP_SENTINEL] = true;
  20731. MapPrototype[DELETE] = MapPrototype.remove;
  20732. MapPrototype.removeIn = MapPrototype.deleteIn;
  20733. // #pragma Trie Nodes
  20734. function ArrayMapNode(ownerID, entries) {
  20735. this.ownerID = ownerID;
  20736. this.entries = entries;
  20737. }
  20738. ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  20739. var entries = this.entries;
  20740. for (var ii = 0, len = entries.length; ii < len; ii++) {
  20741. if (is(key, entries[ii][0])) {
  20742. return entries[ii][1];
  20743. }
  20744. }
  20745. return notSetValue;
  20746. };
  20747. ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  20748. var removed = value === NOT_SET;
  20749. var entries = this.entries;
  20750. var idx = 0;
  20751. for (var len = entries.length; idx < len; idx++) {
  20752. if (is(key, entries[idx][0])) {
  20753. break;
  20754. }
  20755. }
  20756. var exists = idx < len;
  20757. if (exists ? entries[idx][1] === value : removed) {
  20758. return this;
  20759. }
  20760. SetRef(didAlter);
  20761. (removed || !exists) && SetRef(didChangeSize);
  20762. if (removed && entries.length === 1) {
  20763. return; // undefined
  20764. }
  20765. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  20766. return createNodes(ownerID, entries, key, value);
  20767. }
  20768. var isEditable = ownerID && ownerID === this.ownerID;
  20769. var newEntries = isEditable ? entries : arrCopy(entries);
  20770. if (exists) {
  20771. if (removed) {
  20772. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  20773. } else {
  20774. newEntries[idx] = [key, value];
  20775. }
  20776. } else {
  20777. newEntries.push([key, value]);
  20778. }
  20779. if (isEditable) {
  20780. this.entries = newEntries;
  20781. return this;
  20782. }
  20783. return new ArrayMapNode(ownerID, newEntries);
  20784. };
  20785. function BitmapIndexedNode(ownerID, bitmap, nodes) {
  20786. this.ownerID = ownerID;
  20787. this.bitmap = bitmap;
  20788. this.nodes = nodes;
  20789. }
  20790. BitmapIndexedNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  20791. if (keyHash === undefined) {
  20792. keyHash = hash(key);
  20793. }
  20794. var bit = (1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK));
  20795. var bitmap = this.bitmap;
  20796. return (bitmap & bit) === 0 ? notSetValue :
  20797. this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue);
  20798. };
  20799. BitmapIndexedNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  20800. if (keyHash === undefined) {
  20801. keyHash = hash(key);
  20802. }
  20803. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  20804. var bit = 1 << keyHashFrag;
  20805. var bitmap = this.bitmap;
  20806. var exists = (bitmap & bit) !== 0;
  20807. if (!exists && value === NOT_SET) {
  20808. return this;
  20809. }
  20810. var idx = popCount(bitmap & (bit - 1));
  20811. var nodes = this.nodes;
  20812. var node = exists ? nodes[idx] : undefined;
  20813. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  20814. if (newNode === node) {
  20815. return this;
  20816. }
  20817. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  20818. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  20819. }
  20820. if (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) {
  20821. return nodes[idx ^ 1];
  20822. }
  20823. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  20824. return newNode;
  20825. }
  20826. var isEditable = ownerID && ownerID === this.ownerID;
  20827. var newBitmap = exists ? newNode ? bitmap : bitmap ^ bit : bitmap | bit;
  20828. var newNodes = exists ? newNode ?
  20829. setIn(nodes, idx, newNode, isEditable) :
  20830. spliceOut(nodes, idx, isEditable) :
  20831. spliceIn(nodes, idx, newNode, isEditable);
  20832. if (isEditable) {
  20833. this.bitmap = newBitmap;
  20834. this.nodes = newNodes;
  20835. return this;
  20836. }
  20837. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  20838. };
  20839. function HashArrayMapNode(ownerID, count, nodes) {
  20840. this.ownerID = ownerID;
  20841. this.count = count;
  20842. this.nodes = nodes;
  20843. }
  20844. HashArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  20845. if (keyHash === undefined) {
  20846. keyHash = hash(key);
  20847. }
  20848. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  20849. var node = this.nodes[idx];
  20850. return node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue;
  20851. };
  20852. HashArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  20853. if (keyHash === undefined) {
  20854. keyHash = hash(key);
  20855. }
  20856. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  20857. var removed = value === NOT_SET;
  20858. var nodes = this.nodes;
  20859. var node = nodes[idx];
  20860. if (removed && !node) {
  20861. return this;
  20862. }
  20863. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  20864. if (newNode === node) {
  20865. return this;
  20866. }
  20867. var newCount = this.count;
  20868. if (!node) {
  20869. newCount++;
  20870. } else if (!newNode) {
  20871. newCount--;
  20872. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  20873. return packNodes(ownerID, nodes, newCount, idx);
  20874. }
  20875. }
  20876. var isEditable = ownerID && ownerID === this.ownerID;
  20877. var newNodes = setIn(nodes, idx, newNode, isEditable);
  20878. if (isEditable) {
  20879. this.count = newCount;
  20880. this.nodes = newNodes;
  20881. return this;
  20882. }
  20883. return new HashArrayMapNode(ownerID, newCount, newNodes);
  20884. };
  20885. function HashCollisionNode(ownerID, keyHash, entries) {
  20886. this.ownerID = ownerID;
  20887. this.keyHash = keyHash;
  20888. this.entries = entries;
  20889. }
  20890. HashCollisionNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  20891. var entries = this.entries;
  20892. for (var ii = 0, len = entries.length; ii < len; ii++) {
  20893. if (is(key, entries[ii][0])) {
  20894. return entries[ii][1];
  20895. }
  20896. }
  20897. return notSetValue;
  20898. };
  20899. HashCollisionNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  20900. if (keyHash === undefined) {
  20901. keyHash = hash(key);
  20902. }
  20903. var removed = value === NOT_SET;
  20904. if (keyHash !== this.keyHash) {
  20905. if (removed) {
  20906. return this;
  20907. }
  20908. SetRef(didAlter);
  20909. SetRef(didChangeSize);
  20910. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  20911. }
  20912. var entries = this.entries;
  20913. var idx = 0;
  20914. for (var len = entries.length; idx < len; idx++) {
  20915. if (is(key, entries[idx][0])) {
  20916. break;
  20917. }
  20918. }
  20919. var exists = idx < len;
  20920. if (exists ? entries[idx][1] === value : removed) {
  20921. return this;
  20922. }
  20923. SetRef(didAlter);
  20924. (removed || !exists) && SetRef(didChangeSize);
  20925. if (removed && len === 2) {
  20926. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  20927. }
  20928. var isEditable = ownerID && ownerID === this.ownerID;
  20929. var newEntries = isEditable ? entries : arrCopy(entries);
  20930. if (exists) {
  20931. if (removed) {
  20932. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  20933. } else {
  20934. newEntries[idx] = [key, value];
  20935. }
  20936. } else {
  20937. newEntries.push([key, value]);
  20938. }
  20939. if (isEditable) {
  20940. this.entries = newEntries;
  20941. return this;
  20942. }
  20943. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  20944. };
  20945. function ValueNode(ownerID, keyHash, entry) {
  20946. this.ownerID = ownerID;
  20947. this.keyHash = keyHash;
  20948. this.entry = entry;
  20949. }
  20950. ValueNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  20951. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  20952. };
  20953. ValueNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  20954. var removed = value === NOT_SET;
  20955. var keyMatch = is(key, this.entry[0]);
  20956. if (keyMatch ? value === this.entry[1] : removed) {
  20957. return this;
  20958. }
  20959. SetRef(didAlter);
  20960. if (removed) {
  20961. SetRef(didChangeSize);
  20962. return; // undefined
  20963. }
  20964. if (keyMatch) {
  20965. if (ownerID && ownerID === this.ownerID) {
  20966. this.entry[1] = value;
  20967. return this;
  20968. }
  20969. return new ValueNode(ownerID, this.keyHash, [key, value]);
  20970. }
  20971. SetRef(didChangeSize);
  20972. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  20973. };
  20974. // #pragma Iterators
  20975. ArrayMapNode.prototype.iterate =
  20976. HashCollisionNode.prototype.iterate = function (fn, reverse) {
  20977. var entries = this.entries;
  20978. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  20979. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  20980. return false;
  20981. }
  20982. }
  20983. };
  20984. BitmapIndexedNode.prototype.iterate =
  20985. HashArrayMapNode.prototype.iterate = function (fn, reverse) {
  20986. var nodes = this.nodes;
  20987. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  20988. var node = nodes[reverse ? maxIndex - ii : ii];
  20989. if (node && node.iterate(fn, reverse) === false) {
  20990. return false;
  20991. }
  20992. }
  20993. };
  20994. ValueNode.prototype.iterate = function (fn, reverse) {
  20995. return fn(this.entry);
  20996. };
  20997. createClass(MapIterator, Iterator);
  20998. function MapIterator(map, type, reverse) {
  20999. this._type = type;
  21000. this._reverse = reverse;
  21001. this._stack = map._root && mapIteratorFrame(map._root);
  21002. }
  21003. MapIterator.prototype.next = function() {
  21004. var type = this._type;
  21005. var stack = this._stack;
  21006. while (stack) {
  21007. var node = stack.node;
  21008. var index = stack.index++;
  21009. var maxIndex;
  21010. if (node.entry) {
  21011. if (index === 0) {
  21012. return mapIteratorValue(type, node.entry);
  21013. }
  21014. } else if (node.entries) {
  21015. maxIndex = node.entries.length - 1;
  21016. if (index <= maxIndex) {
  21017. return mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index]);
  21018. }
  21019. } else {
  21020. maxIndex = node.nodes.length - 1;
  21021. if (index <= maxIndex) {
  21022. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  21023. if (subNode) {
  21024. if (subNode.entry) {
  21025. return mapIteratorValue(type, subNode.entry);
  21026. }
  21027. stack = this._stack = mapIteratorFrame(subNode, stack);
  21028. }
  21029. continue;
  21030. }
  21031. }
  21032. stack = this._stack = this._stack.__prev;
  21033. }
  21034. return iteratorDone();
  21035. };
  21036. function mapIteratorValue(type, entry) {
  21037. return iteratorValue(type, entry[0], entry[1]);
  21038. }
  21039. function mapIteratorFrame(node, prev) {
  21040. return {
  21041. node: node,
  21042. index: 0,
  21043. __prev: prev
  21044. };
  21045. }
  21046. function makeMap(size, root, ownerID, hash) {
  21047. var map = Object.create(MapPrototype);
  21048. map.size = size;
  21049. map._root = root;
  21050. map.__ownerID = ownerID;
  21051. map.__hash = hash;
  21052. map.__altered = false;
  21053. return map;
  21054. }
  21055. var EMPTY_MAP;
  21056. function emptyMap() {
  21057. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  21058. }
  21059. function updateMap(map, k, v) {
  21060. var newRoot;
  21061. var newSize;
  21062. if (!map._root) {
  21063. if (v === NOT_SET) {
  21064. return map;
  21065. }
  21066. newSize = 1;
  21067. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  21068. } else {
  21069. var didChangeSize = MakeRef(CHANGE_LENGTH);
  21070. var didAlter = MakeRef(DID_ALTER);
  21071. newRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter);
  21072. if (!didAlter.value) {
  21073. return map;
  21074. }
  21075. newSize = map.size + (didChangeSize.value ? v === NOT_SET ? -1 : 1 : 0);
  21076. }
  21077. if (map.__ownerID) {
  21078. map.size = newSize;
  21079. map._root = newRoot;
  21080. map.__hash = undefined;
  21081. map.__altered = true;
  21082. return map;
  21083. }
  21084. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  21085. }
  21086. function updateNode(node, ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  21087. if (!node) {
  21088. if (value === NOT_SET) {
  21089. return node;
  21090. }
  21091. SetRef(didAlter);
  21092. SetRef(didChangeSize);
  21093. return new ValueNode(ownerID, keyHash, [key, value]);
  21094. }
  21095. return node.update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter);
  21096. }
  21097. function isLeafNode(node) {
  21098. return node.constructor === ValueNode || node.constructor === HashCollisionNode;
  21099. }
  21100. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  21101. if (node.keyHash === keyHash) {
  21102. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  21103. }
  21104. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  21105. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  21106. var newNode;
  21107. var nodes = idx1 === idx2 ?
  21108. [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)] :
  21109. ((newNode = new ValueNode(ownerID, keyHash, entry)), idx1 < idx2 ? [node, newNode] : [newNode, node]);
  21110. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  21111. }
  21112. function createNodes(ownerID, entries, key, value) {
  21113. if (!ownerID) {
  21114. ownerID = new OwnerID();
  21115. }
  21116. var node = new ValueNode(ownerID, hash(key), [key, value]);
  21117. for (var ii = 0; ii < entries.length; ii++) {
  21118. var entry = entries[ii];
  21119. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  21120. }
  21121. return node;
  21122. }
  21123. function packNodes(ownerID, nodes, count, excluding) {
  21124. var bitmap = 0;
  21125. var packedII = 0;
  21126. var packedNodes = new Array(count);
  21127. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  21128. var node = nodes[ii];
  21129. if (node !== undefined && ii !== excluding) {
  21130. bitmap |= bit;
  21131. packedNodes[packedII++] = node;
  21132. }
  21133. }
  21134. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  21135. }
  21136. function expandNodes(ownerID, nodes, bitmap, including, node) {
  21137. var count = 0;
  21138. var expandedNodes = new Array(SIZE);
  21139. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  21140. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  21141. }
  21142. expandedNodes[including] = node;
  21143. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  21144. }
  21145. function mergeIntoMapWith(map, merger, iterables) {
  21146. var iters = [];
  21147. for (var ii = 0; ii < iterables.length; ii++) {
  21148. var value = iterables[ii];
  21149. var iter = KeyedIterable(value);
  21150. if (!isIterable(value)) {
  21151. iter = iter.map(function(v ) {return fromJS(v)});
  21152. }
  21153. iters.push(iter);
  21154. }
  21155. return mergeIntoCollectionWith(map, merger, iters);
  21156. }
  21157. function deepMerger(existing, value, key) {
  21158. return existing && existing.mergeDeep && isIterable(value) ?
  21159. existing.mergeDeep(value) :
  21160. is(existing, value) ? existing : value;
  21161. }
  21162. function deepMergerWith(merger) {
  21163. return function(existing, value, key) {
  21164. if (existing && existing.mergeDeepWith && isIterable(value)) {
  21165. return existing.mergeDeepWith(merger, value);
  21166. }
  21167. var nextValue = merger(existing, value, key);
  21168. return is(existing, nextValue) ? existing : nextValue;
  21169. };
  21170. }
  21171. function mergeIntoCollectionWith(collection, merger, iters) {
  21172. iters = iters.filter(function(x ) {return x.size !== 0});
  21173. if (iters.length === 0) {
  21174. return collection;
  21175. }
  21176. if (collection.size === 0 && !collection.__ownerID && iters.length === 1) {
  21177. return collection.constructor(iters[0]);
  21178. }
  21179. return collection.withMutations(function(collection ) {
  21180. var mergeIntoMap = merger ?
  21181. function(value, key) {
  21182. collection.update(key, NOT_SET, function(existing )
  21183. {return existing === NOT_SET ? value : merger(existing, value, key)}
  21184. );
  21185. } :
  21186. function(value, key) {
  21187. collection.set(key, value);
  21188. };
  21189. for (var ii = 0; ii < iters.length; ii++) {
  21190. iters[ii].forEach(mergeIntoMap);
  21191. }
  21192. });
  21193. }
  21194. function updateInDeepMap(existing, keyPathIter, notSetValue, updater) {
  21195. var isNotSet = existing === NOT_SET;
  21196. var step = keyPathIter.next();
  21197. if (step.done) {
  21198. var existingValue = isNotSet ? notSetValue : existing;
  21199. var newValue = updater(existingValue);
  21200. return newValue === existingValue ? existing : newValue;
  21201. }
  21202. invariant(
  21203. isNotSet || (existing && existing.set),
  21204. 'invalid keyPath'
  21205. );
  21206. var key = step.value;
  21207. var nextExisting = isNotSet ? NOT_SET : existing.get(key, NOT_SET);
  21208. var nextUpdated = updateInDeepMap(
  21209. nextExisting,
  21210. keyPathIter,
  21211. notSetValue,
  21212. updater
  21213. );
  21214. return nextUpdated === nextExisting ? existing :
  21215. nextUpdated === NOT_SET ? existing.remove(key) :
  21216. (isNotSet ? emptyMap() : existing).set(key, nextUpdated);
  21217. }
  21218. function popCount(x) {
  21219. x = x - ((x >> 1) & 0x55555555);
  21220. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  21221. x = (x + (x >> 4)) & 0x0f0f0f0f;
  21222. x = x + (x >> 8);
  21223. x = x + (x >> 16);
  21224. return x & 0x7f;
  21225. }
  21226. function setIn(array, idx, val, canEdit) {
  21227. var newArray = canEdit ? array : arrCopy(array);
  21228. newArray[idx] = val;
  21229. return newArray;
  21230. }
  21231. function spliceIn(array, idx, val, canEdit) {
  21232. var newLen = array.length + 1;
  21233. if (canEdit && idx + 1 === newLen) {
  21234. array[idx] = val;
  21235. return array;
  21236. }
  21237. var newArray = new Array(newLen);
  21238. var after = 0;
  21239. for (var ii = 0; ii < newLen; ii++) {
  21240. if (ii === idx) {
  21241. newArray[ii] = val;
  21242. after = -1;
  21243. } else {
  21244. newArray[ii] = array[ii + after];
  21245. }
  21246. }
  21247. return newArray;
  21248. }
  21249. function spliceOut(array, idx, canEdit) {
  21250. var newLen = array.length - 1;
  21251. if (canEdit && idx === newLen) {
  21252. array.pop();
  21253. return array;
  21254. }
  21255. var newArray = new Array(newLen);
  21256. var after = 0;
  21257. for (var ii = 0; ii < newLen; ii++) {
  21258. if (ii === idx) {
  21259. after = 1;
  21260. }
  21261. newArray[ii] = array[ii + after];
  21262. }
  21263. return newArray;
  21264. }
  21265. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  21266. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  21267. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  21268. createClass(List, IndexedCollection);
  21269. // @pragma Construction
  21270. function List(value) {
  21271. var empty = emptyList();
  21272. if (value === null || value === undefined) {
  21273. return empty;
  21274. }
  21275. if (isList(value)) {
  21276. return value;
  21277. }
  21278. var iter = IndexedIterable(value);
  21279. var size = iter.size;
  21280. if (size === 0) {
  21281. return empty;
  21282. }
  21283. assertNotInfinite(size);
  21284. if (size > 0 && size < SIZE) {
  21285. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  21286. }
  21287. return empty.withMutations(function(list ) {
  21288. list.setSize(size);
  21289. iter.forEach(function(v, i) {return list.set(i, v)});
  21290. });
  21291. }
  21292. List.of = function(/*...values*/) {
  21293. return this(arguments);
  21294. };
  21295. List.prototype.toString = function() {
  21296. return this.__toString('List [', ']');
  21297. };
  21298. // @pragma Access
  21299. List.prototype.get = function(index, notSetValue) {
  21300. index = wrapIndex(this, index);
  21301. if (index >= 0 && index < this.size) {
  21302. index += this._origin;
  21303. var node = listNodeFor(this, index);
  21304. return node && node.array[index & MASK];
  21305. }
  21306. return notSetValue;
  21307. };
  21308. // @pragma Modification
  21309. List.prototype.set = function(index, value) {
  21310. return updateList(this, index, value);
  21311. };
  21312. List.prototype.remove = function(index) {
  21313. return !this.has(index) ? this :
  21314. index === 0 ? this.shift() :
  21315. index === this.size - 1 ? this.pop() :
  21316. this.splice(index, 1);
  21317. };
  21318. List.prototype.insert = function(index, value) {
  21319. return this.splice(index, 0, value);
  21320. };
  21321. List.prototype.clear = function() {
  21322. if (this.size === 0) {
  21323. return this;
  21324. }
  21325. if (this.__ownerID) {
  21326. this.size = this._origin = this._capacity = 0;
  21327. this._level = SHIFT;
  21328. this._root = this._tail = null;
  21329. this.__hash = undefined;
  21330. this.__altered = true;
  21331. return this;
  21332. }
  21333. return emptyList();
  21334. };
  21335. List.prototype.push = function(/*...values*/) {
  21336. var values = arguments;
  21337. var oldSize = this.size;
  21338. return this.withMutations(function(list ) {
  21339. setListBounds(list, 0, oldSize + values.length);
  21340. for (var ii = 0; ii < values.length; ii++) {
  21341. list.set(oldSize + ii, values[ii]);
  21342. }
  21343. });
  21344. };
  21345. List.prototype.pop = function() {
  21346. return setListBounds(this, 0, -1);
  21347. };
  21348. List.prototype.unshift = function(/*...values*/) {
  21349. var values = arguments;
  21350. return this.withMutations(function(list ) {
  21351. setListBounds(list, -values.length);
  21352. for (var ii = 0; ii < values.length; ii++) {
  21353. list.set(ii, values[ii]);
  21354. }
  21355. });
  21356. };
  21357. List.prototype.shift = function() {
  21358. return setListBounds(this, 1);
  21359. };
  21360. // @pragma Composition
  21361. List.prototype.merge = function(/*...iters*/) {
  21362. return mergeIntoListWith(this, undefined, arguments);
  21363. };
  21364. List.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  21365. return mergeIntoListWith(this, merger, iters);
  21366. };
  21367. List.prototype.mergeDeep = function(/*...iters*/) {
  21368. return mergeIntoListWith(this, deepMerger, arguments);
  21369. };
  21370. List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  21371. return mergeIntoListWith(this, deepMergerWith(merger), iters);
  21372. };
  21373. List.prototype.setSize = function(size) {
  21374. return setListBounds(this, 0, size);
  21375. };
  21376. // @pragma Iteration
  21377. List.prototype.slice = function(begin, end) {
  21378. var size = this.size;
  21379. if (wholeSlice(begin, end, size)) {
  21380. return this;
  21381. }
  21382. return setListBounds(
  21383. this,
  21384. resolveBegin(begin, size),
  21385. resolveEnd(end, size)
  21386. );
  21387. };
  21388. List.prototype.__iterator = function(type, reverse) {
  21389. var index = 0;
  21390. var values = iterateList(this, reverse);
  21391. return new Iterator(function() {
  21392. var value = values();
  21393. return value === DONE ?
  21394. iteratorDone() :
  21395. iteratorValue(type, index++, value);
  21396. });
  21397. };
  21398. List.prototype.__iterate = function(fn, reverse) {
  21399. var index = 0;
  21400. var values = iterateList(this, reverse);
  21401. var value;
  21402. while ((value = values()) !== DONE) {
  21403. if (fn(value, index++, this) === false) {
  21404. break;
  21405. }
  21406. }
  21407. return index;
  21408. };
  21409. List.prototype.__ensureOwner = function(ownerID) {
  21410. if (ownerID === this.__ownerID) {
  21411. return this;
  21412. }
  21413. if (!ownerID) {
  21414. this.__ownerID = ownerID;
  21415. return this;
  21416. }
  21417. return makeList(this._origin, this._capacity, this._level, this._root, this._tail, ownerID, this.__hash);
  21418. };
  21419. function isList(maybeList) {
  21420. return !!(maybeList && maybeList[IS_LIST_SENTINEL]);
  21421. }
  21422. List.isList = isList;
  21423. var IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
  21424. var ListPrototype = List.prototype;
  21425. ListPrototype[IS_LIST_SENTINEL] = true;
  21426. ListPrototype[DELETE] = ListPrototype.remove;
  21427. ListPrototype.setIn = MapPrototype.setIn;
  21428. ListPrototype.deleteIn =
  21429. ListPrototype.removeIn = MapPrototype.removeIn;
  21430. ListPrototype.update = MapPrototype.update;
  21431. ListPrototype.updateIn = MapPrototype.updateIn;
  21432. ListPrototype.mergeIn = MapPrototype.mergeIn;
  21433. ListPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  21434. ListPrototype.withMutations = MapPrototype.withMutations;
  21435. ListPrototype.asMutable = MapPrototype.asMutable;
  21436. ListPrototype.asImmutable = MapPrototype.asImmutable;
  21437. ListPrototype.wasAltered = MapPrototype.wasAltered;
  21438. function VNode(array, ownerID) {
  21439. this.array = array;
  21440. this.ownerID = ownerID;
  21441. }
  21442. // TODO: seems like these methods are very similar
  21443. VNode.prototype.removeBefore = function(ownerID, level, index) {
  21444. if (index === level ? 1 << level : this.array.length === 0) {
  21445. return this;
  21446. }
  21447. var originIndex = (index >>> level) & MASK;
  21448. if (originIndex >= this.array.length) {
  21449. return new VNode([], ownerID);
  21450. }
  21451. var removingFirst = originIndex === 0;
  21452. var newChild;
  21453. if (level > 0) {
  21454. var oldChild = this.array[originIndex];
  21455. newChild = oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  21456. if (newChild === oldChild && removingFirst) {
  21457. return this;
  21458. }
  21459. }
  21460. if (removingFirst && !newChild) {
  21461. return this;
  21462. }
  21463. var editable = editableVNode(this, ownerID);
  21464. if (!removingFirst) {
  21465. for (var ii = 0; ii < originIndex; ii++) {
  21466. editable.array[ii] = undefined;
  21467. }
  21468. }
  21469. if (newChild) {
  21470. editable.array[originIndex] = newChild;
  21471. }
  21472. return editable;
  21473. };
  21474. VNode.prototype.removeAfter = function(ownerID, level, index) {
  21475. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  21476. return this;
  21477. }
  21478. var sizeIndex = ((index - 1) >>> level) & MASK;
  21479. if (sizeIndex >= this.array.length) {
  21480. return this;
  21481. }
  21482. var newChild;
  21483. if (level > 0) {
  21484. var oldChild = this.array[sizeIndex];
  21485. newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  21486. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  21487. return this;
  21488. }
  21489. }
  21490. var editable = editableVNode(this, ownerID);
  21491. editable.array.splice(sizeIndex + 1);
  21492. if (newChild) {
  21493. editable.array[sizeIndex] = newChild;
  21494. }
  21495. return editable;
  21496. };
  21497. var DONE = {};
  21498. function iterateList(list, reverse) {
  21499. var left = list._origin;
  21500. var right = list._capacity;
  21501. var tailPos = getTailOffset(right);
  21502. var tail = list._tail;
  21503. return iterateNodeOrLeaf(list._root, list._level, 0);
  21504. function iterateNodeOrLeaf(node, level, offset) {
  21505. return level === 0 ?
  21506. iterateLeaf(node, offset) :
  21507. iterateNode(node, level, offset);
  21508. }
  21509. function iterateLeaf(node, offset) {
  21510. var array = offset === tailPos ? tail && tail.array : node && node.array;
  21511. var from = offset > left ? 0 : left - offset;
  21512. var to = right - offset;
  21513. if (to > SIZE) {
  21514. to = SIZE;
  21515. }
  21516. return function() {
  21517. if (from === to) {
  21518. return DONE;
  21519. }
  21520. var idx = reverse ? --to : from++;
  21521. return array && array[idx];
  21522. };
  21523. }
  21524. function iterateNode(node, level, offset) {
  21525. var values;
  21526. var array = node && node.array;
  21527. var from = offset > left ? 0 : (left - offset) >> level;
  21528. var to = ((right - offset) >> level) + 1;
  21529. if (to > SIZE) {
  21530. to = SIZE;
  21531. }
  21532. return function() {
  21533. do {
  21534. if (values) {
  21535. var value = values();
  21536. if (value !== DONE) {
  21537. return value;
  21538. }
  21539. values = null;
  21540. }
  21541. if (from === to) {
  21542. return DONE;
  21543. }
  21544. var idx = reverse ? --to : from++;
  21545. values = iterateNodeOrLeaf(
  21546. array && array[idx], level - SHIFT, offset + (idx << level)
  21547. );
  21548. } while (true);
  21549. };
  21550. }
  21551. }
  21552. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  21553. var list = Object.create(ListPrototype);
  21554. list.size = capacity - origin;
  21555. list._origin = origin;
  21556. list._capacity = capacity;
  21557. list._level = level;
  21558. list._root = root;
  21559. list._tail = tail;
  21560. list.__ownerID = ownerID;
  21561. list.__hash = hash;
  21562. list.__altered = false;
  21563. return list;
  21564. }
  21565. var EMPTY_LIST;
  21566. function emptyList() {
  21567. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  21568. }
  21569. function updateList(list, index, value) {
  21570. index = wrapIndex(list, index);
  21571. if (index !== index) {
  21572. return list;
  21573. }
  21574. if (index >= list.size || index < 0) {
  21575. return list.withMutations(function(list ) {
  21576. index < 0 ?
  21577. setListBounds(list, index).set(0, value) :
  21578. setListBounds(list, 0, index + 1).set(index, value);
  21579. });
  21580. }
  21581. index += list._origin;
  21582. var newTail = list._tail;
  21583. var newRoot = list._root;
  21584. var didAlter = MakeRef(DID_ALTER);
  21585. if (index >= getTailOffset(list._capacity)) {
  21586. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  21587. } else {
  21588. newRoot = updateVNode(newRoot, list.__ownerID, list._level, index, value, didAlter);
  21589. }
  21590. if (!didAlter.value) {
  21591. return list;
  21592. }
  21593. if (list.__ownerID) {
  21594. list._root = newRoot;
  21595. list._tail = newTail;
  21596. list.__hash = undefined;
  21597. list.__altered = true;
  21598. return list;
  21599. }
  21600. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  21601. }
  21602. function updateVNode(node, ownerID, level, index, value, didAlter) {
  21603. var idx = (index >>> level) & MASK;
  21604. var nodeHas = node && idx < node.array.length;
  21605. if (!nodeHas && value === undefined) {
  21606. return node;
  21607. }
  21608. var newNode;
  21609. if (level > 0) {
  21610. var lowerNode = node && node.array[idx];
  21611. var newLowerNode = updateVNode(lowerNode, ownerID, level - SHIFT, index, value, didAlter);
  21612. if (newLowerNode === lowerNode) {
  21613. return node;
  21614. }
  21615. newNode = editableVNode(node, ownerID);
  21616. newNode.array[idx] = newLowerNode;
  21617. return newNode;
  21618. }
  21619. if (nodeHas && node.array[idx] === value) {
  21620. return node;
  21621. }
  21622. SetRef(didAlter);
  21623. newNode = editableVNode(node, ownerID);
  21624. if (value === undefined && idx === newNode.array.length - 1) {
  21625. newNode.array.pop();
  21626. } else {
  21627. newNode.array[idx] = value;
  21628. }
  21629. return newNode;
  21630. }
  21631. function editableVNode(node, ownerID) {
  21632. if (ownerID && node && ownerID === node.ownerID) {
  21633. return node;
  21634. }
  21635. return new VNode(node ? node.array.slice() : [], ownerID);
  21636. }
  21637. function listNodeFor(list, rawIndex) {
  21638. if (rawIndex >= getTailOffset(list._capacity)) {
  21639. return list._tail;
  21640. }
  21641. if (rawIndex < 1 << (list._level + SHIFT)) {
  21642. var node = list._root;
  21643. var level = list._level;
  21644. while (node && level > 0) {
  21645. node = node.array[(rawIndex >>> level) & MASK];
  21646. level -= SHIFT;
  21647. }
  21648. return node;
  21649. }
  21650. }
  21651. function setListBounds(list, begin, end) {
  21652. // Sanitize begin & end using this shorthand for ToInt32(argument)
  21653. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  21654. if (begin !== undefined) {
  21655. begin = begin | 0;
  21656. }
  21657. if (end !== undefined) {
  21658. end = end | 0;
  21659. }
  21660. var owner = list.__ownerID || new OwnerID();
  21661. var oldOrigin = list._origin;
  21662. var oldCapacity = list._capacity;
  21663. var newOrigin = oldOrigin + begin;
  21664. var newCapacity = end === undefined ? oldCapacity : end < 0 ? oldCapacity + end : oldOrigin + end;
  21665. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  21666. return list;
  21667. }
  21668. // If it's going to end after it starts, it's empty.
  21669. if (newOrigin >= newCapacity) {
  21670. return list.clear();
  21671. }
  21672. var newLevel = list._level;
  21673. var newRoot = list._root;
  21674. // New origin might need creating a higher root.
  21675. var offsetShift = 0;
  21676. while (newOrigin + offsetShift < 0) {
  21677. newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner);
  21678. newLevel += SHIFT;
  21679. offsetShift += 1 << newLevel;
  21680. }
  21681. if (offsetShift) {
  21682. newOrigin += offsetShift;
  21683. oldOrigin += offsetShift;
  21684. newCapacity += offsetShift;
  21685. oldCapacity += offsetShift;
  21686. }
  21687. var oldTailOffset = getTailOffset(oldCapacity);
  21688. var newTailOffset = getTailOffset(newCapacity);
  21689. // New size might need creating a higher root.
  21690. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  21691. newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner);
  21692. newLevel += SHIFT;
  21693. }
  21694. // Locate or create the new tail.
  21695. var oldTail = list._tail;
  21696. var newTail = newTailOffset < oldTailOffset ?
  21697. listNodeFor(list, newCapacity - 1) :
  21698. newTailOffset > oldTailOffset ? new VNode([], owner) : oldTail;
  21699. // Merge Tail into tree.
  21700. if (oldTail && newTailOffset > oldTailOffset && newOrigin < oldCapacity && oldTail.array.length) {
  21701. newRoot = editableVNode(newRoot, owner);
  21702. var node = newRoot;
  21703. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  21704. var idx = (oldTailOffset >>> level) & MASK;
  21705. node = node.array[idx] = editableVNode(node.array[idx], owner);
  21706. }
  21707. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  21708. }
  21709. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  21710. if (newCapacity < oldCapacity) {
  21711. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  21712. }
  21713. // If the new origin is within the tail, then we do not need a root.
  21714. if (newOrigin >= newTailOffset) {
  21715. newOrigin -= newTailOffset;
  21716. newCapacity -= newTailOffset;
  21717. newLevel = SHIFT;
  21718. newRoot = null;
  21719. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  21720. // Otherwise, if the root has been trimmed, garbage collect.
  21721. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  21722. offsetShift = 0;
  21723. // Identify the new top root node of the subtree of the old root.
  21724. while (newRoot) {
  21725. var beginIndex = (newOrigin >>> newLevel) & MASK;
  21726. if (beginIndex !== (newTailOffset >>> newLevel) & MASK) {
  21727. break;
  21728. }
  21729. if (beginIndex) {
  21730. offsetShift += (1 << newLevel) * beginIndex;
  21731. }
  21732. newLevel -= SHIFT;
  21733. newRoot = newRoot.array[beginIndex];
  21734. }
  21735. // Trim the new sides of the new root.
  21736. if (newRoot && newOrigin > oldOrigin) {
  21737. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  21738. }
  21739. if (newRoot && newTailOffset < oldTailOffset) {
  21740. newRoot = newRoot.removeAfter(owner, newLevel, newTailOffset - offsetShift);
  21741. }
  21742. if (offsetShift) {
  21743. newOrigin -= offsetShift;
  21744. newCapacity -= offsetShift;
  21745. }
  21746. }
  21747. if (list.__ownerID) {
  21748. list.size = newCapacity - newOrigin;
  21749. list._origin = newOrigin;
  21750. list._capacity = newCapacity;
  21751. list._level = newLevel;
  21752. list._root = newRoot;
  21753. list._tail = newTail;
  21754. list.__hash = undefined;
  21755. list.__altered = true;
  21756. return list;
  21757. }
  21758. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  21759. }
  21760. function mergeIntoListWith(list, merger, iterables) {
  21761. var iters = [];
  21762. var maxSize = 0;
  21763. for (var ii = 0; ii < iterables.length; ii++) {
  21764. var value = iterables[ii];
  21765. var iter = IndexedIterable(value);
  21766. if (iter.size > maxSize) {
  21767. maxSize = iter.size;
  21768. }
  21769. if (!isIterable(value)) {
  21770. iter = iter.map(function(v ) {return fromJS(v)});
  21771. }
  21772. iters.push(iter);
  21773. }
  21774. if (maxSize > list.size) {
  21775. list = list.setSize(maxSize);
  21776. }
  21777. return mergeIntoCollectionWith(list, merger, iters);
  21778. }
  21779. function getTailOffset(size) {
  21780. return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
  21781. }
  21782. createClass(OrderedMap, Map);
  21783. // @pragma Construction
  21784. function OrderedMap(value) {
  21785. return value === null || value === undefined ? emptyOrderedMap() :
  21786. isOrderedMap(value) ? value :
  21787. emptyOrderedMap().withMutations(function(map ) {
  21788. var iter = KeyedIterable(value);
  21789. assertNotInfinite(iter.size);
  21790. iter.forEach(function(v, k) {return map.set(k, v)});
  21791. });
  21792. }
  21793. OrderedMap.of = function(/*...values*/) {
  21794. return this(arguments);
  21795. };
  21796. OrderedMap.prototype.toString = function() {
  21797. return this.__toString('OrderedMap {', '}');
  21798. };
  21799. // @pragma Access
  21800. OrderedMap.prototype.get = function(k, notSetValue) {
  21801. var index = this._map.get(k);
  21802. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  21803. };
  21804. // @pragma Modification
  21805. OrderedMap.prototype.clear = function() {
  21806. if (this.size === 0) {
  21807. return this;
  21808. }
  21809. if (this.__ownerID) {
  21810. this.size = 0;
  21811. this._map.clear();
  21812. this._list.clear();
  21813. return this;
  21814. }
  21815. return emptyOrderedMap();
  21816. };
  21817. OrderedMap.prototype.set = function(k, v) {
  21818. return updateOrderedMap(this, k, v);
  21819. };
  21820. OrderedMap.prototype.remove = function(k) {
  21821. return updateOrderedMap(this, k, NOT_SET);
  21822. };
  21823. OrderedMap.prototype.wasAltered = function() {
  21824. return this._map.wasAltered() || this._list.wasAltered();
  21825. };
  21826. OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  21827. return this._list.__iterate(
  21828. function(entry ) {return entry && fn(entry[1], entry[0], this$0)},
  21829. reverse
  21830. );
  21831. };
  21832. OrderedMap.prototype.__iterator = function(type, reverse) {
  21833. return this._list.fromEntrySeq().__iterator(type, reverse);
  21834. };
  21835. OrderedMap.prototype.__ensureOwner = function(ownerID) {
  21836. if (ownerID === this.__ownerID) {
  21837. return this;
  21838. }
  21839. var newMap = this._map.__ensureOwner(ownerID);
  21840. var newList = this._list.__ensureOwner(ownerID);
  21841. if (!ownerID) {
  21842. this.__ownerID = ownerID;
  21843. this._map = newMap;
  21844. this._list = newList;
  21845. return this;
  21846. }
  21847. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  21848. };
  21849. function isOrderedMap(maybeOrderedMap) {
  21850. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  21851. }
  21852. OrderedMap.isOrderedMap = isOrderedMap;
  21853. OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
  21854. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  21855. function makeOrderedMap(map, list, ownerID, hash) {
  21856. var omap = Object.create(OrderedMap.prototype);
  21857. omap.size = map ? map.size : 0;
  21858. omap._map = map;
  21859. omap._list = list;
  21860. omap.__ownerID = ownerID;
  21861. omap.__hash = hash;
  21862. return omap;
  21863. }
  21864. var EMPTY_ORDERED_MAP;
  21865. function emptyOrderedMap() {
  21866. return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()));
  21867. }
  21868. function updateOrderedMap(omap, k, v) {
  21869. var map = omap._map;
  21870. var list = omap._list;
  21871. var i = map.get(k);
  21872. var has = i !== undefined;
  21873. var newMap;
  21874. var newList;
  21875. if (v === NOT_SET) { // removed
  21876. if (!has) {
  21877. return omap;
  21878. }
  21879. if (list.size >= SIZE && list.size >= map.size * 2) {
  21880. newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx});
  21881. newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap();
  21882. if (omap.__ownerID) {
  21883. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  21884. }
  21885. } else {
  21886. newMap = map.remove(k);
  21887. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  21888. }
  21889. } else {
  21890. if (has) {
  21891. if (v === list.get(i)[1]) {
  21892. return omap;
  21893. }
  21894. newMap = map;
  21895. newList = list.set(i, [k, v]);
  21896. } else {
  21897. newMap = map.set(k, list.size);
  21898. newList = list.set(list.size, [k, v]);
  21899. }
  21900. }
  21901. if (omap.__ownerID) {
  21902. omap.size = newMap.size;
  21903. omap._map = newMap;
  21904. omap._list = newList;
  21905. omap.__hash = undefined;
  21906. return omap;
  21907. }
  21908. return makeOrderedMap(newMap, newList);
  21909. }
  21910. createClass(ToKeyedSequence, KeyedSeq);
  21911. function ToKeyedSequence(indexed, useKeys) {
  21912. this._iter = indexed;
  21913. this._useKeys = useKeys;
  21914. this.size = indexed.size;
  21915. }
  21916. ToKeyedSequence.prototype.get = function(key, notSetValue) {
  21917. return this._iter.get(key, notSetValue);
  21918. };
  21919. ToKeyedSequence.prototype.has = function(key) {
  21920. return this._iter.has(key);
  21921. };
  21922. ToKeyedSequence.prototype.valueSeq = function() {
  21923. return this._iter.valueSeq();
  21924. };
  21925. ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
  21926. var reversedSequence = reverseFactory(this, true);
  21927. if (!this._useKeys) {
  21928. reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
  21929. }
  21930. return reversedSequence;
  21931. };
  21932. ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
  21933. var mappedSequence = mapFactory(this, mapper, context);
  21934. if (!this._useKeys) {
  21935. mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
  21936. }
  21937. return mappedSequence;
  21938. };
  21939. ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  21940. var ii;
  21941. return this._iter.__iterate(
  21942. this._useKeys ?
  21943. function(v, k) {return fn(v, k, this$0)} :
  21944. ((ii = reverse ? resolveSize(this) : 0),
  21945. function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
  21946. reverse
  21947. );
  21948. };
  21949. ToKeyedSequence.prototype.__iterator = function(type, reverse) {
  21950. if (this._useKeys) {
  21951. return this._iter.__iterator(type, reverse);
  21952. }
  21953. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  21954. var ii = reverse ? resolveSize(this) : 0;
  21955. return new Iterator(function() {
  21956. var step = iterator.next();
  21957. return step.done ? step :
  21958. iteratorValue(type, reverse ? --ii : ii++, step.value, step);
  21959. });
  21960. };
  21961. ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
  21962. createClass(ToIndexedSequence, IndexedSeq);
  21963. function ToIndexedSequence(iter) {
  21964. this._iter = iter;
  21965. this.size = iter.size;
  21966. }
  21967. ToIndexedSequence.prototype.includes = function(value) {
  21968. return this._iter.includes(value);
  21969. };
  21970. ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  21971. var iterations = 0;
  21972. return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
  21973. };
  21974. ToIndexedSequence.prototype.__iterator = function(type, reverse) {
  21975. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  21976. var iterations = 0;
  21977. return new Iterator(function() {
  21978. var step = iterator.next();
  21979. return step.done ? step :
  21980. iteratorValue(type, iterations++, step.value, step)
  21981. });
  21982. };
  21983. createClass(ToSetSequence, SetSeq);
  21984. function ToSetSequence(iter) {
  21985. this._iter = iter;
  21986. this.size = iter.size;
  21987. }
  21988. ToSetSequence.prototype.has = function(key) {
  21989. return this._iter.includes(key);
  21990. };
  21991. ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  21992. return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
  21993. };
  21994. ToSetSequence.prototype.__iterator = function(type, reverse) {
  21995. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  21996. return new Iterator(function() {
  21997. var step = iterator.next();
  21998. return step.done ? step :
  21999. iteratorValue(type, step.value, step.value, step);
  22000. });
  22001. };
  22002. createClass(FromEntriesSequence, KeyedSeq);
  22003. function FromEntriesSequence(entries) {
  22004. this._iter = entries;
  22005. this.size = entries.size;
  22006. }
  22007. FromEntriesSequence.prototype.entrySeq = function() {
  22008. return this._iter.toSeq();
  22009. };
  22010. FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  22011. return this._iter.__iterate(function(entry ) {
  22012. // Check if entry exists first so array access doesn't throw for holes
  22013. // in the parent iteration.
  22014. if (entry) {
  22015. validateEntry(entry);
  22016. var indexedIterable = isIterable(entry);
  22017. return fn(
  22018. indexedIterable ? entry.get(1) : entry[1],
  22019. indexedIterable ? entry.get(0) : entry[0],
  22020. this$0
  22021. );
  22022. }
  22023. }, reverse);
  22024. };
  22025. FromEntriesSequence.prototype.__iterator = function(type, reverse) {
  22026. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  22027. return new Iterator(function() {
  22028. while (true) {
  22029. var step = iterator.next();
  22030. if (step.done) {
  22031. return step;
  22032. }
  22033. var entry = step.value;
  22034. // Check if entry exists first so array access doesn't throw for holes
  22035. // in the parent iteration.
  22036. if (entry) {
  22037. validateEntry(entry);
  22038. var indexedIterable = isIterable(entry);
  22039. return iteratorValue(
  22040. type,
  22041. indexedIterable ? entry.get(0) : entry[0],
  22042. indexedIterable ? entry.get(1) : entry[1],
  22043. step
  22044. );
  22045. }
  22046. }
  22047. });
  22048. };
  22049. ToIndexedSequence.prototype.cacheResult =
  22050. ToKeyedSequence.prototype.cacheResult =
  22051. ToSetSequence.prototype.cacheResult =
  22052. FromEntriesSequence.prototype.cacheResult =
  22053. cacheResultThrough;
  22054. function flipFactory(iterable) {
  22055. var flipSequence = makeSequence(iterable);
  22056. flipSequence._iter = iterable;
  22057. flipSequence.size = iterable.size;
  22058. flipSequence.flip = function() {return iterable};
  22059. flipSequence.reverse = function () {
  22060. var reversedSequence = iterable.reverse.apply(this); // super.reverse()
  22061. reversedSequence.flip = function() {return iterable.reverse()};
  22062. return reversedSequence;
  22063. };
  22064. flipSequence.has = function(key ) {return iterable.includes(key)};
  22065. flipSequence.includes = function(key ) {return iterable.has(key)};
  22066. flipSequence.cacheResult = cacheResultThrough;
  22067. flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  22068. return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
  22069. };
  22070. flipSequence.__iteratorUncached = function(type, reverse) {
  22071. if (type === ITERATE_ENTRIES) {
  22072. var iterator = iterable.__iterator(type, reverse);
  22073. return new Iterator(function() {
  22074. var step = iterator.next();
  22075. if (!step.done) {
  22076. var k = step.value[0];
  22077. step.value[0] = step.value[1];
  22078. step.value[1] = k;
  22079. }
  22080. return step;
  22081. });
  22082. }
  22083. return iterable.__iterator(
  22084. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  22085. reverse
  22086. );
  22087. };
  22088. return flipSequence;
  22089. }
  22090. function mapFactory(iterable, mapper, context) {
  22091. var mappedSequence = makeSequence(iterable);
  22092. mappedSequence.size = iterable.size;
  22093. mappedSequence.has = function(key ) {return iterable.has(key)};
  22094. mappedSequence.get = function(key, notSetValue) {
  22095. var v = iterable.get(key, NOT_SET);
  22096. return v === NOT_SET ?
  22097. notSetValue :
  22098. mapper.call(context, v, key, iterable);
  22099. };
  22100. mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  22101. return iterable.__iterate(
  22102. function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
  22103. reverse
  22104. );
  22105. };
  22106. mappedSequence.__iteratorUncached = function (type, reverse) {
  22107. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  22108. return new Iterator(function() {
  22109. var step = iterator.next();
  22110. if (step.done) {
  22111. return step;
  22112. }
  22113. var entry = step.value;
  22114. var key = entry[0];
  22115. return iteratorValue(
  22116. type,
  22117. key,
  22118. mapper.call(context, entry[1], key, iterable),
  22119. step
  22120. );
  22121. });
  22122. };
  22123. return mappedSequence;
  22124. }
  22125. function reverseFactory(iterable, useKeys) {
  22126. var reversedSequence = makeSequence(iterable);
  22127. reversedSequence._iter = iterable;
  22128. reversedSequence.size = iterable.size;
  22129. reversedSequence.reverse = function() {return iterable};
  22130. if (iterable.flip) {
  22131. reversedSequence.flip = function () {
  22132. var flipSequence = flipFactory(iterable);
  22133. flipSequence.reverse = function() {return iterable.flip()};
  22134. return flipSequence;
  22135. };
  22136. }
  22137. reversedSequence.get = function(key, notSetValue)
  22138. {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
  22139. reversedSequence.has = function(key )
  22140. {return iterable.has(useKeys ? key : -1 - key)};
  22141. reversedSequence.includes = function(value ) {return iterable.includes(value)};
  22142. reversedSequence.cacheResult = cacheResultThrough;
  22143. reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
  22144. return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
  22145. };
  22146. reversedSequence.__iterator =
  22147. function(type, reverse) {return iterable.__iterator(type, !reverse)};
  22148. return reversedSequence;
  22149. }
  22150. function filterFactory(iterable, predicate, context, useKeys) {
  22151. var filterSequence = makeSequence(iterable);
  22152. if (useKeys) {
  22153. filterSequence.has = function(key ) {
  22154. var v = iterable.get(key, NOT_SET);
  22155. return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
  22156. };
  22157. filterSequence.get = function(key, notSetValue) {
  22158. var v = iterable.get(key, NOT_SET);
  22159. return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
  22160. v : notSetValue;
  22161. };
  22162. }
  22163. filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  22164. var iterations = 0;
  22165. iterable.__iterate(function(v, k, c) {
  22166. if (predicate.call(context, v, k, c)) {
  22167. iterations++;
  22168. return fn(v, useKeys ? k : iterations - 1, this$0);
  22169. }
  22170. }, reverse);
  22171. return iterations;
  22172. };
  22173. filterSequence.__iteratorUncached = function (type, reverse) {
  22174. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  22175. var iterations = 0;
  22176. return new Iterator(function() {
  22177. while (true) {
  22178. var step = iterator.next();
  22179. if (step.done) {
  22180. return step;
  22181. }
  22182. var entry = step.value;
  22183. var key = entry[0];
  22184. var value = entry[1];
  22185. if (predicate.call(context, value, key, iterable)) {
  22186. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  22187. }
  22188. }
  22189. });
  22190. };
  22191. return filterSequence;
  22192. }
  22193. function countByFactory(iterable, grouper, context) {
  22194. var groups = Map().asMutable();
  22195. iterable.__iterate(function(v, k) {
  22196. groups.update(
  22197. grouper.call(context, v, k, iterable),
  22198. 0,
  22199. function(a ) {return a + 1}
  22200. );
  22201. });
  22202. return groups.asImmutable();
  22203. }
  22204. function groupByFactory(iterable, grouper, context) {
  22205. var isKeyedIter = isKeyed(iterable);
  22206. var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable();
  22207. iterable.__iterate(function(v, k) {
  22208. groups.update(
  22209. grouper.call(context, v, k, iterable),
  22210. function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
  22211. );
  22212. });
  22213. var coerce = iterableClass(iterable);
  22214. return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
  22215. }
  22216. function sliceFactory(iterable, begin, end, useKeys) {
  22217. var originalSize = iterable.size;
  22218. // Sanitize begin & end using this shorthand for ToInt32(argument)
  22219. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  22220. if (begin !== undefined) {
  22221. begin = begin | 0;
  22222. }
  22223. if (end !== undefined) {
  22224. end = end | 0;
  22225. }
  22226. if (wholeSlice(begin, end, originalSize)) {
  22227. return iterable;
  22228. }
  22229. var resolvedBegin = resolveBegin(begin, originalSize);
  22230. var resolvedEnd = resolveEnd(end, originalSize);
  22231. // begin or end will be NaN if they were provided as negative numbers and
  22232. // this iterable's size is unknown. In that case, cache first so there is
  22233. // a known size and these do not resolve to NaN.
  22234. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  22235. return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
  22236. }
  22237. // Note: resolvedEnd is undefined when the original sequence's length is
  22238. // unknown and this slice did not supply an end and should contain all
  22239. // elements after resolvedBegin.
  22240. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  22241. var resolvedSize = resolvedEnd - resolvedBegin;
  22242. var sliceSize;
  22243. if (resolvedSize === resolvedSize) {
  22244. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  22245. }
  22246. var sliceSeq = makeSequence(iterable);
  22247. // If iterable.size is undefined, the size of the realized sliceSeq is
  22248. // unknown at this point unless the number of items to slice is 0
  22249. sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
  22250. if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
  22251. sliceSeq.get = function (index, notSetValue) {
  22252. index = wrapIndex(this, index);
  22253. return index >= 0 && index < sliceSize ?
  22254. iterable.get(index + resolvedBegin, notSetValue) :
  22255. notSetValue;
  22256. };
  22257. }
  22258. sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
  22259. if (sliceSize === 0) {
  22260. return 0;
  22261. }
  22262. if (reverse) {
  22263. return this.cacheResult().__iterate(fn, reverse);
  22264. }
  22265. var skipped = 0;
  22266. var isSkipping = true;
  22267. var iterations = 0;
  22268. iterable.__iterate(function(v, k) {
  22269. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  22270. iterations++;
  22271. return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
  22272. iterations !== sliceSize;
  22273. }
  22274. });
  22275. return iterations;
  22276. };
  22277. sliceSeq.__iteratorUncached = function(type, reverse) {
  22278. if (sliceSize !== 0 && reverse) {
  22279. return this.cacheResult().__iterator(type, reverse);
  22280. }
  22281. // Don't bother instantiating parent iterator if taking 0.
  22282. var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
  22283. var skipped = 0;
  22284. var iterations = 0;
  22285. return new Iterator(function() {
  22286. while (skipped++ < resolvedBegin) {
  22287. iterator.next();
  22288. }
  22289. if (++iterations > sliceSize) {
  22290. return iteratorDone();
  22291. }
  22292. var step = iterator.next();
  22293. if (useKeys || type === ITERATE_VALUES) {
  22294. return step;
  22295. } else if (type === ITERATE_KEYS) {
  22296. return iteratorValue(type, iterations - 1, undefined, step);
  22297. } else {
  22298. return iteratorValue(type, iterations - 1, step.value[1], step);
  22299. }
  22300. });
  22301. };
  22302. return sliceSeq;
  22303. }
  22304. function takeWhileFactory(iterable, predicate, context) {
  22305. var takeSequence = makeSequence(iterable);
  22306. takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  22307. if (reverse) {
  22308. return this.cacheResult().__iterate(fn, reverse);
  22309. }
  22310. var iterations = 0;
  22311. iterable.__iterate(function(v, k, c)
  22312. {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
  22313. );
  22314. return iterations;
  22315. };
  22316. takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  22317. if (reverse) {
  22318. return this.cacheResult().__iterator(type, reverse);
  22319. }
  22320. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  22321. var iterating = true;
  22322. return new Iterator(function() {
  22323. if (!iterating) {
  22324. return iteratorDone();
  22325. }
  22326. var step = iterator.next();
  22327. if (step.done) {
  22328. return step;
  22329. }
  22330. var entry = step.value;
  22331. var k = entry[0];
  22332. var v = entry[1];
  22333. if (!predicate.call(context, v, k, this$0)) {
  22334. iterating = false;
  22335. return iteratorDone();
  22336. }
  22337. return type === ITERATE_ENTRIES ? step :
  22338. iteratorValue(type, k, v, step);
  22339. });
  22340. };
  22341. return takeSequence;
  22342. }
  22343. function skipWhileFactory(iterable, predicate, context, useKeys) {
  22344. var skipSequence = makeSequence(iterable);
  22345. skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  22346. if (reverse) {
  22347. return this.cacheResult().__iterate(fn, reverse);
  22348. }
  22349. var isSkipping = true;
  22350. var iterations = 0;
  22351. iterable.__iterate(function(v, k, c) {
  22352. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  22353. iterations++;
  22354. return fn(v, useKeys ? k : iterations - 1, this$0);
  22355. }
  22356. });
  22357. return iterations;
  22358. };
  22359. skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  22360. if (reverse) {
  22361. return this.cacheResult().__iterator(type, reverse);
  22362. }
  22363. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  22364. var skipping = true;
  22365. var iterations = 0;
  22366. return new Iterator(function() {
  22367. var step, k, v;
  22368. do {
  22369. step = iterator.next();
  22370. if (step.done) {
  22371. if (useKeys || type === ITERATE_VALUES) {
  22372. return step;
  22373. } else if (type === ITERATE_KEYS) {
  22374. return iteratorValue(type, iterations++, undefined, step);
  22375. } else {
  22376. return iteratorValue(type, iterations++, step.value[1], step);
  22377. }
  22378. }
  22379. var entry = step.value;
  22380. k = entry[0];
  22381. v = entry[1];
  22382. skipping && (skipping = predicate.call(context, v, k, this$0));
  22383. } while (skipping);
  22384. return type === ITERATE_ENTRIES ? step :
  22385. iteratorValue(type, k, v, step);
  22386. });
  22387. };
  22388. return skipSequence;
  22389. }
  22390. function concatFactory(iterable, values) {
  22391. var isKeyedIterable = isKeyed(iterable);
  22392. var iters = [iterable].concat(values).map(function(v ) {
  22393. if (!isIterable(v)) {
  22394. v = isKeyedIterable ?
  22395. keyedSeqFromValue(v) :
  22396. indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  22397. } else if (isKeyedIterable) {
  22398. v = KeyedIterable(v);
  22399. }
  22400. return v;
  22401. }).filter(function(v ) {return v.size !== 0});
  22402. if (iters.length === 0) {
  22403. return iterable;
  22404. }
  22405. if (iters.length === 1) {
  22406. var singleton = iters[0];
  22407. if (singleton === iterable ||
  22408. isKeyedIterable && isKeyed(singleton) ||
  22409. isIndexed(iterable) && isIndexed(singleton)) {
  22410. return singleton;
  22411. }
  22412. }
  22413. var concatSeq = new ArraySeq(iters);
  22414. if (isKeyedIterable) {
  22415. concatSeq = concatSeq.toKeyedSeq();
  22416. } else if (!isIndexed(iterable)) {
  22417. concatSeq = concatSeq.toSetSeq();
  22418. }
  22419. concatSeq = concatSeq.flatten(true);
  22420. concatSeq.size = iters.reduce(
  22421. function(sum, seq) {
  22422. if (sum !== undefined) {
  22423. var size = seq.size;
  22424. if (size !== undefined) {
  22425. return sum + size;
  22426. }
  22427. }
  22428. },
  22429. 0
  22430. );
  22431. return concatSeq;
  22432. }
  22433. function flattenFactory(iterable, depth, useKeys) {
  22434. var flatSequence = makeSequence(iterable);
  22435. flatSequence.__iterateUncached = function(fn, reverse) {
  22436. var iterations = 0;
  22437. var stopped = false;
  22438. function flatDeep(iter, currentDepth) {var this$0 = this;
  22439. iter.__iterate(function(v, k) {
  22440. if ((!depth || currentDepth < depth) && isIterable(v)) {
  22441. flatDeep(v, currentDepth + 1);
  22442. } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
  22443. stopped = true;
  22444. }
  22445. return !stopped;
  22446. }, reverse);
  22447. }
  22448. flatDeep(iterable, 0);
  22449. return iterations;
  22450. };
  22451. flatSequence.__iteratorUncached = function(type, reverse) {
  22452. var iterator = iterable.__iterator(type, reverse);
  22453. var stack = [];
  22454. var iterations = 0;
  22455. return new Iterator(function() {
  22456. while (iterator) {
  22457. var step = iterator.next();
  22458. if (step.done !== false) {
  22459. iterator = stack.pop();
  22460. continue;
  22461. }
  22462. var v = step.value;
  22463. if (type === ITERATE_ENTRIES) {
  22464. v = v[1];
  22465. }
  22466. if ((!depth || stack.length < depth) && isIterable(v)) {
  22467. stack.push(iterator);
  22468. iterator = v.__iterator(type, reverse);
  22469. } else {
  22470. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  22471. }
  22472. }
  22473. return iteratorDone();
  22474. });
  22475. };
  22476. return flatSequence;
  22477. }
  22478. function flatMapFactory(iterable, mapper, context) {
  22479. var coerce = iterableClass(iterable);
  22480. return iterable.toSeq().map(
  22481. function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
  22482. ).flatten(true);
  22483. }
  22484. function interposeFactory(iterable, separator) {
  22485. var interposedSequence = makeSequence(iterable);
  22486. interposedSequence.size = iterable.size && iterable.size * 2 -1;
  22487. interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  22488. var iterations = 0;
  22489. iterable.__iterate(function(v, k)
  22490. {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
  22491. fn(v, iterations++, this$0) !== false},
  22492. reverse
  22493. );
  22494. return iterations;
  22495. };
  22496. interposedSequence.__iteratorUncached = function(type, reverse) {
  22497. var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
  22498. var iterations = 0;
  22499. var step;
  22500. return new Iterator(function() {
  22501. if (!step || iterations % 2) {
  22502. step = iterator.next();
  22503. if (step.done) {
  22504. return step;
  22505. }
  22506. }
  22507. return iterations % 2 ?
  22508. iteratorValue(type, iterations++, separator) :
  22509. iteratorValue(type, iterations++, step.value, step);
  22510. });
  22511. };
  22512. return interposedSequence;
  22513. }
  22514. function sortFactory(iterable, comparator, mapper) {
  22515. if (!comparator) {
  22516. comparator = defaultComparator;
  22517. }
  22518. var isKeyedIterable = isKeyed(iterable);
  22519. var index = 0;
  22520. var entries = iterable.toSeq().map(
  22521. function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
  22522. ).toArray();
  22523. entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
  22524. isKeyedIterable ?
  22525. function(v, i) { entries[i].length = 2; } :
  22526. function(v, i) { entries[i] = v[1]; }
  22527. );
  22528. return isKeyedIterable ? KeyedSeq(entries) :
  22529. isIndexed(iterable) ? IndexedSeq(entries) :
  22530. SetSeq(entries);
  22531. }
  22532. function maxFactory(iterable, comparator, mapper) {
  22533. if (!comparator) {
  22534. comparator = defaultComparator;
  22535. }
  22536. if (mapper) {
  22537. var entry = iterable.toSeq()
  22538. .map(function(v, k) {return [v, mapper(v, k, iterable)]})
  22539. .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
  22540. return entry && entry[0];
  22541. } else {
  22542. return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
  22543. }
  22544. }
  22545. function maxCompare(comparator, a, b) {
  22546. var comp = comparator(b, a);
  22547. // b is considered the new max if the comparator declares them equal, but
  22548. // they are not equal and b is in fact a nullish value.
  22549. return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
  22550. }
  22551. function zipWithFactory(keyIter, zipper, iters) {
  22552. var zipSequence = makeSequence(keyIter);
  22553. zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
  22554. // Note: this a generic base implementation of __iterate in terms of
  22555. // __iterator which may be more generically useful in the future.
  22556. zipSequence.__iterate = function(fn, reverse) {
  22557. /* generic:
  22558. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  22559. var step;
  22560. var iterations = 0;
  22561. while (!(step = iterator.next()).done) {
  22562. iterations++;
  22563. if (fn(step.value[1], step.value[0], this) === false) {
  22564. break;
  22565. }
  22566. }
  22567. return iterations;
  22568. */
  22569. // indexed:
  22570. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  22571. var step;
  22572. var iterations = 0;
  22573. while (!(step = iterator.next()).done) {
  22574. if (fn(step.value, iterations++, this) === false) {
  22575. break;
  22576. }
  22577. }
  22578. return iterations;
  22579. };
  22580. zipSequence.__iteratorUncached = function(type, reverse) {
  22581. var iterators = iters.map(function(i )
  22582. {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
  22583. );
  22584. var iterations = 0;
  22585. var isDone = false;
  22586. return new Iterator(function() {
  22587. var steps;
  22588. if (!isDone) {
  22589. steps = iterators.map(function(i ) {return i.next()});
  22590. isDone = steps.some(function(s ) {return s.done});
  22591. }
  22592. if (isDone) {
  22593. return iteratorDone();
  22594. }
  22595. return iteratorValue(
  22596. type,
  22597. iterations++,
  22598. zipper.apply(null, steps.map(function(s ) {return s.value}))
  22599. );
  22600. });
  22601. };
  22602. return zipSequence
  22603. }
  22604. // #pragma Helper Functions
  22605. function reify(iter, seq) {
  22606. return isSeq(iter) ? seq : iter.constructor(seq);
  22607. }
  22608. function validateEntry(entry) {
  22609. if (entry !== Object(entry)) {
  22610. throw new TypeError('Expected [K, V] tuple: ' + entry);
  22611. }
  22612. }
  22613. function resolveSize(iter) {
  22614. assertNotInfinite(iter.size);
  22615. return ensureSize(iter);
  22616. }
  22617. function iterableClass(iterable) {
  22618. return isKeyed(iterable) ? KeyedIterable :
  22619. isIndexed(iterable) ? IndexedIterable :
  22620. SetIterable;
  22621. }
  22622. function makeSequence(iterable) {
  22623. return Object.create(
  22624. (
  22625. isKeyed(iterable) ? KeyedSeq :
  22626. isIndexed(iterable) ? IndexedSeq :
  22627. SetSeq
  22628. ).prototype
  22629. );
  22630. }
  22631. function cacheResultThrough() {
  22632. if (this._iter.cacheResult) {
  22633. this._iter.cacheResult();
  22634. this.size = this._iter.size;
  22635. return this;
  22636. } else {
  22637. return Seq.prototype.cacheResult.call(this);
  22638. }
  22639. }
  22640. function defaultComparator(a, b) {
  22641. return a > b ? 1 : a < b ? -1 : 0;
  22642. }
  22643. function forceIterator(keyPath) {
  22644. var iter = getIterator(keyPath);
  22645. if (!iter) {
  22646. // Array might not be iterable in this environment, so we need a fallback
  22647. // to our wrapped type.
  22648. if (!isArrayLike(keyPath)) {
  22649. throw new TypeError('Expected iterable or array-like: ' + keyPath);
  22650. }
  22651. iter = getIterator(Iterable(keyPath));
  22652. }
  22653. return iter;
  22654. }
  22655. createClass(Record, KeyedCollection);
  22656. function Record(defaultValues, name) {
  22657. var hasInitialized;
  22658. var RecordType = function Record(values) {
  22659. if (values instanceof RecordType) {
  22660. return values;
  22661. }
  22662. if (!(this instanceof RecordType)) {
  22663. return new RecordType(values);
  22664. }
  22665. if (!hasInitialized) {
  22666. hasInitialized = true;
  22667. var keys = Object.keys(defaultValues);
  22668. setProps(RecordTypePrototype, keys);
  22669. RecordTypePrototype.size = keys.length;
  22670. RecordTypePrototype._name = name;
  22671. RecordTypePrototype._keys = keys;
  22672. RecordTypePrototype._defaultValues = defaultValues;
  22673. }
  22674. this._map = Map(values);
  22675. };
  22676. var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
  22677. RecordTypePrototype.constructor = RecordType;
  22678. return RecordType;
  22679. }
  22680. Record.prototype.toString = function() {
  22681. return this.__toString(recordName(this) + ' {', '}');
  22682. };
  22683. // @pragma Access
  22684. Record.prototype.has = function(k) {
  22685. return this._defaultValues.hasOwnProperty(k);
  22686. };
  22687. Record.prototype.get = function(k, notSetValue) {
  22688. if (!this.has(k)) {
  22689. return notSetValue;
  22690. }
  22691. var defaultVal = this._defaultValues[k];
  22692. return this._map ? this._map.get(k, defaultVal) : defaultVal;
  22693. };
  22694. // @pragma Modification
  22695. Record.prototype.clear = function() {
  22696. if (this.__ownerID) {
  22697. this._map && this._map.clear();
  22698. return this;
  22699. }
  22700. var RecordType = this.constructor;
  22701. return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap()));
  22702. };
  22703. Record.prototype.set = function(k, v) {
  22704. if (!this.has(k)) {
  22705. throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
  22706. }
  22707. var newMap = this._map && this._map.set(k, v);
  22708. if (this.__ownerID || newMap === this._map) {
  22709. return this;
  22710. }
  22711. return makeRecord(this, newMap);
  22712. };
  22713. Record.prototype.remove = function(k) {
  22714. if (!this.has(k)) {
  22715. return this;
  22716. }
  22717. var newMap = this._map && this._map.remove(k);
  22718. if (this.__ownerID || newMap === this._map) {
  22719. return this;
  22720. }
  22721. return makeRecord(this, newMap);
  22722. };
  22723. Record.prototype.wasAltered = function() {
  22724. return this._map.wasAltered();
  22725. };
  22726. Record.prototype.__iterator = function(type, reverse) {var this$0 = this;
  22727. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse);
  22728. };
  22729. Record.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  22730. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse);
  22731. };
  22732. Record.prototype.__ensureOwner = function(ownerID) {
  22733. if (ownerID === this.__ownerID) {
  22734. return this;
  22735. }
  22736. var newMap = this._map && this._map.__ensureOwner(ownerID);
  22737. if (!ownerID) {
  22738. this.__ownerID = ownerID;
  22739. this._map = newMap;
  22740. return this;
  22741. }
  22742. return makeRecord(this, newMap, ownerID);
  22743. };
  22744. var RecordPrototype = Record.prototype;
  22745. RecordPrototype[DELETE] = RecordPrototype.remove;
  22746. RecordPrototype.deleteIn =
  22747. RecordPrototype.removeIn = MapPrototype.removeIn;
  22748. RecordPrototype.merge = MapPrototype.merge;
  22749. RecordPrototype.mergeWith = MapPrototype.mergeWith;
  22750. RecordPrototype.mergeIn = MapPrototype.mergeIn;
  22751. RecordPrototype.mergeDeep = MapPrototype.mergeDeep;
  22752. RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith;
  22753. RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  22754. RecordPrototype.setIn = MapPrototype.setIn;
  22755. RecordPrototype.update = MapPrototype.update;
  22756. RecordPrototype.updateIn = MapPrototype.updateIn;
  22757. RecordPrototype.withMutations = MapPrototype.withMutations;
  22758. RecordPrototype.asMutable = MapPrototype.asMutable;
  22759. RecordPrototype.asImmutable = MapPrototype.asImmutable;
  22760. function makeRecord(likeRecord, map, ownerID) {
  22761. var record = Object.create(Object.getPrototypeOf(likeRecord));
  22762. record._map = map;
  22763. record.__ownerID = ownerID;
  22764. return record;
  22765. }
  22766. function recordName(record) {
  22767. return record._name || record.constructor.name || 'Record';
  22768. }
  22769. function setProps(prototype, names) {
  22770. try {
  22771. names.forEach(setProp.bind(undefined, prototype));
  22772. } catch (error) {
  22773. // Object.defineProperty failed. Probably IE8.
  22774. }
  22775. }
  22776. function setProp(prototype, name) {
  22777. Object.defineProperty(prototype, name, {
  22778. get: function() {
  22779. return this.get(name);
  22780. },
  22781. set: function(value) {
  22782. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  22783. this.set(name, value);
  22784. }
  22785. });
  22786. }
  22787. createClass(Set, SetCollection);
  22788. // @pragma Construction
  22789. function Set(value) {
  22790. return value === null || value === undefined ? emptySet() :
  22791. isSet(value) && !isOrdered(value) ? value :
  22792. emptySet().withMutations(function(set ) {
  22793. var iter = SetIterable(value);
  22794. assertNotInfinite(iter.size);
  22795. iter.forEach(function(v ) {return set.add(v)});
  22796. });
  22797. }
  22798. Set.of = function(/*...values*/) {
  22799. return this(arguments);
  22800. };
  22801. Set.fromKeys = function(value) {
  22802. return this(KeyedIterable(value).keySeq());
  22803. };
  22804. Set.prototype.toString = function() {
  22805. return this.__toString('Set {', '}');
  22806. };
  22807. // @pragma Access
  22808. Set.prototype.has = function(value) {
  22809. return this._map.has(value);
  22810. };
  22811. // @pragma Modification
  22812. Set.prototype.add = function(value) {
  22813. return updateSet(this, this._map.set(value, true));
  22814. };
  22815. Set.prototype.remove = function(value) {
  22816. return updateSet(this, this._map.remove(value));
  22817. };
  22818. Set.prototype.clear = function() {
  22819. return updateSet(this, this._map.clear());
  22820. };
  22821. // @pragma Composition
  22822. Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
  22823. iters = iters.filter(function(x ) {return x.size !== 0});
  22824. if (iters.length === 0) {
  22825. return this;
  22826. }
  22827. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  22828. return this.constructor(iters[0]);
  22829. }
  22830. return this.withMutations(function(set ) {
  22831. for (var ii = 0; ii < iters.length; ii++) {
  22832. SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)});
  22833. }
  22834. });
  22835. };
  22836. Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
  22837. if (iters.length === 0) {
  22838. return this;
  22839. }
  22840. iters = iters.map(function(iter ) {return SetIterable(iter)});
  22841. var originalSet = this;
  22842. return this.withMutations(function(set ) {
  22843. originalSet.forEach(function(value ) {
  22844. if (!iters.every(function(iter ) {return iter.includes(value)})) {
  22845. set.remove(value);
  22846. }
  22847. });
  22848. });
  22849. };
  22850. Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
  22851. if (iters.length === 0) {
  22852. return this;
  22853. }
  22854. iters = iters.map(function(iter ) {return SetIterable(iter)});
  22855. var originalSet = this;
  22856. return this.withMutations(function(set ) {
  22857. originalSet.forEach(function(value ) {
  22858. if (iters.some(function(iter ) {return iter.includes(value)})) {
  22859. set.remove(value);
  22860. }
  22861. });
  22862. });
  22863. };
  22864. Set.prototype.merge = function() {
  22865. return this.union.apply(this, arguments);
  22866. };
  22867. Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  22868. return this.union.apply(this, iters);
  22869. };
  22870. Set.prototype.sort = function(comparator) {
  22871. // Late binding
  22872. return OrderedSet(sortFactory(this, comparator));
  22873. };
  22874. Set.prototype.sortBy = function(mapper, comparator) {
  22875. // Late binding
  22876. return OrderedSet(sortFactory(this, comparator, mapper));
  22877. };
  22878. Set.prototype.wasAltered = function() {
  22879. return this._map.wasAltered();
  22880. };
  22881. Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  22882. return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
  22883. };
  22884. Set.prototype.__iterator = function(type, reverse) {
  22885. return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
  22886. };
  22887. Set.prototype.__ensureOwner = function(ownerID) {
  22888. if (ownerID === this.__ownerID) {
  22889. return this;
  22890. }
  22891. var newMap = this._map.__ensureOwner(ownerID);
  22892. if (!ownerID) {
  22893. this.__ownerID = ownerID;
  22894. this._map = newMap;
  22895. return this;
  22896. }
  22897. return this.__make(newMap, ownerID);
  22898. };
  22899. function isSet(maybeSet) {
  22900. return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
  22901. }
  22902. Set.isSet = isSet;
  22903. var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
  22904. var SetPrototype = Set.prototype;
  22905. SetPrototype[IS_SET_SENTINEL] = true;
  22906. SetPrototype[DELETE] = SetPrototype.remove;
  22907. SetPrototype.mergeDeep = SetPrototype.merge;
  22908. SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
  22909. SetPrototype.withMutations = MapPrototype.withMutations;
  22910. SetPrototype.asMutable = MapPrototype.asMutable;
  22911. SetPrototype.asImmutable = MapPrototype.asImmutable;
  22912. SetPrototype.__empty = emptySet;
  22913. SetPrototype.__make = makeSet;
  22914. function updateSet(set, newMap) {
  22915. if (set.__ownerID) {
  22916. set.size = newMap.size;
  22917. set._map = newMap;
  22918. return set;
  22919. }
  22920. return newMap === set._map ? set :
  22921. newMap.size === 0 ? set.__empty() :
  22922. set.__make(newMap);
  22923. }
  22924. function makeSet(map, ownerID) {
  22925. var set = Object.create(SetPrototype);
  22926. set.size = map ? map.size : 0;
  22927. set._map = map;
  22928. set.__ownerID = ownerID;
  22929. return set;
  22930. }
  22931. var EMPTY_SET;
  22932. function emptySet() {
  22933. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  22934. }
  22935. createClass(OrderedSet, Set);
  22936. // @pragma Construction
  22937. function OrderedSet(value) {
  22938. return value === null || value === undefined ? emptyOrderedSet() :
  22939. isOrderedSet(value) ? value :
  22940. emptyOrderedSet().withMutations(function(set ) {
  22941. var iter = SetIterable(value);
  22942. assertNotInfinite(iter.size);
  22943. iter.forEach(function(v ) {return set.add(v)});
  22944. });
  22945. }
  22946. OrderedSet.of = function(/*...values*/) {
  22947. return this(arguments);
  22948. };
  22949. OrderedSet.fromKeys = function(value) {
  22950. return this(KeyedIterable(value).keySeq());
  22951. };
  22952. OrderedSet.prototype.toString = function() {
  22953. return this.__toString('OrderedSet {', '}');
  22954. };
  22955. function isOrderedSet(maybeOrderedSet) {
  22956. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  22957. }
  22958. OrderedSet.isOrderedSet = isOrderedSet;
  22959. var OrderedSetPrototype = OrderedSet.prototype;
  22960. OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
  22961. OrderedSetPrototype.__empty = emptyOrderedSet;
  22962. OrderedSetPrototype.__make = makeOrderedSet;
  22963. function makeOrderedSet(map, ownerID) {
  22964. var set = Object.create(OrderedSetPrototype);
  22965. set.size = map ? map.size : 0;
  22966. set._map = map;
  22967. set.__ownerID = ownerID;
  22968. return set;
  22969. }
  22970. var EMPTY_ORDERED_SET;
  22971. function emptyOrderedSet() {
  22972. return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
  22973. }
  22974. createClass(Stack, IndexedCollection);
  22975. // @pragma Construction
  22976. function Stack(value) {
  22977. return value === null || value === undefined ? emptyStack() :
  22978. isStack(value) ? value :
  22979. emptyStack().unshiftAll(value);
  22980. }
  22981. Stack.of = function(/*...values*/) {
  22982. return this(arguments);
  22983. };
  22984. Stack.prototype.toString = function() {
  22985. return this.__toString('Stack [', ']');
  22986. };
  22987. // @pragma Access
  22988. Stack.prototype.get = function(index, notSetValue) {
  22989. var head = this._head;
  22990. index = wrapIndex(this, index);
  22991. while (head && index--) {
  22992. head = head.next;
  22993. }
  22994. return head ? head.value : notSetValue;
  22995. };
  22996. Stack.prototype.peek = function() {
  22997. return this._head && this._head.value;
  22998. };
  22999. // @pragma Modification
  23000. Stack.prototype.push = function(/*...values*/) {
  23001. if (arguments.length === 0) {
  23002. return this;
  23003. }
  23004. var newSize = this.size + arguments.length;
  23005. var head = this._head;
  23006. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  23007. head = {
  23008. value: arguments[ii],
  23009. next: head
  23010. };
  23011. }
  23012. if (this.__ownerID) {
  23013. this.size = newSize;
  23014. this._head = head;
  23015. this.__hash = undefined;
  23016. this.__altered = true;
  23017. return this;
  23018. }
  23019. return makeStack(newSize, head);
  23020. };
  23021. Stack.prototype.pushAll = function(iter) {
  23022. iter = IndexedIterable(iter);
  23023. if (iter.size === 0) {
  23024. return this;
  23025. }
  23026. assertNotInfinite(iter.size);
  23027. var newSize = this.size;
  23028. var head = this._head;
  23029. iter.reverse().forEach(function(value ) {
  23030. newSize++;
  23031. head = {
  23032. value: value,
  23033. next: head
  23034. };
  23035. });
  23036. if (this.__ownerID) {
  23037. this.size = newSize;
  23038. this._head = head;
  23039. this.__hash = undefined;
  23040. this.__altered = true;
  23041. return this;
  23042. }
  23043. return makeStack(newSize, head);
  23044. };
  23045. Stack.prototype.pop = function() {
  23046. return this.slice(1);
  23047. };
  23048. Stack.prototype.unshift = function(/*...values*/) {
  23049. return this.push.apply(this, arguments);
  23050. };
  23051. Stack.prototype.unshiftAll = function(iter) {
  23052. return this.pushAll(iter);
  23053. };
  23054. Stack.prototype.shift = function() {
  23055. return this.pop.apply(this, arguments);
  23056. };
  23057. Stack.prototype.clear = function() {
  23058. if (this.size === 0) {
  23059. return this;
  23060. }
  23061. if (this.__ownerID) {
  23062. this.size = 0;
  23063. this._head = undefined;
  23064. this.__hash = undefined;
  23065. this.__altered = true;
  23066. return this;
  23067. }
  23068. return emptyStack();
  23069. };
  23070. Stack.prototype.slice = function(begin, end) {
  23071. if (wholeSlice(begin, end, this.size)) {
  23072. return this;
  23073. }
  23074. var resolvedBegin = resolveBegin(begin, this.size);
  23075. var resolvedEnd = resolveEnd(end, this.size);
  23076. if (resolvedEnd !== this.size) {
  23077. // super.slice(begin, end);
  23078. return IndexedCollection.prototype.slice.call(this, begin, end);
  23079. }
  23080. var newSize = this.size - resolvedBegin;
  23081. var head = this._head;
  23082. while (resolvedBegin--) {
  23083. head = head.next;
  23084. }
  23085. if (this.__ownerID) {
  23086. this.size = newSize;
  23087. this._head = head;
  23088. this.__hash = undefined;
  23089. this.__altered = true;
  23090. return this;
  23091. }
  23092. return makeStack(newSize, head);
  23093. };
  23094. // @pragma Mutability
  23095. Stack.prototype.__ensureOwner = function(ownerID) {
  23096. if (ownerID === this.__ownerID) {
  23097. return this;
  23098. }
  23099. if (!ownerID) {
  23100. this.__ownerID = ownerID;
  23101. this.__altered = false;
  23102. return this;
  23103. }
  23104. return makeStack(this.size, this._head, ownerID, this.__hash);
  23105. };
  23106. // @pragma Iteration
  23107. Stack.prototype.__iterate = function(fn, reverse) {
  23108. if (reverse) {
  23109. return this.reverse().__iterate(fn);
  23110. }
  23111. var iterations = 0;
  23112. var node = this._head;
  23113. while (node) {
  23114. if (fn(node.value, iterations++, this) === false) {
  23115. break;
  23116. }
  23117. node = node.next;
  23118. }
  23119. return iterations;
  23120. };
  23121. Stack.prototype.__iterator = function(type, reverse) {
  23122. if (reverse) {
  23123. return this.reverse().__iterator(type);
  23124. }
  23125. var iterations = 0;
  23126. var node = this._head;
  23127. return new Iterator(function() {
  23128. if (node) {
  23129. var value = node.value;
  23130. node = node.next;
  23131. return iteratorValue(type, iterations++, value);
  23132. }
  23133. return iteratorDone();
  23134. });
  23135. };
  23136. function isStack(maybeStack) {
  23137. return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
  23138. }
  23139. Stack.isStack = isStack;
  23140. var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
  23141. var StackPrototype = Stack.prototype;
  23142. StackPrototype[IS_STACK_SENTINEL] = true;
  23143. StackPrototype.withMutations = MapPrototype.withMutations;
  23144. StackPrototype.asMutable = MapPrototype.asMutable;
  23145. StackPrototype.asImmutable = MapPrototype.asImmutable;
  23146. StackPrototype.wasAltered = MapPrototype.wasAltered;
  23147. function makeStack(size, head, ownerID, hash) {
  23148. var map = Object.create(StackPrototype);
  23149. map.size = size;
  23150. map._head = head;
  23151. map.__ownerID = ownerID;
  23152. map.__hash = hash;
  23153. map.__altered = false;
  23154. return map;
  23155. }
  23156. var EMPTY_STACK;
  23157. function emptyStack() {
  23158. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  23159. }
  23160. /**
  23161. * Contributes additional methods to a constructor
  23162. */
  23163. function mixin(ctor, methods) {
  23164. var keyCopier = function(key ) { ctor.prototype[key] = methods[key]; };
  23165. Object.keys(methods).forEach(keyCopier);
  23166. Object.getOwnPropertySymbols &&
  23167. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  23168. return ctor;
  23169. }
  23170. Iterable.Iterator = Iterator;
  23171. mixin(Iterable, {
  23172. // ### Conversion to other types
  23173. toArray: function() {
  23174. assertNotInfinite(this.size);
  23175. var array = new Array(this.size || 0);
  23176. this.valueSeq().__iterate(function(v, i) { array[i] = v; });
  23177. return array;
  23178. },
  23179. toIndexedSeq: function() {
  23180. return new ToIndexedSequence(this);
  23181. },
  23182. toJS: function() {
  23183. return this.toSeq().map(
  23184. function(value ) {return value && typeof value.toJS === 'function' ? value.toJS() : value}
  23185. ).__toJS();
  23186. },
  23187. toJSON: function() {
  23188. return this.toSeq().map(
  23189. function(value ) {return value && typeof value.toJSON === 'function' ? value.toJSON() : value}
  23190. ).__toJS();
  23191. },
  23192. toKeyedSeq: function() {
  23193. return new ToKeyedSequence(this, true);
  23194. },
  23195. toMap: function() {
  23196. // Use Late Binding here to solve the circular dependency.
  23197. return Map(this.toKeyedSeq());
  23198. },
  23199. toObject: function() {
  23200. assertNotInfinite(this.size);
  23201. var object = {};
  23202. this.__iterate(function(v, k) { object[k] = v; });
  23203. return object;
  23204. },
  23205. toOrderedMap: function() {
  23206. // Use Late Binding here to solve the circular dependency.
  23207. return OrderedMap(this.toKeyedSeq());
  23208. },
  23209. toOrderedSet: function() {
  23210. // Use Late Binding here to solve the circular dependency.
  23211. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  23212. },
  23213. toSet: function() {
  23214. // Use Late Binding here to solve the circular dependency.
  23215. return Set(isKeyed(this) ? this.valueSeq() : this);
  23216. },
  23217. toSetSeq: function() {
  23218. return new ToSetSequence(this);
  23219. },
  23220. toSeq: function() {
  23221. return isIndexed(this) ? this.toIndexedSeq() :
  23222. isKeyed(this) ? this.toKeyedSeq() :
  23223. this.toSetSeq();
  23224. },
  23225. toStack: function() {
  23226. // Use Late Binding here to solve the circular dependency.
  23227. return Stack(isKeyed(this) ? this.valueSeq() : this);
  23228. },
  23229. toList: function() {
  23230. // Use Late Binding here to solve the circular dependency.
  23231. return List(isKeyed(this) ? this.valueSeq() : this);
  23232. },
  23233. // ### Common JavaScript methods and properties
  23234. toString: function() {
  23235. return '[Iterable]';
  23236. },
  23237. __toString: function(head, tail) {
  23238. if (this.size === 0) {
  23239. return head + tail;
  23240. }
  23241. return head + ' ' + this.toSeq().map(this.__toStringMapper).join(', ') + ' ' + tail;
  23242. },
  23243. // ### ES6 Collection methods (ES6 Array and Map)
  23244. concat: function() {var values = SLICE$0.call(arguments, 0);
  23245. return reify(this, concatFactory(this, values));
  23246. },
  23247. includes: function(searchValue) {
  23248. return this.some(function(value ) {return is(value, searchValue)});
  23249. },
  23250. entries: function() {
  23251. return this.__iterator(ITERATE_ENTRIES);
  23252. },
  23253. every: function(predicate, context) {
  23254. assertNotInfinite(this.size);
  23255. var returnValue = true;
  23256. this.__iterate(function(v, k, c) {
  23257. if (!predicate.call(context, v, k, c)) {
  23258. returnValue = false;
  23259. return false;
  23260. }
  23261. });
  23262. return returnValue;
  23263. },
  23264. filter: function(predicate, context) {
  23265. return reify(this, filterFactory(this, predicate, context, true));
  23266. },
  23267. find: function(predicate, context, notSetValue) {
  23268. var entry = this.findEntry(predicate, context);
  23269. return entry ? entry[1] : notSetValue;
  23270. },
  23271. findEntry: function(predicate, context) {
  23272. var found;
  23273. this.__iterate(function(v, k, c) {
  23274. if (predicate.call(context, v, k, c)) {
  23275. found = [k, v];
  23276. return false;
  23277. }
  23278. });
  23279. return found;
  23280. },
  23281. findLastEntry: function(predicate, context) {
  23282. return this.toSeq().reverse().findEntry(predicate, context);
  23283. },
  23284. forEach: function(sideEffect, context) {
  23285. assertNotInfinite(this.size);
  23286. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  23287. },
  23288. join: function(separator) {
  23289. assertNotInfinite(this.size);
  23290. separator = separator !== undefined ? '' + separator : ',';
  23291. var joined = '';
  23292. var isFirst = true;
  23293. this.__iterate(function(v ) {
  23294. isFirst ? (isFirst = false) : (joined += separator);
  23295. joined += v !== null && v !== undefined ? v.toString() : '';
  23296. });
  23297. return joined;
  23298. },
  23299. keys: function() {
  23300. return this.__iterator(ITERATE_KEYS);
  23301. },
  23302. map: function(mapper, context) {
  23303. return reify(this, mapFactory(this, mapper, context));
  23304. },
  23305. reduce: function(reducer, initialReduction, context) {
  23306. assertNotInfinite(this.size);
  23307. var reduction;
  23308. var useFirst;
  23309. if (arguments.length < 2) {
  23310. useFirst = true;
  23311. } else {
  23312. reduction = initialReduction;
  23313. }
  23314. this.__iterate(function(v, k, c) {
  23315. if (useFirst) {
  23316. useFirst = false;
  23317. reduction = v;
  23318. } else {
  23319. reduction = reducer.call(context, reduction, v, k, c);
  23320. }
  23321. });
  23322. return reduction;
  23323. },
  23324. reduceRight: function(reducer, initialReduction, context) {
  23325. var reversed = this.toKeyedSeq().reverse();
  23326. return reversed.reduce.apply(reversed, arguments);
  23327. },
  23328. reverse: function() {
  23329. return reify(this, reverseFactory(this, true));
  23330. },
  23331. slice: function(begin, end) {
  23332. return reify(this, sliceFactory(this, begin, end, true));
  23333. },
  23334. some: function(predicate, context) {
  23335. return !this.every(not(predicate), context);
  23336. },
  23337. sort: function(comparator) {
  23338. return reify(this, sortFactory(this, comparator));
  23339. },
  23340. values: function() {
  23341. return this.__iterator(ITERATE_VALUES);
  23342. },
  23343. // ### More sequential methods
  23344. butLast: function() {
  23345. return this.slice(0, -1);
  23346. },
  23347. isEmpty: function() {
  23348. return this.size !== undefined ? this.size === 0 : !this.some(function() {return true});
  23349. },
  23350. count: function(predicate, context) {
  23351. return ensureSize(
  23352. predicate ? this.toSeq().filter(predicate, context) : this
  23353. );
  23354. },
  23355. countBy: function(grouper, context) {
  23356. return countByFactory(this, grouper, context);
  23357. },
  23358. equals: function(other) {
  23359. return deepEqual(this, other);
  23360. },
  23361. entrySeq: function() {
  23362. var iterable = this;
  23363. if (iterable._cache) {
  23364. // We cache as an entries array, so we can just return the cache!
  23365. return new ArraySeq(iterable._cache);
  23366. }
  23367. var entriesSequence = iterable.toSeq().map(entryMapper).toIndexedSeq();
  23368. entriesSequence.fromEntrySeq = function() {return iterable.toSeq()};
  23369. return entriesSequence;
  23370. },
  23371. filterNot: function(predicate, context) {
  23372. return this.filter(not(predicate), context);
  23373. },
  23374. findLast: function(predicate, context, notSetValue) {
  23375. return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
  23376. },
  23377. first: function() {
  23378. return this.find(returnTrue);
  23379. },
  23380. flatMap: function(mapper, context) {
  23381. return reify(this, flatMapFactory(this, mapper, context));
  23382. },
  23383. flatten: function(depth) {
  23384. return reify(this, flattenFactory(this, depth, true));
  23385. },
  23386. fromEntrySeq: function() {
  23387. return new FromEntriesSequence(this);
  23388. },
  23389. get: function(searchKey, notSetValue) {
  23390. return this.find(function(_, key) {return is(key, searchKey)}, undefined, notSetValue);
  23391. },
  23392. getIn: function(searchKeyPath, notSetValue) {
  23393. var nested = this;
  23394. // Note: in an ES6 environment, we would prefer:
  23395. // for (var key of searchKeyPath) {
  23396. var iter = forceIterator(searchKeyPath);
  23397. var step;
  23398. while (!(step = iter.next()).done) {
  23399. var key = step.value;
  23400. nested = nested && nested.get ? nested.get(key, NOT_SET) : NOT_SET;
  23401. if (nested === NOT_SET) {
  23402. return notSetValue;
  23403. }
  23404. }
  23405. return nested;
  23406. },
  23407. groupBy: function(grouper, context) {
  23408. return groupByFactory(this, grouper, context);
  23409. },
  23410. has: function(searchKey) {
  23411. return this.get(searchKey, NOT_SET) !== NOT_SET;
  23412. },
  23413. hasIn: function(searchKeyPath) {
  23414. return this.getIn(searchKeyPath, NOT_SET) !== NOT_SET;
  23415. },
  23416. isSubset: function(iter) {
  23417. iter = typeof iter.includes === 'function' ? iter : Iterable(iter);
  23418. return this.every(function(value ) {return iter.includes(value)});
  23419. },
  23420. isSuperset: function(iter) {
  23421. iter = typeof iter.isSubset === 'function' ? iter : Iterable(iter);
  23422. return iter.isSubset(this);
  23423. },
  23424. keySeq: function() {
  23425. return this.toSeq().map(keyMapper).toIndexedSeq();
  23426. },
  23427. last: function() {
  23428. return this.toSeq().reverse().first();
  23429. },
  23430. max: function(comparator) {
  23431. return maxFactory(this, comparator);
  23432. },
  23433. maxBy: function(mapper, comparator) {
  23434. return maxFactory(this, comparator, mapper);
  23435. },
  23436. min: function(comparator) {
  23437. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator);
  23438. },
  23439. minBy: function(mapper, comparator) {
  23440. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator, mapper);
  23441. },
  23442. rest: function() {
  23443. return this.slice(1);
  23444. },
  23445. skip: function(amount) {
  23446. return this.slice(Math.max(0, amount));
  23447. },
  23448. skipLast: function(amount) {
  23449. return reify(this, this.toSeq().reverse().skip(amount).reverse());
  23450. },
  23451. skipWhile: function(predicate, context) {
  23452. return reify(this, skipWhileFactory(this, predicate, context, true));
  23453. },
  23454. skipUntil: function(predicate, context) {
  23455. return this.skipWhile(not(predicate), context);
  23456. },
  23457. sortBy: function(mapper, comparator) {
  23458. return reify(this, sortFactory(this, comparator, mapper));
  23459. },
  23460. take: function(amount) {
  23461. return this.slice(0, Math.max(0, amount));
  23462. },
  23463. takeLast: function(amount) {
  23464. return reify(this, this.toSeq().reverse().take(amount).reverse());
  23465. },
  23466. takeWhile: function(predicate, context) {
  23467. return reify(this, takeWhileFactory(this, predicate, context));
  23468. },
  23469. takeUntil: function(predicate, context) {
  23470. return this.takeWhile(not(predicate), context);
  23471. },
  23472. valueSeq: function() {
  23473. return this.toIndexedSeq();
  23474. },
  23475. // ### Hashable Object
  23476. hashCode: function() {
  23477. return this.__hash || (this.__hash = hashIterable(this));
  23478. }
  23479. // ### Internal
  23480. // abstract __iterate(fn, reverse)
  23481. // abstract __iterator(type, reverse)
  23482. });
  23483. // var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  23484. // var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  23485. // var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  23486. // var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  23487. var IterablePrototype = Iterable.prototype;
  23488. IterablePrototype[IS_ITERABLE_SENTINEL] = true;
  23489. IterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.values;
  23490. IterablePrototype.__toJS = IterablePrototype.toArray;
  23491. IterablePrototype.__toStringMapper = quoteString;
  23492. IterablePrototype.inspect =
  23493. IterablePrototype.toSource = function() { return this.toString(); };
  23494. IterablePrototype.chain = IterablePrototype.flatMap;
  23495. IterablePrototype.contains = IterablePrototype.includes;
  23496. // Temporary warning about using length
  23497. (function () {
  23498. try {
  23499. Object.defineProperty(IterablePrototype, 'length', {
  23500. get: function () {
  23501. if (!Iterable.noLengthWarning) {
  23502. var stack;
  23503. try {
  23504. throw new Error();
  23505. } catch (error) {
  23506. stack = error.stack;
  23507. }
  23508. if (stack.indexOf('_wrapObject') === -1) {
  23509. console && console.warn && console.warn(
  23510. 'iterable.length has been deprecated, '+
  23511. 'use iterable.size or iterable.count(). '+
  23512. 'This warning will become a silent error in a future version. ' +
  23513. stack
  23514. );
  23515. return this.size;
  23516. }
  23517. }
  23518. }
  23519. });
  23520. } catch (e) {}
  23521. })();
  23522. mixin(KeyedIterable, {
  23523. // ### More sequential methods
  23524. flip: function() {
  23525. return reify(this, flipFactory(this));
  23526. },
  23527. findKey: function(predicate, context) {
  23528. var entry = this.findEntry(predicate, context);
  23529. return entry && entry[0];
  23530. },
  23531. findLastKey: function(predicate, context) {
  23532. return this.toSeq().reverse().findKey(predicate, context);
  23533. },
  23534. keyOf: function(searchValue) {
  23535. return this.findKey(function(value ) {return is(value, searchValue)});
  23536. },
  23537. lastKeyOf: function(searchValue) {
  23538. return this.findLastKey(function(value ) {return is(value, searchValue)});
  23539. },
  23540. mapEntries: function(mapper, context) {var this$0 = this;
  23541. var iterations = 0;
  23542. return reify(this,
  23543. this.toSeq().map(
  23544. function(v, k) {return mapper.call(context, [k, v], iterations++, this$0)}
  23545. ).fromEntrySeq()
  23546. );
  23547. },
  23548. mapKeys: function(mapper, context) {var this$0 = this;
  23549. return reify(this,
  23550. this.toSeq().flip().map(
  23551. function(k, v) {return mapper.call(context, k, v, this$0)}
  23552. ).flip()
  23553. );
  23554. }
  23555. });
  23556. var KeyedIterablePrototype = KeyedIterable.prototype;
  23557. KeyedIterablePrototype[IS_KEYED_SENTINEL] = true;
  23558. KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries;
  23559. KeyedIterablePrototype.__toJS = IterablePrototype.toObject;
  23560. KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)};
  23561. mixin(IndexedIterable, {
  23562. // ### Conversion to other types
  23563. toKeyedSeq: function() {
  23564. return new ToKeyedSequence(this, false);
  23565. },
  23566. // ### ES6 Collection methods (ES6 Array and Map)
  23567. filter: function(predicate, context) {
  23568. return reify(this, filterFactory(this, predicate, context, false));
  23569. },
  23570. findIndex: function(predicate, context) {
  23571. var entry = this.findEntry(predicate, context);
  23572. return entry ? entry[0] : -1;
  23573. },
  23574. indexOf: function(searchValue) {
  23575. var key = this.toKeyedSeq().keyOf(searchValue);
  23576. return key === undefined ? -1 : key;
  23577. },
  23578. lastIndexOf: function(searchValue) {
  23579. var key = this.toKeyedSeq().reverse().keyOf(searchValue);
  23580. return key === undefined ? -1 : key;
  23581. // var index =
  23582. // return this.toSeq().reverse().indexOf(searchValue);
  23583. },
  23584. reverse: function() {
  23585. return reify(this, reverseFactory(this, false));
  23586. },
  23587. slice: function(begin, end) {
  23588. return reify(this, sliceFactory(this, begin, end, false));
  23589. },
  23590. splice: function(index, removeNum /*, ...values*/) {
  23591. var numArgs = arguments.length;
  23592. removeNum = Math.max(removeNum | 0, 0);
  23593. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  23594. return this;
  23595. }
  23596. // If index is negative, it should resolve relative to the size of the
  23597. // collection. However size may be expensive to compute if not cached, so
  23598. // only call count() if the number is in fact negative.
  23599. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  23600. var spliced = this.slice(0, index);
  23601. return reify(
  23602. this,
  23603. numArgs === 1 ?
  23604. spliced :
  23605. spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  23606. );
  23607. },
  23608. // ### More collection methods
  23609. findLastIndex: function(predicate, context) {
  23610. var key = this.toKeyedSeq().findLastKey(predicate, context);
  23611. return key === undefined ? -1 : key;
  23612. },
  23613. first: function() {
  23614. return this.get(0);
  23615. },
  23616. flatten: function(depth) {
  23617. return reify(this, flattenFactory(this, depth, false));
  23618. },
  23619. get: function(index, notSetValue) {
  23620. index = wrapIndex(this, index);
  23621. return (index < 0 || (this.size === Infinity ||
  23622. (this.size !== undefined && index > this.size))) ?
  23623. notSetValue :
  23624. this.find(function(_, key) {return key === index}, undefined, notSetValue);
  23625. },
  23626. has: function(index) {
  23627. index = wrapIndex(this, index);
  23628. return index >= 0 && (this.size !== undefined ?
  23629. this.size === Infinity || index < this.size :
  23630. this.indexOf(index) !== -1
  23631. );
  23632. },
  23633. interpose: function(separator) {
  23634. return reify(this, interposeFactory(this, separator));
  23635. },
  23636. interleave: function(/*...iterables*/) {
  23637. var iterables = [this].concat(arrCopy(arguments));
  23638. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, iterables);
  23639. var interleaved = zipped.flatten(true);
  23640. if (zipped.size) {
  23641. interleaved.size = zipped.size * iterables.length;
  23642. }
  23643. return reify(this, interleaved);
  23644. },
  23645. last: function() {
  23646. return this.get(-1);
  23647. },
  23648. skipWhile: function(predicate, context) {
  23649. return reify(this, skipWhileFactory(this, predicate, context, false));
  23650. },
  23651. zip: function(/*, ...iterables */) {
  23652. var iterables = [this].concat(arrCopy(arguments));
  23653. return reify(this, zipWithFactory(this, defaultZipper, iterables));
  23654. },
  23655. zipWith: function(zipper/*, ...iterables */) {
  23656. var iterables = arrCopy(arguments);
  23657. iterables[0] = this;
  23658. return reify(this, zipWithFactory(this, zipper, iterables));
  23659. }
  23660. });
  23661. IndexedIterable.prototype[IS_INDEXED_SENTINEL] = true;
  23662. IndexedIterable.prototype[IS_ORDERED_SENTINEL] = true;
  23663. mixin(SetIterable, {
  23664. // ### ES6 Collection methods (ES6 Array and Map)
  23665. get: function(value, notSetValue) {
  23666. return this.has(value) ? value : notSetValue;
  23667. },
  23668. includes: function(value) {
  23669. return this.has(value);
  23670. },
  23671. // ### More sequential methods
  23672. keySeq: function() {
  23673. return this.valueSeq();
  23674. }
  23675. });
  23676. SetIterable.prototype.has = IterablePrototype.includes;
  23677. // Mixin subclasses
  23678. mixin(KeyedSeq, KeyedIterable.prototype);
  23679. mixin(IndexedSeq, IndexedIterable.prototype);
  23680. mixin(SetSeq, SetIterable.prototype);
  23681. mixin(KeyedCollection, KeyedIterable.prototype);
  23682. mixin(IndexedCollection, IndexedIterable.prototype);
  23683. mixin(SetCollection, SetIterable.prototype);
  23684. // #pragma Helper functions
  23685. function keyMapper(v, k) {
  23686. return k;
  23687. }
  23688. function entryMapper(v, k) {
  23689. return [k, v];
  23690. }
  23691. function not(predicate) {
  23692. return function() {
  23693. return !predicate.apply(this, arguments);
  23694. }
  23695. }
  23696. function neg(predicate) {
  23697. return function() {
  23698. return -predicate.apply(this, arguments);
  23699. }
  23700. }
  23701. function quoteString(value) {
  23702. return typeof value === 'string' ? JSON.stringify(value) : value;
  23703. }
  23704. function defaultZipper() {
  23705. return arrCopy(arguments);
  23706. }
  23707. function defaultNegComparator(a, b) {
  23708. return a < b ? 1 : a > b ? -1 : 0;
  23709. }
  23710. function hashIterable(iterable) {
  23711. if (iterable.size === Infinity) {
  23712. return 0;
  23713. }
  23714. var ordered = isOrdered(iterable);
  23715. var keyed = isKeyed(iterable);
  23716. var h = ordered ? 1 : 0;
  23717. var size = iterable.__iterate(
  23718. keyed ?
  23719. ordered ?
  23720. function(v, k) { h = 31 * h + hashMerge(hash(v), hash(k)) | 0; } :
  23721. function(v, k) { h = h + hashMerge(hash(v), hash(k)) | 0; } :
  23722. ordered ?
  23723. function(v ) { h = 31 * h + hash(v) | 0; } :
  23724. function(v ) { h = h + hash(v) | 0; }
  23725. );
  23726. return murmurHashOfSize(size, h);
  23727. }
  23728. function murmurHashOfSize(size, h) {
  23729. h = imul(h, 0xCC9E2D51);
  23730. h = imul(h << 15 | h >>> -15, 0x1B873593);
  23731. h = imul(h << 13 | h >>> -13, 5);
  23732. h = (h + 0xE6546B64 | 0) ^ size;
  23733. h = imul(h ^ h >>> 16, 0x85EBCA6B);
  23734. h = imul(h ^ h >>> 13, 0xC2B2AE35);
  23735. h = smi(h ^ h >>> 16);
  23736. return h;
  23737. }
  23738. function hashMerge(a, b) {
  23739. return a ^ b + 0x9E3779B9 + (a << 6) + (a >> 2) | 0; // int
  23740. }
  23741. var Immutable = {
  23742. Iterable: Iterable,
  23743. Seq: Seq,
  23744. Collection: Collection,
  23745. Map: Map,
  23746. OrderedMap: OrderedMap,
  23747. List: List,
  23748. Stack: Stack,
  23749. Set: Set,
  23750. OrderedSet: OrderedSet,
  23751. Record: Record,
  23752. Range: Range,
  23753. Repeat: Repeat,
  23754. is: is,
  23755. fromJS: fromJS
  23756. };
  23757. return Immutable;
  23758. }));
  23759. });
  23760. var parseHTML_1 = styleInject_es.createCommonjsModule(function (module, exports) {
  23761. Object.defineProperty(exports, "__esModule", {
  23762. value: true
  23763. });
  23764. exports["default"] = parseHTML;
  23765. var fallback = function fallback(html) {
  23766. var doc = document.implementation.createHTMLDocument('');
  23767. doc.documentElement.innerHTML = html;
  23768. return doc;
  23769. };
  23770. function parseHTML(html) {
  23771. var doc;
  23772. if (typeof DOMParser !== 'undefined') {
  23773. var parser = new DOMParser();
  23774. doc = parser.parseFromString(html, 'text/html');
  23775. if (doc === null || doc.body === null) {
  23776. doc = fallback(html);
  23777. }
  23778. } else {
  23779. doc = fallback(html);
  23780. }
  23781. return doc.body;
  23782. }
  23783. });
  23784. styleInject_es.unwrapExports(parseHTML_1);
  23785. var convertFromHTML_1 = styleInject_es.createCommonjsModule(function (module, exports) {
  23786. Object.defineProperty(exports, "__esModule", {
  23787. value: true
  23788. });
  23789. exports["default"] = void 0;
  23790. var _parseHTML = interopRequireDefault(parseHTML_1);
  23791. var _rangeSort = interopRequireDefault(rangeSort);
  23792. /**
  23793. * Copyright (c) 2013-present, Facebook, Inc.
  23794. * All rights reserved.
  23795. *
  23796. * Copyright (c) 2013-present, Facebook, Inc.
  23797. * All rights reserved.
  23798. *
  23799. * This source code is licensed under the BSD-style license found in the
  23800. * LICENSE file in the /src directory of this source tree. An additional grant
  23801. * of patent rights can be found in the PATENTS file in the same directory.
  23802. */
  23803. var NBSP = '&nbsp;';
  23804. var SPACE = ' '; // Arbitrary max indent
  23805. var MAX_DEPTH = 4; // used for replacing characters in HTML
  23806. /* eslint-disable no-control-regex */
  23807. var REGEX_CR = new RegExp('\r', 'g');
  23808. var REGEX_LF = new RegExp('\n', 'g');
  23809. var REGEX_NBSP = new RegExp(NBSP, 'g');
  23810. var REGEX_BLOCK_DELIMITER = new RegExp('\r', 'g');
  23811. /* eslint-enable no-control-regex */
  23812. // Block tag flow is different because LIs do not have
  23813. // a deterministic style ;_;
  23814. var blockTags = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'li', 'blockquote', 'pre'];
  23815. var inlineTags = {
  23816. b: 'BOLD',
  23817. code: 'CODE',
  23818. del: 'STRIKETHROUGH',
  23819. em: 'ITALIC',
  23820. i: 'ITALIC',
  23821. s: 'STRIKETHROUGH',
  23822. strike: 'STRIKETHROUGH',
  23823. strong: 'BOLD',
  23824. u: 'UNDERLINE'
  23825. };
  23826. var handleMiddleware = function handleMiddleware(maybeMiddleware, base) {
  23827. if (maybeMiddleware && maybeMiddleware.__isMiddleware === true) {
  23828. return maybeMiddleware(base);
  23829. }
  23830. return maybeMiddleware;
  23831. };
  23832. var defaultHTMLToBlock = function defaultHTMLToBlock(nodeName, node, lastList) {
  23833. return undefined;
  23834. };
  23835. var defaultHTMLToStyle = function defaultHTMLToStyle(nodeName, node, currentStyle) {
  23836. return currentStyle;
  23837. };
  23838. var defaultHTMLToEntity = function defaultHTMLToEntity(nodeName, node) {
  23839. return undefined;
  23840. };
  23841. var defaultTextToEntity = function defaultTextToEntity(text) {
  23842. return [];
  23843. };
  23844. var nullthrows = function nullthrows(x) {
  23845. if (x != null) {
  23846. return x;
  23847. }
  23848. throw new Error('Got unexpected null or undefined');
  23849. };
  23850. var sanitizeDraftText = function sanitizeDraftText(input) {
  23851. return input.replace(REGEX_BLOCK_DELIMITER, '');
  23852. };
  23853. function getEmptyChunk() {
  23854. return {
  23855. text: '',
  23856. inlines: [],
  23857. entities: [],
  23858. blocks: []
  23859. };
  23860. }
  23861. function getWhitespaceChunk(inEntity) {
  23862. var entities = new Array(1);
  23863. if (inEntity) {
  23864. entities[0] = inEntity;
  23865. }
  23866. return {
  23867. text: SPACE,
  23868. inlines: [(0, immutable$2.OrderedSet)()],
  23869. entities: entities,
  23870. blocks: []
  23871. };
  23872. }
  23873. function getSoftNewlineChunk(block, depth) {
  23874. var flat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  23875. var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : (0, immutable$2.Map)();
  23876. if (flat === true) {
  23877. return {
  23878. text: '\r',
  23879. inlines: [(0, immutable$2.OrderedSet)()],
  23880. entities: new Array(1),
  23881. blocks: [{
  23882. type: block,
  23883. data: data,
  23884. depth: Math.max(0, Math.min(MAX_DEPTH, depth))
  23885. }],
  23886. isNewline: true
  23887. };
  23888. }
  23889. return {
  23890. text: '\n',
  23891. inlines: [(0, immutable$2.OrderedSet)()],
  23892. entities: new Array(1),
  23893. blocks: []
  23894. };
  23895. }
  23896. function getBlockDividerChunk(block, depth) {
  23897. var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : (0, immutable$2.Map)();
  23898. return {
  23899. text: '\r',
  23900. inlines: [(0, immutable$2.OrderedSet)()],
  23901. entities: new Array(1),
  23902. blocks: [{
  23903. type: block,
  23904. data: data,
  23905. depth: Math.max(0, Math.min(MAX_DEPTH, depth))
  23906. }]
  23907. };
  23908. }
  23909. function getBlockTypeForTag(tag, lastList) {
  23910. switch (tag) {
  23911. case 'h1':
  23912. return 'header-one';
  23913. case 'h2':
  23914. return 'header-two';
  23915. case 'h3':
  23916. return 'header-three';
  23917. case 'h4':
  23918. return 'header-four';
  23919. case 'h5':
  23920. return 'header-five';
  23921. case 'h6':
  23922. return 'header-six';
  23923. case 'li':
  23924. if (lastList === 'ol') {
  23925. return 'ordered-list-item';
  23926. }
  23927. return 'unordered-list-item';
  23928. case 'blockquote':
  23929. return 'blockquote';
  23930. case 'pre':
  23931. return 'code-block';
  23932. case 'div':
  23933. case 'p':
  23934. return 'unstyled';
  23935. default:
  23936. return null;
  23937. }
  23938. }
  23939. function baseCheckBlockType(nodeName, node, lastList) {
  23940. return getBlockTypeForTag(nodeName, lastList);
  23941. }
  23942. function processInlineTag(tag, node, currentStyle) {
  23943. var styleToCheck = inlineTags[tag];
  23944. if (styleToCheck) {
  23945. currentStyle = currentStyle.add(styleToCheck).toOrderedSet();
  23946. } else if (node instanceof HTMLElement) {
  23947. var htmlElement = node;
  23948. currentStyle = currentStyle.withMutations(function (style) {
  23949. if (htmlElement.style.fontWeight === 'bold') {
  23950. style.add('BOLD');
  23951. }
  23952. if (htmlElement.style.fontStyle === 'italic') {
  23953. style.add('ITALIC');
  23954. }
  23955. if (htmlElement.style.textDecoration === 'underline') {
  23956. style.add('UNDERLINE');
  23957. }
  23958. if (htmlElement.style.textDecoration === 'line-through') {
  23959. style.add('STRIKETHROUGH');
  23960. }
  23961. }).toOrderedSet();
  23962. }
  23963. return currentStyle;
  23964. }
  23965. function baseProcessInlineTag(tag, node) {
  23966. var inlineStyles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : (0, immutable$2.OrderedSet)();
  23967. return processInlineTag(tag, node, inlineStyles);
  23968. }
  23969. function joinChunks(A, B) {
  23970. var flat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  23971. // Sometimes two blocks will touch in the DOM and we need to strip the
  23972. // extra delimiter to preserve niceness.
  23973. var firstInB = B.text.slice(0, 1);
  23974. var lastInA = A.text.slice(-1);
  23975. var adjacentDividers = lastInA === '\r' && firstInB === '\r';
  23976. var isJoiningBlocks = A.text !== '\r' && B.text !== '\r'; // when joining two full blocks like this we want to pop one divider
  23977. var addingNewlineToEmptyBlock = A.text === '\r' && !A.isNewline && B.isNewline; // when joining a newline to an empty block we want to remove the newline
  23978. if (adjacentDividers && (isJoiningBlocks || addingNewlineToEmptyBlock)) {
  23979. A.text = A.text.slice(0, -1);
  23980. A.inlines.pop();
  23981. A.entities.pop();
  23982. A.blocks.pop();
  23983. } // Kill whitespace after blocks if flat mode is on
  23984. if (A.text.slice(-1) === '\r' && flat === true) {
  23985. if (B.text === SPACE || B.text === '\n') {
  23986. return A;
  23987. } else if (firstInB === SPACE || firstInB === '\n') {
  23988. B.text = B.text.slice(1);
  23989. B.inlines.shift();
  23990. B.entities.shift();
  23991. }
  23992. }
  23993. var isNewline = A.text.length === 0 && B.isNewline;
  23994. return {
  23995. text: A.text + B.text,
  23996. inlines: A.inlines.concat(B.inlines),
  23997. entities: A.entities.concat(B.entities),
  23998. blocks: A.blocks.concat(B.blocks),
  23999. isNewline: isNewline
  24000. };
  24001. }
  24002. /*
  24003. * Check to see if we have anything like <p> <blockquote> <h1>... to create
  24004. * block tags from. If we do, we can use those and ignore <div> tags. If we
  24005. * don't, we can treat <div> tags as meaningful (unstyled) blocks.
  24006. */
  24007. function containsSemanticBlockMarkup(html) {
  24008. return blockTags.some(function (tag) {
  24009. return html.indexOf("<".concat(tag)) !== -1;
  24010. });
  24011. }
  24012. function genFragment(node, inlineStyle, lastList, inBlock, fragmentBlockTags, depth, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, inEntity) {
  24013. var nodeName = node.nodeName.toLowerCase();
  24014. var newBlock = false;
  24015. var nextBlockType = 'unstyled'; // Base Case
  24016. if (nodeName === '#text') {
  24017. var text = node.textContent;
  24018. if (text.trim() === '' && inBlock === null) {
  24019. return getEmptyChunk();
  24020. }
  24021. if (text.trim() === '' && inBlock !== 'code-block') {
  24022. return getWhitespaceChunk(inEntity);
  24023. }
  24024. if (inBlock !== 'code-block') {
  24025. // Can't use empty string because MSWord
  24026. text = text.replace(REGEX_LF, SPACE);
  24027. }
  24028. var entities = Array(text.length).fill(inEntity);
  24029. var offsetChange = 0;
  24030. var textEntities = checkEntityText(text, createEntity, getEntity, mergeEntityData, replaceEntityData).sort(_rangeSort["default"]);
  24031. textEntities.forEach(function (_ref) {
  24032. var entity = _ref.entity,
  24033. offset = _ref.offset,
  24034. length = _ref.length,
  24035. result = _ref.result;
  24036. var adjustedOffset = offset + offsetChange;
  24037. if (result === null || result === undefined) {
  24038. result = text.substr(adjustedOffset, length);
  24039. }
  24040. var textArray = text.split('');
  24041. textArray.splice.bind(textArray, adjustedOffset, length).apply(textArray, result.split(''));
  24042. text = textArray.join('');
  24043. entities.splice.bind(entities, adjustedOffset, length).apply(entities, Array(result.length).fill(entity));
  24044. offsetChange += result.length - length;
  24045. });
  24046. return {
  24047. text: text,
  24048. inlines: Array(text.length).fill(inlineStyle),
  24049. entities: entities,
  24050. blocks: []
  24051. };
  24052. } // BR tags
  24053. if (nodeName === 'br') {
  24054. var _blockType = inBlock;
  24055. if (_blockType === null) {
  24056. // BR tag is at top level, treat it as an unstyled block
  24057. return getSoftNewlineChunk('unstyled', depth, true);
  24058. }
  24059. return getSoftNewlineChunk(_blockType || 'unstyled', depth, options.flat);
  24060. }
  24061. var chunk = getEmptyChunk();
  24062. var newChunk = null; // Inline tags
  24063. inlineStyle = processInlineTag(nodeName, node, inlineStyle);
  24064. inlineStyle = processCustomInlineStyles(nodeName, node, inlineStyle); // Handle lists
  24065. if (nodeName === 'ul' || nodeName === 'ol') {
  24066. if (lastList) {
  24067. depth += 1;
  24068. }
  24069. lastList = nodeName;
  24070. inBlock = null;
  24071. } // Block Tags
  24072. var blockInfo = checkBlockType(nodeName, node, lastList, inBlock);
  24073. var blockType;
  24074. var blockDataMap;
  24075. if (blockInfo === false) {
  24076. return getEmptyChunk();
  24077. }
  24078. blockInfo = blockInfo || {};
  24079. if (typeof blockInfo === 'string') {
  24080. blockType = blockInfo;
  24081. blockDataMap = (0, immutable$2.Map)();
  24082. } else {
  24083. blockType = typeof blockInfo === 'string' ? blockInfo : blockInfo.type;
  24084. blockDataMap = blockInfo.data ? (0, immutable$2.Map)(blockInfo.data) : (0, immutable$2.Map)();
  24085. }
  24086. if (!inBlock && (fragmentBlockTags.indexOf(nodeName) !== -1 || blockType)) {
  24087. chunk = getBlockDividerChunk(blockType || getBlockTypeForTag(nodeName, lastList), depth, blockDataMap);
  24088. inBlock = blockType || getBlockTypeForTag(nodeName, lastList);
  24089. newBlock = true;
  24090. } else if (lastList && (inBlock === 'ordered-list-item' || inBlock === 'unordered-list-item') && nodeName === 'li') {
  24091. var listItemBlockType = getBlockTypeForTag(nodeName, lastList);
  24092. chunk = getBlockDividerChunk(listItemBlockType, depth);
  24093. inBlock = listItemBlockType;
  24094. newBlock = true;
  24095. nextBlockType = lastList === 'ul' ? 'unordered-list-item' : 'ordered-list-item';
  24096. } else if (inBlock && inBlock !== 'atomic' && blockType === 'atomic') {
  24097. inBlock = blockType;
  24098. newBlock = true;
  24099. chunk = getSoftNewlineChunk(blockType, depth, true, // atomic blocks within non-atomic blocks must always be split out
  24100. blockDataMap);
  24101. } // Recurse through children
  24102. var child = node.firstChild; // hack to allow conversion of atomic blocks from HTML (e.g. <figure><img
  24103. // src="..." /></figure>). since metadata must be stored on an entity text
  24104. // must exist for the entity to apply to. the way chunks are joined strips
  24105. // whitespace at the end so it cannot be a space character.
  24106. if (child == null && inEntity && (blockType === 'atomic' || inBlock === 'atomic')) {
  24107. child = document.createTextNode('a');
  24108. }
  24109. if (child != null) {
  24110. nodeName = child.nodeName.toLowerCase();
  24111. }
  24112. var entityId = null;
  24113. while (child) {
  24114. entityId = checkEntityNode(nodeName, child, createEntity, getEntity, mergeEntityData, replaceEntityData);
  24115. newChunk = genFragment(child, inlineStyle, lastList, inBlock, fragmentBlockTags, depth, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, entityId || inEntity);
  24116. chunk = joinChunks(chunk, newChunk, options.flat);
  24117. var sibling = child.nextSibling; // Put in a newline to break up blocks inside blocks
  24118. if (sibling && fragmentBlockTags.indexOf(nodeName) >= 0 && inBlock) {
  24119. var newBlockInfo = checkBlockType(nodeName, child, lastList, inBlock);
  24120. var newBlockType = void 0;
  24121. var newBlockData = void 0;
  24122. if (newBlockInfo !== false) {
  24123. newBlockInfo = newBlockInfo || {};
  24124. if (typeof newBlockInfo === 'string') {
  24125. newBlockType = newBlockInfo;
  24126. newBlockData = (0, immutable$2.Map)();
  24127. } else {
  24128. newBlockType = newBlockInfo.type || getBlockTypeForTag(nodeName, lastList);
  24129. newBlockData = newBlockInfo.data ? (0, immutable$2.Map)(newBlockInfo.data) : (0, immutable$2.Map)();
  24130. }
  24131. chunk = joinChunks(chunk, getSoftNewlineChunk(newBlockType, depth, options.flat, newBlockData), options.flat);
  24132. }
  24133. }
  24134. if (sibling) {
  24135. nodeName = sibling.nodeName.toLowerCase();
  24136. }
  24137. child = sibling;
  24138. }
  24139. if (newBlock) {
  24140. chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, (0, immutable$2.Map)()), options.flat);
  24141. }
  24142. return chunk;
  24143. }
  24144. function getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, DOMBuilder) {
  24145. html = html.trim().replace(REGEX_CR, '').replace(REGEX_NBSP, SPACE);
  24146. var safeBody = DOMBuilder(html);
  24147. if (!safeBody) {
  24148. return null;
  24149. } // Sometimes we aren't dealing with content that contains nice semantic
  24150. // tags. In this case, use divs to separate everything out into paragraphs
  24151. // and hope for the best.
  24152. var workingBlocks = containsSemanticBlockMarkup(html) ? blockTags.concat(['div']) : ['div']; // Start with -1 block depth to offset the fact that we are passing in a fake
  24153. // UL block to sta rt with.
  24154. 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
  24155. if (chunk.text.indexOf('\r') === 0) {
  24156. chunk = {
  24157. text: chunk.text.slice(1),
  24158. inlines: chunk.inlines.slice(1),
  24159. entities: chunk.entities.slice(1),
  24160. blocks: chunk.blocks
  24161. };
  24162. } // Kill block delimiter at the end
  24163. if (chunk.text.slice(-1) === '\r') {
  24164. chunk.text = chunk.text.slice(0, -1);
  24165. chunk.inlines = chunk.inlines.slice(0, -1);
  24166. chunk.entities = chunk.entities.slice(0, -1);
  24167. chunk.blocks.pop();
  24168. } // If we saw no block tags, put an unstyled one in
  24169. if (chunk.blocks.length === 0) {
  24170. chunk.blocks.push({
  24171. type: 'unstyled',
  24172. data: (0, immutable$2.Map)(),
  24173. depth: 0
  24174. });
  24175. } // Sometimes we start with text that isn't in a block, which is then
  24176. // followed by blocks. Need to fix up the blocks to add in
  24177. // an unstyled block for this content
  24178. if (chunk.text.split('\r').length === chunk.blocks.length + 1) {
  24179. chunk.blocks.unshift({
  24180. type: 'unstyled',
  24181. data: (0, immutable$2.Map)(),
  24182. depth: 0
  24183. });
  24184. }
  24185. return chunk;
  24186. }
  24187. function convertFromHTMLtoContentBlocks(html, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, DOMBuilder, generateKey) {
  24188. // Be ABSOLUTELY SURE that the dom builder you pass hare won't execute
  24189. // arbitrary code in whatever environment you're running this in. For an
  24190. // example of how we try to do this in-browser, see getSafeBodyFromHTML.
  24191. var chunk = getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, DOMBuilder);
  24192. if (chunk == null) {
  24193. return [];
  24194. }
  24195. var start = 0;
  24196. return chunk.text.split('\r').map(function (textBlock, blockIndex) {
  24197. // Make absolutely certain that our text is acceptable.
  24198. textBlock = sanitizeDraftText(textBlock);
  24199. var end = start + textBlock.length;
  24200. var inlines = nullthrows(chunk).inlines.slice(start, end);
  24201. var entities = nullthrows(chunk).entities.slice(start, end);
  24202. var characterList = (0, immutable$2.List)(inlines.map(function (style, entityIndex) {
  24203. var data = {
  24204. style: style,
  24205. entity: null
  24206. };
  24207. if (entities[entityIndex]) {
  24208. data.entity = entities[entityIndex];
  24209. }
  24210. return Draft.CharacterMetadata.create(data);
  24211. }));
  24212. start = end + 1;
  24213. return new Draft.ContentBlock({
  24214. key: generateKey(),
  24215. type: nullthrows(chunk).blocks[blockIndex].type,
  24216. data: nullthrows(chunk).blocks[blockIndex].data,
  24217. depth: nullthrows(chunk).blocks[blockIndex].depth,
  24218. text: textBlock,
  24219. characterList: characterList
  24220. });
  24221. });
  24222. }
  24223. var convertFromHTML = function convertFromHTML(_ref2) {
  24224. var _ref2$htmlToStyle = _ref2.htmlToStyle,
  24225. htmlToStyle = _ref2$htmlToStyle === void 0 ? defaultHTMLToStyle : _ref2$htmlToStyle,
  24226. _ref2$htmlToEntity = _ref2.htmlToEntity,
  24227. htmlToEntity = _ref2$htmlToEntity === void 0 ? defaultHTMLToEntity : _ref2$htmlToEntity,
  24228. _ref2$textToEntity = _ref2.textToEntity,
  24229. textToEntity = _ref2$textToEntity === void 0 ? defaultTextToEntity : _ref2$textToEntity,
  24230. _ref2$htmlToBlock = _ref2.htmlToBlock,
  24231. htmlToBlock = _ref2$htmlToBlock === void 0 ? defaultHTMLToBlock : _ref2$htmlToBlock;
  24232. return function (html) {
  24233. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  24234. flat: false
  24235. };
  24236. var DOMBuilder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _parseHTML["default"];
  24237. var generateKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : Draft.genKey;
  24238. var contentState = Draft.ContentState.createFromText('');
  24239. var createEntityWithContentState = function createEntityWithContentState() {
  24240. if (contentState.createEntity) {
  24241. var _contentState;
  24242. contentState = (_contentState = contentState).createEntity.apply(_contentState, arguments);
  24243. return contentState.getLastCreatedEntityKey();
  24244. }
  24245. return Draft.Entity.create.apply(Draft.Entity, arguments);
  24246. };
  24247. var getEntityWithContentState = function getEntityWithContentState() {
  24248. if (contentState.getEntity) {
  24249. var _contentState2;
  24250. return (_contentState2 = contentState).getEntity.apply(_contentState2, arguments);
  24251. }
  24252. return Draft.Entity.get.apply(Draft.Entity, arguments);
  24253. };
  24254. var mergeEntityDataWithContentState = function mergeEntityDataWithContentState() {
  24255. if (contentState.mergeEntityData) {
  24256. var _contentState3;
  24257. contentState = (_contentState3 = contentState).mergeEntityData.apply(_contentState3, arguments);
  24258. return;
  24259. }
  24260. Draft.Entity.mergeData.apply(Draft.Entity, arguments);
  24261. };
  24262. var replaceEntityDataWithContentState = function replaceEntityDataWithContentState() {
  24263. if (contentState.replaceEntityData) {
  24264. var _contentState4;
  24265. contentState = (_contentState4 = contentState).replaceEntityData.apply(_contentState4, arguments);
  24266. return;
  24267. }
  24268. Draft.Entity.replaceData.apply(Draft.Entity, arguments);
  24269. };
  24270. var contentBlocks = convertFromHTMLtoContentBlocks(html, handleMiddleware(htmlToStyle, baseProcessInlineTag), handleMiddleware(htmlToEntity, defaultHTMLToEntity), handleMiddleware(textToEntity, defaultTextToEntity), handleMiddleware(htmlToBlock, baseCheckBlockType), createEntityWithContentState, getEntityWithContentState, mergeEntityDataWithContentState, replaceEntityDataWithContentState, options, DOMBuilder, generateKey);
  24271. var blockMap = Draft.BlockMapBuilder.createFromArray(contentBlocks);
  24272. var firstBlockKey = contentBlocks[0].getKey();
  24273. return contentState.merge({
  24274. blockMap: blockMap,
  24275. selectionBefore: Draft.SelectionState.createEmpty(firstBlockKey),
  24276. selectionAfter: Draft.SelectionState.createEmpty(firstBlockKey)
  24277. });
  24278. };
  24279. };
  24280. var _default = function _default() {
  24281. if (arguments.length >= 1 && typeof (arguments.length <= 0 ? undefined : arguments[0]) === 'string') {
  24282. return convertFromHTML({}).apply(void 0, arguments);
  24283. }
  24284. return convertFromHTML.apply(void 0, arguments);
  24285. };
  24286. exports["default"] = _default;
  24287. });
  24288. styleInject_es.unwrapExports(convertFromHTML_1);
  24289. var lib = styleInject_es.createCommonjsModule(function (module, exports) {
  24290. Object.defineProperty(exports, "__esModule", {
  24291. value: true
  24292. });
  24293. Object.defineProperty(exports, "convertToHTML", {
  24294. enumerable: true,
  24295. get: function get() {
  24296. return _convertToHTML["default"];
  24297. }
  24298. });
  24299. Object.defineProperty(exports, "convertFromHTML", {
  24300. enumerable: true,
  24301. get: function get() {
  24302. return _convertFromHTML["default"];
  24303. }
  24304. });
  24305. Object.defineProperty(exports, "parseHTML", {
  24306. enumerable: true,
  24307. get: function get() {
  24308. return _parseHTML["default"];
  24309. }
  24310. });
  24311. var _convertToHTML = interopRequireDefault(convertToHTML_1);
  24312. var _convertFromHTML = interopRequireDefault(convertFromHTML_1);
  24313. var _parseHTML = interopRequireDefault(parseHTML_1);
  24314. });
  24315. styleInject_es.unwrapExports(lib);
  24316. var configs = styleInject_es.createCommonjsModule(function (module, exports) {
  24317. Object.defineProperty(exports, "__esModule", {
  24318. value: true
  24319. });
  24320. exports.getFromHTMLConfig = exports.getToHTMLConfig = exports.blocks = exports.getHexColor = exports.defaultFontFamilies = exports.namedColors = undefined;
  24321. 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; };
  24322. var _react2 = _interopRequireDefault(React__default);
  24323. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  24324. 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; }
  24325. var namedColors = exports.namedColors = {
  24326. "aliceblue": "#f0f8ff",
  24327. "antiquewhite": "#faebd7",
  24328. "aqua": "#00ffff",
  24329. "aquamarine": "#7fffd4",
  24330. "azure": "#f0ffff",
  24331. "beige": "#f5f5dc",
  24332. "bisque": "#ffe4c4",
  24333. "black": "#000000",
  24334. "blanchedalmond": "#ffebcd",
  24335. "blue": "#0000ff",
  24336. "blueviolet": "#8a2be2",
  24337. "brown": "#a52a2a",
  24338. "burlywood": "#deb887",
  24339. "cadetblue": "#5f9ea0",
  24340. "chartreuse": "#7fff00",
  24341. "chocolate": "#d2691e",
  24342. "coral": "#ff7f50",
  24343. "cornflowerblue": "#6495ed",
  24344. "cornsilk": "#fff8dc",
  24345. "crimson": "#dc143c",
  24346. "cyan": "#00ffff",
  24347. "darkblue": "#00008b",
  24348. "darkcyan": "#008b8b",
  24349. "darkgoldenrod": "#b8860b",
  24350. "darkgray": "#a9a9a9",
  24351. "darkgreen": "#006400",
  24352. "darkkhaki": "#bdb76b",
  24353. "darkmagenta": "#8b008b",
  24354. "darkolivegreen": "#556b2f",
  24355. "darkorange": "#ff8c00",
  24356. "darkorchid": "#9932cc",
  24357. "darkred": "#8b0000",
  24358. "darksalmon": "#e9967a",
  24359. "darkseagreen": "#8fbc8f",
  24360. "darkslateblue": "#483d8b",
  24361. "darkslategray": "#2f4f4f",
  24362. "darkturquoise": "#00ced1",
  24363. "darkviolet": "#9400d3",
  24364. "deeppink": "#ff1493",
  24365. "deepskyblue": "#00bfff",
  24366. "dimgray": "#696969",
  24367. "dodgerblue": "#1e90ff",
  24368. "firebrick": "#b22222",
  24369. "floralwhite": "#fffaf0",
  24370. "forestgreen": "#228b22",
  24371. "fuchsia": "#ff00ff",
  24372. "gainsboro": "#dcdcdc",
  24373. "ghostwhite": "#f8f8ff",
  24374. "gold": "#ffd700",
  24375. "goldenrod": "#daa520",
  24376. "gray": "#808080",
  24377. "green": "#008000",
  24378. "greenyellow": "#adff2f",
  24379. "honeydew": "#f0fff0",
  24380. "hotpink": "#ff69b4",
  24381. "indianred ": "#cd5c5c",
  24382. "indigo": "#4b0082",
  24383. "ivory": "#fffff0",
  24384. "khaki": "#f0e68c",
  24385. "lavender": "#e6e6fa",
  24386. "lavenderblush": "#fff0f5",
  24387. "lawngreen": "#7cfc00",
  24388. "lemonchiffon": "#fffacd",
  24389. "lightblue": "#add8e6",
  24390. "lightcoral": "#f08080",
  24391. "lightcyan": "#e0ffff",
  24392. "lightgoldenrodyellow": "#fafad2",
  24393. "lightgrey": "#d3d3d3",
  24394. "lightgreen": "#90ee90",
  24395. "lightpink": "#ffb6c1",
  24396. "lightsalmon": "#ffa07a",
  24397. "lightseagreen": "#20b2aa",
  24398. "lightskyblue": "#87cefa",
  24399. "lightslategray": "#778899",
  24400. "lightsteelblue": "#b0c4de",
  24401. "lightyellow": "#ffffe0",
  24402. "lime": "#00ff00",
  24403. "limegreen": "#32cd32",
  24404. "linen": "#faf0e6",
  24405. "magenta": "#ff00ff",
  24406. "maroon": "#800000",
  24407. "mediumaquamarine": "#66cdaa",
  24408. "mediumblue": "#0000cd",
  24409. "mediumorchid": "#ba55d3",
  24410. "mediumpurple": "#9370d8",
  24411. "mediumseagreen": "#3cb371",
  24412. "mediumslateblue": "#7b68ee",
  24413. "mediumspringgreen": "#00fa9a",
  24414. "mediumturquoise": "#48d1cc",
  24415. "mediumvioletred": "#c71585",
  24416. "midnightblue": "#191970",
  24417. "mintcream": "#f5fffa",
  24418. "mistyrose": "#ffe4e1",
  24419. "moccasin": "#ffe4b5",
  24420. "navajowhite": "#ffdead",
  24421. "navy": "#000080",
  24422. "oldlace": "#fdf5e6",
  24423. "olive": "#808000",
  24424. "olivedrab": "#6b8e23",
  24425. "orange": "#ffa500",
  24426. "orangered": "#ff4500",
  24427. "orchid": "#da70d6",
  24428. "palegoldenrod": "#eee8aa",
  24429. "palegreen": "#98fb98",
  24430. "paleturquoise": "#afeeee",
  24431. "palevioletred": "#d87093",
  24432. "papayawhip": "#ffefd5",
  24433. "peachpuff": "#ffdab9",
  24434. "peru": "#cd853f",
  24435. "pink": "#ffc0cb",
  24436. "plum": "#dda0dd",
  24437. "powderblue": "#b0e0e6",
  24438. "purple": "#800080",
  24439. "rebeccapurple": "#663399",
  24440. "red": "#ff0000",
  24441. "rosybrown": "#bc8f8f",
  24442. "royalblue": "#4169e1",
  24443. "saddlebrown": "#8b4513",
  24444. "salmon": "#fa8072",
  24445. "sandybrown": "#f4a460",
  24446. "seagreen": "#2e8b57",
  24447. "seashell": "#fff5ee",
  24448. "sienna": "#a0522d",
  24449. "silver": "#c0c0c0",
  24450. "skyblue": "#87ceeb",
  24451. "slateblue": "#6a5acd",
  24452. "slategray": "#708090",
  24453. "snow": "#fffafa",
  24454. "springgreen": "#00ff7f",
  24455. "steelblue": "#4682b4",
  24456. "tan": "#d2b48c",
  24457. "teal": "#008080",
  24458. "thistle": "#d8bfd8",
  24459. "tomato": "#ff6347",
  24460. "turquoise": "#40e0d0",
  24461. "violet": "#ee82ee",
  24462. "wheat": "#f5deb3",
  24463. "white": "#ffffff",
  24464. "whitesmoke": "#f5f5f5",
  24465. "yellow": "#ffff00",
  24466. "yellowgreen": "#9acd32"
  24467. };
  24468. var getStyleValue = function getStyleValue(style) {
  24469. return style.split('-')[1];
  24470. };
  24471. var defaultUnitExportFn = function defaultUnitExportFn(unit) {
  24472. return unit + 'px';
  24473. };
  24474. var defaultUnitImportFn = function defaultUnitImportFn(unit) {
  24475. return unit.replace('px', '');
  24476. };
  24477. var ignoredNodeAttributes = ['style'];
  24478. var ignoredEntityNodeAttributes = ['style', 'href', 'target', 'alt', 'title', 'id', 'controls', 'autoplay', 'loop', 'poster'];
  24479. var spreadNodeAttributes = function spreadNodeAttributes(attributesObject) {
  24480. return Object.keys(attributesObject).reduce(function (attributeString, attributeName) {
  24481. return attributeString + " " + attributeName + "=\"" + attributesObject[attributeName] + "\"";
  24482. }, '').replace(/^\s$/, '');
  24483. };
  24484. var defaultFontFamilies = exports.defaultFontFamilies = [{
  24485. name: 'Araial',
  24486. family: 'Arial, Helvetica, sans-serif'
  24487. }, {
  24488. name: 'Georgia',
  24489. family: 'Georgia, serif'
  24490. }, {
  24491. name: 'Impact',
  24492. family: 'Impact, serif'
  24493. }, {
  24494. name: 'Monospace',
  24495. family: '"Courier New", Courier, monospace'
  24496. }, {
  24497. name: 'Tahoma',
  24498. family: "tahoma, arial, 'Hiragino Sans GB', 宋体, sans-serif"
  24499. }];
  24500. var getHexColor = exports.getHexColor = function getHexColor(color) {
  24501. color = color.replace('color:', '').replace(';', '').replace(' ', '');
  24502. if (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(color)) {
  24503. return color;
  24504. } else if (namedColors[color]) {
  24505. return namedColors[color];
  24506. } else if (color.indexOf('rgb') === 0) {
  24507. var rgbArray = color.split(',');
  24508. var convertedColor = rgbArray.length < 3 ? null : '#' + [rgbArray[0], rgbArray[1], rgbArray[2]].map(function (x) {
  24509. var hex = parseInt(x.replace(/\D/g, ''), 10).toString(16);
  24510. return hex.length === 1 ? '0' + hex : hex;
  24511. }).join('');
  24512. return (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(convertedColor) ? convertedColor : null
  24513. );
  24514. } else {
  24515. return null;
  24516. }
  24517. };
  24518. var blocks = exports.blocks = {
  24519. 'header-one': 'h1',
  24520. 'header-two': 'h2',
  24521. 'header-three': 'h3',
  24522. 'header-four': 'h4',
  24523. 'header-five': 'h5',
  24524. 'header-six': 'h6',
  24525. 'unstyled': 'p',
  24526. 'blockquote': 'blockquote'
  24527. };
  24528. var blockTypes = Object.keys(blocks);
  24529. var blockNames = blockTypes.map(function (key) {
  24530. return blocks[key];
  24531. });
  24532. var convertAtomicBlock = function convertAtomicBlock(block, contentState, blockNodeAttributes) {
  24533. if (!block || !block.key) {
  24534. return _react2.default.createElement("p", null);
  24535. }
  24536. var contentBlock = contentState.getBlockForKey(block.key);
  24537. var className = blockNodeAttributes.class,
  24538. nodeAttrAsProps = _objectWithoutProperties(blockNodeAttributes, ["class"]);
  24539. nodeAttrAsProps.className = className;
  24540. if (!contentBlock) {
  24541. return _react2.default.createElement("p", null);
  24542. }
  24543. var entityKey = contentBlock.getEntityAt(0);
  24544. if (!entityKey) {
  24545. return _react2.default.createElement("p", null);
  24546. }
  24547. var entity = contentState.getEntity(entityKey);
  24548. var mediaType = entity.getType().toLowerCase();
  24549. var _block$data = block.data,
  24550. float = _block$data.float,
  24551. alignment = _block$data.alignment;
  24552. var _entity$getData = entity.getData(),
  24553. url = _entity$getData.url,
  24554. link = _entity$getData.link,
  24555. link_target = _entity$getData.link_target,
  24556. width = _entity$getData.width,
  24557. height = _entity$getData.height,
  24558. meta = _entity$getData.meta;
  24559. if (mediaType === 'image') {
  24560. var imageWrapStyle = {};
  24561. var styledClassName = '';
  24562. if (float) {
  24563. imageWrapStyle.float = float;
  24564. styledClassName += ' float-' + float;
  24565. } else if (alignment) {
  24566. imageWrapStyle.textAlign = alignment;
  24567. styledClassName += ' align-' + alignment;
  24568. }
  24569. if (link) {
  24570. return _react2.default.createElement(
  24571. "div",
  24572. { className: "media-wrap image-wrap" + styledClassName, style: imageWrapStyle },
  24573. _react2.default.createElement(
  24574. "a",
  24575. { style: { display: 'inline-block' }, href: link, target: link_target },
  24576. _react2.default.createElement("img", _extends({}, nodeAttrAsProps, meta, { src: url, width: width, height: height, style: { width: width, height: height } }))
  24577. )
  24578. );
  24579. } else {
  24580. return _react2.default.createElement(
  24581. "div",
  24582. { className: "media-wrap image-wrap" + styledClassName, style: imageWrapStyle },
  24583. _react2.default.createElement("img", _extends({}, nodeAttrAsProps, meta, { src: url, width: width, height: height, style: { width: width, height: height } }))
  24584. );
  24585. }
  24586. } else if (mediaType === 'audio') {
  24587. return _react2.default.createElement(
  24588. "div",
  24589. { className: "media-wrap audio-wrap" },
  24590. _react2.default.createElement("audio", _extends({ controls: true }, nodeAttrAsProps, meta, { src: url }))
  24591. );
  24592. } else if (mediaType === 'video') {
  24593. return _react2.default.createElement(
  24594. "div",
  24595. { className: "media-wrap video-wrap" },
  24596. _react2.default.createElement("video", _extends({ controls: true }, nodeAttrAsProps, meta, { src: url, width: width, height: height }))
  24597. );
  24598. } else if (mediaType === 'embed') {
  24599. return _react2.default.createElement(
  24600. "div",
  24601. { className: "media-wrap embed-wrap" },
  24602. _react2.default.createElement("div", { dangerouslySetInnerHTML: { __html: url } })
  24603. );
  24604. } else if (mediaType === 'hr') {
  24605. return _react2.default.createElement("hr", null);
  24606. } else {
  24607. return _react2.default.createElement("p", null);
  24608. }
  24609. };
  24610. var entityToHTML = function entityToHTML(options) {
  24611. return function (entity, originalText) {
  24612. var entityExportFn = options.entityExportFn;
  24613. var entityType = entity.type.toLowerCase();
  24614. if (entityExportFn) {
  24615. var customOutput = entityExportFn(entity, originalText);
  24616. if (customOutput) {
  24617. return customOutput;
  24618. }
  24619. }
  24620. if (entityType === 'link') {
  24621. var _ref = entity.data.nodeAttributes || {},
  24622. className = _ref.class,
  24623. nodeAttrAsProps = _objectWithoutProperties(_ref, ["class"]);
  24624. nodeAttrAsProps.className = className;
  24625. return _react2.default.createElement("a", _extends({ href: entity.data.href, target: entity.data.target }, nodeAttrAsProps));
  24626. }
  24627. };
  24628. };
  24629. var styleToHTML = function styleToHTML(options) {
  24630. return function (style) {
  24631. var unitExportFn = options.unitExportFn || defaultUnitExportFn;
  24632. if (options.styleExportFn) {
  24633. var customOutput = options.styleExportFn(style, options);
  24634. if (customOutput) {
  24635. return customOutput;
  24636. }
  24637. }
  24638. style = style.toLowerCase();
  24639. if (style === 'strikethrough') {
  24640. return _react2.default.createElement("span", { style: { textDecoration: 'line-through' } });
  24641. } else if (style === 'superscript') {
  24642. return _react2.default.createElement("sup", null);
  24643. } else if (style === 'subscript') {
  24644. return _react2.default.createElement("sub", null);
  24645. } else if (style.indexOf('color-') === 0) {
  24646. return _react2.default.createElement("span", { style: { color: '#' + getStyleValue(style) } });
  24647. } else if (style.indexOf('bgcolor-') === 0) {
  24648. return _react2.default.createElement("span", { style: { backgroundColor: '#' + getStyleValue(style) } });
  24649. } else if (style.indexOf('fontsize-') === 0) {
  24650. return _react2.default.createElement("span", { style: { fontSize: unitExportFn(getStyleValue(style), 'font-size', 'html') } });
  24651. } else if (style.indexOf('lineheight-') === 0) {
  24652. return _react2.default.createElement("span", { style: { lineHeight: unitExportFn(getStyleValue(style), 'line-height', 'html') } });
  24653. } else if (style.indexOf('letterspacing-') === 0) {
  24654. return _react2.default.createElement("span", { style: { letterSpacing: unitExportFn(getStyleValue(style), 'letter-spacing', 'html') } });
  24655. } else if (style.indexOf('fontfamily-') === 0) {
  24656. var fontFamily = options.fontFamilies.find(function (item) {
  24657. return item.name.toLowerCase() === getStyleValue(style);
  24658. });
  24659. if (!fontFamily) return;
  24660. return _react2.default.createElement("span", { style: { fontFamily: fontFamily.family } });
  24661. }
  24662. };
  24663. };
  24664. var blockToHTML = function blockToHTML(options) {
  24665. return function (block) {
  24666. var blockExportFn = options.blockExportFn,
  24667. contentState = options.contentState;
  24668. if (blockExportFn) {
  24669. var customOutput = blockExportFn(contentState, block);
  24670. if (customOutput) {
  24671. return customOutput;
  24672. }
  24673. }
  24674. var blockStyle = '';
  24675. var blockType = block.type.toLowerCase();
  24676. var _block$data2 = block.data,
  24677. textAlign = _block$data2.textAlign,
  24678. textIndent = _block$data2.textIndent,
  24679. _block$data2$nodeAttr = _block$data2.nodeAttributes,
  24680. nodeAttributes = _block$data2$nodeAttr === undefined ? {} : _block$data2$nodeAttr;
  24681. var attributeString = spreadNodeAttributes(nodeAttributes);
  24682. if (textAlign || textIndent) {
  24683. blockStyle = ' style="';
  24684. if (textAlign) {
  24685. blockStyle += "text-align:" + textAlign + ";";
  24686. }
  24687. if (textIndent && !isNaN(textIndent) && textIndent > 0) {
  24688. blockStyle += "text-indent:" + textIndent * 2 + "em;";
  24689. }
  24690. blockStyle += '"';
  24691. }
  24692. if (blockType === 'atomic') {
  24693. return convertAtomicBlock(block, contentState, nodeAttributes);
  24694. } else if (blockType === 'code-block') {
  24695. var previousBlock = contentState.getBlockBefore(block.key);
  24696. var nextBlock = contentState.getBlockAfter(block.key);
  24697. var previousBlockType = previousBlock && previousBlock.getType();
  24698. var nextBlockType = nextBlock && nextBlock.getType();
  24699. var start = '';
  24700. var end = '';
  24701. if (previousBlockType !== 'code-block') {
  24702. start = "<pre" + attributeString + "><code>";
  24703. } else {
  24704. start = '';
  24705. }
  24706. if (nextBlockType !== 'code-block') {
  24707. end = '</code></pre>';
  24708. } else {
  24709. end = '<br/>';
  24710. }
  24711. return { start: start, end: end };
  24712. } else if (blocks[blockType]) {
  24713. return {
  24714. start: "<" + blocks[blockType] + blockStyle + attributeString + ">",
  24715. end: "</" + blocks[blockType] + ">"
  24716. };
  24717. } else if (blockType === 'unordered-list-item') {
  24718. return {
  24719. start: "<li" + blockStyle + attributeString + ">",
  24720. end: '</li>',
  24721. nest: _react2.default.createElement("ul", null)
  24722. };
  24723. } else if (blockType === 'ordered-list-item') {
  24724. return {
  24725. start: "<li" + blockStyle + attributeString + ">",
  24726. end: '</li>',
  24727. nest: _react2.default.createElement("ol", null)
  24728. };
  24729. }
  24730. };
  24731. };
  24732. var htmlToStyle = function htmlToStyle(options, source) {
  24733. return function (nodeName, node, currentStyle) {
  24734. if (!node || !node.style) {
  24735. return currentStyle;
  24736. }
  24737. var unitImportFn = options.unitImportFn || defaultUnitImportFn;
  24738. var newStyle = currentStyle;
  24739. [].forEach.call(node.style, function (style) {
  24740. if (nodeName === 'span' && style === 'color') {
  24741. var color = getHexColor(node.style.color);
  24742. newStyle = color ? newStyle.add('COLOR-' + color.replace('#', '').toUpperCase()) : newStyle;
  24743. } else if (nodeName === 'span' && style === 'background-color') {
  24744. var _color = getHexColor(node.style.backgroundColor);
  24745. newStyle = _color ? newStyle.add('BGCOLOR-' + _color.replace('#', '').toUpperCase()) : newStyle;
  24746. } else if (nodeName === 'span' && style === 'font-size') {
  24747. newStyle = newStyle.add('FONTSIZE-' + unitImportFn(node.style.fontSize, 'font-size', source));
  24748. } else if (nodeName === 'span' && style === 'line-height' && !isNaN(parseFloat(node.style.lineHeight, 10))) {
  24749. newStyle = newStyle.add('LINEHEIGHT-' + unitImportFn(node.style.lineHeight, 'line-height', source));
  24750. } else if (nodeName === 'span' && style === 'letter-spacing' && !isNaN(parseFloat(node.style.letterSpacing, 10))) {
  24751. newStyle = newStyle.add('LETTERSPACING-' + unitImportFn(node.style.letterSpacing, 'letter-spacing', source));
  24752. } else if (nodeName === 'span' && style === 'text-decoration') {
  24753. if (node.style.textDecoration === 'line-through') {
  24754. newStyle = newStyle.add('STRIKETHROUGH');
  24755. } else if (node.style.textDecoration === 'underline') {
  24756. newStyle = newStyle.add('UNDERLINE');
  24757. }
  24758. } else if (nodeName === 'span' && style === 'font-family') {
  24759. var fontFamily = options.fontFamilies.find(function (item) {
  24760. return item.family.toLowerCase() === node.style.fontFamily.toLowerCase();
  24761. });
  24762. if (!fontFamily) return;
  24763. newStyle = newStyle.add('FONTFAMILY-' + fontFamily.name.toUpperCase());
  24764. }
  24765. });
  24766. if (nodeName === 'sup') {
  24767. newStyle = newStyle.add('SUPERSCRIPT');
  24768. } else if (nodeName === 'sub') {
  24769. newStyle = newStyle.add('SUBSCRIPT');
  24770. }
  24771. options.styleImportFn && (newStyle = options.styleImportFn(nodeName, node, newStyle, source) || newStyle);
  24772. return newStyle;
  24773. };
  24774. };
  24775. var htmlToEntity = function htmlToEntity(options, source) {
  24776. return function (nodeName, node, createEntity) {
  24777. if (options && options.entityImportFn) {
  24778. var customInput = options.entityImportFn(nodeName, node, createEntity, source);
  24779. if (customInput) {
  24780. return customInput;
  24781. }
  24782. }
  24783. nodeName = nodeName.toLowerCase();
  24784. var alt = node.alt,
  24785. title = node.title,
  24786. id = node.id,
  24787. controls = node.controls,
  24788. autoplay = node.autoplay,
  24789. loop = node.loop,
  24790. poster = node.poster;
  24791. var meta = {};
  24792. var nodeAttributes = {};
  24793. id && (meta.id = id);
  24794. alt && (meta.alt = alt);
  24795. title && (meta.title = title);
  24796. controls && (meta.controls = controls);
  24797. autoplay && (meta.autoPlay = autoplay);
  24798. loop && (meta.loop = loop);
  24799. poster && (meta.poster = poster);
  24800. node.attributes && Object.keys(node.attributes).forEach(function (key) {
  24801. var attr = node.attributes[key];
  24802. ignoredEntityNodeAttributes.indexOf(attr.name) === -1 && (nodeAttributes[attr.name] = attr.value);
  24803. });
  24804. if (nodeName === 'a' && !node.querySelectorAll('img').length) {
  24805. var href = node.getAttribute('href');
  24806. var _target = node.getAttribute('target');
  24807. return createEntity('LINK', 'MUTABLE', { href: href, target: _target, nodeAttributes: nodeAttributes });
  24808. } else if (nodeName === 'audio') {
  24809. return createEntity('AUDIO', 'IMMUTABLE', { url: node.getAttribute('src'), meta: meta, nodeAttributes: nodeAttributes });
  24810. } else if (nodeName === 'video') {
  24811. return createEntity('VIDEO', 'IMMUTABLE', { url: node.getAttribute('src'), meta: meta, nodeAttributes: nodeAttributes });
  24812. } else if (nodeName === 'img') {
  24813. var parentNode = node.parentNode;
  24814. var entityData = { meta: meta };
  24815. var _node$style = node.style,
  24816. width = _node$style.width,
  24817. height = _node$style.height;
  24818. entityData.url = node.getAttribute('src');
  24819. width && (entityData.width = width);
  24820. height && (entityData.height = height);
  24821. if (parentNode.nodeName.toLowerCase() === 'a') {
  24822. entityData.link = parentNode.getAttribute('href');
  24823. entityData.link_target = parentNode.getAttribute('target');
  24824. }
  24825. return createEntity('IMAGE', 'IMMUTABLE', entityData);
  24826. } else if (nodeName === 'hr') {
  24827. return createEntity('HR', 'IMMUTABLE', {});
  24828. } else if (node.parentNode && node.parentNode.classList.contains('embed-wrap')) {
  24829. var embedContent = node.innerHTML || node.outerHTML;
  24830. if (embedContent) {
  24831. return createEntity('EMBED', 'IMMUTABLE', {
  24832. url: embedContent
  24833. });
  24834. }
  24835. }
  24836. };
  24837. };
  24838. var htmlToBlock = function htmlToBlock(options, source) {
  24839. return function (nodeName, node) {
  24840. if (options && options.blockImportFn) {
  24841. var customInput = options.blockImportFn(nodeName, node, source);
  24842. if (customInput) {
  24843. return customInput;
  24844. }
  24845. }
  24846. var nodeAttributes = {};
  24847. var nodeStyle = node.style || {};
  24848. node.attributes && Object.keys(node.attributes).forEach(function (key) {
  24849. var attr = node.attributes[key];
  24850. ignoredNodeAttributes.indexOf(attr.name) === -1 && (nodeAttributes[attr.name] = attr.value);
  24851. });
  24852. if (node.classList && node.classList.contains('media-wrap')) {
  24853. return {
  24854. type: 'atomic',
  24855. data: {
  24856. nodeAttributes: nodeAttributes,
  24857. float: nodeStyle.float,
  24858. alignment: nodeStyle.textAlign
  24859. }
  24860. };
  24861. } else if (nodeName === 'img') {
  24862. return {
  24863. type: 'atomic',
  24864. data: {
  24865. nodeAttributes: nodeAttributes,
  24866. float: nodeStyle.float,
  24867. alignment: nodeStyle.textAlign
  24868. }
  24869. };
  24870. } else if (nodeName === 'hr') {
  24871. return {
  24872. type: 'atomic',
  24873. data: { nodeAttributes: nodeAttributes }
  24874. };
  24875. } else if (nodeName === 'pre') {
  24876. node.innerHTML = node.innerHTML.replace(/<code(.*?)>/g, '').replace(/<\/code>/g, '');
  24877. return {
  24878. type: 'code-block',
  24879. data: { nodeAttributes: nodeAttributes }
  24880. };
  24881. } else if (blockNames.indexOf(nodeName) !== -1) {
  24882. var blockData = { nodeAttributes: nodeAttributes };
  24883. if (nodeStyle.textAlign) {
  24884. blockData.textAlign = nodeStyle.textAlign;
  24885. }
  24886. if (nodeStyle.textIndent) {
  24887. blockData.textIndent = /^\d+em$/.test(nodeStyle.textIndent) ? Math.ceil(parseInt(nodeStyle.textIndent, 10) / 2) : 1;
  24888. }
  24889. return {
  24890. type: blockTypes[blockNames.indexOf(nodeName)],
  24891. data: blockData
  24892. };
  24893. }
  24894. };
  24895. };
  24896. var getToHTMLConfig = exports.getToHTMLConfig = function getToHTMLConfig(options) {
  24897. return {
  24898. styleToHTML: styleToHTML(options),
  24899. entityToHTML: entityToHTML(options),
  24900. blockToHTML: blockToHTML(options)
  24901. };
  24902. };
  24903. var getFromHTMLConfig = exports.getFromHTMLConfig = function getFromHTMLConfig(options) {
  24904. var source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'unknow';
  24905. return {
  24906. htmlToStyle: htmlToStyle(options, source),
  24907. htmlToEntity: htmlToEntity(options, source),
  24908. htmlToBlock: htmlToBlock(options, source)
  24909. };
  24910. };
  24911. });
  24912. styleInject_es.unwrapExports(configs);
  24913. var configs_1 = configs.getFromHTMLConfig;
  24914. var configs_2 = configs.getToHTMLConfig;
  24915. var configs_3 = configs.blocks;
  24916. var configs_4 = configs.getHexColor;
  24917. var configs_5 = configs.defaultFontFamilies;
  24918. var configs_6 = configs.namedColors;
  24919. var dist = styleInject_es.createCommonjsModule(function (module, exports) {
  24920. Object.defineProperty(exports, "__esModule", {
  24921. value: true
  24922. });
  24923. exports.convertRawToEditorState = exports.convertEditorStateToRaw = exports.convertHTMLToEditorState = exports.convertEditorStateToHTML = exports.convertHTMLToRaw = exports.convertRawToHTML = undefined;
  24924. 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; };
  24925. var defaultConvertOptions = {
  24926. fontFamilies: configs.defaultFontFamilies
  24927. };
  24928. var convertRawToHTML = exports.convertRawToHTML = function convertRawToHTML(rawContent, options) {
  24929. options = _extends({}, defaultConvertOptions, options);
  24930. try {
  24931. var contentState = (0, Draft.convertFromRaw)(rawContent);
  24932. options.contentState = contentState;
  24933. return (0, lib.convertToHTML)((0, configs.getToHTMLConfig)(options))(contentState);
  24934. } catch (error) {
  24935. console.warn(error);
  24936. return '';
  24937. }
  24938. };
  24939. var convertHTMLToRaw = exports.convertHTMLToRaw = function convertHTMLToRaw(HTMLString, options, source) {
  24940. options = _extends({}, defaultConvertOptions, options);
  24941. try {
  24942. var contentState = (0, lib.convertFromHTML)((0, configs.getFromHTMLConfig)(options, source))(HTMLString);
  24943. return (0, Draft.convertToRaw)(contentState);
  24944. } catch (error) {
  24945. console.warn(error);
  24946. return {};
  24947. }
  24948. };
  24949. var convertEditorStateToHTML = exports.convertEditorStateToHTML = function convertEditorStateToHTML(editorState, options) {
  24950. options = _extends({}, defaultConvertOptions, options);
  24951. try {
  24952. var contentState = editorState.getCurrentContent();
  24953. options.contentState = contentState;
  24954. return (0, lib.convertToHTML)((0, configs.getToHTMLConfig)(options))(contentState);
  24955. } catch (error) {
  24956. console.warn(error);
  24957. return '';
  24958. }
  24959. };
  24960. var convertHTMLToEditorState = exports.convertHTMLToEditorState = function convertHTMLToEditorState(HTMLString, editorDecorators, options, source) {
  24961. options = _extends({}, defaultConvertOptions, options);
  24962. try {
  24963. return Draft.EditorState.createWithContent((0, lib.convertFromHTML)((0, configs.getFromHTMLConfig)(options, source))(HTMLString), editorDecorators);
  24964. } catch (error) {
  24965. console.warn(error);
  24966. return Draft.EditorState.createEmpty(editorDecorators);
  24967. }
  24968. };
  24969. var convertEditorStateToRaw = exports.convertEditorStateToRaw = function convertEditorStateToRaw(editorState) {
  24970. return (0, Draft.convertToRaw)(editorState.getCurrentContent());
  24971. };
  24972. var convertRawToEditorState = exports.convertRawToEditorState = function convertRawToEditorState(rawContent, editorDecorators) {
  24973. try {
  24974. return Draft.EditorState.createWithContent((0, Draft.convertFromRaw)(rawContent), editorDecorators);
  24975. } catch (error) {
  24976. console.warn(error);
  24977. return Draft.EditorState.createEmpty(editorDecorators);
  24978. }
  24979. };
  24980. });
  24981. styleInject_es.unwrapExports(dist);
  24982. var dist_1 = dist.convertRawToEditorState;
  24983. var dist_2 = dist.convertEditorStateToRaw;
  24984. var dist_3 = dist.convertHTMLToEditorState;
  24985. var dist_4 = dist.convertEditorStateToHTML;
  24986. var dist_5 = dist.convertHTMLToRaw;
  24987. var dist_6 = dist.convertRawToHTML;
  24988. var content = styleInject_es.createCommonjsModule(function (module, exports) {
  24989. Object.defineProperty(exports, "__esModule", {
  24990. value: true
  24991. });
  24992. 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;
  24993. var _immutable2 = _interopRequireDefault(immutable$1);
  24994. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  24995. var strictBlockTypes = ['atomic'];
  24996. var registerStrictBlockType = exports.registerStrictBlockType = function registerStrictBlockType(blockType) {
  24997. strictBlockTypes.indexOf(blockType) === -1 && strictBlockTypes.push(blockType);
  24998. };
  24999. var isEditorState = exports.isEditorState = function isEditorState(editorState) {
  25000. return editorState instanceof Draft.EditorState;
  25001. };
  25002. var createEmptyEditorState = exports.createEmptyEditorState = function createEmptyEditorState(editorDecorators) {
  25003. return Draft.EditorState.createEmpty(editorDecorators);
  25004. };
  25005. var createEditorState = exports.createEditorState = function createEditorState(contentState, editorDecorators) {
  25006. return Draft.EditorState.createWithContent(contentState, editorDecorators);
  25007. };
  25008. var isSelectionCollapsed = exports.isSelectionCollapsed = function isSelectionCollapsed(editorState) {
  25009. return editorState.getSelection().isCollapsed();
  25010. };
  25011. var selectionContainsBlockType = exports.selectionContainsBlockType = function selectionContainsBlockType(editorState, blockType) {
  25012. return getSelectedBlocks(editorState).find(function (block) {
  25013. return block.getType() === blockType;
  25014. });
  25015. };
  25016. var selectionContainsStrictBlock = exports.selectionContainsStrictBlock = function selectionContainsStrictBlock(editorState) {
  25017. return getSelectedBlocks(editorState).find(function (block) {
  25018. return ~strictBlockTypes.indexOf(block.getType());
  25019. });
  25020. };
  25021. var selectBlock = exports.selectBlock = function selectBlock(editorState, block) {
  25022. var blockKey = block.getKey();
  25023. return Draft.EditorState.forceSelection(editorState, new Draft.SelectionState({
  25024. anchorKey: blockKey,
  25025. anchorOffset: 0,
  25026. focusKey: blockKey,
  25027. focusOffset: block.getLength()
  25028. }));
  25029. };
  25030. var selectNextBlock = exports.selectNextBlock = function selectNextBlock(editorState, block) {
  25031. var nextBlock = editorState.getCurrentContent().getBlockAfter(block.getKey());
  25032. return nextBlock ? selectBlock(editorState, nextBlock) : editorState;
  25033. };
  25034. var removeBlock = exports.removeBlock = function removeBlock(editorState, block) {
  25035. var lastSelection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  25036. var nextContentState = void 0,
  25037. nextEditorState = void 0;
  25038. var blockKey = block.getKey();
  25039. nextContentState = Draft.Modifier.removeRange(editorState.getCurrentContent(), new Draft.SelectionState({
  25040. anchorKey: blockKey,
  25041. anchorOffset: 0,
  25042. focusKey: blockKey,
  25043. focusOffset: block.getLength()
  25044. }), 'backward');
  25045. nextContentState = Draft.Modifier.setBlockType(nextContentState, nextContentState.getSelectionAfter(), 'unstyled');
  25046. nextEditorState = Draft.EditorState.push(editorState, nextContentState, 'remove-range');
  25047. return Draft.EditorState.forceSelection(nextEditorState, lastSelection || nextContentState.getSelectionAfter());
  25048. };
  25049. var getSelectionBlock = exports.getSelectionBlock = function getSelectionBlock(editorState) {
  25050. return editorState.getCurrentContent().getBlockForKey(editorState.getSelection().getAnchorKey());
  25051. };
  25052. var updateEachCharacterOfSelection = exports.updateEachCharacterOfSelection = function updateEachCharacterOfSelection(editorState, callback) {
  25053. var selectionState = editorState.getSelection();
  25054. var contentState = editorState.getCurrentContent();
  25055. var contentBlocks = contentState.getBlockMap();
  25056. var selectedBlocks = getSelectedBlocks(editorState);
  25057. if (selectedBlocks.length === 0) {
  25058. return editorState;
  25059. }
  25060. var startKey = selectionState.getStartKey();
  25061. var startOffset = selectionState.getStartOffset();
  25062. var endKey = selectionState.getEndKey();
  25063. var endOffset = selectionState.getEndOffset();
  25064. var nextContentBlocks = contentBlocks.map(function (block) {
  25065. if (selectedBlocks.indexOf(block) === -1) {
  25066. return block;
  25067. }
  25068. var blockKey = block.getKey();
  25069. var charactersList = block.getCharacterList();
  25070. var nextCharactersList = null;
  25071. if (blockKey === startKey && blockKey === endKey) {
  25072. nextCharactersList = charactersList.map(function (character, index) {
  25073. if (index >= startOffset && index < endOffset) {
  25074. return callback(character);
  25075. }
  25076. return character;
  25077. });
  25078. } else if (blockKey === startKey) {
  25079. nextCharactersList = charactersList.map(function (character, index) {
  25080. if (index >= startOffset) {
  25081. return callback(character);
  25082. }
  25083. return character;
  25084. });
  25085. } else if (blockKey === endKey) {
  25086. nextCharactersList = charactersList.map(function (character, index) {
  25087. if (index < endOffset) {
  25088. return callback(character);
  25089. }
  25090. return character;
  25091. });
  25092. } else {
  25093. nextCharactersList = charactersList.map(function (character) {
  25094. return callback(character);
  25095. });
  25096. }
  25097. return block.merge({
  25098. 'characterList': nextCharactersList
  25099. });
  25100. });
  25101. return Draft.EditorState.push(editorState, contentState.merge({
  25102. blockMap: nextContentBlocks,
  25103. selectionBefore: selectionState,
  25104. selectionAfter: selectionState
  25105. }), 'update-selection-character-list');
  25106. };
  25107. var getSelectedBlocks = exports.getSelectedBlocks = function getSelectedBlocks(editorState) {
  25108. var selectionState = editorState.getSelection();
  25109. var contentState = editorState.getCurrentContent();
  25110. var startKey = selectionState.getStartKey();
  25111. var endKey = selectionState.getEndKey();
  25112. var isSameBlock = startKey === endKey;
  25113. var startingBlock = contentState.getBlockForKey(startKey);
  25114. var selectedBlocks = [startingBlock];
  25115. if (!isSameBlock) {
  25116. var blockKey = startKey;
  25117. while (blockKey !== endKey) {
  25118. var nextBlock = contentState.getBlockAfter(blockKey);
  25119. selectedBlocks.push(nextBlock);
  25120. blockKey = nextBlock.getKey();
  25121. }
  25122. }
  25123. return selectedBlocks;
  25124. };
  25125. var setSelectionBlockData = exports.setSelectionBlockData = function setSelectionBlockData(editorState, blockData, override) {
  25126. var newBlockData = override ? blockData : Object.assign({}, getSelectionBlockData(editorState).toJS(), blockData);
  25127. Object.keys(newBlockData).forEach(function (key) {
  25128. if (newBlockData.hasOwnProperty(key) && newBlockData[key] === undefined) {
  25129. delete newBlockData[key];
  25130. }
  25131. });
  25132. return (0, draftjsUtils.setBlockData)(editorState, newBlockData);
  25133. };
  25134. var getSelectionBlockData = exports.getSelectionBlockData = function getSelectionBlockData(editorState, name) {
  25135. var blockData = getSelectionBlock(editorState).getData();
  25136. return name ? blockData.get(name) : blockData;
  25137. };
  25138. var getSelectionBlockType = exports.getSelectionBlockType = function getSelectionBlockType(editorState) {
  25139. return getSelectionBlock(editorState).getType();
  25140. };
  25141. var getSelectionText = exports.getSelectionText = function getSelectionText(editorState) {
  25142. var selectionState = editorState.getSelection();
  25143. var contentState = editorState.getCurrentContent();
  25144. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  25145. return '';
  25146. }
  25147. var anchorKey = selectionState.getAnchorKey();
  25148. var currentContentBlock = contentState.getBlockForKey(anchorKey);
  25149. var start = selectionState.getStartOffset();
  25150. var end = selectionState.getEndOffset();
  25151. return currentContentBlock.getText().slice(start, end);
  25152. };
  25153. var toggleSelectionBlockType = exports.toggleSelectionBlockType = function toggleSelectionBlockType(editorState, blockType) {
  25154. if (selectionContainsStrictBlock(editorState)) {
  25155. return editorState;
  25156. }
  25157. return Draft.RichUtils.toggleBlockType(editorState, blockType);
  25158. };
  25159. var getSelectionEntityType = exports.getSelectionEntityType = function getSelectionEntityType(editorState) {
  25160. var entityKey = (0, draftjsUtils.getSelectionEntity)(editorState);
  25161. if (entityKey) {
  25162. var entity = editorState.getCurrentContent().getEntity(entityKey);
  25163. return entity ? entity.get('type') : null;
  25164. }
  25165. return null;
  25166. };
  25167. var getSelectionEntityData = exports.getSelectionEntityData = function getSelectionEntityData(editorState, type) {
  25168. var entityKey = (0, draftjsUtils.getSelectionEntity)(editorState);
  25169. if (entityKey) {
  25170. var entity = editorState.getCurrentContent().getEntity(entityKey);
  25171. if (entity && entity.get('type') === type) {
  25172. return entity.getData();
  25173. } else {
  25174. return {};
  25175. }
  25176. } else {
  25177. return {};
  25178. }
  25179. };
  25180. var toggleSelectionEntity = exports.toggleSelectionEntity = function toggleSelectionEntity(editorState, entity) {
  25181. var contentState = editorState.getCurrentContent();
  25182. var selectionState = editorState.getSelection();
  25183. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  25184. return editorState;
  25185. }
  25186. if (!entity || !entity.type || getSelectionEntityType(editorState) === entity.type) {
  25187. return Draft.EditorState.push(editorState, Draft.Modifier.applyEntity(contentState, selectionState, null), 'apply-entity');
  25188. }
  25189. try {
  25190. var nextContentState = contentState.createEntity(entity.type, entity.mutability, entity.data);
  25191. var entityKey = nextContentState.getLastCreatedEntityKey();
  25192. var nextEditorState = Draft.EditorState.set(editorState, {
  25193. currentContent: nextContentState
  25194. });
  25195. return Draft.EditorState.push(nextEditorState, Draft.Modifier.applyEntity(nextContentState, selectionState, entityKey), 'apply-entity');
  25196. } catch (error) {
  25197. console.warn(error);
  25198. return editorState;
  25199. }
  25200. };
  25201. var toggleSelectionLink = exports.toggleSelectionLink = function toggleSelectionLink(editorState, href, target) {
  25202. var contentState = editorState.getCurrentContent();
  25203. var selectionState = editorState.getSelection();
  25204. var entityData = { href: href, target: target };
  25205. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  25206. return editorState;
  25207. }
  25208. if (href === false) {
  25209. return Draft.RichUtils.toggleLink(editorState, selectionState, null);
  25210. }
  25211. if (href === null) {
  25212. delete entityData.href;
  25213. }
  25214. try {
  25215. var nextContentState = contentState.createEntity('LINK', 'MUTABLE', entityData);
  25216. var entityKey = nextContentState.getLastCreatedEntityKey();
  25217. var nextEditorState = Draft.EditorState.set(editorState, {
  25218. currentContent: nextContentState
  25219. });
  25220. nextEditorState = Draft.RichUtils.toggleLink(nextEditorState, selectionState, entityKey);
  25221. nextEditorState = Draft.EditorState.forceSelection(nextEditorState, selectionState.merge({
  25222. anchorOffset: selectionState.getEndOffset(),
  25223. focusOffset: selectionState.getEndOffset()
  25224. }));
  25225. nextEditorState = Draft.EditorState.push(nextEditorState, Draft.Modifier.insertText(nextEditorState.getCurrentContent(), nextEditorState.getSelection(), ''), 'insert-text');
  25226. return nextEditorState;
  25227. } catch (error) {
  25228. console.warn(error);
  25229. return editorState;
  25230. }
  25231. };
  25232. var getSelectionInlineStyle = exports.getSelectionInlineStyle = function getSelectionInlineStyle(editorState) {
  25233. return editorState.getCurrentInlineStyle();
  25234. };
  25235. var selectionHasInlineStyle = exports.selectionHasInlineStyle = function selectionHasInlineStyle(editorState, style) {
  25236. return getSelectionInlineStyle(editorState).has(style.toUpperCase());
  25237. };
  25238. var toggleSelectionInlineStyle = exports.toggleSelectionInlineStyle = function toggleSelectionInlineStyle(editorState, style) {
  25239. var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
  25240. var nextEditorState = editorState;
  25241. style = prefix + style.toUpperCase();
  25242. if (prefix) {
  25243. nextEditorState = updateEachCharacterOfSelection(nextEditorState, function (characterMetadata) {
  25244. return characterMetadata.toJS().style.reduce(function (characterMetadata, characterStyle) {
  25245. if (characterStyle.indexOf(prefix) === 0 && style !== characterStyle) {
  25246. return Draft.CharacterMetadata.removeStyle(characterMetadata, characterStyle);
  25247. } else {
  25248. return characterMetadata;
  25249. }
  25250. }, characterMetadata);
  25251. });
  25252. }
  25253. return Draft.RichUtils.toggleInlineStyle(nextEditorState, style);
  25254. };
  25255. var removeSelectionInlineStyles = exports.removeSelectionInlineStyles = function removeSelectionInlineStyles(editorState) {
  25256. return updateEachCharacterOfSelection(editorState, function (characterMetadata) {
  25257. return characterMetadata.merge({
  25258. style: _immutable2.default.OrderedSet([])
  25259. });
  25260. });
  25261. };
  25262. var toggleSelectionAlignment = exports.toggleSelectionAlignment = function toggleSelectionAlignment(editorState, alignment) {
  25263. return setSelectionBlockData(editorState, {
  25264. textAlign: getSelectionBlockData(editorState, 'textAlign') !== alignment ? alignment : undefined
  25265. });
  25266. };
  25267. var toggleSelectionIndent = exports.toggleSelectionIndent = function toggleSelectionIndent(editorState, textIndent) {
  25268. var maxIndent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 6;
  25269. return textIndent < 0 || textIndent > maxIndent || isNaN(textIndent) ? editorState : setSelectionBlockData(editorState, {
  25270. textIndent: textIndent || undefined
  25271. });
  25272. };
  25273. var increaseSelectionIndent = exports.increaseSelectionIndent = function increaseSelectionIndent(editorState) {
  25274. var maxIndent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 6;
  25275. var currentIndent = getSelectionBlockData(editorState, 'textIndent') || 0;
  25276. return toggleSelectionIndent(editorState, currentIndent + 1, maxIndent);
  25277. };
  25278. var decreaseSelectionIndent = exports.decreaseSelectionIndent = function decreaseSelectionIndent(editorState) {
  25279. var currentIndent = getSelectionBlockData(editorState, 'textIndent') || 0;
  25280. return toggleSelectionIndent(editorState, currentIndent - 1);
  25281. };
  25282. var toggleSelectionColor = exports.toggleSelectionColor = function toggleSelectionColor(editorState, color) {
  25283. return toggleSelectionInlineStyle(editorState, color.replace('#', ''), 'COLOR-');
  25284. };
  25285. var toggleSelectionBackgroundColor = exports.toggleSelectionBackgroundColor = function toggleSelectionBackgroundColor(editorState, color) {
  25286. return toggleSelectionInlineStyle(editorState, color.replace('#', ''), 'BGCOLOR-');
  25287. };
  25288. var toggleSelectionFontSize = exports.toggleSelectionFontSize = function toggleSelectionFontSize(editorState, fontSize) {
  25289. return toggleSelectionInlineStyle(editorState, fontSize, 'FONTSIZE-');
  25290. };
  25291. var toggleSelectionLineHeight = exports.toggleSelectionLineHeight = function toggleSelectionLineHeight(editorState, lineHeight) {
  25292. return toggleSelectionInlineStyle(editorState, lineHeight, 'LINEHEIGHT-');
  25293. };
  25294. var toggleSelectionFontFamily = exports.toggleSelectionFontFamily = function toggleSelectionFontFamily(editorState, fontFamily) {
  25295. return toggleSelectionInlineStyle(editorState, fontFamily, 'FONTFAMILY-');
  25296. };
  25297. var toggleSelectionLetterSpacing = exports.toggleSelectionLetterSpacing = function toggleSelectionLetterSpacing(editorState, letterSpacing) {
  25298. return toggleSelectionInlineStyle(editorState, letterSpacing, 'LETTERSPACING-');
  25299. };
  25300. var insertText = exports.insertText = function insertText(editorState, text, inlineStyle, entity) {
  25301. var selectionState = editorState.getSelection();
  25302. var currentSelectedBlockType = getSelectionBlockType(editorState);
  25303. if (currentSelectedBlockType === 'atomic') {
  25304. return editorState;
  25305. }
  25306. var entityKey = void 0;
  25307. var contentState = editorState.getCurrentContent();
  25308. if (entity && entity.type) {
  25309. contentState = contentState.createEntity(entity.type, entity.mutability || 'MUTABLE', entity.data || entityData);
  25310. entityKey = contentState.getLastCreatedEntityKey();
  25311. }
  25312. if (!selectionState.isCollapsed()) {
  25313. return Draft.EditorState.push(editorState, Draft.Modifier.replaceText(contentState, selectionState, text, inlineStyle, entityKey), 'replace-text');
  25314. } else {
  25315. return Draft.EditorState.push(editorState, Draft.Modifier.insertText(contentState, selectionState, text, inlineStyle, entityKey), 'insert-text');
  25316. }
  25317. };
  25318. var insertHTML = exports.insertHTML = function insertHTML(editorState, htmlString, source) {
  25319. if (!htmlString) {
  25320. return editorState;
  25321. }
  25322. var selectionState = editorState.getSelection();
  25323. var contentState = editorState.getCurrentContent();
  25324. var options = editorState.convertOptions || {};
  25325. try {
  25326. var _convertFromRaw = (0, Draft.convertFromRaw)((0, dist.convertHTMLToRaw)(htmlString, options, source)),
  25327. blockMap = _convertFromRaw.blockMap;
  25328. return Draft.EditorState.push(editorState, Draft.Modifier.replaceWithFragment(contentState, selectionState, blockMap), 'insert-fragment');
  25329. } catch (error) {
  25330. console.warn(error);
  25331. return editorState;
  25332. }
  25333. };
  25334. var insertAtomicBlock = exports.insertAtomicBlock = function insertAtomicBlock(editorState, type) {
  25335. var immutable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  25336. var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  25337. if (selectionContainsStrictBlock(editorState)) {
  25338. return insertAtomicBlock(selectNextBlock(editorState, getSelectionBlock(editorState)), type, immutable, data);
  25339. }
  25340. var selectionState = editorState.getSelection();
  25341. var contentState = editorState.getCurrentContent();
  25342. if (!selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  25343. return editorState;
  25344. }
  25345. var contentStateWithEntity = contentState.createEntity(type, immutable ? 'IMMUTABLE' : 'MUTABLE', data);
  25346. var entityKey = contentStateWithEntity.getLastCreatedEntityKey();
  25347. var newEditorState = Draft.AtomicBlockUtils.insertAtomicBlock(editorState, entityKey, ' ');
  25348. return newEditorState;
  25349. };
  25350. var insertHorizontalLine = exports.insertHorizontalLine = function insertHorizontalLine(editorState) {
  25351. return insertAtomicBlock(editorState, 'HR');
  25352. };
  25353. var insertMedias = exports.insertMedias = function insertMedias(editorState) {
  25354. var medias = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  25355. if (!medias.length) {
  25356. return editorState;
  25357. }
  25358. return medias.reduce(function (editorState, media) {
  25359. var url = media.url,
  25360. link = media.link,
  25361. link_target = media.link_target,
  25362. name = media.name,
  25363. type = media.type,
  25364. width = media.width,
  25365. height = media.height,
  25366. meta = media.meta;
  25367. return insertAtomicBlock(editorState, type, true, { url: url, link: link, link_target: link_target, name: name, type: type, width: width, height: height, meta: meta });
  25368. }, editorState);
  25369. };
  25370. var setMediaData = exports.setMediaData = function setMediaData(editorState, entityKey, data) {
  25371. return Draft.EditorState.push(editorState, editorState.getCurrentContent().mergeEntityData(entityKey, data), 'change-block-data');
  25372. };
  25373. var removeMedia = exports.removeMedia = function removeMedia(editorState, mediaBlock) {
  25374. return removeBlock(editorState, mediaBlock);
  25375. };
  25376. var setMediaPosition = exports.setMediaPosition = function setMediaPosition(editorState, mediaBlock, position) {
  25377. var newPosition = {};
  25378. var float = position.float,
  25379. alignment = position.alignment;
  25380. if (typeof float !== 'undefined') {
  25381. newPosition.float = mediaBlock.getData().get('float') === float ? null : float;
  25382. }
  25383. if (typeof alignment !== 'undefined') {
  25384. newPosition.alignment = mediaBlock.getData().get('alignment') === alignment ? null : alignment;
  25385. }
  25386. return setSelectionBlockData(selectBlock(editorState, mediaBlock), newPosition);
  25387. };
  25388. var clear = exports.clear = function clear(editorState) {
  25389. var contentState = editorState.getCurrentContent();
  25390. var firstBlock = contentState.getFirstBlock();
  25391. var lastBlock = contentState.getLastBlock();
  25392. var allSelected = new Draft.SelectionState({
  25393. anchorKey: firstBlock.getKey(),
  25394. anchorOffset: 0,
  25395. focusKey: lastBlock.getKey(),
  25396. focusOffset: lastBlock.getLength(),
  25397. hasFocus: true
  25398. });
  25399. return Draft.RichUtils.toggleBlockType(Draft.EditorState.push(editorState, Draft.Modifier.removeRange(contentState, allSelected, 'backward'), 'remove-range'), 'unstyled');
  25400. };
  25401. var handleKeyCommand = exports.handleKeyCommand = function handleKeyCommand(editorState, command) {
  25402. return Draft.RichUtils.handleKeyCommand(editorState, command);
  25403. };
  25404. var undo = exports.undo = function undo(editorState) {
  25405. return Draft.EditorState.undo(editorState);
  25406. };
  25407. var redo = exports.redo = function redo(editorState) {
  25408. return Draft.EditorState.redo(editorState);
  25409. };
  25410. });
  25411. styleInject_es.unwrapExports(content);
  25412. var content_1 = content.redo;
  25413. var content_2 = content.undo;
  25414. var content_3 = content.handleKeyCommand;
  25415. var content_4 = content.clear;
  25416. var content_5 = content.setMediaPosition;
  25417. var content_6 = content.removeMedia;
  25418. var content_7 = content.setMediaData;
  25419. var content_8 = content.insertMedias;
  25420. var content_9 = content.insertHorizontalLine;
  25421. var content_10 = content.insertAtomicBlock;
  25422. var content_11 = content.insertHTML;
  25423. var content_12 = content.insertText;
  25424. var content_13 = content.toggleSelectionLetterSpacing;
  25425. var content_14 = content.toggleSelectionFontFamily;
  25426. var content_15 = content.toggleSelectionLineHeight;
  25427. var content_16 = content.toggleSelectionFontSize;
  25428. var content_17 = content.toggleSelectionBackgroundColor;
  25429. var content_18 = content.toggleSelectionColor;
  25430. var content_19 = content.decreaseSelectionIndent;
  25431. var content_20 = content.increaseSelectionIndent;
  25432. var content_21 = content.toggleSelectionIndent;
  25433. var content_22 = content.toggleSelectionAlignment;
  25434. var content_23 = content.removeSelectionInlineStyles;
  25435. var content_24 = content.toggleSelectionInlineStyle;
  25436. var content_25 = content.selectionHasInlineStyle;
  25437. var content_26 = content.getSelectionInlineStyle;
  25438. var content_27 = content.toggleSelectionLink;
  25439. var content_28 = content.toggleSelectionEntity;
  25440. var content_29 = content.getSelectionEntityData;
  25441. var content_30 = content.getSelectionEntityType;
  25442. var content_31 = content.toggleSelectionBlockType;
  25443. var content_32 = content.getSelectionText;
  25444. var content_33 = content.getSelectionBlockType;
  25445. var content_34 = content.getSelectionBlockData;
  25446. var content_35 = content.setSelectionBlockData;
  25447. var content_36 = content.getSelectedBlocks;
  25448. var content_37 = content.updateEachCharacterOfSelection;
  25449. var content_38 = content.getSelectionBlock;
  25450. var content_39 = content.removeBlock;
  25451. var content_40 = content.selectNextBlock;
  25452. var content_41 = content.selectBlock;
  25453. var content_42 = content.selectionContainsStrictBlock;
  25454. var content_43 = content.selectionContainsBlockType;
  25455. var content_44 = content.isSelectionCollapsed;
  25456. var content_45 = content.createEditorState;
  25457. var content_46 = content.createEmptyEditorState;
  25458. var content_47 = content.isEditorState;
  25459. var content_48 = content.registerStrictBlockType;
  25460. var base = styleInject_es.createCommonjsModule(function (module, exports) {
  25461. Object.defineProperty(exports, "__esModule", {
  25462. value: true
  25463. });
  25464. var braftUniqueIndex = 0;
  25465. var UniqueIndex = exports.UniqueIndex = function UniqueIndex() {
  25466. return braftUniqueIndex += 1;
  25467. };
  25468. });
  25469. styleInject_es.unwrapExports(base);
  25470. var base_1 = base.UniqueIndex;
  25471. var color = styleInject_es.createCommonjsModule(function (module, exports) {
  25472. Object.defineProperty(exports, "__esModule", {
  25473. value: true
  25474. });
  25475. var _namedColors = {
  25476. "aliceblue": "#f0f8ff",
  25477. "antiquewhite": "#faebd7",
  25478. "aqua": "#00ffff",
  25479. "aquamarine": "#7fffd4",
  25480. "azure": "#f0ffff",
  25481. "beige": "#f5f5dc",
  25482. "bisque": "#ffe4c4",
  25483. "black": "#000000",
  25484. "blanchedalmond": "#ffebcd",
  25485. "blue": "#0000ff",
  25486. "blueviolet": "#8a2be2",
  25487. "brown": "#a52a2a",
  25488. "burlywood": "#deb887",
  25489. "cadetblue": "#5f9ea0",
  25490. "chartreuse": "#7fff00",
  25491. "chocolate": "#d2691e",
  25492. "coral": "#ff7f50",
  25493. "cornflowerblue": "#6495ed",
  25494. "cornsilk": "#fff8dc",
  25495. "crimson": "#dc143c",
  25496. "cyan": "#00ffff",
  25497. "darkblue": "#00008b",
  25498. "darkcyan": "#008b8b",
  25499. "darkgoldenrod": "#b8860b",
  25500. "darkgray": "#a9a9a9",
  25501. "darkgreen": "#006400",
  25502. "darkkhaki": "#bdb76b",
  25503. "darkmagenta": "#8b008b",
  25504. "darkolivegreen": "#556b2f",
  25505. "darkorange": "#ff8c00",
  25506. "darkorchid": "#9932cc",
  25507. "darkred": "#8b0000",
  25508. "darksalmon": "#e9967a",
  25509. "darkseagreen": "#8fbc8f",
  25510. "darkslateblue": "#483d8b",
  25511. "darkslategray": "#2f4f4f",
  25512. "darkturquoise": "#00ced1",
  25513. "darkviolet": "#9400d3",
  25514. "deeppink": "#ff1493",
  25515. "deepskyblue": "#00bfff",
  25516. "dimgray": "#696969",
  25517. "dodgerblue": "#1e90ff",
  25518. "firebrick": "#b22222",
  25519. "floralwhite": "#fffaf0",
  25520. "forestgreen": "#228b22",
  25521. "fuchsia": "#ff00ff",
  25522. "gainsboro": "#dcdcdc",
  25523. "ghostwhite": "#f8f8ff",
  25524. "gold": "#ffd700",
  25525. "goldenrod": "#daa520",
  25526. "gray": "#808080",
  25527. "green": "#008000",
  25528. "greenyellow": "#adff2f",
  25529. "honeydew": "#f0fff0",
  25530. "hotpink": "#ff69b4",
  25531. "indianred ": "#cd5c5c",
  25532. "indigo": "#4b0082",
  25533. "ivory": "#fffff0",
  25534. "khaki": "#f0e68c",
  25535. "lavender": "#e6e6fa",
  25536. "lavenderblush": "#fff0f5",
  25537. "lawngreen": "#7cfc00",
  25538. "lemonchiffon": "#fffacd",
  25539. "lightblue": "#add8e6",
  25540. "lightcoral": "#f08080",
  25541. "lightcyan": "#e0ffff",
  25542. "lightgoldenrodyellow": "#fafad2",
  25543. "lightgrey": "#d3d3d3",
  25544. "lightgreen": "#90ee90",
  25545. "lightpink": "#ffb6c1",
  25546. "lightsalmon": "#ffa07a",
  25547. "lightseagreen": "#20b2aa",
  25548. "lightskyblue": "#87cefa",
  25549. "lightslategray": "#778899",
  25550. "lightsteelblue": "#b0c4de",
  25551. "lightyellow": "#ffffe0",
  25552. "lime": "#00ff00",
  25553. "limegreen": "#32cd32",
  25554. "linen": "#faf0e6",
  25555. "magenta": "#ff00ff",
  25556. "maroon": "#800000",
  25557. "mediumaquamarine": "#66cdaa",
  25558. "mediumblue": "#0000cd",
  25559. "mediumorchid": "#ba55d3",
  25560. "mediumpurple": "#9370d8",
  25561. "mediumseagreen": "#3cb371",
  25562. "mediumslateblue": "#7b68ee",
  25563. "mediumspringgreen": "#00fa9a",
  25564. "mediumturquoise": "#48d1cc",
  25565. "mediumvioletred": "#c71585",
  25566. "midnightblue": "#191970",
  25567. "mintcream": "#f5fffa",
  25568. "mistyrose": "#ffe4e1",
  25569. "moccasin": "#ffe4b5",
  25570. "navajowhite": "#ffdead",
  25571. "navy": "#000080",
  25572. "oldlace": "#fdf5e6",
  25573. "olive": "#808000",
  25574. "olivedrab": "#6b8e23",
  25575. "orange": "#ffa500",
  25576. "orangered": "#ff4500",
  25577. "orchid": "#da70d6",
  25578. "palegoldenrod": "#eee8aa",
  25579. "palegreen": "#98fb98",
  25580. "paleturquoise": "#afeeee",
  25581. "palevioletred": "#d87093",
  25582. "papayawhip": "#ffefd5",
  25583. "peachpuff": "#ffdab9",
  25584. "peru": "#cd853f",
  25585. "pink": "#ffc0cb",
  25586. "plum": "#dda0dd",
  25587. "powderblue": "#b0e0e6",
  25588. "purple": "#800080",
  25589. "rebeccapurple": "#663399",
  25590. "red": "#ff0000",
  25591. "rosybrown": "#bc8f8f",
  25592. "royalblue": "#4169e1",
  25593. "saddlebrown": "#8b4513",
  25594. "salmon": "#fa8072",
  25595. "sandybrown": "#f4a460",
  25596. "seagreen": "#2e8b57",
  25597. "seashell": "#fff5ee",
  25598. "sienna": "#a0522d",
  25599. "silver": "#c0c0c0",
  25600. "skyblue": "#87ceeb",
  25601. "slateblue": "#6a5acd",
  25602. "slategray": "#708090",
  25603. "snow": "#fffafa",
  25604. "springgreen": "#00ff7f",
  25605. "steelblue": "#4682b4",
  25606. "tan": "#d2b48c",
  25607. "teal": "#008080",
  25608. "thistle": "#d8bfd8",
  25609. "tomato": "#ff6347",
  25610. "turquoise": "#40e0d0",
  25611. "violet": "#ee82ee",
  25612. "wheat": "#f5deb3",
  25613. "white": "#ffffff",
  25614. "whitesmoke": "#f5f5f5",
  25615. "yellow": "#ffff00",
  25616. "yellowgreen": "#9acd32"
  25617. };
  25618. var _getHexColor = function _getHexColor(color) {
  25619. color = color.replace('color:', '').replace(';', '').replace(' ', '');
  25620. if (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(color)) {
  25621. return color;
  25622. } else if (namedColors[color]) {
  25623. return namedColors[color];
  25624. } else if (color.indexOf('rgb') === 0) {
  25625. var rgbArray = color.split(',');
  25626. var convertedColor = rgbArray.length < 3 ? null : '#' + [rgbArray[0], rgbArray[1], rgbArray[2]].map(function (x) {
  25627. var hex = parseInt(x.replace(/\D/g, ''), 10).toString(16);
  25628. return hex.length === 1 ? '0' + hex : hex;
  25629. }).join('');
  25630. return (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(convertedColor) ? convertedColor : null
  25631. );
  25632. } else {
  25633. return null;
  25634. }
  25635. };
  25636. var namedColors = exports.namedColors = _namedColors;
  25637. var getHexColor = exports.getHexColor = _getHexColor;
  25638. var detectColorsFromHTMLString = exports.detectColorsFromHTMLString = function detectColorsFromHTMLString(html) {
  25639. return typeof html !== 'string' ? [] : (html.match(/color:[^;]{3,24};/g) || []).map(getHexColor).filter(function (color) {
  25640. return color;
  25641. });
  25642. };
  25643. var detectColorsFromDraftState = exports.detectColorsFromDraftState = function detectColorsFromDraftState(draftState) {
  25644. var result = [];
  25645. if (!draftState || !draftState.blocks || !draftState.blocks.length) {
  25646. return result;
  25647. }
  25648. draftState.blocks.forEach(function (block) {
  25649. if (block && block.inlineStyleRanges && block.inlineStyleRanges.length) {
  25650. block.inlineStyleRanges.forEach(function (inlineStyle) {
  25651. if (inlineStyle.style && inlineStyle.style.indexOf('COLOR-') >= 0) {
  25652. result.push('#' + inlineStyle.style.split('COLOR-')[1]);
  25653. }
  25654. });
  25655. }
  25656. });
  25657. return result.filter(function (color) {
  25658. return color;
  25659. });
  25660. };
  25661. });
  25662. styleInject_es.unwrapExports(color);
  25663. var color_1 = color.namedColors;
  25664. var color_2 = color.getHexColor;
  25665. var color_3 = color.detectColorsFromHTMLString;
  25666. var color_4 = color.detectColorsFromDraftState;
  25667. var dist$1 = styleInject_es.createCommonjsModule(function (module, exports) {
  25668. Object.defineProperty(exports, "__esModule", {
  25669. value: true
  25670. });
  25671. exports.ColorUtils = exports.BaseUtils = exports.ContentUtils = undefined;
  25672. var _ContentUtils = _interopRequireWildcard(content);
  25673. var _BaseUtils = _interopRequireWildcard(base);
  25674. var _ColorUtils = _interopRequireWildcard(color);
  25675. 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; } }
  25676. var ContentUtils = exports.ContentUtils = _ContentUtils;
  25677. var BaseUtils = exports.BaseUtils = _BaseUtils;
  25678. var ColorUtils = exports.ColorUtils = _ColorUtils;
  25679. });
  25680. styleInject_es.unwrapExports(dist$1);
  25681. var dist_1$1 = dist$1.ColorUtils;
  25682. var dist_2$1 = dist$1.BaseUtils;
  25683. var dist_3$1 = dist$1.ContentUtils;
  25684. var dist$2 = styleInject_es.createCommonjsModule(function (module, exports) {
  25685. (function webpackUniversalModuleDefinition(root, factory) {
  25686. module.exports = factory(React__default);
  25687. })(window, function(__WEBPACK_EXTERNAL_MODULE__2__) {
  25688. return /******/ (function(modules) { // webpackBootstrap
  25689. /******/ // The module cache
  25690. /******/ var installedModules = {};
  25691. /******/
  25692. /******/ // The require function
  25693. /******/ function __webpack_require__(moduleId) {
  25694. /******/
  25695. /******/ // Check if module is in cache
  25696. /******/ if(installedModules[moduleId]) {
  25697. /******/ return installedModules[moduleId].exports;
  25698. /******/ }
  25699. /******/ // Create a new module (and put it into the cache)
  25700. /******/ var module = installedModules[moduleId] = {
  25701. /******/ i: moduleId,
  25702. /******/ l: false,
  25703. /******/ exports: {}
  25704. /******/ };
  25705. /******/
  25706. /******/ // Execute the module function
  25707. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  25708. /******/
  25709. /******/ // Flag the module as loaded
  25710. /******/ module.l = true;
  25711. /******/
  25712. /******/ // Return the exports of the module
  25713. /******/ return module.exports;
  25714. /******/ }
  25715. /******/
  25716. /******/
  25717. /******/ // expose the modules object (__webpack_modules__)
  25718. /******/ __webpack_require__.m = modules;
  25719. /******/
  25720. /******/ // expose the module cache
  25721. /******/ __webpack_require__.c = installedModules;
  25722. /******/
  25723. /******/ // define getter function for harmony exports
  25724. /******/ __webpack_require__.d = function(exports, name, getter) {
  25725. /******/ if(!__webpack_require__.o(exports, name)) {
  25726. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  25727. /******/ }
  25728. /******/ };
  25729. /******/
  25730. /******/ // define __esModule on exports
  25731. /******/ __webpack_require__.r = function(exports) {
  25732. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  25733. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  25734. /******/ }
  25735. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  25736. /******/ };
  25737. /******/
  25738. /******/ // create a fake namespace object
  25739. /******/ // mode & 1: value is a module id, require it
  25740. /******/ // mode & 2: merge all properties of value into the ns
  25741. /******/ // mode & 4: return value when already ns object
  25742. /******/ // mode & 8|1: behave like require
  25743. /******/ __webpack_require__.t = function(value, mode) {
  25744. /******/ if(mode & 1) value = __webpack_require__(value);
  25745. /******/ if(mode & 8) return value;
  25746. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  25747. /******/ var ns = Object.create(null);
  25748. /******/ __webpack_require__.r(ns);
  25749. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  25750. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  25751. /******/ return ns;
  25752. /******/ };
  25753. /******/
  25754. /******/ // getDefaultExport function for compatibility with non-harmony modules
  25755. /******/ __webpack_require__.n = function(module) {
  25756. /******/ var getter = module && module.__esModule ?
  25757. /******/ function getDefault() { return module['default']; } :
  25758. /******/ function getModuleExports() { return module; };
  25759. /******/ __webpack_require__.d(getter, 'a', getter);
  25760. /******/ return getter;
  25761. /******/ };
  25762. /******/
  25763. /******/ // Object.prototype.hasOwnProperty.call
  25764. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  25765. /******/
  25766. /******/ // __webpack_public_path__
  25767. /******/ __webpack_require__.p = "/";
  25768. /******/
  25769. /******/
  25770. /******/ // Load entry module and return exports
  25771. /******/ return __webpack_require__(__webpack_require__.s = 20);
  25772. /******/ })
  25773. /************************************************************************/
  25774. /******/ ([
  25775. /* 0 */
  25776. /***/ (function(module, exports, __webpack_require__) {
  25777. Object.defineProperty(exports, "__esModule", {
  25778. value: true
  25779. });
  25780. var compressImage = exports.compressImage = function compressImage(url) {
  25781. var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1280;
  25782. var height = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 800;
  25783. return new Promise(function (resolve, reject) {
  25784. var image = new Image();
  25785. image.src = url;
  25786. image.onerror = function (error) {
  25787. reject(error);
  25788. };
  25789. image.onload = function () {
  25790. try {
  25791. var compressCanvas = document.createElement('canvas');
  25792. var scale = this.width > width || this.height > height ? this.width > this.height ? width / this.width : height / this.height : 1;
  25793. compressCanvas.width = this.width * scale;
  25794. compressCanvas.height = this.height * scale;
  25795. var canvasContext = compressCanvas.getContext('2d');
  25796. canvasContext.drawImage(this, 0, 0, compressCanvas.width, compressCanvas.height);
  25797. resolve({
  25798. url: compressCanvas.toDataURL('image/png', 1),
  25799. width: compressCanvas.width,
  25800. height: compressCanvas.height
  25801. });
  25802. } catch (error) {
  25803. reject(error);
  25804. }
  25805. };
  25806. });
  25807. };
  25808. /***/ }),
  25809. /* 1 */
  25810. /***/ (function(module, exports, __webpack_require__) {
  25811. Object.defineProperty(exports, "__esModule", {
  25812. value: true
  25813. });
  25814. var UniqueIndex = exports.UniqueIndex = function UniqueIndex() {
  25815. if (isNaN(window.__BRAFT_MM_UNIQUE_INDEX__)) {
  25816. window.__BRAFT_MM_UNIQUE_INDEX__ = 1;
  25817. } else {
  25818. window.__BRAFT_MM_UNIQUE_INDEX__ += 1;
  25819. }
  25820. return window.__BRAFT_MM_UNIQUE_INDEX__;
  25821. };
  25822. /***/ }),
  25823. /* 2 */
  25824. /***/ (function(module, exports) {
  25825. module.exports = __WEBPACK_EXTERNAL_MODULE__2__;
  25826. /***/ }),
  25827. /* 3 */
  25828. /***/ (function(module, exports, __webpack_require__) {
  25829. Object.defineProperty(exports, "__esModule", {
  25830. value: true
  25831. });
  25832. exports.default = {
  25833. remove: 'Kaldır',
  25834. cancel: 'İptal',
  25835. confirm: 'Onayla',
  25836. insert: 'Seçilenleri ekle',
  25837. width: 'Genişlik',
  25838. height: 'Yükseklik',
  25839. image: 'Resim',
  25840. video: 'Görüntü',
  25841. audio: 'Ses',
  25842. embed: 'Nesne göm',
  25843. caption: 'Kitaplık',
  25844. dragTip: 'Tıkla ya da dosya sürükle',
  25845. dropTip: 'Yüklemek için sürükleyin',
  25846. selectAll: 'Tümünü seç',
  25847. deselect: 'Seçimi kaldır',
  25848. removeSelected: 'Seçilenleri kaldır',
  25849. externalInputPlaceHolder: 'Kaynak adı|Kaynak bağlantısı',
  25850. externalInputTip: 'Kaynak asını ve bağlantısını "|" ile ayırın ve Enter\' a basın.',
  25851. addLocalFile: 'Yerel\' den ekle',
  25852. addExternalSource: 'Harici kaynaktan ekle',
  25853. unnamedItem: 'Adlandırılmamış giriş',
  25854. confirmInsert: 'Seçilenleri ekle'
  25855. };
  25856. /***/ }),
  25857. /* 4 */
  25858. /***/ (function(module, exports, __webpack_require__) {
  25859. Object.defineProperty(exports, "__esModule", {
  25860. value: true
  25861. });
  25862. exports.default = {
  25863. remove: '削除する',
  25864. cancel: 'キャンセル',
  25865. confirm: '確認する',
  25866. insert: '選択したアイテムを挿入',
  25867. width: '幅',
  25868. height: '身長',
  25869. image: '絵',
  25870. video: 'ビデオ',
  25871. audio: '音声',
  25872. embed: '埋め込みメディア',
  25873. caption: 'メディアライブラリー',
  25874. dragTip: 'ファイルをこの位置までクリックまたはドラッグします',
  25875. dropTip: 'アップロードするマウスを放します',
  25876. selectAll: 'すべて選択',
  25877. deselect: '選択を解除',
  25878. removeSelected: '選択したアイテムを削除',
  25879. externalInputPlaceHolder: 'リソース名|リソースアドレス',
  25880. externalInputTip: 'リソース名とリソースアドレスは "|"で区切ります。',
  25881. addLocalFile: 'ローカルリソースを追加する',
  25882. addExternalSource: 'ネットワークリソースを追加する',
  25883. unnamedItem: '名前のないアイテム',
  25884. confirmInsert: '選択したアイテムを挿入'
  25885. };
  25886. /***/ }),
  25887. /* 5 */
  25888. /***/ (function(module, exports, __webpack_require__) {
  25889. Object.defineProperty(exports, "__esModule", {
  25890. value: true
  25891. });
  25892. exports.default = {
  25893. remove: '삭제',
  25894. cancel: '취소',
  25895. confirm: '확인',
  25896. insert: '선택한항목삽입',
  25897. width: '너비',
  25898. height: '높이',
  25899. image: '그림',
  25900. video: '비디오',
  25901. audio: '오디오',
  25902. embed: '임베디드미디어',
  25903. caption: '미디어라이브러리',
  25904. dragTip: '파일을 클릭하거나이 지점으로 드래그하십시오.',
  25905. dropTip: '업로드하려면마우스를놓으십시오.',
  25906. selectAll: '모두 선택',
  25907. deselect: '선택 취소',
  25908. removeSelected: '선택한 항목 삭제',
  25909. externalInputPlaceHolder: '리소스 이름 | 리소스 주소',
  25910. externalInputTip: '자원 이름과 자원 주소를 "|"',
  25911. addLocalFile: '로컬 리소스 추가',
  25912. addExternalSource: '네트워크 리소스 추가',
  25913. unnamedItem: '이름없는 항목',
  25914. confirmInsert: '선택한 항목 삽입'
  25915. };
  25916. /***/ }),
  25917. /* 6 */
  25918. /***/ (function(module, exports, __webpack_require__) {
  25919. Object.defineProperty(exports, "__esModule", {
  25920. value: true
  25921. });
  25922. exports.default = {
  25923. remove: 'Usuń',
  25924. cancel: 'Anuluj',
  25925. confirm: 'Potwierdź',
  25926. insert: 'Wstaw wybrane elementy',
  25927. width: 'Szerokość',
  25928. height: 'Wysokość',
  25929. image: 'Obraz',
  25930. video: 'Wideo',
  25931. audio: 'Dźwięk',
  25932. embed: 'Obiekt',
  25933. caption: 'Biblioteka mediów',
  25934. dragTip: 'Kliknij lub przenieś tu pliki',
  25935. dropTip: 'Upuść aby dodać plik',
  25936. selectAll: 'Zaznacz wszystko',
  25937. deselect: 'Odznacz',
  25938. removeSelected: 'Usuń wybrane',
  25939. externalInputPlaceHolder: 'Nazwa źródła|Adres URL',
  25940. externalInputTip: 'Oddziel nazwę i adres URL źródła z pomocą "|", Potwierdź Enter-em',
  25941. addLocalFile: 'Dodaj z komputera',
  25942. addExternalSource: 'Dodaj z Internetu',
  25943. unnamedItem: 'Bez nazwy',
  25944. confirmInsert: 'Dodaj wybrane elementy'
  25945. };
  25946. /***/ }),
  25947. /* 7 */
  25948. /***/ (function(module, exports, __webpack_require__) {
  25949. Object.defineProperty(exports, "__esModule", {
  25950. value: true
  25951. });
  25952. exports.default = {
  25953. remove: '删除',
  25954. cancel: '取消',
  25955. confirm: '确认',
  25956. insert: '插入所选项目',
  25957. width: '宽度',
  25958. height: '高度',
  25959. image: '图片',
  25960. video: '视频',
  25961. audio: '音频',
  25962. embed: '嵌入式媒体',
  25963. caption: '媒体库',
  25964. dragTip: '点击或拖动文件至此',
  25965. dropTip: '放开鼠标以上传',
  25966. selectAll: '选择全部',
  25967. deselect: '取消选择',
  25968. removeSelected: '删除选中项目',
  25969. externalInputPlaceHolder: '资源名称|资源地址',
  25970. externalInputTip: '使用“|”分隔资源名称和资源地址',
  25971. addLocalFile: '添加本地资源',
  25972. addExternalSource: '添加网络资源',
  25973. unnamedItem: '未命名项目',
  25974. confirmInsert: '插入选中项目'
  25975. };
  25976. /***/ }),
  25977. /* 8 */
  25978. /***/ (function(module, exports, __webpack_require__) {
  25979. Object.defineProperty(exports, "__esModule", {
  25980. value: true
  25981. });
  25982. exports.default = {
  25983. remove: '删除',
  25984. cancel: '取消',
  25985. confirm: '确认',
  25986. insert: '插入所选项目',
  25987. width: '宽度',
  25988. height: '高度',
  25989. image: '图片',
  25990. video: '视频',
  25991. audio: '音频',
  25992. embed: '嵌入式媒体',
  25993. caption: '媒体库',
  25994. dragTip: '点击或拖动文件至此',
  25995. dropTip: '放开鼠标以上传',
  25996. selectAll: '选择全部',
  25997. deselect: '取消选择',
  25998. removeSelected: '删除选中项目',
  25999. externalInputPlaceHolder: '资源名称|资源地址',
  26000. externalInputTip: '使用“|”分隔资源名称和资源地址',
  26001. addLocalFile: '添加本地资源',
  26002. addExternalSource: '添加网络资源',
  26003. unnamedItem: '未命名项目',
  26004. confirmInsert: '插入选中项目'
  26005. };
  26006. /***/ }),
  26007. /* 9 */
  26008. /***/ (function(module, exports, __webpack_require__) {
  26009. Object.defineProperty(exports, "__esModule", {
  26010. value: true
  26011. });
  26012. exports.default = {
  26013. remove: 'Remove',
  26014. cancel: 'Cancel',
  26015. confirm: 'Confirm',
  26016. insert: 'Insert Selected Items',
  26017. width: 'Width',
  26018. height: 'Height',
  26019. image: 'Image',
  26020. video: 'Video',
  26021. audio: 'Audio',
  26022. embed: 'Embed',
  26023. caption: 'Media Library',
  26024. dragTip: 'Click Or Drag Files Here',
  26025. dropTip: 'Drop To Upload',
  26026. selectAll: 'Select All',
  26027. deselect: 'Deselect',
  26028. removeSelected: 'Remove Selected Items',
  26029. externalInputPlaceHolder: 'Source Name|Source URL',
  26030. externalInputTip: 'Split source name and source URL with "|", confirm by hit Enter.',
  26031. addLocalFile: 'Add from local',
  26032. addExternalSource: 'Add from Internet',
  26033. unnamedItem: 'Unnamed Item',
  26034. confirmInsert: 'Insert selected items'
  26035. };
  26036. /***/ }),
  26037. /* 10 */
  26038. /***/ (function(module, exports, __webpack_require__) {
  26039. Object.defineProperty(exports, "__esModule", {
  26040. value: true
  26041. });
  26042. var _en = __webpack_require__(9);
  26043. var _en2 = _interopRequireDefault(_en);
  26044. var _zh = __webpack_require__(8);
  26045. var _zh2 = _interopRequireDefault(_zh);
  26046. var _zhHant = __webpack_require__(7);
  26047. var _zhHant2 = _interopRequireDefault(_zhHant);
  26048. var _pl = __webpack_require__(6);
  26049. var _pl2 = _interopRequireDefault(_pl);
  26050. var _kr = __webpack_require__(5);
  26051. var _kr2 = _interopRequireDefault(_kr);
  26052. var _jpn = __webpack_require__(4);
  26053. var _jpn2 = _interopRequireDefault(_jpn);
  26054. var _tr = __webpack_require__(3);
  26055. var _tr2 = _interopRequireDefault(_tr);
  26056. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  26057. exports.default = {
  26058. "en": _en2.default,
  26059. "zh": _zh2.default,
  26060. "zh-hant": _zhHant2.default,
  26061. "pl": _pl2.default,
  26062. "kr": _kr2.default,
  26063. "jpn": _jpn2.default,
  26064. "tr": _tr2.default
  26065. };
  26066. /***/ }),
  26067. /* 11 */
  26068. /***/ (function(module, exports) {
  26069. /**
  26070. * When source maps are enabled, `style-loader` uses a link element with a data-uri to
  26071. * embed the css on the page. This breaks all relative urls because now they are relative to a
  26072. * bundle instead of the current page.
  26073. *
  26074. * One solution is to only use full urls, but that may be impossible.
  26075. *
  26076. * Instead, this function "fixes" the relative urls to be absolute according to the current page location.
  26077. *
  26078. * A rudimentary test suite is located at `test/fixUrls.js` and can be run via the `npm test` command.
  26079. *
  26080. */
  26081. module.exports = function (css) {
  26082. // get current location
  26083. var location = typeof window !== "undefined" && window.location;
  26084. if (!location) {
  26085. throw new Error("fixUrls requires window.location");
  26086. }
  26087. // blank or null?
  26088. if (!css || typeof css !== "string") {
  26089. return css;
  26090. }
  26091. var baseUrl = location.protocol + "//" + location.host;
  26092. var currentDir = baseUrl + location.pathname.replace(/\/[^\/]*$/, "/");
  26093. // convert each url(...)
  26094. /*
  26095. This regular expression is just a way to recursively match brackets within
  26096. a string.
  26097. /url\s*\( = Match on the word "url" with any whitespace after it and then a parens
  26098. ( = Start a capturing group
  26099. (?: = Start a non-capturing group
  26100. [^)(] = Match anything that isn't a parentheses
  26101. | = OR
  26102. \( = Match a start parentheses
  26103. (?: = Start another non-capturing groups
  26104. [^)(]+ = Match anything that isn't a parentheses
  26105. | = OR
  26106. \( = Match a start parentheses
  26107. [^)(]* = Match anything that isn't a parentheses
  26108. \) = Match a end parentheses
  26109. ) = End Group
  26110. *\) = Match anything and then a close parens
  26111. ) = Close non-capturing group
  26112. * = Match anything
  26113. ) = Close capturing group
  26114. \) = Match a close parens
  26115. /gi = Get all matches, not the first. Be case insensitive.
  26116. */
  26117. var fixedCss = css.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi, function(fullMatch, origUrl) {
  26118. // strip quotes (if they exist)
  26119. var unquotedOrigUrl = origUrl
  26120. .trim()
  26121. .replace(/^"(.*)"$/, function(o, $1){ return $1; })
  26122. .replace(/^'(.*)'$/, function(o, $1){ return $1; });
  26123. // already a full url? no change
  26124. if (/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(unquotedOrigUrl)) {
  26125. return fullMatch;
  26126. }
  26127. // convert the url to a full url
  26128. var newUrl;
  26129. if (unquotedOrigUrl.indexOf("//") === 0) {
  26130. //TODO: should we add protocol?
  26131. newUrl = unquotedOrigUrl;
  26132. } else if (unquotedOrigUrl.indexOf("/") === 0) {
  26133. // path should be relative to the base url
  26134. newUrl = baseUrl + unquotedOrigUrl; // already starts with '/'
  26135. } else {
  26136. // path should be relative to current directory
  26137. newUrl = currentDir + unquotedOrigUrl.replace(/^\.\//, ""); // Strip leading './'
  26138. }
  26139. // send back the fixed url(...)
  26140. return "url(" + JSON.stringify(newUrl) + ")";
  26141. });
  26142. // send back the fixed css
  26143. return fixedCss;
  26144. };
  26145. /***/ }),
  26146. /* 12 */
  26147. /***/ (function(module, exports, __webpack_require__) {
  26148. /*
  26149. MIT License http://www.opensource.org/licenses/mit-license.php
  26150. Author Tobias Koppers @sokra
  26151. */
  26152. var stylesInDom = {};
  26153. var memoize = function (fn) {
  26154. var memo;
  26155. return function () {
  26156. if (typeof memo === "undefined") memo = fn.apply(this, arguments);
  26157. return memo;
  26158. };
  26159. };
  26160. var isOldIE = memoize(function () {
  26161. // Test for IE <= 9 as proposed by Browserhacks
  26162. // @see http://browserhacks.com/#hack-e71d8692f65334173fee715c222cb805
  26163. // Tests for existence of standard globals is to allow style-loader
  26164. // to operate correctly into non-standard environments
  26165. // @see https://github.com/webpack-contrib/style-loader/issues/177
  26166. return window && document && document.all && !window.atob;
  26167. });
  26168. var getTarget = function (target) {
  26169. return document.querySelector(target);
  26170. };
  26171. var getElement = (function (fn) {
  26172. var memo = {};
  26173. return function(target) {
  26174. // If passing function in options, then use it for resolve "head" element.
  26175. // Useful for Shadow Root style i.e
  26176. // {
  26177. // insertInto: function () { return document.querySelector("#foo").shadowRoot }
  26178. // }
  26179. if (typeof target === 'function') {
  26180. return target();
  26181. }
  26182. if (typeof memo[target] === "undefined") {
  26183. var styleTarget = getTarget.call(this, target);
  26184. // Special case to return head of iframe instead of iframe itself
  26185. if (window.HTMLIFrameElement && styleTarget instanceof window.HTMLIFrameElement) {
  26186. try {
  26187. // This will throw an exception if access to iframe is blocked
  26188. // due to cross-origin restrictions
  26189. styleTarget = styleTarget.contentDocument.head;
  26190. } catch(e) {
  26191. styleTarget = null;
  26192. }
  26193. }
  26194. memo[target] = styleTarget;
  26195. }
  26196. return memo[target]
  26197. };
  26198. })();
  26199. var singleton = null;
  26200. var singletonCounter = 0;
  26201. var stylesInsertedAtTop = [];
  26202. var fixUrls = __webpack_require__(11);
  26203. module.exports = function(list, options) {
  26204. if (typeof DEBUG !== "undefined" && DEBUG) {
  26205. if (typeof document !== "object") throw new Error("The style-loader cannot be used in a non-browser environment");
  26206. }
  26207. options = options || {};
  26208. options.attrs = typeof options.attrs === "object" ? options.attrs : {};
  26209. // Force single-tag solution on IE6-9, which has a hard limit on the # of <style>
  26210. // tags it will allow on a page
  26211. if (!options.singleton && typeof options.singleton !== "boolean") options.singleton = isOldIE();
  26212. // By default, add <style> tags to the <head> element
  26213. if (!options.insertInto) options.insertInto = "head";
  26214. // By default, add <style> tags to the bottom of the target
  26215. if (!options.insertAt) options.insertAt = "bottom";
  26216. var styles = listToStyles(list, options);
  26217. addStylesToDom(styles, options);
  26218. return function update (newList) {
  26219. var mayRemove = [];
  26220. for (var i = 0; i < styles.length; i++) {
  26221. var item = styles[i];
  26222. var domStyle = stylesInDom[item.id];
  26223. domStyle.refs--;
  26224. mayRemove.push(domStyle);
  26225. }
  26226. if(newList) {
  26227. var newStyles = listToStyles(newList, options);
  26228. addStylesToDom(newStyles, options);
  26229. }
  26230. for (var i = 0; i < mayRemove.length; i++) {
  26231. var domStyle = mayRemove[i];
  26232. if(domStyle.refs === 0) {
  26233. for (var j = 0; j < domStyle.parts.length; j++) domStyle.parts[j]();
  26234. delete stylesInDom[domStyle.id];
  26235. }
  26236. }
  26237. };
  26238. };
  26239. function addStylesToDom (styles, options) {
  26240. for (var i = 0; i < styles.length; i++) {
  26241. var item = styles[i];
  26242. var domStyle = stylesInDom[item.id];
  26243. if(domStyle) {
  26244. domStyle.refs++;
  26245. for(var j = 0; j < domStyle.parts.length; j++) {
  26246. domStyle.parts[j](item.parts[j]);
  26247. }
  26248. for(; j < item.parts.length; j++) {
  26249. domStyle.parts.push(addStyle(item.parts[j], options));
  26250. }
  26251. } else {
  26252. var parts = [];
  26253. for(var j = 0; j < item.parts.length; j++) {
  26254. parts.push(addStyle(item.parts[j], options));
  26255. }
  26256. stylesInDom[item.id] = {id: item.id, refs: 1, parts: parts};
  26257. }
  26258. }
  26259. }
  26260. function listToStyles (list, options) {
  26261. var styles = [];
  26262. var newStyles = {};
  26263. for (var i = 0; i < list.length; i++) {
  26264. var item = list[i];
  26265. var id = options.base ? item[0] + options.base : item[0];
  26266. var css = item[1];
  26267. var media = item[2];
  26268. var sourceMap = item[3];
  26269. var part = {css: css, media: media, sourceMap: sourceMap};
  26270. if(!newStyles[id]) styles.push(newStyles[id] = {id: id, parts: [part]});
  26271. else newStyles[id].parts.push(part);
  26272. }
  26273. return styles;
  26274. }
  26275. function insertStyleElement (options, style) {
  26276. var target = getElement(options.insertInto);
  26277. if (!target) {
  26278. throw new Error("Couldn't find a style target. This probably means that the value for the 'insertInto' parameter is invalid.");
  26279. }
  26280. var lastStyleElementInsertedAtTop = stylesInsertedAtTop[stylesInsertedAtTop.length - 1];
  26281. if (options.insertAt === "top") {
  26282. if (!lastStyleElementInsertedAtTop) {
  26283. target.insertBefore(style, target.firstChild);
  26284. } else if (lastStyleElementInsertedAtTop.nextSibling) {
  26285. target.insertBefore(style, lastStyleElementInsertedAtTop.nextSibling);
  26286. } else {
  26287. target.appendChild(style);
  26288. }
  26289. stylesInsertedAtTop.push(style);
  26290. } else if (options.insertAt === "bottom") {
  26291. target.appendChild(style);
  26292. } else if (typeof options.insertAt === "object" && options.insertAt.before) {
  26293. var nextSibling = getElement(options.insertInto + " " + options.insertAt.before);
  26294. target.insertBefore(style, nextSibling);
  26295. } else {
  26296. 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");
  26297. }
  26298. }
  26299. function removeStyleElement (style) {
  26300. if (style.parentNode === null) return false;
  26301. style.parentNode.removeChild(style);
  26302. var idx = stylesInsertedAtTop.indexOf(style);
  26303. if(idx >= 0) {
  26304. stylesInsertedAtTop.splice(idx, 1);
  26305. }
  26306. }
  26307. function createStyleElement (options) {
  26308. var style = document.createElement("style");
  26309. if(options.attrs.type === undefined) {
  26310. options.attrs.type = "text/css";
  26311. }
  26312. addAttrs(style, options.attrs);
  26313. insertStyleElement(options, style);
  26314. return style;
  26315. }
  26316. function createLinkElement (options) {
  26317. var link = document.createElement("link");
  26318. if(options.attrs.type === undefined) {
  26319. options.attrs.type = "text/css";
  26320. }
  26321. options.attrs.rel = "stylesheet";
  26322. addAttrs(link, options.attrs);
  26323. insertStyleElement(options, link);
  26324. return link;
  26325. }
  26326. function addAttrs (el, attrs) {
  26327. Object.keys(attrs).forEach(function (key) {
  26328. el.setAttribute(key, attrs[key]);
  26329. });
  26330. }
  26331. function addStyle (obj, options) {
  26332. var style, update, remove, result;
  26333. // If a transform function was defined, run it on the css
  26334. if (options.transform && obj.css) {
  26335. result = options.transform(obj.css);
  26336. if (result) {
  26337. // If transform returns a value, use that instead of the original css.
  26338. // This allows running runtime transformations on the css.
  26339. obj.css = result;
  26340. } else {
  26341. // If the transform function returns a falsy value, don't add this css.
  26342. // This allows conditional loading of css
  26343. return function() {
  26344. // noop
  26345. };
  26346. }
  26347. }
  26348. if (options.singleton) {
  26349. var styleIndex = singletonCounter++;
  26350. style = singleton || (singleton = createStyleElement(options));
  26351. update = applyToSingletonTag.bind(null, style, styleIndex, false);
  26352. remove = applyToSingletonTag.bind(null, style, styleIndex, true);
  26353. } else if (
  26354. obj.sourceMap &&
  26355. typeof URL === "function" &&
  26356. typeof URL.createObjectURL === "function" &&
  26357. typeof URL.revokeObjectURL === "function" &&
  26358. typeof Blob === "function" &&
  26359. typeof btoa === "function"
  26360. ) {
  26361. style = createLinkElement(options);
  26362. update = updateLink.bind(null, style, options);
  26363. remove = function () {
  26364. removeStyleElement(style);
  26365. if(style.href) URL.revokeObjectURL(style.href);
  26366. };
  26367. } else {
  26368. style = createStyleElement(options);
  26369. update = applyToTag.bind(null, style);
  26370. remove = function () {
  26371. removeStyleElement(style);
  26372. };
  26373. }
  26374. update(obj);
  26375. return function updateStyle (newObj) {
  26376. if (newObj) {
  26377. if (
  26378. newObj.css === obj.css &&
  26379. newObj.media === obj.media &&
  26380. newObj.sourceMap === obj.sourceMap
  26381. ) {
  26382. return;
  26383. }
  26384. update(obj = newObj);
  26385. } else {
  26386. remove();
  26387. }
  26388. };
  26389. }
  26390. var replaceText = (function () {
  26391. var textStore = [];
  26392. return function (index, replacement) {
  26393. textStore[index] = replacement;
  26394. return textStore.filter(Boolean).join('\n');
  26395. };
  26396. })();
  26397. function applyToSingletonTag (style, index, remove, obj) {
  26398. var css = remove ? "" : obj.css;
  26399. if (style.styleSheet) {
  26400. style.styleSheet.cssText = replaceText(index, css);
  26401. } else {
  26402. var cssNode = document.createTextNode(css);
  26403. var childNodes = style.childNodes;
  26404. if (childNodes[index]) style.removeChild(childNodes[index]);
  26405. if (childNodes.length) {
  26406. style.insertBefore(cssNode, childNodes[index]);
  26407. } else {
  26408. style.appendChild(cssNode);
  26409. }
  26410. }
  26411. }
  26412. function applyToTag (style, obj) {
  26413. var css = obj.css;
  26414. var media = obj.media;
  26415. if(media) {
  26416. style.setAttribute("media", media);
  26417. }
  26418. if(style.styleSheet) {
  26419. style.styleSheet.cssText = css;
  26420. } else {
  26421. while(style.firstChild) {
  26422. style.removeChild(style.firstChild);
  26423. }
  26424. style.appendChild(document.createTextNode(css));
  26425. }
  26426. }
  26427. function updateLink (link, options, obj) {
  26428. var css = obj.css;
  26429. var sourceMap = obj.sourceMap;
  26430. /*
  26431. If convertToAbsoluteUrls isn't defined, but sourcemaps are enabled
  26432. and there is no publicPath defined then lets turn convertToAbsoluteUrls
  26433. on by default. Otherwise default to the convertToAbsoluteUrls option
  26434. directly
  26435. */
  26436. var autoFixUrls = options.convertToAbsoluteUrls === undefined && sourceMap;
  26437. if (options.convertToAbsoluteUrls || autoFixUrls) {
  26438. css = fixUrls(css);
  26439. }
  26440. if (sourceMap) {
  26441. // http://stackoverflow.com/a/26603875
  26442. css += "\n/*# sourceMappingURL=data:application/json;base64," + btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))) + " */";
  26443. }
  26444. var blob = new Blob([css], { type: "text/css" });
  26445. var oldSrc = link.href;
  26446. link.href = URL.createObjectURL(blob);
  26447. if(oldSrc) URL.revokeObjectURL(oldSrc);
  26448. }
  26449. /***/ }),
  26450. /* 13 */
  26451. /***/ (function(module, exports) {
  26452. 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=";
  26453. /***/ }),
  26454. /* 14 */
  26455. /***/ (function(module, exports) {
  26456. /*
  26457. MIT License http://www.opensource.org/licenses/mit-license.php
  26458. Author Tobias Koppers @sokra
  26459. */
  26460. // css base code, injected by the css-loader
  26461. module.exports = function(useSourceMap) {
  26462. var list = [];
  26463. // return the list of modules as css string
  26464. list.toString = function toString() {
  26465. return this.map(function (item) {
  26466. var content = cssWithMappingToString(item, useSourceMap);
  26467. if(item[2]) {
  26468. return "@media " + item[2] + "{" + content + "}";
  26469. } else {
  26470. return content;
  26471. }
  26472. }).join("");
  26473. };
  26474. // import a list of modules into the list
  26475. list.i = function(modules, mediaQuery) {
  26476. if(typeof modules === "string")
  26477. modules = [[null, modules, ""]];
  26478. var alreadyImportedModules = {};
  26479. for(var i = 0; i < this.length; i++) {
  26480. var id = this[i][0];
  26481. if(typeof id === "number")
  26482. alreadyImportedModules[id] = true;
  26483. }
  26484. for(i = 0; i < modules.length; i++) {
  26485. var item = modules[i];
  26486. // skip already imported module
  26487. // this implementation is not 100% perfect for weird media query combinations
  26488. // when a module is imported multiple times with different media queries.
  26489. // I hope this will never occur (Hey this way we have smaller bundles)
  26490. if(typeof item[0] !== "number" || !alreadyImportedModules[item[0]]) {
  26491. if(mediaQuery && !item[2]) {
  26492. item[2] = mediaQuery;
  26493. } else if(mediaQuery) {
  26494. item[2] = "(" + item[2] + ") and (" + mediaQuery + ")";
  26495. }
  26496. list.push(item);
  26497. }
  26498. }
  26499. };
  26500. return list;
  26501. };
  26502. function cssWithMappingToString(item, useSourceMap) {
  26503. var content = item[1] || '';
  26504. var cssMapping = item[3];
  26505. if (!cssMapping) {
  26506. return content;
  26507. }
  26508. if (useSourceMap && typeof btoa === 'function') {
  26509. var sourceMapping = toComment(cssMapping);
  26510. var sourceURLs = cssMapping.sources.map(function (source) {
  26511. return '/*# sourceURL=' + cssMapping.sourceRoot + source + ' */'
  26512. });
  26513. return [content].concat(sourceURLs).concat([sourceMapping]).join('\n');
  26514. }
  26515. return [content].join('\n');
  26516. }
  26517. // Adapted from convert-source-map (MIT)
  26518. function toComment(sourceMap) {
  26519. // eslint-disable-next-line no-undef
  26520. var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))));
  26521. var data = 'sourceMappingURL=data:application/json;charset=utf-8;base64,' + base64;
  26522. return '/*# ' + data + ' */';
  26523. }
  26524. /***/ }),
  26525. /* 15 */
  26526. /***/ (function(module, exports) {
  26527. module.exports = function escape(url) {
  26528. if (typeof url !== 'string') {
  26529. return url
  26530. }
  26531. // If url is already wrapped in quotes, remove them
  26532. if (/^['"].*['"]$/.test(url)) {
  26533. url = url.slice(1, -1);
  26534. }
  26535. // Should url be wrapped?
  26536. // See https://drafts.csswg.org/css-values-3/#urls
  26537. if (/["'() \t\n]/.test(url)) {
  26538. return '"' + url.replace(/"/g, '\\"').replace(/\n/g, '\\n') + '"'
  26539. }
  26540. return url
  26541. };
  26542. /***/ }),
  26543. /* 16 */
  26544. /***/ (function(module, exports, __webpack_require__) {
  26545. var escape = __webpack_require__(15);
  26546. exports = module.exports = __webpack_require__(14)(false);
  26547. // imports
  26548. // module
  26549. 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", ""]);
  26550. // exports
  26551. /***/ }),
  26552. /* 17 */
  26553. /***/ (function(module, exports, __webpack_require__) {
  26554. var content = __webpack_require__(16);
  26555. if(typeof content === 'string') content = [[module.i, content, '']];
  26556. var transform;
  26557. var options = {"hmr":true};
  26558. options.transform = transform;
  26559. options.insertInto = undefined;
  26560. var update = __webpack_require__(12)(content, options);
  26561. if(content.locals) module.exports = content.locals;
  26562. /***/ }),
  26563. /* 18 */
  26564. /***/ (function(module, exports, __webpack_require__) {
  26565. Object.defineProperty(exports, "__esModule", {
  26566. value: true
  26567. });
  26568. 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; };
  26569. 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; }; }();
  26570. __webpack_require__(17);
  26571. var _react = __webpack_require__(2);
  26572. var _react2 = _interopRequireDefault(_react);
  26573. var _base = __webpack_require__(1);
  26574. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  26575. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  26576. 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; }
  26577. 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; }
  26578. var defaultAccepts = {
  26579. image: 'image/png,image/jpeg,image/gif,image/webp,image/apng,image/svg',
  26580. video: 'video/mp4',
  26581. audio: 'audio/mp3'
  26582. };
  26583. var BraftFinderView = function (_React$Component) {
  26584. _inherits(BraftFinderView, _React$Component);
  26585. function BraftFinderView(props) {
  26586. _classCallCheck(this, BraftFinderView);
  26587. var _this = _possibleConstructorReturn(this, (BraftFinderView.__proto__ || Object.getPrototypeOf(BraftFinderView)).call(this, props));
  26588. _this.toggleSelectItem = function (event) {
  26589. var itemId = event.currentTarget.dataset.id;
  26590. var item = _this.controller.getMediaItem(itemId);
  26591. if (!item) {
  26592. return false;
  26593. }
  26594. if (item.selected) {
  26595. if (!_this.props.onBeforeDeselect || _this.props.onBeforeDeselect([item], _this.controller.getItems()) !== false) {
  26596. _this.controller.deselectMediaItem(itemId);
  26597. _this.props.onDeselect && _this.props.onDeselect([item], _this.controller.getItems());
  26598. }
  26599. } else {
  26600. if (!_this.props.onBeforeSelect || _this.props.onBeforeSelect([item], _this.controller.getItems()) !== false) {
  26601. _this.controller.selectMediaItem(itemId);
  26602. _this.props.onSelect && _this.props.onSelect([item], _this.controller.getItems());
  26603. }
  26604. }
  26605. };
  26606. _this.removeItem = function (event) {
  26607. var itemId = event.currentTarget.dataset.id;
  26608. var item = _this.controller.getMediaItem(itemId);
  26609. if (!item) {
  26610. return false;
  26611. }
  26612. if (!_this.props.onBeforeRemove || _this.props.onBeforeRemove([item], _this.controller.getItems()) !== false) {
  26613. _this.controller.removeMediaItem(itemId);
  26614. _this.props.onRemove && _this.props.onRemove([item], _this.controller.getItems());
  26615. }
  26616. event.stopPropagation();
  26617. };
  26618. _this.selectAllItems = function () {
  26619. var allItems = _this.controller.getItems();
  26620. if (!_this.props.onBeforeSelect || _this.props.onBeforeSelect(allItems, allItems) !== false) {
  26621. _this.controller.selectAllItems();
  26622. _this.props.onSelect && _this.props.onSelect(allItems, allItems);
  26623. }
  26624. };
  26625. _this.deselectAllItems = function () {
  26626. var allItems = _this.controller.getItems();
  26627. if (!_this.props.onBeforeDeselect || _this.props.onBeforeDeselect(allItems, allItems) !== false) {
  26628. _this.controller.deselectAllItems();
  26629. _this.props.onDeselect && _this.props.onDeselect(allItems, allItems);
  26630. }
  26631. };
  26632. _this.removeSelectedItems = function () {
  26633. var selectedItems = _this.controller.getSelectedItems();
  26634. if (!_this.props.onBeforeRemove || _this.props.onBeforeRemove(selectedItems, _this.controller.getItems()) !== false) {
  26635. _this.controller.removeSelectedItems();
  26636. _this.props.onRemove && _this.props.onRemove(selectedItems, _this.controller.getItems());
  26637. }
  26638. };
  26639. _this.handleDragLeave = function (event) {
  26640. event.preventDefault();
  26641. _this.dragCounter--;
  26642. _this.dragCounter === 0 && _this.setState({
  26643. draging: false
  26644. });
  26645. };
  26646. _this.handleDragDrop = function (event) {
  26647. event.preventDefault();
  26648. _this.dragCounter = 0;
  26649. _this.setState({ draging: false });
  26650. _this.reslovePickedFiles(event);
  26651. };
  26652. _this.handleDragEnter = function (event) {
  26653. event.preventDefault();
  26654. _this.dragCounter++;
  26655. _this.setState({ draging: true });
  26656. };
  26657. _this.reslovePickedFiles = function (event) {
  26658. event.persist();
  26659. var _ref = event.type === 'drop' ? event.dataTransfer : event.target,
  26660. files = _ref.files;
  26661. if (_this.props.onFileSelect) {
  26662. var result = _this.props.onFileSelect(files);
  26663. if (result === false) {
  26664. return false;
  26665. } else if (result instanceof FileList || result instanceof Array) {
  26666. files = result;
  26667. }
  26668. }
  26669. var accepts = _extends({}, defaultAccepts, _this.props.accepts);
  26670. _this.controller.resolveFiles({
  26671. files: files,
  26672. onItemReady: function onItemReady(_ref2) {
  26673. var id = _ref2.id;
  26674. return _this.controller.selectMediaItem(id);
  26675. },
  26676. onAllReady: function onAllReady() {
  26677. return event.target.value = null;
  26678. }
  26679. }, 0, accepts);
  26680. };
  26681. _this.inputExternal = function (event) {
  26682. _this.setState({
  26683. external: _extends({}, _this.state.external, {
  26684. url: event.target.value
  26685. })
  26686. });
  26687. };
  26688. _this.switchExternalType = function (event) {
  26689. _this.setState({
  26690. external: _extends({}, _this.state.external, { type: event.target.dataset.type })
  26691. });
  26692. };
  26693. _this.confirmAddExternal = function (event) {
  26694. if (event.target.nodeName.toLowerCase() === 'button' || event.keyCode === 13) {
  26695. var _this$state$external = _this.state.external,
  26696. url = _this$state$external.url,
  26697. type = _this$state$external.type;
  26698. url = url.split('|');
  26699. var name = url.length > 1 ? url[0] : _this.props.language.unnamedItem;
  26700. url = url.length > 1 ? url[1] : url[0];
  26701. var thumbnail = type === 'IMAGE' ? url : null;
  26702. _this.controller.addItems([{
  26703. thumbnail: thumbnail, url: url, name: name, type: type,
  26704. id: new Date().getTime() + '_' + (0, _base.UniqueIndex)(),
  26705. uploading: false,
  26706. uploadProgress: 1,
  26707. selected: true
  26708. }]);
  26709. _this.setState({
  26710. showExternalForm: false,
  26711. external: {
  26712. url: '',
  26713. type: 'IMAGE'
  26714. }
  26715. });
  26716. }
  26717. };
  26718. _this.toggleExternalForm = function () {
  26719. _this.setState({
  26720. showExternalForm: !_this.state.showExternalForm
  26721. });
  26722. };
  26723. _this.cancelInsert = function () {
  26724. _this.props.onCancel && _this.props.onCancel();
  26725. };
  26726. _this.confirmInsert = function () {
  26727. var selectedItems = _this.controller.getSelectedItems();
  26728. if (_this.props.onBeforeInsert) {
  26729. var filteredItems = _this.props.onBeforeInsert(selectedItems);
  26730. if (filteredItems && filteredItems instanceof Array) {
  26731. _this.controller.deselectAllItems();
  26732. _this.props.onInsert && _this.props.onInsert(filteredItems);
  26733. } else if (filteredItems !== false) {
  26734. _this.controller.deselectAllItems();
  26735. _this.props.onInsert && _this.props.onInsert(selectedItems);
  26736. }
  26737. } else {
  26738. _this.controller.deselectAllItems();
  26739. _this.props.onInsert && _this.props.onInsert(selectedItems);
  26740. }
  26741. };
  26742. _this.dragCounter = 0;
  26743. _this.controller = _this.props.controller;
  26744. var initialItems = _this.controller.getItems();
  26745. _this.state = {
  26746. draging: false,
  26747. error: false,
  26748. confirmable: initialItems.find(function (_ref3) {
  26749. var selected = _ref3.selected;
  26750. return selected;
  26751. }),
  26752. external: {
  26753. url: '',
  26754. type: 'IMAGE'
  26755. },
  26756. fileAccept: '',
  26757. showExternalForm: false,
  26758. allowExternal: false,
  26759. items: initialItems
  26760. };
  26761. _this.changeListenerId = _this.controller.onChange(function (items) {
  26762. _this.setState({ items: items, confirmable: items.find(function (_ref4) {
  26763. var selected = _ref4.selected;
  26764. return selected;
  26765. }) });
  26766. _this.props.onChange && _this.props.onChange(items);
  26767. });
  26768. return _this;
  26769. }
  26770. _createClass(BraftFinderView, [{
  26771. key: 'mapPropsToState',
  26772. value: function mapPropsToState(props) {
  26773. var accepts = props.accepts,
  26774. externals = props.externals;
  26775. accepts = _extends({}, defaultAccepts, accepts);
  26776. var fileAccept = !accepts ? [defaultAccepts.image, defaultAccepts.video, defaultAccepts.audio].join(',') : [accepts.image, accepts.video, accepts.audio].filter(function (item) {
  26777. return item;
  26778. }).join(',');
  26779. var external = {
  26780. url: '',
  26781. type: externals.image ? 'IMAGE' : externals.audio ? 'AUDIO' : externals.video ? 'VIDEO' : externals.embed ? 'EMBED' : ''
  26782. };
  26783. return {
  26784. fileAccept: fileAccept,
  26785. external: external,
  26786. allowExternal: externals && (externals.image || externals.audio || externals.video || externals.embed)
  26787. };
  26788. }
  26789. }, {
  26790. key: 'componentDidMount',
  26791. value: function componentDidMount() {
  26792. this.setState(this.mapPropsToState(this.props));
  26793. }
  26794. }, {
  26795. key: 'componentWillReceiveProps',
  26796. value: function componentWillReceiveProps(nextProps) {
  26797. this.setState(this.mapPropsToState(nextProps));
  26798. }
  26799. }, {
  26800. key: 'componentWillUnmount',
  26801. value: function componentWillUnmount() {
  26802. this.controller.offChange(this.changeListenerId);
  26803. }
  26804. }, {
  26805. key: 'render',
  26806. value: function render() {
  26807. var _props = this.props,
  26808. language = _props.language,
  26809. externals = _props.externals;
  26810. var _state = this.state,
  26811. items = _state.items,
  26812. draging = _state.draging,
  26813. confirmable = _state.confirmable,
  26814. fileAccept = _state.fileAccept,
  26815. external = _state.external,
  26816. showExternalForm = _state.showExternalForm,
  26817. allowExternal = _state.allowExternal;
  26818. return _react2.default.createElement(
  26819. 'div',
  26820. { className: 'braft-finder' },
  26821. _react2.default.createElement(
  26822. 'div',
  26823. {
  26824. onDragEnter: this.handleDragEnter,
  26825. onDragOver: this.handleDragEnter,
  26826. onDragLeave: this.handleDragLeave,
  26827. onDrop: this.handleDragDrop,
  26828. className: 'bf-uploader'
  26829. },
  26830. _react2.default.createElement(
  26831. 'div',
  26832. { className: "bf-drag-uploader " + (draging || !items.length ? 'active ' : ' ') + (draging ? 'draging' : '') },
  26833. _react2.default.createElement(
  26834. 'span',
  26835. { className: 'bf-drag-tip' },
  26836. _react2.default.createElement('input', { accept: fileAccept, onChange: this.reslovePickedFiles, multiple: true, type: 'file' }),
  26837. draging ? language.dropTip : language.dragTip
  26838. )
  26839. ),
  26840. items.length ? _react2.default.createElement(
  26841. 'div',
  26842. { className: 'bf-list-wrap' },
  26843. _react2.default.createElement(
  26844. 'div',
  26845. { className: 'bf-list-tools' },
  26846. _react2.default.createElement(
  26847. 'span',
  26848. { onClick: this.selectAllItems, className: 'bf-select-all' },
  26849. _react2.default.createElement('i', { className: 'braft-icon-done' }),
  26850. ' ',
  26851. language.selectAll
  26852. ),
  26853. _react2.default.createElement(
  26854. 'span',
  26855. { onClick: this.deselectAllItems, disabled: !confirmable, className: 'bf-deselect-all' },
  26856. _react2.default.createElement('i', { className: 'braft-icon-close' }),
  26857. ' ',
  26858. language.deselect
  26859. ),
  26860. _react2.default.createElement(
  26861. 'span',
  26862. { onClick: this.removeSelectedItems, disabled: !confirmable, className: 'bf-remove-selected' },
  26863. _react2.default.createElement('i', { className: 'braft-icon-bin' }),
  26864. ' ',
  26865. language.removeSelected
  26866. )
  26867. ),
  26868. this.buildItemList()
  26869. ) : null,
  26870. showExternalForm && allowExternal ? _react2.default.createElement(
  26871. 'div',
  26872. { className: 'bf-add-external' },
  26873. _react2.default.createElement(
  26874. 'div',
  26875. { className: 'bf-external-form' },
  26876. _react2.default.createElement(
  26877. 'div',
  26878. { className: 'bf-external-input' },
  26879. _react2.default.createElement(
  26880. 'div',
  26881. null,
  26882. _react2.default.createElement('input', { onKeyDown: this.confirmAddExternal, value: external.url, onChange: this.inputExternal, placeholder: language.externalInputPlaceHolder })
  26883. ),
  26884. _react2.default.createElement(
  26885. 'button',
  26886. { type: 'button', onClick: this.confirmAddExternal, disabled: !external.url.trim().length },
  26887. language.confirm
  26888. )
  26889. ),
  26890. _react2.default.createElement(
  26891. 'div',
  26892. { 'data-type': external.type, className: 'bf-switch-external-type' },
  26893. externals.image ? _react2.default.createElement(
  26894. 'button',
  26895. { type: 'button', onClick: this.switchExternalType, 'data-type': 'IMAGE' },
  26896. language.image
  26897. ) : null,
  26898. externals.audio ? _react2.default.createElement(
  26899. 'button',
  26900. { type: 'button', onClick: this.switchExternalType, 'data-type': 'AUDIO' },
  26901. language.audio
  26902. ) : null,
  26903. externals.video ? _react2.default.createElement(
  26904. 'button',
  26905. { type: 'button', onClick: this.switchExternalType, 'data-type': 'VIDEO' },
  26906. language.video
  26907. ) : null,
  26908. externals.embed ? _react2.default.createElement(
  26909. 'button',
  26910. { type: 'button', onClick: this.switchExternalType, 'data-type': 'EMBED' },
  26911. language.embed
  26912. ) : null
  26913. ),
  26914. _react2.default.createElement(
  26915. 'span',
  26916. { className: 'bf-external-tip' },
  26917. language.externalInputTip
  26918. )
  26919. )
  26920. ) : null
  26921. ),
  26922. _react2.default.createElement(
  26923. 'footer',
  26924. { className: 'bf-manager-footer' },
  26925. _react2.default.createElement(
  26926. 'div',
  26927. { className: 'pull-left' },
  26928. allowExternal ? _react2.default.createElement(
  26929. 'span',
  26930. {
  26931. onClick: this.toggleExternalForm,
  26932. className: 'bf-toggle-external-form'
  26933. },
  26934. showExternalForm ? _react2.default.createElement(
  26935. 'span',
  26936. { className: 'bf-bottom-text' },
  26937. _react2.default.createElement('i', { className: 'braft-icon-add' }),
  26938. ' ',
  26939. language.addLocalFile
  26940. ) : _react2.default.createElement(
  26941. 'span',
  26942. { className: 'bf-bottom-text' },
  26943. _react2.default.createElement('i', { className: 'braft-icon-add' }),
  26944. ' ',
  26945. language.addExternalSource
  26946. )
  26947. ) : null
  26948. ),
  26949. _react2.default.createElement(
  26950. 'div',
  26951. { className: 'pull-right' },
  26952. _react2.default.createElement(
  26953. 'button',
  26954. { onClick: this.confirmInsert, className: 'button button-insert', disabled: !confirmable },
  26955. language.insert
  26956. ),
  26957. _react2.default.createElement(
  26958. 'button',
  26959. { onClick: this.cancelInsert, className: 'button button-cancel' },
  26960. language.cancel
  26961. )
  26962. )
  26963. )
  26964. );
  26965. }
  26966. }, {
  26967. key: 'buildItemList',
  26968. value: function buildItemList() {
  26969. var _this2 = this;
  26970. return _react2.default.createElement(
  26971. 'ul',
  26972. { className: 'bf-list' },
  26973. _react2.default.createElement(
  26974. 'li',
  26975. { className: 'bf-add-item' },
  26976. _react2.default.createElement('i', { className: 'braft-icon-add' }),
  26977. _react2.default.createElement('input', { accept: this.state.fileAccept, onChange: this.reslovePickedFiles, multiple: true, type: 'file' })
  26978. ),
  26979. this.state.items.map(function (item, index) {
  26980. var previewerComponents = null;
  26981. var progressMarker = item.uploading && !_this2.props.hideProgress ? _react2.default.createElement(
  26982. 'div',
  26983. { className: 'bf-item-uploading' },
  26984. _react2.default.createElement('div', { className: 'bf-item-uploading-bar', style: { width: item.uploadProgress / 1 + '%' } })
  26985. ) : '';
  26986. switch (item.type) {
  26987. case 'IMAGE':
  26988. previewerComponents = _react2.default.createElement(
  26989. 'div',
  26990. { className: 'bf-image' },
  26991. progressMarker,
  26992. _react2.default.createElement('img', { src: item.thumbnail || item.url })
  26993. );
  26994. break;
  26995. case 'VIDEO':
  26996. previewerComponents = _react2.default.createElement(
  26997. 'div',
  26998. { className: 'bf-icon bf-video', title: item.url },
  26999. progressMarker,
  27000. _react2.default.createElement('i', { className: 'braft-icon-film' }),
  27001. _react2.default.createElement(
  27002. 'span',
  27003. null,
  27004. item.name || item.url
  27005. )
  27006. );
  27007. break;
  27008. case 'AUDIO':
  27009. previewerComponents = _react2.default.createElement(
  27010. 'div',
  27011. { className: 'bf-icon bf-audio', title: item.url },
  27012. progressMarker,
  27013. _react2.default.createElement('i', { className: 'braft-icon-music' }),
  27014. _react2.default.createElement(
  27015. 'span',
  27016. null,
  27017. item.name || item.url
  27018. )
  27019. );
  27020. break;
  27021. case 'EMBED':
  27022. previewerComponents = _react2.default.createElement(
  27023. 'div',
  27024. { className: 'bf-icon bf-embed', title: item.url },
  27025. progressMarker,
  27026. _react2.default.createElement('i', { className: 'braft-icon-code' }),
  27027. _react2.default.createElement(
  27028. 'span',
  27029. null,
  27030. item.name || _this2.props.language.embed
  27031. )
  27032. );
  27033. break;
  27034. default:
  27035. previewerComponents = _react2.default.createElement(
  27036. 'a',
  27037. { className: 'bf-icon bf-file', title: item.url, href: item.url },
  27038. progressMarker,
  27039. _react2.default.createElement('i', { className: 'braft-icon-file-text' }),
  27040. _react2.default.createElement(
  27041. 'span',
  27042. null,
  27043. item.name || item.url
  27044. )
  27045. );
  27046. break;
  27047. }
  27048. var className = ['bf-item'];
  27049. item.selected && className.push('active');
  27050. item.uploading && className.push('uploading');
  27051. item.error && className.push('error');
  27052. return _react2.default.createElement(
  27053. 'li',
  27054. {
  27055. key: index,
  27056. title: item.name,
  27057. 'data-id': item.id,
  27058. className: className.join(' '),
  27059. onClick: _this2.toggleSelectItem
  27060. },
  27061. previewerComponents,
  27062. _react2.default.createElement('span', { 'data-id': item.id, onClick: _this2.removeItem, className: 'bf-item-remove braft-icon-close' }),
  27063. _react2.default.createElement(
  27064. 'span',
  27065. { className: 'bf-item-title' },
  27066. item.name
  27067. )
  27068. );
  27069. })
  27070. );
  27071. }
  27072. }]);
  27073. return BraftFinderView;
  27074. }(_react2.default.Component);
  27075. BraftFinderView.defaultProps = {
  27076. accepts: defaultAccepts,
  27077. externals: {
  27078. image: true,
  27079. video: true,
  27080. audio: true,
  27081. embed: true
  27082. }
  27083. };
  27084. exports.default = BraftFinderView;
  27085. /***/ }),
  27086. /* 19 */
  27087. /***/ (function(module, exports, __webpack_require__) {
  27088. Object.defineProperty(exports, "__esModule", {
  27089. value: true
  27090. });
  27091. 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; };
  27092. var _base = __webpack_require__(1);
  27093. var _image = __webpack_require__(0);
  27094. 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); } }
  27095. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  27096. var defaultValidator = function defaultValidator() {
  27097. return true;
  27098. };
  27099. var BraftFinderController = function BraftFinderController() {
  27100. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  27101. _classCallCheck(this, BraftFinderController);
  27102. _initialiseProps.call(this);
  27103. this.items = props.items || [];
  27104. this.uploadFn = props.uploader;
  27105. this.validateFn = props.validator || defaultValidator;
  27106. this.changeListeners = [];
  27107. }
  27108. // resolvePastedFiles ({ clipboardData }, callback) {
  27109. // if (clipboardData && clipboardData.items && clipboardData.items[0].type.indexOf('image') > -1) {
  27110. // this.uploadImage(clipboardData.items[0].getAsFile(), callback)
  27111. // }
  27112. // }
  27113. ;
  27114. var _initialiseProps = function _initialiseProps() {
  27115. var _this = this;
  27116. this.setProps = function () {
  27117. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  27118. _this.items = props.items || _this.items || [];
  27119. _this.uploadFn = props.uploader;
  27120. _this.validateFn = props.validator || defaultValidator;
  27121. };
  27122. this.getMediaItem = function (id) {
  27123. return _this.items.find(function (item) {
  27124. return item.id === id;
  27125. });
  27126. };
  27127. this.getSelectedItems = function () {
  27128. return _this.items.filter(function (item) {
  27129. return item.selected;
  27130. });
  27131. };
  27132. this.getItems = function () {
  27133. return _this.items;
  27134. };
  27135. this.setItems = function (items) {
  27136. _this.items = items.map(function (item) {
  27137. return _extends({}, item, { id: item.id.toString() });
  27138. }) || [];
  27139. _this.applyChange();
  27140. _this.uploadItems();
  27141. };
  27142. this.addMediaItem = function (item) {
  27143. _this.addItems([item]);
  27144. };
  27145. this.addItems = function (items) {
  27146. _this.items = [].concat(_toConsumableArray(_this.items), _toConsumableArray(items.map(function (item) {
  27147. return _extends({}, item, { id: item.id.toString() });
  27148. })));
  27149. _this.applyChange();
  27150. _this.uploadItems();
  27151. };
  27152. this.selectMediaItem = function (id) {
  27153. var item = _this.getMediaItem(id);
  27154. if (item && (item.uploading || item.error)) {
  27155. return false;
  27156. }
  27157. _this.setMediaItemState(id, {
  27158. selected: true
  27159. });
  27160. };
  27161. this.selectAllItems = function () {
  27162. _this.items = _this.items.filter(function (item) {
  27163. return !item.error && !item.uploading;
  27164. }).map(function (item) {
  27165. return _extends({}, item, { selected: true });
  27166. });
  27167. _this.applyChange();
  27168. };
  27169. this.deselectMediaItem = function (id) {
  27170. _this.setMediaItemState(id, {
  27171. selected: false
  27172. });
  27173. };
  27174. this.deselectAllItems = function () {
  27175. _this.items = _this.items.map(function (item) {
  27176. return _extends({}, item, { selected: false });
  27177. });
  27178. _this.applyChange();
  27179. };
  27180. this.removeMediaItem = function (id) {
  27181. _this.items = _this.items.filter(function (item) {
  27182. return item.id !== id;
  27183. });
  27184. _this.applyChange();
  27185. };
  27186. this.removeItems = function () {
  27187. var ids = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  27188. _this.items = _this.items.filter(function (item) {
  27189. return !ids.includes(item.id);
  27190. });
  27191. _this.applyChange();
  27192. };
  27193. this.removeSelectedItems = function () {
  27194. _this.items = _this.items.filter(function (item) {
  27195. return !item.selected;
  27196. });
  27197. _this.applyChange();
  27198. };
  27199. this.removeErrorItems = function () {
  27200. _this.items = _this.items.filter(function (item) {
  27201. return !item.error;
  27202. });
  27203. _this.applyChange();
  27204. };
  27205. this.removeAllItems = function () {
  27206. _this.items = [];
  27207. _this.applyChange();
  27208. };
  27209. this.setMediaItemState = function (id, state) {
  27210. _this.items = _this.items.map(function (item) {
  27211. return item.id === id ? _extends({}, item, state) : item;
  27212. });
  27213. _this.applyChange();
  27214. };
  27215. this.reuploadErrorItems = function () {
  27216. _this.uploadItems(true);
  27217. };
  27218. this.uploadItems = function () {
  27219. var ignoreError = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  27220. _this.items.forEach(function (item, index) {
  27221. if (item.uploading || item.url) {
  27222. return false;
  27223. }
  27224. if (!ignoreError && item.error) {
  27225. return false;
  27226. }
  27227. if (item.type === 'IMAGE') {
  27228. _this.createThumbnail(item);
  27229. _this.uploadFn = _this.uploadFn || _this.createInlineImage;
  27230. } else if (!_this.uploadFn) {
  27231. _this.setMediaItemState(item.id, { error: 1 });
  27232. return false;
  27233. }
  27234. _this.setMediaItemState(item.id, {
  27235. uploading: true,
  27236. uploadProgress: 0,
  27237. error: 0
  27238. });
  27239. _this.uploadFn({
  27240. id: item.id,
  27241. file: item.file,
  27242. success: function success(res) {
  27243. _this.handleUploadSuccess(item.id, res);
  27244. },
  27245. progress: function progress(_progress) {
  27246. _this.setMediaItemState(item.id, {
  27247. uploading: true,
  27248. uploadProgress: _progress
  27249. });
  27250. },
  27251. error: function error(_error) {
  27252. _this.setMediaItemState(item.id, {
  27253. uploading: false,
  27254. error: 2
  27255. });
  27256. }
  27257. });
  27258. });
  27259. };
  27260. this.createThumbnail = function (_ref) {
  27261. var id = _ref.id,
  27262. file = _ref.file;
  27263. (0, _image.compressImage)(URL.createObjectURL(file), 226, 226).then(function (result) {
  27264. _this.setMediaItemState(id, { thumbnail: result.url });
  27265. });
  27266. };
  27267. this.createInlineImage = function (param) {
  27268. (0, _image.compressImage)(URL.createObjectURL(param.file), 1280, 800).then(function (result) {
  27269. param.success({ url: result.url });
  27270. }).catch(function (error) {
  27271. param.error(error);
  27272. });
  27273. };
  27274. this.handleUploadSuccess = function (id, data) {
  27275. _this.setMediaItemState(id, _extends({}, data, {
  27276. file: null,
  27277. uploadProgress: 1,
  27278. uploading: false,
  27279. selected: false
  27280. }));
  27281. var item = _this.getMediaItem(data.id || id);
  27282. item.onReady && item.onReady(item);
  27283. };
  27284. this.applyChange = function () {
  27285. _this.changeListeners.forEach(function (_ref2) {
  27286. var callback = _ref2.callback;
  27287. return callback(_this.items);
  27288. });
  27289. };
  27290. this.uploadImage = function (file, callback) {
  27291. var fileId = new Date().getTime() + '_' + (0, _base.UniqueIndex)();
  27292. _this.addMediaItem({
  27293. type: 'IMAGE',
  27294. id: fileId,
  27295. file: file,
  27296. name: fileId,
  27297. size: file.size,
  27298. uploadProgress: 0,
  27299. uploading: false,
  27300. selected: false,
  27301. error: 0,
  27302. onReady: callback
  27303. });
  27304. };
  27305. this.uploadImageRecursively = function (files, callback) {
  27306. var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  27307. if (files[index] && files[index].type.indexOf('image') > -1) {
  27308. _this.uploadImage(files[index], function (image) {
  27309. callback && callback(image);
  27310. index < files.length - 1 && _this.uploadImageRecursively(files, callback, index + 1);
  27311. });
  27312. } else {
  27313. index < files.length - 1 && _this.uploadImageRecursively(files, callback, index + 1);
  27314. }
  27315. };
  27316. this.addResolvedFiles = function (param, index, accepts) {
  27317. var data = {
  27318. id: new Date().getTime() + '_' + (0, _base.UniqueIndex)(),
  27319. file: param.files[index],
  27320. name: param.files[index].name,
  27321. size: param.files[index].size,
  27322. uploadProgress: 0,
  27323. uploading: false,
  27324. selected: false,
  27325. error: 0,
  27326. onReady: function onReady(item) {
  27327. param.onItemReady && param.onItemReady(item);
  27328. }
  27329. };
  27330. if (param.files[index].type.indexOf('image/') === 0 && accepts.image) {
  27331. data.type = 'IMAGE';
  27332. _this.addMediaItem(data);
  27333. } else if (param.files[index].type.indexOf('video/') === 0 && accepts.video) {
  27334. data.type = 'VIDEO';
  27335. _this.addMediaItem(data);
  27336. } else if (param.files[index].type.indexOf('audio/') === 0 && accepts.audio) {
  27337. data.type = 'AUDIO';
  27338. _this.addMediaItem(data);
  27339. }
  27340. setTimeout(function () {
  27341. _this.resolveFiles(param, index + 1, accepts);
  27342. }, 60);
  27343. };
  27344. this.resolveFiles = function (param, index, accepts) {
  27345. if (index < param.files.length) {
  27346. var validateResult = _this.validateFn(param.files[index]);
  27347. if (validateResult instanceof Promise) {
  27348. validateResult.then(function () {
  27349. _this.addResolvedFiles(param, index, accepts);
  27350. });
  27351. } else if (validateResult) {
  27352. _this.addResolvedFiles(param, index, accepts);
  27353. }
  27354. } else {
  27355. param.onAllReady && param.onAllReady();
  27356. }
  27357. };
  27358. this.onChange = function (callback) {
  27359. var listenerId = (0, _base.UniqueIndex)();
  27360. _this.changeListeners.push({
  27361. id: listenerId,
  27362. callback: callback
  27363. });
  27364. return listenerId;
  27365. };
  27366. this.offChange = function (listenerId) {
  27367. _this.changeListeners = _this.changeListeners.filter(function (_ref3) {
  27368. var id = _ref3.id;
  27369. return id !== listenerId;
  27370. });
  27371. };
  27372. };
  27373. exports.default = BraftFinderController;
  27374. /***/ }),
  27375. /* 20 */
  27376. /***/ (function(module, exports, __webpack_require__) {
  27377. Object.defineProperty(exports, "__esModule", {
  27378. value: true
  27379. });
  27380. exports.ImageUtils = undefined;
  27381. 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; };
  27382. var _react = __webpack_require__(2);
  27383. var _react2 = _interopRequireDefault(_react);
  27384. var _controller = __webpack_require__(19);
  27385. var _controller2 = _interopRequireDefault(_controller);
  27386. var _view = __webpack_require__(18);
  27387. var _view2 = _interopRequireDefault(_view);
  27388. var _languages = __webpack_require__(10);
  27389. var _languages2 = _interopRequireDefault(_languages);
  27390. var _image = __webpack_require__(0);
  27391. var ImageUtils = _interopRequireWildcard(_image);
  27392. 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; } }
  27393. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  27394. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  27395. 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; }
  27396. 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; }
  27397. var BraftFinder = function (_FinderController) {
  27398. _inherits(BraftFinder, _FinderController);
  27399. function BraftFinder(props) {
  27400. _classCallCheck(this, BraftFinder);
  27401. var _this = _possibleConstructorReturn(this, (BraftFinder.__proto__ || Object.getPrototypeOf(BraftFinder)).call(this, props));
  27402. _initialiseProps.call(_this);
  27403. _this.superProps = props;
  27404. return _this;
  27405. }
  27406. return BraftFinder;
  27407. }(_controller2.default);
  27408. var _initialiseProps = function _initialiseProps() {
  27409. var _this2 = this;
  27410. this.ReactComponent = function () {
  27411. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  27412. var componentProps = _extends({}, _this2.superProps, props);
  27413. var language = (typeof componentProps.language === 'function' ? componentProps.language(_languages2.default, 'braft-finder') : _languages2.default[componentProps.language]) || _languages2.default['zh'];
  27414. return _react2.default.createElement(_view2.default, _extends({}, componentProps, {
  27415. language: language,
  27416. controller: _this2
  27417. }));
  27418. };
  27419. };
  27420. exports.default = BraftFinder;
  27421. exports.ImageUtils = ImageUtils;
  27422. /***/ })
  27423. /******/ ]);
  27424. });
  27425. });
  27426. styleInject_es.unwrapExports(dist$2);
  27427. var dist$3 = styleInject_es.createCommonjsModule(function (module, exports) {
  27428. (function webpackUniversalModuleDefinition(root, factory) {
  27429. module.exports = factory(React__default, dist$1, Draft, immutable$1, dist, reactDom, dist$2, draftjsUtils);
  27430. })(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__) {
  27431. return /******/ (function(modules) { // webpackBootstrap
  27432. /******/ // The module cache
  27433. /******/ var installedModules = {};
  27434. /******/
  27435. /******/ // The require function
  27436. /******/ function __webpack_require__(moduleId) {
  27437. /******/
  27438. /******/ // Check if module is in cache
  27439. /******/ if(installedModules[moduleId]) {
  27440. /******/ return installedModules[moduleId].exports;
  27441. /******/ }
  27442. /******/ // Create a new module (and put it into the cache)
  27443. /******/ var module = installedModules[moduleId] = {
  27444. /******/ i: moduleId,
  27445. /******/ l: false,
  27446. /******/ exports: {}
  27447. /******/ };
  27448. /******/
  27449. /******/ // Execute the module function
  27450. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  27451. /******/
  27452. /******/ // Flag the module as loaded
  27453. /******/ module.l = true;
  27454. /******/
  27455. /******/ // Return the exports of the module
  27456. /******/ return module.exports;
  27457. /******/ }
  27458. /******/
  27459. /******/
  27460. /******/ // expose the modules object (__webpack_modules__)
  27461. /******/ __webpack_require__.m = modules;
  27462. /******/
  27463. /******/ // expose the module cache
  27464. /******/ __webpack_require__.c = installedModules;
  27465. /******/
  27466. /******/ // define getter function for harmony exports
  27467. /******/ __webpack_require__.d = function(exports, name, getter) {
  27468. /******/ if(!__webpack_require__.o(exports, name)) {
  27469. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  27470. /******/ }
  27471. /******/ };
  27472. /******/
  27473. /******/ // define __esModule on exports
  27474. /******/ __webpack_require__.r = function(exports) {
  27475. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  27476. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  27477. /******/ }
  27478. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  27479. /******/ };
  27480. /******/
  27481. /******/ // create a fake namespace object
  27482. /******/ // mode & 1: value is a module id, require it
  27483. /******/ // mode & 2: merge all properties of value into the ns
  27484. /******/ // mode & 4: return value when already ns object
  27485. /******/ // mode & 8|1: behave like require
  27486. /******/ __webpack_require__.t = function(value, mode) {
  27487. /******/ if(mode & 1) value = __webpack_require__(value);
  27488. /******/ if(mode & 8) return value;
  27489. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  27490. /******/ var ns = Object.create(null);
  27491. /******/ __webpack_require__.r(ns);
  27492. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  27493. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  27494. /******/ return ns;
  27495. /******/ };
  27496. /******/
  27497. /******/ // getDefaultExport function for compatibility with non-harmony modules
  27498. /******/ __webpack_require__.n = function(module) {
  27499. /******/ var getter = module && module.__esModule ?
  27500. /******/ function getDefault() { return module['default']; } :
  27501. /******/ function getModuleExports() { return module; };
  27502. /******/ __webpack_require__.d(getter, 'a', getter);
  27503. /******/ return getter;
  27504. /******/ };
  27505. /******/
  27506. /******/ // Object.prototype.hasOwnProperty.call
  27507. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  27508. /******/
  27509. /******/ // __webpack_public_path__
  27510. /******/ __webpack_require__.p = "/";
  27511. /******/
  27512. /******/
  27513. /******/ // Load entry module and return exports
  27514. /******/ return __webpack_require__(__webpack_require__.s = 39);
  27515. /******/ })
  27516. /************************************************************************/
  27517. /******/ ([
  27518. /* 0 */
  27519. /***/ (function(module, exports) {
  27520. module.exports = __WEBPACK_EXTERNAL_MODULE__0__;
  27521. /***/ }),
  27522. /* 1 */
  27523. /***/ (function(module, exports) {
  27524. function _assertThisInitialized(self) {
  27525. if (self === void 0) {
  27526. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  27527. }
  27528. return self;
  27529. }
  27530. module.exports = _assertThisInitialized;
  27531. /***/ }),
  27532. /* 2 */
  27533. /***/ (function(module, exports) {
  27534. function _defineProperty(obj, key, value) {
  27535. if (key in obj) {
  27536. Object.defineProperty(obj, key, {
  27537. value: value,
  27538. enumerable: true,
  27539. configurable: true,
  27540. writable: true
  27541. });
  27542. } else {
  27543. obj[key] = value;
  27544. }
  27545. return obj;
  27546. }
  27547. module.exports = _defineProperty;
  27548. /***/ }),
  27549. /* 3 */
  27550. /***/ (function(module, exports) {
  27551. module.exports = __WEBPACK_EXTERNAL_MODULE__3__;
  27552. /***/ }),
  27553. /* 4 */
  27554. /***/ (function(module, exports) {
  27555. function _classCallCheck(instance, Constructor) {
  27556. if (!(instance instanceof Constructor)) {
  27557. throw new TypeError("Cannot call a class as a function");
  27558. }
  27559. }
  27560. module.exports = _classCallCheck;
  27561. /***/ }),
  27562. /* 5 */
  27563. /***/ (function(module, exports, __webpack_require__) {
  27564. var defineProperty = __webpack_require__(2);
  27565. function _objectSpread(target) {
  27566. for (var i = 1; i < arguments.length; i++) {
  27567. var source = arguments[i] != null ? arguments[i] : {};
  27568. var ownKeys = Object.keys(source);
  27569. if (typeof Object.getOwnPropertySymbols === 'function') {
  27570. ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
  27571. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  27572. }));
  27573. }
  27574. ownKeys.forEach(function (key) {
  27575. defineProperty(target, key, source[key]);
  27576. });
  27577. }
  27578. return target;
  27579. }
  27580. module.exports = _objectSpread;
  27581. /***/ }),
  27582. /* 6 */
  27583. /***/ (function(module, exports) {
  27584. module.exports = __WEBPACK_EXTERNAL_MODULE__6__;
  27585. /***/ }),
  27586. /* 7 */
  27587. /***/ (function(module, exports) {
  27588. function _defineProperties(target, props) {
  27589. for (var i = 0; i < props.length; i++) {
  27590. var descriptor = props[i];
  27591. descriptor.enumerable = descriptor.enumerable || false;
  27592. descriptor.configurable = true;
  27593. if ("value" in descriptor) descriptor.writable = true;
  27594. Object.defineProperty(target, descriptor.key, descriptor);
  27595. }
  27596. }
  27597. function _createClass(Constructor, protoProps, staticProps) {
  27598. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  27599. if (staticProps) _defineProperties(Constructor, staticProps);
  27600. return Constructor;
  27601. }
  27602. module.exports = _createClass;
  27603. /***/ }),
  27604. /* 8 */
  27605. /***/ (function(module, exports, __webpack_require__) {
  27606. var _typeof = __webpack_require__(15);
  27607. var assertThisInitialized = __webpack_require__(1);
  27608. function _possibleConstructorReturn(self, call) {
  27609. if (call && (_typeof(call) === "object" || typeof call === "function")) {
  27610. return call;
  27611. }
  27612. return assertThisInitialized(self);
  27613. }
  27614. module.exports = _possibleConstructorReturn;
  27615. /***/ }),
  27616. /* 9 */
  27617. /***/ (function(module, exports) {
  27618. function _getPrototypeOf(o) {
  27619. module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  27620. return o.__proto__ || Object.getPrototypeOf(o);
  27621. };
  27622. return _getPrototypeOf(o);
  27623. }
  27624. module.exports = _getPrototypeOf;
  27625. /***/ }),
  27626. /* 10 */
  27627. /***/ (function(module, exports, __webpack_require__) {
  27628. var setPrototypeOf = __webpack_require__(26);
  27629. function _inherits(subClass, superClass) {
  27630. if (typeof superClass !== "function" && superClass !== null) {
  27631. throw new TypeError("Super expression must either be null or a function");
  27632. }
  27633. subClass.prototype = Object.create(superClass && superClass.prototype, {
  27634. constructor: {
  27635. value: subClass,
  27636. writable: true,
  27637. configurable: true
  27638. }
  27639. });
  27640. if (superClass) setPrototypeOf(subClass, superClass);
  27641. }
  27642. module.exports = _inherits;
  27643. /***/ }),
  27644. /* 11 */
  27645. /***/ (function(module, exports) {
  27646. function _extends() {
  27647. module.exports = _extends = Object.assign || function (target) {
  27648. for (var i = 1; i < arguments.length; i++) {
  27649. var source = arguments[i];
  27650. for (var key in source) {
  27651. if (Object.prototype.hasOwnProperty.call(source, key)) {
  27652. target[key] = source[key];
  27653. }
  27654. }
  27655. }
  27656. return target;
  27657. };
  27658. return _extends.apply(this, arguments);
  27659. }
  27660. module.exports = _extends;
  27661. /***/ }),
  27662. /* 12 */
  27663. /***/ (function(module, exports, __webpack_require__) {
  27664. var arrayWithoutHoles = __webpack_require__(27);
  27665. var iterableToArray = __webpack_require__(28);
  27666. var nonIterableSpread = __webpack_require__(29);
  27667. function _toConsumableArray(arr) {
  27668. return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread();
  27669. }
  27670. module.exports = _toConsumableArray;
  27671. /***/ }),
  27672. /* 13 */
  27673. /***/ (function(module, exports) {
  27674. module.exports = __WEBPACK_EXTERNAL_MODULE__13__;
  27675. /***/ }),
  27676. /* 14 */
  27677. /***/ (function(module, exports) {
  27678. module.exports = __WEBPACK_EXTERNAL_MODULE__14__;
  27679. /***/ }),
  27680. /* 15 */
  27681. /***/ (function(module, exports) {
  27682. 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); }
  27683. function _typeof(obj) {
  27684. if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") {
  27685. module.exports = _typeof = function _typeof(obj) {
  27686. return _typeof2(obj);
  27687. };
  27688. } else {
  27689. module.exports = _typeof = function _typeof(obj) {
  27690. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj);
  27691. };
  27692. }
  27693. return _typeof(obj);
  27694. }
  27695. module.exports = _typeof;
  27696. /***/ }),
  27697. /* 16 */
  27698. /***/ (function(module, exports) {
  27699. module.exports = __WEBPACK_EXTERNAL_MODULE__16__;
  27700. /***/ }),
  27701. /* 17 */
  27702. /***/ (function(module, exports) {
  27703. module.exports = __WEBPACK_EXTERNAL_MODULE__17__;
  27704. /***/ }),
  27705. /* 18 */
  27706. /***/ (function(module, exports, __webpack_require__) {
  27707. var Immutable = __webpack_require__(13);
  27708. var KEY_SEPARATOR = '-';
  27709. function MultiDecorator(decorators) {
  27710. this.decorators = Immutable.List(decorators);
  27711. }
  27712. /**
  27713. Return list of decoration IDs per character
  27714. @param {ContentBlock}
  27715. @return {List<String>}
  27716. */
  27717. MultiDecorator.prototype.getDecorations = function(block) {
  27718. var decorations = Array(block.getText().length).fill(null);
  27719. this.decorators.forEach(function(decorator, i) {
  27720. var _decorations = decorator.getDecorations(block);
  27721. _decorations.forEach(function(key, offset) {
  27722. if (!key) {
  27723. return;
  27724. }
  27725. key = i + KEY_SEPARATOR + key;
  27726. decorations[offset] = key;
  27727. });
  27728. });
  27729. return Immutable.List(decorations);
  27730. };
  27731. /**
  27732. Return component to render a decoration
  27733. @param {String}
  27734. @return {Function}
  27735. */
  27736. MultiDecorator.prototype.getComponentForKey = function(key) {
  27737. var decorator = this.getDecoratorForKey(key);
  27738. return decorator.getComponentForKey(
  27739. this.getInnerKey(key)
  27740. );
  27741. };
  27742. /**
  27743. Return props to render a decoration
  27744. @param {String}
  27745. @return {Object}
  27746. */
  27747. MultiDecorator.prototype.getPropsForKey = function(key) {
  27748. var decorator = this.getDecoratorForKey(key);
  27749. return decorator.getPropsForKey(
  27750. this.getInnerKey(key)
  27751. );
  27752. };
  27753. /**
  27754. Return a decorator for a specific key
  27755. @param {String}
  27756. @return {Decorator}
  27757. */
  27758. MultiDecorator.prototype.getDecoratorForKey = function(key) {
  27759. var parts = key.split(KEY_SEPARATOR);
  27760. var index = Number(parts[0]);
  27761. return this.decorators.get(index);
  27762. };
  27763. /**
  27764. Return inner key for a decorator
  27765. @param {String}
  27766. @return {String}
  27767. */
  27768. MultiDecorator.prototype.getInnerKey = function(key) {
  27769. var parts = key.split(KEY_SEPARATOR);
  27770. return parts.slice(1).join(KEY_SEPARATOR);
  27771. };
  27772. module.exports = MultiDecorator;
  27773. /***/ }),
  27774. /* 19 */
  27775. /***/ (function(module, exports, __webpack_require__) {
  27776. /**
  27777. * Copyright (c) 2013-present, Facebook, Inc.
  27778. * All rights reserved.
  27779. *
  27780. * This source code is licensed under the BSD-style license found in the
  27781. * LICENSE file in the root directory of this source tree. An additional grant
  27782. * of patent rights can be found in the PATENTS file in the same directory.
  27783. *
  27784. * @providesModule CharacterMetadata
  27785. * @format
  27786. *
  27787. */
  27788. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  27789. 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; }
  27790. 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; }
  27791. var _require = __webpack_require__(13),
  27792. Map = _require.Map,
  27793. OrderedSet = _require.OrderedSet,
  27794. Record = _require.Record;
  27795. // Immutable.map is typed such that the value for every key in the map
  27796. // must be the same type
  27797. var EMPTY_SET = OrderedSet();
  27798. var defaultRecord = {
  27799. style: EMPTY_SET,
  27800. entity: null
  27801. };
  27802. var CharacterMetadataRecord = Record(defaultRecord);
  27803. var CharacterMetadata = function (_CharacterMetadataRec) {
  27804. _inherits(CharacterMetadata, _CharacterMetadataRec);
  27805. function CharacterMetadata() {
  27806. _classCallCheck(this, CharacterMetadata);
  27807. return _possibleConstructorReturn(this, _CharacterMetadataRec.apply(this, arguments));
  27808. }
  27809. CharacterMetadata.prototype.getStyle = function getStyle() {
  27810. return this.get('style');
  27811. };
  27812. CharacterMetadata.prototype.getEntity = function getEntity() {
  27813. return this.get('entity');
  27814. };
  27815. CharacterMetadata.prototype.hasStyle = function hasStyle(style) {
  27816. return this.getStyle().includes(style);
  27817. };
  27818. CharacterMetadata.applyStyle = function applyStyle(record, style) {
  27819. var withStyle = record.set('style', record.getStyle().add(style));
  27820. return CharacterMetadata.create(withStyle);
  27821. };
  27822. CharacterMetadata.removeStyle = function removeStyle(record, style) {
  27823. var withoutStyle = record.set('style', record.getStyle().remove(style));
  27824. return CharacterMetadata.create(withoutStyle);
  27825. };
  27826. CharacterMetadata.applyEntity = function applyEntity(record, entityKey) {
  27827. var withEntity = record.getEntity() === entityKey ? record : record.set('entity', entityKey);
  27828. return CharacterMetadata.create(withEntity);
  27829. };
  27830. /**
  27831. * Use this function instead of the `CharacterMetadata` constructor.
  27832. * Since most content generally uses only a very small number of
  27833. * style/entity permutations, we can reuse these objects as often as
  27834. * possible.
  27835. */
  27836. CharacterMetadata.create = function create(config) {
  27837. if (!config) {
  27838. return EMPTY;
  27839. }
  27840. var defaultConfig = {
  27841. style: EMPTY_SET,
  27842. entity: null
  27843. };
  27844. // Fill in unspecified properties, if necessary.
  27845. var configMap = Map(defaultConfig).merge(config);
  27846. var existing = pool.get(configMap);
  27847. if (existing) {
  27848. return existing;
  27849. }
  27850. var newCharacter = new CharacterMetadata(configMap);
  27851. pool = pool.set(configMap, newCharacter);
  27852. return newCharacter;
  27853. };
  27854. return CharacterMetadata;
  27855. }(CharacterMetadataRecord);
  27856. var EMPTY = new CharacterMetadata();
  27857. var pool = Map([[Map(defaultRecord), EMPTY]]);
  27858. CharacterMetadata.EMPTY = EMPTY;
  27859. module.exports = CharacterMetadata;
  27860. /***/ }),
  27861. /* 20 */
  27862. /***/ (function(module, exports, __webpack_require__) {
  27863. /**
  27864. * Copyright (c) 2013-present, Facebook, Inc.
  27865. * All rights reserved.
  27866. *
  27867. * This source code is licensed under the BSD-style license found in the
  27868. * LICENSE file in the root directory of this source tree. An additional grant
  27869. * of patent rights can be found in the PATENTS file in the same directory.
  27870. *
  27871. * @providesModule findRangesImmutable
  27872. * @format
  27873. *
  27874. */
  27875. /**
  27876. * Search through an array to find contiguous stretches of elements that
  27877. * match a specified filter function.
  27878. *
  27879. * When ranges are found, execute a specified `found` function to supply
  27880. * the values to the caller.
  27881. */
  27882. function findRangesImmutable(haystack, areEqualFn, filterFn, foundFn) {
  27883. if (!haystack.size) {
  27884. return;
  27885. }
  27886. var cursor = 0;
  27887. haystack.reduce(function (value, nextValue, nextIndex) {
  27888. if (!areEqualFn(value, nextValue)) {
  27889. if (filterFn(value)) {
  27890. foundFn(cursor, nextIndex);
  27891. }
  27892. cursor = nextIndex;
  27893. }
  27894. return nextValue;
  27895. });
  27896. filterFn(haystack.last()) && foundFn(cursor, haystack.count());
  27897. }
  27898. module.exports = findRangesImmutable;
  27899. /***/ }),
  27900. /* 21 */
  27901. /***/ (function(module, exports, __webpack_require__) {
  27902. var objectWithoutPropertiesLoose = __webpack_require__(25);
  27903. function _objectWithoutProperties(source, excluded) {
  27904. if (source == null) return {};
  27905. var target = objectWithoutPropertiesLoose(source, excluded);
  27906. var key, i;
  27907. if (Object.getOwnPropertySymbols) {
  27908. var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
  27909. for (i = 0; i < sourceSymbolKeys.length; i++) {
  27910. key = sourceSymbolKeys[i];
  27911. if (excluded.indexOf(key) >= 0) continue;
  27912. if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
  27913. target[key] = source[key];
  27914. }
  27915. }
  27916. return target;
  27917. }
  27918. module.exports = _objectWithoutProperties;
  27919. /***/ }),
  27920. /* 22 */
  27921. /***/ (function(module, exports, __webpack_require__) {
  27922. /**
  27923. * Copyright (c) 2013-present, Facebook, Inc.
  27924. * All rights reserved.
  27925. *
  27926. * This source code is licensed under the BSD-style license found in the
  27927. * LICENSE file in the root directory of this source tree. An additional grant
  27928. * of patent rights can be found in the PATENTS file in the same directory.
  27929. *
  27930. * @providesModule getFragmentFromSelection
  27931. * @format
  27932. *
  27933. */
  27934. var getContentStateFragment = __webpack_require__(30);
  27935. function getFragmentFromSelection(editorState) {
  27936. var selectionState = editorState.getSelection();
  27937. if (selectionState.isCollapsed()) {
  27938. return null;
  27939. }
  27940. return getContentStateFragment(editorState.getCurrentContent(), selectionState);
  27941. }
  27942. module.exports = getFragmentFromSelection;
  27943. /***/ }),
  27944. /* 23 */
  27945. /***/ (function(module, exports) {
  27946. module.exports = __WEBPACK_EXTERNAL_MODULE__23__;
  27947. /***/ }),
  27948. /* 24 */
  27949. /***/ (function(module, exports, __webpack_require__) {
  27950. var arrayWithHoles = __webpack_require__(36);
  27951. var iterableToArrayLimit = __webpack_require__(37);
  27952. var nonIterableRest = __webpack_require__(38);
  27953. function _slicedToArray(arr, i) {
  27954. return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || nonIterableRest();
  27955. }
  27956. module.exports = _slicedToArray;
  27957. /***/ }),
  27958. /* 25 */
  27959. /***/ (function(module, exports) {
  27960. function _objectWithoutPropertiesLoose(source, excluded) {
  27961. if (source == null) return {};
  27962. var target = {};
  27963. var sourceKeys = Object.keys(source);
  27964. var key, i;
  27965. for (i = 0; i < sourceKeys.length; i++) {
  27966. key = sourceKeys[i];
  27967. if (excluded.indexOf(key) >= 0) continue;
  27968. target[key] = source[key];
  27969. }
  27970. return target;
  27971. }
  27972. module.exports = _objectWithoutPropertiesLoose;
  27973. /***/ }),
  27974. /* 26 */
  27975. /***/ (function(module, exports) {
  27976. function _setPrototypeOf(o, p) {
  27977. module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  27978. o.__proto__ = p;
  27979. return o;
  27980. };
  27981. return _setPrototypeOf(o, p);
  27982. }
  27983. module.exports = _setPrototypeOf;
  27984. /***/ }),
  27985. /* 27 */
  27986. /***/ (function(module, exports) {
  27987. function _arrayWithoutHoles(arr) {
  27988. if (Array.isArray(arr)) {
  27989. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
  27990. arr2[i] = arr[i];
  27991. }
  27992. return arr2;
  27993. }
  27994. }
  27995. module.exports = _arrayWithoutHoles;
  27996. /***/ }),
  27997. /* 28 */
  27998. /***/ (function(module, exports) {
  27999. function _iterableToArray(iter) {
  28000. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  28001. }
  28002. module.exports = _iterableToArray;
  28003. /***/ }),
  28004. /* 29 */
  28005. /***/ (function(module, exports) {
  28006. function _nonIterableSpread() {
  28007. throw new TypeError("Invalid attempt to spread non-iterable instance");
  28008. }
  28009. module.exports = _nonIterableSpread;
  28010. /***/ }),
  28011. /* 30 */
  28012. /***/ (function(module, exports, __webpack_require__) {
  28013. /**
  28014. * Copyright (c) 2013-present, Facebook, Inc.
  28015. * All rights reserved.
  28016. *
  28017. * This source code is licensed under the BSD-style license found in the
  28018. * LICENSE file in the root directory of this source tree. An additional grant
  28019. * of patent rights can be found in the PATENTS file in the same directory.
  28020. *
  28021. * @providesModule getContentStateFragment
  28022. * @format
  28023. *
  28024. */
  28025. var randomizeBlockMapKeys = __webpack_require__(31);
  28026. var removeEntitiesAtEdges = __webpack_require__(34);
  28027. var getContentStateFragment = function getContentStateFragment(contentState, selectionState) {
  28028. var startKey = selectionState.getStartKey();
  28029. var startOffset = selectionState.getStartOffset();
  28030. var endKey = selectionState.getEndKey();
  28031. var endOffset = selectionState.getEndOffset();
  28032. // Edge entities should be stripped to ensure that we don't preserve
  28033. // invalid partial entities when the fragment is reused. We do, however,
  28034. // preserve entities that are entirely within the selection range.
  28035. var contentWithoutEdgeEntities = removeEntitiesAtEdges(contentState, selectionState);
  28036. var blockMap = contentWithoutEdgeEntities.getBlockMap();
  28037. var blockKeys = blockMap.keySeq();
  28038. var startIndex = blockKeys.indexOf(startKey);
  28039. var endIndex = blockKeys.indexOf(endKey) + 1;
  28040. return randomizeBlockMapKeys(blockMap.slice(startIndex, endIndex).map(function (block, blockKey) {
  28041. var text = block.getText();
  28042. var chars = block.getCharacterList();
  28043. if (startKey === endKey) {
  28044. return block.merge({
  28045. text: text.slice(startOffset, endOffset),
  28046. characterList: chars.slice(startOffset, endOffset)
  28047. });
  28048. }
  28049. if (blockKey === startKey) {
  28050. return block.merge({
  28051. text: text.slice(startOffset),
  28052. characterList: chars.slice(startOffset)
  28053. });
  28054. }
  28055. if (blockKey === endKey) {
  28056. return block.merge({
  28057. text: text.slice(0, endOffset),
  28058. characterList: chars.slice(0, endOffset)
  28059. });
  28060. }
  28061. return block;
  28062. }));
  28063. };
  28064. module.exports = getContentStateFragment;
  28065. /***/ }),
  28066. /* 31 */
  28067. /***/ (function(module, exports, __webpack_require__) {
  28068. /**
  28069. * Copyright (c) 2013-present, Facebook, Inc.
  28070. * All rights reserved.
  28071. *
  28072. * This source code is licensed under the BSD-style license found in the
  28073. * LICENSE file in the root directory of this source tree. An additional grant
  28074. * of patent rights can be found in the PATENTS file in the same directory.
  28075. *
  28076. * @providesModule randomizeBlockMapKeys
  28077. * @format
  28078. *
  28079. */
  28080. var ContentBlockNode = __webpack_require__(32);
  28081. var Immutable = __webpack_require__(13);
  28082. var generateRandomKey = __webpack_require__(33);
  28083. var OrderedMap = Immutable.OrderedMap;
  28084. var randomizeContentBlockNodeKeys = function randomizeContentBlockNodeKeys(blockMap) {
  28085. var newKeysRef = {};
  28086. // we keep track of root blocks in order to update subsequent sibling links
  28087. var lastRootBlock = void 0;
  28088. return OrderedMap(blockMap.withMutations(function (blockMapState) {
  28089. blockMapState.forEach(function (block, index) {
  28090. var oldKey = block.getKey();
  28091. var nextKey = block.getNextSiblingKey();
  28092. var prevKey = block.getPrevSiblingKey();
  28093. var childrenKeys = block.getChildKeys();
  28094. var parentKey = block.getParentKey();
  28095. // new key that we will use to build linking
  28096. var key = generateRandomKey();
  28097. // we will add it here to re-use it later
  28098. newKeysRef[oldKey] = key;
  28099. if (nextKey) {
  28100. var nextBlock = blockMapState.get(nextKey);
  28101. if (nextBlock) {
  28102. blockMapState.setIn([nextKey, 'prevSibling'], key);
  28103. } else {
  28104. // this can happen when generating random keys for fragments
  28105. blockMapState.setIn([oldKey, 'nextSibling'], null);
  28106. }
  28107. }
  28108. if (prevKey) {
  28109. var prevBlock = blockMapState.get(prevKey);
  28110. if (prevBlock) {
  28111. blockMapState.setIn([prevKey, 'nextSibling'], key);
  28112. } else {
  28113. // this can happen when generating random keys for fragments
  28114. blockMapState.setIn([oldKey, 'prevSibling'], null);
  28115. }
  28116. }
  28117. if (parentKey && blockMapState.get(parentKey)) {
  28118. var parentBlock = blockMapState.get(parentKey);
  28119. var parentChildrenList = parentBlock.getChildKeys();
  28120. blockMapState.setIn([parentKey, 'children'], parentChildrenList.set(parentChildrenList.indexOf(block.getKey()), key));
  28121. } else {
  28122. // blocks will then be treated as root block nodes
  28123. blockMapState.setIn([oldKey, 'parent'], null);
  28124. if (lastRootBlock) {
  28125. blockMapState.setIn([lastRootBlock.getKey(), 'nextSibling'], key);
  28126. blockMapState.setIn([oldKey, 'prevSibling'], newKeysRef[lastRootBlock.getKey()]);
  28127. }
  28128. lastRootBlock = blockMapState.get(oldKey);
  28129. }
  28130. childrenKeys.forEach(function (childKey) {
  28131. var childBlock = blockMapState.get(childKey);
  28132. if (childBlock) {
  28133. blockMapState.setIn([childKey, 'parent'], key);
  28134. } else {
  28135. blockMapState.setIn([oldKey, 'children'], block.getChildKeys().filter(function (child) {
  28136. return child !== childKey;
  28137. }));
  28138. }
  28139. });
  28140. });
  28141. }).toArray().map(function (block) {
  28142. return [newKeysRef[block.getKey()], block.set('key', newKeysRef[block.getKey()])];
  28143. }));
  28144. };
  28145. var randomizeContentBlockKeys = function randomizeContentBlockKeys(blockMap) {
  28146. return OrderedMap(blockMap.toArray().map(function (block) {
  28147. var key = generateRandomKey();
  28148. return [key, block.set('key', key)];
  28149. }));
  28150. };
  28151. var randomizeBlockMapKeys = function randomizeBlockMapKeys(blockMap) {
  28152. var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode;
  28153. if (!isTreeBasedBlockMap) {
  28154. return randomizeContentBlockKeys(blockMap);
  28155. }
  28156. return randomizeContentBlockNodeKeys(blockMap);
  28157. };
  28158. module.exports = randomizeBlockMapKeys;
  28159. /***/ }),
  28160. /* 32 */
  28161. /***/ (function(module, exports, __webpack_require__) {
  28162. /**
  28163. * Copyright (c) 2013-present, Facebook, Inc.
  28164. * All rights reserved.
  28165. *
  28166. * This source code is licensed under the BSD-style license found in the
  28167. * LICENSE file in the root directory of this source tree. An additional grant
  28168. * of patent rights can be found in the PATENTS file in the same directory.
  28169. *
  28170. * @providesModule ContentBlockNode
  28171. * @format
  28172. *
  28173. *
  28174. * This file is a fork of ContentBlock adding support for nesting references by
  28175. * providing links to children, parent, prevSibling, and nextSibling.
  28176. *
  28177. * This is unstable and not part of the public API and should not be used by
  28178. * production systems. This file may be update/removed without notice.
  28179. */
  28180. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  28181. 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; }
  28182. 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; }
  28183. var CharacterMetadata = __webpack_require__(19);
  28184. var Immutable = __webpack_require__(13);
  28185. var findRangesImmutable = __webpack_require__(20);
  28186. var List = Immutable.List,
  28187. Map = Immutable.Map,
  28188. OrderedSet = Immutable.OrderedSet,
  28189. Record = Immutable.Record,
  28190. Repeat = Immutable.Repeat;
  28191. var EMPTY_SET = OrderedSet();
  28192. var defaultRecord = {
  28193. parent: null,
  28194. characterList: List(),
  28195. data: Map(),
  28196. depth: 0,
  28197. key: '',
  28198. text: '',
  28199. type: 'unstyled',
  28200. children: List(),
  28201. prevSibling: null,
  28202. nextSibling: null
  28203. };
  28204. var haveEqualStyle = function haveEqualStyle(charA, charB) {
  28205. return charA.getStyle() === charB.getStyle();
  28206. };
  28207. var haveEqualEntity = function haveEqualEntity(charA, charB) {
  28208. return charA.getEntity() === charB.getEntity();
  28209. };
  28210. var decorateCharacterList = function decorateCharacterList(config) {
  28211. if (!config) {
  28212. return config;
  28213. }
  28214. var characterList = config.characterList,
  28215. text = config.text;
  28216. if (text && !characterList) {
  28217. config.characterList = List(Repeat(CharacterMetadata.EMPTY, text.length));
  28218. }
  28219. return config;
  28220. };
  28221. var ContentBlockNode = function (_Record) {
  28222. _inherits(ContentBlockNode, _Record);
  28223. function ContentBlockNode() {
  28224. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultRecord;
  28225. _classCallCheck(this, ContentBlockNode);
  28226. return _possibleConstructorReturn(this, _Record.call(this, decorateCharacterList(props)));
  28227. }
  28228. ContentBlockNode.prototype.getKey = function getKey() {
  28229. return this.get('key');
  28230. };
  28231. ContentBlockNode.prototype.getType = function getType() {
  28232. return this.get('type');
  28233. };
  28234. ContentBlockNode.prototype.getText = function getText() {
  28235. return this.get('text');
  28236. };
  28237. ContentBlockNode.prototype.getCharacterList = function getCharacterList() {
  28238. return this.get('characterList');
  28239. };
  28240. ContentBlockNode.prototype.getLength = function getLength() {
  28241. return this.getText().length;
  28242. };
  28243. ContentBlockNode.prototype.getDepth = function getDepth() {
  28244. return this.get('depth');
  28245. };
  28246. ContentBlockNode.prototype.getData = function getData() {
  28247. return this.get('data');
  28248. };
  28249. ContentBlockNode.prototype.getInlineStyleAt = function getInlineStyleAt(offset) {
  28250. var character = this.getCharacterList().get(offset);
  28251. return character ? character.getStyle() : EMPTY_SET;
  28252. };
  28253. ContentBlockNode.prototype.getEntityAt = function getEntityAt(offset) {
  28254. var character = this.getCharacterList().get(offset);
  28255. return character ? character.getEntity() : null;
  28256. };
  28257. ContentBlockNode.prototype.getChildKeys = function getChildKeys() {
  28258. return this.get('children');
  28259. };
  28260. ContentBlockNode.prototype.getParentKey = function getParentKey() {
  28261. return this.get('parent');
  28262. };
  28263. ContentBlockNode.prototype.getPrevSiblingKey = function getPrevSiblingKey() {
  28264. return this.get('prevSibling');
  28265. };
  28266. ContentBlockNode.prototype.getNextSiblingKey = function getNextSiblingKey() {
  28267. return this.get('nextSibling');
  28268. };
  28269. ContentBlockNode.prototype.findStyleRanges = function findStyleRanges(filterFn, callback) {
  28270. findRangesImmutable(this.getCharacterList(), haveEqualStyle, filterFn, callback);
  28271. };
  28272. ContentBlockNode.prototype.findEntityRanges = function findEntityRanges(filterFn, callback) {
  28273. findRangesImmutable(this.getCharacterList(), haveEqualEntity, filterFn, callback);
  28274. };
  28275. return ContentBlockNode;
  28276. }(Record(defaultRecord));
  28277. module.exports = ContentBlockNode;
  28278. /***/ }),
  28279. /* 33 */
  28280. /***/ (function(module, exports, __webpack_require__) {
  28281. /**
  28282. * Copyright (c) 2013-present, Facebook, Inc.
  28283. * All rights reserved.
  28284. *
  28285. * This source code is licensed under the BSD-style license found in the
  28286. * LICENSE file in the root directory of this source tree. An additional grant
  28287. * of patent rights can be found in the PATENTS file in the same directory.
  28288. *
  28289. * @providesModule generateRandomKey
  28290. * @format
  28291. *
  28292. */
  28293. var seenKeys = {};
  28294. var MULTIPLIER = Math.pow(2, 24);
  28295. function generateRandomKey() {
  28296. var key = void 0;
  28297. while (key === undefined || seenKeys.hasOwnProperty(key) || !isNaN(+key)) {
  28298. key = Math.floor(Math.random() * MULTIPLIER).toString(32);
  28299. }
  28300. seenKeys[key] = true;
  28301. return key;
  28302. }
  28303. module.exports = generateRandomKey;
  28304. /***/ }),
  28305. /* 34 */
  28306. /***/ (function(module, exports, __webpack_require__) {
  28307. /**
  28308. * Copyright (c) 2013-present, Facebook, Inc.
  28309. * All rights reserved.
  28310. *
  28311. * This source code is licensed under the BSD-style license found in the
  28312. * LICENSE file in the root directory of this source tree. An additional grant
  28313. * of patent rights can be found in the PATENTS file in the same directory.
  28314. *
  28315. * @providesModule removeEntitiesAtEdges
  28316. * @format
  28317. *
  28318. */
  28319. var CharacterMetadata = __webpack_require__(19);
  28320. var findRangesImmutable = __webpack_require__(20);
  28321. var invariant = __webpack_require__(35);
  28322. function removeEntitiesAtEdges(contentState, selectionState) {
  28323. var blockMap = contentState.getBlockMap();
  28324. var entityMap = contentState.getEntityMap();
  28325. var updatedBlocks = {};
  28326. var startKey = selectionState.getStartKey();
  28327. var startOffset = selectionState.getStartOffset();
  28328. var startBlock = blockMap.get(startKey);
  28329. var updatedStart = removeForBlock(entityMap, startBlock, startOffset);
  28330. if (updatedStart !== startBlock) {
  28331. updatedBlocks[startKey] = updatedStart;
  28332. }
  28333. var endKey = selectionState.getEndKey();
  28334. var endOffset = selectionState.getEndOffset();
  28335. var endBlock = blockMap.get(endKey);
  28336. if (startKey === endKey) {
  28337. endBlock = updatedStart;
  28338. }
  28339. var updatedEnd = removeForBlock(entityMap, endBlock, endOffset);
  28340. if (updatedEnd !== endBlock) {
  28341. updatedBlocks[endKey] = updatedEnd;
  28342. }
  28343. if (!Object.keys(updatedBlocks).length) {
  28344. return contentState.set('selectionAfter', selectionState);
  28345. }
  28346. return contentState.merge({
  28347. blockMap: blockMap.merge(updatedBlocks),
  28348. selectionAfter: selectionState
  28349. });
  28350. }
  28351. function getRemovalRange(characters, key, offset) {
  28352. var removalRange;
  28353. findRangesImmutable(characters, function (a, b) {
  28354. return a.getEntity() === b.getEntity();
  28355. }, function (element) {
  28356. return element.getEntity() === key;
  28357. }, function (start, end) {
  28358. if (start <= offset && end >= offset) {
  28359. removalRange = { start: start, end: end };
  28360. }
  28361. });
  28362. !(typeof removalRange === 'object') ? invariant(false) : void 0;
  28363. return removalRange;
  28364. }
  28365. function removeForBlock(entityMap, block, offset) {
  28366. var chars = block.getCharacterList();
  28367. var charBefore = offset > 0 ? chars.get(offset - 1) : undefined;
  28368. var charAfter = offset < chars.count() ? chars.get(offset) : undefined;
  28369. var entityBeforeCursor = charBefore ? charBefore.getEntity() : undefined;
  28370. var entityAfterCursor = charAfter ? charAfter.getEntity() : undefined;
  28371. if (entityAfterCursor && entityAfterCursor === entityBeforeCursor) {
  28372. var entity = entityMap.__get(entityAfterCursor);
  28373. if (entity.getMutability() !== 'MUTABLE') {
  28374. var _getRemovalRange = getRemovalRange(chars, entityAfterCursor, offset),
  28375. start = _getRemovalRange.start,
  28376. end = _getRemovalRange.end;
  28377. var current;
  28378. while (start < end) {
  28379. current = chars.get(start);
  28380. chars = chars.set(start, CharacterMetadata.applyEntity(current, null));
  28381. start++;
  28382. }
  28383. return block.set('characterList', chars);
  28384. }
  28385. }
  28386. return block;
  28387. }
  28388. module.exports = removeEntitiesAtEdges;
  28389. /***/ }),
  28390. /* 35 */
  28391. /***/ (function(module, exports, __webpack_require__) {
  28392. function invariant(condition, format, a, b, c, d, e, f) {
  28393. if (!condition) {
  28394. var error;
  28395. if (format === undefined) {
  28396. error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
  28397. } else {
  28398. var args = [a, b, c, d, e, f];
  28399. var argIndex = 0;
  28400. error = new Error(format.replace(/%s/g, function () {
  28401. return args[argIndex++];
  28402. }));
  28403. error.name = 'Invariant Violation';
  28404. }
  28405. error.framesToPop = 1; // we don't care about invariant's own frame
  28406. throw error;
  28407. }
  28408. }
  28409. module.exports = invariant;
  28410. /***/ }),
  28411. /* 36 */
  28412. /***/ (function(module, exports) {
  28413. function _arrayWithHoles(arr) {
  28414. if (Array.isArray(arr)) return arr;
  28415. }
  28416. module.exports = _arrayWithHoles;
  28417. /***/ }),
  28418. /* 37 */
  28419. /***/ (function(module, exports) {
  28420. function _iterableToArrayLimit(arr, i) {
  28421. var _arr = [];
  28422. var _n = true;
  28423. var _d = false;
  28424. var _e = undefined;
  28425. try {
  28426. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  28427. _arr.push(_s.value);
  28428. if (i && _arr.length === i) break;
  28429. }
  28430. } catch (err) {
  28431. _d = true;
  28432. _e = err;
  28433. } finally {
  28434. try {
  28435. if (!_n && _i["return"] != null) _i["return"]();
  28436. } finally {
  28437. if (_d) throw _e;
  28438. }
  28439. }
  28440. return _arr;
  28441. }
  28442. module.exports = _iterableToArrayLimit;
  28443. /***/ }),
  28444. /* 38 */
  28445. /***/ (function(module, exports) {
  28446. function _nonIterableRest() {
  28447. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  28448. }
  28449. module.exports = _nonIterableRest;
  28450. /***/ }),
  28451. /* 39 */
  28452. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  28453. __webpack_require__.r(__webpack_exports__);
  28454. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/typeof.js
  28455. var helpers_typeof = __webpack_require__(15);
  28456. var typeof_default = /*#__PURE__*/__webpack_require__.n(helpers_typeof);
  28457. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/objectSpread.js
  28458. var objectSpread = __webpack_require__(5);
  28459. var objectSpread_default = /*#__PURE__*/__webpack_require__.n(objectSpread);
  28460. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/objectWithoutProperties.js
  28461. var objectWithoutProperties = __webpack_require__(21);
  28462. var objectWithoutProperties_default = /*#__PURE__*/__webpack_require__.n(objectWithoutProperties);
  28463. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/classCallCheck.js
  28464. var classCallCheck = __webpack_require__(4);
  28465. var classCallCheck_default = /*#__PURE__*/__webpack_require__.n(classCallCheck);
  28466. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/createClass.js
  28467. var createClass = __webpack_require__(7);
  28468. var createClass_default = /*#__PURE__*/__webpack_require__.n(createClass);
  28469. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js
  28470. var possibleConstructorReturn = __webpack_require__(8);
  28471. var possibleConstructorReturn_default = /*#__PURE__*/__webpack_require__.n(possibleConstructorReturn);
  28472. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/getPrototypeOf.js
  28473. var getPrototypeOf = __webpack_require__(9);
  28474. var getPrototypeOf_default = /*#__PURE__*/__webpack_require__.n(getPrototypeOf);
  28475. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/inherits.js
  28476. var inherits = __webpack_require__(10);
  28477. var inherits_default = /*#__PURE__*/__webpack_require__.n(inherits);
  28478. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/assertThisInitialized.js
  28479. var assertThisInitialized = __webpack_require__(1);
  28480. var assertThisInitialized_default = /*#__PURE__*/__webpack_require__.n(assertThisInitialized);
  28481. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/defineProperty.js
  28482. var defineProperty = __webpack_require__(2);
  28483. var defineProperty_default = /*#__PURE__*/__webpack_require__.n(defineProperty);
  28484. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/toConsumableArray.js
  28485. var toConsumableArray = __webpack_require__(12);
  28486. var toConsumableArray_default = /*#__PURE__*/__webpack_require__.n(toConsumableArray);
  28487. // EXTERNAL MODULE: ../node_modules/draft-js/dist/Draft.css
  28488. var Draft = __webpack_require__(40);
  28489. // EXTERNAL MODULE: ./assets/scss/_base.scss
  28490. var _base = __webpack_require__(42);
  28491. // EXTERNAL MODULE: external "react"
  28492. var external_react_ = __webpack_require__(0);
  28493. var external_react_default = /*#__PURE__*/__webpack_require__.n(external_react_);
  28494. // CONCATENATED MODULE: ./languages/en.js
  28495. /* harmony default export */ var en = ({
  28496. base: {
  28497. remove: 'Remove',
  28498. cancel: 'Cancel',
  28499. confirm: 'Confirm',
  28500. inert: 'Insert',
  28501. width: 'Width',
  28502. height: 'Height'
  28503. },
  28504. controls: {
  28505. clear: 'Clear',
  28506. undo: 'Undo',
  28507. redo: 'Redo',
  28508. fontSize: 'Font Size',
  28509. color: 'Color',
  28510. textColor: 'Text',
  28511. tempColors: 'Temp Colors',
  28512. backgroundColor: 'Background',
  28513. bold: 'Bold',
  28514. lineHeight: 'Line Height',
  28515. letterSpacing: 'Letter Spacing',
  28516. textIndent: 'Text Indent',
  28517. increaseIndent: 'Increase Indent',
  28518. decreaseIndent: 'Decrease Indent',
  28519. italic: 'Italic',
  28520. underline: 'Underline',
  28521. strikeThrough: 'Strike Through',
  28522. fontFamily: 'Font Family',
  28523. textAlign: 'Text Alignment',
  28524. alignLeft: 'Left Alignment',
  28525. alignCenter: 'Center Alignment',
  28526. alignRight: 'Right Alignment',
  28527. alignJustify: 'Justify Alignment',
  28528. floatLeft: 'Left Float',
  28529. floatRight: 'Right Float',
  28530. superScript: 'Super Script',
  28531. subScript: 'Sub Script',
  28532. removeStyles: 'Remove Styles',
  28533. headings: 'Headings',
  28534. header: 'Header',
  28535. normal: 'Normal',
  28536. orderedList: 'Ordered List',
  28537. unorderedList: 'Unordered List',
  28538. blockQuote: 'Quote',
  28539. code: 'Code',
  28540. link: 'Link',
  28541. unlink: 'Unlink',
  28542. hr: 'Horizontal Line',
  28543. media: 'Media',
  28544. mediaLibirary: 'Media Library',
  28545. emoji: 'Emoji',
  28546. fullscreen: 'Fullscreen',
  28547. exitFullscreen: 'Exit Fullscreen'
  28548. },
  28549. linkEditor: {
  28550. textInputPlaceHolder: 'Input link text',
  28551. linkInputPlaceHolder: 'Input link URL',
  28552. inputWithEnterPlaceHolder: 'Input link URL and press Enter',
  28553. openInNewWindow: 'Open in new window',
  28554. removeLink: 'Remove Link'
  28555. },
  28556. audioPlayer: {
  28557. title: 'Play Audio'
  28558. },
  28559. videoPlayer: {
  28560. title: 'Play Video',
  28561. embedTitle: 'Embed Media'
  28562. },
  28563. media: {
  28564. image: 'Image',
  28565. video: 'Video',
  28566. audio: 'Audio',
  28567. embed: 'Embed'
  28568. }
  28569. });
  28570. // CONCATENATED MODULE: ./languages/zh.js
  28571. /* harmony default export */ var zh = ({
  28572. base: {
  28573. remove: '删除',
  28574. cancel: '取消',
  28575. confirm: '确定',
  28576. inert: '插入',
  28577. width: '宽度',
  28578. height: '高度'
  28579. },
  28580. controls: {
  28581. clear: '清除内容',
  28582. undo: '撤销',
  28583. redo: '重做',
  28584. fontSize: '字号',
  28585. lineHeight: '行高',
  28586. letterSpacing: '字间距',
  28587. textIndent: '段落缩进',
  28588. increaseIndent: '增加缩进',
  28589. decreaseIndent: '减少缩进',
  28590. border: '边框',
  28591. color: '颜色',
  28592. textColor: '文字颜色',
  28593. backgroundColor: '背景颜色',
  28594. tempColors: '临时颜色',
  28595. bold: '加粗',
  28596. italic: '斜体',
  28597. underline: '下划线',
  28598. strikeThrough: '删除线',
  28599. fontFamily: '字体',
  28600. textAlign: '文本对齐',
  28601. alignLeft: '居左',
  28602. alignCenter: '居中',
  28603. alignRight: '居右',
  28604. alignJustify: '两端',
  28605. floatLeft: '左浮动',
  28606. floatRight: '右浮动',
  28607. superScript: '上标',
  28608. subScript: '下标',
  28609. removeStyles: '清除样式',
  28610. headings: '标题',
  28611. header: '标题',
  28612. normal: '常规',
  28613. orderedList: '有序列表',
  28614. unorderedList: '无序列表',
  28615. blockQuote: '引用',
  28616. code: '代码',
  28617. link: '链接',
  28618. unlink: '清除链接',
  28619. hr: '水平线',
  28620. media: '媒体',
  28621. mediaLibirary: '媒体库',
  28622. emoji: '小表情',
  28623. fullscreen: '全屏',
  28624. exitFullscreen: '退出全屏'
  28625. },
  28626. linkEditor: {
  28627. textInputPlaceHolder: '输入链接文字',
  28628. linkInputPlaceHolder: '输入链接地址',
  28629. inputWithEnterPlaceHolder: '输入链接地址并回车',
  28630. openInNewWindow: '在新窗口打开',
  28631. removeLink: '移除链接'
  28632. },
  28633. audioPlayer: {
  28634. title: '播放音频文件'
  28635. },
  28636. videoPlayer: {
  28637. title: '播放视频文件',
  28638. embedTitle: '嵌入式媒体'
  28639. },
  28640. media: {
  28641. image: '图像',
  28642. video: '视频',
  28643. audio: '音频',
  28644. embed: '嵌入式媒体'
  28645. }
  28646. });
  28647. // CONCATENATED MODULE: ./languages/zh-hant.js
  28648. /* harmony default export */ var zh_hant = ({
  28649. base: {
  28650. remove: '刪除',
  28651. cancel: '取消',
  28652. confirm: '確定',
  28653. inert: '插入',
  28654. width: '宽度',
  28655. height: '高度'
  28656. },
  28657. controls: {
  28658. clear: '清除内容',
  28659. undo: '撤銷',
  28660. redo: '重做',
  28661. fontSize: '字號',
  28662. color: '顏色',
  28663. textColor: '文字顏色',
  28664. backgroundColor: '背景顏色',
  28665. tempColors: '臨時顏色',
  28666. bold: '加粗',
  28667. lineHeight: '行高',
  28668. letterSpacing: '字間距',
  28669. textIndent: '段落縮進',
  28670. increaseIndent: '增加縮進',
  28671. decreaseIndent: '减少縮進',
  28672. border: '邊框',
  28673. italic: '斜體',
  28674. underline: '下劃線',
  28675. strikeThrough: '刪除線',
  28676. fontFamily: '字體',
  28677. textAlign: '文本對齊',
  28678. alignLeft: '居左',
  28679. alignCenter: '居中',
  28680. alignRight: '居右',
  28681. alignJustify: '兩端對齊',
  28682. floatLeft: '左浮動',
  28683. floatRight: '右浮動',
  28684. superScript: '上標',
  28685. subScript: '下標',
  28686. removeStyles: '清除样式',
  28687. headings: '標題',
  28688. header: '標題',
  28689. normal: '常規',
  28690. orderedList: '有序列表',
  28691. unorderedList: '無序列表',
  28692. blockQuote: '引用',
  28693. code: '代碼',
  28694. link: '鏈接',
  28695. unlink: '清除鏈接',
  28696. hr: '水平线',
  28697. media: '媒體',
  28698. mediaLibirary: '媒體库',
  28699. emoji: '小表情',
  28700. fullscreen: '全熒幕',
  28701. exitFullscreen: '退出全熒幕'
  28702. },
  28703. linkEditor: {
  28704. textInputPlaceHolder: '輸入鏈接文字',
  28705. linkInputPlaceHolder: '輸入鏈接地址',
  28706. inputWithEnterPlaceHolder: '輸入鏈接地址並回車',
  28707. openInNewWindow: '在新窗口打開',
  28708. removeLink: '移除鏈接'
  28709. },
  28710. audioPlayer: {
  28711. title: '播放音頻文件'
  28712. },
  28713. videoPlayer: {
  28714. title: '播放視頻文件',
  28715. embedTitle: '嵌入式媒體'
  28716. },
  28717. media: {
  28718. image: '圖像',
  28719. video: '視頻',
  28720. audio: '音頻',
  28721. embed: '嵌入式媒體'
  28722. }
  28723. });
  28724. // CONCATENATED MODULE: ./languages/pl.js
  28725. /* harmony default export */ var pl = ({
  28726. base: {
  28727. remove: 'Usuń',
  28728. cancel: 'Anuluj',
  28729. confirm: 'Potwierdź',
  28730. inert: 'Wstaw',
  28731. width: 'Szerokość',
  28732. height: 'Wysokość'
  28733. },
  28734. controls: {
  28735. clear: 'Wyczyść',
  28736. undo: 'Cofnij',
  28737. redo: 'Przywróć',
  28738. fontSize: 'Wielkość',
  28739. color: 'Kolor',
  28740. textColor: 'Kolor tekstu',
  28741. tempColors: 'Kolory',
  28742. backgroundColor: 'Tło',
  28743. bold: 'Pogrubienie',
  28744. lineHeight: 'Wysokość linii',
  28745. letterSpacing: 'Odstęp znaków',
  28746. textIndent: 'Wcięcie tekstu',
  28747. increaseIndent: 'Zwiększ wcięcie',
  28748. decreaseIndent: 'Zmniejsz wcięcie',
  28749. italic: 'Italiki',
  28750. underline: 'Podkreślenie',
  28751. strikeThrough: 'Przekreślenie',
  28752. fontFamily: 'Czcionka',
  28753. textAlign: 'Wyrównanie tekstu',
  28754. alignLeft: 'Do lewej',
  28755. alignCenter: 'Wycentruj',
  28756. alignRight: 'Do prawej',
  28757. alignJustify: 'Wyjustuj',
  28758. floatLeft: 'Do lewej',
  28759. floatRight: 'Do prawej',
  28760. superScript: 'Superskrypt',
  28761. subScript: 'Subskrypt',
  28762. removeStyles: 'Usuń stylowanie',
  28763. headings: 'Nagłówki',
  28764. header: 'Nagłówek',
  28765. normal: 'Normalny',
  28766. orderedList: 'Lista uporządkowana',
  28767. unorderedList: 'Lista nieuporządkowana',
  28768. blockQuote: 'Cytat',
  28769. code: 'Kod',
  28770. link: 'Link',
  28771. unlink: 'Usuń link',
  28772. hr: 'Linia pozioma',
  28773. media: 'Media',
  28774. mediaLibirary: 'Biblioteka mediów',
  28775. emoji: 'Emoji'
  28776. },
  28777. linkEditor: {
  28778. textInputPlaceHolder: 'Wpisz tekst linku',
  28779. linkInputPlaceHolder: 'Wpisz Adres URL',
  28780. inputWithEnterPlaceHolder: 'Wpisz adres URL i naciśnij Enter',
  28781. openInNewWindow: 'Otwórz w nowym oknie',
  28782. removeLink: 'Usuń link'
  28783. },
  28784. audioPlayer: {
  28785. title: 'Odtwórz audio'
  28786. },
  28787. videoPlayer: {
  28788. title: 'Odtwórz wideo',
  28789. embedTitle: 'Tytuł'
  28790. },
  28791. media: {
  28792. image: 'Obraz',
  28793. video: 'Wideo',
  28794. audio: 'Audio',
  28795. embed: 'Obiekt osadzony'
  28796. }
  28797. });
  28798. // CONCATENATED MODULE: ./languages/kr.js
  28799. /* harmony default export */ var kr = ({
  28800. base: {
  28801. remove: '삭제',
  28802. cancel: '취소',
  28803. confirm: '결정',
  28804. inert: '삽입',
  28805. width: '너비',
  28806. height: '높이'
  28807. },
  28808. controls: {
  28809. clear: '콘텐츠지우기',
  28810. undo: '취소',
  28811. redo: '다시하기',
  28812. fontSize: '글자크기',
  28813. lineHeight: '행높이',
  28814. letterSpacing: '단어간격',
  28815. textIndent: '단락들여쓰기',
  28816. increaseIndent: '들여쓰기늘리기',
  28817. decreaseIndent: '들여쓰기줄이기',
  28818. border: '국경',
  28819. color: '색상',
  28820. textColor: '텍스트색상',
  28821. backgroundColor: '배경색상',
  28822. tempColors: '임시색',
  28823. bold: '굵게',
  28824. italic: '기울임꼴',
  28825. underline: '밑줄',
  28826. strikeThrough: '취소선',
  28827. fontFamily: '글꼴',
  28828. textAlign: '텍스트정렬',
  28829. alignLeft: '왼쪽',
  28830. alignCenter: '중심',
  28831. alignRight: '오른쪽',
  28832. alignJustify: '양쪽끝',
  28833. floatLeft: '떠다니기',
  28834. floatRight: '오른쪽부동',
  28835. superScript: '위첨자',
  28836. subScript: '첨자',
  28837. removeStyles: '스타일지우기',
  28838. headings: '제목',
  28839. header: '제목',
  28840. normal: '재래식',
  28841. orderedList: '순서가지정된목록',
  28842. unorderedList: '정렬되지않은목록',
  28843. blockQuote: '참고문헌',
  28844. code: '코드',
  28845. link: '링크',
  28846. unlink: '링크삭제',
  28847. hr: '수평선',
  28848. media: '미디어',
  28849. mediaLibirary: '미디어라이브러리',
  28850. emoji: '작은표현',
  28851. fullscreen: '전체화면',
  28852. exitFullscreen: '전체화면종료'
  28853. },
  28854. linkEditor: {
  28855. textInputPlaceHolder: '링크텍스트입력',
  28856. linkInputPlaceHolder: '링크주소입력',
  28857. inputWithEnterPlaceHolder: '링크주소입력.',
  28858. openInNewWindow: '새창열기',
  28859. removeLink: '링크삭제'
  28860. },
  28861. audioPlayer: {
  28862. title: '오디오파일재생'
  28863. },
  28864. videoPlayer: {
  28865. title: '비디오파일재생',
  28866. embedTitle: '임베디드미디어'
  28867. },
  28868. media: {
  28869. image: '이미지',
  28870. video: '비디오',
  28871. audio: '오디오',
  28872. embed: '임베디드미디어'
  28873. }
  28874. });
  28875. // CONCATENATED MODULE: ./languages/tr.js
  28876. /* harmony default export */ var tr = ({
  28877. base: {
  28878. remove: 'Kaldır',
  28879. cancel: 'İptal',
  28880. confirm: 'Onayla',
  28881. inert: 'Ekle',
  28882. width: 'Genişlik',
  28883. height: 'Yükseklik'
  28884. },
  28885. controls: {
  28886. clear: 'Temizle',
  28887. undo: 'Geri al',
  28888. redo: 'İleri al',
  28889. fontSize: 'Yazı boyutu',
  28890. color: 'Renk',
  28891. textColor: 'Yazı rengi',
  28892. tempColors: 'Geçici renkler',
  28893. backgroundColor: 'Arkaplan',
  28894. bold: 'Kalın',
  28895. lineHeight: 'Satır yüksekliği',
  28896. letterSpacing: 'Harf aralığı',
  28897. textIndent: 'Çentik aralığı',
  28898. increaseIndent: 'Çentiği genişlet',
  28899. decreaseIndent: 'Çentiği daralt',
  28900. italic: 'Eğik',
  28901. underline: 'Altı çizili',
  28902. strikeThrough: 'Üstü çizili',
  28903. fontFamily: 'Yazı tipi',
  28904. textAlign: 'Metin Hizalama',
  28905. alignLeft: 'Sola hizala',
  28906. alignCenter: 'Ortaya hizala',
  28907. alignRight: 'Sağa hizala',
  28908. alignJustify: 'Her iki tarafa hizala',
  28909. floatLeft: 'Sola yatır',
  28910. floatRight: 'Sağa yatır',
  28911. superScript: 'Ana kod',
  28912. subScript: 'Alt kod',
  28913. removeStyles: 'Stilleri kaldır',
  28914. headings: 'Başlıklar',
  28915. header: 'Başlık',
  28916. normal: 'Normal',
  28917. orderedList: 'Sıralı liste',
  28918. unorderedList: 'Sırasız liste',
  28919. blockQuote: 'Alıntı',
  28920. code: 'Kod',
  28921. link: 'Bağlantı',
  28922. unlink: 'Bağlantıyı kaldır',
  28923. hr: 'Yatay çizgi',
  28924. media: 'Medya',
  28925. mediaLibirary: 'Kütüphane',
  28926. emoji: 'İfade',
  28927. fullscreen: 'Tam ekran',
  28928. exitFullscreen: 'Tam ekrandan çık'
  28929. },
  28930. linkEditor: {
  28931. textInputPlaceHolder: 'Bağlantı metnini girin',
  28932. linkInputPlaceHolder: 'Bağlantı URL\' si girin',
  28933. inputWithEnterPlaceHolder: 'Bağlantı URL\'si girin ve Enter\' a basın',
  28934. openInNewWindow: 'Yeni pencerede aç',
  28935. removeLink: 'Bağlantıyı kaldır'
  28936. },
  28937. audioPlayer: {
  28938. title: 'Ses çal'
  28939. },
  28940. videoPlayer: {
  28941. title: 'Görüntü oynat',
  28942. embedTitle: 'Görüntüyü göm'
  28943. },
  28944. media: {
  28945. image: 'Resim',
  28946. video: 'Görüntü',
  28947. audio: 'Ses',
  28948. embed: 'Gömülü nesne'
  28949. }
  28950. });
  28951. // CONCATENATED MODULE: ./languages/jpn.js
  28952. /* harmony default export */ var jpn = ({
  28953. base: {
  28954. remove: '削除',
  28955. cancel: 'キャンセル',
  28956. confirm: '決定',
  28957. inert: '挿入',
  28958. width: '幅',
  28959. height: '高さ'
  28960. },
  28961. controls: {
  28962. clear: 'クリアコンテンツ',
  28963. undo: 'キャンセル',
  28964. redo: 'キャンセル',
  28965. fontSize: 'フォントサイズ',
  28966. lineHeight: 'フォントサイズ',
  28967. letterSpacing: 'ワード間隔',
  28968. textIndent: '段落のインデント',
  28969. increaseIndent: 'インデントを増やす',
  28970. decreaseIndent: 'インデントを減らす',
  28971. border: '国境',
  28972. color: '色',
  28973. textColor: 'テキストの色',
  28974. backgroundColor: '背景色',
  28975. tempColors: '仮色',
  28976. bold: '太字',
  28977. italic: 'イタリック体',
  28978. underline: '下線',
  28979. strikeThrough: '取り消し線',
  28980. fontFamily: 'フォント',
  28981. textAlign: 'テキストの配置',
  28982. alignLeft: '左',
  28983. alignCenter: '中央揃え',
  28984. alignRight: '右に立つ',
  28985. alignJustify: '両端',
  28986. floatLeft: '左フローティング',
  28987. floatRight: '右フローティング',
  28988. superScript: '上付き',
  28989. subScript: '下付き文字',
  28990. removeStyles: 'クリアスタイル',
  28991. headings: '役職',
  28992. header: '役職',
  28993. normal: '従来の',
  28994. orderedList: '順序付きリスト',
  28995. unorderedList: '番号なしリスト',
  28996. blockQuote: '参照',
  28997. code: 'コード',
  28998. link: 'リンク',
  28999. unlink: 'リンクを解除',
  29000. hr: '横線',
  29001. media: 'メディア',
  29002. mediaLibirary: 'メディアライブラリー',
  29003. emoji: '小さな表現',
  29004. fullscreen: '全画面',
  29005. exitFullscreen: '全画面を退く'
  29006. },
  29007. linkEditor: {
  29008. textInputPlaceHolder: 'リンクテキストを入力',
  29009. linkInputPlaceHolder: 'リンクアドレスを入力',
  29010. inputWithEnterPlaceHolder: 'リンクアドレスを入力して戻ります',
  29011. openInNewWindow: '新しいウィンドウで開く',
  29012. removeLink: '新しいウィンドウで開く'
  29013. },
  29014. audioPlayer: {
  29015. title: 'オーディオファイルを再生する'
  29016. },
  29017. videoPlayer: {
  29018. title: 'ビデオファイルを再生する',
  29019. embedTitle: '埋め込みメディア'
  29020. },
  29021. media: {
  29022. image: '画像',
  29023. video: 'ビデオ',
  29024. audio: '音声',
  29025. embed: '埋め込みメディア'
  29026. }
  29027. });
  29028. // CONCATENATED MODULE: ./languages/ru.js
  29029. /* harmony default export */ var ru = ({
  29030. base: {
  29031. remove: 'Удалить',
  29032. cancel: 'Отмена',
  29033. confirm: 'Подтвердить',
  29034. insert: 'Вставить',
  29035. width: 'Ширина',
  29036. height: 'Высота'
  29037. },
  29038. controls: {
  29039. clear: 'Очистить',
  29040. undo: 'Отменить',
  29041. redo: 'Повторить',
  29042. fontSize: 'Размер шрифта',
  29043. color: 'Цвет',
  29044. textColor: 'Цвет текста',
  29045. tempColors: 'Temp Colors',
  29046. backgroundColor: 'Цвет фона',
  29047. bold: 'Жирный',
  29048. lineHeight: 'Межстрочный интервал',
  29049. letterSpacing: 'Межбуквенный интервал',
  29050. textIndent: 'Отступ',
  29051. increaseIndent: 'Увеличить отступ',
  29052. decreaseIndent: 'Уменьшить отступ',
  29053. italic: 'Курсив',
  29054. underline: 'Подчеркнутый',
  29055. strikeThrough: 'Перечеркнутый',
  29056. fontFamily: 'Шрифт',
  29057. textAlign: 'Расположение текста',
  29058. alignLeft: 'По левому краю',
  29059. alignCenter: 'По центру',
  29060. alignRight: 'По правому краю',
  29061. alignJustify: 'По ширине',
  29062. floatLeft: 'Обтекание слева',
  29063. floatRight: 'Обтекание справа',
  29064. superScript: 'Надстрочный индекс',
  29065. subScript: 'Подстрочный индекс',
  29066. removeStyles: 'Убрать стили',
  29067. headings: 'Заголовки',
  29068. header: 'Заголовок',
  29069. normal: 'Обычный',
  29070. orderedList: 'Упорядоченный список',
  29071. unorderedList: 'Неупорядоченный список',
  29072. blockQuote: 'Цитата',
  29073. code: 'Код',
  29074. link: 'Вставить ссылку',
  29075. unlink: 'Убрать ссылку',
  29076. hr: 'Горизонтальная линия',
  29077. media: 'Медиа',
  29078. mediaLibirary: 'Медиа библиотека',
  29079. emoji: 'Emoji',
  29080. fullscreen: 'Полноэкранный режим',
  29081. exitFullscreen: 'Выйти из полноэкранного режима'
  29082. },
  29083. linkEditor: {
  29084. textInputPlaceHolder: 'Введите текст ссылки',
  29085. linkInputPlaceHolder: 'Вставить ссылку',
  29086. inputWithEnterPlaceHolder: 'Вставить ссылку и нажать Enter',
  29087. openInNewWindow: 'Открыть в новом окне',
  29088. removeLink: 'Убрать ссылку'
  29089. },
  29090. audioPlayer: {
  29091. title: 'Воспроизвести аудиофайл'
  29092. },
  29093. videoPlayer: {
  29094. title: 'Воспроизвести видеофайл',
  29095. embedTitle: 'Embed Media'
  29096. },
  29097. media: {
  29098. image: 'Картинка',
  29099. video: 'Видео',
  29100. audio: 'Аудио',
  29101. embed: 'Встроенное'
  29102. }
  29103. });
  29104. // CONCATENATED MODULE: ./languages/fr.js
  29105. /* harmony default export */ var fr = ({
  29106. base: {
  29107. remove: 'Supprimer',
  29108. cancel: 'Annuler',
  29109. confirm: 'Confirmer',
  29110. inert: 'Insérer',
  29111. width: 'Largeur',
  29112. height: 'Hauteur'
  29113. },
  29114. controls: {
  29115. clear: 'Effacer',
  29116. undo: 'Annuler',
  29117. redo: 'Refaire',
  29118. fontSize: 'Taille de police',
  29119. color: 'Couleur',
  29120. textColor: 'Texte',
  29121. tempColors: 'Couleurs temporaire',
  29122. backgroundColor: 'Couleur d\'arrière plan',
  29123. bold: 'Gras',
  29124. lineHeight: 'Hauteur de ligne',
  29125. letterSpacing: 'Espacement des lettres',
  29126. textIndent: 'Indentation du texte',
  29127. increaseIndent: 'Augmenter l\'indentation',
  29128. decreaseIndent: 'Réduire l\'indentation',
  29129. italic: 'Italique',
  29130. underline: 'Souligner',
  29131. strikeThrough: 'Barrer',
  29132. fontFamily: 'Police d\'écriture',
  29133. textAlign: 'Alignement du texte',
  29134. alignLeft: 'Aligner à gauche',
  29135. alignCenter: 'Aligner au centre',
  29136. alignRight: 'Aligner à droite',
  29137. alignJustify: 'Justifier',
  29138. floatLeft: 'Déplacer à gauche',
  29139. floatRight: 'Déplacer à droite',
  29140. superScript: 'Super-script',
  29141. subScript: 'Sous-script',
  29142. removeStyles: 'Supprimer les styles',
  29143. headings: 'Titres',
  29144. header: 'Entêtes',
  29145. normal: 'Normal',
  29146. orderedList: 'Liste ordonnée',
  29147. unorderedList: 'Liste non-ordonnée',
  29148. blockQuote: 'Citation',
  29149. code: 'Code',
  29150. link: 'Insérer un lien',
  29151. unlink: 'Supprimer le lien',
  29152. hr: 'Ligne horizontale',
  29153. media: 'Média',
  29154. mediaLibirary: 'Bibliothêque',
  29155. emoji: 'Emoji',
  29156. fullscreen: 'Plein écran',
  29157. exitFullscreen: 'Quitter le plein écran'
  29158. },
  29159. linkEditor: {
  29160. textInputPlaceHolder: 'Insérer le texte à afficher',
  29161. linkInputPlaceHolder: 'Insérer le lien URL',
  29162. inputWithEnterPlaceHolder: 'Insérer le lien URL puis appuyer sur Entrée',
  29163. openInNewWindow: 'Ouvrir dans une nouvelle fenêtre',
  29164. removeLink: 'Supprimer le lien'
  29165. },
  29166. audioPlayer: {
  29167. title: 'Lancer le son audio'
  29168. },
  29169. videoPlayer: {
  29170. title: 'Lancer la video',
  29171. embedTitle: 'Intégrer média'
  29172. },
  29173. media: {
  29174. image: 'Image',
  29175. video: 'Vidéo',
  29176. audio: 'Audio',
  29177. embed: 'Intégré'
  29178. }
  29179. });
  29180. // CONCATENATED MODULE: ./languages/pt-br.js
  29181. /* harmony default export */ var pt_br = ({
  29182. base: {
  29183. remove: 'Remover',
  29184. cancel: 'Cancelar',
  29185. confirm: 'Confirmar',
  29186. inert: 'Inserir',
  29187. width: 'Largura',
  29188. height: 'Altura'
  29189. },
  29190. controls: {
  29191. clear: 'Limpar',
  29192. undo: 'Desfazer',
  29193. redo: 'Refazer',
  29194. fontSize: 'Tamanho da Fonte',
  29195. color: 'Cor',
  29196. textColor: 'Texto',
  29197. tempColors: 'Temp Colors',
  29198. backgroundColor: 'Cor de Fundo',
  29199. bold: 'Negrito',
  29200. lineHeight: 'Altura da LinhaLine Height',
  29201. letterSpacing: 'Espaçamento entre Letras',
  29202. textIndent: 'Identação de Texto',
  29203. increaseIndent: 'Aumentar Identação',
  29204. decreaseIndent: 'Diminuir Identção',
  29205. italic: 'Itálico',
  29206. underline: 'Sublinhado',
  29207. strikeThrough: 'Riscado',
  29208. fontFamily: 'Família da Fonte',
  29209. textAlign: 'Alinhamento de Texto',
  29210. alignLeft: 'Alinhamento à Esquerda',
  29211. alignCenter: 'Alinhamento Centralizado',
  29212. alignRight: 'Alinhamento à Direita',
  29213. alignJustify: 'Alinhamento Justificado',
  29214. floatLeft: 'Flutuação à Esquerda',
  29215. floatRight: 'Flutuação à Direita',
  29216. superScript: 'Sobrescrito',
  29217. subScript: 'Subscrito',
  29218. removeStyles: 'Remover Estilos',
  29219. headings: 'Cabeçalhos',
  29220. header: 'Cabeçalho',
  29221. normal: 'Normal',
  29222. orderedList: 'Lista Ordenada',
  29223. unorderedList: 'Lista Não Ordenada',
  29224. blockQuote: 'Citação',
  29225. code: 'Código',
  29226. link: 'Link',
  29227. unlink: 'Remover Link',
  29228. hr: 'Linha Horizontal',
  29229. media: 'Mídia',
  29230. mediaLibirary: 'Biblioteca de Mídia',
  29231. emoji: 'Emoji',
  29232. fullscreen: 'Tela Cheia',
  29233. exitFullscreen: 'Sair de Tela Cheia'
  29234. },
  29235. linkEditor: {
  29236. textInputPlaceHolder: 'Insira o texto do link',
  29237. linkInputPlaceHolder: 'Insira a URL do link',
  29238. inputWithEnterPlaceHolder: 'Insira a URL do link e aperte Enter',
  29239. openInNewWindow: 'Abrir em nova janela',
  29240. removeLink: 'Remover Link'
  29241. },
  29242. audioPlayer: {
  29243. title: 'Tocar Áudio'
  29244. },
  29245. videoPlayer: {
  29246. title: 'Tocar Vídeo',
  29247. embedTitle: 'Mídia Embutida'
  29248. },
  29249. media: {
  29250. image: 'Imagem',
  29251. video: 'Vídeo',
  29252. audio: 'Áudio',
  29253. embed: 'Embutido'
  29254. }
  29255. });
  29256. // CONCATENATED MODULE: ./languages/index.js
  29257. /* harmony default export */ var languages = ({
  29258. 'en': en,
  29259. 'zh': zh,
  29260. 'zh-hant': zh_hant,
  29261. 'pl': pl,
  29262. 'kr': kr,
  29263. 'tr': tr,
  29264. 'jpn': jpn,
  29265. 'ru': ru,
  29266. 'fr': fr,
  29267. 'pt-br': pt_br
  29268. });
  29269. // EXTERNAL MODULE: external "braft-finder"
  29270. var external_braft_finder_ = __webpack_require__(17);
  29271. var external_braft_finder_default = /*#__PURE__*/__webpack_require__.n(external_braft_finder_);
  29272. // EXTERNAL MODULE: external "braft-utils"
  29273. var external_braft_utils_ = __webpack_require__(3);
  29274. // EXTERNAL MODULE: external "draft-js"
  29275. var external_draft_js_ = __webpack_require__(6);
  29276. // EXTERNAL MODULE: external "immutable"
  29277. var external_immutable_ = __webpack_require__(13);
  29278. var external_immutable_default = /*#__PURE__*/__webpack_require__.n(external_immutable_);
  29279. // CONCATENATED MODULE: ./configs/keybindings.js
  29280. // TODO
  29281. // 允许自定义的快捷键设置
  29282. /* harmony default export */ var keybindings = (function (customKeyBindingFn) {
  29283. return function (event) {
  29284. if (event.keyCode === 83 && (external_draft_js_["KeyBindingUtil"].hasCommandModifier(event) || external_draft_js_["KeyBindingUtil"].isCtrlKeyCommand(event))) {
  29285. return 'braft-save';
  29286. }
  29287. if (customKeyBindingFn) {
  29288. return customKeyBindingFn(event) || Object(external_draft_js_["getDefaultKeyBinding"])(event);
  29289. }
  29290. return Object(external_draft_js_["getDefaultKeyBinding"])(event);
  29291. };
  29292. });
  29293. // CONCATENATED MODULE: ./configs/props.js
  29294. /* harmony default export */ var configs_props = ({
  29295. language: 'zh',
  29296. 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'],
  29297. excludeControls: [],
  29298. extendControls: [],
  29299. extendAtomics: [],
  29300. componentBelowControlBar: null,
  29301. media: {
  29302. pasteImage: true,
  29303. imagePasteLimit: 5,
  29304. image: true,
  29305. video: true,
  29306. audio: true,
  29307. uploadFn: null,
  29308. validateFn: null,
  29309. onBeforeDeselect: null,
  29310. onDeselect: null,
  29311. onBeforeSelect: null,
  29312. onSelect: null,
  29313. onBeforeRemove: null,
  29314. onRemove: null,
  29315. onCancel: null,
  29316. onFileSelect: null,
  29317. onBeforeInsert: null,
  29318. onInsert: null,
  29319. onChange: null,
  29320. accepts: {
  29321. image: 'image/png,image/jpeg,image/gif,image/webp,image/apng,image/svg',
  29322. video: 'video/mp4',
  29323. audio: 'audio/mp3'
  29324. },
  29325. externals: {
  29326. audio: true,
  29327. video: true,
  29328. image: true,
  29329. embed: true
  29330. }
  29331. },
  29332. imageControls: ['float-left', 'float-right', 'align-left', 'align-center', 'align-right', 'link', 'size', 'remove'],
  29333. imageResizable: true,
  29334. colors: ['#000000', '#333333', '#666666', '#999999', '#cccccc', '#ffffff', '#61a951', '#16a085', '#07a9fe', '#003ba5', '#8e44ad', '#f32784', '#c0392b', '#d35400', '#f39c12', '#fdda00'],
  29335. colorPicker: null,
  29336. colorPickerTheme: 'dark',
  29337. colorPickerAutoHide: true,
  29338. codeTabIndents: 2,
  29339. headings: ['header-one', 'header-two', 'header-three', 'header-four', 'header-five', 'header-six', 'unstyled'],
  29340. textAligns: ['left', 'center', 'right', 'justify'],
  29341. textBackgroundColor: true,
  29342. allowInsertLinkText: false,
  29343. defaultLinkTarget: '',
  29344. letterSpacings: [0, 1, 2, 3, 4, 5, 6],
  29345. lineHeights: [1, 1.2, 1.5, 1.75, 2, 2.5, 3, 4],
  29346. fontSizes: [12, 14, 16, 18, 20, 24, 28, 30, 32, 36, 40, 48, 56, 64, 72, 96, 120, 144],
  29347. fontFamilies: [{
  29348. name: 'Araial',
  29349. family: 'Arial, Helvetica, sans-serif'
  29350. }, {
  29351. name: 'Georgia',
  29352. family: 'Georgia, serif'
  29353. }, {
  29354. name: 'Impact',
  29355. family: 'Impact, serif'
  29356. }, {
  29357. name: 'Monospace',
  29358. family: '"Courier New", Courier, monospace'
  29359. }, {
  29360. name: 'Tahoma',
  29361. family: 'tahoma, arial, "Hiragino Sans GB", 宋体, sans-serif'
  29362. }],
  29363. converts: {
  29364. unitExportFn: function unitExportFn(value, type) {
  29365. return type === 'line-height' ? value : "".concat(value, "px");
  29366. }
  29367. },
  29368. emojis: ['🤣', '🙌', '💚', '💛', '👏', '😉', '💯', '💕', '💞', '💘', '💙', '💝', '🖤', '💜', '❤️', '😍', '😻', '💓', '💗', '😋', '😇', '😂', '😹', '😘', '💖', '😁', '😀', '🤞', '😲', '😄', '😊', '👍', '😌', '😃', '😅', '✌️', '🤗', '💋', '😗', '😽', '😚', '🤠', '😙', '😺', '👄', '😸', '😏', '😼', '👌', '😎', '😆', '😛', '🙏', '🤝', '🙂', '🤑', '😝', '😐', '😑', '🤤', '😤', '🙃', '🤡', '😶', '😪', '😴', '😵', '😓', '👊', '😦', '😷', '🤐', '😜', '🤓', '👻', '😥', '🙄', '🤔', '🤒', '🙁', '😔', '😯', '☹️', '☠️', '😰', '😩', '😖', '😕', '😒', '😣', '😢', '😮', '😿', '🤧', '😫', '🤥', '😞', '😬', '👎', '💀', '😳', '😨', '🤕', '🤢', '😱', '😭', '😠', '😈', '😧', '💔', '😟', '🙀', '💩', '👿', '😡', '😾', '🖕'],
  29369. stripPastedStyles: false,
  29370. triggerChangeOnMount: true,
  29371. className: '',
  29372. style: {},
  29373. controlBarClassName: '',
  29374. controlBarStyle: {},
  29375. contentClassName: '',
  29376. contentStyle: {},
  29377. draftProps: {},
  29378. hooks: {},
  29379. onChange: null,
  29380. onFocus: null,
  29381. onBlur: null,
  29382. onTab: null,
  29383. onDelete: null,
  29384. onSave: null,
  29385. fixPlaceholder: false
  29386. });
  29387. // EXTERNAL MODULE: ../node_modules/draft-js/lib/getFragmentFromSelection.js
  29388. var getFragmentFromSelection = __webpack_require__(22);
  29389. var getFragmentFromSelection_default = /*#__PURE__*/__webpack_require__.n(getFragmentFromSelection);
  29390. // EXTERNAL MODULE: external "draftjs-utils"
  29391. var external_draftjs_utils_ = __webpack_require__(23);
  29392. // CONCATENATED MODULE: ./configs/handlers.js
  29393. var handlers_keyCommandHandlers = function keyCommandHandlers(command, editorState, editor) {
  29394. if (editor.editorProps.handleKeyCommand && editor.editorProps.handleKeyCommand(command, editorState, editor) === 'handled') {
  29395. return 'handled';
  29396. }
  29397. if (command === 'braft-save') {
  29398. editor.editorProps.onSave && editor.editorProps.onSave(editorState);
  29399. return 'handled';
  29400. }
  29401. var _editor$editorProps = editor.editorProps,
  29402. controls = _editor$editorProps.controls,
  29403. excludeControls = _editor$editorProps.excludeControls;
  29404. var allowIndent = (controls.indexOf('text-indent') !== 0 || controls.find(function (item) {
  29405. return item.key === 'text-indent';
  29406. })) && excludeControls.indexOf('text-indent') === -1;
  29407. var cursorStart = editorState.getSelection().getStartOffset();
  29408. var cursorEnd = editorState.getSelection().getEndOffset();
  29409. var cursorIsAtFirst = cursorStart === 0 && cursorEnd === 0;
  29410. if (command === 'backspace') {
  29411. if (editor.editorProps.onDelete && editor.editorProps.onDelete(editorState) === false) {
  29412. return 'handled';
  29413. }
  29414. var blockType = external_braft_utils_["ContentUtils"].getSelectionBlockType(editorState);
  29415. if (allowIndent && cursorIsAtFirst && blockType !== 'code-block') {
  29416. editor.setValue(external_braft_utils_["ContentUtils"].decreaseSelectionIndent(editorState));
  29417. }
  29418. }
  29419. if (command === 'tab') {
  29420. var _blockType = external_braft_utils_["ContentUtils"].getSelectionBlockType(editorState);
  29421. if (_blockType === 'code-block') {
  29422. editor.setValue(external_braft_utils_["ContentUtils"].insertText(editorState, ' '.repeat(editor.editorProps.codeTabIndents)));
  29423. return 'handled';
  29424. } else if (_blockType === 'ordered-list-item' || _blockType === 'unordered-list-item') {
  29425. var newEditorState = external_draft_js_["RichUtils"].onTab(event, editorState, 4);
  29426. if (newEditorState !== editorState) {
  29427. editor.setValue(newEditorState);
  29428. }
  29429. return 'handled';
  29430. } else if (_blockType !== 'atomic' && allowIndent && cursorIsAtFirst) {
  29431. editor.setValue(external_braft_utils_["ContentUtils"].increaseSelectionIndent(editorState));
  29432. return 'handled';
  29433. }
  29434. }
  29435. var nextEditorState = external_braft_utils_["ContentUtils"].handleKeyCommand(editorState, command);
  29436. if (nextEditorState) {
  29437. editor.setValue(nextEditorState);
  29438. return 'handled';
  29439. }
  29440. return 'not-handled';
  29441. };
  29442. var handlers_returnHandlers = function returnHandlers(event, editorState, editor) {
  29443. if (editor.editorProps.handleReturn && editor.editorProps.handleReturn(event, editorState, editor) === 'handled') {
  29444. return 'handled';
  29445. }
  29446. var currentBlock = external_braft_utils_["ContentUtils"].getSelectionBlock(editorState);
  29447. var currentBlockType = currentBlock.getType();
  29448. if (currentBlockType === 'unordered-list-item' || currentBlockType === 'ordered-list-item') {
  29449. if (currentBlock.getLength() === 0) {
  29450. editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionBlockType(editorState, 'unstyled'));
  29451. return 'handled';
  29452. }
  29453. return 'not-handled';
  29454. } else if (currentBlockType === 'code-block') {
  29455. if (event.which === 13 && (event.getModifierState('Shift') || event.getModifierState('Alt') || event.getModifierState('Control'))) {
  29456. editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionBlockType(editorState, 'unstyled'));
  29457. return 'handled';
  29458. }
  29459. return 'not-handled';
  29460. } else if (currentBlockType === 'blockquote') {
  29461. if (event.which === 13) {
  29462. if (event.getModifierState('Shift') || event.getModifierState('Alt') || event.getModifierState('Control')) {
  29463. event.which = 0;
  29464. } else {
  29465. editor.setValue(external_draft_js_["RichUtils"].insertSoftNewline(editorState));
  29466. return 'handled';
  29467. }
  29468. }
  29469. }
  29470. var nextEditorState = Object(external_draftjs_utils_["handleNewLine"])(editorState, event);
  29471. if (nextEditorState) {
  29472. editor.setValue(nextEditorState);
  29473. return 'handled';
  29474. }
  29475. return 'not-handled';
  29476. };
  29477. var beforeInputHandlers = function beforeInputHandlers(chars, editorState, editor) {
  29478. if (editor.editorProps.handleBeforeInput && editor.editorProps.handleBeforeInput(chars, editorState, editor) === 'handled') {
  29479. return 'handled';
  29480. }
  29481. return 'not-handled';
  29482. };
  29483. var handlers_compositionStartHandler = function compositionStartHandler(_, editor) {
  29484. var editorState = editor.state.editorState;
  29485. var selectedBlocks = external_braft_utils_["ContentUtils"].getSelectedBlocks(editorState);
  29486. if (selectedBlocks && selectedBlocks.length > 1) {
  29487. var nextEditorState = external_draft_js_["EditorState"].push(editorState, external_draft_js_["Modifier"].removeRange(editorState.getCurrentContent(), editorState.getSelection(), 'backward'), 'remove-range');
  29488. editor.setValue(nextEditorState);
  29489. }
  29490. };
  29491. var handlers_dropHandlers = function dropHandlers(selectionState, dataTransfer, editor) {
  29492. if (editor.editorProps.readOnly || editor.editorProps.disabled) {
  29493. return 'handled';
  29494. }
  29495. if (window && window.__BRAFT_DRAGING__IMAGE__) {
  29496. var nextEditorState = external_draft_js_["EditorState"].forceSelection(editor.state.editorState, selectionState);
  29497. nextEditorState = external_braft_utils_["ContentUtils"].insertMedias(nextEditorState, [window.__BRAFT_DRAGING__IMAGE__.mediaData]);
  29498. nextEditorState = external_braft_utils_["ContentUtils"].removeBlock(nextEditorState, window.__BRAFT_DRAGING__IMAGE__.block, nextEditorState.getSelection());
  29499. window.__BRAFT_DRAGING__IMAGE__ = null;
  29500. editor.lockOrUnlockEditor(true);
  29501. editor.setValue(nextEditorState);
  29502. return 'handled';
  29503. } else if (!dataTransfer || !dataTransfer.getText()) {
  29504. return 'handled';
  29505. }
  29506. return 'not-handled';
  29507. };
  29508. var handlers_handleFiles = function handleFiles(files, editor) {
  29509. var _editor$constructor$d = objectSpread_default()({}, editor.constructor.defaultProps.media, editor.editorProps.media),
  29510. pasteImage = _editor$constructor$d.pasteImage,
  29511. validateFn = _editor$constructor$d.validateFn,
  29512. imagePasteLimit = _editor$constructor$d.imagePasteLimit;
  29513. pasteImage && files.slice(0, imagePasteLimit).forEach(function (file) {
  29514. if (file && file.type.indexOf('image') > -1 && editor.braftFinder) {
  29515. var validateResult = validateFn ? validateFn(file) : true;
  29516. if (validateResult instanceof Promise) {
  29517. validateResult.then(function () {
  29518. editor.braftFinder.uploadImage(file, function (image) {
  29519. editor.isLiving && editor.setValue(external_braft_utils_["ContentUtils"].insertMedias(editor.state.editorState, [image]));
  29520. });
  29521. });
  29522. } else if (validateResult) {
  29523. editor.braftFinder.uploadImage(file, function (image) {
  29524. editor.isLiving && editor.setValue(external_braft_utils_["ContentUtils"].insertMedias(editor.state.editorState, [image]));
  29525. });
  29526. }
  29527. }
  29528. });
  29529. if (files[0] && files[0].type.indexOf('image') > -1 && pasteImage) {
  29530. return 'handled';
  29531. }
  29532. return 'not-handled';
  29533. };
  29534. var droppedFilesHandlers = function droppedFilesHandlers(selectionState, files, editor) {
  29535. if (editor.editorProps.handleDroppedFiles && editor.editorProps.handleDroppedFiles(selectionState, files, editor) === 'handled') {
  29536. return 'handled';
  29537. }
  29538. return handlers_handleFiles(files, editor);
  29539. };
  29540. var pastedFilesHandlers = function pastedFilesHandlers(files, editor) {
  29541. if (editor.editorProps.handlePastedFiles && editor.editorProps.handlePastedFiles(files, editor) === 'handled') {
  29542. return 'handled';
  29543. }
  29544. return handlers_handleFiles(files, editor);
  29545. };
  29546. var handlers_copyHandlers = function copyHandlers(event, editor) {
  29547. var blockMap = getFragmentFromSelection_default()(editor.state.editorState);
  29548. if (blockMap && blockMap.toArray) {
  29549. try {
  29550. var tempContentState = external_draft_js_["ContentState"].createFromBlockArray(blockMap.toArray());
  29551. var tempEditorState = external_draft_js_["EditorState"].createWithContent(tempContentState);
  29552. var clipboardData = event.clipboardData || window.clipboardData || event.originalEvent.clipboardData;
  29553. tempEditorState.setConvertOptions(editor.state.editorState.convertOptions);
  29554. clipboardData.setData('text/html', tempEditorState.toHTML());
  29555. clipboardData.setData('text/plain', tempEditorState.toText());
  29556. event.preventDefault();
  29557. } catch (error) {
  29558. console.warn(error);
  29559. }
  29560. }
  29561. };
  29562. var handlers_pastedTextHandlers = function pastedTextHandlers(text, html, editorState, editor) {
  29563. if (editor.editorProps.handlePastedText && editor.editorProps.handlePastedText(text, html, editorState, editor) === 'handled') {
  29564. return 'handled';
  29565. }
  29566. if (!html || editor.editorProps.stripPastedStyles) {
  29567. return false;
  29568. }
  29569. var tempColors = external_braft_utils_["ColorUtils"].detectColorsFromHTMLString(html);
  29570. editor.setState({
  29571. tempColors: toConsumableArray_default()(editor.state.tempColors).concat(toConsumableArray_default()(tempColors)).filter(function (item) {
  29572. return editor.editorProps.colors.indexOf(item) === -1;
  29573. }).filter(function (item, index, array) {
  29574. return array.indexOf(item) === index;
  29575. })
  29576. }, function () {
  29577. editor.setValue(external_braft_utils_["ContentUtils"].insertHTML(editorState, html, 'paste'));
  29578. });
  29579. return 'handled';
  29580. };
  29581. // CONCATENATED MODULE: ./helpers/extension.js
  29582. // TODO
  29583. // - block-style和atomic类型的扩展支持
  29584. var extension_extensionControls = [];
  29585. var extension_extensionDecorators = [];
  29586. var extension_propInterceptors = [];
  29587. var extension_extensionBlockRenderMaps = [];
  29588. var extension_extensionBlockRendererFns = [];
  29589. var extensionInlineStyleMaps = [];
  29590. var extension_extensionInlineStyleFns = [];
  29591. var extensionEntities = [];
  29592. var inlineStyleImporters = [];
  29593. var inlineStyleExporters = [];
  29594. var blockImporters = [];
  29595. var blockExporters = [];
  29596. var filterByEditorId = function filterByEditorId(items, editorId) {
  29597. if (!editorId) {
  29598. return items.filter(function (item) {
  29599. return !item.includeEditors;
  29600. }).map(function (item) {
  29601. return item.data;
  29602. });
  29603. }
  29604. return items.map(function (item) {
  29605. if (!item.includeEditors && !item.excludeEditors) {
  29606. return item.data;
  29607. }
  29608. if (item.includeEditors) {
  29609. return item.includeEditors.indexOf(editorId) !== -1 ? item.data : false;
  29610. }
  29611. if (item.excludeEditors) {
  29612. return item.excludeEditors.indexOf(editorId) !== -1 ? false : item.data;
  29613. }
  29614. return false;
  29615. }).filter(function (item) {
  29616. return item;
  29617. });
  29618. };
  29619. var getPropInterceptors = function getPropInterceptors(editorId) {
  29620. return filterByEditorId(extension_propInterceptors, editorId);
  29621. };
  29622. var getExtensionControls = function getExtensionControls(editorId) {
  29623. return filterByEditorId(extension_extensionControls, editorId);
  29624. };
  29625. var getExtensionDecorators = function getExtensionDecorators(editorId) {
  29626. return filterByEditorId(extension_extensionDecorators, editorId);
  29627. };
  29628. var getExtensionBlockRenderMaps = function getExtensionBlockRenderMaps(editorId) {
  29629. return filterByEditorId(extension_extensionBlockRenderMaps, editorId);
  29630. };
  29631. var getExtensionBlockRendererFns = function getExtensionBlockRendererFns(editorId) {
  29632. return filterByEditorId(extension_extensionBlockRendererFns, editorId);
  29633. };
  29634. var getExtensionInlineStyleMap = function getExtensionInlineStyleMap(editorId) {
  29635. var inlineStyleMap = {};
  29636. filterByEditorId(extensionInlineStyleMaps, editorId).forEach(function (item) {
  29637. inlineStyleMap[item.inlineStyleName] = item.styleMap;
  29638. });
  29639. return inlineStyleMap;
  29640. };
  29641. var getExtensionInlineStyleFns = function getExtensionInlineStyleFns(editorId) {
  29642. return filterByEditorId(extension_extensionInlineStyleFns, editorId);
  29643. };
  29644. var compositeStyleImportFn = function compositeStyleImportFn(styleImportFn, editorId) {
  29645. return function (nodeName, node, style) {
  29646. filterByEditorId(inlineStyleImporters, editorId).forEach(function (styleImporter) {
  29647. if (styleImporter.importer && styleImporter.importer(nodeName, node)) {
  29648. style = style.add(styleImporter.inlineStyleName);
  29649. }
  29650. });
  29651. return styleImportFn ? styleImportFn(nodeName, node, style) : style;
  29652. };
  29653. };
  29654. var compositeStyleExportFn = function compositeStyleExportFn(styleExportFn, editorId) {
  29655. return function (style) {
  29656. style = style.toUpperCase();
  29657. var result = styleExportFn ? styleExportFn(style) : undefined;
  29658. if (result) {
  29659. return result;
  29660. }
  29661. filterByEditorId(inlineStyleExporters, editorId).find(function (item) {
  29662. if (item.inlineStyleName === style) {
  29663. result = item.exporter;
  29664. return true;
  29665. }
  29666. });
  29667. return result;
  29668. };
  29669. };
  29670. var compositeEntityImportFn = function compositeEntityImportFn(entityImportFn, editorId) {
  29671. return function (nodeName, node, createEntity, source) {
  29672. var result = entityImportFn ? entityImportFn(nodeName, node, createEntity, source) : null;
  29673. if (result) {
  29674. return result;
  29675. }
  29676. filterByEditorId(extensionEntities, editorId).find(function (entityItem) {
  29677. var matched = entityItem.importer ? entityItem.importer(nodeName, node, source) : null;
  29678. matched && (result = createEntity(entityItem.entityType, matched.mutability || 'MUTABLE', matched.data || {}));
  29679. return !!matched;
  29680. });
  29681. return result;
  29682. };
  29683. };
  29684. var compositeEntityExportFn = function compositeEntityExportFn(entityExportFn, editorId) {
  29685. return function (entity, originalText) {
  29686. var result = entityExportFn ? entityExportFn(entity, originalText) : undefined;
  29687. if (result) {
  29688. return result;
  29689. }
  29690. var entityType = entity.type.toUpperCase();
  29691. filterByEditorId(extensionEntities, editorId).find(function (entityItem) {
  29692. if (entityItem.entityType === entityType) {
  29693. result = entityItem.exporter ? entityItem.exporter(entity, originalText) : undefined;
  29694. return true;
  29695. }
  29696. });
  29697. return result;
  29698. };
  29699. };
  29700. var compositeBlockImportFn = function compositeBlockImportFn(blockImportFn, editorId) {
  29701. return function (nodeName, node, source) {
  29702. var result = blockImportFn ? blockImportFn(nodeName, node, source) : null;
  29703. if (result) {
  29704. return result;
  29705. }
  29706. filterByEditorId(blockImporters, editorId).find(function (blockImporter) {
  29707. var matched = blockImporter.importer ? blockImporter.importer(nodeName, node, source) : undefined;
  29708. matched && (result = matched);
  29709. return !!matched;
  29710. });
  29711. return result;
  29712. };
  29713. };
  29714. var compositeBlockExportFn = function compositeBlockExportFn(blockExportFn, editorId) {
  29715. return function (contentState, block) {
  29716. var result = blockExportFn ? blockExportFn(contentState, block) : null;
  29717. if (result) {
  29718. return result;
  29719. }
  29720. filterByEditorId(blockExporters, editorId).find(function (blockExporter) {
  29721. var matched = blockExporter.exporter ? blockExporter.exporter(contentState, block) : undefined;
  29722. matched && (result = matched);
  29723. return !!matched;
  29724. });
  29725. return result;
  29726. };
  29727. };
  29728. var extension_useExtension = function useExtension(extension) {
  29729. if (extension instanceof Array) {
  29730. extension.forEach(useExtension);
  29731. return false;
  29732. }
  29733. if (!extension || !extension.type || typeof extension.type !== 'string') {
  29734. return false;
  29735. }
  29736. var includeEditors = extension.includeEditors,
  29737. excludeEditors = extension.excludeEditors;
  29738. if (extension.type === 'control') {
  29739. extension_extensionControls.push({
  29740. includeEditors: includeEditors,
  29741. excludeEditors: excludeEditors,
  29742. data: extension.control
  29743. });
  29744. } else if (extension.type === 'inline-style') {
  29745. var inlineStyleName = extension.name.toUpperCase();
  29746. if (extension.control) {
  29747. extension_extensionControls.push({
  29748. includeEditors: includeEditors,
  29749. excludeEditors: excludeEditors,
  29750. data: objectSpread_default()({
  29751. key: inlineStyleName,
  29752. type: 'inline-style',
  29753. command: inlineStyleName
  29754. }, extension.control)
  29755. });
  29756. }
  29757. if (extension.style) {
  29758. extensionInlineStyleMaps.push({
  29759. includeEditors: includeEditors,
  29760. excludeEditors: excludeEditors,
  29761. data: {
  29762. inlineStyleName: inlineStyleName,
  29763. styleMap: extension.style
  29764. }
  29765. });
  29766. }
  29767. if (extension.styleFn) {
  29768. extension_extensionInlineStyleFns.push({
  29769. includeEditors: includeEditors,
  29770. excludeEditors: excludeEditors,
  29771. data: {
  29772. inlineStyleName: inlineStyleName,
  29773. styleFn: extension.styleFn
  29774. }
  29775. });
  29776. }
  29777. if (extension.importer) {
  29778. inlineStyleImporters.push({
  29779. includeEditors: includeEditors,
  29780. excludeEditors: excludeEditors,
  29781. data: {
  29782. inlineStyleName: inlineStyleName,
  29783. importer: extension.importer
  29784. }
  29785. });
  29786. }
  29787. inlineStyleExporters.push({
  29788. includeEditors: includeEditors,
  29789. excludeEditors: excludeEditors,
  29790. data: {
  29791. inlineStyleName: inlineStyleName,
  29792. exporter: extension.exporter ? extension.exporter(extension) : external_react_default.a.createElement("span", {
  29793. style: extension.style
  29794. })
  29795. }
  29796. });
  29797. } else if (extension.type === 'block-style') ; else if (extension.type === 'entity') {
  29798. var entityType = extension.name.toUpperCase();
  29799. if (extension.control) {
  29800. extension_extensionControls.push({
  29801. includeEditors: includeEditors,
  29802. excludeEditors: excludeEditors,
  29803. data: typeof extension.control === 'function' ? extension.control : objectSpread_default()({
  29804. key: entityType,
  29805. type: 'entity',
  29806. command: entityType,
  29807. data: {
  29808. mutability: extension.mutability || 'MUTABLE',
  29809. data: extension.data || {}
  29810. }
  29811. }, extension.control)
  29812. });
  29813. }
  29814. extensionEntities.push({
  29815. includeEditors: includeEditors,
  29816. excludeEditors: excludeEditors,
  29817. data: {
  29818. entityType: entityType,
  29819. importer: extension.importer,
  29820. exporter: extension.exporter
  29821. }
  29822. });
  29823. extension_extensionDecorators.push({
  29824. includeEditors: includeEditors,
  29825. excludeEditors: excludeEditors,
  29826. data: {
  29827. type: 'entity',
  29828. decorator: {
  29829. key: entityType,
  29830. component: extension.component
  29831. }
  29832. }
  29833. });
  29834. } else if (extension.type === 'block') {
  29835. var blockType = extension.name;
  29836. if (extension.renderMap) {
  29837. extension_extensionBlockRenderMaps.push({
  29838. includeEditors: includeEditors,
  29839. excludeEditors: excludeEditors,
  29840. data: {
  29841. blockType: blockType,
  29842. renderMap: extension.renderMap
  29843. }
  29844. });
  29845. }
  29846. if (extension.rendererFn) {
  29847. extension_extensionBlockRendererFns.push({
  29848. includeEditors: includeEditors,
  29849. excludeEditors: excludeEditors,
  29850. data: {
  29851. blockType: blockType,
  29852. rendererFn: extension.rendererFn
  29853. }
  29854. });
  29855. }
  29856. if (extension.importer) {
  29857. blockImporters.push({
  29858. includeEditors: includeEditors,
  29859. excludeEditors: excludeEditors,
  29860. data: {
  29861. blockType: blockType,
  29862. importer: extension.importer
  29863. }
  29864. });
  29865. }
  29866. if (extension.exporter) {
  29867. blockExporters.push({
  29868. includeEditors: includeEditors,
  29869. excludeEditors: excludeEditors,
  29870. data: {
  29871. blockType: blockType,
  29872. exporter: extension.exporter
  29873. }
  29874. });
  29875. }
  29876. } else if (extension.type === 'atomic') ; else if (extension.type === 'decorator') {
  29877. var decorator = extension.decorator;
  29878. if (decorator && decorator.strategy && decorator.component) {
  29879. extension_extensionDecorators.push({
  29880. includeEditors: includeEditors,
  29881. excludeEditors: excludeEditors,
  29882. data: {
  29883. type: 'strategy',
  29884. decorator: decorator
  29885. }
  29886. });
  29887. } else if (decorator && decorator.getDecorations) {
  29888. extension_extensionDecorators.push({
  29889. includeEditors: includeEditors,
  29890. excludeEditors: excludeEditors,
  29891. data: {
  29892. type: 'class',
  29893. decorator: decorator
  29894. }
  29895. });
  29896. }
  29897. } else if (extension.type === 'prop-interception') {
  29898. extension_propInterceptors.push({
  29899. includeEditors: includeEditors,
  29900. excludeEditors: excludeEditors,
  29901. data: extension.interceptor
  29902. });
  29903. }
  29904. };
  29905. var createExtensibleEditor = function createExtensibleEditor(BraftEditor) {
  29906. BraftEditor.use = extension_useExtension;
  29907. return BraftEditor;
  29908. };
  29909. // CONCATENATED MODULE: ./renderers/block/blockRenderMap.js
  29910. /* harmony default export */ var block_blockRenderMap = (function (props, blockRenderMap) {
  29911. var customBlockRenderMap = Object(external_immutable_["Map"])({
  29912. 'atomic': {
  29913. element: ''
  29914. },
  29915. 'code-block': {
  29916. element: 'code',
  29917. wrapper: external_react_default.a.createElement("pre", {
  29918. className: "braft-code-block"
  29919. })
  29920. }
  29921. });
  29922. try {
  29923. var extensionBlockRenderMaps = getExtensionBlockRenderMaps(props.editorId);
  29924. customBlockRenderMap = extensionBlockRenderMaps.reduce(function (customBlockRenderMap, item) {
  29925. return customBlockRenderMap.merge(typeof item.renderMap === 'function' ? item.renderMap(props) : item.renderMap);
  29926. }, customBlockRenderMap);
  29927. if (blockRenderMap) {
  29928. if (typeof blockRenderMap === 'function') {
  29929. customBlockRenderMap = customBlockRenderMap.merge(blockRenderMap(props));
  29930. } else {
  29931. customBlockRenderMap = customBlockRenderMap.merge(blockRenderMap);
  29932. }
  29933. }
  29934. customBlockRenderMap = external_draft_js_["DefaultDraftBlockRenderMap"].merge(customBlockRenderMap);
  29935. } catch (error) {
  29936. console.warn(error);
  29937. }
  29938. return customBlockRenderMap;
  29939. });
  29940. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/extends.js
  29941. var helpers_extends = __webpack_require__(11);
  29942. var extends_default = /*#__PURE__*/__webpack_require__.n(helpers_extends);
  29943. // EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/slicedToArray.js
  29944. var slicedToArray = __webpack_require__(24);
  29945. var slicedToArray_default = /*#__PURE__*/__webpack_require__.n(slicedToArray);
  29946. // EXTERNAL MODULE: ./renderers/atomics/Image/style.scss
  29947. var Image_style = __webpack_require__(45);
  29948. // EXTERNAL MODULE: ./components/common/Switch/style.scss
  29949. var Switch_style = __webpack_require__(46);
  29950. // CONCATENATED MODULE: ./components/common/Switch/index.jsx
  29951. /* harmony default export */ var Switch = (function (props) {
  29952. var active = props.active,
  29953. _onClick = props.onClick,
  29954. className = props.className;
  29955. return external_react_default.a.createElement("div", {
  29956. onClick: function onClick() {
  29957. return _onClick();
  29958. },
  29959. className: 'bf-switch ' + className + (active ? ' active' : '')
  29960. });
  29961. });
  29962. // CONCATENATED MODULE: ./configs/controls.js
  29963. /* harmony default export */ var configs_controls = (function (lang, editor) {
  29964. return [{
  29965. key: 'undo',
  29966. title: lang.controls.undo,
  29967. text: external_react_default.a.createElement("i", {
  29968. className: "bfi-undo"
  29969. }),
  29970. type: 'editor-method',
  29971. command: 'undo'
  29972. }, {
  29973. key: 'redo',
  29974. title: lang.controls.redo,
  29975. text: external_react_default.a.createElement("i", {
  29976. className: "bfi-redo"
  29977. }),
  29978. type: 'editor-method',
  29979. command: 'redo'
  29980. }, {
  29981. key: 'remove-styles',
  29982. title: lang.controls.removeStyles,
  29983. text: external_react_default.a.createElement("i", {
  29984. className: "bfi-format_clear"
  29985. }),
  29986. type: 'editor-method',
  29987. command: 'removeSelectionInlineStyles'
  29988. }, {
  29989. key: 'hr',
  29990. title: lang.controls.hr,
  29991. text: external_react_default.a.createElement("i", {
  29992. className: "bfi-hr"
  29993. }),
  29994. type: 'editor-method',
  29995. command: 'insertHorizontalLine'
  29996. }, {
  29997. key: 'bold',
  29998. title: lang.controls.bold,
  29999. text: external_react_default.a.createElement("i", {
  30000. className: "bfi-bold"
  30001. }),
  30002. type: 'inline-style',
  30003. command: 'bold'
  30004. }, {
  30005. key: 'italic',
  30006. title: lang.controls.italic,
  30007. text: external_react_default.a.createElement("i", {
  30008. className: "bfi-italic"
  30009. }),
  30010. type: 'inline-style',
  30011. command: 'italic'
  30012. }, {
  30013. key: 'underline',
  30014. title: lang.controls.underline,
  30015. text: external_react_default.a.createElement("i", {
  30016. className: "bfi-underlined"
  30017. }),
  30018. type: 'inline-style',
  30019. command: 'underline'
  30020. }, {
  30021. key: 'strike-through',
  30022. title: lang.controls.strikeThrough,
  30023. text: external_react_default.a.createElement("i", {
  30024. className: "bfi-strikethrough"
  30025. }),
  30026. type: 'inline-style',
  30027. command: 'strikethrough'
  30028. }, {
  30029. key: 'superscript',
  30030. title: lang.controls.superScript,
  30031. text: external_react_default.a.createElement("i", {
  30032. className: "bfi-superscript"
  30033. }),
  30034. type: 'inline-style',
  30035. command: 'superscript'
  30036. }, {
  30037. key: 'subscript',
  30038. title: lang.controls.subScript,
  30039. text: external_react_default.a.createElement("i", {
  30040. className: "bfi-subscript"
  30041. }),
  30042. type: 'inline-style',
  30043. command: 'subscript'
  30044. }, {
  30045. key: 'headings',
  30046. title: lang.controls.headings,
  30047. type: 'headings'
  30048. }, {
  30049. key: 'blockquote',
  30050. title: lang.controls.blockQuote,
  30051. text: external_react_default.a.createElement("i", {
  30052. className: "bfi-quote"
  30053. }),
  30054. type: 'block-type',
  30055. command: 'blockquote'
  30056. }, {
  30057. key: 'code',
  30058. title: lang.controls.code,
  30059. text: external_react_default.a.createElement("i", {
  30060. className: "bfi-code"
  30061. }),
  30062. type: 'block-type',
  30063. command: 'code-block'
  30064. }, {
  30065. key: 'list-ul',
  30066. title: lang.controls.unorderedList,
  30067. text: external_react_default.a.createElement("i", {
  30068. className: "bfi-list"
  30069. }),
  30070. type: 'block-type',
  30071. command: 'unordered-list-item'
  30072. }, {
  30073. key: 'list-ol',
  30074. title: lang.controls.orderedList,
  30075. text: external_react_default.a.createElement("i", {
  30076. className: "bfi-list-numbered"
  30077. }),
  30078. type: 'block-type',
  30079. command: 'ordered-list-item'
  30080. }, {
  30081. key: 'link',
  30082. title: lang.controls.link,
  30083. type: 'link'
  30084. }, {
  30085. key: 'text-color',
  30086. title: lang.controls.color,
  30087. type: 'text-color'
  30088. }, {
  30089. key: 'line-height',
  30090. title: lang.controls.lineHeight,
  30091. type: 'line-height'
  30092. }, {
  30093. key: 'letter-spacing',
  30094. title: lang.controls.letterSpacing,
  30095. type: 'letter-spacing'
  30096. }, {
  30097. key: 'text-indent',
  30098. title: lang.controls.textIndent,
  30099. type: 'text-indent'
  30100. }, {
  30101. key: 'font-size',
  30102. title: lang.controls.fontSize,
  30103. type: 'font-size'
  30104. }, {
  30105. key: 'font-family',
  30106. title: lang.controls.fontFamily,
  30107. type: 'font-family'
  30108. }, {
  30109. key: 'text-align',
  30110. title: lang.controls.textAlign,
  30111. type: 'text-align'
  30112. }, {
  30113. key: 'media',
  30114. title: lang.controls.media,
  30115. text: external_react_default.a.createElement("i", {
  30116. className: "bfi-media"
  30117. }),
  30118. type: 'media'
  30119. }, {
  30120. key: 'emoji',
  30121. title: lang.controls.emoji,
  30122. text: external_react_default.a.createElement("i", {
  30123. className: "bfi-emoji"
  30124. }),
  30125. type: 'emoji'
  30126. }, {
  30127. key: 'clear',
  30128. title: lang.controls.clear,
  30129. text: external_react_default.a.createElement("i", {
  30130. className: "bfi-clear_all"
  30131. }),
  30132. type: 'editor-method',
  30133. command: 'clearEditorContent'
  30134. }, {
  30135. key: 'fullscreen',
  30136. title: editor.state.isFullscreen ? lang.controls.exitFullscreen : lang.controls.fullscreen,
  30137. text: external_react_default.a.createElement("i", {
  30138. className: editor.state.isFullscreen ? 'bfi-fullscreen-exit' : 'bfi-fullscreen'
  30139. }),
  30140. type: 'editor-method',
  30141. command: 'toggleFullscreen'
  30142. }, {
  30143. key: 'modal',
  30144. type: 'modal'
  30145. }, {
  30146. key: 'button',
  30147. type: 'button'
  30148. }, {
  30149. key: 'dropdown',
  30150. type: 'dropdown'
  30151. }, {
  30152. key: 'component',
  30153. type: 'component'
  30154. }];
  30155. });
  30156. var imageControlItems = {
  30157. 'float-left': {
  30158. text: external_react_default.a.createElement("span", {
  30159. "data-float": "left"
  30160. }, "\uE91E"),
  30161. command: 'setImageFloat|left'
  30162. },
  30163. 'float-right': {
  30164. text: external_react_default.a.createElement("span", {
  30165. "data-float": "right"
  30166. }, "\uE914"),
  30167. command: 'setImageFloat|right'
  30168. },
  30169. 'align-left': {
  30170. text: external_react_default.a.createElement("span", {
  30171. "data-align": "left"
  30172. }, "\uE027"),
  30173. command: 'setImageAlignment|left'
  30174. },
  30175. 'align-center': {
  30176. text: external_react_default.a.createElement("span", {
  30177. "data-align": "center"
  30178. }, "\uE028"),
  30179. command: 'setImageAlignment|center'
  30180. },
  30181. 'align-right': {
  30182. text: external_react_default.a.createElement("span", {
  30183. "data-align": "right"
  30184. }, "\uE029"),
  30185. command: 'setImageAlignment|right'
  30186. },
  30187. 'size': {
  30188. text: external_react_default.a.createElement("span", null, "\uE3C2"),
  30189. command: 'toggleSizeEditor'
  30190. },
  30191. 'link': {
  30192. text: external_react_default.a.createElement("span", null, "\uE91A"),
  30193. command: 'toggleLinkEditor'
  30194. },
  30195. 'remove': {
  30196. text: external_react_default.a.createElement("span", null, "\uE9AC"),
  30197. command: 'removeImage'
  30198. }
  30199. };
  30200. // CONCATENATED MODULE: ./renderers/atomics/Image/index.jsx
  30201. var Image_Image =
  30202. /*#__PURE__*/
  30203. function (_React$Component) {
  30204. inherits_default()(Image, _React$Component);
  30205. function Image() {
  30206. var _getPrototypeOf2;
  30207. var _this;
  30208. classCallCheck_default()(this, Image);
  30209. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  30210. args[_key] = arguments[_key];
  30211. }
  30212. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(Image)).call.apply(_getPrototypeOf2, [this].concat(args)));
  30213. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  30214. toolbarVisible: false,
  30215. toolbarOffset: 0,
  30216. linkEditorVisible: false,
  30217. sizeEditorVisible: false,
  30218. tempLink: null,
  30219. tempWidth: null,
  30220. tempHeight: null
  30221. });
  30222. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "initialLeft", void 0);
  30223. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "initialTop", void 0);
  30224. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "initialWidth", void 0);
  30225. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "initialHeight", void 0);
  30226. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "reSizeType", void 0);
  30227. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "changeSize", function (e) {
  30228. var type = _this.reSizeType;
  30229. if (!_this.initialLeft) {
  30230. _this.initialLeft = e.screenX;
  30231. _this.initialTop = e.screenY;
  30232. }
  30233. if (type === 'rightbottom') {
  30234. _this.initialHeight += e.screenY - _this.initialTop;
  30235. _this.initialWidth += e.screenX - _this.initialLeft;
  30236. }
  30237. if (type === 'leftbottom') {
  30238. _this.initialHeight += e.screenY - _this.initialTop;
  30239. _this.initialWidth += -e.screenX + _this.initialLeft;
  30240. }
  30241. _this.initialLeft = e.screenX;
  30242. _this.initialTop = e.screenY;
  30243. });
  30244. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "moveImage", function (e) {
  30245. _this.changeSize(e);
  30246. _this.setState({
  30247. tempWidth: Math.abs(_this.initialWidth),
  30248. tempHeight: Math.abs(_this.initialHeight)
  30249. });
  30250. });
  30251. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "upImage", function () {
  30252. _this.confirmImageSize();
  30253. document.removeEventListener('mousemove', _this.moveImage);
  30254. document.removeEventListener('mouseup', _this.upImage);
  30255. });
  30256. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "repareChangeSize", function (type) {
  30257. return function (e) {
  30258. _this.reSizeType = type;
  30259. var imageRect = _this.imageElement.getBoundingClientRect();
  30260. _this.initialLeft = _this.initialTop = 0;
  30261. _this.initialWidth = imageRect.width;
  30262. _this.initialHeight = imageRect.height;
  30263. e.preventDefault();
  30264. document.addEventListener('mousemove', _this.moveImage);
  30265. document.addEventListener('mouseup', _this.upImage);
  30266. };
  30267. });
  30268. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "preventDragEvent", function (event) {
  30269. event.stopPropagation();
  30270. event.preventDefault();
  30271. });
  30272. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleDragStart", function () {
  30273. if (_this.props.editor.editorProps.readOnly || _this.props.editor.editorProps.disabled) {
  30274. return false;
  30275. }
  30276. window.__BRAFT_DRAGING__IMAGE__ = {
  30277. block: _this.props.block,
  30278. mediaData: objectSpread_default()({
  30279. type: 'IMAGE'
  30280. }, _this.props.mediaData)
  30281. };
  30282. _this.setState({
  30283. toolbarVisible: false
  30284. }, function () {
  30285. _this.unlockEditor();
  30286. });
  30287. return true;
  30288. });
  30289. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleDragEnd", function () {
  30290. window.__BRAFT_DRAGING__IMAGE__ = null;
  30291. return false;
  30292. });
  30293. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "executeCommand", function (command) {
  30294. if (typeof command === 'string') {
  30295. var _command$split = command.split('|'),
  30296. _command$split2 = slicedToArray_default()(_command$split, 2),
  30297. method = _command$split2[0],
  30298. param = _command$split2[1];
  30299. _this[method] && _this[method](param);
  30300. } else if (typeof command === 'function') {
  30301. command(_this.props.block, _this.props.mediaData, _this.props.editor.getValue());
  30302. }
  30303. });
  30304. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeImage", function () {
  30305. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editor.getValue(), _this.props.block));
  30306. _this.unlockEditor();
  30307. });
  30308. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggleLinkEditor", function () {
  30309. _this.setState({
  30310. linkEditorVisible: !_this.state.linkEditorVisible,
  30311. sizeEditorVisible: false
  30312. });
  30313. });
  30314. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggleSizeEditor", function () {
  30315. _this.setState({
  30316. linkEditorVisible: false,
  30317. sizeEditorVisible: !_this.state.sizeEditorVisible
  30318. });
  30319. });
  30320. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleLinkInputKeyDown", function (e) {
  30321. if (e.keyCode === 13) {
  30322. _this.confirmImageLink();
  30323. } else {
  30324. return;
  30325. }
  30326. });
  30327. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageLink", function (e) {
  30328. _this.setState({
  30329. tempLink: e.currentTarget.value
  30330. });
  30331. return;
  30332. });
  30333. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "confirmImageLink", function () {
  30334. var link = _this.state.tempLink;
  30335. var hookReturns = _this.props.hooks('set-image-link', link)(link);
  30336. if (hookReturns === false) {
  30337. return false;
  30338. }
  30339. if (typeof hookReturns === 'string') {
  30340. link = hookReturns;
  30341. }
  30342. if (link !== null) {
  30343. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaData(_this.props.editor.getValue(), _this.props.entityKey, {
  30344. link: link
  30345. }));
  30346. window.setImmediate(_this.props.editor.forceRender);
  30347. }
  30348. });
  30349. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleSizeInputKeyDown", function (e) {
  30350. if (e.keyCode === 13) {
  30351. _this.confirmImageSize();
  30352. } else {
  30353. return;
  30354. }
  30355. });
  30356. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageWidth", function (_ref) {
  30357. var currentTarget = _ref.currentTarget;
  30358. var value = currentTarget.value;
  30359. value && !isNaN(value) && (value = value + 'px');
  30360. _this.setState({
  30361. tempWidth: value
  30362. });
  30363. return;
  30364. });
  30365. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageHeight", function (_ref2) {
  30366. var currentTarget = _ref2.currentTarget;
  30367. var value = currentTarget.value;
  30368. value && !isNaN(value) && (value = value + 'px');
  30369. _this.setState({
  30370. tempHeight: value
  30371. });
  30372. return;
  30373. });
  30374. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "confirmImageSize", function () {
  30375. var _this$state = _this.state,
  30376. width = _this$state.tempWidth,
  30377. height = _this$state.tempHeight;
  30378. var newImageSize = {};
  30379. width !== null && (newImageSize.width = width);
  30380. height !== null && (newImageSize.height = height);
  30381. var hookReturns = _this.props.hooks('set-image-size', newImageSize)(newImageSize);
  30382. if (hookReturns === false) {
  30383. return false;
  30384. }
  30385. if (hookReturns && (hookReturns.width || hookReturns.height)) {
  30386. newImageSize = hookReturns;
  30387. }
  30388. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaData(_this.props.editor.getValue(), _this.props.entityKey, newImageSize));
  30389. window.setImmediate(_this.props.editor.forceRender);
  30390. });
  30391. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageFloat", function (float) {
  30392. var hookReturns = _this.props.hooks('set-image-float', float)(float);
  30393. if (hookReturns === false) {
  30394. return false;
  30395. }
  30396. if (typeof hookReturns === 'string') {
  30397. float = hookReturns;
  30398. }
  30399. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaPosition(_this.props.editor.getValue(), _this.props.block, {
  30400. float: float
  30401. }));
  30402. _this.unlockEditor();
  30403. });
  30404. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setImageAlignment", function (alignment) {
  30405. var hookReturns = _this.props.hooks('set-image-alignment', alignment)(alignment);
  30406. if (hookReturns === false) {
  30407. return false;
  30408. }
  30409. if (typeof hookReturns === 'string') {
  30410. alignment = hookReturns;
  30411. }
  30412. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaPosition(_this.props.editor.getValue(), _this.props.block, {
  30413. alignment: alignment
  30414. }));
  30415. _this.unlockEditor();
  30416. });
  30417. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "showToolbar", function (event) {
  30418. if (_this.props.editor.editorProps.readOnly || _this.props.editor.editorProps.disabled) {
  30419. return false;
  30420. }
  30421. event.preventDefault();
  30422. if (!_this.state.toolbarVisible) {
  30423. _this.setState({
  30424. toolbarVisible: true
  30425. }, function () {
  30426. _this.lockEditor();
  30427. _this.setState({
  30428. toolbarOffset: _this.calcToolbarOffset()
  30429. });
  30430. });
  30431. }
  30432. });
  30433. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "hideToolbar", function (event) {
  30434. event.preventDefault();
  30435. _this.setState({
  30436. toolbarVisible: false
  30437. }, function () {
  30438. _this.unlockEditor(); // this.props.editor.requestFocus()
  30439. });
  30440. });
  30441. return _this;
  30442. }
  30443. createClass_default()(Image, [{
  30444. key: "render",
  30445. value: function render() {
  30446. var _this2 = this;
  30447. var _this$props = this.props,
  30448. mediaData = _this$props.mediaData,
  30449. language = _this$props.language,
  30450. imageControls = _this$props.imageControls,
  30451. imageResizable = _this$props.imageResizable;
  30452. var _this$state2 = this.state,
  30453. toolbarVisible = _this$state2.toolbarVisible,
  30454. toolbarOffset = _this$state2.toolbarOffset,
  30455. linkEditorVisible = _this$state2.linkEditorVisible,
  30456. sizeEditorVisible = _this$state2.sizeEditorVisible,
  30457. tempWidth = _this$state2.tempWidth,
  30458. tempHeight = _this$state2.tempHeight;
  30459. var blockData = this.props.block.getData();
  30460. var float = blockData.get('float');
  30461. var alignment = blockData.get('alignment');
  30462. var url = mediaData.url,
  30463. link = mediaData.link,
  30464. link_target = mediaData.link_target,
  30465. width = mediaData.width,
  30466. height = mediaData.height,
  30467. meta = mediaData.meta;
  30468. var imageStyles = {};
  30469. var clearFix = false;
  30470. if (float) {
  30471. alignment = null;
  30472. } else if (alignment === 'left') {
  30473. imageStyles.float = 'left';
  30474. clearFix = true;
  30475. } else if (alignment === 'right') {
  30476. imageStyles.float = 'right';
  30477. clearFix = true;
  30478. } else if (alignment === 'center') {
  30479. imageStyles.textAlign = 'center';
  30480. } else {
  30481. imageStyles.float = 'left';
  30482. clearFix = true;
  30483. }
  30484. var renderedControlItems = imageControls.map(function (item, index) {
  30485. if (typeof item === 'string' && imageControlItems[item]) {
  30486. return external_react_default.a.createElement("a", {
  30487. className: item === 'link' && link ? 'active' : '',
  30488. key: index,
  30489. onClick: function onClick() {
  30490. return _this2.executeCommand(imageControlItems[item].command);
  30491. }
  30492. }, imageControlItems[item].text);
  30493. } else if (item && (item.render || item.text)) {
  30494. return item.render ? item.render(mediaData, _this2.props.block) : external_react_default.a.createElement("a", {
  30495. key: index,
  30496. onClick: function onClick() {
  30497. return item.onClick && _this2.executeCommand(item.onClick);
  30498. }
  30499. }, item.text);
  30500. } else {
  30501. return null;
  30502. }
  30503. });
  30504. return external_react_default.a.createElement("div", {
  30505. className: "bf-media"
  30506. }, external_react_default.a.createElement("div", {
  30507. style: imageStyles,
  30508. draggable: true,
  30509. onMouseEnter: this.showToolbar,
  30510. onMouseMove: this.showToolbar,
  30511. onMouseLeave: this.hideToolbar,
  30512. onDragStart: this.handleDragStart,
  30513. onDragEnd: this.handleDragEnd,
  30514. ref: function ref(instance) {
  30515. return _this2.mediaEmbederInstance = instance;
  30516. },
  30517. className: "bf-image"
  30518. }, toolbarVisible ? external_react_default.a.createElement("div", {
  30519. style: {
  30520. marginLeft: toolbarOffset
  30521. },
  30522. ref: function ref(instance) {
  30523. return _this2.toolbarElement = instance;
  30524. },
  30525. "data-float": float,
  30526. "data-align": alignment,
  30527. className: "bf-media-toolbar"
  30528. }, linkEditorVisible ? external_react_default.a.createElement("div", {
  30529. className: "bf-image-link-editor"
  30530. }, external_react_default.a.createElement("div", {
  30531. className: "editor-input-group"
  30532. }, external_react_default.a.createElement("input", {
  30533. type: "text",
  30534. placeholder: language.linkEditor.inputWithEnterPlaceHolder,
  30535. onKeyDown: this.handleLinkInputKeyDown,
  30536. onChange: this.setImageLink,
  30537. defaultValue: link
  30538. }), external_react_default.a.createElement("button", {
  30539. type: "button",
  30540. onClick: this.confirmImageLink
  30541. }, language.base.confirm)), external_react_default.a.createElement("div", {
  30542. className: "switch-group"
  30543. }, external_react_default.a.createElement(Switch, {
  30544. active: link_target === '_blank',
  30545. onClick: function onClick() {
  30546. return _this2.setImageLinkTarget(link_target);
  30547. }
  30548. }), external_react_default.a.createElement("label", null, language.linkEditor.openInNewWindow))) : null, sizeEditorVisible ? external_react_default.a.createElement("div", {
  30549. className: "bf-image-size-editor"
  30550. }, external_react_default.a.createElement("div", {
  30551. className: "editor-input-group"
  30552. }, external_react_default.a.createElement("input", {
  30553. type: "text",
  30554. placeholder: language.base.width,
  30555. onKeyDown: this.handleSizeInputKeyDown,
  30556. onChange: this.setImageWidth,
  30557. defaultValue: width
  30558. }), external_react_default.a.createElement("input", {
  30559. type: "text",
  30560. placeholder: language.base.height,
  30561. onKeyDown: this.handleSizeInputKeyDown,
  30562. onChange: this.setImageHeight,
  30563. defaultValue: height
  30564. }), external_react_default.a.createElement("button", {
  30565. type: "button",
  30566. onClick: this.confirmImageSize
  30567. }, language.base.confirm))) : null, renderedControlItems, external_react_default.a.createElement("i", {
  30568. style: {
  30569. marginLeft: toolbarOffset * -1
  30570. },
  30571. className: "bf-media-toolbar-arrow"
  30572. })) : null, external_react_default.a.createElement("div", {
  30573. style: {
  30574. position: 'relative',
  30575. width: "".concat(width, "px"),
  30576. height: "".concat(height, "px"),
  30577. display: 'inline-block'
  30578. }
  30579. }, external_react_default.a.createElement("img", extends_default()({
  30580. ref: function ref(instance) {
  30581. return _this2.imageElement = instance;
  30582. },
  30583. src: url,
  30584. width: width,
  30585. height: height
  30586. }, meta)), toolbarVisible && imageResizable ? external_react_default.a.createElement("div", {
  30587. className: "bf-csize-icon right-bottom",
  30588. onMouseDown: this.repareChangeSize('rightbottom')
  30589. }) : null, toolbarVisible && imageResizable ? external_react_default.a.createElement("div", {
  30590. className: "bf-csize-icon left-bottom",
  30591. onMouseDown: this.repareChangeSize('leftbottom')
  30592. }) : null, external_react_default.a.createElement("div", {
  30593. className: "bf-pre-csize ".concat(this.reSizeType),
  30594. style: {
  30595. width: "".concat(tempWidth, "px"),
  30596. height: "".concat(tempHeight, "px")
  30597. }
  30598. }))), clearFix && external_react_default.a.createElement("div", {
  30599. className: "clearfix",
  30600. style: {
  30601. clear: 'both',
  30602. height: 0,
  30603. lineHeight: 0,
  30604. float: 'none'
  30605. }
  30606. }));
  30607. }
  30608. }, {
  30609. key: "lockEditor",
  30610. value: function lockEditor() {
  30611. this.props.editor.lockOrUnlockEditor(true);
  30612. }
  30613. }, {
  30614. key: "unlockEditor",
  30615. value: function unlockEditor() {
  30616. this.props.editor.lockOrUnlockEditor(false);
  30617. }
  30618. }, {
  30619. key: "calcToolbarOffset",
  30620. value: function calcToolbarOffset() {
  30621. var _this$props2 = this.props,
  30622. getContainerNode = _this$props2.getContainerNode,
  30623. containerNode = _this$props2.containerNode;
  30624. var container = getContainerNode ? getContainerNode() : containerNode;
  30625. if (!container) {
  30626. return 0;
  30627. }
  30628. var viewRect = container.querySelector('.bf-content').getBoundingClientRect();
  30629. var toolbarRect = this.toolbarElement.getBoundingClientRect();
  30630. var imageRect = this.imageElement.getBoundingClientRect();
  30631. var right = viewRect.right - (imageRect.right - imageRect.width / 2 + toolbarRect.width / 2);
  30632. var left = imageRect.left + imageRect.width / 2 - toolbarRect.width / 2 - viewRect.left;
  30633. if (right < 10) {
  30634. return right - 10;
  30635. } else if (left < 10) {
  30636. return left * -1 + 10;
  30637. } else {
  30638. return 0;
  30639. }
  30640. }
  30641. }, {
  30642. key: "setImageLinkTarget",
  30643. value: function setImageLinkTarget(link_target) {
  30644. var hookReturns = this.props.hooks('set-image-link-target', link_target)(link_target);
  30645. if (hookReturns === false) {
  30646. return false;
  30647. }
  30648. if (typeof hookReturns === 'string') {
  30649. link_target = hookReturns;
  30650. }
  30651. link_target = link_target === '_blank' ? '' : '_blank';
  30652. this.props.editor.setValue(external_braft_utils_["ContentUtils"].setMediaData(this.props.editor.getValue(), this.props.entityKey, {
  30653. link_target: link_target
  30654. }));
  30655. window.setImmediate(this.props.editor.forceRender);
  30656. }
  30657. }]);
  30658. return Image;
  30659. }(external_react_default.a.Component);
  30660. // EXTERNAL MODULE: ./renderers/atomics/Video/style.scss
  30661. var Video_style = __webpack_require__(47);
  30662. // EXTERNAL MODULE: ./components/common/Modal/style.scss
  30663. var Modal_style = __webpack_require__(48);
  30664. // EXTERNAL MODULE: external "react-dom"
  30665. var external_react_dom_ = __webpack_require__(16);
  30666. var external_react_dom_default = /*#__PURE__*/__webpack_require__.n(external_react_dom_);
  30667. // CONCATENATED MODULE: ./components/common/Modal/index.jsx
  30668. var Modal_Modal =
  30669. /*#__PURE__*/
  30670. function (_React$Component) {
  30671. inherits_default()(Modal, _React$Component);
  30672. function Modal(props) {
  30673. var _this;
  30674. classCallCheck_default()(this, Modal);
  30675. _this = possibleConstructorReturn_default()(this, getPrototypeOf_default()(Modal).call(this, props));
  30676. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleTransitionEnd", function () {
  30677. if (!_this.rootElement || !_this.rootElement.classList) {
  30678. return false;
  30679. }
  30680. if (!_this.rootElement.classList.contains('active')) {
  30681. external_react_dom_default.a.unmountComponentAtNode(_this.rootElement) && _this.rootElement.parentNode.removeChild(_this.rootElement);
  30682. }
  30683. });
  30684. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleMouseDown", function (event) {
  30685. var tagName = event.target.tagName.toLowerCase();
  30686. if (tagName === 'input' || tagName === 'textarea') {
  30687. return false;
  30688. }
  30689. event.preventDefault();
  30690. });
  30691. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleCancel", function () {
  30692. _this.props.closeOnCancel && _this.close();
  30693. _this.props.onCancel && _this.props.onCancel();
  30694. });
  30695. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleConfirm", function () {
  30696. _this.props.closeOnConfirm && _this.close();
  30697. _this.props.onConfirm && _this.props.onConfirm();
  30698. });
  30699. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleMaskClick", function () {
  30700. _this.props.closeOnBlur && _this.close();
  30701. _this.props.onBlue && _this.props.onBlue();
  30702. });
  30703. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "close", function () {
  30704. _this.unrenderComponent();
  30705. _this.props.onClose && _this.props.onClose();
  30706. });
  30707. _this.active = false;
  30708. _this.componentId = 'BRAFT-MODAL-' + external_braft_utils_["BaseUtils"].UniqueIndex();
  30709. return _this;
  30710. }
  30711. createClass_default()(Modal, [{
  30712. key: "componentDidMount",
  30713. value: function componentDidMount() {
  30714. if (this.props.visible) {
  30715. this.active = true;
  30716. this.renderComponent(this.props);
  30717. }
  30718. }
  30719. }, {
  30720. key: "componentWillReceiveProps",
  30721. value: function componentWillReceiveProps(next) {
  30722. if (this.props.visible && !next.visible) {
  30723. this.unrenderComponent();
  30724. } else if (this.props.visible || next.visible) {
  30725. this.active = true;
  30726. this.renderComponent(next);
  30727. }
  30728. }
  30729. }, {
  30730. key: "render",
  30731. value: function render() {
  30732. return null;
  30733. }
  30734. }, {
  30735. key: "unrenderComponent",
  30736. value: function unrenderComponent() {
  30737. this.active = false;
  30738. this.activeId && window.clearImmediate(this.activeId);
  30739. if (this.rootElement && this.rootElement.classList) {
  30740. this.rootElement.classList.remove('active');
  30741. }
  30742. }
  30743. }, {
  30744. key: "renderComponent",
  30745. value: function renderComponent(props) {
  30746. var _this2 = this;
  30747. if (!this.active) {
  30748. return false;
  30749. }
  30750. var title = props.title,
  30751. className = props.className,
  30752. width = props.width,
  30753. height = props.height,
  30754. children = props.children,
  30755. component = props.component,
  30756. confirmable = props.confirmable,
  30757. showFooter = props.showFooter,
  30758. showCancel = props.showCancel,
  30759. showConfirm = props.showConfirm,
  30760. showClose = props.showClose,
  30761. cancelText = props.cancelText,
  30762. confirmText = props.confirmText,
  30763. bottomText = props.bottomText,
  30764. language = props.language;
  30765. typeof showCancel === 'undefined' && (showCancel = true);
  30766. typeof showClose === 'undefined' && (showClose = true);
  30767. typeof showConfirm === 'undefined' && (showConfirm = true);
  30768. typeof showFooter === 'undefined' && (showFooter = true);
  30769. var childComponent = external_react_default.a.createElement("div", {
  30770. onMouseDown: this.handleMouseDown,
  30771. className: 'bf-modal ' + (className || '')
  30772. }, external_react_default.a.createElement("div", {
  30773. className: "bf-modal-mask",
  30774. onClick: this.handleMaskClick
  30775. }), external_react_default.a.createElement("div", {
  30776. onTransitionEnd: this.handleTransitionEnd,
  30777. style: {
  30778. width: width,
  30779. height: height
  30780. },
  30781. className: "bf-modal-content"
  30782. }, external_react_default.a.createElement("div", {
  30783. className: "bf-modal-header"
  30784. }, external_react_default.a.createElement("h3", {
  30785. className: "bf-modal-caption"
  30786. }, title), showClose && external_react_default.a.createElement("button", {
  30787. type: "button",
  30788. onClick: this.close,
  30789. className: "bf-modal-close-button"
  30790. }, external_react_default.a.createElement("i", {
  30791. className: "bfi-close"
  30792. }))), external_react_default.a.createElement("div", {
  30793. className: "bf-modal-body"
  30794. }, children || component), showFooter ? external_react_default.a.createElement("div", {
  30795. className: "bf-modal-footer"
  30796. }, external_react_default.a.createElement("div", {
  30797. className: "bf-modal-addon-text"
  30798. }, bottomText), external_react_default.a.createElement("div", {
  30799. className: "bf-modal-buttons"
  30800. }, showCancel && external_react_default.a.createElement("button", {
  30801. type: "button",
  30802. onClick: this.handleCancel,
  30803. className: "bf-modal-cancel"
  30804. }, cancelText || language.base.cancel), showConfirm && external_react_default.a.createElement("button", {
  30805. type: "button",
  30806. onClick: this.handleConfirm,
  30807. className: 'bf-modal-confirm ' + (!confirmable ? 'disabled' : '')
  30808. }, confirmText || language.base.confirm))) : null));
  30809. this.rootElement = document.querySelector('#' + this.componentId);
  30810. if (!this.rootElement) {
  30811. this.rootElement = document.createElement('div');
  30812. this.rootElement.id = this.componentId;
  30813. this.rootElement.className = 'bf-modal-root';
  30814. document.body.appendChild(this.rootElement);
  30815. }
  30816. external_react_dom_default.a.render(childComponent, this.rootElement);
  30817. this.activeId = window.setImmediate(function () {
  30818. _this2.rootElement.classList.add('active');
  30819. });
  30820. }
  30821. }]);
  30822. return Modal;
  30823. }(external_react_default.a.Component);
  30824. defineProperty_default()(Modal_Modal, "defaultProps", {
  30825. showFooter: true,
  30826. closeOnBlur: true
  30827. });
  30828. var Modal_showModal = function showModal(props) {
  30829. var hostNode = document.createElement('div');
  30830. hostNode.style.display = 'none';
  30831. document.body.appendChild(hostNode);
  30832. props = objectSpread_default()({
  30833. visible: true,
  30834. closeOnConfirm: true,
  30835. closeOnCancel: true
  30836. }, props);
  30837. var close = function close() {
  30838. external_react_dom_default.a.unmountComponentAtNode(hostNode) && hostNode.parentNode.removeChild(hostNode);
  30839. };
  30840. var onConfirm = function onConfirm() {
  30841. props.onConfirm && props.onConfirm();
  30842. };
  30843. var onCancel = function onCancel() {
  30844. props.onCancel && props.onCancel();
  30845. };
  30846. var onClose = function onClose() {
  30847. close();
  30848. props.onClose && props.onClose();
  30849. };
  30850. var modalInstance = external_react_dom_default.a.render(external_react_default.a.createElement(Modal_Modal, extends_default()({}, props, {
  30851. onConfirm: onConfirm,
  30852. onCancel: onCancel,
  30853. onClose: onClose
  30854. })), hostNode);
  30855. modalInstance.destroy = close;
  30856. modalInstance.update = modalInstance.renderComponent;
  30857. return modalInstance;
  30858. };
  30859. // EXTERNAL MODULE: ./components/business/PlayerModal/style.scss
  30860. var PlayerModal_style = __webpack_require__(49);
  30861. // CONCATENATED MODULE: ./components/business/PlayerModal/index.jsx
  30862. var PlayerModal_playViaModal = function playViaModal(title, component, language) {
  30863. return Modal_showModal({
  30864. title: title,
  30865. component: component,
  30866. language: language,
  30867. showFooter: false
  30868. });
  30869. };
  30870. var typeIconsMap = {
  30871. 'video': 'bfi-film',
  30872. 'audio': 'bfi-music',
  30873. 'embed': 'bfi-code'
  30874. };
  30875. /* harmony default export */ var PlayerModal = (function (_ref) {
  30876. var title = _ref.title,
  30877. type = _ref.type,
  30878. language = _ref.language,
  30879. name = _ref.name,
  30880. url = _ref.url,
  30881. poster = _ref.poster,
  30882. children = _ref.children,
  30883. onRemove = _ref.onRemove;
  30884. return external_react_default.a.createElement("div", {
  30885. className: "bf-player-holder ".concat(type)
  30886. }, external_react_default.a.createElement("div", {
  30887. className: "icon-badge"
  30888. }, external_react_default.a.createElement("i", {
  30889. className: typeIconsMap[type]
  30890. }), external_react_default.a.createElement("span", {
  30891. className: "text"
  30892. }, language.media[type])), external_react_default.a.createElement("button", {
  30893. onMouseDown: onRemove,
  30894. className: "button-remove"
  30895. }, external_react_default.a.createElement("i", {
  30896. className: "bfi-close"
  30897. })), external_react_default.a.createElement("button", {
  30898. onMouseDown: function onMouseDown() {
  30899. return PlayerModal_playViaModal(name ? "".concat(title, ":").concat(name) : title, children, language);
  30900. },
  30901. className: "button-play"
  30902. }, external_react_default.a.createElement("i", {
  30903. className: "bfi-play_arrow"
  30904. })), name ? external_react_default.a.createElement("h5", {
  30905. className: "bf-name"
  30906. }, name) : null, external_react_default.a.createElement("h6", {
  30907. className: "bf-url"
  30908. }, url), poster ? external_react_default.a.createElement("div", {
  30909. className: "bf-poster",
  30910. style: {
  30911. backgroundImage: "url(".concat(poster, ")")
  30912. }
  30913. }) : null);
  30914. });
  30915. // CONCATENATED MODULE: ./renderers/atomics/Video/index.jsx
  30916. var Video_Video =
  30917. /*#__PURE__*/
  30918. function (_React$Component) {
  30919. inherits_default()(Video, _React$Component);
  30920. function Video() {
  30921. var _getPrototypeOf2;
  30922. var _this;
  30923. classCallCheck_default()(this, Video);
  30924. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  30925. args[_key] = arguments[_key];
  30926. }
  30927. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(Video)).call.apply(_getPrototypeOf2, [this].concat(args)));
  30928. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeVideo", function () {
  30929. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editorState, _this.props.block));
  30930. });
  30931. return _this;
  30932. }
  30933. createClass_default()(Video, [{
  30934. key: "render",
  30935. value: function render() {
  30936. var _this$props = this.props,
  30937. mediaData = _this$props.mediaData,
  30938. language = _this$props.language;
  30939. var url = mediaData.url,
  30940. name = mediaData.name,
  30941. meta = mediaData.meta;
  30942. return external_react_default.a.createElement("div", {
  30943. className: "bf-video-wrap"
  30944. }, external_react_default.a.createElement(PlayerModal, {
  30945. type: "video",
  30946. onRemove: this.removeVideo,
  30947. poster: meta ? meta.poster || '' : '',
  30948. language: language,
  30949. url: url,
  30950. name: name,
  30951. title: language.videoPlayer.title
  30952. }, external_react_default.a.createElement("div", {
  30953. className: "bf-video-player"
  30954. }, external_react_default.a.createElement("video", {
  30955. controls: true,
  30956. poster: meta ? meta.poster || '' : ''
  30957. }, external_react_default.a.createElement("source", {
  30958. src: url
  30959. })))));
  30960. }
  30961. }]);
  30962. return Video;
  30963. }(external_react_default.a.Component);
  30964. // EXTERNAL MODULE: ./renderers/atomics/Audio/style.scss
  30965. var Audio_style = __webpack_require__(50);
  30966. // CONCATENATED MODULE: ./renderers/atomics/Audio/index.jsx
  30967. var Audio_Audio =
  30968. /*#__PURE__*/
  30969. function (_React$Component) {
  30970. inherits_default()(Audio, _React$Component);
  30971. function Audio() {
  30972. var _getPrototypeOf2;
  30973. var _this;
  30974. classCallCheck_default()(this, Audio);
  30975. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  30976. args[_key] = arguments[_key];
  30977. }
  30978. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(Audio)).call.apply(_getPrototypeOf2, [this].concat(args)));
  30979. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeAudio", function () {
  30980. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editorState, _this.props.block));
  30981. });
  30982. return _this;
  30983. }
  30984. createClass_default()(Audio, [{
  30985. key: "render",
  30986. value: function render() {
  30987. var _this$props = this.props,
  30988. mediaData = _this$props.mediaData,
  30989. language = _this$props.language;
  30990. var url = mediaData.url,
  30991. name = mediaData.name,
  30992. meta = mediaData.meta;
  30993. return external_react_default.a.createElement("div", {
  30994. className: "bf-audio-wrap"
  30995. }, external_react_default.a.createElement(PlayerModal, {
  30996. type: "audio",
  30997. onRemove: this.removeAudio,
  30998. poster: meta ? meta.poster || '' : '',
  30999. language: language,
  31000. url: url,
  31001. name: name,
  31002. title: language.audioPlayer.title
  31003. }, external_react_default.a.createElement("div", {
  31004. className: "bf-audio-player"
  31005. }, external_react_default.a.createElement("audio", {
  31006. controls: true,
  31007. src: url
  31008. }))));
  31009. }
  31010. }]);
  31011. return Audio;
  31012. }(external_react_default.a.Component);
  31013. // EXTERNAL MODULE: ./renderers/atomics/Embed/style.scss
  31014. var Embed_style = __webpack_require__(51);
  31015. // CONCATENATED MODULE: ./renderers/atomics/Embed/index.jsx
  31016. var Embed_Embed =
  31017. /*#__PURE__*/
  31018. function (_React$Component) {
  31019. inherits_default()(Embed, _React$Component);
  31020. function Embed() {
  31021. var _getPrototypeOf2;
  31022. var _this;
  31023. classCallCheck_default()(this, Embed);
  31024. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  31025. args[_key] = arguments[_key];
  31026. }
  31027. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(Embed)).call.apply(_getPrototypeOf2, [this].concat(args)));
  31028. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeEmbed", function () {
  31029. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editorState, _this.props.block));
  31030. });
  31031. return _this;
  31032. }
  31033. createClass_default()(Embed, [{
  31034. key: "render",
  31035. value: function render() {
  31036. var _this$props = this.props,
  31037. mediaData = _this$props.mediaData,
  31038. language = _this$props.language;
  31039. var name = mediaData.name,
  31040. url = mediaData.url,
  31041. meta = mediaData.meta;
  31042. return external_react_default.a.createElement("div", {
  31043. className: "bf-embed-wrap"
  31044. }, external_react_default.a.createElement(PlayerModal, {
  31045. type: "embed",
  31046. onRemove: this.removeEmbed,
  31047. poster: meta ? meta.poster || '' : '',
  31048. language: language,
  31049. url: url,
  31050. name: name,
  31051. title: language.videoPlayer.embedTitle
  31052. }, external_react_default.a.createElement("div", {
  31053. className: "bf-embed-player",
  31054. dangerouslySetInnerHTML: {
  31055. __html: url
  31056. }
  31057. })));
  31058. }
  31059. }]);
  31060. return Embed;
  31061. }(external_react_default.a.Component);
  31062. // EXTERNAL MODULE: ./renderers/atomics/HorizontalLine/style.scss
  31063. var HorizontalLine_style = __webpack_require__(52);
  31064. // CONCATENATED MODULE: ./renderers/atomics/HorizontalLine/index.jsx
  31065. var HorizontalLine_HorizontalLine =
  31066. /*#__PURE__*/
  31067. function (_React$Component) {
  31068. inherits_default()(HorizontalLine, _React$Component);
  31069. function HorizontalLine() {
  31070. var _getPrototypeOf2;
  31071. var _this;
  31072. classCallCheck_default()(this, HorizontalLine);
  31073. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  31074. args[_key] = arguments[_key];
  31075. }
  31076. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(HorizontalLine)).call.apply(_getPrototypeOf2, [this].concat(args)));
  31077. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeHorizontalLine", function () {
  31078. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].removeBlock(_this.props.editorState, _this.props.block));
  31079. });
  31080. return _this;
  31081. }
  31082. createClass_default()(HorizontalLine, [{
  31083. key: "render",
  31084. value: function render() {
  31085. return external_react_default.a.createElement("div", {
  31086. className: "bf-hr"
  31087. }, external_react_default.a.createElement("div", {
  31088. className: "bf-media-toolbar"
  31089. }, external_react_default.a.createElement("a", {
  31090. onClick: this.removeHorizontalLine
  31091. }, "\uE9AC")));
  31092. }
  31093. }]);
  31094. return HorizontalLine;
  31095. }(external_react_default.a.Component);
  31096. // CONCATENATED MODULE: ./renderers/block/blockRendererFn.js
  31097. var blockRendererFn_BlockRenderFnContext = function BlockRenderFnContext() {
  31098. var _this = this;
  31099. classCallCheck_default()(this, BlockRenderFnContext);
  31100. defineProperty_default()(this, "superProps", void 0);
  31101. defineProperty_default()(this, "customBlockRendererFn", void 0);
  31102. defineProperty_default()(this, "getRenderFn", function (superProps, customBlockRendererFn) {
  31103. _this.superProps = superProps;
  31104. _this.customBlockRendererFn = customBlockRendererFn;
  31105. return _this.blockRendererFn;
  31106. });
  31107. defineProperty_default()(this, "renderAtomicBlock", function (props) {
  31108. var superProps = _this.superProps;
  31109. var entityKey = props.block.getEntityAt(0);
  31110. if (!entityKey) {
  31111. return null;
  31112. }
  31113. var entity = props.contentState.getEntity(entityKey);
  31114. var mediaData = entity.getData();
  31115. var mediaType = entity.getType();
  31116. var mediaProps = objectSpread_default()({}, superProps, {
  31117. block: props.block,
  31118. mediaData: mediaData,
  31119. entityKey: entityKey
  31120. });
  31121. if (mediaType === 'IMAGE') {
  31122. return external_react_default.a.createElement(Image_Image, mediaProps);
  31123. } else if (mediaType === 'AUDIO') {
  31124. return external_react_default.a.createElement(Audio_Audio, mediaProps);
  31125. } else if (mediaType === 'VIDEO') {
  31126. return external_react_default.a.createElement(Video_Video, mediaProps);
  31127. } else if (mediaType === 'EMBED') {
  31128. return external_react_default.a.createElement(Embed_Embed, mediaProps);
  31129. } else if (mediaType === 'HR') {
  31130. return external_react_default.a.createElement(HorizontalLine_HorizontalLine, mediaProps);
  31131. }
  31132. if (superProps.extendAtomics) {
  31133. var atomics = superProps.extendAtomics;
  31134. for (var i = 0; i < atomics.length; i++) {
  31135. if (mediaType === atomics[i].type) {
  31136. var Component = atomics[i].component;
  31137. return external_react_default.a.createElement(Component, mediaProps);
  31138. }
  31139. }
  31140. }
  31141. return null;
  31142. });
  31143. defineProperty_default()(this, "blockRendererFn", function (block) {
  31144. var customBlockRendererFn = _this.customBlockRendererFn,
  31145. superProps = _this.superProps;
  31146. var blockType = block.getType();
  31147. var blockRenderer = null;
  31148. if (customBlockRendererFn) {
  31149. blockRenderer = customBlockRendererFn(block, superProps) || null;
  31150. }
  31151. if (blockRenderer) {
  31152. return blockRenderer;
  31153. }
  31154. var extensionBlockRendererFns = getExtensionBlockRendererFns(superProps.editorId);
  31155. extensionBlockRendererFns.find(function (item) {
  31156. if (item.blockType === blockType || item.blockType instanceof RegExp && item.blockType.test(blockType)) {
  31157. blockRenderer = item.rendererFn ? item.rendererFn(superProps) : null;
  31158. return true;
  31159. }
  31160. });
  31161. if (blockRenderer) {
  31162. return blockRenderer;
  31163. }
  31164. if (blockType === 'atomic') {
  31165. blockRenderer = {
  31166. component: _this.renderAtomicBlock,
  31167. editable: false
  31168. };
  31169. }
  31170. return blockRenderer;
  31171. });
  31172. };
  31173. var blockRenderFnContext = new blockRendererFn_BlockRenderFnContext();
  31174. /* harmony default export */ var block_blockRendererFn = (blockRenderFnContext.getRenderFn);
  31175. // CONCATENATED MODULE: ./renderers/block/blockStyleFn.js
  31176. /* harmony default export */ var block_blockStyleFn = (function (customBlockStyleFn) {
  31177. return function (block) {
  31178. var blockAlignment = block.getData() && block.getData().get('textAlign');
  31179. var blockIndent = block.getData() && block.getData().get('textIndent');
  31180. var blockFloat = block.getData() && block.getData().get('float');
  31181. var result = '';
  31182. if (blockAlignment) {
  31183. result = "bfa-".concat(blockAlignment);
  31184. }
  31185. if (blockIndent && blockIndent !== 0) {
  31186. result += " bftd-".concat(blockIndent);
  31187. }
  31188. if (blockFloat) {
  31189. result += " bff-".concat(blockFloat);
  31190. }
  31191. if (customBlockStyleFn) {
  31192. result += customBlockStyleFn(block) || '';
  31193. }
  31194. return result;
  31195. };
  31196. });
  31197. // CONCATENATED MODULE: ./renderers/inline/inlineStyleMap.js
  31198. /* harmony default export */ var inlineStyleMap = (function (props) {
  31199. var customStyleMap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  31200. var extensionInlineStyleMap = getExtensionInlineStyleMap(props.editorId);
  31201. return objectSpread_default()({
  31202. 'SUPERSCRIPT': {
  31203. position: 'relative',
  31204. top: '-8px',
  31205. fontSize: '11px'
  31206. },
  31207. 'SUBSCRIPT': {
  31208. position: 'relative',
  31209. bottom: '-8px',
  31210. fontSize: '11px'
  31211. }
  31212. }, extensionInlineStyleMap, customStyleMap);
  31213. });
  31214. // CONCATENATED MODULE: ./renderers/inline/inlineStyleFn.js
  31215. var getStyleValue = function getStyleValue(style) {
  31216. return style.split('-')[1];
  31217. };
  31218. /* harmony default export */ var inlineStyleFn = (function (props, options) {
  31219. return function (styles, block) {
  31220. var output = {};
  31221. var fontFamilies = options.fontFamilies,
  31222. unitExportFn = options.unitExportFn,
  31223. customStyleFn = options.customStyleFn;
  31224. var extensionInlineStyleFns = getExtensionInlineStyleFns(props.editorId);
  31225. extensionInlineStyleFns.forEach(function (item) {
  31226. output = item.styleFn ? item.styleFn(styles, block, output) : output;
  31227. });
  31228. output = customStyleFn ? customStyleFn(styles, block, output) : {};
  31229. styles.forEach(function (style) {
  31230. if (style.indexOf('COLOR-') === 0) {
  31231. output.color = '#' + getStyleValue(style);
  31232. } else if (style.indexOf('BGCOLOR-') === 0) {
  31233. output.backgroundColor = '#' + getStyleValue(style);
  31234. } else if (style.indexOf('FONTSIZE-') === 0) {
  31235. output.fontSize = unitExportFn(getStyleValue(style), 'font-size', 'editor');
  31236. } else if (style.indexOf('LINEHEIGHT-') === 0) {
  31237. output.lineHeight = unitExportFn(getStyleValue(style), 'line-height', 'editor');
  31238. } else if (style.indexOf('LETTERSPACING-') === 0) {
  31239. output.letterSpacing = unitExportFn(getStyleValue(style), 'letter-spacing', 'editor');
  31240. } else if (style.indexOf('TEXTINDENT-') === 0) {
  31241. output.textIndent = unitExportFn(getStyleValue(style), 'text-indent', 'editor');
  31242. } else if (style.indexOf('FONTFAMILY-') === 0) {
  31243. output.fontFamily = (fontFamilies.find(function (item) {
  31244. return item.name.toUpperCase() === getStyleValue(style);
  31245. }) || {}).family || '';
  31246. }
  31247. });
  31248. return output;
  31249. };
  31250. });
  31251. // EXTERNAL MODULE: ../node_modules/draft-js-multidecorators/index.js
  31252. var draft_js_multidecorators = __webpack_require__(18);
  31253. var draft_js_multidecorators_default = /*#__PURE__*/__webpack_require__.n(draft_js_multidecorators);
  31254. // CONCATENATED MODULE: ./renderers/decorators/Link/index.jsx
  31255. /* harmony default export */ var Link = (function (props) {
  31256. var children = props.children,
  31257. entityKey = props.entityKey,
  31258. contentState = props.contentState;
  31259. var _contentState$getEnti = contentState.getEntity(entityKey).getData(),
  31260. href = _contentState$getEnti.href,
  31261. target = _contentState$getEnti.target;
  31262. return external_react_default.a.createElement("span", {
  31263. className: "bf-link-wrap"
  31264. }, external_react_default.a.createElement("a", {
  31265. onClick: function onClick(event) {
  31266. return viewLink(event, href);
  31267. },
  31268. className: "bf-link",
  31269. href: href,
  31270. target: target
  31271. }, children));
  31272. });
  31273. var viewLink = function viewLink(event, link) {
  31274. // 当按下Ctrl/command键时,点击打开链接文字中的url
  31275. if (event.getModifierState('Control') || event.getModifierState('Meta')) {
  31276. var tempLink = document.createElement('a');
  31277. tempLink.href = link;
  31278. tempLink.target = event.currentTarget.target;
  31279. tempLink.click();
  31280. }
  31281. };
  31282. // CONCATENATED MODULE: ./renderers/decorators/index.js
  31283. var KEY_SEPARATOR = '-';
  31284. draft_js_multidecorators_default.a.prototype.getDecorations = function (block, contentState) {
  31285. var decorations = Array(block.getText().length).fill(null);
  31286. this.decorators.forEach(function (decorator, i) {
  31287. decorator.getDecorations(block, contentState).forEach(function (key, offset) {
  31288. if (!key) {
  31289. return;
  31290. }
  31291. key = i + KEY_SEPARATOR + key;
  31292. decorations[offset] = key;
  31293. });
  31294. });
  31295. return external_immutable_default.a.List(decorations);
  31296. };
  31297. var builtinDecorators = [{
  31298. type: 'entity',
  31299. decorator: {
  31300. key: 'LINK',
  31301. component: Link
  31302. }
  31303. }];
  31304. var createStrategy = function createStrategy(type) {
  31305. return function (block, callback, contentState) {
  31306. block.findEntityRanges(function (character) {
  31307. var entityKey = character.getEntity();
  31308. return entityKey !== null && contentState.getEntity(entityKey).getType() === type;
  31309. }, callback);
  31310. };
  31311. };
  31312. /* harmony default export */ var decorators = (function (editorId) {
  31313. var extensionDecorators = getExtensionDecorators(editorId);
  31314. var entityDecorators = builtinDecorators.concat(toConsumableArray_default()(extensionDecorators.filter(function (item) {
  31315. return item.type === 'entity';
  31316. })));
  31317. var strategyDecorators = extensionDecorators.filter(function (item) {
  31318. return item.type === 'strategy';
  31319. });
  31320. var classDecorators = extensionDecorators.filter(function (item) {
  31321. return item.type === 'class';
  31322. });
  31323. return new draft_js_multidecorators_default.a(toConsumableArray_default()(classDecorators.map(function (item) {
  31324. return item.decorator;
  31325. })).concat([// combine decorators created with strategy
  31326. new external_draft_js_["CompositeDecorator"](strategyDecorators.map(function (item) {
  31327. return item.decorator;
  31328. })), // combine decorators for entities
  31329. new external_draft_js_["CompositeDecorator"](entityDecorators.map(function (item) {
  31330. return {
  31331. strategy: createStrategy(item.decorator.key),
  31332. component: item.decorator.component
  31333. };
  31334. }))]));
  31335. });
  31336. // CONCATENATED MODULE: ./renderers/index.js
  31337. var getBlockRenderMap = block_blockRenderMap;
  31338. var getBlockRendererFn = block_blockRendererFn;
  31339. var getBlockStyleFn = block_blockStyleFn;
  31340. var getCustomStyleMap = inlineStyleMap;
  31341. var getCustomStyleFn = inlineStyleFn;
  31342. var getDecorators = decorators;
  31343. // EXTERNAL MODULE: ./components/business/ControlBar/style.scss
  31344. var ControlBar_style = __webpack_require__(53);
  31345. // EXTERNAL MODULE: ./components/business/LinkEditor/style.scss
  31346. var LinkEditor_style = __webpack_require__(54);
  31347. // EXTERNAL MODULE: ./components/common/DropDown/style.scss
  31348. var DropDown_style = __webpack_require__(55);
  31349. // CONCATENATED MODULE: ./helpers/responsive.js
  31350. var resizeEventHandlers = [];
  31351. var responsiveHelperInited = false;
  31352. var debouce = false;
  31353. /* harmony default export */ var responsive = ({
  31354. resolve: function resolve(eventHandler) {
  31355. var id = external_braft_utils_["BaseUtils"].UniqueIndex();
  31356. resizeEventHandlers.push({
  31357. id: id,
  31358. eventHandler: eventHandler
  31359. });
  31360. return id;
  31361. },
  31362. unresolve: function unresolve(id) {
  31363. resizeEventHandlers = resizeEventHandlers.filter(function (item) {
  31364. return item.id !== id;
  31365. });
  31366. }
  31367. });
  31368. if (!responsiveHelperInited && (typeof window === "undefined" ? "undefined" : typeof_default()(window)) === 'object') {
  31369. window.addEventListener('resize', function (event) {
  31370. clearTimeout(debouce);
  31371. debouce = setTimeout(function () {
  31372. resizeEventHandlers.map(function (item) {
  31373. typeof item.eventHandler === 'function' && item.eventHandler(event);
  31374. });
  31375. debouce = false;
  31376. }, 100);
  31377. });
  31378. responsiveHelperInited = true;
  31379. }
  31380. // CONCATENATED MODULE: ./components/common/DropDown/index.jsx
  31381. var DropDown_DropDown =
  31382. /*#__PURE__*/
  31383. function (_React$Component) {
  31384. inherits_default()(DropDown, _React$Component);
  31385. function DropDown() {
  31386. var _getPrototypeOf2;
  31387. var _this;
  31388. classCallCheck_default()(this, DropDown);
  31389. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  31390. args[_key] = arguments[_key];
  31391. }
  31392. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(DropDown)).call.apply(_getPrototypeOf2, [this].concat(args)));
  31393. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "responsiveResolveId", null);
  31394. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "dropDownHandlerElement", null);
  31395. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "dropDownContentElement", null);
  31396. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  31397. active: false,
  31398. offset: 0
  31399. });
  31400. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "fixDropDownPosition", function () {
  31401. var viewRect = _this.props.getContainerNode().getBoundingClientRect();
  31402. var handlerRect = _this.dropDownHandlerElement.getBoundingClientRect();
  31403. var contentRect = _this.dropDownContentElement.getBoundingClientRect();
  31404. var offset = 0;
  31405. var right = handlerRect.right - handlerRect.width / 2 + contentRect.width / 2;
  31406. var left = handlerRect.left + handlerRect.width / 2 - contentRect.width / 2;
  31407. right = viewRect.right - right;
  31408. left = left - viewRect.left;
  31409. if (right < 10) {
  31410. offset = right - 10;
  31411. } else if (left < 10) {
  31412. offset = left * -1 + 10;
  31413. }
  31414. if (offset !== _this.state.offset) {
  31415. _this.setState({
  31416. offset: offset
  31417. });
  31418. }
  31419. });
  31420. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "registerClickEvent", function (event) {
  31421. var autoHide = _this.props.autoHide;
  31422. var active = _this.state.active;
  31423. if (_this.dropDownContentElement.contains(event.target) || _this.dropDownHandlerElement.contains(event.target)) {
  31424. return false;
  31425. }
  31426. autoHide && active && _this.hide();
  31427. });
  31428. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggle", function () {
  31429. _this.setState({
  31430. active: !_this.state.active
  31431. });
  31432. });
  31433. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "show", function () {
  31434. _this.setState({
  31435. active: true
  31436. });
  31437. });
  31438. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "hide", function () {
  31439. _this.setState({
  31440. active: false
  31441. });
  31442. });
  31443. return _this;
  31444. }
  31445. createClass_default()(DropDown, [{
  31446. key: "componentDidMount",
  31447. value: function componentDidMount() {
  31448. if (document) {
  31449. document.body.addEventListener('click', this.registerClickEvent);
  31450. this.responsiveResolveId = responsive.resolve(this.fixDropDownPosition);
  31451. }
  31452. }
  31453. }, {
  31454. key: "componentWillReceiveProps",
  31455. value: function componentWillReceiveProps(next) {
  31456. if (!this.props.disabled && next.disabled) {
  31457. this.hide();
  31458. }
  31459. }
  31460. }, {
  31461. key: "componentDidUpdate",
  31462. value: function componentDidUpdate(prevState) {
  31463. if (!prevState.active && this.state.active) {
  31464. this.fixDropDownPosition();
  31465. }
  31466. }
  31467. }, {
  31468. key: "componentWillUnmount",
  31469. value: function componentWillUnmount() {
  31470. if (document) {
  31471. document.body.removeEventListener('click', this.registerClickEvent);
  31472. responsive.unresolve(this.responsiveResolveId);
  31473. }
  31474. }
  31475. }, {
  31476. key: "render",
  31477. value: function render() {
  31478. var _this2 = this;
  31479. var _this$state = this.state,
  31480. active = _this$state.active,
  31481. offset = _this$state.offset;
  31482. var _this$props = this.props,
  31483. caption = _this$props.caption,
  31484. htmlCaption = _this$props.htmlCaption,
  31485. title = _this$props.title,
  31486. disabled = _this$props.disabled,
  31487. showArrow = _this$props.showArrow,
  31488. arrowActive = _this$props.arrowActive,
  31489. className = _this$props.className,
  31490. children = _this$props.children,
  31491. theme = _this$props.theme;
  31492. disabled && (active = false);
  31493. theme === 'light' && (className = ' light-theme ' + className);
  31494. return external_react_default.a.createElement("div", {
  31495. className: 'bf-dropdown ' + (active ? 'active ' : '') + (disabled ? 'disabled ' : '') + className
  31496. }, htmlCaption ? external_react_default.a.createElement("button", {
  31497. type: "button",
  31498. className: "dropdown-handler",
  31499. "data-title": title,
  31500. onClick: this.toggle,
  31501. dangerouslySetInnerHTML: htmlCaption ? {
  31502. __html: htmlCaption
  31503. } : null,
  31504. ref: function ref(instance) {
  31505. return _this2.dropDownHandlerElement = instance;
  31506. }
  31507. }) : external_react_default.a.createElement("button", {
  31508. type: "button",
  31509. className: "dropdown-handler",
  31510. "data-title": title,
  31511. onClick: this.toggle,
  31512. ref: function ref(instance) {
  31513. return _this2.dropDownHandlerElement = instance;
  31514. }
  31515. }, external_react_default.a.createElement("span", null, caption), showArrow !== false ? external_react_default.a.createElement("i", {
  31516. className: "bfi-drop-down"
  31517. }) : null), external_react_default.a.createElement("div", {
  31518. className: "dropdown-content",
  31519. style: {
  31520. marginLeft: offset
  31521. },
  31522. ref: function ref(instance) {
  31523. return _this2.dropDownContentElement = instance;
  31524. }
  31525. }, external_react_default.a.createElement("i", {
  31526. style: {
  31527. marginLeft: offset * -1
  31528. },
  31529. className: 'dropdown-arrow' + (arrowActive ? ' active' : '')
  31530. }), external_react_default.a.createElement("div", {
  31531. className: "dropdown-content-inner"
  31532. }, children)));
  31533. }
  31534. }]);
  31535. return DropDown;
  31536. }(external_react_default.a.Component);
  31537. // CONCATENATED MODULE: ./components/business/ControlGroup/index.jsx
  31538. /* harmony default export */ var ControlGroup = (function (props) {
  31539. if (external_react_default.a.Fragment) {
  31540. return external_react_default.a.createElement(external_react_default.a.Fragment, null, props.children);
  31541. } else {
  31542. return external_react_default.a.createElement("div", {
  31543. className: "control-item-group"
  31544. }, props.children);
  31545. }
  31546. });
  31547. // CONCATENATED MODULE: ./components/business/LinkEditor/index.jsx
  31548. var LinkEditor_LinkEditor =
  31549. /*#__PURE__*/
  31550. function (_React$Component) {
  31551. inherits_default()(LinkEditor, _React$Component);
  31552. function LinkEditor(props) {
  31553. var _this;
  31554. classCallCheck_default()(this, LinkEditor);
  31555. _this = possibleConstructorReturn_default()(this, getPrototypeOf_default()(LinkEditor).call(this, props));
  31556. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "dropDownInstance", null);
  31557. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handeKeyDown", function (e) {
  31558. if (e.keyCode === 13) {
  31559. _this.handleConfirm();
  31560. e.preventDefault();
  31561. return false;
  31562. }
  31563. });
  31564. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleTnputText", function (e) {
  31565. _this.setState({
  31566. text: e.currentTarget.value
  31567. });
  31568. });
  31569. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleInputLink", function (e) {
  31570. _this.setState({
  31571. href: e.currentTarget.value
  31572. });
  31573. });
  31574. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setTarget", function () {
  31575. _this.setState({
  31576. target: _this.state.target === '_blank' ? '' : '_blank'
  31577. });
  31578. });
  31579. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleCancel", function () {
  31580. _this.dropDownInstance.hide();
  31581. });
  31582. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleUnlink", function () {
  31583. _this.dropDownInstance.hide();
  31584. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLink(_this.props.editorState, false));
  31585. });
  31586. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleConfirm", function () {
  31587. var _this$state = _this.state,
  31588. text = _this$state.text,
  31589. href = _this$state.href,
  31590. target = _this$state.target,
  31591. textSelected = _this$state.textSelected;
  31592. var hookReturns = _this.props.hooks('toggle-link', {
  31593. href: href,
  31594. target: target
  31595. })({
  31596. href: href,
  31597. target: target
  31598. });
  31599. _this.dropDownInstance.hide();
  31600. _this.props.editor.requestFocus();
  31601. if (hookReturns === false) {
  31602. return false;
  31603. }
  31604. if (hookReturns) {
  31605. typeof hookReturns.href === 'string' && (href = hookReturns.href);
  31606. typeof hookReturns.target === 'string' && (target = hookReturns.target);
  31607. }
  31608. if (textSelected) {
  31609. if (href) {
  31610. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLink(_this.props.editorState, href, target));
  31611. } else {
  31612. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLink(_this.props.editorState, false));
  31613. }
  31614. } else {
  31615. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].insertText(_this.props.editorState, text || href, null, {
  31616. type: 'LINK',
  31617. data: {
  31618. href: href,
  31619. target: target
  31620. }
  31621. }));
  31622. }
  31623. });
  31624. _this.state = {
  31625. text: '',
  31626. href: '',
  31627. target: props.defaultLinkTarget || '',
  31628. textSelected: false
  31629. };
  31630. return _this;
  31631. }
  31632. createClass_default()(LinkEditor, [{
  31633. key: "componentWillReceiveProps",
  31634. value: function componentWillReceiveProps(nextProps) {
  31635. var _ContentUtils$getSele = external_braft_utils_["ContentUtils"].getSelectionEntityData(nextProps.editorState, 'LINK'),
  31636. href = _ContentUtils$getSele.href,
  31637. target = _ContentUtils$getSele.target;
  31638. var textSelected = !external_braft_utils_["ContentUtils"].isSelectionCollapsed(this.props.editorState) && external_braft_utils_["ContentUtils"].getSelectionBlockType(this.props.editorState) !== 'atomic';
  31639. var selectedText = '';
  31640. if (textSelected) {
  31641. selectedText = external_braft_utils_["ContentUtils"].getSelectionText(this.props.editorState);
  31642. }
  31643. this.setState({
  31644. textSelected: textSelected,
  31645. text: selectedText,
  31646. href: href || '',
  31647. target: typeof target === 'undefined' ? nextProps.defaultLinkTarget || '' : target || ''
  31648. });
  31649. }
  31650. }, {
  31651. key: "render",
  31652. value: function render() {
  31653. var _this2 = this;
  31654. var allowInsertLinkText = this.props.allowInsertLinkText;
  31655. var _this$state2 = this.state,
  31656. text = _this$state2.text,
  31657. href = _this$state2.href,
  31658. target = _this$state2.target,
  31659. textSelected = _this$state2.textSelected;
  31660. var caption = external_react_default.a.createElement("i", {
  31661. className: "bfi-link"
  31662. });
  31663. return external_react_default.a.createElement(ControlGroup, null, external_react_default.a.createElement(DropDown_DropDown, {
  31664. key: 0,
  31665. caption: caption,
  31666. title: this.props.language.controls.link,
  31667. autoHide: true,
  31668. getContainerNode: this.props.getContainerNode,
  31669. showArrow: false,
  31670. ref: function ref(instance) {
  31671. return _this2.dropDownInstance = instance;
  31672. },
  31673. className: 'control-item dropdown link-editor-dropdown'
  31674. }, external_react_default.a.createElement("div", {
  31675. className: "bf-link-editor"
  31676. }, allowInsertLinkText ? external_react_default.a.createElement("div", {
  31677. className: "input-group"
  31678. }, external_react_default.a.createElement("input", {
  31679. type: "text",
  31680. value: text,
  31681. spellCheck: false,
  31682. disabled: textSelected,
  31683. placeholder: this.props.language.linkEditor.textInputPlaceHolder,
  31684. onKeyDown: this.handeKeyDown,
  31685. onChange: this.handleTnputText
  31686. })) : null, external_react_default.a.createElement("div", {
  31687. className: "input-group"
  31688. }, external_react_default.a.createElement("input", {
  31689. type: "text",
  31690. value: href,
  31691. spellCheck: false,
  31692. placeholder: this.props.language.linkEditor.linkInputPlaceHolder,
  31693. onKeyDown: this.handeKeyDown,
  31694. onChange: this.handleInputLink
  31695. })), external_react_default.a.createElement("div", {
  31696. className: "switch-group"
  31697. }, external_react_default.a.createElement(Switch, {
  31698. active: target === '_blank',
  31699. onClick: this.setTarget
  31700. }), external_react_default.a.createElement("label", null, this.props.language.linkEditor.openInNewWindow)), external_react_default.a.createElement("div", {
  31701. className: "buttons"
  31702. }, external_react_default.a.createElement("a", {
  31703. onClick: this.handleUnlink,
  31704. className: "primary button-remove-link pull-left"
  31705. }, external_react_default.a.createElement("i", {
  31706. className: "bfi-close"
  31707. }), external_react_default.a.createElement("span", null, this.props.language.linkEditor.removeLink)), external_react_default.a.createElement("button", {
  31708. type: "button",
  31709. onClick: this.handleConfirm,
  31710. className: "primary pull-right"
  31711. }, this.props.language.base.confirm), external_react_default.a.createElement("button", {
  31712. type: "button",
  31713. onClick: this.handleCancel,
  31714. className: "default pull-right"
  31715. }, this.props.language.base.cancel)))), external_react_default.a.createElement("button", {
  31716. key: 1,
  31717. type: "button",
  31718. "data-title": this.props.language.controls.unlink,
  31719. className: "control-item button",
  31720. onClick: this.handleUnlink,
  31721. disabled: !textSelected || !href
  31722. }, external_react_default.a.createElement("i", {
  31723. className: "bfi-link-off"
  31724. })));
  31725. }
  31726. }]);
  31727. return LinkEditor;
  31728. }(external_react_default.a.Component);
  31729. // EXTERNAL MODULE: ./components/business/Headings/style.scss
  31730. var Headings_style = __webpack_require__(56);
  31731. // CONCATENATED MODULE: ./configs/maps.js
  31732. var maps_getHeadings = function getHeadings(lang) {
  31733. return [{
  31734. key: 'header-one',
  31735. title: lang.controls.header + ' 1',
  31736. text: external_react_default.a.createElement("h1", null, lang.controls.header, " 1"),
  31737. type: 'block-type',
  31738. command: 'header-one'
  31739. }, {
  31740. key: 'header-two',
  31741. title: lang.controls.header + ' 2',
  31742. text: external_react_default.a.createElement("h2", null, lang.controls.header, " 2"),
  31743. type: 'block-type',
  31744. command: 'header-two'
  31745. }, {
  31746. key: 'header-three',
  31747. title: lang.controls.header + ' 3',
  31748. text: external_react_default.a.createElement("h3", null, lang.controls.header, " 3"),
  31749. type: 'block-type',
  31750. command: 'header-three'
  31751. }, {
  31752. key: 'header-four',
  31753. title: lang.controls.header + ' 4',
  31754. text: external_react_default.a.createElement("h4", null, lang.controls.header, " 4"),
  31755. type: 'block-type',
  31756. command: 'header-four'
  31757. }, {
  31758. key: 'header-five',
  31759. title: lang.controls.header + ' 5',
  31760. text: external_react_default.a.createElement("h5", null, lang.controls.header, " 5"),
  31761. type: 'block-type',
  31762. command: 'header-five'
  31763. }, {
  31764. key: 'header-six',
  31765. title: lang.controls.header + ' 6',
  31766. text: external_react_default.a.createElement("h6", null, lang.controls.header, " 6"),
  31767. type: 'block-type',
  31768. command: 'header-six'
  31769. }, {
  31770. key: 'unstyled',
  31771. title: lang.controls.normal,
  31772. text: lang.controls.normal,
  31773. type: 'block-type',
  31774. command: 'unstyled'
  31775. }];
  31776. };
  31777. // CONCATENATED MODULE: ./components/business/Headings/index.jsx
  31778. /* harmony default export */ var Headings = (function (props) {
  31779. var dropDownInstance = null;
  31780. var headings = maps_getHeadings(props.language).filter(function (item) {
  31781. return props.headings.indexOf(item.key) !== -1;
  31782. });
  31783. var currentHeadingIndex = headings.findIndex(function (item) {
  31784. return item.command === props.current;
  31785. });
  31786. var caption = headings[currentHeadingIndex] ? headings[currentHeadingIndex].title : props.language.controls.normal;
  31787. return external_react_default.a.createElement(DropDown_DropDown, {
  31788. caption: caption,
  31789. autoHide: true,
  31790. getContainerNode: props.getContainerNode,
  31791. title: props.language.controls.headings,
  31792. arrowActive: currentHeadingIndex === 0,
  31793. ref: function ref(instance) {
  31794. return dropDownInstance = instance;
  31795. },
  31796. className: 'control-item dropdown headings-dropdown'
  31797. }, external_react_default.a.createElement("ul", {
  31798. className: "menu"
  31799. }, headings.map(function (item, index) {
  31800. var isActive = props.current === item.command;
  31801. return external_react_default.a.createElement("li", {
  31802. key: index,
  31803. className: 'menu-item' + (isActive ? ' active' : ''),
  31804. onClick: function onClick() {
  31805. props.onChange(item.command, item.type), dropDownInstance.hide();
  31806. }
  31807. }, item.text);
  31808. })));
  31809. });
  31810. // EXTERNAL MODULE: ./components/business/TextColor/style.scss
  31811. var TextColor_style = __webpack_require__(57);
  31812. // EXTERNAL MODULE: ./components/common/ColorPicker/style.scss
  31813. var ColorPicker_style = __webpack_require__(58);
  31814. // CONCATENATED MODULE: ./components/common/ColorPicker/index.jsx
  31815. /* harmony default export */ var common_ColorPicker = (function (props) {
  31816. return external_react_default.a.createElement("div", {
  31817. className: "bf-colors-wrap"
  31818. }, external_react_default.a.createElement("ul", {
  31819. className: "bf-colors"
  31820. }, props.presetColors.map(function (item, index) {
  31821. var className = props.color && item.toLowerCase() === props.color.toLowerCase() ? 'color-item active' : 'color-item';
  31822. return external_react_default.a.createElement("li", {
  31823. key: index,
  31824. title: item,
  31825. className: className,
  31826. style: {
  31827. color: item
  31828. },
  31829. "data-color": item.replace('#', ''),
  31830. onClick: function onClick(e) {
  31831. props.onChange(e.currentTarget.dataset.color, true);
  31832. }
  31833. });
  31834. })));
  31835. });
  31836. // CONCATENATED MODULE: ./components/business/TextColor/index.jsx
  31837. var TextColor_TextColor =
  31838. /*#__PURE__*/
  31839. function (_React$Component) {
  31840. inherits_default()(TextColor, _React$Component);
  31841. function TextColor() {
  31842. var _getPrototypeOf2;
  31843. var _this;
  31844. classCallCheck_default()(this, TextColor);
  31845. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  31846. args[_key] = arguments[_key];
  31847. }
  31848. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(TextColor)).call.apply(_getPrototypeOf2, [this].concat(args)));
  31849. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  31850. colorType: 'color'
  31851. });
  31852. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "switchColorType", function (_ref) {
  31853. var currentTarget = _ref.currentTarget;
  31854. _this.setState({
  31855. colorType: currentTarget.dataset.type
  31856. });
  31857. });
  31858. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggleColor", function (color, closePicker) {
  31859. if (color) {
  31860. var hookReturns = _this.props.hooks("toggle-text-".concat(_this.state.colorType), color)(color);
  31861. if (hookReturns === false) {
  31862. return false;
  31863. }
  31864. if (typeof hookReturns === 'string') {
  31865. color = hookReturns;
  31866. }
  31867. if (_this.state.colorType === 'color') {
  31868. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionColor(_this.props.editorState, color));
  31869. } else {
  31870. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionBackgroundColor(_this.props.editorState, color));
  31871. }
  31872. }
  31873. if (closePicker) {
  31874. _this.dropDownInstance.hide();
  31875. _this.props.editor.requestFocus();
  31876. }
  31877. });
  31878. return _this;
  31879. }
  31880. createClass_default()(TextColor, [{
  31881. key: "render",
  31882. value: function render() {
  31883. var _this2 = this;
  31884. var captionStyle = {};
  31885. var currentColor = null;
  31886. var colorType = this.state.colorType;
  31887. var selectionStyles = this.props.editorState.getCurrentInlineStyle().toJS();
  31888. selectionStyles.forEach(function (style) {
  31889. if (style.indexOf('COLOR-') === 0) {
  31890. captionStyle.color = '#' + style.split('-')[1];
  31891. colorType === 'color' && (currentColor = captionStyle.color);
  31892. }
  31893. if (style.indexOf('BGCOLOR-') === 0) {
  31894. captionStyle.backgroundColor = '#' + style.split('-')[1];
  31895. colorType === 'background-color' && (currentColor = captionStyle.backgroundColor);
  31896. }
  31897. });
  31898. var caption = external_react_default.a.createElement("i", {
  31899. style: captionStyle,
  31900. className: "bfi-text-color"
  31901. }, external_react_default.a.createElement("span", {
  31902. className: "path1"
  31903. }), external_react_default.a.createElement("span", {
  31904. className: "path2"
  31905. }));
  31906. var ColorPicker = this.props.colorPicker || common_ColorPicker;
  31907. return external_react_default.a.createElement(DropDown_DropDown, {
  31908. caption: caption,
  31909. title: this.props.language.controls.color,
  31910. showArrow: false,
  31911. autoHide: this.props.autoHide,
  31912. theme: this.props.theme,
  31913. getContainerNode: this.props.getContainerNode,
  31914. ref: function ref(instance) {
  31915. return _this2.dropDownInstance = instance;
  31916. },
  31917. className: 'control-item dropdown text-color-dropdown'
  31918. }, external_react_default.a.createElement("div", {
  31919. className: "bf-text-color-picker-wrap"
  31920. }, external_react_default.a.createElement("div", {
  31921. className: "bf-color-switch-buttons",
  31922. style: this.props.enableBackgroundColor ? {} : {
  31923. display: 'none'
  31924. }
  31925. }, external_react_default.a.createElement("button", {
  31926. type: "button",
  31927. "data-type": "color",
  31928. className: colorType === 'color' ? 'active' : '',
  31929. onClick: this.switchColorType
  31930. }, this.props.language.controls.textColor), external_react_default.a.createElement("button", {
  31931. type: "button",
  31932. "data-type": "background-color",
  31933. className: colorType === 'background-color' ? 'active' : '',
  31934. onClick: this.switchColorType
  31935. }, this.props.language.controls.backgroundColor)), external_react_default.a.createElement(ColorPicker, {
  31936. width: 200,
  31937. color: currentColor,
  31938. disableAlpha: true,
  31939. presetColors: this.props.colors,
  31940. onChange: this.toggleColor
  31941. })));
  31942. }
  31943. }]);
  31944. return TextColor;
  31945. }(external_react_default.a.Component);
  31946. // EXTERNAL MODULE: ./components/business/FontSize/style.scss
  31947. var FontSize_style = __webpack_require__(59);
  31948. // CONCATENATED MODULE: ./components/business/FontSize/index.jsx
  31949. var FontSize_toggleFontSize = function toggleFontSize(event, props) {
  31950. var fontSize = event.currentTarget.dataset.size;
  31951. var hookReturns = props.hooks('toggle-font-size', fontSize)(fontSize);
  31952. if (hookReturns === false) {
  31953. return false;
  31954. }
  31955. if (!isNaN(fontSize)) {
  31956. fontSize = hookReturns;
  31957. }
  31958. props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionFontSize(props.editorState, fontSize));
  31959. props.editor.requestFocus();
  31960. };
  31961. /* harmony default export */ var FontSize = (function (props) {
  31962. var caption = null;
  31963. var currentFontSize = null;
  31964. var dropDownInstance = null;
  31965. props.fontSizes.find(function (item) {
  31966. if (external_braft_utils_["ContentUtils"].selectionHasInlineStyle(props.editorState, 'FONTSIZE-' + item)) {
  31967. caption = item;
  31968. currentFontSize = item;
  31969. return true;
  31970. }
  31971. return false;
  31972. });
  31973. return external_react_default.a.createElement(DropDown_DropDown, {
  31974. autoHide: true,
  31975. caption: caption || props.defaultCaption,
  31976. getContainerNode: props.getContainerNode,
  31977. title: props.language.controls.fontSize,
  31978. ref: function ref(instance) {
  31979. return dropDownInstance = instance;
  31980. },
  31981. className: 'control-item dropdown bf-font-size-dropdown'
  31982. }, external_react_default.a.createElement("ul", {
  31983. className: "bf-font-sizes"
  31984. }, props.fontSizes.map(function (item, index) {
  31985. return external_react_default.a.createElement("li", {
  31986. key: index,
  31987. className: item === currentFontSize ? 'active' : null,
  31988. "data-size": item,
  31989. onClick: function onClick(event) {
  31990. FontSize_toggleFontSize(event, props), dropDownInstance.hide();
  31991. }
  31992. }, item);
  31993. })));
  31994. });
  31995. // EXTERNAL MODULE: ./components/business/LineHeight/style.scss
  31996. var LineHeight_style = __webpack_require__(60);
  31997. // CONCATENATED MODULE: ./components/business/LineHeight/index.jsx
  31998. var LineHeight_toggleLineHeight = function toggleLineHeight(event, props) {
  31999. var lineHeight = event.currentTarget.dataset.size;
  32000. var hookReturns = props.hooks('toggle-line-height', lineHeight)(lineHeight);
  32001. if (hookReturns === false) {
  32002. return false;
  32003. }
  32004. if (!isNaN(hookReturns)) {
  32005. lineHeight = hookReturns;
  32006. }
  32007. props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLineHeight(props.editorState, lineHeight));
  32008. props.editor.requestFocus();
  32009. };
  32010. /* harmony default export */ var LineHeight = (function (props) {
  32011. var caption = null;
  32012. var currentLineHeight = null;
  32013. var dropDownInstance = null;
  32014. props.lineHeights.find(function (item) {
  32015. if (external_braft_utils_["ContentUtils"].selectionHasInlineStyle(props.editorState, 'LINEHEIGHT-' + item)) {
  32016. caption = item;
  32017. currentLineHeight = item;
  32018. return true;
  32019. }
  32020. return false;
  32021. });
  32022. return external_react_default.a.createElement(DropDown_DropDown, {
  32023. autoHide: true,
  32024. caption: caption || props.defaultCaption,
  32025. getContainerNode: props.getContainerNode,
  32026. title: props.language.controls.lineHeight,
  32027. ref: function ref(instance) {
  32028. return dropDownInstance = instance;
  32029. },
  32030. className: 'control-item dropdown bf-line-height-dropdown'
  32031. }, external_react_default.a.createElement("ul", {
  32032. className: "bf-line-heights"
  32033. }, props.lineHeights.map(function (item, index) {
  32034. return external_react_default.a.createElement("li", {
  32035. key: index,
  32036. className: item === currentLineHeight ? 'active' : null,
  32037. "data-size": item,
  32038. onClick: function onClick(event) {
  32039. LineHeight_toggleLineHeight(event, props), dropDownInstance.hide();
  32040. }
  32041. }, item);
  32042. })));
  32043. });
  32044. // EXTERNAL MODULE: ./components/business/FontFamily/style.scss
  32045. var FontFamily_style = __webpack_require__(61);
  32046. // CONCATENATED MODULE: ./components/business/FontFamily/index.jsx
  32047. var FontFamily_toggleFontFamily = function toggleFontFamily(event, props) {
  32048. var fontFamilyName = event.currentTarget.dataset.name;
  32049. var hookReturns = props.hooks('toggle-font-family', fontFamilyName)(fontFamilyName, props.fontFamilies);
  32050. if (hookReturns === false) {
  32051. return false;
  32052. }
  32053. if (typeof hookReturns === 'string') {
  32054. fontFamilyName = hookReturns;
  32055. }
  32056. props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionFontFamily(props.editorState, fontFamilyName));
  32057. props.editor.requestFocus();
  32058. };
  32059. /* harmony default export */ var FontFamily = (function (props) {
  32060. var caption = null;
  32061. var currentIndex = null;
  32062. var dropDownInstance = null;
  32063. props.fontFamilies.find(function (item, index) {
  32064. if (external_braft_utils_["ContentUtils"].selectionHasInlineStyle(props.editorState, 'FONTFAMILY-' + item.name)) {
  32065. caption = item.name;
  32066. currentIndex = index;
  32067. return true;
  32068. }
  32069. return false;
  32070. });
  32071. return external_react_default.a.createElement(DropDown_DropDown, {
  32072. caption: caption || props.defaultCaption,
  32073. getContainerNode: props.getContainerNode,
  32074. title: props.language.controls.fontFamily,
  32075. autoHide: true,
  32076. arrowActive: currentIndex === 0,
  32077. ref: function ref(instance) {
  32078. return dropDownInstance = instance;
  32079. },
  32080. className: 'control-item dropdown font-family-dropdown'
  32081. }, external_react_default.a.createElement("ul", {
  32082. className: "menu"
  32083. }, props.fontFamilies.map(function (item, index) {
  32084. return external_react_default.a.createElement("li", {
  32085. key: index,
  32086. className: 'menu-item ' + (index === currentIndex ? 'active' : ''),
  32087. "data-name": item.name,
  32088. onClick: function onClick(event) {
  32089. FontFamily_toggleFontFamily(event, props), dropDownInstance.hide();
  32090. }
  32091. }, external_react_default.a.createElement("span", {
  32092. style: {
  32093. fontFamily: item.family
  32094. }
  32095. }, item.name));
  32096. })));
  32097. });
  32098. // CONCATENATED MODULE: ./components/business/TextAlign/index.jsx
  32099. var TextAlign_TextAlign =
  32100. /*#__PURE__*/
  32101. function (_React$Component) {
  32102. inherits_default()(TextAlign, _React$Component);
  32103. function TextAlign() {
  32104. var _getPrototypeOf2;
  32105. var _this;
  32106. classCallCheck_default()(this, TextAlign);
  32107. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  32108. args[_key] = arguments[_key];
  32109. }
  32110. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(TextAlign)).call.apply(_getPrototypeOf2, [this].concat(args)));
  32111. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  32112. currentAlignment: undefined
  32113. });
  32114. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setAlignment", function (event) {
  32115. var alignment = event.currentTarget.dataset.alignment;
  32116. var hookReturns = _this.props.hooks('toggle-text-alignment', alignment)(alignment);
  32117. if (_this.props.textAligns.indexOf(hookReturns) > -1) {
  32118. alignment = hookReturns;
  32119. }
  32120. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionAlignment(_this.props.editorState, alignment));
  32121. _this.props.editor.requestFocus();
  32122. });
  32123. return _this;
  32124. }
  32125. createClass_default()(TextAlign, [{
  32126. key: "componentWillReceiveProps",
  32127. value: function componentWillReceiveProps(next) {
  32128. this.setState({
  32129. currentAlignment: external_braft_utils_["ContentUtils"].getSelectionBlockData(next.editorState, 'textAlign')
  32130. });
  32131. }
  32132. }, {
  32133. key: "render",
  32134. value: function render() {
  32135. var _this2 = this;
  32136. var textAlignmentTitles = [this.props.language.controls.alignLeft, this.props.language.controls.alignCenter, this.props.language.controls.alignRight, this.props.language.controls.alignJustify];
  32137. return external_react_default.a.createElement(ControlGroup, null, this.props.textAligns.map(function (item, index) {
  32138. return external_react_default.a.createElement("button", {
  32139. type: "button",
  32140. key: index,
  32141. "data-title": textAlignmentTitles[index],
  32142. "data-alignment": item,
  32143. className: 'control-item button ' + (item === _this2.state.currentAlignment ? 'active' : null),
  32144. onClick: _this2.setAlignment
  32145. }, external_react_default.a.createElement("i", {
  32146. className: 'bfi-align-' + item
  32147. }));
  32148. }));
  32149. }
  32150. }]);
  32151. return TextAlign;
  32152. }(external_react_default.a.Component);
  32153. // EXTERNAL MODULE: ./components/business/EmojiPicker/style.scss
  32154. var EmojiPicker_style = __webpack_require__(62);
  32155. // CONCATENATED MODULE: ./components/business/EmojiPicker/index.jsx
  32156. var EmojiPicker_insertEmoji = function insertEmoji(event, props) {
  32157. var emoji = event.currentTarget.dataset.emoji;
  32158. var hookReturns = props.hooks('insert-emoji', emoji)(emoji);
  32159. if (hookReturns === false) {
  32160. return false;
  32161. }
  32162. if (typeof hookReturns === 'string') {
  32163. emoji = hookReturns;
  32164. }
  32165. props.editor.setValue(external_braft_utils_["ContentUtils"].insertText(props.editorState, emoji));
  32166. props.editor.requestFocus();
  32167. };
  32168. /* harmony default export */ var EmojiPicker = (function (props) {
  32169. return external_react_default.a.createElement(DropDown_DropDown, {
  32170. caption: props.defaultCaption,
  32171. autoHide: true,
  32172. showArrow: false,
  32173. getContainerNode: props.getContainerNode,
  32174. title: props.language.controls.emoji,
  32175. className: 'control-item dropdown bf-emoji-dropdown'
  32176. }, external_react_default.a.createElement("div", {
  32177. className: "bf-emojis-wrap"
  32178. }, external_react_default.a.createElement("ul", {
  32179. className: "bf-emojis"
  32180. }, props.emojis.map(function (item, index) {
  32181. return external_react_default.a.createElement("li", {
  32182. key: index,
  32183. "data-emoji": item,
  32184. onClick: function onClick(event) {
  32185. return EmojiPicker_insertEmoji(event, props);
  32186. }
  32187. }, item);
  32188. }))));
  32189. });
  32190. // EXTERNAL MODULE: ./components/business/LetterSpacing/style.scss
  32191. var LetterSpacing_style = __webpack_require__(63);
  32192. // CONCATENATED MODULE: ./components/business/LetterSpacing/index.jsx
  32193. var LetterSpacing_toggleLetterSpacing = function toggleLetterSpacing(event, props) {
  32194. var letterSpacing = event.currentTarget.dataset.size;
  32195. var hookReturns = props.hooks('toggle-letter-spacing', letterSpacing)(letterSpacing);
  32196. if (hookReturns === false) {
  32197. return false;
  32198. }
  32199. if (!isNaN(hookReturns)) {
  32200. letterSpacing = hookReturns;
  32201. }
  32202. props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionLetterSpacing(props.editorState, letterSpacing));
  32203. props.editor.requestFocus();
  32204. };
  32205. /* harmony default export */ var LetterSpacing = (function (props) {
  32206. var caption = null;
  32207. var currentLetterSpacing = null;
  32208. var dropDownInstance = null;
  32209. props.letterSpacings.find(function (item) {
  32210. if (external_braft_utils_["ContentUtils"].selectionHasInlineStyle(props.editorState, 'LETTERSPACING-' + item)) {
  32211. caption = item;
  32212. currentLetterSpacing = item;
  32213. return true;
  32214. }
  32215. return false;
  32216. });
  32217. return external_react_default.a.createElement(DropDown_DropDown, {
  32218. autoHide: true,
  32219. caption: caption || props.defaultCaption,
  32220. getContainerNode: props.getContainerNode,
  32221. title: props.language.controls.letterSpacing,
  32222. ref: function ref(instance) {
  32223. return dropDownInstance = instance;
  32224. },
  32225. className: 'control-item dropdown bf-letter-spacing-dropdown'
  32226. }, external_react_default.a.createElement("ul", {
  32227. className: "bf-letter-spacings"
  32228. }, props.letterSpacings.map(function (item, index) {
  32229. return external_react_default.a.createElement("li", {
  32230. key: index,
  32231. className: item === currentLetterSpacing ? 'active' : null,
  32232. "data-size": item,
  32233. onClick: function onClick(event) {
  32234. LetterSpacing_toggleLetterSpacing(event, props), dropDownInstance.hide();
  32235. }
  32236. }, item);
  32237. })));
  32238. });
  32239. // CONCATENATED MODULE: ./components/business/TextIndent/index.jsx
  32240. var TextIndent_TextAlign =
  32241. /*#__PURE__*/
  32242. function (_React$Component) {
  32243. inherits_default()(TextAlign, _React$Component);
  32244. function TextAlign() {
  32245. var _getPrototypeOf2;
  32246. var _this;
  32247. classCallCheck_default()(this, TextAlign);
  32248. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  32249. args[_key] = arguments[_key];
  32250. }
  32251. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(TextAlign)).call.apply(_getPrototypeOf2, [this].concat(args)));
  32252. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "state", {
  32253. currentIndent: 0
  32254. });
  32255. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "increaseIndent", function () {
  32256. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].increaseSelectionIndent(_this.props.editorState));
  32257. _this.props.editor.requestFocus();
  32258. });
  32259. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "decreaseIndent", function () {
  32260. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].decreaseSelectionIndent(_this.props.editorState));
  32261. _this.props.editor.requestFocus();
  32262. });
  32263. return _this;
  32264. }
  32265. createClass_default()(TextAlign, [{
  32266. key: "componentWillReceiveProps",
  32267. value: function componentWillReceiveProps(nextProps) {
  32268. this.setState({
  32269. currentIndent: external_braft_utils_["ContentUtils"].getSelectionBlockData(nextProps.editorState, 'textIndent') || 0
  32270. });
  32271. }
  32272. }, {
  32273. key: "render",
  32274. value: function render() {
  32275. var currentIndent = this.state.currentIndent;
  32276. var language = this.props.language;
  32277. return external_react_default.a.createElement(ControlGroup, null, external_react_default.a.createElement("button", {
  32278. key: 0,
  32279. type: "button",
  32280. "data-title": language.controls.increaseIndent,
  32281. disabled: currentIndent >= 6,
  32282. className: "control-item button button-indent-increase".concat(currentIndent > 0 && currentIndent < 6 ? ' active' : ''),
  32283. onClick: this.increaseIndent
  32284. }, external_react_default.a.createElement("i", {
  32285. className: 'bfi-indent-increase'
  32286. })), external_react_default.a.createElement("button", {
  32287. key: 1,
  32288. type: "button",
  32289. "data-title": language.controls.decreaseIndent,
  32290. disabled: currentIndent <= 0,
  32291. className: "control-item button button-indent-decrease",
  32292. onClick: this.decreaseIndent
  32293. }, external_react_default.a.createElement("i", {
  32294. className: 'bfi-indent-decrease'
  32295. })));
  32296. }
  32297. }]);
  32298. return TextAlign;
  32299. }(external_react_default.a.Component);
  32300. // CONCATENATED MODULE: ./components/business/ControlBar/index.jsx
  32301. var commandHookMap = {
  32302. 'inline-style': 'toggle-inline-style',
  32303. 'block-type': 'change-block-type',
  32304. 'editor-method': 'exec-editor-command'
  32305. };
  32306. var exclusiveInlineStyles = {
  32307. 'superscript': 'subscript',
  32308. 'subscript': 'superscript'
  32309. };
  32310. var mergeControls = function mergeControls(commonProps, builtControls, extensionControls, extendControls) {
  32311. extensionControls = extensionControls.map(function (item) {
  32312. return typeof item === 'function' ? item(commonProps) : item;
  32313. });
  32314. extendControls = extendControls.map(function (item) {
  32315. return typeof item === 'function' ? item(commonProps) : item;
  32316. });
  32317. if (extensionControls.length === 0 && extendControls.length === 0) {
  32318. return builtControls;
  32319. }
  32320. return builtControls.map(function (item) {
  32321. return extendControls.find(function (subItem) {
  32322. return subItem.replace === (item.key || item);
  32323. }) || extensionControls.find(function (subItem) {
  32324. return subItem.replace === (item.key || item);
  32325. }) || item;
  32326. }).concat(extensionControls.length ? 'separator' : '').concat(extensionControls.filter(function (item) {
  32327. return !item.replace;
  32328. })).concat(extendControls.filter(function (item) {
  32329. return typeof item === 'string' || !item.replace;
  32330. }));
  32331. };
  32332. var ControlBar_ControlBar =
  32333. /*#__PURE__*/
  32334. function (_React$Component) {
  32335. inherits_default()(ControlBar, _React$Component);
  32336. function ControlBar() {
  32337. var _getPrototypeOf2;
  32338. var _this;
  32339. classCallCheck_default()(this, ControlBar);
  32340. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  32341. args[_key] = arguments[_key];
  32342. }
  32343. _this = possibleConstructorReturn_default()(this, (_getPrototypeOf2 = getPrototypeOf_default()(ControlBar)).call.apply(_getPrototypeOf2, [this].concat(args)));
  32344. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "allControls", []);
  32345. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "mediaLibiraryModal", null);
  32346. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "extendedModals", {});
  32347. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "openBraftFinder", function () {
  32348. if (!_this.props.braftFinder || !_this.props.braftFinder.ReactComponent) {
  32349. return false;
  32350. }
  32351. if (_this.props.hooks('open-braft-finder')() === false) {
  32352. return false;
  32353. }
  32354. var mediaProps = _this.props.media;
  32355. var MediaLibrary = _this.props.braftFinder.ReactComponent;
  32356. _this.mediaLibiraryModal = Modal_showModal({
  32357. title: _this.props.language.controls.mediaLibirary,
  32358. language: _this.props.language,
  32359. width: 640,
  32360. showFooter: false,
  32361. component: external_react_default.a.createElement(MediaLibrary, {
  32362. accepts: mediaProps.accepts,
  32363. onCancel: _this.closeBraftFinder,
  32364. onInsert: _this.insertMedias,
  32365. onChange: mediaProps.onChange,
  32366. externals: mediaProps.externals,
  32367. onBeforeSelect: _this.bindBraftFinderHook('select-medias'),
  32368. onBeforeDeselect: _this.bindBraftFinderHook('deselect-medias'),
  32369. onBeforeRemove: _this.bindBraftFinderHook('remove-medias'),
  32370. onBeforeInsert: _this.bindBraftFinderHook('insert-medias'),
  32371. onFileSelect: _this.bindBraftFinderHook('select-files')
  32372. })
  32373. });
  32374. });
  32375. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "bindBraftFinderHook", function (hookName) {
  32376. return function () {
  32377. return _this.props.hooks(hookName, arguments.length <= 0 ? undefined : arguments[0]).apply(void 0, arguments);
  32378. };
  32379. });
  32380. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "insertMedias", function (medias) {
  32381. _this.props.editor.setValue(external_braft_utils_["ContentUtils"].insertMedias(_this.props.editorState, medias));
  32382. _this.props.editor.requestFocus();
  32383. _this.props.media.onInsert && _this.props.media.onInsert(medias);
  32384. _this.closeBraftFinder();
  32385. });
  32386. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "closeBraftFinder", function () {
  32387. _this.props.media.onCancel && _this.props.media.onCancel();
  32388. _this.mediaLibiraryModal && _this.mediaLibiraryModal.close();
  32389. });
  32390. return _this;
  32391. }
  32392. createClass_default()(ControlBar, [{
  32393. key: "componentDidUpdate",
  32394. value: function componentDidUpdate() {
  32395. var _this2 = this;
  32396. var language = this.props.language;
  32397. this.allControls.forEach(function (item) {
  32398. if (item.type === 'modal') {
  32399. if (item.modal && item.modal.id && _this2.extendedModals[item.modal.id]) {
  32400. _this2.extendedModals[item.modal.id].update(objectSpread_default()({}, item.modal, {
  32401. language: language
  32402. }));
  32403. }
  32404. }
  32405. });
  32406. }
  32407. }, {
  32408. key: "getControlItemClassName",
  32409. value: function getControlItemClassName(data) {
  32410. var className = 'control-item button';
  32411. var type = data.type,
  32412. command = data.command;
  32413. if (type === 'inline-style' && external_braft_utils_["ContentUtils"].selectionHasInlineStyle(this.props.editorState, command)) {
  32414. className += ' active';
  32415. } else if (type === 'block-type' && external_braft_utils_["ContentUtils"].getSelectionBlockType(this.props.editorState) === command) {
  32416. className += ' active';
  32417. } else if (type === 'entity' && external_braft_utils_["ContentUtils"].getSelectionEntityType(this.props.editorState) === command) {
  32418. className += ' active';
  32419. }
  32420. return className;
  32421. }
  32422. }, {
  32423. key: "applyControl",
  32424. value: function applyControl(command, type) {
  32425. var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  32426. var hookReturns = this.props.hooks(commandHookMap[type] || type, command)(command);
  32427. var editorState = this.props.editorState;
  32428. if (hookReturns === false) {
  32429. return false;
  32430. }
  32431. if (typeof hookReturns === 'string') {
  32432. command = hookReturns;
  32433. }
  32434. if (type === 'inline-style') {
  32435. var exclusiveInlineStyle = exclusiveInlineStyles[command];
  32436. if (exclusiveInlineStyle && external_braft_utils_["ContentUtils"].selectionHasInlineStyle(editorState, exclusiveInlineStyle)) {
  32437. editorState = external_braft_utils_["ContentUtils"].toggleSelectionInlineStyle(editorState, exclusiveInlineStyle);
  32438. }
  32439. this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionInlineStyle(editorState, command));
  32440. } else if (type === 'block-type') {
  32441. this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionBlockType(editorState, command));
  32442. } else if (type === 'entity') {
  32443. this.props.editor.setValue(external_braft_utils_["ContentUtils"].toggleSelectionEntity(editorState, {
  32444. type: command,
  32445. mutability: data.mutability || 'MUTABLE',
  32446. data: data.data || {}
  32447. }));
  32448. } else if (type === 'editor-method') {
  32449. this.props.editor[command] && this.props.editor[command]();
  32450. }
  32451. }
  32452. }, {
  32453. key: "render",
  32454. value: function render() {
  32455. var _this3 = this;
  32456. var _this$props = this.props,
  32457. editor = _this$props.editor,
  32458. editorId = _this$props.editorId,
  32459. editorState = _this$props.editorState,
  32460. className = _this$props.className,
  32461. style = _this$props.style,
  32462. controls = _this$props.controls,
  32463. media = _this$props.media,
  32464. extendControls = _this$props.extendControls,
  32465. language = _this$props.language,
  32466. hooks = _this$props.hooks,
  32467. colors = _this$props.colors,
  32468. colorPicker = _this$props.colorPicker,
  32469. colorPickerTheme = _this$props.colorPickerTheme,
  32470. colorPickerAutoHide = _this$props.colorPickerAutoHide,
  32471. headings = _this$props.headings,
  32472. fontSizes = _this$props.fontSizes,
  32473. fontFamilies = _this$props.fontFamilies,
  32474. emojis = _this$props.emojis,
  32475. getContainerNode = _this$props.getContainerNode,
  32476. lineHeights = _this$props.lineHeights,
  32477. letterSpacings = _this$props.letterSpacings,
  32478. textAligns = _this$props.textAligns,
  32479. textBackgroundColor = _this$props.textBackgroundColor,
  32480. allowInsertLinkText = _this$props.allowInsertLinkText,
  32481. defaultLinkTarget = _this$props.defaultLinkTarget;
  32482. var currentBlockType = external_braft_utils_["ContentUtils"].getSelectionBlockType(editorState);
  32483. var commonProps = {
  32484. editor: editor,
  32485. editorId: editorId,
  32486. editorState: editorState,
  32487. language: language,
  32488. getContainerNode: getContainerNode,
  32489. hooks: hooks
  32490. };
  32491. var renderedControls = [];
  32492. var editorControls = configs_controls(language, editor);
  32493. var extensionControls = getExtensionControls(editorId);
  32494. var allControls = mergeControls(commonProps, controls, extensionControls, extendControls);
  32495. this.allControls = allControls;
  32496. return external_react_default.a.createElement("div", {
  32497. className: "bf-controlbar ".concat(className || ''),
  32498. style: style,
  32499. onMouseDown: this.preventDefault
  32500. }, allControls.map(function (item, index) {
  32501. var itemKey = typeof item === 'string' ? item : item.key;
  32502. if (typeof itemKey !== 'string') {
  32503. return null;
  32504. }
  32505. if (renderedControls.indexOf(itemKey) > -1) {
  32506. return null;
  32507. }
  32508. if (itemKey.toLowerCase() === 'separator') {
  32509. return external_react_default.a.createElement("span", {
  32510. key: index,
  32511. className: "separator-line"
  32512. });
  32513. }
  32514. var controlItem = editorControls.find(function (subItem) {
  32515. return subItem.key.toLowerCase() === itemKey.toLowerCase();
  32516. });
  32517. if (typeof item !== 'string') {
  32518. controlItem = objectSpread_default()({}, controlItem, item);
  32519. }
  32520. if (!controlItem) {
  32521. return null;
  32522. }
  32523. renderedControls.push(itemKey);
  32524. if (controlItem.type === 'headings') {
  32525. return external_react_default.a.createElement(Headings, extends_default()({
  32526. key: index,
  32527. headings: headings,
  32528. current: currentBlockType,
  32529. onChange: function onChange(command) {
  32530. return _this3.applyControl(command, 'block-type');
  32531. }
  32532. }, commonProps));
  32533. } else if (controlItem.type === 'text-color') {
  32534. return external_react_default.a.createElement(TextColor_TextColor, extends_default()({
  32535. key: index,
  32536. colors: colors,
  32537. colorPicker: colorPicker,
  32538. theme: colorPickerTheme,
  32539. autoHide: colorPickerAutoHide,
  32540. enableBackgroundColor: textBackgroundColor
  32541. }, commonProps));
  32542. } else if (controlItem.type === 'font-size') {
  32543. return external_react_default.a.createElement(FontSize, extends_default()({
  32544. key: index,
  32545. fontSizes: fontSizes,
  32546. defaultCaption: controlItem.title
  32547. }, commonProps));
  32548. } else if (controlItem.type === 'line-height') {
  32549. return external_react_default.a.createElement(LineHeight, extends_default()({
  32550. key: index,
  32551. lineHeights: lineHeights,
  32552. defaultCaption: controlItem.title
  32553. }, commonProps));
  32554. } else if (controlItem.type === 'letter-spacing') {
  32555. return external_react_default.a.createElement(LetterSpacing, extends_default()({
  32556. key: index,
  32557. letterSpacings: letterSpacings,
  32558. defaultCaption: controlItem.title
  32559. }, commonProps));
  32560. } else if (controlItem.type === 'text-indent') {
  32561. return external_react_default.a.createElement(TextIndent_TextAlign, extends_default()({
  32562. key: index,
  32563. defaultCaption: controlItem.title
  32564. }, commonProps));
  32565. } else if (controlItem.type === 'font-family') {
  32566. return external_react_default.a.createElement(FontFamily, extends_default()({
  32567. key: index,
  32568. fontFamilies: fontFamilies,
  32569. defaultCaption: controlItem.title
  32570. }, commonProps));
  32571. } else if (controlItem.type === 'emoji') {
  32572. return external_react_default.a.createElement(EmojiPicker, extends_default()({
  32573. key: index,
  32574. emojis: emojis,
  32575. defaultCaption: controlItem.text
  32576. }, commonProps));
  32577. } else if (controlItem.type === 'link') {
  32578. return external_react_default.a.createElement(LinkEditor_LinkEditor, extends_default()({
  32579. key: index,
  32580. defaultLinkTarget: defaultLinkTarget,
  32581. allowInsertLinkText: allowInsertLinkText
  32582. }, commonProps));
  32583. } else if (controlItem.type === 'text-align') {
  32584. return external_react_default.a.createElement(TextAlign_TextAlign, extends_default()({
  32585. key: index,
  32586. textAligns: textAligns
  32587. }, commonProps));
  32588. } else if (controlItem.type === 'media') {
  32589. if (!media.image && !media.video && !media.audio) {
  32590. return null;
  32591. }
  32592. return external_react_default.a.createElement("button", {
  32593. type: "button",
  32594. key: index,
  32595. "data-title": controlItem.title,
  32596. disabled: controlItem.disabled,
  32597. className: "control-item media button",
  32598. onClick: _this3.openBraftFinder
  32599. }, controlItem.text);
  32600. } else if (controlItem.type === 'dropdown') {
  32601. return external_react_default.a.createElement(DropDown_DropDown, extends_default()({
  32602. key: index,
  32603. className: "control-item extend-control-item dropdown ".concat(controlItem.className || ''),
  32604. caption: controlItem.text,
  32605. htmlCaption: controlItem.html,
  32606. showArrow: controlItem.showArrow,
  32607. title: controlItem.title,
  32608. arrowActive: controlItem.arrowActive,
  32609. theme: controlItem.theme,
  32610. autoHide: controlItem.autoHide,
  32611. disabled: controlItem.disabled,
  32612. ref: controlItem.ref
  32613. }, commonProps), controlItem.component);
  32614. } else if (controlItem.type === 'modal') {
  32615. return external_react_default.a.createElement("button", {
  32616. type: "button",
  32617. key: index,
  32618. "data-title": controlItem.title,
  32619. disabled: controlItem.disabled,
  32620. className: "control-item extend-control-item button ".concat(controlItem.className || ''),
  32621. dangerouslySetInnerHTML: controlItem.html ? {
  32622. __html: controlItem.html
  32623. } : null,
  32624. onClick: function onClick(event) {
  32625. if (controlItem.modal && controlItem.modal.id) {
  32626. if (_this3.extendedModals[controlItem.modal.id]) {
  32627. _this3.extendedModals[controlItem.modal.id].active = true;
  32628. _this3.extendedModals[controlItem.modal.id].update(objectSpread_default()({}, controlItem.modal, {
  32629. language: language
  32630. }));
  32631. } else {
  32632. _this3.extendedModals[controlItem.modal.id] = Modal_showModal(objectSpread_default()({}, controlItem.modal, {
  32633. language: language
  32634. }));
  32635. controlItem.modal.onCreate && controlItem.modal.onCreate(_this3.extendedModals[controlItem.modal.id]);
  32636. }
  32637. }
  32638. controlItem.onClick && controlItem.onClick(event);
  32639. }
  32640. }, !controlItem.html ? controlItem.text : null);
  32641. } else if (controlItem.type === 'component') {
  32642. return external_react_default.a.createElement("div", {
  32643. key: index,
  32644. className: "component-wrapper ".concat(controlItem.className || '')
  32645. }, controlItem.component);
  32646. } else if (controlItem.type === 'button') {
  32647. return external_react_default.a.createElement("button", {
  32648. type: "button",
  32649. key: index,
  32650. "data-title": controlItem.title,
  32651. disabled: controlItem.disabled,
  32652. className: "control-item button ".concat(controlItem.className || ''),
  32653. dangerouslySetInnerHTML: controlItem.html ? {
  32654. __html: controlItem.html
  32655. } : null,
  32656. onClick: function onClick(event) {
  32657. return controlItem.onClick && controlItem.onClick(event);
  32658. }
  32659. }, !controlItem.html ? controlItem.text : null);
  32660. } else if (controlItem) {
  32661. var disabled = false;
  32662. if (controlItem.command === 'undo') {
  32663. disabled = editorState.getUndoStack().size === 0;
  32664. } else if (controlItem.command === 'redo') {
  32665. disabled = editorState.getRedoStack().size === 0;
  32666. }
  32667. return external_react_default.a.createElement("button", {
  32668. type: "button",
  32669. key: index,
  32670. disabled: disabled,
  32671. "data-title": controlItem.title,
  32672. className: _this3.getControlItemClassName({
  32673. type: controlItem.type,
  32674. command: controlItem.command
  32675. }),
  32676. onClick: function onClick() {
  32677. return _this3.applyControl(controlItem.command, controlItem.type, controlItem.data);
  32678. }
  32679. }, controlItem.text);
  32680. }
  32681. }));
  32682. }
  32683. }, {
  32684. key: "preventDefault",
  32685. value: function preventDefault(event) {
  32686. var tagName = event.target.tagName.toLowerCase();
  32687. if (tagName === 'input' || tagName === 'label') ; else {
  32688. event.preventDefault();
  32689. }
  32690. }
  32691. }]);
  32692. return ControlBar;
  32693. }(external_react_default.a.Component);
  32694. // CONCATENATED MODULE: ./editor/index.jsx
  32695. var buildHooks = function buildHooks(hooks) {
  32696. return function (hookName) {
  32697. var defaultReturns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  32698. return hooks[hookName] || function () {
  32699. return defaultReturns;
  32700. };
  32701. };
  32702. };
  32703. var filterColors = function filterColors(colors, colors2) {
  32704. return colors.filter(function (item) {
  32705. return !colors2.find(function (color) {
  32706. return color.toLowerCase() === item.toLowerCase();
  32707. });
  32708. }).filter(function (item, index, array) {
  32709. return array.indexOf(item) === index;
  32710. });
  32711. };
  32712. var editor_isControlEnabled = function isControlEnabled(props, controlName) {
  32713. return toConsumableArray_default()(props.controls).concat(toConsumableArray_default()(props.extendControls)).find(function (item) {
  32714. return item === controlName || item.key === controlName;
  32715. }) && props.excludeControls.indexOf(controlName) === -1;
  32716. };
  32717. var editor_getConvertOptions = function getConvertOptions(props) {
  32718. var editorId = props.editorId || props.id;
  32719. var convertOptions = objectSpread_default()({}, configs_props.converts, props.converts, {
  32720. fontFamilies: props.fontFamilies
  32721. });
  32722. convertOptions.styleImportFn = compositeStyleImportFn(convertOptions.styleImportFn, editorId);
  32723. convertOptions.styleExportFn = compositeStyleExportFn(convertOptions.styleExportFn, editorId);
  32724. convertOptions.entityImportFn = compositeEntityImportFn(convertOptions.entityImportFn, editorId);
  32725. convertOptions.entityExportFn = compositeEntityExportFn(convertOptions.entityExportFn, editorId);
  32726. convertOptions.blockImportFn = compositeBlockImportFn(convertOptions.blockImportFn, editorId);
  32727. convertOptions.blockExportFn = compositeBlockExportFn(convertOptions.blockExportFn, editorId);
  32728. return convertOptions;
  32729. };
  32730. var editor_BraftEditor =
  32731. /*#__PURE__*/
  32732. function (_React$Component) {
  32733. inherits_default()(BraftEditor, _React$Component);
  32734. function BraftEditor(props) {
  32735. var _this;
  32736. classCallCheck_default()(this, BraftEditor);
  32737. _this = possibleConstructorReturn_default()(this, getPrototypeOf_default()(BraftEditor).call(this, props));
  32738. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "onChange", function (editorState, callback) {
  32739. if (!(editorState instanceof external_draft_js_["EditorState"])) {
  32740. editorState = external_draft_js_["EditorState"].set(editorState, {
  32741. decorator: _this.editorDecorators
  32742. });
  32743. }
  32744. if (!editorState.convertOptions) {
  32745. editorState.setConvertOptions(editor_getConvertOptions(_this.editorProps));
  32746. }
  32747. _this.setState({
  32748. editorState: editorState
  32749. }, function () {
  32750. _this.props.onChange && _this.props.onChange(editorState);
  32751. callback && callback(editorState);
  32752. });
  32753. });
  32754. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "getDraftInstance", function () {
  32755. return _this.draftInstance;
  32756. });
  32757. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "getFinderInstance", function () {
  32758. return _this.braftFinder;
  32759. });
  32760. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "getValue", function () {
  32761. return _this.state.editorState;
  32762. });
  32763. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setValue", function (editorState, callback) {
  32764. return _this.onChange(editorState, callback);
  32765. });
  32766. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "forceRender", function () {
  32767. var selectionState = _this.state.editorState.getSelection();
  32768. _this.setValue(external_draft_js_["EditorState"].set(_this.state.editorState, {
  32769. decorator: _this.editorDecorators
  32770. }), function () {
  32771. _this.setValue(external_draft_js_["EditorState"].forceSelection(_this.state.editorState, selectionState));
  32772. });
  32773. });
  32774. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "onTab", function (event) {
  32775. if (handlers_keyCommandHandlers('tab', _this.state.editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this))) === 'handled') {
  32776. event.preventDefault();
  32777. }
  32778. _this.editorProps.onTab && _this.editorProps.onTab(event);
  32779. });
  32780. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "onFocus", function () {
  32781. _this.isFocused = true;
  32782. _this.editorProps.onFocus && _this.editorProps.onFocus(_this.state.editorState);
  32783. });
  32784. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "onBlur", function () {
  32785. _this.isFocused = false;
  32786. _this.editorProps.onBlur && _this.editorProps.onBlur(_this.state.editorState);
  32787. });
  32788. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "requestFocus", function () {
  32789. setTimeout(function () {
  32790. return _this.draftInstance.focus();
  32791. }, 0);
  32792. });
  32793. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleKeyCommand", function (command, editorState) {
  32794. return handlers_keyCommandHandlers(command, editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32795. });
  32796. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleReturn", function (event, editorState) {
  32797. return handlers_returnHandlers(event, editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32798. });
  32799. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleBeforeInput", function (chars, editorState) {
  32800. return beforeInputHandlers(chars, editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32801. });
  32802. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleDrop", function (selectionState, dataTransfer) {
  32803. return handlers_dropHandlers(selectionState, dataTransfer, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32804. });
  32805. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleDroppedFiles", function (selectionState, files) {
  32806. return droppedFilesHandlers(selectionState, files, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32807. });
  32808. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handlePastedFiles", function (files) {
  32809. return pastedFilesHandlers(files, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32810. });
  32811. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleCopyContent", function (event) {
  32812. return handlers_copyHandlers(event, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32813. });
  32814. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handlePastedText", function (text, html, editorState) {
  32815. return handlers_pastedTextHandlers(text, html, editorState, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32816. });
  32817. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "handleCompositionStart", function (event) {
  32818. return handlers_compositionStartHandler(event, assertThisInitialized_default()(assertThisInitialized_default()(_this)));
  32819. });
  32820. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "undo", function () {
  32821. _this.setValue(external_braft_utils_["ContentUtils"].undo(_this.state.editorState));
  32822. });
  32823. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "redo", function () {
  32824. _this.setValue(external_braft_utils_["ContentUtils"].redo(_this.state.editorState));
  32825. });
  32826. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "removeSelectionInlineStyles", function () {
  32827. _this.setValue(external_braft_utils_["ContentUtils"].removeSelectionInlineStyles(_this.state.editorState));
  32828. });
  32829. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "insertHorizontalLine", function () {
  32830. _this.setValue(external_braft_utils_["ContentUtils"].insertHorizontalLine(_this.state.editorState));
  32831. });
  32832. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "clearEditorContent", function () {
  32833. _this.setValue(external_braft_utils_["ContentUtils"].clear(_this.state.editorState), function (editorState) {
  32834. _this.setValue(external_braft_utils_["ContentUtils"].toggleSelectionIndent(editorState, 0));
  32835. });
  32836. });
  32837. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "toggleFullscreen", function (fullscreen) {
  32838. _this.setState({
  32839. isFullscreen: typeof fullscreen !== 'undefined' ? fullscreen : !_this.state.isFullscreen
  32840. }, function () {
  32841. _this.editorProps.onFullscreen && _this.editorProps.onFullscreen(_this.state.isFullscreen);
  32842. });
  32843. });
  32844. defineProperty_default()(assertThisInitialized_default()(assertThisInitialized_default()(_this)), "setEditorContainerNode", function (containerNode) {
  32845. _this.containerNode = containerNode;
  32846. });
  32847. _this.editorProps = _this.getEditorProps(props);
  32848. _this.editorDecorators = getDecorators(_this.editorProps.editorId || _this.editorProps.id);
  32849. _this.isFocused = false;
  32850. _this.isLiving = false;
  32851. _this.braftFinder = null;
  32852. _this.valueInitialized = !!(_this.props.defaultValue || _this.props.value);
  32853. 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);
  32854. defaultEditorState.setConvertOptions(editor_getConvertOptions(_this.editorProps));
  32855. var tempColors = [];
  32856. if (external_braft_utils_["ContentUtils"].isEditorState(defaultEditorState)) {
  32857. var colors = external_braft_utils_["ColorUtils"].detectColorsFromDraftState(defaultEditorState.toRAW(true));
  32858. defaultEditorState.setConvertOptions(editor_getConvertOptions(_this.editorProps));
  32859. tempColors = filterColors(colors, _this.editorProps.colors);
  32860. }
  32861. _this.state = {
  32862. tempColors: tempColors,
  32863. editorState: defaultEditorState,
  32864. isFullscreen: false,
  32865. draftProps: {}
  32866. };
  32867. _this.containerNode = null;
  32868. return _this;
  32869. }
  32870. createClass_default()(BraftEditor, [{
  32871. key: "getEditorProps",
  32872. value: function getEditorProps(props) {
  32873. var _this2 = this;
  32874. props = props || this.props;
  32875. var _props = props,
  32876. value = _props.value,
  32877. defaultValue = _props.defaultValue,
  32878. onChange = _props.onChange,
  32879. restProps = objectWithoutProperties_default()(_props, ["value", "defaultValue", "onChange"]); // eslint-disable-line no-unused-vars
  32880. var propInterceptors = getPropInterceptors(restProps.editorId || restProps.id);
  32881. if (propInterceptors.length === 0) {
  32882. return restProps;
  32883. }
  32884. var porpsMap = Object(external_immutable_["Map"])(restProps);
  32885. propInterceptors.forEach(function (interceptor) {
  32886. porpsMap = porpsMap.merge(Object(external_immutable_["Map"])(interceptor(porpsMap.toJS(), _this2) || {}));
  32887. });
  32888. return porpsMap.toJS();
  32889. }
  32890. }, {
  32891. key: "componentWillMount",
  32892. value: function componentWillMount() {
  32893. if (editor_isControlEnabled(this.editorProps, 'media')) {
  32894. var _this$editorProps = this.editorProps,
  32895. language = _this$editorProps.language,
  32896. media = _this$editorProps.media;
  32897. var _defaultProps$media$m = objectSpread_default()({}, configs_props.media, media),
  32898. uploadFn = _defaultProps$media$m.uploadFn,
  32899. validateFn = _defaultProps$media$m.validateFn,
  32900. items = _defaultProps$media$m.items;
  32901. this.braftFinder = new external_braft_finder_default.a({
  32902. items: items,
  32903. language: language,
  32904. uploader: uploadFn,
  32905. validator: validateFn
  32906. });
  32907. this.forceUpdate();
  32908. }
  32909. }
  32910. }, {
  32911. key: "componentDidMount",
  32912. value: function componentDidMount() {
  32913. this.isLiving = true;
  32914. }
  32915. }, {
  32916. key: "componentDidUpdate",
  32917. value: function componentDidUpdate(_, prevState) {
  32918. if (prevState.editorState !== this.state.editorState) {
  32919. this.state.editorState.setConvertOptions(editor_getConvertOptions(this.editorProps));
  32920. }
  32921. }
  32922. }, {
  32923. key: "componentWillReceiveProps",
  32924. value: function componentWillReceiveProps(props) {
  32925. var _this3 = this;
  32926. this.editorProps = this.getEditorProps(props);
  32927. var editorState = props.value;
  32928. var _this$editorProps2 = this.editorProps,
  32929. media = _this$editorProps2.media,
  32930. language = _this$editorProps2.language;
  32931. var currentProps = this.getEditorProps();
  32932. if (!editor_isControlEnabled(currentProps, 'media') && editor_isControlEnabled(this.editorProps, 'media') && !this.braftFinder) {
  32933. var _defaultProps$media$m2 = objectSpread_default()({}, configs_props.media, media),
  32934. uploadFn = _defaultProps$media$m2.uploadFn,
  32935. validateFn = _defaultProps$media$m2.validateFn,
  32936. items = _defaultProps$media$m2.items;
  32937. this.braftFinder = new external_braft_finder_default.a({
  32938. items: items,
  32939. language: language,
  32940. uploader: uploadFn,
  32941. validator: validateFn
  32942. });
  32943. this.forceUpdate();
  32944. }
  32945. if (media && media.items && this.braftFinder) {
  32946. this.braftFinder.setItems(media.items);
  32947. }
  32948. var nextEditorState;
  32949. if (!this.valueInitialized && typeof this.props.defaultValue === 'undefined' && external_braft_utils_["ContentUtils"].isEditorState(props.defaultValue)) {
  32950. nextEditorState = props.defaultValue;
  32951. } else if (external_braft_utils_["ContentUtils"].isEditorState(editorState)) {
  32952. nextEditorState = editorState;
  32953. }
  32954. if (nextEditorState) {
  32955. if (nextEditorState && nextEditorState !== this.state.editorState) {
  32956. var tempColors = external_braft_utils_["ColorUtils"].detectColorsFromDraftState(nextEditorState.toRAW(true));
  32957. nextEditorState.setConvertOptions(editor_getConvertOptions(this.editorProps));
  32958. this.setState({
  32959. tempColors: filterColors(toConsumableArray_default()(this.state.tempColors).concat(toConsumableArray_default()(tempColors)), currentProps.colors),
  32960. editorState: nextEditorState
  32961. }, function () {
  32962. _this3.props.onChange && _this3.props.onChange(nextEditorState);
  32963. });
  32964. } else {
  32965. this.setState({
  32966. editorState: nextEditorState
  32967. });
  32968. }
  32969. }
  32970. }
  32971. }, {
  32972. key: "componentWillUnmount",
  32973. value: function componentWillUnmount() {
  32974. this.isLiving = false;
  32975. this.controlBarInstance && this.controlBarInstance.closeBraftFinder();
  32976. }
  32977. }, {
  32978. key: "lockOrUnlockEditor",
  32979. value: function lockOrUnlockEditor(editorLocked) {
  32980. this.setState({
  32981. editorLocked: editorLocked
  32982. });
  32983. }
  32984. }, {
  32985. key: "render",
  32986. value: function render() {
  32987. var _this4 = this;
  32988. var _this$editorProps3 = this.editorProps,
  32989. id = _this$editorProps3.id,
  32990. editorId = _this$editorProps3.editorId,
  32991. controls = _this$editorProps3.controls,
  32992. excludeControls = _this$editorProps3.excludeControls,
  32993. extendControls = _this$editorProps3.extendControls,
  32994. readOnly = _this$editorProps3.readOnly,
  32995. disabled = _this$editorProps3.disabled,
  32996. media = _this$editorProps3.media,
  32997. language = _this$editorProps3.language,
  32998. colors = _this$editorProps3.colors,
  32999. colorPicker = _this$editorProps3.colorPicker,
  33000. colorPickerTheme = _this$editorProps3.colorPickerTheme,
  33001. colorPickerAutoHide = _this$editorProps3.colorPickerAutoHide,
  33002. hooks = _this$editorProps3.hooks,
  33003. fontSizes = _this$editorProps3.fontSizes,
  33004. fontFamilies = _this$editorProps3.fontFamilies,
  33005. emojis = _this$editorProps3.emojis,
  33006. placeholder = _this$editorProps3.placeholder,
  33007. fixPlaceholder = _this$editorProps3.fixPlaceholder,
  33008. headings = _this$editorProps3.headings,
  33009. imageControls = _this$editorProps3.imageControls,
  33010. imageResizable = _this$editorProps3.imageResizable,
  33011. lineHeights = _this$editorProps3.lineHeights,
  33012. letterSpacings = _this$editorProps3.letterSpacings,
  33013. textAligns = _this$editorProps3.textAligns,
  33014. textBackgroundColor = _this$editorProps3.textBackgroundColor,
  33015. allowInsertLinkText = _this$editorProps3.allowInsertLinkText,
  33016. defaultLinkTarget = _this$editorProps3.defaultLinkTarget,
  33017. extendAtomics = _this$editorProps3.extendAtomics,
  33018. className = _this$editorProps3.className,
  33019. style = _this$editorProps3.style,
  33020. controlBarClassName = _this$editorProps3.controlBarClassName,
  33021. controlBarStyle = _this$editorProps3.controlBarStyle,
  33022. contentClassName = _this$editorProps3.contentClassName,
  33023. contentStyle = _this$editorProps3.contentStyle,
  33024. stripPastedStyles = _this$editorProps3.stripPastedStyles,
  33025. componentBelowControlBar = _this$editorProps3.componentBelowControlBar;
  33026. var _this$state = this.state,
  33027. isFullscreen = _this$state.isFullscreen,
  33028. editorState = _this$state.editorState;
  33029. editorId = editorId || id;
  33030. hooks = buildHooks(hooks);
  33031. controls = controls.filter(function (item) {
  33032. return excludeControls.indexOf(item) === -1;
  33033. });
  33034. language = (typeof language === 'function' ? language(languages, 'braft-editor') : languages[language]) || languages[configs_props.language];
  33035. var externalMedias = media && media.externals ? objectSpread_default()({}, configs_props.media.externals, media.externals) : configs_props.media.externals;
  33036. var accepts = media && media.accepts ? objectSpread_default()({}, configs_props.media.accepts, media.accepts) : configs_props.media.accepts;
  33037. media = objectSpread_default()({}, configs_props.media, media, {
  33038. externalMedias: externalMedias,
  33039. accepts: accepts
  33040. });
  33041. if (!media.uploadFn) {
  33042. media.video = false;
  33043. media.audio = false;
  33044. }
  33045. var controlBarProps = {
  33046. editor: this,
  33047. editorState: editorState,
  33048. braftFinder: this.braftFinder,
  33049. ref: function ref(instance) {
  33050. return _this4.controlBarInstance = instance;
  33051. },
  33052. getContainerNode: function getContainerNode() {
  33053. return _this4.containerNode;
  33054. },
  33055. className: controlBarClassName,
  33056. style: controlBarStyle,
  33057. colors: toConsumableArray_default()(colors).concat(toConsumableArray_default()(this.state.tempColors)),
  33058. colorPicker: colorPicker,
  33059. colorPickerTheme: colorPickerTheme,
  33060. colorPickerAutoHide: colorPickerAutoHide,
  33061. hooks: hooks,
  33062. editorId: editorId,
  33063. media: media,
  33064. controls: controls,
  33065. language: language,
  33066. extendControls: extendControls,
  33067. headings: headings,
  33068. fontSizes: fontSizes,
  33069. fontFamilies: fontFamilies,
  33070. emojis: emojis,
  33071. lineHeights: lineHeights,
  33072. letterSpacings: letterSpacings,
  33073. textAligns: textAligns,
  33074. textBackgroundColor: textBackgroundColor,
  33075. allowInsertLinkText: allowInsertLinkText,
  33076. defaultLinkTarget: defaultLinkTarget
  33077. };
  33078. var unitExportFn = editorState.convertOptions.unitExportFn;
  33079. var commonProps = {
  33080. editor: this,
  33081. editorId: editorId,
  33082. hooks: hooks,
  33083. editorState: editorState,
  33084. containerNode: this.containerNode,
  33085. imageControls: imageControls,
  33086. imageResizable: imageResizable,
  33087. language: language,
  33088. extendAtomics: extendAtomics
  33089. };
  33090. var blockRendererFn = getBlockRendererFn(commonProps, this.editorProps.blockRendererFn);
  33091. var blockRenderMap = getBlockRenderMap(commonProps, this.editorProps.blockRenderMap);
  33092. var blockStyleFn = getBlockStyleFn(this.editorProps.blockStyleFn);
  33093. var customStyleMap = getCustomStyleMap(commonProps, this.editorProps.customStyleMap);
  33094. var customStyleFn = getCustomStyleFn(commonProps, {
  33095. fontFamilies: fontFamilies,
  33096. unitExportFn: unitExportFn,
  33097. customStyleFn: this.editorProps.customStyleFn
  33098. });
  33099. var keyBindingFn = keybindings(this.editorProps.keyBindingFn);
  33100. var mixedProps = {};
  33101. if (this.state.editorLocked || this.editorProps.disabled || this.editorProps.readOnly || this.editorProps.draftProps.readOnly) {
  33102. mixedProps.readOnly = true;
  33103. }
  33104. if (placeholder && fixPlaceholder && editorState.isEmpty() && editorState.getCurrentContent().getFirstBlock().getType() !== 'unstyled') {
  33105. placeholder = '';
  33106. }
  33107. var draftProps = objectSpread_default()({
  33108. ref: function ref(instance) {
  33109. _this4.draftInstance = instance;
  33110. },
  33111. editorState: editorState,
  33112. handleKeyCommand: this.handleKeyCommand,
  33113. handleReturn: this.handleReturn,
  33114. handleBeforeInput: this.handleBeforeInput,
  33115. handleDrop: this.handleDrop,
  33116. handleDroppedFiles: this.handleDroppedFiles,
  33117. handlePastedText: this.handlePastedText,
  33118. handlePastedFiles: this.handlePastedFiles,
  33119. onChange: this.onChange,
  33120. onTab: this.onTab,
  33121. onFocus: this.onFocus,
  33122. onBlur: this.onBlur,
  33123. blockRenderMap: blockRenderMap,
  33124. blockRendererFn: blockRendererFn,
  33125. blockStyleFn: blockStyleFn,
  33126. customStyleMap: customStyleMap,
  33127. customStyleFn: customStyleFn,
  33128. keyBindingFn: keyBindingFn,
  33129. placeholder: placeholder,
  33130. stripPastedStyles: stripPastedStyles
  33131. }, this.editorProps.draftProps, mixedProps);
  33132. return external_react_default.a.createElement("div", {
  33133. style: style,
  33134. ref: this.setEditorContainerNode,
  33135. className: "bf-container ".concat(className).concat(disabled ? ' disabled' : '').concat(readOnly ? ' read-only' : '').concat(isFullscreen ? ' fullscreen' : '')
  33136. }, external_react_default.a.createElement(ControlBar_ControlBar, controlBarProps), componentBelowControlBar, external_react_default.a.createElement("div", {
  33137. onCompositionStart: this.handleCompositionStart,
  33138. className: "bf-content ".concat(contentClassName),
  33139. onCopy: this.handleCopyContent,
  33140. style: contentStyle
  33141. }, external_react_default.a.createElement(external_draft_js_["Editor"], draftProps)));
  33142. }
  33143. }]);
  33144. return BraftEditor;
  33145. }(external_react_default.a.Component);
  33146. defineProperty_default()(editor_BraftEditor, "defaultProps", configs_props);
  33147. // EXTERNAL MODULE: external "braft-convert"
  33148. var external_braft_convert_ = __webpack_require__(14);
  33149. // CONCATENATED MODULE: ./index.jsx
  33150. /* concated harmony reexport EditorState */__webpack_require__.d(__webpack_exports__, "EditorState", function() { return external_draft_js_["EditorState"]; });
  33151. /* concated harmony reexport getDecorators */__webpack_require__.d(__webpack_exports__, "getDecorators", function() { return getDecorators; });
  33152. external_draft_js_["EditorState"].prototype.setConvertOptions = function () {
  33153. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  33154. this.convertOptions = options;
  33155. };
  33156. external_draft_js_["EditorState"].prototype.toHTML = function () {
  33157. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  33158. var convertOptions = this.convertOptions || {};
  33159. return Object(external_braft_convert_["convertEditorStateToHTML"])(this, objectSpread_default()({}, convertOptions, options));
  33160. };
  33161. external_draft_js_["EditorState"].prototype.toRAW = function (noStringify) {
  33162. return noStringify ? Object(external_braft_convert_["convertEditorStateToRaw"])(this) : JSON.stringify(Object(external_braft_convert_["convertEditorStateToRaw"])(this));
  33163. };
  33164. external_draft_js_["EditorState"].prototype.toText = function () {
  33165. return this.getCurrentContent().getPlainText();
  33166. };
  33167. external_draft_js_["EditorState"].prototype.isEmpty = function () {
  33168. return !this.getCurrentContent().hasText();
  33169. };
  33170. editor_BraftEditor.createEditorState = external_draft_js_["EditorState"].createFrom = function (content) {
  33171. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  33172. options.unitExportFn = options.unitExportFn || editor_BraftEditor.defaultProps.converts.unitExportFn;
  33173. options.styleImportFn = compositeStyleImportFn(options.styleImportFn, options.editorId);
  33174. options.entityImportFn = compositeEntityImportFn(options.entityImportFn, options.editorId);
  33175. options.blockImportFn = compositeBlockImportFn(options.blockImportFn, options.editorId);
  33176. var editorState = null;
  33177. if (content instanceof external_draft_js_["EditorState"]) {
  33178. editorState = content;
  33179. } else if (typeof_default()(content) === 'object' && content && content.blocks && content.entityMap) {
  33180. editorState = Object(external_braft_convert_["convertRawToEditorState"])(content, getDecorators(options.editorId));
  33181. } else if (typeof content === 'string') {
  33182. try {
  33183. if (/^(-)?\d+$/.test(content)) {
  33184. editorState = Object(external_braft_convert_["convertHTMLToEditorState"])(content, getDecorators(options.editorId), options, 'create');
  33185. } else {
  33186. editorState = external_draft_js_["EditorState"].createFrom(JSON.parse(content), options);
  33187. }
  33188. } catch (error) {
  33189. editorState = Object(external_braft_convert_["convertHTMLToEditorState"])(content, getDecorators(options.editorId), options, 'create');
  33190. }
  33191. } else if (typeof content === 'number') {
  33192. editorState = Object(external_braft_convert_["convertHTMLToEditorState"])(content.toLocaleString().replace(/,/g, ''), getDecorators(options.editorId), options, 'create');
  33193. } else {
  33194. editorState = external_draft_js_["EditorState"].createEmpty(getDecorators(options.editorId));
  33195. }
  33196. options.styleExportFn = compositeStyleExportFn(options.styleExportFn, options.editorId);
  33197. options.entityExportFn = compositeEntityExportFn(options.entityExportFn, options.editorId);
  33198. options.blockExportFn = compositeBlockExportFn(options.blockExportFn, options.editorId);
  33199. editorState.setConvertOptions(options);
  33200. return editorState;
  33201. };
  33202. /* harmony default export */ var index_0 = __webpack_exports__["default"] = (createExtensibleEditor(editor_BraftEditor));
  33203. // 2.1版本开发计划
  33204. // [ ]优化选中多行文字是插入链接报错的问题
  33205. // [ ]新增编辑器内图片删除hook
  33206. // 2.2版本开发计划
  33207. // [ ]表格功能
  33208. // [ ]美化UI,包括图标和界面风格
  33209. // 2.3版本开发计划
  33210. // [ ]初级md快捷输入支持
  33211. // [ ]图片裁切等简单的编辑功能
  33212. // [ ]允许自定义快捷键
  33213. /***/ }),
  33214. /* 40 */
  33215. /***/ (function(module, exports) {
  33216. // removed by extract-text-webpack-plugin
  33217. /***/ }),
  33218. /* 41 */,
  33219. /* 42 */
  33220. /***/ (function(module, exports) {
  33221. // removed by extract-text-webpack-plugin
  33222. /***/ }),
  33223. /* 43 */,
  33224. /* 44 */,
  33225. /* 45 */
  33226. /***/ (function(module, exports) {
  33227. // removed by extract-text-webpack-plugin
  33228. /***/ }),
  33229. /* 46 */
  33230. /***/ (function(module, exports) {
  33231. // removed by extract-text-webpack-plugin
  33232. /***/ }),
  33233. /* 47 */
  33234. /***/ (function(module, exports) {
  33235. // removed by extract-text-webpack-plugin
  33236. /***/ }),
  33237. /* 48 */
  33238. /***/ (function(module, exports) {
  33239. // removed by extract-text-webpack-plugin
  33240. /***/ }),
  33241. /* 49 */
  33242. /***/ (function(module, exports) {
  33243. // removed by extract-text-webpack-plugin
  33244. /***/ }),
  33245. /* 50 */
  33246. /***/ (function(module, exports) {
  33247. // removed by extract-text-webpack-plugin
  33248. /***/ }),
  33249. /* 51 */
  33250. /***/ (function(module, exports) {
  33251. // removed by extract-text-webpack-plugin
  33252. /***/ }),
  33253. /* 52 */
  33254. /***/ (function(module, exports) {
  33255. // removed by extract-text-webpack-plugin
  33256. /***/ }),
  33257. /* 53 */
  33258. /***/ (function(module, exports) {
  33259. // removed by extract-text-webpack-plugin
  33260. /***/ }),
  33261. /* 54 */
  33262. /***/ (function(module, exports) {
  33263. // removed by extract-text-webpack-plugin
  33264. /***/ }),
  33265. /* 55 */
  33266. /***/ (function(module, exports) {
  33267. // removed by extract-text-webpack-plugin
  33268. /***/ }),
  33269. /* 56 */
  33270. /***/ (function(module, exports) {
  33271. // removed by extract-text-webpack-plugin
  33272. /***/ }),
  33273. /* 57 */
  33274. /***/ (function(module, exports) {
  33275. // removed by extract-text-webpack-plugin
  33276. /***/ }),
  33277. /* 58 */
  33278. /***/ (function(module, exports) {
  33279. // removed by extract-text-webpack-plugin
  33280. /***/ }),
  33281. /* 59 */
  33282. /***/ (function(module, exports) {
  33283. // removed by extract-text-webpack-plugin
  33284. /***/ }),
  33285. /* 60 */
  33286. /***/ (function(module, exports) {
  33287. // removed by extract-text-webpack-plugin
  33288. /***/ }),
  33289. /* 61 */
  33290. /***/ (function(module, exports) {
  33291. // removed by extract-text-webpack-plugin
  33292. /***/ }),
  33293. /* 62 */
  33294. /***/ (function(module, exports) {
  33295. // removed by extract-text-webpack-plugin
  33296. /***/ }),
  33297. /* 63 */
  33298. /***/ (function(module, exports) {
  33299. // removed by extract-text-webpack-plugin
  33300. /***/ })
  33301. /******/ ]);
  33302. });
  33303. });
  33304. var BraftEditor = styleInject_es.unwrapExports(dist$3);
  33305. 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)}";
  33306. styleInject_es.styleInject(css);
  33307. 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}";
  33308. styleInject_es.styleInject(css$1);
  33309. var immutable$3 = styleInject_es.createCommonjsModule(function (module, exports) {
  33310. /**
  33311. * Copyright (c) 2014-present, Facebook, Inc.
  33312. *
  33313. * This source code is licensed under the MIT license found in the
  33314. * LICENSE file in the root directory of this source tree.
  33315. */
  33316. (function (global, factory) {
  33317. factory(exports) ;
  33318. }(styleInject_es.commonjsGlobal, (function (exports) {
  33319. // Used for setting prototype methods that IE8 chokes on.
  33320. var DELETE = 'delete';
  33321. // Constants describing the size of trie nodes.
  33322. var SHIFT = 5; // Resulted in best performance after ______?
  33323. var SIZE = 1 << SHIFT;
  33324. var MASK = SIZE - 1;
  33325. // A consistent shared value representing "not set" which equals nothing other
  33326. // than itself, and nothing that could be provided externally.
  33327. var NOT_SET = {};
  33328. // Boolean references, Rough equivalent of `bool &`.
  33329. function MakeRef() {
  33330. return { value: false };
  33331. }
  33332. function SetRef(ref) {
  33333. if (ref) {
  33334. ref.value = true;
  33335. }
  33336. }
  33337. // A function which returns a value representing an "owner" for transient writes
  33338. // to tries. The return value will only ever equal itself, and will not equal
  33339. // the return of any subsequent call of this function.
  33340. function OwnerID() {}
  33341. function ensureSize(iter) {
  33342. if (iter.size === undefined) {
  33343. iter.size = iter.__iterate(returnTrue);
  33344. }
  33345. return iter.size;
  33346. }
  33347. function wrapIndex(iter, index) {
  33348. // This implements "is array index" which the ECMAString spec defines as:
  33349. //
  33350. // A String property name P is an array index if and only if
  33351. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  33352. // to 2^32−1.
  33353. //
  33354. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  33355. if (typeof index !== 'number') {
  33356. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  33357. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  33358. return NaN;
  33359. }
  33360. index = uint32Index;
  33361. }
  33362. return index < 0 ? ensureSize(iter) + index : index;
  33363. }
  33364. function returnTrue() {
  33365. return true;
  33366. }
  33367. function wholeSlice(begin, end, size) {
  33368. return (
  33369. ((begin === 0 && !isNeg(begin)) ||
  33370. (size !== undefined && begin <= -size)) &&
  33371. (end === undefined || (size !== undefined && end >= size))
  33372. );
  33373. }
  33374. function resolveBegin(begin, size) {
  33375. return resolveIndex(begin, size, 0);
  33376. }
  33377. function resolveEnd(end, size) {
  33378. return resolveIndex(end, size, size);
  33379. }
  33380. function resolveIndex(index, size, defaultIndex) {
  33381. // Sanitize indices using this shorthand for ToInt32(argument)
  33382. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  33383. return index === undefined
  33384. ? defaultIndex
  33385. : isNeg(index)
  33386. ? size === Infinity
  33387. ? size
  33388. : Math.max(0, size + index) | 0
  33389. : size === undefined || size === index
  33390. ? index
  33391. : Math.min(size, index) | 0;
  33392. }
  33393. function isNeg(value) {
  33394. // Account for -0 which is negative, but not less than 0.
  33395. return value < 0 || (value === 0 && 1 / value === -Infinity);
  33396. }
  33397. // Note: value is unchanged to not break immutable-devtools.
  33398. var IS_COLLECTION_SYMBOL = '@@__IMMUTABLE_ITERABLE__@@';
  33399. function isCollection(maybeCollection) {
  33400. return Boolean(maybeCollection && maybeCollection[IS_COLLECTION_SYMBOL]);
  33401. }
  33402. var IS_KEYED_SYMBOL = '@@__IMMUTABLE_KEYED__@@';
  33403. function isKeyed(maybeKeyed) {
  33404. return Boolean(maybeKeyed && maybeKeyed[IS_KEYED_SYMBOL]);
  33405. }
  33406. var IS_INDEXED_SYMBOL = '@@__IMMUTABLE_INDEXED__@@';
  33407. function isIndexed(maybeIndexed) {
  33408. return Boolean(maybeIndexed && maybeIndexed[IS_INDEXED_SYMBOL]);
  33409. }
  33410. function isAssociative(maybeAssociative) {
  33411. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  33412. }
  33413. var Collection = function Collection(value) {
  33414. return isCollection(value) ? value : Seq(value);
  33415. };
  33416. var KeyedCollection = /*@__PURE__*/(function (Collection) {
  33417. function KeyedCollection(value) {
  33418. return isKeyed(value) ? value : KeyedSeq(value);
  33419. }
  33420. if ( Collection ) KeyedCollection.__proto__ = Collection;
  33421. KeyedCollection.prototype = Object.create( Collection && Collection.prototype );
  33422. KeyedCollection.prototype.constructor = KeyedCollection;
  33423. return KeyedCollection;
  33424. }(Collection));
  33425. var IndexedCollection = /*@__PURE__*/(function (Collection) {
  33426. function IndexedCollection(value) {
  33427. return isIndexed(value) ? value : IndexedSeq(value);
  33428. }
  33429. if ( Collection ) IndexedCollection.__proto__ = Collection;
  33430. IndexedCollection.prototype = Object.create( Collection && Collection.prototype );
  33431. IndexedCollection.prototype.constructor = IndexedCollection;
  33432. return IndexedCollection;
  33433. }(Collection));
  33434. var SetCollection = /*@__PURE__*/(function (Collection) {
  33435. function SetCollection(value) {
  33436. return isCollection(value) && !isAssociative(value) ? value : SetSeq(value);
  33437. }
  33438. if ( Collection ) SetCollection.__proto__ = Collection;
  33439. SetCollection.prototype = Object.create( Collection && Collection.prototype );
  33440. SetCollection.prototype.constructor = SetCollection;
  33441. return SetCollection;
  33442. }(Collection));
  33443. Collection.Keyed = KeyedCollection;
  33444. Collection.Indexed = IndexedCollection;
  33445. Collection.Set = SetCollection;
  33446. var IS_SEQ_SYMBOL = '@@__IMMUTABLE_SEQ__@@';
  33447. function isSeq(maybeSeq) {
  33448. return Boolean(maybeSeq && maybeSeq[IS_SEQ_SYMBOL]);
  33449. }
  33450. var IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@';
  33451. function isRecord(maybeRecord) {
  33452. return Boolean(maybeRecord && maybeRecord[IS_RECORD_SYMBOL]);
  33453. }
  33454. function isImmutable(maybeImmutable) {
  33455. return isCollection(maybeImmutable) || isRecord(maybeImmutable);
  33456. }
  33457. var IS_ORDERED_SYMBOL = '@@__IMMUTABLE_ORDERED__@@';
  33458. function isOrdered(maybeOrdered) {
  33459. return Boolean(maybeOrdered && maybeOrdered[IS_ORDERED_SYMBOL]);
  33460. }
  33461. var ITERATE_KEYS = 0;
  33462. var ITERATE_VALUES = 1;
  33463. var ITERATE_ENTRIES = 2;
  33464. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  33465. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  33466. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  33467. var Iterator = function Iterator(next) {
  33468. this.next = next;
  33469. };
  33470. Iterator.prototype.toString = function toString () {
  33471. return '[Iterator]';
  33472. };
  33473. Iterator.KEYS = ITERATE_KEYS;
  33474. Iterator.VALUES = ITERATE_VALUES;
  33475. Iterator.ENTRIES = ITERATE_ENTRIES;
  33476. Iterator.prototype.inspect = Iterator.prototype.toSource = function() {
  33477. return this.toString();
  33478. };
  33479. Iterator.prototype[ITERATOR_SYMBOL] = function() {
  33480. return this;
  33481. };
  33482. function iteratorValue(type, k, v, iteratorResult) {
  33483. var value = type === 0 ? k : type === 1 ? v : [k, v];
  33484. iteratorResult
  33485. ? (iteratorResult.value = value)
  33486. : (iteratorResult = {
  33487. value: value,
  33488. done: false,
  33489. });
  33490. return iteratorResult;
  33491. }
  33492. function iteratorDone() {
  33493. return { value: undefined, done: true };
  33494. }
  33495. function hasIterator(maybeIterable) {
  33496. return !!getIteratorFn(maybeIterable);
  33497. }
  33498. function isIterator(maybeIterator) {
  33499. return maybeIterator && typeof maybeIterator.next === 'function';
  33500. }
  33501. function getIterator(iterable) {
  33502. var iteratorFn = getIteratorFn(iterable);
  33503. return iteratorFn && iteratorFn.call(iterable);
  33504. }
  33505. function getIteratorFn(iterable) {
  33506. var iteratorFn =
  33507. iterable &&
  33508. ((REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  33509. iterable[FAUX_ITERATOR_SYMBOL]);
  33510. if (typeof iteratorFn === 'function') {
  33511. return iteratorFn;
  33512. }
  33513. }
  33514. var hasOwnProperty = Object.prototype.hasOwnProperty;
  33515. function isArrayLike(value) {
  33516. if (Array.isArray(value) || typeof value === 'string') {
  33517. return true;
  33518. }
  33519. return (
  33520. value &&
  33521. typeof value === 'object' &&
  33522. Number.isInteger(value.length) &&
  33523. value.length >= 0 &&
  33524. (value.length === 0
  33525. ? // Only {length: 0} is considered Array-like.
  33526. Object.keys(value).length === 1
  33527. : // An object is only Array-like if it has a property where the last value
  33528. // in the array-like may be found (which could be undefined).
  33529. value.hasOwnProperty(value.length - 1))
  33530. );
  33531. }
  33532. var Seq = /*@__PURE__*/(function (Collection$$1) {
  33533. function Seq(value) {
  33534. return value === null || value === undefined
  33535. ? emptySequence()
  33536. : isImmutable(value)
  33537. ? value.toSeq()
  33538. : seqFromValue(value);
  33539. }
  33540. if ( Collection$$1 ) Seq.__proto__ = Collection$$1;
  33541. Seq.prototype = Object.create( Collection$$1 && Collection$$1.prototype );
  33542. Seq.prototype.constructor = Seq;
  33543. Seq.prototype.toSeq = function toSeq () {
  33544. return this;
  33545. };
  33546. Seq.prototype.toString = function toString () {
  33547. return this.__toString('Seq {', '}');
  33548. };
  33549. Seq.prototype.cacheResult = function cacheResult () {
  33550. if (!this._cache && this.__iterateUncached) {
  33551. this._cache = this.entrySeq().toArray();
  33552. this.size = this._cache.length;
  33553. }
  33554. return this;
  33555. };
  33556. // abstract __iterateUncached(fn, reverse)
  33557. Seq.prototype.__iterate = function __iterate (fn, reverse) {
  33558. var cache = this._cache;
  33559. if (cache) {
  33560. var size = cache.length;
  33561. var i = 0;
  33562. while (i !== size) {
  33563. var entry = cache[reverse ? size - ++i : i++];
  33564. if (fn(entry[1], entry[0], this) === false) {
  33565. break;
  33566. }
  33567. }
  33568. return i;
  33569. }
  33570. return this.__iterateUncached(fn, reverse);
  33571. };
  33572. // abstract __iteratorUncached(type, reverse)
  33573. Seq.prototype.__iterator = function __iterator (type, reverse) {
  33574. var cache = this._cache;
  33575. if (cache) {
  33576. var size = cache.length;
  33577. var i = 0;
  33578. return new Iterator(function () {
  33579. if (i === size) {
  33580. return iteratorDone();
  33581. }
  33582. var entry = cache[reverse ? size - ++i : i++];
  33583. return iteratorValue(type, entry[0], entry[1]);
  33584. });
  33585. }
  33586. return this.__iteratorUncached(type, reverse);
  33587. };
  33588. return Seq;
  33589. }(Collection));
  33590. var KeyedSeq = /*@__PURE__*/(function (Seq) {
  33591. function KeyedSeq(value) {
  33592. return value === null || value === undefined
  33593. ? emptySequence().toKeyedSeq()
  33594. : isCollection(value)
  33595. ? isKeyed(value)
  33596. ? value.toSeq()
  33597. : value.fromEntrySeq()
  33598. : isRecord(value)
  33599. ? value.toSeq()
  33600. : keyedSeqFromValue(value);
  33601. }
  33602. if ( Seq ) KeyedSeq.__proto__ = Seq;
  33603. KeyedSeq.prototype = Object.create( Seq && Seq.prototype );
  33604. KeyedSeq.prototype.constructor = KeyedSeq;
  33605. KeyedSeq.prototype.toKeyedSeq = function toKeyedSeq () {
  33606. return this;
  33607. };
  33608. return KeyedSeq;
  33609. }(Seq));
  33610. var IndexedSeq = /*@__PURE__*/(function (Seq) {
  33611. function IndexedSeq(value) {
  33612. return value === null || value === undefined
  33613. ? emptySequence()
  33614. : isCollection(value)
  33615. ? isKeyed(value)
  33616. ? value.entrySeq()
  33617. : value.toIndexedSeq()
  33618. : isRecord(value)
  33619. ? value.toSeq().entrySeq()
  33620. : indexedSeqFromValue(value);
  33621. }
  33622. if ( Seq ) IndexedSeq.__proto__ = Seq;
  33623. IndexedSeq.prototype = Object.create( Seq && Seq.prototype );
  33624. IndexedSeq.prototype.constructor = IndexedSeq;
  33625. IndexedSeq.of = function of (/*...values*/) {
  33626. return IndexedSeq(arguments);
  33627. };
  33628. IndexedSeq.prototype.toIndexedSeq = function toIndexedSeq () {
  33629. return this;
  33630. };
  33631. IndexedSeq.prototype.toString = function toString () {
  33632. return this.__toString('Seq [', ']');
  33633. };
  33634. return IndexedSeq;
  33635. }(Seq));
  33636. var SetSeq = /*@__PURE__*/(function (Seq) {
  33637. function SetSeq(value) {
  33638. return (isCollection(value) && !isAssociative(value)
  33639. ? value
  33640. : IndexedSeq(value)
  33641. ).toSetSeq();
  33642. }
  33643. if ( Seq ) SetSeq.__proto__ = Seq;
  33644. SetSeq.prototype = Object.create( Seq && Seq.prototype );
  33645. SetSeq.prototype.constructor = SetSeq;
  33646. SetSeq.of = function of (/*...values*/) {
  33647. return SetSeq(arguments);
  33648. };
  33649. SetSeq.prototype.toSetSeq = function toSetSeq () {
  33650. return this;
  33651. };
  33652. return SetSeq;
  33653. }(Seq));
  33654. Seq.isSeq = isSeq;
  33655. Seq.Keyed = KeyedSeq;
  33656. Seq.Set = SetSeq;
  33657. Seq.Indexed = IndexedSeq;
  33658. Seq.prototype[IS_SEQ_SYMBOL] = true;
  33659. // #pragma Root Sequences
  33660. var ArraySeq = /*@__PURE__*/(function (IndexedSeq) {
  33661. function ArraySeq(array) {
  33662. this._array = array;
  33663. this.size = array.length;
  33664. }
  33665. if ( IndexedSeq ) ArraySeq.__proto__ = IndexedSeq;
  33666. ArraySeq.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
  33667. ArraySeq.prototype.constructor = ArraySeq;
  33668. ArraySeq.prototype.get = function get (index, notSetValue) {
  33669. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  33670. };
  33671. ArraySeq.prototype.__iterate = function __iterate (fn, reverse) {
  33672. var array = this._array;
  33673. var size = array.length;
  33674. var i = 0;
  33675. while (i !== size) {
  33676. var ii = reverse ? size - ++i : i++;
  33677. if (fn(array[ii], ii, this) === false) {
  33678. break;
  33679. }
  33680. }
  33681. return i;
  33682. };
  33683. ArraySeq.prototype.__iterator = function __iterator (type, reverse) {
  33684. var array = this._array;
  33685. var size = array.length;
  33686. var i = 0;
  33687. return new Iterator(function () {
  33688. if (i === size) {
  33689. return iteratorDone();
  33690. }
  33691. var ii = reverse ? size - ++i : i++;
  33692. return iteratorValue(type, ii, array[ii]);
  33693. });
  33694. };
  33695. return ArraySeq;
  33696. }(IndexedSeq));
  33697. var ObjectSeq = /*@__PURE__*/(function (KeyedSeq) {
  33698. function ObjectSeq(object) {
  33699. var keys = Object.keys(object);
  33700. this._object = object;
  33701. this._keys = keys;
  33702. this.size = keys.length;
  33703. }
  33704. if ( KeyedSeq ) ObjectSeq.__proto__ = KeyedSeq;
  33705. ObjectSeq.prototype = Object.create( KeyedSeq && KeyedSeq.prototype );
  33706. ObjectSeq.prototype.constructor = ObjectSeq;
  33707. ObjectSeq.prototype.get = function get (key, notSetValue) {
  33708. if (notSetValue !== undefined && !this.has(key)) {
  33709. return notSetValue;
  33710. }
  33711. return this._object[key];
  33712. };
  33713. ObjectSeq.prototype.has = function has (key) {
  33714. return hasOwnProperty.call(this._object, key);
  33715. };
  33716. ObjectSeq.prototype.__iterate = function __iterate (fn, reverse) {
  33717. var object = this._object;
  33718. var keys = this._keys;
  33719. var size = keys.length;
  33720. var i = 0;
  33721. while (i !== size) {
  33722. var key = keys[reverse ? size - ++i : i++];
  33723. if (fn(object[key], key, this) === false) {
  33724. break;
  33725. }
  33726. }
  33727. return i;
  33728. };
  33729. ObjectSeq.prototype.__iterator = function __iterator (type, reverse) {
  33730. var object = this._object;
  33731. var keys = this._keys;
  33732. var size = keys.length;
  33733. var i = 0;
  33734. return new Iterator(function () {
  33735. if (i === size) {
  33736. return iteratorDone();
  33737. }
  33738. var key = keys[reverse ? size - ++i : i++];
  33739. return iteratorValue(type, key, object[key]);
  33740. });
  33741. };
  33742. return ObjectSeq;
  33743. }(KeyedSeq));
  33744. ObjectSeq.prototype[IS_ORDERED_SYMBOL] = true;
  33745. var CollectionSeq = /*@__PURE__*/(function (IndexedSeq) {
  33746. function CollectionSeq(collection) {
  33747. this._collection = collection;
  33748. this.size = collection.length || collection.size;
  33749. }
  33750. if ( IndexedSeq ) CollectionSeq.__proto__ = IndexedSeq;
  33751. CollectionSeq.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
  33752. CollectionSeq.prototype.constructor = CollectionSeq;
  33753. CollectionSeq.prototype.__iterateUncached = function __iterateUncached (fn, reverse) {
  33754. if (reverse) {
  33755. return this.cacheResult().__iterate(fn, reverse);
  33756. }
  33757. var collection = this._collection;
  33758. var iterator = getIterator(collection);
  33759. var iterations = 0;
  33760. if (isIterator(iterator)) {
  33761. var step;
  33762. while (!(step = iterator.next()).done) {
  33763. if (fn(step.value, iterations++, this) === false) {
  33764. break;
  33765. }
  33766. }
  33767. }
  33768. return iterations;
  33769. };
  33770. CollectionSeq.prototype.__iteratorUncached = function __iteratorUncached (type, reverse) {
  33771. if (reverse) {
  33772. return this.cacheResult().__iterator(type, reverse);
  33773. }
  33774. var collection = this._collection;
  33775. var iterator = getIterator(collection);
  33776. if (!isIterator(iterator)) {
  33777. return new Iterator(iteratorDone);
  33778. }
  33779. var iterations = 0;
  33780. return new Iterator(function () {
  33781. var step = iterator.next();
  33782. return step.done ? step : iteratorValue(type, iterations++, step.value);
  33783. });
  33784. };
  33785. return CollectionSeq;
  33786. }(IndexedSeq));
  33787. // # pragma Helper functions
  33788. var EMPTY_SEQ;
  33789. function emptySequence() {
  33790. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  33791. }
  33792. function keyedSeqFromValue(value) {
  33793. var seq = Array.isArray(value)
  33794. ? new ArraySeq(value)
  33795. : hasIterator(value)
  33796. ? new CollectionSeq(value)
  33797. : undefined;
  33798. if (seq) {
  33799. return seq.fromEntrySeq();
  33800. }
  33801. if (typeof value === 'object') {
  33802. return new ObjectSeq(value);
  33803. }
  33804. throw new TypeError(
  33805. 'Expected Array or collection object of [k, v] entries, or keyed object: ' +
  33806. value
  33807. );
  33808. }
  33809. function indexedSeqFromValue(value) {
  33810. var seq = maybeIndexedSeqFromValue(value);
  33811. if (seq) {
  33812. return seq;
  33813. }
  33814. throw new TypeError(
  33815. 'Expected Array or collection object of values: ' + value
  33816. );
  33817. }
  33818. function seqFromValue(value) {
  33819. var seq = maybeIndexedSeqFromValue(value);
  33820. if (seq) {
  33821. return seq;
  33822. }
  33823. if (typeof value === 'object') {
  33824. return new ObjectSeq(value);
  33825. }
  33826. throw new TypeError(
  33827. 'Expected Array or collection object of values, or keyed object: ' + value
  33828. );
  33829. }
  33830. function maybeIndexedSeqFromValue(value) {
  33831. return isArrayLike(value)
  33832. ? new ArraySeq(value)
  33833. : hasIterator(value)
  33834. ? new CollectionSeq(value)
  33835. : undefined;
  33836. }
  33837. var IS_MAP_SYMBOL = '@@__IMMUTABLE_MAP__@@';
  33838. function isMap(maybeMap) {
  33839. return Boolean(maybeMap && maybeMap[IS_MAP_SYMBOL]);
  33840. }
  33841. function isOrderedMap(maybeOrderedMap) {
  33842. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  33843. }
  33844. function isValueObject(maybeValue) {
  33845. return Boolean(
  33846. maybeValue &&
  33847. typeof maybeValue.equals === 'function' &&
  33848. typeof maybeValue.hashCode === 'function'
  33849. );
  33850. }
  33851. /**
  33852. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  33853. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  33854. *
  33855. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  33856. * value, which is different from the algorithm described by
  33857. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  33858. *
  33859. * This is extended further to allow Objects to describe the values they
  33860. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  33861. *
  33862. * Note: because of this extension, the key equality of Immutable.Map and the
  33863. * value equality of Immutable.Set will differ from ES6 Map and Set.
  33864. *
  33865. * ### Defining custom values
  33866. *
  33867. * The easiest way to describe the value an object represents is by implementing
  33868. * `valueOf`. For example, `Date` represents a value by returning a unix
  33869. * timestamp for `valueOf`:
  33870. *
  33871. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  33872. * var date2 = new Date(1234567890000);
  33873. * date1.valueOf(); // 1234567890000
  33874. * assert( date1 !== date2 );
  33875. * assert( Immutable.is( date1, date2 ) );
  33876. *
  33877. * Note: overriding `valueOf` may have other implications if you use this object
  33878. * where JavaScript expects a primitive, such as implicit string coercion.
  33879. *
  33880. * For more complex types, especially collections, implementing `valueOf` may
  33881. * not be performant. An alternative is to implement `equals` and `hashCode`.
  33882. *
  33883. * `equals` takes another object, presumably of similar type, and returns true
  33884. * if it is equal. Equality is symmetrical, so the same result should be
  33885. * returned if this and the argument are flipped.
  33886. *
  33887. * assert( a.equals(b) === b.equals(a) );
  33888. *
  33889. * `hashCode` returns a 32bit integer number representing the object which will
  33890. * be used to determine how to store the value object in a Map or Set. You must
  33891. * provide both or neither methods, one must not exist without the other.
  33892. *
  33893. * Also, an important relationship between these methods must be upheld: if two
  33894. * values are equal, they *must* return the same hashCode. If the values are not
  33895. * equal, they might have the same hashCode; this is called a hash collision,
  33896. * and while undesirable for performance reasons, it is acceptable.
  33897. *
  33898. * if (a.equals(b)) {
  33899. * assert( a.hashCode() === b.hashCode() );
  33900. * }
  33901. *
  33902. * All Immutable collections are Value Objects: they implement `equals()`
  33903. * and `hashCode()`.
  33904. */
  33905. function is(valueA, valueB) {
  33906. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  33907. return true;
  33908. }
  33909. if (!valueA || !valueB) {
  33910. return false;
  33911. }
  33912. if (
  33913. typeof valueA.valueOf === 'function' &&
  33914. typeof valueB.valueOf === 'function'
  33915. ) {
  33916. valueA = valueA.valueOf();
  33917. valueB = valueB.valueOf();
  33918. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  33919. return true;
  33920. }
  33921. if (!valueA || !valueB) {
  33922. return false;
  33923. }
  33924. }
  33925. return !!(
  33926. isValueObject(valueA) &&
  33927. isValueObject(valueB) &&
  33928. valueA.equals(valueB)
  33929. );
  33930. }
  33931. var imul =
  33932. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2
  33933. ? Math.imul
  33934. : function imul(a, b) {
  33935. a |= 0; // int
  33936. b |= 0; // int
  33937. var c = a & 0xffff;
  33938. var d = b & 0xffff;
  33939. // Shift by 0 fixes the sign on the high part.
  33940. return (c * d + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0)) | 0; // int
  33941. };
  33942. // v8 has an optimization for storing 31-bit signed numbers.
  33943. // Values which have either 00 or 11 as the high order bits qualify.
  33944. // This function drops the highest order bit in a signed number, maintaining
  33945. // the sign bit.
  33946. function smi(i32) {
  33947. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xbfffffff);
  33948. }
  33949. var defaultValueOf = Object.prototype.valueOf;
  33950. function hash(o) {
  33951. switch (typeof o) {
  33952. case 'boolean':
  33953. // The hash values for built-in constants are a 1 value for each 5-byte
  33954. // shift region expect for the first, which encodes the value. This
  33955. // reduces the odds of a hash collision for these common values.
  33956. return o ? 0x42108421 : 0x42108420;
  33957. case 'number':
  33958. return hashNumber(o);
  33959. case 'string':
  33960. return o.length > STRING_HASH_CACHE_MIN_STRLEN
  33961. ? cachedHashString(o)
  33962. : hashString(o);
  33963. case 'object':
  33964. case 'function':
  33965. if (o === null) {
  33966. return 0x42108422;
  33967. }
  33968. if (typeof o.hashCode === 'function') {
  33969. // Drop any high bits from accidentally long hash codes.
  33970. return smi(o.hashCode(o));
  33971. }
  33972. if (o.valueOf !== defaultValueOf && typeof o.valueOf === 'function') {
  33973. o = o.valueOf(o);
  33974. }
  33975. return hashJSObj(o);
  33976. case 'undefined':
  33977. return 0x42108423;
  33978. default:
  33979. if (typeof o.toString === 'function') {
  33980. return hashString(o.toString());
  33981. }
  33982. throw new Error('Value type ' + typeof o + ' cannot be hashed.');
  33983. }
  33984. }
  33985. // Compress arbitrarily large numbers into smi hashes.
  33986. function hashNumber(n) {
  33987. if (n !== n || n === Infinity) {
  33988. return 0;
  33989. }
  33990. var hash = n | 0;
  33991. if (hash !== n) {
  33992. hash ^= n * 0xffffffff;
  33993. }
  33994. while (n > 0xffffffff) {
  33995. n /= 0xffffffff;
  33996. hash ^= n;
  33997. }
  33998. return smi(hash);
  33999. }
  34000. function cachedHashString(string) {
  34001. var hashed = stringHashCache[string];
  34002. if (hashed === undefined) {
  34003. hashed = hashString(string);
  34004. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  34005. STRING_HASH_CACHE_SIZE = 0;
  34006. stringHashCache = {};
  34007. }
  34008. STRING_HASH_CACHE_SIZE++;
  34009. stringHashCache[string] = hashed;
  34010. }
  34011. return hashed;
  34012. }
  34013. // http://jsperf.com/hashing-strings
  34014. function hashString(string) {
  34015. // This is the hash from JVM
  34016. // The hash code for a string is computed as
  34017. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  34018. // where s[i] is the ith character of the string and n is the length of
  34019. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  34020. // (exclusive) by dropping high bits.
  34021. var hashed = 0;
  34022. for (var ii = 0; ii < string.length; ii++) {
  34023. hashed = (31 * hashed + string.charCodeAt(ii)) | 0;
  34024. }
  34025. return smi(hashed);
  34026. }
  34027. function hashJSObj(obj) {
  34028. var hashed;
  34029. if (usingWeakMap) {
  34030. hashed = weakMap.get(obj);
  34031. if (hashed !== undefined) {
  34032. return hashed;
  34033. }
  34034. }
  34035. hashed = obj[UID_HASH_KEY];
  34036. if (hashed !== undefined) {
  34037. return hashed;
  34038. }
  34039. if (!canDefineProperty) {
  34040. hashed = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  34041. if (hashed !== undefined) {
  34042. return hashed;
  34043. }
  34044. hashed = getIENodeHash(obj);
  34045. if (hashed !== undefined) {
  34046. return hashed;
  34047. }
  34048. }
  34049. hashed = ++objHashUID;
  34050. if (objHashUID & 0x40000000) {
  34051. objHashUID = 0;
  34052. }
  34053. if (usingWeakMap) {
  34054. weakMap.set(obj, hashed);
  34055. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  34056. throw new Error('Non-extensible objects are not allowed as keys.');
  34057. } else if (canDefineProperty) {
  34058. Object.defineProperty(obj, UID_HASH_KEY, {
  34059. enumerable: false,
  34060. configurable: false,
  34061. writable: false,
  34062. value: hashed,
  34063. });
  34064. } else if (
  34065. obj.propertyIsEnumerable !== undefined &&
  34066. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable
  34067. ) {
  34068. // Since we can't define a non-enumerable property on the object
  34069. // we'll hijack one of the less-used non-enumerable properties to
  34070. // save our hash on it. Since this is a function it will not show up in
  34071. // `JSON.stringify` which is what we want.
  34072. obj.propertyIsEnumerable = function() {
  34073. return this.constructor.prototype.propertyIsEnumerable.apply(
  34074. this,
  34075. arguments
  34076. );
  34077. };
  34078. obj.propertyIsEnumerable[UID_HASH_KEY] = hashed;
  34079. } else if (obj.nodeType !== undefined) {
  34080. // At this point we couldn't get the IE `uniqueID` to use as a hash
  34081. // and we couldn't use a non-enumerable property to exploit the
  34082. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  34083. // itself.
  34084. obj[UID_HASH_KEY] = hashed;
  34085. } else {
  34086. throw new Error('Unable to set a non-enumerable property on object.');
  34087. }
  34088. return hashed;
  34089. }
  34090. // Get references to ES5 object methods.
  34091. var isExtensible = Object.isExtensible;
  34092. // True if Object.defineProperty works as expected. IE8 fails this test.
  34093. var canDefineProperty = (function() {
  34094. try {
  34095. Object.defineProperty({}, '@', {});
  34096. return true;
  34097. } catch (e) {
  34098. return false;
  34099. }
  34100. })();
  34101. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  34102. // and avoid memory leaks from the IE cloneNode bug.
  34103. function getIENodeHash(node) {
  34104. if (node && node.nodeType > 0) {
  34105. switch (node.nodeType) {
  34106. case 1: // Element
  34107. return node.uniqueID;
  34108. case 9: // Document
  34109. return node.documentElement && node.documentElement.uniqueID;
  34110. }
  34111. }
  34112. }
  34113. // If possible, use a WeakMap.
  34114. var usingWeakMap = typeof WeakMap === 'function';
  34115. var weakMap;
  34116. if (usingWeakMap) {
  34117. weakMap = new WeakMap();
  34118. }
  34119. var objHashUID = 0;
  34120. var UID_HASH_KEY = '__immutablehash__';
  34121. if (typeof Symbol === 'function') {
  34122. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  34123. }
  34124. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  34125. var STRING_HASH_CACHE_MAX_SIZE = 255;
  34126. var STRING_HASH_CACHE_SIZE = 0;
  34127. var stringHashCache = {};
  34128. var ToKeyedSequence = /*@__PURE__*/(function (KeyedSeq$$1) {
  34129. function ToKeyedSequence(indexed, useKeys) {
  34130. this._iter = indexed;
  34131. this._useKeys = useKeys;
  34132. this.size = indexed.size;
  34133. }
  34134. if ( KeyedSeq$$1 ) ToKeyedSequence.__proto__ = KeyedSeq$$1;
  34135. ToKeyedSequence.prototype = Object.create( KeyedSeq$$1 && KeyedSeq$$1.prototype );
  34136. ToKeyedSequence.prototype.constructor = ToKeyedSequence;
  34137. ToKeyedSequence.prototype.get = function get (key, notSetValue) {
  34138. return this._iter.get(key, notSetValue);
  34139. };
  34140. ToKeyedSequence.prototype.has = function has (key) {
  34141. return this._iter.has(key);
  34142. };
  34143. ToKeyedSequence.prototype.valueSeq = function valueSeq () {
  34144. return this._iter.valueSeq();
  34145. };
  34146. ToKeyedSequence.prototype.reverse = function reverse () {
  34147. var this$1 = this;
  34148. var reversedSequence = reverseFactory(this, true);
  34149. if (!this._useKeys) {
  34150. reversedSequence.valueSeq = function () { return this$1._iter.toSeq().reverse(); };
  34151. }
  34152. return reversedSequence;
  34153. };
  34154. ToKeyedSequence.prototype.map = function map (mapper, context) {
  34155. var this$1 = this;
  34156. var mappedSequence = mapFactory(this, mapper, context);
  34157. if (!this._useKeys) {
  34158. mappedSequence.valueSeq = function () { return this$1._iter.toSeq().map(mapper, context); };
  34159. }
  34160. return mappedSequence;
  34161. };
  34162. ToKeyedSequence.prototype.__iterate = function __iterate (fn, reverse) {
  34163. var this$1 = this;
  34164. return this._iter.__iterate(function (v, k) { return fn(v, k, this$1); }, reverse);
  34165. };
  34166. ToKeyedSequence.prototype.__iterator = function __iterator (type, reverse) {
  34167. return this._iter.__iterator(type, reverse);
  34168. };
  34169. return ToKeyedSequence;
  34170. }(KeyedSeq));
  34171. ToKeyedSequence.prototype[IS_ORDERED_SYMBOL] = true;
  34172. var ToIndexedSequence = /*@__PURE__*/(function (IndexedSeq$$1) {
  34173. function ToIndexedSequence(iter) {
  34174. this._iter = iter;
  34175. this.size = iter.size;
  34176. }
  34177. if ( IndexedSeq$$1 ) ToIndexedSequence.__proto__ = IndexedSeq$$1;
  34178. ToIndexedSequence.prototype = Object.create( IndexedSeq$$1 && IndexedSeq$$1.prototype );
  34179. ToIndexedSequence.prototype.constructor = ToIndexedSequence;
  34180. ToIndexedSequence.prototype.includes = function includes (value) {
  34181. return this._iter.includes(value);
  34182. };
  34183. ToIndexedSequence.prototype.__iterate = function __iterate (fn, reverse) {
  34184. var this$1 = this;
  34185. var i = 0;
  34186. reverse && ensureSize(this);
  34187. return this._iter.__iterate(
  34188. function (v) { return fn(v, reverse ? this$1.size - ++i : i++, this$1); },
  34189. reverse
  34190. );
  34191. };
  34192. ToIndexedSequence.prototype.__iterator = function __iterator (type, reverse) {
  34193. var this$1 = this;
  34194. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  34195. var i = 0;
  34196. reverse && ensureSize(this);
  34197. return new Iterator(function () {
  34198. var step = iterator.next();
  34199. return step.done
  34200. ? step
  34201. : iteratorValue(
  34202. type,
  34203. reverse ? this$1.size - ++i : i++,
  34204. step.value,
  34205. step
  34206. );
  34207. });
  34208. };
  34209. return ToIndexedSequence;
  34210. }(IndexedSeq));
  34211. var ToSetSequence = /*@__PURE__*/(function (SetSeq$$1) {
  34212. function ToSetSequence(iter) {
  34213. this._iter = iter;
  34214. this.size = iter.size;
  34215. }
  34216. if ( SetSeq$$1 ) ToSetSequence.__proto__ = SetSeq$$1;
  34217. ToSetSequence.prototype = Object.create( SetSeq$$1 && SetSeq$$1.prototype );
  34218. ToSetSequence.prototype.constructor = ToSetSequence;
  34219. ToSetSequence.prototype.has = function has (key) {
  34220. return this._iter.includes(key);
  34221. };
  34222. ToSetSequence.prototype.__iterate = function __iterate (fn, reverse) {
  34223. var this$1 = this;
  34224. return this._iter.__iterate(function (v) { return fn(v, v, this$1); }, reverse);
  34225. };
  34226. ToSetSequence.prototype.__iterator = function __iterator (type, reverse) {
  34227. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  34228. return new Iterator(function () {
  34229. var step = iterator.next();
  34230. return step.done
  34231. ? step
  34232. : iteratorValue(type, step.value, step.value, step);
  34233. });
  34234. };
  34235. return ToSetSequence;
  34236. }(SetSeq));
  34237. var FromEntriesSequence = /*@__PURE__*/(function (KeyedSeq$$1) {
  34238. function FromEntriesSequence(entries) {
  34239. this._iter = entries;
  34240. this.size = entries.size;
  34241. }
  34242. if ( KeyedSeq$$1 ) FromEntriesSequence.__proto__ = KeyedSeq$$1;
  34243. FromEntriesSequence.prototype = Object.create( KeyedSeq$$1 && KeyedSeq$$1.prototype );
  34244. FromEntriesSequence.prototype.constructor = FromEntriesSequence;
  34245. FromEntriesSequence.prototype.entrySeq = function entrySeq () {
  34246. return this._iter.toSeq();
  34247. };
  34248. FromEntriesSequence.prototype.__iterate = function __iterate (fn, reverse) {
  34249. var this$1 = this;
  34250. return this._iter.__iterate(function (entry) {
  34251. // Check if entry exists first so array access doesn't throw for holes
  34252. // in the parent iteration.
  34253. if (entry) {
  34254. validateEntry(entry);
  34255. var indexedCollection = isCollection(entry);
  34256. return fn(
  34257. indexedCollection ? entry.get(1) : entry[1],
  34258. indexedCollection ? entry.get(0) : entry[0],
  34259. this$1
  34260. );
  34261. }
  34262. }, reverse);
  34263. };
  34264. FromEntriesSequence.prototype.__iterator = function __iterator (type, reverse) {
  34265. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  34266. return new Iterator(function () {
  34267. while (true) {
  34268. var step = iterator.next();
  34269. if (step.done) {
  34270. return step;
  34271. }
  34272. var entry = step.value;
  34273. // Check if entry exists first so array access doesn't throw for holes
  34274. // in the parent iteration.
  34275. if (entry) {
  34276. validateEntry(entry);
  34277. var indexedCollection = isCollection(entry);
  34278. return iteratorValue(
  34279. type,
  34280. indexedCollection ? entry.get(0) : entry[0],
  34281. indexedCollection ? entry.get(1) : entry[1],
  34282. step
  34283. );
  34284. }
  34285. }
  34286. });
  34287. };
  34288. return FromEntriesSequence;
  34289. }(KeyedSeq));
  34290. ToIndexedSequence.prototype.cacheResult = ToKeyedSequence.prototype.cacheResult = ToSetSequence.prototype.cacheResult = FromEntriesSequence.prototype.cacheResult = cacheResultThrough;
  34291. function flipFactory(collection) {
  34292. var flipSequence = makeSequence(collection);
  34293. flipSequence._iter = collection;
  34294. flipSequence.size = collection.size;
  34295. flipSequence.flip = function () { return collection; };
  34296. flipSequence.reverse = function() {
  34297. var reversedSequence = collection.reverse.apply(this); // super.reverse()
  34298. reversedSequence.flip = function () { return collection.reverse(); };
  34299. return reversedSequence;
  34300. };
  34301. flipSequence.has = function (key) { return collection.includes(key); };
  34302. flipSequence.includes = function (key) { return collection.has(key); };
  34303. flipSequence.cacheResult = cacheResultThrough;
  34304. flipSequence.__iterateUncached = function(fn, reverse) {
  34305. var this$1 = this;
  34306. return collection.__iterate(function (v, k) { return fn(k, v, this$1) !== false; }, reverse);
  34307. };
  34308. flipSequence.__iteratorUncached = function(type, reverse) {
  34309. if (type === ITERATE_ENTRIES) {
  34310. var iterator = collection.__iterator(type, reverse);
  34311. return new Iterator(function () {
  34312. var step = iterator.next();
  34313. if (!step.done) {
  34314. var k = step.value[0];
  34315. step.value[0] = step.value[1];
  34316. step.value[1] = k;
  34317. }
  34318. return step;
  34319. });
  34320. }
  34321. return collection.__iterator(
  34322. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  34323. reverse
  34324. );
  34325. };
  34326. return flipSequence;
  34327. }
  34328. function mapFactory(collection, mapper, context) {
  34329. var mappedSequence = makeSequence(collection);
  34330. mappedSequence.size = collection.size;
  34331. mappedSequence.has = function (key) { return collection.has(key); };
  34332. mappedSequence.get = function (key, notSetValue) {
  34333. var v = collection.get(key, NOT_SET);
  34334. return v === NOT_SET
  34335. ? notSetValue
  34336. : mapper.call(context, v, key, collection);
  34337. };
  34338. mappedSequence.__iterateUncached = function(fn, reverse) {
  34339. var this$1 = this;
  34340. return collection.__iterate(
  34341. function (v, k, c) { return fn(mapper.call(context, v, k, c), k, this$1) !== false; },
  34342. reverse
  34343. );
  34344. };
  34345. mappedSequence.__iteratorUncached = function(type, reverse) {
  34346. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  34347. return new Iterator(function () {
  34348. var step = iterator.next();
  34349. if (step.done) {
  34350. return step;
  34351. }
  34352. var entry = step.value;
  34353. var key = entry[0];
  34354. return iteratorValue(
  34355. type,
  34356. key,
  34357. mapper.call(context, entry[1], key, collection),
  34358. step
  34359. );
  34360. });
  34361. };
  34362. return mappedSequence;
  34363. }
  34364. function reverseFactory(collection, useKeys) {
  34365. var this$1 = this;
  34366. var reversedSequence = makeSequence(collection);
  34367. reversedSequence._iter = collection;
  34368. reversedSequence.size = collection.size;
  34369. reversedSequence.reverse = function () { return collection; };
  34370. if (collection.flip) {
  34371. reversedSequence.flip = function() {
  34372. var flipSequence = flipFactory(collection);
  34373. flipSequence.reverse = function () { return collection.flip(); };
  34374. return flipSequence;
  34375. };
  34376. }
  34377. reversedSequence.get = function (key, notSetValue) { return collection.get(useKeys ? key : -1 - key, notSetValue); };
  34378. reversedSequence.has = function (key) { return collection.has(useKeys ? key : -1 - key); };
  34379. reversedSequence.includes = function (value) { return collection.includes(value); };
  34380. reversedSequence.cacheResult = cacheResultThrough;
  34381. reversedSequence.__iterate = function(fn, reverse) {
  34382. var this$1 = this;
  34383. var i = 0;
  34384. reverse && ensureSize(collection);
  34385. return collection.__iterate(
  34386. function (v, k) { return fn(v, useKeys ? k : reverse ? this$1.size - ++i : i++, this$1); },
  34387. !reverse
  34388. );
  34389. };
  34390. reversedSequence.__iterator = function (type, reverse) {
  34391. var i = 0;
  34392. reverse && ensureSize(collection);
  34393. var iterator = collection.__iterator(ITERATE_ENTRIES, !reverse);
  34394. return new Iterator(function () {
  34395. var step = iterator.next();
  34396. if (step.done) {
  34397. return step;
  34398. }
  34399. var entry = step.value;
  34400. return iteratorValue(
  34401. type,
  34402. useKeys ? entry[0] : reverse ? this$1.size - ++i : i++,
  34403. entry[1],
  34404. step
  34405. );
  34406. });
  34407. };
  34408. return reversedSequence;
  34409. }
  34410. function filterFactory(collection, predicate, context, useKeys) {
  34411. var filterSequence = makeSequence(collection);
  34412. if (useKeys) {
  34413. filterSequence.has = function (key) {
  34414. var v = collection.get(key, NOT_SET);
  34415. return v !== NOT_SET && !!predicate.call(context, v, key, collection);
  34416. };
  34417. filterSequence.get = function (key, notSetValue) {
  34418. var v = collection.get(key, NOT_SET);
  34419. return v !== NOT_SET && predicate.call(context, v, key, collection)
  34420. ? v
  34421. : notSetValue;
  34422. };
  34423. }
  34424. filterSequence.__iterateUncached = function(fn, reverse) {
  34425. var this$1 = this;
  34426. var iterations = 0;
  34427. collection.__iterate(function (v, k, c) {
  34428. if (predicate.call(context, v, k, c)) {
  34429. iterations++;
  34430. return fn(v, useKeys ? k : iterations - 1, this$1);
  34431. }
  34432. }, reverse);
  34433. return iterations;
  34434. };
  34435. filterSequence.__iteratorUncached = function(type, reverse) {
  34436. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  34437. var iterations = 0;
  34438. return new Iterator(function () {
  34439. while (true) {
  34440. var step = iterator.next();
  34441. if (step.done) {
  34442. return step;
  34443. }
  34444. var entry = step.value;
  34445. var key = entry[0];
  34446. var value = entry[1];
  34447. if (predicate.call(context, value, key, collection)) {
  34448. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  34449. }
  34450. }
  34451. });
  34452. };
  34453. return filterSequence;
  34454. }
  34455. function countByFactory(collection, grouper, context) {
  34456. var groups = Map().asMutable();
  34457. collection.__iterate(function (v, k) {
  34458. groups.update(grouper.call(context, v, k, collection), 0, function (a) { return a + 1; });
  34459. });
  34460. return groups.asImmutable();
  34461. }
  34462. function groupByFactory(collection, grouper, context) {
  34463. var isKeyedIter = isKeyed(collection);
  34464. var groups = (isOrdered(collection) ? OrderedMap() : Map()).asMutable();
  34465. collection.__iterate(function (v, k) {
  34466. groups.update(
  34467. grouper.call(context, v, k, collection),
  34468. function (a) { return ((a = a || []), a.push(isKeyedIter ? [k, v] : v), a); }
  34469. );
  34470. });
  34471. var coerce = collectionClass(collection);
  34472. return groups.map(function (arr) { return reify(collection, coerce(arr)); }).asImmutable();
  34473. }
  34474. function sliceFactory(collection, begin, end, useKeys) {
  34475. var originalSize = collection.size;
  34476. if (wholeSlice(begin, end, originalSize)) {
  34477. return collection;
  34478. }
  34479. var resolvedBegin = resolveBegin(begin, originalSize);
  34480. var resolvedEnd = resolveEnd(end, originalSize);
  34481. // begin or end will be NaN if they were provided as negative numbers and
  34482. // this collection's size is unknown. In that case, cache first so there is
  34483. // a known size and these do not resolve to NaN.
  34484. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  34485. return sliceFactory(collection.toSeq().cacheResult(), begin, end, useKeys);
  34486. }
  34487. // Note: resolvedEnd is undefined when the original sequence's length is
  34488. // unknown and this slice did not supply an end and should contain all
  34489. // elements after resolvedBegin.
  34490. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  34491. var resolvedSize = resolvedEnd - resolvedBegin;
  34492. var sliceSize;
  34493. if (resolvedSize === resolvedSize) {
  34494. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  34495. }
  34496. var sliceSeq = makeSequence(collection);
  34497. // If collection.size is undefined, the size of the realized sliceSeq is
  34498. // unknown at this point unless the number of items to slice is 0
  34499. sliceSeq.size =
  34500. sliceSize === 0 ? sliceSize : (collection.size && sliceSize) || undefined;
  34501. if (!useKeys && isSeq(collection) && sliceSize >= 0) {
  34502. sliceSeq.get = function(index, notSetValue) {
  34503. index = wrapIndex(this, index);
  34504. return index >= 0 && index < sliceSize
  34505. ? collection.get(index + resolvedBegin, notSetValue)
  34506. : notSetValue;
  34507. };
  34508. }
  34509. sliceSeq.__iterateUncached = function(fn, reverse) {
  34510. var this$1 = this;
  34511. if (sliceSize === 0) {
  34512. return 0;
  34513. }
  34514. if (reverse) {
  34515. return this.cacheResult().__iterate(fn, reverse);
  34516. }
  34517. var skipped = 0;
  34518. var isSkipping = true;
  34519. var iterations = 0;
  34520. collection.__iterate(function (v, k) {
  34521. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  34522. iterations++;
  34523. return (
  34524. fn(v, useKeys ? k : iterations - 1, this$1) !== false &&
  34525. iterations !== sliceSize
  34526. );
  34527. }
  34528. });
  34529. return iterations;
  34530. };
  34531. sliceSeq.__iteratorUncached = function(type, reverse) {
  34532. if (sliceSize !== 0 && reverse) {
  34533. return this.cacheResult().__iterator(type, reverse);
  34534. }
  34535. // Don't bother instantiating parent iterator if taking 0.
  34536. if (sliceSize === 0) {
  34537. return new Iterator(iteratorDone);
  34538. }
  34539. var iterator = collection.__iterator(type, reverse);
  34540. var skipped = 0;
  34541. var iterations = 0;
  34542. return new Iterator(function () {
  34543. while (skipped++ < resolvedBegin) {
  34544. iterator.next();
  34545. }
  34546. if (++iterations > sliceSize) {
  34547. return iteratorDone();
  34548. }
  34549. var step = iterator.next();
  34550. if (useKeys || type === ITERATE_VALUES || step.done) {
  34551. return step;
  34552. }
  34553. if (type === ITERATE_KEYS) {
  34554. return iteratorValue(type, iterations - 1, undefined, step);
  34555. }
  34556. return iteratorValue(type, iterations - 1, step.value[1], step);
  34557. });
  34558. };
  34559. return sliceSeq;
  34560. }
  34561. function takeWhileFactory(collection, predicate, context) {
  34562. var takeSequence = makeSequence(collection);
  34563. takeSequence.__iterateUncached = function(fn, reverse) {
  34564. var this$1 = this;
  34565. if (reverse) {
  34566. return this.cacheResult().__iterate(fn, reverse);
  34567. }
  34568. var iterations = 0;
  34569. collection.__iterate(
  34570. function (v, k, c) { return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$1); }
  34571. );
  34572. return iterations;
  34573. };
  34574. takeSequence.__iteratorUncached = function(type, reverse) {
  34575. var this$1 = this;
  34576. if (reverse) {
  34577. return this.cacheResult().__iterator(type, reverse);
  34578. }
  34579. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  34580. var iterating = true;
  34581. return new Iterator(function () {
  34582. if (!iterating) {
  34583. return iteratorDone();
  34584. }
  34585. var step = iterator.next();
  34586. if (step.done) {
  34587. return step;
  34588. }
  34589. var entry = step.value;
  34590. var k = entry[0];
  34591. var v = entry[1];
  34592. if (!predicate.call(context, v, k, this$1)) {
  34593. iterating = false;
  34594. return iteratorDone();
  34595. }
  34596. return type === ITERATE_ENTRIES ? step : iteratorValue(type, k, v, step);
  34597. });
  34598. };
  34599. return takeSequence;
  34600. }
  34601. function skipWhileFactory(collection, predicate, context, useKeys) {
  34602. var skipSequence = makeSequence(collection);
  34603. skipSequence.__iterateUncached = function(fn, reverse) {
  34604. var this$1 = this;
  34605. if (reverse) {
  34606. return this.cacheResult().__iterate(fn, reverse);
  34607. }
  34608. var isSkipping = true;
  34609. var iterations = 0;
  34610. collection.__iterate(function (v, k, c) {
  34611. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  34612. iterations++;
  34613. return fn(v, useKeys ? k : iterations - 1, this$1);
  34614. }
  34615. });
  34616. return iterations;
  34617. };
  34618. skipSequence.__iteratorUncached = function(type, reverse) {
  34619. var this$1 = this;
  34620. if (reverse) {
  34621. return this.cacheResult().__iterator(type, reverse);
  34622. }
  34623. var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
  34624. var skipping = true;
  34625. var iterations = 0;
  34626. return new Iterator(function () {
  34627. var step;
  34628. var k;
  34629. var v;
  34630. do {
  34631. step = iterator.next();
  34632. if (step.done) {
  34633. if (useKeys || type === ITERATE_VALUES) {
  34634. return step;
  34635. }
  34636. if (type === ITERATE_KEYS) {
  34637. return iteratorValue(type, iterations++, undefined, step);
  34638. }
  34639. return iteratorValue(type, iterations++, step.value[1], step);
  34640. }
  34641. var entry = step.value;
  34642. k = entry[0];
  34643. v = entry[1];
  34644. skipping && (skipping = predicate.call(context, v, k, this$1));
  34645. } while (skipping);
  34646. return type === ITERATE_ENTRIES ? step : iteratorValue(type, k, v, step);
  34647. });
  34648. };
  34649. return skipSequence;
  34650. }
  34651. function concatFactory(collection, values) {
  34652. var isKeyedCollection = isKeyed(collection);
  34653. var iters = [collection]
  34654. .concat(values)
  34655. .map(function (v) {
  34656. if (!isCollection(v)) {
  34657. v = isKeyedCollection
  34658. ? keyedSeqFromValue(v)
  34659. : indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  34660. } else if (isKeyedCollection) {
  34661. v = KeyedCollection(v);
  34662. }
  34663. return v;
  34664. })
  34665. .filter(function (v) { return v.size !== 0; });
  34666. if (iters.length === 0) {
  34667. return collection;
  34668. }
  34669. if (iters.length === 1) {
  34670. var singleton = iters[0];
  34671. if (
  34672. singleton === collection ||
  34673. (isKeyedCollection && isKeyed(singleton)) ||
  34674. (isIndexed(collection) && isIndexed(singleton))
  34675. ) {
  34676. return singleton;
  34677. }
  34678. }
  34679. var concatSeq = new ArraySeq(iters);
  34680. if (isKeyedCollection) {
  34681. concatSeq = concatSeq.toKeyedSeq();
  34682. } else if (!isIndexed(collection)) {
  34683. concatSeq = concatSeq.toSetSeq();
  34684. }
  34685. concatSeq = concatSeq.flatten(true);
  34686. concatSeq.size = iters.reduce(function (sum, seq) {
  34687. if (sum !== undefined) {
  34688. var size = seq.size;
  34689. if (size !== undefined) {
  34690. return sum + size;
  34691. }
  34692. }
  34693. }, 0);
  34694. return concatSeq;
  34695. }
  34696. function flattenFactory(collection, depth, useKeys) {
  34697. var flatSequence = makeSequence(collection);
  34698. flatSequence.__iterateUncached = function(fn, reverse) {
  34699. if (reverse) {
  34700. return this.cacheResult().__iterate(fn, reverse);
  34701. }
  34702. var iterations = 0;
  34703. var stopped = false;
  34704. function flatDeep(iter, currentDepth) {
  34705. iter.__iterate(function (v, k) {
  34706. if ((!depth || currentDepth < depth) && isCollection(v)) {
  34707. flatDeep(v, currentDepth + 1);
  34708. } else {
  34709. iterations++;
  34710. if (fn(v, useKeys ? k : iterations - 1, flatSequence) === false) {
  34711. stopped = true;
  34712. }
  34713. }
  34714. return !stopped;
  34715. }, reverse);
  34716. }
  34717. flatDeep(collection, 0);
  34718. return iterations;
  34719. };
  34720. flatSequence.__iteratorUncached = function(type, reverse) {
  34721. if (reverse) {
  34722. return this.cacheResult().__iterator(type, reverse);
  34723. }
  34724. var iterator = collection.__iterator(type, reverse);
  34725. var stack = [];
  34726. var iterations = 0;
  34727. return new Iterator(function () {
  34728. while (iterator) {
  34729. var step = iterator.next();
  34730. if (step.done !== false) {
  34731. iterator = stack.pop();
  34732. continue;
  34733. }
  34734. var v = step.value;
  34735. if (type === ITERATE_ENTRIES) {
  34736. v = v[1];
  34737. }
  34738. if ((!depth || stack.length < depth) && isCollection(v)) {
  34739. stack.push(iterator);
  34740. iterator = v.__iterator(type, reverse);
  34741. } else {
  34742. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  34743. }
  34744. }
  34745. return iteratorDone();
  34746. });
  34747. };
  34748. return flatSequence;
  34749. }
  34750. function flatMapFactory(collection, mapper, context) {
  34751. var coerce = collectionClass(collection);
  34752. return collection
  34753. .toSeq()
  34754. .map(function (v, k) { return coerce(mapper.call(context, v, k, collection)); })
  34755. .flatten(true);
  34756. }
  34757. function interposeFactory(collection, separator) {
  34758. var interposedSequence = makeSequence(collection);
  34759. interposedSequence.size = collection.size && collection.size * 2 - 1;
  34760. interposedSequence.__iterateUncached = function(fn, reverse) {
  34761. var this$1 = this;
  34762. var iterations = 0;
  34763. collection.__iterate(
  34764. function (v) { return (!iterations || fn(separator, iterations++, this$1) !== false) &&
  34765. fn(v, iterations++, this$1) !== false; },
  34766. reverse
  34767. );
  34768. return iterations;
  34769. };
  34770. interposedSequence.__iteratorUncached = function(type, reverse) {
  34771. var iterator = collection.__iterator(ITERATE_VALUES, reverse);
  34772. var iterations = 0;
  34773. var step;
  34774. return new Iterator(function () {
  34775. if (!step || iterations % 2) {
  34776. step = iterator.next();
  34777. if (step.done) {
  34778. return step;
  34779. }
  34780. }
  34781. return iterations % 2
  34782. ? iteratorValue(type, iterations++, separator)
  34783. : iteratorValue(type, iterations++, step.value, step);
  34784. });
  34785. };
  34786. return interposedSequence;
  34787. }
  34788. function sortFactory(collection, comparator, mapper) {
  34789. if (!comparator) {
  34790. comparator = defaultComparator;
  34791. }
  34792. var isKeyedCollection = isKeyed(collection);
  34793. var index = 0;
  34794. var entries = collection
  34795. .toSeq()
  34796. .map(function (v, k) { return [k, v, index++, mapper ? mapper(v, k, collection) : v]; })
  34797. .valueSeq()
  34798. .toArray();
  34799. entries.sort(function (a, b) { return comparator(a[3], b[3]) || a[2] - b[2]; }).forEach(
  34800. isKeyedCollection
  34801. ? function (v, i) {
  34802. entries[i].length = 2;
  34803. }
  34804. : function (v, i) {
  34805. entries[i] = v[1];
  34806. }
  34807. );
  34808. return isKeyedCollection
  34809. ? KeyedSeq(entries)
  34810. : isIndexed(collection)
  34811. ? IndexedSeq(entries)
  34812. : SetSeq(entries);
  34813. }
  34814. function maxFactory(collection, comparator, mapper) {
  34815. if (!comparator) {
  34816. comparator = defaultComparator;
  34817. }
  34818. if (mapper) {
  34819. var entry = collection
  34820. .toSeq()
  34821. .map(function (v, k) { return [v, mapper(v, k, collection)]; })
  34822. .reduce(function (a, b) { return (maxCompare(comparator, a[1], b[1]) ? b : a); });
  34823. return entry && entry[0];
  34824. }
  34825. return collection.reduce(function (a, b) { return (maxCompare(comparator, a, b) ? b : a); });
  34826. }
  34827. function maxCompare(comparator, a, b) {
  34828. var comp = comparator(b, a);
  34829. // b is considered the new max if the comparator declares them equal, but
  34830. // they are not equal and b is in fact a nullish value.
  34831. return (
  34832. (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) ||
  34833. comp > 0
  34834. );
  34835. }
  34836. function zipWithFactory(keyIter, zipper, iters, zipAll) {
  34837. var zipSequence = makeSequence(keyIter);
  34838. var sizes = new ArraySeq(iters).map(function (i) { return i.size; });
  34839. zipSequence.size = zipAll ? sizes.max() : sizes.min();
  34840. // Note: this a generic base implementation of __iterate in terms of
  34841. // __iterator which may be more generically useful in the future.
  34842. zipSequence.__iterate = function(fn, reverse) {
  34843. /* generic:
  34844. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  34845. var step;
  34846. var iterations = 0;
  34847. while (!(step = iterator.next()).done) {
  34848. iterations++;
  34849. if (fn(step.value[1], step.value[0], this) === false) {
  34850. break;
  34851. }
  34852. }
  34853. return iterations;
  34854. */
  34855. // indexed:
  34856. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  34857. var step;
  34858. var iterations = 0;
  34859. while (!(step = iterator.next()).done) {
  34860. if (fn(step.value, iterations++, this) === false) {
  34861. break;
  34862. }
  34863. }
  34864. return iterations;
  34865. };
  34866. zipSequence.__iteratorUncached = function(type, reverse) {
  34867. var iterators = iters.map(
  34868. function (i) { return ((i = Collection(i)), getIterator(reverse ? i.reverse() : i)); }
  34869. );
  34870. var iterations = 0;
  34871. var isDone = false;
  34872. return new Iterator(function () {
  34873. var steps;
  34874. if (!isDone) {
  34875. steps = iterators.map(function (i) { return i.next(); });
  34876. isDone = zipAll ? steps.every(function (s) { return s.done; }) : steps.some(function (s) { return s.done; });
  34877. }
  34878. if (isDone) {
  34879. return iteratorDone();
  34880. }
  34881. return iteratorValue(
  34882. type,
  34883. iterations++,
  34884. zipper.apply(null, steps.map(function (s) { return s.value; }))
  34885. );
  34886. });
  34887. };
  34888. return zipSequence;
  34889. }
  34890. // #pragma Helper Functions
  34891. function reify(iter, seq) {
  34892. return iter === seq ? iter : isSeq(iter) ? seq : iter.constructor(seq);
  34893. }
  34894. function validateEntry(entry) {
  34895. if (entry !== Object(entry)) {
  34896. throw new TypeError('Expected [K, V] tuple: ' + entry);
  34897. }
  34898. }
  34899. function collectionClass(collection) {
  34900. return isKeyed(collection)
  34901. ? KeyedCollection
  34902. : isIndexed(collection)
  34903. ? IndexedCollection
  34904. : SetCollection;
  34905. }
  34906. function makeSequence(collection) {
  34907. return Object.create(
  34908. (isKeyed(collection)
  34909. ? KeyedSeq
  34910. : isIndexed(collection)
  34911. ? IndexedSeq
  34912. : SetSeq
  34913. ).prototype
  34914. );
  34915. }
  34916. function cacheResultThrough() {
  34917. if (this._iter.cacheResult) {
  34918. this._iter.cacheResult();
  34919. this.size = this._iter.size;
  34920. return this;
  34921. }
  34922. return Seq.prototype.cacheResult.call(this);
  34923. }
  34924. function defaultComparator(a, b) {
  34925. if (a === undefined && b === undefined) {
  34926. return 0;
  34927. }
  34928. if (a === undefined) {
  34929. return 1;
  34930. }
  34931. if (b === undefined) {
  34932. return -1;
  34933. }
  34934. return a > b ? 1 : a < b ? -1 : 0;
  34935. }
  34936. // http://jsperf.com/copy-array-inline
  34937. function arrCopy(arr, offset) {
  34938. offset = offset || 0;
  34939. var len = Math.max(0, arr.length - offset);
  34940. var newArr = new Array(len);
  34941. for (var ii = 0; ii < len; ii++) {
  34942. newArr[ii] = arr[ii + offset];
  34943. }
  34944. return newArr;
  34945. }
  34946. function invariant(condition, error) {
  34947. if (!condition) { throw new Error(error); }
  34948. }
  34949. function assertNotInfinite(size) {
  34950. invariant(
  34951. size !== Infinity,
  34952. 'Cannot perform this action with an infinite size.'
  34953. );
  34954. }
  34955. function coerceKeyPath(keyPath) {
  34956. if (isArrayLike(keyPath) && typeof keyPath !== 'string') {
  34957. return keyPath;
  34958. }
  34959. if (isOrdered(keyPath)) {
  34960. return keyPath.toArray();
  34961. }
  34962. throw new TypeError(
  34963. 'Invalid keyPath: expected Ordered Collection or Array: ' + keyPath
  34964. );
  34965. }
  34966. function isPlainObj(value) {
  34967. return (
  34968. value &&
  34969. (typeof value.constructor !== 'function' ||
  34970. value.constructor.name === 'Object')
  34971. );
  34972. }
  34973. /**
  34974. * Returns true if the value is a potentially-persistent data structure, either
  34975. * provided by Immutable.js or a plain Array or Object.
  34976. */
  34977. function isDataStructure(value) {
  34978. return (
  34979. typeof value === 'object' &&
  34980. (isImmutable(value) || Array.isArray(value) || isPlainObj(value))
  34981. );
  34982. }
  34983. /**
  34984. * Converts a value to a string, adding quotes if a string was provided.
  34985. */
  34986. function quoteString(value) {
  34987. try {
  34988. return typeof value === 'string' ? JSON.stringify(value) : String(value);
  34989. } catch (_ignoreError) {
  34990. return JSON.stringify(value);
  34991. }
  34992. }
  34993. function has(collection, key) {
  34994. return isImmutable(collection)
  34995. ? collection.has(key)
  34996. : isDataStructure(collection) && hasOwnProperty.call(collection, key);
  34997. }
  34998. function get(collection, key, notSetValue) {
  34999. return isImmutable(collection)
  35000. ? collection.get(key, notSetValue)
  35001. : !has(collection, key)
  35002. ? notSetValue
  35003. : typeof collection.get === 'function'
  35004. ? collection.get(key)
  35005. : collection[key];
  35006. }
  35007. function shallowCopy(from) {
  35008. if (Array.isArray(from)) {
  35009. return arrCopy(from);
  35010. }
  35011. var to = {};
  35012. for (var key in from) {
  35013. if (hasOwnProperty.call(from, key)) {
  35014. to[key] = from[key];
  35015. }
  35016. }
  35017. return to;
  35018. }
  35019. function remove(collection, key) {
  35020. if (!isDataStructure(collection)) {
  35021. throw new TypeError(
  35022. 'Cannot update non-data-structure value: ' + collection
  35023. );
  35024. }
  35025. if (isImmutable(collection)) {
  35026. if (!collection.remove) {
  35027. throw new TypeError(
  35028. 'Cannot update immutable value without .remove() method: ' + collection
  35029. );
  35030. }
  35031. return collection.remove(key);
  35032. }
  35033. if (!hasOwnProperty.call(collection, key)) {
  35034. return collection;
  35035. }
  35036. var collectionCopy = shallowCopy(collection);
  35037. if (Array.isArray(collectionCopy)) {
  35038. collectionCopy.splice(key, 1);
  35039. } else {
  35040. delete collectionCopy[key];
  35041. }
  35042. return collectionCopy;
  35043. }
  35044. function set(collection, key, value) {
  35045. if (!isDataStructure(collection)) {
  35046. throw new TypeError(
  35047. 'Cannot update non-data-structure value: ' + collection
  35048. );
  35049. }
  35050. if (isImmutable(collection)) {
  35051. if (!collection.set) {
  35052. throw new TypeError(
  35053. 'Cannot update immutable value without .set() method: ' + collection
  35054. );
  35055. }
  35056. return collection.set(key, value);
  35057. }
  35058. if (hasOwnProperty.call(collection, key) && value === collection[key]) {
  35059. return collection;
  35060. }
  35061. var collectionCopy = shallowCopy(collection);
  35062. collectionCopy[key] = value;
  35063. return collectionCopy;
  35064. }
  35065. function updateIn(collection, keyPath, notSetValue, updater) {
  35066. if (!updater) {
  35067. updater = notSetValue;
  35068. notSetValue = undefined;
  35069. }
  35070. var updatedValue = updateInDeeply(
  35071. isImmutable(collection),
  35072. collection,
  35073. coerceKeyPath(keyPath),
  35074. 0,
  35075. notSetValue,
  35076. updater
  35077. );
  35078. return updatedValue === NOT_SET ? notSetValue : updatedValue;
  35079. }
  35080. function updateInDeeply(
  35081. inImmutable,
  35082. existing,
  35083. keyPath,
  35084. i,
  35085. notSetValue,
  35086. updater
  35087. ) {
  35088. var wasNotSet = existing === NOT_SET;
  35089. if (i === keyPath.length) {
  35090. var existingValue = wasNotSet ? notSetValue : existing;
  35091. var newValue = updater(existingValue);
  35092. return newValue === existingValue ? existing : newValue;
  35093. }
  35094. if (!wasNotSet && !isDataStructure(existing)) {
  35095. throw new TypeError(
  35096. 'Cannot update within non-data-structure value in path [' +
  35097. keyPath.slice(0, i).map(quoteString) +
  35098. ']: ' +
  35099. existing
  35100. );
  35101. }
  35102. var key = keyPath[i];
  35103. var nextExisting = wasNotSet ? NOT_SET : get(existing, key, NOT_SET);
  35104. var nextUpdated = updateInDeeply(
  35105. nextExisting === NOT_SET ? inImmutable : isImmutable(nextExisting),
  35106. nextExisting,
  35107. keyPath,
  35108. i + 1,
  35109. notSetValue,
  35110. updater
  35111. );
  35112. return nextUpdated === nextExisting
  35113. ? existing
  35114. : nextUpdated === NOT_SET
  35115. ? remove(existing, key)
  35116. : set(
  35117. wasNotSet ? (inImmutable ? emptyMap() : {}) : existing,
  35118. key,
  35119. nextUpdated
  35120. );
  35121. }
  35122. function setIn(collection, keyPath, value) {
  35123. return updateIn(collection, keyPath, NOT_SET, function () { return value; });
  35124. }
  35125. function setIn$1(keyPath, v) {
  35126. return setIn(this, keyPath, v);
  35127. }
  35128. function removeIn(collection, keyPath) {
  35129. return updateIn(collection, keyPath, function () { return NOT_SET; });
  35130. }
  35131. function deleteIn(keyPath) {
  35132. return removeIn(this, keyPath);
  35133. }
  35134. function update(collection, key, notSetValue, updater) {
  35135. return updateIn(collection, [key], notSetValue, updater);
  35136. }
  35137. function update$1(key, notSetValue, updater) {
  35138. return arguments.length === 1
  35139. ? key(this)
  35140. : update(this, key, notSetValue, updater);
  35141. }
  35142. function updateIn$1(keyPath, notSetValue, updater) {
  35143. return updateIn(this, keyPath, notSetValue, updater);
  35144. }
  35145. function merge() {
  35146. var iters = [], len = arguments.length;
  35147. while ( len-- ) iters[ len ] = arguments[ len ];
  35148. return mergeIntoKeyedWith(this, iters);
  35149. }
  35150. function mergeWith(merger) {
  35151. var iters = [], len = arguments.length - 1;
  35152. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  35153. if (typeof merger !== 'function') {
  35154. throw new TypeError('Invalid merger function: ' + merger);
  35155. }
  35156. return mergeIntoKeyedWith(this, iters, merger);
  35157. }
  35158. function mergeIntoKeyedWith(collection, collections, merger) {
  35159. var iters = [];
  35160. for (var ii = 0; ii < collections.length; ii++) {
  35161. var collection$1 = KeyedCollection(collections[ii]);
  35162. if (collection$1.size !== 0) {
  35163. iters.push(collection$1);
  35164. }
  35165. }
  35166. if (iters.length === 0) {
  35167. return collection;
  35168. }
  35169. if (
  35170. collection.toSeq().size === 0 &&
  35171. !collection.__ownerID &&
  35172. iters.length === 1
  35173. ) {
  35174. return collection.constructor(iters[0]);
  35175. }
  35176. return collection.withMutations(function (collection) {
  35177. var mergeIntoCollection = merger
  35178. ? function (value, key) {
  35179. update(
  35180. collection,
  35181. key,
  35182. NOT_SET,
  35183. function (oldVal) { return (oldVal === NOT_SET ? value : merger(oldVal, value, key)); }
  35184. );
  35185. }
  35186. : function (value, key) {
  35187. collection.set(key, value);
  35188. };
  35189. for (var ii = 0; ii < iters.length; ii++) {
  35190. iters[ii].forEach(mergeIntoCollection);
  35191. }
  35192. });
  35193. }
  35194. function merge$1(collection) {
  35195. var sources = [], len = arguments.length - 1;
  35196. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  35197. return mergeWithSources(collection, sources);
  35198. }
  35199. function mergeWith$1(merger, collection) {
  35200. var sources = [], len = arguments.length - 2;
  35201. while ( len-- > 0 ) sources[ len ] = arguments[ len + 2 ];
  35202. return mergeWithSources(collection, sources, merger);
  35203. }
  35204. function mergeDeep(collection) {
  35205. var sources = [], len = arguments.length - 1;
  35206. while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
  35207. return mergeDeepWithSources(collection, sources);
  35208. }
  35209. function mergeDeepWith(merger, collection) {
  35210. var sources = [], len = arguments.length - 2;
  35211. while ( len-- > 0 ) sources[ len ] = arguments[ len + 2 ];
  35212. return mergeDeepWithSources(collection, sources, merger);
  35213. }
  35214. function mergeDeepWithSources(collection, sources, merger) {
  35215. return mergeWithSources(collection, sources, deepMergerWith(merger));
  35216. }
  35217. function mergeWithSources(collection, sources, merger) {
  35218. if (!isDataStructure(collection)) {
  35219. throw new TypeError(
  35220. 'Cannot merge into non-data-structure value: ' + collection
  35221. );
  35222. }
  35223. if (isImmutable(collection)) {
  35224. return typeof merger === 'function' && collection.mergeWith
  35225. ? collection.mergeWith.apply(collection, [ merger ].concat( sources ))
  35226. : collection.merge
  35227. ? collection.merge.apply(collection, sources)
  35228. : collection.concat.apply(collection, sources);
  35229. }
  35230. var isArray = Array.isArray(collection);
  35231. var merged = collection;
  35232. var Collection$$1 = isArray ? IndexedCollection : KeyedCollection;
  35233. var mergeItem = isArray
  35234. ? function (value) {
  35235. // Copy on write
  35236. if (merged === collection) {
  35237. merged = shallowCopy(merged);
  35238. }
  35239. merged.push(value);
  35240. }
  35241. : function (value, key) {
  35242. var hasVal = hasOwnProperty.call(merged, key);
  35243. var nextVal =
  35244. hasVal && merger ? merger(merged[key], value, key) : value;
  35245. if (!hasVal || nextVal !== merged[key]) {
  35246. // Copy on write
  35247. if (merged === collection) {
  35248. merged = shallowCopy(merged);
  35249. }
  35250. merged[key] = nextVal;
  35251. }
  35252. };
  35253. for (var i = 0; i < sources.length; i++) {
  35254. Collection$$1(sources[i]).forEach(mergeItem);
  35255. }
  35256. return merged;
  35257. }
  35258. function deepMergerWith(merger) {
  35259. function deepMerger(oldValue, newValue, key) {
  35260. return isDataStructure(oldValue) && isDataStructure(newValue)
  35261. ? mergeWithSources(oldValue, [newValue], deepMerger)
  35262. : merger
  35263. ? merger(oldValue, newValue, key)
  35264. : newValue;
  35265. }
  35266. return deepMerger;
  35267. }
  35268. function mergeDeep$1() {
  35269. var iters = [], len = arguments.length;
  35270. while ( len-- ) iters[ len ] = arguments[ len ];
  35271. return mergeDeepWithSources(this, iters);
  35272. }
  35273. function mergeDeepWith$1(merger) {
  35274. var iters = [], len = arguments.length - 1;
  35275. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  35276. return mergeDeepWithSources(this, iters, merger);
  35277. }
  35278. function mergeIn(keyPath) {
  35279. var iters = [], len = arguments.length - 1;
  35280. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  35281. return updateIn(this, keyPath, emptyMap(), function (m) { return mergeWithSources(m, iters); });
  35282. }
  35283. function mergeDeepIn(keyPath) {
  35284. var iters = [], len = arguments.length - 1;
  35285. while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
  35286. return updateIn(this, keyPath, emptyMap(), function (m) { return mergeDeepWithSources(m, iters); }
  35287. );
  35288. }
  35289. function withMutations(fn) {
  35290. var mutable = this.asMutable();
  35291. fn(mutable);
  35292. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  35293. }
  35294. function asMutable() {
  35295. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  35296. }
  35297. function asImmutable() {
  35298. return this.__ensureOwner();
  35299. }
  35300. function wasAltered() {
  35301. return this.__altered;
  35302. }
  35303. var Map = /*@__PURE__*/(function (KeyedCollection$$1) {
  35304. function Map(value) {
  35305. return value === null || value === undefined
  35306. ? emptyMap()
  35307. : isMap(value) && !isOrdered(value)
  35308. ? value
  35309. : emptyMap().withMutations(function (map) {
  35310. var iter = KeyedCollection$$1(value);
  35311. assertNotInfinite(iter.size);
  35312. iter.forEach(function (v, k) { return map.set(k, v); });
  35313. });
  35314. }
  35315. if ( KeyedCollection$$1 ) Map.__proto__ = KeyedCollection$$1;
  35316. Map.prototype = Object.create( KeyedCollection$$1 && KeyedCollection$$1.prototype );
  35317. Map.prototype.constructor = Map;
  35318. Map.of = function of () {
  35319. var keyValues = [], len = arguments.length;
  35320. while ( len-- ) keyValues[ len ] = arguments[ len ];
  35321. return emptyMap().withMutations(function (map) {
  35322. for (var i = 0; i < keyValues.length; i += 2) {
  35323. if (i + 1 >= keyValues.length) {
  35324. throw new Error('Missing value for key: ' + keyValues[i]);
  35325. }
  35326. map.set(keyValues[i], keyValues[i + 1]);
  35327. }
  35328. });
  35329. };
  35330. Map.prototype.toString = function toString () {
  35331. return this.__toString('Map {', '}');
  35332. };
  35333. // @pragma Access
  35334. Map.prototype.get = function get (k, notSetValue) {
  35335. return this._root
  35336. ? this._root.get(0, undefined, k, notSetValue)
  35337. : notSetValue;
  35338. };
  35339. // @pragma Modification
  35340. Map.prototype.set = function set (k, v) {
  35341. return updateMap(this, k, v);
  35342. };
  35343. Map.prototype.remove = function remove (k) {
  35344. return updateMap(this, k, NOT_SET);
  35345. };
  35346. Map.prototype.deleteAll = function deleteAll (keys) {
  35347. var collection = Collection(keys);
  35348. if (collection.size === 0) {
  35349. return this;
  35350. }
  35351. return this.withMutations(function (map) {
  35352. collection.forEach(function (key) { return map.remove(key); });
  35353. });
  35354. };
  35355. Map.prototype.clear = function clear () {
  35356. if (this.size === 0) {
  35357. return this;
  35358. }
  35359. if (this.__ownerID) {
  35360. this.size = 0;
  35361. this._root = null;
  35362. this.__hash = undefined;
  35363. this.__altered = true;
  35364. return this;
  35365. }
  35366. return emptyMap();
  35367. };
  35368. // @pragma Composition
  35369. Map.prototype.sort = function sort (comparator) {
  35370. // Late binding
  35371. return OrderedMap(sortFactory(this, comparator));
  35372. };
  35373. Map.prototype.sortBy = function sortBy (mapper, comparator) {
  35374. // Late binding
  35375. return OrderedMap(sortFactory(this, comparator, mapper));
  35376. };
  35377. Map.prototype.map = function map (mapper, context) {
  35378. return this.withMutations(function (map) {
  35379. map.forEach(function (value, key) {
  35380. map.set(key, mapper.call(context, value, key, map));
  35381. });
  35382. });
  35383. };
  35384. // @pragma Mutability
  35385. Map.prototype.__iterator = function __iterator (type, reverse) {
  35386. return new MapIterator(this, type, reverse);
  35387. };
  35388. Map.prototype.__iterate = function __iterate (fn, reverse) {
  35389. var this$1 = this;
  35390. var iterations = 0;
  35391. this._root &&
  35392. this._root.iterate(function (entry) {
  35393. iterations++;
  35394. return fn(entry[1], entry[0], this$1);
  35395. }, reverse);
  35396. return iterations;
  35397. };
  35398. Map.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  35399. if (ownerID === this.__ownerID) {
  35400. return this;
  35401. }
  35402. if (!ownerID) {
  35403. if (this.size === 0) {
  35404. return emptyMap();
  35405. }
  35406. this.__ownerID = ownerID;
  35407. this.__altered = false;
  35408. return this;
  35409. }
  35410. return makeMap(this.size, this._root, ownerID, this.__hash);
  35411. };
  35412. return Map;
  35413. }(KeyedCollection));
  35414. Map.isMap = isMap;
  35415. var MapPrototype = Map.prototype;
  35416. MapPrototype[IS_MAP_SYMBOL] = true;
  35417. MapPrototype[DELETE] = MapPrototype.remove;
  35418. MapPrototype.removeAll = MapPrototype.deleteAll;
  35419. MapPrototype.setIn = setIn$1;
  35420. MapPrototype.removeIn = MapPrototype.deleteIn = deleteIn;
  35421. MapPrototype.update = update$1;
  35422. MapPrototype.updateIn = updateIn$1;
  35423. MapPrototype.merge = MapPrototype.concat = merge;
  35424. MapPrototype.mergeWith = mergeWith;
  35425. MapPrototype.mergeDeep = mergeDeep$1;
  35426. MapPrototype.mergeDeepWith = mergeDeepWith$1;
  35427. MapPrototype.mergeIn = mergeIn;
  35428. MapPrototype.mergeDeepIn = mergeDeepIn;
  35429. MapPrototype.withMutations = withMutations;
  35430. MapPrototype.wasAltered = wasAltered;
  35431. MapPrototype.asImmutable = asImmutable;
  35432. MapPrototype['@@transducer/init'] = MapPrototype.asMutable = asMutable;
  35433. MapPrototype['@@transducer/step'] = function(result, arr) {
  35434. return result.set(arr[0], arr[1]);
  35435. };
  35436. MapPrototype['@@transducer/result'] = function(obj) {
  35437. return obj.asImmutable();
  35438. };
  35439. // #pragma Trie Nodes
  35440. var ArrayMapNode = function ArrayMapNode(ownerID, entries) {
  35441. this.ownerID = ownerID;
  35442. this.entries = entries;
  35443. };
  35444. ArrayMapNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  35445. var entries = this.entries;
  35446. for (var ii = 0, len = entries.length; ii < len; ii++) {
  35447. if (is(key, entries[ii][0])) {
  35448. return entries[ii][1];
  35449. }
  35450. }
  35451. return notSetValue;
  35452. };
  35453. ArrayMapNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  35454. var removed = value === NOT_SET;
  35455. var entries = this.entries;
  35456. var idx = 0;
  35457. var len = entries.length;
  35458. for (; idx < len; idx++) {
  35459. if (is(key, entries[idx][0])) {
  35460. break;
  35461. }
  35462. }
  35463. var exists = idx < len;
  35464. if (exists ? entries[idx][1] === value : removed) {
  35465. return this;
  35466. }
  35467. SetRef(didAlter);
  35468. (removed || !exists) && SetRef(didChangeSize);
  35469. if (removed && entries.length === 1) {
  35470. return; // undefined
  35471. }
  35472. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  35473. return createNodes(ownerID, entries, key, value);
  35474. }
  35475. var isEditable = ownerID && ownerID === this.ownerID;
  35476. var newEntries = isEditable ? entries : arrCopy(entries);
  35477. if (exists) {
  35478. if (removed) {
  35479. idx === len - 1
  35480. ? newEntries.pop()
  35481. : (newEntries[idx] = newEntries.pop());
  35482. } else {
  35483. newEntries[idx] = [key, value];
  35484. }
  35485. } else {
  35486. newEntries.push([key, value]);
  35487. }
  35488. if (isEditable) {
  35489. this.entries = newEntries;
  35490. return this;
  35491. }
  35492. return new ArrayMapNode(ownerID, newEntries);
  35493. };
  35494. var BitmapIndexedNode = function BitmapIndexedNode(ownerID, bitmap, nodes) {
  35495. this.ownerID = ownerID;
  35496. this.bitmap = bitmap;
  35497. this.nodes = nodes;
  35498. };
  35499. BitmapIndexedNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  35500. if (keyHash === undefined) {
  35501. keyHash = hash(key);
  35502. }
  35503. var bit = 1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK);
  35504. var bitmap = this.bitmap;
  35505. return (bitmap & bit) === 0
  35506. ? notSetValue
  35507. : this.nodes[popCount(bitmap & (bit - 1))].get(
  35508. shift + SHIFT,
  35509. keyHash,
  35510. key,
  35511. notSetValue
  35512. );
  35513. };
  35514. BitmapIndexedNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  35515. if (keyHash === undefined) {
  35516. keyHash = hash(key);
  35517. }
  35518. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  35519. var bit = 1 << keyHashFrag;
  35520. var bitmap = this.bitmap;
  35521. var exists = (bitmap & bit) !== 0;
  35522. if (!exists && value === NOT_SET) {
  35523. return this;
  35524. }
  35525. var idx = popCount(bitmap & (bit - 1));
  35526. var nodes = this.nodes;
  35527. var node = exists ? nodes[idx] : undefined;
  35528. var newNode = updateNode(
  35529. node,
  35530. ownerID,
  35531. shift + SHIFT,
  35532. keyHash,
  35533. key,
  35534. value,
  35535. didChangeSize,
  35536. didAlter
  35537. );
  35538. if (newNode === node) {
  35539. return this;
  35540. }
  35541. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  35542. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  35543. }
  35544. if (
  35545. exists &&
  35546. !newNode &&
  35547. nodes.length === 2 &&
  35548. isLeafNode(nodes[idx ^ 1])
  35549. ) {
  35550. return nodes[idx ^ 1];
  35551. }
  35552. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  35553. return newNode;
  35554. }
  35555. var isEditable = ownerID && ownerID === this.ownerID;
  35556. var newBitmap = exists ? (newNode ? bitmap : bitmap ^ bit) : bitmap | bit;
  35557. var newNodes = exists
  35558. ? newNode
  35559. ? setAt(nodes, idx, newNode, isEditable)
  35560. : spliceOut(nodes, idx, isEditable)
  35561. : spliceIn(nodes, idx, newNode, isEditable);
  35562. if (isEditable) {
  35563. this.bitmap = newBitmap;
  35564. this.nodes = newNodes;
  35565. return this;
  35566. }
  35567. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  35568. };
  35569. var HashArrayMapNode = function HashArrayMapNode(ownerID, count, nodes) {
  35570. this.ownerID = ownerID;
  35571. this.count = count;
  35572. this.nodes = nodes;
  35573. };
  35574. HashArrayMapNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  35575. if (keyHash === undefined) {
  35576. keyHash = hash(key);
  35577. }
  35578. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  35579. var node = this.nodes[idx];
  35580. return node
  35581. ? node.get(shift + SHIFT, keyHash, key, notSetValue)
  35582. : notSetValue;
  35583. };
  35584. HashArrayMapNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  35585. if (keyHash === undefined) {
  35586. keyHash = hash(key);
  35587. }
  35588. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  35589. var removed = value === NOT_SET;
  35590. var nodes = this.nodes;
  35591. var node = nodes[idx];
  35592. if (removed && !node) {
  35593. return this;
  35594. }
  35595. var newNode = updateNode(
  35596. node,
  35597. ownerID,
  35598. shift + SHIFT,
  35599. keyHash,
  35600. key,
  35601. value,
  35602. didChangeSize,
  35603. didAlter
  35604. );
  35605. if (newNode === node) {
  35606. return this;
  35607. }
  35608. var newCount = this.count;
  35609. if (!node) {
  35610. newCount++;
  35611. } else if (!newNode) {
  35612. newCount--;
  35613. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  35614. return packNodes(ownerID, nodes, newCount, idx);
  35615. }
  35616. }
  35617. var isEditable = ownerID && ownerID === this.ownerID;
  35618. var newNodes = setAt(nodes, idx, newNode, isEditable);
  35619. if (isEditable) {
  35620. this.count = newCount;
  35621. this.nodes = newNodes;
  35622. return this;
  35623. }
  35624. return new HashArrayMapNode(ownerID, newCount, newNodes);
  35625. };
  35626. var HashCollisionNode = function HashCollisionNode(ownerID, keyHash, entries) {
  35627. this.ownerID = ownerID;
  35628. this.keyHash = keyHash;
  35629. this.entries = entries;
  35630. };
  35631. HashCollisionNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  35632. var entries = this.entries;
  35633. for (var ii = 0, len = entries.length; ii < len; ii++) {
  35634. if (is(key, entries[ii][0])) {
  35635. return entries[ii][1];
  35636. }
  35637. }
  35638. return notSetValue;
  35639. };
  35640. HashCollisionNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  35641. if (keyHash === undefined) {
  35642. keyHash = hash(key);
  35643. }
  35644. var removed = value === NOT_SET;
  35645. if (keyHash !== this.keyHash) {
  35646. if (removed) {
  35647. return this;
  35648. }
  35649. SetRef(didAlter);
  35650. SetRef(didChangeSize);
  35651. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  35652. }
  35653. var entries = this.entries;
  35654. var idx = 0;
  35655. var len = entries.length;
  35656. for (; idx < len; idx++) {
  35657. if (is(key, entries[idx][0])) {
  35658. break;
  35659. }
  35660. }
  35661. var exists = idx < len;
  35662. if (exists ? entries[idx][1] === value : removed) {
  35663. return this;
  35664. }
  35665. SetRef(didAlter);
  35666. (removed || !exists) && SetRef(didChangeSize);
  35667. if (removed && len === 2) {
  35668. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  35669. }
  35670. var isEditable = ownerID && ownerID === this.ownerID;
  35671. var newEntries = isEditable ? entries : arrCopy(entries);
  35672. if (exists) {
  35673. if (removed) {
  35674. idx === len - 1
  35675. ? newEntries.pop()
  35676. : (newEntries[idx] = newEntries.pop());
  35677. } else {
  35678. newEntries[idx] = [key, value];
  35679. }
  35680. } else {
  35681. newEntries.push([key, value]);
  35682. }
  35683. if (isEditable) {
  35684. this.entries = newEntries;
  35685. return this;
  35686. }
  35687. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  35688. };
  35689. var ValueNode = function ValueNode(ownerID, keyHash, entry) {
  35690. this.ownerID = ownerID;
  35691. this.keyHash = keyHash;
  35692. this.entry = entry;
  35693. };
  35694. ValueNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
  35695. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  35696. };
  35697. ValueNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  35698. var removed = value === NOT_SET;
  35699. var keyMatch = is(key, this.entry[0]);
  35700. if (keyMatch ? value === this.entry[1] : removed) {
  35701. return this;
  35702. }
  35703. SetRef(didAlter);
  35704. if (removed) {
  35705. SetRef(didChangeSize);
  35706. return; // undefined
  35707. }
  35708. if (keyMatch) {
  35709. if (ownerID && ownerID === this.ownerID) {
  35710. this.entry[1] = value;
  35711. return this;
  35712. }
  35713. return new ValueNode(ownerID, this.keyHash, [key, value]);
  35714. }
  35715. SetRef(didChangeSize);
  35716. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  35717. };
  35718. // #pragma Iterators
  35719. ArrayMapNode.prototype.iterate = HashCollisionNode.prototype.iterate = function(
  35720. fn,
  35721. reverse
  35722. ) {
  35723. var entries = this.entries;
  35724. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  35725. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  35726. return false;
  35727. }
  35728. }
  35729. };
  35730. BitmapIndexedNode.prototype.iterate = HashArrayMapNode.prototype.iterate = function(
  35731. fn,
  35732. reverse
  35733. ) {
  35734. var nodes = this.nodes;
  35735. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  35736. var node = nodes[reverse ? maxIndex - ii : ii];
  35737. if (node && node.iterate(fn, reverse) === false) {
  35738. return false;
  35739. }
  35740. }
  35741. };
  35742. // eslint-disable-next-line no-unused-vars
  35743. ValueNode.prototype.iterate = function(fn, reverse) {
  35744. return fn(this.entry);
  35745. };
  35746. var MapIterator = /*@__PURE__*/(function (Iterator$$1) {
  35747. function MapIterator(map, type, reverse) {
  35748. this._type = type;
  35749. this._reverse = reverse;
  35750. this._stack = map._root && mapIteratorFrame(map._root);
  35751. }
  35752. if ( Iterator$$1 ) MapIterator.__proto__ = Iterator$$1;
  35753. MapIterator.prototype = Object.create( Iterator$$1 && Iterator$$1.prototype );
  35754. MapIterator.prototype.constructor = MapIterator;
  35755. MapIterator.prototype.next = function next () {
  35756. var type = this._type;
  35757. var stack = this._stack;
  35758. while (stack) {
  35759. var node = stack.node;
  35760. var index = stack.index++;
  35761. var maxIndex = (void 0);
  35762. if (node.entry) {
  35763. if (index === 0) {
  35764. return mapIteratorValue(type, node.entry);
  35765. }
  35766. } else if (node.entries) {
  35767. maxIndex = node.entries.length - 1;
  35768. if (index <= maxIndex) {
  35769. return mapIteratorValue(
  35770. type,
  35771. node.entries[this._reverse ? maxIndex - index : index]
  35772. );
  35773. }
  35774. } else {
  35775. maxIndex = node.nodes.length - 1;
  35776. if (index <= maxIndex) {
  35777. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  35778. if (subNode) {
  35779. if (subNode.entry) {
  35780. return mapIteratorValue(type, subNode.entry);
  35781. }
  35782. stack = this._stack = mapIteratorFrame(subNode, stack);
  35783. }
  35784. continue;
  35785. }
  35786. }
  35787. stack = this._stack = this._stack.__prev;
  35788. }
  35789. return iteratorDone();
  35790. };
  35791. return MapIterator;
  35792. }(Iterator));
  35793. function mapIteratorValue(type, entry) {
  35794. return iteratorValue(type, entry[0], entry[1]);
  35795. }
  35796. function mapIteratorFrame(node, prev) {
  35797. return {
  35798. node: node,
  35799. index: 0,
  35800. __prev: prev,
  35801. };
  35802. }
  35803. function makeMap(size, root, ownerID, hash$$1) {
  35804. var map = Object.create(MapPrototype);
  35805. map.size = size;
  35806. map._root = root;
  35807. map.__ownerID = ownerID;
  35808. map.__hash = hash$$1;
  35809. map.__altered = false;
  35810. return map;
  35811. }
  35812. var EMPTY_MAP;
  35813. function emptyMap() {
  35814. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  35815. }
  35816. function updateMap(map, k, v) {
  35817. var newRoot;
  35818. var newSize;
  35819. if (!map._root) {
  35820. if (v === NOT_SET) {
  35821. return map;
  35822. }
  35823. newSize = 1;
  35824. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  35825. } else {
  35826. var didChangeSize = MakeRef();
  35827. var didAlter = MakeRef();
  35828. newRoot = updateNode(
  35829. map._root,
  35830. map.__ownerID,
  35831. 0,
  35832. undefined,
  35833. k,
  35834. v,
  35835. didChangeSize,
  35836. didAlter
  35837. );
  35838. if (!didAlter.value) {
  35839. return map;
  35840. }
  35841. newSize = map.size + (didChangeSize.value ? (v === NOT_SET ? -1 : 1) : 0);
  35842. }
  35843. if (map.__ownerID) {
  35844. map.size = newSize;
  35845. map._root = newRoot;
  35846. map.__hash = undefined;
  35847. map.__altered = true;
  35848. return map;
  35849. }
  35850. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  35851. }
  35852. function updateNode(
  35853. node,
  35854. ownerID,
  35855. shift,
  35856. keyHash,
  35857. key,
  35858. value,
  35859. didChangeSize,
  35860. didAlter
  35861. ) {
  35862. if (!node) {
  35863. if (value === NOT_SET) {
  35864. return node;
  35865. }
  35866. SetRef(didAlter);
  35867. SetRef(didChangeSize);
  35868. return new ValueNode(ownerID, keyHash, [key, value]);
  35869. }
  35870. return node.update(
  35871. ownerID,
  35872. shift,
  35873. keyHash,
  35874. key,
  35875. value,
  35876. didChangeSize,
  35877. didAlter
  35878. );
  35879. }
  35880. function isLeafNode(node) {
  35881. return (
  35882. node.constructor === ValueNode || node.constructor === HashCollisionNode
  35883. );
  35884. }
  35885. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  35886. if (node.keyHash === keyHash) {
  35887. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  35888. }
  35889. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  35890. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  35891. var newNode;
  35892. var nodes =
  35893. idx1 === idx2
  35894. ? [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)]
  35895. : ((newNode = new ValueNode(ownerID, keyHash, entry)),
  35896. idx1 < idx2 ? [node, newNode] : [newNode, node]);
  35897. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  35898. }
  35899. function createNodes(ownerID, entries, key, value) {
  35900. if (!ownerID) {
  35901. ownerID = new OwnerID();
  35902. }
  35903. var node = new ValueNode(ownerID, hash(key), [key, value]);
  35904. for (var ii = 0; ii < entries.length; ii++) {
  35905. var entry = entries[ii];
  35906. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  35907. }
  35908. return node;
  35909. }
  35910. function packNodes(ownerID, nodes, count, excluding) {
  35911. var bitmap = 0;
  35912. var packedII = 0;
  35913. var packedNodes = new Array(count);
  35914. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  35915. var node = nodes[ii];
  35916. if (node !== undefined && ii !== excluding) {
  35917. bitmap |= bit;
  35918. packedNodes[packedII++] = node;
  35919. }
  35920. }
  35921. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  35922. }
  35923. function expandNodes(ownerID, nodes, bitmap, including, node) {
  35924. var count = 0;
  35925. var expandedNodes = new Array(SIZE);
  35926. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  35927. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  35928. }
  35929. expandedNodes[including] = node;
  35930. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  35931. }
  35932. function popCount(x) {
  35933. x -= (x >> 1) & 0x55555555;
  35934. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  35935. x = (x + (x >> 4)) & 0x0f0f0f0f;
  35936. x += x >> 8;
  35937. x += x >> 16;
  35938. return x & 0x7f;
  35939. }
  35940. function setAt(array, idx, val, canEdit) {
  35941. var newArray = canEdit ? array : arrCopy(array);
  35942. newArray[idx] = val;
  35943. return newArray;
  35944. }
  35945. function spliceIn(array, idx, val, canEdit) {
  35946. var newLen = array.length + 1;
  35947. if (canEdit && idx + 1 === newLen) {
  35948. array[idx] = val;
  35949. return array;
  35950. }
  35951. var newArray = new Array(newLen);
  35952. var after = 0;
  35953. for (var ii = 0; ii < newLen; ii++) {
  35954. if (ii === idx) {
  35955. newArray[ii] = val;
  35956. after = -1;
  35957. } else {
  35958. newArray[ii] = array[ii + after];
  35959. }
  35960. }
  35961. return newArray;
  35962. }
  35963. function spliceOut(array, idx, canEdit) {
  35964. var newLen = array.length - 1;
  35965. if (canEdit && idx === newLen) {
  35966. array.pop();
  35967. return array;
  35968. }
  35969. var newArray = new Array(newLen);
  35970. var after = 0;
  35971. for (var ii = 0; ii < newLen; ii++) {
  35972. if (ii === idx) {
  35973. after = 1;
  35974. }
  35975. newArray[ii] = array[ii + after];
  35976. }
  35977. return newArray;
  35978. }
  35979. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  35980. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  35981. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  35982. var IS_LIST_SYMBOL = '@@__IMMUTABLE_LIST__@@';
  35983. function isList(maybeList) {
  35984. return Boolean(maybeList && maybeList[IS_LIST_SYMBOL]);
  35985. }
  35986. var List = /*@__PURE__*/(function (IndexedCollection$$1) {
  35987. function List(value) {
  35988. var empty = emptyList();
  35989. if (value === null || value === undefined) {
  35990. return empty;
  35991. }
  35992. if (isList(value)) {
  35993. return value;
  35994. }
  35995. var iter = IndexedCollection$$1(value);
  35996. var size = iter.size;
  35997. if (size === 0) {
  35998. return empty;
  35999. }
  36000. assertNotInfinite(size);
  36001. if (size > 0 && size < SIZE) {
  36002. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  36003. }
  36004. return empty.withMutations(function (list) {
  36005. list.setSize(size);
  36006. iter.forEach(function (v, i) { return list.set(i, v); });
  36007. });
  36008. }
  36009. if ( IndexedCollection$$1 ) List.__proto__ = IndexedCollection$$1;
  36010. List.prototype = Object.create( IndexedCollection$$1 && IndexedCollection$$1.prototype );
  36011. List.prototype.constructor = List;
  36012. List.of = function of (/*...values*/) {
  36013. return this(arguments);
  36014. };
  36015. List.prototype.toString = function toString () {
  36016. return this.__toString('List [', ']');
  36017. };
  36018. // @pragma Access
  36019. List.prototype.get = function get (index, notSetValue) {
  36020. index = wrapIndex(this, index);
  36021. if (index >= 0 && index < this.size) {
  36022. index += this._origin;
  36023. var node = listNodeFor(this, index);
  36024. return node && node.array[index & MASK];
  36025. }
  36026. return notSetValue;
  36027. };
  36028. // @pragma Modification
  36029. List.prototype.set = function set (index, value) {
  36030. return updateList(this, index, value);
  36031. };
  36032. List.prototype.remove = function remove (index) {
  36033. return !this.has(index)
  36034. ? this
  36035. : index === 0
  36036. ? this.shift()
  36037. : index === this.size - 1
  36038. ? this.pop()
  36039. : this.splice(index, 1);
  36040. };
  36041. List.prototype.insert = function insert (index, value) {
  36042. return this.splice(index, 0, value);
  36043. };
  36044. List.prototype.clear = function clear () {
  36045. if (this.size === 0) {
  36046. return this;
  36047. }
  36048. if (this.__ownerID) {
  36049. this.size = this._origin = this._capacity = 0;
  36050. this._level = SHIFT;
  36051. this._root = this._tail = null;
  36052. this.__hash = undefined;
  36053. this.__altered = true;
  36054. return this;
  36055. }
  36056. return emptyList();
  36057. };
  36058. List.prototype.push = function push (/*...values*/) {
  36059. var values = arguments;
  36060. var oldSize = this.size;
  36061. return this.withMutations(function (list) {
  36062. setListBounds(list, 0, oldSize + values.length);
  36063. for (var ii = 0; ii < values.length; ii++) {
  36064. list.set(oldSize + ii, values[ii]);
  36065. }
  36066. });
  36067. };
  36068. List.prototype.pop = function pop () {
  36069. return setListBounds(this, 0, -1);
  36070. };
  36071. List.prototype.unshift = function unshift (/*...values*/) {
  36072. var values = arguments;
  36073. return this.withMutations(function (list) {
  36074. setListBounds(list, -values.length);
  36075. for (var ii = 0; ii < values.length; ii++) {
  36076. list.set(ii, values[ii]);
  36077. }
  36078. });
  36079. };
  36080. List.prototype.shift = function shift () {
  36081. return setListBounds(this, 1);
  36082. };
  36083. // @pragma Composition
  36084. List.prototype.concat = function concat (/*...collections*/) {
  36085. var arguments$1 = arguments;
  36086. var seqs = [];
  36087. for (var i = 0; i < arguments.length; i++) {
  36088. var argument = arguments$1[i];
  36089. var seq = IndexedCollection$$1(
  36090. typeof argument !== 'string' && hasIterator(argument)
  36091. ? argument
  36092. : [argument]
  36093. );
  36094. if (seq.size !== 0) {
  36095. seqs.push(seq);
  36096. }
  36097. }
  36098. if (seqs.length === 0) {
  36099. return this;
  36100. }
  36101. if (this.size === 0 && !this.__ownerID && seqs.length === 1) {
  36102. return this.constructor(seqs[0]);
  36103. }
  36104. return this.withMutations(function (list) {
  36105. seqs.forEach(function (seq) { return seq.forEach(function (value) { return list.push(value); }); });
  36106. });
  36107. };
  36108. List.prototype.setSize = function setSize (size) {
  36109. return setListBounds(this, 0, size);
  36110. };
  36111. List.prototype.map = function map (mapper, context) {
  36112. var this$1 = this;
  36113. return this.withMutations(function (list) {
  36114. for (var i = 0; i < this$1.size; i++) {
  36115. list.set(i, mapper.call(context, list.get(i), i, list));
  36116. }
  36117. });
  36118. };
  36119. // @pragma Iteration
  36120. List.prototype.slice = function slice (begin, end) {
  36121. var size = this.size;
  36122. if (wholeSlice(begin, end, size)) {
  36123. return this;
  36124. }
  36125. return setListBounds(
  36126. this,
  36127. resolveBegin(begin, size),
  36128. resolveEnd(end, size)
  36129. );
  36130. };
  36131. List.prototype.__iterator = function __iterator (type, reverse) {
  36132. var index = reverse ? this.size : 0;
  36133. var values = iterateList(this, reverse);
  36134. return new Iterator(function () {
  36135. var value = values();
  36136. return value === DONE
  36137. ? iteratorDone()
  36138. : iteratorValue(type, reverse ? --index : index++, value);
  36139. });
  36140. };
  36141. List.prototype.__iterate = function __iterate (fn, reverse) {
  36142. var index = reverse ? this.size : 0;
  36143. var values = iterateList(this, reverse);
  36144. var value;
  36145. while ((value = values()) !== DONE) {
  36146. if (fn(value, reverse ? --index : index++, this) === false) {
  36147. break;
  36148. }
  36149. }
  36150. return index;
  36151. };
  36152. List.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  36153. if (ownerID === this.__ownerID) {
  36154. return this;
  36155. }
  36156. if (!ownerID) {
  36157. if (this.size === 0) {
  36158. return emptyList();
  36159. }
  36160. this.__ownerID = ownerID;
  36161. this.__altered = false;
  36162. return this;
  36163. }
  36164. return makeList(
  36165. this._origin,
  36166. this._capacity,
  36167. this._level,
  36168. this._root,
  36169. this._tail,
  36170. ownerID,
  36171. this.__hash
  36172. );
  36173. };
  36174. return List;
  36175. }(IndexedCollection));
  36176. List.isList = isList;
  36177. var ListPrototype = List.prototype;
  36178. ListPrototype[IS_LIST_SYMBOL] = true;
  36179. ListPrototype[DELETE] = ListPrototype.remove;
  36180. ListPrototype.merge = ListPrototype.concat;
  36181. ListPrototype.setIn = setIn$1;
  36182. ListPrototype.deleteIn = ListPrototype.removeIn = deleteIn;
  36183. ListPrototype.update = update$1;
  36184. ListPrototype.updateIn = updateIn$1;
  36185. ListPrototype.mergeIn = mergeIn;
  36186. ListPrototype.mergeDeepIn = mergeDeepIn;
  36187. ListPrototype.withMutations = withMutations;
  36188. ListPrototype.wasAltered = wasAltered;
  36189. ListPrototype.asImmutable = asImmutable;
  36190. ListPrototype['@@transducer/init'] = ListPrototype.asMutable = asMutable;
  36191. ListPrototype['@@transducer/step'] = function(result, arr) {
  36192. return result.push(arr);
  36193. };
  36194. ListPrototype['@@transducer/result'] = function(obj) {
  36195. return obj.asImmutable();
  36196. };
  36197. var VNode = function VNode(array, ownerID) {
  36198. this.array = array;
  36199. this.ownerID = ownerID;
  36200. };
  36201. // TODO: seems like these methods are very similar
  36202. VNode.prototype.removeBefore = function removeBefore (ownerID, level, index) {
  36203. if (index === level ? 1 << level : this.array.length === 0) {
  36204. return this;
  36205. }
  36206. var originIndex = (index >>> level) & MASK;
  36207. if (originIndex >= this.array.length) {
  36208. return new VNode([], ownerID);
  36209. }
  36210. var removingFirst = originIndex === 0;
  36211. var newChild;
  36212. if (level > 0) {
  36213. var oldChild = this.array[originIndex];
  36214. newChild =
  36215. oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  36216. if (newChild === oldChild && removingFirst) {
  36217. return this;
  36218. }
  36219. }
  36220. if (removingFirst && !newChild) {
  36221. return this;
  36222. }
  36223. var editable = editableVNode(this, ownerID);
  36224. if (!removingFirst) {
  36225. for (var ii = 0; ii < originIndex; ii++) {
  36226. editable.array[ii] = undefined;
  36227. }
  36228. }
  36229. if (newChild) {
  36230. editable.array[originIndex] = newChild;
  36231. }
  36232. return editable;
  36233. };
  36234. VNode.prototype.removeAfter = function removeAfter (ownerID, level, index) {
  36235. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  36236. return this;
  36237. }
  36238. var sizeIndex = ((index - 1) >>> level) & MASK;
  36239. if (sizeIndex >= this.array.length) {
  36240. return this;
  36241. }
  36242. var newChild;
  36243. if (level > 0) {
  36244. var oldChild = this.array[sizeIndex];
  36245. newChild =
  36246. oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  36247. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  36248. return this;
  36249. }
  36250. }
  36251. var editable = editableVNode(this, ownerID);
  36252. editable.array.splice(sizeIndex + 1);
  36253. if (newChild) {
  36254. editable.array[sizeIndex] = newChild;
  36255. }
  36256. return editable;
  36257. };
  36258. var DONE = {};
  36259. function iterateList(list, reverse) {
  36260. var left = list._origin;
  36261. var right = list._capacity;
  36262. var tailPos = getTailOffset(right);
  36263. var tail = list._tail;
  36264. return iterateNodeOrLeaf(list._root, list._level, 0);
  36265. function iterateNodeOrLeaf(node, level, offset) {
  36266. return level === 0
  36267. ? iterateLeaf(node, offset)
  36268. : iterateNode(node, level, offset);
  36269. }
  36270. function iterateLeaf(node, offset) {
  36271. var array = offset === tailPos ? tail && tail.array : node && node.array;
  36272. var from = offset > left ? 0 : left - offset;
  36273. var to = right - offset;
  36274. if (to > SIZE) {
  36275. to = SIZE;
  36276. }
  36277. return function () {
  36278. if (from === to) {
  36279. return DONE;
  36280. }
  36281. var idx = reverse ? --to : from++;
  36282. return array && array[idx];
  36283. };
  36284. }
  36285. function iterateNode(node, level, offset) {
  36286. var values;
  36287. var array = node && node.array;
  36288. var from = offset > left ? 0 : (left - offset) >> level;
  36289. var to = ((right - offset) >> level) + 1;
  36290. if (to > SIZE) {
  36291. to = SIZE;
  36292. }
  36293. return function () {
  36294. while (true) {
  36295. if (values) {
  36296. var value = values();
  36297. if (value !== DONE) {
  36298. return value;
  36299. }
  36300. values = null;
  36301. }
  36302. if (from === to) {
  36303. return DONE;
  36304. }
  36305. var idx = reverse ? --to : from++;
  36306. values = iterateNodeOrLeaf(
  36307. array && array[idx],
  36308. level - SHIFT,
  36309. offset + (idx << level)
  36310. );
  36311. }
  36312. };
  36313. }
  36314. }
  36315. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  36316. var list = Object.create(ListPrototype);
  36317. list.size = capacity - origin;
  36318. list._origin = origin;
  36319. list._capacity = capacity;
  36320. list._level = level;
  36321. list._root = root;
  36322. list._tail = tail;
  36323. list.__ownerID = ownerID;
  36324. list.__hash = hash;
  36325. list.__altered = false;
  36326. return list;
  36327. }
  36328. var EMPTY_LIST;
  36329. function emptyList() {
  36330. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  36331. }
  36332. function updateList(list, index, value) {
  36333. index = wrapIndex(list, index);
  36334. if (index !== index) {
  36335. return list;
  36336. }
  36337. if (index >= list.size || index < 0) {
  36338. return list.withMutations(function (list) {
  36339. index < 0
  36340. ? setListBounds(list, index).set(0, value)
  36341. : setListBounds(list, 0, index + 1).set(index, value);
  36342. });
  36343. }
  36344. index += list._origin;
  36345. var newTail = list._tail;
  36346. var newRoot = list._root;
  36347. var didAlter = MakeRef();
  36348. if (index >= getTailOffset(list._capacity)) {
  36349. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  36350. } else {
  36351. newRoot = updateVNode(
  36352. newRoot,
  36353. list.__ownerID,
  36354. list._level,
  36355. index,
  36356. value,
  36357. didAlter
  36358. );
  36359. }
  36360. if (!didAlter.value) {
  36361. return list;
  36362. }
  36363. if (list.__ownerID) {
  36364. list._root = newRoot;
  36365. list._tail = newTail;
  36366. list.__hash = undefined;
  36367. list.__altered = true;
  36368. return list;
  36369. }
  36370. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  36371. }
  36372. function updateVNode(node, ownerID, level, index, value, didAlter) {
  36373. var idx = (index >>> level) & MASK;
  36374. var nodeHas = node && idx < node.array.length;
  36375. if (!nodeHas && value === undefined) {
  36376. return node;
  36377. }
  36378. var newNode;
  36379. if (level > 0) {
  36380. var lowerNode = node && node.array[idx];
  36381. var newLowerNode = updateVNode(
  36382. lowerNode,
  36383. ownerID,
  36384. level - SHIFT,
  36385. index,
  36386. value,
  36387. didAlter
  36388. );
  36389. if (newLowerNode === lowerNode) {
  36390. return node;
  36391. }
  36392. newNode = editableVNode(node, ownerID);
  36393. newNode.array[idx] = newLowerNode;
  36394. return newNode;
  36395. }
  36396. if (nodeHas && node.array[idx] === value) {
  36397. return node;
  36398. }
  36399. if (didAlter) {
  36400. SetRef(didAlter);
  36401. }
  36402. newNode = editableVNode(node, ownerID);
  36403. if (value === undefined && idx === newNode.array.length - 1) {
  36404. newNode.array.pop();
  36405. } else {
  36406. newNode.array[idx] = value;
  36407. }
  36408. return newNode;
  36409. }
  36410. function editableVNode(node, ownerID) {
  36411. if (ownerID && node && ownerID === node.ownerID) {
  36412. return node;
  36413. }
  36414. return new VNode(node ? node.array.slice() : [], ownerID);
  36415. }
  36416. function listNodeFor(list, rawIndex) {
  36417. if (rawIndex >= getTailOffset(list._capacity)) {
  36418. return list._tail;
  36419. }
  36420. if (rawIndex < 1 << (list._level + SHIFT)) {
  36421. var node = list._root;
  36422. var level = list._level;
  36423. while (node && level > 0) {
  36424. node = node.array[(rawIndex >>> level) & MASK];
  36425. level -= SHIFT;
  36426. }
  36427. return node;
  36428. }
  36429. }
  36430. function setListBounds(list, begin, end) {
  36431. // Sanitize begin & end using this shorthand for ToInt32(argument)
  36432. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  36433. if (begin !== undefined) {
  36434. begin |= 0;
  36435. }
  36436. if (end !== undefined) {
  36437. end |= 0;
  36438. }
  36439. var owner = list.__ownerID || new OwnerID();
  36440. var oldOrigin = list._origin;
  36441. var oldCapacity = list._capacity;
  36442. var newOrigin = oldOrigin + begin;
  36443. var newCapacity =
  36444. end === undefined
  36445. ? oldCapacity
  36446. : end < 0
  36447. ? oldCapacity + end
  36448. : oldOrigin + end;
  36449. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  36450. return list;
  36451. }
  36452. // If it's going to end after it starts, it's empty.
  36453. if (newOrigin >= newCapacity) {
  36454. return list.clear();
  36455. }
  36456. var newLevel = list._level;
  36457. var newRoot = list._root;
  36458. // New origin might need creating a higher root.
  36459. var offsetShift = 0;
  36460. while (newOrigin + offsetShift < 0) {
  36461. newRoot = new VNode(
  36462. newRoot && newRoot.array.length ? [undefined, newRoot] : [],
  36463. owner
  36464. );
  36465. newLevel += SHIFT;
  36466. offsetShift += 1 << newLevel;
  36467. }
  36468. if (offsetShift) {
  36469. newOrigin += offsetShift;
  36470. oldOrigin += offsetShift;
  36471. newCapacity += offsetShift;
  36472. oldCapacity += offsetShift;
  36473. }
  36474. var oldTailOffset = getTailOffset(oldCapacity);
  36475. var newTailOffset = getTailOffset(newCapacity);
  36476. // New size might need creating a higher root.
  36477. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  36478. newRoot = new VNode(
  36479. newRoot && newRoot.array.length ? [newRoot] : [],
  36480. owner
  36481. );
  36482. newLevel += SHIFT;
  36483. }
  36484. // Locate or create the new tail.
  36485. var oldTail = list._tail;
  36486. var newTail =
  36487. newTailOffset < oldTailOffset
  36488. ? listNodeFor(list, newCapacity - 1)
  36489. : newTailOffset > oldTailOffset
  36490. ? new VNode([], owner)
  36491. : oldTail;
  36492. // Merge Tail into tree.
  36493. if (
  36494. oldTail &&
  36495. newTailOffset > oldTailOffset &&
  36496. newOrigin < oldCapacity &&
  36497. oldTail.array.length
  36498. ) {
  36499. newRoot = editableVNode(newRoot, owner);
  36500. var node = newRoot;
  36501. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  36502. var idx = (oldTailOffset >>> level) & MASK;
  36503. node = node.array[idx] = editableVNode(node.array[idx], owner);
  36504. }
  36505. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  36506. }
  36507. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  36508. if (newCapacity < oldCapacity) {
  36509. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  36510. }
  36511. // If the new origin is within the tail, then we do not need a root.
  36512. if (newOrigin >= newTailOffset) {
  36513. newOrigin -= newTailOffset;
  36514. newCapacity -= newTailOffset;
  36515. newLevel = SHIFT;
  36516. newRoot = null;
  36517. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  36518. // Otherwise, if the root has been trimmed, garbage collect.
  36519. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  36520. offsetShift = 0;
  36521. // Identify the new top root node of the subtree of the old root.
  36522. while (newRoot) {
  36523. var beginIndex = (newOrigin >>> newLevel) & MASK;
  36524. if ((beginIndex !== newTailOffset >>> newLevel) & MASK) {
  36525. break;
  36526. }
  36527. if (beginIndex) {
  36528. offsetShift += (1 << newLevel) * beginIndex;
  36529. }
  36530. newLevel -= SHIFT;
  36531. newRoot = newRoot.array[beginIndex];
  36532. }
  36533. // Trim the new sides of the new root.
  36534. if (newRoot && newOrigin > oldOrigin) {
  36535. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  36536. }
  36537. if (newRoot && newTailOffset < oldTailOffset) {
  36538. newRoot = newRoot.removeAfter(
  36539. owner,
  36540. newLevel,
  36541. newTailOffset - offsetShift
  36542. );
  36543. }
  36544. if (offsetShift) {
  36545. newOrigin -= offsetShift;
  36546. newCapacity -= offsetShift;
  36547. }
  36548. }
  36549. if (list.__ownerID) {
  36550. list.size = newCapacity - newOrigin;
  36551. list._origin = newOrigin;
  36552. list._capacity = newCapacity;
  36553. list._level = newLevel;
  36554. list._root = newRoot;
  36555. list._tail = newTail;
  36556. list.__hash = undefined;
  36557. list.__altered = true;
  36558. return list;
  36559. }
  36560. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  36561. }
  36562. function getTailOffset(size) {
  36563. return size < SIZE ? 0 : ((size - 1) >>> SHIFT) << SHIFT;
  36564. }
  36565. var OrderedMap = /*@__PURE__*/(function (Map$$1) {
  36566. function OrderedMap(value) {
  36567. return value === null || value === undefined
  36568. ? emptyOrderedMap()
  36569. : isOrderedMap(value)
  36570. ? value
  36571. : emptyOrderedMap().withMutations(function (map) {
  36572. var iter = KeyedCollection(value);
  36573. assertNotInfinite(iter.size);
  36574. iter.forEach(function (v, k) { return map.set(k, v); });
  36575. });
  36576. }
  36577. if ( Map$$1 ) OrderedMap.__proto__ = Map$$1;
  36578. OrderedMap.prototype = Object.create( Map$$1 && Map$$1.prototype );
  36579. OrderedMap.prototype.constructor = OrderedMap;
  36580. OrderedMap.of = function of (/*...values*/) {
  36581. return this(arguments);
  36582. };
  36583. OrderedMap.prototype.toString = function toString () {
  36584. return this.__toString('OrderedMap {', '}');
  36585. };
  36586. // @pragma Access
  36587. OrderedMap.prototype.get = function get (k, notSetValue) {
  36588. var index = this._map.get(k);
  36589. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  36590. };
  36591. // @pragma Modification
  36592. OrderedMap.prototype.clear = function clear () {
  36593. if (this.size === 0) {
  36594. return this;
  36595. }
  36596. if (this.__ownerID) {
  36597. this.size = 0;
  36598. this._map.clear();
  36599. this._list.clear();
  36600. return this;
  36601. }
  36602. return emptyOrderedMap();
  36603. };
  36604. OrderedMap.prototype.set = function set (k, v) {
  36605. return updateOrderedMap(this, k, v);
  36606. };
  36607. OrderedMap.prototype.remove = function remove (k) {
  36608. return updateOrderedMap(this, k, NOT_SET);
  36609. };
  36610. OrderedMap.prototype.wasAltered = function wasAltered () {
  36611. return this._map.wasAltered() || this._list.wasAltered();
  36612. };
  36613. OrderedMap.prototype.__iterate = function __iterate (fn, reverse) {
  36614. var this$1 = this;
  36615. return this._list.__iterate(
  36616. function (entry) { return entry && fn(entry[1], entry[0], this$1); },
  36617. reverse
  36618. );
  36619. };
  36620. OrderedMap.prototype.__iterator = function __iterator (type, reverse) {
  36621. return this._list.fromEntrySeq().__iterator(type, reverse);
  36622. };
  36623. OrderedMap.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  36624. if (ownerID === this.__ownerID) {
  36625. return this;
  36626. }
  36627. var newMap = this._map.__ensureOwner(ownerID);
  36628. var newList = this._list.__ensureOwner(ownerID);
  36629. if (!ownerID) {
  36630. if (this.size === 0) {
  36631. return emptyOrderedMap();
  36632. }
  36633. this.__ownerID = ownerID;
  36634. this._map = newMap;
  36635. this._list = newList;
  36636. return this;
  36637. }
  36638. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  36639. };
  36640. return OrderedMap;
  36641. }(Map));
  36642. OrderedMap.isOrderedMap = isOrderedMap;
  36643. OrderedMap.prototype[IS_ORDERED_SYMBOL] = true;
  36644. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  36645. function makeOrderedMap(map, list, ownerID, hash) {
  36646. var omap = Object.create(OrderedMap.prototype);
  36647. omap.size = map ? map.size : 0;
  36648. omap._map = map;
  36649. omap._list = list;
  36650. omap.__ownerID = ownerID;
  36651. omap.__hash = hash;
  36652. return omap;
  36653. }
  36654. var EMPTY_ORDERED_MAP;
  36655. function emptyOrderedMap() {
  36656. return (
  36657. EMPTY_ORDERED_MAP ||
  36658. (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()))
  36659. );
  36660. }
  36661. function updateOrderedMap(omap, k, v) {
  36662. var map = omap._map;
  36663. var list = omap._list;
  36664. var i = map.get(k);
  36665. var has = i !== undefined;
  36666. var newMap;
  36667. var newList;
  36668. if (v === NOT_SET) {
  36669. // removed
  36670. if (!has) {
  36671. return omap;
  36672. }
  36673. if (list.size >= SIZE && list.size >= map.size * 2) {
  36674. newList = list.filter(function (entry, idx) { return entry !== undefined && i !== idx; });
  36675. newMap = newList
  36676. .toKeyedSeq()
  36677. .map(function (entry) { return entry[0]; })
  36678. .flip()
  36679. .toMap();
  36680. if (omap.__ownerID) {
  36681. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  36682. }
  36683. } else {
  36684. newMap = map.remove(k);
  36685. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  36686. }
  36687. } else if (has) {
  36688. if (v === list.get(i)[1]) {
  36689. return omap;
  36690. }
  36691. newMap = map;
  36692. newList = list.set(i, [k, v]);
  36693. } else {
  36694. newMap = map.set(k, list.size);
  36695. newList = list.set(list.size, [k, v]);
  36696. }
  36697. if (omap.__ownerID) {
  36698. omap.size = newMap.size;
  36699. omap._map = newMap;
  36700. omap._list = newList;
  36701. omap.__hash = undefined;
  36702. return omap;
  36703. }
  36704. return makeOrderedMap(newMap, newList);
  36705. }
  36706. var IS_STACK_SYMBOL = '@@__IMMUTABLE_STACK__@@';
  36707. function isStack(maybeStack) {
  36708. return Boolean(maybeStack && maybeStack[IS_STACK_SYMBOL]);
  36709. }
  36710. var Stack = /*@__PURE__*/(function (IndexedCollection$$1) {
  36711. function Stack(value) {
  36712. return value === null || value === undefined
  36713. ? emptyStack()
  36714. : isStack(value)
  36715. ? value
  36716. : emptyStack().pushAll(value);
  36717. }
  36718. if ( IndexedCollection$$1 ) Stack.__proto__ = IndexedCollection$$1;
  36719. Stack.prototype = Object.create( IndexedCollection$$1 && IndexedCollection$$1.prototype );
  36720. Stack.prototype.constructor = Stack;
  36721. Stack.of = function of (/*...values*/) {
  36722. return this(arguments);
  36723. };
  36724. Stack.prototype.toString = function toString () {
  36725. return this.__toString('Stack [', ']');
  36726. };
  36727. // @pragma Access
  36728. Stack.prototype.get = function get (index, notSetValue) {
  36729. var head = this._head;
  36730. index = wrapIndex(this, index);
  36731. while (head && index--) {
  36732. head = head.next;
  36733. }
  36734. return head ? head.value : notSetValue;
  36735. };
  36736. Stack.prototype.peek = function peek () {
  36737. return this._head && this._head.value;
  36738. };
  36739. // @pragma Modification
  36740. Stack.prototype.push = function push (/*...values*/) {
  36741. var arguments$1 = arguments;
  36742. if (arguments.length === 0) {
  36743. return this;
  36744. }
  36745. var newSize = this.size + arguments.length;
  36746. var head = this._head;
  36747. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  36748. head = {
  36749. value: arguments$1[ii],
  36750. next: head,
  36751. };
  36752. }
  36753. if (this.__ownerID) {
  36754. this.size = newSize;
  36755. this._head = head;
  36756. this.__hash = undefined;
  36757. this.__altered = true;
  36758. return this;
  36759. }
  36760. return makeStack(newSize, head);
  36761. };
  36762. Stack.prototype.pushAll = function pushAll (iter) {
  36763. iter = IndexedCollection$$1(iter);
  36764. if (iter.size === 0) {
  36765. return this;
  36766. }
  36767. if (this.size === 0 && isStack(iter)) {
  36768. return iter;
  36769. }
  36770. assertNotInfinite(iter.size);
  36771. var newSize = this.size;
  36772. var head = this._head;
  36773. iter.__iterate(function (value) {
  36774. newSize++;
  36775. head = {
  36776. value: value,
  36777. next: head,
  36778. };
  36779. }, /* reverse */ true);
  36780. if (this.__ownerID) {
  36781. this.size = newSize;
  36782. this._head = head;
  36783. this.__hash = undefined;
  36784. this.__altered = true;
  36785. return this;
  36786. }
  36787. return makeStack(newSize, head);
  36788. };
  36789. Stack.prototype.pop = function pop () {
  36790. return this.slice(1);
  36791. };
  36792. Stack.prototype.clear = function clear () {
  36793. if (this.size === 0) {
  36794. return this;
  36795. }
  36796. if (this.__ownerID) {
  36797. this.size = 0;
  36798. this._head = undefined;
  36799. this.__hash = undefined;
  36800. this.__altered = true;
  36801. return this;
  36802. }
  36803. return emptyStack();
  36804. };
  36805. Stack.prototype.slice = function slice (begin, end) {
  36806. if (wholeSlice(begin, end, this.size)) {
  36807. return this;
  36808. }
  36809. var resolvedBegin = resolveBegin(begin, this.size);
  36810. var resolvedEnd = resolveEnd(end, this.size);
  36811. if (resolvedEnd !== this.size) {
  36812. // super.slice(begin, end);
  36813. return IndexedCollection$$1.prototype.slice.call(this, begin, end);
  36814. }
  36815. var newSize = this.size - resolvedBegin;
  36816. var head = this._head;
  36817. while (resolvedBegin--) {
  36818. head = head.next;
  36819. }
  36820. if (this.__ownerID) {
  36821. this.size = newSize;
  36822. this._head = head;
  36823. this.__hash = undefined;
  36824. this.__altered = true;
  36825. return this;
  36826. }
  36827. return makeStack(newSize, head);
  36828. };
  36829. // @pragma Mutability
  36830. Stack.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  36831. if (ownerID === this.__ownerID) {
  36832. return this;
  36833. }
  36834. if (!ownerID) {
  36835. if (this.size === 0) {
  36836. return emptyStack();
  36837. }
  36838. this.__ownerID = ownerID;
  36839. this.__altered = false;
  36840. return this;
  36841. }
  36842. return makeStack(this.size, this._head, ownerID, this.__hash);
  36843. };
  36844. // @pragma Iteration
  36845. Stack.prototype.__iterate = function __iterate (fn, reverse) {
  36846. var this$1 = this;
  36847. if (reverse) {
  36848. return new ArraySeq(this.toArray()).__iterate(
  36849. function (v, k) { return fn(v, k, this$1); },
  36850. reverse
  36851. );
  36852. }
  36853. var iterations = 0;
  36854. var node = this._head;
  36855. while (node) {
  36856. if (fn(node.value, iterations++, this) === false) {
  36857. break;
  36858. }
  36859. node = node.next;
  36860. }
  36861. return iterations;
  36862. };
  36863. Stack.prototype.__iterator = function __iterator (type, reverse) {
  36864. if (reverse) {
  36865. return new ArraySeq(this.toArray()).__iterator(type, reverse);
  36866. }
  36867. var iterations = 0;
  36868. var node = this._head;
  36869. return new Iterator(function () {
  36870. if (node) {
  36871. var value = node.value;
  36872. node = node.next;
  36873. return iteratorValue(type, iterations++, value);
  36874. }
  36875. return iteratorDone();
  36876. });
  36877. };
  36878. return Stack;
  36879. }(IndexedCollection));
  36880. Stack.isStack = isStack;
  36881. var StackPrototype = Stack.prototype;
  36882. StackPrototype[IS_STACK_SYMBOL] = true;
  36883. StackPrototype.shift = StackPrototype.pop;
  36884. StackPrototype.unshift = StackPrototype.push;
  36885. StackPrototype.unshiftAll = StackPrototype.pushAll;
  36886. StackPrototype.withMutations = withMutations;
  36887. StackPrototype.wasAltered = wasAltered;
  36888. StackPrototype.asImmutable = asImmutable;
  36889. StackPrototype['@@transducer/init'] = StackPrototype.asMutable = asMutable;
  36890. StackPrototype['@@transducer/step'] = function(result, arr) {
  36891. return result.unshift(arr);
  36892. };
  36893. StackPrototype['@@transducer/result'] = function(obj) {
  36894. return obj.asImmutable();
  36895. };
  36896. function makeStack(size, head, ownerID, hash) {
  36897. var map = Object.create(StackPrototype);
  36898. map.size = size;
  36899. map._head = head;
  36900. map.__ownerID = ownerID;
  36901. map.__hash = hash;
  36902. map.__altered = false;
  36903. return map;
  36904. }
  36905. var EMPTY_STACK;
  36906. function emptyStack() {
  36907. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  36908. }
  36909. var IS_SET_SYMBOL = '@@__IMMUTABLE_SET__@@';
  36910. function isSet(maybeSet) {
  36911. return Boolean(maybeSet && maybeSet[IS_SET_SYMBOL]);
  36912. }
  36913. function isOrderedSet(maybeOrderedSet) {
  36914. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  36915. }
  36916. function deepEqual(a, b) {
  36917. if (a === b) {
  36918. return true;
  36919. }
  36920. if (
  36921. !isCollection(b) ||
  36922. (a.size !== undefined && b.size !== undefined && a.size !== b.size) ||
  36923. (a.__hash !== undefined &&
  36924. b.__hash !== undefined &&
  36925. a.__hash !== b.__hash) ||
  36926. isKeyed(a) !== isKeyed(b) ||
  36927. isIndexed(a) !== isIndexed(b) ||
  36928. isOrdered(a) !== isOrdered(b)
  36929. ) {
  36930. return false;
  36931. }
  36932. if (a.size === 0 && b.size === 0) {
  36933. return true;
  36934. }
  36935. var notAssociative = !isAssociative(a);
  36936. if (isOrdered(a)) {
  36937. var entries = a.entries();
  36938. return (
  36939. b.every(function (v, k) {
  36940. var entry = entries.next().value;
  36941. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  36942. }) && entries.next().done
  36943. );
  36944. }
  36945. var flipped = false;
  36946. if (a.size === undefined) {
  36947. if (b.size === undefined) {
  36948. if (typeof a.cacheResult === 'function') {
  36949. a.cacheResult();
  36950. }
  36951. } else {
  36952. flipped = true;
  36953. var _ = a;
  36954. a = b;
  36955. b = _;
  36956. }
  36957. }
  36958. var allEqual = true;
  36959. var bSize = b.__iterate(function (v, k) {
  36960. if (
  36961. notAssociative
  36962. ? !a.has(v)
  36963. : flipped
  36964. ? !is(v, a.get(k, NOT_SET))
  36965. : !is(a.get(k, NOT_SET), v)
  36966. ) {
  36967. allEqual = false;
  36968. return false;
  36969. }
  36970. });
  36971. return allEqual && a.size === bSize;
  36972. }
  36973. /**
  36974. * Contributes additional methods to a constructor
  36975. */
  36976. function mixin(ctor, methods) {
  36977. var keyCopier = function (key) {
  36978. ctor.prototype[key] = methods[key];
  36979. };
  36980. Object.keys(methods).forEach(keyCopier);
  36981. Object.getOwnPropertySymbols &&
  36982. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  36983. return ctor;
  36984. }
  36985. function toJS(value) {
  36986. if (!value || typeof value !== 'object') {
  36987. return value;
  36988. }
  36989. if (!isCollection(value)) {
  36990. if (!isDataStructure(value)) {
  36991. return value;
  36992. }
  36993. value = Seq(value);
  36994. }
  36995. if (isKeyed(value)) {
  36996. var result$1 = {};
  36997. value.__iterate(function (v, k) {
  36998. result$1[k] = toJS(v);
  36999. });
  37000. return result$1;
  37001. }
  37002. var result = [];
  37003. value.__iterate(function (v) {
  37004. result.push(toJS(v));
  37005. });
  37006. return result;
  37007. }
  37008. var Set = /*@__PURE__*/(function (SetCollection$$1) {
  37009. function Set(value) {
  37010. return value === null || value === undefined
  37011. ? emptySet()
  37012. : isSet(value) && !isOrdered(value)
  37013. ? value
  37014. : emptySet().withMutations(function (set) {
  37015. var iter = SetCollection$$1(value);
  37016. assertNotInfinite(iter.size);
  37017. iter.forEach(function (v) { return set.add(v); });
  37018. });
  37019. }
  37020. if ( SetCollection$$1 ) Set.__proto__ = SetCollection$$1;
  37021. Set.prototype = Object.create( SetCollection$$1 && SetCollection$$1.prototype );
  37022. Set.prototype.constructor = Set;
  37023. Set.of = function of (/*...values*/) {
  37024. return this(arguments);
  37025. };
  37026. Set.fromKeys = function fromKeys (value) {
  37027. return this(KeyedCollection(value).keySeq());
  37028. };
  37029. Set.intersect = function intersect (sets) {
  37030. sets = Collection(sets).toArray();
  37031. return sets.length
  37032. ? SetPrototype.intersect.apply(Set(sets.pop()), sets)
  37033. : emptySet();
  37034. };
  37035. Set.union = function union (sets) {
  37036. sets = Collection(sets).toArray();
  37037. return sets.length
  37038. ? SetPrototype.union.apply(Set(sets.pop()), sets)
  37039. : emptySet();
  37040. };
  37041. Set.prototype.toString = function toString () {
  37042. return this.__toString('Set {', '}');
  37043. };
  37044. // @pragma Access
  37045. Set.prototype.has = function has (value) {
  37046. return this._map.has(value);
  37047. };
  37048. // @pragma Modification
  37049. Set.prototype.add = function add (value) {
  37050. return updateSet(this, this._map.set(value, value));
  37051. };
  37052. Set.prototype.remove = function remove (value) {
  37053. return updateSet(this, this._map.remove(value));
  37054. };
  37055. Set.prototype.clear = function clear () {
  37056. return updateSet(this, this._map.clear());
  37057. };
  37058. // @pragma Composition
  37059. Set.prototype.map = function map (mapper, context) {
  37060. var this$1 = this;
  37061. var removes = [];
  37062. var adds = [];
  37063. this.forEach(function (value) {
  37064. var mapped = mapper.call(context, value, value, this$1);
  37065. if (mapped !== value) {
  37066. removes.push(value);
  37067. adds.push(mapped);
  37068. }
  37069. });
  37070. return this.withMutations(function (set) {
  37071. removes.forEach(function (value) { return set.remove(value); });
  37072. adds.forEach(function (value) { return set.add(value); });
  37073. });
  37074. };
  37075. Set.prototype.union = function union () {
  37076. var iters = [], len = arguments.length;
  37077. while ( len-- ) iters[ len ] = arguments[ len ];
  37078. iters = iters.filter(function (x) { return x.size !== 0; });
  37079. if (iters.length === 0) {
  37080. return this;
  37081. }
  37082. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  37083. return this.constructor(iters[0]);
  37084. }
  37085. return this.withMutations(function (set) {
  37086. for (var ii = 0; ii < iters.length; ii++) {
  37087. SetCollection$$1(iters[ii]).forEach(function (value) { return set.add(value); });
  37088. }
  37089. });
  37090. };
  37091. Set.prototype.intersect = function intersect () {
  37092. var iters = [], len = arguments.length;
  37093. while ( len-- ) iters[ len ] = arguments[ len ];
  37094. if (iters.length === 0) {
  37095. return this;
  37096. }
  37097. iters = iters.map(function (iter) { return SetCollection$$1(iter); });
  37098. var toRemove = [];
  37099. this.forEach(function (value) {
  37100. if (!iters.every(function (iter) { return iter.includes(value); })) {
  37101. toRemove.push(value);
  37102. }
  37103. });
  37104. return this.withMutations(function (set) {
  37105. toRemove.forEach(function (value) {
  37106. set.remove(value);
  37107. });
  37108. });
  37109. };
  37110. Set.prototype.subtract = function subtract () {
  37111. var iters = [], len = arguments.length;
  37112. while ( len-- ) iters[ len ] = arguments[ len ];
  37113. if (iters.length === 0) {
  37114. return this;
  37115. }
  37116. iters = iters.map(function (iter) { return SetCollection$$1(iter); });
  37117. var toRemove = [];
  37118. this.forEach(function (value) {
  37119. if (iters.some(function (iter) { return iter.includes(value); })) {
  37120. toRemove.push(value);
  37121. }
  37122. });
  37123. return this.withMutations(function (set) {
  37124. toRemove.forEach(function (value) {
  37125. set.remove(value);
  37126. });
  37127. });
  37128. };
  37129. Set.prototype.sort = function sort (comparator) {
  37130. // Late binding
  37131. return OrderedSet(sortFactory(this, comparator));
  37132. };
  37133. Set.prototype.sortBy = function sortBy (mapper, comparator) {
  37134. // Late binding
  37135. return OrderedSet(sortFactory(this, comparator, mapper));
  37136. };
  37137. Set.prototype.wasAltered = function wasAltered () {
  37138. return this._map.wasAltered();
  37139. };
  37140. Set.prototype.__iterate = function __iterate (fn, reverse) {
  37141. var this$1 = this;
  37142. return this._map.__iterate(function (k) { return fn(k, k, this$1); }, reverse);
  37143. };
  37144. Set.prototype.__iterator = function __iterator (type, reverse) {
  37145. return this._map.__iterator(type, reverse);
  37146. };
  37147. Set.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  37148. if (ownerID === this.__ownerID) {
  37149. return this;
  37150. }
  37151. var newMap = this._map.__ensureOwner(ownerID);
  37152. if (!ownerID) {
  37153. if (this.size === 0) {
  37154. return this.__empty();
  37155. }
  37156. this.__ownerID = ownerID;
  37157. this._map = newMap;
  37158. return this;
  37159. }
  37160. return this.__make(newMap, ownerID);
  37161. };
  37162. return Set;
  37163. }(SetCollection));
  37164. Set.isSet = isSet;
  37165. var SetPrototype = Set.prototype;
  37166. SetPrototype[IS_SET_SYMBOL] = true;
  37167. SetPrototype[DELETE] = SetPrototype.remove;
  37168. SetPrototype.merge = SetPrototype.concat = SetPrototype.union;
  37169. SetPrototype.withMutations = withMutations;
  37170. SetPrototype.asImmutable = asImmutable;
  37171. SetPrototype['@@transducer/init'] = SetPrototype.asMutable = asMutable;
  37172. SetPrototype['@@transducer/step'] = function(result, arr) {
  37173. return result.add(arr);
  37174. };
  37175. SetPrototype['@@transducer/result'] = function(obj) {
  37176. return obj.asImmutable();
  37177. };
  37178. SetPrototype.__empty = emptySet;
  37179. SetPrototype.__make = makeSet;
  37180. function updateSet(set, newMap) {
  37181. if (set.__ownerID) {
  37182. set.size = newMap.size;
  37183. set._map = newMap;
  37184. return set;
  37185. }
  37186. return newMap === set._map
  37187. ? set
  37188. : newMap.size === 0
  37189. ? set.__empty()
  37190. : set.__make(newMap);
  37191. }
  37192. function makeSet(map, ownerID) {
  37193. var set = Object.create(SetPrototype);
  37194. set.size = map ? map.size : 0;
  37195. set._map = map;
  37196. set.__ownerID = ownerID;
  37197. return set;
  37198. }
  37199. var EMPTY_SET;
  37200. function emptySet() {
  37201. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  37202. }
  37203. /**
  37204. * Returns a lazy seq of nums from start (inclusive) to end
  37205. * (exclusive), by step, where start defaults to 0, step to 1, and end to
  37206. * infinity. When start is equal to end, returns empty list.
  37207. */
  37208. var Range = /*@__PURE__*/(function (IndexedSeq$$1) {
  37209. function Range(start, end, step) {
  37210. if (!(this instanceof Range)) {
  37211. return new Range(start, end, step);
  37212. }
  37213. invariant(step !== 0, 'Cannot step a Range by 0');
  37214. start = start || 0;
  37215. if (end === undefined) {
  37216. end = Infinity;
  37217. }
  37218. step = step === undefined ? 1 : Math.abs(step);
  37219. if (end < start) {
  37220. step = -step;
  37221. }
  37222. this._start = start;
  37223. this._end = end;
  37224. this._step = step;
  37225. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  37226. if (this.size === 0) {
  37227. if (EMPTY_RANGE) {
  37228. return EMPTY_RANGE;
  37229. }
  37230. EMPTY_RANGE = this;
  37231. }
  37232. }
  37233. if ( IndexedSeq$$1 ) Range.__proto__ = IndexedSeq$$1;
  37234. Range.prototype = Object.create( IndexedSeq$$1 && IndexedSeq$$1.prototype );
  37235. Range.prototype.constructor = Range;
  37236. Range.prototype.toString = function toString () {
  37237. if (this.size === 0) {
  37238. return 'Range []';
  37239. }
  37240. return (
  37241. 'Range [ ' +
  37242. this._start +
  37243. '...' +
  37244. this._end +
  37245. (this._step !== 1 ? ' by ' + this._step : '') +
  37246. ' ]'
  37247. );
  37248. };
  37249. Range.prototype.get = function get (index, notSetValue) {
  37250. return this.has(index)
  37251. ? this._start + wrapIndex(this, index) * this._step
  37252. : notSetValue;
  37253. };
  37254. Range.prototype.includes = function includes (searchValue) {
  37255. var possibleIndex = (searchValue - this._start) / this._step;
  37256. return (
  37257. possibleIndex >= 0 &&
  37258. possibleIndex < this.size &&
  37259. possibleIndex === Math.floor(possibleIndex)
  37260. );
  37261. };
  37262. Range.prototype.slice = function slice (begin, end) {
  37263. if (wholeSlice(begin, end, this.size)) {
  37264. return this;
  37265. }
  37266. begin = resolveBegin(begin, this.size);
  37267. end = resolveEnd(end, this.size);
  37268. if (end <= begin) {
  37269. return new Range(0, 0);
  37270. }
  37271. return new Range(
  37272. this.get(begin, this._end),
  37273. this.get(end, this._end),
  37274. this._step
  37275. );
  37276. };
  37277. Range.prototype.indexOf = function indexOf (searchValue) {
  37278. var offsetValue = searchValue - this._start;
  37279. if (offsetValue % this._step === 0) {
  37280. var index = offsetValue / this._step;
  37281. if (index >= 0 && index < this.size) {
  37282. return index;
  37283. }
  37284. }
  37285. return -1;
  37286. };
  37287. Range.prototype.lastIndexOf = function lastIndexOf (searchValue) {
  37288. return this.indexOf(searchValue);
  37289. };
  37290. Range.prototype.__iterate = function __iterate (fn, reverse) {
  37291. var size = this.size;
  37292. var step = this._step;
  37293. var value = reverse ? this._start + (size - 1) * step : this._start;
  37294. var i = 0;
  37295. while (i !== size) {
  37296. if (fn(value, reverse ? size - ++i : i++, this) === false) {
  37297. break;
  37298. }
  37299. value += reverse ? -step : step;
  37300. }
  37301. return i;
  37302. };
  37303. Range.prototype.__iterator = function __iterator (type, reverse) {
  37304. var size = this.size;
  37305. var step = this._step;
  37306. var value = reverse ? this._start + (size - 1) * step : this._start;
  37307. var i = 0;
  37308. return new Iterator(function () {
  37309. if (i === size) {
  37310. return iteratorDone();
  37311. }
  37312. var v = value;
  37313. value += reverse ? -step : step;
  37314. return iteratorValue(type, reverse ? size - ++i : i++, v);
  37315. });
  37316. };
  37317. Range.prototype.equals = function equals (other) {
  37318. return other instanceof Range
  37319. ? this._start === other._start &&
  37320. this._end === other._end &&
  37321. this._step === other._step
  37322. : deepEqual(this, other);
  37323. };
  37324. return Range;
  37325. }(IndexedSeq));
  37326. var EMPTY_RANGE;
  37327. function getIn(collection, searchKeyPath, notSetValue) {
  37328. var keyPath = coerceKeyPath(searchKeyPath);
  37329. var i = 0;
  37330. while (i !== keyPath.length) {
  37331. collection = get(collection, keyPath[i++], NOT_SET);
  37332. if (collection === NOT_SET) {
  37333. return notSetValue;
  37334. }
  37335. }
  37336. return collection;
  37337. }
  37338. function getIn$1(searchKeyPath, notSetValue) {
  37339. return getIn(this, searchKeyPath, notSetValue);
  37340. }
  37341. function hasIn(collection, keyPath) {
  37342. return getIn(collection, keyPath, NOT_SET) !== NOT_SET;
  37343. }
  37344. function hasIn$1(searchKeyPath) {
  37345. return hasIn(this, searchKeyPath);
  37346. }
  37347. function toObject() {
  37348. assertNotInfinite(this.size);
  37349. var object = {};
  37350. this.__iterate(function (v, k) {
  37351. object[k] = v;
  37352. });
  37353. return object;
  37354. }
  37355. // Note: all of these methods are deprecated.
  37356. Collection.isIterable = isCollection;
  37357. Collection.isKeyed = isKeyed;
  37358. Collection.isIndexed = isIndexed;
  37359. Collection.isAssociative = isAssociative;
  37360. Collection.isOrdered = isOrdered;
  37361. Collection.Iterator = Iterator;
  37362. mixin(Collection, {
  37363. // ### Conversion to other types
  37364. toArray: function toArray() {
  37365. assertNotInfinite(this.size);
  37366. var array = new Array(this.size || 0);
  37367. var useTuples = isKeyed(this);
  37368. var i = 0;
  37369. this.__iterate(function (v, k) {
  37370. // Keyed collections produce an array of tuples.
  37371. array[i++] = useTuples ? [k, v] : v;
  37372. });
  37373. return array;
  37374. },
  37375. toIndexedSeq: function toIndexedSeq() {
  37376. return new ToIndexedSequence(this);
  37377. },
  37378. toJS: function toJS$1() {
  37379. return toJS(this);
  37380. },
  37381. toKeyedSeq: function toKeyedSeq() {
  37382. return new ToKeyedSequence(this, true);
  37383. },
  37384. toMap: function toMap() {
  37385. // Use Late Binding here to solve the circular dependency.
  37386. return Map(this.toKeyedSeq());
  37387. },
  37388. toObject: toObject,
  37389. toOrderedMap: function toOrderedMap() {
  37390. // Use Late Binding here to solve the circular dependency.
  37391. return OrderedMap(this.toKeyedSeq());
  37392. },
  37393. toOrderedSet: function toOrderedSet() {
  37394. // Use Late Binding here to solve the circular dependency.
  37395. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  37396. },
  37397. toSet: function toSet() {
  37398. // Use Late Binding here to solve the circular dependency.
  37399. return Set(isKeyed(this) ? this.valueSeq() : this);
  37400. },
  37401. toSetSeq: function toSetSeq() {
  37402. return new ToSetSequence(this);
  37403. },
  37404. toSeq: function toSeq() {
  37405. return isIndexed(this)
  37406. ? this.toIndexedSeq()
  37407. : isKeyed(this)
  37408. ? this.toKeyedSeq()
  37409. : this.toSetSeq();
  37410. },
  37411. toStack: function toStack() {
  37412. // Use Late Binding here to solve the circular dependency.
  37413. return Stack(isKeyed(this) ? this.valueSeq() : this);
  37414. },
  37415. toList: function toList() {
  37416. // Use Late Binding here to solve the circular dependency.
  37417. return List(isKeyed(this) ? this.valueSeq() : this);
  37418. },
  37419. // ### Common JavaScript methods and properties
  37420. toString: function toString() {
  37421. return '[Collection]';
  37422. },
  37423. __toString: function __toString(head, tail) {
  37424. if (this.size === 0) {
  37425. return head + tail;
  37426. }
  37427. return (
  37428. head +
  37429. ' ' +
  37430. this.toSeq()
  37431. .map(this.__toStringMapper)
  37432. .join(', ') +
  37433. ' ' +
  37434. tail
  37435. );
  37436. },
  37437. // ### ES6 Collection methods (ES6 Array and Map)
  37438. concat: function concat() {
  37439. var values = [], len = arguments.length;
  37440. while ( len-- ) values[ len ] = arguments[ len ];
  37441. return reify(this, concatFactory(this, values));
  37442. },
  37443. includes: function includes(searchValue) {
  37444. return this.some(function (value) { return is(value, searchValue); });
  37445. },
  37446. entries: function entries() {
  37447. return this.__iterator(ITERATE_ENTRIES);
  37448. },
  37449. every: function every(predicate, context) {
  37450. assertNotInfinite(this.size);
  37451. var returnValue = true;
  37452. this.__iterate(function (v, k, c) {
  37453. if (!predicate.call(context, v, k, c)) {
  37454. returnValue = false;
  37455. return false;
  37456. }
  37457. });
  37458. return returnValue;
  37459. },
  37460. filter: function filter(predicate, context) {
  37461. return reify(this, filterFactory(this, predicate, context, true));
  37462. },
  37463. find: function find(predicate, context, notSetValue) {
  37464. var entry = this.findEntry(predicate, context);
  37465. return entry ? entry[1] : notSetValue;
  37466. },
  37467. forEach: function forEach(sideEffect, context) {
  37468. assertNotInfinite(this.size);
  37469. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  37470. },
  37471. join: function join(separator) {
  37472. assertNotInfinite(this.size);
  37473. separator = separator !== undefined ? '' + separator : ',';
  37474. var joined = '';
  37475. var isFirst = true;
  37476. this.__iterate(function (v) {
  37477. isFirst ? (isFirst = false) : (joined += separator);
  37478. joined += v !== null && v !== undefined ? v.toString() : '';
  37479. });
  37480. return joined;
  37481. },
  37482. keys: function keys() {
  37483. return this.__iterator(ITERATE_KEYS);
  37484. },
  37485. map: function map(mapper, context) {
  37486. return reify(this, mapFactory(this, mapper, context));
  37487. },
  37488. reduce: function reduce$1(reducer, initialReduction, context) {
  37489. return reduce(
  37490. this,
  37491. reducer,
  37492. initialReduction,
  37493. context,
  37494. arguments.length < 2,
  37495. false
  37496. );
  37497. },
  37498. reduceRight: function reduceRight(reducer, initialReduction, context) {
  37499. return reduce(
  37500. this,
  37501. reducer,
  37502. initialReduction,
  37503. context,
  37504. arguments.length < 2,
  37505. true
  37506. );
  37507. },
  37508. reverse: function reverse() {
  37509. return reify(this, reverseFactory(this, true));
  37510. },
  37511. slice: function slice(begin, end) {
  37512. return reify(this, sliceFactory(this, begin, end, true));
  37513. },
  37514. some: function some(predicate, context) {
  37515. return !this.every(not(predicate), context);
  37516. },
  37517. sort: function sort(comparator) {
  37518. return reify(this, sortFactory(this, comparator));
  37519. },
  37520. values: function values() {
  37521. return this.__iterator(ITERATE_VALUES);
  37522. },
  37523. // ### More sequential methods
  37524. butLast: function butLast() {
  37525. return this.slice(0, -1);
  37526. },
  37527. isEmpty: function isEmpty() {
  37528. return this.size !== undefined ? this.size === 0 : !this.some(function () { return true; });
  37529. },
  37530. count: function count(predicate, context) {
  37531. return ensureSize(
  37532. predicate ? this.toSeq().filter(predicate, context) : this
  37533. );
  37534. },
  37535. countBy: function countBy(grouper, context) {
  37536. return countByFactory(this, grouper, context);
  37537. },
  37538. equals: function equals(other) {
  37539. return deepEqual(this, other);
  37540. },
  37541. entrySeq: function entrySeq() {
  37542. var collection = this;
  37543. if (collection._cache) {
  37544. // We cache as an entries array, so we can just return the cache!
  37545. return new ArraySeq(collection._cache);
  37546. }
  37547. var entriesSequence = collection
  37548. .toSeq()
  37549. .map(entryMapper)
  37550. .toIndexedSeq();
  37551. entriesSequence.fromEntrySeq = function () { return collection.toSeq(); };
  37552. return entriesSequence;
  37553. },
  37554. filterNot: function filterNot(predicate, context) {
  37555. return this.filter(not(predicate), context);
  37556. },
  37557. findEntry: function findEntry(predicate, context, notSetValue) {
  37558. var found = notSetValue;
  37559. this.__iterate(function (v, k, c) {
  37560. if (predicate.call(context, v, k, c)) {
  37561. found = [k, v];
  37562. return false;
  37563. }
  37564. });
  37565. return found;
  37566. },
  37567. findKey: function findKey(predicate, context) {
  37568. var entry = this.findEntry(predicate, context);
  37569. return entry && entry[0];
  37570. },
  37571. findLast: function findLast(predicate, context, notSetValue) {
  37572. return this.toKeyedSeq()
  37573. .reverse()
  37574. .find(predicate, context, notSetValue);
  37575. },
  37576. findLastEntry: function findLastEntry(predicate, context, notSetValue) {
  37577. return this.toKeyedSeq()
  37578. .reverse()
  37579. .findEntry(predicate, context, notSetValue);
  37580. },
  37581. findLastKey: function findLastKey(predicate, context) {
  37582. return this.toKeyedSeq()
  37583. .reverse()
  37584. .findKey(predicate, context);
  37585. },
  37586. first: function first(notSetValue) {
  37587. return this.find(returnTrue, null, notSetValue);
  37588. },
  37589. flatMap: function flatMap(mapper, context) {
  37590. return reify(this, flatMapFactory(this, mapper, context));
  37591. },
  37592. flatten: function flatten(depth) {
  37593. return reify(this, flattenFactory(this, depth, true));
  37594. },
  37595. fromEntrySeq: function fromEntrySeq() {
  37596. return new FromEntriesSequence(this);
  37597. },
  37598. get: function get(searchKey, notSetValue) {
  37599. return this.find(function (_, key) { return is(key, searchKey); }, undefined, notSetValue);
  37600. },
  37601. getIn: getIn$1,
  37602. groupBy: function groupBy(grouper, context) {
  37603. return groupByFactory(this, grouper, context);
  37604. },
  37605. has: function has(searchKey) {
  37606. return this.get(searchKey, NOT_SET) !== NOT_SET;
  37607. },
  37608. hasIn: hasIn$1,
  37609. isSubset: function isSubset(iter) {
  37610. iter = typeof iter.includes === 'function' ? iter : Collection(iter);
  37611. return this.every(function (value) { return iter.includes(value); });
  37612. },
  37613. isSuperset: function isSuperset(iter) {
  37614. iter = typeof iter.isSubset === 'function' ? iter : Collection(iter);
  37615. return iter.isSubset(this);
  37616. },
  37617. keyOf: function keyOf(searchValue) {
  37618. return this.findKey(function (value) { return is(value, searchValue); });
  37619. },
  37620. keySeq: function keySeq() {
  37621. return this.toSeq()
  37622. .map(keyMapper)
  37623. .toIndexedSeq();
  37624. },
  37625. last: function last(notSetValue) {
  37626. return this.toSeq()
  37627. .reverse()
  37628. .first(notSetValue);
  37629. },
  37630. lastKeyOf: function lastKeyOf(searchValue) {
  37631. return this.toKeyedSeq()
  37632. .reverse()
  37633. .keyOf(searchValue);
  37634. },
  37635. max: function max(comparator) {
  37636. return maxFactory(this, comparator);
  37637. },
  37638. maxBy: function maxBy(mapper, comparator) {
  37639. return maxFactory(this, comparator, mapper);
  37640. },
  37641. min: function min(comparator) {
  37642. return maxFactory(
  37643. this,
  37644. comparator ? neg(comparator) : defaultNegComparator
  37645. );
  37646. },
  37647. minBy: function minBy(mapper, comparator) {
  37648. return maxFactory(
  37649. this,
  37650. comparator ? neg(comparator) : defaultNegComparator,
  37651. mapper
  37652. );
  37653. },
  37654. rest: function rest() {
  37655. return this.slice(1);
  37656. },
  37657. skip: function skip(amount) {
  37658. return amount === 0 ? this : this.slice(Math.max(0, amount));
  37659. },
  37660. skipLast: function skipLast(amount) {
  37661. return amount === 0 ? this : this.slice(0, -Math.max(0, amount));
  37662. },
  37663. skipWhile: function skipWhile(predicate, context) {
  37664. return reify(this, skipWhileFactory(this, predicate, context, true));
  37665. },
  37666. skipUntil: function skipUntil(predicate, context) {
  37667. return this.skipWhile(not(predicate), context);
  37668. },
  37669. sortBy: function sortBy(mapper, comparator) {
  37670. return reify(this, sortFactory(this, comparator, mapper));
  37671. },
  37672. take: function take(amount) {
  37673. return this.slice(0, Math.max(0, amount));
  37674. },
  37675. takeLast: function takeLast(amount) {
  37676. return this.slice(-Math.max(0, amount));
  37677. },
  37678. takeWhile: function takeWhile(predicate, context) {
  37679. return reify(this, takeWhileFactory(this, predicate, context));
  37680. },
  37681. takeUntil: function takeUntil(predicate, context) {
  37682. return this.takeWhile(not(predicate), context);
  37683. },
  37684. update: function update(fn) {
  37685. return fn(this);
  37686. },
  37687. valueSeq: function valueSeq() {
  37688. return this.toIndexedSeq();
  37689. },
  37690. // ### Hashable Object
  37691. hashCode: function hashCode() {
  37692. return this.__hash || (this.__hash = hashCollection(this));
  37693. },
  37694. // ### Internal
  37695. // abstract __iterate(fn, reverse)
  37696. // abstract __iterator(type, reverse)
  37697. });
  37698. var CollectionPrototype = Collection.prototype;
  37699. CollectionPrototype[IS_COLLECTION_SYMBOL] = true;
  37700. CollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.values;
  37701. CollectionPrototype.toJSON = CollectionPrototype.toArray;
  37702. CollectionPrototype.__toStringMapper = quoteString;
  37703. CollectionPrototype.inspect = CollectionPrototype.toSource = function() {
  37704. return this.toString();
  37705. };
  37706. CollectionPrototype.chain = CollectionPrototype.flatMap;
  37707. CollectionPrototype.contains = CollectionPrototype.includes;
  37708. mixin(KeyedCollection, {
  37709. // ### More sequential methods
  37710. flip: function flip() {
  37711. return reify(this, flipFactory(this));
  37712. },
  37713. mapEntries: function mapEntries(mapper, context) {
  37714. var this$1 = this;
  37715. var iterations = 0;
  37716. return reify(
  37717. this,
  37718. this.toSeq()
  37719. .map(function (v, k) { return mapper.call(context, [k, v], iterations++, this$1); })
  37720. .fromEntrySeq()
  37721. );
  37722. },
  37723. mapKeys: function mapKeys(mapper, context) {
  37724. var this$1 = this;
  37725. return reify(
  37726. this,
  37727. this.toSeq()
  37728. .flip()
  37729. .map(function (k, v) { return mapper.call(context, k, v, this$1); })
  37730. .flip()
  37731. );
  37732. },
  37733. });
  37734. var KeyedCollectionPrototype = KeyedCollection.prototype;
  37735. KeyedCollectionPrototype[IS_KEYED_SYMBOL] = true;
  37736. KeyedCollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.entries;
  37737. KeyedCollectionPrototype.toJSON = toObject;
  37738. KeyedCollectionPrototype.__toStringMapper = function (v, k) { return quoteString(k) + ': ' + quoteString(v); };
  37739. mixin(IndexedCollection, {
  37740. // ### Conversion to other types
  37741. toKeyedSeq: function toKeyedSeq() {
  37742. return new ToKeyedSequence(this, false);
  37743. },
  37744. // ### ES6 Collection methods (ES6 Array and Map)
  37745. filter: function filter(predicate, context) {
  37746. return reify(this, filterFactory(this, predicate, context, false));
  37747. },
  37748. findIndex: function findIndex(predicate, context) {
  37749. var entry = this.findEntry(predicate, context);
  37750. return entry ? entry[0] : -1;
  37751. },
  37752. indexOf: function indexOf(searchValue) {
  37753. var key = this.keyOf(searchValue);
  37754. return key === undefined ? -1 : key;
  37755. },
  37756. lastIndexOf: function lastIndexOf(searchValue) {
  37757. var key = this.lastKeyOf(searchValue);
  37758. return key === undefined ? -1 : key;
  37759. },
  37760. reverse: function reverse() {
  37761. return reify(this, reverseFactory(this, false));
  37762. },
  37763. slice: function slice(begin, end) {
  37764. return reify(this, sliceFactory(this, begin, end, false));
  37765. },
  37766. splice: function splice(index, removeNum /*, ...values*/) {
  37767. var numArgs = arguments.length;
  37768. removeNum = Math.max(removeNum || 0, 0);
  37769. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  37770. return this;
  37771. }
  37772. // If index is negative, it should resolve relative to the size of the
  37773. // collection. However size may be expensive to compute if not cached, so
  37774. // only call count() if the number is in fact negative.
  37775. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  37776. var spliced = this.slice(0, index);
  37777. return reify(
  37778. this,
  37779. numArgs === 1
  37780. ? spliced
  37781. : spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  37782. );
  37783. },
  37784. // ### More collection methods
  37785. findLastIndex: function findLastIndex(predicate, context) {
  37786. var entry = this.findLastEntry(predicate, context);
  37787. return entry ? entry[0] : -1;
  37788. },
  37789. first: function first(notSetValue) {
  37790. return this.get(0, notSetValue);
  37791. },
  37792. flatten: function flatten(depth) {
  37793. return reify(this, flattenFactory(this, depth, false));
  37794. },
  37795. get: function get(index, notSetValue) {
  37796. index = wrapIndex(this, index);
  37797. return index < 0 ||
  37798. (this.size === Infinity || (this.size !== undefined && index > this.size))
  37799. ? notSetValue
  37800. : this.find(function (_, key) { return key === index; }, undefined, notSetValue);
  37801. },
  37802. has: function has(index) {
  37803. index = wrapIndex(this, index);
  37804. return (
  37805. index >= 0 &&
  37806. (this.size !== undefined
  37807. ? this.size === Infinity || index < this.size
  37808. : this.indexOf(index) !== -1)
  37809. );
  37810. },
  37811. interpose: function interpose(separator) {
  37812. return reify(this, interposeFactory(this, separator));
  37813. },
  37814. interleave: function interleave(/*...collections*/) {
  37815. var collections = [this].concat(arrCopy(arguments));
  37816. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, collections);
  37817. var interleaved = zipped.flatten(true);
  37818. if (zipped.size) {
  37819. interleaved.size = zipped.size * collections.length;
  37820. }
  37821. return reify(this, interleaved);
  37822. },
  37823. keySeq: function keySeq() {
  37824. return Range(0, this.size);
  37825. },
  37826. last: function last(notSetValue) {
  37827. return this.get(-1, notSetValue);
  37828. },
  37829. skipWhile: function skipWhile(predicate, context) {
  37830. return reify(this, skipWhileFactory(this, predicate, context, false));
  37831. },
  37832. zip: function zip(/*, ...collections */) {
  37833. var collections = [this].concat(arrCopy(arguments));
  37834. return reify(this, zipWithFactory(this, defaultZipper, collections));
  37835. },
  37836. zipAll: function zipAll(/*, ...collections */) {
  37837. var collections = [this].concat(arrCopy(arguments));
  37838. return reify(this, zipWithFactory(this, defaultZipper, collections, true));
  37839. },
  37840. zipWith: function zipWith(zipper /*, ...collections */) {
  37841. var collections = arrCopy(arguments);
  37842. collections[0] = this;
  37843. return reify(this, zipWithFactory(this, zipper, collections));
  37844. },
  37845. });
  37846. var IndexedCollectionPrototype = IndexedCollection.prototype;
  37847. IndexedCollectionPrototype[IS_INDEXED_SYMBOL] = true;
  37848. IndexedCollectionPrototype[IS_ORDERED_SYMBOL] = true;
  37849. mixin(SetCollection, {
  37850. // ### ES6 Collection methods (ES6 Array and Map)
  37851. get: function get(value, notSetValue) {
  37852. return this.has(value) ? value : notSetValue;
  37853. },
  37854. includes: function includes(value) {
  37855. return this.has(value);
  37856. },
  37857. // ### More sequential methods
  37858. keySeq: function keySeq() {
  37859. return this.valueSeq();
  37860. },
  37861. });
  37862. SetCollection.prototype.has = CollectionPrototype.includes;
  37863. SetCollection.prototype.contains = SetCollection.prototype.includes;
  37864. // Mixin subclasses
  37865. mixin(KeyedSeq, KeyedCollection.prototype);
  37866. mixin(IndexedSeq, IndexedCollection.prototype);
  37867. mixin(SetSeq, SetCollection.prototype);
  37868. // #pragma Helper functions
  37869. function reduce(collection, reducer, reduction, context, useFirst, reverse) {
  37870. assertNotInfinite(collection.size);
  37871. collection.__iterate(function (v, k, c) {
  37872. if (useFirst) {
  37873. useFirst = false;
  37874. reduction = v;
  37875. } else {
  37876. reduction = reducer.call(context, reduction, v, k, c);
  37877. }
  37878. }, reverse);
  37879. return reduction;
  37880. }
  37881. function keyMapper(v, k) {
  37882. return k;
  37883. }
  37884. function entryMapper(v, k) {
  37885. return [k, v];
  37886. }
  37887. function not(predicate) {
  37888. return function() {
  37889. return !predicate.apply(this, arguments);
  37890. };
  37891. }
  37892. function neg(predicate) {
  37893. return function() {
  37894. return -predicate.apply(this, arguments);
  37895. };
  37896. }
  37897. function defaultZipper() {
  37898. return arrCopy(arguments);
  37899. }
  37900. function defaultNegComparator(a, b) {
  37901. return a < b ? 1 : a > b ? -1 : 0;
  37902. }
  37903. function hashCollection(collection) {
  37904. if (collection.size === Infinity) {
  37905. return 0;
  37906. }
  37907. var ordered = isOrdered(collection);
  37908. var keyed = isKeyed(collection);
  37909. var h = ordered ? 1 : 0;
  37910. var size = collection.__iterate(
  37911. keyed
  37912. ? ordered
  37913. ? function (v, k) {
  37914. h = (31 * h + hashMerge(hash(v), hash(k))) | 0;
  37915. }
  37916. : function (v, k) {
  37917. h = (h + hashMerge(hash(v), hash(k))) | 0;
  37918. }
  37919. : ordered
  37920. ? function (v) {
  37921. h = (31 * h + hash(v)) | 0;
  37922. }
  37923. : function (v) {
  37924. h = (h + hash(v)) | 0;
  37925. }
  37926. );
  37927. return murmurHashOfSize(size, h);
  37928. }
  37929. function murmurHashOfSize(size, h) {
  37930. h = imul(h, 0xcc9e2d51);
  37931. h = imul((h << 15) | (h >>> -15), 0x1b873593);
  37932. h = imul((h << 13) | (h >>> -13), 5);
  37933. h = ((h + 0xe6546b64) | 0) ^ size;
  37934. h = imul(h ^ (h >>> 16), 0x85ebca6b);
  37935. h = imul(h ^ (h >>> 13), 0xc2b2ae35);
  37936. h = smi(h ^ (h >>> 16));
  37937. return h;
  37938. }
  37939. function hashMerge(a, b) {
  37940. return (a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2))) | 0; // int
  37941. }
  37942. var OrderedSet = /*@__PURE__*/(function (Set$$1) {
  37943. function OrderedSet(value) {
  37944. return value === null || value === undefined
  37945. ? emptyOrderedSet()
  37946. : isOrderedSet(value)
  37947. ? value
  37948. : emptyOrderedSet().withMutations(function (set) {
  37949. var iter = SetCollection(value);
  37950. assertNotInfinite(iter.size);
  37951. iter.forEach(function (v) { return set.add(v); });
  37952. });
  37953. }
  37954. if ( Set$$1 ) OrderedSet.__proto__ = Set$$1;
  37955. OrderedSet.prototype = Object.create( Set$$1 && Set$$1.prototype );
  37956. OrderedSet.prototype.constructor = OrderedSet;
  37957. OrderedSet.of = function of (/*...values*/) {
  37958. return this(arguments);
  37959. };
  37960. OrderedSet.fromKeys = function fromKeys (value) {
  37961. return this(KeyedCollection(value).keySeq());
  37962. };
  37963. OrderedSet.prototype.toString = function toString () {
  37964. return this.__toString('OrderedSet {', '}');
  37965. };
  37966. return OrderedSet;
  37967. }(Set));
  37968. OrderedSet.isOrderedSet = isOrderedSet;
  37969. var OrderedSetPrototype = OrderedSet.prototype;
  37970. OrderedSetPrototype[IS_ORDERED_SYMBOL] = true;
  37971. OrderedSetPrototype.zip = IndexedCollectionPrototype.zip;
  37972. OrderedSetPrototype.zipWith = IndexedCollectionPrototype.zipWith;
  37973. OrderedSetPrototype.__empty = emptyOrderedSet;
  37974. OrderedSetPrototype.__make = makeOrderedSet;
  37975. function makeOrderedSet(map, ownerID) {
  37976. var set = Object.create(OrderedSetPrototype);
  37977. set.size = map ? map.size : 0;
  37978. set._map = map;
  37979. set.__ownerID = ownerID;
  37980. return set;
  37981. }
  37982. var EMPTY_ORDERED_SET;
  37983. function emptyOrderedSet() {
  37984. return (
  37985. EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()))
  37986. );
  37987. }
  37988. var Record = function Record(defaultValues, name) {
  37989. var hasInitialized;
  37990. var RecordType = function Record(values) {
  37991. var this$1 = this;
  37992. if (values instanceof RecordType) {
  37993. return values;
  37994. }
  37995. if (!(this instanceof RecordType)) {
  37996. return new RecordType(values);
  37997. }
  37998. if (!hasInitialized) {
  37999. hasInitialized = true;
  38000. var keys = Object.keys(defaultValues);
  38001. var indices = (RecordTypePrototype._indices = {});
  38002. // Deprecated: left to attempt not to break any external code which
  38003. // relies on a ._name property existing on record instances.
  38004. // Use Record.getDescriptiveName() instead
  38005. RecordTypePrototype._name = name;
  38006. RecordTypePrototype._keys = keys;
  38007. RecordTypePrototype._defaultValues = defaultValues;
  38008. for (var i = 0; i < keys.length; i++) {
  38009. var propName = keys[i];
  38010. indices[propName] = i;
  38011. if (RecordTypePrototype[propName]) {
  38012. /* eslint-disable no-console */
  38013. typeof console === 'object' &&
  38014. console.warn &&
  38015. console.warn(
  38016. 'Cannot define ' +
  38017. recordName(this) +
  38018. ' with property "' +
  38019. propName +
  38020. '" since that property name is part of the Record API.'
  38021. );
  38022. /* eslint-enable no-console */
  38023. } else {
  38024. setProp(RecordTypePrototype, propName);
  38025. }
  38026. }
  38027. }
  38028. this.__ownerID = undefined;
  38029. this._values = List().withMutations(function (l) {
  38030. l.setSize(this$1._keys.length);
  38031. KeyedCollection(values).forEach(function (v, k) {
  38032. l.set(this$1._indices[k], v === this$1._defaultValues[k] ? undefined : v);
  38033. });
  38034. });
  38035. };
  38036. var RecordTypePrototype = (RecordType.prototype = Object.create(
  38037. RecordPrototype
  38038. ));
  38039. RecordTypePrototype.constructor = RecordType;
  38040. if (name) {
  38041. RecordType.displayName = name;
  38042. }
  38043. return RecordType;
  38044. };
  38045. Record.prototype.toString = function toString () {
  38046. var str = recordName(this) + ' { ';
  38047. var keys = this._keys;
  38048. var k;
  38049. for (var i = 0, l = keys.length; i !== l; i++) {
  38050. k = keys[i];
  38051. str += (i ? ', ' : '') + k + ': ' + quoteString(this.get(k));
  38052. }
  38053. return str + ' }';
  38054. };
  38055. Record.prototype.equals = function equals (other) {
  38056. return (
  38057. this === other ||
  38058. (other &&
  38059. this._keys === other._keys &&
  38060. recordSeq(this).equals(recordSeq(other)))
  38061. );
  38062. };
  38063. Record.prototype.hashCode = function hashCode () {
  38064. return recordSeq(this).hashCode();
  38065. };
  38066. // @pragma Access
  38067. Record.prototype.has = function has (k) {
  38068. return this._indices.hasOwnProperty(k);
  38069. };
  38070. Record.prototype.get = function get (k, notSetValue) {
  38071. if (!this.has(k)) {
  38072. return notSetValue;
  38073. }
  38074. var index = this._indices[k];
  38075. var value = this._values.get(index);
  38076. return value === undefined ? this._defaultValues[k] : value;
  38077. };
  38078. // @pragma Modification
  38079. Record.prototype.set = function set (k, v) {
  38080. if (this.has(k)) {
  38081. var newValues = this._values.set(
  38082. this._indices[k],
  38083. v === this._defaultValues[k] ? undefined : v
  38084. );
  38085. if (newValues !== this._values && !this.__ownerID) {
  38086. return makeRecord(this, newValues);
  38087. }
  38088. }
  38089. return this;
  38090. };
  38091. Record.prototype.remove = function remove (k) {
  38092. return this.set(k);
  38093. };
  38094. Record.prototype.clear = function clear () {
  38095. var newValues = this._values.clear().setSize(this._keys.length);
  38096. return this.__ownerID ? this : makeRecord(this, newValues);
  38097. };
  38098. Record.prototype.wasAltered = function wasAltered () {
  38099. return this._values.wasAltered();
  38100. };
  38101. Record.prototype.toSeq = function toSeq () {
  38102. return recordSeq(this);
  38103. };
  38104. Record.prototype.toJS = function toJS$1 () {
  38105. return toJS(this);
  38106. };
  38107. Record.prototype.entries = function entries () {
  38108. return this.__iterator(ITERATE_ENTRIES);
  38109. };
  38110. Record.prototype.__iterator = function __iterator (type, reverse) {
  38111. return recordSeq(this).__iterator(type, reverse);
  38112. };
  38113. Record.prototype.__iterate = function __iterate (fn, reverse) {
  38114. return recordSeq(this).__iterate(fn, reverse);
  38115. };
  38116. Record.prototype.__ensureOwner = function __ensureOwner (ownerID) {
  38117. if (ownerID === this.__ownerID) {
  38118. return this;
  38119. }
  38120. var newValues = this._values.__ensureOwner(ownerID);
  38121. if (!ownerID) {
  38122. this.__ownerID = ownerID;
  38123. this._values = newValues;
  38124. return this;
  38125. }
  38126. return makeRecord(this, newValues, ownerID);
  38127. };
  38128. Record.isRecord = isRecord;
  38129. Record.getDescriptiveName = recordName;
  38130. var RecordPrototype = Record.prototype;
  38131. RecordPrototype[IS_RECORD_SYMBOL] = true;
  38132. RecordPrototype[DELETE] = RecordPrototype.remove;
  38133. RecordPrototype.deleteIn = RecordPrototype.removeIn = deleteIn;
  38134. RecordPrototype.getIn = getIn$1;
  38135. RecordPrototype.hasIn = CollectionPrototype.hasIn;
  38136. RecordPrototype.merge = merge;
  38137. RecordPrototype.mergeWith = mergeWith;
  38138. RecordPrototype.mergeIn = mergeIn;
  38139. RecordPrototype.mergeDeep = mergeDeep$1;
  38140. RecordPrototype.mergeDeepWith = mergeDeepWith$1;
  38141. RecordPrototype.mergeDeepIn = mergeDeepIn;
  38142. RecordPrototype.setIn = setIn$1;
  38143. RecordPrototype.update = update$1;
  38144. RecordPrototype.updateIn = updateIn$1;
  38145. RecordPrototype.withMutations = withMutations;
  38146. RecordPrototype.asMutable = asMutable;
  38147. RecordPrototype.asImmutable = asImmutable;
  38148. RecordPrototype[ITERATOR_SYMBOL] = RecordPrototype.entries;
  38149. RecordPrototype.toJSON = RecordPrototype.toObject =
  38150. CollectionPrototype.toObject;
  38151. RecordPrototype.inspect = RecordPrototype.toSource = function() {
  38152. return this.toString();
  38153. };
  38154. function makeRecord(likeRecord, values, ownerID) {
  38155. var record = Object.create(Object.getPrototypeOf(likeRecord));
  38156. record._values = values;
  38157. record.__ownerID = ownerID;
  38158. return record;
  38159. }
  38160. function recordName(record) {
  38161. return record.constructor.displayName || record.constructor.name || 'Record';
  38162. }
  38163. function recordSeq(record) {
  38164. return keyedSeqFromValue(record._keys.map(function (k) { return [k, record.get(k)]; }));
  38165. }
  38166. function setProp(prototype, name) {
  38167. try {
  38168. Object.defineProperty(prototype, name, {
  38169. get: function() {
  38170. return this.get(name);
  38171. },
  38172. set: function(value) {
  38173. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  38174. this.set(name, value);
  38175. },
  38176. });
  38177. } catch (error) {
  38178. // Object.defineProperty failed. Probably IE8.
  38179. }
  38180. }
  38181. /**
  38182. * Returns a lazy Seq of `value` repeated `times` times. When `times` is
  38183. * undefined, returns an infinite sequence of `value`.
  38184. */
  38185. var Repeat = /*@__PURE__*/(function (IndexedSeq$$1) {
  38186. function Repeat(value, times) {
  38187. if (!(this instanceof Repeat)) {
  38188. return new Repeat(value, times);
  38189. }
  38190. this._value = value;
  38191. this.size = times === undefined ? Infinity : Math.max(0, times);
  38192. if (this.size === 0) {
  38193. if (EMPTY_REPEAT) {
  38194. return EMPTY_REPEAT;
  38195. }
  38196. EMPTY_REPEAT = this;
  38197. }
  38198. }
  38199. if ( IndexedSeq$$1 ) Repeat.__proto__ = IndexedSeq$$1;
  38200. Repeat.prototype = Object.create( IndexedSeq$$1 && IndexedSeq$$1.prototype );
  38201. Repeat.prototype.constructor = Repeat;
  38202. Repeat.prototype.toString = function toString () {
  38203. if (this.size === 0) {
  38204. return 'Repeat []';
  38205. }
  38206. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  38207. };
  38208. Repeat.prototype.get = function get (index, notSetValue) {
  38209. return this.has(index) ? this._value : notSetValue;
  38210. };
  38211. Repeat.prototype.includes = function includes (searchValue) {
  38212. return is(this._value, searchValue);
  38213. };
  38214. Repeat.prototype.slice = function slice (begin, end) {
  38215. var size = this.size;
  38216. return wholeSlice(begin, end, size)
  38217. ? this
  38218. : new Repeat(
  38219. this._value,
  38220. resolveEnd(end, size) - resolveBegin(begin, size)
  38221. );
  38222. };
  38223. Repeat.prototype.reverse = function reverse () {
  38224. return this;
  38225. };
  38226. Repeat.prototype.indexOf = function indexOf (searchValue) {
  38227. if (is(this._value, searchValue)) {
  38228. return 0;
  38229. }
  38230. return -1;
  38231. };
  38232. Repeat.prototype.lastIndexOf = function lastIndexOf (searchValue) {
  38233. if (is(this._value, searchValue)) {
  38234. return this.size;
  38235. }
  38236. return -1;
  38237. };
  38238. Repeat.prototype.__iterate = function __iterate (fn, reverse) {
  38239. var size = this.size;
  38240. var i = 0;
  38241. while (i !== size) {
  38242. if (fn(this._value, reverse ? size - ++i : i++, this) === false) {
  38243. break;
  38244. }
  38245. }
  38246. return i;
  38247. };
  38248. Repeat.prototype.__iterator = function __iterator (type, reverse) {
  38249. var this$1 = this;
  38250. var size = this.size;
  38251. var i = 0;
  38252. return new Iterator(
  38253. function () { return i === size
  38254. ? iteratorDone()
  38255. : iteratorValue(type, reverse ? size - ++i : i++, this$1._value); }
  38256. );
  38257. };
  38258. Repeat.prototype.equals = function equals (other) {
  38259. return other instanceof Repeat
  38260. ? is(this._value, other._value)
  38261. : deepEqual(other);
  38262. };
  38263. return Repeat;
  38264. }(IndexedSeq));
  38265. var EMPTY_REPEAT;
  38266. function fromJS(value, converter) {
  38267. return fromJSWith(
  38268. [],
  38269. converter || defaultConverter,
  38270. value,
  38271. '',
  38272. converter && converter.length > 2 ? [] : undefined,
  38273. { '': value }
  38274. );
  38275. }
  38276. function fromJSWith(stack, converter, value, key, keyPath, parentValue) {
  38277. var toSeq = Array.isArray(value)
  38278. ? IndexedSeq
  38279. : isPlainObj(value)
  38280. ? KeyedSeq
  38281. : null;
  38282. if (toSeq) {
  38283. if (~stack.indexOf(value)) {
  38284. throw new TypeError('Cannot convert circular structure to Immutable');
  38285. }
  38286. stack.push(value);
  38287. keyPath && key !== '' && keyPath.push(key);
  38288. var converted = converter.call(
  38289. parentValue,
  38290. key,
  38291. toSeq(value).map(function (v, k) { return fromJSWith(stack, converter, v, k, keyPath, value); }
  38292. ),
  38293. keyPath && keyPath.slice()
  38294. );
  38295. stack.pop();
  38296. keyPath && keyPath.pop();
  38297. return converted;
  38298. }
  38299. return value;
  38300. }
  38301. function defaultConverter(k, v) {
  38302. return isKeyed(v) ? v.toMap() : v.toList();
  38303. }
  38304. var version = "4.0.0-rc.11";
  38305. var Immutable = {
  38306. version: version,
  38307. Collection: Collection,
  38308. // Note: Iterable is deprecated
  38309. Iterable: Collection,
  38310. Seq: Seq,
  38311. Map: Map,
  38312. OrderedMap: OrderedMap,
  38313. List: List,
  38314. Stack: Stack,
  38315. Set: Set,
  38316. OrderedSet: OrderedSet,
  38317. Record: Record,
  38318. Range: Range,
  38319. Repeat: Repeat,
  38320. is: is,
  38321. fromJS: fromJS,
  38322. hash: hash,
  38323. isImmutable: isImmutable,
  38324. isCollection: isCollection,
  38325. isKeyed: isKeyed,
  38326. isIndexed: isIndexed,
  38327. isAssociative: isAssociative,
  38328. isOrdered: isOrdered,
  38329. isValueObject: isValueObject,
  38330. isSeq: isSeq,
  38331. isList: isList,
  38332. isMap: isMap,
  38333. isOrderedMap: isOrderedMap,
  38334. isStack: isStack,
  38335. isSet: isSet,
  38336. isOrderedSet: isOrderedSet,
  38337. isRecord: isRecord,
  38338. get: get,
  38339. getIn: getIn,
  38340. has: has,
  38341. hasIn: hasIn,
  38342. merge: merge$1,
  38343. mergeDeep: mergeDeep,
  38344. mergeWith: mergeWith$1,
  38345. mergeDeepWith: mergeDeepWith,
  38346. remove: remove,
  38347. removeIn: removeIn,
  38348. set: set,
  38349. setIn: setIn,
  38350. update: update,
  38351. updateIn: updateIn,
  38352. };
  38353. // Note: Iterable is deprecated
  38354. var Iterable = Collection;
  38355. exports.default = Immutable;
  38356. exports.version = version;
  38357. exports.Collection = Collection;
  38358. exports.Iterable = Iterable;
  38359. exports.Seq = Seq;
  38360. exports.Map = Map;
  38361. exports.OrderedMap = OrderedMap;
  38362. exports.List = List;
  38363. exports.Stack = Stack;
  38364. exports.Set = Set;
  38365. exports.OrderedSet = OrderedSet;
  38366. exports.Record = Record;
  38367. exports.Range = Range;
  38368. exports.Repeat = Repeat;
  38369. exports.is = is;
  38370. exports.fromJS = fromJS;
  38371. exports.hash = hash;
  38372. exports.isImmutable = isImmutable;
  38373. exports.isCollection = isCollection;
  38374. exports.isKeyed = isKeyed;
  38375. exports.isIndexed = isIndexed;
  38376. exports.isAssociative = isAssociative;
  38377. exports.isOrdered = isOrdered;
  38378. exports.isValueObject = isValueObject;
  38379. exports.get = get;
  38380. exports.getIn = getIn;
  38381. exports.has = has;
  38382. exports.hasIn = hasIn;
  38383. exports.merge = merge$1;
  38384. exports.mergeDeep = mergeDeep;
  38385. exports.mergeWith = mergeWith$1;
  38386. exports.mergeDeepWith = mergeDeepWith;
  38387. exports.remove = remove;
  38388. exports.removeIn = removeIn;
  38389. exports.set = set;
  38390. exports.setIn = setIn;
  38391. exports.update = update;
  38392. exports.updateIn = updateIn;
  38393. Object.defineProperty(exports, '__esModule', { value: true });
  38394. })));
  38395. });
  38396. styleInject_es.unwrapExports(immutable$3);
  38397. var draftjsUtils$1 = styleInject_es.createCommonjsModule(function (module, exports) {
  38398. !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;});
  38399. });
  38400. styleInject_es.unwrapExports(draftjsUtils$1);
  38401. var draftjsUtils_1$1 = draftjsUtils$1.draftjsUtils;
  38402. var content$1 = styleInject_es.createCommonjsModule(function (module, exports) {
  38403. Object.defineProperty(exports, "__esModule", {
  38404. value: true
  38405. });
  38406. 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;
  38407. var _immutable2 = _interopRequireDefault(immutable$3);
  38408. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  38409. var strictBlockTypes = ['atomic'];
  38410. var registerStrictBlockType = exports.registerStrictBlockType = function registerStrictBlockType(blockType) {
  38411. strictBlockTypes.indexOf(blockType) === -1 && strictBlockTypes.push(blockType);
  38412. };
  38413. var isEditorState = exports.isEditorState = function isEditorState(editorState) {
  38414. return editorState instanceof Draft.EditorState;
  38415. };
  38416. var createEmptyEditorState = exports.createEmptyEditorState = function createEmptyEditorState(editorDecorators) {
  38417. return Draft.EditorState.createEmpty(editorDecorators);
  38418. };
  38419. var createEditorState = exports.createEditorState = function createEditorState(contentState, editorDecorators) {
  38420. return Draft.EditorState.createWithContent(contentState, editorDecorators);
  38421. };
  38422. var isSelectionCollapsed = exports.isSelectionCollapsed = function isSelectionCollapsed(editorState) {
  38423. return editorState.getSelection().isCollapsed();
  38424. };
  38425. var selectionContainsBlockType = exports.selectionContainsBlockType = function selectionContainsBlockType(editorState, blockType) {
  38426. return getSelectedBlocks(editorState).find(function (block) {
  38427. return block.getType() === blockType;
  38428. });
  38429. };
  38430. var selectionContainsStrictBlock = exports.selectionContainsStrictBlock = function selectionContainsStrictBlock(editorState) {
  38431. return getSelectedBlocks(editorState).find(function (block) {
  38432. return ~strictBlockTypes.indexOf(block.getType());
  38433. });
  38434. };
  38435. var selectBlock = exports.selectBlock = function selectBlock(editorState, block) {
  38436. var blockKey = block.getKey();
  38437. return Draft.EditorState.forceSelection(editorState, new Draft.SelectionState({
  38438. anchorKey: blockKey,
  38439. anchorOffset: 0,
  38440. focusKey: blockKey,
  38441. focusOffset: block.getLength()
  38442. }));
  38443. };
  38444. var selectNextBlock = exports.selectNextBlock = function selectNextBlock(editorState, block) {
  38445. var nextBlock = editorState.getCurrentContent().getBlockAfter(block.getKey());
  38446. return nextBlock ? selectBlock(editorState, nextBlock) : editorState;
  38447. };
  38448. var removeBlock = exports.removeBlock = function removeBlock(editorState, block) {
  38449. var lastSelection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  38450. var nextContentState = void 0,
  38451. nextEditorState = void 0;
  38452. var blockKey = block.getKey();
  38453. nextContentState = Draft.Modifier.removeRange(editorState.getCurrentContent(), new Draft.SelectionState({
  38454. anchorKey: blockKey,
  38455. anchorOffset: 0,
  38456. focusKey: blockKey,
  38457. focusOffset: block.getLength()
  38458. }), 'backward');
  38459. nextContentState = Draft.Modifier.setBlockType(nextContentState, nextContentState.getSelectionAfter(), 'unstyled');
  38460. nextEditorState = Draft.EditorState.push(editorState, nextContentState, 'remove-range');
  38461. return Draft.EditorState.forceSelection(nextEditorState, lastSelection || nextContentState.getSelectionAfter());
  38462. };
  38463. var getSelectionBlock = exports.getSelectionBlock = function getSelectionBlock(editorState) {
  38464. return editorState.getCurrentContent().getBlockForKey(editorState.getSelection().getAnchorKey());
  38465. };
  38466. var updateEachCharacterOfSelection = exports.updateEachCharacterOfSelection = function updateEachCharacterOfSelection(editorState, callback) {
  38467. var selectionState = editorState.getSelection();
  38468. var contentState = editorState.getCurrentContent();
  38469. var contentBlocks = contentState.getBlockMap();
  38470. var selectedBlocks = getSelectedBlocks(editorState);
  38471. if (selectedBlocks.length === 0) {
  38472. return editorState;
  38473. }
  38474. var startKey = selectionState.getStartKey();
  38475. var startOffset = selectionState.getStartOffset();
  38476. var endKey = selectionState.getEndKey();
  38477. var endOffset = selectionState.getEndOffset();
  38478. var nextContentBlocks = contentBlocks.map(function (block) {
  38479. if (selectedBlocks.indexOf(block) === -1) {
  38480. return block;
  38481. }
  38482. var blockKey = block.getKey();
  38483. var charactersList = block.getCharacterList();
  38484. var nextCharactersList = null;
  38485. if (blockKey === startKey && blockKey === endKey) {
  38486. nextCharactersList = charactersList.map(function (character, index) {
  38487. if (index >= startOffset && index < endOffset) {
  38488. return callback(character);
  38489. }
  38490. return character;
  38491. });
  38492. } else if (blockKey === startKey) {
  38493. nextCharactersList = charactersList.map(function (character, index) {
  38494. if (index >= startOffset) {
  38495. return callback(character);
  38496. }
  38497. return character;
  38498. });
  38499. } else if (blockKey === endKey) {
  38500. nextCharactersList = charactersList.map(function (character, index) {
  38501. if (index < endOffset) {
  38502. return callback(character);
  38503. }
  38504. return character;
  38505. });
  38506. } else {
  38507. nextCharactersList = charactersList.map(function (character) {
  38508. return callback(character);
  38509. });
  38510. }
  38511. return block.merge({
  38512. 'characterList': nextCharactersList
  38513. });
  38514. });
  38515. return Draft.EditorState.push(editorState, contentState.merge({
  38516. blockMap: nextContentBlocks,
  38517. selectionBefore: selectionState,
  38518. selectionAfter: selectionState
  38519. }), 'update-selection-character-list');
  38520. };
  38521. var getSelectedBlocks = exports.getSelectedBlocks = function getSelectedBlocks(editorState) {
  38522. var selectionState = editorState.getSelection();
  38523. var contentState = editorState.getCurrentContent();
  38524. var startKey = selectionState.getStartKey();
  38525. var endKey = selectionState.getEndKey();
  38526. var isSameBlock = startKey === endKey;
  38527. var startingBlock = contentState.getBlockForKey(startKey);
  38528. var selectedBlocks = [startingBlock];
  38529. if (!isSameBlock) {
  38530. var blockKey = startKey;
  38531. while (blockKey !== endKey) {
  38532. var nextBlock = contentState.getBlockAfter(blockKey);
  38533. selectedBlocks.push(nextBlock);
  38534. blockKey = nextBlock.getKey();
  38535. }
  38536. }
  38537. return selectedBlocks;
  38538. };
  38539. var setSelectionBlockData = exports.setSelectionBlockData = function setSelectionBlockData(editorState, blockData, override) {
  38540. var newBlockData = override ? blockData : Object.assign({}, getSelectionBlockData(editorState).toJS(), blockData);
  38541. Object.keys(newBlockData).forEach(function (key) {
  38542. if (newBlockData.hasOwnProperty(key) && newBlockData[key] === undefined) {
  38543. delete newBlockData[key];
  38544. }
  38545. });
  38546. return (0, draftjsUtils$1.setBlockData)(editorState, newBlockData);
  38547. };
  38548. var getSelectionBlockData = exports.getSelectionBlockData = function getSelectionBlockData(editorState, name) {
  38549. var blockData = getSelectionBlock(editorState).getData();
  38550. return name ? blockData.get(name) : blockData;
  38551. };
  38552. var getSelectionBlockType = exports.getSelectionBlockType = function getSelectionBlockType(editorState) {
  38553. return getSelectionBlock(editorState).getType();
  38554. };
  38555. var getSelectionText = exports.getSelectionText = function getSelectionText(editorState) {
  38556. var selectionState = editorState.getSelection();
  38557. var contentState = editorState.getCurrentContent();
  38558. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  38559. return '';
  38560. }
  38561. var anchorKey = selectionState.getAnchorKey();
  38562. var currentContentBlock = contentState.getBlockForKey(anchorKey);
  38563. var start = selectionState.getStartOffset();
  38564. var end = selectionState.getEndOffset();
  38565. return currentContentBlock.getText().slice(start, end);
  38566. };
  38567. var toggleSelectionBlockType = exports.toggleSelectionBlockType = function toggleSelectionBlockType(editorState, blockType) {
  38568. if (selectionContainsStrictBlock(editorState)) {
  38569. return editorState;
  38570. }
  38571. return Draft.RichUtils.toggleBlockType(editorState, blockType);
  38572. };
  38573. var getSelectionEntityType = exports.getSelectionEntityType = function getSelectionEntityType(editorState) {
  38574. var entityKey = (0, draftjsUtils$1.getSelectionEntity)(editorState);
  38575. if (entityKey) {
  38576. var entity = editorState.getCurrentContent().getEntity(entityKey);
  38577. return entity ? entity.get('type') : null;
  38578. }
  38579. return null;
  38580. };
  38581. var getSelectionEntityData = exports.getSelectionEntityData = function getSelectionEntityData(editorState, type) {
  38582. var entityKey = (0, draftjsUtils$1.getSelectionEntity)(editorState);
  38583. if (entityKey) {
  38584. var entity = editorState.getCurrentContent().getEntity(entityKey);
  38585. if (entity && entity.get('type') === type) {
  38586. return entity.getData();
  38587. } else {
  38588. return {};
  38589. }
  38590. } else {
  38591. return {};
  38592. }
  38593. };
  38594. var toggleSelectionEntity = exports.toggleSelectionEntity = function toggleSelectionEntity(editorState, entity) {
  38595. var contentState = editorState.getCurrentContent();
  38596. var selectionState = editorState.getSelection();
  38597. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  38598. return editorState;
  38599. }
  38600. if (!entity || !entity.type || getSelectionEntityType(editorState) === entity.type) {
  38601. return Draft.EditorState.push(editorState, Draft.Modifier.applyEntity(contentState, selectionState, null), 'apply-entity');
  38602. }
  38603. try {
  38604. var nextContentState = contentState.createEntity(entity.type, entity.mutability, entity.data);
  38605. var entityKey = nextContentState.getLastCreatedEntityKey();
  38606. var nextEditorState = Draft.EditorState.set(editorState, {
  38607. currentContent: nextContentState
  38608. });
  38609. return Draft.EditorState.push(nextEditorState, Draft.Modifier.applyEntity(nextContentState, selectionState, entityKey), 'apply-entity');
  38610. } catch (error) {
  38611. console.warn(error);
  38612. return editorState;
  38613. }
  38614. };
  38615. var toggleSelectionLink = exports.toggleSelectionLink = function toggleSelectionLink(editorState, href, target) {
  38616. var contentState = editorState.getCurrentContent();
  38617. var selectionState = editorState.getSelection();
  38618. var entityData = { href: href, target: target };
  38619. if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  38620. return editorState;
  38621. }
  38622. if (href === false) {
  38623. return Draft.RichUtils.toggleLink(editorState, selectionState, null);
  38624. }
  38625. if (href === null) {
  38626. delete entityData.href;
  38627. }
  38628. try {
  38629. var nextContentState = contentState.createEntity('LINK', 'MUTABLE', entityData);
  38630. var entityKey = nextContentState.getLastCreatedEntityKey();
  38631. var nextEditorState = Draft.EditorState.set(editorState, {
  38632. currentContent: nextContentState
  38633. });
  38634. nextEditorState = Draft.RichUtils.toggleLink(nextEditorState, selectionState, entityKey);
  38635. nextEditorState = Draft.EditorState.forceSelection(nextEditorState, selectionState.merge({
  38636. anchorOffset: selectionState.getEndOffset(),
  38637. focusOffset: selectionState.getEndOffset()
  38638. }));
  38639. nextEditorState = Draft.EditorState.push(nextEditorState, Draft.Modifier.insertText(nextEditorState.getCurrentContent(), nextEditorState.getSelection(), ''), 'insert-text');
  38640. return nextEditorState;
  38641. } catch (error) {
  38642. console.warn(error);
  38643. return editorState;
  38644. }
  38645. };
  38646. var getSelectionInlineStyle = exports.getSelectionInlineStyle = function getSelectionInlineStyle(editorState) {
  38647. return editorState.getCurrentInlineStyle();
  38648. };
  38649. var selectionHasInlineStyle = exports.selectionHasInlineStyle = function selectionHasInlineStyle(editorState, style) {
  38650. return getSelectionInlineStyle(editorState).has(style.toUpperCase());
  38651. };
  38652. var toggleSelectionInlineStyle = exports.toggleSelectionInlineStyle = function toggleSelectionInlineStyle(editorState, style) {
  38653. var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
  38654. var nextEditorState = editorState;
  38655. style = prefix + style.toUpperCase();
  38656. if (prefix) {
  38657. nextEditorState = updateEachCharacterOfSelection(nextEditorState, function (characterMetadata) {
  38658. return characterMetadata.toJS().style.reduce(function (characterMetadata, characterStyle) {
  38659. if (characterStyle.indexOf(prefix) === 0 && style !== characterStyle) {
  38660. return Draft.CharacterMetadata.removeStyle(characterMetadata, characterStyle);
  38661. } else {
  38662. return characterMetadata;
  38663. }
  38664. }, characterMetadata);
  38665. });
  38666. }
  38667. return Draft.RichUtils.toggleInlineStyle(nextEditorState, style);
  38668. };
  38669. var removeSelectionInlineStyles = exports.removeSelectionInlineStyles = function removeSelectionInlineStyles(editorState) {
  38670. return updateEachCharacterOfSelection(editorState, function (characterMetadata) {
  38671. return characterMetadata.merge({
  38672. style: _immutable2.default.OrderedSet([])
  38673. });
  38674. });
  38675. };
  38676. var toggleSelectionAlignment = exports.toggleSelectionAlignment = function toggleSelectionAlignment(editorState, alignment) {
  38677. return setSelectionBlockData(editorState, {
  38678. textAlign: getSelectionBlockData(editorState, 'textAlign') !== alignment ? alignment : undefined
  38679. });
  38680. };
  38681. var toggleSelectionIndent = exports.toggleSelectionIndent = function toggleSelectionIndent(editorState, textIndent) {
  38682. var maxIndent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 6;
  38683. return textIndent < 0 || textIndent > maxIndent || isNaN(textIndent) ? editorState : setSelectionBlockData(editorState, {
  38684. textIndent: textIndent || undefined
  38685. });
  38686. };
  38687. var increaseSelectionIndent = exports.increaseSelectionIndent = function increaseSelectionIndent(editorState) {
  38688. var maxIndent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 6;
  38689. var currentIndent = getSelectionBlockData(editorState, 'textIndent') || 0;
  38690. return toggleSelectionIndent(editorState, currentIndent + 1, maxIndent);
  38691. };
  38692. var decreaseSelectionIndent = exports.decreaseSelectionIndent = function decreaseSelectionIndent(editorState) {
  38693. var currentIndent = getSelectionBlockData(editorState, 'textIndent') || 0;
  38694. return toggleSelectionIndent(editorState, currentIndent - 1);
  38695. };
  38696. var toggleSelectionColor = exports.toggleSelectionColor = function toggleSelectionColor(editorState, color) {
  38697. return toggleSelectionInlineStyle(editorState, color.replace('#', ''), 'COLOR-');
  38698. };
  38699. var toggleSelectionBackgroundColor = exports.toggleSelectionBackgroundColor = function toggleSelectionBackgroundColor(editorState, color) {
  38700. return toggleSelectionInlineStyle(editorState, color.replace('#', ''), 'BGCOLOR-');
  38701. };
  38702. var toggleSelectionFontSize = exports.toggleSelectionFontSize = function toggleSelectionFontSize(editorState, fontSize) {
  38703. return toggleSelectionInlineStyle(editorState, fontSize, 'FONTSIZE-');
  38704. };
  38705. var toggleSelectionLineHeight = exports.toggleSelectionLineHeight = function toggleSelectionLineHeight(editorState, lineHeight) {
  38706. return toggleSelectionInlineStyle(editorState, lineHeight, 'LINEHEIGHT-');
  38707. };
  38708. var toggleSelectionFontFamily = exports.toggleSelectionFontFamily = function toggleSelectionFontFamily(editorState, fontFamily) {
  38709. return toggleSelectionInlineStyle(editorState, fontFamily, 'FONTFAMILY-');
  38710. };
  38711. var toggleSelectionLetterSpacing = exports.toggleSelectionLetterSpacing = function toggleSelectionLetterSpacing(editorState, letterSpacing) {
  38712. return toggleSelectionInlineStyle(editorState, letterSpacing, 'LETTERSPACING-');
  38713. };
  38714. var insertText = exports.insertText = function insertText(editorState, text, inlineStyle, entity) {
  38715. var selectionState = editorState.getSelection();
  38716. var currentSelectedBlockType = getSelectionBlockType(editorState);
  38717. if (currentSelectedBlockType === 'atomic') {
  38718. return editorState;
  38719. }
  38720. var entityKey = void 0;
  38721. var contentState = editorState.getCurrentContent();
  38722. if (entity && entity.type) {
  38723. contentState = contentState.createEntity(entity.type, entity.mutability || 'MUTABLE', entity.data || entityData);
  38724. entityKey = contentState.getLastCreatedEntityKey();
  38725. }
  38726. if (!selectionState.isCollapsed()) {
  38727. return Draft.EditorState.push(editorState, Draft.Modifier.replaceText(contentState, selectionState, text, inlineStyle, entityKey), 'replace-text');
  38728. } else {
  38729. return Draft.EditorState.push(editorState, Draft.Modifier.insertText(contentState, selectionState, text, inlineStyle, entityKey), 'insert-text');
  38730. }
  38731. };
  38732. var insertHTML = exports.insertHTML = function insertHTML(editorState, htmlString, source) {
  38733. if (!htmlString) {
  38734. return editorState;
  38735. }
  38736. var selectionState = editorState.getSelection();
  38737. var contentState = editorState.getCurrentContent();
  38738. var options = editorState.convertOptions || {};
  38739. try {
  38740. var _convertFromRaw = (0, Draft.convertFromRaw)((0, dist.convertHTMLToRaw)(htmlString, options, source)),
  38741. blockMap = _convertFromRaw.blockMap;
  38742. return Draft.EditorState.push(editorState, Draft.Modifier.replaceWithFragment(contentState, selectionState, blockMap), 'insert-fragment');
  38743. } catch (error) {
  38744. console.warn(error);
  38745. return editorState;
  38746. }
  38747. };
  38748. var insertAtomicBlock = exports.insertAtomicBlock = function insertAtomicBlock(editorState, type) {
  38749. var immutable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  38750. var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  38751. if (selectionContainsStrictBlock(editorState)) {
  38752. return insertAtomicBlock(selectNextBlock(editorState, getSelectionBlock(editorState)), type, immutable, data);
  38753. }
  38754. var selectionState = editorState.getSelection();
  38755. var contentState = editorState.getCurrentContent();
  38756. if (!selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
  38757. return editorState;
  38758. }
  38759. var contentStateWithEntity = contentState.createEntity(type, immutable ? 'IMMUTABLE' : 'MUTABLE', data);
  38760. var entityKey = contentStateWithEntity.getLastCreatedEntityKey();
  38761. var newEditorState = Draft.AtomicBlockUtils.insertAtomicBlock(editorState, entityKey, ' ');
  38762. return newEditorState;
  38763. };
  38764. var insertHorizontalLine = exports.insertHorizontalLine = function insertHorizontalLine(editorState) {
  38765. return insertAtomicBlock(editorState, 'HR');
  38766. };
  38767. var insertMedias = exports.insertMedias = function insertMedias(editorState) {
  38768. var medias = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  38769. if (!medias.length) {
  38770. return editorState;
  38771. }
  38772. return medias.reduce(function (editorState, media) {
  38773. var url = media.url,
  38774. link = media.link,
  38775. link_target = media.link_target,
  38776. name = media.name,
  38777. type = media.type,
  38778. width = media.width,
  38779. height = media.height,
  38780. meta = media.meta;
  38781. return insertAtomicBlock(editorState, type, true, { url: url, link: link, link_target: link_target, name: name, type: type, width: width, height: height, meta: meta });
  38782. }, editorState);
  38783. };
  38784. var setMediaData = exports.setMediaData = function setMediaData(editorState, entityKey, data) {
  38785. return Draft.EditorState.push(editorState, editorState.getCurrentContent().mergeEntityData(entityKey, data), 'change-block-data');
  38786. };
  38787. var removeMedia = exports.removeMedia = function removeMedia(editorState, mediaBlock) {
  38788. return removeBlock(editorState, mediaBlock);
  38789. };
  38790. var setMediaPosition = exports.setMediaPosition = function setMediaPosition(editorState, mediaBlock, position) {
  38791. var newPosition = {};
  38792. var float = position.float,
  38793. alignment = position.alignment;
  38794. if (typeof float !== 'undefined') {
  38795. newPosition.float = mediaBlock.getData().get('float') === float ? null : float;
  38796. }
  38797. if (typeof alignment !== 'undefined') {
  38798. newPosition.alignment = mediaBlock.getData().get('alignment') === alignment ? null : alignment;
  38799. }
  38800. return setSelectionBlockData(selectBlock(editorState, mediaBlock), newPosition);
  38801. };
  38802. var clear = exports.clear = function clear(editorState) {
  38803. var contentState = editorState.getCurrentContent();
  38804. var firstBlock = contentState.getFirstBlock();
  38805. var lastBlock = contentState.getLastBlock();
  38806. var allSelected = new Draft.SelectionState({
  38807. anchorKey: firstBlock.getKey(),
  38808. anchorOffset: 0,
  38809. focusKey: lastBlock.getKey(),
  38810. focusOffset: lastBlock.getLength(),
  38811. hasFocus: true
  38812. });
  38813. return Draft.RichUtils.toggleBlockType(Draft.EditorState.push(editorState, Draft.Modifier.removeRange(contentState, allSelected, 'backward'), 'remove-range'), 'unstyled');
  38814. };
  38815. var handleKeyCommand = exports.handleKeyCommand = function handleKeyCommand(editorState, command) {
  38816. return Draft.RichUtils.handleKeyCommand(editorState, command);
  38817. };
  38818. var undo = exports.undo = function undo(editorState) {
  38819. return Draft.EditorState.undo(editorState);
  38820. };
  38821. var redo = exports.redo = function redo(editorState) {
  38822. return Draft.EditorState.redo(editorState);
  38823. };
  38824. });
  38825. styleInject_es.unwrapExports(content$1);
  38826. var content_1$1 = content$1.redo;
  38827. var content_2$1 = content$1.undo;
  38828. var content_3$1 = content$1.handleKeyCommand;
  38829. var content_4$1 = content$1.clear;
  38830. var content_5$1 = content$1.setMediaPosition;
  38831. var content_6$1 = content$1.removeMedia;
  38832. var content_7$1 = content$1.setMediaData;
  38833. var content_8$1 = content$1.insertMedias;
  38834. var content_9$1 = content$1.insertHorizontalLine;
  38835. var content_10$1 = content$1.insertAtomicBlock;
  38836. var content_11$1 = content$1.insertHTML;
  38837. var content_12$1 = content$1.insertText;
  38838. var content_13$1 = content$1.toggleSelectionLetterSpacing;
  38839. var content_14$1 = content$1.toggleSelectionFontFamily;
  38840. var content_15$1 = content$1.toggleSelectionLineHeight;
  38841. var content_16$1 = content$1.toggleSelectionFontSize;
  38842. var content_17$1 = content$1.toggleSelectionBackgroundColor;
  38843. var content_18$1 = content$1.toggleSelectionColor;
  38844. var content_19$1 = content$1.decreaseSelectionIndent;
  38845. var content_20$1 = content$1.increaseSelectionIndent;
  38846. var content_21$1 = content$1.toggleSelectionIndent;
  38847. var content_22$1 = content$1.toggleSelectionAlignment;
  38848. var content_23$1 = content$1.removeSelectionInlineStyles;
  38849. var content_24$1 = content$1.toggleSelectionInlineStyle;
  38850. var content_25$1 = content$1.selectionHasInlineStyle;
  38851. var content_26$1 = content$1.getSelectionInlineStyle;
  38852. var content_27$1 = content$1.toggleSelectionLink;
  38853. var content_28$1 = content$1.toggleSelectionEntity;
  38854. var content_29$1 = content$1.getSelectionEntityData;
  38855. var content_30$1 = content$1.getSelectionEntityType;
  38856. var content_31$1 = content$1.toggleSelectionBlockType;
  38857. var content_32$1 = content$1.getSelectionText;
  38858. var content_33$1 = content$1.getSelectionBlockType;
  38859. var content_34$1 = content$1.getSelectionBlockData;
  38860. var content_35$1 = content$1.setSelectionBlockData;
  38861. var content_36$1 = content$1.getSelectedBlocks;
  38862. var content_37$1 = content$1.updateEachCharacterOfSelection;
  38863. var content_38$1 = content$1.getSelectionBlock;
  38864. var content_39$1 = content$1.removeBlock;
  38865. var content_40$1 = content$1.selectNextBlock;
  38866. var content_41$1 = content$1.selectBlock;
  38867. var content_42$1 = content$1.selectionContainsStrictBlock;
  38868. var content_43$1 = content$1.selectionContainsBlockType;
  38869. var content_44$1 = content$1.isSelectionCollapsed;
  38870. var content_45$1 = content$1.createEditorState;
  38871. var content_46$1 = content$1.createEmptyEditorState;
  38872. var content_47$1 = content$1.isEditorState;
  38873. var content_48$1 = content$1.registerStrictBlockType;
  38874. var base$1 = styleInject_es.createCommonjsModule(function (module, exports) {
  38875. Object.defineProperty(exports, "__esModule", {
  38876. value: true
  38877. });
  38878. var braftUniqueIndex = 0;
  38879. var UniqueIndex = exports.UniqueIndex = function UniqueIndex() {
  38880. return braftUniqueIndex += 1;
  38881. };
  38882. });
  38883. styleInject_es.unwrapExports(base$1);
  38884. var base_1$1 = base$1.UniqueIndex;
  38885. var color$1 = styleInject_es.createCommonjsModule(function (module, exports) {
  38886. Object.defineProperty(exports, "__esModule", {
  38887. value: true
  38888. });
  38889. var _namedColors = {
  38890. "aliceblue": "#f0f8ff",
  38891. "antiquewhite": "#faebd7",
  38892. "aqua": "#00ffff",
  38893. "aquamarine": "#7fffd4",
  38894. "azure": "#f0ffff",
  38895. "beige": "#f5f5dc",
  38896. "bisque": "#ffe4c4",
  38897. "black": "#000000",
  38898. "blanchedalmond": "#ffebcd",
  38899. "blue": "#0000ff",
  38900. "blueviolet": "#8a2be2",
  38901. "brown": "#a52a2a",
  38902. "burlywood": "#deb887",
  38903. "cadetblue": "#5f9ea0",
  38904. "chartreuse": "#7fff00",
  38905. "chocolate": "#d2691e",
  38906. "coral": "#ff7f50",
  38907. "cornflowerblue": "#6495ed",
  38908. "cornsilk": "#fff8dc",
  38909. "crimson": "#dc143c",
  38910. "cyan": "#00ffff",
  38911. "darkblue": "#00008b",
  38912. "darkcyan": "#008b8b",
  38913. "darkgoldenrod": "#b8860b",
  38914. "darkgray": "#a9a9a9",
  38915. "darkgreen": "#006400",
  38916. "darkkhaki": "#bdb76b",
  38917. "darkmagenta": "#8b008b",
  38918. "darkolivegreen": "#556b2f",
  38919. "darkorange": "#ff8c00",
  38920. "darkorchid": "#9932cc",
  38921. "darkred": "#8b0000",
  38922. "darksalmon": "#e9967a",
  38923. "darkseagreen": "#8fbc8f",
  38924. "darkslateblue": "#483d8b",
  38925. "darkslategray": "#2f4f4f",
  38926. "darkturquoise": "#00ced1",
  38927. "darkviolet": "#9400d3",
  38928. "deeppink": "#ff1493",
  38929. "deepskyblue": "#00bfff",
  38930. "dimgray": "#696969",
  38931. "dodgerblue": "#1e90ff",
  38932. "firebrick": "#b22222",
  38933. "floralwhite": "#fffaf0",
  38934. "forestgreen": "#228b22",
  38935. "fuchsia": "#ff00ff",
  38936. "gainsboro": "#dcdcdc",
  38937. "ghostwhite": "#f8f8ff",
  38938. "gold": "#ffd700",
  38939. "goldenrod": "#daa520",
  38940. "gray": "#808080",
  38941. "green": "#008000",
  38942. "greenyellow": "#adff2f",
  38943. "honeydew": "#f0fff0",
  38944. "hotpink": "#ff69b4",
  38945. "indianred ": "#cd5c5c",
  38946. "indigo": "#4b0082",
  38947. "ivory": "#fffff0",
  38948. "khaki": "#f0e68c",
  38949. "lavender": "#e6e6fa",
  38950. "lavenderblush": "#fff0f5",
  38951. "lawngreen": "#7cfc00",
  38952. "lemonchiffon": "#fffacd",
  38953. "lightblue": "#add8e6",
  38954. "lightcoral": "#f08080",
  38955. "lightcyan": "#e0ffff",
  38956. "lightgoldenrodyellow": "#fafad2",
  38957. "lightgrey": "#d3d3d3",
  38958. "lightgreen": "#90ee90",
  38959. "lightpink": "#ffb6c1",
  38960. "lightsalmon": "#ffa07a",
  38961. "lightseagreen": "#20b2aa",
  38962. "lightskyblue": "#87cefa",
  38963. "lightslategray": "#778899",
  38964. "lightsteelblue": "#b0c4de",
  38965. "lightyellow": "#ffffe0",
  38966. "lime": "#00ff00",
  38967. "limegreen": "#32cd32",
  38968. "linen": "#faf0e6",
  38969. "magenta": "#ff00ff",
  38970. "maroon": "#800000",
  38971. "mediumaquamarine": "#66cdaa",
  38972. "mediumblue": "#0000cd",
  38973. "mediumorchid": "#ba55d3",
  38974. "mediumpurple": "#9370d8",
  38975. "mediumseagreen": "#3cb371",
  38976. "mediumslateblue": "#7b68ee",
  38977. "mediumspringgreen": "#00fa9a",
  38978. "mediumturquoise": "#48d1cc",
  38979. "mediumvioletred": "#c71585",
  38980. "midnightblue": "#191970",
  38981. "mintcream": "#f5fffa",
  38982. "mistyrose": "#ffe4e1",
  38983. "moccasin": "#ffe4b5",
  38984. "navajowhite": "#ffdead",
  38985. "navy": "#000080",
  38986. "oldlace": "#fdf5e6",
  38987. "olive": "#808000",
  38988. "olivedrab": "#6b8e23",
  38989. "orange": "#ffa500",
  38990. "orangered": "#ff4500",
  38991. "orchid": "#da70d6",
  38992. "palegoldenrod": "#eee8aa",
  38993. "palegreen": "#98fb98",
  38994. "paleturquoise": "#afeeee",
  38995. "palevioletred": "#d87093",
  38996. "papayawhip": "#ffefd5",
  38997. "peachpuff": "#ffdab9",
  38998. "peru": "#cd853f",
  38999. "pink": "#ffc0cb",
  39000. "plum": "#dda0dd",
  39001. "powderblue": "#b0e0e6",
  39002. "purple": "#800080",
  39003. "rebeccapurple": "#663399",
  39004. "red": "#ff0000",
  39005. "rosybrown": "#bc8f8f",
  39006. "royalblue": "#4169e1",
  39007. "saddlebrown": "#8b4513",
  39008. "salmon": "#fa8072",
  39009. "sandybrown": "#f4a460",
  39010. "seagreen": "#2e8b57",
  39011. "seashell": "#fff5ee",
  39012. "sienna": "#a0522d",
  39013. "silver": "#c0c0c0",
  39014. "skyblue": "#87ceeb",
  39015. "slateblue": "#6a5acd",
  39016. "slategray": "#708090",
  39017. "snow": "#fffafa",
  39018. "springgreen": "#00ff7f",
  39019. "steelblue": "#4682b4",
  39020. "tan": "#d2b48c",
  39021. "teal": "#008080",
  39022. "thistle": "#d8bfd8",
  39023. "tomato": "#ff6347",
  39024. "turquoise": "#40e0d0",
  39025. "violet": "#ee82ee",
  39026. "wheat": "#f5deb3",
  39027. "white": "#ffffff",
  39028. "whitesmoke": "#f5f5f5",
  39029. "yellow": "#ffff00",
  39030. "yellowgreen": "#9acd32"
  39031. };
  39032. var _getHexColor = function _getHexColor(color) {
  39033. color = color.replace('color:', '').replace(';', '').replace(' ', '');
  39034. if (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(color)) {
  39035. return color;
  39036. } else if (namedColors[color]) {
  39037. return namedColors[color];
  39038. } else if (color.indexOf('rgb') === 0) {
  39039. var rgbArray = color.split(',');
  39040. var convertedColor = rgbArray.length < 3 ? null : '#' + [rgbArray[0], rgbArray[1], rgbArray[2]].map(function (x) {
  39041. var hex = parseInt(x.replace(/\D/g, ''), 10).toString(16);
  39042. return hex.length === 1 ? '0' + hex : hex;
  39043. }).join('');
  39044. return (/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(convertedColor) ? convertedColor : null
  39045. );
  39046. } else {
  39047. return null;
  39048. }
  39049. };
  39050. var namedColors = exports.namedColors = _namedColors;
  39051. var getHexColor = exports.getHexColor = _getHexColor;
  39052. var detectColorsFromHTMLString = exports.detectColorsFromHTMLString = function detectColorsFromHTMLString(html) {
  39053. return typeof html !== 'string' ? [] : (html.match(/color:[^;]{3,24};/g) || []).map(getHexColor).filter(function (color) {
  39054. return color;
  39055. });
  39056. };
  39057. var detectColorsFromDraftState = exports.detectColorsFromDraftState = function detectColorsFromDraftState(draftState) {
  39058. var result = [];
  39059. if (!draftState || !draftState.blocks || !draftState.blocks.length) {
  39060. return result;
  39061. }
  39062. draftState.blocks.forEach(function (block) {
  39063. if (block && block.inlineStyleRanges && block.inlineStyleRanges.length) {
  39064. block.inlineStyleRanges.forEach(function (inlineStyle) {
  39065. if (inlineStyle.style && inlineStyle.style.indexOf('COLOR-') >= 0) {
  39066. result.push('#' + inlineStyle.style.split('COLOR-')[1]);
  39067. }
  39068. });
  39069. }
  39070. });
  39071. return result.filter(function (color) {
  39072. return color;
  39073. });
  39074. };
  39075. });
  39076. styleInject_es.unwrapExports(color$1);
  39077. var color_1$1 = color$1.namedColors;
  39078. var color_2$1 = color$1.getHexColor;
  39079. var color_3$1 = color$1.detectColorsFromHTMLString;
  39080. var color_4$1 = color$1.detectColorsFromDraftState;
  39081. var dist$4 = styleInject_es.createCommonjsModule(function (module, exports) {
  39082. Object.defineProperty(exports, "__esModule", {
  39083. value: true
  39084. });
  39085. exports.ColorUtils = exports.BaseUtils = exports.ContentUtils = undefined;
  39086. var _ContentUtils = _interopRequireWildcard(content$1);
  39087. var _BaseUtils = _interopRequireWildcard(base$1);
  39088. var _ColorUtils = _interopRequireWildcard(color$1);
  39089. 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; } }
  39090. var ContentUtils = exports.ContentUtils = _ContentUtils;
  39091. var BaseUtils = exports.BaseUtils = _BaseUtils;
  39092. var ColorUtils = exports.ColorUtils = _ColorUtils;
  39093. });
  39094. styleInject_es.unwrapExports(dist$4);
  39095. var dist_1$2 = dist$4.ColorUtils;
  39096. var dist_2$2 = dist$4.BaseUtils;
  39097. var dist_3$2 = dist$4.ContentUtils;
  39098. var emoticon = styleInject_es.createCommonjsModule(function (module, exports) {
  39099. (function webpackUniversalModuleDefinition(root, factory) {
  39100. module.exports = factory(React__default, dist$4);
  39101. })(window, function(__WEBPACK_EXTERNAL_MODULE__1__, __WEBPACK_EXTERNAL_MODULE__6__) {
  39102. return /******/ (function(modules) { // webpackBootstrap
  39103. /******/ // The module cache
  39104. /******/ var installedModules = {};
  39105. /******/
  39106. /******/ // The require function
  39107. /******/ function __webpack_require__(moduleId) {
  39108. /******/
  39109. /******/ // Check if module is in cache
  39110. /******/ if(installedModules[moduleId]) {
  39111. /******/ return installedModules[moduleId].exports;
  39112. /******/ }
  39113. /******/ // Create a new module (and put it into the cache)
  39114. /******/ var module = installedModules[moduleId] = {
  39115. /******/ i: moduleId,
  39116. /******/ l: false,
  39117. /******/ exports: {}
  39118. /******/ };
  39119. /******/
  39120. /******/ // Execute the module function
  39121. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  39122. /******/
  39123. /******/ // Flag the module as loaded
  39124. /******/ module.l = true;
  39125. /******/
  39126. /******/ // Return the exports of the module
  39127. /******/ return module.exports;
  39128. /******/ }
  39129. /******/
  39130. /******/
  39131. /******/ // expose the modules object (__webpack_modules__)
  39132. /******/ __webpack_require__.m = modules;
  39133. /******/
  39134. /******/ // expose the module cache
  39135. /******/ __webpack_require__.c = installedModules;
  39136. /******/
  39137. /******/ // define getter function for harmony exports
  39138. /******/ __webpack_require__.d = function(exports, name, getter) {
  39139. /******/ if(!__webpack_require__.o(exports, name)) {
  39140. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  39141. /******/ }
  39142. /******/ };
  39143. /******/
  39144. /******/ // define __esModule on exports
  39145. /******/ __webpack_require__.r = function(exports) {
  39146. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  39147. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  39148. /******/ }
  39149. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  39150. /******/ };
  39151. /******/
  39152. /******/ // create a fake namespace object
  39153. /******/ // mode & 1: value is a module id, require it
  39154. /******/ // mode & 2: merge all properties of value into the ns
  39155. /******/ // mode & 4: return value when already ns object
  39156. /******/ // mode & 8|1: behave like require
  39157. /******/ __webpack_require__.t = function(value, mode) {
  39158. /******/ if(mode & 1) value = __webpack_require__(value);
  39159. /******/ if(mode & 8) return value;
  39160. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  39161. /******/ var ns = Object.create(null);
  39162. /******/ __webpack_require__.r(ns);
  39163. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  39164. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  39165. /******/ return ns;
  39166. /******/ };
  39167. /******/
  39168. /******/ // getDefaultExport function for compatibility with non-harmony modules
  39169. /******/ __webpack_require__.n = function(module) {
  39170. /******/ var getter = module && module.__esModule ?
  39171. /******/ function getDefault() { return module['default']; } :
  39172. /******/ function getModuleExports() { return module; };
  39173. /******/ __webpack_require__.d(getter, 'a', getter);
  39174. /******/ return getter;
  39175. /******/ };
  39176. /******/
  39177. /******/ // Object.prototype.hasOwnProperty.call
  39178. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  39179. /******/
  39180. /******/ // __webpack_public_path__
  39181. /******/ __webpack_require__.p = "/";
  39182. /******/
  39183. /******/
  39184. /******/ // Load entry module and return exports
  39185. /******/ return __webpack_require__(__webpack_require__.s = 33);
  39186. /******/ })
  39187. /************************************************************************/
  39188. /******/ ({
  39189. /***/ 1:
  39190. /***/ (function(module, exports) {
  39191. module.exports = __WEBPACK_EXTERNAL_MODULE__1__;
  39192. /***/ }),
  39193. /***/ 2:
  39194. /***/ (function(module, exports) {
  39195. function _defineProperty(obj, key, value) {
  39196. if (key in obj) {
  39197. Object.defineProperty(obj, key, {
  39198. value: value,
  39199. enumerable: true,
  39200. configurable: true,
  39201. writable: true
  39202. });
  39203. } else {
  39204. obj[key] = value;
  39205. }
  39206. return obj;
  39207. }
  39208. module.exports = _defineProperty;
  39209. /***/ }),
  39210. /***/ 33:
  39211. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  39212. __webpack_require__.r(__webpack_exports__);
  39213. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "defaultEmoticons", function() { return defaultEmoticons; });
  39214. /* harmony import */ var _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
  39215. /* harmony import */ var _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0__);
  39216. /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
  39217. /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
  39218. /* harmony import */ var braft_utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6);
  39219. /* harmony import */ var _styles_scss__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(48);
  39220. // https://www.iconfinder.com/iconsets/emoji-18
  39221. 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) {
  39222. return "".concat(item, ".png");
  39223. });
  39224. var insertEmoticon = function insertEmoticon(editor, editorState, src) {
  39225. editor.setValue(braft_utils__WEBPACK_IMPORTED_MODULE_2__["ContentUtils"].insertText(editorState, ' ', null, {
  39226. type: 'EMOTICON',
  39227. mutability: 'IMMUTABLE',
  39228. data: {
  39229. src: src
  39230. }
  39231. }));
  39232. };
  39233. var controlRef = null;
  39234. var bindControlRef = function bindControlRef(ref) {
  39235. return controlRef = ref;
  39236. };
  39237. /* harmony default export */ __webpack_exports__["default"] = (function (options) {
  39238. options = _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0___default()({
  39239. emoticons: [],
  39240. closeOnSelect: false,
  39241. closeOnBlur: false
  39242. }, options);
  39243. var _options = options,
  39244. emoticons = _options.emoticons,
  39245. closeOnSelect = _options.closeOnSelect,
  39246. closeOnBlur = _options.closeOnBlur,
  39247. includeEditors = _options.includeEditors,
  39248. excludeEditors = _options.excludeEditors;
  39249. return {
  39250. type: 'entity',
  39251. includeEditors: includeEditors,
  39252. excludeEditors: excludeEditors,
  39253. name: 'EMOTICON',
  39254. control: function control(props) {
  39255. return {
  39256. key: 'EMOTICON',
  39257. replace: 'emoji',
  39258. type: 'dropdown',
  39259. text: react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("i", {
  39260. className: "bfi-emoji"
  39261. }),
  39262. showArrow: false,
  39263. ref: bindControlRef,
  39264. autoHide: closeOnBlur,
  39265. component: react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("div", {
  39266. className: "braft-emoticon-picker"
  39267. }, react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("div", {
  39268. className: "braft-emoticons-list"
  39269. }, emoticons.map(function (item, index) {
  39270. return react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("img", {
  39271. onClick: function onClick() {
  39272. insertEmoticon(props.editor, props.editorState, item);
  39273. closeOnSelect && controlRef && controlRef.hide();
  39274. },
  39275. key: index,
  39276. src: item
  39277. });
  39278. })))
  39279. };
  39280. },
  39281. mutability: 'IMMUTABLE',
  39282. component: function component(props) {
  39283. var entity = props.contentState.getEntity(props.entityKey);
  39284. var _entity$getData = entity.getData(),
  39285. src = _entity$getData.src;
  39286. return react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("span", {
  39287. className: "braft-emoticon-in-editor"
  39288. }, react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("img", {
  39289. src: src
  39290. }), props.children);
  39291. },
  39292. importer: function importer(nodeName, node) {
  39293. if (nodeName.toLowerCase() === 'span' && node.classList && node.classList.contains('braft-emoticon-wrap')) {
  39294. var imgNode = node.querySelector('img');
  39295. var src = imgNode.getAttribute('src'); // 移除img节点以避免生成atomic block
  39296. node.removeChild(imgNode);
  39297. return {
  39298. mutability: 'IMMUTABLE',
  39299. data: {
  39300. src: src
  39301. }
  39302. };
  39303. }
  39304. },
  39305. exporter: function exporter(entityObject, initialText) {
  39306. var src = entityObject.data.src;
  39307. return react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("span", {
  39308. className: "braft-emoticon-wrap"
  39309. }, react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement("img", {
  39310. src: src
  39311. }), initialText);
  39312. }
  39313. };
  39314. });
  39315. /***/ }),
  39316. /***/ 48:
  39317. /***/ (function(module, exports) {
  39318. // removed by extract-text-webpack-plugin
  39319. /***/ }),
  39320. /***/ 5:
  39321. /***/ (function(module, exports, __webpack_require__) {
  39322. var defineProperty = __webpack_require__(2);
  39323. function _objectSpread(target) {
  39324. for (var i = 1; i < arguments.length; i++) {
  39325. var source = arguments[i] != null ? arguments[i] : {};
  39326. var ownKeys = Object.keys(source);
  39327. if (typeof Object.getOwnPropertySymbols === 'function') {
  39328. ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
  39329. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  39330. }));
  39331. }
  39332. ownKeys.forEach(function (key) {
  39333. defineProperty(target, key, source[key]);
  39334. });
  39335. }
  39336. return target;
  39337. }
  39338. module.exports = _objectSpread;
  39339. /***/ }),
  39340. /***/ 6:
  39341. /***/ (function(module, exports) {
  39342. module.exports = __WEBPACK_EXTERNAL_MODULE__6__;
  39343. /***/ })
  39344. /******/ });
  39345. });
  39346. });
  39347. var Emoticon = styleInject_es.unwrapExports(emoticon);
  39348. var emoticon_1 = emoticon.defaultEmoticons;
  39349. var maxLength = styleInject_es.createCommonjsModule(function (module, exports) {
  39350. (function webpackUniversalModuleDefinition(root, factory) {
  39351. module.exports = factory();
  39352. })(window, function() {
  39353. return /******/ (function(modules) { // webpackBootstrap
  39354. /******/ // The module cache
  39355. /******/ var installedModules = {};
  39356. /******/
  39357. /******/ // The require function
  39358. /******/ function __webpack_require__(moduleId) {
  39359. /******/
  39360. /******/ // Check if module is in cache
  39361. /******/ if(installedModules[moduleId]) {
  39362. /******/ return installedModules[moduleId].exports;
  39363. /******/ }
  39364. /******/ // Create a new module (and put it into the cache)
  39365. /******/ var module = installedModules[moduleId] = {
  39366. /******/ i: moduleId,
  39367. /******/ l: false,
  39368. /******/ exports: {}
  39369. /******/ };
  39370. /******/
  39371. /******/ // Execute the module function
  39372. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  39373. /******/
  39374. /******/ // Flag the module as loaded
  39375. /******/ module.l = true;
  39376. /******/
  39377. /******/ // Return the exports of the module
  39378. /******/ return module.exports;
  39379. /******/ }
  39380. /******/
  39381. /******/
  39382. /******/ // expose the modules object (__webpack_modules__)
  39383. /******/ __webpack_require__.m = modules;
  39384. /******/
  39385. /******/ // expose the module cache
  39386. /******/ __webpack_require__.c = installedModules;
  39387. /******/
  39388. /******/ // define getter function for harmony exports
  39389. /******/ __webpack_require__.d = function(exports, name, getter) {
  39390. /******/ if(!__webpack_require__.o(exports, name)) {
  39391. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  39392. /******/ }
  39393. /******/ };
  39394. /******/
  39395. /******/ // define __esModule on exports
  39396. /******/ __webpack_require__.r = function(exports) {
  39397. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  39398. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  39399. /******/ }
  39400. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  39401. /******/ };
  39402. /******/
  39403. /******/ // create a fake namespace object
  39404. /******/ // mode & 1: value is a module id, require it
  39405. /******/ // mode & 2: merge all properties of value into the ns
  39406. /******/ // mode & 4: return value when already ns object
  39407. /******/ // mode & 8|1: behave like require
  39408. /******/ __webpack_require__.t = function(value, mode) {
  39409. /******/ if(mode & 1) value = __webpack_require__(value);
  39410. /******/ if(mode & 8) return value;
  39411. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  39412. /******/ var ns = Object.create(null);
  39413. /******/ __webpack_require__.r(ns);
  39414. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  39415. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  39416. /******/ return ns;
  39417. /******/ };
  39418. /******/
  39419. /******/ // getDefaultExport function for compatibility with non-harmony modules
  39420. /******/ __webpack_require__.n = function(module) {
  39421. /******/ var getter = module && module.__esModule ?
  39422. /******/ function getDefault() { return module['default']; } :
  39423. /******/ function getModuleExports() { return module; };
  39424. /******/ __webpack_require__.d(getter, 'a', getter);
  39425. /******/ return getter;
  39426. /******/ };
  39427. /******/
  39428. /******/ // Object.prototype.hasOwnProperty.call
  39429. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  39430. /******/
  39431. /******/ // __webpack_public_path__
  39432. /******/ __webpack_require__.p = "/";
  39433. /******/
  39434. /******/
  39435. /******/ // Load entry module and return exports
  39436. /******/ return __webpack_require__(__webpack_require__.s = 34);
  39437. /******/ })
  39438. /************************************************************************/
  39439. /******/ ({
  39440. /***/ 2:
  39441. /***/ (function(module, exports) {
  39442. function _defineProperty(obj, key, value) {
  39443. if (key in obj) {
  39444. Object.defineProperty(obj, key, {
  39445. value: value,
  39446. enumerable: true,
  39447. configurable: true,
  39448. writable: true
  39449. });
  39450. } else {
  39451. obj[key] = value;
  39452. }
  39453. return obj;
  39454. }
  39455. module.exports = _defineProperty;
  39456. /***/ }),
  39457. /***/ 34:
  39458. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  39459. __webpack_require__.r(__webpack_exports__);
  39460. /* harmony import */ var _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
  39461. /* harmony import */ var _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0__);
  39462. var getSelectedTextLength = function getSelectedTextLength(editorState) {
  39463. var currentSelection = editorState.getSelection();
  39464. var isCollapsed = currentSelection.isCollapsed();
  39465. var length = 0;
  39466. if (!isCollapsed) {
  39467. var currentContent = editorState.getCurrentContent();
  39468. var startKey = currentSelection.getStartKey();
  39469. var endKey = currentSelection.getEndKey();
  39470. var startBlock = currentContent.getBlockForKey(startKey);
  39471. var isStartAndEndBlockAreTheSame = startKey === endKey;
  39472. var startBlockTextLength = startBlock.getLength();
  39473. var startSelectedTextLength = startBlockTextLength - currentSelection.getStartOffset();
  39474. var endSelectedTextLength = currentSelection.getEndOffset();
  39475. var keyAfterEnd = currentContent.getKeyAfter(endKey);
  39476. if (isStartAndEndBlockAreTheSame) {
  39477. length += currentSelection.getEndOffset() - currentSelection.getStartOffset();
  39478. } else {
  39479. var currentKey = startKey;
  39480. while (currentKey && currentKey !== keyAfterEnd) {
  39481. if (currentKey === startKey) {
  39482. length += startSelectedTextLength + 1;
  39483. } else if (currentKey === endKey) {
  39484. length += endSelectedTextLength;
  39485. } else {
  39486. length += currentContent.getBlockForKey(currentKey).getLength() + 1;
  39487. }
  39488. currentKey = currentContent.getKeyAfter(currentKey);
  39489. }
  39490. }
  39491. }
  39492. return length;
  39493. };
  39494. /* harmony default export */ __webpack_exports__["default"] = (function (options) {
  39495. options = _babel_runtime_helpers_objectSpread__WEBPACK_IMPORTED_MODULE_0___default()({
  39496. defaultValue: Infinity
  39497. }, options);
  39498. var _options = options,
  39499. includeEditors = _options.includeEditors,
  39500. excludeEditors = _options.excludeEditors,
  39501. defaultValue = _options.defaultValue;
  39502. return {
  39503. type: 'prop-interception',
  39504. includeEditors: includeEditors,
  39505. excludeEditors: excludeEditors,
  39506. interceptor: function interceptor(editorProps) {
  39507. var maxLength = editorProps.maxLength || defaultValue;
  39508. editorProps.handleBeforeInput = function (_, editorState) {
  39509. if (maxLength === Infinity) {
  39510. return 'not-handled';
  39511. }
  39512. var currentContentLength = editorState.toText().length;
  39513. var selectedTextLength = getSelectedTextLength(editorState);
  39514. if (currentContentLength - selectedTextLength > maxLength - 1) {
  39515. editorProps.onReachMaxLength && editorProps.onReachMaxLength(maxLength);
  39516. return 'handled';
  39517. }
  39518. };
  39519. editorProps.handlePastedText = function (pastedText, _, editorState) {
  39520. if (maxLength === Infinity) {
  39521. return 'not-handled';
  39522. }
  39523. var currentContentLength = editorState.toText().length;
  39524. var selectedTextLength = getSelectedTextLength(editorState);
  39525. if (currentContentLength + pastedText.length - selectedTextLength > maxLength) {
  39526. editorProps.onReachMaxLength && editorProps.onReachMaxLength(maxLength);
  39527. return 'handled';
  39528. }
  39529. };
  39530. return editorProps;
  39531. }
  39532. };
  39533. });
  39534. /***/ }),
  39535. /***/ 5:
  39536. /***/ (function(module, exports, __webpack_require__) {
  39537. var defineProperty = __webpack_require__(2);
  39538. function _objectSpread(target) {
  39539. for (var i = 1; i < arguments.length; i++) {
  39540. var source = arguments[i] != null ? arguments[i] : {};
  39541. var ownKeys = Object.keys(source);
  39542. if (typeof Object.getOwnPropertySymbols === 'function') {
  39543. ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
  39544. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  39545. }));
  39546. }
  39547. ownKeys.forEach(function (key) {
  39548. defineProperty(target, key, source[key]);
  39549. });
  39550. }
  39551. return target;
  39552. }
  39553. module.exports = _objectSpread;
  39554. /***/ })
  39555. /******/ });
  39556. });
  39557. });
  39558. var MaxLength = styleInject_es.unwrapExports(maxLength);
  39559. var lengthOptions = {
  39560. defaultValue: 100 // 指定默认限制数,如不指定则为Infinity(无限)
  39561. // includeEditors: ['editor-id-1'], // 指定该模块对哪些BraftEditor生效,不传此属性则对所有BraftEditor有效
  39562. // excludeEditors: ['editor-id-2'], // 指定该模块对哪些BraftEditor无效
  39563. };
  39564. BraftEditor.use(MaxLength(lengthOptions)); // 转换默认表情包列表,让webpack可以正确加载到默认表情包中的图片,请确保已对png格式的文件配置了loader
  39565. // 如果你使用的webpack版本不支持动态require,或者使用的其他打包工具,请勿使用此写法
  39566. var emoticons = emoticon_1.map(function (item) {
  39567. return require("braft-extensions/dist/assets/".concat(item));
  39568. }); // 也可以使用自己的表情包资源,不受打包工具限制
  39569. // 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', ...]
  39570. var emotionOptions = {
  39571. // includeEditors: ['editor-id-1'], // 指定该模块对哪些BraftEditor生效,不传此属性则对所有BraftEditor有效
  39572. // excludeEditors: ['editor-id-2'], // 指定该模块对哪些BraftEditor无效
  39573. emoticons: emoticons,
  39574. // 指定可用表情图片列表,默认为空
  39575. closeOnBlur: true,
  39576. // 指定是否在点击表情选择器之外的地方时关闭表情选择器,默认false
  39577. closeOnSelect: false // 指定是否在选择表情后关闭表情选择器,默认false
  39578. };
  39579. BraftEditor.use(Emoticon(emotionOptions));
  39580. var BarftEditorPage = function BarftEditorPage() {
  39581. var controls = ["bold", "italic", "underline", "separator", "link", "emoji", "separator", "media"];
  39582. var _useState = React.useState(BraftEditor.createEditorState("<p>Hello <b>World!</b></p>")),
  39583. _useState2 = styleInject_es._slicedToArray(_useState, 2),
  39584. editorState = _useState2[0],
  39585. setEditorState = _useState2[1];
  39586. return React__default.createElement("div", {
  39587. className: "editor-wrapper"
  39588. }, React__default.createElement(BraftEditor, {
  39589. value: editorState,
  39590. onChange: setEditorState,
  39591. controls: controls,
  39592. contentStyle: {
  39593. height: 210,
  39594. boxShadow: "inset 0 1px 3px rgba(0,0,0,.1)"
  39595. }
  39596. }));
  39597. };
  39598. 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";
  39599. var styles = {"wrapper":"RichTextEditor_wrapper__A033L","btnListWrapper":"RichTextEditor_btnListWrapper__3iF9d","editorWrapper":"RichTextEditor_editorWrapper__PzQ_1"};
  39600. styleInject_es.styleInject(css$2);
  39601. // 自定义组件,用于超链接
  39602. var Link = function Link(props) {
  39603. // 这里通过contentState来获取entity�,之后通过getData获取entity中包含的数据
  39604. var _props$contentState$g = props.contentState.getEntity(props.entityKey).getData(),
  39605. url = _props$contentState$g.url;
  39606. return React__default.createElement("a", {
  39607. href: url
  39608. }, props.children);
  39609. }; // decorator,用于超链接
  39610. var decorator = new Draft_4([{
  39611. strategy: function strategy(contentBlock, callback, contentState) {
  39612. // 这个方法接收2个函数作为参数,如果第一个参数的函数执行时�返回true,就会执行第二个参数函数,同时会�将匹配的�字符的起始位置和结束位置传递给第二个参数。
  39613. contentBlock.findEntityRanges(function (character) {
  39614. var entityKey = character.getEntity();
  39615. return entityKey !== null && contentState.getEntity(entityKey).getType() === 'LINK';
  39616. }, function () {
  39617. callback.apply(void 0, arguments);
  39618. });
  39619. },
  39620. component: Link
  39621. }, {
  39622. strategy: function strategy(contentBlock, callback, contentState) {
  39623. contentBlock.findEntityRanges(function (character) {
  39624. var entityKey = character.getEntity();
  39625. return entityKey !== null && contentState.getEntity(entityKey).getType() === 'EMOJI';
  39626. }, function () {
  39627. callback.apply(void 0, arguments);
  39628. });
  39629. },
  39630. // component: (props: any) => (<span style={{ color: 'red' }}>[Emoji]</span>)
  39631. component: function component(props) {
  39632. return React__default.createElement("i", {
  39633. style: {
  39634. display: 'inline-block',
  39635. height: '18px',
  39636. width: '18px',
  39637. backgroundImage: "url(https://i.pinimg.com/originals/03/7e/79/037e79b2fb52127537be79110891ae3f.png)",
  39638. backgroundSize: '100% 100%',
  39639. color: 'transparent'
  39640. }
  39641. }, "e");
  39642. }
  39643. }]);
  39644. var RichTextEditor =
  39645. /*#__PURE__*/
  39646. function (_React$Component) {
  39647. styleInject_es._inherits(RichTextEditor, _React$Component);
  39648. function RichTextEditor(props) {
  39649. var _this;
  39650. styleInject_es._classCallCheck(this, RichTextEditor);
  39651. _this = styleInject_es._possibleConstructorReturn(this, styleInject_es._getPrototypeOf(RichTextEditor).call(this, props));
  39652. styleInject_es._defineProperty(styleInject_es._assertThisInitialized(_this), "onChange", void 0);
  39653. _this.state = {
  39654. editorState: Draft_3.createEmpty(decorator)
  39655. };
  39656. _this.onChange = function (editorState) {
  39657. return _this.setState({
  39658. editorState: editorState
  39659. });
  39660. };
  39661. _this.handleKeyCommand = _this.handleKeyCommand.bind(styleInject_es._assertThisInitialized(_this));
  39662. _this.defaultBlockStyleFn = _this.defaultBlockStyleFn.bind(styleInject_es._assertThisInitialized(_this));
  39663. return _this;
  39664. }
  39665. styleInject_es._createClass(RichTextEditor, [{
  39666. key: "handleKeyCommand",
  39667. value: function handleKeyCommand(command, editorState) {
  39668. var newState = Draft_15.handleKeyCommand(editorState, command);
  39669. console.log('command: ', command);
  39670. console.log('newState: ', newState);
  39671. if (newState) {
  39672. this.onChange(newState);
  39673. return "handled";
  39674. }
  39675. switch (command) {
  39676. case 'backspace':
  39677. var contentState = editorState.getCurrentContent();
  39678. var selectionState = editorState.getSelection();
  39679. var _ref = [selectionState.getStartOffset(), selectionState.getEndOffset()],
  39680. startOffset = _ref[0],
  39681. endOffset = _ref[1];
  39682. if (startOffset === endOffset) {
  39683. // 未选中状态
  39684. console.log(selectionState.getAnchorKey());
  39685. } // 选中状态
  39686. break;
  39687. }
  39688. return "not-handled";
  39689. }
  39690. }, {
  39691. key: "_onBoldClick",
  39692. value: function _onBoldClick() {
  39693. this.onChange(Draft_15.toggleInlineStyle(this.state.editorState, 'BOLD'));
  39694. }
  39695. }, {
  39696. key: "_onLinkClick",
  39697. value: function _onLinkClick() {
  39698. var editorState = this.state.editorState;
  39699. var contentState = editorState.getCurrentContent();
  39700. var selectionState = editorState.getSelection();
  39701. var contentStateWithEntity = contentState.createEntity('LINK', 'MUTABLE', {
  39702. url: 'http://www.zombo.com'
  39703. });
  39704. var entityKey = contentStateWithEntity.getLastCreatedEntityKey();
  39705. var contentStateWithLink = Draft_14.applyEntity(contentStateWithEntity, selectionState, entityKey);
  39706. var newEditorState = Draft_3.push(editorState, contentStateWithLink, 'apply-entity');
  39707. this.onChange(newEditorState);
  39708. }
  39709. }, {
  39710. key: "_onEmojiClick",
  39711. value: function _onEmojiClick(e, emojiCode) {
  39712. var editorState = this.state.editorState;
  39713. var contentState = editorState.getCurrentContent();
  39714. var selectionState = editorState.getSelection();
  39715. var EMOJIEntity = contentState.createEntity('EMOJI', 'IMMUTABLE', {
  39716. emojiCode: emojiCode
  39717. });
  39718. var entityKey = EMOJIEntity.getLastCreatedEntityKey();
  39719. var ncsWithEntity = Draft_14.insertText(contentState, selectionState, 'e', undefined, entityKey);
  39720. var newEditorState = Draft_3.push(editorState, ncsWithEntity, 'insert-characters'); // const newEditorState = AtomicBlockUtils.insertAtomicBlock(
  39721. // editorState,
  39722. // entityKey,
  39723. // ' '
  39724. // );
  39725. this.onChange(newEditorState);
  39726. }
  39727. }, {
  39728. key: "_onCheckRange",
  39729. value: function _onCheckRange() {
  39730. console.log(this.state.editorState.getCurrentContent());
  39731. console.log(Draft_20(this.state.editorState.getCurrentContent()));
  39732. }
  39733. }, {
  39734. key: "defaultBlockStyleFn",
  39735. value: function defaultBlockStyleFn(contentBlock) {
  39736. var type = contentBlock.getType();
  39737. return "";
  39738. }
  39739. }, {
  39740. key: "defaultBlockRenderFn",
  39741. value: function defaultBlockRenderFn(contentBlock) {
  39742. var type = contentBlock.getType();
  39743. return contentBlock;
  39744. }
  39745. }, {
  39746. key: "render",
  39747. value: function render() {
  39748. var _this2 = this;
  39749. var editorState = this.state.editorState;
  39750. return React__default.createElement("div", {
  39751. className: styles.wrapper
  39752. }, React__default.createElement("div", {
  39753. className: styles.btnListWrapper
  39754. }, React__default.createElement("button", {
  39755. onClick: this._onBoldClick.bind(this)
  39756. }, "Bold"), React__default.createElement("button", {
  39757. onClick: this._onCheckRange.bind(this)
  39758. }, "Check"), React__default.createElement("button", {
  39759. onClick: this._onLinkClick.bind(this)
  39760. }, "Link"), React__default.createElement("button", {
  39761. onClick: function onClick(e) {
  39762. return _this2._onEmojiClick(e, '0011');
  39763. }
  39764. }, "Emoji")), React__default.createElement("div", {
  39765. className: styles.editorWrapper
  39766. }, React__default.createElement(Draft_1, {
  39767. editorState: editorState,
  39768. blockStyleFn: this.defaultBlockStyleFn,
  39769. blockRendererFn: this.defaultBlockRenderFn,
  39770. handleKeyCommand: this.handleKeyCommand,
  39771. onChange: this.onChange
  39772. })));
  39773. }
  39774. }]);
  39775. return RichTextEditor;
  39776. }(React__default.Component);
  39777. /*!
  39778. * isobject <https://github.com/jonschlinkert/isobject>
  39779. *
  39780. * Copyright (c) 2014-2017, Jon Schlinkert.
  39781. * Released under the MIT License.
  39782. */
  39783. function isObject(val) {
  39784. return val != null && typeof val === 'object' && Array.isArray(val) === false;
  39785. }
  39786. /*!
  39787. * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
  39788. *
  39789. * Copyright (c) 2014-2017, Jon Schlinkert.
  39790. * Released under the MIT License.
  39791. */
  39792. function isObjectObject(o) {
  39793. return isObject(o) === true
  39794. && Object.prototype.toString.call(o) === '[object Object]';
  39795. }
  39796. function isPlainObject(o) {
  39797. var ctor,prot;
  39798. if (isObjectObject(o) === false) return false;
  39799. // If has modified constructor
  39800. ctor = o.constructor;
  39801. if (typeof ctor !== 'function') return false;
  39802. // If has modified prototype
  39803. prot = ctor.prototype;
  39804. if (isObjectObject(prot) === false) return false;
  39805. // If constructor does not have an Object-specific method
  39806. if (prot.hasOwnProperty('isPrototypeOf') === false) {
  39807. return false;
  39808. }
  39809. // Most likely a plain Object
  39810. return true;
  39811. }
  39812. var index_cjs = isPlainObject;
  39813. var immer_1 = styleInject_es.createCommonjsModule(function (module, exports) {
  39814. Object.defineProperty(exports, '__esModule', { value: true });
  39815. // Should be no imports here!
  39816. var _a; // SOme things that should be evaluated before all else...
  39817. var hasSymbol = typeof Symbol !== "undefined";
  39818. var hasMap = typeof Map !== "undefined";
  39819. var hasSet = typeof Set !== "undefined";
  39820. /**
  39821. * The sentinel value returned by producers to replace the draft with undefined.
  39822. */
  39823. var NOTHING = hasSymbol ? Symbol("immer-nothing") : (_a = {}, _a["immer-nothing"] = true, _a);
  39824. /**
  39825. * To let Immer treat your class instances as plain immutable objects
  39826. * (albeit with a custom prototype), you must define either an instance property
  39827. * or a static property on each of your custom classes.
  39828. *
  39829. * Otherwise, your class instance will never be drafted, which means it won't be
  39830. * safe to mutate in a produce callback.
  39831. */
  39832. var DRAFTABLE = hasSymbol ? Symbol("immer-draftable") : "__$immer_draftable";
  39833. var DRAFT_STATE = hasSymbol ? Symbol("immer-state") : "__$immer_state";
  39834. var iteratorSymbol = hasSymbol ? Symbol.iterator : "@@iterator";
  39835. /* istanbul ignore next */
  39836. var extendStatics = function (d, b) {
  39837. extendStatics = Object.setPrototypeOf || {
  39838. __proto__: []
  39839. } instanceof Array && function (d, b) {
  39840. d.__proto__ = b;
  39841. } || function (d, b) {
  39842. for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } }
  39843. };
  39844. return extendStatics(d, b);
  39845. }; // Ugly hack to resolve #502 and inherit built in Map / Set
  39846. function __extends(d, b) {
  39847. extendStatics(d, b);
  39848. function __() {
  39849. this.constructor = d;
  39850. }
  39851. d.prototype = ( // @ts-ignore
  39852. __.prototype = b.prototype, new __());
  39853. }
  39854. var Archtype;
  39855. (function (Archtype) {
  39856. Archtype[Archtype["Object"] = 0] = "Object";
  39857. Archtype[Archtype["Array"] = 1] = "Array";
  39858. Archtype[Archtype["Map"] = 2] = "Map";
  39859. Archtype[Archtype["Set"] = 3] = "Set";
  39860. })(Archtype || (Archtype = {}));
  39861. var ProxyType;
  39862. (function (ProxyType) {
  39863. ProxyType[ProxyType["ProxyObject"] = 0] = "ProxyObject";
  39864. ProxyType[ProxyType["ProxyArray"] = 1] = "ProxyArray";
  39865. ProxyType[ProxyType["ES5Object"] = 2] = "ES5Object";
  39866. ProxyType[ProxyType["ES5Array"] = 3] = "ES5Array";
  39867. ProxyType[ProxyType["Map"] = 4] = "Map";
  39868. ProxyType[ProxyType["Set"] = 5] = "Set";
  39869. })(ProxyType || (ProxyType = {}));
  39870. /** Returns true if the given value is an Immer draft */
  39871. function isDraft(value) {
  39872. return !!value && !!value[DRAFT_STATE];
  39873. }
  39874. /** Returns true if the given value can be drafted by Immer */
  39875. function isDraftable(value) {
  39876. if (!value) { return false; }
  39877. return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!value.constructor[DRAFTABLE] || isMap(value) || isSet(value);
  39878. }
  39879. function isPlainObject(value) {
  39880. if (!value || typeof value !== "object") { return false; }
  39881. var proto = Object.getPrototypeOf(value);
  39882. return !proto || proto === Object.prototype;
  39883. }
  39884. function original(value) {
  39885. if (value && value[DRAFT_STATE]) {
  39886. return value[DRAFT_STATE].base;
  39887. } // otherwise return undefined
  39888. }
  39889. var ownKeys = typeof Reflect !== "undefined" && Reflect.ownKeys ? Reflect.ownKeys : typeof Object.getOwnPropertySymbols !== "undefined" ? function (obj) {
  39890. return Object.getOwnPropertyNames(obj).concat(Object.getOwnPropertySymbols(obj));
  39891. } :
  39892. /* istanbul ignore next */
  39893. Object.getOwnPropertyNames;
  39894. function each(obj, iter) {
  39895. if (getArchtype(obj) === Archtype.Object) {
  39896. ownKeys(obj).forEach(function (key) {
  39897. return iter(key, obj[key], obj);
  39898. });
  39899. } else {
  39900. obj.forEach(function (entry, index) {
  39901. return iter(index, entry, obj);
  39902. });
  39903. }
  39904. }
  39905. function isEnumerable(base, prop) {
  39906. var desc = Object.getOwnPropertyDescriptor(base, prop);
  39907. return desc && desc.enumerable ? true : false;
  39908. }
  39909. function getArchtype(thing) {
  39910. /* istanbul ignore next */
  39911. if (!thing) { die(); }
  39912. if (thing[DRAFT_STATE]) {
  39913. switch (thing[DRAFT_STATE].type) {
  39914. case ProxyType.ES5Object:
  39915. case ProxyType.ProxyObject:
  39916. return Archtype.Object;
  39917. case ProxyType.ES5Array:
  39918. case ProxyType.ProxyArray:
  39919. return Archtype.Array;
  39920. case ProxyType.Map:
  39921. return Archtype.Map;
  39922. case ProxyType.Set:
  39923. return Archtype.Set;
  39924. }
  39925. }
  39926. return Array.isArray(thing) ? Archtype.Array : isMap(thing) ? Archtype.Map : isSet(thing) ? Archtype.Set : Archtype.Object;
  39927. }
  39928. function has(thing, prop) {
  39929. return getArchtype(thing) === Archtype.Map ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
  39930. }
  39931. function get(thing, prop) {
  39932. // @ts-ignore
  39933. return getArchtype(thing) === Archtype.Map ? thing.get(prop) : thing[prop];
  39934. }
  39935. function set(thing, propOrOldValue, value) {
  39936. switch (getArchtype(thing)) {
  39937. case Archtype.Map:
  39938. thing.set(propOrOldValue, value);
  39939. break;
  39940. case Archtype.Set:
  39941. thing.delete(propOrOldValue);
  39942. thing.add(value);
  39943. break;
  39944. default:
  39945. thing[propOrOldValue] = value;
  39946. }
  39947. }
  39948. function is(x, y) {
  39949. // From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js
  39950. if (x === y) {
  39951. return x !== 0 || 1 / x === 1 / y;
  39952. } else {
  39953. return x !== x && y !== y;
  39954. }
  39955. }
  39956. function isMap(target) {
  39957. return hasMap && target instanceof Map;
  39958. }
  39959. function isSet(target) {
  39960. return hasSet && target instanceof Set;
  39961. }
  39962. function latest(state) {
  39963. return state.copy || state.base;
  39964. }
  39965. function shallowCopy(base, invokeGetters) {
  39966. if (invokeGetters === void 0) {
  39967. invokeGetters = false;
  39968. }
  39969. if (Array.isArray(base)) { return base.slice(); }
  39970. var clone = Object.create(Object.getPrototypeOf(base));
  39971. ownKeys(base).forEach(function (key) {
  39972. if (key === DRAFT_STATE) {
  39973. return; // Never copy over draft state.
  39974. }
  39975. var desc = Object.getOwnPropertyDescriptor(base, key);
  39976. var value = desc.value;
  39977. if (desc.get) {
  39978. if (!invokeGetters) {
  39979. throw new Error("Immer drafts cannot have computed properties");
  39980. }
  39981. value = desc.get.call(base);
  39982. }
  39983. if (desc.enumerable) {
  39984. clone[key] = value;
  39985. } else {
  39986. Object.defineProperty(clone, key, {
  39987. value: value,
  39988. writable: true,
  39989. configurable: true
  39990. });
  39991. }
  39992. });
  39993. return clone;
  39994. }
  39995. function freeze(obj, deep) {
  39996. if (!isDraftable(obj) || isDraft(obj) || Object.isFrozen(obj)) { return; }
  39997. var type = getArchtype(obj);
  39998. if (type === Archtype.Set) {
  39999. obj.add = obj.clear = obj.delete = dontMutateFrozenCollections;
  40000. } else if (type === Archtype.Map) {
  40001. obj.set = obj.clear = obj.delete = dontMutateFrozenCollections;
  40002. }
  40003. Object.freeze(obj);
  40004. if (deep) { each(obj, function (_, value) {
  40005. return freeze(value, true);
  40006. }); }
  40007. }
  40008. function dontMutateFrozenCollections() {
  40009. throw new Error("This object has been frozen and should not be mutated");
  40010. }
  40011. function createHiddenProperty(target, prop, value) {
  40012. Object.defineProperty(target, prop, {
  40013. value: value,
  40014. enumerable: false,
  40015. writable: true
  40016. });
  40017. }
  40018. /* istanbul ignore next */
  40019. function die() {
  40020. throw new Error("Illegal state, please file a bug");
  40021. }
  40022. /** Each scope represents a `produce` call. */
  40023. var ImmerScope =
  40024. /** @class */
  40025. function () {
  40026. function ImmerScope(parent, immer) {
  40027. this.drafts = [];
  40028. this.parent = parent;
  40029. this.immer = immer; // Whenever the modified draft contains a draft from another scope, we
  40030. // need to prevent auto-freezing so the unowned draft can be finalized.
  40031. this.canAutoFreeze = true;
  40032. }
  40033. ImmerScope.prototype.usePatches = function (patchListener) {
  40034. if (patchListener) {
  40035. this.patches = [];
  40036. this.inversePatches = [];
  40037. this.patchListener = patchListener;
  40038. }
  40039. };
  40040. ImmerScope.prototype.revoke = function () {
  40041. this.leave();
  40042. this.drafts.forEach(revoke); // @ts-ignore
  40043. this.drafts = null;
  40044. };
  40045. ImmerScope.prototype.leave = function () {
  40046. if (this === ImmerScope.current) {
  40047. ImmerScope.current = this.parent;
  40048. }
  40049. };
  40050. ImmerScope.enter = function (immer) {
  40051. var scope = new ImmerScope(ImmerScope.current, immer);
  40052. ImmerScope.current = scope;
  40053. return scope;
  40054. };
  40055. return ImmerScope;
  40056. }();
  40057. function revoke(draft) {
  40058. var state = draft[DRAFT_STATE];
  40059. if (state.type === ProxyType.ProxyObject || state.type === ProxyType.ProxyArray) { state.revoke(); }else { state.revoked = true; }
  40060. }
  40061. function processResult(immer, result, scope) {
  40062. var baseDraft = scope.drafts[0];
  40063. var isReplaced = result !== undefined && result !== baseDraft;
  40064. immer.willFinalize(scope, result, isReplaced);
  40065. if (isReplaced) {
  40066. if (baseDraft[DRAFT_STATE].modified) {
  40067. scope.revoke();
  40068. 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
  40069. }
  40070. if (isDraftable(result)) {
  40071. // Finalize the result in case it contains (or is) a subset of the draft.
  40072. result = finalize(immer, result, scope);
  40073. maybeFreeze(immer, result);
  40074. }
  40075. if (scope.patches) {
  40076. scope.patches.push({
  40077. op: "replace",
  40078. path: [],
  40079. value: result
  40080. });
  40081. scope.inversePatches.push({
  40082. op: "replace",
  40083. path: [],
  40084. value: baseDraft[DRAFT_STATE].base
  40085. });
  40086. }
  40087. } else {
  40088. // Finalize the base draft.
  40089. result = finalize(immer, baseDraft, scope, []);
  40090. }
  40091. scope.revoke();
  40092. if (scope.patches) {
  40093. scope.patchListener(scope.patches, scope.inversePatches);
  40094. }
  40095. return result !== NOTHING ? result : undefined;
  40096. }
  40097. function finalize(immer, draft, scope, path) {
  40098. var state = draft[DRAFT_STATE];
  40099. if (!state) {
  40100. if (Object.isFrozen(draft)) { return draft; }
  40101. return finalizeTree(immer, draft, scope);
  40102. } // Never finalize drafts owned by another scope.
  40103. if (state.scope !== scope) {
  40104. return draft;
  40105. }
  40106. if (!state.modified) {
  40107. maybeFreeze(immer, state.base, true);
  40108. return state.base;
  40109. }
  40110. if (!state.finalized) {
  40111. state.finalized = true;
  40112. finalizeTree(immer, state.draft, scope, path); // We cannot really delete anything inside of a Set. We can only replace the whole Set.
  40113. if (immer.onDelete && state.type !== ProxyType.Set) {
  40114. // The `assigned` object is unreliable with ES5 drafts.
  40115. if (immer.useProxies) {
  40116. var assigned = state.assigned;
  40117. each(assigned, function (prop, exists) {
  40118. if (!exists) { immer.onDelete(state, prop); }
  40119. });
  40120. } else {
  40121. var base = state.base,
  40122. copy_1 = state.copy;
  40123. each(base, function (prop) {
  40124. if (!has(copy_1, prop)) { immer.onDelete(state, prop); }
  40125. });
  40126. }
  40127. }
  40128. if (immer.onCopy) {
  40129. immer.onCopy(state);
  40130. } // At this point, all descendants of `state.copy` have been finalized,
  40131. // so we can be sure that `scope.canAutoFreeze` is accurate.
  40132. if (immer.autoFreeze && scope.canAutoFreeze) {
  40133. freeze(state.copy, false);
  40134. }
  40135. if (path && scope.patches) {
  40136. generatePatches(state, path, scope.patches, scope.inversePatches);
  40137. }
  40138. }
  40139. return state.copy;
  40140. }
  40141. function finalizeTree(immer, root, scope, rootPath) {
  40142. var state = root[DRAFT_STATE];
  40143. if (state) {
  40144. if (state.type === ProxyType.ES5Object || state.type === ProxyType.ES5Array) {
  40145. // Create the final copy, with added keys and without deleted keys.
  40146. state.copy = shallowCopy(state.draft, true);
  40147. }
  40148. root = state.copy;
  40149. }
  40150. each(root, function (key, value) {
  40151. return finalizeProperty(immer, scope, root, state, root, key, value, rootPath);
  40152. });
  40153. return root;
  40154. }
  40155. function finalizeProperty(immer, scope, root, rootState, parentValue, prop, childValue, rootPath) {
  40156. if (childValue === parentValue) {
  40157. throw Error("Immer forbids circular references");
  40158. } // In the `finalizeTree` method, only the `root` object may be a draft.
  40159. var isDraftProp = !!rootState && parentValue === root;
  40160. var isSetMember = isSet(parentValue);
  40161. if (isDraft(childValue)) {
  40162. var path = rootPath && isDraftProp && !isSetMember && // Set objects are atomic since they have no keys.
  40163. !has(rootState.assigned, prop) // Skip deep patches for assigned keys.
  40164. ? rootPath.concat(prop) : undefined; // Drafts owned by `scope` are finalized here.
  40165. childValue = finalize(immer, childValue, scope, path);
  40166. set(parentValue, prop, childValue); // Drafts from another scope must prevent auto-freezing.
  40167. if (isDraft(childValue)) {
  40168. scope.canAutoFreeze = false;
  40169. }
  40170. } // Unchanged draft properties are ignored.
  40171. else if (isDraftProp && is(childValue, get(rootState.base, prop))) {
  40172. return;
  40173. } // Search new objects for unfinalized drafts. Frozen objects should never contain drafts.
  40174. // TODO: the recursion over here looks weird, shouldn't non-draft stuff have it's own recursion?
  40175. // especially the passing on of root and rootState doesn't make sense...
  40176. else if (isDraftable(childValue) && !Object.isFrozen(childValue)) {
  40177. each(childValue, function (key, grandChild) {
  40178. return finalizeProperty(immer, scope, root, rootState, childValue, key, grandChild, rootPath);
  40179. });
  40180. maybeFreeze(immer, childValue);
  40181. }
  40182. if (isDraftProp && immer.onAssign && !isSetMember) {
  40183. immer.onAssign(rootState, prop, childValue);
  40184. }
  40185. }
  40186. function maybeFreeze(immer, value, deep) {
  40187. if (deep === void 0) {
  40188. deep = false;
  40189. }
  40190. if (immer.autoFreeze && !isDraft(value)) {
  40191. freeze(value, deep);
  40192. }
  40193. }
  40194. /**
  40195. * Returns a new draft of the `base` object.
  40196. *
  40197. * The second argument is the parent draft-state (used internally).
  40198. */
  40199. function createProxy(base, parent) {
  40200. var isArray = Array.isArray(base);
  40201. var state = {
  40202. type: isArray ? ProxyType.ProxyArray : ProxyType.ProxyObject,
  40203. // Track which produce call this is associated with.
  40204. scope: parent ? parent.scope : ImmerScope.current,
  40205. // True for both shallow and deep changes.
  40206. modified: false,
  40207. // Used during finalization.
  40208. finalized: false,
  40209. // Track which properties have been assigned (true) or deleted (false).
  40210. assigned: {},
  40211. // The parent draft state.
  40212. parent: parent,
  40213. // The base state.
  40214. base: base,
  40215. // The base proxy.
  40216. draft: null,
  40217. // Any property proxies.
  40218. drafts: {},
  40219. // The base copy with any updated values.
  40220. copy: null,
  40221. // Called by the `produce` function.
  40222. revoke: null,
  40223. isManual: false
  40224. }; // the traps must target something, a bit like the 'real' base.
  40225. // but also, we need to be able to determine from the target what the relevant state is
  40226. // (to avoid creating traps per instance to capture the state in closure,
  40227. // and to avoid creating weird hidden properties as well)
  40228. // So the trick is to use 'state' as the actual 'target'! (and make sure we intercept everything)
  40229. // Note that in the case of an array, we put the state in an array to have better Reflect defaults ootb
  40230. var target = state;
  40231. var traps = objectTraps;
  40232. if (isArray) {
  40233. target = [state];
  40234. traps = arrayTraps;
  40235. } // TODO: optimization: might be faster, cheaper if we created a non-revocable proxy
  40236. // and administrate revoking ourselves
  40237. var _a = Proxy.revocable(target, traps),
  40238. revoke = _a.revoke,
  40239. proxy = _a.proxy;
  40240. state.draft = proxy;
  40241. state.revoke = revoke;
  40242. return proxy;
  40243. }
  40244. /**
  40245. * Object drafts
  40246. */
  40247. var objectTraps = {
  40248. get: function (state, prop) {
  40249. if (prop === DRAFT_STATE) { return state; }
  40250. var drafts = state.drafts; // Check for existing draft in unmodified state.
  40251. if (!state.modified && has(drafts, prop)) {
  40252. return drafts[prop];
  40253. }
  40254. var value = latest(state)[prop];
  40255. if (state.finalized || !isDraftable(value)) {
  40256. return value;
  40257. } // Check for existing draft in modified state.
  40258. if (state.modified) {
  40259. // Assigned values are never drafted. This catches any drafts we created, too.
  40260. if (value !== peek(state.base, prop)) { return value; } // Store drafts on the copy (when one exists).
  40261. // @ts-ignore
  40262. drafts = state.copy;
  40263. }
  40264. return drafts[prop] = state.scope.immer.createProxy(value, state);
  40265. },
  40266. has: function (state, prop) {
  40267. return prop in latest(state);
  40268. },
  40269. ownKeys: function (state) {
  40270. return Reflect.ownKeys(latest(state));
  40271. },
  40272. set: function (state, prop
  40273. /* strictly not, but helps TS */
  40274. , value) {
  40275. if (!state.modified) {
  40276. var baseValue = peek(state.base, prop); // Optimize based on value's truthiness. Truthy values are guaranteed to
  40277. // never be undefined, so we can avoid the `in` operator. Lastly, truthy
  40278. // values may be drafts, but falsy values are never drafts.
  40279. var isUnchanged = value ? is(baseValue, value) || value === state.drafts[prop] : is(baseValue, value) && prop in state.base;
  40280. if (isUnchanged) { return true; }
  40281. prepareCopy(state);
  40282. markChanged(state);
  40283. }
  40284. state.assigned[prop] = true; // @ts-ignore
  40285. state.copy[prop] = value;
  40286. return true;
  40287. },
  40288. deleteProperty: function (state, prop) {
  40289. // The `undefined` check is a fast path for pre-existing keys.
  40290. if (peek(state.base, prop) !== undefined || prop in state.base) {
  40291. state.assigned[prop] = false;
  40292. prepareCopy(state);
  40293. markChanged(state);
  40294. } else if (state.assigned[prop]) {
  40295. // if an originally not assigned property was deleted
  40296. delete state.assigned[prop];
  40297. } // @ts-ignore
  40298. if (state.copy) { delete state.copy[prop]; }
  40299. return true;
  40300. },
  40301. // Note: We never coerce `desc.value` into an Immer draft, because we can't make
  40302. // the same guarantee in ES5 mode.
  40303. getOwnPropertyDescriptor: function (state, prop) {
  40304. var owner = latest(state);
  40305. var desc = Reflect.getOwnPropertyDescriptor(owner, prop);
  40306. if (desc) {
  40307. desc.writable = true;
  40308. desc.configurable = state.type !== ProxyType.ProxyArray || prop !== "length";
  40309. }
  40310. return desc;
  40311. },
  40312. defineProperty: function () {
  40313. throw new Error("Object.defineProperty() cannot be used on an Immer draft"); // prettier-ignore
  40314. },
  40315. getPrototypeOf: function (state) {
  40316. return Object.getPrototypeOf(state.base);
  40317. },
  40318. setPrototypeOf: function () {
  40319. throw new Error("Object.setPrototypeOf() cannot be used on an Immer draft"); // prettier-ignore
  40320. }
  40321. };
  40322. /**
  40323. * Array drafts
  40324. */
  40325. var arrayTraps = {};
  40326. each(objectTraps, function (key, fn) {
  40327. // @ts-ignore
  40328. arrayTraps[key] = function () {
  40329. arguments[0] = arguments[0][0];
  40330. return fn.apply(this, arguments);
  40331. };
  40332. });
  40333. arrayTraps.deleteProperty = function (state, prop) {
  40334. if (isNaN(parseInt(prop))) {
  40335. throw new Error("Immer only supports deleting array indices"); // prettier-ignore
  40336. }
  40337. return objectTraps.deleteProperty.call(this, state[0], prop);
  40338. };
  40339. arrayTraps.set = function (state, prop, value) {
  40340. if (prop !== "length" && isNaN(parseInt(prop))) {
  40341. throw new Error("Immer only supports setting array indices and the 'length' property"); // prettier-ignore
  40342. }
  40343. return objectTraps.set.call(this, state[0], prop, value, state[0]);
  40344. };
  40345. /**
  40346. * Map drafts
  40347. */
  40348. // Access a property without creating an Immer draft.
  40349. function peek(draft, prop) {
  40350. var state = draft[DRAFT_STATE];
  40351. var desc = Reflect.getOwnPropertyDescriptor(state ? latest(state) : draft, prop);
  40352. return desc && desc.value;
  40353. }
  40354. function markChanged(state) {
  40355. if (!state.modified) {
  40356. state.modified = true;
  40357. if (state.type === ProxyType.ProxyObject || state.type === ProxyType.ProxyArray) {
  40358. var copy_1 = state.copy = shallowCopy(state.base);
  40359. each(state.drafts, function (key, value) {
  40360. // @ts-ignore
  40361. copy_1[key] = value;
  40362. });
  40363. state.drafts = undefined;
  40364. }
  40365. if (state.parent) {
  40366. markChanged(state.parent);
  40367. }
  40368. }
  40369. }
  40370. function prepareCopy(state) {
  40371. if (!state.copy) {
  40372. state.copy = shallowCopy(state.base);
  40373. }
  40374. }
  40375. function willFinalizeES5(scope, result, isReplaced) {
  40376. scope.drafts.forEach(function (draft) {
  40377. draft[DRAFT_STATE].finalizing = true;
  40378. });
  40379. if (!isReplaced) {
  40380. if (scope.patches) {
  40381. markChangesRecursively(scope.drafts[0]);
  40382. } // This is faster when we don't care about which attributes changed.
  40383. markChangesSweep(scope.drafts);
  40384. } // When a child draft is returned, look for changes.
  40385. else if (isDraft(result) && result[DRAFT_STATE].scope === scope) {
  40386. markChangesSweep(scope.drafts);
  40387. }
  40388. }
  40389. function createES5Proxy(base, parent) {
  40390. var isArray = Array.isArray(base);
  40391. var draft = clonePotentialDraft(base);
  40392. each(draft, function (prop) {
  40393. proxyProperty(draft, prop, isArray || isEnumerable(base, prop));
  40394. });
  40395. var state = {
  40396. type: isArray ? ProxyType.ES5Array : ProxyType.ES5Object,
  40397. scope: parent ? parent.scope : ImmerScope.current,
  40398. modified: false,
  40399. finalizing: false,
  40400. finalized: false,
  40401. assigned: {},
  40402. parent: parent,
  40403. base: base,
  40404. draft: draft,
  40405. copy: null,
  40406. revoked: false,
  40407. isManual: false
  40408. };
  40409. createHiddenProperty(draft, DRAFT_STATE, state);
  40410. return draft;
  40411. } // Access a property without creating an Immer draft.
  40412. function peek$1(draft, prop) {
  40413. var state = draft[DRAFT_STATE];
  40414. if (state && !state.finalizing) {
  40415. state.finalizing = true;
  40416. var value = draft[prop];
  40417. state.finalizing = false;
  40418. return value;
  40419. }
  40420. return draft[prop];
  40421. }
  40422. function get$1(state, prop) {
  40423. assertUnrevoked(state);
  40424. var value = peek$1(latest(state), prop);
  40425. if (state.finalizing) { return value; } // Create a draft if the value is unmodified.
  40426. if (value === peek$1(state.base, prop) && isDraftable(value)) {
  40427. prepareCopy$1(state); // @ts-ignore
  40428. return state.copy[prop] = state.scope.immer.createProxy(value, state);
  40429. }
  40430. return value;
  40431. }
  40432. function set$1(state, prop, value) {
  40433. assertUnrevoked(state);
  40434. state.assigned[prop] = true;
  40435. if (!state.modified) {
  40436. if (is(value, peek$1(latest(state), prop))) { return; }
  40437. markChangedES5(state);
  40438. prepareCopy$1(state);
  40439. } // @ts-ignore
  40440. state.copy[prop] = value;
  40441. }
  40442. function markChangedES5(state) {
  40443. if (!state.modified) {
  40444. state.modified = true;
  40445. if (state.parent) { markChangedES5(state.parent); }
  40446. }
  40447. }
  40448. function prepareCopy$1(state) {
  40449. if (!state.copy) { state.copy = clonePotentialDraft(state.base); }
  40450. }
  40451. function clonePotentialDraft(base) {
  40452. var state = base && base[DRAFT_STATE];
  40453. if (state) {
  40454. state.finalizing = true;
  40455. var draft = shallowCopy(state.draft, true);
  40456. state.finalizing = false;
  40457. return draft;
  40458. }
  40459. return shallowCopy(base);
  40460. } // property descriptors are recycled to make sure we don't create a get and set closure per property,
  40461. // but share them all instead
  40462. var descriptors = {};
  40463. function proxyProperty(draft, prop, enumerable) {
  40464. var desc = descriptors[prop];
  40465. if (desc) {
  40466. desc.enumerable = enumerable;
  40467. } else {
  40468. descriptors[prop] = desc = {
  40469. configurable: true,
  40470. enumerable: enumerable,
  40471. get: function () {
  40472. return get$1(this[DRAFT_STATE], prop);
  40473. },
  40474. set: function (value) {
  40475. set$1(this[DRAFT_STATE], prop, value);
  40476. }
  40477. };
  40478. }
  40479. Object.defineProperty(draft, prop, desc);
  40480. }
  40481. function assertUnrevoked(state) {
  40482. 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))); }
  40483. } // This looks expensive, but only proxies are visited, and only objects without known changes are scanned.
  40484. function markChangesSweep(drafts) {
  40485. // The natural order of drafts in the `scope` array is based on when they
  40486. // were accessed. By processing drafts in reverse natural order, we have a
  40487. // better chance of processing leaf nodes first. When a leaf node is known to
  40488. // have changed, we can avoid any traversal of its ancestor nodes.
  40489. for (var i = drafts.length - 1; i >= 0; i--) {
  40490. var state = drafts[i][DRAFT_STATE];
  40491. if (!state.modified) {
  40492. switch (state.type) {
  40493. case ProxyType.ES5Array:
  40494. if (hasArrayChanges(state)) { markChangedES5(state); }
  40495. break;
  40496. case ProxyType.ES5Object:
  40497. if (hasObjectChanges(state)) { markChangedES5(state); }
  40498. break;
  40499. }
  40500. }
  40501. }
  40502. }
  40503. function markChangesRecursively(object) {
  40504. if (!object || typeof object !== "object") { return; }
  40505. var state = object[DRAFT_STATE];
  40506. if (!state) { return; }
  40507. var base = state.base,
  40508. draft = state.draft,
  40509. assigned = state.assigned,
  40510. type = state.type;
  40511. if (type === ProxyType.ES5Object) {
  40512. // Look for added keys.
  40513. // TODO: looks quite duplicate to hasObjectChanges,
  40514. // probably there is a faster way to detect changes, as sweep + recurse seems to do some
  40515. // unnecessary work.
  40516. // also: probably we can store the information we detect here, to speed up tree finalization!
  40517. each(draft, function (key) {
  40518. if (key === DRAFT_STATE) { return; } // The `undefined` check is a fast path for pre-existing keys.
  40519. if (base[key] === undefined && !has(base, key)) {
  40520. assigned[key] = true;
  40521. markChangedES5(state);
  40522. } else if (!assigned[key]) {
  40523. // Only untouched properties trigger recursion.
  40524. markChangesRecursively(draft[key]);
  40525. }
  40526. }); // Look for removed keys.
  40527. each(base, function (key) {
  40528. // The `undefined` check is a fast path for pre-existing keys.
  40529. if (draft[key] === undefined && !has(draft, key)) {
  40530. assigned[key] = false;
  40531. markChangedES5(state);
  40532. }
  40533. });
  40534. } else if (type === ProxyType.ES5Array && hasArrayChanges(state)) {
  40535. markChangedES5(state);
  40536. assigned.length = true;
  40537. if (draft.length < base.length) {
  40538. for (var i = draft.length; i < base.length; i++) { assigned[i] = false; }
  40539. } else {
  40540. for (var i = base.length; i < draft.length; i++) { assigned[i] = true; }
  40541. }
  40542. for (var i = 0; i < draft.length; i++) {
  40543. // Only untouched indices trigger recursion.
  40544. if (assigned[i] === undefined) { markChangesRecursively(draft[i]); }
  40545. }
  40546. }
  40547. }
  40548. function hasObjectChanges(state) {
  40549. var base = state.base,
  40550. draft = state.draft; // Search for added keys and changed keys. Start at the back, because
  40551. // non-numeric keys are ordered by time of definition on the object.
  40552. var keys = Object.keys(draft);
  40553. for (var i = keys.length - 1; i >= 0; i--) {
  40554. var key = keys[i];
  40555. var baseValue = base[key]; // The `undefined` check is a fast path for pre-existing keys.
  40556. if (baseValue === undefined && !has(base, key)) {
  40557. return true;
  40558. } // Once a base key is deleted, future changes go undetected, because its
  40559. // descriptor is erased. This branch detects any missed changes.
  40560. else {
  40561. var value = draft[key];
  40562. var state_1 = value && value[DRAFT_STATE];
  40563. if (state_1 ? state_1.base !== baseValue : !is(value, baseValue)) {
  40564. return true;
  40565. }
  40566. }
  40567. } // At this point, no keys were added or changed.
  40568. // Compare key count to determine if keys were deleted.
  40569. return keys.length !== Object.keys(base).length;
  40570. }
  40571. function hasArrayChanges(state) {
  40572. var draft = state.draft;
  40573. if (draft.length !== state.base.length) { return true; } // See #116
  40574. // If we first shorten the length, our array interceptors will be removed.
  40575. // If after that new items are added, result in the same original length,
  40576. // those last items will have no intercepting property.
  40577. // So if there is no own descriptor on the last position, we know that items were removed and added
  40578. // N.B.: splice, unshift, etc only shift values around, but not prop descriptors, so we only have to check
  40579. // the last one
  40580. var descriptor = Object.getOwnPropertyDescriptor(draft, draft.length - 1); // descriptor can be null, but only for newly created sparse arrays, eg. new Array(10)
  40581. 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
  40582. return false;
  40583. }
  40584. var DraftMap = function (_super) {
  40585. if (!_super) {
  40586. /* istanbul ignore next */
  40587. throw new Error("Map is not polyfilled");
  40588. }
  40589. __extends(DraftMap, _super); // Create class manually, cause #502
  40590. function DraftMap(target, parent) {
  40591. this[DRAFT_STATE] = {
  40592. type: ProxyType.Map,
  40593. parent: parent,
  40594. scope: parent ? parent.scope : ImmerScope.current,
  40595. modified: false,
  40596. finalized: false,
  40597. copy: undefined,
  40598. assigned: undefined,
  40599. base: target,
  40600. draft: this,
  40601. isManual: false,
  40602. revoked: false
  40603. };
  40604. return this;
  40605. }
  40606. var p = DraftMap.prototype; // TODO: smaller build size if we create a util for Object.defineProperty
  40607. Object.defineProperty(p, "size", {
  40608. get: function () {
  40609. return latest(this[DRAFT_STATE]).size;
  40610. },
  40611. enumerable: true,
  40612. configurable: true
  40613. });
  40614. p.has = function (key) {
  40615. return latest(this[DRAFT_STATE]).has(key);
  40616. };
  40617. p.set = function (key, value) {
  40618. var state = this[DRAFT_STATE];
  40619. assertUnrevoked(state);
  40620. if (latest(state).get(key) !== value) {
  40621. prepareCopy$2(state);
  40622. state.scope.immer.markChanged(state);
  40623. state.assigned.set(key, true);
  40624. state.copy.set(key, value);
  40625. state.assigned.set(key, true);
  40626. }
  40627. return this;
  40628. };
  40629. p.delete = function (key) {
  40630. if (!this.has(key)) {
  40631. return false;
  40632. }
  40633. var state = this[DRAFT_STATE];
  40634. assertUnrevoked(state);
  40635. prepareCopy$2(state);
  40636. state.scope.immer.markChanged(state);
  40637. state.assigned.set(key, false);
  40638. state.copy.delete(key);
  40639. return true;
  40640. };
  40641. p.clear = function () {
  40642. var state = this[DRAFT_STATE];
  40643. assertUnrevoked(state);
  40644. prepareCopy$2(state);
  40645. state.scope.immer.markChanged(state);
  40646. state.assigned = new Map();
  40647. return state.copy.clear();
  40648. };
  40649. p.forEach = function (cb, thisArg) {
  40650. var _this = this;
  40651. var state = this[DRAFT_STATE];
  40652. latest(state).forEach(function (_value, key, _map) {
  40653. cb.call(thisArg, _this.get(key), key, _this);
  40654. });
  40655. };
  40656. p.get = function (key) {
  40657. var state = this[DRAFT_STATE];
  40658. assertUnrevoked(state);
  40659. var value = latest(state).get(key);
  40660. if (state.finalized || !isDraftable(value)) {
  40661. return value;
  40662. }
  40663. if (value !== state.base.get(key)) {
  40664. return value; // either already drafted or reassigned
  40665. } // despite what it looks, this creates a draft only once, see above condition
  40666. var draft = state.scope.immer.createProxy(value, state);
  40667. prepareCopy$2(state);
  40668. state.copy.set(key, draft);
  40669. return draft;
  40670. };
  40671. p.keys = function () {
  40672. return latest(this[DRAFT_STATE]).keys();
  40673. };
  40674. p.values = function () {
  40675. var _a;
  40676. var _this = this;
  40677. var iterator = this.keys();
  40678. return _a = {}, _a[iteratorSymbol] = function () {
  40679. return _this.values();
  40680. }, _a.next = function () {
  40681. var r = iterator.next();
  40682. /* istanbul ignore next */
  40683. if (r.done) { return r; }
  40684. var value = _this.get(r.value);
  40685. return {
  40686. done: false,
  40687. value: value
  40688. };
  40689. }, _a;
  40690. };
  40691. p.entries = function () {
  40692. var _a;
  40693. var _this = this;
  40694. var iterator = this.keys();
  40695. return _a = {}, _a[iteratorSymbol] = function () {
  40696. return _this.entries();
  40697. }, _a.next = function () {
  40698. var r = iterator.next();
  40699. /* istanbul ignore next */
  40700. if (r.done) { return r; }
  40701. var value = _this.get(r.value);
  40702. return {
  40703. done: false,
  40704. value: [r.value, value]
  40705. };
  40706. }, _a;
  40707. };
  40708. p[iteratorSymbol] = function () {
  40709. return this.entries();
  40710. };
  40711. return DraftMap;
  40712. }(Map);
  40713. function proxyMap(target, parent) {
  40714. // @ts-ignore
  40715. return new DraftMap(target, parent);
  40716. }
  40717. function prepareCopy$2(state) {
  40718. if (!state.copy) {
  40719. state.assigned = new Map();
  40720. state.copy = new Map(state.base);
  40721. }
  40722. }
  40723. var DraftSet = function (_super) {
  40724. if (!_super) {
  40725. /* istanbul ignore next */
  40726. throw new Error("Set is not polyfilled");
  40727. }
  40728. __extends(DraftSet, _super); // Create class manually, cause #502
  40729. function DraftSet(target, parent) {
  40730. this[DRAFT_STATE] = {
  40731. type: ProxyType.Set,
  40732. parent: parent,
  40733. scope: parent ? parent.scope : ImmerScope.current,
  40734. modified: false,
  40735. finalized: false,
  40736. copy: undefined,
  40737. base: target,
  40738. draft: this,
  40739. drafts: new Map(),
  40740. revoked: false,
  40741. isManual: false
  40742. };
  40743. return this;
  40744. }
  40745. var p = DraftSet.prototype;
  40746. Object.defineProperty(p, "size", {
  40747. get: function () {
  40748. return latest(this[DRAFT_STATE]).size;
  40749. },
  40750. enumerable: true,
  40751. configurable: true
  40752. });
  40753. p.has = function (value) {
  40754. var state = this[DRAFT_STATE];
  40755. assertUnrevoked(state); // bit of trickery here, to be able to recognize both the value, and the draft of its value
  40756. if (!state.copy) {
  40757. return state.base.has(value);
  40758. }
  40759. if (state.copy.has(value)) { return true; }
  40760. if (state.drafts.has(value) && state.copy.has(state.drafts.get(value))) { return true; }
  40761. return false;
  40762. };
  40763. p.add = function (value) {
  40764. var state = this[DRAFT_STATE];
  40765. assertUnrevoked(state);
  40766. if (state.copy) {
  40767. state.copy.add(value);
  40768. } else if (!state.base.has(value)) {
  40769. prepareCopy$3(state);
  40770. state.scope.immer.markChanged(state);
  40771. state.copy.add(value);
  40772. }
  40773. return this;
  40774. };
  40775. p.delete = function (value) {
  40776. if (!this.has(value)) {
  40777. return false;
  40778. }
  40779. var state = this[DRAFT_STATE];
  40780. assertUnrevoked(state);
  40781. prepareCopy$3(state);
  40782. state.scope.immer.markChanged(state);
  40783. return state.copy.delete(value) || (state.drafts.has(value) ? state.copy.delete(state.drafts.get(value)) :
  40784. /* istanbul ignore next */
  40785. false);
  40786. };
  40787. p.clear = function () {
  40788. var state = this[DRAFT_STATE];
  40789. assertUnrevoked(state);
  40790. prepareCopy$3(state);
  40791. state.scope.immer.markChanged(state);
  40792. return state.copy.clear();
  40793. };
  40794. p.values = function () {
  40795. var state = this[DRAFT_STATE];
  40796. assertUnrevoked(state);
  40797. prepareCopy$3(state);
  40798. return state.copy.values();
  40799. };
  40800. p.entries = function entries() {
  40801. var state = this[DRAFT_STATE];
  40802. assertUnrevoked(state);
  40803. prepareCopy$3(state);
  40804. return state.copy.entries();
  40805. };
  40806. p.keys = function () {
  40807. return this.values();
  40808. };
  40809. p[iteratorSymbol] = function () {
  40810. return this.values();
  40811. };
  40812. p.forEach = function forEach(cb, thisArg) {
  40813. var iterator = this.values();
  40814. var result = iterator.next();
  40815. while (!result.done) {
  40816. cb.call(thisArg, result.value, result.value, this);
  40817. result = iterator.next();
  40818. }
  40819. };
  40820. return DraftSet;
  40821. }(Set);
  40822. function proxySet(target, parent) {
  40823. // @ts-ignore
  40824. return new DraftSet(target, parent);
  40825. }
  40826. function prepareCopy$3(state) {
  40827. if (!state.copy) {
  40828. // create drafts for all entries to preserve insertion order
  40829. state.copy = new Set();
  40830. state.base.forEach(function (value) {
  40831. if (isDraftable(value)) {
  40832. var draft = state.scope.immer.createProxy(value, state);
  40833. state.drafts.set(value, draft);
  40834. state.copy.add(draft);
  40835. } else {
  40836. state.copy.add(value);
  40837. }
  40838. });
  40839. }
  40840. }
  40841. function generatePatches(state, basePath, patches, inversePatches) {
  40842. switch (state.type) {
  40843. case ProxyType.ProxyObject:
  40844. case ProxyType.ES5Object:
  40845. case ProxyType.Map:
  40846. return generatePatchesFromAssigned(state, basePath, patches, inversePatches);
  40847. case ProxyType.ES5Array:
  40848. case ProxyType.ProxyArray:
  40849. return generateArrayPatches(state, basePath, patches, inversePatches);
  40850. case ProxyType.Set:
  40851. return generateSetPatches(state, basePath, patches, inversePatches);
  40852. }
  40853. }
  40854. function generateArrayPatches(state, basePath, patches, inversePatches) {
  40855. var _a, _b;
  40856. var base = state.base,
  40857. assigned = state.assigned,
  40858. copy = state.copy;
  40859. /* istanbul ignore next */
  40860. if (!copy) { die(); } // Reduce complexity by ensuring `base` is never longer.
  40861. if (copy.length < base.length) {
  40862. _a = [copy, base], base = _a[0], copy = _a[1];
  40863. _b = [inversePatches, patches], patches = _b[0], inversePatches = _b[1];
  40864. }
  40865. var delta = copy.length - base.length; // Find the first replaced index.
  40866. var start = 0;
  40867. while (base[start] === copy[start] && start < base.length) {
  40868. ++start;
  40869. } // Find the last replaced index. Search from the end to optimize splice patches.
  40870. var end = base.length;
  40871. while (end > start && base[end - 1] === copy[end + delta - 1]) {
  40872. --end;
  40873. } // Process replaced indices.
  40874. for (var i = start; i < end; ++i) {
  40875. if (assigned[i] && copy[i] !== base[i]) {
  40876. var path = basePath.concat([i]);
  40877. patches.push({
  40878. op: "replace",
  40879. path: path,
  40880. value: copy[i]
  40881. });
  40882. inversePatches.push({
  40883. op: "replace",
  40884. path: path,
  40885. value: base[i]
  40886. });
  40887. }
  40888. }
  40889. var replaceCount = patches.length; // Process added indices.
  40890. for (var i = end + delta - 1; i >= end; --i) {
  40891. var path = basePath.concat([i]);
  40892. patches[replaceCount + i - end] = {
  40893. op: "add",
  40894. path: path,
  40895. value: copy[i]
  40896. };
  40897. inversePatches.push({
  40898. op: "remove",
  40899. path: path
  40900. });
  40901. }
  40902. } // This is used for both Map objects and normal objects.
  40903. function generatePatchesFromAssigned(state, basePath, patches, inversePatches) {
  40904. var base = state.base,
  40905. copy = state.copy;
  40906. each(state.assigned, function (key, assignedValue) {
  40907. var origValue = get(base, key);
  40908. var value = get(copy, key);
  40909. var op = !assignedValue ? "remove" : has(base, key) ? "replace" : "add";
  40910. if (origValue === value && op === "replace") { return; }
  40911. var path = basePath.concat(key);
  40912. patches.push(op === "remove" ? {
  40913. op: op,
  40914. path: path
  40915. } : {
  40916. op: op,
  40917. path: path,
  40918. value: value
  40919. });
  40920. inversePatches.push(op === "add" ? {
  40921. op: "remove",
  40922. path: path
  40923. } : op === "remove" ? {
  40924. op: "add",
  40925. path: path,
  40926. value: origValue
  40927. } : {
  40928. op: "replace",
  40929. path: path,
  40930. value: origValue
  40931. });
  40932. });
  40933. }
  40934. function generateSetPatches(state, basePath, patches, inversePatches) {
  40935. var base = state.base,
  40936. copy = state.copy;
  40937. var i = 0;
  40938. base.forEach(function (value) {
  40939. if (!copy.has(value)) {
  40940. var path = basePath.concat([i]);
  40941. patches.push({
  40942. op: "remove",
  40943. path: path,
  40944. value: value
  40945. });
  40946. inversePatches.unshift({
  40947. op: "add",
  40948. path: path,
  40949. value: value
  40950. });
  40951. }
  40952. i++;
  40953. });
  40954. i = 0;
  40955. copy.forEach(function (value) {
  40956. if (!base.has(value)) {
  40957. var path = basePath.concat([i]);
  40958. patches.push({
  40959. op: "add",
  40960. path: path,
  40961. value: value
  40962. });
  40963. inversePatches.unshift({
  40964. op: "remove",
  40965. path: path,
  40966. value: value
  40967. });
  40968. }
  40969. i++;
  40970. });
  40971. }
  40972. function applyPatches(draft, patches) {
  40973. patches.forEach(function (patch) {
  40974. var path = patch.path,
  40975. op = patch.op;
  40976. /* istanbul ignore next */
  40977. if (!path.length) { die(); }
  40978. var base = draft;
  40979. for (var i = 0; i < path.length - 1; i++) {
  40980. base = get(base, path[i]);
  40981. if (!base || typeof base !== "object") { throw new Error("Cannot apply patch, path doesn't resolve: " + path.join("/")); } // prettier-ignore
  40982. }
  40983. var type = getArchtype(base);
  40984. var value = deepClonePatchValue(patch.value); // used to clone patch to ensure original patch is not modified, see #411
  40985. var key = path[path.length - 1];
  40986. switch (op) {
  40987. case "replace":
  40988. switch (type) {
  40989. case Archtype.Map:
  40990. return base.set(key, value);
  40991. /* istanbul ignore next */
  40992. case Archtype.Set:
  40993. throw new Error('Sets cannot have "replace" patches.');
  40994. default:
  40995. // if value is an object, then it's assigned by reference
  40996. // in the following add or remove ops, the value field inside the patch will also be modifyed
  40997. // so we use value from the cloned patch
  40998. // @ts-ignore
  40999. return base[key] = value;
  41000. }
  41001. case "add":
  41002. switch (type) {
  41003. case Archtype.Array:
  41004. return base.splice(key, 0, value);
  41005. case Archtype.Map:
  41006. return base.set(key, value);
  41007. case Archtype.Set:
  41008. return base.add(value);
  41009. default:
  41010. return base[key] = value;
  41011. }
  41012. case "remove":
  41013. switch (type) {
  41014. case Archtype.Array:
  41015. return base.splice(key, 1);
  41016. case Archtype.Map:
  41017. return base.delete(key);
  41018. case Archtype.Set:
  41019. return base.delete(patch.value);
  41020. default:
  41021. return delete base[key];
  41022. }
  41023. default:
  41024. throw new Error("Unsupported patch operation: " + op);
  41025. }
  41026. });
  41027. return draft;
  41028. }
  41029. function deepClonePatchValue(obj) {
  41030. if (!obj || typeof obj !== "object") { return obj; }
  41031. if (Array.isArray(obj)) { return obj.map(deepClonePatchValue); }
  41032. if (isMap(obj)) { return new Map(Array.from(obj.entries()).map(function (_a) {
  41033. var k = _a[0],
  41034. v = _a[1];
  41035. return [k, deepClonePatchValue(v)];
  41036. })); } // Not needed: if (isSet(obj)) return new Set(Array.from(obj.values()).map(deepClone))
  41037. var cloned = Object.create(Object.getPrototypeOf(obj));
  41038. for (var key in obj) { cloned[key] = deepClonePatchValue(obj[key]); }
  41039. return cloned;
  41040. }
  41041. /*! *****************************************************************************
  41042. Copyright (c) Microsoft Corporation. All rights reserved.
  41043. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  41044. this file except in compliance with the License. You may obtain a copy of the
  41045. License at http://www.apache.org/licenses/LICENSE-2.0
  41046. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41047. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  41048. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  41049. MERCHANTABLITY OR NON-INFRINGEMENT.
  41050. See the Apache Version 2.0 License for specific language governing permissions
  41051. and limitations under the License.
  41052. ***************************************************************************** */
  41053. function __spreadArrays() {
  41054. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  41055. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  41056. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  41057. r[k] = a[j];
  41058. return r;
  41059. }
  41060. /* istanbul ignore next */
  41061. function verifyMinified() {}
  41062. var configDefaults = {
  41063. useProxies: typeof Proxy !== "undefined" && typeof Proxy.revocable !== "undefined" && typeof Reflect !== "undefined",
  41064. autoFreeze: typeof process !== "undefined" ? process.env.NODE_ENV !== "production" :
  41065. /* istanbul ignore next */
  41066. verifyMinified.name === "verifyMinified",
  41067. onAssign: null,
  41068. onDelete: null,
  41069. onCopy: null
  41070. };
  41071. var Immer =
  41072. /** @class */
  41073. function () {
  41074. function Immer(config) {
  41075. var _this = this;
  41076. this.useProxies = false;
  41077. this.autoFreeze = false;
  41078. each(configDefaults, function (key, value) {
  41079. var _a, _b; // @ts-ignore
  41080. _this[key] = (_b = (_a = config) === null || _a === void 0 ? void 0 : _a[key], _b !== null && _b !== void 0 ? _b : value);
  41081. });
  41082. this.setUseProxies(this.useProxies);
  41083. this.produce = this.produce.bind(this);
  41084. this.produceWithPatches = this.produceWithPatches.bind(this);
  41085. }
  41086. /**
  41087. * The `produce` function takes a value and a "recipe function" (whose
  41088. * return value often depends on the base state). The recipe function is
  41089. * free to mutate its first argument however it wants. All mutations are
  41090. * only ever applied to a __copy__ of the base state.
  41091. *
  41092. * Pass only a function to create a "curried producer" which relieves you
  41093. * from passing the recipe function every time.
  41094. *
  41095. * Only plain objects and arrays are made mutable. All other objects are
  41096. * considered uncopyable.
  41097. *
  41098. * Note: This function is __bound__ to its `Immer` instance.
  41099. *
  41100. * @param {any} base - the initial state
  41101. * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified
  41102. * @param {Function} patchListener - optional function that will be called with all the patches produced here
  41103. * @returns {any} a new state, or the initial state if nothing was modified
  41104. */
  41105. Immer.prototype.produce = function (base, recipe, patchListener) {
  41106. var _this = this; // curried invocation
  41107. if (typeof base === "function" && typeof recipe !== "function") {
  41108. var defaultBase_1 = recipe;
  41109. recipe = base;
  41110. var self_1 = this;
  41111. return function curriedProduce(base) {
  41112. var arguments$1 = arguments;
  41113. var _this = this;
  41114. if (base === void 0) {
  41115. base = defaultBase_1;
  41116. }
  41117. var args = [];
  41118. for (var _i = 1; _i < arguments.length; _i++) {
  41119. args[_i - 1] = arguments$1[_i];
  41120. }
  41121. return self_1.produce(base, function (draft) {
  41122. return recipe.call.apply(recipe, __spreadArrays([_this, draft], args));
  41123. }); // prettier-ignore
  41124. };
  41125. } // prettier-ignore
  41126. {
  41127. if (typeof recipe !== "function") {
  41128. throw new Error("The first or second argument to `produce` must be a function");
  41129. }
  41130. if (patchListener !== undefined && typeof patchListener !== "function") {
  41131. throw new Error("The third argument to `produce` must be a function or undefined");
  41132. }
  41133. }
  41134. var result; // Only plain objects, arrays, and "immerable classes" are drafted.
  41135. if (isDraftable(base)) {
  41136. var scope_1 = ImmerScope.enter(this);
  41137. var proxy = this.createProxy(base, undefined);
  41138. var hasError = true;
  41139. try {
  41140. result = recipe(proxy);
  41141. hasError = false;
  41142. } finally {
  41143. // finally instead of catch + rethrow better preserves original stack
  41144. if (hasError) { scope_1.revoke(); }else { scope_1.leave(); }
  41145. }
  41146. if (typeof Promise !== "undefined" && result instanceof Promise) {
  41147. return result.then(function (result) {
  41148. scope_1.usePatches(patchListener);
  41149. return processResult(_this, result, scope_1);
  41150. }, function (error) {
  41151. scope_1.revoke();
  41152. throw error;
  41153. });
  41154. }
  41155. scope_1.usePatches(patchListener);
  41156. return processResult(this, result, scope_1);
  41157. } else {
  41158. result = recipe(base);
  41159. if (result === NOTHING) { return undefined; }
  41160. if (result === undefined) { result = base; }
  41161. maybeFreeze(this, result, true);
  41162. return result;
  41163. }
  41164. };
  41165. Immer.prototype.produceWithPatches = function (arg1, arg2, arg3) {
  41166. var _this = this;
  41167. if (typeof arg1 === "function") {
  41168. return function (state) {
  41169. var arguments$1 = arguments;
  41170. var args = [];
  41171. for (var _i = 1; _i < arguments.length; _i++) {
  41172. args[_i - 1] = arguments$1[_i];
  41173. }
  41174. return _this.produceWithPatches(state, function (draft) {
  41175. return arg1.apply(void 0, __spreadArrays([draft], args));
  41176. });
  41177. };
  41178. } // non-curried form
  41179. /* istanbul ignore next */
  41180. if (arg3) { die(); }
  41181. var patches, inversePatches;
  41182. var nextState = this.produce(arg1, arg2, function (p, ip) {
  41183. patches = p;
  41184. inversePatches = ip;
  41185. });
  41186. return [nextState, patches, inversePatches];
  41187. };
  41188. Immer.prototype.createDraft = function (base) {
  41189. if (!isDraftable(base)) {
  41190. throw new Error("First argument to `createDraft` must be a plain object, an array, or an immerable object"); // prettier-ignore
  41191. }
  41192. var scope = ImmerScope.enter(this);
  41193. var proxy = this.createProxy(base, undefined);
  41194. proxy[DRAFT_STATE].isManual = true;
  41195. scope.leave();
  41196. return proxy;
  41197. };
  41198. Immer.prototype.finishDraft = function (draft, patchListener) {
  41199. var state = draft && draft[DRAFT_STATE];
  41200. if (!state || !state.isManual) {
  41201. throw new Error("First argument to `finishDraft` must be a draft returned by `createDraft`"); // prettier-ignore
  41202. }
  41203. if (state.finalized) {
  41204. throw new Error("The given draft is already finalized"); // prettier-ignore
  41205. }
  41206. var scope = state.scope;
  41207. scope.usePatches(patchListener);
  41208. return processResult(this, undefined, scope);
  41209. };
  41210. /**
  41211. * Pass true to automatically freeze all copies created by Immer.
  41212. *
  41213. * By default, auto-freezing is disabled in production.
  41214. */
  41215. Immer.prototype.setAutoFreeze = function (value) {
  41216. this.autoFreeze = value;
  41217. };
  41218. /**
  41219. * Pass true to use the ES2015 `Proxy` class when creating drafts, which is
  41220. * always faster than using ES5 proxies.
  41221. *
  41222. * By default, feature detection is used, so calling this is rarely necessary.
  41223. */
  41224. Immer.prototype.setUseProxies = function (value) {
  41225. this.useProxies = value;
  41226. };
  41227. Immer.prototype.applyPatches = function (base, patches) {
  41228. // If a patch replaces the entire state, take that replacement as base
  41229. // before applying patches
  41230. var i;
  41231. for (i = patches.length - 1; i >= 0; i--) {
  41232. var patch = patches[i];
  41233. if (patch.path.length === 0 && patch.op === "replace") {
  41234. base = patch.value;
  41235. break;
  41236. }
  41237. }
  41238. if (isDraft(base)) {
  41239. // N.B: never hits if some patch a replacement, patches are never drafts
  41240. return applyPatches(base, patches);
  41241. } // Otherwise, produce a copy of the base state.
  41242. return this.produce(base, function (draft) {
  41243. return applyPatches(draft, patches.slice(i + 1));
  41244. });
  41245. };
  41246. Immer.prototype.createProxy = function (value, parent) {
  41247. // precondition: createProxy should be guarded by isDraftable, so we know we can safely draft
  41248. var draft = isMap(value) ? proxyMap(value, parent) : isSet(value) ? proxySet(value, parent) : this.useProxies ? createProxy(value, parent) : createES5Proxy(value, parent);
  41249. var scope = parent ? parent.scope : ImmerScope.current;
  41250. scope.drafts.push(draft);
  41251. return draft;
  41252. };
  41253. Immer.prototype.willFinalize = function (scope, thing, isReplaced) {
  41254. if (!this.useProxies) { willFinalizeES5(scope, thing, isReplaced); }
  41255. };
  41256. Immer.prototype.markChanged = function (state) {
  41257. if (this.useProxies) {
  41258. markChanged(state);
  41259. } else {
  41260. markChangedES5(state);
  41261. }
  41262. };
  41263. return Immer;
  41264. }();
  41265. var immer = new Immer();
  41266. /**
  41267. * The `produce` function takes a value and a "recipe function" (whose
  41268. * return value often depends on the base state). The recipe function is
  41269. * free to mutate its first argument however it wants. All mutations are
  41270. * only ever applied to a __copy__ of the base state.
  41271. *
  41272. * Pass only a function to create a "curried producer" which relieves you
  41273. * from passing the recipe function every time.
  41274. *
  41275. * Only plain objects and arrays are made mutable. All other objects are
  41276. * considered uncopyable.
  41277. *
  41278. * Note: This function is __bound__ to its `Immer` instance.
  41279. *
  41280. * @param {any} base - the initial state
  41281. * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified
  41282. * @param {Function} patchListener - optional function that will be called with all the patches produced here
  41283. * @returns {any} a new state, or the initial state if nothing was modified
  41284. */
  41285. var produce = immer.produce;
  41286. /**
  41287. * Like `produce`, but `produceWithPatches` always returns a tuple
  41288. * [nextState, patches, inversePatches] (instead of just the next state)
  41289. */
  41290. var produceWithPatches = immer.produceWithPatches.bind(immer);
  41291. /**
  41292. * Pass true to automatically freeze all copies created by Immer.
  41293. *
  41294. * By default, auto-freezing is disabled in production.
  41295. */
  41296. var setAutoFreeze = immer.setAutoFreeze.bind(immer);
  41297. /**
  41298. * Pass true to use the ES2015 `Proxy` class when creating drafts, which is
  41299. * always faster than using ES5 proxies.
  41300. *
  41301. * By default, feature detection is used, so calling this is rarely necessary.
  41302. */
  41303. var setUseProxies = immer.setUseProxies.bind(immer);
  41304. /**
  41305. * Apply an array of Immer patches to the first argument.
  41306. *
  41307. * This function is a producer, which means copy-on-write is in effect.
  41308. */
  41309. var applyPatches$1 = immer.applyPatches.bind(immer);
  41310. /**
  41311. * Create an Immer draft from the given base state, which may be a draft itself.
  41312. * The draft can be modified until you finalize it with the `finishDraft` function.
  41313. */
  41314. var createDraft = immer.createDraft.bind(immer);
  41315. /**
  41316. * Finalize an Immer draft from a `createDraft` call, returning the base state
  41317. * (if no changes were made) or a modified copy. The draft must *not* be
  41318. * mutated afterwards.
  41319. *
  41320. * Pass a function as the 2nd argument to generate Immer patches based on the
  41321. * changes that were made.
  41322. */
  41323. var finishDraft = immer.finishDraft.bind(immer);
  41324. /**
  41325. * This function is actually a no-op, but can be used to cast an immutable type
  41326. * to an draft type and make TypeScript happy
  41327. *
  41328. * @param value
  41329. */
  41330. function castDraft(value) {
  41331. return value;
  41332. }
  41333. /**
  41334. * This function is actually a no-op, but can be used to cast a mutable type
  41335. * to an immutable type and make TypeScript happy
  41336. * @param value
  41337. */
  41338. function castImmutable(value) {
  41339. return value;
  41340. }
  41341. exports.Immer = Immer;
  41342. exports.applyPatches = applyPatches$1;
  41343. exports.castDraft = castDraft;
  41344. exports.castImmutable = castImmutable;
  41345. exports.createDraft = createDraft;
  41346. exports.default = produce;
  41347. exports.finishDraft = finishDraft;
  41348. exports.immerable = DRAFTABLE;
  41349. exports.isDraft = isDraft;
  41350. exports.isDraftable = isDraftable;
  41351. exports.nothing = NOTHING;
  41352. exports.original = original;
  41353. exports.produce = produce;
  41354. exports.produceWithPatches = produceWithPatches;
  41355. exports.setAutoFreeze = setAutoFreeze;
  41356. exports.setUseProxies = setUseProxies;
  41357. });
  41358. styleInject_es.unwrapExports(immer_1);
  41359. var immer_2 = immer_1.Immer;
  41360. var immer_3 = immer_1.applyPatches;
  41361. var immer_4 = immer_1.castDraft;
  41362. var immer_5 = immer_1.castImmutable;
  41363. var immer_6 = immer_1.createDraft;
  41364. var immer_7 = immer_1.finishDraft;
  41365. var immer_8 = immer_1.immerable;
  41366. var immer_9 = immer_1.isDraft;
  41367. var immer_10 = immer_1.isDraftable;
  41368. var immer_11 = immer_1.nothing;
  41369. var immer_12 = immer_1.original;
  41370. var immer_13 = immer_1.produce;
  41371. var immer_14 = immer_1.produceWithPatches;
  41372. var immer_15 = immer_1.setAutoFreeze;
  41373. var immer_16 = immer_1.setUseProxies;
  41374. var esrever = styleInject_es.createCommonjsModule(function (module, exports) {
  41375. (function(root) {
  41376. // Detect free variables `exports`
  41377. var freeExports = exports;
  41378. // Detect free variable `module`
  41379. var freeModule = module &&
  41380. module.exports == freeExports && module;
  41381. // Detect free variable `global`, from Node.js or Browserified code,
  41382. // and use it as `root`
  41383. var freeGlobal = typeof styleInject_es.commonjsGlobal == 'object' && styleInject_es.commonjsGlobal;
  41384. if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
  41385. root = freeGlobal;
  41386. }
  41387. /*--------------------------------------------------------------------------*/
  41388. 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;
  41389. var regexSurrogatePair = /([\uD800-\uDBFF])([\uDC00-\uDFFF])/g;
  41390. var reverse = function(string) {
  41391. // Step 1: deal with combining marks and astral symbols (surrogate pairs)
  41392. string = string
  41393. // Swap symbols with their combining marks so the combining marks go first
  41394. .replace(regexSymbolWithCombiningMarks, function($0, $1, $2) {
  41395. // Reverse the combining marks so they will end up in the same order
  41396. // later on (after another round of reversing)
  41397. return reverse($2) + $1;
  41398. })
  41399. // Swap high and low surrogates so the low surrogates go first
  41400. .replace(regexSurrogatePair, '$2$1');
  41401. // Step 2: reverse the code units in the string
  41402. var result = '';
  41403. var index = string.length;
  41404. while (index--) {
  41405. result += string.charAt(index);
  41406. }
  41407. return result;
  41408. };
  41409. /*--------------------------------------------------------------------------*/
  41410. var esrever = {
  41411. 'version': '0.2.0',
  41412. 'reverse': reverse
  41413. };
  41414. // Some AMD build optimizers, like r.js, check for specific condition patterns
  41415. // like the following:
  41416. if (freeExports && !freeExports.nodeType) {
  41417. if (freeModule) { // in Node.js, io.js, or RingoJS v0.8.0+
  41418. freeModule.exports = esrever;
  41419. } else { // in Narwhal or RingoJS v0.7.0-
  41420. for (var key in esrever) {
  41421. esrever.hasOwnProperty(key) && (freeExports[key] = esrever[key]);
  41422. }
  41423. }
  41424. } else { // in Rhino or a web browser
  41425. root.esrever = esrever;
  41426. }
  41427. }(styleInject_es.commonjsGlobal));
  41428. });
  41429. var dist$5 = styleInject_es.createCommonjsModule(function (module, exports) {
  41430. Object.defineProperty(exports, '__esModule', { value: true });
  41431. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  41432. var isPlainObject = _interopDefault(index_cjs);
  41433. function _defineProperty(obj, key, value) {
  41434. if (key in obj) {
  41435. Object.defineProperty(obj, key, {
  41436. value: value,
  41437. enumerable: true,
  41438. configurable: true,
  41439. writable: true
  41440. });
  41441. } else {
  41442. obj[key] = value;
  41443. }
  41444. return obj;
  41445. }
  41446. var DIRTY_PATHS = new WeakMap();
  41447. var FLUSHING = new WeakMap();
  41448. var NORMALIZING = new WeakMap();
  41449. var PATH_REFS = new WeakMap();
  41450. var POINT_REFS = new WeakMap();
  41451. var RANGE_REFS = new WeakMap();
  41452. 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; }
  41453. 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; }
  41454. /**
  41455. * Create a new Slate `Editor` object.
  41456. */
  41457. var createEditor = () => {
  41458. var editor = {
  41459. children: [],
  41460. operations: [],
  41461. selection: null,
  41462. marks: null,
  41463. isInline: () => false,
  41464. isVoid: () => false,
  41465. onChange: () => {},
  41466. apply: op => {
  41467. for (var ref of Editor.pathRefs(editor)) {
  41468. PathRef.transform(ref, op);
  41469. }
  41470. for (var _ref of Editor.pointRefs(editor)) {
  41471. PointRef.transform(_ref, op);
  41472. }
  41473. for (var _ref2 of Editor.rangeRefs(editor)) {
  41474. RangeRef.transform(_ref2, op);
  41475. }
  41476. var set = new Set();
  41477. var dirtyPaths = [];
  41478. var add = path => {
  41479. if (path) {
  41480. var key = path.join(',');
  41481. if (!set.has(key)) {
  41482. set.add(key);
  41483. dirtyPaths.push(path);
  41484. }
  41485. }
  41486. };
  41487. var oldDirtyPaths = DIRTY_PATHS.get(editor) || [];
  41488. var newDirtyPaths = getDirtyPaths(op);
  41489. for (var path of oldDirtyPaths) {
  41490. var newPath = Path.transform(path, op);
  41491. add(newPath);
  41492. }
  41493. for (var _path of newDirtyPaths) {
  41494. add(_path);
  41495. }
  41496. DIRTY_PATHS.set(editor, dirtyPaths);
  41497. Editor.transform(editor, op);
  41498. editor.operations.push(op);
  41499. Editor.normalize(editor); // Clear any formats applied to the cursor if the selection changes.
  41500. if (op.type === 'set_selection') {
  41501. editor.marks = null;
  41502. }
  41503. if (!FLUSHING.get(editor)) {
  41504. FLUSHING.set(editor, true);
  41505. Promise.resolve().then(() => {
  41506. FLUSHING.set(editor, false);
  41507. editor.onChange();
  41508. editor.operations = [];
  41509. });
  41510. }
  41511. },
  41512. addMark: (key, value) => {
  41513. var {
  41514. selection
  41515. } = editor;
  41516. if (selection) {
  41517. if (Range.isExpanded(selection)) {
  41518. Transforms.setNodes(editor, {
  41519. [key]: value
  41520. }, {
  41521. match: Text.isText,
  41522. split: true
  41523. });
  41524. } else {
  41525. var marks = _objectSpread({}, Editor.marks(editor) || {}, {
  41526. [key]: value
  41527. });
  41528. editor.marks = marks;
  41529. editor.onChange();
  41530. }
  41531. }
  41532. },
  41533. deleteBackward: unit => {
  41534. var {
  41535. selection
  41536. } = editor;
  41537. if (selection && Range.isCollapsed(selection)) {
  41538. Transforms.delete(editor, {
  41539. unit,
  41540. reverse: true
  41541. });
  41542. }
  41543. },
  41544. deleteForward: unit => {
  41545. var {
  41546. selection
  41547. } = editor;
  41548. if (selection && Range.isCollapsed(selection)) {
  41549. Transforms.delete(editor, {
  41550. unit
  41551. });
  41552. }
  41553. },
  41554. deleteFragment: () => {
  41555. var {
  41556. selection
  41557. } = editor;
  41558. if (selection && Range.isExpanded(selection)) {
  41559. Transforms.delete(editor);
  41560. }
  41561. },
  41562. insertBreak: () => {
  41563. Transforms.splitNodes(editor, {
  41564. always: true
  41565. });
  41566. },
  41567. insertFragment: fragment => {
  41568. Transforms.insertFragment(editor, fragment);
  41569. },
  41570. insertNode: node => {
  41571. Transforms.insertNodes(editor, node);
  41572. },
  41573. insertText: text => {
  41574. var {
  41575. selection,
  41576. marks
  41577. } = editor;
  41578. if (selection) {
  41579. // If the cursor is at the end of an inline, move it outside of
  41580. // the inline before inserting
  41581. if (Range.isCollapsed(selection)) {
  41582. var inline = Editor.above(editor, {
  41583. match: n => Editor.isInline(editor, n),
  41584. mode: 'highest'
  41585. });
  41586. if (inline) {
  41587. var [, inlinePath] = inline;
  41588. if (Editor.isEnd(editor, selection.anchor, inlinePath)) {
  41589. var point = Editor.after(editor, inlinePath);
  41590. Transforms.setSelection(editor, {
  41591. anchor: point,
  41592. focus: point
  41593. });
  41594. }
  41595. }
  41596. }
  41597. if (marks) {
  41598. var node = _objectSpread({
  41599. text
  41600. }, marks);
  41601. Transforms.insertNodes(editor, node);
  41602. } else {
  41603. Transforms.insertText(editor, text);
  41604. }
  41605. editor.marks = null;
  41606. }
  41607. },
  41608. normalizeNode: entry => {
  41609. var [node, path] = entry; // There are no core normalizations for text nodes.
  41610. if (Text.isText(node)) {
  41611. return;
  41612. } // Ensure that block and inline nodes have at least one text child.
  41613. if (Element.isElement(node) && node.children.length === 0) {
  41614. var child = {
  41615. text: ''
  41616. };
  41617. Transforms.insertNodes(editor, child, {
  41618. at: path.concat(0),
  41619. voids: true
  41620. });
  41621. return;
  41622. } // Determine whether the node should have block or inline children.
  41623. 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
  41624. // index that accounts for any added/removed nodes.
  41625. var n = 0;
  41626. for (var i = 0; i < node.children.length; i++, n++) {
  41627. var _child = node.children[i];
  41628. var prev = node.children[i - 1];
  41629. var isLast = i === node.children.length - 1;
  41630. var isInlineOrText = Text.isText(_child) || Element.isElement(_child) && editor.isInline(_child); // Only allow block nodes in the top-level children and parent blocks
  41631. // that only contain block nodes. Similarly, only allow inline nodes in
  41632. // other inline nodes, or parent blocks that only contain inlines and
  41633. // text.
  41634. if (isInlineOrText !== shouldHaveInlines) {
  41635. Transforms.removeNodes(editor, {
  41636. at: path.concat(n),
  41637. voids: true
  41638. });
  41639. n--;
  41640. } else if (Element.isElement(_child)) {
  41641. // Ensure that inline nodes are surrounded by text nodes.
  41642. if (editor.isInline(_child)) {
  41643. if (prev == null || !Text.isText(prev)) {
  41644. var newChild = {
  41645. text: ''
  41646. };
  41647. Transforms.insertNodes(editor, newChild, {
  41648. at: path.concat(n),
  41649. voids: true
  41650. });
  41651. n++;
  41652. } else if (isLast) {
  41653. var _newChild = {
  41654. text: ''
  41655. };
  41656. Transforms.insertNodes(editor, _newChild, {
  41657. at: path.concat(n + 1),
  41658. voids: true
  41659. });
  41660. n++;
  41661. }
  41662. }
  41663. } else {
  41664. // Merge adjacent text nodes that are empty or match.
  41665. if (prev != null && Text.isText(prev)) {
  41666. if (Text.equals(_child, prev, {
  41667. loose: true
  41668. })) {
  41669. Transforms.mergeNodes(editor, {
  41670. at: path.concat(n),
  41671. voids: true
  41672. });
  41673. n--;
  41674. } else if (prev.text === '') {
  41675. Transforms.removeNodes(editor, {
  41676. at: path.concat(n - 1),
  41677. voids: true
  41678. });
  41679. n--;
  41680. } else if (isLast && _child.text === '') {
  41681. Transforms.removeNodes(editor, {
  41682. at: path.concat(n),
  41683. voids: true
  41684. });
  41685. n--;
  41686. }
  41687. }
  41688. }
  41689. }
  41690. },
  41691. removeMark: key => {
  41692. var {
  41693. selection
  41694. } = editor;
  41695. if (selection) {
  41696. if (Range.isExpanded(selection)) {
  41697. Transforms.unsetNodes(editor, key, {
  41698. match: Text.isText,
  41699. split: true
  41700. });
  41701. } else {
  41702. var marks = _objectSpread({}, Editor.marks(editor) || {});
  41703. delete marks[key];
  41704. editor.marks = marks;
  41705. editor.onChange();
  41706. }
  41707. }
  41708. }
  41709. };
  41710. return editor;
  41711. };
  41712. /**
  41713. * Get the "dirty" paths generated from an operation.
  41714. */
  41715. var getDirtyPaths = op => {
  41716. switch (op.type) {
  41717. case 'insert_text':
  41718. case 'remove_text':
  41719. case 'set_node':
  41720. {
  41721. var {
  41722. path
  41723. } = op;
  41724. return Path.levels(path);
  41725. }
  41726. case 'insert_node':
  41727. {
  41728. var {
  41729. node,
  41730. path: _path2
  41731. } = op;
  41732. var levels = Path.levels(_path2);
  41733. var descendants = Text.isText(node) ? [] : Array.from(Node.nodes(node), (_ref3) => {
  41734. var [, p] = _ref3;
  41735. return _path2.concat(p);
  41736. });
  41737. return [...levels, ...descendants];
  41738. }
  41739. case 'merge_node':
  41740. {
  41741. var {
  41742. path: _path3
  41743. } = op;
  41744. var ancestors = Path.ancestors(_path3);
  41745. var previousPath = Path.previous(_path3);
  41746. return [...ancestors, previousPath];
  41747. }
  41748. case 'move_node':
  41749. {
  41750. var {
  41751. path: _path4,
  41752. newPath
  41753. } = op;
  41754. if (Path.equals(_path4, newPath)) {
  41755. return [];
  41756. }
  41757. var oldAncestors = [];
  41758. var newAncestors = [];
  41759. for (var ancestor of Path.ancestors(_path4)) {
  41760. var p = Path.transform(ancestor, op);
  41761. oldAncestors.push(p);
  41762. }
  41763. for (var _ancestor of Path.ancestors(newPath)) {
  41764. var _p = Path.transform(_ancestor, op);
  41765. newAncestors.push(_p);
  41766. }
  41767. return [...oldAncestors, ...newAncestors];
  41768. }
  41769. case 'remove_node':
  41770. {
  41771. var {
  41772. path: _path5
  41773. } = op;
  41774. var _ancestors = Path.ancestors(_path5);
  41775. return [..._ancestors];
  41776. }
  41777. case 'split_node':
  41778. {
  41779. var {
  41780. path: _path6
  41781. } = op;
  41782. var _levels = Path.levels(_path6);
  41783. var nextPath = Path.next(_path6);
  41784. return [..._levels, nextPath];
  41785. }
  41786. default:
  41787. {
  41788. return [];
  41789. }
  41790. }
  41791. };
  41792. function _objectWithoutPropertiesLoose(source, excluded) {
  41793. if (source == null) return {};
  41794. var target = {};
  41795. var sourceKeys = Object.keys(source);
  41796. var key, i;
  41797. for (i = 0; i < sourceKeys.length; i++) {
  41798. key = sourceKeys[i];
  41799. if (excluded.indexOf(key) >= 0) continue;
  41800. target[key] = source[key];
  41801. }
  41802. return target;
  41803. }
  41804. function _objectWithoutProperties(source, excluded) {
  41805. if (source == null) return {};
  41806. var target = _objectWithoutPropertiesLoose(source, excluded);
  41807. var key, i;
  41808. if (Object.getOwnPropertySymbols) {
  41809. var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
  41810. for (i = 0; i < sourceSymbolKeys.length; i++) {
  41811. key = sourceSymbolKeys[i];
  41812. if (excluded.indexOf(key) >= 0) continue;
  41813. if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
  41814. target[key] = source[key];
  41815. }
  41816. }
  41817. return target;
  41818. }
  41819. /**
  41820. * Constants for string distance checking.
  41821. */
  41822. var SPACE = /\s/;
  41823. 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]/;
  41824. var CHAMELEON = /['\u2018\u2019]/;
  41825. var SURROGATE_START = 0xd800;
  41826. var SURROGATE_END = 0xdfff;
  41827. var ZERO_WIDTH_JOINER = 0x200d;
  41828. /**
  41829. * Get the distance to the end of the first character in a string of text.
  41830. */
  41831. var getCharacterDistance = text => {
  41832. var offset = 0; // prev types:
  41833. // SURR: surrogate pair
  41834. // MOD: modifier (technically also surrogate pair)
  41835. // ZWJ: zero width joiner
  41836. // VAR: variation selector
  41837. // BMP: sequenceable character from basic multilingual plane
  41838. var prev = null;
  41839. var charCode = text.charCodeAt(0);
  41840. while (charCode) {
  41841. if (isSurrogate(charCode)) {
  41842. var modifier = isModifier(charCode, text, offset); // Early returns are the heart of this function, where we decide if previous and current
  41843. // codepoints should form a single character (in terms of how many of them should selection
  41844. // jump over).
  41845. if (prev === 'SURR' || prev === 'BMP') {
  41846. break;
  41847. }
  41848. offset += 2;
  41849. prev = modifier ? 'MOD' : 'SURR';
  41850. charCode = text.charCodeAt(offset); // Absolutely fine to `continue` without any checks because if `charCode` is NaN (which
  41851. // is the case when out of `text` range), next `while` loop won"t execute and we"re done.
  41852. continue;
  41853. }
  41854. if (charCode === ZERO_WIDTH_JOINER) {
  41855. offset += 1;
  41856. prev = 'ZWJ';
  41857. charCode = text.charCodeAt(offset);
  41858. continue;
  41859. }
  41860. if (isBMPEmoji(charCode)) {
  41861. if (prev && prev !== 'ZWJ' && prev !== 'VAR') {
  41862. break;
  41863. }
  41864. offset += 1;
  41865. prev = 'BMP';
  41866. charCode = text.charCodeAt(offset);
  41867. continue;
  41868. }
  41869. if (isVariationSelector(charCode)) {
  41870. if (prev && prev !== 'ZWJ') {
  41871. break;
  41872. }
  41873. offset += 1;
  41874. prev = 'VAR';
  41875. charCode = text.charCodeAt(offset);
  41876. continue;
  41877. } // Modifier 'groups up' with what ever character is before that (even whitespace), need to
  41878. // look ahead.
  41879. if (prev === 'MOD') {
  41880. offset += 1;
  41881. break;
  41882. } // If while loop ever gets here, we're done (e.g latin chars).
  41883. break;
  41884. }
  41885. return offset || 1;
  41886. };
  41887. /**
  41888. * Get the distance to the end of the first word in a string of text.
  41889. */
  41890. var getWordDistance = text => {
  41891. var length = 0;
  41892. var i = 0;
  41893. var started = false;
  41894. var char;
  41895. while (char = text.charAt(i)) {
  41896. var l = getCharacterDistance(char);
  41897. char = text.slice(i, i + l);
  41898. var rest = text.slice(i + l);
  41899. if (isWordCharacter(char, rest)) {
  41900. started = true;
  41901. length += l;
  41902. } else if (!started) {
  41903. length += l;
  41904. } else {
  41905. break;
  41906. }
  41907. i += l;
  41908. }
  41909. return length;
  41910. };
  41911. /**
  41912. * Check if a character is a word character. The `remaining` argument is used
  41913. * because sometimes you must read subsequent characters to truly determine it.
  41914. */
  41915. var isWordCharacter = (char, remaining) => {
  41916. if (SPACE.test(char)) {
  41917. return false;
  41918. } // Chameleons count as word characters as long as they're in a word, so
  41919. // recurse to see if the next one is a word character or not.
  41920. if (CHAMELEON.test(char)) {
  41921. var next = remaining.charAt(0);
  41922. var length = getCharacterDistance(next);
  41923. next = remaining.slice(0, length);
  41924. var rest = remaining.slice(length);
  41925. if (isWordCharacter(next, rest)) {
  41926. return true;
  41927. }
  41928. }
  41929. if (PUNCTUATION.test(char)) {
  41930. return false;
  41931. }
  41932. return true;
  41933. };
  41934. /**
  41935. * Determines if `code` is a surrogate
  41936. */
  41937. var isSurrogate = code => SURROGATE_START <= code && code <= SURROGATE_END;
  41938. /**
  41939. * Does `code` form Modifier with next one.
  41940. *
  41941. * https://emojipedia.org/modifiers/
  41942. */
  41943. var isModifier = (code, text, offset) => {
  41944. if (code === 0xd83c) {
  41945. var next = text.charCodeAt(offset + 1);
  41946. return next <= 0xdfff && next >= 0xdffb;
  41947. }
  41948. return false;
  41949. };
  41950. /**
  41951. * Is `code` a Variation Selector.
  41952. *
  41953. * https://codepoints.net/variation_selectors
  41954. */
  41955. var isVariationSelector = code => {
  41956. return code <= 0xfe0f && code >= 0xfe00;
  41957. };
  41958. /**
  41959. * Is `code` one of the BMP codes used in emoji sequences.
  41960. *
  41961. * https://emojipedia.org/emoji-zwj-sequences/
  41962. */
  41963. var isBMPEmoji = code => {
  41964. // This requires tiny bit of maintanance, better ideas?
  41965. // Fortunately it only happens if new Unicode Standard
  41966. // is released. Fails gracefully if upkeep lags behind,
  41967. // same way Slate previously behaved with all emojis.
  41968. return code === 0x2764 || // heart (❤)
  41969. code === 0x2642 || // male (♂)
  41970. code === 0x2640 || // female (♀)
  41971. code === 0x2620 || // scull (☠)
  41972. code === 0x2695 || // medical (⚕)
  41973. code === 0x2708 || // plane (✈️)
  41974. code === 0x25ef // large circle (◯)
  41975. ;
  41976. };
  41977. 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; }
  41978. 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; }
  41979. var Editor = {
  41980. /**
  41981. * Get the ancestor above a location in the document.
  41982. */
  41983. above(editor) {
  41984. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  41985. var {
  41986. voids = false,
  41987. mode = 'lowest',
  41988. at = editor.selection,
  41989. match
  41990. } = options;
  41991. if (!at) {
  41992. return;
  41993. }
  41994. var path = Editor.path(editor, at);
  41995. var reverse = mode === 'lowest';
  41996. for (var [n, p] of Editor.levels(editor, {
  41997. at: path,
  41998. voids,
  41999. match,
  42000. reverse
  42001. })) {
  42002. if (!Text.isText(n) && !Path.equals(path, p)) {
  42003. return [n, p];
  42004. }
  42005. }
  42006. },
  42007. /**
  42008. * Add a custom property to the leaf text nodes in the current selection.
  42009. *
  42010. * If the selection is currently collapsed, the marks will be added to the
  42011. * `editor.marks` property instead, and applied when text is inserted next.
  42012. */
  42013. addMark(editor, key, value) {
  42014. editor.addMark(key, value);
  42015. },
  42016. /**
  42017. * Get the point after a location.
  42018. */
  42019. after(editor, at) {
  42020. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  42021. var anchor = Editor.point(editor, at, {
  42022. edge: 'end'
  42023. });
  42024. var focus = Editor.end(editor, []);
  42025. var range = {
  42026. anchor,
  42027. focus
  42028. };
  42029. var {
  42030. distance = 1
  42031. } = options;
  42032. var d = 0;
  42033. var target;
  42034. for (var p of Editor.positions(editor, _objectSpread$1({}, options, {
  42035. at: range
  42036. }))) {
  42037. if (d > distance) {
  42038. break;
  42039. }
  42040. if (d !== 0) {
  42041. target = p;
  42042. }
  42043. d++;
  42044. }
  42045. return target;
  42046. },
  42047. /**
  42048. * Get the point before a location.
  42049. */
  42050. before(editor, at) {
  42051. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  42052. var anchor = Editor.start(editor, []);
  42053. var focus = Editor.point(editor, at, {
  42054. edge: 'start'
  42055. });
  42056. var range = {
  42057. anchor,
  42058. focus
  42059. };
  42060. var {
  42061. distance = 1
  42062. } = options;
  42063. var d = 0;
  42064. var target;
  42065. for (var p of Editor.positions(editor, _objectSpread$1({}, options, {
  42066. at: range,
  42067. reverse: true
  42068. }))) {
  42069. if (d > distance) {
  42070. break;
  42071. }
  42072. if (d !== 0) {
  42073. target = p;
  42074. }
  42075. d++;
  42076. }
  42077. return target;
  42078. },
  42079. /**
  42080. * Delete content in the editor backward from the current selection.
  42081. */
  42082. deleteBackward(editor) {
  42083. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  42084. var {
  42085. unit = 'character'
  42086. } = options;
  42087. editor.deleteBackward(unit);
  42088. },
  42089. /**
  42090. * Delete content in the editor forward from the current selection.
  42091. */
  42092. deleteForward(editor) {
  42093. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  42094. var {
  42095. unit = 'character'
  42096. } = options;
  42097. editor.deleteForward(unit);
  42098. },
  42099. /**
  42100. * Delete the content in the current selection.
  42101. */
  42102. deleteFragment(editor) {
  42103. editor.deleteFragment();
  42104. },
  42105. /**
  42106. * Get the start and end points of a location.
  42107. */
  42108. edges(editor, at) {
  42109. return [Editor.start(editor, at), Editor.end(editor, at)];
  42110. },
  42111. /**
  42112. * Get the end point of a location.
  42113. */
  42114. end(editor, at) {
  42115. return Editor.point(editor, at, {
  42116. edge: 'end'
  42117. });
  42118. },
  42119. /**
  42120. * Get the first node at a location.
  42121. */
  42122. first(editor, at) {
  42123. var path = Editor.path(editor, at, {
  42124. edge: 'start'
  42125. });
  42126. return Editor.node(editor, path);
  42127. },
  42128. /**
  42129. * Get the fragment at a location.
  42130. */
  42131. fragment(editor, at) {
  42132. var range = Editor.range(editor, at);
  42133. var fragment = Node.fragment(editor, range);
  42134. return fragment;
  42135. },
  42136. /**
  42137. * Check if a node has block children.
  42138. */
  42139. hasBlocks(editor, element) {
  42140. return element.children.some(n => Editor.isBlock(editor, n));
  42141. },
  42142. /**
  42143. * Check if a node has inline and text children.
  42144. */
  42145. hasInlines(editor, element) {
  42146. return element.children.some(n => Text.isText(n) || Editor.isInline(editor, n));
  42147. },
  42148. /**
  42149. * Check if a node has text children.
  42150. */
  42151. hasTexts(editor, element) {
  42152. return element.children.every(n => Text.isText(n));
  42153. },
  42154. /**
  42155. * Insert a block break at the current selection.
  42156. *
  42157. * If the selection is currently expanded, it will be deleted first.
  42158. */
  42159. insertBreak(editor) {
  42160. editor.insertBreak();
  42161. },
  42162. /**
  42163. * Insert a fragment at the current selection.
  42164. *
  42165. * If the selection is currently expanded, it will be deleted first.
  42166. */
  42167. insertFragment(editor, fragment) {
  42168. editor.insertFragment(fragment);
  42169. },
  42170. /**
  42171. * Insert a node at the current selection.
  42172. *
  42173. * If the selection is currently expanded, it will be deleted first.
  42174. */
  42175. insertNode(editor, node) {
  42176. editor.insertNode(node);
  42177. },
  42178. /**
  42179. * Insert text at the current selection.
  42180. *
  42181. * If the selection is currently expanded, it will be deleted first.
  42182. */
  42183. insertText(editor, text) {
  42184. editor.insertText(text);
  42185. },
  42186. /**
  42187. * Check if a value is a block `Element` object.
  42188. */
  42189. isBlock(editor, value) {
  42190. return Element.isElement(value) && !editor.isInline(value);
  42191. },
  42192. /**
  42193. * Check if a value is an `Editor` object.
  42194. */
  42195. isEditor(value) {
  42196. 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);
  42197. },
  42198. /**
  42199. * Check if a point is the end point of a location.
  42200. */
  42201. isEnd(editor, point, at) {
  42202. var end = Editor.end(editor, at);
  42203. return Point.equals(point, end);
  42204. },
  42205. /**
  42206. * Check if a point is an edge of a location.
  42207. */
  42208. isEdge(editor, point, at) {
  42209. return Editor.isStart(editor, point, at) || Editor.isEnd(editor, point, at);
  42210. },
  42211. /**
  42212. * Check if an element is empty, accounting for void nodes.
  42213. */
  42214. isEmpty(editor, element) {
  42215. var {
  42216. children
  42217. } = element;
  42218. var [first] = children;
  42219. return children.length === 0 || children.length === 1 && Text.isText(first) && first.text === '' && !editor.isVoid(element);
  42220. },
  42221. /**
  42222. * Check if a value is an inline `Element` object.
  42223. */
  42224. isInline(editor, value) {
  42225. return Element.isElement(value) && editor.isInline(value);
  42226. },
  42227. /**
  42228. * Check if the editor is currently normalizing after each operation.
  42229. */
  42230. isNormalizing(editor) {
  42231. var isNormalizing = NORMALIZING.get(editor);
  42232. return isNormalizing === undefined ? true : isNormalizing;
  42233. },
  42234. /**
  42235. * Check if a point is the start point of a location.
  42236. */
  42237. isStart(editor, point, at) {
  42238. // PERF: If the offset isn't `0` we know it's not the start.
  42239. if (point.offset !== 0) {
  42240. return false;
  42241. }
  42242. var start = Editor.start(editor, at);
  42243. return Point.equals(point, start);
  42244. },
  42245. /**
  42246. * Check if a value is a void `Element` object.
  42247. */
  42248. isVoid(editor, value) {
  42249. return Element.isElement(value) && editor.isVoid(value);
  42250. },
  42251. /**
  42252. * Get the last node at a location.
  42253. */
  42254. last(editor, at) {
  42255. var path = Editor.path(editor, at, {
  42256. edge: 'end'
  42257. });
  42258. return Editor.node(editor, path);
  42259. },
  42260. /**
  42261. * Get the leaf text node at a location.
  42262. */
  42263. leaf(editor, at) {
  42264. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  42265. var path = Editor.path(editor, at, options);
  42266. var node = Node.leaf(editor, path);
  42267. return [node, path];
  42268. },
  42269. /**
  42270. * Iterate through all of the levels at a location.
  42271. */
  42272. *levels(editor) {
  42273. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  42274. var {
  42275. at = editor.selection,
  42276. reverse = false,
  42277. voids = false
  42278. } = options;
  42279. var {
  42280. match
  42281. } = options;
  42282. if (match == null) {
  42283. match = () => true;
  42284. }
  42285. if (!at) {
  42286. return;
  42287. }
  42288. var levels = [];
  42289. var path = Editor.path(editor, at);
  42290. for (var [n, p] of Node.levels(editor, path)) {
  42291. if (!match(n)) {
  42292. continue;
  42293. }
  42294. levels.push([n, p]);
  42295. if (!voids && Editor.isVoid(editor, n)) {
  42296. break;
  42297. }
  42298. }
  42299. if (reverse) {
  42300. levels.reverse();
  42301. }
  42302. yield* levels;
  42303. },
  42304. /**
  42305. * Get the marks that would be added to text at the current selection.
  42306. */
  42307. marks(editor) {
  42308. var {
  42309. marks,
  42310. selection
  42311. } = editor;
  42312. if (!selection) {
  42313. return null;
  42314. }
  42315. if (marks) {
  42316. return marks;
  42317. }
  42318. if (Range.isExpanded(selection)) {
  42319. var [match] = Editor.nodes(editor, {
  42320. match: Text.isText
  42321. });
  42322. if (match) {
  42323. var [_node] = match;
  42324. var _rest = _objectWithoutProperties(_node, ["text"]);
  42325. return _rest;
  42326. } else {
  42327. return {};
  42328. }
  42329. }
  42330. var {
  42331. anchor
  42332. } = selection;
  42333. var {
  42334. path
  42335. } = anchor;
  42336. var [node] = Editor.leaf(editor, path);
  42337. if (anchor.offset === 0) {
  42338. var prev = Editor.previous(editor, {
  42339. at: path,
  42340. match: Text.isText
  42341. });
  42342. var block = Editor.above(editor, {
  42343. match: n => Editor.isBlock(editor, n)
  42344. });
  42345. if (prev && block) {
  42346. var [prevNode, prevPath] = prev;
  42347. var [, blockPath] = block;
  42348. if (Path.isAncestor(blockPath, prevPath)) {
  42349. node = prevNode;
  42350. }
  42351. }
  42352. }
  42353. var rest = _objectWithoutProperties(node, ["text"]);
  42354. return rest;
  42355. },
  42356. /**
  42357. * Get the matching node in the branch of the document after a location.
  42358. */
  42359. next(editor) {
  42360. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  42361. var {
  42362. mode = 'lowest',
  42363. voids = false
  42364. } = options;
  42365. var {
  42366. match,
  42367. at = editor.selection
  42368. } = options;
  42369. if (!at) {
  42370. return;
  42371. }
  42372. var [, from] = Editor.last(editor, at);
  42373. var [, to] = Editor.last(editor, []);
  42374. var span = [from, to];
  42375. if (Path.isPath(at) && at.length === 0) {
  42376. throw new Error("Cannot get the next node from the root node!");
  42377. }
  42378. if (match == null) {
  42379. if (Path.isPath(at)) {
  42380. var [parent] = Editor.parent(editor, at);
  42381. match = n => parent.children.includes(n);
  42382. } else {
  42383. match = () => true;
  42384. }
  42385. }
  42386. var [, next] = Editor.nodes(editor, {
  42387. at: span,
  42388. match,
  42389. mode,
  42390. voids
  42391. });
  42392. return next;
  42393. },
  42394. /**
  42395. * Get the node at a location.
  42396. */
  42397. node(editor, at) {
  42398. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  42399. var path = Editor.path(editor, at, options);
  42400. var node = Node.get(editor, path);
  42401. return [node, path];
  42402. },
  42403. /**
  42404. * Iterate through all of the nodes in the Editor.
  42405. */
  42406. *nodes(editor) {
  42407. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  42408. var {
  42409. at = editor.selection,
  42410. mode = 'all',
  42411. universal = false,
  42412. reverse = false,
  42413. voids = false
  42414. } = options;
  42415. var {
  42416. match
  42417. } = options;
  42418. if (!match) {
  42419. match = () => true;
  42420. }
  42421. if (!at) {
  42422. return;
  42423. }
  42424. var from;
  42425. var to;
  42426. if (Span.isSpan(at)) {
  42427. from = at[0];
  42428. to = at[1];
  42429. } else {
  42430. var first = Editor.path(editor, at, {
  42431. edge: 'start'
  42432. });
  42433. var last = Editor.path(editor, at, {
  42434. edge: 'end'
  42435. });
  42436. from = reverse ? last : first;
  42437. to = reverse ? first : last;
  42438. }
  42439. var iterable = Node.nodes(editor, {
  42440. reverse,
  42441. from,
  42442. to,
  42443. pass: (_ref) => {
  42444. var [n] = _ref;
  42445. return voids ? false : Editor.isVoid(editor, n);
  42446. }
  42447. });
  42448. var matches = [];
  42449. var hit;
  42450. for (var [node, path] of iterable) {
  42451. var isLower = hit && Path.compare(path, hit[1]) === 0; // In highest mode any node lower than the last hit is not a match.
  42452. if (mode === 'highest' && isLower) {
  42453. continue;
  42454. }
  42455. if (!match(node)) {
  42456. // If we've arrived at a leaf text node that is not lower than the last
  42457. // hit, then we've found a branch that doesn't include a match, which
  42458. // means the match is not universal.
  42459. if (universal && !isLower && Text.isText(node)) {
  42460. return;
  42461. } else {
  42462. continue;
  42463. }
  42464. } // If there's a match and it's lower than the last, update the hit.
  42465. if (mode === 'lowest' && isLower) {
  42466. hit = [node, path];
  42467. continue;
  42468. } // In lowest mode we emit the last hit, once it's guaranteed lowest.
  42469. var emit = mode === 'lowest' ? hit : [node, path];
  42470. if (emit) {
  42471. if (universal) {
  42472. matches.push(emit);
  42473. } else {
  42474. yield emit;
  42475. }
  42476. }
  42477. hit = [node, path];
  42478. } // Since lowest is always emitting one behind, catch up at the end.
  42479. if (mode === 'lowest' && hit) {
  42480. if (universal) {
  42481. matches.push(hit);
  42482. } else {
  42483. yield hit;
  42484. }
  42485. } // Universal defers to ensure that the match occurs in every branch, so we
  42486. // yield all of the matches after iterating.
  42487. if (universal) {
  42488. yield* matches;
  42489. }
  42490. },
  42491. /**
  42492. * Normalize any dirty objects in the editor.
  42493. */
  42494. normalize(editor) {
  42495. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  42496. var {
  42497. force = false
  42498. } = options;
  42499. var getDirtyPaths = editor => {
  42500. return DIRTY_PATHS.get(editor) || [];
  42501. };
  42502. if (!Editor.isNormalizing(editor)) {
  42503. return;
  42504. }
  42505. if (force) {
  42506. var allPaths = Array.from(Node.nodes(editor), (_ref2) => {
  42507. var [, p] = _ref2;
  42508. return p;
  42509. });
  42510. DIRTY_PATHS.set(editor, allPaths);
  42511. }
  42512. if (getDirtyPaths(editor).length === 0) {
  42513. return;
  42514. }
  42515. Editor.withoutNormalizing(editor, () => {
  42516. var max = getDirtyPaths(editor).length * 42; // HACK: better way?
  42517. var m = 0;
  42518. while (getDirtyPaths(editor).length !== 0) {
  42519. if (m > max) {
  42520. 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 "));
  42521. }
  42522. var path = getDirtyPaths(editor).pop();
  42523. var entry = Editor.node(editor, path);
  42524. editor.normalizeNode(entry);
  42525. m++;
  42526. }
  42527. });
  42528. },
  42529. /**
  42530. * Get the parent node of a location.
  42531. */
  42532. parent(editor, at) {
  42533. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  42534. var path = Editor.path(editor, at, options);
  42535. var parentPath = Path.parent(path);
  42536. var entry = Editor.node(editor, parentPath);
  42537. return entry;
  42538. },
  42539. /**
  42540. * Get the path of a location.
  42541. */
  42542. path(editor, at) {
  42543. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  42544. var {
  42545. depth,
  42546. edge
  42547. } = options;
  42548. if (Path.isPath(at)) {
  42549. if (edge === 'start') {
  42550. var [, firstPath] = Node.first(editor, at);
  42551. at = firstPath;
  42552. } else if (edge === 'end') {
  42553. var [, lastPath] = Node.last(editor, at);
  42554. at = lastPath;
  42555. }
  42556. }
  42557. if (Range.isRange(at)) {
  42558. if (edge === 'start') {
  42559. at = Range.start(at);
  42560. } else if (edge === 'end') {
  42561. at = Range.end(at);
  42562. } else {
  42563. at = Path.common(at.anchor.path, at.focus.path);
  42564. }
  42565. }
  42566. if (Point.isPoint(at)) {
  42567. at = at.path;
  42568. }
  42569. if (depth != null) {
  42570. at = at.slice(0, depth);
  42571. }
  42572. return at;
  42573. },
  42574. /**
  42575. * Create a mutable ref for a `Path` object, which will stay in sync as new
  42576. * operations are applied to the editor.
  42577. */
  42578. pathRef(editor, path) {
  42579. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  42580. var {
  42581. affinity = 'forward'
  42582. } = options;
  42583. var ref = {
  42584. current: path,
  42585. affinity,
  42586. unref() {
  42587. var {
  42588. current
  42589. } = ref;
  42590. var pathRefs = Editor.pathRefs(editor);
  42591. pathRefs.delete(ref);
  42592. ref.current = null;
  42593. return current;
  42594. }
  42595. };
  42596. var refs = Editor.pathRefs(editor);
  42597. refs.add(ref);
  42598. return ref;
  42599. },
  42600. /**
  42601. * Get the set of currently tracked path refs of the editor.
  42602. */
  42603. pathRefs(editor) {
  42604. var refs = PATH_REFS.get(editor);
  42605. if (!refs) {
  42606. refs = new Set();
  42607. PATH_REFS.set(editor, refs);
  42608. }
  42609. return refs;
  42610. },
  42611. /**
  42612. * Get the start or end point of a location.
  42613. */
  42614. point(editor, at) {
  42615. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  42616. var {
  42617. edge = 'start'
  42618. } = options;
  42619. if (Path.isPath(at)) {
  42620. var path;
  42621. if (edge === 'end') {
  42622. var [, lastPath] = Node.last(editor, at);
  42623. path = lastPath;
  42624. } else {
  42625. var [, firstPath] = Node.first(editor, at);
  42626. path = firstPath;
  42627. }
  42628. var node = Node.get(editor, path);
  42629. if (!Text.isText(node)) {
  42630. throw new Error("Cannot get the ".concat(edge, " point in the node at path [").concat(at, "] because it has no ").concat(edge, " text node."));
  42631. }
  42632. return {
  42633. path,
  42634. offset: edge === 'end' ? node.text.length : 0
  42635. };
  42636. }
  42637. if (Range.isRange(at)) {
  42638. var [start, end] = Range.edges(at);
  42639. return edge === 'start' ? start : end;
  42640. }
  42641. return at;
  42642. },
  42643. /**
  42644. * Create a mutable ref for a `Point` object, which will stay in sync as new
  42645. * operations are applied to the editor.
  42646. */
  42647. pointRef(editor, point) {
  42648. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  42649. var {
  42650. affinity = 'forward'
  42651. } = options;
  42652. var ref = {
  42653. current: point,
  42654. affinity,
  42655. unref() {
  42656. var {
  42657. current
  42658. } = ref;
  42659. var pointRefs = Editor.pointRefs(editor);
  42660. pointRefs.delete(ref);
  42661. ref.current = null;
  42662. return current;
  42663. }
  42664. };
  42665. var refs = Editor.pointRefs(editor);
  42666. refs.add(ref);
  42667. return ref;
  42668. },
  42669. /**
  42670. * Get the set of currently tracked point refs of the editor.
  42671. */
  42672. pointRefs(editor) {
  42673. var refs = POINT_REFS.get(editor);
  42674. if (!refs) {
  42675. refs = new Set();
  42676. POINT_REFS.set(editor, refs);
  42677. }
  42678. return refs;
  42679. },
  42680. /**
  42681. * Iterate through all of the positions in the document where a `Point` can be
  42682. * placed.
  42683. *
  42684. * By default it will move forward by individual offsets at a time, but you
  42685. * can pass the `unit: 'character'` option to moved forward one character, word,
  42686. * or line at at time.
  42687. *
  42688. * Note: void nodes are treated as a single point, and iteration will not
  42689. * happen inside their content.
  42690. */
  42691. *positions(editor) {
  42692. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  42693. var {
  42694. at = editor.selection,
  42695. unit = 'offset',
  42696. reverse = false
  42697. } = options;
  42698. if (!at) {
  42699. return;
  42700. }
  42701. var range = Editor.range(editor, at);
  42702. var [start, end] = Range.edges(range);
  42703. var first = reverse ? end : start;
  42704. var string = '';
  42705. var available = 0;
  42706. var offset = 0;
  42707. var distance = null;
  42708. var isNewBlock = false;
  42709. var advance = () => {
  42710. if (distance == null) {
  42711. if (unit === 'character') {
  42712. distance = getCharacterDistance(string);
  42713. } else if (unit === 'word') {
  42714. distance = getWordDistance(string);
  42715. } else if (unit === 'line' || unit === 'block') {
  42716. distance = string.length;
  42717. } else {
  42718. distance = 1;
  42719. }
  42720. string = string.slice(distance);
  42721. } // Add or substract the offset.
  42722. offset = reverse ? offset - distance : offset + distance; // Subtract the distance traveled from the available text.
  42723. available = available - distance; // If the available had room to spare, reset the distance so that it will
  42724. // advance again next time. Otherwise, set it to the overflow amount.
  42725. distance = available >= 0 ? null : 0 - available;
  42726. };
  42727. for (var [node, path] of Editor.nodes(editor, {
  42728. at,
  42729. reverse
  42730. })) {
  42731. if (Element.isElement(node)) {
  42732. // Void nodes are a special case, since we don't want to iterate over
  42733. // their content. We instead always just yield their first point.
  42734. if (editor.isVoid(node)) {
  42735. yield Editor.start(editor, path);
  42736. continue;
  42737. }
  42738. if (editor.isInline(node)) {
  42739. continue;
  42740. }
  42741. if (Editor.hasInlines(editor, node)) {
  42742. var e = Path.isAncestor(path, end.path) ? end : Editor.end(editor, path);
  42743. var s = Path.isAncestor(path, start.path) ? start : Editor.start(editor, path);
  42744. var text = Editor.string(editor, {
  42745. anchor: s,
  42746. focus: e
  42747. });
  42748. string = reverse ? esrever.reverse(text) : text;
  42749. isNewBlock = true;
  42750. }
  42751. }
  42752. if (Text.isText(node)) {
  42753. var isFirst = Path.equals(path, first.path);
  42754. available = node.text.length;
  42755. offset = reverse ? available : 0;
  42756. if (isFirst) {
  42757. available = reverse ? first.offset : available - first.offset;
  42758. offset = first.offset;
  42759. }
  42760. if (isFirst || isNewBlock || unit === 'offset') {
  42761. yield {
  42762. path,
  42763. offset
  42764. };
  42765. }
  42766. while (true) {
  42767. // If there's no more string, continue to the next block.
  42768. if (string === '') {
  42769. break;
  42770. } else {
  42771. advance();
  42772. } // If the available space hasn't overflow, we have another point to
  42773. // yield in the current text node.
  42774. if (available >= 0) {
  42775. yield {
  42776. path,
  42777. offset
  42778. };
  42779. } else {
  42780. break;
  42781. }
  42782. }
  42783. isNewBlock = false;
  42784. }
  42785. }
  42786. },
  42787. /**
  42788. * Get the matching node in the branch of the document before a location.
  42789. */
  42790. previous(editor) {
  42791. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  42792. var {
  42793. mode = 'lowest',
  42794. voids = false
  42795. } = options;
  42796. var {
  42797. match,
  42798. at = editor.selection
  42799. } = options;
  42800. if (!at) {
  42801. return;
  42802. }
  42803. var [, from] = Editor.first(editor, at);
  42804. var [, to] = Editor.first(editor, []);
  42805. var span = [from, to];
  42806. if (Path.isPath(at) && at.length === 0) {
  42807. throw new Error("Cannot get the previous node from the root node!");
  42808. }
  42809. if (match == null) {
  42810. if (Path.isPath(at)) {
  42811. var [parent] = Editor.parent(editor, at);
  42812. match = n => parent.children.includes(n);
  42813. } else {
  42814. match = () => true;
  42815. }
  42816. }
  42817. var [, previous] = Editor.nodes(editor, {
  42818. reverse: true,
  42819. at: span,
  42820. match,
  42821. mode,
  42822. voids
  42823. });
  42824. return previous;
  42825. },
  42826. /**
  42827. * Get a range of a location.
  42828. */
  42829. range(editor, at, to) {
  42830. if (Range.isRange(at) && !to) {
  42831. return at;
  42832. }
  42833. var start = Editor.start(editor, at);
  42834. var end = Editor.end(editor, to || at);
  42835. return {
  42836. anchor: start,
  42837. focus: end
  42838. };
  42839. },
  42840. /**
  42841. * Create a mutable ref for a `Range` object, which will stay in sync as new
  42842. * operations are applied to the editor.
  42843. */
  42844. rangeRef(editor, range) {
  42845. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  42846. var {
  42847. affinity = 'forward'
  42848. } = options;
  42849. var ref = {
  42850. current: range,
  42851. affinity,
  42852. unref() {
  42853. var {
  42854. current
  42855. } = ref;
  42856. var rangeRefs = Editor.rangeRefs(editor);
  42857. rangeRefs.delete(ref);
  42858. ref.current = null;
  42859. return current;
  42860. }
  42861. };
  42862. var refs = Editor.rangeRefs(editor);
  42863. refs.add(ref);
  42864. return ref;
  42865. },
  42866. /**
  42867. * Get the set of currently tracked range refs of the editor.
  42868. */
  42869. rangeRefs(editor) {
  42870. var refs = RANGE_REFS.get(editor);
  42871. if (!refs) {
  42872. refs = new Set();
  42873. RANGE_REFS.set(editor, refs);
  42874. }
  42875. return refs;
  42876. },
  42877. /**
  42878. * Remove a custom property from all of the leaf text nodes in the current
  42879. * selection.
  42880. *
  42881. * If the selection is currently collapsed, the removal will be stored on
  42882. * `editor.marks` and applied to the text inserted next.
  42883. */
  42884. removeMark(editor, key) {
  42885. editor.removeMark(key);
  42886. },
  42887. /**
  42888. * Get the start point of a location.
  42889. */
  42890. start(editor, at) {
  42891. return Editor.point(editor, at, {
  42892. edge: 'start'
  42893. });
  42894. },
  42895. /**
  42896. * Get the text string content of a location.
  42897. *
  42898. * Note: the text of void nodes is presumed to be an empty string, regardless
  42899. * of what their actual content is.
  42900. */
  42901. string(editor, at) {
  42902. var range = Editor.range(editor, at);
  42903. var [start, end] = Range.edges(range);
  42904. var text = '';
  42905. for (var [node, path] of Editor.nodes(editor, {
  42906. at: range,
  42907. match: Text.isText
  42908. })) {
  42909. var t = node.text;
  42910. if (Path.equals(path, end.path)) {
  42911. t = t.slice(0, end.offset);
  42912. }
  42913. if (Path.equals(path, start.path)) {
  42914. t = t.slice(start.offset);
  42915. }
  42916. text += t;
  42917. }
  42918. return text;
  42919. },
  42920. /**
  42921. * Transform the editor by an operation.
  42922. */
  42923. transform(editor, op) {
  42924. editor.children = immer_1.createDraft(editor.children);
  42925. var selection = editor.selection && immer_1.createDraft(editor.selection);
  42926. switch (op.type) {
  42927. case 'insert_node':
  42928. {
  42929. var {
  42930. path,
  42931. node
  42932. } = op;
  42933. var parent = Node.parent(editor, path);
  42934. var index = path[path.length - 1];
  42935. parent.children.splice(index, 0, node);
  42936. if (selection) {
  42937. for (var [point, key] of Range.points(selection)) {
  42938. selection[key] = Point.transform(point, op);
  42939. }
  42940. }
  42941. break;
  42942. }
  42943. case 'insert_text':
  42944. {
  42945. var {
  42946. path: _path,
  42947. offset,
  42948. text
  42949. } = op;
  42950. var _node2 = Node.leaf(editor, _path);
  42951. var before = _node2.text.slice(0, offset);
  42952. var after = _node2.text.slice(offset);
  42953. _node2.text = before + text + after;
  42954. if (selection) {
  42955. for (var [_point, _key] of Range.points(selection)) {
  42956. selection[_key] = Point.transform(_point, op);
  42957. }
  42958. }
  42959. break;
  42960. }
  42961. case 'merge_node':
  42962. {
  42963. var {
  42964. path: _path2
  42965. } = op;
  42966. var _node3 = Node.get(editor, _path2);
  42967. var prevPath = Path.previous(_path2);
  42968. var prev = Node.get(editor, prevPath);
  42969. var _parent = Node.parent(editor, _path2);
  42970. var _index = _path2[_path2.length - 1];
  42971. if (Text.isText(_node3) && Text.isText(prev)) {
  42972. prev.text += _node3.text;
  42973. } else if (!Text.isText(_node3) && !Text.isText(prev)) {
  42974. prev.children.push(..._node3.children);
  42975. } else {
  42976. throw new Error("Cannot apply a \"merge_node\" operation at path [".concat(_path2, "] to nodes of different interaces: ").concat(_node3, " ").concat(prev));
  42977. }
  42978. _parent.children.splice(_index, 1);
  42979. if (selection) {
  42980. for (var [_point2, _key2] of Range.points(selection)) {
  42981. selection[_key2] = Point.transform(_point2, op);
  42982. }
  42983. }
  42984. break;
  42985. }
  42986. case 'move_node':
  42987. {
  42988. var {
  42989. path: _path3,
  42990. newPath
  42991. } = op;
  42992. if (Path.isAncestor(_path3, newPath)) {
  42993. throw new Error("Cannot move a path [".concat(_path3, "] to new path [").concat(newPath, "] because the destination is inside itself."));
  42994. }
  42995. var _node4 = Node.get(editor, _path3);
  42996. var _parent2 = Node.parent(editor, _path3);
  42997. var _index2 = _path3[_path3.length - 1]; // This is tricky, but since the `path` and `newPath` both refer to
  42998. // the same snapshot in time, there's a mismatch. After either
  42999. // removing the original position, the second step's path can be out
  43000. // of date. So instead of using the `op.newPath` directly, we
  43001. // transform `op.path` to ascertain what the `newPath` would be after
  43002. // the operation was applied.
  43003. _parent2.children.splice(_index2, 1);
  43004. var truePath = Path.transform(_path3, op);
  43005. var newParent = Node.get(editor, Path.parent(truePath));
  43006. var newIndex = truePath[truePath.length - 1];
  43007. newParent.children.splice(newIndex, 0, _node4);
  43008. if (selection) {
  43009. for (var [_point3, _key3] of Range.points(selection)) {
  43010. selection[_key3] = Point.transform(_point3, op);
  43011. }
  43012. }
  43013. break;
  43014. }
  43015. case 'remove_node':
  43016. {
  43017. var {
  43018. path: _path4
  43019. } = op;
  43020. var _index3 = _path4[_path4.length - 1];
  43021. var _parent3 = Node.parent(editor, _path4);
  43022. _parent3.children.splice(_index3, 1); // Transform all of the points in the value, but if the point was in the
  43023. // node that was removed we need to update the range or remove it.
  43024. if (selection) {
  43025. for (var [_point4, _key4] of Range.points(selection)) {
  43026. var result = Point.transform(_point4, op);
  43027. if (selection != null && result != null) {
  43028. selection[_key4] = result;
  43029. } else {
  43030. var _prev = void 0;
  43031. var next = void 0;
  43032. for (var [n, p] of Node.texts(editor)) {
  43033. if (Path.compare(p, _path4) === -1) {
  43034. _prev = [n, p];
  43035. } else {
  43036. next = [n, p];
  43037. break;
  43038. }
  43039. }
  43040. if (_prev) {
  43041. _point4.path = _prev[1];
  43042. _point4.offset = _prev[0].text.length;
  43043. } else if (next) {
  43044. _point4.path = next[1];
  43045. _point4.offset = 0;
  43046. } else {
  43047. selection = null;
  43048. }
  43049. }
  43050. }
  43051. }
  43052. break;
  43053. }
  43054. case 'remove_text':
  43055. {
  43056. var {
  43057. path: _path5,
  43058. offset: _offset,
  43059. text: _text2
  43060. } = op;
  43061. var _node5 = Node.leaf(editor, _path5);
  43062. var _before = _node5.text.slice(0, _offset);
  43063. var _after = _node5.text.slice(_offset + _text2.length);
  43064. _node5.text = _before + _after;
  43065. if (selection) {
  43066. for (var [_point5, _key5] of Range.points(selection)) {
  43067. selection[_key5] = Point.transform(_point5, op);
  43068. }
  43069. }
  43070. break;
  43071. }
  43072. case 'set_node':
  43073. {
  43074. var {
  43075. path: _path6,
  43076. newProperties
  43077. } = op;
  43078. if (_path6.length === 0) {
  43079. throw new Error("Cannot set properties on the root node!");
  43080. }
  43081. var _node6 = Node.get(editor, _path6);
  43082. for (var _key6 in newProperties) {
  43083. if (_key6 === 'children' || _key6 === 'text') {
  43084. throw new Error("Cannot set the \"".concat(_key6, "\" property of nodes!"));
  43085. }
  43086. var value = newProperties[_key6];
  43087. if (value == null) {
  43088. delete _node6[_key6];
  43089. } else {
  43090. _node6[_key6] = value;
  43091. }
  43092. }
  43093. break;
  43094. }
  43095. case 'set_selection':
  43096. {
  43097. var {
  43098. newProperties: _newProperties
  43099. } = op;
  43100. if (_newProperties == null) {
  43101. selection = _newProperties;
  43102. } else if (selection == null) {
  43103. if (!Range.isRange(_newProperties)) {
  43104. throw new Error("Cannot apply an incomplete \"set_selection\" operation properties ".concat(JSON.stringify(_newProperties), " when there is no current selection."));
  43105. }
  43106. selection = _newProperties;
  43107. } else {
  43108. Object.assign(selection, _newProperties);
  43109. }
  43110. break;
  43111. }
  43112. case 'split_node':
  43113. {
  43114. var {
  43115. path: _path7,
  43116. position,
  43117. properties
  43118. } = op;
  43119. if (_path7.length === 0) {
  43120. throw new Error("Cannot apply a \"split_node\" operation at path [".concat(_path7, "] because the root node cannot be split."));
  43121. }
  43122. var _node7 = Node.get(editor, _path7);
  43123. var _parent4 = Node.parent(editor, _path7);
  43124. var _index4 = _path7[_path7.length - 1];
  43125. var newNode;
  43126. if (Text.isText(_node7)) {
  43127. var _before2 = _node7.text.slice(0, position);
  43128. var _after2 = _node7.text.slice(position);
  43129. _node7.text = _before2;
  43130. newNode = _objectSpread$1({}, _node7, {}, properties, {
  43131. text: _after2
  43132. });
  43133. } else {
  43134. var _before3 = _node7.children.slice(0, position);
  43135. var _after3 = _node7.children.slice(position);
  43136. _node7.children = _before3;
  43137. newNode = _objectSpread$1({}, _node7, {}, properties, {
  43138. children: _after3
  43139. });
  43140. }
  43141. _parent4.children.splice(_index4 + 1, 0, newNode);
  43142. if (selection) {
  43143. for (var [_point6, _key7] of Range.points(selection)) {
  43144. selection[_key7] = Point.transform(_point6, op);
  43145. }
  43146. }
  43147. break;
  43148. }
  43149. }
  43150. editor.children = immer_1.finishDraft(editor.children);
  43151. if (selection) {
  43152. editor.selection = immer_1.isDraft(selection) ? immer_1.finishDraft(selection) : selection;
  43153. } else {
  43154. editor.selection = null;
  43155. }
  43156. },
  43157. /**
  43158. * Convert a range into a non-hanging one.
  43159. */
  43160. unhangRange(editor, range) {
  43161. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  43162. var {
  43163. voids = false
  43164. } = options;
  43165. var [start, end] = Range.edges(range); // PERF: exit early if we can guarantee that the range isn't hanging.
  43166. if (start.offset !== 0 || end.offset !== 0 || Range.isCollapsed(range)) {
  43167. return range;
  43168. }
  43169. var endBlock = Editor.above(editor, {
  43170. at: end,
  43171. match: n => Editor.isBlock(editor, n)
  43172. });
  43173. var blockPath = endBlock ? endBlock[1] : [];
  43174. var first = Editor.start(editor, []);
  43175. var before = {
  43176. anchor: first,
  43177. focus: end
  43178. };
  43179. var skip = true;
  43180. for (var [node, path] of Editor.nodes(editor, {
  43181. at: before,
  43182. match: Text.isText,
  43183. reverse: true,
  43184. voids
  43185. })) {
  43186. if (skip) {
  43187. skip = false;
  43188. continue;
  43189. }
  43190. if (node.text !== '' || Path.isBefore(path, blockPath)) {
  43191. end = {
  43192. path,
  43193. offset: node.text.length
  43194. };
  43195. break;
  43196. }
  43197. }
  43198. return {
  43199. anchor: start,
  43200. focus: end
  43201. };
  43202. },
  43203. /**
  43204. * Match a void node in the current branch of the editor.
  43205. */
  43206. void(editor) {
  43207. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  43208. return Editor.above(editor, _objectSpread$1({}, options, {
  43209. match: n => Editor.isVoid(editor, n)
  43210. }));
  43211. },
  43212. /**
  43213. * Call a function, deferring normalization until after it completes.
  43214. */
  43215. withoutNormalizing(editor, fn) {
  43216. var value = Editor.isNormalizing(editor);
  43217. NORMALIZING.set(editor, false);
  43218. fn();
  43219. NORMALIZING.set(editor, value);
  43220. Editor.normalize(editor);
  43221. }
  43222. };
  43223. var Element = {
  43224. /**
  43225. * Check if a value implements the `Element` interface.
  43226. */
  43227. isElement(value) {
  43228. return isPlainObject(value) && Node.isNodeList(value.children) && !Editor.isEditor(value);
  43229. },
  43230. /**
  43231. * Check if a value is an array of `Element` objects.
  43232. */
  43233. isElementList(value) {
  43234. return Array.isArray(value) && (value.length === 0 || Element.isElement(value[0]));
  43235. },
  43236. /**
  43237. * Check if an element matches set of properties.
  43238. *
  43239. * Note: this checks custom properties, and it does not ensure that any
  43240. * children are equivalent.
  43241. */
  43242. matches(element, props) {
  43243. for (var key in props) {
  43244. if (key === 'children') {
  43245. continue;
  43246. }
  43247. if (element[key] !== props[key]) {
  43248. return false;
  43249. }
  43250. }
  43251. return true;
  43252. }
  43253. };
  43254. var Location = {
  43255. /**
  43256. * Check if a value implements the `Location` interface.
  43257. */
  43258. isLocation(value) {
  43259. return Path.isPath(value) || Point.isPoint(value) || Range.isRange(value);
  43260. }
  43261. };
  43262. var Span = {
  43263. /**
  43264. * Check if a value implements the `Span` interface.
  43265. */
  43266. isSpan(value) {
  43267. return Array.isArray(value) && value.length === 2 && value.every(Path.isPath);
  43268. }
  43269. };
  43270. var Node = {
  43271. /**
  43272. * Get the node at a specific path, asserting that it's an ancestor node.
  43273. */
  43274. ancestor(root, path) {
  43275. var node = Node.get(root, path);
  43276. if (Text.isText(node)) {
  43277. throw new Error("Cannot get the ancestor node at path [".concat(path, "] because it refers to a text node instead: ").concat(node));
  43278. }
  43279. return node;
  43280. },
  43281. /**
  43282. * Return an iterable of all the ancestor nodes above a specific path.
  43283. *
  43284. * By default the order is bottom-up, from lowest to highest ancestor in
  43285. * the tree, but you can pass the `reverse: true` option to go top-down.
  43286. */
  43287. *ancestors(root, path) {
  43288. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  43289. for (var p of Path.ancestors(path, options)) {
  43290. var n = Node.ancestor(root, p);
  43291. var entry = [n, p];
  43292. yield entry;
  43293. }
  43294. },
  43295. /**
  43296. * Get the child of a node at a specific index.
  43297. */
  43298. child(root, index) {
  43299. if (Text.isText(root)) {
  43300. throw new Error("Cannot get the child of a text node: ".concat(JSON.stringify(root)));
  43301. }
  43302. var c = root.children[index];
  43303. if (c == null) {
  43304. throw new Error("Cannot get child at index `".concat(index, "` in node: ").concat(JSON.stringify(root)));
  43305. }
  43306. return c;
  43307. },
  43308. /**
  43309. * Iterate over the children of a node at a specific path.
  43310. */
  43311. *children(root, path) {
  43312. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  43313. var {
  43314. reverse = false
  43315. } = options;
  43316. var ancestor = Node.ancestor(root, path);
  43317. var {
  43318. children
  43319. } = ancestor;
  43320. var index = reverse ? children.length - 1 : 0;
  43321. while (reverse ? index >= 0 : index < children.length) {
  43322. var child = Node.child(ancestor, index);
  43323. var childPath = path.concat(index);
  43324. yield [child, childPath];
  43325. index = reverse ? index - 1 : index + 1;
  43326. }
  43327. },
  43328. /**
  43329. * Get an entry for the common ancesetor node of two paths.
  43330. */
  43331. common(root, path, another) {
  43332. var p = Path.common(path, another);
  43333. var n = Node.get(root, p);
  43334. return [n, p];
  43335. },
  43336. /**
  43337. * Get the node at a specific path, asserting that it's a descendant node.
  43338. */
  43339. descendant(root, path) {
  43340. var node = Node.get(root, path);
  43341. if (Editor.isEditor(node)) {
  43342. throw new Error("Cannot get the descendant node at path [".concat(path, "] because it refers to the root editor node instead: ").concat(node));
  43343. }
  43344. return node;
  43345. },
  43346. /**
  43347. * Return an iterable of all the descendant node entries inside a root node.
  43348. */
  43349. *descendants(root) {
  43350. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  43351. for (var [node, path] of Node.nodes(root, options)) {
  43352. if (path.length !== 0) {
  43353. // NOTE: we have to coerce here because checking the path's length does
  43354. // guarantee that `node` is not a `Editor`, but TypeScript doesn't know.
  43355. yield [node, path];
  43356. }
  43357. }
  43358. },
  43359. /**
  43360. * Return an iterable of all the element nodes inside a root node. Each iteration
  43361. * will return an `ElementEntry` tuple consisting of `[Element, Path]`. If the
  43362. * root node is an element it will be included in the iteration as well.
  43363. */
  43364. *elements(root) {
  43365. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  43366. for (var [node, path] of Node.nodes(root, options)) {
  43367. if (Element.isElement(node)) {
  43368. yield [node, path];
  43369. }
  43370. }
  43371. },
  43372. /**
  43373. * Get the first node entry in a root node from a path.
  43374. */
  43375. first(root, path) {
  43376. var p = path.slice();
  43377. var n = Node.get(root, p);
  43378. while (n) {
  43379. if (Text.isText(n) || n.children.length === 0) {
  43380. break;
  43381. } else {
  43382. n = n.children[0];
  43383. p.push(0);
  43384. }
  43385. }
  43386. return [n, p];
  43387. },
  43388. /**
  43389. * Get the sliced fragment represented by a range inside a root node.
  43390. */
  43391. fragment(root, range) {
  43392. if (Text.isText(root)) {
  43393. throw new Error("Cannot get a fragment starting from a root text node: ".concat(JSON.stringify(root)));
  43394. }
  43395. var newRoot = immer_1.produce(root, r => {
  43396. var [start, end] = Range.edges(range);
  43397. var iterable = Node.nodes(r, {
  43398. reverse: true,
  43399. pass: (_ref) => {
  43400. var [, path] = _ref;
  43401. return !Range.includes(range, path);
  43402. }
  43403. });
  43404. for (var [, path] of iterable) {
  43405. if (!Range.includes(range, path)) {
  43406. var parent = Node.parent(r, path);
  43407. var index = path[path.length - 1];
  43408. parent.children.splice(index, 1);
  43409. }
  43410. if (Path.equals(path, end.path)) {
  43411. var leaf = Node.leaf(r, path);
  43412. leaf.text = leaf.text.slice(0, end.offset);
  43413. }
  43414. if (Path.equals(path, start.path)) {
  43415. var _leaf = Node.leaf(r, path);
  43416. _leaf.text = _leaf.text.slice(start.offset);
  43417. }
  43418. }
  43419. delete r.selection;
  43420. });
  43421. return newRoot.children;
  43422. },
  43423. /**
  43424. * Get the descendant node referred to by a specific path. If the path is an
  43425. * empty array, it refers to the root node itself.
  43426. */
  43427. get(root, path) {
  43428. var node = root;
  43429. for (var i = 0; i < path.length; i++) {
  43430. var p = path[i];
  43431. if (Text.isText(node) || !node.children[p]) {
  43432. throw new Error("Cannot find a descendant at path [".concat(path, "] in node: ").concat(JSON.stringify(root)));
  43433. }
  43434. node = node.children[p];
  43435. }
  43436. return node;
  43437. },
  43438. /**
  43439. * Check if a descendant node exists at a specific path.
  43440. */
  43441. has(root, path) {
  43442. var node = root;
  43443. for (var i = 0; i < path.length; i++) {
  43444. var p = path[i];
  43445. if (Text.isText(node) || !node.children[p]) {
  43446. return false;
  43447. }
  43448. node = node.children[p];
  43449. }
  43450. return true;
  43451. },
  43452. /**
  43453. * Check if a value implements the `Node` interface.
  43454. */
  43455. isNode(value) {
  43456. return Text.isText(value) || Element.isElement(value) || Editor.isEditor(value);
  43457. },
  43458. /**
  43459. * Check if a value is a list of `Node` objects.
  43460. */
  43461. isNodeList(value) {
  43462. return Array.isArray(value) && (value.length === 0 || Node.isNode(value[0]));
  43463. },
  43464. /**
  43465. * Get the lash node entry in a root node from a path.
  43466. */
  43467. last(root, path) {
  43468. var p = path.slice();
  43469. var n = Node.get(root, p);
  43470. while (n) {
  43471. if (Text.isText(n) || n.children.length === 0) {
  43472. break;
  43473. } else {
  43474. var i = n.children.length - 1;
  43475. n = n.children[i];
  43476. p.push(i);
  43477. }
  43478. }
  43479. return [n, p];
  43480. },
  43481. /**
  43482. * Get the node at a specific path, ensuring it's a leaf text node.
  43483. */
  43484. leaf(root, path) {
  43485. var node = Node.get(root, path);
  43486. if (!Text.isText(node)) {
  43487. throw new Error("Cannot get the leaf node at path [".concat(path, "] because it refers to a non-leaf node: ").concat(node));
  43488. }
  43489. return node;
  43490. },
  43491. /**
  43492. * Return an iterable of the in a branch of the tree, from a specific path.
  43493. *
  43494. * By default the order is top-down, from lowest to highest node in the tree,
  43495. * but you can pass the `reverse: true` option to go bottom-up.
  43496. */
  43497. *levels(root, path) {
  43498. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  43499. for (var p of Path.levels(path, options)) {
  43500. var n = Node.get(root, p);
  43501. yield [n, p];
  43502. }
  43503. },
  43504. /**
  43505. * Check if a node matches a set of props.
  43506. */
  43507. matches(node, props) {
  43508. return Element.isElement(node) && Element.matches(node, props) || Text.isText(node) && Text.matches(node, props);
  43509. },
  43510. /**
  43511. * Return an iterable of all the node entries of a root node. Each entry is
  43512. * returned as a `[Node, Path]` tuple, with the path referring to the node's
  43513. * position inside the root node.
  43514. */
  43515. *nodes(root) {
  43516. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  43517. var {
  43518. pass,
  43519. reverse = false
  43520. } = options;
  43521. var {
  43522. from = [],
  43523. to
  43524. } = options;
  43525. var visited = new Set();
  43526. var p = [];
  43527. var n = root;
  43528. while (true) {
  43529. if (to && (reverse ? Path.isBefore(p, to) : Path.isAfter(p, to))) {
  43530. break;
  43531. }
  43532. if (!visited.has(n)) {
  43533. yield [n, p];
  43534. } // If we're allowed to go downward and we haven't decsended yet, do.
  43535. if (!visited.has(n) && !Text.isText(n) && n.children.length !== 0 && (pass == null || pass([n, p]) === false)) {
  43536. visited.add(n);
  43537. var nextIndex = reverse ? n.children.length - 1 : 0;
  43538. if (Path.isAncestor(p, from)) {
  43539. nextIndex = from[p.length];
  43540. }
  43541. p = p.concat(nextIndex);
  43542. n = Node.get(root, p);
  43543. continue;
  43544. } // If we're at the root and we can't go down, we're done.
  43545. if (p.length === 0) {
  43546. break;
  43547. } // If we're going forward...
  43548. if (!reverse) {
  43549. var newPath = Path.next(p);
  43550. if (Node.has(root, newPath)) {
  43551. p = newPath;
  43552. n = Node.get(root, p);
  43553. continue;
  43554. }
  43555. } // If we're going backward...
  43556. if (reverse && p[p.length - 1] !== 0) {
  43557. var _newPath = Path.previous(p);
  43558. p = _newPath;
  43559. n = Node.get(root, p);
  43560. continue;
  43561. } // Otherwise we're going upward...
  43562. p = Path.parent(p);
  43563. n = Node.get(root, p);
  43564. visited.add(n);
  43565. }
  43566. },
  43567. /**
  43568. * Get the parent of a node at a specific path.
  43569. */
  43570. parent(root, path) {
  43571. var parentPath = Path.parent(path);
  43572. var p = Node.get(root, parentPath);
  43573. if (Text.isText(p)) {
  43574. throw new Error("Cannot get the parent of path [".concat(path, "] because it does not exist in the root."));
  43575. }
  43576. return p;
  43577. },
  43578. /**
  43579. * Get the concatenated text string of a node's content.
  43580. *
  43581. * Note that this will not include spaces or line breaks between block nodes.
  43582. * It is not a user-facing string, but a string for performing offset-related
  43583. * computations for a node.
  43584. */
  43585. string(node) {
  43586. if (Text.isText(node)) {
  43587. return node.text;
  43588. } else {
  43589. return node.children.map(Node.string).join('');
  43590. }
  43591. },
  43592. /**
  43593. * Return an iterable of all leaf text nodes in a root node.
  43594. */
  43595. *texts(root) {
  43596. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  43597. for (var [node, path] of Node.nodes(root, options)) {
  43598. if (Text.isText(node)) {
  43599. yield [node, path];
  43600. }
  43601. }
  43602. }
  43603. };
  43604. 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; }
  43605. 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; }
  43606. var Operation = {
  43607. /**
  43608. * Check of a value is a `NodeOperation` object.
  43609. */
  43610. isNodeOperation(value) {
  43611. return Operation.isOperation(value) && value.type.endsWith('_node');
  43612. },
  43613. /**
  43614. * Check of a value is an `Operation` object.
  43615. */
  43616. isOperation(value) {
  43617. if (!isPlainObject(value)) {
  43618. return false;
  43619. }
  43620. switch (value.type) {
  43621. case 'insert_node':
  43622. return Path.isPath(value.path) && Node.isNode(value.node);
  43623. case 'insert_text':
  43624. return typeof value.offset === 'number' && typeof value.text === 'string' && Path.isPath(value.path);
  43625. case 'merge_node':
  43626. return typeof value.position === 'number' && (typeof value.target === 'number' || value.target === null) && Path.isPath(value.path) && isPlainObject(value.properties);
  43627. case 'move_node':
  43628. return Path.isPath(value.path) && Path.isPath(value.newPath);
  43629. case 'remove_node':
  43630. return Path.isPath(value.path) && Node.isNode(value.node);
  43631. case 'remove_text':
  43632. return typeof value.offset === 'number' && typeof value.text === 'string' && Path.isPath(value.path);
  43633. case 'set_node':
  43634. return Path.isPath(value.path) && isPlainObject(value.properties) && isPlainObject(value.newProperties);
  43635. case 'set_selection':
  43636. return value.properties === null && Range.isRange(value.newProperties) || value.newProperties === null && Range.isRange(value.properties) || isPlainObject(value.properties) && isPlainObject(value.newProperties);
  43637. case 'split_node':
  43638. return Path.isPath(value.path) && typeof value.position === 'number' && (typeof value.target === 'number' || value.target === null) && isPlainObject(value.properties);
  43639. default:
  43640. return false;
  43641. }
  43642. },
  43643. /**
  43644. * Check if a value is a list of `Operation` objects.
  43645. */
  43646. isOperationList(value) {
  43647. return Array.isArray(value) && (value.length === 0 || Operation.isOperation(value[0]));
  43648. },
  43649. /**
  43650. * Check of a value is a `SelectionOperation` object.
  43651. */
  43652. isSelectionOperation(value) {
  43653. return Operation.isOperation(value) && value.type.endsWith('_selection');
  43654. },
  43655. /**
  43656. * Check of a value is a `TextOperation` object.
  43657. */
  43658. isTextOperation(value) {
  43659. return Operation.isOperation(value) && value.type.endsWith('_text');
  43660. },
  43661. /**
  43662. * Invert an operation, returning a new operation that will exactly undo the
  43663. * original when applied.
  43664. */
  43665. inverse(op) {
  43666. switch (op.type) {
  43667. case 'insert_node':
  43668. {
  43669. return _objectSpread$2({}, op, {
  43670. type: 'remove_node'
  43671. });
  43672. }
  43673. case 'insert_text':
  43674. {
  43675. return _objectSpread$2({}, op, {
  43676. type: 'remove_text'
  43677. });
  43678. }
  43679. case 'merge_node':
  43680. {
  43681. return _objectSpread$2({}, op, {
  43682. type: 'split_node',
  43683. path: Path.previous(op.path)
  43684. });
  43685. }
  43686. case 'move_node':
  43687. {
  43688. var {
  43689. newPath,
  43690. path
  43691. } = op; // PERF: in this case the move operation is a no-op anyways.
  43692. if (Path.equals(newPath, path)) {
  43693. return op;
  43694. } // We need to get the original path here, but sometimes the `newPath`
  43695. // is a younger sibling of (or ends before) the original, and this
  43696. // accounts for it.
  43697. var inversePath = Path.transform(path, op);
  43698. var inverseNewPath = Path.transform(Path.next(path), op);
  43699. return _objectSpread$2({}, op, {
  43700. path: inversePath,
  43701. newPath: inverseNewPath
  43702. });
  43703. }
  43704. case 'remove_node':
  43705. {
  43706. return _objectSpread$2({}, op, {
  43707. type: 'insert_node'
  43708. });
  43709. }
  43710. case 'remove_text':
  43711. {
  43712. return _objectSpread$2({}, op, {
  43713. type: 'insert_text'
  43714. });
  43715. }
  43716. case 'set_node':
  43717. {
  43718. var {
  43719. properties,
  43720. newProperties
  43721. } = op;
  43722. return _objectSpread$2({}, op, {
  43723. properties: newProperties,
  43724. newProperties: properties
  43725. });
  43726. }
  43727. case 'set_selection':
  43728. {
  43729. var {
  43730. properties: _properties,
  43731. newProperties: _newProperties
  43732. } = op;
  43733. if (_properties == null) {
  43734. return _objectSpread$2({}, op, {
  43735. properties: _newProperties,
  43736. newProperties: null
  43737. });
  43738. } else if (_newProperties == null) {
  43739. return _objectSpread$2({}, op, {
  43740. properties: null,
  43741. newProperties: _properties
  43742. });
  43743. } else {
  43744. return _objectSpread$2({}, op, {
  43745. properties: _newProperties,
  43746. newProperties: _properties
  43747. });
  43748. }
  43749. }
  43750. case 'split_node':
  43751. {
  43752. return _objectSpread$2({}, op, {
  43753. type: 'merge_node',
  43754. path: Path.next(op.path)
  43755. });
  43756. }
  43757. }
  43758. }
  43759. };
  43760. var Path = {
  43761. /**
  43762. * Get a list of ancestor paths for a given path.
  43763. *
  43764. * The paths are sorted from deepest to shallowest ancestor. However, if the
  43765. * `reverse: true` option is passed, they are reversed.
  43766. */
  43767. ancestors(path) {
  43768. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  43769. var {
  43770. reverse = false
  43771. } = options;
  43772. var paths = Path.levels(path, options);
  43773. if (reverse) {
  43774. paths = paths.slice(1);
  43775. } else {
  43776. paths = paths.slice(0, -1);
  43777. }
  43778. return paths;
  43779. },
  43780. /**
  43781. * Get the common ancestor path of two paths.
  43782. */
  43783. common(path, another) {
  43784. var common = [];
  43785. for (var i = 0; i < path.length && i < another.length; i++) {
  43786. var av = path[i];
  43787. var bv = another[i];
  43788. if (av !== bv) {
  43789. break;
  43790. }
  43791. common.push(av);
  43792. }
  43793. return common;
  43794. },
  43795. /**
  43796. * Compare a path to another, returning an integer indicating whether the path
  43797. * was before, at, or after the other.
  43798. *
  43799. * Note: Two paths of unequal length can still receive a `0` result if one is
  43800. * directly above or below the other. If you want exact matching, use
  43801. * [[Path.equals]] instead.
  43802. */
  43803. compare(path, another) {
  43804. var min = Math.min(path.length, another.length);
  43805. for (var i = 0; i < min; i++) {
  43806. if (path[i] < another[i]) return -1;
  43807. if (path[i] > another[i]) return 1;
  43808. }
  43809. return 0;
  43810. },
  43811. /**
  43812. * Check if a path ends after one of the indexes in another.
  43813. */
  43814. endsAfter(path, another) {
  43815. var i = path.length - 1;
  43816. var as = path.slice(0, i);
  43817. var bs = another.slice(0, i);
  43818. var av = path[i];
  43819. var bv = another[i];
  43820. return Path.equals(as, bs) && av > bv;
  43821. },
  43822. /**
  43823. * Check if a path ends at one of the indexes in another.
  43824. */
  43825. endsAt(path, another) {
  43826. var i = path.length;
  43827. var as = path.slice(0, i);
  43828. var bs = another.slice(0, i);
  43829. return Path.equals(as, bs);
  43830. },
  43831. /**
  43832. * Check if a path ends before one of the indexes in another.
  43833. */
  43834. endsBefore(path, another) {
  43835. var i = path.length - 1;
  43836. var as = path.slice(0, i);
  43837. var bs = another.slice(0, i);
  43838. var av = path[i];
  43839. var bv = another[i];
  43840. return Path.equals(as, bs) && av < bv;
  43841. },
  43842. /**
  43843. * Check if a path is exactly equal to another.
  43844. */
  43845. equals(path, another) {
  43846. return path.length === another.length && path.every((n, i) => n === another[i]);
  43847. },
  43848. /**
  43849. * Check if a path is after another.
  43850. */
  43851. isAfter(path, another) {
  43852. return Path.compare(path, another) === 1;
  43853. },
  43854. /**
  43855. * Check if a path is an ancestor of another.
  43856. */
  43857. isAncestor(path, another) {
  43858. return path.length < another.length && Path.compare(path, another) === 0;
  43859. },
  43860. /**
  43861. * Check if a path is before another.
  43862. */
  43863. isBefore(path, another) {
  43864. return Path.compare(path, another) === -1;
  43865. },
  43866. /**
  43867. * Check if a path is a child of another.
  43868. */
  43869. isChild(path, another) {
  43870. return path.length === another.length + 1 && Path.compare(path, another) === 0;
  43871. },
  43872. /**
  43873. * Check if a path is equal to or an ancestor of another.
  43874. */
  43875. isCommon(path, another) {
  43876. return path.length <= another.length && Path.compare(path, another) === 0;
  43877. },
  43878. /**
  43879. * Check if a path is a descendant of another.
  43880. */
  43881. isDescendant(path, another) {
  43882. return path.length > another.length && Path.compare(path, another) === 0;
  43883. },
  43884. /**
  43885. * Check if a path is the parent of another.
  43886. */
  43887. isParent(path, another) {
  43888. return path.length + 1 === another.length && Path.compare(path, another) === 0;
  43889. },
  43890. /**
  43891. * Check is a value implements the `Path` interface.
  43892. */
  43893. isPath(value) {
  43894. return Array.isArray(value) && (value.length === 0 || typeof value[0] === 'number');
  43895. },
  43896. /**
  43897. * Check if a path is a sibling of another.
  43898. */
  43899. isSibling(path, another) {
  43900. if (path.length !== another.length) {
  43901. return false;
  43902. }
  43903. var as = path.slice(0, -1);
  43904. var bs = another.slice(0, -1);
  43905. var al = path[path.length - 1];
  43906. var bl = another[another.length - 1];
  43907. return al !== bl && Path.equals(as, bs);
  43908. },
  43909. /**
  43910. * Get a list of paths at every level down to a path. Note: this is the same
  43911. * as `Path.ancestors`, but including the path itself.
  43912. *
  43913. * The paths are sorted from shallowest to deepest. However, if the `reverse:
  43914. * true` option is passed, they are reversed.
  43915. */
  43916. levels(path) {
  43917. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  43918. var {
  43919. reverse = false
  43920. } = options;
  43921. var list = [];
  43922. for (var i = 0; i <= path.length; i++) {
  43923. list.push(path.slice(0, i));
  43924. }
  43925. if (reverse) {
  43926. list.reverse();
  43927. }
  43928. return list;
  43929. },
  43930. /**
  43931. * Given a path, get the path to the next sibling node.
  43932. */
  43933. next(path) {
  43934. if (path.length === 0) {
  43935. throw new Error("Cannot get the next path of a root path [".concat(path, "], because it has no next index."));
  43936. }
  43937. var last = path[path.length - 1];
  43938. return path.slice(0, -1).concat(last + 1);
  43939. },
  43940. /**
  43941. * Given a path, return a new path referring to the parent node above it.
  43942. */
  43943. parent(path) {
  43944. if (path.length === 0) {
  43945. throw new Error("Cannot get the parent path of the root path [".concat(path, "]."));
  43946. }
  43947. return path.slice(0, -1);
  43948. },
  43949. /**
  43950. * Given a path, get the path to the previous sibling node.
  43951. */
  43952. previous(path) {
  43953. if (path.length === 0) {
  43954. throw new Error("Cannot get the previous path of a root path [".concat(path, "], because it has no previous index."));
  43955. }
  43956. var last = path[path.length - 1];
  43957. if (last <= 0) {
  43958. throw new Error("Cannot get the previous path of a first child path [".concat(path, "] because it would result in a negative index."));
  43959. }
  43960. return path.slice(0, -1).concat(last - 1);
  43961. },
  43962. /**
  43963. * Get a path relative to an ancestor.
  43964. */
  43965. relative(path, ancestor) {
  43966. if (!Path.isAncestor(ancestor, path) && !Path.equals(path, ancestor)) {
  43967. 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."));
  43968. }
  43969. return path.slice(ancestor.length);
  43970. },
  43971. /**
  43972. * Transform a path by an operation.
  43973. */
  43974. transform(path, operation) {
  43975. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  43976. return immer_1.produce(path, p => {
  43977. var {
  43978. affinity = 'forward'
  43979. } = options; // PERF: Exit early if the operation is guaranteed not to have an effect.
  43980. if (path.length === 0) {
  43981. return;
  43982. }
  43983. switch (operation.type) {
  43984. case 'insert_node':
  43985. {
  43986. var {
  43987. path: op
  43988. } = operation;
  43989. if (Path.equals(op, p) || Path.endsBefore(op, p) || Path.isAncestor(op, p)) {
  43990. p[op.length - 1] += 1;
  43991. }
  43992. break;
  43993. }
  43994. case 'remove_node':
  43995. {
  43996. var {
  43997. path: _op
  43998. } = operation;
  43999. if (Path.equals(_op, p) || Path.isAncestor(_op, p)) {
  44000. return null;
  44001. } else if (Path.endsBefore(_op, p)) {
  44002. p[_op.length - 1] -= 1;
  44003. }
  44004. break;
  44005. }
  44006. case 'merge_node':
  44007. {
  44008. var {
  44009. path: _op2,
  44010. position
  44011. } = operation;
  44012. if (Path.equals(_op2, p) || Path.endsBefore(_op2, p)) {
  44013. p[_op2.length - 1] -= 1;
  44014. } else if (Path.isAncestor(_op2, p)) {
  44015. p[_op2.length - 1] -= 1;
  44016. p[_op2.length] += position;
  44017. }
  44018. break;
  44019. }
  44020. case 'split_node':
  44021. {
  44022. var {
  44023. path: _op3,
  44024. position: _position
  44025. } = operation;
  44026. if (Path.equals(_op3, p)) {
  44027. if (affinity === 'forward') {
  44028. p[p.length - 1] += 1;
  44029. } else if (affinity === 'backward') ; else {
  44030. return null;
  44031. }
  44032. } else if (Path.endsBefore(_op3, p)) {
  44033. p[_op3.length - 1] += 1;
  44034. } else if (Path.isAncestor(_op3, p) && path[_op3.length] >= _position) {
  44035. p[_op3.length - 1] += 1;
  44036. p[_op3.length] -= _position;
  44037. }
  44038. break;
  44039. }
  44040. case 'move_node':
  44041. {
  44042. var {
  44043. path: _op4,
  44044. newPath: onp
  44045. } = operation; // If the old and new path are the same, it's a no-op.
  44046. if (Path.equals(_op4, onp)) {
  44047. return;
  44048. }
  44049. if (Path.isAncestor(_op4, p) || Path.equals(_op4, p)) {
  44050. var copy = onp.slice();
  44051. if (Path.endsBefore(_op4, onp) && _op4.length < onp.length) {
  44052. var i = Math.min(onp.length, _op4.length) - 1;
  44053. copy[i] -= 1;
  44054. }
  44055. return copy.concat(p.slice(_op4.length));
  44056. } else if (Path.endsBefore(onp, p) || Path.equals(onp, p) || Path.isAncestor(onp, p)) {
  44057. if (Path.endsBefore(_op4, p)) {
  44058. p[_op4.length - 1] -= 1;
  44059. }
  44060. p[onp.length - 1] += 1;
  44061. } else if (Path.endsBefore(_op4, p)) {
  44062. if (Path.equals(onp, p)) {
  44063. p[onp.length - 1] += 1;
  44064. }
  44065. p[_op4.length - 1] -= 1;
  44066. }
  44067. break;
  44068. }
  44069. }
  44070. });
  44071. }
  44072. };
  44073. var PathRef = {
  44074. /**
  44075. * Transform the path ref's current value by an operation.
  44076. */
  44077. transform(ref, op) {
  44078. var {
  44079. current,
  44080. affinity
  44081. } = ref;
  44082. if (current == null) {
  44083. return;
  44084. }
  44085. var path = Path.transform(current, op, {
  44086. affinity
  44087. });
  44088. ref.current = path;
  44089. if (path == null) {
  44090. ref.unref();
  44091. }
  44092. }
  44093. };
  44094. 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; }
  44095. 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; }
  44096. var Point = {
  44097. /**
  44098. * Compare a point to another, returning an integer indicating whether the
  44099. * point was before, at, or after the other.
  44100. */
  44101. compare(point, another) {
  44102. var result = Path.compare(point.path, another.path);
  44103. if (result === 0) {
  44104. if (point.offset < another.offset) return -1;
  44105. if (point.offset > another.offset) return 1;
  44106. return 0;
  44107. }
  44108. return result;
  44109. },
  44110. /**
  44111. * Check if a point is after another.
  44112. */
  44113. isAfter(point, another) {
  44114. return Point.compare(point, another) === 1;
  44115. },
  44116. /**
  44117. * Check if a point is before another.
  44118. */
  44119. isBefore(point, another) {
  44120. return Point.compare(point, another) === -1;
  44121. },
  44122. /**
  44123. * Check if a point is exactly equal to another.
  44124. */
  44125. equals(point, another) {
  44126. // PERF: ensure the offsets are equal first since they are cheaper to check.
  44127. return point.offset === another.offset && Path.equals(point.path, another.path);
  44128. },
  44129. /**
  44130. * Check if a value implements the `Point` interface.
  44131. */
  44132. isPoint(value) {
  44133. return isPlainObject(value) && typeof value.offset === 'number' && Path.isPath(value.path);
  44134. },
  44135. /**
  44136. * Transform a point by an operation.
  44137. */
  44138. transform(point, op) {
  44139. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  44140. return immer_1.produce(point, p => {
  44141. var {
  44142. affinity = 'forward'
  44143. } = options;
  44144. var {
  44145. path,
  44146. offset
  44147. } = p;
  44148. switch (op.type) {
  44149. case 'insert_node':
  44150. case 'move_node':
  44151. {
  44152. p.path = Path.transform(path, op, options);
  44153. break;
  44154. }
  44155. case 'insert_text':
  44156. {
  44157. if (Path.equals(op.path, path) && op.offset <= offset) {
  44158. p.offset += op.text.length;
  44159. }
  44160. break;
  44161. }
  44162. case 'merge_node':
  44163. {
  44164. if (Path.equals(op.path, path)) {
  44165. p.offset += op.position;
  44166. }
  44167. p.path = Path.transform(path, op, options);
  44168. break;
  44169. }
  44170. case 'remove_text':
  44171. {
  44172. if (Path.equals(op.path, path) && op.offset <= offset) {
  44173. p.offset -= Math.min(offset - op.offset, op.text.length);
  44174. }
  44175. break;
  44176. }
  44177. case 'remove_node':
  44178. {
  44179. if (Path.equals(op.path, path) || Path.isAncestor(op.path, path)) {
  44180. return null;
  44181. }
  44182. p.path = Path.transform(path, op, options);
  44183. break;
  44184. }
  44185. case 'split_node':
  44186. {
  44187. if (Path.equals(op.path, path)) {
  44188. if (op.position === offset && affinity == null) {
  44189. return null;
  44190. } else if (op.position < offset || op.position === offset && affinity === 'forward') {
  44191. p.offset -= op.position;
  44192. p.path = Path.transform(path, op, _objectSpread$3({}, options, {
  44193. affinity: 'forward'
  44194. }));
  44195. }
  44196. } else {
  44197. p.path = Path.transform(path, op, options);
  44198. }
  44199. break;
  44200. }
  44201. }
  44202. });
  44203. }
  44204. };
  44205. var PointRef = {
  44206. /**
  44207. * Transform the point ref's current value by an operation.
  44208. */
  44209. transform(ref, op) {
  44210. var {
  44211. current,
  44212. affinity
  44213. } = ref;
  44214. if (current == null) {
  44215. return;
  44216. }
  44217. var point = Point.transform(current, op, {
  44218. affinity
  44219. });
  44220. ref.current = point;
  44221. if (point == null) {
  44222. ref.unref();
  44223. }
  44224. }
  44225. };
  44226. 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; }
  44227. 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; }
  44228. var Range = {
  44229. /**
  44230. * Get the start and end points of a range, in the order in which they appear
  44231. * in the document.
  44232. */
  44233. edges(range) {
  44234. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  44235. var {
  44236. reverse = false
  44237. } = options;
  44238. var {
  44239. anchor,
  44240. focus
  44241. } = range;
  44242. return Range.isBackward(range) === reverse ? [anchor, focus] : [focus, anchor];
  44243. },
  44244. /**
  44245. * Get the end point of a range.
  44246. */
  44247. end(range) {
  44248. var [, end] = Range.edges(range);
  44249. return end;
  44250. },
  44251. /**
  44252. * Check if a range is exactly equal to another.
  44253. */
  44254. equals(range, another) {
  44255. return Point.equals(range.anchor, another.anchor) && Point.equals(range.focus, another.focus);
  44256. },
  44257. /**
  44258. * Check if a range includes a path, a point or part of another range.
  44259. */
  44260. includes(range, target) {
  44261. if (Range.isRange(target)) {
  44262. if (Range.includes(range, target.anchor) || Range.includes(range, target.focus)) {
  44263. return true;
  44264. }
  44265. var [rs, re] = Range.edges(range);
  44266. var [ts, te] = Range.edges(target);
  44267. return Point.isBefore(rs, ts) && Point.isAfter(re, te);
  44268. }
  44269. var [start, end] = Range.edges(range);
  44270. var isAfterStart = false;
  44271. var isBeforeEnd = false;
  44272. if (Point.isPoint(target)) {
  44273. isAfterStart = Point.compare(target, start) >= 0;
  44274. isBeforeEnd = Point.compare(target, end) <= 0;
  44275. } else {
  44276. isAfterStart = Path.compare(target, start.path) >= 0;
  44277. isBeforeEnd = Path.compare(target, end.path) <= 0;
  44278. }
  44279. return isAfterStart && isBeforeEnd;
  44280. },
  44281. /**
  44282. * Get the intersection of a range with another.
  44283. */
  44284. intersection(range, another) {
  44285. var rest = _objectWithoutProperties(range, ["anchor", "focus"]);
  44286. var [s1, e1] = Range.edges(range);
  44287. var [s2, e2] = Range.edges(another);
  44288. var start = Point.isBefore(s1, s2) ? s2 : s1;
  44289. var end = Point.isBefore(e1, e2) ? e1 : e2;
  44290. if (Point.isBefore(end, start)) {
  44291. return null;
  44292. } else {
  44293. return _objectSpread$4({
  44294. anchor: start,
  44295. focus: end
  44296. }, rest);
  44297. }
  44298. },
  44299. /**
  44300. * Check if a range is backward, meaning that its anchor point appears in the
  44301. * document _after_ its focus point.
  44302. */
  44303. isBackward(range) {
  44304. var {
  44305. anchor,
  44306. focus
  44307. } = range;
  44308. return Point.isAfter(anchor, focus);
  44309. },
  44310. /**
  44311. * Check if a range is collapsed, meaning that both its anchor and focus
  44312. * points refer to the exact same position in the document.
  44313. */
  44314. isCollapsed(range) {
  44315. var {
  44316. anchor,
  44317. focus
  44318. } = range;
  44319. return Point.equals(anchor, focus);
  44320. },
  44321. /**
  44322. * Check if a range is expanded.
  44323. *
  44324. * This is the opposite of [[Range.isCollapsed]] and is provided for legibility.
  44325. */
  44326. isExpanded(range) {
  44327. return !Range.isCollapsed(range);
  44328. },
  44329. /**
  44330. * Check if a range is forward.
  44331. *
  44332. * This is the opposite of [[Range.isBackward]] and is provided for legibility.
  44333. */
  44334. isForward(range) {
  44335. return !Range.isBackward(range);
  44336. },
  44337. /**
  44338. * Check if a value implements the [[Range]] interface.
  44339. */
  44340. isRange(value) {
  44341. return isPlainObject(value) && Point.isPoint(value.anchor) && Point.isPoint(value.focus);
  44342. },
  44343. /**
  44344. * Iterate through all of the point entries in a range.
  44345. */
  44346. *points(range) {
  44347. yield [range.anchor, 'anchor'];
  44348. yield [range.focus, 'focus'];
  44349. },
  44350. /**
  44351. * Get the start point of a range.
  44352. */
  44353. start(range) {
  44354. var [start] = Range.edges(range);
  44355. return start;
  44356. },
  44357. /**
  44358. * Transform a range by an operation.
  44359. */
  44360. transform(range, op, options) {
  44361. var {
  44362. affinity = 'inward'
  44363. } = options;
  44364. var affinityAnchor;
  44365. var affinityFocus;
  44366. if (affinity === 'inward') {
  44367. if (Range.isForward(range)) {
  44368. affinityAnchor = 'forward';
  44369. affinityFocus = 'backward';
  44370. } else {
  44371. affinityAnchor = 'backward';
  44372. affinityFocus = 'forward';
  44373. }
  44374. } else if (affinity === 'outward') {
  44375. if (Range.isForward(range)) {
  44376. affinityAnchor = 'backward';
  44377. affinityFocus = 'forward';
  44378. } else {
  44379. affinityAnchor = 'forward';
  44380. affinityFocus = 'backward';
  44381. }
  44382. } else {
  44383. affinityAnchor = affinity;
  44384. affinityFocus = affinity;
  44385. }
  44386. return immer_1.produce(range, r => {
  44387. var anchor = Point.transform(r.anchor, op, {
  44388. affinity: affinityAnchor
  44389. });
  44390. var focus = Point.transform(r.focus, op, {
  44391. affinity: affinityFocus
  44392. });
  44393. if (!anchor || !focus) {
  44394. return null;
  44395. }
  44396. r.anchor = anchor;
  44397. r.focus = focus;
  44398. });
  44399. }
  44400. };
  44401. var RangeRef = {
  44402. /**
  44403. * Transform the range ref's current value by an operation.
  44404. */
  44405. transform(ref, op) {
  44406. var {
  44407. current,
  44408. affinity
  44409. } = ref;
  44410. if (current == null) {
  44411. return;
  44412. }
  44413. var path = Range.transform(current, op, {
  44414. affinity
  44415. });
  44416. ref.current = path;
  44417. if (path == null) {
  44418. ref.unref();
  44419. }
  44420. }
  44421. };
  44422. 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; }
  44423. 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; }
  44424. var Text = {
  44425. /**
  44426. * Check if two text nodes are equal.
  44427. */
  44428. equals(text, another) {
  44429. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  44430. var {
  44431. loose = false
  44432. } = options;
  44433. for (var key in text) {
  44434. if (loose && key === 'text') {
  44435. continue;
  44436. }
  44437. if (text[key] !== another[key]) {
  44438. return false;
  44439. }
  44440. }
  44441. for (var _key in another) {
  44442. if (loose && _key === 'text') {
  44443. continue;
  44444. }
  44445. if (text[_key] !== another[_key]) {
  44446. return false;
  44447. }
  44448. }
  44449. return true;
  44450. },
  44451. /**
  44452. * Check if a value implements the `Text` interface.
  44453. */
  44454. isText(value) {
  44455. return isPlainObject(value) && typeof value.text === 'string';
  44456. },
  44457. /**
  44458. * Check if a value is a list of `Text` objects.
  44459. */
  44460. isTextList(value) {
  44461. return Array.isArray(value) && (value.length === 0 || Text.isText(value[0]));
  44462. },
  44463. /**
  44464. * Check if an text matches set of properties.
  44465. *
  44466. * Note: this is for matching custom properties, and it does not ensure that
  44467. * the `text` property are two nodes equal.
  44468. */
  44469. matches(text, props) {
  44470. for (var key in props) {
  44471. if (key === 'text') {
  44472. continue;
  44473. }
  44474. if (text[key] !== props[key]) {
  44475. return false;
  44476. }
  44477. }
  44478. return true;
  44479. },
  44480. /**
  44481. * Get the leaves for a text node given decorations.
  44482. */
  44483. decorations(node, decorations) {
  44484. var leaves = [_objectSpread$5({}, node)];
  44485. for (var dec of decorations) {
  44486. var rest = _objectWithoutProperties(dec, ["anchor", "focus"]);
  44487. var [start, end] = Range.edges(dec);
  44488. var next = [];
  44489. var o = 0;
  44490. for (var leaf of leaves) {
  44491. var {
  44492. length
  44493. } = leaf.text;
  44494. var offset = o;
  44495. o += length; // If the range encompases the entire leaf, add the range.
  44496. if (start.offset <= offset && end.offset >= offset + length) {
  44497. Object.assign(leaf, rest);
  44498. next.push(leaf);
  44499. continue;
  44500. } // If the range starts after the leaf, or ends before it, continue.
  44501. if (start.offset > offset + length || end.offset < offset || end.offset === offset && offset !== 0) {
  44502. next.push(leaf);
  44503. continue;
  44504. } // Otherwise we need to split the leaf, at the start, end, or both,
  44505. // and add the range to the middle intersecting section. Do the end
  44506. // split first since we don't need to update the offset that way.
  44507. var middle = leaf;
  44508. var before = void 0;
  44509. var after = void 0;
  44510. if (end.offset < offset + length) {
  44511. var off = end.offset - offset;
  44512. after = _objectSpread$5({}, middle, {
  44513. text: middle.text.slice(off)
  44514. });
  44515. middle = _objectSpread$5({}, middle, {
  44516. text: middle.text.slice(0, off)
  44517. });
  44518. }
  44519. if (start.offset > offset) {
  44520. var _off = start.offset - offset;
  44521. before = _objectSpread$5({}, middle, {
  44522. text: middle.text.slice(0, _off)
  44523. });
  44524. middle = _objectSpread$5({}, middle, {
  44525. text: middle.text.slice(_off)
  44526. });
  44527. }
  44528. Object.assign(middle, rest);
  44529. if (before) {
  44530. next.push(before);
  44531. }
  44532. next.push(middle);
  44533. if (after) {
  44534. next.push(after);
  44535. }
  44536. }
  44537. leaves = next;
  44538. }
  44539. return leaves;
  44540. }
  44541. };
  44542. 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; }
  44543. 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; }
  44544. var GeneralTransforms = {
  44545. /**
  44546. * Transform the editor by an operation.
  44547. */
  44548. transform(editor, op) {
  44549. editor.children = immer_1.createDraft(editor.children);
  44550. var selection = editor.selection && immer_1.createDraft(editor.selection);
  44551. switch (op.type) {
  44552. case 'insert_node':
  44553. {
  44554. var {
  44555. path,
  44556. node
  44557. } = op;
  44558. var parent = Node.parent(editor, path);
  44559. var index = path[path.length - 1];
  44560. parent.children.splice(index, 0, node);
  44561. if (selection) {
  44562. for (var [point, key] of Range.points(selection)) {
  44563. selection[key] = Point.transform(point, op);
  44564. }
  44565. }
  44566. break;
  44567. }
  44568. case 'insert_text':
  44569. {
  44570. var {
  44571. path: _path,
  44572. offset,
  44573. text
  44574. } = op;
  44575. var _node = Node.leaf(editor, _path);
  44576. var before = _node.text.slice(0, offset);
  44577. var after = _node.text.slice(offset);
  44578. _node.text = before + text + after;
  44579. if (selection) {
  44580. for (var [_point, _key] of Range.points(selection)) {
  44581. selection[_key] = Point.transform(_point, op);
  44582. }
  44583. }
  44584. break;
  44585. }
  44586. case 'merge_node':
  44587. {
  44588. var {
  44589. path: _path2
  44590. } = op;
  44591. var _node2 = Node.get(editor, _path2);
  44592. var prevPath = Path.previous(_path2);
  44593. var prev = Node.get(editor, prevPath);
  44594. var _parent = Node.parent(editor, _path2);
  44595. var _index = _path2[_path2.length - 1];
  44596. if (Text.isText(_node2) && Text.isText(prev)) {
  44597. prev.text += _node2.text;
  44598. } else if (!Text.isText(_node2) && !Text.isText(prev)) {
  44599. prev.children.push(..._node2.children);
  44600. } else {
  44601. throw new Error("Cannot apply a \"merge_node\" operation at path [".concat(_path2, "] to nodes of different interaces: ").concat(_node2, " ").concat(prev));
  44602. }
  44603. _parent.children.splice(_index, 1);
  44604. if (selection) {
  44605. for (var [_point2, _key2] of Range.points(selection)) {
  44606. selection[_key2] = Point.transform(_point2, op);
  44607. }
  44608. }
  44609. break;
  44610. }
  44611. case 'move_node':
  44612. {
  44613. var {
  44614. path: _path3,
  44615. newPath
  44616. } = op;
  44617. if (Path.isAncestor(_path3, newPath)) {
  44618. throw new Error("Cannot move a path [".concat(_path3, "] to new path [").concat(newPath, "] because the destination is inside itself."));
  44619. }
  44620. var _node3 = Node.get(editor, _path3);
  44621. var _parent2 = Node.parent(editor, _path3);
  44622. var _index2 = _path3[_path3.length - 1]; // This is tricky, but since the `path` and `newPath` both refer to
  44623. // the same snapshot in time, there's a mismatch. After either
  44624. // removing the original position, the second step's path can be out
  44625. // of date. So instead of using the `op.newPath` directly, we
  44626. // transform `op.path` to ascertain what the `newPath` would be after
  44627. // the operation was applied.
  44628. _parent2.children.splice(_index2, 1);
  44629. var truePath = Path.transform(_path3, op);
  44630. var newParent = Node.get(editor, Path.parent(truePath));
  44631. var newIndex = truePath[truePath.length - 1];
  44632. newParent.children.splice(newIndex, 0, _node3);
  44633. if (selection) {
  44634. for (var [_point3, _key3] of Range.points(selection)) {
  44635. selection[_key3] = Point.transform(_point3, op);
  44636. }
  44637. }
  44638. break;
  44639. }
  44640. case 'remove_node':
  44641. {
  44642. var {
  44643. path: _path4
  44644. } = op;
  44645. var _index3 = _path4[_path4.length - 1];
  44646. var _parent3 = Node.parent(editor, _path4);
  44647. _parent3.children.splice(_index3, 1); // Transform all of the points in the value, but if the point was in the
  44648. // node that was removed we need to update the range or remove it.
  44649. if (selection) {
  44650. for (var [_point4, _key4] of Range.points(selection)) {
  44651. var result = Point.transform(_point4, op);
  44652. if (selection != null && result != null) {
  44653. selection[_key4] = result;
  44654. } else {
  44655. var _prev = void 0;
  44656. var next = void 0;
  44657. for (var [n, p] of Node.texts(editor)) {
  44658. if (Path.compare(p, _path4) === -1) {
  44659. _prev = [n, p];
  44660. } else {
  44661. next = [n, p];
  44662. break;
  44663. }
  44664. }
  44665. if (_prev) {
  44666. _point4.path = _prev[1];
  44667. _point4.offset = _prev[0].text.length;
  44668. } else if (next) {
  44669. _point4.path = next[1];
  44670. _point4.offset = 0;
  44671. } else {
  44672. selection = null;
  44673. }
  44674. }
  44675. }
  44676. }
  44677. break;
  44678. }
  44679. case 'remove_text':
  44680. {
  44681. var {
  44682. path: _path5,
  44683. offset: _offset,
  44684. text: _text
  44685. } = op;
  44686. var _node4 = Node.leaf(editor, _path5);
  44687. var _before = _node4.text.slice(0, _offset);
  44688. var _after = _node4.text.slice(_offset + _text.length);
  44689. _node4.text = _before + _after;
  44690. if (selection) {
  44691. for (var [_point5, _key5] of Range.points(selection)) {
  44692. selection[_key5] = Point.transform(_point5, op);
  44693. }
  44694. }
  44695. break;
  44696. }
  44697. case 'set_node':
  44698. {
  44699. var {
  44700. path: _path6,
  44701. newProperties
  44702. } = op;
  44703. if (_path6.length === 0) {
  44704. throw new Error("Cannot set properties on the root node!");
  44705. }
  44706. var _node5 = Node.get(editor, _path6);
  44707. for (var _key6 in newProperties) {
  44708. if (_key6 === 'children' || _key6 === 'text') {
  44709. throw new Error("Cannot set the \"".concat(_key6, "\" property of nodes!"));
  44710. }
  44711. var value = newProperties[_key6];
  44712. if (value == null) {
  44713. delete _node5[_key6];
  44714. } else {
  44715. _node5[_key6] = value;
  44716. }
  44717. }
  44718. break;
  44719. }
  44720. case 'set_selection':
  44721. {
  44722. var {
  44723. newProperties: _newProperties
  44724. } = op;
  44725. if (_newProperties == null) {
  44726. selection = _newProperties;
  44727. } else if (selection == null) {
  44728. if (!Range.isRange(_newProperties)) {
  44729. throw new Error("Cannot apply an incomplete \"set_selection\" operation properties ".concat(JSON.stringify(_newProperties), " when there is no current selection."));
  44730. }
  44731. selection = _newProperties;
  44732. } else {
  44733. Object.assign(selection, _newProperties);
  44734. }
  44735. break;
  44736. }
  44737. case 'split_node':
  44738. {
  44739. var {
  44740. path: _path7,
  44741. position,
  44742. properties
  44743. } = op;
  44744. if (_path7.length === 0) {
  44745. throw new Error("Cannot apply a \"split_node\" operation at path [".concat(_path7, "] because the root node cannot be split."));
  44746. }
  44747. var _node6 = Node.get(editor, _path7);
  44748. var _parent4 = Node.parent(editor, _path7);
  44749. var _index4 = _path7[_path7.length - 1];
  44750. var newNode;
  44751. if (Text.isText(_node6)) {
  44752. var _before2 = _node6.text.slice(0, position);
  44753. var _after2 = _node6.text.slice(position);
  44754. _node6.text = _before2;
  44755. newNode = _objectSpread$6({}, _node6, {}, properties, {
  44756. text: _after2
  44757. });
  44758. } else {
  44759. var _before3 = _node6.children.slice(0, position);
  44760. var _after3 = _node6.children.slice(position);
  44761. _node6.children = _before3;
  44762. newNode = _objectSpread$6({}, _node6, {}, properties, {
  44763. children: _after3
  44764. });
  44765. }
  44766. _parent4.children.splice(_index4 + 1, 0, newNode);
  44767. if (selection) {
  44768. for (var [_point6, _key7] of Range.points(selection)) {
  44769. selection[_key7] = Point.transform(_point6, op);
  44770. }
  44771. }
  44772. break;
  44773. }
  44774. }
  44775. editor.children = immer_1.finishDraft(editor.children);
  44776. if (selection) {
  44777. editor.selection = immer_1.isDraft(selection) ? immer_1.finishDraft(selection) : selection;
  44778. } else {
  44779. editor.selection = null;
  44780. }
  44781. }
  44782. };
  44783. 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; }
  44784. 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; }
  44785. var NodeTransforms = {
  44786. /**
  44787. * Insert nodes at a specific location in the Editor.
  44788. */
  44789. insertNodes(editor, nodes) {
  44790. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  44791. Editor.withoutNormalizing(editor, () => {
  44792. var {
  44793. hanging = false,
  44794. voids = false,
  44795. mode = 'lowest'
  44796. } = options;
  44797. var {
  44798. at,
  44799. match,
  44800. select
  44801. } = options;
  44802. if (Node.isNode(nodes)) {
  44803. nodes = [nodes];
  44804. }
  44805. if (nodes.length === 0) {
  44806. return;
  44807. }
  44808. var [node] = nodes; // By default, use the selection as the target location. But if there is
  44809. // no selection, insert at the end of the document since that is such a
  44810. // common use case when inserting from a non-selected state.
  44811. if (!at) {
  44812. if (editor.selection) {
  44813. at = editor.selection;
  44814. } else if (editor.children.length > 0) {
  44815. at = Editor.end(editor, []);
  44816. } else {
  44817. at = [0];
  44818. }
  44819. select = true;
  44820. }
  44821. if (select == null) {
  44822. select = false;
  44823. }
  44824. if (Range.isRange(at)) {
  44825. if (!hanging) {
  44826. at = Editor.unhangRange(editor, at);
  44827. }
  44828. if (Range.isCollapsed(at)) {
  44829. at = at.anchor;
  44830. } else {
  44831. var [, end] = Range.edges(at);
  44832. var pointRef = Editor.pointRef(editor, end);
  44833. Transforms.delete(editor, {
  44834. at
  44835. });
  44836. at = pointRef.unref();
  44837. }
  44838. }
  44839. if (Point.isPoint(at)) {
  44840. if (match == null) {
  44841. if (Text.isText(node)) {
  44842. match = n => Text.isText(n);
  44843. } else if (editor.isInline(node)) {
  44844. match = n => Text.isText(n) || Editor.isInline(editor, n);
  44845. } else {
  44846. match = n => Editor.isBlock(editor, n);
  44847. }
  44848. }
  44849. var [entry] = Editor.nodes(editor, {
  44850. at: at.path,
  44851. match,
  44852. mode,
  44853. voids
  44854. });
  44855. if (entry) {
  44856. var [, _matchPath] = entry;
  44857. var pathRef = Editor.pathRef(editor, _matchPath);
  44858. var isAtEnd = Editor.isEnd(editor, at, _matchPath);
  44859. Transforms.splitNodes(editor, {
  44860. at,
  44861. match,
  44862. mode,
  44863. voids
  44864. });
  44865. var path = pathRef.unref();
  44866. at = isAtEnd ? Path.next(path) : path;
  44867. } else {
  44868. return;
  44869. }
  44870. }
  44871. var parentPath = Path.parent(at);
  44872. var index = at[at.length - 1];
  44873. if (!voids && Editor.void(editor, {
  44874. at: parentPath
  44875. })) {
  44876. return;
  44877. }
  44878. for (var _node of nodes) {
  44879. var _path = parentPath.concat(index);
  44880. index++;
  44881. editor.apply({
  44882. type: 'insert_node',
  44883. path: _path,
  44884. node: _node
  44885. });
  44886. }
  44887. if (select) {
  44888. var point = Editor.end(editor, at);
  44889. if (point) {
  44890. Transforms.select(editor, point);
  44891. }
  44892. }
  44893. });
  44894. },
  44895. /**
  44896. * Lift nodes at a specific location upwards in the document tree, splitting
  44897. * their parent in two if necessary.
  44898. */
  44899. liftNodes(editor) {
  44900. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  44901. Editor.withoutNormalizing(editor, () => {
  44902. var {
  44903. at = editor.selection,
  44904. mode = 'lowest',
  44905. voids = false
  44906. } = options;
  44907. var {
  44908. match
  44909. } = options;
  44910. if (match == null) {
  44911. match = Path.isPath(at) ? matchPath(editor, at) : n => Editor.isBlock(editor, n);
  44912. }
  44913. if (!at) {
  44914. return;
  44915. }
  44916. var matches = Editor.nodes(editor, {
  44917. at,
  44918. match,
  44919. mode,
  44920. voids
  44921. });
  44922. var pathRefs = Array.from(matches, (_ref) => {
  44923. var [, p] = _ref;
  44924. return Editor.pathRef(editor, p);
  44925. });
  44926. for (var pathRef of pathRefs) {
  44927. var path = pathRef.unref();
  44928. if (path.length < 2) {
  44929. throw new Error("Cannot lift node at a path [".concat(path, "] because it has a depth of less than `2`."));
  44930. }
  44931. var [parent, parentPath] = Editor.node(editor, Path.parent(path));
  44932. var index = path[path.length - 1];
  44933. var {
  44934. length
  44935. } = parent.children;
  44936. if (length === 1) {
  44937. var toPath = Path.next(parentPath);
  44938. Transforms.moveNodes(editor, {
  44939. at: path,
  44940. to: toPath,
  44941. voids
  44942. });
  44943. Transforms.removeNodes(editor, {
  44944. at: parentPath,
  44945. voids
  44946. });
  44947. } else if (index === 0) {
  44948. Transforms.moveNodes(editor, {
  44949. at: path,
  44950. to: parentPath,
  44951. voids
  44952. });
  44953. } else if (index === length - 1) {
  44954. var _toPath = Path.next(parentPath);
  44955. Transforms.moveNodes(editor, {
  44956. at: path,
  44957. to: _toPath,
  44958. voids
  44959. });
  44960. } else {
  44961. var splitPath = Path.next(path);
  44962. var _toPath2 = Path.next(parentPath);
  44963. Transforms.splitNodes(editor, {
  44964. at: splitPath,
  44965. voids
  44966. });
  44967. Transforms.moveNodes(editor, {
  44968. at: path,
  44969. to: _toPath2,
  44970. voids
  44971. });
  44972. }
  44973. }
  44974. });
  44975. },
  44976. /**
  44977. * Merge a node at a location with the previous node of the same depth,
  44978. * removing any empty containing nodes after the merge if necessary.
  44979. */
  44980. mergeNodes(editor) {
  44981. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  44982. Editor.withoutNormalizing(editor, () => {
  44983. var {
  44984. match,
  44985. at = editor.selection
  44986. } = options;
  44987. var {
  44988. hanging = false,
  44989. voids = false,
  44990. mode = 'lowest'
  44991. } = options;
  44992. if (!at) {
  44993. return;
  44994. }
  44995. if (match == null) {
  44996. if (Path.isPath(at)) {
  44997. var [parent] = Editor.parent(editor, at);
  44998. match = n => parent.children.includes(n);
  44999. } else {
  45000. match = n => Editor.isBlock(editor, n);
  45001. }
  45002. }
  45003. if (!hanging && Range.isRange(at)) {
  45004. at = Editor.unhangRange(editor, at);
  45005. }
  45006. if (Range.isRange(at)) {
  45007. if (Range.isCollapsed(at)) {
  45008. at = at.anchor;
  45009. } else {
  45010. var [, end] = Range.edges(at);
  45011. var pointRef = Editor.pointRef(editor, end);
  45012. Transforms.delete(editor, {
  45013. at
  45014. });
  45015. at = pointRef.unref();
  45016. if (options.at == null) {
  45017. Transforms.select(editor, at);
  45018. }
  45019. }
  45020. }
  45021. var [current] = Editor.nodes(editor, {
  45022. at,
  45023. match,
  45024. voids,
  45025. mode
  45026. });
  45027. var prev = Editor.previous(editor, {
  45028. at,
  45029. match,
  45030. voids,
  45031. mode
  45032. });
  45033. if (!current || !prev) {
  45034. return;
  45035. }
  45036. var [node, path] = current;
  45037. var [prevNode, prevPath] = prev;
  45038. if (path.length === 0 || prevPath.length === 0) {
  45039. return;
  45040. }
  45041. var newPath = Path.next(prevPath);
  45042. var commonPath = Path.common(path, prevPath);
  45043. var isPreviousSibling = Path.isSibling(path, prevPath);
  45044. var levels = Array.from(Editor.levels(editor, {
  45045. at: path
  45046. }), (_ref2) => {
  45047. var [n] = _ref2;
  45048. return n;
  45049. }).slice(commonPath.length).slice(0, -1); // Determine if the merge will leave an ancestor of the path empty as a
  45050. // result, in which case we'll want to remove it after merging.
  45051. var emptyAncestor = Editor.above(editor, {
  45052. at: path,
  45053. mode: 'highest',
  45054. match: n => levels.includes(n) && Element.isElement(n) && n.children.length === 1
  45055. });
  45056. var emptyRef = emptyAncestor && Editor.pathRef(editor, emptyAncestor[1]);
  45057. var properties;
  45058. var position; // Ensure that the nodes are equivalent, and figure out what the position
  45059. // and extra properties of the merge will be.
  45060. if (Text.isText(node) && Text.isText(prevNode)) {
  45061. var rest = _objectWithoutProperties(node, ["text"]);
  45062. position = prevNode.text.length;
  45063. properties = rest;
  45064. } else if (Element.isElement(node) && Element.isElement(prevNode)) {
  45065. var rest = _objectWithoutProperties(node, ["children"]);
  45066. position = prevNode.children.length;
  45067. properties = rest;
  45068. } else {
  45069. 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)));
  45070. } // If the node isn't already the next sibling of the previous node, move
  45071. // it so that it is before merging.
  45072. if (!isPreviousSibling) {
  45073. Transforms.moveNodes(editor, {
  45074. at: path,
  45075. to: newPath,
  45076. voids
  45077. });
  45078. } // If there was going to be an empty ancestor of the node that was merged,
  45079. // we remove it from the tree.
  45080. if (emptyRef) {
  45081. Transforms.removeNodes(editor, {
  45082. at: emptyRef.current,
  45083. voids
  45084. });
  45085. } // If the target node that we're merging with is empty, remove it instead
  45086. // of merging the two. This is a common rich text editor behavior to
  45087. // prevent losing formatting when deleting entire nodes when you have a
  45088. // hanging selection.
  45089. if (Element.isElement(prevNode) && Editor.isEmpty(editor, prevNode) || Text.isText(prevNode) && prevNode.text === '') {
  45090. Transforms.removeNodes(editor, {
  45091. at: prevPath,
  45092. voids
  45093. });
  45094. } else {
  45095. editor.apply({
  45096. type: 'merge_node',
  45097. path: newPath,
  45098. position,
  45099. target: null,
  45100. properties
  45101. });
  45102. }
  45103. if (emptyRef) {
  45104. emptyRef.unref();
  45105. }
  45106. });
  45107. },
  45108. /**
  45109. * Move the nodes at a location to a new location.
  45110. */
  45111. moveNodes(editor, options) {
  45112. Editor.withoutNormalizing(editor, () => {
  45113. var {
  45114. to,
  45115. at = editor.selection,
  45116. mode = 'lowest',
  45117. voids = false
  45118. } = options;
  45119. var {
  45120. match
  45121. } = options;
  45122. if (!at) {
  45123. return;
  45124. }
  45125. if (match == null) {
  45126. match = Path.isPath(at) ? matchPath(editor, at) : n => Editor.isBlock(editor, n);
  45127. }
  45128. var toRef = Editor.pathRef(editor, to);
  45129. var targets = Editor.nodes(editor, {
  45130. at,
  45131. match,
  45132. mode,
  45133. voids
  45134. });
  45135. var pathRefs = Array.from(targets, (_ref3) => {
  45136. var [, p] = _ref3;
  45137. return Editor.pathRef(editor, p);
  45138. });
  45139. for (var pathRef of pathRefs) {
  45140. var path = pathRef.unref();
  45141. var newPath = toRef.current;
  45142. if (path.length !== 0) {
  45143. editor.apply({
  45144. type: 'move_node',
  45145. path,
  45146. newPath
  45147. });
  45148. }
  45149. }
  45150. toRef.unref();
  45151. });
  45152. },
  45153. /**
  45154. * Remove the nodes at a specific location in the document.
  45155. */
  45156. removeNodes(editor) {
  45157. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  45158. Editor.withoutNormalizing(editor, () => {
  45159. var {
  45160. hanging = false,
  45161. voids = false,
  45162. mode = 'lowest'
  45163. } = options;
  45164. var {
  45165. at = editor.selection,
  45166. match
  45167. } = options;
  45168. if (!at) {
  45169. return;
  45170. }
  45171. if (match == null) {
  45172. match = Path.isPath(at) ? matchPath(editor, at) : n => Editor.isBlock(editor, n);
  45173. }
  45174. if (!hanging && Range.isRange(at)) {
  45175. at = Editor.unhangRange(editor, at);
  45176. }
  45177. var depths = Editor.nodes(editor, {
  45178. at,
  45179. match,
  45180. mode,
  45181. voids
  45182. });
  45183. var pathRefs = Array.from(depths, (_ref4) => {
  45184. var [, p] = _ref4;
  45185. return Editor.pathRef(editor, p);
  45186. });
  45187. for (var pathRef of pathRefs) {
  45188. var path = pathRef.unref();
  45189. if (path) {
  45190. var [node] = Editor.node(editor, path);
  45191. editor.apply({
  45192. type: 'remove_node',
  45193. path,
  45194. node
  45195. });
  45196. }
  45197. }
  45198. });
  45199. },
  45200. /**
  45201. * Set new properties on the nodes at a location.
  45202. */
  45203. setNodes(editor, props) {
  45204. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  45205. Editor.withoutNormalizing(editor, () => {
  45206. var {
  45207. match,
  45208. at = editor.selection
  45209. } = options;
  45210. var {
  45211. hanging = false,
  45212. mode = 'lowest',
  45213. split = false,
  45214. voids = false
  45215. } = options;
  45216. if (!at) {
  45217. return;
  45218. }
  45219. if (match == null) {
  45220. match = Path.isPath(at) ? matchPath(editor, at) : n => Editor.isBlock(editor, n);
  45221. }
  45222. if (!hanging && Range.isRange(at)) {
  45223. at = Editor.unhangRange(editor, at);
  45224. }
  45225. if (split && Range.isRange(at)) {
  45226. var rangeRef = Editor.rangeRef(editor, at, {
  45227. affinity: 'inward'
  45228. });
  45229. var [start, end] = Range.edges(at);
  45230. var splitMode = mode === 'lowest' ? 'lowest' : 'highest';
  45231. Transforms.splitNodes(editor, {
  45232. at: end,
  45233. match,
  45234. mode: splitMode,
  45235. voids
  45236. });
  45237. Transforms.splitNodes(editor, {
  45238. at: start,
  45239. match,
  45240. mode: splitMode,
  45241. voids
  45242. });
  45243. at = rangeRef.unref();
  45244. if (options.at == null) {
  45245. Transforms.select(editor, at);
  45246. }
  45247. }
  45248. for (var [node, path] of Editor.nodes(editor, {
  45249. at,
  45250. match,
  45251. mode,
  45252. voids
  45253. })) {
  45254. var properties = {};
  45255. var newProperties = {}; // You can't set properties on the editor node.
  45256. if (path.length === 0) {
  45257. continue;
  45258. }
  45259. for (var k in props) {
  45260. if (k === 'children' || k === 'text') {
  45261. continue;
  45262. }
  45263. if (props[k] !== node[k]) {
  45264. properties[k] = node[k];
  45265. newProperties[k] = props[k];
  45266. }
  45267. }
  45268. if (Object.keys(newProperties).length !== 0) {
  45269. editor.apply({
  45270. type: 'set_node',
  45271. path,
  45272. properties,
  45273. newProperties
  45274. });
  45275. }
  45276. }
  45277. });
  45278. },
  45279. /**
  45280. * Split the nodes at a specific location.
  45281. */
  45282. splitNodes(editor) {
  45283. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  45284. Editor.withoutNormalizing(editor, () => {
  45285. var {
  45286. mode = 'lowest',
  45287. voids = false
  45288. } = options;
  45289. var {
  45290. match,
  45291. at = editor.selection,
  45292. height = 0,
  45293. always = false
  45294. } = options;
  45295. if (match == null) {
  45296. match = n => Editor.isBlock(editor, n);
  45297. }
  45298. if (Range.isRange(at)) {
  45299. at = deleteRange(editor, at);
  45300. } // If the target is a path, the default height-skipping and position
  45301. // counters need to account for us potentially splitting at a non-leaf.
  45302. if (Path.isPath(at)) {
  45303. var path = at;
  45304. var point = Editor.point(editor, path);
  45305. var [parent] = Editor.parent(editor, path);
  45306. match = n => n === parent;
  45307. height = point.path.length - path.length + 1;
  45308. at = point;
  45309. always = true;
  45310. }
  45311. if (!at) {
  45312. return;
  45313. }
  45314. var beforeRef = Editor.pointRef(editor, at, {
  45315. affinity: 'backward'
  45316. });
  45317. var [highest] = Editor.nodes(editor, {
  45318. at,
  45319. match,
  45320. mode,
  45321. voids
  45322. });
  45323. if (!highest) {
  45324. return;
  45325. }
  45326. var voidMatch = Editor.void(editor, {
  45327. at,
  45328. mode: 'highest'
  45329. });
  45330. var nudge = 0;
  45331. if (!voids && voidMatch) {
  45332. var [voidNode, voidPath] = voidMatch;
  45333. if (Element.isElement(voidNode) && editor.isInline(voidNode)) {
  45334. var after = Editor.after(editor, voidPath);
  45335. if (!after) {
  45336. var text = {
  45337. text: ''
  45338. };
  45339. var afterPath = Path.next(voidPath);
  45340. Transforms.insertNodes(editor, text, {
  45341. at: afterPath,
  45342. voids
  45343. });
  45344. after = Editor.point(editor, afterPath);
  45345. }
  45346. at = after;
  45347. always = true;
  45348. }
  45349. var siblingHeight = at.path.length - voidPath.length;
  45350. height = siblingHeight + 1;
  45351. always = true;
  45352. }
  45353. var afterRef = Editor.pointRef(editor, at);
  45354. var depth = at.path.length - height;
  45355. var [, highestPath] = highest;
  45356. var lowestPath = at.path.slice(0, depth);
  45357. var position = height === 0 ? at.offset : at.path[depth] + nudge;
  45358. var target = null;
  45359. for (var [node, _path2] of Editor.levels(editor, {
  45360. at: lowestPath,
  45361. reverse: true,
  45362. voids
  45363. })) {
  45364. var split = false;
  45365. if (_path2.length < highestPath.length || _path2.length === 0 || !voids && Editor.isVoid(editor, node)) {
  45366. break;
  45367. }
  45368. var _point = beforeRef.current;
  45369. var isEnd = Editor.isEnd(editor, _point, _path2);
  45370. if (always || !beforeRef || !Editor.isEdge(editor, _point, _path2)) {
  45371. split = true;
  45372. var properties = _objectWithoutProperties(node, ["text", "children"]);
  45373. editor.apply({
  45374. type: 'split_node',
  45375. path: _path2,
  45376. position,
  45377. target,
  45378. properties
  45379. });
  45380. }
  45381. target = position;
  45382. position = _path2[_path2.length - 1] + (split || isEnd ? 1 : 0);
  45383. }
  45384. if (options.at == null) {
  45385. var _point2 = afterRef.current || Editor.end(editor, []);
  45386. Transforms.select(editor, _point2);
  45387. }
  45388. beforeRef.unref();
  45389. afterRef.unref();
  45390. });
  45391. },
  45392. /**
  45393. * Unset properties on the nodes at a location.
  45394. */
  45395. unsetNodes(editor, props) {
  45396. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  45397. if (!Array.isArray(props)) {
  45398. props = [props];
  45399. }
  45400. var obj = {};
  45401. for (var key of props) {
  45402. obj[key] = null;
  45403. }
  45404. Transforms.setNodes(editor, obj, options);
  45405. },
  45406. /**
  45407. * Unwrap the nodes at a location from a parent node, splitting the parent if
  45408. * necessary to ensure that only the content in the range is unwrapped.
  45409. */
  45410. unwrapNodes(editor, options) {
  45411. Editor.withoutNormalizing(editor, () => {
  45412. var {
  45413. mode = 'lowest',
  45414. split = false,
  45415. voids = false
  45416. } = options;
  45417. var {
  45418. at = editor.selection,
  45419. match
  45420. } = options;
  45421. if (!at) {
  45422. return;
  45423. }
  45424. if (match == null) {
  45425. match = Path.isPath(at) ? matchPath(editor, at) : n => Editor.isBlock(editor, n);
  45426. }
  45427. if (Path.isPath(at)) {
  45428. at = Editor.range(editor, at);
  45429. }
  45430. var rangeRef = Range.isRange(at) ? Editor.rangeRef(editor, at) : null;
  45431. var matches = Editor.nodes(editor, {
  45432. at,
  45433. match,
  45434. mode,
  45435. voids
  45436. });
  45437. var pathRefs = Array.from(matches, (_ref5) => {
  45438. var [, p] = _ref5;
  45439. return Editor.pathRef(editor, p);
  45440. });
  45441. var _loop = function _loop(pathRef) {
  45442. var path = pathRef.unref();
  45443. var [node] = Editor.node(editor, path);
  45444. var range = Editor.range(editor, path);
  45445. if (split && rangeRef) {
  45446. range = Range.intersection(rangeRef.current, range);
  45447. }
  45448. Transforms.liftNodes(editor, {
  45449. at: range,
  45450. match: n => node.children.includes(n),
  45451. voids
  45452. });
  45453. };
  45454. for (var pathRef of pathRefs) {
  45455. _loop(pathRef);
  45456. }
  45457. if (rangeRef) {
  45458. rangeRef.unref();
  45459. }
  45460. });
  45461. },
  45462. /**
  45463. * Wrap the nodes at a location in a new container node, splitting the edges
  45464. * of the range first to ensure that only the content in the range is wrapped.
  45465. */
  45466. wrapNodes(editor, element) {
  45467. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  45468. Editor.withoutNormalizing(editor, () => {
  45469. var {
  45470. mode = 'lowest',
  45471. split = false,
  45472. voids = false
  45473. } = options;
  45474. var {
  45475. match,
  45476. at = editor.selection
  45477. } = options;
  45478. if (!at) {
  45479. return;
  45480. }
  45481. if (match == null) {
  45482. if (Path.isPath(at)) {
  45483. match = matchPath(editor, at);
  45484. } else if (editor.isInline(element)) {
  45485. match = n => Editor.isInline(editor, n) || Text.isText(n);
  45486. } else {
  45487. match = n => Editor.isBlock(editor, n);
  45488. }
  45489. }
  45490. if (split && Range.isRange(at)) {
  45491. var [start, end] = Range.edges(at);
  45492. var rangeRef = Editor.rangeRef(editor, at, {
  45493. affinity: 'inward'
  45494. });
  45495. Transforms.splitNodes(editor, {
  45496. at: end,
  45497. match,
  45498. voids
  45499. });
  45500. Transforms.splitNodes(editor, {
  45501. at: start,
  45502. match,
  45503. voids
  45504. });
  45505. at = rangeRef.unref();
  45506. if (options.at == null) {
  45507. Transforms.select(editor, at);
  45508. }
  45509. }
  45510. var roots = Array.from(Editor.nodes(editor, {
  45511. at,
  45512. match: editor.isInline(element) ? n => Editor.isBlock(editor, n) : n => Editor.isEditor(n),
  45513. mode: 'highest',
  45514. voids
  45515. }));
  45516. for (var [, rootPath] of roots) {
  45517. var a = Range.isRange(at) ? Range.intersection(at, Editor.range(editor, rootPath)) : at;
  45518. if (!a) {
  45519. continue;
  45520. }
  45521. var matches = Array.from(Editor.nodes(editor, {
  45522. at: a,
  45523. match,
  45524. mode,
  45525. voids
  45526. }));
  45527. if (matches.length > 0) {
  45528. (function () {
  45529. var [first] = matches;
  45530. var last = matches[matches.length - 1];
  45531. var [, firstPath] = first;
  45532. var [, lastPath] = last;
  45533. var commonPath = Path.equals(firstPath, lastPath) ? Path.parent(firstPath) : Path.common(firstPath, lastPath);
  45534. var range = Editor.range(editor, firstPath, lastPath);
  45535. var [commonNode] = Editor.node(editor, commonPath);
  45536. var depth = commonPath.length + 1;
  45537. var wrapperPath = Path.next(lastPath.slice(0, depth));
  45538. var wrapper = _objectSpread$7({}, element, {
  45539. children: []
  45540. });
  45541. Transforms.insertNodes(editor, wrapper, {
  45542. at: wrapperPath,
  45543. voids
  45544. });
  45545. Transforms.moveNodes(editor, {
  45546. at: range,
  45547. match: n => commonNode.children.includes(n),
  45548. to: wrapperPath.concat(0),
  45549. voids
  45550. });
  45551. })();
  45552. }
  45553. }
  45554. });
  45555. }
  45556. };
  45557. /**
  45558. * Convert a range into a point by deleting it's content.
  45559. */
  45560. var deleteRange = (editor, range) => {
  45561. if (Range.isCollapsed(range)) {
  45562. return range.anchor;
  45563. } else {
  45564. var [, end] = Range.edges(range);
  45565. var pointRef = Editor.pointRef(editor, end);
  45566. Transforms.delete(editor, {
  45567. at: range
  45568. });
  45569. return pointRef.unref();
  45570. }
  45571. };
  45572. var matchPath = (editor, path) => {
  45573. var [node] = Editor.node(editor, path);
  45574. return n => n === node;
  45575. };
  45576. var SelectionTransforms = {
  45577. /**
  45578. * Collapse the selection.
  45579. */
  45580. collapse(editor) {
  45581. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  45582. var {
  45583. edge = 'anchor'
  45584. } = options;
  45585. var {
  45586. selection
  45587. } = editor;
  45588. if (!selection) {
  45589. return;
  45590. } else if (edge === 'anchor') {
  45591. Transforms.select(editor, selection.anchor);
  45592. } else if (edge === 'focus') {
  45593. Transforms.select(editor, selection.focus);
  45594. } else if (edge === 'start') {
  45595. var [start] = Range.edges(selection);
  45596. Transforms.select(editor, start);
  45597. } else if (edge === 'end') {
  45598. var [, end] = Range.edges(selection);
  45599. Transforms.select(editor, end);
  45600. }
  45601. },
  45602. /**
  45603. * Unset the selection.
  45604. */
  45605. deselect(editor) {
  45606. var {
  45607. selection
  45608. } = editor;
  45609. if (selection) {
  45610. editor.apply({
  45611. type: 'set_selection',
  45612. properties: selection,
  45613. newProperties: null
  45614. });
  45615. }
  45616. },
  45617. /**
  45618. * Move the selection's point forward or backward.
  45619. */
  45620. move(editor) {
  45621. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  45622. var {
  45623. selection
  45624. } = editor;
  45625. var {
  45626. distance = 1,
  45627. unit = 'character',
  45628. reverse = false
  45629. } = options;
  45630. var {
  45631. edge = null
  45632. } = options;
  45633. if (!selection) {
  45634. return;
  45635. }
  45636. if (edge === 'start') {
  45637. edge = Range.isBackward(selection) ? 'focus' : 'anchor';
  45638. }
  45639. if (edge === 'end') {
  45640. edge = Range.isBackward(selection) ? 'anchor' : 'focus';
  45641. }
  45642. var {
  45643. anchor,
  45644. focus
  45645. } = selection;
  45646. var opts = {
  45647. distance,
  45648. unit
  45649. };
  45650. var props = {};
  45651. if (edge == null || edge === 'anchor') {
  45652. var point = reverse ? Editor.before(editor, anchor, opts) : Editor.after(editor, anchor, opts);
  45653. if (point) {
  45654. props.anchor = point;
  45655. }
  45656. }
  45657. if (edge == null || edge === 'focus') {
  45658. var _point = reverse ? Editor.before(editor, focus, opts) : Editor.after(editor, focus, opts);
  45659. if (_point) {
  45660. props.focus = _point;
  45661. }
  45662. }
  45663. Transforms.setSelection(editor, props);
  45664. },
  45665. /**
  45666. * Set the selection to a new value.
  45667. */
  45668. select(editor, target) {
  45669. var {
  45670. selection
  45671. } = editor;
  45672. target = Editor.range(editor, target);
  45673. if (selection) {
  45674. Transforms.setSelection(editor, target);
  45675. return;
  45676. }
  45677. if (!Range.isRange(target)) {
  45678. 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)));
  45679. }
  45680. editor.apply({
  45681. type: 'set_selection',
  45682. properties: selection,
  45683. newProperties: target
  45684. });
  45685. },
  45686. /**
  45687. * Set new properties on one of the selection's points.
  45688. */
  45689. setPoint(editor, props, options) {
  45690. var {
  45691. selection
  45692. } = editor;
  45693. var {
  45694. edge = 'both'
  45695. } = options;
  45696. if (!selection) {
  45697. return;
  45698. }
  45699. if (edge === 'start') {
  45700. edge = Range.isBackward(selection) ? 'focus' : 'anchor';
  45701. }
  45702. if (edge === 'end') {
  45703. edge = Range.isBackward(selection) ? 'anchor' : 'focus';
  45704. }
  45705. var {
  45706. anchor,
  45707. focus
  45708. } = selection;
  45709. var point = edge === 'anchor' ? anchor : focus;
  45710. var newPoint = Object.assign(point, props);
  45711. if (edge === 'anchor') {
  45712. Transforms.setSelection(editor, {
  45713. anchor: newPoint
  45714. });
  45715. } else {
  45716. Transforms.setSelection(editor, {
  45717. focus: newPoint
  45718. });
  45719. }
  45720. },
  45721. /**
  45722. * Set new properties on the selection.
  45723. */
  45724. setSelection(editor, props) {
  45725. var {
  45726. selection
  45727. } = editor;
  45728. var oldProps = {};
  45729. var newProps = {};
  45730. if (!selection) {
  45731. return;
  45732. }
  45733. for (var k in props) {
  45734. 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]) {
  45735. oldProps[k] = selection[k];
  45736. newProps[k] = props[k];
  45737. }
  45738. }
  45739. if (Object.keys(oldProps).length > 0) {
  45740. editor.apply({
  45741. type: 'set_selection',
  45742. properties: oldProps,
  45743. newProperties: newProps
  45744. });
  45745. }
  45746. }
  45747. };
  45748. var TextTransforms = {
  45749. /**
  45750. * Delete content in the editor.
  45751. */
  45752. delete(editor) {
  45753. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  45754. Editor.withoutNormalizing(editor, () => {
  45755. var {
  45756. reverse = false,
  45757. unit = 'character',
  45758. distance = 1,
  45759. voids = false
  45760. } = options;
  45761. var {
  45762. at = editor.selection,
  45763. hanging = false
  45764. } = options;
  45765. if (!at) {
  45766. return;
  45767. }
  45768. if (Range.isRange(at) && Range.isCollapsed(at)) {
  45769. at = at.anchor;
  45770. }
  45771. if (Point.isPoint(at)) {
  45772. var furthestVoid = Editor.void(editor, {
  45773. at,
  45774. mode: 'highest'
  45775. });
  45776. if (!voids && furthestVoid) {
  45777. var [, voidPath] = furthestVoid;
  45778. at = voidPath;
  45779. } else {
  45780. var opts = {
  45781. unit,
  45782. distance
  45783. };
  45784. var target = reverse ? Editor.before(editor, at, opts) || Editor.start(editor, []) : Editor.after(editor, at, opts) || Editor.end(editor, []);
  45785. at = {
  45786. anchor: at,
  45787. focus: target
  45788. };
  45789. hanging = true;
  45790. }
  45791. }
  45792. if (Path.isPath(at)) {
  45793. Transforms.removeNodes(editor, {
  45794. at,
  45795. voids
  45796. });
  45797. return;
  45798. }
  45799. if (Range.isCollapsed(at)) {
  45800. return;
  45801. }
  45802. if (!hanging) {
  45803. at = Editor.unhangRange(editor, at, {
  45804. voids
  45805. });
  45806. }
  45807. var [start, end] = Range.edges(at);
  45808. var startBlock = Editor.above(editor, {
  45809. match: n => Editor.isBlock(editor, n),
  45810. at: start,
  45811. voids
  45812. });
  45813. var endBlock = Editor.above(editor, {
  45814. match: n => Editor.isBlock(editor, n),
  45815. at: end,
  45816. voids
  45817. });
  45818. var isAcrossBlocks = startBlock && endBlock && !Path.equals(startBlock[1], endBlock[1]);
  45819. var isSingleText = Path.equals(start.path, end.path);
  45820. var startVoid = voids ? null : Editor.void(editor, {
  45821. at: start,
  45822. mode: 'highest'
  45823. });
  45824. var endVoid = voids ? null : Editor.void(editor, {
  45825. at: end,
  45826. mode: 'highest'
  45827. }); // If the start or end points are inside an inline void, nudge them out.
  45828. if (startVoid) {
  45829. var before = Editor.before(editor, start);
  45830. if (before && startBlock && Path.isAncestor(startBlock[1], before.path)) {
  45831. start = before;
  45832. }
  45833. }
  45834. if (endVoid) {
  45835. var after = Editor.after(editor, end);
  45836. if (after && endBlock && Path.isAncestor(endBlock[1], after.path)) {
  45837. end = after;
  45838. }
  45839. } // Get the highest nodes that are completely inside the range, as well as
  45840. // the start and end nodes.
  45841. var matches = [];
  45842. var lastPath;
  45843. for (var entry of Editor.nodes(editor, {
  45844. at,
  45845. voids
  45846. })) {
  45847. var [node, path] = entry;
  45848. if (lastPath && Path.compare(path, lastPath) === 0) {
  45849. continue;
  45850. }
  45851. if (!voids && Editor.isVoid(editor, node) || !Path.isCommon(path, start.path) && !Path.isCommon(path, end.path)) {
  45852. matches.push(entry);
  45853. lastPath = path;
  45854. }
  45855. }
  45856. var pathRefs = Array.from(matches, (_ref) => {
  45857. var [, p] = _ref;
  45858. return Editor.pathRef(editor, p);
  45859. });
  45860. var startRef = Editor.pointRef(editor, start);
  45861. var endRef = Editor.pointRef(editor, end);
  45862. if (!isSingleText && !startVoid) {
  45863. var _point = startRef.current;
  45864. var [_node] = Editor.leaf(editor, _point);
  45865. var {
  45866. path: _path
  45867. } = _point;
  45868. var {
  45869. offset
  45870. } = start;
  45871. var text = _node.text.slice(offset);
  45872. editor.apply({
  45873. type: 'remove_text',
  45874. path: _path,
  45875. offset,
  45876. text
  45877. });
  45878. }
  45879. for (var pathRef of pathRefs) {
  45880. var _path2 = pathRef.unref();
  45881. Transforms.removeNodes(editor, {
  45882. at: _path2,
  45883. voids
  45884. });
  45885. }
  45886. if (!endVoid) {
  45887. var _point2 = endRef.current;
  45888. var [_node2] = Editor.leaf(editor, _point2);
  45889. var {
  45890. path: _path3
  45891. } = _point2;
  45892. var _offset = isSingleText ? start.offset : 0;
  45893. var _text = _node2.text.slice(_offset, end.offset);
  45894. editor.apply({
  45895. type: 'remove_text',
  45896. path: _path3,
  45897. offset: _offset,
  45898. text: _text
  45899. });
  45900. }
  45901. if (!isSingleText && isAcrossBlocks && endRef.current && startRef.current) {
  45902. Transforms.mergeNodes(editor, {
  45903. at: endRef.current,
  45904. hanging: true,
  45905. voids
  45906. });
  45907. }
  45908. var point = endRef.unref() || startRef.unref();
  45909. if (options.at == null && point) {
  45910. Transforms.select(editor, point);
  45911. }
  45912. });
  45913. },
  45914. /**
  45915. * Insert a fragment at a specific location in the editor.
  45916. */
  45917. insertFragment(editor, fragment) {
  45918. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  45919. Editor.withoutNormalizing(editor, () => {
  45920. var {
  45921. hanging = false,
  45922. voids = false
  45923. } = options;
  45924. var {
  45925. at = editor.selection
  45926. } = options;
  45927. if (!fragment.length) {
  45928. return;
  45929. }
  45930. if (!at) {
  45931. return;
  45932. } else if (Range.isRange(at)) {
  45933. if (!hanging) {
  45934. at = Editor.unhangRange(editor, at);
  45935. }
  45936. if (Range.isCollapsed(at)) {
  45937. at = at.anchor;
  45938. } else {
  45939. var [, end] = Range.edges(at);
  45940. if (!voids && Editor.void(editor, {
  45941. at: end
  45942. })) {
  45943. return;
  45944. }
  45945. var pointRef = Editor.pointRef(editor, end);
  45946. Transforms.delete(editor, {
  45947. at
  45948. });
  45949. at = pointRef.unref();
  45950. }
  45951. } else if (Path.isPath(at)) {
  45952. at = Editor.start(editor, at);
  45953. }
  45954. if (!voids && Editor.void(editor, {
  45955. at
  45956. })) {
  45957. return;
  45958. } // If the insert point is at the edge of an inline node, move it outside
  45959. // instead since it will need to be split otherwise.
  45960. var inlineElementMatch = Editor.above(editor, {
  45961. at,
  45962. match: n => Editor.isInline(editor, n),
  45963. mode: 'highest',
  45964. voids
  45965. });
  45966. if (inlineElementMatch) {
  45967. var [, _inlinePath] = inlineElementMatch;
  45968. if (Editor.isEnd(editor, at, _inlinePath)) {
  45969. var after = Editor.after(editor, _inlinePath);
  45970. at = after;
  45971. } else if (Editor.isStart(editor, at, _inlinePath)) {
  45972. var before = Editor.before(editor, _inlinePath);
  45973. at = before;
  45974. }
  45975. }
  45976. var blockMatch = Editor.above(editor, {
  45977. match: n => Editor.isBlock(editor, n),
  45978. at,
  45979. voids
  45980. });
  45981. var [, blockPath] = blockMatch;
  45982. var isBlockStart = Editor.isStart(editor, at, blockPath);
  45983. var isBlockEnd = Editor.isEnd(editor, at, blockPath);
  45984. var mergeStart = !isBlockStart || isBlockStart && isBlockEnd;
  45985. var mergeEnd = !isBlockEnd;
  45986. var [, firstPath] = Node.first({
  45987. children: fragment
  45988. }, []);
  45989. var [, lastPath] = Node.last({
  45990. children: fragment
  45991. }, []);
  45992. var matches = [];
  45993. var matcher = (_ref2) => {
  45994. var [n, p] = _ref2;
  45995. if (mergeStart && Path.isAncestor(p, firstPath) && Element.isElement(n) && !editor.isVoid(n) && !editor.isInline(n)) {
  45996. return false;
  45997. }
  45998. if (mergeEnd && Path.isAncestor(p, lastPath) && Element.isElement(n) && !editor.isVoid(n) && !editor.isInline(n)) {
  45999. return false;
  46000. }
  46001. return true;
  46002. };
  46003. for (var entry of Node.nodes({
  46004. children: fragment
  46005. }, {
  46006. pass: matcher
  46007. })) {
  46008. if (entry[1].length > 0 && matcher(entry)) {
  46009. matches.push(entry);
  46010. }
  46011. }
  46012. var starts = [];
  46013. var middles = [];
  46014. var ends = [];
  46015. var starting = true;
  46016. var hasBlocks = false;
  46017. for (var [node] of matches) {
  46018. if (Element.isElement(node) && !editor.isInline(node)) {
  46019. starting = false;
  46020. hasBlocks = true;
  46021. middles.push(node);
  46022. } else if (starting) {
  46023. starts.push(node);
  46024. } else {
  46025. ends.push(node);
  46026. }
  46027. }
  46028. var [inlineMatch] = Editor.nodes(editor, {
  46029. at,
  46030. match: n => Text.isText(n) || Editor.isInline(editor, n),
  46031. mode: 'highest',
  46032. voids
  46033. });
  46034. var [, inlinePath] = inlineMatch;
  46035. var isInlineStart = Editor.isStart(editor, at, inlinePath);
  46036. var isInlineEnd = Editor.isEnd(editor, at, inlinePath);
  46037. var middleRef = Editor.pathRef(editor, isBlockEnd ? Path.next(blockPath) : blockPath);
  46038. var endRef = Editor.pathRef(editor, isInlineEnd ? Path.next(inlinePath) : inlinePath);
  46039. Transforms.splitNodes(editor, {
  46040. at,
  46041. match: n => hasBlocks ? Editor.isBlock(editor, n) : Text.isText(n) || Editor.isInline(editor, n),
  46042. mode: hasBlocks ? 'lowest' : 'highest',
  46043. voids
  46044. });
  46045. var startRef = Editor.pathRef(editor, !isInlineStart || isInlineStart && isInlineEnd ? Path.next(inlinePath) : inlinePath);
  46046. Transforms.insertNodes(editor, starts, {
  46047. at: startRef.current,
  46048. match: n => Text.isText(n) || Editor.isInline(editor, n),
  46049. mode: 'highest',
  46050. voids
  46051. });
  46052. Transforms.insertNodes(editor, middles, {
  46053. at: middleRef.current,
  46054. match: n => Editor.isBlock(editor, n),
  46055. mode: 'lowest',
  46056. voids
  46057. });
  46058. Transforms.insertNodes(editor, ends, {
  46059. at: endRef.current,
  46060. match: n => Text.isText(n) || Editor.isInline(editor, n),
  46061. mode: 'highest',
  46062. voids
  46063. });
  46064. if (!options.at) {
  46065. var path;
  46066. if (ends.length > 0) {
  46067. path = Path.previous(endRef.current);
  46068. } else if (middles.length > 0) {
  46069. path = Path.previous(middleRef.current);
  46070. } else {
  46071. path = Path.previous(startRef.current);
  46072. }
  46073. var _end = Editor.end(editor, path);
  46074. Transforms.select(editor, _end);
  46075. }
  46076. startRef.unref();
  46077. middleRef.unref();
  46078. endRef.unref();
  46079. });
  46080. },
  46081. /**
  46082. * Insert a string of text in the Editor.
  46083. */
  46084. insertText(editor, text) {
  46085. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  46086. Editor.withoutNormalizing(editor, () => {
  46087. var {
  46088. voids = false
  46089. } = options;
  46090. var {
  46091. at = editor.selection
  46092. } = options;
  46093. if (!at) {
  46094. return;
  46095. }
  46096. if (Path.isPath(at)) {
  46097. at = Editor.range(editor, at);
  46098. }
  46099. if (Range.isRange(at)) {
  46100. if (Range.isCollapsed(at)) {
  46101. at = at.anchor;
  46102. } else {
  46103. var end = Range.end(at);
  46104. if (!voids && Editor.void(editor, {
  46105. at: end
  46106. })) {
  46107. return;
  46108. }
  46109. var pointRef = Editor.pointRef(editor, end);
  46110. Transforms.delete(editor, {
  46111. at,
  46112. voids
  46113. });
  46114. at = pointRef.unref();
  46115. Transforms.setSelection(editor, {
  46116. anchor: at,
  46117. focus: at
  46118. });
  46119. }
  46120. }
  46121. if (!voids && Editor.void(editor, {
  46122. at
  46123. })) {
  46124. return;
  46125. }
  46126. var {
  46127. path,
  46128. offset
  46129. } = at;
  46130. editor.apply({
  46131. type: 'insert_text',
  46132. path,
  46133. offset,
  46134. text
  46135. });
  46136. });
  46137. }
  46138. };
  46139. 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; }
  46140. 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; }
  46141. var Transforms = _objectSpread$8({}, GeneralTransforms, {}, NodeTransforms, {}, SelectionTransforms, {}, TextTransforms);
  46142. exports.Editor = Editor;
  46143. exports.Element = Element;
  46144. exports.Location = Location;
  46145. exports.Node = Node;
  46146. exports.Operation = Operation;
  46147. exports.Path = Path;
  46148. exports.PathRef = PathRef;
  46149. exports.Point = Point;
  46150. exports.PointRef = PointRef;
  46151. exports.Range = Range;
  46152. exports.RangeRef = RangeRef;
  46153. exports.Span = Span;
  46154. exports.Text = Text;
  46155. exports.Transforms = Transforms;
  46156. exports.createEditor = createEditor;
  46157. });
  46158. styleInject_es.unwrapExports(dist$5);
  46159. var dist_1$3 = dist$5.Editor;
  46160. var dist_2$3 = dist$5.Element;
  46161. var dist_3$3 = dist$5.Location;
  46162. var dist_4$1 = dist$5.Node;
  46163. var dist_5$1 = dist$5.Operation;
  46164. var dist_6$1 = dist$5.Path;
  46165. var dist_7 = dist$5.PathRef;
  46166. var dist_8 = dist$5.Point;
  46167. var dist_9 = dist$5.PointRef;
  46168. var dist_10 = dist$5.Range;
  46169. var dist_11 = dist$5.RangeRef;
  46170. var dist_12 = dist$5.Span;
  46171. var dist_13 = dist$5.Text;
  46172. var dist_14 = dist$5.Transforms;
  46173. var dist_15 = dist$5.createEditor;
  46174. /**
  46175. * Returns a function, that, as long as it continues to be invoked, will not
  46176. * be triggered. The function will be called after it stops being called for
  46177. * N milliseconds. If `immediate` is passed, trigger the function on the
  46178. * leading edge, instead of the trailing. The function also has a property 'clear'
  46179. * that is a function which will clear the timer to prevent previously scheduled executions.
  46180. *
  46181. * @source underscore.js
  46182. * @see http://unscriptable.com/2009/03/20/debouncing-javascript-methods/
  46183. * @param {Function} function to wrap
  46184. * @param {Number} timeout in ms (`100`)
  46185. * @param {Boolean} whether to execute at the beginning (`false`)
  46186. * @api public
  46187. */
  46188. function debounce(func, wait, immediate){
  46189. var timeout, args, context, timestamp, result;
  46190. if (null == wait) wait = 100;
  46191. function later() {
  46192. var last = Date.now() - timestamp;
  46193. if (last < wait && last >= 0) {
  46194. timeout = setTimeout(later, wait - last);
  46195. } else {
  46196. timeout = null;
  46197. if (!immediate) {
  46198. result = func.apply(context, args);
  46199. context = args = null;
  46200. }
  46201. }
  46202. }
  46203. var debounced = function(){
  46204. context = this;
  46205. args = arguments;
  46206. timestamp = Date.now();
  46207. var callNow = immediate && !timeout;
  46208. if (!timeout) timeout = setTimeout(later, wait);
  46209. if (callNow) {
  46210. result = func.apply(context, args);
  46211. context = args = null;
  46212. }
  46213. return result;
  46214. };
  46215. debounced.clear = function() {
  46216. if (timeout) {
  46217. clearTimeout(timeout);
  46218. timeout = null;
  46219. }
  46220. };
  46221. debounced.flush = function() {
  46222. if (timeout) {
  46223. result = func.apply(context, args);
  46224. context = args = null;
  46225. clearTimeout(timeout);
  46226. timeout = null;
  46227. }
  46228. };
  46229. return debounced;
  46230. }
  46231. // Adds compatibility for ES modules
  46232. debounce.debounce = debounce;
  46233. var debounce_1 = debounce;
  46234. var computeScrollIntoView = styleInject_es.createCommonjsModule(function (module, exports) {
  46235. exports.__esModule = true;
  46236. exports["default"] = void 0;
  46237. function isElement(el) {
  46238. return el != null && typeof el === 'object' && el.nodeType === 1;
  46239. }
  46240. function canOverflow(overflow, skipOverflowHiddenElements) {
  46241. if (skipOverflowHiddenElements && overflow === 'hidden') {
  46242. return false;
  46243. }
  46244. return overflow !== 'visible' && overflow !== 'clip';
  46245. }
  46246. function getFrameElement(el) {
  46247. if (!el.ownerDocument || !el.ownerDocument.defaultView) {
  46248. return null;
  46249. }
  46250. return el.ownerDocument.defaultView.frameElement;
  46251. }
  46252. function isHiddenByFrame(el) {
  46253. var frame = getFrameElement(el);
  46254. if (!frame) {
  46255. return false;
  46256. }
  46257. return frame.clientHeight < el.scrollHeight || frame.clientWidth < el.scrollWidth;
  46258. }
  46259. function isScrollable(el, skipOverflowHiddenElements) {
  46260. if (el.clientHeight < el.scrollHeight || el.clientWidth < el.scrollWidth) {
  46261. var style = getComputedStyle(el, null);
  46262. return canOverflow(style.overflowY, skipOverflowHiddenElements) || canOverflow(style.overflowX, skipOverflowHiddenElements) || isHiddenByFrame(el);
  46263. }
  46264. return false;
  46265. }
  46266. function alignNearest(scrollingEdgeStart, scrollingEdgeEnd, scrollingSize, scrollingBorderStart, scrollingBorderEnd, elementEdgeStart, elementEdgeEnd, elementSize) {
  46267. if (elementEdgeStart < scrollingEdgeStart && elementEdgeEnd > scrollingEdgeEnd || elementEdgeStart > scrollingEdgeStart && elementEdgeEnd < scrollingEdgeEnd) {
  46268. return 0;
  46269. }
  46270. if (elementEdgeStart <= scrollingEdgeStart && elementSize <= scrollingSize || elementEdgeEnd >= scrollingEdgeEnd && elementSize >= scrollingSize) {
  46271. return elementEdgeStart - scrollingEdgeStart - scrollingBorderStart;
  46272. }
  46273. if (elementEdgeEnd > scrollingEdgeEnd && elementSize < scrollingSize || elementEdgeStart < scrollingEdgeStart && elementSize > scrollingSize) {
  46274. return elementEdgeEnd - scrollingEdgeEnd + scrollingBorderEnd;
  46275. }
  46276. return 0;
  46277. }
  46278. var _default = function _default(target, options) {
  46279. var scrollMode = options.scrollMode,
  46280. block = options.block,
  46281. inline = options.inline,
  46282. boundary = options.boundary,
  46283. skipOverflowHiddenElements = options.skipOverflowHiddenElements;
  46284. var checkBoundary = typeof boundary === 'function' ? boundary : function (node) {
  46285. return node !== boundary;
  46286. };
  46287. if (!isElement(target)) {
  46288. throw new TypeError('Invalid target');
  46289. }
  46290. var scrollingElement = document.scrollingElement || document.documentElement;
  46291. var frames = [];
  46292. var cursor = target;
  46293. while (isElement(cursor) && checkBoundary(cursor)) {
  46294. cursor = cursor.parentNode;
  46295. if (cursor === scrollingElement) {
  46296. frames.push(cursor);
  46297. break;
  46298. }
  46299. if (cursor === document.body && isScrollable(cursor) && !isScrollable(document.documentElement)) {
  46300. continue;
  46301. }
  46302. if (isScrollable(cursor, skipOverflowHiddenElements)) {
  46303. frames.push(cursor);
  46304. }
  46305. }
  46306. var viewportWidth = window.visualViewport ? visualViewport.width : innerWidth;
  46307. var viewportHeight = window.visualViewport ? visualViewport.height : innerHeight;
  46308. var viewportX = window.scrollX || pageXOffset;
  46309. var viewportY = window.scrollY || pageYOffset;
  46310. var _target$getBoundingCl = target.getBoundingClientRect(),
  46311. targetHeight = _target$getBoundingCl.height,
  46312. targetWidth = _target$getBoundingCl.width,
  46313. targetTop = _target$getBoundingCl.top,
  46314. targetRight = _target$getBoundingCl.right,
  46315. targetBottom = _target$getBoundingCl.bottom,
  46316. targetLeft = _target$getBoundingCl.left;
  46317. var targetBlock = block === 'start' || block === 'nearest' ? targetTop : block === 'end' ? targetBottom : targetTop + targetHeight / 2;
  46318. var targetInline = inline === 'center' ? targetLeft + targetWidth / 2 : inline === 'end' ? targetRight : targetLeft;
  46319. var computations = [];
  46320. for (var index = 0; index < frames.length; index++) {
  46321. var frame = frames[index];
  46322. var _frame$getBoundingCli = frame.getBoundingClientRect(),
  46323. height = _frame$getBoundingCli.height,
  46324. width = _frame$getBoundingCli.width,
  46325. top = _frame$getBoundingCli.top,
  46326. right = _frame$getBoundingCli.right,
  46327. bottom = _frame$getBoundingCli.bottom,
  46328. left = _frame$getBoundingCli.left;
  46329. if (scrollMode === 'if-needed' && targetTop >= 0 && targetLeft >= 0 && targetBottom <= viewportHeight && targetRight <= viewportWidth && targetTop >= top && targetBottom <= bottom && targetLeft >= left && targetRight <= right) {
  46330. return computations;
  46331. }
  46332. var frameStyle = getComputedStyle(frame);
  46333. var borderLeft = parseInt(frameStyle.borderLeftWidth, 10);
  46334. var borderTop = parseInt(frameStyle.borderTopWidth, 10);
  46335. var borderRight = parseInt(frameStyle.borderRightWidth, 10);
  46336. var borderBottom = parseInt(frameStyle.borderBottomWidth, 10);
  46337. var blockScroll = 0;
  46338. var inlineScroll = 0;
  46339. var scrollbarWidth = 'offsetWidth' in frame ? frame.offsetWidth - frame.clientWidth - borderLeft - borderRight : 0;
  46340. var scrollbarHeight = 'offsetHeight' in frame ? frame.offsetHeight - frame.clientHeight - borderTop - borderBottom : 0;
  46341. if (scrollingElement === frame) {
  46342. if (block === 'start') {
  46343. blockScroll = targetBlock;
  46344. } else if (block === 'end') {
  46345. blockScroll = targetBlock - viewportHeight;
  46346. } else if (block === 'nearest') {
  46347. blockScroll = alignNearest(viewportY, viewportY + viewportHeight, viewportHeight, borderTop, borderBottom, viewportY + targetBlock, viewportY + targetBlock + targetHeight, targetHeight);
  46348. } else {
  46349. blockScroll = targetBlock - viewportHeight / 2;
  46350. }
  46351. if (inline === 'start') {
  46352. inlineScroll = targetInline;
  46353. } else if (inline === 'center') {
  46354. inlineScroll = targetInline - viewportWidth / 2;
  46355. } else if (inline === 'end') {
  46356. inlineScroll = targetInline - viewportWidth;
  46357. } else {
  46358. inlineScroll = alignNearest(viewportX, viewportX + viewportWidth, viewportWidth, borderLeft, borderRight, viewportX + targetInline, viewportX + targetInline + targetWidth, targetWidth);
  46359. }
  46360. blockScroll = Math.max(0, blockScroll + viewportY);
  46361. inlineScroll = Math.max(0, inlineScroll + viewportX);
  46362. } else {
  46363. if (block === 'start') {
  46364. blockScroll = targetBlock - top - borderTop;
  46365. } else if (block === 'end') {
  46366. blockScroll = targetBlock - bottom + borderBottom + scrollbarHeight;
  46367. } else if (block === 'nearest') {
  46368. blockScroll = alignNearest(top, bottom, height, borderTop, borderBottom + scrollbarHeight, targetBlock, targetBlock + targetHeight, targetHeight);
  46369. } else {
  46370. blockScroll = targetBlock - (top + height / 2) + scrollbarHeight / 2;
  46371. }
  46372. if (inline === 'start') {
  46373. inlineScroll = targetInline - left - borderLeft;
  46374. } else if (inline === 'center') {
  46375. inlineScroll = targetInline - (left + width / 2) + scrollbarWidth / 2;
  46376. } else if (inline === 'end') {
  46377. inlineScroll = targetInline - right + borderRight + scrollbarWidth;
  46378. } else {
  46379. inlineScroll = alignNearest(left, right, width, borderLeft, borderRight + scrollbarWidth, targetInline, targetInline + targetWidth, targetWidth);
  46380. }
  46381. var scrollLeft = frame.scrollLeft,
  46382. scrollTop = frame.scrollTop;
  46383. blockScroll = Math.max(0, Math.min(scrollTop + blockScroll, frame.scrollHeight - height + scrollbarHeight));
  46384. inlineScroll = Math.max(0, Math.min(scrollLeft + inlineScroll, frame.scrollWidth - width + scrollbarWidth));
  46385. targetBlock += scrollTop - blockScroll;
  46386. targetInline += scrollLeft - inlineScroll;
  46387. }
  46388. computations.push({
  46389. el: frame,
  46390. top: blockScroll,
  46391. left: inlineScroll
  46392. });
  46393. }
  46394. return computations;
  46395. };
  46396. exports["default"] = _default;
  46397. module.exports = exports.default;
  46398. });
  46399. styleInject_es.unwrapExports(computeScrollIntoView);
  46400. var scrollIntoViewIfNeeded = styleInject_es.createCommonjsModule(function (module, exports) {
  46401. exports.__esModule = true;
  46402. exports["default"] = void 0;
  46403. var _computeScrollIntoView = _interopRequireDefault(computeScrollIntoView);
  46404. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  46405. function isOptionsObject(options) {
  46406. return options === Object(options) && Object.keys(options).length !== 0;
  46407. }
  46408. function defaultBehavior(actions, behavior) {
  46409. if (behavior === void 0) {
  46410. behavior = 'auto';
  46411. }
  46412. var canSmoothScroll = 'scrollBehavior' in document.body.style;
  46413. actions.forEach(function (_ref) {
  46414. var el = _ref.el,
  46415. top = _ref.top,
  46416. left = _ref.left;
  46417. if (el.scroll && canSmoothScroll) {
  46418. el.scroll({
  46419. top: top,
  46420. left: left,
  46421. behavior: behavior
  46422. });
  46423. } else {
  46424. el.scrollTop = top;
  46425. el.scrollLeft = left;
  46426. }
  46427. });
  46428. }
  46429. function getOptions(options) {
  46430. if (options === false) {
  46431. return {
  46432. block: 'end',
  46433. inline: 'nearest'
  46434. };
  46435. }
  46436. if (isOptionsObject(options)) {
  46437. return options;
  46438. }
  46439. return {
  46440. block: 'start',
  46441. inline: 'nearest'
  46442. };
  46443. }
  46444. function scrollIntoView(target, options) {
  46445. var targetIsDetached = !target.ownerDocument.documentElement.contains(target);
  46446. if (isOptionsObject(options) && typeof options.behavior === 'function') {
  46447. return options.behavior(targetIsDetached ? [] : (0, _computeScrollIntoView["default"])(target, options));
  46448. }
  46449. if (targetIsDetached) {
  46450. return;
  46451. }
  46452. var computeOptions = getOptions(options);
  46453. return defaultBehavior((0, _computeScrollIntoView["default"])(target, computeOptions), computeOptions.behavior);
  46454. }
  46455. var _default = scrollIntoView;
  46456. exports["default"] = _default;
  46457. module.exports = exports.default;
  46458. });
  46459. styleInject_es.unwrapExports(scrollIntoViewIfNeeded);
  46460. var direction_1 = direction;
  46461. var RTL$1 = '\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC';
  46462. var LTR$1 =
  46463. 'A-Za-z\u00C0-\u00D6\u00D8-\u00F6' +
  46464. '\u00F8-\u02B8\u0300-\u0590\u0800-\u1FFF\u200E\u2C00-\uFB1C' +
  46465. '\uFE00-\uFE6F\uFEFD-\uFFFF';
  46466. var rtl = new RegExp('^[^' + LTR$1 + ']*[' + RTL$1 + ']');
  46467. var ltr = new RegExp('^[^' + RTL$1 + ']*[' + LTR$1 + ']');
  46468. function direction(value) {
  46469. value = String(value || '');
  46470. if (rtl.test(value)) {
  46471. return 'rtl'
  46472. }
  46473. if (ltr.test(value)) {
  46474. return 'ltr'
  46475. }
  46476. return 'neutral'
  46477. }
  46478. var lib$1 = styleInject_es.createCommonjsModule(function (module, exports) {
  46479. Object.defineProperty(exports, "__esModule", {
  46480. value: true
  46481. });
  46482. /**
  46483. * Constants.
  46484. */
  46485. var IS_MAC = typeof window != 'undefined' && /Mac|iPod|iPhone|iPad/.test(window.navigator.platform);
  46486. var MODIFIERS = {
  46487. alt: 'altKey',
  46488. control: 'ctrlKey',
  46489. meta: 'metaKey',
  46490. shift: 'shiftKey'
  46491. };
  46492. var ALIASES = {
  46493. add: '+',
  46494. break: 'pause',
  46495. cmd: 'meta',
  46496. command: 'meta',
  46497. ctl: 'control',
  46498. ctrl: 'control',
  46499. del: 'delete',
  46500. down: 'arrowdown',
  46501. esc: 'escape',
  46502. ins: 'insert',
  46503. left: 'arrowleft',
  46504. mod: IS_MAC ? 'meta' : 'control',
  46505. opt: 'alt',
  46506. option: 'alt',
  46507. return: 'enter',
  46508. right: 'arrowright',
  46509. space: ' ',
  46510. spacebar: ' ',
  46511. up: 'arrowup',
  46512. win: 'meta',
  46513. windows: 'meta'
  46514. };
  46515. var CODES = {
  46516. backspace: 8,
  46517. tab: 9,
  46518. enter: 13,
  46519. shift: 16,
  46520. control: 17,
  46521. alt: 18,
  46522. pause: 19,
  46523. capslock: 20,
  46524. escape: 27,
  46525. ' ': 32,
  46526. pageup: 33,
  46527. pagedown: 34,
  46528. end: 35,
  46529. home: 36,
  46530. arrowleft: 37,
  46531. arrowup: 38,
  46532. arrowright: 39,
  46533. arrowdown: 40,
  46534. insert: 45,
  46535. delete: 46,
  46536. meta: 91,
  46537. numlock: 144,
  46538. scrolllock: 145,
  46539. ';': 186,
  46540. '=': 187,
  46541. ',': 188,
  46542. '-': 189,
  46543. '.': 190,
  46544. '/': 191,
  46545. '`': 192,
  46546. '[': 219,
  46547. '\\': 220,
  46548. ']': 221,
  46549. '\'': 222
  46550. };
  46551. for (var f = 1; f < 20; f++) {
  46552. CODES['f' + f] = 111 + f;
  46553. }
  46554. /**
  46555. * Is hotkey?
  46556. */
  46557. function isHotkey(hotkey, options, event) {
  46558. if (options && !('byKey' in options)) {
  46559. event = options;
  46560. options = null;
  46561. }
  46562. if (!Array.isArray(hotkey)) {
  46563. hotkey = [hotkey];
  46564. }
  46565. var array = hotkey.map(function (string) {
  46566. return parseHotkey(string, options);
  46567. });
  46568. var check = function check(e) {
  46569. return array.some(function (object) {
  46570. return compareHotkey(object, e);
  46571. });
  46572. };
  46573. var ret = event == null ? check : check(event);
  46574. return ret;
  46575. }
  46576. function isCodeHotkey(hotkey, event) {
  46577. return isHotkey(hotkey, event);
  46578. }
  46579. function isKeyHotkey(hotkey, event) {
  46580. return isHotkey(hotkey, { byKey: true }, event);
  46581. }
  46582. /**
  46583. * Parse.
  46584. */
  46585. function parseHotkey(hotkey, options) {
  46586. var byKey = options && options.byKey;
  46587. var ret = {};
  46588. // Special case to handle the `+` key since we use it as a separator.
  46589. hotkey = hotkey.replace('++', '+add');
  46590. var values = hotkey.split('+');
  46591. var length = values.length;
  46592. // Ensure that all the modifiers are set to false unless the hotkey has them.
  46593. for (var k in MODIFIERS) {
  46594. ret[MODIFIERS[k]] = false;
  46595. }
  46596. var _iteratorNormalCompletion = true;
  46597. var _didIteratorError = false;
  46598. var _iteratorError = undefined;
  46599. try {
  46600. for (var _iterator = values[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  46601. var value = _step.value;
  46602. var optional = value.endsWith('?') && value.length > 1;
  46603. if (optional) {
  46604. value = value.slice(0, -1);
  46605. }
  46606. var name = toKeyName(value);
  46607. var modifier = MODIFIERS[name];
  46608. if (length === 1 || !modifier) {
  46609. if (byKey) {
  46610. ret.key = name;
  46611. } else {
  46612. ret.which = toKeyCode(value);
  46613. }
  46614. }
  46615. if (modifier) {
  46616. ret[modifier] = optional ? null : true;
  46617. }
  46618. }
  46619. } catch (err) {
  46620. _didIteratorError = true;
  46621. _iteratorError = err;
  46622. } finally {
  46623. try {
  46624. if (!_iteratorNormalCompletion && _iterator.return) {
  46625. _iterator.return();
  46626. }
  46627. } finally {
  46628. if (_didIteratorError) {
  46629. throw _iteratorError;
  46630. }
  46631. }
  46632. }
  46633. return ret;
  46634. }
  46635. /**
  46636. * Compare.
  46637. */
  46638. function compareHotkey(object, event) {
  46639. for (var key in object) {
  46640. var expected = object[key];
  46641. var actual = void 0;
  46642. if (expected == null) {
  46643. continue;
  46644. }
  46645. if (key === 'key' && event.key != null) {
  46646. actual = event.key.toLowerCase();
  46647. } else if (key === 'which') {
  46648. actual = expected === 91 && event.which === 93 ? 91 : event.which;
  46649. } else {
  46650. actual = event[key];
  46651. }
  46652. if (actual == null && expected === false) {
  46653. continue;
  46654. }
  46655. if (actual !== expected) {
  46656. return false;
  46657. }
  46658. }
  46659. return true;
  46660. }
  46661. /**
  46662. * Utils.
  46663. */
  46664. function toKeyCode(name) {
  46665. name = toKeyName(name);
  46666. var code = CODES[name] || name.toUpperCase().charCodeAt(0);
  46667. return code;
  46668. }
  46669. function toKeyName(name) {
  46670. name = name.toLowerCase();
  46671. name = ALIASES[name] || name;
  46672. return name;
  46673. }
  46674. /**
  46675. * Export.
  46676. */
  46677. exports.default = isHotkey;
  46678. exports.isHotkey = isHotkey;
  46679. exports.isCodeHotkey = isCodeHotkey;
  46680. exports.isKeyHotkey = isKeyHotkey;
  46681. exports.parseHotkey = parseHotkey;
  46682. exports.compareHotkey = compareHotkey;
  46683. exports.toKeyCode = toKeyCode;
  46684. exports.toKeyName = toKeyName;
  46685. });
  46686. styleInject_es.unwrapExports(lib$1);
  46687. var lib_1 = lib$1.isHotkey;
  46688. var lib_2 = lib$1.isCodeHotkey;
  46689. var lib_3 = lib$1.isKeyHotkey;
  46690. var lib_4 = lib$1.parseHotkey;
  46691. var lib_5 = lib$1.compareHotkey;
  46692. var lib_6 = lib$1.toKeyCode;
  46693. var lib_7 = lib$1.toKeyName;
  46694. var dist$6 = styleInject_es.createCommonjsModule(function (module, exports) {
  46695. Object.defineProperty(exports, '__esModule', { value: true });
  46696. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  46697. var React__default$1 = _interopDefault(React__default);
  46698. var debounce = _interopDefault(debounce_1);
  46699. var scrollIntoView = _interopDefault(scrollIntoViewIfNeeded);
  46700. var getDirection = _interopDefault(direction_1);
  46701. var ReactDOM = _interopDefault(reactDom);
  46702. /**
  46703. * Leaf content strings.
  46704. */
  46705. const String = (props) => {
  46706. const { isLast, leaf, parent, text } = props;
  46707. const editor = useEditor();
  46708. const path = ReactEditor.findPath(editor, text);
  46709. const parentPath = dist$5.Path.parent(path);
  46710. // COMPAT: Render text inside void nodes with a zero-width space.
  46711. // So the node can contain selection but the text is not visible.
  46712. if (editor.isVoid(parent)) {
  46713. return React__default$1.createElement(ZeroWidthString, { length: dist$5.Node.string(parent).length });
  46714. }
  46715. // COMPAT: If this is the last text node in an empty block, render a zero-
  46716. // width space that will convert into a line break when copying and pasting
  46717. // to support expected plain text.
  46718. if (leaf.text === '' &&
  46719. parent.children[parent.children.length - 1] === text &&
  46720. !editor.isInline(parent) &&
  46721. dist$5.Editor.string(editor, parentPath) === '') {
  46722. return React__default$1.createElement(ZeroWidthString, { isLineBreak: true });
  46723. }
  46724. // COMPAT: If the text is empty, it's because it's on the edge of an inline
  46725. // node, so we render a zero-width space so that the selection can be
  46726. // inserted next to it still.
  46727. if (leaf.text === '') {
  46728. return React__default$1.createElement(ZeroWidthString, null);
  46729. }
  46730. // COMPAT: Browsers will collapse trailing new lines at the end of blocks,
  46731. // so we need to add an extra trailing new lines to prevent that.
  46732. if (isLast && leaf.text.slice(-1) === '\n') {
  46733. return React__default$1.createElement(TextString, { isTrailing: true, text: leaf.text });
  46734. }
  46735. return React__default$1.createElement(TextString, { text: leaf.text });
  46736. };
  46737. /**
  46738. * Leaf strings with text in them.
  46739. */
  46740. const TextString = (props) => {
  46741. const { text, isTrailing = false } = props;
  46742. return (React__default$1.createElement("span", { "data-slate-string": true },
  46743. text,
  46744. isTrailing ? '\n' : null));
  46745. };
  46746. /**
  46747. * Leaf strings without text, render as zero-width strings.
  46748. */
  46749. const ZeroWidthString = (props) => {
  46750. const { length = 0, isLineBreak = false } = props;
  46751. return (React__default$1.createElement("span", { "data-slate-zero-width": isLineBreak ? 'n' : 'z', "data-slate-length": length },
  46752. '\uFEFF',
  46753. isLineBreak ? React__default$1.createElement("br", null) : null));
  46754. };
  46755. /**
  46756. * Two weak maps that allow us rebuild a path given a node. They are populated
  46757. * at render time such that after a render occurs we can always backtrack.
  46758. */
  46759. var NODE_TO_INDEX = new WeakMap();
  46760. var NODE_TO_PARENT = new WeakMap();
  46761. /**
  46762. * Weak maps that allow us to go between Slate nodes and DOM nodes. These
  46763. * are used to resolve DOM event-related logic into Slate actions.
  46764. */
  46765. var EDITOR_TO_ELEMENT = new WeakMap();
  46766. var ELEMENT_TO_NODE = new WeakMap();
  46767. var KEY_TO_ELEMENT = new WeakMap();
  46768. var NODE_TO_ELEMENT = new WeakMap();
  46769. var NODE_TO_KEY = new WeakMap();
  46770. /**
  46771. * Weak maps for storing editor-related state.
  46772. */
  46773. var IS_READ_ONLY = new WeakMap();
  46774. var IS_FOCUSED = new WeakMap();
  46775. /**
  46776. * Weak map for associating the context `onChange` context with the plugin.
  46777. */
  46778. var EDITOR_TO_ON_CHANGE = new WeakMap();
  46779. /**
  46780. * Symbols.
  46781. */
  46782. var PLACEHOLDER_SYMBOL = Symbol('placeholder');
  46783. /**
  46784. * Individual leaves in a text node with unique formatting.
  46785. */
  46786. const Leaf = (props) => {
  46787. const { leaf, isLast, text, parent, renderLeaf = (props) => React__default$1.createElement(DefaultLeaf, Object.assign({}, props)), } = props;
  46788. let children = (React__default$1.createElement(String, { isLast: isLast, leaf: leaf, parent: parent, text: text }));
  46789. if (leaf[PLACEHOLDER_SYMBOL]) {
  46790. children = (React__default$1.createElement(React__default$1.Fragment, null,
  46791. React__default$1.createElement("span", { contentEditable: false, style: {
  46792. pointerEvents: 'none',
  46793. display: 'inline-block',
  46794. verticalAlign: 'text-top',
  46795. width: '0',
  46796. maxWidth: '100%',
  46797. whiteSpace: 'nowrap',
  46798. opacity: '0.333',
  46799. } }, leaf.placeholder),
  46800. children));
  46801. }
  46802. // COMPAT: Having the `data-` attributes on these leaf elements ensures that
  46803. // in certain misbehaving browsers they aren't weirdly cloned/destroyed by
  46804. // contenteditable behaviors. (2019/05/08)
  46805. const attributes = {
  46806. 'data-slate-leaf': true,
  46807. };
  46808. return renderLeaf({ attributes, children, leaf, text });
  46809. };
  46810. const MemoizedLeaf = React__default$1.memo(Leaf, (prev, next) => {
  46811. return (next.parent === prev.parent &&
  46812. next.isLast === prev.isLast &&
  46813. next.renderLeaf === prev.renderLeaf &&
  46814. next.text === prev.text &&
  46815. dist$5.Text.matches(next.leaf, prev.leaf));
  46816. });
  46817. /**
  46818. * The default custom leaf renderer.
  46819. */
  46820. const DefaultLeaf = (props) => {
  46821. const { attributes, children } = props;
  46822. return React__default$1.createElement("span", Object.assign({}, attributes), children);
  46823. };
  46824. /**
  46825. * Prevent warning on SSR by falling back to useEffect when window is not defined
  46826. */
  46827. var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React__default.useLayoutEffect : React__default.useEffect;
  46828. /**
  46829. * Text.
  46830. */
  46831. const Text = (props) => {
  46832. const { decorations, isLast, parent, renderLeaf, text } = props;
  46833. const editor = useEditor();
  46834. const ref = React__default.useRef(null);
  46835. const leaves = dist$5.Text.decorations(text, decorations);
  46836. const key = ReactEditor.findKey(editor, text);
  46837. const children = [];
  46838. for (let i = 0; i < leaves.length; i++) {
  46839. const leaf = leaves[i];
  46840. children.push(React__default$1.createElement(MemoizedLeaf, { isLast: isLast && i === leaves.length - 1, key: `${key.id}-${i}`, leaf: leaf, text: text, parent: parent, renderLeaf: renderLeaf }));
  46841. }
  46842. // Update element-related weak maps with the DOM element ref.
  46843. useIsomorphicLayoutEffect(() => {
  46844. if (ref.current) {
  46845. KEY_TO_ELEMENT.set(key, ref.current);
  46846. NODE_TO_ELEMENT.set(text, ref.current);
  46847. ELEMENT_TO_NODE.set(ref.current, text);
  46848. }
  46849. else {
  46850. KEY_TO_ELEMENT.delete(key);
  46851. NODE_TO_ELEMENT.delete(text);
  46852. }
  46853. });
  46854. return (React__default$1.createElement("span", { "data-slate-node": "text", ref: ref }, children));
  46855. };
  46856. const MemoizedText = React__default$1.memo(Text, (prev, next) => {
  46857. return (next.parent === prev.parent &&
  46858. next.isLast === prev.isLast &&
  46859. next.renderLeaf === prev.renderLeaf &&
  46860. next.text === prev.text);
  46861. });
  46862. /**
  46863. * A React context for sharing the `selected` state of an element.
  46864. */
  46865. var SelectedContext = React__default.createContext(false);
  46866. /**
  46867. * Get the current `selected` state of an element.
  46868. */
  46869. var useSelected = () => {
  46870. return React__default.useContext(SelectedContext);
  46871. };
  46872. /**
  46873. * Element.
  46874. */
  46875. const Element = (props) => {
  46876. const { decorate, decorations, element, renderElement = (p) => React__default$1.createElement(DefaultElement, Object.assign({}, p)), renderLeaf, selection, } = props;
  46877. const ref = React__default.useRef(null);
  46878. const editor = useEditor();
  46879. const readOnly = useReadOnly();
  46880. const isInline = editor.isInline(element);
  46881. const key = ReactEditor.findKey(editor, element);
  46882. let children = (React__default$1.createElement(Children, { decorate: decorate, decorations: decorations, node: element, renderElement: renderElement, renderLeaf: renderLeaf, selection: selection }));
  46883. // Attributes that the developer must mix into the element in their
  46884. // custom node renderer component.
  46885. const attributes = {
  46886. 'data-slate-node': 'element',
  46887. ref,
  46888. };
  46889. if (isInline) {
  46890. attributes['data-slate-inline'] = true;
  46891. }
  46892. // If it's a block node with inline children, add the proper `dir` attribute
  46893. // for text direction.
  46894. if (!isInline && dist$5.Editor.hasInlines(editor, element)) {
  46895. const text = dist$5.Node.string(element);
  46896. const dir = getDirection(text);
  46897. if (dir === 'rtl') {
  46898. attributes.dir = dir;
  46899. }
  46900. }
  46901. // If it's a void node, wrap the children in extra void-specific elements.
  46902. if (dist$5.Editor.isVoid(editor, element)) {
  46903. attributes['data-slate-void'] = true;
  46904. if (!readOnly && isInline) {
  46905. attributes.contentEditable = false;
  46906. }
  46907. const Tag = isInline ? 'span' : 'div';
  46908. const [[text]] = dist$5.Node.texts(element);
  46909. children = readOnly ? null : (React__default$1.createElement(Tag, { "data-slate-spacer": true, style: {
  46910. height: '0',
  46911. color: 'transparent',
  46912. outline: 'none',
  46913. position: 'absolute',
  46914. } },
  46915. React__default$1.createElement(MemoizedText, { decorations: [], isLast: false, parent: element, text: text })));
  46916. NODE_TO_INDEX.set(text, 0);
  46917. NODE_TO_PARENT.set(text, element);
  46918. }
  46919. // Update element-related weak maps with the DOM element ref.
  46920. useIsomorphicLayoutEffect(() => {
  46921. if (ref.current) {
  46922. KEY_TO_ELEMENT.set(key, ref.current);
  46923. NODE_TO_ELEMENT.set(element, ref.current);
  46924. ELEMENT_TO_NODE.set(ref.current, element);
  46925. }
  46926. else {
  46927. KEY_TO_ELEMENT.delete(key);
  46928. NODE_TO_ELEMENT.delete(element);
  46929. }
  46930. });
  46931. return (React__default$1.createElement(SelectedContext.Provider, { value: !!selection }, renderElement({ attributes, children, element })));
  46932. };
  46933. const MemoizedElement = React__default$1.memo(Element, (prev, next) => {
  46934. return (prev.decorate === next.decorate &&
  46935. prev.element === next.element &&
  46936. prev.renderElement === next.renderElement &&
  46937. prev.renderLeaf === next.renderLeaf &&
  46938. isRangeListEqual(prev.decorations, next.decorations) &&
  46939. (prev.selection === next.selection ||
  46940. (!!prev.selection &&
  46941. !!next.selection &&
  46942. dist$5.Range.equals(prev.selection, next.selection))));
  46943. });
  46944. /**
  46945. * The default element renderer.
  46946. */
  46947. const DefaultElement = (props) => {
  46948. const { attributes, children, element } = props;
  46949. const editor = useEditor();
  46950. const Tag = editor.isInline(element) ? 'span' : 'div';
  46951. return (React__default$1.createElement(Tag, Object.assign({}, attributes, { style: { position: 'relative' } }), children));
  46952. };
  46953. /**
  46954. * Check if a list of ranges is equal to another.
  46955. *
  46956. * PERF: this requires the two lists to also have the ranges inside them in the
  46957. * same order, but this is an okay constraint for us since decorations are
  46958. * kept in order, and the odd case where they aren't is okay to re-render for.
  46959. */
  46960. const isRangeListEqual = (list, another) => {
  46961. if (list.length !== another.length) {
  46962. return false;
  46963. }
  46964. for (let i = 0; i < list.length; i++) {
  46965. const range = list[i];
  46966. const other = another[i];
  46967. if (!dist$5.Range.equals(range, other)) {
  46968. return false;
  46969. }
  46970. }
  46971. return true;
  46972. };
  46973. /**
  46974. * A React context for sharing the editor object.
  46975. */
  46976. const EditorContext = React__default.createContext(null);
  46977. /**
  46978. * Get the current editor object from the React context.
  46979. */
  46980. const useEditor = () => {
  46981. const editor = React__default.useContext(EditorContext);
  46982. if (!editor) {
  46983. throw new Error(`The \`useEditor\` hook must be used inside the <Slate> component's context.`);
  46984. }
  46985. return editor;
  46986. };
  46987. /**
  46988. * Children.
  46989. */
  46990. const Children = (props) => {
  46991. const { decorate, decorations, node, renderElement, renderLeaf, selection, } = props;
  46992. const editor = useEditor();
  46993. const path = ReactEditor.findPath(editor, node);
  46994. const children = [];
  46995. const isLeafBlock = dist$5.Element.isElement(node) &&
  46996. !editor.isInline(node) &&
  46997. dist$5.Editor.hasInlines(editor, node);
  46998. for (let i = 0; i < node.children.length; i++) {
  46999. const p = path.concat(i);
  47000. const n = node.children[i];
  47001. const key = ReactEditor.findKey(editor, n);
  47002. const range = dist$5.Editor.range(editor, p);
  47003. const sel = selection && dist$5.Range.intersection(range, selection);
  47004. const ds = decorate([n, p]);
  47005. for (const dec of decorations) {
  47006. const d = dist$5.Range.intersection(dec, range);
  47007. if (d) {
  47008. ds.push(d);
  47009. }
  47010. }
  47011. if (dist$5.Element.isElement(n)) {
  47012. children.push(React__default$1.createElement(MemoizedElement, { decorate: decorate, decorations: ds, element: n, key: key.id, renderElement: renderElement, renderLeaf: renderLeaf, selection: sel }));
  47013. }
  47014. else {
  47015. children.push(React__default$1.createElement(MemoizedText, { decorations: ds, key: key.id, isLast: isLeafBlock && i === node.children.length - 1, parent: node, renderLeaf: renderLeaf, text: n }));
  47016. }
  47017. NODE_TO_INDEX.set(n, i);
  47018. NODE_TO_PARENT.set(n, node);
  47019. }
  47020. return React__default$1.createElement(React__default$1.Fragment, null, children);
  47021. };
  47022. var IS_IOS = typeof navigator !== 'undefined' && typeof window !== 'undefined' && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
  47023. var IS_APPLE = typeof navigator !== 'undefined' && /Mac OS X/.test(navigator.userAgent);
  47024. var IS_FIREFOX = typeof navigator !== 'undefined' && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
  47025. var IS_SAFARI = typeof navigator !== 'undefined' && /Version\/[\d\.]+.*Safari/.test(navigator.userAgent);
  47026. /**
  47027. * Hotkey mappings for each platform.
  47028. */
  47029. var HOTKEYS = {
  47030. bold: 'mod+b',
  47031. compose: ['down', 'left', 'right', 'up', 'backspace', 'enter'],
  47032. moveBackward: 'left',
  47033. moveForward: 'right',
  47034. moveWordBackward: 'ctrl+left',
  47035. moveWordForward: 'ctrl+right',
  47036. deleteBackward: 'shift?+backspace',
  47037. deleteForward: 'shift?+delete',
  47038. extendBackward: 'shift+left',
  47039. extendForward: 'shift+right',
  47040. italic: 'mod+i',
  47041. splitBlock: 'shift?+enter',
  47042. undo: 'mod+z'
  47043. };
  47044. var APPLE_HOTKEYS = {
  47045. moveLineBackward: 'opt+up',
  47046. moveLineForward: 'opt+down',
  47047. moveWordBackward: 'opt+left',
  47048. moveWordForward: 'opt+right',
  47049. deleteBackward: ['ctrl+backspace', 'ctrl+h'],
  47050. deleteForward: ['ctrl+delete', 'ctrl+d'],
  47051. deleteLineBackward: 'cmd+shift?+backspace',
  47052. deleteLineForward: ['cmd+shift?+delete', 'ctrl+k'],
  47053. deleteWordBackward: 'opt+shift?+backspace',
  47054. deleteWordForward: 'opt+shift?+delete',
  47055. extendLineBackward: 'opt+shift+up',
  47056. extendLineForward: 'opt+shift+down',
  47057. redo: 'cmd+shift+z',
  47058. transposeCharacter: 'ctrl+t'
  47059. };
  47060. var WINDOWS_HOTKEYS = {
  47061. deleteWordBackward: 'ctrl+shift?+backspace',
  47062. deleteWordForward: 'ctrl+shift?+delete',
  47063. redo: ['ctrl+y', 'ctrl+shift+z']
  47064. };
  47065. /**
  47066. * Create a platform-aware hotkey checker.
  47067. */
  47068. var create = key => {
  47069. var generic = HOTKEYS[key];
  47070. var apple = APPLE_HOTKEYS[key];
  47071. var windows = WINDOWS_HOTKEYS[key];
  47072. var isGeneric = generic && lib$1.isKeyHotkey(generic);
  47073. var isApple = apple && lib$1.isKeyHotkey(apple);
  47074. var isWindows = windows && lib$1.isKeyHotkey(windows);
  47075. return event => {
  47076. if (isGeneric && isGeneric(event)) return true;
  47077. if (IS_APPLE && isApple && isApple(event)) return true;
  47078. if (!IS_APPLE && isWindows && isWindows(event)) return true;
  47079. return false;
  47080. };
  47081. };
  47082. /**
  47083. * Hotkeys.
  47084. */
  47085. var Hotkeys = {
  47086. isBold: create('bold'),
  47087. isCompose: create('compose'),
  47088. isMoveBackward: create('moveBackward'),
  47089. isMoveForward: create('moveForward'),
  47090. isDeleteBackward: create('deleteBackward'),
  47091. isDeleteForward: create('deleteForward'),
  47092. isDeleteLineBackward: create('deleteLineBackward'),
  47093. isDeleteLineForward: create('deleteLineForward'),
  47094. isDeleteWordBackward: create('deleteWordBackward'),
  47095. isDeleteWordForward: create('deleteWordForward'),
  47096. isExtendBackward: create('extendBackward'),
  47097. isExtendForward: create('extendForward'),
  47098. isExtendLineBackward: create('extendLineBackward'),
  47099. isExtendLineForward: create('extendLineForward'),
  47100. isItalic: create('italic'),
  47101. isMoveLineBackward: create('moveLineBackward'),
  47102. isMoveLineForward: create('moveLineForward'),
  47103. isMoveWordBackward: create('moveWordBackward'),
  47104. isMoveWordForward: create('moveWordForward'),
  47105. isRedo: create('redo'),
  47106. isSplitBlock: create('splitBlock'),
  47107. isTransposeCharacter: create('transposeCharacter'),
  47108. isUndo: create('undo')
  47109. };
  47110. /**
  47111. * A React context for sharing the `readOnly` state of the editor.
  47112. */
  47113. var ReadOnlyContext = React__default.createContext(false);
  47114. /**
  47115. * Get the current `readOnly` state of the editor.
  47116. */
  47117. var useReadOnly = () => {
  47118. return React__default.useContext(ReadOnlyContext);
  47119. };
  47120. /**
  47121. * A React context for sharing the editor object, in a way that re-renders the
  47122. * context whenever changes occur.
  47123. */
  47124. const SlateContext = React__default.createContext(null);
  47125. /**
  47126. * Get the current editor object from the React context.
  47127. */
  47128. const useSlate = () => {
  47129. const context = React__default.useContext(SlateContext);
  47130. if (!context) {
  47131. throw new Error(`The \`useSlate\` hook must be used inside the <SlateProvider> component's context.`);
  47132. }
  47133. const [editor] = context;
  47134. return editor;
  47135. };
  47136. /**
  47137. * Types.
  47138. */
  47139. /**
  47140. * Check if a DOM node is a comment node.
  47141. */
  47142. var isDOMComment = value => {
  47143. return isDOMNode(value) && value.nodeType === 8;
  47144. };
  47145. /**
  47146. * Check if a DOM node is an element node.
  47147. */
  47148. var isDOMElement = value => {
  47149. return isDOMNode(value) && value.nodeType === 1;
  47150. };
  47151. /**
  47152. * Check if a value is a DOM node.
  47153. */
  47154. var isDOMNode = value => {
  47155. return value instanceof Node;
  47156. };
  47157. /**
  47158. * Check if a DOM node is an element node.
  47159. */
  47160. var isDOMText = value => {
  47161. return isDOMNode(value) && value.nodeType === 3;
  47162. };
  47163. /**
  47164. * Normalize a DOM point so that it always refers to a text node.
  47165. */
  47166. var normalizeDOMPoint = domPoint => {
  47167. var [node, offset] = domPoint; // If it's an element node, its offset refers to the index of its children
  47168. // including comment nodes, so try to find the right text child node.
  47169. if (isDOMElement(node) && node.childNodes.length) {
  47170. var isLast = offset === node.childNodes.length;
  47171. var direction = isLast ? 'backward' : 'forward';
  47172. var index = isLast ? offset - 1 : offset;
  47173. node = getEditableChild(node, index, direction); // If the node has children, traverse until we have a leaf node. Leaf nodes
  47174. // can be either text nodes, or other void DOM nodes.
  47175. while (isDOMElement(node) && node.childNodes.length) {
  47176. var i = isLast ? node.childNodes.length - 1 : 0;
  47177. node = getEditableChild(node, i, direction);
  47178. } // Determine the new offset inside the text node.
  47179. offset = isLast && node.textContent != null ? node.textContent.length : 0;
  47180. } // Return the node and offset.
  47181. return [node, offset];
  47182. };
  47183. /**
  47184. * Get the nearest editable child at `index` in a `parent`, preferring
  47185. * `direction`.
  47186. */
  47187. var getEditableChild = (parent, index, direction) => {
  47188. var {
  47189. childNodes
  47190. } = parent;
  47191. var child = childNodes[index];
  47192. var i = index;
  47193. var triedForward = false;
  47194. var triedBackward = false; // While the child is a comment node, or an element node with no children,
  47195. // keep iterating to find a sibling non-void, non-comment node.
  47196. while (isDOMComment(child) || isDOMElement(child) && child.childNodes.length === 0 || isDOMElement(child) && child.getAttribute('contenteditable') === 'false') {
  47197. if (triedForward && triedBackward) {
  47198. break;
  47199. }
  47200. if (i >= childNodes.length) {
  47201. triedForward = true;
  47202. i = index - 1;
  47203. direction = 'backward';
  47204. continue;
  47205. }
  47206. if (i < 0) {
  47207. triedBackward = true;
  47208. i = index + 1;
  47209. direction = 'forward';
  47210. continue;
  47211. }
  47212. child = childNodes[i];
  47213. i += direction === 'forward' ? 1 : -1;
  47214. }
  47215. return child;
  47216. };
  47217. /**
  47218. * Editable.
  47219. */
  47220. const Editable = (props) => {
  47221. const { autoFocus, decorate = defaultDecorate, onDOMBeforeInput: propsOnDOMBeforeInput, placeholder, readOnly = false, renderElement, renderLeaf, style = {}, as: Component = 'div', ...attributes } = props;
  47222. const editor = useSlate();
  47223. const ref = React__default.useRef(null);
  47224. // Update internal state on each render.
  47225. IS_READ_ONLY.set(editor, readOnly);
  47226. // Keep track of some state for the event handler logic.
  47227. const state = React__default.useMemo(() => ({
  47228. isComposing: false,
  47229. isUpdatingSelection: false,
  47230. latestElement: null,
  47231. }), []);
  47232. // Update element-related weak maps with the DOM element ref.
  47233. useIsomorphicLayoutEffect(() => {
  47234. if (ref.current) {
  47235. EDITOR_TO_ELEMENT.set(editor, ref.current);
  47236. NODE_TO_ELEMENT.set(editor, ref.current);
  47237. ELEMENT_TO_NODE.set(ref.current, editor);
  47238. }
  47239. else {
  47240. NODE_TO_ELEMENT.delete(editor);
  47241. }
  47242. });
  47243. // Attach a native DOM event handler for `selectionchange`, because React's
  47244. // built-in `onSelect` handler doesn't fire for all selection changes. It's a
  47245. // leaky polyfill that only fires on keypresses or clicks. Instead, we want to
  47246. // fire for any change to the selection inside the editor. (2019/11/04)
  47247. // https://github.com/facebook/react/issues/5785
  47248. useIsomorphicLayoutEffect(() => {
  47249. window.document.addEventListener('selectionchange', onDOMSelectionChange);
  47250. return () => {
  47251. window.document.removeEventListener('selectionchange', onDOMSelectionChange);
  47252. };
  47253. }, []);
  47254. // Attach a native DOM event handler for `beforeinput` events, because React's
  47255. // built-in `onBeforeInput` is actually a leaky polyfill that doesn't expose
  47256. // real `beforeinput` events sadly... (2019/11/04)
  47257. // https://github.com/facebook/react/issues/11211
  47258. useIsomorphicLayoutEffect(() => {
  47259. if (ref.current) {
  47260. // @ts-ignore The `beforeinput` event isn't recognized.
  47261. ref.current.addEventListener('beforeinput', onDOMBeforeInput);
  47262. }
  47263. return () => {
  47264. if (ref.current) {
  47265. // @ts-ignore The `beforeinput` event isn't recognized.
  47266. ref.current.removeEventListener('beforeinput', onDOMBeforeInput);
  47267. }
  47268. };
  47269. }, []);
  47270. // Whenever the editor updates, make sure the DOM selection state is in sync.
  47271. useIsomorphicLayoutEffect(() => {
  47272. const { selection } = editor;
  47273. const domSelection = window.getSelection();
  47274. if (state.isComposing || !domSelection || !ReactEditor.isFocused(editor)) {
  47275. return;
  47276. }
  47277. const hasDomSelection = domSelection.type !== 'None';
  47278. // If the DOM selection is properly unset, we're done.
  47279. if (!selection && !hasDomSelection) {
  47280. return;
  47281. }
  47282. const newDomRange = selection && ReactEditor.toDOMRange(editor, selection);
  47283. // If the DOM selection is already correct, we're done.
  47284. if (hasDomSelection &&
  47285. newDomRange &&
  47286. isRangeEqual(domSelection.getRangeAt(0), newDomRange)) {
  47287. return;
  47288. }
  47289. // Otherwise the DOM selection is out of sync, so update it.
  47290. const el = ReactEditor.toDOMNode(editor, editor);
  47291. state.isUpdatingSelection = true;
  47292. domSelection.removeAllRanges();
  47293. if (newDomRange) {
  47294. domSelection.addRange(newDomRange);
  47295. const leafEl = newDomRange.startContainer.parentElement;
  47296. scrollIntoView(leafEl, { scrollMode: 'if-needed' });
  47297. }
  47298. setTimeout(() => {
  47299. // COMPAT: In Firefox, it's not enough to create a range, you also need
  47300. // to focus the contenteditable element too. (2016/11/16)
  47301. if (newDomRange && IS_FIREFOX) {
  47302. el.focus();
  47303. }
  47304. state.isUpdatingSelection = false;
  47305. });
  47306. });
  47307. // The autoFocus TextareaHTMLAttribute doesn't do anything on a div, so it
  47308. // needs to be manually focused.
  47309. React__default.useEffect(() => {
  47310. if (ref.current && autoFocus) {
  47311. ref.current.focus();
  47312. }
  47313. }, [autoFocus]);
  47314. // Listen on the native `beforeinput` event to get real "Level 2" events. This
  47315. // is required because React's `beforeinput` is fake and never really attaches
  47316. // to the real event sadly. (2019/11/01)
  47317. // https://github.com/facebook/react/issues/11211
  47318. const onDOMBeforeInput = React__default.useCallback((event) => {
  47319. if (!readOnly &&
  47320. hasEditableTarget(editor, event.target) &&
  47321. !isDOMEventHandled(event, propsOnDOMBeforeInput)) {
  47322. const { selection } = editor;
  47323. const { inputType: type } = event;
  47324. const data = event.dataTransfer || event.data || undefined;
  47325. // These two types occur while a user is composing text and can't be
  47326. // cancelled. Let them through and wait for the composition to end.
  47327. if (type === 'insertCompositionText' ||
  47328. type === 'deleteCompositionText') {
  47329. return;
  47330. }
  47331. event.preventDefault();
  47332. // COMPAT: For the deleting forward/backward input types we don't want
  47333. // to change the selection because it is the range that will be deleted,
  47334. // and those commands determine that for themselves.
  47335. if (!type.startsWith('delete') || type.startsWith('deleteBy')) {
  47336. const [targetRange] = event.getTargetRanges();
  47337. if (targetRange) {
  47338. const range = ReactEditor.toSlateRange(editor, targetRange);
  47339. if (!selection || !dist$5.Range.equals(selection, range)) {
  47340. dist$5.Transforms.select(editor, range);
  47341. }
  47342. }
  47343. }
  47344. // COMPAT: If the selection is expanded, even if the command seems like
  47345. // a delete forward/backward command it should delete the selection.
  47346. if (selection &&
  47347. dist$5.Range.isExpanded(selection) &&
  47348. type.startsWith('delete')) {
  47349. dist$5.Editor.deleteFragment(editor);
  47350. return;
  47351. }
  47352. switch (type) {
  47353. case 'deleteByComposition':
  47354. case 'deleteByCut':
  47355. case 'deleteByDrag': {
  47356. dist$5.Editor.deleteFragment(editor);
  47357. break;
  47358. }
  47359. case 'deleteContent':
  47360. case 'deleteContentForward': {
  47361. dist$5.Editor.deleteForward(editor);
  47362. break;
  47363. }
  47364. case 'deleteContentBackward': {
  47365. dist$5.Editor.deleteBackward(editor);
  47366. break;
  47367. }
  47368. case 'deleteEntireSoftLine': {
  47369. dist$5.Editor.deleteBackward(editor, { unit: 'line' });
  47370. dist$5.Editor.deleteForward(editor, { unit: 'line' });
  47371. break;
  47372. }
  47373. case 'deleteHardLineBackward': {
  47374. dist$5.Editor.deleteBackward(editor, { unit: 'block' });
  47375. break;
  47376. }
  47377. case 'deleteSoftLineBackward': {
  47378. dist$5.Editor.deleteBackward(editor, { unit: 'line' });
  47379. break;
  47380. }
  47381. case 'deleteHardLineForward': {
  47382. dist$5.Editor.deleteForward(editor, { unit: 'block' });
  47383. break;
  47384. }
  47385. case 'deleteSoftLineForward': {
  47386. dist$5.Editor.deleteForward(editor, { unit: 'line' });
  47387. break;
  47388. }
  47389. case 'deleteWordBackward': {
  47390. dist$5.Editor.deleteBackward(editor, { unit: 'word' });
  47391. break;
  47392. }
  47393. case 'deleteWordForward': {
  47394. dist$5.Editor.deleteForward(editor, { unit: 'word' });
  47395. break;
  47396. }
  47397. case 'insertLineBreak':
  47398. case 'insertParagraph': {
  47399. dist$5.Editor.insertBreak(editor);
  47400. break;
  47401. }
  47402. case 'insertFromComposition':
  47403. case 'insertFromDrop':
  47404. case 'insertFromPaste':
  47405. case 'insertFromYank':
  47406. case 'insertReplacementText':
  47407. case 'insertText': {
  47408. if (data instanceof DataTransfer) {
  47409. ReactEditor.insertData(editor, data);
  47410. }
  47411. else if (typeof data === 'string') {
  47412. dist$5.Editor.insertText(editor, data);
  47413. }
  47414. break;
  47415. }
  47416. }
  47417. }
  47418. }, []);
  47419. // Listen on the native `selectionchange` event to be able to update any time
  47420. // the selection changes. This is required because React's `onSelect` is leaky
  47421. // and non-standard so it doesn't fire until after a selection has been
  47422. // released. This causes issues in situations where another change happens
  47423. // while a selection is being dragged.
  47424. const onDOMSelectionChange = React__default.useCallback(debounce(() => {
  47425. if (!readOnly && !state.isComposing && !state.isUpdatingSelection) {
  47426. const { activeElement } = window.document;
  47427. const el = ReactEditor.toDOMNode(editor, editor);
  47428. const domSelection = window.getSelection();
  47429. const domRange = domSelection &&
  47430. domSelection.rangeCount > 0 &&
  47431. domSelection.getRangeAt(0);
  47432. if (activeElement === el) {
  47433. state.latestElement = activeElement;
  47434. IS_FOCUSED.set(editor, true);
  47435. }
  47436. else {
  47437. IS_FOCUSED.delete(editor);
  47438. }
  47439. if (domRange &&
  47440. hasEditableTarget(editor, domRange.startContainer) &&
  47441. hasEditableTarget(editor, domRange.endContainer)) {
  47442. const range = ReactEditor.toSlateRange(editor, domRange);
  47443. dist$5.Transforms.select(editor, range);
  47444. }
  47445. else {
  47446. dist$5.Transforms.deselect(editor);
  47447. }
  47448. }
  47449. }, 100), []);
  47450. const decorations = decorate([editor, []]);
  47451. if (placeholder &&
  47452. editor.children.length === 1 &&
  47453. Array.from(dist$5.Node.texts(editor)).length === 1 &&
  47454. dist$5.Node.string(editor) === '') {
  47455. const start = dist$5.Editor.start(editor, []);
  47456. decorations.push({
  47457. [PLACEHOLDER_SYMBOL]: true,
  47458. placeholder,
  47459. anchor: start,
  47460. focus: start,
  47461. });
  47462. }
  47463. return (React__default$1.createElement(ReadOnlyContext.Provider, { value: readOnly },
  47464. React__default$1.createElement(Component
  47465. // COMPAT: The Grammarly Chrome extension works by changing the DOM
  47466. // out from under `contenteditable` elements, which leads to weird
  47467. // behaviors so we have to disable it like editor. (2017/04/24)
  47468. , Object.assign({ "data-gramm": false, role: readOnly ? undefined : 'textbox' }, attributes, {
  47469. // COMPAT: Firefox doesn't support the `beforeinput` event, so we'd
  47470. // have to use hacks to make these replacement-based features work.
  47471. 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: {
  47472. // Prevent the default outline styles.
  47473. outline: 'none',
  47474. // Preserve adjacent whitespace and new lines.
  47475. whiteSpace: 'pre-wrap',
  47476. // Allow words to break if they are too long.
  47477. wordWrap: 'break-word',
  47478. // Allow for passed-in styles to override anything.
  47479. ...style,
  47480. }, onBeforeInput: React__default.useCallback((event) => {
  47481. // COMPAT: Firefox doesn't support the `beforeinput` event, so we
  47482. // fall back to React's leaky polyfill instead just for it. It
  47483. // only works for the `insertText` input type.
  47484. if (IS_FIREFOX && !readOnly) {
  47485. event.preventDefault();
  47486. const text = event.data;
  47487. dist$5.Editor.insertText(editor, text);
  47488. }
  47489. }, [readOnly]), onBlur: React__default.useCallback((event) => {
  47490. if (readOnly ||
  47491. state.isUpdatingSelection ||
  47492. !hasEditableTarget(editor, event.target) ||
  47493. isEventHandled(event, attributes.onBlur)) {
  47494. return;
  47495. }
  47496. // COMPAT: If the current `activeElement` is still the previous
  47497. // one, this is due to the window being blurred when the tab
  47498. // itself becomes unfocused, so we want to abort early to allow to
  47499. // editor to stay focused when the tab becomes focused again.
  47500. if (state.latestElement === window.document.activeElement) {
  47501. return;
  47502. }
  47503. const { relatedTarget } = event;
  47504. const el = ReactEditor.toDOMNode(editor, editor);
  47505. // COMPAT: The event should be ignored if the focus is returning
  47506. // to the editor from an embedded editable element (eg. an <input>
  47507. // element inside a void node).
  47508. if (relatedTarget === el) {
  47509. return;
  47510. }
  47511. // COMPAT: The event should be ignored if the focus is moving from
  47512. // the editor to inside a void node's spacer element.
  47513. if (isDOMElement(relatedTarget) &&
  47514. relatedTarget.hasAttribute('data-slate-spacer')) {
  47515. return;
  47516. }
  47517. // COMPAT: The event should be ignored if the focus is moving to a
  47518. // non- editable section of an element that isn't a void node (eg.
  47519. // a list item of the check list example).
  47520. if (relatedTarget != null &&
  47521. isDOMNode(relatedTarget) &&
  47522. ReactEditor.hasDOMNode(editor, relatedTarget)) {
  47523. const node = ReactEditor.toSlateNode(editor, relatedTarget);
  47524. if (dist$5.Element.isElement(node) && !editor.isVoid(node)) {
  47525. return;
  47526. }
  47527. }
  47528. IS_FOCUSED.delete(editor);
  47529. }, [readOnly, attributes.onBlur]), onClick: React__default.useCallback((event) => {
  47530. if (!readOnly &&
  47531. hasTarget(editor, event.target) &&
  47532. !isEventHandled(event, attributes.onClick) &&
  47533. isDOMNode(event.target)) {
  47534. const node = ReactEditor.toSlateNode(editor, event.target);
  47535. const path = ReactEditor.findPath(editor, node);
  47536. const start = dist$5.Editor.start(editor, path);
  47537. if (dist$5.Editor.void(editor, { at: start })) {
  47538. const range = dist$5.Editor.range(editor, start);
  47539. dist$5.Transforms.select(editor, range);
  47540. }
  47541. }
  47542. }, [readOnly, attributes.onClick]), onCompositionEnd: React__default.useCallback((event) => {
  47543. if (hasEditableTarget(editor, event.target) &&
  47544. !isEventHandled(event, attributes.onCompositionEnd)) {
  47545. state.isComposing = false;
  47546. // COMPAT: In Chrome, `beforeinput` events for compositions
  47547. // aren't correct and never fire the "insertFromComposition"
  47548. // type that we need. So instead, insert whenever a composition
  47549. // ends since it will already have been committed to the DOM.
  47550. if (!IS_SAFARI && !IS_FIREFOX && event.data) {
  47551. dist$5.Editor.insertText(editor, event.data);
  47552. }
  47553. }
  47554. }, [attributes.onCompositionEnd]), onCompositionStart: React__default.useCallback((event) => {
  47555. if (hasEditableTarget(editor, event.target) &&
  47556. !isEventHandled(event, attributes.onCompositionStart)) {
  47557. state.isComposing = true;
  47558. }
  47559. }, [attributes.onCompositionStart]), onCopy: React__default.useCallback((event) => {
  47560. if (hasEditableTarget(editor, event.target) &&
  47561. !isEventHandled(event, attributes.onCopy)) {
  47562. event.preventDefault();
  47563. setFragmentData(event.clipboardData, editor);
  47564. }
  47565. }, [attributes.onCopy]), onCut: React__default.useCallback((event) => {
  47566. if (!readOnly &&
  47567. hasEditableTarget(editor, event.target) &&
  47568. !isEventHandled(event, attributes.onCut)) {
  47569. event.preventDefault();
  47570. setFragmentData(event.clipboardData, editor);
  47571. const { selection } = editor;
  47572. if (selection && dist$5.Range.isExpanded(selection)) {
  47573. dist$5.Editor.deleteFragment(editor);
  47574. }
  47575. }
  47576. }, [readOnly, attributes.onCut]), onDragOver: React__default.useCallback((event) => {
  47577. if (hasTarget(editor, event.target) &&
  47578. !isEventHandled(event, attributes.onDragOver)) {
  47579. // Only when the target is void, call `preventDefault` to signal
  47580. // that drops are allowed. Editable content is droppable by
  47581. // default, and calling `preventDefault` hides the cursor.
  47582. const node = ReactEditor.toSlateNode(editor, event.target);
  47583. if (dist$5.Editor.isVoid(editor, node)) {
  47584. event.preventDefault();
  47585. }
  47586. }
  47587. }, [attributes.onDragOver]), onDragStart: React__default.useCallback((event) => {
  47588. if (hasTarget(editor, event.target) &&
  47589. !isEventHandled(event, attributes.onDragStart)) {
  47590. const node = ReactEditor.toSlateNode(editor, event.target);
  47591. const path = ReactEditor.findPath(editor, node);
  47592. const voidMatch = dist$5.Editor.void(editor, { at: path });
  47593. // If starting a drag on a void node, make sure it is selected
  47594. // so that it shows up in the selection's fragment.
  47595. if (voidMatch) {
  47596. const range = dist$5.Editor.range(editor, path);
  47597. dist$5.Transforms.select(editor, range);
  47598. }
  47599. setFragmentData(event.dataTransfer, editor);
  47600. }
  47601. }, [attributes.onDragStart]), onDrop: React__default.useCallback((event) => {
  47602. if (hasTarget(editor, event.target) &&
  47603. !readOnly &&
  47604. !isEventHandled(event, attributes.onDrop)) {
  47605. // COMPAT: Firefox doesn't fire `beforeinput` events at all, and
  47606. // Chromium browsers don't properly fire them for files being
  47607. // dropped into a `contenteditable`. (2019/11/26)
  47608. // https://bugs.chromium.org/p/chromium/issues/detail?id=1028668
  47609. if (IS_FIREFOX ||
  47610. (!IS_SAFARI && event.dataTransfer.files.length > 0)) {
  47611. event.preventDefault();
  47612. const range = ReactEditor.findEventRange(editor, event);
  47613. const data = event.dataTransfer;
  47614. dist$5.Transforms.select(editor, range);
  47615. ReactEditor.insertData(editor, data);
  47616. }
  47617. }
  47618. }, [readOnly, attributes.onDrop]), onFocus: React__default.useCallback((event) => {
  47619. if (!readOnly &&
  47620. !state.isUpdatingSelection &&
  47621. hasEditableTarget(editor, event.target) &&
  47622. !isEventHandled(event, attributes.onFocus)) {
  47623. const el = ReactEditor.toDOMNode(editor, editor);
  47624. state.latestElement = window.document.activeElement;
  47625. // COMPAT: If the editor has nested editable elements, the focus
  47626. // can go to them. In Firefox, this must be prevented because it
  47627. // results in issues with keyboard navigation. (2017/03/30)
  47628. if (IS_FIREFOX && event.target !== el) {
  47629. el.focus();
  47630. return;
  47631. }
  47632. IS_FOCUSED.set(editor, true);
  47633. }
  47634. }, [readOnly, attributes.onFocus]), onKeyDown: React__default.useCallback((event) => {
  47635. if (!readOnly &&
  47636. hasEditableTarget(editor, event.target) &&
  47637. !isEventHandled(event, attributes.onKeyDown)) {
  47638. const { nativeEvent } = event;
  47639. const { selection } = editor;
  47640. // COMPAT: Since we prevent the default behavior on
  47641. // `beforeinput` events, the browser doesn't think there's ever
  47642. // any history stack to undo or redo, so we have to manage these
  47643. // hotkeys ourselves. (2019/11/06)
  47644. if (Hotkeys.isRedo(nativeEvent)) {
  47645. event.preventDefault();
  47646. if (editor.redo) {
  47647. editor.redo();
  47648. }
  47649. return;
  47650. }
  47651. if (Hotkeys.isUndo(nativeEvent)) {
  47652. event.preventDefault();
  47653. if (editor.undo) {
  47654. editor.undo();
  47655. }
  47656. return;
  47657. }
  47658. // COMPAT: Certain browsers don't handle the selection updates
  47659. // properly. In Chrome, the selection isn't properly extended.
  47660. // And in Firefox, the selection isn't properly collapsed.
  47661. // (2017/10/17)
  47662. if (Hotkeys.isMoveLineBackward(nativeEvent)) {
  47663. event.preventDefault();
  47664. dist$5.Transforms.move(editor, { unit: 'line', reverse: true });
  47665. return;
  47666. }
  47667. if (Hotkeys.isMoveLineForward(nativeEvent)) {
  47668. event.preventDefault();
  47669. dist$5.Transforms.move(editor, { unit: 'line' });
  47670. return;
  47671. }
  47672. if (Hotkeys.isExtendLineBackward(nativeEvent)) {
  47673. event.preventDefault();
  47674. dist$5.Transforms.move(editor, {
  47675. unit: 'line',
  47676. edge: 'focus',
  47677. reverse: true,
  47678. });
  47679. return;
  47680. }
  47681. if (Hotkeys.isExtendLineForward(nativeEvent)) {
  47682. event.preventDefault();
  47683. dist$5.Transforms.move(editor, { unit: 'line', edge: 'focus' });
  47684. return;
  47685. }
  47686. // COMPAT: If a void node is selected, or a zero-width text node
  47687. // adjacent to an inline is selected, we need to handle these
  47688. // hotkeys manually because browsers won't be able to skip over
  47689. // the void node with the zero-width space not being an empty
  47690. // string.
  47691. if (Hotkeys.isMoveBackward(nativeEvent)) {
  47692. event.preventDefault();
  47693. if (selection && dist$5.Range.isCollapsed(selection)) {
  47694. dist$5.Transforms.move(editor, { reverse: true });
  47695. }
  47696. else {
  47697. dist$5.Transforms.collapse(editor, { edge: 'start' });
  47698. }
  47699. return;
  47700. }
  47701. if (Hotkeys.isMoveForward(nativeEvent)) {
  47702. event.preventDefault();
  47703. if (selection && dist$5.Range.isCollapsed(selection)) {
  47704. dist$5.Transforms.move(editor);
  47705. }
  47706. else {
  47707. dist$5.Transforms.collapse(editor, { edge: 'end' });
  47708. }
  47709. return;
  47710. }
  47711. if (Hotkeys.isMoveWordBackward(nativeEvent)) {
  47712. event.preventDefault();
  47713. dist$5.Transforms.move(editor, { unit: 'word', reverse: true });
  47714. return;
  47715. }
  47716. if (Hotkeys.isMoveWordForward(nativeEvent)) {
  47717. event.preventDefault();
  47718. dist$5.Transforms.move(editor, { unit: 'word' });
  47719. return;
  47720. }
  47721. // COMPAT: Firefox doesn't support the `beforeinput` event, so we
  47722. // fall back to guessing at the input intention for hotkeys.
  47723. // COMPAT: In iOS, some of these hotkeys are handled in the
  47724. if (IS_FIREFOX) {
  47725. // We don't have a core behavior for these, but they change the
  47726. // DOM if we don't prevent them, so we have to.
  47727. if (Hotkeys.isBold(nativeEvent) ||
  47728. Hotkeys.isItalic(nativeEvent) ||
  47729. Hotkeys.isTransposeCharacter(nativeEvent)) {
  47730. event.preventDefault();
  47731. return;
  47732. }
  47733. if (Hotkeys.isSplitBlock(nativeEvent)) {
  47734. event.preventDefault();
  47735. dist$5.Editor.insertBreak(editor);
  47736. return;
  47737. }
  47738. if (Hotkeys.isDeleteBackward(nativeEvent)) {
  47739. event.preventDefault();
  47740. if (selection && dist$5.Range.isExpanded(selection)) {
  47741. dist$5.Editor.deleteFragment(editor);
  47742. }
  47743. else {
  47744. dist$5.Editor.deleteBackward(editor);
  47745. }
  47746. return;
  47747. }
  47748. if (Hotkeys.isDeleteForward(nativeEvent)) {
  47749. event.preventDefault();
  47750. if (selection && dist$5.Range.isExpanded(selection)) {
  47751. dist$5.Editor.deleteFragment(editor);
  47752. }
  47753. else {
  47754. dist$5.Editor.deleteForward(editor);
  47755. }
  47756. return;
  47757. }
  47758. if (Hotkeys.isDeleteLineBackward(nativeEvent)) {
  47759. event.preventDefault();
  47760. if (selection && dist$5.Range.isExpanded(selection)) {
  47761. dist$5.Editor.deleteFragment(editor);
  47762. }
  47763. else {
  47764. dist$5.Editor.deleteBackward(editor, { unit: 'line' });
  47765. }
  47766. return;
  47767. }
  47768. if (Hotkeys.isDeleteLineForward(nativeEvent)) {
  47769. event.preventDefault();
  47770. if (selection && dist$5.Range.isExpanded(selection)) {
  47771. dist$5.Editor.deleteFragment(editor);
  47772. }
  47773. else {
  47774. dist$5.Editor.deleteForward(editor, { unit: 'line' });
  47775. }
  47776. return;
  47777. }
  47778. if (Hotkeys.isDeleteWordBackward(nativeEvent)) {
  47779. event.preventDefault();
  47780. if (selection && dist$5.Range.isExpanded(selection)) {
  47781. dist$5.Editor.deleteFragment(editor);
  47782. }
  47783. else {
  47784. dist$5.Editor.deleteBackward(editor, { unit: 'word' });
  47785. }
  47786. return;
  47787. }
  47788. if (Hotkeys.isDeleteWordForward(nativeEvent)) {
  47789. event.preventDefault();
  47790. if (selection && dist$5.Range.isExpanded(selection)) {
  47791. dist$5.Editor.deleteFragment(editor);
  47792. }
  47793. else {
  47794. dist$5.Editor.deleteForward(editor, { unit: 'word' });
  47795. }
  47796. return;
  47797. }
  47798. }
  47799. }
  47800. }, [readOnly, attributes.onKeyDown]), onPaste: React__default.useCallback((event) => {
  47801. // COMPAT: Firefox doesn't support the `beforeinput` event, so we
  47802. // fall back to React's `onPaste` here instead.
  47803. if (IS_FIREFOX &&
  47804. !readOnly &&
  47805. hasEditableTarget(editor, event.target) &&
  47806. !isEventHandled(event, attributes.onPaste)) {
  47807. event.preventDefault();
  47808. ReactEditor.insertData(editor, event.clipboardData);
  47809. }
  47810. }, [readOnly, attributes.onPaste]) }),
  47811. React__default$1.createElement(Children, { decorate: decorate, decorations: decorations, node: editor, renderElement: renderElement, renderLeaf: renderLeaf, selection: editor.selection }))));
  47812. };
  47813. /**
  47814. * A default memoized decorate function.
  47815. */
  47816. const defaultDecorate = () => [];
  47817. /**
  47818. * Check if two DOM range objects are equal.
  47819. */
  47820. const isRangeEqual = (a, b) => {
  47821. return ((a.startContainer === b.startContainer &&
  47822. a.startOffset === b.startOffset &&
  47823. a.endContainer === b.endContainer &&
  47824. a.endOffset === b.endOffset) ||
  47825. (a.startContainer === b.endContainer &&
  47826. a.startOffset === b.endOffset &&
  47827. a.endContainer === b.startContainer &&
  47828. a.endOffset === b.startOffset));
  47829. };
  47830. /**
  47831. * Check if the target is in the editor.
  47832. */
  47833. const hasTarget = (editor, target) => {
  47834. return isDOMNode(target) && ReactEditor.hasDOMNode(editor, target);
  47835. };
  47836. /**
  47837. * Check if the target is editable and in the editor.
  47838. */
  47839. const hasEditableTarget = (editor, target) => {
  47840. return (isDOMNode(target) &&
  47841. ReactEditor.hasDOMNode(editor, target, { editable: true }));
  47842. };
  47843. /**
  47844. * Check if an event is overrided by a handler.
  47845. */
  47846. const isEventHandled = (event, handler) => {
  47847. if (!handler) {
  47848. return false;
  47849. }
  47850. handler(event);
  47851. return event.isDefaultPrevented() || event.isPropagationStopped();
  47852. };
  47853. /**
  47854. * Check if a DOM event is overrided by a handler.
  47855. */
  47856. const isDOMEventHandled = (event, handler) => {
  47857. if (!handler) {
  47858. return false;
  47859. }
  47860. handler(event);
  47861. return event.defaultPrevented;
  47862. };
  47863. /**
  47864. * Set the currently selected fragment to the clipboard.
  47865. */
  47866. const setFragmentData = (dataTransfer, editor) => {
  47867. const { selection } = editor;
  47868. if (!selection) {
  47869. return;
  47870. }
  47871. const [start, end] = dist$5.Range.edges(selection);
  47872. const startVoid = dist$5.Editor.void(editor, { at: start.path });
  47873. const endVoid = dist$5.Editor.void(editor, { at: end.path });
  47874. if (dist$5.Range.isCollapsed(selection) && !startVoid) {
  47875. return;
  47876. }
  47877. // Create a fake selection so that we can add a Base64-encoded copy of the
  47878. // fragment to the HTML, to decode on future pastes.
  47879. const domRange = ReactEditor.toDOMRange(editor, selection);
  47880. let contents = domRange.cloneContents();
  47881. let attach = contents.childNodes[0];
  47882. // Make sure attach is non-empty, since empty nodes will not get copied.
  47883. contents.childNodes.forEach(node => {
  47884. if (node.textContent && node.textContent.trim() !== '') {
  47885. attach = node;
  47886. }
  47887. });
  47888. // COMPAT: If the end node is a void node, we need to move the end of the
  47889. // range from the void node's spacer span, to the end of the void node's
  47890. // content, since the spacer is before void's content in the DOM.
  47891. if (endVoid) {
  47892. const [voidNode] = endVoid;
  47893. const r = domRange.cloneRange();
  47894. const domNode = ReactEditor.toDOMNode(editor, voidNode);
  47895. r.setEndAfter(domNode);
  47896. contents = r.cloneContents();
  47897. }
  47898. // COMPAT: If the start node is a void node, we need to attach the encoded
  47899. // fragment to the void node's content node instead of the spacer, because
  47900. // attaching it to empty `<div>/<span>` nodes will end up having it erased by
  47901. // most browsers. (2018/04/27)
  47902. if (startVoid) {
  47903. attach = contents.querySelector('[data-slate-spacer]');
  47904. }
  47905. // Remove any zero-width space spans from the cloned DOM so that they don't
  47906. // show up elsewhere when pasted.
  47907. Array.from(contents.querySelectorAll('[data-slate-zero-width]')).forEach(zw => {
  47908. const isNewline = zw.getAttribute('data-slate-zero-width') === 'n';
  47909. zw.textContent = isNewline ? '\n' : '';
  47910. });
  47911. // Set a `data-slate-fragment` attribute on a non-empty node, so it shows up
  47912. // in the HTML, and can be used for intra-Slate pasting. If it's a text
  47913. // node, wrap it in a `<span>` so we have something to set an attribute on.
  47914. if (isDOMText(attach)) {
  47915. const span = document.createElement('span');
  47916. // COMPAT: In Chrome and Safari, if we don't add the `white-space` style
  47917. // then leading and trailing spaces will be ignored. (2017/09/21)
  47918. span.style.whiteSpace = 'pre';
  47919. span.appendChild(attach);
  47920. contents.appendChild(span);
  47921. attach = span;
  47922. }
  47923. const fragment = dist$5.Node.fragment(editor, selection);
  47924. const string = JSON.stringify(fragment);
  47925. const encoded = window.btoa(encodeURIComponent(string));
  47926. attach.setAttribute('data-slate-fragment', encoded);
  47927. dataTransfer.setData('application/x-slate-fragment', encoded);
  47928. // Add the content to a <div> so that we can get its inner HTML.
  47929. const div = document.createElement('div');
  47930. div.appendChild(contents);
  47931. dataTransfer.setData('text/html', div.innerHTML);
  47932. dataTransfer.setData('text/plain', getPlainText(div));
  47933. };
  47934. /**
  47935. * Get a plaintext representation of the content of a node, accounting for block
  47936. * elements which get a newline appended.
  47937. */
  47938. const getPlainText = (domNode) => {
  47939. let text = '';
  47940. if (isDOMText(domNode) && domNode.nodeValue) {
  47941. return domNode.nodeValue;
  47942. }
  47943. if (isDOMElement(domNode)) {
  47944. for (const childNode of Array.from(domNode.childNodes)) {
  47945. text += getPlainText(childNode);
  47946. }
  47947. const display = getComputedStyle(domNode).getPropertyValue('display');
  47948. if (display === 'block' || display === 'list' || domNode.tagName === 'BR') {
  47949. text += '\n';
  47950. }
  47951. }
  47952. return text;
  47953. };
  47954. /**
  47955. * An auto-incrementing identifier for keys.
  47956. */
  47957. var n = 0;
  47958. /**
  47959. * A class that keeps track of a key string. We use a full class here because we
  47960. * want to be able to use them as keys in `WeakMap` objects.
  47961. */
  47962. class Key {
  47963. constructor() {
  47964. this.id = "".concat(n++);
  47965. }
  47966. }
  47967. var ReactEditor = {
  47968. /**
  47969. * Find a key for a Slate node.
  47970. */
  47971. findKey(editor, node) {
  47972. var key = NODE_TO_KEY.get(node);
  47973. if (!key) {
  47974. key = new Key();
  47975. NODE_TO_KEY.set(node, key);
  47976. }
  47977. return key;
  47978. },
  47979. /**
  47980. * Find the path of Slate node.
  47981. */
  47982. findPath(editor, node) {
  47983. var path = [];
  47984. var child = node;
  47985. while (true) {
  47986. var parent = NODE_TO_PARENT.get(child);
  47987. if (parent == null) {
  47988. if (dist$5.Editor.isEditor(child)) {
  47989. return path;
  47990. } else {
  47991. break;
  47992. }
  47993. }
  47994. var i = NODE_TO_INDEX.get(child);
  47995. if (i == null) {
  47996. break;
  47997. }
  47998. path.unshift(i);
  47999. child = parent;
  48000. }
  48001. throw new Error("Unable to find the path for Slate node: ".concat(JSON.stringify(node)));
  48002. },
  48003. /**
  48004. * Check if the editor is focused.
  48005. */
  48006. isFocused(editor) {
  48007. return !!IS_FOCUSED.get(editor);
  48008. },
  48009. /**
  48010. * Check if the editor is in read-only mode.
  48011. */
  48012. isReadOnly(editor) {
  48013. return !!IS_READ_ONLY.get(editor);
  48014. },
  48015. /**
  48016. * Blur the editor.
  48017. */
  48018. blur(editor) {
  48019. var el = ReactEditor.toDOMNode(editor, editor);
  48020. IS_FOCUSED.set(editor, false);
  48021. if (window.document.activeElement === el) {
  48022. el.blur();
  48023. }
  48024. },
  48025. /**
  48026. * Focus the editor.
  48027. */
  48028. focus(editor) {
  48029. var el = ReactEditor.toDOMNode(editor, editor);
  48030. IS_FOCUSED.set(editor, true);
  48031. if (window.document.activeElement !== el) {
  48032. el.focus({
  48033. preventScroll: true
  48034. });
  48035. }
  48036. },
  48037. /**
  48038. * Deselect the editor.
  48039. */
  48040. deselect(editor) {
  48041. var {
  48042. selection
  48043. } = editor;
  48044. var domSelection = window.getSelection();
  48045. if (domSelection && domSelection.rangeCount > 0) {
  48046. domSelection.removeAllRanges();
  48047. }
  48048. if (selection) {
  48049. dist$5.Transforms.deselect(editor);
  48050. }
  48051. },
  48052. /**
  48053. * Check if a DOM node is within the editor.
  48054. */
  48055. hasDOMNode(editor, target) {
  48056. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  48057. var {
  48058. editable = false
  48059. } = options;
  48060. var el = ReactEditor.toDOMNode(editor, editor);
  48061. var element; // COMPAT: In Firefox, reading `target.nodeType` will throw an error if
  48062. // target is originating from an internal "restricted" element (e.g. a
  48063. // stepper arrow on a number input). (2018/05/04)
  48064. // https://github.com/ianstormtaylor/slate/issues/1819
  48065. try {
  48066. element = isDOMElement(target) ? target : target.parentElement;
  48067. } catch (err) {
  48068. if (!err.message.includes('Permission denied to access property "nodeType"')) {
  48069. throw err;
  48070. }
  48071. }
  48072. if (!element) {
  48073. return false;
  48074. }
  48075. return element.closest("[data-slate-editor]") === el && (!editable || el.isContentEditable);
  48076. },
  48077. /**
  48078. * Insert data from a `DataTransfer` into the editor.
  48079. */
  48080. insertData(editor, data) {
  48081. editor.insertData(data);
  48082. },
  48083. /**
  48084. * Find the native DOM element from a Slate node.
  48085. */
  48086. toDOMNode(editor, node) {
  48087. var domNode = dist$5.Editor.isEditor(node) ? EDITOR_TO_ELEMENT.get(editor) : KEY_TO_ELEMENT.get(ReactEditor.findKey(editor, node));
  48088. if (!domNode) {
  48089. throw new Error("Cannot resolve a DOM node from Slate node: ".concat(JSON.stringify(node)));
  48090. }
  48091. return domNode;
  48092. },
  48093. /**
  48094. * Find a native DOM selection point from a Slate point.
  48095. */
  48096. toDOMPoint(editor, point) {
  48097. var [node] = dist$5.Editor.node(editor, point.path);
  48098. var el = ReactEditor.toDOMNode(editor, node);
  48099. var domPoint; // If we're inside a void node, force the offset to 0, otherwise the zero
  48100. // width spacing character will result in an incorrect offset of 1
  48101. if (dist$5.Editor.void(editor, {
  48102. at: point
  48103. })) {
  48104. point = {
  48105. path: point.path,
  48106. offset: 0
  48107. };
  48108. } // For each leaf, we need to isolate its content, which means filtering
  48109. // to its direct text and zero-width spans. (We have to filter out any
  48110. // other siblings that may have been rendered alongside them.)
  48111. var selector = "[data-slate-string], [data-slate-zero-width]";
  48112. var texts = Array.from(el.querySelectorAll(selector));
  48113. var start = 0;
  48114. for (var text of texts) {
  48115. var domNode = text.childNodes[0];
  48116. if (domNode == null || domNode.textContent == null) {
  48117. continue;
  48118. }
  48119. var {
  48120. length
  48121. } = domNode.textContent;
  48122. var attr = text.getAttribute('data-slate-length');
  48123. var trueLength = attr == null ? length : parseInt(attr, 10);
  48124. var end = start + trueLength;
  48125. if (point.offset <= end) {
  48126. var offset = Math.min(length, Math.max(0, point.offset - start));
  48127. domPoint = [domNode, offset];
  48128. break;
  48129. }
  48130. start = end;
  48131. }
  48132. if (!domPoint) {
  48133. throw new Error("Cannot resolve a DOM point from Slate point: ".concat(JSON.stringify(point)));
  48134. }
  48135. return domPoint;
  48136. },
  48137. /**
  48138. * Find a native DOM range from a Slate `range`.
  48139. */
  48140. toDOMRange(editor, range) {
  48141. var {
  48142. anchor,
  48143. focus
  48144. } = range;
  48145. var domAnchor = ReactEditor.toDOMPoint(editor, anchor);
  48146. var domFocus = dist$5.Range.isCollapsed(range) ? domAnchor : ReactEditor.toDOMPoint(editor, focus);
  48147. var domRange = window.document.createRange();
  48148. var start = dist$5.Range.isBackward(range) ? domFocus : domAnchor;
  48149. var end = dist$5.Range.isBackward(range) ? domAnchor : domFocus;
  48150. domRange.setStart(start[0], start[1]);
  48151. domRange.setEnd(end[0], end[1]);
  48152. return domRange;
  48153. },
  48154. /**
  48155. * Find a Slate node from a native DOM `element`.
  48156. */
  48157. toSlateNode(editor, domNode) {
  48158. var domEl = isDOMElement(domNode) ? domNode : domNode.parentElement;
  48159. if (domEl && !domEl.hasAttribute('data-slate-node')) {
  48160. domEl = domEl.closest("[data-slate-node]");
  48161. }
  48162. var node = domEl ? ELEMENT_TO_NODE.get(domEl) : null;
  48163. if (!node) {
  48164. throw new Error("Cannot resolve a Slate node from DOM node: ".concat(domEl));
  48165. }
  48166. return node;
  48167. },
  48168. /**
  48169. * Get the target range from a DOM `event`.
  48170. */
  48171. findEventRange(editor, event) {
  48172. if ('nativeEvent' in event) {
  48173. event = event.nativeEvent;
  48174. }
  48175. var {
  48176. clientX: x,
  48177. clientY: y,
  48178. target
  48179. } = event;
  48180. if (x == null || y == null) {
  48181. throw new Error("Cannot resolve a Slate range from a DOM event: ".concat(event));
  48182. }
  48183. var node = ReactEditor.toSlateNode(editor, event.target);
  48184. var path = ReactEditor.findPath(editor, node); // If the drop target is inside a void node, move it into either the
  48185. // next or previous node, depending on which side the `x` and `y`
  48186. // coordinates are closest to.
  48187. if (dist$5.Editor.isVoid(editor, node)) {
  48188. var rect = target.getBoundingClientRect();
  48189. var isPrev = editor.isInline(node) ? x - rect.left < rect.left + rect.width - x : y - rect.top < rect.top + rect.height - y;
  48190. var edge = dist$5.Editor.point(editor, path, {
  48191. edge: isPrev ? 'start' : 'end'
  48192. });
  48193. var point = isPrev ? dist$5.Editor.before(editor, edge) : dist$5.Editor.after(editor, edge);
  48194. if (point) {
  48195. var _range = dist$5.Editor.range(editor, point);
  48196. return _range;
  48197. }
  48198. } // Else resolve a range from the caret position where the drop occured.
  48199. var domRange;
  48200. var {
  48201. document
  48202. } = window; // COMPAT: In Firefox, `caretRangeFromPoint` doesn't exist. (2016/07/25)
  48203. if (document.caretRangeFromPoint) {
  48204. domRange = document.caretRangeFromPoint(x, y);
  48205. } else {
  48206. var position = document.caretPositionFromPoint(x, y);
  48207. if (position) {
  48208. domRange = document.createRange();
  48209. domRange.setStart(position.offsetNode, position.offset);
  48210. domRange.setEnd(position.offsetNode, position.offset);
  48211. }
  48212. }
  48213. if (!domRange) {
  48214. throw new Error("Cannot resolve a Slate range from a DOM event: ".concat(event));
  48215. } // Resolve a Slate range from the DOM range.
  48216. var range = ReactEditor.toSlateRange(editor, domRange);
  48217. return range;
  48218. },
  48219. /**
  48220. * Find a Slate point from a DOM selection's `domNode` and `domOffset`.
  48221. */
  48222. toSlatePoint(editor, domPoint) {
  48223. var [nearestNode, nearestOffset] = normalizeDOMPoint(domPoint);
  48224. var parentNode = nearestNode.parentNode;
  48225. var textNode = null;
  48226. var offset = 0;
  48227. if (parentNode) {
  48228. var voidNode = parentNode.closest('[data-slate-void="true"]');
  48229. var leafNode = parentNode.closest('[data-slate-leaf]');
  48230. var domNode = null; // Calculate how far into the text node the `nearestNode` is, so that we
  48231. // can determine what the offset relative to the text node is.
  48232. if (leafNode) {
  48233. textNode = leafNode.closest('[data-slate-node="text"]');
  48234. var range = window.document.createRange();
  48235. range.setStart(textNode, 0);
  48236. range.setEnd(nearestNode, nearestOffset);
  48237. var contents = range.cloneContents();
  48238. var removals = [...contents.querySelectorAll('[data-slate-zero-width]'), ...contents.querySelectorAll('[contenteditable=false]')];
  48239. removals.forEach(el => {
  48240. el.parentNode.removeChild(el);
  48241. }); // COMPAT: Edge has a bug where Range.prototype.toString() will
  48242. // convert \n into \r\n. The bug causes a loop when slate-react
  48243. // attempts to reposition its cursor to match the native position. Use
  48244. // textContent.length instead.
  48245. // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10291116/
  48246. offset = contents.textContent.length;
  48247. domNode = textNode;
  48248. } else if (voidNode) {
  48249. // For void nodes, the element with the offset key will be a cousin, not an
  48250. // ancestor, so find it by going down from the nearest void parent.
  48251. leafNode = voidNode.querySelector('[data-slate-leaf]');
  48252. textNode = leafNode.closest('[data-slate-node="text"]');
  48253. domNode = leafNode;
  48254. offset = domNode.textContent.length;
  48255. } // COMPAT: If the parent node is a Slate zero-width space, editor is
  48256. // because the text node should have no characters. However, during IME
  48257. // composition the ASCII characters will be prepended to the zero-width
  48258. // space, so subtract 1 from the offset to account for the zero-width
  48259. // space character.
  48260. if (domNode && offset === domNode.textContent.length && parentNode.hasAttribute('data-slate-zero-width')) {
  48261. offset--;
  48262. }
  48263. }
  48264. if (!textNode) {
  48265. throw new Error("Cannot resolve a Slate point from DOM point: ".concat(domPoint));
  48266. } // COMPAT: If someone is clicking from one Slate editor into another,
  48267. // the select event fires twice, once for the old editor's `element`
  48268. // first, and then afterwards for the correct `element`. (2017/03/03)
  48269. var slateNode = ReactEditor.toSlateNode(editor, textNode);
  48270. var path = ReactEditor.findPath(editor, slateNode);
  48271. return {
  48272. path,
  48273. offset
  48274. };
  48275. },
  48276. /**
  48277. * Find a Slate range from a DOM range or selection.
  48278. */
  48279. toSlateRange(editor, domRange) {
  48280. var el = domRange instanceof Selection ? domRange.anchorNode : domRange.startContainer;
  48281. var anchorNode;
  48282. var anchorOffset;
  48283. var focusNode;
  48284. var focusOffset;
  48285. var isCollapsed;
  48286. if (el) {
  48287. if (domRange instanceof Selection) {
  48288. anchorNode = domRange.anchorNode;
  48289. anchorOffset = domRange.anchorOffset;
  48290. focusNode = domRange.focusNode;
  48291. focusOffset = domRange.focusOffset;
  48292. isCollapsed = domRange.isCollapsed;
  48293. } else {
  48294. anchorNode = domRange.startContainer;
  48295. anchorOffset = domRange.startOffset;
  48296. focusNode = domRange.endContainer;
  48297. focusOffset = domRange.endOffset;
  48298. isCollapsed = domRange.collapsed;
  48299. }
  48300. }
  48301. if (anchorNode == null || focusNode == null || anchorOffset == null || focusOffset == null) {
  48302. throw new Error("Cannot resolve a Slate range from DOM range: ".concat(domRange));
  48303. }
  48304. var anchor = ReactEditor.toSlatePoint(editor, [anchorNode, anchorOffset]);
  48305. var focus = isCollapsed ? anchor : ReactEditor.toSlatePoint(editor, [focusNode, focusOffset]);
  48306. return {
  48307. anchor,
  48308. focus
  48309. };
  48310. }
  48311. };
  48312. /**
  48313. * A React context for sharing the `focused` state of the editor.
  48314. */
  48315. var FocusedContext = React__default.createContext(false);
  48316. /**
  48317. * Get the current `focused` state of the editor.
  48318. */
  48319. var useFocused = () => {
  48320. return React__default.useContext(FocusedContext);
  48321. };
  48322. /**
  48323. * A wrapper around the provider to handle `onChange` events, because the editor
  48324. * is a mutable singleton so it won't ever register as "changed" otherwise.
  48325. */
  48326. const Slate = (props) => {
  48327. const { editor, children, onChange, value, ...rest } = props;
  48328. const [key, setKey] = React__default.useState(0);
  48329. const context = React__default.useMemo(() => {
  48330. editor.children = value;
  48331. Object.assign(editor, rest);
  48332. return [editor];
  48333. }, [key, value, ...Object.values(rest)]);
  48334. const onContextChange = React__default.useCallback(() => {
  48335. onChange(editor.children);
  48336. setKey(key + 1);
  48337. }, [key, onChange]);
  48338. EDITOR_TO_ON_CHANGE.set(editor, onContextChange);
  48339. return (React__default$1.createElement(SlateContext.Provider, { value: context },
  48340. React__default$1.createElement(EditorContext.Provider, { value: editor },
  48341. React__default$1.createElement(FocusedContext.Provider, { value: ReactEditor.isFocused(editor) }, children))));
  48342. };
  48343. /**
  48344. * `withReact` adds React and DOM specific behaviors to the editor.
  48345. */
  48346. var withReact = editor => {
  48347. var e = editor;
  48348. var {
  48349. apply,
  48350. onChange
  48351. } = e;
  48352. e.apply = op => {
  48353. var matches = [];
  48354. switch (op.type) {
  48355. case 'insert_text':
  48356. case 'remove_text':
  48357. case 'set_node':
  48358. {
  48359. for (var [node, path] of dist$5.Editor.levels(e, {
  48360. at: op.path
  48361. })) {
  48362. var key = ReactEditor.findKey(e, node);
  48363. matches.push([path, key]);
  48364. }
  48365. break;
  48366. }
  48367. case 'insert_node':
  48368. case 'remove_node':
  48369. case 'merge_node':
  48370. case 'split_node':
  48371. {
  48372. for (var [_node, _path] of dist$5.Editor.levels(e, {
  48373. at: dist$5.Path.parent(op.path)
  48374. })) {
  48375. var _key = ReactEditor.findKey(e, _node);
  48376. matches.push([_path, _key]);
  48377. }
  48378. break;
  48379. }
  48380. }
  48381. apply(op);
  48382. for (var [_path2, _key2] of matches) {
  48383. var [_node2] = dist$5.Editor.node(e, _path2);
  48384. NODE_TO_KEY.set(_node2, _key2);
  48385. }
  48386. };
  48387. e.insertData = data => {
  48388. var fragment = data.getData('application/x-slate-fragment');
  48389. if (fragment) {
  48390. var decoded = decodeURIComponent(window.atob(fragment));
  48391. var parsed = JSON.parse(decoded);
  48392. dist$5.Transforms.insertFragment(e, parsed);
  48393. return;
  48394. }
  48395. var text = data.getData('text/plain');
  48396. if (text) {
  48397. var lines = text.split('\n');
  48398. var split = false;
  48399. for (var line of lines) {
  48400. if (split) {
  48401. dist$5.Transforms.splitNodes(e);
  48402. }
  48403. dist$5.Transforms.insertText(e, line);
  48404. split = true;
  48405. }
  48406. }
  48407. };
  48408. e.onChange = () => {
  48409. // COMPAT: React doesn't batch `setState` hook calls, which means that the
  48410. // children and selection can get out of sync for one render pass. So we
  48411. // have to use this unstable API to ensure it batches them. (2019/12/03)
  48412. // https://github.com/facebook/react/issues/14259#issuecomment-439702367
  48413. ReactDOM.unstable_batchedUpdates(() => {
  48414. var onContextChange = EDITOR_TO_ON_CHANGE.get(e);
  48415. if (onContextChange) {
  48416. onContextChange();
  48417. }
  48418. onChange();
  48419. });
  48420. };
  48421. return e;
  48422. };
  48423. exports.DefaultElement = DefaultElement;
  48424. exports.DefaultLeaf = DefaultLeaf;
  48425. exports.Editable = Editable;
  48426. exports.ReactEditor = ReactEditor;
  48427. exports.Slate = Slate;
  48428. exports.useEditor = useEditor;
  48429. exports.useFocused = useFocused;
  48430. exports.useReadOnly = useReadOnly;
  48431. exports.useSelected = useSelected;
  48432. exports.useSlate = useSlate;
  48433. exports.withReact = withReact;
  48434. });
  48435. styleInject_es.unwrapExports(dist$6);
  48436. var dist_1$4 = dist$6.DefaultElement;
  48437. var dist_2$4 = dist$6.DefaultLeaf;
  48438. var dist_3$4 = dist$6.Editable;
  48439. var dist_4$2 = dist$6.ReactEditor;
  48440. var dist_5$2 = dist$6.Slate;
  48441. var dist_6$2 = dist$6.useEditor;
  48442. var dist_7$1 = dist$6.useFocused;
  48443. var dist_8$1 = dist$6.useReadOnly;
  48444. var dist_9$1 = dist$6.useSelected;
  48445. var dist_10$1 = dist$6.useSlate;
  48446. var dist_11$1 = dist$6.withReact;
  48447. var RichTextEditorForSlate = function RichTextEditorForSlate() {
  48448. var editor = React.useMemo(function () {
  48449. return dist_11$1(dist_15());
  48450. }, []);
  48451. var _useState = React.useState([{
  48452. type: 'paragraph',
  48453. children: [{
  48454. text: 'A line of text in a paragraph.'
  48455. }]
  48456. }]),
  48457. _useState2 = styleInject_es._slicedToArray(_useState, 2),
  48458. value = _useState2[0],
  48459. setValue = _useState2[1];
  48460. return (// Add the editable component inside the context.
  48461. React__default.createElement(dist_5$2, {
  48462. editor: editor,
  48463. value: value,
  48464. onChange: function onChange(value) {
  48465. console.log('value: ', value);
  48466. setValue(value);
  48467. }
  48468. }, React__default.createElement(dist_3$4, null))
  48469. );
  48470. }; // class RichTextEditorForSlate extends React.Component<RichTextEditorForSlateProps, RichTextEditorForSlateState> {
  48471. exports.BraftEditor = BarftEditorPage;
  48472. exports.RichTextEditor = RichTextEditor;
  48473. exports.RichTextEditorForSlate = RichTextEditorForSlate;
  48474. //# sourceMappingURL=index.js.map