Keine Beschreibung

Draft-ec3417b2.js 565KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690
  1. import { c as createCommonjsModule, j as commonjsGlobal } from './_commonjsHelpers-aeb41076.js';
  2. import 'react';
  3. import { R as React, r as require$$3 } from './_react-dom_commonjs-external-d3012e04.js';
  4. import 'react-dom';
  5. /*
  6. object-assign
  7. (c) Sindre Sorhus
  8. @license MIT
  9. */
  10. /* eslint-disable no-unused-vars */
  11. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  12. var hasOwnProperty = Object.prototype.hasOwnProperty;
  13. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  14. function toObject(val) {
  15. if (val === null || val === undefined) {
  16. throw new TypeError('Object.assign cannot be called with null or undefined');
  17. }
  18. return Object(val);
  19. }
  20. function shouldUseNative() {
  21. try {
  22. if (!Object.assign) {
  23. return false;
  24. }
  25. // Detect buggy property enumeration order in older V8 versions.
  26. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  27. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  28. test1[5] = 'de';
  29. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  30. return false;
  31. }
  32. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  33. var test2 = {};
  34. for (var i = 0; i < 10; i++) {
  35. test2['_' + String.fromCharCode(i)] = i;
  36. }
  37. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  38. return test2[n];
  39. });
  40. if (order2.join('') !== '0123456789') {
  41. return false;
  42. }
  43. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  44. var test3 = {};
  45. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  46. test3[letter] = letter;
  47. });
  48. if (Object.keys(Object.assign({}, test3)).join('') !==
  49. 'abcdefghijklmnopqrst') {
  50. return false;
  51. }
  52. return true;
  53. } catch (err) {
  54. // We don't expect any of the above to throw, but better to be safe.
  55. return false;
  56. }
  57. }
  58. var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
  59. var from;
  60. var to = toObject(target);
  61. var symbols;
  62. for (var s = 1; s < arguments.length; s++) {
  63. from = Object(arguments[s]);
  64. for (var key in from) {
  65. if (hasOwnProperty.call(from, key)) {
  66. to[key] = from[key];
  67. }
  68. }
  69. if (getOwnPropertySymbols) {
  70. symbols = getOwnPropertySymbols(from);
  71. for (var i = 0; i < symbols.length; i++) {
  72. if (propIsEnumerable.call(from, symbols[i])) {
  73. to[symbols[i]] = from[symbols[i]];
  74. }
  75. }
  76. }
  77. }
  78. return to;
  79. };
  80. var immutable = createCommonjsModule(function (module, exports) {
  81. /**
  82. * Copyright (c) 2014-2015, Facebook, Inc.
  83. * All rights reserved.
  84. *
  85. * This source code is licensed under the BSD-style license found in the
  86. * LICENSE file in the root directory of this source tree. An additional grant
  87. * of patent rights can be found in the PATENTS file in the same directory.
  88. */
  89. (function (global, factory) {
  90. module.exports = factory() ;
  91. }(commonjsGlobal, function () {var SLICE$0 = Array.prototype.slice;
  92. function createClass(ctor, superClass) {
  93. if (superClass) {
  94. ctor.prototype = Object.create(superClass.prototype);
  95. }
  96. ctor.prototype.constructor = ctor;
  97. }
  98. function Iterable(value) {
  99. return isIterable(value) ? value : Seq(value);
  100. }
  101. createClass(KeyedIterable, Iterable);
  102. function KeyedIterable(value) {
  103. return isKeyed(value) ? value : KeyedSeq(value);
  104. }
  105. createClass(IndexedIterable, Iterable);
  106. function IndexedIterable(value) {
  107. return isIndexed(value) ? value : IndexedSeq(value);
  108. }
  109. createClass(SetIterable, Iterable);
  110. function SetIterable(value) {
  111. return isIterable(value) && !isAssociative(value) ? value : SetSeq(value);
  112. }
  113. function isIterable(maybeIterable) {
  114. return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]);
  115. }
  116. function isKeyed(maybeKeyed) {
  117. return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
  118. }
  119. function isIndexed(maybeIndexed) {
  120. return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
  121. }
  122. function isAssociative(maybeAssociative) {
  123. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  124. }
  125. function isOrdered(maybeOrdered) {
  126. return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
  127. }
  128. Iterable.isIterable = isIterable;
  129. Iterable.isKeyed = isKeyed;
  130. Iterable.isIndexed = isIndexed;
  131. Iterable.isAssociative = isAssociative;
  132. Iterable.isOrdered = isOrdered;
  133. Iterable.Keyed = KeyedIterable;
  134. Iterable.Indexed = IndexedIterable;
  135. Iterable.Set = SetIterable;
  136. var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  137. var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  138. var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  139. var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  140. // Used for setting prototype methods that IE8 chokes on.
  141. var DELETE = 'delete';
  142. // Constants describing the size of trie nodes.
  143. var SHIFT = 5; // Resulted in best performance after ______?
  144. var SIZE = 1 << SHIFT;
  145. var MASK = SIZE - 1;
  146. // A consistent shared value representing "not set" which equals nothing other
  147. // than itself, and nothing that could be provided externally.
  148. var NOT_SET = {};
  149. // Boolean references, Rough equivalent of `bool &`.
  150. var CHANGE_LENGTH = { value: false };
  151. var DID_ALTER = { value: false };
  152. function MakeRef(ref) {
  153. ref.value = false;
  154. return ref;
  155. }
  156. function SetRef(ref) {
  157. ref && (ref.value = true);
  158. }
  159. // A function which returns a value representing an "owner" for transient writes
  160. // to tries. The return value will only ever equal itself, and will not equal
  161. // the return of any subsequent call of this function.
  162. function OwnerID() {}
  163. // http://jsperf.com/copy-array-inline
  164. function arrCopy(arr, offset) {
  165. offset = offset || 0;
  166. var len = Math.max(0, arr.length - offset);
  167. var newArr = new Array(len);
  168. for (var ii = 0; ii < len; ii++) {
  169. newArr[ii] = arr[ii + offset];
  170. }
  171. return newArr;
  172. }
  173. function ensureSize(iter) {
  174. if (iter.size === undefined) {
  175. iter.size = iter.__iterate(returnTrue);
  176. }
  177. return iter.size;
  178. }
  179. function wrapIndex(iter, index) {
  180. // This implements "is array index" which the ECMAString spec defines as:
  181. //
  182. // A String property name P is an array index if and only if
  183. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  184. // to 2^32−1.
  185. //
  186. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  187. if (typeof index !== 'number') {
  188. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  189. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  190. return NaN;
  191. }
  192. index = uint32Index;
  193. }
  194. return index < 0 ? ensureSize(iter) + index : index;
  195. }
  196. function returnTrue() {
  197. return true;
  198. }
  199. function wholeSlice(begin, end, size) {
  200. return (begin === 0 || (size !== undefined && begin <= -size)) &&
  201. (end === undefined || (size !== undefined && end >= size));
  202. }
  203. function resolveBegin(begin, size) {
  204. return resolveIndex(begin, size, 0);
  205. }
  206. function resolveEnd(end, size) {
  207. return resolveIndex(end, size, size);
  208. }
  209. function resolveIndex(index, size, defaultIndex) {
  210. return index === undefined ?
  211. defaultIndex :
  212. index < 0 ?
  213. Math.max(0, size + index) :
  214. size === undefined ?
  215. index :
  216. Math.min(size, index);
  217. }
  218. /* global Symbol */
  219. var ITERATE_KEYS = 0;
  220. var ITERATE_VALUES = 1;
  221. var ITERATE_ENTRIES = 2;
  222. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  223. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  224. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  225. function Iterator(next) {
  226. this.next = next;
  227. }
  228. Iterator.prototype.toString = function() {
  229. return '[Iterator]';
  230. };
  231. Iterator.KEYS = ITERATE_KEYS;
  232. Iterator.VALUES = ITERATE_VALUES;
  233. Iterator.ENTRIES = ITERATE_ENTRIES;
  234. Iterator.prototype.inspect =
  235. Iterator.prototype.toSource = function () { return this.toString(); };
  236. Iterator.prototype[ITERATOR_SYMBOL] = function () {
  237. return this;
  238. };
  239. function iteratorValue(type, k, v, iteratorResult) {
  240. var value = type === 0 ? k : type === 1 ? v : [k, v];
  241. iteratorResult ? (iteratorResult.value = value) : (iteratorResult = {
  242. value: value, done: false
  243. });
  244. return iteratorResult;
  245. }
  246. function iteratorDone() {
  247. return { value: undefined, done: true };
  248. }
  249. function hasIterator(maybeIterable) {
  250. return !!getIteratorFn(maybeIterable);
  251. }
  252. function isIterator(maybeIterator) {
  253. return maybeIterator && typeof maybeIterator.next === 'function';
  254. }
  255. function getIterator(iterable) {
  256. var iteratorFn = getIteratorFn(iterable);
  257. return iteratorFn && iteratorFn.call(iterable);
  258. }
  259. function getIteratorFn(iterable) {
  260. var iteratorFn = iterable && (
  261. (REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  262. iterable[FAUX_ITERATOR_SYMBOL]
  263. );
  264. if (typeof iteratorFn === 'function') {
  265. return iteratorFn;
  266. }
  267. }
  268. function isArrayLike(value) {
  269. return value && typeof value.length === 'number';
  270. }
  271. createClass(Seq, Iterable);
  272. function Seq(value) {
  273. return value === null || value === undefined ? emptySequence() :
  274. isIterable(value) ? value.toSeq() : seqFromValue(value);
  275. }
  276. Seq.of = function(/*...values*/) {
  277. return Seq(arguments);
  278. };
  279. Seq.prototype.toSeq = function() {
  280. return this;
  281. };
  282. Seq.prototype.toString = function() {
  283. return this.__toString('Seq {', '}');
  284. };
  285. Seq.prototype.cacheResult = function() {
  286. if (!this._cache && this.__iterateUncached) {
  287. this._cache = this.entrySeq().toArray();
  288. this.size = this._cache.length;
  289. }
  290. return this;
  291. };
  292. // abstract __iterateUncached(fn, reverse)
  293. Seq.prototype.__iterate = function(fn, reverse) {
  294. return seqIterate(this, fn, reverse, true);
  295. };
  296. // abstract __iteratorUncached(type, reverse)
  297. Seq.prototype.__iterator = function(type, reverse) {
  298. return seqIterator(this, type, reverse, true);
  299. };
  300. createClass(KeyedSeq, Seq);
  301. function KeyedSeq(value) {
  302. return value === null || value === undefined ?
  303. emptySequence().toKeyedSeq() :
  304. isIterable(value) ?
  305. (isKeyed(value) ? value.toSeq() : value.fromEntrySeq()) :
  306. keyedSeqFromValue(value);
  307. }
  308. KeyedSeq.prototype.toKeyedSeq = function() {
  309. return this;
  310. };
  311. createClass(IndexedSeq, Seq);
  312. function IndexedSeq(value) {
  313. return value === null || value === undefined ? emptySequence() :
  314. !isIterable(value) ? indexedSeqFromValue(value) :
  315. isKeyed(value) ? value.entrySeq() : value.toIndexedSeq();
  316. }
  317. IndexedSeq.of = function(/*...values*/) {
  318. return IndexedSeq(arguments);
  319. };
  320. IndexedSeq.prototype.toIndexedSeq = function() {
  321. return this;
  322. };
  323. IndexedSeq.prototype.toString = function() {
  324. return this.__toString('Seq [', ']');
  325. };
  326. IndexedSeq.prototype.__iterate = function(fn, reverse) {
  327. return seqIterate(this, fn, reverse, false);
  328. };
  329. IndexedSeq.prototype.__iterator = function(type, reverse) {
  330. return seqIterator(this, type, reverse, false);
  331. };
  332. createClass(SetSeq, Seq);
  333. function SetSeq(value) {
  334. return (
  335. value === null || value === undefined ? emptySequence() :
  336. !isIterable(value) ? indexedSeqFromValue(value) :
  337. isKeyed(value) ? value.entrySeq() : value
  338. ).toSetSeq();
  339. }
  340. SetSeq.of = function(/*...values*/) {
  341. return SetSeq(arguments);
  342. };
  343. SetSeq.prototype.toSetSeq = function() {
  344. return this;
  345. };
  346. Seq.isSeq = isSeq;
  347. Seq.Keyed = KeyedSeq;
  348. Seq.Set = SetSeq;
  349. Seq.Indexed = IndexedSeq;
  350. var IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
  351. Seq.prototype[IS_SEQ_SENTINEL] = true;
  352. createClass(ArraySeq, IndexedSeq);
  353. function ArraySeq(array) {
  354. this._array = array;
  355. this.size = array.length;
  356. }
  357. ArraySeq.prototype.get = function(index, notSetValue) {
  358. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  359. };
  360. ArraySeq.prototype.__iterate = function(fn, reverse) {
  361. var array = this._array;
  362. var maxIndex = array.length - 1;
  363. for (var ii = 0; ii <= maxIndex; ii++) {
  364. if (fn(array[reverse ? maxIndex - ii : ii], ii, this) === false) {
  365. return ii + 1;
  366. }
  367. }
  368. return ii;
  369. };
  370. ArraySeq.prototype.__iterator = function(type, reverse) {
  371. var array = this._array;
  372. var maxIndex = array.length - 1;
  373. var ii = 0;
  374. return new Iterator(function()
  375. {return ii > maxIndex ?
  376. iteratorDone() :
  377. iteratorValue(type, ii, array[reverse ? maxIndex - ii++ : ii++])}
  378. );
  379. };
  380. createClass(ObjectSeq, KeyedSeq);
  381. function ObjectSeq(object) {
  382. var keys = Object.keys(object);
  383. this._object = object;
  384. this._keys = keys;
  385. this.size = keys.length;
  386. }
  387. ObjectSeq.prototype.get = function(key, notSetValue) {
  388. if (notSetValue !== undefined && !this.has(key)) {
  389. return notSetValue;
  390. }
  391. return this._object[key];
  392. };
  393. ObjectSeq.prototype.has = function(key) {
  394. return this._object.hasOwnProperty(key);
  395. };
  396. ObjectSeq.prototype.__iterate = function(fn, reverse) {
  397. var object = this._object;
  398. var keys = this._keys;
  399. var maxIndex = keys.length - 1;
  400. for (var ii = 0; ii <= maxIndex; ii++) {
  401. var key = keys[reverse ? maxIndex - ii : ii];
  402. if (fn(object[key], key, this) === false) {
  403. return ii + 1;
  404. }
  405. }
  406. return ii;
  407. };
  408. ObjectSeq.prototype.__iterator = function(type, reverse) {
  409. var object = this._object;
  410. var keys = this._keys;
  411. var maxIndex = keys.length - 1;
  412. var ii = 0;
  413. return new Iterator(function() {
  414. var key = keys[reverse ? maxIndex - ii : ii];
  415. return ii++ > maxIndex ?
  416. iteratorDone() :
  417. iteratorValue(type, key, object[key]);
  418. });
  419. };
  420. ObjectSeq.prototype[IS_ORDERED_SENTINEL] = true;
  421. createClass(IterableSeq, IndexedSeq);
  422. function IterableSeq(iterable) {
  423. this._iterable = iterable;
  424. this.size = iterable.length || iterable.size;
  425. }
  426. IterableSeq.prototype.__iterateUncached = function(fn, reverse) {
  427. if (reverse) {
  428. return this.cacheResult().__iterate(fn, reverse);
  429. }
  430. var iterable = this._iterable;
  431. var iterator = getIterator(iterable);
  432. var iterations = 0;
  433. if (isIterator(iterator)) {
  434. var step;
  435. while (!(step = iterator.next()).done) {
  436. if (fn(step.value, iterations++, this) === false) {
  437. break;
  438. }
  439. }
  440. }
  441. return iterations;
  442. };
  443. IterableSeq.prototype.__iteratorUncached = function(type, reverse) {
  444. if (reverse) {
  445. return this.cacheResult().__iterator(type, reverse);
  446. }
  447. var iterable = this._iterable;
  448. var iterator = getIterator(iterable);
  449. if (!isIterator(iterator)) {
  450. return new Iterator(iteratorDone);
  451. }
  452. var iterations = 0;
  453. return new Iterator(function() {
  454. var step = iterator.next();
  455. return step.done ? step : iteratorValue(type, iterations++, step.value);
  456. });
  457. };
  458. createClass(IteratorSeq, IndexedSeq);
  459. function IteratorSeq(iterator) {
  460. this._iterator = iterator;
  461. this._iteratorCache = [];
  462. }
  463. IteratorSeq.prototype.__iterateUncached = function(fn, reverse) {
  464. if (reverse) {
  465. return this.cacheResult().__iterate(fn, reverse);
  466. }
  467. var iterator = this._iterator;
  468. var cache = this._iteratorCache;
  469. var iterations = 0;
  470. while (iterations < cache.length) {
  471. if (fn(cache[iterations], iterations++, this) === false) {
  472. return iterations;
  473. }
  474. }
  475. var step;
  476. while (!(step = iterator.next()).done) {
  477. var val = step.value;
  478. cache[iterations] = val;
  479. if (fn(val, iterations++, this) === false) {
  480. break;
  481. }
  482. }
  483. return iterations;
  484. };
  485. IteratorSeq.prototype.__iteratorUncached = function(type, reverse) {
  486. if (reverse) {
  487. return this.cacheResult().__iterator(type, reverse);
  488. }
  489. var iterator = this._iterator;
  490. var cache = this._iteratorCache;
  491. var iterations = 0;
  492. return new Iterator(function() {
  493. if (iterations >= cache.length) {
  494. var step = iterator.next();
  495. if (step.done) {
  496. return step;
  497. }
  498. cache[iterations] = step.value;
  499. }
  500. return iteratorValue(type, iterations, cache[iterations++]);
  501. });
  502. };
  503. // # pragma Helper functions
  504. function isSeq(maybeSeq) {
  505. return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]);
  506. }
  507. var EMPTY_SEQ;
  508. function emptySequence() {
  509. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  510. }
  511. function keyedSeqFromValue(value) {
  512. var seq =
  513. Array.isArray(value) ? new ArraySeq(value).fromEntrySeq() :
  514. isIterator(value) ? new IteratorSeq(value).fromEntrySeq() :
  515. hasIterator(value) ? new IterableSeq(value).fromEntrySeq() :
  516. typeof value === 'object' ? new ObjectSeq(value) :
  517. undefined;
  518. if (!seq) {
  519. throw new TypeError(
  520. 'Expected Array or iterable object of [k, v] entries, '+
  521. 'or keyed object: ' + value
  522. );
  523. }
  524. return seq;
  525. }
  526. function indexedSeqFromValue(value) {
  527. var seq = maybeIndexedSeqFromValue(value);
  528. if (!seq) {
  529. throw new TypeError(
  530. 'Expected Array or iterable object of values: ' + value
  531. );
  532. }
  533. return seq;
  534. }
  535. function seqFromValue(value) {
  536. var seq = maybeIndexedSeqFromValue(value) ||
  537. (typeof value === 'object' && new ObjectSeq(value));
  538. if (!seq) {
  539. throw new TypeError(
  540. 'Expected Array or iterable object of values, or keyed object: ' + value
  541. );
  542. }
  543. return seq;
  544. }
  545. function maybeIndexedSeqFromValue(value) {
  546. return (
  547. isArrayLike(value) ? new ArraySeq(value) :
  548. isIterator(value) ? new IteratorSeq(value) :
  549. hasIterator(value) ? new IterableSeq(value) :
  550. undefined
  551. );
  552. }
  553. function seqIterate(seq, fn, reverse, useKeys) {
  554. var cache = seq._cache;
  555. if (cache) {
  556. var maxIndex = cache.length - 1;
  557. for (var ii = 0; ii <= maxIndex; ii++) {
  558. var entry = cache[reverse ? maxIndex - ii : ii];
  559. if (fn(entry[1], useKeys ? entry[0] : ii, seq) === false) {
  560. return ii + 1;
  561. }
  562. }
  563. return ii;
  564. }
  565. return seq.__iterateUncached(fn, reverse);
  566. }
  567. function seqIterator(seq, type, reverse, useKeys) {
  568. var cache = seq._cache;
  569. if (cache) {
  570. var maxIndex = cache.length - 1;
  571. var ii = 0;
  572. return new Iterator(function() {
  573. var entry = cache[reverse ? maxIndex - ii : ii];
  574. return ii++ > maxIndex ?
  575. iteratorDone() :
  576. iteratorValue(type, useKeys ? entry[0] : ii - 1, entry[1]);
  577. });
  578. }
  579. return seq.__iteratorUncached(type, reverse);
  580. }
  581. function fromJS(json, converter) {
  582. return converter ?
  583. fromJSWith(converter, json, '', {'': json}) :
  584. fromJSDefault(json);
  585. }
  586. function fromJSWith(converter, json, key, parentJSON) {
  587. if (Array.isArray(json)) {
  588. return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  589. }
  590. if (isPlainObj(json)) {
  591. return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  592. }
  593. return json;
  594. }
  595. function fromJSDefault(json) {
  596. if (Array.isArray(json)) {
  597. return IndexedSeq(json).map(fromJSDefault).toList();
  598. }
  599. if (isPlainObj(json)) {
  600. return KeyedSeq(json).map(fromJSDefault).toMap();
  601. }
  602. return json;
  603. }
  604. function isPlainObj(value) {
  605. return value && (value.constructor === Object || value.constructor === undefined);
  606. }
  607. /**
  608. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  609. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  610. *
  611. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  612. * value, which is different from the algorithm described by
  613. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  614. *
  615. * This is extended further to allow Objects to describe the values they
  616. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  617. *
  618. * Note: because of this extension, the key equality of Immutable.Map and the
  619. * value equality of Immutable.Set will differ from ES6 Map and Set.
  620. *
  621. * ### Defining custom values
  622. *
  623. * The easiest way to describe the value an object represents is by implementing
  624. * `valueOf`. For example, `Date` represents a value by returning a unix
  625. * timestamp for `valueOf`:
  626. *
  627. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  628. * var date2 = new Date(1234567890000);
  629. * date1.valueOf(); // 1234567890000
  630. * assert( date1 !== date2 );
  631. * assert( Immutable.is( date1, date2 ) );
  632. *
  633. * Note: overriding `valueOf` may have other implications if you use this object
  634. * where JavaScript expects a primitive, such as implicit string coercion.
  635. *
  636. * For more complex types, especially collections, implementing `valueOf` may
  637. * not be performant. An alternative is to implement `equals` and `hashCode`.
  638. *
  639. * `equals` takes another object, presumably of similar type, and returns true
  640. * if the it is equal. Equality is symmetrical, so the same result should be
  641. * returned if this and the argument are flipped.
  642. *
  643. * assert( a.equals(b) === b.equals(a) );
  644. *
  645. * `hashCode` returns a 32bit integer number representing the object which will
  646. * be used to determine how to store the value object in a Map or Set. You must
  647. * provide both or neither methods, one must not exist without the other.
  648. *
  649. * Also, an important relationship between these methods must be upheld: if two
  650. * values are equal, they *must* return the same hashCode. If the values are not
  651. * equal, they might have the same hashCode; this is called a hash collision,
  652. * and while undesirable for performance reasons, it is acceptable.
  653. *
  654. * if (a.equals(b)) {
  655. * assert( a.hashCode() === b.hashCode() );
  656. * }
  657. *
  658. * All Immutable collections implement `equals` and `hashCode`.
  659. *
  660. */
  661. function is(valueA, valueB) {
  662. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  663. return true;
  664. }
  665. if (!valueA || !valueB) {
  666. return false;
  667. }
  668. if (typeof valueA.valueOf === 'function' &&
  669. typeof valueB.valueOf === 'function') {
  670. valueA = valueA.valueOf();
  671. valueB = valueB.valueOf();
  672. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  673. return true;
  674. }
  675. if (!valueA || !valueB) {
  676. return false;
  677. }
  678. }
  679. if (typeof valueA.equals === 'function' &&
  680. typeof valueB.equals === 'function' &&
  681. valueA.equals(valueB)) {
  682. return true;
  683. }
  684. return false;
  685. }
  686. function deepEqual(a, b) {
  687. if (a === b) {
  688. return true;
  689. }
  690. if (
  691. !isIterable(b) ||
  692. a.size !== undefined && b.size !== undefined && a.size !== b.size ||
  693. a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
  694. isKeyed(a) !== isKeyed(b) ||
  695. isIndexed(a) !== isIndexed(b) ||
  696. isOrdered(a) !== isOrdered(b)
  697. ) {
  698. return false;
  699. }
  700. if (a.size === 0 && b.size === 0) {
  701. return true;
  702. }
  703. var notAssociative = !isAssociative(a);
  704. if (isOrdered(a)) {
  705. var entries = a.entries();
  706. return b.every(function(v, k) {
  707. var entry = entries.next().value;
  708. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  709. }) && entries.next().done;
  710. }
  711. var flipped = false;
  712. if (a.size === undefined) {
  713. if (b.size === undefined) {
  714. if (typeof a.cacheResult === 'function') {
  715. a.cacheResult();
  716. }
  717. } else {
  718. flipped = true;
  719. var _ = a;
  720. a = b;
  721. b = _;
  722. }
  723. }
  724. var allEqual = true;
  725. var bSize = b.__iterate(function(v, k) {
  726. if (notAssociative ? !a.has(v) :
  727. flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
  728. allEqual = false;
  729. return false;
  730. }
  731. });
  732. return allEqual && a.size === bSize;
  733. }
  734. createClass(Repeat, IndexedSeq);
  735. function Repeat(value, times) {
  736. if (!(this instanceof Repeat)) {
  737. return new Repeat(value, times);
  738. }
  739. this._value = value;
  740. this.size = times === undefined ? Infinity : Math.max(0, times);
  741. if (this.size === 0) {
  742. if (EMPTY_REPEAT) {
  743. return EMPTY_REPEAT;
  744. }
  745. EMPTY_REPEAT = this;
  746. }
  747. }
  748. Repeat.prototype.toString = function() {
  749. if (this.size === 0) {
  750. return 'Repeat []';
  751. }
  752. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  753. };
  754. Repeat.prototype.get = function(index, notSetValue) {
  755. return this.has(index) ? this._value : notSetValue;
  756. };
  757. Repeat.prototype.includes = function(searchValue) {
  758. return is(this._value, searchValue);
  759. };
  760. Repeat.prototype.slice = function(begin, end) {
  761. var size = this.size;
  762. return wholeSlice(begin, end, size) ? this :
  763. new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
  764. };
  765. Repeat.prototype.reverse = function() {
  766. return this;
  767. };
  768. Repeat.prototype.indexOf = function(searchValue) {
  769. if (is(this._value, searchValue)) {
  770. return 0;
  771. }
  772. return -1;
  773. };
  774. Repeat.prototype.lastIndexOf = function(searchValue) {
  775. if (is(this._value, searchValue)) {
  776. return this.size;
  777. }
  778. return -1;
  779. };
  780. Repeat.prototype.__iterate = function(fn, reverse) {
  781. for (var ii = 0; ii < this.size; ii++) {
  782. if (fn(this._value, ii, this) === false) {
  783. return ii + 1;
  784. }
  785. }
  786. return ii;
  787. };
  788. Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
  789. var ii = 0;
  790. return new Iterator(function()
  791. {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
  792. );
  793. };
  794. Repeat.prototype.equals = function(other) {
  795. return other instanceof Repeat ?
  796. is(this._value, other._value) :
  797. deepEqual(other);
  798. };
  799. var EMPTY_REPEAT;
  800. function invariant(condition, error) {
  801. if (!condition) throw new Error(error);
  802. }
  803. createClass(Range, IndexedSeq);
  804. function Range(start, end, step) {
  805. if (!(this instanceof Range)) {
  806. return new Range(start, end, step);
  807. }
  808. invariant(step !== 0, 'Cannot step a Range by 0');
  809. start = start || 0;
  810. if (end === undefined) {
  811. end = Infinity;
  812. }
  813. step = step === undefined ? 1 : Math.abs(step);
  814. if (end < start) {
  815. step = -step;
  816. }
  817. this._start = start;
  818. this._end = end;
  819. this._step = step;
  820. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  821. if (this.size === 0) {
  822. if (EMPTY_RANGE) {
  823. return EMPTY_RANGE;
  824. }
  825. EMPTY_RANGE = this;
  826. }
  827. }
  828. Range.prototype.toString = function() {
  829. if (this.size === 0) {
  830. return 'Range []';
  831. }
  832. return 'Range [ ' +
  833. this._start + '...' + this._end +
  834. (this._step > 1 ? ' by ' + this._step : '') +
  835. ' ]';
  836. };
  837. Range.prototype.get = function(index, notSetValue) {
  838. return this.has(index) ?
  839. this._start + wrapIndex(this, index) * this._step :
  840. notSetValue;
  841. };
  842. Range.prototype.includes = function(searchValue) {
  843. var possibleIndex = (searchValue - this._start) / this._step;
  844. return possibleIndex >= 0 &&
  845. possibleIndex < this.size &&
  846. possibleIndex === Math.floor(possibleIndex);
  847. };
  848. Range.prototype.slice = function(begin, end) {
  849. if (wholeSlice(begin, end, this.size)) {
  850. return this;
  851. }
  852. begin = resolveBegin(begin, this.size);
  853. end = resolveEnd(end, this.size);
  854. if (end <= begin) {
  855. return new Range(0, 0);
  856. }
  857. return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
  858. };
  859. Range.prototype.indexOf = function(searchValue) {
  860. var offsetValue = searchValue - this._start;
  861. if (offsetValue % this._step === 0) {
  862. var index = offsetValue / this._step;
  863. if (index >= 0 && index < this.size) {
  864. return index
  865. }
  866. }
  867. return -1;
  868. };
  869. Range.prototype.lastIndexOf = function(searchValue) {
  870. return this.indexOf(searchValue);
  871. };
  872. Range.prototype.__iterate = function(fn, reverse) {
  873. var maxIndex = this.size - 1;
  874. var step = this._step;
  875. var value = reverse ? this._start + maxIndex * step : this._start;
  876. for (var ii = 0; ii <= maxIndex; ii++) {
  877. if (fn(value, ii, this) === false) {
  878. return ii + 1;
  879. }
  880. value += reverse ? -step : step;
  881. }
  882. return ii;
  883. };
  884. Range.prototype.__iterator = function(type, reverse) {
  885. var maxIndex = this.size - 1;
  886. var step = this._step;
  887. var value = reverse ? this._start + maxIndex * step : this._start;
  888. var ii = 0;
  889. return new Iterator(function() {
  890. var v = value;
  891. value += reverse ? -step : step;
  892. return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
  893. });
  894. };
  895. Range.prototype.equals = function(other) {
  896. return other instanceof Range ?
  897. this._start === other._start &&
  898. this._end === other._end &&
  899. this._step === other._step :
  900. deepEqual(this, other);
  901. };
  902. var EMPTY_RANGE;
  903. createClass(Collection, Iterable);
  904. function Collection() {
  905. throw TypeError('Abstract');
  906. }
  907. createClass(KeyedCollection, Collection);function KeyedCollection() {}
  908. createClass(IndexedCollection, Collection);function IndexedCollection() {}
  909. createClass(SetCollection, Collection);function SetCollection() {}
  910. Collection.Keyed = KeyedCollection;
  911. Collection.Indexed = IndexedCollection;
  912. Collection.Set = SetCollection;
  913. var imul =
  914. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
  915. Math.imul :
  916. function imul(a, b) {
  917. a = a | 0; // int
  918. b = b | 0; // int
  919. var c = a & 0xffff;
  920. var d = b & 0xffff;
  921. // Shift by 0 fixes the sign on the high part.
  922. return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int
  923. };
  924. // v8 has an optimization for storing 31-bit signed numbers.
  925. // Values which have either 00 or 11 as the high order bits qualify.
  926. // This function drops the highest order bit in a signed number, maintaining
  927. // the sign bit.
  928. function smi(i32) {
  929. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
  930. }
  931. function hash(o) {
  932. if (o === false || o === null || o === undefined) {
  933. return 0;
  934. }
  935. if (typeof o.valueOf === 'function') {
  936. o = o.valueOf();
  937. if (o === false || o === null || o === undefined) {
  938. return 0;
  939. }
  940. }
  941. if (o === true) {
  942. return 1;
  943. }
  944. var type = typeof o;
  945. if (type === 'number') {
  946. var h = o | 0;
  947. if (h !== o) {
  948. h ^= o * 0xFFFFFFFF;
  949. }
  950. while (o > 0xFFFFFFFF) {
  951. o /= 0xFFFFFFFF;
  952. h ^= o;
  953. }
  954. return smi(h);
  955. }
  956. if (type === 'string') {
  957. return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
  958. }
  959. if (typeof o.hashCode === 'function') {
  960. return o.hashCode();
  961. }
  962. if (type === 'object') {
  963. return hashJSObj(o);
  964. }
  965. if (typeof o.toString === 'function') {
  966. return hashString(o.toString());
  967. }
  968. throw new Error('Value type ' + type + ' cannot be hashed.');
  969. }
  970. function cachedHashString(string) {
  971. var hash = stringHashCache[string];
  972. if (hash === undefined) {
  973. hash = hashString(string);
  974. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  975. STRING_HASH_CACHE_SIZE = 0;
  976. stringHashCache = {};
  977. }
  978. STRING_HASH_CACHE_SIZE++;
  979. stringHashCache[string] = hash;
  980. }
  981. return hash;
  982. }
  983. // http://jsperf.com/hashing-strings
  984. function hashString(string) {
  985. // This is the hash from JVM
  986. // The hash code for a string is computed as
  987. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  988. // where s[i] is the ith character of the string and n is the length of
  989. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  990. // (exclusive) by dropping high bits.
  991. var hash = 0;
  992. for (var ii = 0; ii < string.length; ii++) {
  993. hash = 31 * hash + string.charCodeAt(ii) | 0;
  994. }
  995. return smi(hash);
  996. }
  997. function hashJSObj(obj) {
  998. var hash;
  999. if (usingWeakMap) {
  1000. hash = weakMap.get(obj);
  1001. if (hash !== undefined) {
  1002. return hash;
  1003. }
  1004. }
  1005. hash = obj[UID_HASH_KEY];
  1006. if (hash !== undefined) {
  1007. return hash;
  1008. }
  1009. if (!canDefineProperty) {
  1010. hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  1011. if (hash !== undefined) {
  1012. return hash;
  1013. }
  1014. hash = getIENodeHash(obj);
  1015. if (hash !== undefined) {
  1016. return hash;
  1017. }
  1018. }
  1019. hash = ++objHashUID;
  1020. if (objHashUID & 0x40000000) {
  1021. objHashUID = 0;
  1022. }
  1023. if (usingWeakMap) {
  1024. weakMap.set(obj, hash);
  1025. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  1026. throw new Error('Non-extensible objects are not allowed as keys.');
  1027. } else if (canDefineProperty) {
  1028. Object.defineProperty(obj, UID_HASH_KEY, {
  1029. 'enumerable': false,
  1030. 'configurable': false,
  1031. 'writable': false,
  1032. 'value': hash
  1033. });
  1034. } else if (obj.propertyIsEnumerable !== undefined &&
  1035. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
  1036. // Since we can't define a non-enumerable property on the object
  1037. // we'll hijack one of the less-used non-enumerable properties to
  1038. // save our hash on it. Since this is a function it will not show up in
  1039. // `JSON.stringify` which is what we want.
  1040. obj.propertyIsEnumerable = function() {
  1041. return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
  1042. };
  1043. obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
  1044. } else if (obj.nodeType !== undefined) {
  1045. // At this point we couldn't get the IE `uniqueID` to use as a hash
  1046. // and we couldn't use a non-enumerable property to exploit the
  1047. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  1048. // itself.
  1049. obj[UID_HASH_KEY] = hash;
  1050. } else {
  1051. throw new Error('Unable to set a non-enumerable property on object.');
  1052. }
  1053. return hash;
  1054. }
  1055. // Get references to ES5 object methods.
  1056. var isExtensible = Object.isExtensible;
  1057. // True if Object.defineProperty works as expected. IE8 fails this test.
  1058. var canDefineProperty = (function() {
  1059. try {
  1060. Object.defineProperty({}, '@', {});
  1061. return true;
  1062. } catch (e) {
  1063. return false;
  1064. }
  1065. }());
  1066. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  1067. // and avoid memory leaks from the IE cloneNode bug.
  1068. function getIENodeHash(node) {
  1069. if (node && node.nodeType > 0) {
  1070. switch (node.nodeType) {
  1071. case 1: // Element
  1072. return node.uniqueID;
  1073. case 9: // Document
  1074. return node.documentElement && node.documentElement.uniqueID;
  1075. }
  1076. }
  1077. }
  1078. // If possible, use a WeakMap.
  1079. var usingWeakMap = typeof WeakMap === 'function';
  1080. var weakMap;
  1081. if (usingWeakMap) {
  1082. weakMap = new WeakMap();
  1083. }
  1084. var objHashUID = 0;
  1085. var UID_HASH_KEY = '__immutablehash__';
  1086. if (typeof Symbol === 'function') {
  1087. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  1088. }
  1089. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  1090. var STRING_HASH_CACHE_MAX_SIZE = 255;
  1091. var STRING_HASH_CACHE_SIZE = 0;
  1092. var stringHashCache = {};
  1093. function assertNotInfinite(size) {
  1094. invariant(
  1095. size !== Infinity,
  1096. 'Cannot perform this action with an infinite size.'
  1097. );
  1098. }
  1099. createClass(Map, KeyedCollection);
  1100. // @pragma Construction
  1101. function Map(value) {
  1102. return value === null || value === undefined ? emptyMap() :
  1103. isMap(value) && !isOrdered(value) ? value :
  1104. emptyMap().withMutations(function(map ) {
  1105. var iter = KeyedIterable(value);
  1106. assertNotInfinite(iter.size);
  1107. iter.forEach(function(v, k) {return map.set(k, v)});
  1108. });
  1109. }
  1110. Map.prototype.toString = function() {
  1111. return this.__toString('Map {', '}');
  1112. };
  1113. // @pragma Access
  1114. Map.prototype.get = function(k, notSetValue) {
  1115. return this._root ?
  1116. this._root.get(0, undefined, k, notSetValue) :
  1117. notSetValue;
  1118. };
  1119. // @pragma Modification
  1120. Map.prototype.set = function(k, v) {
  1121. return updateMap(this, k, v);
  1122. };
  1123. Map.prototype.setIn = function(keyPath, v) {
  1124. return this.updateIn(keyPath, NOT_SET, function() {return v});
  1125. };
  1126. Map.prototype.remove = function(k) {
  1127. return updateMap(this, k, NOT_SET);
  1128. };
  1129. Map.prototype.deleteIn = function(keyPath) {
  1130. return this.updateIn(keyPath, function() {return NOT_SET});
  1131. };
  1132. Map.prototype.update = function(k, notSetValue, updater) {
  1133. return arguments.length === 1 ?
  1134. k(this) :
  1135. this.updateIn([k], notSetValue, updater);
  1136. };
  1137. Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
  1138. if (!updater) {
  1139. updater = notSetValue;
  1140. notSetValue = undefined;
  1141. }
  1142. var updatedValue = updateInDeepMap(
  1143. this,
  1144. forceIterator(keyPath),
  1145. notSetValue,
  1146. updater
  1147. );
  1148. return updatedValue === NOT_SET ? undefined : updatedValue;
  1149. };
  1150. Map.prototype.clear = function() {
  1151. if (this.size === 0) {
  1152. return this;
  1153. }
  1154. if (this.__ownerID) {
  1155. this.size = 0;
  1156. this._root = null;
  1157. this.__hash = undefined;
  1158. this.__altered = true;
  1159. return this;
  1160. }
  1161. return emptyMap();
  1162. };
  1163. // @pragma Composition
  1164. Map.prototype.merge = function(/*...iters*/) {
  1165. return mergeIntoMapWith(this, undefined, arguments);
  1166. };
  1167. Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1168. return mergeIntoMapWith(this, merger, iters);
  1169. };
  1170. Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  1171. return this.updateIn(
  1172. keyPath,
  1173. emptyMap(),
  1174. function(m ) {return typeof m.merge === 'function' ?
  1175. m.merge.apply(m, iters) :
  1176. iters[iters.length - 1]}
  1177. );
  1178. };
  1179. Map.prototype.mergeDeep = function(/*...iters*/) {
  1180. return mergeIntoMapWith(this, deepMerger, arguments);
  1181. };
  1182. Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1183. return mergeIntoMapWith(this, deepMergerWith(merger), iters);
  1184. };
  1185. Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  1186. return this.updateIn(
  1187. keyPath,
  1188. emptyMap(),
  1189. function(m ) {return typeof m.mergeDeep === 'function' ?
  1190. m.mergeDeep.apply(m, iters) :
  1191. iters[iters.length - 1]}
  1192. );
  1193. };
  1194. Map.prototype.sort = function(comparator) {
  1195. // Late binding
  1196. return OrderedMap(sortFactory(this, comparator));
  1197. };
  1198. Map.prototype.sortBy = function(mapper, comparator) {
  1199. // Late binding
  1200. return OrderedMap(sortFactory(this, comparator, mapper));
  1201. };
  1202. // @pragma Mutability
  1203. Map.prototype.withMutations = function(fn) {
  1204. var mutable = this.asMutable();
  1205. fn(mutable);
  1206. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  1207. };
  1208. Map.prototype.asMutable = function() {
  1209. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  1210. };
  1211. Map.prototype.asImmutable = function() {
  1212. return this.__ensureOwner();
  1213. };
  1214. Map.prototype.wasAltered = function() {
  1215. return this.__altered;
  1216. };
  1217. Map.prototype.__iterator = function(type, reverse) {
  1218. return new MapIterator(this, type, reverse);
  1219. };
  1220. Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  1221. var iterations = 0;
  1222. this._root && this._root.iterate(function(entry ) {
  1223. iterations++;
  1224. return fn(entry[1], entry[0], this$0);
  1225. }, reverse);
  1226. return iterations;
  1227. };
  1228. Map.prototype.__ensureOwner = function(ownerID) {
  1229. if (ownerID === this.__ownerID) {
  1230. return this;
  1231. }
  1232. if (!ownerID) {
  1233. this.__ownerID = ownerID;
  1234. this.__altered = false;
  1235. return this;
  1236. }
  1237. return makeMap(this.size, this._root, ownerID, this.__hash);
  1238. };
  1239. function isMap(maybeMap) {
  1240. return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
  1241. }
  1242. Map.isMap = isMap;
  1243. var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
  1244. var MapPrototype = Map.prototype;
  1245. MapPrototype[IS_MAP_SENTINEL] = true;
  1246. MapPrototype[DELETE] = MapPrototype.remove;
  1247. MapPrototype.removeIn = MapPrototype.deleteIn;
  1248. // #pragma Trie Nodes
  1249. function ArrayMapNode(ownerID, entries) {
  1250. this.ownerID = ownerID;
  1251. this.entries = entries;
  1252. }
  1253. ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1254. var entries = this.entries;
  1255. for (var ii = 0, len = entries.length; ii < len; ii++) {
  1256. if (is(key, entries[ii][0])) {
  1257. return entries[ii][1];
  1258. }
  1259. }
  1260. return notSetValue;
  1261. };
  1262. ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1263. var removed = value === NOT_SET;
  1264. var entries = this.entries;
  1265. var idx = 0;
  1266. for (var len = entries.length; idx < len; idx++) {
  1267. if (is(key, entries[idx][0])) {
  1268. break;
  1269. }
  1270. }
  1271. var exists = idx < len;
  1272. if (exists ? entries[idx][1] === value : removed) {
  1273. return this;
  1274. }
  1275. SetRef(didAlter);
  1276. (removed || !exists) && SetRef(didChangeSize);
  1277. if (removed && entries.length === 1) {
  1278. return; // undefined
  1279. }
  1280. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  1281. return createNodes(ownerID, entries, key, value);
  1282. }
  1283. var isEditable = ownerID && ownerID === this.ownerID;
  1284. var newEntries = isEditable ? entries : arrCopy(entries);
  1285. if (exists) {
  1286. if (removed) {
  1287. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  1288. } else {
  1289. newEntries[idx] = [key, value];
  1290. }
  1291. } else {
  1292. newEntries.push([key, value]);
  1293. }
  1294. if (isEditable) {
  1295. this.entries = newEntries;
  1296. return this;
  1297. }
  1298. return new ArrayMapNode(ownerID, newEntries);
  1299. };
  1300. function BitmapIndexedNode(ownerID, bitmap, nodes) {
  1301. this.ownerID = ownerID;
  1302. this.bitmap = bitmap;
  1303. this.nodes = nodes;
  1304. }
  1305. BitmapIndexedNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1306. if (keyHash === undefined) {
  1307. keyHash = hash(key);
  1308. }
  1309. var bit = (1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK));
  1310. var bitmap = this.bitmap;
  1311. return (bitmap & bit) === 0 ? notSetValue :
  1312. this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue);
  1313. };
  1314. BitmapIndexedNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1315. if (keyHash === undefined) {
  1316. keyHash = hash(key);
  1317. }
  1318. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1319. var bit = 1 << keyHashFrag;
  1320. var bitmap = this.bitmap;
  1321. var exists = (bitmap & bit) !== 0;
  1322. if (!exists && value === NOT_SET) {
  1323. return this;
  1324. }
  1325. var idx = popCount(bitmap & (bit - 1));
  1326. var nodes = this.nodes;
  1327. var node = exists ? nodes[idx] : undefined;
  1328. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  1329. if (newNode === node) {
  1330. return this;
  1331. }
  1332. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  1333. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  1334. }
  1335. if (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) {
  1336. return nodes[idx ^ 1];
  1337. }
  1338. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  1339. return newNode;
  1340. }
  1341. var isEditable = ownerID && ownerID === this.ownerID;
  1342. var newBitmap = exists ? newNode ? bitmap : bitmap ^ bit : bitmap | bit;
  1343. var newNodes = exists ? newNode ?
  1344. setIn(nodes, idx, newNode, isEditable) :
  1345. spliceOut(nodes, idx, isEditable) :
  1346. spliceIn(nodes, idx, newNode, isEditable);
  1347. if (isEditable) {
  1348. this.bitmap = newBitmap;
  1349. this.nodes = newNodes;
  1350. return this;
  1351. }
  1352. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  1353. };
  1354. function HashArrayMapNode(ownerID, count, nodes) {
  1355. this.ownerID = ownerID;
  1356. this.count = count;
  1357. this.nodes = nodes;
  1358. }
  1359. HashArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1360. if (keyHash === undefined) {
  1361. keyHash = hash(key);
  1362. }
  1363. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1364. var node = this.nodes[idx];
  1365. return node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue;
  1366. };
  1367. HashArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1368. if (keyHash === undefined) {
  1369. keyHash = hash(key);
  1370. }
  1371. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1372. var removed = value === NOT_SET;
  1373. var nodes = this.nodes;
  1374. var node = nodes[idx];
  1375. if (removed && !node) {
  1376. return this;
  1377. }
  1378. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  1379. if (newNode === node) {
  1380. return this;
  1381. }
  1382. var newCount = this.count;
  1383. if (!node) {
  1384. newCount++;
  1385. } else if (!newNode) {
  1386. newCount--;
  1387. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  1388. return packNodes(ownerID, nodes, newCount, idx);
  1389. }
  1390. }
  1391. var isEditable = ownerID && ownerID === this.ownerID;
  1392. var newNodes = setIn(nodes, idx, newNode, isEditable);
  1393. if (isEditable) {
  1394. this.count = newCount;
  1395. this.nodes = newNodes;
  1396. return this;
  1397. }
  1398. return new HashArrayMapNode(ownerID, newCount, newNodes);
  1399. };
  1400. function HashCollisionNode(ownerID, keyHash, entries) {
  1401. this.ownerID = ownerID;
  1402. this.keyHash = keyHash;
  1403. this.entries = entries;
  1404. }
  1405. HashCollisionNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1406. var entries = this.entries;
  1407. for (var ii = 0, len = entries.length; ii < len; ii++) {
  1408. if (is(key, entries[ii][0])) {
  1409. return entries[ii][1];
  1410. }
  1411. }
  1412. return notSetValue;
  1413. };
  1414. HashCollisionNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1415. if (keyHash === undefined) {
  1416. keyHash = hash(key);
  1417. }
  1418. var removed = value === NOT_SET;
  1419. if (keyHash !== this.keyHash) {
  1420. if (removed) {
  1421. return this;
  1422. }
  1423. SetRef(didAlter);
  1424. SetRef(didChangeSize);
  1425. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  1426. }
  1427. var entries = this.entries;
  1428. var idx = 0;
  1429. for (var len = entries.length; idx < len; idx++) {
  1430. if (is(key, entries[idx][0])) {
  1431. break;
  1432. }
  1433. }
  1434. var exists = idx < len;
  1435. if (exists ? entries[idx][1] === value : removed) {
  1436. return this;
  1437. }
  1438. SetRef(didAlter);
  1439. (removed || !exists) && SetRef(didChangeSize);
  1440. if (removed && len === 2) {
  1441. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  1442. }
  1443. var isEditable = ownerID && ownerID === this.ownerID;
  1444. var newEntries = isEditable ? entries : arrCopy(entries);
  1445. if (exists) {
  1446. if (removed) {
  1447. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  1448. } else {
  1449. newEntries[idx] = [key, value];
  1450. }
  1451. } else {
  1452. newEntries.push([key, value]);
  1453. }
  1454. if (isEditable) {
  1455. this.entries = newEntries;
  1456. return this;
  1457. }
  1458. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  1459. };
  1460. function ValueNode(ownerID, keyHash, entry) {
  1461. this.ownerID = ownerID;
  1462. this.keyHash = keyHash;
  1463. this.entry = entry;
  1464. }
  1465. ValueNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1466. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  1467. };
  1468. ValueNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1469. var removed = value === NOT_SET;
  1470. var keyMatch = is(key, this.entry[0]);
  1471. if (keyMatch ? value === this.entry[1] : removed) {
  1472. return this;
  1473. }
  1474. SetRef(didAlter);
  1475. if (removed) {
  1476. SetRef(didChangeSize);
  1477. return; // undefined
  1478. }
  1479. if (keyMatch) {
  1480. if (ownerID && ownerID === this.ownerID) {
  1481. this.entry[1] = value;
  1482. return this;
  1483. }
  1484. return new ValueNode(ownerID, this.keyHash, [key, value]);
  1485. }
  1486. SetRef(didChangeSize);
  1487. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  1488. };
  1489. // #pragma Iterators
  1490. ArrayMapNode.prototype.iterate =
  1491. HashCollisionNode.prototype.iterate = function (fn, reverse) {
  1492. var entries = this.entries;
  1493. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  1494. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  1495. return false;
  1496. }
  1497. }
  1498. };
  1499. BitmapIndexedNode.prototype.iterate =
  1500. HashArrayMapNode.prototype.iterate = function (fn, reverse) {
  1501. var nodes = this.nodes;
  1502. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  1503. var node = nodes[reverse ? maxIndex - ii : ii];
  1504. if (node && node.iterate(fn, reverse) === false) {
  1505. return false;
  1506. }
  1507. }
  1508. };
  1509. ValueNode.prototype.iterate = function (fn, reverse) {
  1510. return fn(this.entry);
  1511. };
  1512. createClass(MapIterator, Iterator);
  1513. function MapIterator(map, type, reverse) {
  1514. this._type = type;
  1515. this._reverse = reverse;
  1516. this._stack = map._root && mapIteratorFrame(map._root);
  1517. }
  1518. MapIterator.prototype.next = function() {
  1519. var type = this._type;
  1520. var stack = this._stack;
  1521. while (stack) {
  1522. var node = stack.node;
  1523. var index = stack.index++;
  1524. var maxIndex;
  1525. if (node.entry) {
  1526. if (index === 0) {
  1527. return mapIteratorValue(type, node.entry);
  1528. }
  1529. } else if (node.entries) {
  1530. maxIndex = node.entries.length - 1;
  1531. if (index <= maxIndex) {
  1532. return mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index]);
  1533. }
  1534. } else {
  1535. maxIndex = node.nodes.length - 1;
  1536. if (index <= maxIndex) {
  1537. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  1538. if (subNode) {
  1539. if (subNode.entry) {
  1540. return mapIteratorValue(type, subNode.entry);
  1541. }
  1542. stack = this._stack = mapIteratorFrame(subNode, stack);
  1543. }
  1544. continue;
  1545. }
  1546. }
  1547. stack = this._stack = this._stack.__prev;
  1548. }
  1549. return iteratorDone();
  1550. };
  1551. function mapIteratorValue(type, entry) {
  1552. return iteratorValue(type, entry[0], entry[1]);
  1553. }
  1554. function mapIteratorFrame(node, prev) {
  1555. return {
  1556. node: node,
  1557. index: 0,
  1558. __prev: prev
  1559. };
  1560. }
  1561. function makeMap(size, root, ownerID, hash) {
  1562. var map = Object.create(MapPrototype);
  1563. map.size = size;
  1564. map._root = root;
  1565. map.__ownerID = ownerID;
  1566. map.__hash = hash;
  1567. map.__altered = false;
  1568. return map;
  1569. }
  1570. var EMPTY_MAP;
  1571. function emptyMap() {
  1572. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  1573. }
  1574. function updateMap(map, k, v) {
  1575. var newRoot;
  1576. var newSize;
  1577. if (!map._root) {
  1578. if (v === NOT_SET) {
  1579. return map;
  1580. }
  1581. newSize = 1;
  1582. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  1583. } else {
  1584. var didChangeSize = MakeRef(CHANGE_LENGTH);
  1585. var didAlter = MakeRef(DID_ALTER);
  1586. newRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter);
  1587. if (!didAlter.value) {
  1588. return map;
  1589. }
  1590. newSize = map.size + (didChangeSize.value ? v === NOT_SET ? -1 : 1 : 0);
  1591. }
  1592. if (map.__ownerID) {
  1593. map.size = newSize;
  1594. map._root = newRoot;
  1595. map.__hash = undefined;
  1596. map.__altered = true;
  1597. return map;
  1598. }
  1599. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  1600. }
  1601. function updateNode(node, ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1602. if (!node) {
  1603. if (value === NOT_SET) {
  1604. return node;
  1605. }
  1606. SetRef(didAlter);
  1607. SetRef(didChangeSize);
  1608. return new ValueNode(ownerID, keyHash, [key, value]);
  1609. }
  1610. return node.update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter);
  1611. }
  1612. function isLeafNode(node) {
  1613. return node.constructor === ValueNode || node.constructor === HashCollisionNode;
  1614. }
  1615. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  1616. if (node.keyHash === keyHash) {
  1617. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  1618. }
  1619. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  1620. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1621. var newNode;
  1622. var nodes = idx1 === idx2 ?
  1623. [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)] :
  1624. ((newNode = new ValueNode(ownerID, keyHash, entry)), idx1 < idx2 ? [node, newNode] : [newNode, node]);
  1625. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  1626. }
  1627. function createNodes(ownerID, entries, key, value) {
  1628. if (!ownerID) {
  1629. ownerID = new OwnerID();
  1630. }
  1631. var node = new ValueNode(ownerID, hash(key), [key, value]);
  1632. for (var ii = 0; ii < entries.length; ii++) {
  1633. var entry = entries[ii];
  1634. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  1635. }
  1636. return node;
  1637. }
  1638. function packNodes(ownerID, nodes, count, excluding) {
  1639. var bitmap = 0;
  1640. var packedII = 0;
  1641. var packedNodes = new Array(count);
  1642. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  1643. var node = nodes[ii];
  1644. if (node !== undefined && ii !== excluding) {
  1645. bitmap |= bit;
  1646. packedNodes[packedII++] = node;
  1647. }
  1648. }
  1649. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  1650. }
  1651. function expandNodes(ownerID, nodes, bitmap, including, node) {
  1652. var count = 0;
  1653. var expandedNodes = new Array(SIZE);
  1654. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  1655. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  1656. }
  1657. expandedNodes[including] = node;
  1658. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  1659. }
  1660. function mergeIntoMapWith(map, merger, iterables) {
  1661. var iters = [];
  1662. for (var ii = 0; ii < iterables.length; ii++) {
  1663. var value = iterables[ii];
  1664. var iter = KeyedIterable(value);
  1665. if (!isIterable(value)) {
  1666. iter = iter.map(function(v ) {return fromJS(v)});
  1667. }
  1668. iters.push(iter);
  1669. }
  1670. return mergeIntoCollectionWith(map, merger, iters);
  1671. }
  1672. function deepMerger(existing, value, key) {
  1673. return existing && existing.mergeDeep && isIterable(value) ?
  1674. existing.mergeDeep(value) :
  1675. is(existing, value) ? existing : value;
  1676. }
  1677. function deepMergerWith(merger) {
  1678. return function(existing, value, key) {
  1679. if (existing && existing.mergeDeepWith && isIterable(value)) {
  1680. return existing.mergeDeepWith(merger, value);
  1681. }
  1682. var nextValue = merger(existing, value, key);
  1683. return is(existing, nextValue) ? existing : nextValue;
  1684. };
  1685. }
  1686. function mergeIntoCollectionWith(collection, merger, iters) {
  1687. iters = iters.filter(function(x ) {return x.size !== 0});
  1688. if (iters.length === 0) {
  1689. return collection;
  1690. }
  1691. if (collection.size === 0 && !collection.__ownerID && iters.length === 1) {
  1692. return collection.constructor(iters[0]);
  1693. }
  1694. return collection.withMutations(function(collection ) {
  1695. var mergeIntoMap = merger ?
  1696. function(value, key) {
  1697. collection.update(key, NOT_SET, function(existing )
  1698. {return existing === NOT_SET ? value : merger(existing, value, key)}
  1699. );
  1700. } :
  1701. function(value, key) {
  1702. collection.set(key, value);
  1703. };
  1704. for (var ii = 0; ii < iters.length; ii++) {
  1705. iters[ii].forEach(mergeIntoMap);
  1706. }
  1707. });
  1708. }
  1709. function updateInDeepMap(existing, keyPathIter, notSetValue, updater) {
  1710. var isNotSet = existing === NOT_SET;
  1711. var step = keyPathIter.next();
  1712. if (step.done) {
  1713. var existingValue = isNotSet ? notSetValue : existing;
  1714. var newValue = updater(existingValue);
  1715. return newValue === existingValue ? existing : newValue;
  1716. }
  1717. invariant(
  1718. isNotSet || (existing && existing.set),
  1719. 'invalid keyPath'
  1720. );
  1721. var key = step.value;
  1722. var nextExisting = isNotSet ? NOT_SET : existing.get(key, NOT_SET);
  1723. var nextUpdated = updateInDeepMap(
  1724. nextExisting,
  1725. keyPathIter,
  1726. notSetValue,
  1727. updater
  1728. );
  1729. return nextUpdated === nextExisting ? existing :
  1730. nextUpdated === NOT_SET ? existing.remove(key) :
  1731. (isNotSet ? emptyMap() : existing).set(key, nextUpdated);
  1732. }
  1733. function popCount(x) {
  1734. x = x - ((x >> 1) & 0x55555555);
  1735. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  1736. x = (x + (x >> 4)) & 0x0f0f0f0f;
  1737. x = x + (x >> 8);
  1738. x = x + (x >> 16);
  1739. return x & 0x7f;
  1740. }
  1741. function setIn(array, idx, val, canEdit) {
  1742. var newArray = canEdit ? array : arrCopy(array);
  1743. newArray[idx] = val;
  1744. return newArray;
  1745. }
  1746. function spliceIn(array, idx, val, canEdit) {
  1747. var newLen = array.length + 1;
  1748. if (canEdit && idx + 1 === newLen) {
  1749. array[idx] = val;
  1750. return array;
  1751. }
  1752. var newArray = new Array(newLen);
  1753. var after = 0;
  1754. for (var ii = 0; ii < newLen; ii++) {
  1755. if (ii === idx) {
  1756. newArray[ii] = val;
  1757. after = -1;
  1758. } else {
  1759. newArray[ii] = array[ii + after];
  1760. }
  1761. }
  1762. return newArray;
  1763. }
  1764. function spliceOut(array, idx, canEdit) {
  1765. var newLen = array.length - 1;
  1766. if (canEdit && idx === newLen) {
  1767. array.pop();
  1768. return array;
  1769. }
  1770. var newArray = new Array(newLen);
  1771. var after = 0;
  1772. for (var ii = 0; ii < newLen; ii++) {
  1773. if (ii === idx) {
  1774. after = 1;
  1775. }
  1776. newArray[ii] = array[ii + after];
  1777. }
  1778. return newArray;
  1779. }
  1780. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  1781. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  1782. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  1783. createClass(List, IndexedCollection);
  1784. // @pragma Construction
  1785. function List(value) {
  1786. var empty = emptyList();
  1787. if (value === null || value === undefined) {
  1788. return empty;
  1789. }
  1790. if (isList(value)) {
  1791. return value;
  1792. }
  1793. var iter = IndexedIterable(value);
  1794. var size = iter.size;
  1795. if (size === 0) {
  1796. return empty;
  1797. }
  1798. assertNotInfinite(size);
  1799. if (size > 0 && size < SIZE) {
  1800. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  1801. }
  1802. return empty.withMutations(function(list ) {
  1803. list.setSize(size);
  1804. iter.forEach(function(v, i) {return list.set(i, v)});
  1805. });
  1806. }
  1807. List.of = function(/*...values*/) {
  1808. return this(arguments);
  1809. };
  1810. List.prototype.toString = function() {
  1811. return this.__toString('List [', ']');
  1812. };
  1813. // @pragma Access
  1814. List.prototype.get = function(index, notSetValue) {
  1815. index = wrapIndex(this, index);
  1816. if (index >= 0 && index < this.size) {
  1817. index += this._origin;
  1818. var node = listNodeFor(this, index);
  1819. return node && node.array[index & MASK];
  1820. }
  1821. return notSetValue;
  1822. };
  1823. // @pragma Modification
  1824. List.prototype.set = function(index, value) {
  1825. return updateList(this, index, value);
  1826. };
  1827. List.prototype.remove = function(index) {
  1828. return !this.has(index) ? this :
  1829. index === 0 ? this.shift() :
  1830. index === this.size - 1 ? this.pop() :
  1831. this.splice(index, 1);
  1832. };
  1833. List.prototype.insert = function(index, value) {
  1834. return this.splice(index, 0, value);
  1835. };
  1836. List.prototype.clear = function() {
  1837. if (this.size === 0) {
  1838. return this;
  1839. }
  1840. if (this.__ownerID) {
  1841. this.size = this._origin = this._capacity = 0;
  1842. this._level = SHIFT;
  1843. this._root = this._tail = null;
  1844. this.__hash = undefined;
  1845. this.__altered = true;
  1846. return this;
  1847. }
  1848. return emptyList();
  1849. };
  1850. List.prototype.push = function(/*...values*/) {
  1851. var values = arguments;
  1852. var oldSize = this.size;
  1853. return this.withMutations(function(list ) {
  1854. setListBounds(list, 0, oldSize + values.length);
  1855. for (var ii = 0; ii < values.length; ii++) {
  1856. list.set(oldSize + ii, values[ii]);
  1857. }
  1858. });
  1859. };
  1860. List.prototype.pop = function() {
  1861. return setListBounds(this, 0, -1);
  1862. };
  1863. List.prototype.unshift = function(/*...values*/) {
  1864. var values = arguments;
  1865. return this.withMutations(function(list ) {
  1866. setListBounds(list, -values.length);
  1867. for (var ii = 0; ii < values.length; ii++) {
  1868. list.set(ii, values[ii]);
  1869. }
  1870. });
  1871. };
  1872. List.prototype.shift = function() {
  1873. return setListBounds(this, 1);
  1874. };
  1875. // @pragma Composition
  1876. List.prototype.merge = function(/*...iters*/) {
  1877. return mergeIntoListWith(this, undefined, arguments);
  1878. };
  1879. List.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1880. return mergeIntoListWith(this, merger, iters);
  1881. };
  1882. List.prototype.mergeDeep = function(/*...iters*/) {
  1883. return mergeIntoListWith(this, deepMerger, arguments);
  1884. };
  1885. List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1886. return mergeIntoListWith(this, deepMergerWith(merger), iters);
  1887. };
  1888. List.prototype.setSize = function(size) {
  1889. return setListBounds(this, 0, size);
  1890. };
  1891. // @pragma Iteration
  1892. List.prototype.slice = function(begin, end) {
  1893. var size = this.size;
  1894. if (wholeSlice(begin, end, size)) {
  1895. return this;
  1896. }
  1897. return setListBounds(
  1898. this,
  1899. resolveBegin(begin, size),
  1900. resolveEnd(end, size)
  1901. );
  1902. };
  1903. List.prototype.__iterator = function(type, reverse) {
  1904. var index = 0;
  1905. var values = iterateList(this, reverse);
  1906. return new Iterator(function() {
  1907. var value = values();
  1908. return value === DONE ?
  1909. iteratorDone() :
  1910. iteratorValue(type, index++, value);
  1911. });
  1912. };
  1913. List.prototype.__iterate = function(fn, reverse) {
  1914. var index = 0;
  1915. var values = iterateList(this, reverse);
  1916. var value;
  1917. while ((value = values()) !== DONE) {
  1918. if (fn(value, index++, this) === false) {
  1919. break;
  1920. }
  1921. }
  1922. return index;
  1923. };
  1924. List.prototype.__ensureOwner = function(ownerID) {
  1925. if (ownerID === this.__ownerID) {
  1926. return this;
  1927. }
  1928. if (!ownerID) {
  1929. this.__ownerID = ownerID;
  1930. return this;
  1931. }
  1932. return makeList(this._origin, this._capacity, this._level, this._root, this._tail, ownerID, this.__hash);
  1933. };
  1934. function isList(maybeList) {
  1935. return !!(maybeList && maybeList[IS_LIST_SENTINEL]);
  1936. }
  1937. List.isList = isList;
  1938. var IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
  1939. var ListPrototype = List.prototype;
  1940. ListPrototype[IS_LIST_SENTINEL] = true;
  1941. ListPrototype[DELETE] = ListPrototype.remove;
  1942. ListPrototype.setIn = MapPrototype.setIn;
  1943. ListPrototype.deleteIn =
  1944. ListPrototype.removeIn = MapPrototype.removeIn;
  1945. ListPrototype.update = MapPrototype.update;
  1946. ListPrototype.updateIn = MapPrototype.updateIn;
  1947. ListPrototype.mergeIn = MapPrototype.mergeIn;
  1948. ListPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  1949. ListPrototype.withMutations = MapPrototype.withMutations;
  1950. ListPrototype.asMutable = MapPrototype.asMutable;
  1951. ListPrototype.asImmutable = MapPrototype.asImmutable;
  1952. ListPrototype.wasAltered = MapPrototype.wasAltered;
  1953. function VNode(array, ownerID) {
  1954. this.array = array;
  1955. this.ownerID = ownerID;
  1956. }
  1957. // TODO: seems like these methods are very similar
  1958. VNode.prototype.removeBefore = function(ownerID, level, index) {
  1959. if (index === level ? 1 << level : this.array.length === 0) {
  1960. return this;
  1961. }
  1962. var originIndex = (index >>> level) & MASK;
  1963. if (originIndex >= this.array.length) {
  1964. return new VNode([], ownerID);
  1965. }
  1966. var removingFirst = originIndex === 0;
  1967. var newChild;
  1968. if (level > 0) {
  1969. var oldChild = this.array[originIndex];
  1970. newChild = oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  1971. if (newChild === oldChild && removingFirst) {
  1972. return this;
  1973. }
  1974. }
  1975. if (removingFirst && !newChild) {
  1976. return this;
  1977. }
  1978. var editable = editableVNode(this, ownerID);
  1979. if (!removingFirst) {
  1980. for (var ii = 0; ii < originIndex; ii++) {
  1981. editable.array[ii] = undefined;
  1982. }
  1983. }
  1984. if (newChild) {
  1985. editable.array[originIndex] = newChild;
  1986. }
  1987. return editable;
  1988. };
  1989. VNode.prototype.removeAfter = function(ownerID, level, index) {
  1990. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  1991. return this;
  1992. }
  1993. var sizeIndex = ((index - 1) >>> level) & MASK;
  1994. if (sizeIndex >= this.array.length) {
  1995. return this;
  1996. }
  1997. var newChild;
  1998. if (level > 0) {
  1999. var oldChild = this.array[sizeIndex];
  2000. newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  2001. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  2002. return this;
  2003. }
  2004. }
  2005. var editable = editableVNode(this, ownerID);
  2006. editable.array.splice(sizeIndex + 1);
  2007. if (newChild) {
  2008. editable.array[sizeIndex] = newChild;
  2009. }
  2010. return editable;
  2011. };
  2012. var DONE = {};
  2013. function iterateList(list, reverse) {
  2014. var left = list._origin;
  2015. var right = list._capacity;
  2016. var tailPos = getTailOffset(right);
  2017. var tail = list._tail;
  2018. return iterateNodeOrLeaf(list._root, list._level, 0);
  2019. function iterateNodeOrLeaf(node, level, offset) {
  2020. return level === 0 ?
  2021. iterateLeaf(node, offset) :
  2022. iterateNode(node, level, offset);
  2023. }
  2024. function iterateLeaf(node, offset) {
  2025. var array = offset === tailPos ? tail && tail.array : node && node.array;
  2026. var from = offset > left ? 0 : left - offset;
  2027. var to = right - offset;
  2028. if (to > SIZE) {
  2029. to = SIZE;
  2030. }
  2031. return function() {
  2032. if (from === to) {
  2033. return DONE;
  2034. }
  2035. var idx = reverse ? --to : from++;
  2036. return array && array[idx];
  2037. };
  2038. }
  2039. function iterateNode(node, level, offset) {
  2040. var values;
  2041. var array = node && node.array;
  2042. var from = offset > left ? 0 : (left - offset) >> level;
  2043. var to = ((right - offset) >> level) + 1;
  2044. if (to > SIZE) {
  2045. to = SIZE;
  2046. }
  2047. return function() {
  2048. do {
  2049. if (values) {
  2050. var value = values();
  2051. if (value !== DONE) {
  2052. return value;
  2053. }
  2054. values = null;
  2055. }
  2056. if (from === to) {
  2057. return DONE;
  2058. }
  2059. var idx = reverse ? --to : from++;
  2060. values = iterateNodeOrLeaf(
  2061. array && array[idx], level - SHIFT, offset + (idx << level)
  2062. );
  2063. } while (true);
  2064. };
  2065. }
  2066. }
  2067. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  2068. var list = Object.create(ListPrototype);
  2069. list.size = capacity - origin;
  2070. list._origin = origin;
  2071. list._capacity = capacity;
  2072. list._level = level;
  2073. list._root = root;
  2074. list._tail = tail;
  2075. list.__ownerID = ownerID;
  2076. list.__hash = hash;
  2077. list.__altered = false;
  2078. return list;
  2079. }
  2080. var EMPTY_LIST;
  2081. function emptyList() {
  2082. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  2083. }
  2084. function updateList(list, index, value) {
  2085. index = wrapIndex(list, index);
  2086. if (index !== index) {
  2087. return list;
  2088. }
  2089. if (index >= list.size || index < 0) {
  2090. return list.withMutations(function(list ) {
  2091. index < 0 ?
  2092. setListBounds(list, index).set(0, value) :
  2093. setListBounds(list, 0, index + 1).set(index, value);
  2094. });
  2095. }
  2096. index += list._origin;
  2097. var newTail = list._tail;
  2098. var newRoot = list._root;
  2099. var didAlter = MakeRef(DID_ALTER);
  2100. if (index >= getTailOffset(list._capacity)) {
  2101. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  2102. } else {
  2103. newRoot = updateVNode(newRoot, list.__ownerID, list._level, index, value, didAlter);
  2104. }
  2105. if (!didAlter.value) {
  2106. return list;
  2107. }
  2108. if (list.__ownerID) {
  2109. list._root = newRoot;
  2110. list._tail = newTail;
  2111. list.__hash = undefined;
  2112. list.__altered = true;
  2113. return list;
  2114. }
  2115. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  2116. }
  2117. function updateVNode(node, ownerID, level, index, value, didAlter) {
  2118. var idx = (index >>> level) & MASK;
  2119. var nodeHas = node && idx < node.array.length;
  2120. if (!nodeHas && value === undefined) {
  2121. return node;
  2122. }
  2123. var newNode;
  2124. if (level > 0) {
  2125. var lowerNode = node && node.array[idx];
  2126. var newLowerNode = updateVNode(lowerNode, ownerID, level - SHIFT, index, value, didAlter);
  2127. if (newLowerNode === lowerNode) {
  2128. return node;
  2129. }
  2130. newNode = editableVNode(node, ownerID);
  2131. newNode.array[idx] = newLowerNode;
  2132. return newNode;
  2133. }
  2134. if (nodeHas && node.array[idx] === value) {
  2135. return node;
  2136. }
  2137. SetRef(didAlter);
  2138. newNode = editableVNode(node, ownerID);
  2139. if (value === undefined && idx === newNode.array.length - 1) {
  2140. newNode.array.pop();
  2141. } else {
  2142. newNode.array[idx] = value;
  2143. }
  2144. return newNode;
  2145. }
  2146. function editableVNode(node, ownerID) {
  2147. if (ownerID && node && ownerID === node.ownerID) {
  2148. return node;
  2149. }
  2150. return new VNode(node ? node.array.slice() : [], ownerID);
  2151. }
  2152. function listNodeFor(list, rawIndex) {
  2153. if (rawIndex >= getTailOffset(list._capacity)) {
  2154. return list._tail;
  2155. }
  2156. if (rawIndex < 1 << (list._level + SHIFT)) {
  2157. var node = list._root;
  2158. var level = list._level;
  2159. while (node && level > 0) {
  2160. node = node.array[(rawIndex >>> level) & MASK];
  2161. level -= SHIFT;
  2162. }
  2163. return node;
  2164. }
  2165. }
  2166. function setListBounds(list, begin, end) {
  2167. // Sanitize begin & end using this shorthand for ToInt32(argument)
  2168. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  2169. if (begin !== undefined) {
  2170. begin = begin | 0;
  2171. }
  2172. if (end !== undefined) {
  2173. end = end | 0;
  2174. }
  2175. var owner = list.__ownerID || new OwnerID();
  2176. var oldOrigin = list._origin;
  2177. var oldCapacity = list._capacity;
  2178. var newOrigin = oldOrigin + begin;
  2179. var newCapacity = end === undefined ? oldCapacity : end < 0 ? oldCapacity + end : oldOrigin + end;
  2180. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  2181. return list;
  2182. }
  2183. // If it's going to end after it starts, it's empty.
  2184. if (newOrigin >= newCapacity) {
  2185. return list.clear();
  2186. }
  2187. var newLevel = list._level;
  2188. var newRoot = list._root;
  2189. // New origin might need creating a higher root.
  2190. var offsetShift = 0;
  2191. while (newOrigin + offsetShift < 0) {
  2192. newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner);
  2193. newLevel += SHIFT;
  2194. offsetShift += 1 << newLevel;
  2195. }
  2196. if (offsetShift) {
  2197. newOrigin += offsetShift;
  2198. oldOrigin += offsetShift;
  2199. newCapacity += offsetShift;
  2200. oldCapacity += offsetShift;
  2201. }
  2202. var oldTailOffset = getTailOffset(oldCapacity);
  2203. var newTailOffset = getTailOffset(newCapacity);
  2204. // New size might need creating a higher root.
  2205. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  2206. newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner);
  2207. newLevel += SHIFT;
  2208. }
  2209. // Locate or create the new tail.
  2210. var oldTail = list._tail;
  2211. var newTail = newTailOffset < oldTailOffset ?
  2212. listNodeFor(list, newCapacity - 1) :
  2213. newTailOffset > oldTailOffset ? new VNode([], owner) : oldTail;
  2214. // Merge Tail into tree.
  2215. if (oldTail && newTailOffset > oldTailOffset && newOrigin < oldCapacity && oldTail.array.length) {
  2216. newRoot = editableVNode(newRoot, owner);
  2217. var node = newRoot;
  2218. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  2219. var idx = (oldTailOffset >>> level) & MASK;
  2220. node = node.array[idx] = editableVNode(node.array[idx], owner);
  2221. }
  2222. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  2223. }
  2224. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  2225. if (newCapacity < oldCapacity) {
  2226. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  2227. }
  2228. // If the new origin is within the tail, then we do not need a root.
  2229. if (newOrigin >= newTailOffset) {
  2230. newOrigin -= newTailOffset;
  2231. newCapacity -= newTailOffset;
  2232. newLevel = SHIFT;
  2233. newRoot = null;
  2234. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  2235. // Otherwise, if the root has been trimmed, garbage collect.
  2236. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  2237. offsetShift = 0;
  2238. // Identify the new top root node of the subtree of the old root.
  2239. while (newRoot) {
  2240. var beginIndex = (newOrigin >>> newLevel) & MASK;
  2241. if (beginIndex !== (newTailOffset >>> newLevel) & MASK) {
  2242. break;
  2243. }
  2244. if (beginIndex) {
  2245. offsetShift += (1 << newLevel) * beginIndex;
  2246. }
  2247. newLevel -= SHIFT;
  2248. newRoot = newRoot.array[beginIndex];
  2249. }
  2250. // Trim the new sides of the new root.
  2251. if (newRoot && newOrigin > oldOrigin) {
  2252. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  2253. }
  2254. if (newRoot && newTailOffset < oldTailOffset) {
  2255. newRoot = newRoot.removeAfter(owner, newLevel, newTailOffset - offsetShift);
  2256. }
  2257. if (offsetShift) {
  2258. newOrigin -= offsetShift;
  2259. newCapacity -= offsetShift;
  2260. }
  2261. }
  2262. if (list.__ownerID) {
  2263. list.size = newCapacity - newOrigin;
  2264. list._origin = newOrigin;
  2265. list._capacity = newCapacity;
  2266. list._level = newLevel;
  2267. list._root = newRoot;
  2268. list._tail = newTail;
  2269. list.__hash = undefined;
  2270. list.__altered = true;
  2271. return list;
  2272. }
  2273. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  2274. }
  2275. function mergeIntoListWith(list, merger, iterables) {
  2276. var iters = [];
  2277. var maxSize = 0;
  2278. for (var ii = 0; ii < iterables.length; ii++) {
  2279. var value = iterables[ii];
  2280. var iter = IndexedIterable(value);
  2281. if (iter.size > maxSize) {
  2282. maxSize = iter.size;
  2283. }
  2284. if (!isIterable(value)) {
  2285. iter = iter.map(function(v ) {return fromJS(v)});
  2286. }
  2287. iters.push(iter);
  2288. }
  2289. if (maxSize > list.size) {
  2290. list = list.setSize(maxSize);
  2291. }
  2292. return mergeIntoCollectionWith(list, merger, iters);
  2293. }
  2294. function getTailOffset(size) {
  2295. return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
  2296. }
  2297. createClass(OrderedMap, Map);
  2298. // @pragma Construction
  2299. function OrderedMap(value) {
  2300. return value === null || value === undefined ? emptyOrderedMap() :
  2301. isOrderedMap(value) ? value :
  2302. emptyOrderedMap().withMutations(function(map ) {
  2303. var iter = KeyedIterable(value);
  2304. assertNotInfinite(iter.size);
  2305. iter.forEach(function(v, k) {return map.set(k, v)});
  2306. });
  2307. }
  2308. OrderedMap.of = function(/*...values*/) {
  2309. return this(arguments);
  2310. };
  2311. OrderedMap.prototype.toString = function() {
  2312. return this.__toString('OrderedMap {', '}');
  2313. };
  2314. // @pragma Access
  2315. OrderedMap.prototype.get = function(k, notSetValue) {
  2316. var index = this._map.get(k);
  2317. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  2318. };
  2319. // @pragma Modification
  2320. OrderedMap.prototype.clear = function() {
  2321. if (this.size === 0) {
  2322. return this;
  2323. }
  2324. if (this.__ownerID) {
  2325. this.size = 0;
  2326. this._map.clear();
  2327. this._list.clear();
  2328. return this;
  2329. }
  2330. return emptyOrderedMap();
  2331. };
  2332. OrderedMap.prototype.set = function(k, v) {
  2333. return updateOrderedMap(this, k, v);
  2334. };
  2335. OrderedMap.prototype.remove = function(k) {
  2336. return updateOrderedMap(this, k, NOT_SET);
  2337. };
  2338. OrderedMap.prototype.wasAltered = function() {
  2339. return this._map.wasAltered() || this._list.wasAltered();
  2340. };
  2341. OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2342. return this._list.__iterate(
  2343. function(entry ) {return entry && fn(entry[1], entry[0], this$0)},
  2344. reverse
  2345. );
  2346. };
  2347. OrderedMap.prototype.__iterator = function(type, reverse) {
  2348. return this._list.fromEntrySeq().__iterator(type, reverse);
  2349. };
  2350. OrderedMap.prototype.__ensureOwner = function(ownerID) {
  2351. if (ownerID === this.__ownerID) {
  2352. return this;
  2353. }
  2354. var newMap = this._map.__ensureOwner(ownerID);
  2355. var newList = this._list.__ensureOwner(ownerID);
  2356. if (!ownerID) {
  2357. this.__ownerID = ownerID;
  2358. this._map = newMap;
  2359. this._list = newList;
  2360. return this;
  2361. }
  2362. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  2363. };
  2364. function isOrderedMap(maybeOrderedMap) {
  2365. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  2366. }
  2367. OrderedMap.isOrderedMap = isOrderedMap;
  2368. OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
  2369. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  2370. function makeOrderedMap(map, list, ownerID, hash) {
  2371. var omap = Object.create(OrderedMap.prototype);
  2372. omap.size = map ? map.size : 0;
  2373. omap._map = map;
  2374. omap._list = list;
  2375. omap.__ownerID = ownerID;
  2376. omap.__hash = hash;
  2377. return omap;
  2378. }
  2379. var EMPTY_ORDERED_MAP;
  2380. function emptyOrderedMap() {
  2381. return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()));
  2382. }
  2383. function updateOrderedMap(omap, k, v) {
  2384. var map = omap._map;
  2385. var list = omap._list;
  2386. var i = map.get(k);
  2387. var has = i !== undefined;
  2388. var newMap;
  2389. var newList;
  2390. if (v === NOT_SET) { // removed
  2391. if (!has) {
  2392. return omap;
  2393. }
  2394. if (list.size >= SIZE && list.size >= map.size * 2) {
  2395. newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx});
  2396. newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap();
  2397. if (omap.__ownerID) {
  2398. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  2399. }
  2400. } else {
  2401. newMap = map.remove(k);
  2402. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  2403. }
  2404. } else {
  2405. if (has) {
  2406. if (v === list.get(i)[1]) {
  2407. return omap;
  2408. }
  2409. newMap = map;
  2410. newList = list.set(i, [k, v]);
  2411. } else {
  2412. newMap = map.set(k, list.size);
  2413. newList = list.set(list.size, [k, v]);
  2414. }
  2415. }
  2416. if (omap.__ownerID) {
  2417. omap.size = newMap.size;
  2418. omap._map = newMap;
  2419. omap._list = newList;
  2420. omap.__hash = undefined;
  2421. return omap;
  2422. }
  2423. return makeOrderedMap(newMap, newList);
  2424. }
  2425. createClass(ToKeyedSequence, KeyedSeq);
  2426. function ToKeyedSequence(indexed, useKeys) {
  2427. this._iter = indexed;
  2428. this._useKeys = useKeys;
  2429. this.size = indexed.size;
  2430. }
  2431. ToKeyedSequence.prototype.get = function(key, notSetValue) {
  2432. return this._iter.get(key, notSetValue);
  2433. };
  2434. ToKeyedSequence.prototype.has = function(key) {
  2435. return this._iter.has(key);
  2436. };
  2437. ToKeyedSequence.prototype.valueSeq = function() {
  2438. return this._iter.valueSeq();
  2439. };
  2440. ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
  2441. var reversedSequence = reverseFactory(this, true);
  2442. if (!this._useKeys) {
  2443. reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
  2444. }
  2445. return reversedSequence;
  2446. };
  2447. ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
  2448. var mappedSequence = mapFactory(this, mapper, context);
  2449. if (!this._useKeys) {
  2450. mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
  2451. }
  2452. return mappedSequence;
  2453. };
  2454. ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2455. var ii;
  2456. return this._iter.__iterate(
  2457. this._useKeys ?
  2458. function(v, k) {return fn(v, k, this$0)} :
  2459. ((ii = reverse ? resolveSize(this) : 0),
  2460. function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
  2461. reverse
  2462. );
  2463. };
  2464. ToKeyedSequence.prototype.__iterator = function(type, reverse) {
  2465. if (this._useKeys) {
  2466. return this._iter.__iterator(type, reverse);
  2467. }
  2468. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2469. var ii = reverse ? resolveSize(this) : 0;
  2470. return new Iterator(function() {
  2471. var step = iterator.next();
  2472. return step.done ? step :
  2473. iteratorValue(type, reverse ? --ii : ii++, step.value, step);
  2474. });
  2475. };
  2476. ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
  2477. createClass(ToIndexedSequence, IndexedSeq);
  2478. function ToIndexedSequence(iter) {
  2479. this._iter = iter;
  2480. this.size = iter.size;
  2481. }
  2482. ToIndexedSequence.prototype.includes = function(value) {
  2483. return this._iter.includes(value);
  2484. };
  2485. ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2486. var iterations = 0;
  2487. return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
  2488. };
  2489. ToIndexedSequence.prototype.__iterator = function(type, reverse) {
  2490. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2491. var iterations = 0;
  2492. return new Iterator(function() {
  2493. var step = iterator.next();
  2494. return step.done ? step :
  2495. iteratorValue(type, iterations++, step.value, step)
  2496. });
  2497. };
  2498. createClass(ToSetSequence, SetSeq);
  2499. function ToSetSequence(iter) {
  2500. this._iter = iter;
  2501. this.size = iter.size;
  2502. }
  2503. ToSetSequence.prototype.has = function(key) {
  2504. return this._iter.includes(key);
  2505. };
  2506. ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2507. return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
  2508. };
  2509. ToSetSequence.prototype.__iterator = function(type, reverse) {
  2510. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2511. return new Iterator(function() {
  2512. var step = iterator.next();
  2513. return step.done ? step :
  2514. iteratorValue(type, step.value, step.value, step);
  2515. });
  2516. };
  2517. createClass(FromEntriesSequence, KeyedSeq);
  2518. function FromEntriesSequence(entries) {
  2519. this._iter = entries;
  2520. this.size = entries.size;
  2521. }
  2522. FromEntriesSequence.prototype.entrySeq = function() {
  2523. return this._iter.toSeq();
  2524. };
  2525. FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2526. return this._iter.__iterate(function(entry ) {
  2527. // Check if entry exists first so array access doesn't throw for holes
  2528. // in the parent iteration.
  2529. if (entry) {
  2530. validateEntry(entry);
  2531. var indexedIterable = isIterable(entry);
  2532. return fn(
  2533. indexedIterable ? entry.get(1) : entry[1],
  2534. indexedIterable ? entry.get(0) : entry[0],
  2535. this$0
  2536. );
  2537. }
  2538. }, reverse);
  2539. };
  2540. FromEntriesSequence.prototype.__iterator = function(type, reverse) {
  2541. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2542. return new Iterator(function() {
  2543. while (true) {
  2544. var step = iterator.next();
  2545. if (step.done) {
  2546. return step;
  2547. }
  2548. var entry = step.value;
  2549. // Check if entry exists first so array access doesn't throw for holes
  2550. // in the parent iteration.
  2551. if (entry) {
  2552. validateEntry(entry);
  2553. var indexedIterable = isIterable(entry);
  2554. return iteratorValue(
  2555. type,
  2556. indexedIterable ? entry.get(0) : entry[0],
  2557. indexedIterable ? entry.get(1) : entry[1],
  2558. step
  2559. );
  2560. }
  2561. }
  2562. });
  2563. };
  2564. ToIndexedSequence.prototype.cacheResult =
  2565. ToKeyedSequence.prototype.cacheResult =
  2566. ToSetSequence.prototype.cacheResult =
  2567. FromEntriesSequence.prototype.cacheResult =
  2568. cacheResultThrough;
  2569. function flipFactory(iterable) {
  2570. var flipSequence = makeSequence(iterable);
  2571. flipSequence._iter = iterable;
  2572. flipSequence.size = iterable.size;
  2573. flipSequence.flip = function() {return iterable};
  2574. flipSequence.reverse = function () {
  2575. var reversedSequence = iterable.reverse.apply(this); // super.reverse()
  2576. reversedSequence.flip = function() {return iterable.reverse()};
  2577. return reversedSequence;
  2578. };
  2579. flipSequence.has = function(key ) {return iterable.includes(key)};
  2580. flipSequence.includes = function(key ) {return iterable.has(key)};
  2581. flipSequence.cacheResult = cacheResultThrough;
  2582. flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2583. return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
  2584. };
  2585. flipSequence.__iteratorUncached = function(type, reverse) {
  2586. if (type === ITERATE_ENTRIES) {
  2587. var iterator = iterable.__iterator(type, reverse);
  2588. return new Iterator(function() {
  2589. var step = iterator.next();
  2590. if (!step.done) {
  2591. var k = step.value[0];
  2592. step.value[0] = step.value[1];
  2593. step.value[1] = k;
  2594. }
  2595. return step;
  2596. });
  2597. }
  2598. return iterable.__iterator(
  2599. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  2600. reverse
  2601. );
  2602. };
  2603. return flipSequence;
  2604. }
  2605. function mapFactory(iterable, mapper, context) {
  2606. var mappedSequence = makeSequence(iterable);
  2607. mappedSequence.size = iterable.size;
  2608. mappedSequence.has = function(key ) {return iterable.has(key)};
  2609. mappedSequence.get = function(key, notSetValue) {
  2610. var v = iterable.get(key, NOT_SET);
  2611. return v === NOT_SET ?
  2612. notSetValue :
  2613. mapper.call(context, v, key, iterable);
  2614. };
  2615. mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2616. return iterable.__iterate(
  2617. function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
  2618. reverse
  2619. );
  2620. };
  2621. mappedSequence.__iteratorUncached = function (type, reverse) {
  2622. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2623. return new Iterator(function() {
  2624. var step = iterator.next();
  2625. if (step.done) {
  2626. return step;
  2627. }
  2628. var entry = step.value;
  2629. var key = entry[0];
  2630. return iteratorValue(
  2631. type,
  2632. key,
  2633. mapper.call(context, entry[1], key, iterable),
  2634. step
  2635. );
  2636. });
  2637. };
  2638. return mappedSequence;
  2639. }
  2640. function reverseFactory(iterable, useKeys) {
  2641. var reversedSequence = makeSequence(iterable);
  2642. reversedSequence._iter = iterable;
  2643. reversedSequence.size = iterable.size;
  2644. reversedSequence.reverse = function() {return iterable};
  2645. if (iterable.flip) {
  2646. reversedSequence.flip = function () {
  2647. var flipSequence = flipFactory(iterable);
  2648. flipSequence.reverse = function() {return iterable.flip()};
  2649. return flipSequence;
  2650. };
  2651. }
  2652. reversedSequence.get = function(key, notSetValue)
  2653. {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
  2654. reversedSequence.has = function(key )
  2655. {return iterable.has(useKeys ? key : -1 - key)};
  2656. reversedSequence.includes = function(value ) {return iterable.includes(value)};
  2657. reversedSequence.cacheResult = cacheResultThrough;
  2658. reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
  2659. return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
  2660. };
  2661. reversedSequence.__iterator =
  2662. function(type, reverse) {return iterable.__iterator(type, !reverse)};
  2663. return reversedSequence;
  2664. }
  2665. function filterFactory(iterable, predicate, context, useKeys) {
  2666. var filterSequence = makeSequence(iterable);
  2667. if (useKeys) {
  2668. filterSequence.has = function(key ) {
  2669. var v = iterable.get(key, NOT_SET);
  2670. return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
  2671. };
  2672. filterSequence.get = function(key, notSetValue) {
  2673. var v = iterable.get(key, NOT_SET);
  2674. return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
  2675. v : notSetValue;
  2676. };
  2677. }
  2678. filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2679. var iterations = 0;
  2680. iterable.__iterate(function(v, k, c) {
  2681. if (predicate.call(context, v, k, c)) {
  2682. iterations++;
  2683. return fn(v, useKeys ? k : iterations - 1, this$0);
  2684. }
  2685. }, reverse);
  2686. return iterations;
  2687. };
  2688. filterSequence.__iteratorUncached = function (type, reverse) {
  2689. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2690. var iterations = 0;
  2691. return new Iterator(function() {
  2692. while (true) {
  2693. var step = iterator.next();
  2694. if (step.done) {
  2695. return step;
  2696. }
  2697. var entry = step.value;
  2698. var key = entry[0];
  2699. var value = entry[1];
  2700. if (predicate.call(context, value, key, iterable)) {
  2701. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  2702. }
  2703. }
  2704. });
  2705. };
  2706. return filterSequence;
  2707. }
  2708. function countByFactory(iterable, grouper, context) {
  2709. var groups = Map().asMutable();
  2710. iterable.__iterate(function(v, k) {
  2711. groups.update(
  2712. grouper.call(context, v, k, iterable),
  2713. 0,
  2714. function(a ) {return a + 1}
  2715. );
  2716. });
  2717. return groups.asImmutable();
  2718. }
  2719. function groupByFactory(iterable, grouper, context) {
  2720. var isKeyedIter = isKeyed(iterable);
  2721. var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable();
  2722. iterable.__iterate(function(v, k) {
  2723. groups.update(
  2724. grouper.call(context, v, k, iterable),
  2725. function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
  2726. );
  2727. });
  2728. var coerce = iterableClass(iterable);
  2729. return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
  2730. }
  2731. function sliceFactory(iterable, begin, end, useKeys) {
  2732. var originalSize = iterable.size;
  2733. // Sanitize begin & end using this shorthand for ToInt32(argument)
  2734. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  2735. if (begin !== undefined) {
  2736. begin = begin | 0;
  2737. }
  2738. if (end !== undefined) {
  2739. end = end | 0;
  2740. }
  2741. if (wholeSlice(begin, end, originalSize)) {
  2742. return iterable;
  2743. }
  2744. var resolvedBegin = resolveBegin(begin, originalSize);
  2745. var resolvedEnd = resolveEnd(end, originalSize);
  2746. // begin or end will be NaN if they were provided as negative numbers and
  2747. // this iterable's size is unknown. In that case, cache first so there is
  2748. // a known size and these do not resolve to NaN.
  2749. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  2750. return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
  2751. }
  2752. // Note: resolvedEnd is undefined when the original sequence's length is
  2753. // unknown and this slice did not supply an end and should contain all
  2754. // elements after resolvedBegin.
  2755. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  2756. var resolvedSize = resolvedEnd - resolvedBegin;
  2757. var sliceSize;
  2758. if (resolvedSize === resolvedSize) {
  2759. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  2760. }
  2761. var sliceSeq = makeSequence(iterable);
  2762. // If iterable.size is undefined, the size of the realized sliceSeq is
  2763. // unknown at this point unless the number of items to slice is 0
  2764. sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
  2765. if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
  2766. sliceSeq.get = function (index, notSetValue) {
  2767. index = wrapIndex(this, index);
  2768. return index >= 0 && index < sliceSize ?
  2769. iterable.get(index + resolvedBegin, notSetValue) :
  2770. notSetValue;
  2771. };
  2772. }
  2773. sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
  2774. if (sliceSize === 0) {
  2775. return 0;
  2776. }
  2777. if (reverse) {
  2778. return this.cacheResult().__iterate(fn, reverse);
  2779. }
  2780. var skipped = 0;
  2781. var isSkipping = true;
  2782. var iterations = 0;
  2783. iterable.__iterate(function(v, k) {
  2784. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  2785. iterations++;
  2786. return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
  2787. iterations !== sliceSize;
  2788. }
  2789. });
  2790. return iterations;
  2791. };
  2792. sliceSeq.__iteratorUncached = function(type, reverse) {
  2793. if (sliceSize !== 0 && reverse) {
  2794. return this.cacheResult().__iterator(type, reverse);
  2795. }
  2796. // Don't bother instantiating parent iterator if taking 0.
  2797. var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
  2798. var skipped = 0;
  2799. var iterations = 0;
  2800. return new Iterator(function() {
  2801. while (skipped++ < resolvedBegin) {
  2802. iterator.next();
  2803. }
  2804. if (++iterations > sliceSize) {
  2805. return iteratorDone();
  2806. }
  2807. var step = iterator.next();
  2808. if (useKeys || type === ITERATE_VALUES) {
  2809. return step;
  2810. } else if (type === ITERATE_KEYS) {
  2811. return iteratorValue(type, iterations - 1, undefined, step);
  2812. } else {
  2813. return iteratorValue(type, iterations - 1, step.value[1], step);
  2814. }
  2815. });
  2816. };
  2817. return sliceSeq;
  2818. }
  2819. function takeWhileFactory(iterable, predicate, context) {
  2820. var takeSequence = makeSequence(iterable);
  2821. takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  2822. if (reverse) {
  2823. return this.cacheResult().__iterate(fn, reverse);
  2824. }
  2825. var iterations = 0;
  2826. iterable.__iterate(function(v, k, c)
  2827. {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
  2828. );
  2829. return iterations;
  2830. };
  2831. takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  2832. if (reverse) {
  2833. return this.cacheResult().__iterator(type, reverse);
  2834. }
  2835. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2836. var iterating = true;
  2837. return new Iterator(function() {
  2838. if (!iterating) {
  2839. return iteratorDone();
  2840. }
  2841. var step = iterator.next();
  2842. if (step.done) {
  2843. return step;
  2844. }
  2845. var entry = step.value;
  2846. var k = entry[0];
  2847. var v = entry[1];
  2848. if (!predicate.call(context, v, k, this$0)) {
  2849. iterating = false;
  2850. return iteratorDone();
  2851. }
  2852. return type === ITERATE_ENTRIES ? step :
  2853. iteratorValue(type, k, v, step);
  2854. });
  2855. };
  2856. return takeSequence;
  2857. }
  2858. function skipWhileFactory(iterable, predicate, context, useKeys) {
  2859. var skipSequence = makeSequence(iterable);
  2860. skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2861. if (reverse) {
  2862. return this.cacheResult().__iterate(fn, reverse);
  2863. }
  2864. var isSkipping = true;
  2865. var iterations = 0;
  2866. iterable.__iterate(function(v, k, c) {
  2867. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  2868. iterations++;
  2869. return fn(v, useKeys ? k : iterations - 1, this$0);
  2870. }
  2871. });
  2872. return iterations;
  2873. };
  2874. skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  2875. if (reverse) {
  2876. return this.cacheResult().__iterator(type, reverse);
  2877. }
  2878. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2879. var skipping = true;
  2880. var iterations = 0;
  2881. return new Iterator(function() {
  2882. var step, k, v;
  2883. do {
  2884. step = iterator.next();
  2885. if (step.done) {
  2886. if (useKeys || type === ITERATE_VALUES) {
  2887. return step;
  2888. } else if (type === ITERATE_KEYS) {
  2889. return iteratorValue(type, iterations++, undefined, step);
  2890. } else {
  2891. return iteratorValue(type, iterations++, step.value[1], step);
  2892. }
  2893. }
  2894. var entry = step.value;
  2895. k = entry[0];
  2896. v = entry[1];
  2897. skipping && (skipping = predicate.call(context, v, k, this$0));
  2898. } while (skipping);
  2899. return type === ITERATE_ENTRIES ? step :
  2900. iteratorValue(type, k, v, step);
  2901. });
  2902. };
  2903. return skipSequence;
  2904. }
  2905. function concatFactory(iterable, values) {
  2906. var isKeyedIterable = isKeyed(iterable);
  2907. var iters = [iterable].concat(values).map(function(v ) {
  2908. if (!isIterable(v)) {
  2909. v = isKeyedIterable ?
  2910. keyedSeqFromValue(v) :
  2911. indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  2912. } else if (isKeyedIterable) {
  2913. v = KeyedIterable(v);
  2914. }
  2915. return v;
  2916. }).filter(function(v ) {return v.size !== 0});
  2917. if (iters.length === 0) {
  2918. return iterable;
  2919. }
  2920. if (iters.length === 1) {
  2921. var singleton = iters[0];
  2922. if (singleton === iterable ||
  2923. isKeyedIterable && isKeyed(singleton) ||
  2924. isIndexed(iterable) && isIndexed(singleton)) {
  2925. return singleton;
  2926. }
  2927. }
  2928. var concatSeq = new ArraySeq(iters);
  2929. if (isKeyedIterable) {
  2930. concatSeq = concatSeq.toKeyedSeq();
  2931. } else if (!isIndexed(iterable)) {
  2932. concatSeq = concatSeq.toSetSeq();
  2933. }
  2934. concatSeq = concatSeq.flatten(true);
  2935. concatSeq.size = iters.reduce(
  2936. function(sum, seq) {
  2937. if (sum !== undefined) {
  2938. var size = seq.size;
  2939. if (size !== undefined) {
  2940. return sum + size;
  2941. }
  2942. }
  2943. },
  2944. 0
  2945. );
  2946. return concatSeq;
  2947. }
  2948. function flattenFactory(iterable, depth, useKeys) {
  2949. var flatSequence = makeSequence(iterable);
  2950. flatSequence.__iterateUncached = function(fn, reverse) {
  2951. var iterations = 0;
  2952. var stopped = false;
  2953. function flatDeep(iter, currentDepth) {var this$0 = this;
  2954. iter.__iterate(function(v, k) {
  2955. if ((!depth || currentDepth < depth) && isIterable(v)) {
  2956. flatDeep(v, currentDepth + 1);
  2957. } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
  2958. stopped = true;
  2959. }
  2960. return !stopped;
  2961. }, reverse);
  2962. }
  2963. flatDeep(iterable, 0);
  2964. return iterations;
  2965. };
  2966. flatSequence.__iteratorUncached = function(type, reverse) {
  2967. var iterator = iterable.__iterator(type, reverse);
  2968. var stack = [];
  2969. var iterations = 0;
  2970. return new Iterator(function() {
  2971. while (iterator) {
  2972. var step = iterator.next();
  2973. if (step.done !== false) {
  2974. iterator = stack.pop();
  2975. continue;
  2976. }
  2977. var v = step.value;
  2978. if (type === ITERATE_ENTRIES) {
  2979. v = v[1];
  2980. }
  2981. if ((!depth || stack.length < depth) && isIterable(v)) {
  2982. stack.push(iterator);
  2983. iterator = v.__iterator(type, reverse);
  2984. } else {
  2985. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  2986. }
  2987. }
  2988. return iteratorDone();
  2989. });
  2990. };
  2991. return flatSequence;
  2992. }
  2993. function flatMapFactory(iterable, mapper, context) {
  2994. var coerce = iterableClass(iterable);
  2995. return iterable.toSeq().map(
  2996. function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
  2997. ).flatten(true);
  2998. }
  2999. function interposeFactory(iterable, separator) {
  3000. var interposedSequence = makeSequence(iterable);
  3001. interposedSequence.size = iterable.size && iterable.size * 2 -1;
  3002. interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  3003. var iterations = 0;
  3004. iterable.__iterate(function(v, k)
  3005. {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
  3006. fn(v, iterations++, this$0) !== false},
  3007. reverse
  3008. );
  3009. return iterations;
  3010. };
  3011. interposedSequence.__iteratorUncached = function(type, reverse) {
  3012. var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
  3013. var iterations = 0;
  3014. var step;
  3015. return new Iterator(function() {
  3016. if (!step || iterations % 2) {
  3017. step = iterator.next();
  3018. if (step.done) {
  3019. return step;
  3020. }
  3021. }
  3022. return iterations % 2 ?
  3023. iteratorValue(type, iterations++, separator) :
  3024. iteratorValue(type, iterations++, step.value, step);
  3025. });
  3026. };
  3027. return interposedSequence;
  3028. }
  3029. function sortFactory(iterable, comparator, mapper) {
  3030. if (!comparator) {
  3031. comparator = defaultComparator;
  3032. }
  3033. var isKeyedIterable = isKeyed(iterable);
  3034. var index = 0;
  3035. var entries = iterable.toSeq().map(
  3036. function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
  3037. ).toArray();
  3038. entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
  3039. isKeyedIterable ?
  3040. function(v, i) { entries[i].length = 2; } :
  3041. function(v, i) { entries[i] = v[1]; }
  3042. );
  3043. return isKeyedIterable ? KeyedSeq(entries) :
  3044. isIndexed(iterable) ? IndexedSeq(entries) :
  3045. SetSeq(entries);
  3046. }
  3047. function maxFactory(iterable, comparator, mapper) {
  3048. if (!comparator) {
  3049. comparator = defaultComparator;
  3050. }
  3051. if (mapper) {
  3052. var entry = iterable.toSeq()
  3053. .map(function(v, k) {return [v, mapper(v, k, iterable)]})
  3054. .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
  3055. return entry && entry[0];
  3056. } else {
  3057. return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
  3058. }
  3059. }
  3060. function maxCompare(comparator, a, b) {
  3061. var comp = comparator(b, a);
  3062. // b is considered the new max if the comparator declares them equal, but
  3063. // they are not equal and b is in fact a nullish value.
  3064. return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
  3065. }
  3066. function zipWithFactory(keyIter, zipper, iters) {
  3067. var zipSequence = makeSequence(keyIter);
  3068. zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
  3069. // Note: this a generic base implementation of __iterate in terms of
  3070. // __iterator which may be more generically useful in the future.
  3071. zipSequence.__iterate = function(fn, reverse) {
  3072. /* generic:
  3073. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  3074. var step;
  3075. var iterations = 0;
  3076. while (!(step = iterator.next()).done) {
  3077. iterations++;
  3078. if (fn(step.value[1], step.value[0], this) === false) {
  3079. break;
  3080. }
  3081. }
  3082. return iterations;
  3083. */
  3084. // indexed:
  3085. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  3086. var step;
  3087. var iterations = 0;
  3088. while (!(step = iterator.next()).done) {
  3089. if (fn(step.value, iterations++, this) === false) {
  3090. break;
  3091. }
  3092. }
  3093. return iterations;
  3094. };
  3095. zipSequence.__iteratorUncached = function(type, reverse) {
  3096. var iterators = iters.map(function(i )
  3097. {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
  3098. );
  3099. var iterations = 0;
  3100. var isDone = false;
  3101. return new Iterator(function() {
  3102. var steps;
  3103. if (!isDone) {
  3104. steps = iterators.map(function(i ) {return i.next()});
  3105. isDone = steps.some(function(s ) {return s.done});
  3106. }
  3107. if (isDone) {
  3108. return iteratorDone();
  3109. }
  3110. return iteratorValue(
  3111. type,
  3112. iterations++,
  3113. zipper.apply(null, steps.map(function(s ) {return s.value}))
  3114. );
  3115. });
  3116. };
  3117. return zipSequence
  3118. }
  3119. // #pragma Helper Functions
  3120. function reify(iter, seq) {
  3121. return isSeq(iter) ? seq : iter.constructor(seq);
  3122. }
  3123. function validateEntry(entry) {
  3124. if (entry !== Object(entry)) {
  3125. throw new TypeError('Expected [K, V] tuple: ' + entry);
  3126. }
  3127. }
  3128. function resolveSize(iter) {
  3129. assertNotInfinite(iter.size);
  3130. return ensureSize(iter);
  3131. }
  3132. function iterableClass(iterable) {
  3133. return isKeyed(iterable) ? KeyedIterable :
  3134. isIndexed(iterable) ? IndexedIterable :
  3135. SetIterable;
  3136. }
  3137. function makeSequence(iterable) {
  3138. return Object.create(
  3139. (
  3140. isKeyed(iterable) ? KeyedSeq :
  3141. isIndexed(iterable) ? IndexedSeq :
  3142. SetSeq
  3143. ).prototype
  3144. );
  3145. }
  3146. function cacheResultThrough() {
  3147. if (this._iter.cacheResult) {
  3148. this._iter.cacheResult();
  3149. this.size = this._iter.size;
  3150. return this;
  3151. } else {
  3152. return Seq.prototype.cacheResult.call(this);
  3153. }
  3154. }
  3155. function defaultComparator(a, b) {
  3156. return a > b ? 1 : a < b ? -1 : 0;
  3157. }
  3158. function forceIterator(keyPath) {
  3159. var iter = getIterator(keyPath);
  3160. if (!iter) {
  3161. // Array might not be iterable in this environment, so we need a fallback
  3162. // to our wrapped type.
  3163. if (!isArrayLike(keyPath)) {
  3164. throw new TypeError('Expected iterable or array-like: ' + keyPath);
  3165. }
  3166. iter = getIterator(Iterable(keyPath));
  3167. }
  3168. return iter;
  3169. }
  3170. createClass(Record, KeyedCollection);
  3171. function Record(defaultValues, name) {
  3172. var hasInitialized;
  3173. var RecordType = function Record(values) {
  3174. if (values instanceof RecordType) {
  3175. return values;
  3176. }
  3177. if (!(this instanceof RecordType)) {
  3178. return new RecordType(values);
  3179. }
  3180. if (!hasInitialized) {
  3181. hasInitialized = true;
  3182. var keys = Object.keys(defaultValues);
  3183. setProps(RecordTypePrototype, keys);
  3184. RecordTypePrototype.size = keys.length;
  3185. RecordTypePrototype._name = name;
  3186. RecordTypePrototype._keys = keys;
  3187. RecordTypePrototype._defaultValues = defaultValues;
  3188. }
  3189. this._map = Map(values);
  3190. };
  3191. var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
  3192. RecordTypePrototype.constructor = RecordType;
  3193. return RecordType;
  3194. }
  3195. Record.prototype.toString = function() {
  3196. return this.__toString(recordName(this) + ' {', '}');
  3197. };
  3198. // @pragma Access
  3199. Record.prototype.has = function(k) {
  3200. return this._defaultValues.hasOwnProperty(k);
  3201. };
  3202. Record.prototype.get = function(k, notSetValue) {
  3203. if (!this.has(k)) {
  3204. return notSetValue;
  3205. }
  3206. var defaultVal = this._defaultValues[k];
  3207. return this._map ? this._map.get(k, defaultVal) : defaultVal;
  3208. };
  3209. // @pragma Modification
  3210. Record.prototype.clear = function() {
  3211. if (this.__ownerID) {
  3212. this._map && this._map.clear();
  3213. return this;
  3214. }
  3215. var RecordType = this.constructor;
  3216. return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap()));
  3217. };
  3218. Record.prototype.set = function(k, v) {
  3219. if (!this.has(k)) {
  3220. throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
  3221. }
  3222. var newMap = this._map && this._map.set(k, v);
  3223. if (this.__ownerID || newMap === this._map) {
  3224. return this;
  3225. }
  3226. return makeRecord(this, newMap);
  3227. };
  3228. Record.prototype.remove = function(k) {
  3229. if (!this.has(k)) {
  3230. return this;
  3231. }
  3232. var newMap = this._map && this._map.remove(k);
  3233. if (this.__ownerID || newMap === this._map) {
  3234. return this;
  3235. }
  3236. return makeRecord(this, newMap);
  3237. };
  3238. Record.prototype.wasAltered = function() {
  3239. return this._map.wasAltered();
  3240. };
  3241. Record.prototype.__iterator = function(type, reverse) {var this$0 = this;
  3242. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse);
  3243. };
  3244. Record.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  3245. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse);
  3246. };
  3247. Record.prototype.__ensureOwner = function(ownerID) {
  3248. if (ownerID === this.__ownerID) {
  3249. return this;
  3250. }
  3251. var newMap = this._map && this._map.__ensureOwner(ownerID);
  3252. if (!ownerID) {
  3253. this.__ownerID = ownerID;
  3254. this._map = newMap;
  3255. return this;
  3256. }
  3257. return makeRecord(this, newMap, ownerID);
  3258. };
  3259. var RecordPrototype = Record.prototype;
  3260. RecordPrototype[DELETE] = RecordPrototype.remove;
  3261. RecordPrototype.deleteIn =
  3262. RecordPrototype.removeIn = MapPrototype.removeIn;
  3263. RecordPrototype.merge = MapPrototype.merge;
  3264. RecordPrototype.mergeWith = MapPrototype.mergeWith;
  3265. RecordPrototype.mergeIn = MapPrototype.mergeIn;
  3266. RecordPrototype.mergeDeep = MapPrototype.mergeDeep;
  3267. RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith;
  3268. RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  3269. RecordPrototype.setIn = MapPrototype.setIn;
  3270. RecordPrototype.update = MapPrototype.update;
  3271. RecordPrototype.updateIn = MapPrototype.updateIn;
  3272. RecordPrototype.withMutations = MapPrototype.withMutations;
  3273. RecordPrototype.asMutable = MapPrototype.asMutable;
  3274. RecordPrototype.asImmutable = MapPrototype.asImmutable;
  3275. function makeRecord(likeRecord, map, ownerID) {
  3276. var record = Object.create(Object.getPrototypeOf(likeRecord));
  3277. record._map = map;
  3278. record.__ownerID = ownerID;
  3279. return record;
  3280. }
  3281. function recordName(record) {
  3282. return record._name || record.constructor.name || 'Record';
  3283. }
  3284. function setProps(prototype, names) {
  3285. try {
  3286. names.forEach(setProp.bind(undefined, prototype));
  3287. } catch (error) {
  3288. // Object.defineProperty failed. Probably IE8.
  3289. }
  3290. }
  3291. function setProp(prototype, name) {
  3292. Object.defineProperty(prototype, name, {
  3293. get: function() {
  3294. return this.get(name);
  3295. },
  3296. set: function(value) {
  3297. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  3298. this.set(name, value);
  3299. }
  3300. });
  3301. }
  3302. createClass(Set, SetCollection);
  3303. // @pragma Construction
  3304. function Set(value) {
  3305. return value === null || value === undefined ? emptySet() :
  3306. isSet(value) && !isOrdered(value) ? value :
  3307. emptySet().withMutations(function(set ) {
  3308. var iter = SetIterable(value);
  3309. assertNotInfinite(iter.size);
  3310. iter.forEach(function(v ) {return set.add(v)});
  3311. });
  3312. }
  3313. Set.of = function(/*...values*/) {
  3314. return this(arguments);
  3315. };
  3316. Set.fromKeys = function(value) {
  3317. return this(KeyedIterable(value).keySeq());
  3318. };
  3319. Set.prototype.toString = function() {
  3320. return this.__toString('Set {', '}');
  3321. };
  3322. // @pragma Access
  3323. Set.prototype.has = function(value) {
  3324. return this._map.has(value);
  3325. };
  3326. // @pragma Modification
  3327. Set.prototype.add = function(value) {
  3328. return updateSet(this, this._map.set(value, true));
  3329. };
  3330. Set.prototype.remove = function(value) {
  3331. return updateSet(this, this._map.remove(value));
  3332. };
  3333. Set.prototype.clear = function() {
  3334. return updateSet(this, this._map.clear());
  3335. };
  3336. // @pragma Composition
  3337. Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
  3338. iters = iters.filter(function(x ) {return x.size !== 0});
  3339. if (iters.length === 0) {
  3340. return this;
  3341. }
  3342. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  3343. return this.constructor(iters[0]);
  3344. }
  3345. return this.withMutations(function(set ) {
  3346. for (var ii = 0; ii < iters.length; ii++) {
  3347. SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)});
  3348. }
  3349. });
  3350. };
  3351. Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
  3352. if (iters.length === 0) {
  3353. return this;
  3354. }
  3355. iters = iters.map(function(iter ) {return SetIterable(iter)});
  3356. var originalSet = this;
  3357. return this.withMutations(function(set ) {
  3358. originalSet.forEach(function(value ) {
  3359. if (!iters.every(function(iter ) {return iter.includes(value)})) {
  3360. set.remove(value);
  3361. }
  3362. });
  3363. });
  3364. };
  3365. Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
  3366. if (iters.length === 0) {
  3367. return this;
  3368. }
  3369. iters = iters.map(function(iter ) {return SetIterable(iter)});
  3370. var originalSet = this;
  3371. return this.withMutations(function(set ) {
  3372. originalSet.forEach(function(value ) {
  3373. if (iters.some(function(iter ) {return iter.includes(value)})) {
  3374. set.remove(value);
  3375. }
  3376. });
  3377. });
  3378. };
  3379. Set.prototype.merge = function() {
  3380. return this.union.apply(this, arguments);
  3381. };
  3382. Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  3383. return this.union.apply(this, iters);
  3384. };
  3385. Set.prototype.sort = function(comparator) {
  3386. // Late binding
  3387. return OrderedSet(sortFactory(this, comparator));
  3388. };
  3389. Set.prototype.sortBy = function(mapper, comparator) {
  3390. // Late binding
  3391. return OrderedSet(sortFactory(this, comparator, mapper));
  3392. };
  3393. Set.prototype.wasAltered = function() {
  3394. return this._map.wasAltered();
  3395. };
  3396. Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  3397. return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
  3398. };
  3399. Set.prototype.__iterator = function(type, reverse) {
  3400. return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
  3401. };
  3402. Set.prototype.__ensureOwner = function(ownerID) {
  3403. if (ownerID === this.__ownerID) {
  3404. return this;
  3405. }
  3406. var newMap = this._map.__ensureOwner(ownerID);
  3407. if (!ownerID) {
  3408. this.__ownerID = ownerID;
  3409. this._map = newMap;
  3410. return this;
  3411. }
  3412. return this.__make(newMap, ownerID);
  3413. };
  3414. function isSet(maybeSet) {
  3415. return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
  3416. }
  3417. Set.isSet = isSet;
  3418. var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
  3419. var SetPrototype = Set.prototype;
  3420. SetPrototype[IS_SET_SENTINEL] = true;
  3421. SetPrototype[DELETE] = SetPrototype.remove;
  3422. SetPrototype.mergeDeep = SetPrototype.merge;
  3423. SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
  3424. SetPrototype.withMutations = MapPrototype.withMutations;
  3425. SetPrototype.asMutable = MapPrototype.asMutable;
  3426. SetPrototype.asImmutable = MapPrototype.asImmutable;
  3427. SetPrototype.__empty = emptySet;
  3428. SetPrototype.__make = makeSet;
  3429. function updateSet(set, newMap) {
  3430. if (set.__ownerID) {
  3431. set.size = newMap.size;
  3432. set._map = newMap;
  3433. return set;
  3434. }
  3435. return newMap === set._map ? set :
  3436. newMap.size === 0 ? set.__empty() :
  3437. set.__make(newMap);
  3438. }
  3439. function makeSet(map, ownerID) {
  3440. var set = Object.create(SetPrototype);
  3441. set.size = map ? map.size : 0;
  3442. set._map = map;
  3443. set.__ownerID = ownerID;
  3444. return set;
  3445. }
  3446. var EMPTY_SET;
  3447. function emptySet() {
  3448. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  3449. }
  3450. createClass(OrderedSet, Set);
  3451. // @pragma Construction
  3452. function OrderedSet(value) {
  3453. return value === null || value === undefined ? emptyOrderedSet() :
  3454. isOrderedSet(value) ? value :
  3455. emptyOrderedSet().withMutations(function(set ) {
  3456. var iter = SetIterable(value);
  3457. assertNotInfinite(iter.size);
  3458. iter.forEach(function(v ) {return set.add(v)});
  3459. });
  3460. }
  3461. OrderedSet.of = function(/*...values*/) {
  3462. return this(arguments);
  3463. };
  3464. OrderedSet.fromKeys = function(value) {
  3465. return this(KeyedIterable(value).keySeq());
  3466. };
  3467. OrderedSet.prototype.toString = function() {
  3468. return this.__toString('OrderedSet {', '}');
  3469. };
  3470. function isOrderedSet(maybeOrderedSet) {
  3471. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  3472. }
  3473. OrderedSet.isOrderedSet = isOrderedSet;
  3474. var OrderedSetPrototype = OrderedSet.prototype;
  3475. OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
  3476. OrderedSetPrototype.__empty = emptyOrderedSet;
  3477. OrderedSetPrototype.__make = makeOrderedSet;
  3478. function makeOrderedSet(map, ownerID) {
  3479. var set = Object.create(OrderedSetPrototype);
  3480. set.size = map ? map.size : 0;
  3481. set._map = map;
  3482. set.__ownerID = ownerID;
  3483. return set;
  3484. }
  3485. var EMPTY_ORDERED_SET;
  3486. function emptyOrderedSet() {
  3487. return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
  3488. }
  3489. createClass(Stack, IndexedCollection);
  3490. // @pragma Construction
  3491. function Stack(value) {
  3492. return value === null || value === undefined ? emptyStack() :
  3493. isStack(value) ? value :
  3494. emptyStack().unshiftAll(value);
  3495. }
  3496. Stack.of = function(/*...values*/) {
  3497. return this(arguments);
  3498. };
  3499. Stack.prototype.toString = function() {
  3500. return this.__toString('Stack [', ']');
  3501. };
  3502. // @pragma Access
  3503. Stack.prototype.get = function(index, notSetValue) {
  3504. var head = this._head;
  3505. index = wrapIndex(this, index);
  3506. while (head && index--) {
  3507. head = head.next;
  3508. }
  3509. return head ? head.value : notSetValue;
  3510. };
  3511. Stack.prototype.peek = function() {
  3512. return this._head && this._head.value;
  3513. };
  3514. // @pragma Modification
  3515. Stack.prototype.push = function(/*...values*/) {
  3516. if (arguments.length === 0) {
  3517. return this;
  3518. }
  3519. var newSize = this.size + arguments.length;
  3520. var head = this._head;
  3521. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  3522. head = {
  3523. value: arguments[ii],
  3524. next: head
  3525. };
  3526. }
  3527. if (this.__ownerID) {
  3528. this.size = newSize;
  3529. this._head = head;
  3530. this.__hash = undefined;
  3531. this.__altered = true;
  3532. return this;
  3533. }
  3534. return makeStack(newSize, head);
  3535. };
  3536. Stack.prototype.pushAll = function(iter) {
  3537. iter = IndexedIterable(iter);
  3538. if (iter.size === 0) {
  3539. return this;
  3540. }
  3541. assertNotInfinite(iter.size);
  3542. var newSize = this.size;
  3543. var head = this._head;
  3544. iter.reverse().forEach(function(value ) {
  3545. newSize++;
  3546. head = {
  3547. value: value,
  3548. next: head
  3549. };
  3550. });
  3551. if (this.__ownerID) {
  3552. this.size = newSize;
  3553. this._head = head;
  3554. this.__hash = undefined;
  3555. this.__altered = true;
  3556. return this;
  3557. }
  3558. return makeStack(newSize, head);
  3559. };
  3560. Stack.prototype.pop = function() {
  3561. return this.slice(1);
  3562. };
  3563. Stack.prototype.unshift = function(/*...values*/) {
  3564. return this.push.apply(this, arguments);
  3565. };
  3566. Stack.prototype.unshiftAll = function(iter) {
  3567. return this.pushAll(iter);
  3568. };
  3569. Stack.prototype.shift = function() {
  3570. return this.pop.apply(this, arguments);
  3571. };
  3572. Stack.prototype.clear = function() {
  3573. if (this.size === 0) {
  3574. return this;
  3575. }
  3576. if (this.__ownerID) {
  3577. this.size = 0;
  3578. this._head = undefined;
  3579. this.__hash = undefined;
  3580. this.__altered = true;
  3581. return this;
  3582. }
  3583. return emptyStack();
  3584. };
  3585. Stack.prototype.slice = function(begin, end) {
  3586. if (wholeSlice(begin, end, this.size)) {
  3587. return this;
  3588. }
  3589. var resolvedBegin = resolveBegin(begin, this.size);
  3590. var resolvedEnd = resolveEnd(end, this.size);
  3591. if (resolvedEnd !== this.size) {
  3592. // super.slice(begin, end);
  3593. return IndexedCollection.prototype.slice.call(this, begin, end);
  3594. }
  3595. var newSize = this.size - resolvedBegin;
  3596. var head = this._head;
  3597. while (resolvedBegin--) {
  3598. head = head.next;
  3599. }
  3600. if (this.__ownerID) {
  3601. this.size = newSize;
  3602. this._head = head;
  3603. this.__hash = undefined;
  3604. this.__altered = true;
  3605. return this;
  3606. }
  3607. return makeStack(newSize, head);
  3608. };
  3609. // @pragma Mutability
  3610. Stack.prototype.__ensureOwner = function(ownerID) {
  3611. if (ownerID === this.__ownerID) {
  3612. return this;
  3613. }
  3614. if (!ownerID) {
  3615. this.__ownerID = ownerID;
  3616. this.__altered = false;
  3617. return this;
  3618. }
  3619. return makeStack(this.size, this._head, ownerID, this.__hash);
  3620. };
  3621. // @pragma Iteration
  3622. Stack.prototype.__iterate = function(fn, reverse) {
  3623. if (reverse) {
  3624. return this.reverse().__iterate(fn);
  3625. }
  3626. var iterations = 0;
  3627. var node = this._head;
  3628. while (node) {
  3629. if (fn(node.value, iterations++, this) === false) {
  3630. break;
  3631. }
  3632. node = node.next;
  3633. }
  3634. return iterations;
  3635. };
  3636. Stack.prototype.__iterator = function(type, reverse) {
  3637. if (reverse) {
  3638. return this.reverse().__iterator(type);
  3639. }
  3640. var iterations = 0;
  3641. var node = this._head;
  3642. return new Iterator(function() {
  3643. if (node) {
  3644. var value = node.value;
  3645. node = node.next;
  3646. return iteratorValue(type, iterations++, value);
  3647. }
  3648. return iteratorDone();
  3649. });
  3650. };
  3651. function isStack(maybeStack) {
  3652. return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
  3653. }
  3654. Stack.isStack = isStack;
  3655. var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
  3656. var StackPrototype = Stack.prototype;
  3657. StackPrototype[IS_STACK_SENTINEL] = true;
  3658. StackPrototype.withMutations = MapPrototype.withMutations;
  3659. StackPrototype.asMutable = MapPrototype.asMutable;
  3660. StackPrototype.asImmutable = MapPrototype.asImmutable;
  3661. StackPrototype.wasAltered = MapPrototype.wasAltered;
  3662. function makeStack(size, head, ownerID, hash) {
  3663. var map = Object.create(StackPrototype);
  3664. map.size = size;
  3665. map._head = head;
  3666. map.__ownerID = ownerID;
  3667. map.__hash = hash;
  3668. map.__altered = false;
  3669. return map;
  3670. }
  3671. var EMPTY_STACK;
  3672. function emptyStack() {
  3673. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  3674. }
  3675. /**
  3676. * Contributes additional methods to a constructor
  3677. */
  3678. function mixin(ctor, methods) {
  3679. var keyCopier = function(key ) { ctor.prototype[key] = methods[key]; };
  3680. Object.keys(methods).forEach(keyCopier);
  3681. Object.getOwnPropertySymbols &&
  3682. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  3683. return ctor;
  3684. }
  3685. Iterable.Iterator = Iterator;
  3686. mixin(Iterable, {
  3687. // ### Conversion to other types
  3688. toArray: function() {
  3689. assertNotInfinite(this.size);
  3690. var array = new Array(this.size || 0);
  3691. this.valueSeq().__iterate(function(v, i) { array[i] = v; });
  3692. return array;
  3693. },
  3694. toIndexedSeq: function() {
  3695. return new ToIndexedSequence(this);
  3696. },
  3697. toJS: function() {
  3698. return this.toSeq().map(
  3699. function(value ) {return value && typeof value.toJS === 'function' ? value.toJS() : value}
  3700. ).__toJS();
  3701. },
  3702. toJSON: function() {
  3703. return this.toSeq().map(
  3704. function(value ) {return value && typeof value.toJSON === 'function' ? value.toJSON() : value}
  3705. ).__toJS();
  3706. },
  3707. toKeyedSeq: function() {
  3708. return new ToKeyedSequence(this, true);
  3709. },
  3710. toMap: function() {
  3711. // Use Late Binding here to solve the circular dependency.
  3712. return Map(this.toKeyedSeq());
  3713. },
  3714. toObject: function() {
  3715. assertNotInfinite(this.size);
  3716. var object = {};
  3717. this.__iterate(function(v, k) { object[k] = v; });
  3718. return object;
  3719. },
  3720. toOrderedMap: function() {
  3721. // Use Late Binding here to solve the circular dependency.
  3722. return OrderedMap(this.toKeyedSeq());
  3723. },
  3724. toOrderedSet: function() {
  3725. // Use Late Binding here to solve the circular dependency.
  3726. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  3727. },
  3728. toSet: function() {
  3729. // Use Late Binding here to solve the circular dependency.
  3730. return Set(isKeyed(this) ? this.valueSeq() : this);
  3731. },
  3732. toSetSeq: function() {
  3733. return new ToSetSequence(this);
  3734. },
  3735. toSeq: function() {
  3736. return isIndexed(this) ? this.toIndexedSeq() :
  3737. isKeyed(this) ? this.toKeyedSeq() :
  3738. this.toSetSeq();
  3739. },
  3740. toStack: function() {
  3741. // Use Late Binding here to solve the circular dependency.
  3742. return Stack(isKeyed(this) ? this.valueSeq() : this);
  3743. },
  3744. toList: function() {
  3745. // Use Late Binding here to solve the circular dependency.
  3746. return List(isKeyed(this) ? this.valueSeq() : this);
  3747. },
  3748. // ### Common JavaScript methods and properties
  3749. toString: function() {
  3750. return '[Iterable]';
  3751. },
  3752. __toString: function(head, tail) {
  3753. if (this.size === 0) {
  3754. return head + tail;
  3755. }
  3756. return head + ' ' + this.toSeq().map(this.__toStringMapper).join(', ') + ' ' + tail;
  3757. },
  3758. // ### ES6 Collection methods (ES6 Array and Map)
  3759. concat: function() {var values = SLICE$0.call(arguments, 0);
  3760. return reify(this, concatFactory(this, values));
  3761. },
  3762. includes: function(searchValue) {
  3763. return this.some(function(value ) {return is(value, searchValue)});
  3764. },
  3765. entries: function() {
  3766. return this.__iterator(ITERATE_ENTRIES);
  3767. },
  3768. every: function(predicate, context) {
  3769. assertNotInfinite(this.size);
  3770. var returnValue = true;
  3771. this.__iterate(function(v, k, c) {
  3772. if (!predicate.call(context, v, k, c)) {
  3773. returnValue = false;
  3774. return false;
  3775. }
  3776. });
  3777. return returnValue;
  3778. },
  3779. filter: function(predicate, context) {
  3780. return reify(this, filterFactory(this, predicate, context, true));
  3781. },
  3782. find: function(predicate, context, notSetValue) {
  3783. var entry = this.findEntry(predicate, context);
  3784. return entry ? entry[1] : notSetValue;
  3785. },
  3786. findEntry: function(predicate, context) {
  3787. var found;
  3788. this.__iterate(function(v, k, c) {
  3789. if (predicate.call(context, v, k, c)) {
  3790. found = [k, v];
  3791. return false;
  3792. }
  3793. });
  3794. return found;
  3795. },
  3796. findLastEntry: function(predicate, context) {
  3797. return this.toSeq().reverse().findEntry(predicate, context);
  3798. },
  3799. forEach: function(sideEffect, context) {
  3800. assertNotInfinite(this.size);
  3801. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  3802. },
  3803. join: function(separator) {
  3804. assertNotInfinite(this.size);
  3805. separator = separator !== undefined ? '' + separator : ',';
  3806. var joined = '';
  3807. var isFirst = true;
  3808. this.__iterate(function(v ) {
  3809. isFirst ? (isFirst = false) : (joined += separator);
  3810. joined += v !== null && v !== undefined ? v.toString() : '';
  3811. });
  3812. return joined;
  3813. },
  3814. keys: function() {
  3815. return this.__iterator(ITERATE_KEYS);
  3816. },
  3817. map: function(mapper, context) {
  3818. return reify(this, mapFactory(this, mapper, context));
  3819. },
  3820. reduce: function(reducer, initialReduction, context) {
  3821. assertNotInfinite(this.size);
  3822. var reduction;
  3823. var useFirst;
  3824. if (arguments.length < 2) {
  3825. useFirst = true;
  3826. } else {
  3827. reduction = initialReduction;
  3828. }
  3829. this.__iterate(function(v, k, c) {
  3830. if (useFirst) {
  3831. useFirst = false;
  3832. reduction = v;
  3833. } else {
  3834. reduction = reducer.call(context, reduction, v, k, c);
  3835. }
  3836. });
  3837. return reduction;
  3838. },
  3839. reduceRight: function(reducer, initialReduction, context) {
  3840. var reversed = this.toKeyedSeq().reverse();
  3841. return reversed.reduce.apply(reversed, arguments);
  3842. },
  3843. reverse: function() {
  3844. return reify(this, reverseFactory(this, true));
  3845. },
  3846. slice: function(begin, end) {
  3847. return reify(this, sliceFactory(this, begin, end, true));
  3848. },
  3849. some: function(predicate, context) {
  3850. return !this.every(not(predicate), context);
  3851. },
  3852. sort: function(comparator) {
  3853. return reify(this, sortFactory(this, comparator));
  3854. },
  3855. values: function() {
  3856. return this.__iterator(ITERATE_VALUES);
  3857. },
  3858. // ### More sequential methods
  3859. butLast: function() {
  3860. return this.slice(0, -1);
  3861. },
  3862. isEmpty: function() {
  3863. return this.size !== undefined ? this.size === 0 : !this.some(function() {return true});
  3864. },
  3865. count: function(predicate, context) {
  3866. return ensureSize(
  3867. predicate ? this.toSeq().filter(predicate, context) : this
  3868. );
  3869. },
  3870. countBy: function(grouper, context) {
  3871. return countByFactory(this, grouper, context);
  3872. },
  3873. equals: function(other) {
  3874. return deepEqual(this, other);
  3875. },
  3876. entrySeq: function() {
  3877. var iterable = this;
  3878. if (iterable._cache) {
  3879. // We cache as an entries array, so we can just return the cache!
  3880. return new ArraySeq(iterable._cache);
  3881. }
  3882. var entriesSequence = iterable.toSeq().map(entryMapper).toIndexedSeq();
  3883. entriesSequence.fromEntrySeq = function() {return iterable.toSeq()};
  3884. return entriesSequence;
  3885. },
  3886. filterNot: function(predicate, context) {
  3887. return this.filter(not(predicate), context);
  3888. },
  3889. findLast: function(predicate, context, notSetValue) {
  3890. return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
  3891. },
  3892. first: function() {
  3893. return this.find(returnTrue);
  3894. },
  3895. flatMap: function(mapper, context) {
  3896. return reify(this, flatMapFactory(this, mapper, context));
  3897. },
  3898. flatten: function(depth) {
  3899. return reify(this, flattenFactory(this, depth, true));
  3900. },
  3901. fromEntrySeq: function() {
  3902. return new FromEntriesSequence(this);
  3903. },
  3904. get: function(searchKey, notSetValue) {
  3905. return this.find(function(_, key) {return is(key, searchKey)}, undefined, notSetValue);
  3906. },
  3907. getIn: function(searchKeyPath, notSetValue) {
  3908. var nested = this;
  3909. // Note: in an ES6 environment, we would prefer:
  3910. // for (var key of searchKeyPath) {
  3911. var iter = forceIterator(searchKeyPath);
  3912. var step;
  3913. while (!(step = iter.next()).done) {
  3914. var key = step.value;
  3915. nested = nested && nested.get ? nested.get(key, NOT_SET) : NOT_SET;
  3916. if (nested === NOT_SET) {
  3917. return notSetValue;
  3918. }
  3919. }
  3920. return nested;
  3921. },
  3922. groupBy: function(grouper, context) {
  3923. return groupByFactory(this, grouper, context);
  3924. },
  3925. has: function(searchKey) {
  3926. return this.get(searchKey, NOT_SET) !== NOT_SET;
  3927. },
  3928. hasIn: function(searchKeyPath) {
  3929. return this.getIn(searchKeyPath, NOT_SET) !== NOT_SET;
  3930. },
  3931. isSubset: function(iter) {
  3932. iter = typeof iter.includes === 'function' ? iter : Iterable(iter);
  3933. return this.every(function(value ) {return iter.includes(value)});
  3934. },
  3935. isSuperset: function(iter) {
  3936. iter = typeof iter.isSubset === 'function' ? iter : Iterable(iter);
  3937. return iter.isSubset(this);
  3938. },
  3939. keySeq: function() {
  3940. return this.toSeq().map(keyMapper).toIndexedSeq();
  3941. },
  3942. last: function() {
  3943. return this.toSeq().reverse().first();
  3944. },
  3945. max: function(comparator) {
  3946. return maxFactory(this, comparator);
  3947. },
  3948. maxBy: function(mapper, comparator) {
  3949. return maxFactory(this, comparator, mapper);
  3950. },
  3951. min: function(comparator) {
  3952. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator);
  3953. },
  3954. minBy: function(mapper, comparator) {
  3955. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator, mapper);
  3956. },
  3957. rest: function() {
  3958. return this.slice(1);
  3959. },
  3960. skip: function(amount) {
  3961. return this.slice(Math.max(0, amount));
  3962. },
  3963. skipLast: function(amount) {
  3964. return reify(this, this.toSeq().reverse().skip(amount).reverse());
  3965. },
  3966. skipWhile: function(predicate, context) {
  3967. return reify(this, skipWhileFactory(this, predicate, context, true));
  3968. },
  3969. skipUntil: function(predicate, context) {
  3970. return this.skipWhile(not(predicate), context);
  3971. },
  3972. sortBy: function(mapper, comparator) {
  3973. return reify(this, sortFactory(this, comparator, mapper));
  3974. },
  3975. take: function(amount) {
  3976. return this.slice(0, Math.max(0, amount));
  3977. },
  3978. takeLast: function(amount) {
  3979. return reify(this, this.toSeq().reverse().take(amount).reverse());
  3980. },
  3981. takeWhile: function(predicate, context) {
  3982. return reify(this, takeWhileFactory(this, predicate, context));
  3983. },
  3984. takeUntil: function(predicate, context) {
  3985. return this.takeWhile(not(predicate), context);
  3986. },
  3987. valueSeq: function() {
  3988. return this.toIndexedSeq();
  3989. },
  3990. // ### Hashable Object
  3991. hashCode: function() {
  3992. return this.__hash || (this.__hash = hashIterable(this));
  3993. }
  3994. // ### Internal
  3995. // abstract __iterate(fn, reverse)
  3996. // abstract __iterator(type, reverse)
  3997. });
  3998. // var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  3999. // var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  4000. // var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  4001. // var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  4002. var IterablePrototype = Iterable.prototype;
  4003. IterablePrototype[IS_ITERABLE_SENTINEL] = true;
  4004. IterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.values;
  4005. IterablePrototype.__toJS = IterablePrototype.toArray;
  4006. IterablePrototype.__toStringMapper = quoteString;
  4007. IterablePrototype.inspect =
  4008. IterablePrototype.toSource = function() { return this.toString(); };
  4009. IterablePrototype.chain = IterablePrototype.flatMap;
  4010. IterablePrototype.contains = IterablePrototype.includes;
  4011. // Temporary warning about using length
  4012. (function () {
  4013. try {
  4014. Object.defineProperty(IterablePrototype, 'length', {
  4015. get: function () {
  4016. if (!Iterable.noLengthWarning) {
  4017. var stack;
  4018. try {
  4019. throw new Error();
  4020. } catch (error) {
  4021. stack = error.stack;
  4022. }
  4023. if (stack.indexOf('_wrapObject') === -1) {
  4024. console && console.warn && console.warn(
  4025. 'iterable.length has been deprecated, '+
  4026. 'use iterable.size or iterable.count(). '+
  4027. 'This warning will become a silent error in a future version. ' +
  4028. stack
  4029. );
  4030. return this.size;
  4031. }
  4032. }
  4033. }
  4034. });
  4035. } catch (e) {}
  4036. })();
  4037. mixin(KeyedIterable, {
  4038. // ### More sequential methods
  4039. flip: function() {
  4040. return reify(this, flipFactory(this));
  4041. },
  4042. findKey: function(predicate, context) {
  4043. var entry = this.findEntry(predicate, context);
  4044. return entry && entry[0];
  4045. },
  4046. findLastKey: function(predicate, context) {
  4047. return this.toSeq().reverse().findKey(predicate, context);
  4048. },
  4049. keyOf: function(searchValue) {
  4050. return this.findKey(function(value ) {return is(value, searchValue)});
  4051. },
  4052. lastKeyOf: function(searchValue) {
  4053. return this.findLastKey(function(value ) {return is(value, searchValue)});
  4054. },
  4055. mapEntries: function(mapper, context) {var this$0 = this;
  4056. var iterations = 0;
  4057. return reify(this,
  4058. this.toSeq().map(
  4059. function(v, k) {return mapper.call(context, [k, v], iterations++, this$0)}
  4060. ).fromEntrySeq()
  4061. );
  4062. },
  4063. mapKeys: function(mapper, context) {var this$0 = this;
  4064. return reify(this,
  4065. this.toSeq().flip().map(
  4066. function(k, v) {return mapper.call(context, k, v, this$0)}
  4067. ).flip()
  4068. );
  4069. }
  4070. });
  4071. var KeyedIterablePrototype = KeyedIterable.prototype;
  4072. KeyedIterablePrototype[IS_KEYED_SENTINEL] = true;
  4073. KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries;
  4074. KeyedIterablePrototype.__toJS = IterablePrototype.toObject;
  4075. KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)};
  4076. mixin(IndexedIterable, {
  4077. // ### Conversion to other types
  4078. toKeyedSeq: function() {
  4079. return new ToKeyedSequence(this, false);
  4080. },
  4081. // ### ES6 Collection methods (ES6 Array and Map)
  4082. filter: function(predicate, context) {
  4083. return reify(this, filterFactory(this, predicate, context, false));
  4084. },
  4085. findIndex: function(predicate, context) {
  4086. var entry = this.findEntry(predicate, context);
  4087. return entry ? entry[0] : -1;
  4088. },
  4089. indexOf: function(searchValue) {
  4090. var key = this.toKeyedSeq().keyOf(searchValue);
  4091. return key === undefined ? -1 : key;
  4092. },
  4093. lastIndexOf: function(searchValue) {
  4094. var key = this.toKeyedSeq().reverse().keyOf(searchValue);
  4095. return key === undefined ? -1 : key;
  4096. // var index =
  4097. // return this.toSeq().reverse().indexOf(searchValue);
  4098. },
  4099. reverse: function() {
  4100. return reify(this, reverseFactory(this, false));
  4101. },
  4102. slice: function(begin, end) {
  4103. return reify(this, sliceFactory(this, begin, end, false));
  4104. },
  4105. splice: function(index, removeNum /*, ...values*/) {
  4106. var numArgs = arguments.length;
  4107. removeNum = Math.max(removeNum | 0, 0);
  4108. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  4109. return this;
  4110. }
  4111. // If index is negative, it should resolve relative to the size of the
  4112. // collection. However size may be expensive to compute if not cached, so
  4113. // only call count() if the number is in fact negative.
  4114. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  4115. var spliced = this.slice(0, index);
  4116. return reify(
  4117. this,
  4118. numArgs === 1 ?
  4119. spliced :
  4120. spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  4121. );
  4122. },
  4123. // ### More collection methods
  4124. findLastIndex: function(predicate, context) {
  4125. var key = this.toKeyedSeq().findLastKey(predicate, context);
  4126. return key === undefined ? -1 : key;
  4127. },
  4128. first: function() {
  4129. return this.get(0);
  4130. },
  4131. flatten: function(depth) {
  4132. return reify(this, flattenFactory(this, depth, false));
  4133. },
  4134. get: function(index, notSetValue) {
  4135. index = wrapIndex(this, index);
  4136. return (index < 0 || (this.size === Infinity ||
  4137. (this.size !== undefined && index > this.size))) ?
  4138. notSetValue :
  4139. this.find(function(_, key) {return key === index}, undefined, notSetValue);
  4140. },
  4141. has: function(index) {
  4142. index = wrapIndex(this, index);
  4143. return index >= 0 && (this.size !== undefined ?
  4144. this.size === Infinity || index < this.size :
  4145. this.indexOf(index) !== -1
  4146. );
  4147. },
  4148. interpose: function(separator) {
  4149. return reify(this, interposeFactory(this, separator));
  4150. },
  4151. interleave: function(/*...iterables*/) {
  4152. var iterables = [this].concat(arrCopy(arguments));
  4153. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, iterables);
  4154. var interleaved = zipped.flatten(true);
  4155. if (zipped.size) {
  4156. interleaved.size = zipped.size * iterables.length;
  4157. }
  4158. return reify(this, interleaved);
  4159. },
  4160. last: function() {
  4161. return this.get(-1);
  4162. },
  4163. skipWhile: function(predicate, context) {
  4164. return reify(this, skipWhileFactory(this, predicate, context, false));
  4165. },
  4166. zip: function(/*, ...iterables */) {
  4167. var iterables = [this].concat(arrCopy(arguments));
  4168. return reify(this, zipWithFactory(this, defaultZipper, iterables));
  4169. },
  4170. zipWith: function(zipper/*, ...iterables */) {
  4171. var iterables = arrCopy(arguments);
  4172. iterables[0] = this;
  4173. return reify(this, zipWithFactory(this, zipper, iterables));
  4174. }
  4175. });
  4176. IndexedIterable.prototype[IS_INDEXED_SENTINEL] = true;
  4177. IndexedIterable.prototype[IS_ORDERED_SENTINEL] = true;
  4178. mixin(SetIterable, {
  4179. // ### ES6 Collection methods (ES6 Array and Map)
  4180. get: function(value, notSetValue) {
  4181. return this.has(value) ? value : notSetValue;
  4182. },
  4183. includes: function(value) {
  4184. return this.has(value);
  4185. },
  4186. // ### More sequential methods
  4187. keySeq: function() {
  4188. return this.valueSeq();
  4189. }
  4190. });
  4191. SetIterable.prototype.has = IterablePrototype.includes;
  4192. // Mixin subclasses
  4193. mixin(KeyedSeq, KeyedIterable.prototype);
  4194. mixin(IndexedSeq, IndexedIterable.prototype);
  4195. mixin(SetSeq, SetIterable.prototype);
  4196. mixin(KeyedCollection, KeyedIterable.prototype);
  4197. mixin(IndexedCollection, IndexedIterable.prototype);
  4198. mixin(SetCollection, SetIterable.prototype);
  4199. // #pragma Helper functions
  4200. function keyMapper(v, k) {
  4201. return k;
  4202. }
  4203. function entryMapper(v, k) {
  4204. return [k, v];
  4205. }
  4206. function not(predicate) {
  4207. return function() {
  4208. return !predicate.apply(this, arguments);
  4209. }
  4210. }
  4211. function neg(predicate) {
  4212. return function() {
  4213. return -predicate.apply(this, arguments);
  4214. }
  4215. }
  4216. function quoteString(value) {
  4217. return typeof value === 'string' ? JSON.stringify(value) : value;
  4218. }
  4219. function defaultZipper() {
  4220. return arrCopy(arguments);
  4221. }
  4222. function defaultNegComparator(a, b) {
  4223. return a < b ? 1 : a > b ? -1 : 0;
  4224. }
  4225. function hashIterable(iterable) {
  4226. if (iterable.size === Infinity) {
  4227. return 0;
  4228. }
  4229. var ordered = isOrdered(iterable);
  4230. var keyed = isKeyed(iterable);
  4231. var h = ordered ? 1 : 0;
  4232. var size = iterable.__iterate(
  4233. keyed ?
  4234. ordered ?
  4235. function(v, k) { h = 31 * h + hashMerge(hash(v), hash(k)) | 0; } :
  4236. function(v, k) { h = h + hashMerge(hash(v), hash(k)) | 0; } :
  4237. ordered ?
  4238. function(v ) { h = 31 * h + hash(v) | 0; } :
  4239. function(v ) { h = h + hash(v) | 0; }
  4240. );
  4241. return murmurHashOfSize(size, h);
  4242. }
  4243. function murmurHashOfSize(size, h) {
  4244. h = imul(h, 0xCC9E2D51);
  4245. h = imul(h << 15 | h >>> -15, 0x1B873593);
  4246. h = imul(h << 13 | h >>> -13, 5);
  4247. h = (h + 0xE6546B64 | 0) ^ size;
  4248. h = imul(h ^ h >>> 16, 0x85EBCA6B);
  4249. h = imul(h ^ h >>> 13, 0xC2B2AE35);
  4250. h = smi(h ^ h >>> 16);
  4251. return h;
  4252. }
  4253. function hashMerge(a, b) {
  4254. return a ^ b + 0x9E3779B9 + (a << 6) + (a >> 2) | 0; // int
  4255. }
  4256. var Immutable = {
  4257. Iterable: Iterable,
  4258. Seq: Seq,
  4259. Collection: Collection,
  4260. Map: Map,
  4261. OrderedMap: OrderedMap,
  4262. List: List,
  4263. Stack: Stack,
  4264. Set: Set,
  4265. OrderedSet: OrderedSet,
  4266. Record: Record,
  4267. Range: Range,
  4268. Repeat: Repeat,
  4269. is: is,
  4270. fromJS: fromJS
  4271. };
  4272. return Immutable;
  4273. }));
  4274. });
  4275. var OrderedMap = immutable.OrderedMap;
  4276. var BlockMapBuilder = {
  4277. createFromArray: function createFromArray(blocks) {
  4278. return OrderedMap(blocks.map(function (block) {
  4279. return [block.getKey(), block];
  4280. }));
  4281. }
  4282. };
  4283. var BlockMapBuilder_1 = BlockMapBuilder;
  4284. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4285. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4286. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4287. var Map = immutable.Map,
  4288. OrderedSet = immutable.OrderedSet,
  4289. Record = immutable.Record;
  4290. // Immutable.map is typed such that the value for every key in the map
  4291. // must be the same type
  4292. var EMPTY_SET = OrderedSet();
  4293. var defaultRecord = {
  4294. style: EMPTY_SET,
  4295. entity: null
  4296. };
  4297. var CharacterMetadataRecord = Record(defaultRecord);
  4298. var CharacterMetadata = function (_CharacterMetadataRec) {
  4299. _inherits(CharacterMetadata, _CharacterMetadataRec);
  4300. function CharacterMetadata() {
  4301. _classCallCheck(this, CharacterMetadata);
  4302. return _possibleConstructorReturn(this, _CharacterMetadataRec.apply(this, arguments));
  4303. }
  4304. CharacterMetadata.prototype.getStyle = function getStyle() {
  4305. return this.get('style');
  4306. };
  4307. CharacterMetadata.prototype.getEntity = function getEntity() {
  4308. return this.get('entity');
  4309. };
  4310. CharacterMetadata.prototype.hasStyle = function hasStyle(style) {
  4311. return this.getStyle().includes(style);
  4312. };
  4313. CharacterMetadata.applyStyle = function applyStyle(record, style) {
  4314. var withStyle = record.set('style', record.getStyle().add(style));
  4315. return CharacterMetadata.create(withStyle);
  4316. };
  4317. CharacterMetadata.removeStyle = function removeStyle(record, style) {
  4318. var withoutStyle = record.set('style', record.getStyle().remove(style));
  4319. return CharacterMetadata.create(withoutStyle);
  4320. };
  4321. CharacterMetadata.applyEntity = function applyEntity(record, entityKey) {
  4322. var withEntity = record.getEntity() === entityKey ? record : record.set('entity', entityKey);
  4323. return CharacterMetadata.create(withEntity);
  4324. };
  4325. /**
  4326. * Use this function instead of the `CharacterMetadata` constructor.
  4327. * Since most content generally uses only a very small number of
  4328. * style/entity permutations, we can reuse these objects as often as
  4329. * possible.
  4330. */
  4331. CharacterMetadata.create = function create(config) {
  4332. if (!config) {
  4333. return EMPTY;
  4334. }
  4335. var defaultConfig = {
  4336. style: EMPTY_SET,
  4337. entity: null
  4338. };
  4339. // Fill in unspecified properties, if necessary.
  4340. var configMap = Map(defaultConfig).merge(config);
  4341. var existing = pool.get(configMap);
  4342. if (existing) {
  4343. return existing;
  4344. }
  4345. var newCharacter = new CharacterMetadata(configMap);
  4346. pool = pool.set(configMap, newCharacter);
  4347. return newCharacter;
  4348. };
  4349. return CharacterMetadata;
  4350. }(CharacterMetadataRecord);
  4351. var EMPTY = new CharacterMetadata();
  4352. var pool = Map([[Map(defaultRecord), EMPTY]]);
  4353. CharacterMetadata.EMPTY = EMPTY;
  4354. var CharacterMetadata_1 = CharacterMetadata;
  4355. /**
  4356. * Copyright (c) 2013-present, Facebook, Inc.
  4357. * All rights reserved.
  4358. *
  4359. * This source code is licensed under the BSD-style license found in the
  4360. * LICENSE file in the root directory of this source tree. An additional grant
  4361. * of patent rights can be found in the PATENTS file in the same directory.
  4362. *
  4363. * @providesModule findRangesImmutable
  4364. * @format
  4365. *
  4366. */
  4367. /**
  4368. * Search through an array to find contiguous stretches of elements that
  4369. * match a specified filter function.
  4370. *
  4371. * When ranges are found, execute a specified `found` function to supply
  4372. * the values to the caller.
  4373. */
  4374. function findRangesImmutable(haystack, areEqualFn, filterFn, foundFn) {
  4375. if (!haystack.size) {
  4376. return;
  4377. }
  4378. var cursor = 0;
  4379. haystack.reduce(function (value, nextValue, nextIndex) {
  4380. if (!areEqualFn(value, nextValue)) {
  4381. if (filterFn(value)) {
  4382. foundFn(cursor, nextIndex);
  4383. }
  4384. cursor = nextIndex;
  4385. }
  4386. return nextValue;
  4387. });
  4388. filterFn(haystack.last()) && foundFn(cursor, haystack.count());
  4389. }
  4390. var findRangesImmutable_1 = findRangesImmutable;
  4391. function _classCallCheck$1(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4392. function _possibleConstructorReturn$1(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4393. function _inherits$1(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4394. var List = immutable.List,
  4395. Map$1 = immutable.Map,
  4396. OrderedSet$1 = immutable.OrderedSet,
  4397. Record$1 = immutable.Record,
  4398. Repeat = immutable.Repeat;
  4399. var EMPTY_SET$1 = OrderedSet$1();
  4400. var defaultRecord$1 = {
  4401. key: '',
  4402. type: 'unstyled',
  4403. text: '',
  4404. characterList: List(),
  4405. depth: 0,
  4406. data: Map$1()
  4407. };
  4408. var ContentBlockRecord = Record$1(defaultRecord$1);
  4409. var decorateCharacterList = function decorateCharacterList(config) {
  4410. if (!config) {
  4411. return config;
  4412. }
  4413. var characterList = config.characterList,
  4414. text = config.text;
  4415. if (text && !characterList) {
  4416. config.characterList = List(Repeat(CharacterMetadata_1.EMPTY, text.length));
  4417. }
  4418. return config;
  4419. };
  4420. var ContentBlock = function (_ContentBlockRecord) {
  4421. _inherits$1(ContentBlock, _ContentBlockRecord);
  4422. function ContentBlock(config) {
  4423. _classCallCheck$1(this, ContentBlock);
  4424. return _possibleConstructorReturn$1(this, _ContentBlockRecord.call(this, decorateCharacterList(config)));
  4425. }
  4426. ContentBlock.prototype.getKey = function getKey() {
  4427. return this.get('key');
  4428. };
  4429. ContentBlock.prototype.getType = function getType() {
  4430. return this.get('type');
  4431. };
  4432. ContentBlock.prototype.getText = function getText() {
  4433. return this.get('text');
  4434. };
  4435. ContentBlock.prototype.getCharacterList = function getCharacterList() {
  4436. return this.get('characterList');
  4437. };
  4438. ContentBlock.prototype.getLength = function getLength() {
  4439. return this.getText().length;
  4440. };
  4441. ContentBlock.prototype.getDepth = function getDepth() {
  4442. return this.get('depth');
  4443. };
  4444. ContentBlock.prototype.getData = function getData() {
  4445. return this.get('data');
  4446. };
  4447. ContentBlock.prototype.getInlineStyleAt = function getInlineStyleAt(offset) {
  4448. var character = this.getCharacterList().get(offset);
  4449. return character ? character.getStyle() : EMPTY_SET$1;
  4450. };
  4451. ContentBlock.prototype.getEntityAt = function getEntityAt(offset) {
  4452. var character = this.getCharacterList().get(offset);
  4453. return character ? character.getEntity() : null;
  4454. };
  4455. /**
  4456. * Execute a callback for every contiguous range of styles within the block.
  4457. */
  4458. ContentBlock.prototype.findStyleRanges = function findStyleRanges(filterFn, callback) {
  4459. findRangesImmutable_1(this.getCharacterList(), haveEqualStyle, filterFn, callback);
  4460. };
  4461. /**
  4462. * Execute a callback for every contiguous range of entities within the block.
  4463. */
  4464. ContentBlock.prototype.findEntityRanges = function findEntityRanges(filterFn, callback) {
  4465. findRangesImmutable_1(this.getCharacterList(), haveEqualEntity, filterFn, callback);
  4466. };
  4467. return ContentBlock;
  4468. }(ContentBlockRecord);
  4469. function haveEqualStyle(charA, charB) {
  4470. return charA.getStyle() === charB.getStyle();
  4471. }
  4472. function haveEqualEntity(charA, charB) {
  4473. return charA.getEntity() === charB.getEntity();
  4474. }
  4475. var ContentBlock_1 = ContentBlock;
  4476. function _classCallCheck$2(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4477. function _possibleConstructorReturn$2(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4478. function _inherits$2(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4479. var List$1 = immutable.List,
  4480. Map$2 = immutable.Map,
  4481. OrderedSet$2 = immutable.OrderedSet,
  4482. Record$2 = immutable.Record,
  4483. Repeat$1 = immutable.Repeat;
  4484. var EMPTY_SET$2 = OrderedSet$2();
  4485. var defaultRecord$2 = {
  4486. parent: null,
  4487. characterList: List$1(),
  4488. data: Map$2(),
  4489. depth: 0,
  4490. key: '',
  4491. text: '',
  4492. type: 'unstyled',
  4493. children: List$1(),
  4494. prevSibling: null,
  4495. nextSibling: null
  4496. };
  4497. var haveEqualStyle$1 = function haveEqualStyle(charA, charB) {
  4498. return charA.getStyle() === charB.getStyle();
  4499. };
  4500. var haveEqualEntity$1 = function haveEqualEntity(charA, charB) {
  4501. return charA.getEntity() === charB.getEntity();
  4502. };
  4503. var decorateCharacterList$1 = function decorateCharacterList(config) {
  4504. if (!config) {
  4505. return config;
  4506. }
  4507. var characterList = config.characterList,
  4508. text = config.text;
  4509. if (text && !characterList) {
  4510. config.characterList = List$1(Repeat$1(CharacterMetadata_1.EMPTY, text.length));
  4511. }
  4512. return config;
  4513. };
  4514. var ContentBlockNode = function (_Record) {
  4515. _inherits$2(ContentBlockNode, _Record);
  4516. function ContentBlockNode() {
  4517. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultRecord$2;
  4518. _classCallCheck$2(this, ContentBlockNode);
  4519. return _possibleConstructorReturn$2(this, _Record.call(this, decorateCharacterList$1(props)));
  4520. }
  4521. ContentBlockNode.prototype.getKey = function getKey() {
  4522. return this.get('key');
  4523. };
  4524. ContentBlockNode.prototype.getType = function getType() {
  4525. return this.get('type');
  4526. };
  4527. ContentBlockNode.prototype.getText = function getText() {
  4528. return this.get('text');
  4529. };
  4530. ContentBlockNode.prototype.getCharacterList = function getCharacterList() {
  4531. return this.get('characterList');
  4532. };
  4533. ContentBlockNode.prototype.getLength = function getLength() {
  4534. return this.getText().length;
  4535. };
  4536. ContentBlockNode.prototype.getDepth = function getDepth() {
  4537. return this.get('depth');
  4538. };
  4539. ContentBlockNode.prototype.getData = function getData() {
  4540. return this.get('data');
  4541. };
  4542. ContentBlockNode.prototype.getInlineStyleAt = function getInlineStyleAt(offset) {
  4543. var character = this.getCharacterList().get(offset);
  4544. return character ? character.getStyle() : EMPTY_SET$2;
  4545. };
  4546. ContentBlockNode.prototype.getEntityAt = function getEntityAt(offset) {
  4547. var character = this.getCharacterList().get(offset);
  4548. return character ? character.getEntity() : null;
  4549. };
  4550. ContentBlockNode.prototype.getChildKeys = function getChildKeys() {
  4551. return this.get('children');
  4552. };
  4553. ContentBlockNode.prototype.getParentKey = function getParentKey() {
  4554. return this.get('parent');
  4555. };
  4556. ContentBlockNode.prototype.getPrevSiblingKey = function getPrevSiblingKey() {
  4557. return this.get('prevSibling');
  4558. };
  4559. ContentBlockNode.prototype.getNextSiblingKey = function getNextSiblingKey() {
  4560. return this.get('nextSibling');
  4561. };
  4562. ContentBlockNode.prototype.findStyleRanges = function findStyleRanges(filterFn, callback) {
  4563. findRangesImmutable_1(this.getCharacterList(), haveEqualStyle$1, filterFn, callback);
  4564. };
  4565. ContentBlockNode.prototype.findEntityRanges = function findEntityRanges(filterFn, callback) {
  4566. findRangesImmutable_1(this.getCharacterList(), haveEqualEntity$1, filterFn, callback);
  4567. };
  4568. return ContentBlockNode;
  4569. }(Record$2(defaultRecord$2));
  4570. var ContentBlockNode_1 = ContentBlockNode;
  4571. /**
  4572. * Copyright 2013-present, Facebook, Inc.
  4573. * All rights reserved.
  4574. *
  4575. * This source code is licensed under the BSD-style license found in the
  4576. * LICENSE file in the root directory of this source tree. An additional grant
  4577. * of patent rights can be found in the PATENTS file in the same directory.
  4578. *
  4579. * @providesModule DraftFeatureFlags-core
  4580. * @format
  4581. *
  4582. */
  4583. var DraftFeatureFlags = {
  4584. draft_killswitch_allow_nontextnodes: false,
  4585. draft_segmented_entities_behavior: false,
  4586. draft_handlebeforeinput_composed_text: false,
  4587. draft_tree_data_support: false
  4588. };
  4589. var DraftFeatureFlagsCore = DraftFeatureFlags;
  4590. var DraftFeatureFlags_1 = DraftFeatureFlagsCore;
  4591. var Map$3 = immutable.Map;
  4592. var ContentStateInlineStyle = {
  4593. add: function add(contentState, selectionState, inlineStyle) {
  4594. return modifyInlineStyle(contentState, selectionState, inlineStyle, true);
  4595. },
  4596. remove: function remove(contentState, selectionState, inlineStyle) {
  4597. return modifyInlineStyle(contentState, selectionState, inlineStyle, false);
  4598. }
  4599. };
  4600. function modifyInlineStyle(contentState, selectionState, inlineStyle, addOrRemove) {
  4601. var blockMap = contentState.getBlockMap();
  4602. var startKey = selectionState.getStartKey();
  4603. var startOffset = selectionState.getStartOffset();
  4604. var endKey = selectionState.getEndKey();
  4605. var endOffset = selectionState.getEndOffset();
  4606. var newBlocks = blockMap.skipUntil(function (_, k) {
  4607. return k === startKey;
  4608. }).takeUntil(function (_, k) {
  4609. return k === endKey;
  4610. }).concat(Map$3([[endKey, blockMap.get(endKey)]])).map(function (block, blockKey) {
  4611. var sliceStart;
  4612. var sliceEnd;
  4613. if (startKey === endKey) {
  4614. sliceStart = startOffset;
  4615. sliceEnd = endOffset;
  4616. } else {
  4617. sliceStart = blockKey === startKey ? startOffset : 0;
  4618. sliceEnd = blockKey === endKey ? endOffset : block.getLength();
  4619. }
  4620. var chars = block.getCharacterList();
  4621. var current;
  4622. while (sliceStart < sliceEnd) {
  4623. current = chars.get(sliceStart);
  4624. chars = chars.set(sliceStart, addOrRemove ? CharacterMetadata_1.applyStyle(current, inlineStyle) : CharacterMetadata_1.removeStyle(current, inlineStyle));
  4625. sliceStart++;
  4626. }
  4627. return block.set('characterList', chars);
  4628. });
  4629. return contentState.merge({
  4630. blockMap: blockMap.merge(newBlocks),
  4631. selectionBefore: selectionState,
  4632. selectionAfter: selectionState
  4633. });
  4634. }
  4635. var ContentStateInlineStyle_1 = ContentStateInlineStyle;
  4636. function applyEntityToContentBlock(contentBlock, start, end, entityKey) {
  4637. var characterList = contentBlock.getCharacterList();
  4638. while (start < end) {
  4639. characterList = characterList.set(start, CharacterMetadata_1.applyEntity(characterList.get(start), entityKey));
  4640. start++;
  4641. }
  4642. return contentBlock.set('characterList', characterList);
  4643. }
  4644. var applyEntityToContentBlock_1 = applyEntityToContentBlock;
  4645. function applyEntityToContentState(contentState, selectionState, entityKey) {
  4646. var blockMap = contentState.getBlockMap();
  4647. var startKey = selectionState.getStartKey();
  4648. var startOffset = selectionState.getStartOffset();
  4649. var endKey = selectionState.getEndKey();
  4650. var endOffset = selectionState.getEndOffset();
  4651. var newBlocks = blockMap.skipUntil(function (_, k) {
  4652. return k === startKey;
  4653. }).takeUntil(function (_, k) {
  4654. return k === endKey;
  4655. }).toOrderedMap().merge(immutable.OrderedMap([[endKey, blockMap.get(endKey)]])).map(function (block, blockKey) {
  4656. var sliceStart = blockKey === startKey ? startOffset : 0;
  4657. var sliceEnd = blockKey === endKey ? endOffset : block.getLength();
  4658. return applyEntityToContentBlock_1(block, sliceStart, sliceEnd, entityKey);
  4659. });
  4660. return contentState.merge({
  4661. blockMap: blockMap.merge(newBlocks),
  4662. selectionBefore: selectionState,
  4663. selectionAfter: selectionState
  4664. });
  4665. }
  4666. var applyEntityToContentState_1 = applyEntityToContentState;
  4667. /**
  4668. * Copyright (c) 2013-present, Facebook, Inc.
  4669. * All rights reserved.
  4670. *
  4671. * This source code is licensed under the BSD-style license found in the
  4672. * LICENSE file in the root directory of this source tree. An additional grant
  4673. * of patent rights can be found in the PATENTS file in the same directory.
  4674. *
  4675. * @providesModule DraftEntitySegments
  4676. * @format
  4677. *
  4678. */
  4679. /**
  4680. * Identify the range to delete from a segmented entity.
  4681. *
  4682. * Rules:
  4683. *
  4684. * Example: 'John F. Kennedy'
  4685. *
  4686. * - Deletion from within any non-whitespace (i.e. ['John', 'F.', 'Kennedy'])
  4687. * will return the range of that text.
  4688. *
  4689. * 'John F. Kennedy' -> 'John F.'
  4690. * ^
  4691. *
  4692. * - Forward deletion of whitespace will remove the following section:
  4693. *
  4694. * 'John F. Kennedy' -> 'John Kennedy'
  4695. * ^
  4696. *
  4697. * - Backward deletion of whitespace will remove the previous section:
  4698. *
  4699. * 'John F. Kennedy' -> 'F. Kennedy'
  4700. * ^
  4701. */
  4702. var DraftEntitySegments = {
  4703. getRemovalRange: function getRemovalRange(selectionStart, selectionEnd, text, entityStart, direction) {
  4704. var segments = text.split(' ');
  4705. segments = segments.map(function ( /*string*/segment, /*number*/ii) {
  4706. if (direction === 'forward') {
  4707. if (ii > 0) {
  4708. return ' ' + segment;
  4709. }
  4710. } else if (ii < segments.length - 1) {
  4711. return segment + ' ';
  4712. }
  4713. return segment;
  4714. });
  4715. var segmentStart = entityStart;
  4716. var segmentEnd;
  4717. var segment;
  4718. var removalStart = null;
  4719. var removalEnd = null;
  4720. for (var jj = 0; jj < segments.length; jj++) {
  4721. segment = segments[jj];
  4722. segmentEnd = segmentStart + segment.length;
  4723. // Our selection overlaps this segment.
  4724. if (selectionStart < segmentEnd && segmentStart < selectionEnd) {
  4725. if (removalStart !== null) {
  4726. removalEnd = segmentEnd;
  4727. } else {
  4728. removalStart = segmentStart;
  4729. removalEnd = segmentEnd;
  4730. }
  4731. } else if (removalStart !== null) {
  4732. break;
  4733. }
  4734. segmentStart = segmentEnd;
  4735. }
  4736. var entityEnd = entityStart + text.length;
  4737. var atStart = removalStart === entityStart;
  4738. var atEnd = removalEnd === entityEnd;
  4739. if (!atStart && atEnd || atStart && !atEnd) {
  4740. if (direction === 'forward') {
  4741. if (removalEnd !== entityEnd) {
  4742. removalEnd++;
  4743. }
  4744. } else if (removalStart !== entityStart) {
  4745. removalStart--;
  4746. }
  4747. }
  4748. return {
  4749. start: removalStart,
  4750. end: removalEnd
  4751. };
  4752. }
  4753. };
  4754. var DraftEntitySegments_1 = DraftEntitySegments;
  4755. /**
  4756. * Copyright (c) 2013-present, Facebook, Inc.
  4757. *
  4758. * This source code is licensed under the MIT license found in the
  4759. * LICENSE file in the root directory of this source tree.
  4760. *
  4761. */
  4762. /**
  4763. * Use invariant() to assert state which your program assumes to be true.
  4764. *
  4765. * Provide sprintf-style format (only %s is supported) and arguments
  4766. * to provide information about what broke and what you were
  4767. * expecting.
  4768. *
  4769. * The invariant message will be stripped in production, but the invariant
  4770. * will remain to ensure logic does not differ in production.
  4771. */
  4772. var validateFormat = function validateFormat(format) {};
  4773. if (process.env.NODE_ENV !== 'production') {
  4774. validateFormat = function validateFormat(format) {
  4775. if (format === undefined) {
  4776. throw new Error('invariant requires an error message argument');
  4777. }
  4778. };
  4779. }
  4780. function invariant(condition, format, a, b, c, d, e, f) {
  4781. validateFormat(format);
  4782. if (!condition) {
  4783. var error;
  4784. if (format === undefined) {
  4785. error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
  4786. } else {
  4787. var args = [a, b, c, d, e, f];
  4788. var argIndex = 0;
  4789. error = new Error(format.replace(/%s/g, function () {
  4790. return args[argIndex++];
  4791. }));
  4792. error.name = 'Invariant Violation';
  4793. }
  4794. error.framesToPop = 1; // we don't care about invariant's own frame
  4795. throw error;
  4796. }
  4797. }
  4798. var invariant_1 = invariant;
  4799. /**
  4800. * Obtain the start and end positions of the range that has the
  4801. * specified entity applied to it.
  4802. *
  4803. * Entity keys are applied only to contiguous stretches of text, so this
  4804. * method searches for the first instance of the entity key and returns
  4805. * the subsequent range.
  4806. */
  4807. function getRangesForDraftEntity(block, key) {
  4808. var ranges = [];
  4809. block.findEntityRanges(function (c) {
  4810. return c.getEntity() === key;
  4811. }, function (start, end) {
  4812. ranges.push({ start: start, end: end });
  4813. });
  4814. !!!ranges.length ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Entity key not found in this range.') : invariant_1(false) : void 0;
  4815. return ranges;
  4816. }
  4817. var getRangesForDraftEntity_1 = getRangesForDraftEntity;
  4818. /**
  4819. * Given a SelectionState and a removal direction, determine the entire range
  4820. * that should be removed from a ContentState. This is based on any entities
  4821. * within the target, with their `mutability` values taken into account.
  4822. *
  4823. * For instance, if we are attempting to remove part of an "immutable" entity
  4824. * range, the entire entity must be removed. The returned `SelectionState`
  4825. * will be adjusted accordingly.
  4826. */
  4827. function getCharacterRemovalRange(entityMap, startBlock, endBlock, selectionState, direction) {
  4828. var start = selectionState.getStartOffset();
  4829. var end = selectionState.getEndOffset();
  4830. var startEntityKey = startBlock.getEntityAt(start);
  4831. var endEntityKey = endBlock.getEntityAt(end - 1);
  4832. if (!startEntityKey && !endEntityKey) {
  4833. return selectionState;
  4834. }
  4835. var newSelectionState = selectionState;
  4836. if (startEntityKey && startEntityKey === endEntityKey) {
  4837. newSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, true, true);
  4838. } else if (startEntityKey && endEntityKey) {
  4839. var startSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, false, true);
  4840. var endSelectionState = getEntityRemovalRange(entityMap, endBlock, newSelectionState, direction, endEntityKey, false, false);
  4841. newSelectionState = newSelectionState.merge({
  4842. anchorOffset: startSelectionState.getAnchorOffset(),
  4843. focusOffset: endSelectionState.getFocusOffset(),
  4844. isBackward: false
  4845. });
  4846. } else if (startEntityKey) {
  4847. var _startSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, false, true);
  4848. newSelectionState = newSelectionState.merge({
  4849. anchorOffset: _startSelectionState.getStartOffset(),
  4850. isBackward: false
  4851. });
  4852. } else if (endEntityKey) {
  4853. var _endSelectionState = getEntityRemovalRange(entityMap, endBlock, newSelectionState, direction, endEntityKey, false, false);
  4854. newSelectionState = newSelectionState.merge({
  4855. focusOffset: _endSelectionState.getEndOffset(),
  4856. isBackward: false
  4857. });
  4858. }
  4859. return newSelectionState;
  4860. }
  4861. function getEntityRemovalRange(entityMap, block, selectionState, direction, entityKey, isEntireSelectionWithinEntity, isEntityAtStart) {
  4862. var start = selectionState.getStartOffset();
  4863. var end = selectionState.getEndOffset();
  4864. var entity = entityMap.__get(entityKey);
  4865. var mutability = entity.getMutability();
  4866. var sideToConsider = isEntityAtStart ? start : end;
  4867. // `MUTABLE` entities can just have the specified range of text removed
  4868. // directly. No adjustments are needed.
  4869. if (mutability === 'MUTABLE') {
  4870. return selectionState;
  4871. }
  4872. // Find the entity range that overlaps with our removal range.
  4873. var entityRanges = getRangesForDraftEntity_1(block, entityKey).filter(function (range) {
  4874. return sideToConsider <= range.end && sideToConsider >= range.start;
  4875. });
  4876. !(entityRanges.length == 1) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'There should only be one entity range within this removal range.') : invariant_1(false) : void 0;
  4877. var entityRange = entityRanges[0];
  4878. // For `IMMUTABLE` entity types, we will remove the entire entity range.
  4879. if (mutability === 'IMMUTABLE') {
  4880. return selectionState.merge({
  4881. anchorOffset: entityRange.start,
  4882. focusOffset: entityRange.end,
  4883. isBackward: false
  4884. });
  4885. }
  4886. // For `SEGMENTED` entity types, determine the appropriate segment to
  4887. // remove.
  4888. if (!isEntireSelectionWithinEntity) {
  4889. if (isEntityAtStart) {
  4890. end = entityRange.end;
  4891. } else {
  4892. start = entityRange.start;
  4893. }
  4894. }
  4895. var removalRange = DraftEntitySegments_1.getRemovalRange(start, end, block.getText().slice(entityRange.start, entityRange.end), entityRange.start, direction);
  4896. return selectionState.merge({
  4897. anchorOffset: removalRange.start,
  4898. focusOffset: removalRange.end,
  4899. isBackward: false
  4900. });
  4901. }
  4902. var getCharacterRemovalRange_1 = getCharacterRemovalRange;
  4903. /**
  4904. * Copyright (c) 2013-present, Facebook, Inc.
  4905. * All rights reserved.
  4906. *
  4907. * This source code is licensed under the BSD-style license found in the
  4908. * LICENSE file in the root directory of this source tree. An additional grant
  4909. * of patent rights can be found in the PATENTS file in the same directory.
  4910. *
  4911. * @providesModule generateRandomKey
  4912. * @format
  4913. *
  4914. */
  4915. var seenKeys = {};
  4916. var MULTIPLIER = Math.pow(2, 24);
  4917. function generateRandomKey() {
  4918. var key = void 0;
  4919. while (key === undefined || seenKeys.hasOwnProperty(key) || !isNaN(+key)) {
  4920. key = Math.floor(Math.random() * MULTIPLIER).toString(32);
  4921. }
  4922. seenKeys[key] = true;
  4923. return key;
  4924. }
  4925. var generateRandomKey_1 = generateRandomKey;
  4926. var OrderedMap$1 = immutable.OrderedMap;
  4927. var randomizeContentBlockNodeKeys = function randomizeContentBlockNodeKeys(blockMap) {
  4928. var newKeysRef = {};
  4929. // we keep track of root blocks in order to update subsequent sibling links
  4930. var lastRootBlock = void 0;
  4931. return OrderedMap$1(blockMap.withMutations(function (blockMapState) {
  4932. blockMapState.forEach(function (block, index) {
  4933. var oldKey = block.getKey();
  4934. var nextKey = block.getNextSiblingKey();
  4935. var prevKey = block.getPrevSiblingKey();
  4936. var childrenKeys = block.getChildKeys();
  4937. var parentKey = block.getParentKey();
  4938. // new key that we will use to build linking
  4939. var key = generateRandomKey_1();
  4940. // we will add it here to re-use it later
  4941. newKeysRef[oldKey] = key;
  4942. if (nextKey) {
  4943. var nextBlock = blockMapState.get(nextKey);
  4944. if (nextBlock) {
  4945. blockMapState.setIn([nextKey, 'prevSibling'], key);
  4946. } else {
  4947. // this can happen when generating random keys for fragments
  4948. blockMapState.setIn([oldKey, 'nextSibling'], null);
  4949. }
  4950. }
  4951. if (prevKey) {
  4952. var prevBlock = blockMapState.get(prevKey);
  4953. if (prevBlock) {
  4954. blockMapState.setIn([prevKey, 'nextSibling'], key);
  4955. } else {
  4956. // this can happen when generating random keys for fragments
  4957. blockMapState.setIn([oldKey, 'prevSibling'], null);
  4958. }
  4959. }
  4960. if (parentKey && blockMapState.get(parentKey)) {
  4961. var parentBlock = blockMapState.get(parentKey);
  4962. var parentChildrenList = parentBlock.getChildKeys();
  4963. blockMapState.setIn([parentKey, 'children'], parentChildrenList.set(parentChildrenList.indexOf(block.getKey()), key));
  4964. } else {
  4965. // blocks will then be treated as root block nodes
  4966. blockMapState.setIn([oldKey, 'parent'], null);
  4967. if (lastRootBlock) {
  4968. blockMapState.setIn([lastRootBlock.getKey(), 'nextSibling'], key);
  4969. blockMapState.setIn([oldKey, 'prevSibling'], newKeysRef[lastRootBlock.getKey()]);
  4970. }
  4971. lastRootBlock = blockMapState.get(oldKey);
  4972. }
  4973. childrenKeys.forEach(function (childKey) {
  4974. var childBlock = blockMapState.get(childKey);
  4975. if (childBlock) {
  4976. blockMapState.setIn([childKey, 'parent'], key);
  4977. } else {
  4978. blockMapState.setIn([oldKey, 'children'], block.getChildKeys().filter(function (child) {
  4979. return child !== childKey;
  4980. }));
  4981. }
  4982. });
  4983. });
  4984. }).toArray().map(function (block) {
  4985. return [newKeysRef[block.getKey()], block.set('key', newKeysRef[block.getKey()])];
  4986. }));
  4987. };
  4988. var randomizeContentBlockKeys = function randomizeContentBlockKeys(blockMap) {
  4989. return OrderedMap$1(blockMap.toArray().map(function (block) {
  4990. var key = generateRandomKey_1();
  4991. return [key, block.set('key', key)];
  4992. }));
  4993. };
  4994. var randomizeBlockMapKeys = function randomizeBlockMapKeys(blockMap) {
  4995. var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode_1;
  4996. if (!isTreeBasedBlockMap) {
  4997. return randomizeContentBlockKeys(blockMap);
  4998. }
  4999. return randomizeContentBlockNodeKeys(blockMap);
  5000. };
  5001. var randomizeBlockMapKeys_1 = randomizeBlockMapKeys;
  5002. function removeEntitiesAtEdges(contentState, selectionState) {
  5003. var blockMap = contentState.getBlockMap();
  5004. var entityMap = contentState.getEntityMap();
  5005. var updatedBlocks = {};
  5006. var startKey = selectionState.getStartKey();
  5007. var startOffset = selectionState.getStartOffset();
  5008. var startBlock = blockMap.get(startKey);
  5009. var updatedStart = removeForBlock(entityMap, startBlock, startOffset);
  5010. if (updatedStart !== startBlock) {
  5011. updatedBlocks[startKey] = updatedStart;
  5012. }
  5013. var endKey = selectionState.getEndKey();
  5014. var endOffset = selectionState.getEndOffset();
  5015. var endBlock = blockMap.get(endKey);
  5016. if (startKey === endKey) {
  5017. endBlock = updatedStart;
  5018. }
  5019. var updatedEnd = removeForBlock(entityMap, endBlock, endOffset);
  5020. if (updatedEnd !== endBlock) {
  5021. updatedBlocks[endKey] = updatedEnd;
  5022. }
  5023. if (!Object.keys(updatedBlocks).length) {
  5024. return contentState.set('selectionAfter', selectionState);
  5025. }
  5026. return contentState.merge({
  5027. blockMap: blockMap.merge(updatedBlocks),
  5028. selectionAfter: selectionState
  5029. });
  5030. }
  5031. function getRemovalRange(characters, key, offset) {
  5032. var removalRange;
  5033. findRangesImmutable_1(characters, function (a, b) {
  5034. return a.getEntity() === b.getEntity();
  5035. }, function (element) {
  5036. return element.getEntity() === key;
  5037. }, function (start, end) {
  5038. if (start <= offset && end >= offset) {
  5039. removalRange = { start: start, end: end };
  5040. }
  5041. });
  5042. !(typeof removalRange === 'object') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Removal range must exist within character list.') : invariant_1(false) : void 0;
  5043. return removalRange;
  5044. }
  5045. function removeForBlock(entityMap, block, offset) {
  5046. var chars = block.getCharacterList();
  5047. var charBefore = offset > 0 ? chars.get(offset - 1) : undefined;
  5048. var charAfter = offset < chars.count() ? chars.get(offset) : undefined;
  5049. var entityBeforeCursor = charBefore ? charBefore.getEntity() : undefined;
  5050. var entityAfterCursor = charAfter ? charAfter.getEntity() : undefined;
  5051. if (entityAfterCursor && entityAfterCursor === entityBeforeCursor) {
  5052. var entity = entityMap.__get(entityAfterCursor);
  5053. if (entity.getMutability() !== 'MUTABLE') {
  5054. var _getRemovalRange = getRemovalRange(chars, entityAfterCursor, offset),
  5055. start = _getRemovalRange.start,
  5056. end = _getRemovalRange.end;
  5057. var current;
  5058. while (start < end) {
  5059. current = chars.get(start);
  5060. chars = chars.set(start, CharacterMetadata_1.applyEntity(current, null));
  5061. start++;
  5062. }
  5063. return block.set('characterList', chars);
  5064. }
  5065. }
  5066. return block;
  5067. }
  5068. var removeEntitiesAtEdges_1 = removeEntitiesAtEdges;
  5069. var getContentStateFragment = function getContentStateFragment(contentState, selectionState) {
  5070. var startKey = selectionState.getStartKey();
  5071. var startOffset = selectionState.getStartOffset();
  5072. var endKey = selectionState.getEndKey();
  5073. var endOffset = selectionState.getEndOffset();
  5074. // Edge entities should be stripped to ensure that we don't preserve
  5075. // invalid partial entities when the fragment is reused. We do, however,
  5076. // preserve entities that are entirely within the selection range.
  5077. var contentWithoutEdgeEntities = removeEntitiesAtEdges_1(contentState, selectionState);
  5078. var blockMap = contentWithoutEdgeEntities.getBlockMap();
  5079. var blockKeys = blockMap.keySeq();
  5080. var startIndex = blockKeys.indexOf(startKey);
  5081. var endIndex = blockKeys.indexOf(endKey) + 1;
  5082. return randomizeBlockMapKeys_1(blockMap.slice(startIndex, endIndex).map(function (block, blockKey) {
  5083. var text = block.getText();
  5084. var chars = block.getCharacterList();
  5085. if (startKey === endKey) {
  5086. return block.merge({
  5087. text: text.slice(startOffset, endOffset),
  5088. characterList: chars.slice(startOffset, endOffset)
  5089. });
  5090. }
  5091. if (blockKey === startKey) {
  5092. return block.merge({
  5093. text: text.slice(startOffset),
  5094. characterList: chars.slice(startOffset)
  5095. });
  5096. }
  5097. if (blockKey === endKey) {
  5098. return block.merge({
  5099. text: text.slice(0, endOffset),
  5100. characterList: chars.slice(0, endOffset)
  5101. });
  5102. }
  5103. return block;
  5104. }));
  5105. };
  5106. var getContentStateFragment_1 = getContentStateFragment;
  5107. /**
  5108. * Copyright (c) 2013-present, Facebook, Inc.
  5109. * All rights reserved.
  5110. *
  5111. * This source code is licensed under the BSD-style license found in the
  5112. * LICENSE file in the root directory of this source tree. An additional grant
  5113. * of patent rights can be found in the PATENTS file in the same directory.
  5114. *
  5115. * @providesModule insertIntoList
  5116. * @format
  5117. *
  5118. */
  5119. /**
  5120. * Maintain persistence for target list when appending and prepending.
  5121. */
  5122. function insertIntoList(targetList, toInsert, offset) {
  5123. if (offset === targetList.count()) {
  5124. toInsert.forEach(function (c) {
  5125. targetList = targetList.push(c);
  5126. });
  5127. } else if (offset === 0) {
  5128. toInsert.reverse().forEach(function (c) {
  5129. targetList = targetList.unshift(c);
  5130. });
  5131. } else {
  5132. var head = targetList.slice(0, offset);
  5133. var tail = targetList.slice(offset);
  5134. targetList = head.concat(toInsert, tail).toList();
  5135. }
  5136. return targetList;
  5137. }
  5138. var insertIntoList_1 = insertIntoList;
  5139. var List$2 = immutable.List;
  5140. var updateExistingBlock = function updateExistingBlock(contentState, selectionState, blockMap, fragmentBlock, targetKey, targetOffset) {
  5141. var targetBlock = blockMap.get(targetKey);
  5142. var text = targetBlock.getText();
  5143. var chars = targetBlock.getCharacterList();
  5144. var finalKey = targetKey;
  5145. var finalOffset = targetOffset + fragmentBlock.getText().length;
  5146. var newBlock = targetBlock.merge({
  5147. text: text.slice(0, targetOffset) + fragmentBlock.getText() + text.slice(targetOffset),
  5148. characterList: insertIntoList_1(chars, fragmentBlock.getCharacterList(), targetOffset),
  5149. data: fragmentBlock.getData()
  5150. });
  5151. return contentState.merge({
  5152. blockMap: blockMap.set(targetKey, newBlock),
  5153. selectionBefore: selectionState,
  5154. selectionAfter: selectionState.merge({
  5155. anchorKey: finalKey,
  5156. anchorOffset: finalOffset,
  5157. focusKey: finalKey,
  5158. focusOffset: finalOffset,
  5159. isBackward: false
  5160. })
  5161. });
  5162. };
  5163. /**
  5164. * Appends text/characterList from the fragment first block to
  5165. * target block.
  5166. */
  5167. var updateHead = function updateHead(block, targetOffset, fragment) {
  5168. var text = block.getText();
  5169. var chars = block.getCharacterList();
  5170. // Modify head portion of block.
  5171. var headText = text.slice(0, targetOffset);
  5172. var headCharacters = chars.slice(0, targetOffset);
  5173. var appendToHead = fragment.first();
  5174. return block.merge({
  5175. text: headText + appendToHead.getText(),
  5176. characterList: headCharacters.concat(appendToHead.getCharacterList()),
  5177. type: headText ? block.getType() : appendToHead.getType(),
  5178. data: appendToHead.getData()
  5179. });
  5180. };
  5181. /**
  5182. * Appends offset text/characterList from the target block to the last
  5183. * fragment block.
  5184. */
  5185. var updateTail = function updateTail(block, targetOffset, fragment) {
  5186. // Modify tail portion of block.
  5187. var text = block.getText();
  5188. var chars = block.getCharacterList();
  5189. // Modify head portion of block.
  5190. var blockSize = text.length;
  5191. var tailText = text.slice(targetOffset, blockSize);
  5192. var tailCharacters = chars.slice(targetOffset, blockSize);
  5193. var prependToTail = fragment.last();
  5194. return prependToTail.merge({
  5195. text: prependToTail.getText() + tailText,
  5196. characterList: prependToTail.getCharacterList().concat(tailCharacters),
  5197. data: prependToTail.getData()
  5198. });
  5199. };
  5200. var getRootBlocks = function getRootBlocks(block, blockMap) {
  5201. var headKey = block.getKey();
  5202. var rootBlock = block;
  5203. var rootBlocks = [];
  5204. // sometimes the fragment head block will not be part of the blockMap itself this can happen when
  5205. // the fragment head is used to update the target block, however when this does not happen we need
  5206. // to make sure that we include it on the rootBlocks since the first block of a fragment is always a
  5207. // fragment root block
  5208. if (blockMap.get(headKey)) {
  5209. rootBlocks.push(headKey);
  5210. }
  5211. while (rootBlock && rootBlock.getNextSiblingKey()) {
  5212. var lastSiblingKey = rootBlock.getNextSiblingKey();
  5213. if (!lastSiblingKey) {
  5214. break;
  5215. }
  5216. rootBlocks.push(lastSiblingKey);
  5217. rootBlock = blockMap.get(lastSiblingKey);
  5218. }
  5219. return rootBlocks;
  5220. };
  5221. var updateBlockMapLinks = function updateBlockMapLinks(blockMap, originalBlockMap, targetBlock, fragmentHeadBlock) {
  5222. return blockMap.withMutations(function (blockMapState) {
  5223. var targetKey = targetBlock.getKey();
  5224. var headKey = fragmentHeadBlock.getKey();
  5225. var targetNextKey = targetBlock.getNextSiblingKey();
  5226. var targetParentKey = targetBlock.getParentKey();
  5227. var fragmentRootBlocks = getRootBlocks(fragmentHeadBlock, blockMap);
  5228. var lastRootFragmentBlockKey = fragmentRootBlocks[fragmentRootBlocks.length - 1];
  5229. if (blockMapState.get(headKey)) {
  5230. // update the fragment head when it is part of the blockMap otherwise
  5231. blockMapState.setIn([targetKey, 'nextSibling'], headKey);
  5232. blockMapState.setIn([headKey, 'prevSibling'], targetKey);
  5233. } else {
  5234. // update the target block that had the fragment head contents merged into it
  5235. blockMapState.setIn([targetKey, 'nextSibling'], fragmentHeadBlock.getNextSiblingKey());
  5236. blockMapState.setIn([fragmentHeadBlock.getNextSiblingKey(), 'prevSibling'], targetKey);
  5237. }
  5238. // update the last root block fragment
  5239. blockMapState.setIn([lastRootFragmentBlockKey, 'nextSibling'], targetNextKey);
  5240. // update the original target next block
  5241. if (targetNextKey) {
  5242. blockMapState.setIn([targetNextKey, 'prevSibling'], lastRootFragmentBlockKey);
  5243. }
  5244. // update fragment parent links
  5245. fragmentRootBlocks.forEach(function (blockKey) {
  5246. return blockMapState.setIn([blockKey, 'parent'], targetParentKey);
  5247. });
  5248. // update targetBlock parent child links
  5249. if (targetParentKey) {
  5250. var targetParent = blockMap.get(targetParentKey);
  5251. var originalTargetParentChildKeys = targetParent.getChildKeys();
  5252. var targetBlockIndex = originalTargetParentChildKeys.indexOf(targetKey);
  5253. var insertionIndex = targetBlockIndex + 1;
  5254. var newChildrenKeysArray = originalTargetParentChildKeys.toArray();
  5255. // insert fragment children
  5256. newChildrenKeysArray.splice.apply(newChildrenKeysArray, [insertionIndex, 0].concat(fragmentRootBlocks));
  5257. blockMapState.setIn([targetParentKey, 'children'], List$2(newChildrenKeysArray));
  5258. }
  5259. });
  5260. };
  5261. var insertFragment = function insertFragment(contentState, selectionState, blockMap, fragment, targetKey, targetOffset) {
  5262. var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode_1;
  5263. var newBlockArr = [];
  5264. var fragmentSize = fragment.size;
  5265. var target = blockMap.get(targetKey);
  5266. var head = fragment.first();
  5267. var tail = fragment.last();
  5268. var finalOffset = tail.getLength();
  5269. var finalKey = tail.getKey();
  5270. var shouldNotUpdateFromFragmentBlock = isTreeBasedBlockMap && (!target.getChildKeys().isEmpty() || !head.getChildKeys().isEmpty());
  5271. blockMap.forEach(function (block, blockKey) {
  5272. if (blockKey !== targetKey) {
  5273. newBlockArr.push(block);
  5274. return;
  5275. }
  5276. if (shouldNotUpdateFromFragmentBlock) {
  5277. newBlockArr.push(block);
  5278. } else {
  5279. newBlockArr.push(updateHead(block, targetOffset, fragment));
  5280. }
  5281. // Insert fragment blocks after the head and before the tail.
  5282. fragment
  5283. // when we are updating the target block with the head fragment block we skip the first fragment
  5284. // head since its contents have already been merged with the target block otherwise we include
  5285. // the whole fragment
  5286. .slice(shouldNotUpdateFromFragmentBlock ? 0 : 1, fragmentSize - 1).forEach(function (fragmentBlock) {
  5287. return newBlockArr.push(fragmentBlock);
  5288. });
  5289. // update tail
  5290. newBlockArr.push(updateTail(block, targetOffset, fragment));
  5291. });
  5292. var updatedBlockMap = BlockMapBuilder_1.createFromArray(newBlockArr);
  5293. if (isTreeBasedBlockMap) {
  5294. updatedBlockMap = updateBlockMapLinks(updatedBlockMap, blockMap, target, head);
  5295. }
  5296. return contentState.merge({
  5297. blockMap: updatedBlockMap,
  5298. selectionBefore: selectionState,
  5299. selectionAfter: selectionState.merge({
  5300. anchorKey: finalKey,
  5301. anchorOffset: finalOffset,
  5302. focusKey: finalKey,
  5303. focusOffset: finalOffset,
  5304. isBackward: false
  5305. })
  5306. });
  5307. };
  5308. var insertFragmentIntoContentState = function insertFragmentIntoContentState(contentState, selectionState, fragmentBlockMap) {
  5309. !selectionState.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`insertFragment` should only be called with a collapsed selection state.') : invariant_1(false) : void 0;
  5310. var blockMap = contentState.getBlockMap();
  5311. var fragment = randomizeBlockMapKeys_1(fragmentBlockMap);
  5312. var targetKey = selectionState.getStartKey();
  5313. var targetOffset = selectionState.getStartOffset();
  5314. var targetBlock = blockMap.get(targetKey);
  5315. if (targetBlock instanceof ContentBlockNode_1) {
  5316. !targetBlock.getChildKeys().isEmpty() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`insertFragment` should not be called when a container node is selected.') : invariant_1(false) : void 0;
  5317. }
  5318. // When we insert a fragment with a single block we simply update the target block
  5319. // with the contents of the inserted fragment block
  5320. if (fragment.size === 1) {
  5321. return updateExistingBlock(contentState, selectionState, blockMap, fragment.first(), targetKey, targetOffset);
  5322. }
  5323. return insertFragment(contentState, selectionState, blockMap, fragment, targetKey, targetOffset);
  5324. };
  5325. var insertFragmentIntoContentState_1 = insertFragmentIntoContentState;
  5326. var Repeat$2 = immutable.Repeat;
  5327. function insertTextIntoContentState(contentState, selectionState, text, characterMetadata) {
  5328. !selectionState.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`insertText` should only be called with a collapsed range.') : invariant_1(false) : void 0;
  5329. var len = text.length;
  5330. if (!len) {
  5331. return contentState;
  5332. }
  5333. var blockMap = contentState.getBlockMap();
  5334. var key = selectionState.getStartKey();
  5335. var offset = selectionState.getStartOffset();
  5336. var block = blockMap.get(key);
  5337. var blockText = block.getText();
  5338. var newBlock = block.merge({
  5339. text: blockText.slice(0, offset) + text + blockText.slice(offset, block.getLength()),
  5340. characterList: insertIntoList_1(block.getCharacterList(), Repeat$2(characterMetadata, len).toList(), offset)
  5341. });
  5342. var newOffset = offset + len;
  5343. return contentState.merge({
  5344. blockMap: blockMap.set(key, newBlock),
  5345. selectionAfter: selectionState.merge({
  5346. anchorOffset: newOffset,
  5347. focusOffset: newOffset
  5348. })
  5349. });
  5350. }
  5351. var insertTextIntoContentState_1 = insertTextIntoContentState;
  5352. var Map$4 = immutable.Map;
  5353. function modifyBlockForContentState(contentState, selectionState, operation) {
  5354. var startKey = selectionState.getStartKey();
  5355. var endKey = selectionState.getEndKey();
  5356. var blockMap = contentState.getBlockMap();
  5357. var newBlocks = blockMap.toSeq().skipUntil(function (_, k) {
  5358. return k === startKey;
  5359. }).takeUntil(function (_, k) {
  5360. return k === endKey;
  5361. }).concat(Map$4([[endKey, blockMap.get(endKey)]])).map(operation);
  5362. return contentState.merge({
  5363. blockMap: blockMap.merge(newBlocks),
  5364. selectionBefore: selectionState,
  5365. selectionAfter: selectionState
  5366. });
  5367. }
  5368. var modifyBlockForContentState_1 = modifyBlockForContentState;
  5369. /**
  5370. * Copyright (c) 2013-present, Facebook, Inc.
  5371. * All rights reserved.
  5372. *
  5373. * This source code is licensed under the BSD-style license found in the
  5374. * LICENSE file in the root directory of this source tree. An additional grant
  5375. * of patent rights can be found in the PATENTS file in the same directory.
  5376. *
  5377. * @providesModule getNextDelimiterBlockKey
  5378. * @format
  5379. *
  5380. *
  5381. * This is unstable and not part of the public API and should not be used by
  5382. * production systems. This file may be update/removed without notice.
  5383. */
  5384. var getNextDelimiterBlockKey = function getNextDelimiterBlockKey(block, blockMap) {
  5385. var isExperimentalTreeBlock = block instanceof ContentBlockNode_1;
  5386. if (!isExperimentalTreeBlock) {
  5387. return null;
  5388. }
  5389. var nextSiblingKey = block.getNextSiblingKey();
  5390. if (nextSiblingKey) {
  5391. return nextSiblingKey;
  5392. }
  5393. var parent = block.getParentKey();
  5394. if (!parent) {
  5395. return null;
  5396. }
  5397. var nextNonDescendantBlock = blockMap.get(parent);
  5398. while (nextNonDescendantBlock && !nextNonDescendantBlock.getNextSiblingKey()) {
  5399. var parentKey = nextNonDescendantBlock.getParentKey();
  5400. nextNonDescendantBlock = parentKey ? blockMap.get(parentKey) : null;
  5401. }
  5402. if (!nextNonDescendantBlock) {
  5403. return null;
  5404. }
  5405. return nextNonDescendantBlock.getNextSiblingKey();
  5406. };
  5407. var getNextDelimiterBlockKey_1 = getNextDelimiterBlockKey;
  5408. var List$3 = immutable.List,
  5409. Map$5 = immutable.Map;
  5410. var transformBlock = function transformBlock(key, blockMap, func) {
  5411. if (!key) {
  5412. return;
  5413. }
  5414. var block = blockMap.get(key);
  5415. if (!block) {
  5416. return;
  5417. }
  5418. blockMap.set(key, func(block));
  5419. };
  5420. /**
  5421. * Ancestors needs to be preserved when there are non selected
  5422. * children to make sure we do not leave any orphans behind
  5423. */
  5424. var getAncestorsKeys = function getAncestorsKeys(blockKey, blockMap) {
  5425. var parents = [];
  5426. if (!blockKey) {
  5427. return parents;
  5428. }
  5429. var blockNode = blockMap.get(blockKey);
  5430. while (blockNode && blockNode.getParentKey()) {
  5431. var parentKey = blockNode.getParentKey();
  5432. if (parentKey) {
  5433. parents.push(parentKey);
  5434. }
  5435. blockNode = parentKey ? blockMap.get(parentKey) : null;
  5436. }
  5437. return parents;
  5438. };
  5439. /**
  5440. * Get all next delimiter keys until we hit a root delimiter and return
  5441. * an array of key references
  5442. */
  5443. var getNextDelimitersBlockKeys = function getNextDelimitersBlockKeys(block, blockMap) {
  5444. var nextDelimiters = [];
  5445. if (!block) {
  5446. return nextDelimiters;
  5447. }
  5448. var nextDelimiter = getNextDelimiterBlockKey_1(block, blockMap);
  5449. while (nextDelimiter && blockMap.get(nextDelimiter)) {
  5450. var _block = blockMap.get(nextDelimiter);
  5451. nextDelimiters.push(nextDelimiter);
  5452. // we do not need to keep checking all root node siblings, just the first occurance
  5453. nextDelimiter = _block.getParentKey() ? getNextDelimiterBlockKey_1(_block, blockMap) : null;
  5454. }
  5455. return nextDelimiters;
  5456. };
  5457. var getNextValidSibling = function getNextValidSibling(block, blockMap, originalBlockMap) {
  5458. if (!block) {
  5459. return null;
  5460. }
  5461. // note that we need to make sure we refer to the original block since this
  5462. // function is called within a withMutations
  5463. var nextValidSiblingKey = originalBlockMap.get(block.getKey()).getNextSiblingKey();
  5464. while (nextValidSiblingKey && !blockMap.get(nextValidSiblingKey)) {
  5465. nextValidSiblingKey = originalBlockMap.get(nextValidSiblingKey).getNextSiblingKey() || null;
  5466. }
  5467. return nextValidSiblingKey;
  5468. };
  5469. var getPrevValidSibling = function getPrevValidSibling(block, blockMap, originalBlockMap) {
  5470. if (!block) {
  5471. return null;
  5472. }
  5473. // note that we need to make sure we refer to the original block since this
  5474. // function is called within a withMutations
  5475. var prevValidSiblingKey = originalBlockMap.get(block.getKey()).getPrevSiblingKey();
  5476. while (prevValidSiblingKey && !blockMap.get(prevValidSiblingKey)) {
  5477. prevValidSiblingKey = originalBlockMap.get(prevValidSiblingKey).getPrevSiblingKey() || null;
  5478. }
  5479. return prevValidSiblingKey;
  5480. };
  5481. var updateBlockMapLinks$1 = function updateBlockMapLinks(blockMap, startBlock, endBlock, originalBlockMap) {
  5482. return blockMap.withMutations(function (blocks) {
  5483. // update start block if its retained
  5484. transformBlock(startBlock.getKey(), blocks, function (block) {
  5485. return block.merge({
  5486. nextSibling: getNextValidSibling(startBlock, blocks, originalBlockMap),
  5487. prevSibling: getPrevValidSibling(startBlock, blocks, originalBlockMap)
  5488. });
  5489. });
  5490. // update endblock if its retained
  5491. transformBlock(endBlock.getKey(), blocks, function (block) {
  5492. return block.merge({
  5493. nextSibling: getNextValidSibling(endBlock, blocks, originalBlockMap),
  5494. prevSibling: getPrevValidSibling(endBlock, blocks, originalBlockMap)
  5495. });
  5496. });
  5497. // update start block parent ancestors
  5498. getAncestorsKeys(startBlock.getKey(), originalBlockMap).forEach(function (parentKey) {
  5499. return transformBlock(parentKey, blocks, function (block) {
  5500. return block.merge({
  5501. children: block.getChildKeys().filter(function (key) {
  5502. return blocks.get(key);
  5503. }),
  5504. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  5505. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  5506. });
  5507. });
  5508. });
  5509. // update start block next - can only happen if startBlock == endBlock
  5510. transformBlock(startBlock.getNextSiblingKey(), blocks, function (block) {
  5511. return block.merge({
  5512. prevSibling: startBlock.getPrevSiblingKey()
  5513. });
  5514. });
  5515. // update start block prev
  5516. transformBlock(startBlock.getPrevSiblingKey(), blocks, function (block) {
  5517. return block.merge({
  5518. nextSibling: getNextValidSibling(startBlock, blocks, originalBlockMap)
  5519. });
  5520. });
  5521. // update end block next
  5522. transformBlock(endBlock.getNextSiblingKey(), blocks, function (block) {
  5523. return block.merge({
  5524. prevSibling: getPrevValidSibling(endBlock, blocks, originalBlockMap)
  5525. });
  5526. });
  5527. // update end block prev
  5528. transformBlock(endBlock.getPrevSiblingKey(), blocks, function (block) {
  5529. return block.merge({
  5530. nextSibling: endBlock.getNextSiblingKey()
  5531. });
  5532. });
  5533. // update end block parent ancestors
  5534. getAncestorsKeys(endBlock.getKey(), originalBlockMap).forEach(function (parentKey) {
  5535. transformBlock(parentKey, blocks, function (block) {
  5536. return block.merge({
  5537. children: block.getChildKeys().filter(function (key) {
  5538. return blocks.get(key);
  5539. }),
  5540. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  5541. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  5542. });
  5543. });
  5544. });
  5545. // update next delimiters all the way to a root delimiter
  5546. getNextDelimitersBlockKeys(endBlock, originalBlockMap).forEach(function (delimiterKey) {
  5547. return transformBlock(delimiterKey, blocks, function (block) {
  5548. return block.merge({
  5549. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  5550. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  5551. });
  5552. });
  5553. });
  5554. });
  5555. };
  5556. var removeRangeFromContentState = function removeRangeFromContentState(contentState, selectionState) {
  5557. if (selectionState.isCollapsed()) {
  5558. return contentState;
  5559. }
  5560. var blockMap = contentState.getBlockMap();
  5561. var startKey = selectionState.getStartKey();
  5562. var startOffset = selectionState.getStartOffset();
  5563. var endKey = selectionState.getEndKey();
  5564. var endOffset = selectionState.getEndOffset();
  5565. var startBlock = blockMap.get(startKey);
  5566. var endBlock = blockMap.get(endKey);
  5567. // we assume that ContentBlockNode and ContentBlocks are not mixed together
  5568. var isExperimentalTreeBlock = startBlock instanceof ContentBlockNode_1;
  5569. // used to retain blocks that should not be deleted to avoid orphan children
  5570. var parentAncestors = [];
  5571. if (isExperimentalTreeBlock) {
  5572. var endBlockchildrenKeys = endBlock.getChildKeys();
  5573. var endBlockAncestors = getAncestorsKeys(endKey, blockMap);
  5574. // endBlock has unselected sibblings so we can not remove its ancestors parents
  5575. if (endBlock.getNextSiblingKey()) {
  5576. parentAncestors = parentAncestors.concat(endBlockAncestors);
  5577. }
  5578. // endBlock has children so can not remove this block or any of its ancestors
  5579. if (!endBlockchildrenKeys.isEmpty()) {
  5580. parentAncestors = parentAncestors.concat(endBlockAncestors.concat([endKey]));
  5581. }
  5582. // we need to retain all ancestors of the next delimiter block
  5583. parentAncestors = parentAncestors.concat(getAncestorsKeys(getNextDelimiterBlockKey_1(endBlock, blockMap), blockMap));
  5584. }
  5585. var characterList = void 0;
  5586. if (startBlock === endBlock) {
  5587. characterList = removeFromList(startBlock.getCharacterList(), startOffset, endOffset);
  5588. } else {
  5589. characterList = startBlock.getCharacterList().slice(0, startOffset).concat(endBlock.getCharacterList().slice(endOffset));
  5590. }
  5591. var modifiedStart = startBlock.merge({
  5592. text: startBlock.getText().slice(0, startOffset) + endBlock.getText().slice(endOffset),
  5593. characterList: characterList
  5594. });
  5595. var newBlocks = blockMap.toSeq().skipUntil(function (_, k) {
  5596. return k === startKey;
  5597. }).takeUntil(function (_, k) {
  5598. return k === endKey;
  5599. }).filter(function (_, k) {
  5600. return parentAncestors.indexOf(k) === -1;
  5601. }).concat(Map$5([[endKey, null]])).map(function (_, k) {
  5602. return k === startKey ? modifiedStart : null;
  5603. });
  5604. var updatedBlockMap = blockMap.merge(newBlocks).filter(function (block) {
  5605. return !!block;
  5606. });
  5607. if (isExperimentalTreeBlock) {
  5608. updatedBlockMap = updateBlockMapLinks$1(updatedBlockMap, startBlock, endBlock, blockMap);
  5609. }
  5610. return contentState.merge({
  5611. blockMap: updatedBlockMap,
  5612. selectionBefore: selectionState,
  5613. selectionAfter: selectionState.merge({
  5614. anchorKey: startKey,
  5615. anchorOffset: startOffset,
  5616. focusKey: startKey,
  5617. focusOffset: startOffset,
  5618. isBackward: false
  5619. })
  5620. });
  5621. };
  5622. /**
  5623. * Maintain persistence for target list when removing characters on the
  5624. * head and tail of the character list.
  5625. */
  5626. var removeFromList = function removeFromList(targetList, startOffset, endOffset) {
  5627. if (startOffset === 0) {
  5628. while (startOffset < endOffset) {
  5629. targetList = targetList.shift();
  5630. startOffset++;
  5631. }
  5632. } else if (endOffset === targetList.count()) {
  5633. while (endOffset > startOffset) {
  5634. targetList = targetList.pop();
  5635. endOffset--;
  5636. }
  5637. } else {
  5638. var head = targetList.slice(0, startOffset);
  5639. var tail = targetList.slice(endOffset);
  5640. targetList = head.concat(tail).toList();
  5641. }
  5642. return targetList;
  5643. };
  5644. var removeRangeFromContentState_1 = removeRangeFromContentState;
  5645. var List$4 = immutable.List,
  5646. Map$6 = immutable.Map;
  5647. var transformBlock$1 = function transformBlock(key, blockMap, func) {
  5648. if (!key) {
  5649. return;
  5650. }
  5651. var block = blockMap.get(key);
  5652. if (!block) {
  5653. return;
  5654. }
  5655. blockMap.set(key, func(block));
  5656. };
  5657. var updateBlockMapLinks$2 = function updateBlockMapLinks(blockMap, originalBlock, belowBlock) {
  5658. return blockMap.withMutations(function (blocks) {
  5659. var originalBlockKey = originalBlock.getKey();
  5660. var belowBlockKey = belowBlock.getKey();
  5661. // update block parent
  5662. transformBlock$1(originalBlock.getParentKey(), blocks, function (block) {
  5663. var parentChildrenList = block.getChildKeys();
  5664. var insertionIndex = parentChildrenList.indexOf(originalBlockKey) + 1;
  5665. var newChildrenArray = parentChildrenList.toArray();
  5666. newChildrenArray.splice(insertionIndex, 0, belowBlockKey);
  5667. return block.merge({
  5668. children: List$4(newChildrenArray)
  5669. });
  5670. });
  5671. // update original next block
  5672. transformBlock$1(originalBlock.getNextSiblingKey(), blocks, function (block) {
  5673. return block.merge({
  5674. prevSibling: belowBlockKey
  5675. });
  5676. });
  5677. // update original block
  5678. transformBlock$1(originalBlockKey, blocks, function (block) {
  5679. return block.merge({
  5680. nextSibling: belowBlockKey
  5681. });
  5682. });
  5683. // update below block
  5684. transformBlock$1(belowBlockKey, blocks, function (block) {
  5685. return block.merge({
  5686. prevSibling: originalBlockKey
  5687. });
  5688. });
  5689. });
  5690. };
  5691. var splitBlockInContentState = function splitBlockInContentState(contentState, selectionState) {
  5692. !selectionState.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Selection range must be collapsed.') : invariant_1(false) : void 0;
  5693. var key = selectionState.getAnchorKey();
  5694. var offset = selectionState.getAnchorOffset();
  5695. var blockMap = contentState.getBlockMap();
  5696. var blockToSplit = blockMap.get(key);
  5697. var text = blockToSplit.getText();
  5698. var chars = blockToSplit.getCharacterList();
  5699. var keyBelow = generateRandomKey_1();
  5700. var isExperimentalTreeBlock = blockToSplit instanceof ContentBlockNode_1;
  5701. var blockAbove = blockToSplit.merge({
  5702. text: text.slice(0, offset),
  5703. characterList: chars.slice(0, offset)
  5704. });
  5705. var blockBelow = blockAbove.merge({
  5706. key: keyBelow,
  5707. text: text.slice(offset),
  5708. characterList: chars.slice(offset),
  5709. data: Map$6()
  5710. });
  5711. var blocksBefore = blockMap.toSeq().takeUntil(function (v) {
  5712. return v === blockToSplit;
  5713. });
  5714. var blocksAfter = blockMap.toSeq().skipUntil(function (v) {
  5715. return v === blockToSplit;
  5716. }).rest();
  5717. var newBlocks = blocksBefore.concat([[key, blockAbove], [keyBelow, blockBelow]], blocksAfter).toOrderedMap();
  5718. if (isExperimentalTreeBlock) {
  5719. !blockToSplit.getChildKeys().isEmpty() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'ContentBlockNode must not have children') : invariant_1(false) : void 0;
  5720. newBlocks = updateBlockMapLinks$2(newBlocks, blockAbove, blockBelow);
  5721. }
  5722. return contentState.merge({
  5723. blockMap: newBlocks,
  5724. selectionBefore: selectionState,
  5725. selectionAfter: selectionState.merge({
  5726. anchorKey: keyBelow,
  5727. anchorOffset: 0,
  5728. focusKey: keyBelow,
  5729. focusOffset: 0,
  5730. isBackward: false
  5731. })
  5732. });
  5733. };
  5734. var splitBlockInContentState_1 = splitBlockInContentState;
  5735. var OrderedSet$3 = immutable.OrderedSet;
  5736. /**
  5737. * `DraftModifier` provides a set of convenience methods that apply
  5738. * modifications to a `ContentState` object based on a target `SelectionState`.
  5739. *
  5740. * Any change to a `ContentState` should be decomposable into a series of
  5741. * transaction functions that apply the required changes and return output
  5742. * `ContentState` objects.
  5743. *
  5744. * These functions encapsulate some of the most common transaction sequences.
  5745. */
  5746. var DraftModifier = {
  5747. replaceText: function replaceText(contentState, rangeToReplace, text, inlineStyle, entityKey) {
  5748. var withoutEntities = removeEntitiesAtEdges_1(contentState, rangeToReplace);
  5749. var withoutText = removeRangeFromContentState_1(withoutEntities, rangeToReplace);
  5750. var character = CharacterMetadata_1.create({
  5751. style: inlineStyle || OrderedSet$3(),
  5752. entity: entityKey || null
  5753. });
  5754. return insertTextIntoContentState_1(withoutText, withoutText.getSelectionAfter(), text, character);
  5755. },
  5756. insertText: function insertText(contentState, targetRange, text, inlineStyle, entityKey) {
  5757. !targetRange.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Target range must be collapsed for `insertText`.') : invariant_1(false) : void 0;
  5758. return DraftModifier.replaceText(contentState, targetRange, text, inlineStyle, entityKey);
  5759. },
  5760. moveText: function moveText(contentState, removalRange, targetRange) {
  5761. var movedFragment = getContentStateFragment_1(contentState, removalRange);
  5762. var afterRemoval = DraftModifier.removeRange(contentState, removalRange, 'backward');
  5763. return DraftModifier.replaceWithFragment(afterRemoval, targetRange, movedFragment);
  5764. },
  5765. replaceWithFragment: function replaceWithFragment(contentState, targetRange, fragment) {
  5766. var withoutEntities = removeEntitiesAtEdges_1(contentState, targetRange);
  5767. var withoutText = removeRangeFromContentState_1(withoutEntities, targetRange);
  5768. return insertFragmentIntoContentState_1(withoutText, withoutText.getSelectionAfter(), fragment);
  5769. },
  5770. removeRange: function removeRange(contentState, rangeToRemove, removalDirection) {
  5771. var startKey = void 0,
  5772. endKey = void 0,
  5773. startBlock = void 0,
  5774. endBlock = void 0;
  5775. if (rangeToRemove.getIsBackward()) {
  5776. rangeToRemove = rangeToRemove.merge({
  5777. anchorKey: rangeToRemove.getFocusKey(),
  5778. anchorOffset: rangeToRemove.getFocusOffset(),
  5779. focusKey: rangeToRemove.getAnchorKey(),
  5780. focusOffset: rangeToRemove.getAnchorOffset(),
  5781. isBackward: false
  5782. });
  5783. }
  5784. startKey = rangeToRemove.getAnchorKey();
  5785. endKey = rangeToRemove.getFocusKey();
  5786. startBlock = contentState.getBlockForKey(startKey);
  5787. endBlock = contentState.getBlockForKey(endKey);
  5788. var startOffset = rangeToRemove.getStartOffset();
  5789. var endOffset = rangeToRemove.getEndOffset();
  5790. var startEntityKey = startBlock.getEntityAt(startOffset);
  5791. var endEntityKey = endBlock.getEntityAt(endOffset - 1);
  5792. // Check whether the selection state overlaps with a single entity.
  5793. // If so, try to remove the appropriate substring of the entity text.
  5794. if (startKey === endKey) {
  5795. if (startEntityKey && startEntityKey === endEntityKey) {
  5796. var _adjustedRemovalRange = getCharacterRemovalRange_1(contentState.getEntityMap(), startBlock, endBlock, rangeToRemove, removalDirection);
  5797. return removeRangeFromContentState_1(contentState, _adjustedRemovalRange);
  5798. }
  5799. }
  5800. var adjustedRemovalRange = rangeToRemove;
  5801. var withoutEntities = removeEntitiesAtEdges_1(contentState, adjustedRemovalRange);
  5802. return removeRangeFromContentState_1(withoutEntities, adjustedRemovalRange);
  5803. },
  5804. splitBlock: function splitBlock(contentState, selectionState) {
  5805. var withoutEntities = removeEntitiesAtEdges_1(contentState, selectionState);
  5806. var withoutText = removeRangeFromContentState_1(withoutEntities, selectionState);
  5807. return splitBlockInContentState_1(withoutText, withoutText.getSelectionAfter());
  5808. },
  5809. applyInlineStyle: function applyInlineStyle(contentState, selectionState, inlineStyle) {
  5810. return ContentStateInlineStyle_1.add(contentState, selectionState, inlineStyle);
  5811. },
  5812. removeInlineStyle: function removeInlineStyle(contentState, selectionState, inlineStyle) {
  5813. return ContentStateInlineStyle_1.remove(contentState, selectionState, inlineStyle);
  5814. },
  5815. setBlockType: function setBlockType(contentState, selectionState, blockType) {
  5816. return modifyBlockForContentState_1(contentState, selectionState, function (block) {
  5817. return block.merge({ type: blockType, depth: 0 });
  5818. });
  5819. },
  5820. setBlockData: function setBlockData(contentState, selectionState, blockData) {
  5821. return modifyBlockForContentState_1(contentState, selectionState, function (block) {
  5822. return block.merge({ data: blockData });
  5823. });
  5824. },
  5825. mergeBlockData: function mergeBlockData(contentState, selectionState, blockData) {
  5826. return modifyBlockForContentState_1(contentState, selectionState, function (block) {
  5827. return block.merge({ data: block.getData().merge(blockData) });
  5828. });
  5829. },
  5830. applyEntity: function applyEntity(contentState, selectionState, entityKey) {
  5831. var withoutEntities = removeEntitiesAtEdges_1(contentState, selectionState);
  5832. return applyEntityToContentState_1(withoutEntities, selectionState, entityKey);
  5833. }
  5834. };
  5835. var DraftModifier_1 = DraftModifier;
  5836. /**
  5837. * Copyright (c) 2013-present, Facebook, Inc.
  5838. *
  5839. * This source code is licensed under the MIT license found in the
  5840. * LICENSE file in the root directory of this source tree.
  5841. *
  5842. *
  5843. */
  5844. function makeEmptyFunction(arg) {
  5845. return function () {
  5846. return arg;
  5847. };
  5848. }
  5849. /**
  5850. * This function accepts and discards inputs; it has no side effects. This is
  5851. * primarily useful idiomatically for overridable function endpoints which
  5852. * always need to be callable, since JS lacks a null-call idiom ala Cocoa.
  5853. */
  5854. var emptyFunction = function emptyFunction() {};
  5855. emptyFunction.thatReturns = makeEmptyFunction;
  5856. emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
  5857. emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
  5858. emptyFunction.thatReturnsNull = makeEmptyFunction(null);
  5859. emptyFunction.thatReturnsThis = function () {
  5860. return this;
  5861. };
  5862. emptyFunction.thatReturnsArgument = function (arg) {
  5863. return arg;
  5864. };
  5865. var emptyFunction_1 = emptyFunction;
  5866. var List$5 = immutable.List,
  5867. Repeat$3 = immutable.Repeat,
  5868. Record$3 = immutable.Record;
  5869. var returnTrue = emptyFunction_1.thatReturnsTrue;
  5870. var FINGERPRINT_DELIMITER = '-';
  5871. var defaultLeafRange = {
  5872. start: null,
  5873. end: null
  5874. };
  5875. var LeafRange = Record$3(defaultLeafRange);
  5876. var defaultDecoratorRange = {
  5877. start: null,
  5878. end: null,
  5879. decoratorKey: null,
  5880. leaves: null
  5881. };
  5882. var DecoratorRange = Record$3(defaultDecoratorRange);
  5883. var BlockTree = {
  5884. /**
  5885. * Generate a block tree for a given ContentBlock/decorator pair.
  5886. */
  5887. generate: function generate(contentState, block, decorator) {
  5888. var textLength = block.getLength();
  5889. if (!textLength) {
  5890. return List$5.of(new DecoratorRange({
  5891. start: 0,
  5892. end: 0,
  5893. decoratorKey: null,
  5894. leaves: List$5.of(new LeafRange({ start: 0, end: 0 }))
  5895. }));
  5896. }
  5897. var leafSets = [];
  5898. var decorations = decorator ? decorator.getDecorations(block, contentState) : List$5(Repeat$3(null, textLength));
  5899. var chars = block.getCharacterList();
  5900. findRangesImmutable_1(decorations, areEqual, returnTrue, function (start, end) {
  5901. leafSets.push(new DecoratorRange({
  5902. start: start,
  5903. end: end,
  5904. decoratorKey: decorations.get(start),
  5905. leaves: generateLeaves(chars.slice(start, end).toList(), start)
  5906. }));
  5907. });
  5908. return List$5(leafSets);
  5909. },
  5910. /**
  5911. * Create a string representation of the given tree map. This allows us
  5912. * to rapidly determine whether a tree has undergone a significant
  5913. * structural change.
  5914. */
  5915. getFingerprint: function getFingerprint(tree) {
  5916. return tree.map(function (leafSet) {
  5917. var decoratorKey = leafSet.get('decoratorKey');
  5918. var fingerprintString = decoratorKey !== null ? decoratorKey + '.' + (leafSet.get('end') - leafSet.get('start')) : '';
  5919. return '' + fingerprintString + '.' + leafSet.get('leaves').size;
  5920. }).join(FINGERPRINT_DELIMITER);
  5921. }
  5922. };
  5923. /**
  5924. * Generate LeafRange records for a given character list.
  5925. */
  5926. function generateLeaves(characters, offset) {
  5927. var leaves = [];
  5928. var inlineStyles = characters.map(function (c) {
  5929. return c.getStyle();
  5930. }).toList();
  5931. findRangesImmutable_1(inlineStyles, areEqual, returnTrue, function (start, end) {
  5932. leaves.push(new LeafRange({
  5933. start: start + offset,
  5934. end: end + offset
  5935. }));
  5936. });
  5937. return List$5(leaves);
  5938. }
  5939. function areEqual(a, b) {
  5940. return a === b;
  5941. }
  5942. var BlockTree_1 = BlockTree;
  5943. function _classCallCheck$3(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5944. function _possibleConstructorReturn$3(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  5945. function _inherits$3(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5946. var Record$4 = immutable.Record;
  5947. var DraftEntityInstanceRecord = Record$4({
  5948. type: 'TOKEN',
  5949. mutability: 'IMMUTABLE',
  5950. data: Object
  5951. });
  5952. /**
  5953. * An instance of a document entity, consisting of a `type` and relevant
  5954. * `data`, metadata about the entity.
  5955. *
  5956. * For instance, a "link" entity might provide a URI, and a "mention"
  5957. * entity might provide the mentioned user's ID. These pieces of data
  5958. * may be used when rendering the entity as part of a ContentBlock DOM
  5959. * representation. For a link, the data would be used as an href for
  5960. * the rendered anchor. For a mention, the ID could be used to retrieve
  5961. * a hovercard.
  5962. */
  5963. var DraftEntityInstance = function (_DraftEntityInstanceR) {
  5964. _inherits$3(DraftEntityInstance, _DraftEntityInstanceR);
  5965. function DraftEntityInstance() {
  5966. _classCallCheck$3(this, DraftEntityInstance);
  5967. return _possibleConstructorReturn$3(this, _DraftEntityInstanceR.apply(this, arguments));
  5968. }
  5969. DraftEntityInstance.prototype.getType = function getType() {
  5970. return this.get('type');
  5971. };
  5972. DraftEntityInstance.prototype.getMutability = function getMutability() {
  5973. return this.get('mutability');
  5974. };
  5975. DraftEntityInstance.prototype.getData = function getData() {
  5976. return this.get('data');
  5977. };
  5978. return DraftEntityInstance;
  5979. }(DraftEntityInstanceRecord);
  5980. var DraftEntityInstance_1 = DraftEntityInstance;
  5981. var _extends = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  5982. /**
  5983. * Copyright (c) 2013-present, Facebook, Inc.
  5984. * All rights reserved.
  5985. *
  5986. * This source code is licensed under the BSD-style license found in the
  5987. * LICENSE file in the root directory of this source tree. An additional grant
  5988. * of patent rights can be found in the PATENTS file in the same directory.
  5989. *
  5990. * @providesModule DraftEntity
  5991. * @format
  5992. *
  5993. */
  5994. var Map$7 = immutable.Map;
  5995. var instances = Map$7();
  5996. var instanceKey = 0;
  5997. /**
  5998. * Temporary utility for generating the warnings
  5999. */
  6000. function logWarning(oldMethodCall, newMethodCall) {
  6001. console.warn('WARNING: ' + oldMethodCall + ' will be deprecated soon!\nPlease use "' + newMethodCall + '" instead.');
  6002. }
  6003. /**
  6004. * A "document entity" is an object containing metadata associated with a
  6005. * piece of text in a ContentBlock.
  6006. *
  6007. * For example, a `link` entity might include a `uri` property. When a
  6008. * ContentBlock is rendered in the browser, text that refers to that link
  6009. * entity may be rendered as an anchor, with the `uri` as the href value.
  6010. *
  6011. * In a ContentBlock, every position in the text may correspond to zero
  6012. * or one entities. This correspondence is tracked using a key string,
  6013. * generated via DraftEntity.create() and used to obtain entity metadata
  6014. * via DraftEntity.get().
  6015. */
  6016. var DraftEntity = {
  6017. /**
  6018. * WARNING: This method will be deprecated soon!
  6019. * Please use 'contentState.getLastCreatedEntityKey' instead.
  6020. * ---
  6021. * Get the random key string from whatever entity was last created.
  6022. * We need this to support the new API, as part of transitioning to put Entity
  6023. * storage in contentState.
  6024. */
  6025. getLastCreatedEntityKey: function getLastCreatedEntityKey() {
  6026. logWarning('DraftEntity.getLastCreatedEntityKey', 'contentState.getLastCreatedEntityKey');
  6027. return DraftEntity.__getLastCreatedEntityKey();
  6028. },
  6029. /**
  6030. * WARNING: This method will be deprecated soon!
  6031. * Please use 'contentState.createEntity' instead.
  6032. * ---
  6033. * Create a DraftEntityInstance and store it for later retrieval.
  6034. *
  6035. * A random key string will be generated and returned. This key may
  6036. * be used to track the entity's usage in a ContentBlock, and for
  6037. * retrieving data about the entity at render time.
  6038. */
  6039. create: function create(type, mutability, data) {
  6040. logWarning('DraftEntity.create', 'contentState.createEntity');
  6041. return DraftEntity.__create(type, mutability, data);
  6042. },
  6043. /**
  6044. * WARNING: This method will be deprecated soon!
  6045. * Please use 'contentState.addEntity' instead.
  6046. * ---
  6047. * Add an existing DraftEntityInstance to the DraftEntity map. This is
  6048. * useful when restoring instances from the server.
  6049. */
  6050. add: function add(instance) {
  6051. logWarning('DraftEntity.add', 'contentState.addEntity');
  6052. return DraftEntity.__add(instance);
  6053. },
  6054. /**
  6055. * WARNING: This method will be deprecated soon!
  6056. * Please use 'contentState.getEntity' instead.
  6057. * ---
  6058. * Retrieve the entity corresponding to the supplied key string.
  6059. */
  6060. get: function get(key) {
  6061. logWarning('DraftEntity.get', 'contentState.getEntity');
  6062. return DraftEntity.__get(key);
  6063. },
  6064. /**
  6065. * WARNING: This method will be deprecated soon!
  6066. * Please use 'contentState.mergeEntityData' instead.
  6067. * ---
  6068. * Entity instances are immutable. If you need to update the data for an
  6069. * instance, this method will merge your data updates and return a new
  6070. * instance.
  6071. */
  6072. mergeData: function mergeData(key, toMerge) {
  6073. logWarning('DraftEntity.mergeData', 'contentState.mergeEntityData');
  6074. return DraftEntity.__mergeData(key, toMerge);
  6075. },
  6076. /**
  6077. * WARNING: This method will be deprecated soon!
  6078. * Please use 'contentState.replaceEntityData' instead.
  6079. * ---
  6080. * Completely replace the data for a given instance.
  6081. */
  6082. replaceData: function replaceData(key, newData) {
  6083. logWarning('DraftEntity.replaceData', 'contentState.replaceEntityData');
  6084. return DraftEntity.__replaceData(key, newData);
  6085. },
  6086. // ***********************************WARNING******************************
  6087. // --- the above public API will be deprecated in the next version of Draft!
  6088. // The methods below this line are private - don't call them directly.
  6089. /**
  6090. * Get the random key string from whatever entity was last created.
  6091. * We need this to support the new API, as part of transitioning to put Entity
  6092. * storage in contentState.
  6093. */
  6094. __getLastCreatedEntityKey: function __getLastCreatedEntityKey() {
  6095. return '' + instanceKey;
  6096. },
  6097. /**
  6098. * Create a DraftEntityInstance and store it for later retrieval.
  6099. *
  6100. * A random key string will be generated and returned. This key may
  6101. * be used to track the entity's usage in a ContentBlock, and for
  6102. * retrieving data about the entity at render time.
  6103. */
  6104. __create: function __create(type, mutability, data) {
  6105. return DraftEntity.__add(new DraftEntityInstance_1({ type: type, mutability: mutability, data: data || {} }));
  6106. },
  6107. /**
  6108. * Add an existing DraftEntityInstance to the DraftEntity map. This is
  6109. * useful when restoring instances from the server.
  6110. */
  6111. __add: function __add(instance) {
  6112. var key = '' + ++instanceKey;
  6113. instances = instances.set(key, instance);
  6114. return key;
  6115. },
  6116. /**
  6117. * Retrieve the entity corresponding to the supplied key string.
  6118. */
  6119. __get: function __get(key) {
  6120. var instance = instances.get(key);
  6121. !!!instance ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Unknown DraftEntity key: %s.', key) : invariant_1(false) : void 0;
  6122. return instance;
  6123. },
  6124. /**
  6125. * Entity instances are immutable. If you need to update the data for an
  6126. * instance, this method will merge your data updates and return a new
  6127. * instance.
  6128. */
  6129. __mergeData: function __mergeData(key, toMerge) {
  6130. var instance = DraftEntity.__get(key);
  6131. var newData = _extends({}, instance.getData(), toMerge);
  6132. var newInstance = instance.set('data', newData);
  6133. instances = instances.set(key, newInstance);
  6134. return newInstance;
  6135. },
  6136. /**
  6137. * Completely replace the data for a given instance.
  6138. */
  6139. __replaceData: function __replaceData(key, newData) {
  6140. var instance = DraftEntity.__get(key);
  6141. var newInstance = instance.set('data', newData);
  6142. instances = instances.set(key, newInstance);
  6143. return newInstance;
  6144. }
  6145. };
  6146. var DraftEntity_1 = DraftEntity;
  6147. function _classCallCheck$4(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6148. function _possibleConstructorReturn$4(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6149. function _inherits$4(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6150. var Record$5 = immutable.Record;
  6151. var defaultRecord$3 = {
  6152. anchorKey: '',
  6153. anchorOffset: 0,
  6154. focusKey: '',
  6155. focusOffset: 0,
  6156. isBackward: false,
  6157. hasFocus: false
  6158. };
  6159. var SelectionStateRecord = Record$5(defaultRecord$3);
  6160. var SelectionState = function (_SelectionStateRecord) {
  6161. _inherits$4(SelectionState, _SelectionStateRecord);
  6162. function SelectionState() {
  6163. _classCallCheck$4(this, SelectionState);
  6164. return _possibleConstructorReturn$4(this, _SelectionStateRecord.apply(this, arguments));
  6165. }
  6166. SelectionState.prototype.serialize = function serialize() {
  6167. return 'Anchor: ' + this.getAnchorKey() + ':' + this.getAnchorOffset() + ', ' + 'Focus: ' + this.getFocusKey() + ':' + this.getFocusOffset() + ', ' + 'Is Backward: ' + String(this.getIsBackward()) + ', ' + 'Has Focus: ' + String(this.getHasFocus());
  6168. };
  6169. SelectionState.prototype.getAnchorKey = function getAnchorKey() {
  6170. return this.get('anchorKey');
  6171. };
  6172. SelectionState.prototype.getAnchorOffset = function getAnchorOffset() {
  6173. return this.get('anchorOffset');
  6174. };
  6175. SelectionState.prototype.getFocusKey = function getFocusKey() {
  6176. return this.get('focusKey');
  6177. };
  6178. SelectionState.prototype.getFocusOffset = function getFocusOffset() {
  6179. return this.get('focusOffset');
  6180. };
  6181. SelectionState.prototype.getIsBackward = function getIsBackward() {
  6182. return this.get('isBackward');
  6183. };
  6184. SelectionState.prototype.getHasFocus = function getHasFocus() {
  6185. return this.get('hasFocus');
  6186. };
  6187. /**
  6188. * Return whether the specified range overlaps with an edge of the
  6189. * SelectionState.
  6190. */
  6191. SelectionState.prototype.hasEdgeWithin = function hasEdgeWithin(blockKey, start, end) {
  6192. var anchorKey = this.getAnchorKey();
  6193. var focusKey = this.getFocusKey();
  6194. if (anchorKey === focusKey && anchorKey === blockKey) {
  6195. var selectionStart = this.getStartOffset();
  6196. var selectionEnd = this.getEndOffset();
  6197. return start <= selectionEnd && selectionStart <= end;
  6198. }
  6199. if (blockKey !== anchorKey && blockKey !== focusKey) {
  6200. return false;
  6201. }
  6202. var offsetToCheck = blockKey === anchorKey ? this.getAnchorOffset() : this.getFocusOffset();
  6203. return start <= offsetToCheck && end >= offsetToCheck;
  6204. };
  6205. SelectionState.prototype.isCollapsed = function isCollapsed() {
  6206. return this.getAnchorKey() === this.getFocusKey() && this.getAnchorOffset() === this.getFocusOffset();
  6207. };
  6208. SelectionState.prototype.getStartKey = function getStartKey() {
  6209. return this.getIsBackward() ? this.getFocusKey() : this.getAnchorKey();
  6210. };
  6211. SelectionState.prototype.getStartOffset = function getStartOffset() {
  6212. return this.getIsBackward() ? this.getFocusOffset() : this.getAnchorOffset();
  6213. };
  6214. SelectionState.prototype.getEndKey = function getEndKey() {
  6215. return this.getIsBackward() ? this.getAnchorKey() : this.getFocusKey();
  6216. };
  6217. SelectionState.prototype.getEndOffset = function getEndOffset() {
  6218. return this.getIsBackward() ? this.getAnchorOffset() : this.getFocusOffset();
  6219. };
  6220. SelectionState.createEmpty = function createEmpty(key) {
  6221. return new SelectionState({
  6222. anchorKey: key,
  6223. anchorOffset: 0,
  6224. focusKey: key,
  6225. focusOffset: 0,
  6226. isBackward: false,
  6227. hasFocus: false
  6228. });
  6229. };
  6230. return SelectionState;
  6231. }(SelectionStateRecord);
  6232. var SelectionState_1 = SelectionState;
  6233. /**
  6234. * Copyright (c) 2013-present, Facebook, Inc.
  6235. * All rights reserved.
  6236. *
  6237. * This source code is licensed under the BSD-style license found in the
  6238. * LICENSE file in the root directory of this source tree. An additional grant
  6239. * of patent rights can be found in the PATENTS file in the same directory.
  6240. *
  6241. * @providesModule sanitizeDraftText
  6242. * @format
  6243. *
  6244. */
  6245. var REGEX_BLOCK_DELIMITER = new RegExp('\r', 'g');
  6246. function sanitizeDraftText(input) {
  6247. return input.replace(REGEX_BLOCK_DELIMITER, '');
  6248. }
  6249. var sanitizeDraftText_1 = sanitizeDraftText;
  6250. function _classCallCheck$5(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6251. function _possibleConstructorReturn$5(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6252. function _inherits$5(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6253. var List$6 = immutable.List,
  6254. Record$6 = immutable.Record,
  6255. Repeat$4 = immutable.Repeat;
  6256. var defaultRecord$4 = {
  6257. entityMap: null,
  6258. blockMap: null,
  6259. selectionBefore: null,
  6260. selectionAfter: null
  6261. };
  6262. var ContentBlockNodeRecord = ContentBlock_1;
  6263. var ContentStateRecord = Record$6(defaultRecord$4);
  6264. var ContentState = function (_ContentStateRecord) {
  6265. _inherits$5(ContentState, _ContentStateRecord);
  6266. function ContentState() {
  6267. _classCallCheck$5(this, ContentState);
  6268. return _possibleConstructorReturn$5(this, _ContentStateRecord.apply(this, arguments));
  6269. }
  6270. ContentState.prototype.getEntityMap = function getEntityMap() {
  6271. // TODO: update this when we fully remove DraftEntity
  6272. return DraftEntity_1;
  6273. };
  6274. ContentState.prototype.getBlockMap = function getBlockMap() {
  6275. return this.get('blockMap');
  6276. };
  6277. ContentState.prototype.getSelectionBefore = function getSelectionBefore() {
  6278. return this.get('selectionBefore');
  6279. };
  6280. ContentState.prototype.getSelectionAfter = function getSelectionAfter() {
  6281. return this.get('selectionAfter');
  6282. };
  6283. ContentState.prototype.getBlockForKey = function getBlockForKey(key) {
  6284. var block = this.getBlockMap().get(key);
  6285. return block;
  6286. };
  6287. ContentState.prototype.getKeyBefore = function getKeyBefore(key) {
  6288. return this.getBlockMap().reverse().keySeq().skipUntil(function (v) {
  6289. return v === key;
  6290. }).skip(1).first();
  6291. };
  6292. ContentState.prototype.getKeyAfter = function getKeyAfter(key) {
  6293. return this.getBlockMap().keySeq().skipUntil(function (v) {
  6294. return v === key;
  6295. }).skip(1).first();
  6296. };
  6297. ContentState.prototype.getBlockAfter = function getBlockAfter(key) {
  6298. return this.getBlockMap().skipUntil(function (_, k) {
  6299. return k === key;
  6300. }).skip(1).first();
  6301. };
  6302. ContentState.prototype.getBlockBefore = function getBlockBefore(key) {
  6303. return this.getBlockMap().reverse().skipUntil(function (_, k) {
  6304. return k === key;
  6305. }).skip(1).first();
  6306. };
  6307. ContentState.prototype.getBlocksAsArray = function getBlocksAsArray() {
  6308. return this.getBlockMap().toArray();
  6309. };
  6310. ContentState.prototype.getFirstBlock = function getFirstBlock() {
  6311. return this.getBlockMap().first();
  6312. };
  6313. ContentState.prototype.getLastBlock = function getLastBlock() {
  6314. return this.getBlockMap().last();
  6315. };
  6316. ContentState.prototype.getPlainText = function getPlainText(delimiter) {
  6317. return this.getBlockMap().map(function (block) {
  6318. return block ? block.getText() : '';
  6319. }).join(delimiter || '\n');
  6320. };
  6321. ContentState.prototype.getLastCreatedEntityKey = function getLastCreatedEntityKey() {
  6322. // TODO: update this when we fully remove DraftEntity
  6323. return DraftEntity_1.__getLastCreatedEntityKey();
  6324. };
  6325. ContentState.prototype.hasText = function hasText() {
  6326. var blockMap = this.getBlockMap();
  6327. return blockMap.size > 1 || blockMap.first().getLength() > 0;
  6328. };
  6329. ContentState.prototype.createEntity = function createEntity(type, mutability, data) {
  6330. // TODO: update this when we fully remove DraftEntity
  6331. DraftEntity_1.__create(type, mutability, data);
  6332. return this;
  6333. };
  6334. ContentState.prototype.mergeEntityData = function mergeEntityData(key, toMerge) {
  6335. // TODO: update this when we fully remove DraftEntity
  6336. DraftEntity_1.__mergeData(key, toMerge);
  6337. return this;
  6338. };
  6339. ContentState.prototype.replaceEntityData = function replaceEntityData(key, newData) {
  6340. // TODO: update this when we fully remove DraftEntity
  6341. DraftEntity_1.__replaceData(key, newData);
  6342. return this;
  6343. };
  6344. ContentState.prototype.addEntity = function addEntity(instance) {
  6345. // TODO: update this when we fully remove DraftEntity
  6346. DraftEntity_1.__add(instance);
  6347. return this;
  6348. };
  6349. ContentState.prototype.getEntity = function getEntity(key) {
  6350. // TODO: update this when we fully remove DraftEntity
  6351. return DraftEntity_1.__get(key);
  6352. };
  6353. ContentState.createFromBlockArray = function createFromBlockArray(
  6354. // TODO: update flow type when we completely deprecate the old entity API
  6355. blocks, entityMap) {
  6356. // TODO: remove this when we completely deprecate the old entity API
  6357. var theBlocks = Array.isArray(blocks) ? blocks : blocks.contentBlocks;
  6358. var blockMap = BlockMapBuilder_1.createFromArray(theBlocks);
  6359. var selectionState = blockMap.isEmpty() ? new SelectionState_1() : SelectionState_1.createEmpty(blockMap.first().getKey());
  6360. return new ContentState({
  6361. blockMap: blockMap,
  6362. entityMap: entityMap || DraftEntity_1,
  6363. selectionBefore: selectionState,
  6364. selectionAfter: selectionState
  6365. });
  6366. };
  6367. ContentState.createFromText = function createFromText(text) {
  6368. var delimiter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : /\r\n?|\n/g;
  6369. var strings = text.split(delimiter);
  6370. var blocks = strings.map(function (block) {
  6371. block = sanitizeDraftText_1(block);
  6372. return new ContentBlockNodeRecord({
  6373. key: generateRandomKey_1(),
  6374. text: block,
  6375. type: 'unstyled',
  6376. characterList: List$6(Repeat$4(CharacterMetadata_1.EMPTY, block.length))
  6377. });
  6378. });
  6379. return ContentState.createFromBlockArray(blocks);
  6380. };
  6381. return ContentState;
  6382. }(ContentStateRecord);
  6383. var ContentState_1 = ContentState;
  6384. var NEUTRAL = 'NEUTRAL'; // No strong direction
  6385. var LTR = 'LTR'; // Left-to-Right direction
  6386. var RTL = 'RTL'; // Right-to-Left direction
  6387. var globalDir = null;
  6388. // == Helpers ==
  6389. /**
  6390. * Check if a directionality value is a Strong one
  6391. */
  6392. function isStrong(dir) {
  6393. return dir === LTR || dir === RTL;
  6394. }
  6395. /**
  6396. * Get string value to be used for `dir` HTML attribute or `direction` CSS
  6397. * property.
  6398. */
  6399. function getHTMLDir(dir) {
  6400. !isStrong(dir) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`dir` must be a strong direction to be converted to HTML Direction') : invariant_1(false) : void 0;
  6401. return dir === LTR ? 'ltr' : 'rtl';
  6402. }
  6403. /**
  6404. * Get string value to be used for `dir` HTML attribute or `direction` CSS
  6405. * property, but returns null if `dir` has same value as `otherDir`.
  6406. * `null`.
  6407. */
  6408. function getHTMLDirIfDifferent(dir, otherDir) {
  6409. !isStrong(dir) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`dir` must be a strong direction to be converted to HTML Direction') : invariant_1(false) : void 0;
  6410. !isStrong(otherDir) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`otherDir` must be a strong direction to be converted to HTML Direction') : invariant_1(false) : void 0;
  6411. return dir === otherDir ? null : getHTMLDir(dir);
  6412. }
  6413. // == Global Direction ==
  6414. /**
  6415. * Set the global direction.
  6416. */
  6417. function setGlobalDir(dir) {
  6418. globalDir = dir;
  6419. }
  6420. /**
  6421. * Initialize the global direction
  6422. */
  6423. function initGlobalDir() {
  6424. setGlobalDir(LTR);
  6425. }
  6426. /**
  6427. * Get the global direction
  6428. */
  6429. function getGlobalDir() {
  6430. if (!globalDir) {
  6431. this.initGlobalDir();
  6432. }
  6433. !globalDir ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Global direction not set.') : invariant_1(false) : void 0;
  6434. return globalDir;
  6435. }
  6436. var UnicodeBidiDirection = {
  6437. // Values
  6438. NEUTRAL: NEUTRAL,
  6439. LTR: LTR,
  6440. RTL: RTL,
  6441. // Helpers
  6442. isStrong: isStrong,
  6443. getHTMLDir: getHTMLDir,
  6444. getHTMLDirIfDifferent: getHTMLDirIfDifferent,
  6445. // Global Direction
  6446. setGlobalDir: setGlobalDir,
  6447. initGlobalDir: initGlobalDir,
  6448. getGlobalDir: getGlobalDir
  6449. };
  6450. var UnicodeBidiDirection_1 = UnicodeBidiDirection;
  6451. /**
  6452. * RegExp ranges of characters with a *Strong* Bidi_Class value.
  6453. *
  6454. * Data is based on DerivedBidiClass.txt in UCD version 7.0.0.
  6455. *
  6456. * NOTE: For performance reasons, we only support Unicode's
  6457. * Basic Multilingual Plane (BMP) for now.
  6458. */
  6459. var RANGE_BY_BIDI_TYPE = {
  6460. L: 'A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u01BA\u01BB' + '\u01BC-\u01BF\u01C0-\u01C3\u01C4-\u0293\u0294\u0295-\u02AF\u02B0-\u02B8' + '\u02BB-\u02C1\u02D0-\u02D1\u02E0-\u02E4\u02EE\u0370-\u0373\u0376-\u0377' + '\u037A\u037B-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1' + '\u03A3-\u03F5\u03F7-\u0481\u0482\u048A-\u052F\u0531-\u0556\u0559' + '\u055A-\u055F\u0561-\u0587\u0589\u0903\u0904-\u0939\u093B\u093D' + '\u093E-\u0940\u0949-\u094C\u094E-\u094F\u0950\u0958-\u0961\u0964-\u0965' + '\u0966-\u096F\u0970\u0971\u0972-\u0980\u0982-\u0983\u0985-\u098C' + '\u098F-\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD' + '\u09BE-\u09C0\u09C7-\u09C8\u09CB-\u09CC\u09CE\u09D7\u09DC-\u09DD' + '\u09DF-\u09E1\u09E6-\u09EF\u09F0-\u09F1\u09F4-\u09F9\u09FA\u0A03' + '\u0A05-\u0A0A\u0A0F-\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32-\u0A33' + '\u0A35-\u0A36\u0A38-\u0A39\u0A3E-\u0A40\u0A59-\u0A5C\u0A5E\u0A66-\u0A6F' + '\u0A72-\u0A74\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0' + '\u0AB2-\u0AB3\u0AB5-\u0AB9\u0ABD\u0ABE-\u0AC0\u0AC9\u0ACB-\u0ACC\u0AD0' + '\u0AE0-\u0AE1\u0AE6-\u0AEF\u0AF0\u0B02-\u0B03\u0B05-\u0B0C\u0B0F-\u0B10' + '\u0B13-\u0B28\u0B2A-\u0B30\u0B32-\u0B33\u0B35-\u0B39\u0B3D\u0B3E\u0B40' + '\u0B47-\u0B48\u0B4B-\u0B4C\u0B57\u0B5C-\u0B5D\u0B5F-\u0B61\u0B66-\u0B6F' + '\u0B70\u0B71\u0B72-\u0B77\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95' + '\u0B99-\u0B9A\u0B9C\u0B9E-\u0B9F\u0BA3-\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9' + '\u0BBE-\u0BBF\u0BC1-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCC\u0BD0\u0BD7' + '\u0BE6-\u0BEF\u0BF0-\u0BF2\u0C01-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10' + '\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C41-\u0C44\u0C58-\u0C59\u0C60-\u0C61' + '\u0C66-\u0C6F\u0C7F\u0C82-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8' + '\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CBE\u0CBF\u0CC0-\u0CC4\u0CC6' + '\u0CC7-\u0CC8\u0CCA-\u0CCB\u0CD5-\u0CD6\u0CDE\u0CE0-\u0CE1\u0CE6-\u0CEF' + '\u0CF1-\u0CF2\u0D02-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D' + '\u0D3E-\u0D40\u0D46-\u0D48\u0D4A-\u0D4C\u0D4E\u0D57\u0D60-\u0D61' + '\u0D66-\u0D6F\u0D70-\u0D75\u0D79\u0D7A-\u0D7F\u0D82-\u0D83\u0D85-\u0D96' + '\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCF-\u0DD1\u0DD8-\u0DDF' + '\u0DE6-\u0DEF\u0DF2-\u0DF3\u0DF4\u0E01-\u0E30\u0E32-\u0E33\u0E40-\u0E45' + '\u0E46\u0E4F\u0E50-\u0E59\u0E5A-\u0E5B\u0E81-\u0E82\u0E84\u0E87-\u0E88' + '\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7' + '\u0EAA-\u0EAB\u0EAD-\u0EB0\u0EB2-\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6' + '\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F01-\u0F03\u0F04-\u0F12\u0F13\u0F14' + '\u0F15-\u0F17\u0F1A-\u0F1F\u0F20-\u0F29\u0F2A-\u0F33\u0F34\u0F36\u0F38' + '\u0F3E-\u0F3F\u0F40-\u0F47\u0F49-\u0F6C\u0F7F\u0F85\u0F88-\u0F8C' + '\u0FBE-\u0FC5\u0FC7-\u0FCC\u0FCE-\u0FCF\u0FD0-\u0FD4\u0FD5-\u0FD8' + '\u0FD9-\u0FDA\u1000-\u102A\u102B-\u102C\u1031\u1038\u103B-\u103C\u103F' + '\u1040-\u1049\u104A-\u104F\u1050-\u1055\u1056-\u1057\u105A-\u105D\u1061' + '\u1062-\u1064\u1065-\u1066\u1067-\u106D\u106E-\u1070\u1075-\u1081' + '\u1083-\u1084\u1087-\u108C\u108E\u108F\u1090-\u1099\u109A-\u109C' + '\u109E-\u109F\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FB\u10FC' + '\u10FD-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288' + '\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5' + '\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1360-\u1368' + '\u1369-\u137C\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166D-\u166E' + '\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EB-\u16ED\u16EE-\u16F0' + '\u16F1-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1735-\u1736' + '\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17B6\u17BE-\u17C5' + '\u17C7-\u17C8\u17D4-\u17D6\u17D7\u17D8-\u17DA\u17DC\u17E0-\u17E9' + '\u1810-\u1819\u1820-\u1842\u1843\u1844-\u1877\u1880-\u18A8\u18AA' + '\u18B0-\u18F5\u1900-\u191E\u1923-\u1926\u1929-\u192B\u1930-\u1931' + '\u1933-\u1938\u1946-\u194F\u1950-\u196D\u1970-\u1974\u1980-\u19AB' + '\u19B0-\u19C0\u19C1-\u19C7\u19C8-\u19C9\u19D0-\u19D9\u19DA\u1A00-\u1A16' + '\u1A19-\u1A1A\u1A1E-\u1A1F\u1A20-\u1A54\u1A55\u1A57\u1A61\u1A63-\u1A64' + '\u1A6D-\u1A72\u1A80-\u1A89\u1A90-\u1A99\u1AA0-\u1AA6\u1AA7\u1AA8-\u1AAD' + '\u1B04\u1B05-\u1B33\u1B35\u1B3B\u1B3D-\u1B41\u1B43-\u1B44\u1B45-\u1B4B' + '\u1B50-\u1B59\u1B5A-\u1B60\u1B61-\u1B6A\u1B74-\u1B7C\u1B82\u1B83-\u1BA0' + '\u1BA1\u1BA6-\u1BA7\u1BAA\u1BAE-\u1BAF\u1BB0-\u1BB9\u1BBA-\u1BE5\u1BE7' + '\u1BEA-\u1BEC\u1BEE\u1BF2-\u1BF3\u1BFC-\u1BFF\u1C00-\u1C23\u1C24-\u1C2B' + '\u1C34-\u1C35\u1C3B-\u1C3F\u1C40-\u1C49\u1C4D-\u1C4F\u1C50-\u1C59' + '\u1C5A-\u1C77\u1C78-\u1C7D\u1C7E-\u1C7F\u1CC0-\u1CC7\u1CD3\u1CE1' + '\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF2-\u1CF3\u1CF5-\u1CF6\u1D00-\u1D2B' + '\u1D2C-\u1D6A\u1D6B-\u1D77\u1D78\u1D79-\u1D9A\u1D9B-\u1DBF\u1E00-\u1F15' + '\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D' + '\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC' + '\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200E' + '\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D' + '\u2124\u2126\u2128\u212A-\u212D\u212F-\u2134\u2135-\u2138\u2139' + '\u213C-\u213F\u2145-\u2149\u214E\u214F\u2160-\u2182\u2183-\u2184' + '\u2185-\u2188\u2336-\u237A\u2395\u249C-\u24E9\u26AC\u2800-\u28FF' + '\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2C7B\u2C7C-\u2C7D\u2C7E-\u2CE4' + '\u2CEB-\u2CEE\u2CF2-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F' + '\u2D70\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE' + '\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005\u3006\u3007' + '\u3021-\u3029\u302E-\u302F\u3031-\u3035\u3038-\u303A\u303B\u303C' + '\u3041-\u3096\u309D-\u309E\u309F\u30A1-\u30FA\u30FC-\u30FE\u30FF' + '\u3105-\u312D\u3131-\u318E\u3190-\u3191\u3192-\u3195\u3196-\u319F' + '\u31A0-\u31BA\u31F0-\u31FF\u3200-\u321C\u3220-\u3229\u322A-\u3247' + '\u3248-\u324F\u3260-\u327B\u327F\u3280-\u3289\u328A-\u32B0\u32C0-\u32CB' + '\u32D0-\u32FE\u3300-\u3376\u337B-\u33DD\u33E0-\u33FE\u3400-\u4DB5' + '\u4E00-\u9FCC\uA000-\uA014\uA015\uA016-\uA48C\uA4D0-\uA4F7\uA4F8-\uA4FD' + '\uA4FE-\uA4FF\uA500-\uA60B\uA60C\uA610-\uA61F\uA620-\uA629\uA62A-\uA62B' + '\uA640-\uA66D\uA66E\uA680-\uA69B\uA69C-\uA69D\uA6A0-\uA6E5\uA6E6-\uA6EF' + '\uA6F2-\uA6F7\uA722-\uA76F\uA770\uA771-\uA787\uA789-\uA78A\uA78B-\uA78E' + '\uA790-\uA7AD\uA7B0-\uA7B1\uA7F7\uA7F8-\uA7F9\uA7FA\uA7FB-\uA801' + '\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA823-\uA824\uA827\uA830-\uA835' + '\uA836-\uA837\uA840-\uA873\uA880-\uA881\uA882-\uA8B3\uA8B4-\uA8C3' + '\uA8CE-\uA8CF\uA8D0-\uA8D9\uA8F2-\uA8F7\uA8F8-\uA8FA\uA8FB\uA900-\uA909' + '\uA90A-\uA925\uA92E-\uA92F\uA930-\uA946\uA952-\uA953\uA95F\uA960-\uA97C' + '\uA983\uA984-\uA9B2\uA9B4-\uA9B5\uA9BA-\uA9BB\uA9BD-\uA9C0\uA9C1-\uA9CD' + '\uA9CF\uA9D0-\uA9D9\uA9DE-\uA9DF\uA9E0-\uA9E4\uA9E6\uA9E7-\uA9EF' + '\uA9F0-\uA9F9\uA9FA-\uA9FE\uAA00-\uAA28\uAA2F-\uAA30\uAA33-\uAA34' + '\uAA40-\uAA42\uAA44-\uAA4B\uAA4D\uAA50-\uAA59\uAA5C-\uAA5F\uAA60-\uAA6F' + '\uAA70\uAA71-\uAA76\uAA77-\uAA79\uAA7A\uAA7B\uAA7D\uAA7E-\uAAAF\uAAB1' + '\uAAB5-\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADC\uAADD\uAADE-\uAADF' + '\uAAE0-\uAAEA\uAAEB\uAAEE-\uAAEF\uAAF0-\uAAF1\uAAF2\uAAF3-\uAAF4\uAAF5' + '\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E' + '\uAB30-\uAB5A\uAB5B\uAB5C-\uAB5F\uAB64-\uAB65\uABC0-\uABE2\uABE3-\uABE4' + '\uABE6-\uABE7\uABE9-\uABEA\uABEB\uABEC\uABF0-\uABF9\uAC00-\uD7A3' + '\uD7B0-\uD7C6\uD7CB-\uD7FB\uE000-\uF8FF\uF900-\uFA6D\uFA70-\uFAD9' + '\uFB00-\uFB06\uFB13-\uFB17\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFF6F\uFF70' + '\uFF71-\uFF9D\uFF9E-\uFF9F\uFFA0-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF' + '\uFFD2-\uFFD7\uFFDA-\uFFDC',
  6461. R: '\u0590\u05BE\u05C0\u05C3\u05C6\u05C8-\u05CF\u05D0-\u05EA\u05EB-\u05EF' + '\u05F0-\u05F2\u05F3-\u05F4\u05F5-\u05FF\u07C0-\u07C9\u07CA-\u07EA' + '\u07F4-\u07F5\u07FA\u07FB-\u07FF\u0800-\u0815\u081A\u0824\u0828' + '\u082E-\u082F\u0830-\u083E\u083F\u0840-\u0858\u085C-\u085D\u085E' + '\u085F-\u089F\u200F\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB37\uFB38-\uFB3C' + '\uFB3D\uFB3E\uFB3F\uFB40-\uFB41\uFB42\uFB43-\uFB44\uFB45\uFB46-\uFB4F',
  6462. AL: '\u0608\u060B\u060D\u061B\u061C\u061D\u061E-\u061F\u0620-\u063F\u0640' + '\u0641-\u064A\u066D\u066E-\u066F\u0671-\u06D3\u06D4\u06D5\u06E5-\u06E6' + '\u06EE-\u06EF\u06FA-\u06FC\u06FD-\u06FE\u06FF\u0700-\u070D\u070E\u070F' + '\u0710\u0712-\u072F\u074B-\u074C\u074D-\u07A5\u07B1\u07B2-\u07BF' + '\u08A0-\u08B2\u08B3-\u08E3\uFB50-\uFBB1\uFBB2-\uFBC1\uFBC2-\uFBD2' + '\uFBD3-\uFD3D\uFD40-\uFD4F\uFD50-\uFD8F\uFD90-\uFD91\uFD92-\uFDC7' + '\uFDC8-\uFDCF\uFDF0-\uFDFB\uFDFC\uFDFE-\uFDFF\uFE70-\uFE74\uFE75' + '\uFE76-\uFEFC\uFEFD-\uFEFE'
  6463. };
  6464. var REGEX_STRONG = new RegExp('[' + RANGE_BY_BIDI_TYPE.L + RANGE_BY_BIDI_TYPE.R + RANGE_BY_BIDI_TYPE.AL + ']');
  6465. var REGEX_RTL = new RegExp('[' + RANGE_BY_BIDI_TYPE.R + RANGE_BY_BIDI_TYPE.AL + ']');
  6466. /**
  6467. * Returns the first strong character (has Bidi_Class value of L, R, or AL).
  6468. *
  6469. * @param str A text block; e.g. paragraph, table cell, tag
  6470. * @return A character with strong bidi direction, or null if not found
  6471. */
  6472. function firstStrongChar(str) {
  6473. var match = REGEX_STRONG.exec(str);
  6474. return match == null ? null : match[0];
  6475. }
  6476. /**
  6477. * Returns the direction of a block of text, based on the direction of its
  6478. * first strong character (has Bidi_Class value of L, R, or AL).
  6479. *
  6480. * @param str A text block; e.g. paragraph, table cell, tag
  6481. * @return The resolved direction
  6482. */
  6483. function firstStrongCharDir(str) {
  6484. var strongChar = firstStrongChar(str);
  6485. if (strongChar == null) {
  6486. return UnicodeBidiDirection_1.NEUTRAL;
  6487. }
  6488. return REGEX_RTL.exec(strongChar) ? UnicodeBidiDirection_1.RTL : UnicodeBidiDirection_1.LTR;
  6489. }
  6490. /**
  6491. * Returns the direction of a block of text, based on the direction of its
  6492. * first strong character (has Bidi_Class value of L, R, or AL), or a fallback
  6493. * direction, if no strong character is found.
  6494. *
  6495. * This function is supposed to be used in respect to Higher-Level Protocol
  6496. * rule HL1. (http://www.unicode.org/reports/tr9/#HL1)
  6497. *
  6498. * @param str A text block; e.g. paragraph, table cell, tag
  6499. * @param fallback Fallback direction, used if no strong direction detected
  6500. * for the block (default = NEUTRAL)
  6501. * @return The resolved direction
  6502. */
  6503. function resolveBlockDir(str, fallback) {
  6504. fallback = fallback || UnicodeBidiDirection_1.NEUTRAL;
  6505. if (!str.length) {
  6506. return fallback;
  6507. }
  6508. var blockDir = firstStrongCharDir(str);
  6509. return blockDir === UnicodeBidiDirection_1.NEUTRAL ? fallback : blockDir;
  6510. }
  6511. /**
  6512. * Returns the direction of a block of text, based on the direction of its
  6513. * first strong character (has Bidi_Class value of L, R, or AL), or a fallback
  6514. * direction, if no strong character is found.
  6515. *
  6516. * NOTE: This function is similar to resolveBlockDir(), but uses the global
  6517. * direction as the fallback, so it *always* returns a Strong direction,
  6518. * making it useful for integration in places that you need to make the final
  6519. * decision, like setting some CSS class.
  6520. *
  6521. * This function is supposed to be used in respect to Higher-Level Protocol
  6522. * rule HL1. (http://www.unicode.org/reports/tr9/#HL1)
  6523. *
  6524. * @param str A text block; e.g. paragraph, table cell
  6525. * @param strongFallback Fallback direction, used if no strong direction
  6526. * detected for the block (default = global direction)
  6527. * @return The resolved Strong direction
  6528. */
  6529. function getDirection(str, strongFallback) {
  6530. if (!strongFallback) {
  6531. strongFallback = UnicodeBidiDirection_1.getGlobalDir();
  6532. }
  6533. !UnicodeBidiDirection_1.isStrong(strongFallback) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Fallback direction must be a strong direction') : invariant_1(false) : void 0;
  6534. return resolveBlockDir(str, strongFallback);
  6535. }
  6536. /**
  6537. * Returns true if getDirection(arguments...) returns LTR.
  6538. *
  6539. * @param str A text block; e.g. paragraph, table cell
  6540. * @param strongFallback Fallback direction, used if no strong direction
  6541. * detected for the block (default = global direction)
  6542. * @return True if the resolved direction is LTR
  6543. */
  6544. function isDirectionLTR(str, strongFallback) {
  6545. return getDirection(str, strongFallback) === UnicodeBidiDirection_1.LTR;
  6546. }
  6547. /**
  6548. * Returns true if getDirection(arguments...) returns RTL.
  6549. *
  6550. * @param str A text block; e.g. paragraph, table cell
  6551. * @param strongFallback Fallback direction, used if no strong direction
  6552. * detected for the block (default = global direction)
  6553. * @return True if the resolved direction is RTL
  6554. */
  6555. function isDirectionRTL(str, strongFallback) {
  6556. return getDirection(str, strongFallback) === UnicodeBidiDirection_1.RTL;
  6557. }
  6558. var UnicodeBidi = {
  6559. firstStrongChar: firstStrongChar,
  6560. firstStrongCharDir: firstStrongCharDir,
  6561. resolveBlockDir: resolveBlockDir,
  6562. getDirection: getDirection,
  6563. isDirectionLTR: isDirectionLTR,
  6564. isDirectionRTL: isDirectionRTL
  6565. };
  6566. var UnicodeBidi_1 = UnicodeBidi;
  6567. function _classCallCheck$6(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6568. var UnicodeBidiService = function () {
  6569. /**
  6570. * Stateful class for paragraph direction detection
  6571. *
  6572. * @param defaultDir Default direction of the service
  6573. */
  6574. function UnicodeBidiService(defaultDir) {
  6575. _classCallCheck$6(this, UnicodeBidiService);
  6576. if (!defaultDir) {
  6577. defaultDir = UnicodeBidiDirection_1.getGlobalDir();
  6578. } else {
  6579. !UnicodeBidiDirection_1.isStrong(defaultDir) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Default direction must be a strong direction (LTR or RTL)') : invariant_1(false) : void 0;
  6580. }
  6581. this._defaultDir = defaultDir;
  6582. this.reset();
  6583. }
  6584. /**
  6585. * Reset the internal state
  6586. *
  6587. * Instead of creating a new instance, you can just reset() your instance
  6588. * everytime you start a new loop.
  6589. */
  6590. UnicodeBidiService.prototype.reset = function reset() {
  6591. this._lastDir = this._defaultDir;
  6592. };
  6593. /**
  6594. * Returns the direction of a block of text, and remembers it as the
  6595. * fall-back direction for the next paragraph.
  6596. *
  6597. * @param str A text block, e.g. paragraph, table cell, tag
  6598. * @return The resolved direction
  6599. */
  6600. UnicodeBidiService.prototype.getDirection = function getDirection(str) {
  6601. this._lastDir = UnicodeBidi_1.getDirection(str, this._lastDir);
  6602. return this._lastDir;
  6603. };
  6604. return UnicodeBidiService;
  6605. }();
  6606. var UnicodeBidiService_1 = UnicodeBidiService;
  6607. /**
  6608. * Copyright (c) 2013-present, Facebook, Inc.
  6609. *
  6610. * This source code is licensed under the MIT license found in the
  6611. * LICENSE file in the root directory of this source tree.
  6612. *
  6613. *
  6614. */
  6615. var nullthrows = function nullthrows(x) {
  6616. if (x != null) {
  6617. return x;
  6618. }
  6619. throw new Error("Got unexpected null or undefined");
  6620. };
  6621. var nullthrows_1 = nullthrows;
  6622. var OrderedMap$2 = immutable.OrderedMap;
  6623. var bidiService;
  6624. var EditorBidiService = {
  6625. getDirectionMap: function getDirectionMap(content, prevBidiMap) {
  6626. if (!bidiService) {
  6627. bidiService = new UnicodeBidiService_1();
  6628. } else {
  6629. bidiService.reset();
  6630. }
  6631. var blockMap = content.getBlockMap();
  6632. var nextBidi = blockMap.valueSeq().map(function (block) {
  6633. return nullthrows_1(bidiService).getDirection(block.getText());
  6634. });
  6635. var bidiMap = OrderedMap$2(blockMap.keySeq().zip(nextBidi));
  6636. if (prevBidiMap != null && immutable.is(prevBidiMap, bidiMap)) {
  6637. return prevBidiMap;
  6638. }
  6639. return bidiMap;
  6640. }
  6641. };
  6642. var EditorBidiService_1 = EditorBidiService;
  6643. var _extends$1 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  6644. function _classCallCheck$7(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6645. var OrderedSet$4 = immutable.OrderedSet,
  6646. Record$7 = immutable.Record,
  6647. Stack = immutable.Stack;
  6648. var defaultRecord$5 = {
  6649. allowUndo: true,
  6650. currentContent: null,
  6651. decorator: null,
  6652. directionMap: null,
  6653. forceSelection: false,
  6654. inCompositionMode: false,
  6655. inlineStyleOverride: null,
  6656. lastChangeType: null,
  6657. nativelyRenderedContent: null,
  6658. redoStack: Stack(),
  6659. selection: null,
  6660. treeMap: null,
  6661. undoStack: Stack()
  6662. };
  6663. var EditorStateRecord = Record$7(defaultRecord$5);
  6664. var EditorState = function () {
  6665. EditorState.createEmpty = function createEmpty(decorator) {
  6666. return EditorState.createWithContent(ContentState_1.createFromText(''), decorator);
  6667. };
  6668. EditorState.createWithContent = function createWithContent(contentState, decorator) {
  6669. var firstKey = contentState.getBlockMap().first().getKey();
  6670. return EditorState.create({
  6671. currentContent: contentState,
  6672. undoStack: Stack(),
  6673. redoStack: Stack(),
  6674. decorator: decorator || null,
  6675. selection: SelectionState_1.createEmpty(firstKey)
  6676. });
  6677. };
  6678. EditorState.create = function create(config) {
  6679. var currentContent = config.currentContent,
  6680. decorator = config.decorator;
  6681. var recordConfig = _extends$1({}, config, {
  6682. treeMap: generateNewTreeMap(currentContent, decorator),
  6683. directionMap: EditorBidiService_1.getDirectionMap(currentContent)
  6684. });
  6685. return new EditorState(new EditorStateRecord(recordConfig));
  6686. };
  6687. EditorState.set = function set(editorState, put) {
  6688. var map = editorState.getImmutable().withMutations(function (state) {
  6689. var existingDecorator = state.get('decorator');
  6690. var decorator = existingDecorator;
  6691. if (put.decorator === null) {
  6692. decorator = null;
  6693. } else if (put.decorator) {
  6694. decorator = put.decorator;
  6695. }
  6696. var newContent = put.currentContent || editorState.getCurrentContent();
  6697. if (decorator !== existingDecorator) {
  6698. var treeMap = state.get('treeMap');
  6699. var newTreeMap;
  6700. if (decorator && existingDecorator) {
  6701. newTreeMap = regenerateTreeForNewDecorator(newContent, newContent.getBlockMap(), treeMap, decorator, existingDecorator);
  6702. } else {
  6703. newTreeMap = generateNewTreeMap(newContent, decorator);
  6704. }
  6705. state.merge({
  6706. decorator: decorator,
  6707. treeMap: newTreeMap,
  6708. nativelyRenderedContent: null
  6709. });
  6710. return;
  6711. }
  6712. var existingContent = editorState.getCurrentContent();
  6713. if (newContent !== existingContent) {
  6714. state.set('treeMap', regenerateTreeForNewBlocks(editorState, newContent.getBlockMap(), newContent.getEntityMap(), decorator));
  6715. }
  6716. state.merge(put);
  6717. });
  6718. return new EditorState(map);
  6719. };
  6720. EditorState.prototype.toJS = function toJS() {
  6721. return this.getImmutable().toJS();
  6722. };
  6723. EditorState.prototype.getAllowUndo = function getAllowUndo() {
  6724. return this.getImmutable().get('allowUndo');
  6725. };
  6726. EditorState.prototype.getCurrentContent = function getCurrentContent() {
  6727. return this.getImmutable().get('currentContent');
  6728. };
  6729. EditorState.prototype.getUndoStack = function getUndoStack() {
  6730. return this.getImmutable().get('undoStack');
  6731. };
  6732. EditorState.prototype.getRedoStack = function getRedoStack() {
  6733. return this.getImmutable().get('redoStack');
  6734. };
  6735. EditorState.prototype.getSelection = function getSelection() {
  6736. return this.getImmutable().get('selection');
  6737. };
  6738. EditorState.prototype.getDecorator = function getDecorator() {
  6739. return this.getImmutable().get('decorator');
  6740. };
  6741. EditorState.prototype.isInCompositionMode = function isInCompositionMode() {
  6742. return this.getImmutable().get('inCompositionMode');
  6743. };
  6744. EditorState.prototype.mustForceSelection = function mustForceSelection() {
  6745. return this.getImmutable().get('forceSelection');
  6746. };
  6747. EditorState.prototype.getNativelyRenderedContent = function getNativelyRenderedContent() {
  6748. return this.getImmutable().get('nativelyRenderedContent');
  6749. };
  6750. EditorState.prototype.getLastChangeType = function getLastChangeType() {
  6751. return this.getImmutable().get('lastChangeType');
  6752. };
  6753. /**
  6754. * While editing, the user may apply inline style commands with a collapsed
  6755. * cursor, intending to type text that adopts the specified style. In this
  6756. * case, we track the specified style as an "override" that takes precedence
  6757. * over the inline style of the text adjacent to the cursor.
  6758. *
  6759. * If null, there is no override in place.
  6760. */
  6761. EditorState.prototype.getInlineStyleOverride = function getInlineStyleOverride() {
  6762. return this.getImmutable().get('inlineStyleOverride');
  6763. };
  6764. EditorState.setInlineStyleOverride = function setInlineStyleOverride(editorState, inlineStyleOverride) {
  6765. return EditorState.set(editorState, { inlineStyleOverride: inlineStyleOverride });
  6766. };
  6767. /**
  6768. * Get the appropriate inline style for the editor state. If an
  6769. * override is in place, use it. Otherwise, the current style is
  6770. * based on the location of the selection state.
  6771. */
  6772. EditorState.prototype.getCurrentInlineStyle = function getCurrentInlineStyle() {
  6773. var override = this.getInlineStyleOverride();
  6774. if (override != null) {
  6775. return override;
  6776. }
  6777. var content = this.getCurrentContent();
  6778. var selection = this.getSelection();
  6779. if (selection.isCollapsed()) {
  6780. return getInlineStyleForCollapsedSelection(content, selection);
  6781. }
  6782. return getInlineStyleForNonCollapsedSelection(content, selection);
  6783. };
  6784. EditorState.prototype.getBlockTree = function getBlockTree(blockKey) {
  6785. return this.getImmutable().getIn(['treeMap', blockKey]);
  6786. };
  6787. EditorState.prototype.isSelectionAtStartOfContent = function isSelectionAtStartOfContent() {
  6788. var firstKey = this.getCurrentContent().getBlockMap().first().getKey();
  6789. return this.getSelection().hasEdgeWithin(firstKey, 0, 0);
  6790. };
  6791. EditorState.prototype.isSelectionAtEndOfContent = function isSelectionAtEndOfContent() {
  6792. var content = this.getCurrentContent();
  6793. var blockMap = content.getBlockMap();
  6794. var last = blockMap.last();
  6795. var end = last.getLength();
  6796. return this.getSelection().hasEdgeWithin(last.getKey(), end, end);
  6797. };
  6798. EditorState.prototype.getDirectionMap = function getDirectionMap() {
  6799. return this.getImmutable().get('directionMap');
  6800. };
  6801. /**
  6802. * Incorporate native DOM selection changes into the EditorState. This
  6803. * method can be used when we simply want to accept whatever the DOM
  6804. * has given us to represent selection, and we do not need to re-render
  6805. * the editor.
  6806. *
  6807. * To forcibly move the DOM selection, see `EditorState.forceSelection`.
  6808. */
  6809. EditorState.acceptSelection = function acceptSelection(editorState, selection) {
  6810. return updateSelection(editorState, selection, false);
  6811. };
  6812. /**
  6813. * At times, we need to force the DOM selection to be where we
  6814. * need it to be. This can occur when the anchor or focus nodes
  6815. * are non-text nodes, for instance. In this case, we want to trigger
  6816. * a re-render of the editor, which in turn forces selection into
  6817. * the correct place in the DOM. The `forceSelection` method
  6818. * accomplishes this.
  6819. *
  6820. * This method should be used in cases where you need to explicitly
  6821. * move the DOM selection from one place to another without a change
  6822. * in ContentState.
  6823. */
  6824. EditorState.forceSelection = function forceSelection(editorState, selection) {
  6825. if (!selection.getHasFocus()) {
  6826. selection = selection.set('hasFocus', true);
  6827. }
  6828. return updateSelection(editorState, selection, true);
  6829. };
  6830. /**
  6831. * Move selection to the end of the editor without forcing focus.
  6832. */
  6833. EditorState.moveSelectionToEnd = function moveSelectionToEnd(editorState) {
  6834. var content = editorState.getCurrentContent();
  6835. var lastBlock = content.getLastBlock();
  6836. var lastKey = lastBlock.getKey();
  6837. var length = lastBlock.getLength();
  6838. return EditorState.acceptSelection(editorState, new SelectionState_1({
  6839. anchorKey: lastKey,
  6840. anchorOffset: length,
  6841. focusKey: lastKey,
  6842. focusOffset: length,
  6843. isBackward: false
  6844. }));
  6845. };
  6846. /**
  6847. * Force focus to the end of the editor. This is useful in scenarios
  6848. * where we want to programmatically focus the input and it makes sense
  6849. * to allow the user to continue working seamlessly.
  6850. */
  6851. EditorState.moveFocusToEnd = function moveFocusToEnd(editorState) {
  6852. var afterSelectionMove = EditorState.moveSelectionToEnd(editorState);
  6853. return EditorState.forceSelection(afterSelectionMove, afterSelectionMove.getSelection());
  6854. };
  6855. /**
  6856. * Push the current ContentState onto the undo stack if it should be
  6857. * considered a boundary state, and set the provided ContentState as the
  6858. * new current content.
  6859. */
  6860. EditorState.push = function push(editorState, contentState, changeType) {
  6861. if (editorState.getCurrentContent() === contentState) {
  6862. return editorState;
  6863. }
  6864. var forceSelection = changeType !== 'insert-characters';
  6865. var directionMap = EditorBidiService_1.getDirectionMap(contentState, editorState.getDirectionMap());
  6866. if (!editorState.getAllowUndo()) {
  6867. return EditorState.set(editorState, {
  6868. currentContent: contentState,
  6869. directionMap: directionMap,
  6870. lastChangeType: changeType,
  6871. selection: contentState.getSelectionAfter(),
  6872. forceSelection: forceSelection,
  6873. inlineStyleOverride: null
  6874. });
  6875. }
  6876. var selection = editorState.getSelection();
  6877. var currentContent = editorState.getCurrentContent();
  6878. var undoStack = editorState.getUndoStack();
  6879. var newContent = contentState;
  6880. if (selection !== currentContent.getSelectionAfter() || mustBecomeBoundary(editorState, changeType)) {
  6881. undoStack = undoStack.push(currentContent);
  6882. newContent = newContent.set('selectionBefore', selection);
  6883. } else if (changeType === 'insert-characters' || changeType === 'backspace-character' || changeType === 'delete-character') {
  6884. // Preserve the previous selection.
  6885. newContent = newContent.set('selectionBefore', currentContent.getSelectionBefore());
  6886. }
  6887. var inlineStyleOverride = editorState.getInlineStyleOverride();
  6888. // Don't discard inline style overrides for the following change types:
  6889. var overrideChangeTypes = ['adjust-depth', 'change-block-type', 'split-block'];
  6890. if (overrideChangeTypes.indexOf(changeType) === -1) {
  6891. inlineStyleOverride = null;
  6892. }
  6893. var editorStateChanges = {
  6894. currentContent: newContent,
  6895. directionMap: directionMap,
  6896. undoStack: undoStack,
  6897. redoStack: Stack(),
  6898. lastChangeType: changeType,
  6899. selection: contentState.getSelectionAfter(),
  6900. forceSelection: forceSelection,
  6901. inlineStyleOverride: inlineStyleOverride
  6902. };
  6903. return EditorState.set(editorState, editorStateChanges);
  6904. };
  6905. /**
  6906. * Make the top ContentState in the undo stack the new current content and
  6907. * push the current content onto the redo stack.
  6908. */
  6909. EditorState.undo = function undo(editorState) {
  6910. if (!editorState.getAllowUndo()) {
  6911. return editorState;
  6912. }
  6913. var undoStack = editorState.getUndoStack();
  6914. var newCurrentContent = undoStack.peek();
  6915. if (!newCurrentContent) {
  6916. return editorState;
  6917. }
  6918. var currentContent = editorState.getCurrentContent();
  6919. var directionMap = EditorBidiService_1.getDirectionMap(newCurrentContent, editorState.getDirectionMap());
  6920. return EditorState.set(editorState, {
  6921. currentContent: newCurrentContent,
  6922. directionMap: directionMap,
  6923. undoStack: undoStack.shift(),
  6924. redoStack: editorState.getRedoStack().push(currentContent),
  6925. forceSelection: true,
  6926. inlineStyleOverride: null,
  6927. lastChangeType: 'undo',
  6928. nativelyRenderedContent: null,
  6929. selection: currentContent.getSelectionBefore()
  6930. });
  6931. };
  6932. /**
  6933. * Make the top ContentState in the redo stack the new current content and
  6934. * push the current content onto the undo stack.
  6935. */
  6936. EditorState.redo = function redo(editorState) {
  6937. if (!editorState.getAllowUndo()) {
  6938. return editorState;
  6939. }
  6940. var redoStack = editorState.getRedoStack();
  6941. var newCurrentContent = redoStack.peek();
  6942. if (!newCurrentContent) {
  6943. return editorState;
  6944. }
  6945. var currentContent = editorState.getCurrentContent();
  6946. var directionMap = EditorBidiService_1.getDirectionMap(newCurrentContent, editorState.getDirectionMap());
  6947. return EditorState.set(editorState, {
  6948. currentContent: newCurrentContent,
  6949. directionMap: directionMap,
  6950. undoStack: editorState.getUndoStack().push(currentContent),
  6951. redoStack: redoStack.shift(),
  6952. forceSelection: true,
  6953. inlineStyleOverride: null,
  6954. lastChangeType: 'redo',
  6955. nativelyRenderedContent: null,
  6956. selection: newCurrentContent.getSelectionAfter()
  6957. });
  6958. };
  6959. /**
  6960. * Not for public consumption.
  6961. */
  6962. function EditorState(immutable) {
  6963. _classCallCheck$7(this, EditorState);
  6964. this._immutable = immutable;
  6965. }
  6966. /**
  6967. * Not for public consumption.
  6968. */
  6969. EditorState.prototype.getImmutable = function getImmutable() {
  6970. return this._immutable;
  6971. };
  6972. return EditorState;
  6973. }();
  6974. /**
  6975. * Set the supplied SelectionState as the new current selection, and set
  6976. * the `force` flag to trigger manual selection placement by the view.
  6977. */
  6978. function updateSelection(editorState, selection, forceSelection) {
  6979. return EditorState.set(editorState, {
  6980. selection: selection,
  6981. forceSelection: forceSelection,
  6982. nativelyRenderedContent: null,
  6983. inlineStyleOverride: null
  6984. });
  6985. }
  6986. /**
  6987. * Regenerate the entire tree map for a given ContentState and decorator.
  6988. * Returns an OrderedMap that maps all available ContentBlock objects.
  6989. */
  6990. function generateNewTreeMap(contentState, decorator) {
  6991. return contentState.getBlockMap().map(function (block) {
  6992. return BlockTree_1.generate(contentState, block, decorator);
  6993. }).toOrderedMap();
  6994. }
  6995. /**
  6996. * Regenerate tree map objects for all ContentBlocks that have changed
  6997. * between the current editorState and newContent. Returns an OrderedMap
  6998. * with only changed regenerated tree map objects.
  6999. */
  7000. function regenerateTreeForNewBlocks(editorState, newBlockMap, newEntityMap, decorator) {
  7001. var contentState = editorState.getCurrentContent().set('entityMap', newEntityMap);
  7002. var prevBlockMap = contentState.getBlockMap();
  7003. var prevTreeMap = editorState.getImmutable().get('treeMap');
  7004. return prevTreeMap.merge(newBlockMap.toSeq().filter(function (block, key) {
  7005. return block !== prevBlockMap.get(key);
  7006. }).map(function (block) {
  7007. return BlockTree_1.generate(contentState, block, decorator);
  7008. }));
  7009. }
  7010. /**
  7011. * Generate tree map objects for a new decorator object, preserving any
  7012. * decorations that are unchanged from the previous decorator.
  7013. *
  7014. * Note that in order for this to perform optimally, decoration Lists for
  7015. * decorators should be preserved when possible to allow for direct immutable
  7016. * List comparison.
  7017. */
  7018. function regenerateTreeForNewDecorator(content, blockMap, previousTreeMap, decorator, existingDecorator) {
  7019. return previousTreeMap.merge(blockMap.toSeq().filter(function (block) {
  7020. return decorator.getDecorations(block, content) !== existingDecorator.getDecorations(block, content);
  7021. }).map(function (block) {
  7022. return BlockTree_1.generate(content, block, decorator);
  7023. }));
  7024. }
  7025. /**
  7026. * Return whether a change should be considered a boundary state, given
  7027. * the previous change type. Allows us to discard potential boundary states
  7028. * during standard typing or deletion behavior.
  7029. */
  7030. function mustBecomeBoundary(editorState, changeType) {
  7031. var lastChangeType = editorState.getLastChangeType();
  7032. return changeType !== lastChangeType || changeType !== 'insert-characters' && changeType !== 'backspace-character' && changeType !== 'delete-character';
  7033. }
  7034. function getInlineStyleForCollapsedSelection(content, selection) {
  7035. var startKey = selection.getStartKey();
  7036. var startOffset = selection.getStartOffset();
  7037. var startBlock = content.getBlockForKey(startKey);
  7038. // If the cursor is not at the start of the block, look backward to
  7039. // preserve the style of the preceding character.
  7040. if (startOffset > 0) {
  7041. return startBlock.getInlineStyleAt(startOffset - 1);
  7042. }
  7043. // The caret is at position zero in this block. If the block has any
  7044. // text at all, use the style of the first character.
  7045. if (startBlock.getLength()) {
  7046. return startBlock.getInlineStyleAt(0);
  7047. }
  7048. // Otherwise, look upward in the document to find the closest character.
  7049. return lookUpwardForInlineStyle(content, startKey);
  7050. }
  7051. function getInlineStyleForNonCollapsedSelection(content, selection) {
  7052. var startKey = selection.getStartKey();
  7053. var startOffset = selection.getStartOffset();
  7054. var startBlock = content.getBlockForKey(startKey);
  7055. // If there is a character just inside the selection, use its style.
  7056. if (startOffset < startBlock.getLength()) {
  7057. return startBlock.getInlineStyleAt(startOffset);
  7058. }
  7059. // Check if the selection at the end of a non-empty block. Use the last
  7060. // style in the block.
  7061. if (startOffset > 0) {
  7062. return startBlock.getInlineStyleAt(startOffset - 1);
  7063. }
  7064. // Otherwise, look upward in the document to find the closest character.
  7065. return lookUpwardForInlineStyle(content, startKey);
  7066. }
  7067. function lookUpwardForInlineStyle(content, fromKey) {
  7068. var lastNonEmpty = content.getBlockMap().reverse().skipUntil(function (_, k) {
  7069. return k === fromKey;
  7070. }).skip(1).skipUntil(function (block, _) {
  7071. return block.getLength();
  7072. }).first();
  7073. if (lastNonEmpty) return lastNonEmpty.getInlineStyleAt(lastNonEmpty.getLength() - 1);
  7074. return OrderedSet$4();
  7075. }
  7076. var EditorState_1 = EditorState;
  7077. var OrderedMap$3 = immutable.OrderedMap,
  7078. List$7 = immutable.List;
  7079. var transformBlock$2 = function transformBlock(key, blockMap, func) {
  7080. if (!key) {
  7081. return;
  7082. }
  7083. var block = blockMap.get(key);
  7084. if (!block) {
  7085. return;
  7086. }
  7087. blockMap.set(key, func(block));
  7088. };
  7089. var updateBlockMapLinks$3 = function updateBlockMapLinks(blockMap, originalBlockToBeMoved, originalTargetBlock, insertionMode, isExperimentalTreeBlock) {
  7090. if (!isExperimentalTreeBlock) {
  7091. return blockMap;
  7092. }
  7093. // possible values of 'insertionMode' are: 'after', 'before'
  7094. var isInsertedAfterTarget = insertionMode === 'after';
  7095. var originalBlockKey = originalBlockToBeMoved.getKey();
  7096. var originalTargetKey = originalTargetBlock.getKey();
  7097. var originalParentKey = originalBlockToBeMoved.getParentKey();
  7098. var originalNextSiblingKey = originalBlockToBeMoved.getNextSiblingKey();
  7099. var originalPrevSiblingKey = originalBlockToBeMoved.getPrevSiblingKey();
  7100. var newParentKey = originalTargetBlock.getParentKey();
  7101. var newNextSiblingKey = isInsertedAfterTarget ? originalTargetBlock.getNextSiblingKey() : originalTargetKey;
  7102. var newPrevSiblingKey = isInsertedAfterTarget ? originalTargetKey : originalTargetBlock.getPrevSiblingKey();
  7103. return blockMap.withMutations(function (blocks) {
  7104. // update old parent
  7105. transformBlock$2(originalParentKey, blocks, function (block) {
  7106. var parentChildrenList = block.getChildKeys();
  7107. return block.merge({
  7108. children: parentChildrenList['delete'](parentChildrenList.indexOf(originalBlockKey))
  7109. });
  7110. });
  7111. // update old prev
  7112. transformBlock$2(originalPrevSiblingKey, blocks, function (block) {
  7113. return block.merge({
  7114. nextSibling: originalNextSiblingKey
  7115. });
  7116. });
  7117. // update old next
  7118. transformBlock$2(originalNextSiblingKey, blocks, function (block) {
  7119. return block.merge({
  7120. prevSibling: originalPrevSiblingKey
  7121. });
  7122. });
  7123. // update new next
  7124. transformBlock$2(newNextSiblingKey, blocks, function (block) {
  7125. return block.merge({
  7126. prevSibling: originalBlockKey
  7127. });
  7128. });
  7129. // update new prev
  7130. transformBlock$2(newPrevSiblingKey, blocks, function (block) {
  7131. return block.merge({
  7132. nextSibling: originalBlockKey
  7133. });
  7134. });
  7135. // update new parent
  7136. transformBlock$2(newParentKey, blocks, function (block) {
  7137. var newParentChildrenList = block.getChildKeys();
  7138. var targetBlockIndex = newParentChildrenList.indexOf(originalTargetKey);
  7139. var insertionIndex = isInsertedAfterTarget ? targetBlockIndex + 1 : targetBlockIndex !== 0 ? targetBlockIndex - 1 : 0;
  7140. var newChildrenArray = newParentChildrenList.toArray();
  7141. newChildrenArray.splice(insertionIndex, 0, originalBlockKey);
  7142. return block.merge({
  7143. children: List$7(newChildrenArray)
  7144. });
  7145. });
  7146. // update block
  7147. transformBlock$2(originalBlockKey, blocks, function (block) {
  7148. return block.merge({
  7149. nextSibling: newNextSiblingKey,
  7150. prevSibling: newPrevSiblingKey,
  7151. parent: newParentKey
  7152. });
  7153. });
  7154. });
  7155. };
  7156. var moveBlockInContentState = function moveBlockInContentState(contentState, blockToBeMoved, targetBlock, insertionMode) {
  7157. !(insertionMode !== 'replace') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Replacing blocks is not supported.') : invariant_1(false) : void 0;
  7158. var targetKey = targetBlock.getKey();
  7159. var blockKey = blockToBeMoved.getKey();
  7160. !(blockKey !== targetKey) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Block cannot be moved next to itself.') : invariant_1(false) : void 0;
  7161. var blockMap = contentState.getBlockMap();
  7162. var isExperimentalTreeBlock = blockToBeMoved instanceof ContentBlockNode_1;
  7163. var blocksToBeMoved = [blockToBeMoved];
  7164. var blockMapWithoutBlocksToBeMoved = blockMap['delete'](blockKey);
  7165. if (isExperimentalTreeBlock) {
  7166. blocksToBeMoved = [];
  7167. blockMapWithoutBlocksToBeMoved = blockMap.withMutations(function (blocks) {
  7168. var nextSiblingKey = blockToBeMoved.getNextSiblingKey();
  7169. var nextDelimiterBlockKey = getNextDelimiterBlockKey_1(blockToBeMoved, blocks);
  7170. blocks.toSeq().skipUntil(function (block) {
  7171. return block.getKey() === blockKey;
  7172. }).takeWhile(function (block) {
  7173. var key = block.getKey();
  7174. var isBlockToBeMoved = key === blockKey;
  7175. var hasNextSiblingAndIsNotNextSibling = nextSiblingKey && key !== nextSiblingKey;
  7176. var doesNotHaveNextSiblingAndIsNotDelimiter = !nextSiblingKey && block.getParentKey() && (!nextDelimiterBlockKey || key !== nextDelimiterBlockKey);
  7177. return !!(isBlockToBeMoved || hasNextSiblingAndIsNotNextSibling || doesNotHaveNextSiblingAndIsNotDelimiter);
  7178. }).forEach(function (block) {
  7179. blocksToBeMoved.push(block);
  7180. blocks['delete'](block.getKey());
  7181. });
  7182. });
  7183. }
  7184. var blocksBefore = blockMapWithoutBlocksToBeMoved.toSeq().takeUntil(function (v) {
  7185. return v === targetBlock;
  7186. });
  7187. var blocksAfter = blockMapWithoutBlocksToBeMoved.toSeq().skipUntil(function (v) {
  7188. return v === targetBlock;
  7189. }).skip(1);
  7190. var slicedBlocks = blocksToBeMoved.map(function (block) {
  7191. return [block.getKey(), block];
  7192. });
  7193. var newBlocks = OrderedMap$3();
  7194. if (insertionMode === 'before') {
  7195. var blockBefore = contentState.getBlockBefore(targetKey);
  7196. !(!blockBefore || blockBefore.getKey() !== blockToBeMoved.getKey()) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Block cannot be moved next to itself.') : invariant_1(false) : void 0;
  7197. newBlocks = blocksBefore.concat([].concat(slicedBlocks, [[targetKey, targetBlock]]), blocksAfter).toOrderedMap();
  7198. } else if (insertionMode === 'after') {
  7199. var blockAfter = contentState.getBlockAfter(targetKey);
  7200. !(!blockAfter || blockAfter.getKey() !== blockKey) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Block cannot be moved next to itself.') : invariant_1(false) : void 0;
  7201. newBlocks = blocksBefore.concat([[targetKey, targetBlock]].concat(slicedBlocks), blocksAfter).toOrderedMap();
  7202. }
  7203. return contentState.merge({
  7204. blockMap: updateBlockMapLinks$3(newBlocks, blockToBeMoved, targetBlock, insertionMode, isExperimentalTreeBlock),
  7205. selectionBefore: contentState.getSelectionAfter(),
  7206. selectionAfter: contentState.getSelectionAfter().merge({
  7207. anchorKey: blockKey,
  7208. focusKey: blockKey
  7209. })
  7210. });
  7211. };
  7212. var moveBlockInContentState_1 = moveBlockInContentState;
  7213. var ContentBlockRecord$1 = ContentBlock_1;
  7214. var List$8 = immutable.List,
  7215. Repeat$5 = immutable.Repeat;
  7216. var AtomicBlockUtils = {
  7217. insertAtomicBlock: function insertAtomicBlock(editorState, entityKey, character) {
  7218. var contentState = editorState.getCurrentContent();
  7219. var selectionState = editorState.getSelection();
  7220. var afterRemoval = DraftModifier_1.removeRange(contentState, selectionState, 'backward');
  7221. var targetSelection = afterRemoval.getSelectionAfter();
  7222. var afterSplit = DraftModifier_1.splitBlock(afterRemoval, targetSelection);
  7223. var insertionTarget = afterSplit.getSelectionAfter();
  7224. var asAtomicBlock = DraftModifier_1.setBlockType(afterSplit, insertionTarget, 'atomic');
  7225. var charData = CharacterMetadata_1.create({ entity: entityKey });
  7226. var atomicBlockConfig = {
  7227. key: generateRandomKey_1(),
  7228. type: 'atomic',
  7229. text: character,
  7230. characterList: List$8(Repeat$5(charData, character.length))
  7231. };
  7232. var atomicDividerBlockConfig = {
  7233. key: generateRandomKey_1(),
  7234. type: 'unstyled'
  7235. };
  7236. var fragmentArray = [new ContentBlockRecord$1(atomicBlockConfig), new ContentBlockRecord$1(atomicDividerBlockConfig)];
  7237. var fragment = BlockMapBuilder_1.createFromArray(fragmentArray);
  7238. var withAtomicBlock = DraftModifier_1.replaceWithFragment(asAtomicBlock, insertionTarget, fragment);
  7239. var newContent = withAtomicBlock.merge({
  7240. selectionBefore: selectionState,
  7241. selectionAfter: withAtomicBlock.getSelectionAfter().set('hasFocus', true)
  7242. });
  7243. return EditorState_1.push(editorState, newContent, 'insert-fragment');
  7244. },
  7245. moveAtomicBlock: function moveAtomicBlock(editorState, atomicBlock, targetRange, insertionMode) {
  7246. var contentState = editorState.getCurrentContent();
  7247. var selectionState = editorState.getSelection();
  7248. var withMovedAtomicBlock = void 0;
  7249. if (insertionMode === 'before' || insertionMode === 'after') {
  7250. var targetBlock = contentState.getBlockForKey(insertionMode === 'before' ? targetRange.getStartKey() : targetRange.getEndKey());
  7251. withMovedAtomicBlock = moveBlockInContentState_1(contentState, atomicBlock, targetBlock, insertionMode);
  7252. } else {
  7253. var afterRemoval = DraftModifier_1.removeRange(contentState, targetRange, 'backward');
  7254. var selectionAfterRemoval = afterRemoval.getSelectionAfter();
  7255. var _targetBlock = afterRemoval.getBlockForKey(selectionAfterRemoval.getFocusKey());
  7256. if (selectionAfterRemoval.getStartOffset() === 0) {
  7257. withMovedAtomicBlock = moveBlockInContentState_1(afterRemoval, atomicBlock, _targetBlock, 'before');
  7258. } else if (selectionAfterRemoval.getEndOffset() === _targetBlock.getLength()) {
  7259. withMovedAtomicBlock = moveBlockInContentState_1(afterRemoval, atomicBlock, _targetBlock, 'after');
  7260. } else {
  7261. var afterSplit = DraftModifier_1.splitBlock(afterRemoval, selectionAfterRemoval);
  7262. var selectionAfterSplit = afterSplit.getSelectionAfter();
  7263. var _targetBlock2 = afterSplit.getBlockForKey(selectionAfterSplit.getFocusKey());
  7264. withMovedAtomicBlock = moveBlockInContentState_1(afterSplit, atomicBlock, _targetBlock2, 'before');
  7265. }
  7266. }
  7267. var newContent = withMovedAtomicBlock.merge({
  7268. selectionBefore: selectionState,
  7269. selectionAfter: withMovedAtomicBlock.getSelectionAfter().set('hasFocus', true)
  7270. });
  7271. return EditorState_1.push(editorState, newContent, 'move-block');
  7272. }
  7273. };
  7274. var AtomicBlockUtils_1 = AtomicBlockUtils;
  7275. function _classCallCheck$8(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7276. var List$9 = immutable.List;
  7277. var DELIMITER = '.';
  7278. /**
  7279. * A CompositeDraftDecorator traverses through a list of DraftDecorator
  7280. * instances to identify sections of a ContentBlock that should be rendered
  7281. * in a "decorated" manner. For example, hashtags, mentions, and links may
  7282. * be intended to stand out visually, be rendered as anchors, etc.
  7283. *
  7284. * The list of decorators supplied to the constructor will be used in the
  7285. * order they are provided. This allows the caller to specify a priority for
  7286. * string matching, in case of match collisions among decorators.
  7287. *
  7288. * For instance, I may have a link with a `#` in its text. Though this section
  7289. * of text may match our hashtag decorator, it should not be treated as a
  7290. * hashtag. I should therefore list my link DraftDecorator
  7291. * before my hashtag DraftDecorator when constructing this composite
  7292. * decorator instance.
  7293. *
  7294. * Thus, when a collision like this is encountered, the earlier match is
  7295. * preserved and the new match is discarded.
  7296. */
  7297. var CompositeDraftDecorator = function () {
  7298. function CompositeDraftDecorator(decorators) {
  7299. _classCallCheck$8(this, CompositeDraftDecorator);
  7300. // Copy the decorator array, since we use this array order to determine
  7301. // precedence of decoration matching. If the array is mutated externally,
  7302. // we don't want to be affected here.
  7303. this._decorators = decorators.slice();
  7304. }
  7305. CompositeDraftDecorator.prototype.getDecorations = function getDecorations(block, contentState) {
  7306. var decorations = Array(block.getText().length).fill(null);
  7307. this._decorators.forEach(function ( /*object*/decorator, /*number*/ii) {
  7308. var counter = 0;
  7309. var strategy = decorator.strategy;
  7310. var callback = function callback( /*number*/start, /*number*/end) {
  7311. // Find out if any of our matching range is already occupied
  7312. // by another decorator. If so, discard the match. Otherwise, store
  7313. // the component key for rendering.
  7314. if (canOccupySlice(decorations, start, end)) {
  7315. occupySlice(decorations, start, end, ii + DELIMITER + counter);
  7316. counter++;
  7317. }
  7318. };
  7319. strategy(block, callback, contentState);
  7320. });
  7321. return List$9(decorations);
  7322. };
  7323. CompositeDraftDecorator.prototype.getComponentForKey = function getComponentForKey(key) {
  7324. var componentKey = parseInt(key.split(DELIMITER)[0], 10);
  7325. return this._decorators[componentKey].component;
  7326. };
  7327. CompositeDraftDecorator.prototype.getPropsForKey = function getPropsForKey(key) {
  7328. var componentKey = parseInt(key.split(DELIMITER)[0], 10);
  7329. return this._decorators[componentKey].props;
  7330. };
  7331. return CompositeDraftDecorator;
  7332. }();
  7333. /**
  7334. * Determine whether we can occupy the specified slice of the decorations
  7335. * array.
  7336. */
  7337. function canOccupySlice(decorations, start, end) {
  7338. for (var ii = start; ii < end; ii++) {
  7339. if (decorations[ii] != null) {
  7340. return false;
  7341. }
  7342. }
  7343. return true;
  7344. }
  7345. /**
  7346. * Splice the specified component into our decoration array at the desired
  7347. * range.
  7348. */
  7349. function occupySlice(targetArr, start, end, componentKey) {
  7350. for (var ii = start; ii < end; ii++) {
  7351. targetArr[ii] = componentKey;
  7352. }
  7353. }
  7354. var CompositeDraftDecorator_1 = CompositeDraftDecorator;
  7355. /**
  7356. * Copyright (c) 2013-present, Facebook, Inc.
  7357. *
  7358. * This source code is licensed under the MIT license found in the
  7359. * LICENSE file in the root directory of this source tree.
  7360. *
  7361. */
  7362. /**
  7363. * This function is used to mark string literals representing CSS class names
  7364. * so that they can be transformed statically. This allows for modularization
  7365. * and minification of CSS class names.
  7366. *
  7367. * In static_upstream, this function is actually implemented, but it should
  7368. * eventually be replaced with something more descriptive, and the transform
  7369. * that is used in the main stack should be ported for use elsewhere.
  7370. *
  7371. * @param string|object className to modularize, or an object of key/values.
  7372. * In the object case, the values are conditions that
  7373. * determine if the className keys should be included.
  7374. * @param [string ...] Variable list of classNames in the string case.
  7375. * @return string Renderable space-separated CSS className.
  7376. */
  7377. function cx(classNames) {
  7378. if (typeof classNames == 'object') {
  7379. return Object.keys(classNames).filter(function (className) {
  7380. return classNames[className];
  7381. }).map(replace).join(' ');
  7382. }
  7383. return Array.prototype.map.call(arguments, replace).join(' ');
  7384. }
  7385. function replace(str) {
  7386. return str.replace(/\//g, '-');
  7387. }
  7388. var cx_1 = cx;
  7389. var Map$8 = immutable.Map;
  7390. var UL_WRAP = React.createElement('ul', { className: cx_1('public/DraftStyleDefault/ul') });
  7391. var OL_WRAP = React.createElement('ol', { className: cx_1('public/DraftStyleDefault/ol') });
  7392. var PRE_WRAP = React.createElement('pre', { className: cx_1('public/DraftStyleDefault/pre') });
  7393. var DefaultDraftBlockRenderMap = Map$8({
  7394. 'header-one': {
  7395. element: 'h1'
  7396. },
  7397. 'header-two': {
  7398. element: 'h2'
  7399. },
  7400. 'header-three': {
  7401. element: 'h3'
  7402. },
  7403. 'header-four': {
  7404. element: 'h4'
  7405. },
  7406. 'header-five': {
  7407. element: 'h5'
  7408. },
  7409. 'header-six': {
  7410. element: 'h6'
  7411. },
  7412. 'unordered-list-item': {
  7413. element: 'li',
  7414. wrapper: UL_WRAP
  7415. },
  7416. 'ordered-list-item': {
  7417. element: 'li',
  7418. wrapper: OL_WRAP
  7419. },
  7420. blockquote: {
  7421. element: 'blockquote'
  7422. },
  7423. atomic: {
  7424. element: 'figure'
  7425. },
  7426. 'code-block': {
  7427. element: 'pre',
  7428. wrapper: PRE_WRAP
  7429. },
  7430. unstyled: {
  7431. element: 'div',
  7432. aliasedElements: ['p']
  7433. }
  7434. });
  7435. var DefaultDraftBlockRenderMap_1 = DefaultDraftBlockRenderMap;
  7436. /**
  7437. * Copyright (c) 2013-present, Facebook, Inc.
  7438. * All rights reserved.
  7439. *
  7440. * This source code is licensed under the BSD-style license found in the
  7441. * LICENSE file in the root directory of this source tree. An additional grant
  7442. * of patent rights can be found in the PATENTS file in the same directory.
  7443. *
  7444. * @providesModule DefaultDraftInlineStyle
  7445. * @format
  7446. *
  7447. */
  7448. var DefaultDraftInlineStyle = {
  7449. BOLD: {
  7450. fontWeight: 'bold'
  7451. },
  7452. CODE: {
  7453. fontFamily: 'monospace',
  7454. wordWrap: 'break-word'
  7455. },
  7456. ITALIC: {
  7457. fontStyle: 'italic'
  7458. },
  7459. STRIKETHROUGH: {
  7460. textDecoration: 'line-through'
  7461. },
  7462. UNDERLINE: {
  7463. textDecoration: 'underline'
  7464. }
  7465. };
  7466. /**
  7467. * Copyright (c) 2013-present, Facebook, Inc.
  7468. *
  7469. * This source code is licensed under the MIT license found in the
  7470. * LICENSE file in the root directory of this source tree.
  7471. *
  7472. */
  7473. var Keys = {
  7474. BACKSPACE: 8,
  7475. TAB: 9,
  7476. RETURN: 13,
  7477. ALT: 18,
  7478. ESC: 27,
  7479. SPACE: 32,
  7480. PAGE_UP: 33,
  7481. PAGE_DOWN: 34,
  7482. END: 35,
  7483. HOME: 36,
  7484. LEFT: 37,
  7485. UP: 38,
  7486. RIGHT: 39,
  7487. DOWN: 40,
  7488. DELETE: 46,
  7489. COMMA: 188,
  7490. PERIOD: 190,
  7491. A: 65,
  7492. Z: 90,
  7493. ZERO: 48,
  7494. NUMPAD_0: 96,
  7495. NUMPAD_9: 105
  7496. };
  7497. /**
  7498. * Copyright (c) 2013-present, Facebook, Inc.
  7499. * All rights reserved.
  7500. *
  7501. * This source code is licensed under the BSD-style license found in the
  7502. * LICENSE file in the root directory of this source tree. An additional grant
  7503. * of patent rights can be found in the PATENTS file in the same directory.
  7504. *
  7505. * @providesModule getEntityKeyForSelection
  7506. * @format
  7507. *
  7508. */
  7509. /**
  7510. * Return the entity key that should be used when inserting text for the
  7511. * specified target selection, only if the entity is `MUTABLE`. `IMMUTABLE`
  7512. * and `SEGMENTED` entities should not be used for insertion behavior.
  7513. */
  7514. function getEntityKeyForSelection(contentState, targetSelection) {
  7515. var entityKey;
  7516. if (targetSelection.isCollapsed()) {
  7517. var key = targetSelection.getAnchorKey();
  7518. var offset = targetSelection.getAnchorOffset();
  7519. if (offset > 0) {
  7520. entityKey = contentState.getBlockForKey(key).getEntityAt(offset - 1);
  7521. if (entityKey !== contentState.getBlockForKey(key).getEntityAt(offset)) {
  7522. return null;
  7523. }
  7524. return filterKey(contentState.getEntityMap(), entityKey);
  7525. }
  7526. return null;
  7527. }
  7528. var startKey = targetSelection.getStartKey();
  7529. var startOffset = targetSelection.getStartOffset();
  7530. var startBlock = contentState.getBlockForKey(startKey);
  7531. entityKey = startOffset === startBlock.getLength() ? null : startBlock.getEntityAt(startOffset);
  7532. return filterKey(contentState.getEntityMap(), entityKey);
  7533. }
  7534. /**
  7535. * Determine whether an entity key corresponds to a `MUTABLE` entity. If so,
  7536. * return it. If not, return null.
  7537. */
  7538. function filterKey(entityMap, entityKey) {
  7539. if (entityKey) {
  7540. var entity = entityMap.__get(entityKey);
  7541. return entity.getMutability() === 'MUTABLE' ? entityKey : null;
  7542. }
  7543. return null;
  7544. }
  7545. var getEntityKeyForSelection_1 = getEntityKeyForSelection;
  7546. /**
  7547. * Copyright (c) 2013-present, Facebook, Inc.
  7548. * All rights reserved.
  7549. *
  7550. * This source code is licensed under the BSD-style license found in the
  7551. * LICENSE file in the root directory of this source tree. An additional grant
  7552. * of patent rights can be found in the PATENTS file in the same directory.
  7553. *
  7554. * @providesModule isEventHandled
  7555. * @format
  7556. *
  7557. */
  7558. /**
  7559. * Utility method for determining whether or not the value returned
  7560. * from a handler indicates that it was handled.
  7561. */
  7562. function isEventHandled(value) {
  7563. return value === 'handled' || value === true;
  7564. }
  7565. var isEventHandled_1 = isEventHandled;
  7566. /**
  7567. * Copyright (c) 2013-present, Facebook, Inc.
  7568. * All rights reserved.
  7569. *
  7570. * This source code is licensed under the BSD-style license found in the
  7571. * LICENSE file in the root directory of this source tree. An additional grant
  7572. * of patent rights can be found in the PATENTS file in the same directory.
  7573. *
  7574. * @providesModule isSelectionAtLeafStart
  7575. * @format
  7576. *
  7577. */
  7578. function isSelectionAtLeafStart(editorState) {
  7579. var selection = editorState.getSelection();
  7580. var anchorKey = selection.getAnchorKey();
  7581. var blockTree = editorState.getBlockTree(anchorKey);
  7582. var offset = selection.getStartOffset();
  7583. var isAtStart = false;
  7584. blockTree.some(function (leafSet) {
  7585. if (offset === leafSet.get('start')) {
  7586. isAtStart = true;
  7587. return true;
  7588. }
  7589. if (offset < leafSet.get('end')) {
  7590. return leafSet.get('leaves').some(function (leaf) {
  7591. var leafStart = leaf.get('start');
  7592. if (offset === leafStart) {
  7593. isAtStart = true;
  7594. return true;
  7595. }
  7596. return false;
  7597. });
  7598. }
  7599. return false;
  7600. });
  7601. return isAtStart;
  7602. }
  7603. var isSelectionAtLeafStart_1 = isSelectionAtLeafStart;
  7604. /**
  7605. * Millisecond delay to allow `compositionstart` to fire again upon
  7606. * `compositionend`.
  7607. *
  7608. * This is used for Korean input to ensure that typing can continue without
  7609. * the editor trying to render too quickly. More specifically, Safari 7.1+
  7610. * triggers `compositionstart` a little slower than Chrome/FF, which
  7611. * leads to composed characters being resolved and re-render occurring
  7612. * sooner than we want.
  7613. */
  7614. var RESOLVE_DELAY = 20;
  7615. /**
  7616. * A handful of variables used to track the current composition and its
  7617. * resolution status. These exist at the module level because it is not
  7618. * possible to have compositions occurring in multiple editors simultaneously,
  7619. * and it simplifies state management with respect to the DraftEditor component.
  7620. */
  7621. var resolved = false;
  7622. var stillComposing = false;
  7623. var textInputData = '';
  7624. var DraftEditorCompositionHandler = {
  7625. onBeforeInput: function onBeforeInput(editor, e) {
  7626. textInputData = (textInputData || '') + e.data;
  7627. },
  7628. /**
  7629. * A `compositionstart` event has fired while we're still in composition
  7630. * mode. Continue the current composition session to prevent a re-render.
  7631. */
  7632. onCompositionStart: function onCompositionStart(editor) {
  7633. stillComposing = true;
  7634. },
  7635. /**
  7636. * Attempt to end the current composition session.
  7637. *
  7638. * Defer handling because browser will still insert the chars into active
  7639. * element after `compositionend`. If a `compositionstart` event fires
  7640. * before `resolveComposition` executes, our composition session will
  7641. * continue.
  7642. *
  7643. * The `resolved` flag is useful because certain IME interfaces fire the
  7644. * `compositionend` event multiple times, thus queueing up multiple attempts
  7645. * at handling the composition. Since handling the same composition event
  7646. * twice could break the DOM, we only use the first event. Example: Arabic
  7647. * Google Input Tools on Windows 8.1 fires `compositionend` three times.
  7648. */
  7649. onCompositionEnd: function onCompositionEnd(editor) {
  7650. resolved = false;
  7651. stillComposing = false;
  7652. setTimeout(function () {
  7653. if (!resolved) {
  7654. DraftEditorCompositionHandler.resolveComposition(editor);
  7655. }
  7656. }, RESOLVE_DELAY);
  7657. },
  7658. /**
  7659. * In Safari, keydown events may fire when committing compositions. If
  7660. * the arrow keys are used to commit, prevent default so that the cursor
  7661. * doesn't move, otherwise it will jump back noticeably on re-render.
  7662. */
  7663. onKeyDown: function onKeyDown(editor, e) {
  7664. if (!stillComposing) {
  7665. // If a keydown event is received after compositionend but before the
  7666. // 20ms timer expires (ex: type option-E then backspace, or type A then
  7667. // backspace in 2-Set Korean), we should immediately resolve the
  7668. // composition and reinterpret the key press in edit mode.
  7669. DraftEditorCompositionHandler.resolveComposition(editor);
  7670. editor._onKeyDown(e);
  7671. return;
  7672. }
  7673. if (e.which === Keys.RIGHT || e.which === Keys.LEFT) {
  7674. e.preventDefault();
  7675. }
  7676. },
  7677. /**
  7678. * Keypress events may fire when committing compositions. In Firefox,
  7679. * pressing RETURN commits the composition and inserts extra newline
  7680. * characters that we do not want. `preventDefault` allows the composition
  7681. * to be committed while preventing the extra characters.
  7682. */
  7683. onKeyPress: function onKeyPress(editor, e) {
  7684. if (e.which === Keys.RETURN) {
  7685. e.preventDefault();
  7686. }
  7687. },
  7688. /**
  7689. * Attempt to insert composed characters into the document.
  7690. *
  7691. * If we are still in a composition session, do nothing. Otherwise, insert
  7692. * the characters into the document and terminate the composition session.
  7693. *
  7694. * If no characters were composed -- for instance, the user
  7695. * deleted all composed characters and committed nothing new --
  7696. * force a re-render. We also re-render when the composition occurs
  7697. * at the beginning of a leaf, to ensure that if the browser has
  7698. * created a new text node for the composition, we will discard it.
  7699. *
  7700. * Resetting innerHTML will move focus to the beginning of the editor,
  7701. * so we update to force it back to the correct place.
  7702. */
  7703. resolveComposition: function resolveComposition(editor) {
  7704. if (stillComposing) {
  7705. return;
  7706. }
  7707. resolved = true;
  7708. var composedChars = textInputData;
  7709. textInputData = '';
  7710. var editorState = EditorState_1.set(editor._latestEditorState, {
  7711. inCompositionMode: false
  7712. });
  7713. var currentStyle = editorState.getCurrentInlineStyle();
  7714. var entityKey = getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection());
  7715. var mustReset = !composedChars || isSelectionAtLeafStart_1(editorState) || currentStyle.size > 0 || entityKey !== null;
  7716. if (mustReset) {
  7717. editor.restoreEditorDOM();
  7718. }
  7719. editor.exitCurrentMode();
  7720. if (composedChars) {
  7721. // If characters have been composed, re-rendering with the update
  7722. // is sufficient to reset the editor.
  7723. var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), composedChars, currentStyle, entityKey);
  7724. editor.update(EditorState_1.push(editorState, contentState, 'insert-characters'));
  7725. return;
  7726. }
  7727. if (mustReset) {
  7728. editor.update(EditorState_1.set(editorState, {
  7729. nativelyRenderedContent: null,
  7730. forceSelection: true
  7731. }));
  7732. }
  7733. }
  7734. };
  7735. var DraftEditorCompositionHandler_1 = DraftEditorCompositionHandler;
  7736. var uaParser = createCommonjsModule(function (module, exports) {
  7737. /*!
  7738. * UAParser.js v0.7.21
  7739. * Lightweight JavaScript-based User-Agent string parser
  7740. * https://github.com/faisalman/ua-parser-js
  7741. *
  7742. * Copyright © 2012-2019 Faisal Salman <f@faisalman.com>
  7743. * Licensed under MIT License
  7744. */
  7745. (function (window, undefined$1) {
  7746. //////////////
  7747. // Constants
  7748. /////////////
  7749. var LIBVERSION = '0.7.21',
  7750. EMPTY = '',
  7751. UNKNOWN = '?',
  7752. FUNC_TYPE = 'function',
  7753. OBJ_TYPE = 'object',
  7754. STR_TYPE = 'string',
  7755. MAJOR = 'major', // deprecated
  7756. MODEL = 'model',
  7757. NAME = 'name',
  7758. TYPE = 'type',
  7759. VENDOR = 'vendor',
  7760. VERSION = 'version',
  7761. ARCHITECTURE= 'architecture',
  7762. CONSOLE = 'console',
  7763. MOBILE = 'mobile',
  7764. TABLET = 'tablet',
  7765. SMARTTV = 'smarttv',
  7766. WEARABLE = 'wearable',
  7767. EMBEDDED = 'embedded';
  7768. ///////////
  7769. // Helper
  7770. //////////
  7771. var util = {
  7772. extend : function (regexes, extensions) {
  7773. var mergedRegexes = {};
  7774. for (var i in regexes) {
  7775. if (extensions[i] && extensions[i].length % 2 === 0) {
  7776. mergedRegexes[i] = extensions[i].concat(regexes[i]);
  7777. } else {
  7778. mergedRegexes[i] = regexes[i];
  7779. }
  7780. }
  7781. return mergedRegexes;
  7782. },
  7783. has : function (str1, str2) {
  7784. if (typeof str1 === "string") {
  7785. return str2.toLowerCase().indexOf(str1.toLowerCase()) !== -1;
  7786. } else {
  7787. return false;
  7788. }
  7789. },
  7790. lowerize : function (str) {
  7791. return str.toLowerCase();
  7792. },
  7793. major : function (version) {
  7794. return typeof(version) === STR_TYPE ? version.replace(/[^\d\.]/g,'').split(".")[0] : undefined$1;
  7795. },
  7796. trim : function (str) {
  7797. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  7798. }
  7799. };
  7800. ///////////////
  7801. // Map helper
  7802. //////////////
  7803. var mapper = {
  7804. rgx : function (ua, arrays) {
  7805. var i = 0, j, k, p, q, matches, match;
  7806. // loop through all regexes maps
  7807. while (i < arrays.length && !matches) {
  7808. var regex = arrays[i], // even sequence (0,2,4,..)
  7809. props = arrays[i + 1]; // odd sequence (1,3,5,..)
  7810. j = k = 0;
  7811. // try matching uastring with regexes
  7812. while (j < regex.length && !matches) {
  7813. matches = regex[j++].exec(ua);
  7814. if (!!matches) {
  7815. for (p = 0; p < props.length; p++) {
  7816. match = matches[++k];
  7817. q = props[p];
  7818. // check if given property is actually array
  7819. if (typeof q === OBJ_TYPE && q.length > 0) {
  7820. if (q.length == 2) {
  7821. if (typeof q[1] == FUNC_TYPE) {
  7822. // assign modified match
  7823. this[q[0]] = q[1].call(this, match);
  7824. } else {
  7825. // assign given value, ignore regex match
  7826. this[q[0]] = q[1];
  7827. }
  7828. } else if (q.length == 3) {
  7829. // check whether function or regex
  7830. if (typeof q[1] === FUNC_TYPE && !(q[1].exec && q[1].test)) {
  7831. // call function (usually string mapper)
  7832. this[q[0]] = match ? q[1].call(this, match, q[2]) : undefined$1;
  7833. } else {
  7834. // sanitize match using given regex
  7835. this[q[0]] = match ? match.replace(q[1], q[2]) : undefined$1;
  7836. }
  7837. } else if (q.length == 4) {
  7838. this[q[0]] = match ? q[3].call(this, match.replace(q[1], q[2])) : undefined$1;
  7839. }
  7840. } else {
  7841. this[q] = match ? match : undefined$1;
  7842. }
  7843. }
  7844. }
  7845. }
  7846. i += 2;
  7847. }
  7848. },
  7849. str : function (str, map) {
  7850. for (var i in map) {
  7851. // check if array
  7852. if (typeof map[i] === OBJ_TYPE && map[i].length > 0) {
  7853. for (var j = 0; j < map[i].length; j++) {
  7854. if (util.has(map[i][j], str)) {
  7855. return (i === UNKNOWN) ? undefined$1 : i;
  7856. }
  7857. }
  7858. } else if (util.has(map[i], str)) {
  7859. return (i === UNKNOWN) ? undefined$1 : i;
  7860. }
  7861. }
  7862. return str;
  7863. }
  7864. };
  7865. ///////////////
  7866. // String map
  7867. //////////////
  7868. var maps = {
  7869. browser : {
  7870. oldsafari : {
  7871. version : {
  7872. '1.0' : '/8',
  7873. '1.2' : '/1',
  7874. '1.3' : '/3',
  7875. '2.0' : '/412',
  7876. '2.0.2' : '/416',
  7877. '2.0.3' : '/417',
  7878. '2.0.4' : '/419',
  7879. '?' : '/'
  7880. }
  7881. }
  7882. },
  7883. device : {
  7884. amazon : {
  7885. model : {
  7886. 'Fire Phone' : ['SD', 'KF']
  7887. }
  7888. },
  7889. sprint : {
  7890. model : {
  7891. 'Evo Shift 4G' : '7373KT'
  7892. },
  7893. vendor : {
  7894. 'HTC' : 'APA',
  7895. 'Sprint' : 'Sprint'
  7896. }
  7897. }
  7898. },
  7899. os : {
  7900. windows : {
  7901. version : {
  7902. 'ME' : '4.90',
  7903. 'NT 3.11' : 'NT3.51',
  7904. 'NT 4.0' : 'NT4.0',
  7905. '2000' : 'NT 5.0',
  7906. 'XP' : ['NT 5.1', 'NT 5.2'],
  7907. 'Vista' : 'NT 6.0',
  7908. '7' : 'NT 6.1',
  7909. '8' : 'NT 6.2',
  7910. '8.1' : 'NT 6.3',
  7911. '10' : ['NT 6.4', 'NT 10.0'],
  7912. 'RT' : 'ARM'
  7913. }
  7914. }
  7915. }
  7916. };
  7917. //////////////
  7918. // Regex map
  7919. /////////////
  7920. var regexes = {
  7921. browser : [[
  7922. // Presto based
  7923. /(opera\smini)\/([\w\.-]+)/i, // Opera Mini
  7924. /(opera\s[mobiletab]+).+version\/([\w\.-]+)/i, // Opera Mobi/Tablet
  7925. /(opera).+version\/([\w\.]+)/i, // Opera > 9.80
  7926. /(opera)[\/\s]+([\w\.]+)/i // Opera < 9.80
  7927. ], [NAME, VERSION], [
  7928. /(opios)[\/\s]+([\w\.]+)/i // Opera mini on iphone >= 8.0
  7929. ], [[NAME, 'Opera Mini'], VERSION], [
  7930. /\s(opr)\/([\w\.]+)/i // Opera Webkit
  7931. ], [[NAME, 'Opera'], VERSION], [
  7932. // Mixed
  7933. /(kindle)\/([\w\.]+)/i, // Kindle
  7934. /(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?([\w\.]*)/i,
  7935. // Lunascape/Maxthon/Netfront/Jasmine/Blazer
  7936. // Trident based
  7937. /(avant\s|iemobile|slim)(?:browser)?[\/\s]?([\w\.]*)/i,
  7938. // Avant/IEMobile/SlimBrowser
  7939. /(bidubrowser|baidubrowser)[\/\s]?([\w\.]+)/i, // Baidu Browser
  7940. /(?:ms|\()(ie)\s([\w\.]+)/i, // Internet Explorer
  7941. // Webkit/KHTML based
  7942. /(rekonq)\/([\w\.]*)/i, // Rekonq
  7943. /(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt|iron|vivaldi|iridium|phantomjs|bowser|quark|qupzilla|falkon)\/([\w\.-]+)/i
  7944. // Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt/Iron/Iridium/PhantomJS/Bowser/QupZilla/Falkon
  7945. ], [NAME, VERSION], [
  7946. /(konqueror)\/([\w\.]+)/i // Konqueror
  7947. ], [[NAME, 'Konqueror'], VERSION], [
  7948. /(trident).+rv[:\s]([\w\.]+).+like\sgecko/i // IE11
  7949. ], [[NAME, 'IE'], VERSION], [
  7950. /(edge|edgios|edga|edg)\/((\d+)?[\w\.]+)/i // Microsoft Edge
  7951. ], [[NAME, 'Edge'], VERSION], [
  7952. /(yabrowser)\/([\w\.]+)/i // Yandex
  7953. ], [[NAME, 'Yandex'], VERSION], [
  7954. /(Avast)\/([\w\.]+)/i // Avast Secure Browser
  7955. ], [[NAME, 'Avast Secure Browser'], VERSION], [
  7956. /(AVG)\/([\w\.]+)/i // AVG Secure Browser
  7957. ], [[NAME, 'AVG Secure Browser'], VERSION], [
  7958. /(puffin)\/([\w\.]+)/i // Puffin
  7959. ], [[NAME, 'Puffin'], VERSION], [
  7960. /(focus)\/([\w\.]+)/i // Firefox Focus
  7961. ], [[NAME, 'Firefox Focus'], VERSION], [
  7962. /(opt)\/([\w\.]+)/i // Opera Touch
  7963. ], [[NAME, 'Opera Touch'], VERSION], [
  7964. /((?:[\s\/])uc?\s?browser|(?:juc.+)ucweb)[\/\s]?([\w\.]+)/i // UCBrowser
  7965. ], [[NAME, 'UCBrowser'], VERSION], [
  7966. /(comodo_dragon)\/([\w\.]+)/i // Comodo Dragon
  7967. ], [[NAME, /_/g, ' '], VERSION], [
  7968. /(windowswechat qbcore)\/([\w\.]+)/i // WeChat Desktop for Windows Built-in Browser
  7969. ], [[NAME, 'WeChat(Win) Desktop'], VERSION], [
  7970. /(micromessenger)\/([\w\.]+)/i // WeChat
  7971. ], [[NAME, 'WeChat'], VERSION], [
  7972. /(brave)\/([\w\.]+)/i // Brave browser
  7973. ], [[NAME, 'Brave'], VERSION], [
  7974. /(qqbrowserlite)\/([\w\.]+)/i // QQBrowserLite
  7975. ], [NAME, VERSION], [
  7976. /(QQ)\/([\d\.]+)/i // QQ, aka ShouQ
  7977. ], [NAME, VERSION], [
  7978. /m?(qqbrowser)[\/\s]?([\w\.]+)/i // QQBrowser
  7979. ], [NAME, VERSION], [
  7980. /(baiduboxapp)[\/\s]?([\w\.]+)/i // Baidu App
  7981. ], [NAME, VERSION], [
  7982. /(2345Explorer)[\/\s]?([\w\.]+)/i // 2345 Browser
  7983. ], [NAME, VERSION], [
  7984. /(MetaSr)[\/\s]?([\w\.]+)/i // SouGouBrowser
  7985. ], [NAME], [
  7986. /(LBBROWSER)/i // LieBao Browser
  7987. ], [NAME], [
  7988. /xiaomi\/miuibrowser\/([\w\.]+)/i // MIUI Browser
  7989. ], [VERSION, [NAME, 'MIUI Browser']], [
  7990. /;fbav\/([\w\.]+);/i // Facebook App for iOS & Android
  7991. ], [VERSION, [NAME, 'Facebook']], [
  7992. /safari\s(line)\/([\w\.]+)/i, // Line App for iOS
  7993. /android.+(line)\/([\w\.]+)\/iab/i // Line App for Android
  7994. ], [NAME, VERSION], [
  7995. /headlesschrome(?:\/([\w\.]+)|\s)/i // Chrome Headless
  7996. ], [VERSION, [NAME, 'Chrome Headless']], [
  7997. /\swv\).+(chrome)\/([\w\.]+)/i // Chrome WebView
  7998. ], [[NAME, /(.+)/, '$1 WebView'], VERSION], [
  7999. /((?:oculus|samsung)browser)\/([\w\.]+)/i
  8000. ], [[NAME, /(.+(?:g|us))(.+)/, '$1 $2'], VERSION], [ // Oculus / Samsung Browser
  8001. /android.+version\/([\w\.]+)\s+(?:mobile\s?safari|safari)*/i // Android Browser
  8002. ], [VERSION, [NAME, 'Android Browser']], [
  8003. /(sailfishbrowser)\/([\w\.]+)/i // Sailfish Browser
  8004. ], [[NAME, 'Sailfish Browser'], VERSION], [
  8005. /(chrome|omniweb|arora|[tizenoka]{5}\s?browser)\/v?([\w\.]+)/i
  8006. // Chrome/OmniWeb/Arora/Tizen/Nokia
  8007. ], [NAME, VERSION], [
  8008. /(dolfin)\/([\w\.]+)/i // Dolphin
  8009. ], [[NAME, 'Dolphin'], VERSION], [
  8010. /(qihu|qhbrowser|qihoobrowser|360browser)/i // 360
  8011. ], [[NAME, '360 Browser']], [
  8012. /((?:android.+)crmo|crios)\/([\w\.]+)/i // Chrome for Android/iOS
  8013. ], [[NAME, 'Chrome'], VERSION], [
  8014. /(coast)\/([\w\.]+)/i // Opera Coast
  8015. ], [[NAME, 'Opera Coast'], VERSION], [
  8016. /fxios\/([\w\.-]+)/i // Firefox for iOS
  8017. ], [VERSION, [NAME, 'Firefox']], [
  8018. /version\/([\w\.]+).+?mobile\/\w+\s(safari)/i // Mobile Safari
  8019. ], [VERSION, [NAME, 'Mobile Safari']], [
  8020. /version\/([\w\.]+).+?(mobile\s?safari|safari)/i // Safari & Safari Mobile
  8021. ], [VERSION, NAME], [
  8022. /webkit.+?(gsa)\/([\w\.]+).+?(mobile\s?safari|safari)(\/[\w\.]+)/i // Google Search Appliance on iOS
  8023. ], [[NAME, 'GSA'], VERSION], [
  8024. /webkit.+?(mobile\s?safari|safari)(\/[\w\.]+)/i // Safari < 3.0
  8025. ], [NAME, [VERSION, mapper.str, maps.browser.oldsafari.version]], [
  8026. /(webkit|khtml)\/([\w\.]+)/i
  8027. ], [NAME, VERSION], [
  8028. // Gecko based
  8029. /(navigator|netscape)\/([\w\.-]+)/i // Netscape
  8030. ], [[NAME, 'Netscape'], VERSION], [
  8031. /(swiftfox)/i, // Swiftfox
  8032. /(icedragon|iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo|conkeror)[\/\s]?([\w\.\+]+)/i,
  8033. // IceDragon/Iceweasel/Camino/Chimera/Fennec/Maemo/Minimo/Conkeror
  8034. /(firefox|seamonkey|k-meleon|icecat|iceape|firebird|phoenix|palemoon|basilisk|waterfox)\/([\w\.-]+)$/i,
  8035. // Firefox/SeaMonkey/K-Meleon/IceCat/IceApe/Firebird/Phoenix
  8036. /(mozilla)\/([\w\.]+).+rv\:.+gecko\/\d+/i, // Mozilla
  8037. // Other
  8038. /(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|sleipnir)[\/\s]?([\w\.]+)/i,
  8039. // Polaris/Lynx/Dillo/iCab/Doris/Amaya/w3m/NetSurf/Sleipnir
  8040. /(links)\s\(([\w\.]+)/i, // Links
  8041. /(gobrowser)\/?([\w\.]*)/i, // GoBrowser
  8042. /(ice\s?browser)\/v?([\w\._]+)/i, // ICE Browser
  8043. /(mosaic)[\/\s]([\w\.]+)/i // Mosaic
  8044. ], [NAME, VERSION]
  8045. ],
  8046. cpu : [[
  8047. /(?:(amd|x(?:(?:86|64)[_-])?|wow|win)64)[;\)]/i // AMD64
  8048. ], [[ARCHITECTURE, 'amd64']], [
  8049. /(ia32(?=;))/i // IA32 (quicktime)
  8050. ], [[ARCHITECTURE, util.lowerize]], [
  8051. /((?:i[346]|x)86)[;\)]/i // IA32
  8052. ], [[ARCHITECTURE, 'ia32']], [
  8053. // PocketPC mistakenly identified as PowerPC
  8054. /windows\s(ce|mobile);\sppc;/i
  8055. ], [[ARCHITECTURE, 'arm']], [
  8056. /((?:ppc|powerpc)(?:64)?)(?:\smac|;|\))/i // PowerPC
  8057. ], [[ARCHITECTURE, /ower/, '', util.lowerize]], [
  8058. /(sun4\w)[;\)]/i // SPARC
  8059. ], [[ARCHITECTURE, 'sparc']], [
  8060. /((?:avr32|ia64(?=;))|68k(?=\))|arm(?:64|(?=v\d+[;l]))|(?=atmel\s)avr|(?:irix|mips|sparc)(?:64)?(?=;)|pa-risc)/i
  8061. // IA64, 68K, ARM/64, AVR/32, IRIX/64, MIPS/64, SPARC/64, PA-RISC
  8062. ], [[ARCHITECTURE, util.lowerize]]
  8063. ],
  8064. device : [[
  8065. /\((ipad|playbook);[\w\s\),;-]+(rim|apple)/i // iPad/PlayBook
  8066. ], [MODEL, VENDOR, [TYPE, TABLET]], [
  8067. /applecoremedia\/[\w\.]+ \((ipad)/ // iPad
  8068. ], [MODEL, [VENDOR, 'Apple'], [TYPE, TABLET]], [
  8069. /(apple\s{0,1}tv)/i // Apple TV
  8070. ], [[MODEL, 'Apple TV'], [VENDOR, 'Apple'], [TYPE, SMARTTV]], [
  8071. /(archos)\s(gamepad2?)/i, // Archos
  8072. /(hp).+(touchpad)/i, // HP TouchPad
  8073. /(hp).+(tablet)/i, // HP Tablet
  8074. /(kindle)\/([\w\.]+)/i, // Kindle
  8075. /\s(nook)[\w\s]+build\/(\w+)/i, // Nook
  8076. /(dell)\s(strea[kpr\s\d]*[\dko])/i // Dell Streak
  8077. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8078. /(kf[A-z]+)\sbuild\/.+silk\//i // Kindle Fire HD
  8079. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, TABLET]], [
  8080. /(sd|kf)[0349hijorstuw]+\sbuild\/.+silk\//i // Fire Phone
  8081. ], [[MODEL, mapper.str, maps.device.amazon.model], [VENDOR, 'Amazon'], [TYPE, MOBILE]], [
  8082. /android.+aft([bms])\sbuild/i // Fire TV
  8083. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, SMARTTV]], [
  8084. /\((ip[honed|\s\w*]+);.+(apple)/i // iPod/iPhone
  8085. ], [MODEL, VENDOR, [TYPE, MOBILE]], [
  8086. /\((ip[honed|\s\w*]+);/i // iPod/iPhone
  8087. ], [MODEL, [VENDOR, 'Apple'], [TYPE, MOBILE]], [
  8088. /(blackberry)[\s-]?(\w+)/i, // BlackBerry
  8089. /(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|meizu|motorola|polytron)[\s_-]?([\w-]*)/i,
  8090. // BenQ/Palm/Sony-Ericsson/Acer/Asus/Dell/Meizu/Motorola/Polytron
  8091. /(hp)\s([\w\s]+\w)/i, // HP iPAQ
  8092. /(asus)-?(\w+)/i // Asus
  8093. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8094. /\(bb10;\s(\w+)/i // BlackBerry 10
  8095. ], [MODEL, [VENDOR, 'BlackBerry'], [TYPE, MOBILE]], [
  8096. // Asus Tablets
  8097. /android.+(transfo[prime\s]{4,10}\s\w+|eeepc|slider\s\w+|nexus 7|padfone|p00c)/i
  8098. ], [MODEL, [VENDOR, 'Asus'], [TYPE, TABLET]], [
  8099. /(sony)\s(tablet\s[ps])\sbuild\//i, // Sony
  8100. /(sony)?(?:sgp.+)\sbuild\//i
  8101. ], [[VENDOR, 'Sony'], [MODEL, 'Xperia Tablet'], [TYPE, TABLET]], [
  8102. /android.+\s([c-g]\d{4}|so[-l]\w+)(?=\sbuild\/|\).+chrome\/(?![1-6]{0,1}\d\.))/i
  8103. ], [MODEL, [VENDOR, 'Sony'], [TYPE, MOBILE]], [
  8104. /\s(ouya)\s/i, // Ouya
  8105. /(nintendo)\s([wids3u]+)/i // Nintendo
  8106. ], [VENDOR, MODEL, [TYPE, CONSOLE]], [
  8107. /android.+;\s(shield)\sbuild/i // Nvidia
  8108. ], [MODEL, [VENDOR, 'Nvidia'], [TYPE, CONSOLE]], [
  8109. /(playstation\s[34portablevi]+)/i // Playstation
  8110. ], [MODEL, [VENDOR, 'Sony'], [TYPE, CONSOLE]], [
  8111. /(sprint\s(\w+))/i // Sprint Phones
  8112. ], [[VENDOR, mapper.str, maps.device.sprint.vendor], [MODEL, mapper.str, maps.device.sprint.model], [TYPE, MOBILE]], [
  8113. /(htc)[;_\s-]+([\w\s]+(?=\)|\sbuild)|\w+)/i, // HTC
  8114. /(zte)-(\w*)/i, // ZTE
  8115. /(alcatel|geeksphone|nexian|panasonic|(?=;\s)sony)[_\s-]?([\w-]*)/i
  8116. // Alcatel/GeeksPhone/Nexian/Panasonic/Sony
  8117. ], [VENDOR, [MODEL, /_/g, ' '], [TYPE, MOBILE]], [
  8118. /(nexus\s9)/i // HTC Nexus 9
  8119. ], [MODEL, [VENDOR, 'HTC'], [TYPE, TABLET]], [
  8120. /d\/huawei([\w\s-]+)[;\)]/i,
  8121. /(nexus\s6p|vog-l29|ane-lx1|eml-l29)/i // Huawei
  8122. ], [MODEL, [VENDOR, 'Huawei'], [TYPE, MOBILE]], [
  8123. /android.+(bah2?-a?[lw]\d{2})/i // Huawei MediaPad
  8124. ], [MODEL, [VENDOR, 'Huawei'], [TYPE, TABLET]], [
  8125. /(microsoft);\s(lumia[\s\w]+)/i // Microsoft Lumia
  8126. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8127. /[\s\(;](xbox(?:\sone)?)[\s\);]/i // Microsoft Xbox
  8128. ], [MODEL, [VENDOR, 'Microsoft'], [TYPE, CONSOLE]], [
  8129. /(kin\.[onetw]{3})/i // Microsoft Kin
  8130. ], [[MODEL, /\./g, ' '], [VENDOR, 'Microsoft'], [TYPE, MOBILE]], [
  8131. // Motorola
  8132. /\s(milestone|droid(?:[2-4x]|\s(?:bionic|x2|pro|razr))?:?(\s4g)?)[\w\s]+build\//i,
  8133. /mot[\s-]?(\w*)/i,
  8134. /(XT\d{3,4}) build\//i,
  8135. /(nexus\s6)/i
  8136. ], [MODEL, [VENDOR, 'Motorola'], [TYPE, MOBILE]], [
  8137. /android.+\s(mz60\d|xoom[\s2]{0,2})\sbuild\//i
  8138. ], [MODEL, [VENDOR, 'Motorola'], [TYPE, TABLET]], [
  8139. /hbbtv\/\d+\.\d+\.\d+\s+\([\w\s]*;\s*(\w[^;]*);([^;]*)/i // HbbTV devices
  8140. ], [[VENDOR, util.trim], [MODEL, util.trim], [TYPE, SMARTTV]], [
  8141. /hbbtv.+maple;(\d+)/i
  8142. ], [[MODEL, /^/, 'SmartTV'], [VENDOR, 'Samsung'], [TYPE, SMARTTV]], [
  8143. /\(dtv[\);].+(aquos)/i // Sharp
  8144. ], [MODEL, [VENDOR, 'Sharp'], [TYPE, SMARTTV]], [
  8145. /android.+((sch-i[89]0\d|shw-m380s|gt-p\d{4}|gt-n\d+|sgh-t8[56]9|nexus 10))/i,
  8146. /((SM-T\w+))/i
  8147. ], [[VENDOR, 'Samsung'], MODEL, [TYPE, TABLET]], [ // Samsung
  8148. /smart-tv.+(samsung)/i
  8149. ], [VENDOR, [TYPE, SMARTTV], MODEL], [
  8150. /((s[cgp]h-\w+|gt-\w+|galaxy\snexus|sm-\w[\w\d]+))/i,
  8151. /(sam[sung]*)[\s-]*(\w+-?[\w-]*)/i,
  8152. /sec-((sgh\w+))/i
  8153. ], [[VENDOR, 'Samsung'], MODEL, [TYPE, MOBILE]], [
  8154. /sie-(\w*)/i // Siemens
  8155. ], [MODEL, [VENDOR, 'Siemens'], [TYPE, MOBILE]], [
  8156. /(maemo|nokia).*(n900|lumia\s\d+)/i, // Nokia
  8157. /(nokia)[\s_-]?([\w-]*)/i
  8158. ], [[VENDOR, 'Nokia'], MODEL, [TYPE, MOBILE]], [
  8159. /android[x\d\.\s;]+\s([ab][1-7]\-?[0178a]\d\d?)/i // Acer
  8160. ], [MODEL, [VENDOR, 'Acer'], [TYPE, TABLET]], [
  8161. /android.+([vl]k\-?\d{3})\s+build/i // LG Tablet
  8162. ], [MODEL, [VENDOR, 'LG'], [TYPE, TABLET]], [
  8163. /android\s3\.[\s\w;-]{10}(lg?)-([06cv9]{3,4})/i // LG Tablet
  8164. ], [[VENDOR, 'LG'], MODEL, [TYPE, TABLET]], [
  8165. /(lg) netcast\.tv/i // LG SmartTV
  8166. ], [VENDOR, MODEL, [TYPE, SMARTTV]], [
  8167. /(nexus\s[45])/i, // LG
  8168. /lg[e;\s\/-]+(\w*)/i,
  8169. /android.+lg(\-?[\d\w]+)\s+build/i
  8170. ], [MODEL, [VENDOR, 'LG'], [TYPE, MOBILE]], [
  8171. /(lenovo)\s?(s(?:5000|6000)(?:[\w-]+)|tab(?:[\s\w]+))/i // Lenovo tablets
  8172. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8173. /android.+(ideatab[a-z0-9\-\s]+)/i // Lenovo
  8174. ], [MODEL, [VENDOR, 'Lenovo'], [TYPE, TABLET]], [
  8175. /(lenovo)[_\s-]?([\w-]+)/i
  8176. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8177. /linux;.+((jolla));/i // Jolla
  8178. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8179. /((pebble))app\/[\d\.]+\s/i // Pebble
  8180. ], [VENDOR, MODEL, [TYPE, WEARABLE]], [
  8181. /android.+;\s(oppo)\s?([\w\s]+)\sbuild/i // OPPO
  8182. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8183. /crkey/i // Google Chromecast
  8184. ], [[MODEL, 'Chromecast'], [VENDOR, 'Google'], [TYPE, SMARTTV]], [
  8185. /android.+;\s(glass)\s\d/i // Google Glass
  8186. ], [MODEL, [VENDOR, 'Google'], [TYPE, WEARABLE]], [
  8187. /android.+;\s(pixel c)[\s)]/i // Google Pixel C
  8188. ], [MODEL, [VENDOR, 'Google'], [TYPE, TABLET]], [
  8189. /android.+;\s(pixel( [23])?( xl)?)[\s)]/i // Google Pixel
  8190. ], [MODEL, [VENDOR, 'Google'], [TYPE, MOBILE]], [
  8191. /android.+;\s(\w+)\s+build\/hm\1/i, // Xiaomi Hongmi 'numeric' models
  8192. /android.+(hm[\s\-_]*note?[\s_]*(?:\d\w)?)\s+build/i, // Xiaomi Hongmi
  8193. /android.+(mi[\s\-_]*(?:a\d|one|one[\s_]plus|note lte)?[\s_]*(?:\d?\w?)[\s_]*(?:plus)?)\s+build/i,
  8194. // Xiaomi Mi
  8195. /android.+(redmi[\s\-_]*(?:note)?(?:[\s_]*[\w\s]+))\s+build/i // Redmi Phones
  8196. ], [[MODEL, /_/g, ' '], [VENDOR, 'Xiaomi'], [TYPE, MOBILE]], [
  8197. /android.+(mi[\s\-_]*(?:pad)(?:[\s_]*[\w\s]+))\s+build/i // Mi Pad tablets
  8198. ],[[MODEL, /_/g, ' '], [VENDOR, 'Xiaomi'], [TYPE, TABLET]], [
  8199. /android.+;\s(m[1-5]\snote)\sbuild/i // Meizu
  8200. ], [MODEL, [VENDOR, 'Meizu'], [TYPE, MOBILE]], [
  8201. /(mz)-([\w-]{2,})/i
  8202. ], [[VENDOR, 'Meizu'], MODEL, [TYPE, MOBILE]], [
  8203. /android.+a000(1)\s+build/i, // OnePlus
  8204. /android.+oneplus\s(a\d{4})[\s)]/i
  8205. ], [MODEL, [VENDOR, 'OnePlus'], [TYPE, MOBILE]], [
  8206. /android.+[;\/]\s*(RCT[\d\w]+)\s+build/i // RCA Tablets
  8207. ], [MODEL, [VENDOR, 'RCA'], [TYPE, TABLET]], [
  8208. /android.+[;\/\s]+(Venue[\d\s]{2,7})\s+build/i // Dell Venue Tablets
  8209. ], [MODEL, [VENDOR, 'Dell'], [TYPE, TABLET]], [
  8210. /android.+[;\/]\s*(Q[T|M][\d\w]+)\s+build/i // Verizon Tablet
  8211. ], [MODEL, [VENDOR, 'Verizon'], [TYPE, TABLET]], [
  8212. /android.+[;\/]\s+(Barnes[&\s]+Noble\s+|BN[RT])(V?.*)\s+build/i // Barnes & Noble Tablet
  8213. ], [[VENDOR, 'Barnes & Noble'], MODEL, [TYPE, TABLET]], [
  8214. /android.+[;\/]\s+(TM\d{3}.*\b)\s+build/i // Barnes & Noble Tablet
  8215. ], [MODEL, [VENDOR, 'NuVision'], [TYPE, TABLET]], [
  8216. /android.+;\s(k88)\sbuild/i // ZTE K Series Tablet
  8217. ], [MODEL, [VENDOR, 'ZTE'], [TYPE, TABLET]], [
  8218. /android.+[;\/]\s*(gen\d{3})\s+build.*49h/i // Swiss GEN Mobile
  8219. ], [MODEL, [VENDOR, 'Swiss'], [TYPE, MOBILE]], [
  8220. /android.+[;\/]\s*(zur\d{3})\s+build/i // Swiss ZUR Tablet
  8221. ], [MODEL, [VENDOR, 'Swiss'], [TYPE, TABLET]], [
  8222. /android.+[;\/]\s*((Zeki)?TB.*\b)\s+build/i // Zeki Tablets
  8223. ], [MODEL, [VENDOR, 'Zeki'], [TYPE, TABLET]], [
  8224. /(android).+[;\/]\s+([YR]\d{2})\s+build/i,
  8225. /android.+[;\/]\s+(Dragon[\-\s]+Touch\s+|DT)(\w{5})\sbuild/i // Dragon Touch Tablet
  8226. ], [[VENDOR, 'Dragon Touch'], MODEL, [TYPE, TABLET]], [
  8227. /android.+[;\/]\s*(NS-?\w{0,9})\sbuild/i // Insignia Tablets
  8228. ], [MODEL, [VENDOR, 'Insignia'], [TYPE, TABLET]], [
  8229. /android.+[;\/]\s*((NX|Next)-?\w{0,9})\s+build/i // NextBook Tablets
  8230. ], [MODEL, [VENDOR, 'NextBook'], [TYPE, TABLET]], [
  8231. /android.+[;\/]\s*(Xtreme\_)?(V(1[045]|2[015]|30|40|60|7[05]|90))\s+build/i
  8232. ], [[VENDOR, 'Voice'], MODEL, [TYPE, MOBILE]], [ // Voice Xtreme Phones
  8233. /android.+[;\/]\s*(LVTEL\-)?(V1[12])\s+build/i // LvTel Phones
  8234. ], [[VENDOR, 'LvTel'], MODEL, [TYPE, MOBILE]], [
  8235. /android.+;\s(PH-1)\s/i
  8236. ], [MODEL, [VENDOR, 'Essential'], [TYPE, MOBILE]], [ // Essential PH-1
  8237. /android.+[;\/]\s*(V(100MD|700NA|7011|917G).*\b)\s+build/i // Envizen Tablets
  8238. ], [MODEL, [VENDOR, 'Envizen'], [TYPE, TABLET]], [
  8239. /android.+[;\/]\s*(Le[\s\-]+Pan)[\s\-]+(\w{1,9})\s+build/i // Le Pan Tablets
  8240. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8241. /android.+[;\/]\s*(Trio[\s\-]*.*)\s+build/i // MachSpeed Tablets
  8242. ], [MODEL, [VENDOR, 'MachSpeed'], [TYPE, TABLET]], [
  8243. /android.+[;\/]\s*(Trinity)[\-\s]*(T\d{3})\s+build/i // Trinity Tablets
  8244. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8245. /android.+[;\/]\s*TU_(1491)\s+build/i // Rotor Tablets
  8246. ], [MODEL, [VENDOR, 'Rotor'], [TYPE, TABLET]], [
  8247. /android.+(KS(.+))\s+build/i // Amazon Kindle Tablets
  8248. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, TABLET]], [
  8249. /android.+(Gigaset)[\s\-]+(Q\w{1,9})\s+build/i // Gigaset Tablets
  8250. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8251. /\s(tablet|tab)[;\/]/i, // Unidentifiable Tablet
  8252. /\s(mobile)(?:[;\/]|\ssafari)/i // Unidentifiable Mobile
  8253. ], [[TYPE, util.lowerize], VENDOR, MODEL], [
  8254. /[\s\/\(](smart-?tv)[;\)]/i // SmartTV
  8255. ], [[TYPE, SMARTTV]], [
  8256. /(android[\w\.\s\-]{0,9});.+build/i // Generic Android Device
  8257. ], [MODEL, [VENDOR, 'Generic']]
  8258. ],
  8259. engine : [[
  8260. /windows.+\sedge\/([\w\.]+)/i // EdgeHTML
  8261. ], [VERSION, [NAME, 'EdgeHTML']], [
  8262. /webkit\/537\.36.+chrome\/(?!27)([\w\.]+)/i // Blink
  8263. ], [VERSION, [NAME, 'Blink']], [
  8264. /(presto)\/([\w\.]+)/i, // Presto
  8265. /(webkit|trident|netfront|netsurf|amaya|lynx|w3m|goanna)\/([\w\.]+)/i,
  8266. // WebKit/Trident/NetFront/NetSurf/Amaya/Lynx/w3m/Goanna
  8267. /(khtml|tasman|links)[\/\s]\(?([\w\.]+)/i, // KHTML/Tasman/Links
  8268. /(icab)[\/\s]([23]\.[\d\.]+)/i // iCab
  8269. ], [NAME, VERSION], [
  8270. /rv\:([\w\.]{1,9}).+(gecko)/i // Gecko
  8271. ], [VERSION, NAME]
  8272. ],
  8273. os : [[
  8274. // Windows based
  8275. /microsoft\s(windows)\s(vista|xp)/i // Windows (iTunes)
  8276. ], [NAME, VERSION], [
  8277. /(windows)\snt\s6\.2;\s(arm)/i, // Windows RT
  8278. /(windows\sphone(?:\sos)*)[\s\/]?([\d\.\s\w]*)/i, // Windows Phone
  8279. /(windows\smobile|windows)[\s\/]?([ntce\d\.\s]+\w)/i
  8280. ], [NAME, [VERSION, mapper.str, maps.os.windows.version]], [
  8281. /(win(?=3|9|n)|win\s9x\s)([nt\d\.]+)/i
  8282. ], [[NAME, 'Windows'], [VERSION, mapper.str, maps.os.windows.version]], [
  8283. // Mobile/Embedded OS
  8284. /\((bb)(10);/i // BlackBerry 10
  8285. ], [[NAME, 'BlackBerry'], VERSION], [
  8286. /(blackberry)\w*\/?([\w\.]*)/i, // Blackberry
  8287. /(tizen|kaios)[\/\s]([\w\.]+)/i, // Tizen/KaiOS
  8288. /(android|webos|palm\sos|qnx|bada|rim\stablet\sos|meego|sailfish|contiki)[\/\s-]?([\w\.]*)/i
  8289. // Android/WebOS/Palm/QNX/Bada/RIM/MeeGo/Contiki/Sailfish OS
  8290. ], [NAME, VERSION], [
  8291. /(symbian\s?os|symbos|s60(?=;))[\/\s-]?([\w\.]*)/i // Symbian
  8292. ], [[NAME, 'Symbian'], VERSION], [
  8293. /\((series40);/i // Series 40
  8294. ], [NAME], [
  8295. /mozilla.+\(mobile;.+gecko.+firefox/i // Firefox OS
  8296. ], [[NAME, 'Firefox OS'], VERSION], [
  8297. // Console
  8298. /(nintendo|playstation)\s([wids34portablevu]+)/i, // Nintendo/Playstation
  8299. // GNU/Linux based
  8300. /(mint)[\/\s\(]?(\w*)/i, // Mint
  8301. /(mageia|vectorlinux)[;\s]/i, // Mageia/VectorLinux
  8302. /(joli|[kxln]?ubuntu|debian|suse|opensuse|gentoo|(?=\s)arch|slackware|fedora|mandriva|centos|pclinuxos|redhat|zenwalk|linpus)[\/\s-]?(?!chrom)([\w\.-]*)/i,
  8303. // Joli/Ubuntu/Debian/SUSE/Gentoo/Arch/Slackware
  8304. // Fedora/Mandriva/CentOS/PCLinuxOS/RedHat/Zenwalk/Linpus
  8305. /(hurd|linux)\s?([\w\.]*)/i, // Hurd/Linux
  8306. /(gnu)\s?([\w\.]*)/i // GNU
  8307. ], [NAME, VERSION], [
  8308. /(cros)\s[\w]+\s([\w\.]+\w)/i // Chromium OS
  8309. ], [[NAME, 'Chromium OS'], VERSION],[
  8310. // Solaris
  8311. /(sunos)\s?([\w\.\d]*)/i // Solaris
  8312. ], [[NAME, 'Solaris'], VERSION], [
  8313. // BSD based
  8314. /\s([frentopc-]{0,4}bsd|dragonfly)\s?([\w\.]*)/i // FreeBSD/NetBSD/OpenBSD/PC-BSD/DragonFly
  8315. ], [NAME, VERSION],[
  8316. /(haiku)\s(\w+)/i // Haiku
  8317. ], [NAME, VERSION],[
  8318. /cfnetwork\/.+darwin/i,
  8319. /ip[honead]{2,4}(?:.*os\s([\w]+)\slike\smac|;\sopera)/i // iOS
  8320. ], [[VERSION, /_/g, '.'], [NAME, 'iOS']], [
  8321. /(mac\sos\sx)\s?([\w\s\.]*)/i,
  8322. /(macintosh|mac(?=_powerpc)\s)/i // Mac OS
  8323. ], [[NAME, 'Mac OS'], [VERSION, /_/g, '.']], [
  8324. // Other
  8325. /((?:open)?solaris)[\/\s-]?([\w\.]*)/i, // Solaris
  8326. /(aix)\s((\d)(?=\.|\)|\s)[\w\.])*/i, // AIX
  8327. /(plan\s9|minix|beos|os\/2|amigaos|morphos|risc\sos|openvms|fuchsia)/i,
  8328. // Plan9/Minix/BeOS/OS2/AmigaOS/MorphOS/RISCOS/OpenVMS/Fuchsia
  8329. /(unix)\s?([\w\.]*)/i // UNIX
  8330. ], [NAME, VERSION]
  8331. ]
  8332. };
  8333. /////////////////
  8334. // Constructor
  8335. ////////////////
  8336. var UAParser = function (uastring, extensions) {
  8337. if (typeof uastring === 'object') {
  8338. extensions = uastring;
  8339. uastring = undefined$1;
  8340. }
  8341. if (!(this instanceof UAParser)) {
  8342. return new UAParser(uastring, extensions).getResult();
  8343. }
  8344. var ua = uastring || ((window && window.navigator && window.navigator.userAgent) ? window.navigator.userAgent : EMPTY);
  8345. var rgxmap = extensions ? util.extend(regexes, extensions) : regexes;
  8346. this.getBrowser = function () {
  8347. var browser = { name: undefined$1, version: undefined$1 };
  8348. mapper.rgx.call(browser, ua, rgxmap.browser);
  8349. browser.major = util.major(browser.version); // deprecated
  8350. return browser;
  8351. };
  8352. this.getCPU = function () {
  8353. var cpu = { architecture: undefined$1 };
  8354. mapper.rgx.call(cpu, ua, rgxmap.cpu);
  8355. return cpu;
  8356. };
  8357. this.getDevice = function () {
  8358. var device = { vendor: undefined$1, model: undefined$1, type: undefined$1 };
  8359. mapper.rgx.call(device, ua, rgxmap.device);
  8360. return device;
  8361. };
  8362. this.getEngine = function () {
  8363. var engine = { name: undefined$1, version: undefined$1 };
  8364. mapper.rgx.call(engine, ua, rgxmap.engine);
  8365. return engine;
  8366. };
  8367. this.getOS = function () {
  8368. var os = { name: undefined$1, version: undefined$1 };
  8369. mapper.rgx.call(os, ua, rgxmap.os);
  8370. return os;
  8371. };
  8372. this.getResult = function () {
  8373. return {
  8374. ua : this.getUA(),
  8375. browser : this.getBrowser(),
  8376. engine : this.getEngine(),
  8377. os : this.getOS(),
  8378. device : this.getDevice(),
  8379. cpu : this.getCPU()
  8380. };
  8381. };
  8382. this.getUA = function () {
  8383. return ua;
  8384. };
  8385. this.setUA = function (uastring) {
  8386. ua = uastring;
  8387. return this;
  8388. };
  8389. return this;
  8390. };
  8391. UAParser.VERSION = LIBVERSION;
  8392. UAParser.BROWSER = {
  8393. NAME : NAME,
  8394. MAJOR : MAJOR, // deprecated
  8395. VERSION : VERSION
  8396. };
  8397. UAParser.CPU = {
  8398. ARCHITECTURE : ARCHITECTURE
  8399. };
  8400. UAParser.DEVICE = {
  8401. MODEL : MODEL,
  8402. VENDOR : VENDOR,
  8403. TYPE : TYPE,
  8404. CONSOLE : CONSOLE,
  8405. MOBILE : MOBILE,
  8406. SMARTTV : SMARTTV,
  8407. TABLET : TABLET,
  8408. WEARABLE: WEARABLE,
  8409. EMBEDDED: EMBEDDED
  8410. };
  8411. UAParser.ENGINE = {
  8412. NAME : NAME,
  8413. VERSION : VERSION
  8414. };
  8415. UAParser.OS = {
  8416. NAME : NAME,
  8417. VERSION : VERSION
  8418. };
  8419. ///////////
  8420. // Export
  8421. //////////
  8422. // check js environment
  8423. {
  8424. // nodejs env
  8425. if ( module.exports) {
  8426. exports = module.exports = UAParser;
  8427. }
  8428. exports.UAParser = UAParser;
  8429. }
  8430. // jQuery/Zepto specific (optional)
  8431. // Note:
  8432. // In AMD env the global scope should be kept clean, but jQuery is an exception.
  8433. // jQuery always exports to global scope, unless jQuery.noConflict(true) is used,
  8434. // and we should catch that.
  8435. var $ = window && (window.jQuery || window.Zepto);
  8436. if ($ && !$.ua) {
  8437. var parser = new UAParser();
  8438. $.ua = parser.getResult();
  8439. $.ua.get = function () {
  8440. return parser.getUA();
  8441. };
  8442. $.ua.set = function (uastring) {
  8443. parser.setUA(uastring);
  8444. var result = parser.getResult();
  8445. for (var prop in result) {
  8446. $.ua[prop] = result[prop];
  8447. }
  8448. };
  8449. }
  8450. })(typeof window === 'object' ? window : commonjsGlobal);
  8451. });
  8452. var uaParser_1 = uaParser.UAParser;
  8453. var UNKNOWN = 'Unknown';
  8454. var PLATFORM_MAP = {
  8455. 'Mac OS': 'Mac OS X'
  8456. };
  8457. /**
  8458. * Convert from UAParser platform name to what we expect.
  8459. */
  8460. function convertPlatformName(name) {
  8461. return PLATFORM_MAP[name] || name;
  8462. }
  8463. /**
  8464. * Get the version number in parts. This is very naive. We actually get major
  8465. * version as a part of UAParser already, which is generally good enough, but
  8466. * let's get the minor just in case.
  8467. */
  8468. function getBrowserVersion(version) {
  8469. if (!version) {
  8470. return {
  8471. major: '',
  8472. minor: ''
  8473. };
  8474. }
  8475. var parts = version.split('.');
  8476. return {
  8477. major: parts[0],
  8478. minor: parts[1]
  8479. };
  8480. }
  8481. /**
  8482. * Get the UA data fom UAParser and then convert it to the format we're
  8483. * expecting for our APIS.
  8484. */
  8485. var parser = new uaParser();
  8486. var results = parser.getResult();
  8487. // Do some conversion first.
  8488. var browserVersionData = getBrowserVersion(results.browser.version);
  8489. var uaData = {
  8490. browserArchitecture: results.cpu.architecture || UNKNOWN,
  8491. browserFullVersion: results.browser.version || UNKNOWN,
  8492. browserMinorVersion: browserVersionData.minor || UNKNOWN,
  8493. browserName: results.browser.name || UNKNOWN,
  8494. browserVersion: results.browser.major || UNKNOWN,
  8495. deviceName: results.device.model || UNKNOWN,
  8496. engineName: results.engine.name || UNKNOWN,
  8497. engineVersion: results.engine.version || UNKNOWN,
  8498. platformArchitecture: results.cpu.architecture || UNKNOWN,
  8499. platformName: convertPlatformName(results.os.name) || UNKNOWN,
  8500. platformVersion: results.os.version || UNKNOWN,
  8501. platformFullVersion: results.os.version || UNKNOWN
  8502. };
  8503. var UserAgentData = uaData;
  8504. var componentRegex = /\./;
  8505. var orRegex = /\|\|/;
  8506. var rangeRegex = /\s+\-\s+/;
  8507. var modifierRegex = /^(<=|<|=|>=|~>|~|>|)?\s*(.+)/;
  8508. var numericRegex = /^(\d*)(.*)/;
  8509. /**
  8510. * Splits input `range` on "||" and returns true if any subrange matches
  8511. * `version`.
  8512. *
  8513. * @param {string} range
  8514. * @param {string} version
  8515. * @returns {boolean}
  8516. */
  8517. function checkOrExpression(range, version) {
  8518. var expressions = range.split(orRegex);
  8519. if (expressions.length > 1) {
  8520. return expressions.some(function (range) {
  8521. return VersionRange.contains(range, version);
  8522. });
  8523. } else {
  8524. range = expressions[0].trim();
  8525. return checkRangeExpression(range, version);
  8526. }
  8527. }
  8528. /**
  8529. * Splits input `range` on " - " (the surrounding whitespace is required) and
  8530. * returns true if version falls between the two operands.
  8531. *
  8532. * @param {string} range
  8533. * @param {string} version
  8534. * @returns {boolean}
  8535. */
  8536. function checkRangeExpression(range, version) {
  8537. var expressions = range.split(rangeRegex);
  8538. !(expressions.length > 0 && expressions.length <= 2) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'the "-" operator expects exactly 2 operands') : invariant_1(false) : void 0;
  8539. if (expressions.length === 1) {
  8540. return checkSimpleExpression(expressions[0], version);
  8541. } else {
  8542. var startVersion = expressions[0],
  8543. endVersion = expressions[1];
  8544. !(isSimpleVersion(startVersion) && isSimpleVersion(endVersion)) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'operands to the "-" operator must be simple (no modifiers)') : invariant_1(false) : void 0;
  8545. return checkSimpleExpression('>=' + startVersion, version) && checkSimpleExpression('<=' + endVersion, version);
  8546. }
  8547. }
  8548. /**
  8549. * Checks if `range` matches `version`. `range` should be a "simple" range (ie.
  8550. * not a compound range using the " - " or "||" operators).
  8551. *
  8552. * @param {string} range
  8553. * @param {string} version
  8554. * @returns {boolean}
  8555. */
  8556. function checkSimpleExpression(range, version) {
  8557. range = range.trim();
  8558. if (range === '') {
  8559. return true;
  8560. }
  8561. var versionComponents = version.split(componentRegex);
  8562. var _getModifierAndCompon = getModifierAndComponents(range),
  8563. modifier = _getModifierAndCompon.modifier,
  8564. rangeComponents = _getModifierAndCompon.rangeComponents;
  8565. switch (modifier) {
  8566. case '<':
  8567. return checkLessThan(versionComponents, rangeComponents);
  8568. case '<=':
  8569. return checkLessThanOrEqual(versionComponents, rangeComponents);
  8570. case '>=':
  8571. return checkGreaterThanOrEqual(versionComponents, rangeComponents);
  8572. case '>':
  8573. return checkGreaterThan(versionComponents, rangeComponents);
  8574. case '~':
  8575. case '~>':
  8576. return checkApproximateVersion(versionComponents, rangeComponents);
  8577. default:
  8578. return checkEqual(versionComponents, rangeComponents);
  8579. }
  8580. }
  8581. /**
  8582. * Checks whether `a` is less than `b`.
  8583. *
  8584. * @param {array<string>} a
  8585. * @param {array<string>} b
  8586. * @returns {boolean}
  8587. */
  8588. function checkLessThan(a, b) {
  8589. return compareComponents(a, b) === -1;
  8590. }
  8591. /**
  8592. * Checks whether `a` is less than or equal to `b`.
  8593. *
  8594. * @param {array<string>} a
  8595. * @param {array<string>} b
  8596. * @returns {boolean}
  8597. */
  8598. function checkLessThanOrEqual(a, b) {
  8599. var result = compareComponents(a, b);
  8600. return result === -1 || result === 0;
  8601. }
  8602. /**
  8603. * Checks whether `a` is equal to `b`.
  8604. *
  8605. * @param {array<string>} a
  8606. * @param {array<string>} b
  8607. * @returns {boolean}
  8608. */
  8609. function checkEqual(a, b) {
  8610. return compareComponents(a, b) === 0;
  8611. }
  8612. /**
  8613. * Checks whether `a` is greater than or equal to `b`.
  8614. *
  8615. * @param {array<string>} a
  8616. * @param {array<string>} b
  8617. * @returns {boolean}
  8618. */
  8619. function checkGreaterThanOrEqual(a, b) {
  8620. var result = compareComponents(a, b);
  8621. return result === 1 || result === 0;
  8622. }
  8623. /**
  8624. * Checks whether `a` is greater than `b`.
  8625. *
  8626. * @param {array<string>} a
  8627. * @param {array<string>} b
  8628. * @returns {boolean}
  8629. */
  8630. function checkGreaterThan(a, b) {
  8631. return compareComponents(a, b) === 1;
  8632. }
  8633. /**
  8634. * Checks whether `a` is "reasonably close" to `b` (as described in
  8635. * https://www.npmjs.org/doc/misc/semver.html). For example, if `b` is "1.3.1"
  8636. * then "reasonably close" is defined as ">= 1.3.1 and < 1.4".
  8637. *
  8638. * @param {array<string>} a
  8639. * @param {array<string>} b
  8640. * @returns {boolean}
  8641. */
  8642. function checkApproximateVersion(a, b) {
  8643. var lowerBound = b.slice();
  8644. var upperBound = b.slice();
  8645. if (upperBound.length > 1) {
  8646. upperBound.pop();
  8647. }
  8648. var lastIndex = upperBound.length - 1;
  8649. var numeric = parseInt(upperBound[lastIndex], 10);
  8650. if (isNumber(numeric)) {
  8651. upperBound[lastIndex] = numeric + 1 + '';
  8652. }
  8653. return checkGreaterThanOrEqual(a, lowerBound) && checkLessThan(a, upperBound);
  8654. }
  8655. /**
  8656. * Extracts the optional modifier (<, <=, =, >=, >, ~, ~>) and version
  8657. * components from `range`.
  8658. *
  8659. * For example, given `range` ">= 1.2.3" returns an object with a `modifier` of
  8660. * `">="` and `components` of `[1, 2, 3]`.
  8661. *
  8662. * @param {string} range
  8663. * @returns {object}
  8664. */
  8665. function getModifierAndComponents(range) {
  8666. var rangeComponents = range.split(componentRegex);
  8667. var matches = rangeComponents[0].match(modifierRegex);
  8668. !matches ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'expected regex to match but it did not') : invariant_1(false) : void 0;
  8669. return {
  8670. modifier: matches[1],
  8671. rangeComponents: [matches[2]].concat(rangeComponents.slice(1))
  8672. };
  8673. }
  8674. /**
  8675. * Determines if `number` is a number.
  8676. *
  8677. * @param {mixed} number
  8678. * @returns {boolean}
  8679. */
  8680. function isNumber(number) {
  8681. return !isNaN(number) && isFinite(number);
  8682. }
  8683. /**
  8684. * Tests whether `range` is a "simple" version number without any modifiers
  8685. * (">", "~" etc).
  8686. *
  8687. * @param {string} range
  8688. * @returns {boolean}
  8689. */
  8690. function isSimpleVersion(range) {
  8691. return !getModifierAndComponents(range).modifier;
  8692. }
  8693. /**
  8694. * Zero-pads array `array` until it is at least `length` long.
  8695. *
  8696. * @param {array} array
  8697. * @param {number} length
  8698. */
  8699. function zeroPad(array, length) {
  8700. for (var i = array.length; i < length; i++) {
  8701. array[i] = '0';
  8702. }
  8703. }
  8704. /**
  8705. * Normalizes `a` and `b` in preparation for comparison by doing the following:
  8706. *
  8707. * - zero-pads `a` and `b`
  8708. * - marks any "x", "X" or "*" component in `b` as equivalent by zero-ing it out
  8709. * in both `a` and `b`
  8710. * - marks any final "*" component in `b` as a greedy wildcard by zero-ing it
  8711. * and all of its successors in `a`
  8712. *
  8713. * @param {array<string>} a
  8714. * @param {array<string>} b
  8715. * @returns {array<array<string>>}
  8716. */
  8717. function normalizeVersions(a, b) {
  8718. a = a.slice();
  8719. b = b.slice();
  8720. zeroPad(a, b.length);
  8721. // mark "x" and "*" components as equal
  8722. for (var i = 0; i < b.length; i++) {
  8723. var matches = b[i].match(/^[x*]$/i);
  8724. if (matches) {
  8725. b[i] = a[i] = '0';
  8726. // final "*" greedily zeros all remaining components
  8727. if (matches[0] === '*' && i === b.length - 1) {
  8728. for (var j = i; j < a.length; j++) {
  8729. a[j] = '0';
  8730. }
  8731. }
  8732. }
  8733. }
  8734. zeroPad(b, a.length);
  8735. return [a, b];
  8736. }
  8737. /**
  8738. * Returns the numerical -- not the lexicographical -- ordering of `a` and `b`.
  8739. *
  8740. * For example, `10-alpha` is greater than `2-beta`.
  8741. *
  8742. * @param {string} a
  8743. * @param {string} b
  8744. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  8745. * or greater than `b`, respectively
  8746. */
  8747. function compareNumeric(a, b) {
  8748. var aPrefix = a.match(numericRegex)[1];
  8749. var bPrefix = b.match(numericRegex)[1];
  8750. var aNumeric = parseInt(aPrefix, 10);
  8751. var bNumeric = parseInt(bPrefix, 10);
  8752. if (isNumber(aNumeric) && isNumber(bNumeric) && aNumeric !== bNumeric) {
  8753. return compare(aNumeric, bNumeric);
  8754. } else {
  8755. return compare(a, b);
  8756. }
  8757. }
  8758. /**
  8759. * Returns the ordering of `a` and `b`.
  8760. *
  8761. * @param {string|number} a
  8762. * @param {string|number} b
  8763. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  8764. * or greater than `b`, respectively
  8765. */
  8766. function compare(a, b) {
  8767. !(typeof a === typeof b) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '"a" and "b" must be of the same type') : invariant_1(false) : void 0;
  8768. if (a > b) {
  8769. return 1;
  8770. } else if (a < b) {
  8771. return -1;
  8772. } else {
  8773. return 0;
  8774. }
  8775. }
  8776. /**
  8777. * Compares arrays of version components.
  8778. *
  8779. * @param {array<string>} a
  8780. * @param {array<string>} b
  8781. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  8782. * or greater than `b`, respectively
  8783. */
  8784. function compareComponents(a, b) {
  8785. var _normalizeVersions = normalizeVersions(a, b),
  8786. aNormalized = _normalizeVersions[0],
  8787. bNormalized = _normalizeVersions[1];
  8788. for (var i = 0; i < bNormalized.length; i++) {
  8789. var result = compareNumeric(aNormalized[i], bNormalized[i]);
  8790. if (result) {
  8791. return result;
  8792. }
  8793. }
  8794. return 0;
  8795. }
  8796. var VersionRange = {
  8797. /**
  8798. * Checks whether `version` satisfies the `range` specification.
  8799. *
  8800. * We support a subset of the expressions defined in
  8801. * https://www.npmjs.org/doc/misc/semver.html:
  8802. *
  8803. * version Must match version exactly
  8804. * =version Same as just version
  8805. * >version Must be greater than version
  8806. * >=version Must be greater than or equal to version
  8807. * <version Must be less than version
  8808. * <=version Must be less than or equal to version
  8809. * ~version Must be at least version, but less than the next significant
  8810. * revision above version:
  8811. * "~1.2.3" is equivalent to ">= 1.2.3 and < 1.3"
  8812. * ~>version Equivalent to ~version
  8813. * 1.2.x Must match "1.2.x", where "x" is a wildcard that matches
  8814. * anything
  8815. * 1.2.* Similar to "1.2.x", but "*" in the trailing position is a
  8816. * "greedy" wildcard, so will match any number of additional
  8817. * components:
  8818. * "1.2.*" will match "1.2.1", "1.2.1.1", "1.2.1.1.1" etc
  8819. * * Any version
  8820. * "" (Empty string) Same as *
  8821. * v1 - v2 Equivalent to ">= v1 and <= v2"
  8822. * r1 || r2 Passes if either r1 or r2 are satisfied
  8823. *
  8824. * @param {string} range
  8825. * @param {string} version
  8826. * @returns {boolean}
  8827. */
  8828. contains: function contains(range, version) {
  8829. return checkOrExpression(range.trim(), version.trim());
  8830. }
  8831. };
  8832. var VersionRange_1 = VersionRange;
  8833. /**
  8834. * Copyright (c) 2013-present, Facebook, Inc.
  8835. *
  8836. * This source code is licensed under the MIT license found in the
  8837. * LICENSE file in the root directory of this source tree.
  8838. *
  8839. */
  8840. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  8841. /**
  8842. * Executes the provided `callback` once for each enumerable own property in the
  8843. * object and constructs a new object from the results. The `callback` is
  8844. * invoked with three arguments:
  8845. *
  8846. * - the property value
  8847. * - the property name
  8848. * - the object being traversed
  8849. *
  8850. * Properties that are added after the call to `mapObject` will not be visited
  8851. * by `callback`. If the values of existing properties are changed, the value
  8852. * passed to `callback` will be the value at the time `mapObject` visits them.
  8853. * Properties that are deleted before being visited are not visited.
  8854. *
  8855. * @grep function objectMap()
  8856. * @grep function objMap()
  8857. *
  8858. * @param {?object} object
  8859. * @param {function} callback
  8860. * @param {*} context
  8861. * @return {?object}
  8862. */
  8863. function mapObject(object, callback, context) {
  8864. if (!object) {
  8865. return null;
  8866. }
  8867. var result = {};
  8868. for (var name in object) {
  8869. if (hasOwnProperty$1.call(object, name)) {
  8870. result[name] = callback.call(context, object[name], name, object);
  8871. }
  8872. }
  8873. return result;
  8874. }
  8875. var mapObject_1 = mapObject;
  8876. /**
  8877. * Copyright (c) 2013-present, Facebook, Inc.
  8878. *
  8879. * This source code is licensed under the MIT license found in the
  8880. * LICENSE file in the root directory of this source tree.
  8881. *
  8882. *
  8883. * @typechecks static-only
  8884. */
  8885. /**
  8886. * Memoizes the return value of a function that accepts one string argument.
  8887. */
  8888. function memoizeStringOnly(callback) {
  8889. var cache = {};
  8890. return function (string) {
  8891. if (!cache.hasOwnProperty(string)) {
  8892. cache[string] = callback.call(this, string);
  8893. }
  8894. return cache[string];
  8895. };
  8896. }
  8897. var memoizeStringOnly_1 = memoizeStringOnly;
  8898. /**
  8899. * Checks to see whether `name` and `version` satisfy `query`.
  8900. *
  8901. * @param {string} name Name of the browser, device, engine or platform
  8902. * @param {?string} version Version of the browser, engine or platform
  8903. * @param {string} query Query of form "Name [range expression]"
  8904. * @param {?function} normalizer Optional pre-processor for range expression
  8905. * @return {boolean}
  8906. */
  8907. function compare$1(name, version, query, normalizer) {
  8908. // check for exact match with no version
  8909. if (name === query) {
  8910. return true;
  8911. }
  8912. // check for non-matching names
  8913. if (!query.startsWith(name)) {
  8914. return false;
  8915. }
  8916. // full comparison with version
  8917. var range = query.slice(name.length);
  8918. if (version) {
  8919. range = normalizer ? normalizer(range) : range;
  8920. return VersionRange_1.contains(range, version);
  8921. }
  8922. return false;
  8923. }
  8924. /**
  8925. * Normalizes `version` by stripping any "NT" prefix, but only on the Windows
  8926. * platform.
  8927. *
  8928. * Mimics the stripping performed by the `UserAgentWindowsPlatform` PHP class.
  8929. *
  8930. * @param {string} version
  8931. * @return {string}
  8932. */
  8933. function normalizePlatformVersion(version) {
  8934. if (UserAgentData.platformName === 'Windows') {
  8935. return version.replace(/^\s*NT/, '');
  8936. }
  8937. return version;
  8938. }
  8939. /**
  8940. * Provides client-side access to the authoritative PHP-generated User Agent
  8941. * information supplied by the server.
  8942. */
  8943. var UserAgent = {
  8944. /**
  8945. * Check if the User Agent browser matches `query`.
  8946. *
  8947. * `query` should be a string like "Chrome" or "Chrome > 33".
  8948. *
  8949. * Valid browser names include:
  8950. *
  8951. * - ACCESS NetFront
  8952. * - AOL
  8953. * - Amazon Silk
  8954. * - Android
  8955. * - BlackBerry
  8956. * - BlackBerry PlayBook
  8957. * - Chrome
  8958. * - Chrome for iOS
  8959. * - Chrome frame
  8960. * - Facebook PHP SDK
  8961. * - Facebook for iOS
  8962. * - Firefox
  8963. * - IE
  8964. * - IE Mobile
  8965. * - Mobile Safari
  8966. * - Motorola Internet Browser
  8967. * - Nokia
  8968. * - Openwave Mobile Browser
  8969. * - Opera
  8970. * - Opera Mini
  8971. * - Opera Mobile
  8972. * - Safari
  8973. * - UIWebView
  8974. * - Unknown
  8975. * - webOS
  8976. * - etc...
  8977. *
  8978. * An authoritative list can be found in the PHP `BrowserDetector` class and
  8979. * related classes in the same file (see calls to `new UserAgentBrowser` here:
  8980. * https://fburl.com/50728104).
  8981. *
  8982. * @note Function results are memoized
  8983. *
  8984. * @param {string} query Query of the form "Name [range expression]"
  8985. * @return {boolean}
  8986. */
  8987. isBrowser: function isBrowser(query) {
  8988. return compare$1(UserAgentData.browserName, UserAgentData.browserFullVersion, query);
  8989. },
  8990. /**
  8991. * Check if the User Agent browser uses a 32 or 64 bit architecture.
  8992. *
  8993. * @note Function results are memoized
  8994. *
  8995. * @param {string} query Query of the form "32" or "64".
  8996. * @return {boolean}
  8997. */
  8998. isBrowserArchitecture: function isBrowserArchitecture(query) {
  8999. return compare$1(UserAgentData.browserArchitecture, null, query);
  9000. },
  9001. /**
  9002. * Check if the User Agent device matches `query`.
  9003. *
  9004. * `query` should be a string like "iPhone" or "iPad".
  9005. *
  9006. * Valid device names include:
  9007. *
  9008. * - Kindle
  9009. * - Kindle Fire
  9010. * - Unknown
  9011. * - iPad
  9012. * - iPhone
  9013. * - iPod
  9014. * - etc...
  9015. *
  9016. * An authoritative list can be found in the PHP `DeviceDetector` class and
  9017. * related classes in the same file (see calls to `new UserAgentDevice` here:
  9018. * https://fburl.com/50728332).
  9019. *
  9020. * @note Function results are memoized
  9021. *
  9022. * @param {string} query Query of the form "Name"
  9023. * @return {boolean}
  9024. */
  9025. isDevice: function isDevice(query) {
  9026. return compare$1(UserAgentData.deviceName, null, query);
  9027. },
  9028. /**
  9029. * Check if the User Agent rendering engine matches `query`.
  9030. *
  9031. * `query` should be a string like "WebKit" or "WebKit >= 537".
  9032. *
  9033. * Valid engine names include:
  9034. *
  9035. * - Gecko
  9036. * - Presto
  9037. * - Trident
  9038. * - WebKit
  9039. * - etc...
  9040. *
  9041. * An authoritative list can be found in the PHP `RenderingEngineDetector`
  9042. * class related classes in the same file (see calls to `new
  9043. * UserAgentRenderingEngine` here: https://fburl.com/50728617).
  9044. *
  9045. * @note Function results are memoized
  9046. *
  9047. * @param {string} query Query of the form "Name [range expression]"
  9048. * @return {boolean}
  9049. */
  9050. isEngine: function isEngine(query) {
  9051. return compare$1(UserAgentData.engineName, UserAgentData.engineVersion, query);
  9052. },
  9053. /**
  9054. * Check if the User Agent platform matches `query`.
  9055. *
  9056. * `query` should be a string like "Windows" or "iOS 5 - 6".
  9057. *
  9058. * Valid platform names include:
  9059. *
  9060. * - Android
  9061. * - BlackBerry OS
  9062. * - Java ME
  9063. * - Linux
  9064. * - Mac OS X
  9065. * - Mac OS X Calendar
  9066. * - Mac OS X Internet Account
  9067. * - Symbian
  9068. * - SymbianOS
  9069. * - Windows
  9070. * - Windows Mobile
  9071. * - Windows Phone
  9072. * - iOS
  9073. * - iOS Facebook Integration Account
  9074. * - iOS Facebook Social Sharing UI
  9075. * - webOS
  9076. * - Chrome OS
  9077. * - etc...
  9078. *
  9079. * An authoritative list can be found in the PHP `PlatformDetector` class and
  9080. * related classes in the same file (see calls to `new UserAgentPlatform`
  9081. * here: https://fburl.com/50729226).
  9082. *
  9083. * @note Function results are memoized
  9084. *
  9085. * @param {string} query Query of the form "Name [range expression]"
  9086. * @return {boolean}
  9087. */
  9088. isPlatform: function isPlatform(query) {
  9089. return compare$1(UserAgentData.platformName, UserAgentData.platformFullVersion, query, normalizePlatformVersion);
  9090. },
  9091. /**
  9092. * Check if the User Agent platform is a 32 or 64 bit architecture.
  9093. *
  9094. * @note Function results are memoized
  9095. *
  9096. * @param {string} query Query of the form "32" or "64".
  9097. * @return {boolean}
  9098. */
  9099. isPlatformArchitecture: function isPlatformArchitecture(query) {
  9100. return compare$1(UserAgentData.platformArchitecture, null, query);
  9101. }
  9102. };
  9103. var UserAgent_1 = mapObject_1(UserAgent, memoizeStringOnly_1);
  9104. function _classCallCheck$9(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9105. function _possibleConstructorReturn$6(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  9106. function _inherits$6(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  9107. // In IE, spans with <br> tags render as two newlines. By rendering a span
  9108. // with only a newline character, we can be sure to render a single line.
  9109. var useNewlineChar = UserAgent_1.isBrowser('IE <= 11');
  9110. /**
  9111. * Check whether the node should be considered a newline.
  9112. */
  9113. function isNewline(node) {
  9114. return useNewlineChar ? node.textContent === '\n' : node.tagName === 'BR';
  9115. }
  9116. /**
  9117. * Placeholder elements for empty text content.
  9118. *
  9119. * What is this `data-text` attribute, anyway? It turns out that we need to
  9120. * put an attribute on the lowest-level text node in order to preserve correct
  9121. * spellcheck handling. If the <span> is naked, Chrome and Safari may do
  9122. * bizarre things to do the DOM -- split text nodes, create extra spans, etc.
  9123. * If the <span> has an attribute, this appears not to happen.
  9124. * See http://jsfiddle.net/9khdavod/ for the failure case, and
  9125. * http://jsfiddle.net/7pg143f7/ for the fixed case.
  9126. */
  9127. var NEWLINE_A = useNewlineChar ? React.createElement(
  9128. 'span',
  9129. { key: 'A', 'data-text': 'true' },
  9130. '\n'
  9131. ) : React.createElement('br', { key: 'A', 'data-text': 'true' });
  9132. var NEWLINE_B = useNewlineChar ? React.createElement(
  9133. 'span',
  9134. { key: 'B', 'data-text': 'true' },
  9135. '\n'
  9136. ) : React.createElement('br', { key: 'B', 'data-text': 'true' });
  9137. /**
  9138. * The lowest-level component in a `DraftEditor`, the text node component
  9139. * replaces the default React text node implementation. This allows us to
  9140. * perform custom handling of newline behavior and avoid re-rendering text
  9141. * nodes with DOM state that already matches the expectations of our immutable
  9142. * editor state.
  9143. */
  9144. var DraftEditorTextNode = function (_React$Component) {
  9145. _inherits$6(DraftEditorTextNode, _React$Component);
  9146. function DraftEditorTextNode(props) {
  9147. _classCallCheck$9(this, DraftEditorTextNode);
  9148. // By flipping this flag, we also keep flipping keys which forces
  9149. // React to remount this node every time it rerenders.
  9150. var _this = _possibleConstructorReturn$6(this, _React$Component.call(this, props));
  9151. _this._forceFlag = false;
  9152. return _this;
  9153. }
  9154. DraftEditorTextNode.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  9155. var node = require$$3.findDOMNode(this);
  9156. var shouldBeNewline = nextProps.children === '';
  9157. !(node instanceof Element) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'node is not an Element') : invariant_1(false) : void 0;
  9158. if (shouldBeNewline) {
  9159. return !isNewline(node);
  9160. }
  9161. return node.textContent !== nextProps.children;
  9162. };
  9163. DraftEditorTextNode.prototype.componentDidMount = function componentDidMount() {
  9164. this._forceFlag = !this._forceFlag;
  9165. };
  9166. DraftEditorTextNode.prototype.componentDidUpdate = function componentDidUpdate() {
  9167. this._forceFlag = !this._forceFlag;
  9168. };
  9169. DraftEditorTextNode.prototype.render = function render() {
  9170. if (this.props.children === '') {
  9171. return this._forceFlag ? NEWLINE_A : NEWLINE_B;
  9172. }
  9173. return React.createElement(
  9174. 'span',
  9175. { key: this._forceFlag ? 'A' : 'B', 'data-text': 'true' },
  9176. this.props.children
  9177. );
  9178. };
  9179. return DraftEditorTextNode;
  9180. }(React.Component);
  9181. var DraftEditorTextNode_react = DraftEditorTextNode;
  9182. /**
  9183. * Copyright (c) 2013-present, Facebook, Inc.
  9184. * All rights reserved.
  9185. *
  9186. * This source code is licensed under the BSD-style license found in the
  9187. * LICENSE file in the root directory of this source tree. An additional grant
  9188. * of patent rights can be found in the PATENTS file in the same directory.
  9189. *
  9190. * @providesModule DraftJsDebugLogging
  9191. */
  9192. var DraftJsDebugLogging = {
  9193. logSelectionStateFailure: function logSelectionStateFailure() {
  9194. return null;
  9195. }
  9196. };
  9197. /**
  9198. * Copyright (c) 2013-present, Facebook, Inc.
  9199. *
  9200. * This source code is licensed under the MIT license found in the
  9201. * LICENSE file in the root directory of this source tree.
  9202. *
  9203. * @typechecks
  9204. */
  9205. /**
  9206. * @param {*} object The object to check.
  9207. * @return {boolean} Whether or not the object is a DOM node.
  9208. */
  9209. function isNode(object) {
  9210. var doc = object ? object.ownerDocument || object : document;
  9211. var defaultView = doc.defaultView || window;
  9212. return !!(object && (typeof defaultView.Node === 'function' ? object instanceof defaultView.Node : typeof object === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string'));
  9213. }
  9214. var isNode_1 = isNode;
  9215. /**
  9216. * Copyright (c) 2013-present, Facebook, Inc.
  9217. *
  9218. * This source code is licensed under the MIT license found in the
  9219. * LICENSE file in the root directory of this source tree.
  9220. *
  9221. * @typechecks
  9222. */
  9223. /**
  9224. * @param {*} object The object to check.
  9225. * @return {boolean} Whether or not the object is a DOM text node.
  9226. */
  9227. function isTextNode(object) {
  9228. return isNode_1(object) && object.nodeType == 3;
  9229. }
  9230. var isTextNode_1 = isTextNode;
  9231. /**
  9232. * Copyright (c) 2013-present, Facebook, Inc.
  9233. *
  9234. * This source code is licensed under the MIT license found in the
  9235. * LICENSE file in the root directory of this source tree.
  9236. *
  9237. *
  9238. */
  9239. /*eslint-disable no-bitwise */
  9240. /**
  9241. * Checks if a given DOM node contains or is another DOM node.
  9242. */
  9243. function containsNode(outerNode, innerNode) {
  9244. if (!outerNode || !innerNode) {
  9245. return false;
  9246. } else if (outerNode === innerNode) {
  9247. return true;
  9248. } else if (isTextNode_1(outerNode)) {
  9249. return false;
  9250. } else if (isTextNode_1(innerNode)) {
  9251. return containsNode(outerNode, innerNode.parentNode);
  9252. } else if ('contains' in outerNode) {
  9253. return outerNode.contains(innerNode);
  9254. } else if (outerNode.compareDocumentPosition) {
  9255. return !!(outerNode.compareDocumentPosition(innerNode) & 16);
  9256. } else {
  9257. return false;
  9258. }
  9259. }
  9260. var containsNode_1 = containsNode;
  9261. /**
  9262. * Copyright (c) 2013-present, Facebook, Inc.
  9263. *
  9264. * This source code is licensed under the MIT license found in the
  9265. * LICENSE file in the root directory of this source tree.
  9266. *
  9267. * @typechecks
  9268. */
  9269. /* eslint-disable fb-www/typeof-undefined */
  9270. /**
  9271. * Same as document.activeElement but wraps in a try-catch block. In IE it is
  9272. * not safe to call document.activeElement if there is nothing focused.
  9273. *
  9274. * The activeElement will be null only if the document or document body is not
  9275. * yet defined.
  9276. *
  9277. * @param {?DOMDocument} doc Defaults to current document.
  9278. * @return {?DOMElement}
  9279. */
  9280. function getActiveElement(doc) /*?DOMElement*/{
  9281. doc = doc || (typeof document !== 'undefined' ? document : undefined);
  9282. if (typeof doc === 'undefined') {
  9283. return null;
  9284. }
  9285. try {
  9286. return doc.activeElement || doc.body;
  9287. } catch (e) {
  9288. return doc.body;
  9289. }
  9290. }
  9291. var getActiveElement_1 = getActiveElement;
  9292. function getAnonymizedDOM(node, getNodeLabels) {
  9293. if (!node) {
  9294. return '[empty]';
  9295. }
  9296. var anonymized = anonymizeTextWithin(node, getNodeLabels);
  9297. if (anonymized.nodeType === Node.TEXT_NODE) {
  9298. return anonymized.textContent;
  9299. }
  9300. !(anonymized instanceof Element) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Node must be an Element if it is not a text node.') : invariant_1(false) : void 0;
  9301. return anonymized.outerHTML;
  9302. }
  9303. function anonymizeTextWithin(node, getNodeLabels) {
  9304. var labels = getNodeLabels !== undefined ? getNodeLabels(node) : [];
  9305. if (node.nodeType === Node.TEXT_NODE) {
  9306. var length = node.textContent.length;
  9307. return document.createTextNode('[text ' + length + (labels.length ? ' | ' + labels.join(', ') : '') + ']');
  9308. }
  9309. var clone = node.cloneNode();
  9310. if (clone.nodeType === 1 && labels.length) {
  9311. clone.setAttribute('data-labels', labels.join(', '));
  9312. }
  9313. var childNodes = node.childNodes;
  9314. for (var ii = 0; ii < childNodes.length; ii++) {
  9315. clone.appendChild(anonymizeTextWithin(childNodes[ii], getNodeLabels));
  9316. }
  9317. return clone;
  9318. }
  9319. function getAnonymizedEditorDOM(node, getNodeLabels) {
  9320. // grabbing the DOM content of the Draft editor
  9321. var currentNode = node;
  9322. while (currentNode) {
  9323. if (currentNode instanceof Element && currentNode.hasAttribute('contenteditable')) {
  9324. // found the Draft editor container
  9325. return getAnonymizedDOM(currentNode, getNodeLabels);
  9326. } else {
  9327. currentNode = currentNode.parentNode;
  9328. }
  9329. }
  9330. return 'Could not find contentEditable parent of node';
  9331. }
  9332. function getNodeLength(node) {
  9333. return node.nodeValue === null ? node.childNodes.length : node.nodeValue.length;
  9334. }
  9335. /**
  9336. * In modern non-IE browsers, we can support both forward and backward
  9337. * selections.
  9338. *
  9339. * Note: IE10+ supports the Selection object, but it does not support
  9340. * the `extend` method, which means that even in modern IE, it's not possible
  9341. * to programatically create a backward selection. Thus, for all IE
  9342. * versions, we use the old IE API to create our selections.
  9343. */
  9344. function setDraftEditorSelection(selectionState, node, blockKey, nodeStart, nodeEnd) {
  9345. // It's possible that the editor has been removed from the DOM but
  9346. // our selection code doesn't know it yet. Forcing selection in
  9347. // this case may lead to errors, so just bail now.
  9348. if (!containsNode_1(document.documentElement, node)) {
  9349. return;
  9350. }
  9351. var selection = commonjsGlobal.getSelection();
  9352. var anchorKey = selectionState.getAnchorKey();
  9353. var anchorOffset = selectionState.getAnchorOffset();
  9354. var focusKey = selectionState.getFocusKey();
  9355. var focusOffset = selectionState.getFocusOffset();
  9356. var isBackward = selectionState.getIsBackward();
  9357. // IE doesn't support backward selection. Swap key/offset pairs.
  9358. if (!selection.extend && isBackward) {
  9359. var tempKey = anchorKey;
  9360. var tempOffset = anchorOffset;
  9361. anchorKey = focusKey;
  9362. anchorOffset = focusOffset;
  9363. focusKey = tempKey;
  9364. focusOffset = tempOffset;
  9365. isBackward = false;
  9366. }
  9367. var hasAnchor = anchorKey === blockKey && nodeStart <= anchorOffset && nodeEnd >= anchorOffset;
  9368. var hasFocus = focusKey === blockKey && nodeStart <= focusOffset && nodeEnd >= focusOffset;
  9369. // If the selection is entirely bound within this node, set the selection
  9370. // and be done.
  9371. if (hasAnchor && hasFocus) {
  9372. selection.removeAllRanges();
  9373. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  9374. addFocusToSelection(selection, node, focusOffset - nodeStart, selectionState);
  9375. return;
  9376. }
  9377. if (!isBackward) {
  9378. // If the anchor is within this node, set the range start.
  9379. if (hasAnchor) {
  9380. selection.removeAllRanges();
  9381. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  9382. }
  9383. // If the focus is within this node, we can assume that we have
  9384. // already set the appropriate start range on the selection, and
  9385. // can simply extend the selection.
  9386. if (hasFocus) {
  9387. addFocusToSelection(selection, node, focusOffset - nodeStart, selectionState);
  9388. }
  9389. } else {
  9390. // If this node has the focus, set the selection range to be a
  9391. // collapsed range beginning here. Later, when we encounter the anchor,
  9392. // we'll use this information to extend the selection.
  9393. if (hasFocus) {
  9394. selection.removeAllRanges();
  9395. addPointToSelection(selection, node, focusOffset - nodeStart, selectionState);
  9396. }
  9397. // If this node has the anchor, we may assume that the correct
  9398. // focus information is already stored on the selection object.
  9399. // We keep track of it, reset the selection range, and extend it
  9400. // back to the focus point.
  9401. if (hasAnchor) {
  9402. var storedFocusNode = selection.focusNode;
  9403. var storedFocusOffset = selection.focusOffset;
  9404. selection.removeAllRanges();
  9405. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  9406. addFocusToSelection(selection, storedFocusNode, storedFocusOffset, selectionState);
  9407. }
  9408. }
  9409. }
  9410. /**
  9411. * Extend selection towards focus point.
  9412. */
  9413. function addFocusToSelection(selection, node, offset, selectionState) {
  9414. var activeElement = getActiveElement_1();
  9415. if (selection.extend && containsNode_1(activeElement, node)) {
  9416. // If `extend` is called while another element has focus, an error is
  9417. // thrown. We therefore disable `extend` if the active element is somewhere
  9418. // other than the node we are selecting. This should only occur in Firefox,
  9419. // since it is the only browser to support multiple selections.
  9420. // See https://bugzilla.mozilla.org/show_bug.cgi?id=921444.
  9421. // logging to catch bug that is being reported in t16250795
  9422. if (offset > getNodeLength(node)) {
  9423. // the call to 'selection.extend' is about to throw
  9424. DraftJsDebugLogging.logSelectionStateFailure({
  9425. anonymizedDom: getAnonymizedEditorDOM(node),
  9426. extraParams: JSON.stringify({ offset: offset }),
  9427. selectionState: JSON.stringify(selectionState.toJS())
  9428. });
  9429. }
  9430. // logging to catch bug that is being reported in t18110632
  9431. var nodeWasFocus = node === selection.focusNode;
  9432. try {
  9433. selection.extend(node, offset);
  9434. } catch (e) {
  9435. DraftJsDebugLogging.logSelectionStateFailure({
  9436. anonymizedDom: getAnonymizedEditorDOM(node, function (n) {
  9437. var labels = [];
  9438. if (n === activeElement) {
  9439. labels.push('active element');
  9440. }
  9441. if (n === selection.anchorNode) {
  9442. labels.push('selection anchor node');
  9443. }
  9444. if (n === selection.focusNode) {
  9445. labels.push('selection focus node');
  9446. }
  9447. return labels;
  9448. }),
  9449. extraParams: JSON.stringify({
  9450. activeElementName: activeElement ? activeElement.nodeName : null,
  9451. nodeIsFocus: node === selection.focusNode,
  9452. nodeWasFocus: nodeWasFocus,
  9453. selectionRangeCount: selection.rangeCount,
  9454. selectionAnchorNodeName: selection.anchorNode ? selection.anchorNode.nodeName : null,
  9455. selectionAnchorOffset: selection.anchorOffset,
  9456. selectionFocusNodeName: selection.focusNode ? selection.focusNode.nodeName : null,
  9457. selectionFocusOffset: selection.focusOffset,
  9458. message: e ? '' + e : null,
  9459. offset: offset
  9460. }, null, 2),
  9461. selectionState: JSON.stringify(selectionState.toJS(), null, 2)
  9462. });
  9463. // allow the error to be thrown -
  9464. // better than continuing in a broken state
  9465. throw e;
  9466. }
  9467. } else {
  9468. // IE doesn't support extend. This will mean no backward selection.
  9469. // Extract the existing selection range and add focus to it.
  9470. // Additionally, clone the selection range. IE11 throws an
  9471. // InvalidStateError when attempting to access selection properties
  9472. // after the range is detached.
  9473. var range = selection.getRangeAt(0);
  9474. range.setEnd(node, offset);
  9475. selection.addRange(range.cloneRange());
  9476. }
  9477. }
  9478. function addPointToSelection(selection, node, offset, selectionState) {
  9479. var range = document.createRange();
  9480. // logging to catch bug that is being reported in t16250795
  9481. if (offset > getNodeLength(node)) {
  9482. // in this case we know that the call to 'range.setStart' is about to throw
  9483. DraftJsDebugLogging.logSelectionStateFailure({
  9484. anonymizedDom: getAnonymizedEditorDOM(node),
  9485. extraParams: JSON.stringify({ offset: offset }),
  9486. selectionState: JSON.stringify(selectionState.toJS())
  9487. });
  9488. }
  9489. range.setStart(node, offset);
  9490. selection.addRange(range);
  9491. }
  9492. var setDraftEditorSelection_1 = setDraftEditorSelection;
  9493. function _classCallCheck$a(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9494. function _possibleConstructorReturn$7(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  9495. function _inherits$7(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  9496. /**
  9497. * All leaf nodes in the editor are spans with single text nodes. Leaf
  9498. * elements are styled based on the merging of an optional custom style map
  9499. * and a default style map.
  9500. *
  9501. * `DraftEditorLeaf` also provides a wrapper for calling into the imperative
  9502. * DOM Selection API. In this way, top-level components can declaratively
  9503. * maintain the selection state.
  9504. */
  9505. var DraftEditorLeaf = function (_React$Component) {
  9506. _inherits$7(DraftEditorLeaf, _React$Component);
  9507. function DraftEditorLeaf() {
  9508. _classCallCheck$a(this, DraftEditorLeaf);
  9509. return _possibleConstructorReturn$7(this, _React$Component.apply(this, arguments));
  9510. }
  9511. DraftEditorLeaf.prototype._setSelection = function _setSelection() {
  9512. var selection = this.props.selection;
  9513. // If selection state is irrelevant to the parent block, no-op.
  9514. if (selection == null || !selection.getHasFocus()) {
  9515. return;
  9516. }
  9517. var _props = this.props,
  9518. block = _props.block,
  9519. start = _props.start,
  9520. text = _props.text;
  9521. var blockKey = block.getKey();
  9522. var end = start + text.length;
  9523. if (!selection.hasEdgeWithin(blockKey, start, end)) {
  9524. return;
  9525. }
  9526. // Determine the appropriate target node for selection. If the child
  9527. // is not a text node, it is a <br /> spacer. In this case, use the
  9528. // <span> itself as the selection target.
  9529. var node = require$$3.findDOMNode(this);
  9530. !node ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing node') : invariant_1(false) : void 0;
  9531. var child = node.firstChild;
  9532. !child ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing child') : invariant_1(false) : void 0;
  9533. var targetNode = void 0;
  9534. if (child.nodeType === Node.TEXT_NODE) {
  9535. targetNode = child;
  9536. } else if (child.tagName === 'BR') {
  9537. targetNode = node;
  9538. } else {
  9539. targetNode = child.firstChild;
  9540. !targetNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing targetNode') : invariant_1(false) : void 0;
  9541. }
  9542. setDraftEditorSelection_1(selection, targetNode, blockKey, start, end);
  9543. };
  9544. /**
  9545. * By making individual leaf instances aware of their context within
  9546. * the text of the editor, we can set our selection range more
  9547. * easily than we could in the non-React world.
  9548. *
  9549. * Note that this depends on our maintaining tight control over the
  9550. * DOM structure of the DraftEditor component. If leaves had multiple
  9551. * text nodes, this would be harder.
  9552. */
  9553. DraftEditorLeaf.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  9554. var leafNode = require$$3.findDOMNode(this.leaf);
  9555. !leafNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing leafNode') : invariant_1(false) : void 0;
  9556. return leafNode.textContent !== nextProps.text || nextProps.styleSet !== this.props.styleSet || nextProps.forceSelection;
  9557. };
  9558. DraftEditorLeaf.prototype.componentDidUpdate = function componentDidUpdate() {
  9559. this._setSelection();
  9560. };
  9561. DraftEditorLeaf.prototype.componentDidMount = function componentDidMount() {
  9562. this._setSelection();
  9563. };
  9564. DraftEditorLeaf.prototype.render = function render() {
  9565. var _this2 = this;
  9566. var block = this.props.block;
  9567. var text = this.props.text;
  9568. // If the leaf is at the end of its block and ends in a soft newline, append
  9569. // an extra line feed character. Browsers collapse trailing newline
  9570. // characters, which leaves the cursor in the wrong place after a
  9571. // shift+enter. The extra character repairs this.
  9572. if (text.endsWith('\n') && this.props.isLast) {
  9573. text += '\n';
  9574. }
  9575. var _props2 = this.props,
  9576. customStyleMap = _props2.customStyleMap,
  9577. customStyleFn = _props2.customStyleFn,
  9578. offsetKey = _props2.offsetKey,
  9579. styleSet = _props2.styleSet;
  9580. var styleObj = styleSet.reduce(function (map, styleName) {
  9581. var mergedStyles = {};
  9582. var style = customStyleMap[styleName];
  9583. if (style !== undefined && map.textDecoration !== style.textDecoration) {
  9584. // .trim() is necessary for IE9/10/11 and Edge
  9585. mergedStyles.textDecoration = [map.textDecoration, style.textDecoration].join(' ').trim();
  9586. }
  9587. return objectAssign(map, style, mergedStyles);
  9588. }, {});
  9589. if (customStyleFn) {
  9590. var newStyles = customStyleFn(styleSet, block);
  9591. styleObj = objectAssign(styleObj, newStyles);
  9592. }
  9593. return React.createElement(
  9594. 'span',
  9595. {
  9596. 'data-offset-key': offsetKey,
  9597. ref: function ref(_ref) {
  9598. return _this2.leaf = _ref;
  9599. },
  9600. style: styleObj },
  9601. React.createElement(
  9602. DraftEditorTextNode_react,
  9603. null,
  9604. text
  9605. )
  9606. );
  9607. };
  9608. return DraftEditorLeaf;
  9609. }(React.Component);
  9610. var DraftEditorLeaf_react = DraftEditorLeaf;
  9611. /**
  9612. * Copyright (c) 2013-present, Facebook, Inc.
  9613. * All rights reserved.
  9614. *
  9615. * This source code is licensed under the BSD-style license found in the
  9616. * LICENSE file in the root directory of this source tree. An additional grant
  9617. * of patent rights can be found in the PATENTS file in the same directory.
  9618. *
  9619. * @providesModule DraftOffsetKey
  9620. * @format
  9621. *
  9622. */
  9623. var KEY_DELIMITER = '-';
  9624. var DraftOffsetKey = {
  9625. encode: function encode(blockKey, decoratorKey, leafKey) {
  9626. return blockKey + KEY_DELIMITER + decoratorKey + KEY_DELIMITER + leafKey;
  9627. },
  9628. decode: function decode(offsetKey) {
  9629. var _offsetKey$split = offsetKey.split(KEY_DELIMITER),
  9630. blockKey = _offsetKey$split[0],
  9631. decoratorKey = _offsetKey$split[1],
  9632. leafKey = _offsetKey$split[2];
  9633. return {
  9634. blockKey: blockKey,
  9635. decoratorKey: parseInt(decoratorKey, 10),
  9636. leafKey: parseInt(leafKey, 10)
  9637. };
  9638. }
  9639. };
  9640. var DraftOffsetKey_1 = DraftOffsetKey;
  9641. /**
  9642. * Copyright (c) 2013-present, Facebook, Inc.
  9643. *
  9644. * This source code is licensed under the MIT license found in the
  9645. * LICENSE file in the root directory of this source tree.
  9646. *
  9647. */
  9648. /**
  9649. * @param {DOMElement} element
  9650. * @param {DOMDocument} doc
  9651. * @return {boolean}
  9652. */
  9653. function _isViewportScrollElement(element, doc) {
  9654. return !!doc && (element === doc.documentElement || element === doc.body);
  9655. }
  9656. /**
  9657. * Scroll Module. This class contains 4 simple static functions
  9658. * to be used to access Element.scrollTop/scrollLeft properties.
  9659. * To solve the inconsistencies between browsers when either
  9660. * document.body or document.documentElement is supplied,
  9661. * below logic will be used to alleviate the issue:
  9662. *
  9663. * 1. If 'element' is either 'document.body' or 'document.documentElement,
  9664. * get whichever element's 'scroll{Top,Left}' is larger.
  9665. * 2. If 'element' is either 'document.body' or 'document.documentElement',
  9666. * set the 'scroll{Top,Left}' on both elements.
  9667. */
  9668. var Scroll = {
  9669. /**
  9670. * @param {DOMElement} element
  9671. * @return {number}
  9672. */
  9673. getTop: function getTop(element) {
  9674. var doc = element.ownerDocument;
  9675. return _isViewportScrollElement(element, doc) ?
  9676. // In practice, they will either both have the same value,
  9677. // or one will be zero and the other will be the scroll position
  9678. // of the viewport. So we can use `X || Y` instead of `Math.max(X, Y)`
  9679. doc.body.scrollTop || doc.documentElement.scrollTop : element.scrollTop;
  9680. },
  9681. /**
  9682. * @param {DOMElement} element
  9683. * @param {number} newTop
  9684. */
  9685. setTop: function setTop(element, newTop) {
  9686. var doc = element.ownerDocument;
  9687. if (_isViewportScrollElement(element, doc)) {
  9688. doc.body.scrollTop = doc.documentElement.scrollTop = newTop;
  9689. } else {
  9690. element.scrollTop = newTop;
  9691. }
  9692. },
  9693. /**
  9694. * @param {DOMElement} element
  9695. * @return {number}
  9696. */
  9697. getLeft: function getLeft(element) {
  9698. var doc = element.ownerDocument;
  9699. return _isViewportScrollElement(element, doc) ? doc.body.scrollLeft || doc.documentElement.scrollLeft : element.scrollLeft;
  9700. },
  9701. /**
  9702. * @param {DOMElement} element
  9703. * @param {number} newLeft
  9704. */
  9705. setLeft: function setLeft(element, newLeft) {
  9706. var doc = element.ownerDocument;
  9707. if (_isViewportScrollElement(element, doc)) {
  9708. doc.body.scrollLeft = doc.documentElement.scrollLeft = newLeft;
  9709. } else {
  9710. element.scrollLeft = newLeft;
  9711. }
  9712. }
  9713. };
  9714. var Scroll_1 = Scroll;
  9715. /**
  9716. * Copyright (c) 2013-present, Facebook, Inc.
  9717. *
  9718. * This source code is licensed under the MIT license found in the
  9719. * LICENSE file in the root directory of this source tree.
  9720. *
  9721. * @typechecks
  9722. */
  9723. var _hyphenPattern = /-(.)/g;
  9724. /**
  9725. * Camelcases a hyphenated string, for example:
  9726. *
  9727. * > camelize('background-color')
  9728. * < "backgroundColor"
  9729. *
  9730. * @param {string} string
  9731. * @return {string}
  9732. */
  9733. function camelize(string) {
  9734. return string.replace(_hyphenPattern, function (_, character) {
  9735. return character.toUpperCase();
  9736. });
  9737. }
  9738. var camelize_1 = camelize;
  9739. /**
  9740. * Copyright (c) 2013-present, Facebook, Inc.
  9741. *
  9742. * This source code is licensed under the MIT license found in the
  9743. * LICENSE file in the root directory of this source tree.
  9744. *
  9745. * @typechecks
  9746. */
  9747. var _uppercasePattern = /([A-Z])/g;
  9748. /**
  9749. * Hyphenates a camelcased string, for example:
  9750. *
  9751. * > hyphenate('backgroundColor')
  9752. * < "background-color"
  9753. *
  9754. * For CSS style names, use `hyphenateStyleName` instead which works properly
  9755. * with all vendor prefixes, including `ms`.
  9756. *
  9757. * @param {string} string
  9758. * @return {string}
  9759. */
  9760. function hyphenate(string) {
  9761. return string.replace(_uppercasePattern, '-$1').toLowerCase();
  9762. }
  9763. var hyphenate_1 = hyphenate;
  9764. /**
  9765. * Copyright (c) 2013-present, Facebook, Inc.
  9766. *
  9767. * This source code is licensed under the MIT license found in the
  9768. * LICENSE file in the root directory of this source tree.
  9769. *
  9770. * @typechecks
  9771. */
  9772. function asString(value) /*?string*/{
  9773. return value == null ? value : String(value);
  9774. }
  9775. function getStyleProperty( /*DOMNode*/node, /*string*/name) /*?string*/{
  9776. var computedStyle = void 0;
  9777. // W3C Standard
  9778. if (window.getComputedStyle) {
  9779. // In certain cases such as within an iframe in FF3, this returns null.
  9780. computedStyle = window.getComputedStyle(node, null);
  9781. if (computedStyle) {
  9782. return asString(computedStyle.getPropertyValue(hyphenate_1(name)));
  9783. }
  9784. }
  9785. // Safari
  9786. if (document.defaultView && document.defaultView.getComputedStyle) {
  9787. computedStyle = document.defaultView.getComputedStyle(node, null);
  9788. // A Safari bug causes this to return null for `display: none` elements.
  9789. if (computedStyle) {
  9790. return asString(computedStyle.getPropertyValue(hyphenate_1(name)));
  9791. }
  9792. if (name === 'display') {
  9793. return 'none';
  9794. }
  9795. }
  9796. // Internet Explorer
  9797. if (node.currentStyle) {
  9798. if (name === 'float') {
  9799. return asString(node.currentStyle.cssFloat || node.currentStyle.styleFloat);
  9800. }
  9801. return asString(node.currentStyle[camelize_1(name)]);
  9802. }
  9803. return asString(node.style && node.style[camelize_1(name)]);
  9804. }
  9805. var getStyleProperty_1 = getStyleProperty;
  9806. /**
  9807. * Copyright (c) 2013-present, Facebook, Inc.
  9808. *
  9809. * This source code is licensed under the MIT license found in the
  9810. * LICENSE file in the root directory of this source tree.
  9811. *
  9812. * @typechecks
  9813. */
  9814. /**
  9815. * @param {DOMNode} element [description]
  9816. * @param {string} name Overflow style property name.
  9817. * @return {boolean} True if the supplied ndoe is scrollable.
  9818. */
  9819. function _isNodeScrollable(element, name) {
  9820. var overflow = Style.get(element, name);
  9821. return overflow === 'auto' || overflow === 'scroll';
  9822. }
  9823. /**
  9824. * Utilities for querying and mutating style properties.
  9825. */
  9826. var Style = {
  9827. /**
  9828. * Gets the style property for the supplied node. This will return either the
  9829. * computed style, if available, or the declared style.
  9830. *
  9831. * @param {DOMNode} node
  9832. * @param {string} name Style property name.
  9833. * @return {?string} Style property value.
  9834. */
  9835. get: getStyleProperty_1,
  9836. /**
  9837. * Determines the nearest ancestor of a node that is scrollable.
  9838. *
  9839. * NOTE: This can be expensive if used repeatedly or on a node nested deeply.
  9840. *
  9841. * @param {?DOMNode} node Node from which to start searching.
  9842. * @return {?DOMWindow|DOMElement} Scroll parent of the supplied node.
  9843. */
  9844. getScrollParent: function getScrollParent(node) {
  9845. if (!node) {
  9846. return null;
  9847. }
  9848. var ownerDocument = node.ownerDocument;
  9849. while (node && node !== ownerDocument.body) {
  9850. if (_isNodeScrollable(node, 'overflow') || _isNodeScrollable(node, 'overflowY') || _isNodeScrollable(node, 'overflowX')) {
  9851. return node;
  9852. }
  9853. node = node.parentNode;
  9854. }
  9855. return ownerDocument.defaultView || ownerDocument.parentWindow;
  9856. }
  9857. };
  9858. var Style_1 = Style;
  9859. /**
  9860. * Copyright (c) 2013-present, Facebook, Inc.
  9861. *
  9862. * This source code is licensed under the MIT license found in the
  9863. * LICENSE file in the root directory of this source tree.
  9864. *
  9865. * @typechecks
  9866. */
  9867. /**
  9868. * Gets an element's bounding rect in pixels relative to the viewport.
  9869. *
  9870. * @param {DOMElement} elem
  9871. * @return {object}
  9872. */
  9873. function getElementRect(elem) {
  9874. var docElem = elem.ownerDocument.documentElement;
  9875. // FF 2, Safari 3 and Opera 9.5- do not support getBoundingClientRect().
  9876. // IE9- will throw if the element is not in the document.
  9877. if (!('getBoundingClientRect' in elem) || !containsNode_1(docElem, elem)) {
  9878. return {
  9879. left: 0,
  9880. right: 0,
  9881. top: 0,
  9882. bottom: 0
  9883. };
  9884. }
  9885. // Subtracts clientTop/Left because IE8- added a 2px border to the
  9886. // <html> element (see http://fburl.com/1493213). IE 7 in
  9887. // Quicksmode does not report clientLeft/clientTop so there
  9888. // will be an unaccounted offset of 2px when in quirksmode
  9889. var rect = elem.getBoundingClientRect();
  9890. return {
  9891. left: Math.round(rect.left) - docElem.clientLeft,
  9892. right: Math.round(rect.right) - docElem.clientLeft,
  9893. top: Math.round(rect.top) - docElem.clientTop,
  9894. bottom: Math.round(rect.bottom) - docElem.clientTop
  9895. };
  9896. }
  9897. var getElementRect_1 = getElementRect;
  9898. /**
  9899. * Copyright (c) 2013-present, Facebook, Inc.
  9900. *
  9901. * This source code is licensed under the MIT license found in the
  9902. * LICENSE file in the root directory of this source tree.
  9903. *
  9904. * @typechecks
  9905. */
  9906. /**
  9907. * Gets an element's position in pixels relative to the viewport. The returned
  9908. * object represents the position of the element's top left corner.
  9909. *
  9910. * @param {DOMElement} element
  9911. * @return {object}
  9912. */
  9913. function getElementPosition(element) {
  9914. var rect = getElementRect_1(element);
  9915. return {
  9916. x: rect.left,
  9917. y: rect.top,
  9918. width: rect.right - rect.left,
  9919. height: rect.bottom - rect.top
  9920. };
  9921. }
  9922. var getElementPosition_1 = getElementPosition;
  9923. /**
  9924. * Copyright (c) 2013-present, Facebook, Inc.
  9925. *
  9926. * This source code is licensed under the MIT license found in the
  9927. * LICENSE file in the root directory of this source tree.
  9928. *
  9929. * @typechecks
  9930. */
  9931. var isWebkit = typeof navigator !== 'undefined' && navigator.userAgent.indexOf('AppleWebKit') > -1;
  9932. /**
  9933. * Gets the element with the document scroll properties such as `scrollLeft` and
  9934. * `scrollHeight`. This may differ across different browsers.
  9935. *
  9936. * NOTE: The return value can be null if the DOM is not yet ready.
  9937. *
  9938. * @param {?DOMDocument} doc Defaults to current document.
  9939. * @return {?DOMElement}
  9940. */
  9941. function getDocumentScrollElement(doc) {
  9942. doc = doc || document;
  9943. if (doc.scrollingElement) {
  9944. return doc.scrollingElement;
  9945. }
  9946. return !isWebkit && doc.compatMode === 'CSS1Compat' ? doc.documentElement : doc.body;
  9947. }
  9948. var getDocumentScrollElement_1 = getDocumentScrollElement;
  9949. /**
  9950. * Copyright (c) 2013-present, Facebook, Inc.
  9951. *
  9952. * This source code is licensed under the MIT license found in the
  9953. * LICENSE file in the root directory of this source tree.
  9954. *
  9955. * @typechecks
  9956. */
  9957. /**
  9958. * Gets the scroll position of the supplied element or window.
  9959. *
  9960. * The return values are unbounded, unlike `getScrollPosition`. This means they
  9961. * may be negative or exceed the element boundaries (which is possible using
  9962. * inertial scrolling).
  9963. *
  9964. * @param {DOMWindow|DOMElement} scrollable
  9965. * @return {object} Map with `x` and `y` keys.
  9966. */
  9967. function getUnboundedScrollPosition(scrollable) {
  9968. if (scrollable.Window && scrollable instanceof scrollable.Window) {
  9969. return {
  9970. x: scrollable.pageXOffset || scrollable.document.documentElement.scrollLeft,
  9971. y: scrollable.pageYOffset || scrollable.document.documentElement.scrollTop
  9972. };
  9973. }
  9974. return {
  9975. x: scrollable.scrollLeft,
  9976. y: scrollable.scrollTop
  9977. };
  9978. }
  9979. var getUnboundedScrollPosition_1 = getUnboundedScrollPosition;
  9980. /**
  9981. * Gets the scroll position of the supplied element or window.
  9982. *
  9983. * The return values are bounded. This means that if the scroll position is
  9984. * negative or exceeds the element boundaries (which is possible using inertial
  9985. * scrolling), you will get zero or the maximum scroll position, respectively.
  9986. *
  9987. * If you need the unbound scroll position, use `getUnboundedScrollPosition`.
  9988. *
  9989. * @param {DOMWindow|DOMElement} scrollable
  9990. * @return {object} Map with `x` and `y` keys.
  9991. */
  9992. function getScrollPosition(scrollable) {
  9993. var documentScrollElement = getDocumentScrollElement_1(scrollable.ownerDocument || scrollable.document);
  9994. if (scrollable.Window && scrollable instanceof scrollable.Window) {
  9995. scrollable = documentScrollElement;
  9996. }
  9997. var scrollPosition = getUnboundedScrollPosition_1(scrollable);
  9998. var viewport = scrollable === documentScrollElement ? scrollable.ownerDocument.documentElement : scrollable;
  9999. var xMax = scrollable.scrollWidth - viewport.clientWidth;
  10000. var yMax = scrollable.scrollHeight - viewport.clientHeight;
  10001. scrollPosition.x = Math.max(0, Math.min(scrollPosition.x, xMax));
  10002. scrollPosition.y = Math.max(0, Math.min(scrollPosition.y, yMax));
  10003. return scrollPosition;
  10004. }
  10005. var getScrollPosition_1 = getScrollPosition;
  10006. function getViewportWidth() {
  10007. var width = void 0;
  10008. if (document.documentElement) {
  10009. width = document.documentElement.clientWidth;
  10010. }
  10011. if (!width && document.body) {
  10012. width = document.body.clientWidth;
  10013. }
  10014. return width || 0;
  10015. } /**
  10016. * Copyright (c) 2013-present, Facebook, Inc.
  10017. *
  10018. * This source code is licensed under the MIT license found in the
  10019. * LICENSE file in the root directory of this source tree.
  10020. *
  10021. *
  10022. * @typechecks
  10023. */
  10024. function getViewportHeight() {
  10025. var height = void 0;
  10026. if (document.documentElement) {
  10027. height = document.documentElement.clientHeight;
  10028. }
  10029. if (!height && document.body) {
  10030. height = document.body.clientHeight;
  10031. }
  10032. return height || 0;
  10033. }
  10034. /**
  10035. * Gets the viewport dimensions including any scrollbars.
  10036. */
  10037. function getViewportDimensions() {
  10038. return {
  10039. width: window.innerWidth || getViewportWidth(),
  10040. height: window.innerHeight || getViewportHeight()
  10041. };
  10042. }
  10043. /**
  10044. * Gets the viewport dimensions excluding any scrollbars.
  10045. */
  10046. getViewportDimensions.withoutScrollbars = function () {
  10047. return {
  10048. width: getViewportWidth(),
  10049. height: getViewportHeight()
  10050. };
  10051. };
  10052. var getViewportDimensions_1 = getViewportDimensions;
  10053. var _extends$2 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  10054. function _classCallCheck$b(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10055. function _possibleConstructorReturn$8(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  10056. function _inherits$8(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  10057. var SCROLL_BUFFER = 10;
  10058. /**
  10059. * Return whether a block overlaps with either edge of the `SelectionState`.
  10060. */
  10061. var isBlockOnSelectionEdge = function isBlockOnSelectionEdge(selection, key) {
  10062. return selection.getAnchorKey() === key || selection.getFocusKey() === key;
  10063. };
  10064. /**
  10065. * The default block renderer for a `DraftEditor` component.
  10066. *
  10067. * A `DraftEditorBlock` is able to render a given `ContentBlock` to its
  10068. * appropriate decorator and inline style components.
  10069. */
  10070. var DraftEditorBlock = function (_React$Component) {
  10071. _inherits$8(DraftEditorBlock, _React$Component);
  10072. function DraftEditorBlock() {
  10073. _classCallCheck$b(this, DraftEditorBlock);
  10074. return _possibleConstructorReturn$8(this, _React$Component.apply(this, arguments));
  10075. }
  10076. DraftEditorBlock.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  10077. return this.props.block !== nextProps.block || this.props.tree !== nextProps.tree || this.props.direction !== nextProps.direction || isBlockOnSelectionEdge(nextProps.selection, nextProps.block.getKey()) && nextProps.forceSelection;
  10078. };
  10079. /**
  10080. * When a block is mounted and overlaps the selection state, we need to make
  10081. * sure that the cursor is visible to match native behavior. This may not
  10082. * be the case if the user has pressed `RETURN` or pasted some content, since
  10083. * programatically creating these new blocks and setting the DOM selection
  10084. * will miss out on the browser natively scrolling to that position.
  10085. *
  10086. * To replicate native behavior, if the block overlaps the selection state
  10087. * on mount, force the scroll position. Check the scroll state of the scroll
  10088. * parent, and adjust it to align the entire block to the bottom of the
  10089. * scroll parent.
  10090. */
  10091. DraftEditorBlock.prototype.componentDidMount = function componentDidMount() {
  10092. var selection = this.props.selection;
  10093. var endKey = selection.getEndKey();
  10094. if (!selection.getHasFocus() || endKey !== this.props.block.getKey()) {
  10095. return;
  10096. }
  10097. var blockNode = require$$3.findDOMNode(this);
  10098. var scrollParent = Style_1.getScrollParent(blockNode);
  10099. var scrollPosition = getScrollPosition_1(scrollParent);
  10100. var scrollDelta = void 0;
  10101. if (scrollParent === window) {
  10102. var nodePosition = getElementPosition_1(blockNode);
  10103. var nodeBottom = nodePosition.y + nodePosition.height;
  10104. var viewportHeight = getViewportDimensions_1().height;
  10105. scrollDelta = nodeBottom - viewportHeight;
  10106. if (scrollDelta > 0) {
  10107. window.scrollTo(scrollPosition.x, scrollPosition.y + scrollDelta + SCROLL_BUFFER);
  10108. }
  10109. } else {
  10110. !(blockNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'blockNode is not an HTMLElement') : invariant_1(false) : void 0;
  10111. var blockBottom = blockNode.offsetHeight + blockNode.offsetTop;
  10112. var scrollBottom = scrollParent.offsetHeight + scrollPosition.y;
  10113. scrollDelta = blockBottom - scrollBottom;
  10114. if (scrollDelta > 0) {
  10115. Scroll_1.setTop(scrollParent, Scroll_1.getTop(scrollParent) + scrollDelta + SCROLL_BUFFER);
  10116. }
  10117. }
  10118. };
  10119. DraftEditorBlock.prototype._renderChildren = function _renderChildren() {
  10120. var _this2 = this;
  10121. var block = this.props.block;
  10122. var blockKey = block.getKey();
  10123. var text = block.getText();
  10124. var lastLeafSet = this.props.tree.size - 1;
  10125. var hasSelection = isBlockOnSelectionEdge(this.props.selection, blockKey);
  10126. return this.props.tree.map(function (leafSet, ii) {
  10127. var leavesForLeafSet = leafSet.get('leaves');
  10128. var lastLeaf = leavesForLeafSet.size - 1;
  10129. var leaves = leavesForLeafSet.map(function (leaf, jj) {
  10130. var offsetKey = DraftOffsetKey_1.encode(blockKey, ii, jj);
  10131. var start = leaf.get('start');
  10132. var end = leaf.get('end');
  10133. return React.createElement(DraftEditorLeaf_react, {
  10134. key: offsetKey,
  10135. offsetKey: offsetKey,
  10136. block: block,
  10137. start: start,
  10138. selection: hasSelection ? _this2.props.selection : null,
  10139. forceSelection: _this2.props.forceSelection,
  10140. text: text.slice(start, end),
  10141. styleSet: block.getInlineStyleAt(start),
  10142. customStyleMap: _this2.props.customStyleMap,
  10143. customStyleFn: _this2.props.customStyleFn,
  10144. isLast: ii === lastLeafSet && jj === lastLeaf
  10145. });
  10146. }).toArray();
  10147. var decoratorKey = leafSet.get('decoratorKey');
  10148. if (decoratorKey == null) {
  10149. return leaves;
  10150. }
  10151. if (!_this2.props.decorator) {
  10152. return leaves;
  10153. }
  10154. var decorator = nullthrows_1(_this2.props.decorator);
  10155. var DecoratorComponent = decorator.getComponentForKey(decoratorKey);
  10156. if (!DecoratorComponent) {
  10157. return leaves;
  10158. }
  10159. var decoratorProps = decorator.getPropsForKey(decoratorKey);
  10160. var decoratorOffsetKey = DraftOffsetKey_1.encode(blockKey, ii, 0);
  10161. var decoratedText = text.slice(leavesForLeafSet.first().get('start'), leavesForLeafSet.last().get('end'));
  10162. // Resetting dir to the same value on a child node makes Chrome/Firefox
  10163. // confused on cursor movement. See http://jsfiddle.net/d157kLck/3/
  10164. var dir = UnicodeBidiDirection_1.getHTMLDirIfDifferent(UnicodeBidi_1.getDirection(decoratedText), _this2.props.direction);
  10165. return React.createElement(
  10166. DecoratorComponent,
  10167. _extends$2({}, decoratorProps, {
  10168. contentState: _this2.props.contentState,
  10169. decoratedText: decoratedText,
  10170. dir: dir,
  10171. key: decoratorOffsetKey,
  10172. entityKey: block.getEntityAt(leafSet.get('start')),
  10173. offsetKey: decoratorOffsetKey }),
  10174. leaves
  10175. );
  10176. }).toArray();
  10177. };
  10178. DraftEditorBlock.prototype.render = function render() {
  10179. var _props = this.props,
  10180. direction = _props.direction,
  10181. offsetKey = _props.offsetKey;
  10182. var className = cx_1({
  10183. 'public/DraftStyleDefault/block': true,
  10184. 'public/DraftStyleDefault/ltr': direction === 'LTR',
  10185. 'public/DraftStyleDefault/rtl': direction === 'RTL'
  10186. });
  10187. return React.createElement(
  10188. 'div',
  10189. { 'data-offset-key': offsetKey, className: className },
  10190. this._renderChildren()
  10191. );
  10192. };
  10193. return DraftEditorBlock;
  10194. }(React.Component);
  10195. var DraftEditorBlock_react = DraftEditorBlock;
  10196. /**
  10197. * Copyright (c) 2013-present, Facebook, Inc.
  10198. *
  10199. * This source code is licensed under the MIT license found in the
  10200. * LICENSE file in the root directory of this source tree.
  10201. *
  10202. * @typechecks static-only
  10203. */
  10204. /**
  10205. * Combines multiple className strings into one.
  10206. * http://jsperf.com/joinclasses-args-vs-array
  10207. *
  10208. * @param {...?string} className
  10209. * @return {string}
  10210. */
  10211. function joinClasses(className /*, ... */) {
  10212. if (!className) {
  10213. className = '';
  10214. }
  10215. var nextClass = void 0;
  10216. var argLength = arguments.length;
  10217. if (argLength > 1) {
  10218. for (var ii = 1; ii < argLength; ii++) {
  10219. nextClass = arguments[ii];
  10220. if (nextClass) {
  10221. className = (className ? className + ' ' : '') + nextClass;
  10222. }
  10223. }
  10224. }
  10225. return className;
  10226. }
  10227. var joinClasses_1 = joinClasses;
  10228. var _extends$3 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  10229. function _classCallCheck$c(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10230. function _possibleConstructorReturn$9(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  10231. function _inherits$9(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  10232. /**
  10233. * Provide default styling for list items. This way, lists will be styled with
  10234. * proper counters and indentation even if the caller does not specify
  10235. * their own styling at all. If more than five levels of nesting are needed,
  10236. * the necessary CSS classes can be provided via `blockStyleFn` configuration.
  10237. */
  10238. var getListItemClasses = function getListItemClasses(type, depth, shouldResetCount, direction) {
  10239. return cx_1({
  10240. 'public/DraftStyleDefault/unorderedListItem': type === 'unordered-list-item',
  10241. 'public/DraftStyleDefault/orderedListItem': type === 'ordered-list-item',
  10242. 'public/DraftStyleDefault/reset': shouldResetCount,
  10243. 'public/DraftStyleDefault/depth0': depth === 0,
  10244. 'public/DraftStyleDefault/depth1': depth === 1,
  10245. 'public/DraftStyleDefault/depth2': depth === 2,
  10246. 'public/DraftStyleDefault/depth3': depth === 3,
  10247. 'public/DraftStyleDefault/depth4': depth === 4,
  10248. 'public/DraftStyleDefault/listLTR': direction === 'LTR',
  10249. 'public/DraftStyleDefault/listRTL': direction === 'RTL'
  10250. });
  10251. };
  10252. /**
  10253. * `DraftEditorContents` is the container component for all block components
  10254. * rendered for a `DraftEditor`. It is optimized to aggressively avoid
  10255. * re-rendering blocks whenever possible.
  10256. *
  10257. * This component is separate from `DraftEditor` because certain props
  10258. * (for instance, ARIA props) must be allowed to update without affecting
  10259. * the contents of the editor.
  10260. */
  10261. var DraftEditorContents = function (_React$Component) {
  10262. _inherits$9(DraftEditorContents, _React$Component);
  10263. function DraftEditorContents() {
  10264. _classCallCheck$c(this, DraftEditorContents);
  10265. return _possibleConstructorReturn$9(this, _React$Component.apply(this, arguments));
  10266. }
  10267. DraftEditorContents.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  10268. var prevEditorState = this.props.editorState;
  10269. var nextEditorState = nextProps.editorState;
  10270. var prevDirectionMap = prevEditorState.getDirectionMap();
  10271. var nextDirectionMap = nextEditorState.getDirectionMap();
  10272. // Text direction has changed for one or more blocks. We must re-render.
  10273. if (prevDirectionMap !== nextDirectionMap) {
  10274. return true;
  10275. }
  10276. var didHaveFocus = prevEditorState.getSelection().getHasFocus();
  10277. var nowHasFocus = nextEditorState.getSelection().getHasFocus();
  10278. if (didHaveFocus !== nowHasFocus) {
  10279. return true;
  10280. }
  10281. var nextNativeContent = nextEditorState.getNativelyRenderedContent();
  10282. var wasComposing = prevEditorState.isInCompositionMode();
  10283. var nowComposing = nextEditorState.isInCompositionMode();
  10284. // If the state is unchanged or we're currently rendering a natively
  10285. // rendered state, there's nothing new to be done.
  10286. if (prevEditorState === nextEditorState || nextNativeContent !== null && nextEditorState.getCurrentContent() === nextNativeContent || wasComposing && nowComposing) {
  10287. return false;
  10288. }
  10289. var prevContent = prevEditorState.getCurrentContent();
  10290. var nextContent = nextEditorState.getCurrentContent();
  10291. var prevDecorator = prevEditorState.getDecorator();
  10292. var nextDecorator = nextEditorState.getDecorator();
  10293. return wasComposing !== nowComposing || prevContent !== nextContent || prevDecorator !== nextDecorator || nextEditorState.mustForceSelection();
  10294. };
  10295. DraftEditorContents.prototype.render = function render() {
  10296. var _props = this.props,
  10297. blockRenderMap = _props.blockRenderMap,
  10298. blockRendererFn = _props.blockRendererFn,
  10299. blockStyleFn = _props.blockStyleFn,
  10300. customStyleMap = _props.customStyleMap,
  10301. customStyleFn = _props.customStyleFn,
  10302. editorState = _props.editorState,
  10303. editorKey = _props.editorKey,
  10304. textDirectionality = _props.textDirectionality;
  10305. var content = editorState.getCurrentContent();
  10306. var selection = editorState.getSelection();
  10307. var forceSelection = editorState.mustForceSelection();
  10308. var decorator = editorState.getDecorator();
  10309. var directionMap = nullthrows_1(editorState.getDirectionMap());
  10310. var blocksAsArray = content.getBlocksAsArray();
  10311. var processedBlocks = [];
  10312. var currentDepth = null;
  10313. var lastWrapperTemplate = null;
  10314. for (var ii = 0; ii < blocksAsArray.length; ii++) {
  10315. var _block = blocksAsArray[ii];
  10316. var key = _block.getKey();
  10317. var blockType = _block.getType();
  10318. var customRenderer = blockRendererFn(_block);
  10319. var CustomComponent = void 0,
  10320. customProps = void 0,
  10321. customEditable = void 0;
  10322. if (customRenderer) {
  10323. CustomComponent = customRenderer.component;
  10324. customProps = customRenderer.props;
  10325. customEditable = customRenderer.editable;
  10326. }
  10327. var direction = textDirectionality ? textDirectionality : directionMap.get(key);
  10328. var offsetKey = DraftOffsetKey_1.encode(key, 0, 0);
  10329. var componentProps = {
  10330. contentState: content,
  10331. block: _block,
  10332. blockProps: customProps,
  10333. blockStyleFn: blockStyleFn,
  10334. customStyleMap: customStyleMap,
  10335. customStyleFn: customStyleFn,
  10336. decorator: decorator,
  10337. direction: direction,
  10338. forceSelection: forceSelection,
  10339. key: key,
  10340. offsetKey: offsetKey,
  10341. selection: selection,
  10342. tree: editorState.getBlockTree(key)
  10343. };
  10344. var configForType = blockRenderMap.get(blockType) || blockRenderMap.get('unstyled');
  10345. var wrapperTemplate = configForType.wrapper;
  10346. var Element = configForType.element || blockRenderMap.get('unstyled').element;
  10347. var depth = _block.getDepth();
  10348. var className = '';
  10349. if (blockStyleFn) {
  10350. className = blockStyleFn(_block);
  10351. }
  10352. // List items are special snowflakes, since we handle nesting and
  10353. // counters manually.
  10354. if (Element === 'li') {
  10355. var shouldResetCount = lastWrapperTemplate !== wrapperTemplate || currentDepth === null || depth > currentDepth;
  10356. className = joinClasses_1(className, getListItemClasses(blockType, depth, shouldResetCount, direction));
  10357. }
  10358. var Component = CustomComponent || DraftEditorBlock_react;
  10359. var childProps = {
  10360. className: className,
  10361. 'data-block': true,
  10362. 'data-editor': editorKey,
  10363. 'data-offset-key': offsetKey,
  10364. key: key
  10365. };
  10366. if (customEditable !== undefined) {
  10367. childProps = _extends$3({}, childProps, {
  10368. contentEditable: customEditable,
  10369. suppressContentEditableWarning: true
  10370. });
  10371. }
  10372. var child = React.createElement(Element, childProps, React.createElement(Component, componentProps));
  10373. processedBlocks.push({
  10374. block: child,
  10375. wrapperTemplate: wrapperTemplate,
  10376. key: key,
  10377. offsetKey: offsetKey
  10378. });
  10379. if (wrapperTemplate) {
  10380. currentDepth = _block.getDepth();
  10381. } else {
  10382. currentDepth = null;
  10383. }
  10384. lastWrapperTemplate = wrapperTemplate;
  10385. }
  10386. // Group contiguous runs of blocks that have the same wrapperTemplate
  10387. var outputBlocks = [];
  10388. for (var _ii = 0; _ii < processedBlocks.length;) {
  10389. var info = processedBlocks[_ii];
  10390. if (info.wrapperTemplate) {
  10391. var blocks = [];
  10392. do {
  10393. blocks.push(processedBlocks[_ii].block);
  10394. _ii++;
  10395. } while (_ii < processedBlocks.length && processedBlocks[_ii].wrapperTemplate === info.wrapperTemplate);
  10396. var wrapperElement = React.cloneElement(info.wrapperTemplate, {
  10397. key: info.key + '-wrap',
  10398. 'data-offset-key': info.offsetKey
  10399. }, blocks);
  10400. outputBlocks.push(wrapperElement);
  10401. } else {
  10402. outputBlocks.push(info.block);
  10403. _ii++;
  10404. }
  10405. }
  10406. return React.createElement(
  10407. 'div',
  10408. { 'data-contents': 'true' },
  10409. outputBlocks
  10410. );
  10411. };
  10412. return DraftEditorContents;
  10413. }(React.Component);
  10414. var DraftEditorContentsCore_react = DraftEditorContents;
  10415. var DraftEditorContents_react = DraftEditorContentsCore_react;
  10416. /**
  10417. * Copyright (c) 2013-present, Facebook, Inc.
  10418. *
  10419. * This source code is licensed under the MIT license found in the
  10420. * LICENSE file in the root directory of this source tree.
  10421. *
  10422. */
  10423. var PhotosMimeType = {
  10424. isImage: function isImage(mimeString) {
  10425. return getParts(mimeString)[0] === 'image';
  10426. },
  10427. isJpeg: function isJpeg(mimeString) {
  10428. var parts = getParts(mimeString);
  10429. return PhotosMimeType.isImage(mimeString) && (
  10430. // see http://fburl.com/10972194
  10431. parts[1] === 'jpeg' || parts[1] === 'pjpeg');
  10432. }
  10433. };
  10434. function getParts(mimeString) {
  10435. return mimeString.split('/');
  10436. }
  10437. var PhotosMimeType_1 = PhotosMimeType;
  10438. /**
  10439. * Copyright (c) 2013-present, Facebook, Inc.
  10440. *
  10441. * This source code is licensed under the MIT license found in the
  10442. * LICENSE file in the root directory of this source tree.
  10443. *
  10444. * @typechecks
  10445. */
  10446. /**
  10447. * Convert array-like objects to arrays.
  10448. *
  10449. * This API assumes the caller knows the contents of the data type. For less
  10450. * well defined inputs use createArrayFromMixed.
  10451. *
  10452. * @param {object|function|filelist} obj
  10453. * @return {array}
  10454. */
  10455. function toArray(obj) {
  10456. var length = obj.length;
  10457. // Some browsers builtin objects can report typeof 'function' (e.g. NodeList
  10458. // in old versions of Safari).
  10459. !(!Array.isArray(obj) && (typeof obj === 'object' || typeof obj === 'function')) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'toArray: Array-like object expected') : invariant_1(false) : void 0;
  10460. !(typeof length === 'number') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'toArray: Object needs a length property') : invariant_1(false) : void 0;
  10461. !(length === 0 || length - 1 in obj) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'toArray: Object should have keys for indices') : invariant_1(false) : void 0;
  10462. !(typeof obj.callee !== 'function') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'toArray: Object can\'t be `arguments`. Use rest params ' + '(function(...args) {}) or Array.from() instead.') : invariant_1(false) : void 0;
  10463. // Old IE doesn't give collections access to hasOwnProperty. Assume inputs
  10464. // without method will throw during the slice call and skip straight to the
  10465. // fallback.
  10466. if (obj.hasOwnProperty) {
  10467. try {
  10468. return Array.prototype.slice.call(obj);
  10469. } catch (e) {
  10470. // IE < 9 does not support Array#slice on collections objects
  10471. }
  10472. }
  10473. // Fall back to copying key by key. This assumes all keys have a value,
  10474. // so will not preserve sparsely populated inputs.
  10475. var ret = Array(length);
  10476. for (var ii = 0; ii < length; ii++) {
  10477. ret[ii] = obj[ii];
  10478. }
  10479. return ret;
  10480. }
  10481. /**
  10482. * Perform a heuristic test to determine if an object is "array-like".
  10483. *
  10484. * A monk asked Joshu, a Zen master, "Has a dog Buddha nature?"
  10485. * Joshu replied: "Mu."
  10486. *
  10487. * This function determines if its argument has "array nature": it returns
  10488. * true if the argument is an actual array, an `arguments' object, or an
  10489. * HTMLCollection (e.g. node.childNodes or node.getElementsByTagName()).
  10490. *
  10491. * It will return false for other array-like objects like Filelist.
  10492. *
  10493. * @param {*} obj
  10494. * @return {boolean}
  10495. */
  10496. function hasArrayNature(obj) {
  10497. return (
  10498. // not null/false
  10499. !!obj && (
  10500. // arrays are objects, NodeLists are functions in Safari
  10501. typeof obj == 'object' || typeof obj == 'function') &&
  10502. // quacks like an array
  10503. 'length' in obj &&
  10504. // not window
  10505. !('setInterval' in obj) &&
  10506. // no DOM node should be considered an array-like
  10507. // a 'select' element has 'length' and 'item' properties on IE8
  10508. typeof obj.nodeType != 'number' && (
  10509. // a real array
  10510. Array.isArray(obj) ||
  10511. // arguments
  10512. 'callee' in obj ||
  10513. // HTMLCollection/NodeList
  10514. 'item' in obj)
  10515. );
  10516. }
  10517. /**
  10518. * Ensure that the argument is an array by wrapping it in an array if it is not.
  10519. * Creates a copy of the argument if it is already an array.
  10520. *
  10521. * This is mostly useful idiomatically:
  10522. *
  10523. * var createArrayFromMixed = require('createArrayFromMixed');
  10524. *
  10525. * function takesOneOrMoreThings(things) {
  10526. * things = createArrayFromMixed(things);
  10527. * ...
  10528. * }
  10529. *
  10530. * This allows you to treat `things' as an array, but accept scalars in the API.
  10531. *
  10532. * If you need to convert an array-like object, like `arguments`, into an array
  10533. * use toArray instead.
  10534. *
  10535. * @param {*} obj
  10536. * @return {array}
  10537. */
  10538. function createArrayFromMixed(obj) {
  10539. if (!hasArrayNature(obj)) {
  10540. return [obj];
  10541. } else if (Array.isArray(obj)) {
  10542. return obj.slice();
  10543. } else {
  10544. return toArray(obj);
  10545. }
  10546. }
  10547. var createArrayFromMixed_1 = createArrayFromMixed;
  10548. function _classCallCheck$d(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10549. /**
  10550. * Copyright (c) 2013-present, Facebook, Inc.
  10551. *
  10552. * This source code is licensed under the MIT license found in the
  10553. * LICENSE file in the root directory of this source tree.
  10554. *
  10555. * @typechecks
  10556. */
  10557. var CR_LF_REGEX = new RegExp('\r\n', 'g');
  10558. var LF_ONLY = '\n';
  10559. var RICH_TEXT_TYPES = {
  10560. 'text/rtf': 1,
  10561. 'text/html': 1
  10562. };
  10563. /**
  10564. * If DataTransferItem is a file then return the Blob of data.
  10565. *
  10566. * @param {object} item
  10567. * @return {?blob}
  10568. */
  10569. function getFileFromDataTransfer(item) {
  10570. if (item.kind == 'file') {
  10571. return item.getAsFile();
  10572. }
  10573. }
  10574. var DataTransfer = function () {
  10575. /**
  10576. * @param {object} data
  10577. */
  10578. function DataTransfer(data) {
  10579. _classCallCheck$d(this, DataTransfer);
  10580. this.data = data;
  10581. // Types could be DOMStringList or array
  10582. this.types = data.types ? createArrayFromMixed_1(data.types) : [];
  10583. }
  10584. /**
  10585. * Is this likely to be a rich text data transfer?
  10586. *
  10587. * @return {boolean}
  10588. */
  10589. DataTransfer.prototype.isRichText = function isRichText() {
  10590. // If HTML is available, treat this data as rich text. This way, we avoid
  10591. // using a pasted image if it is packaged with HTML -- this may occur with
  10592. // pastes from MS Word, for example. However this is only rich text if
  10593. // there's accompanying text.
  10594. if (this.getHTML() && this.getText()) {
  10595. return true;
  10596. }
  10597. // When an image is copied from a preview window, you end up with two
  10598. // DataTransferItems one of which is a file's metadata as text. Skip those.
  10599. if (this.isImage()) {
  10600. return false;
  10601. }
  10602. return this.types.some(function (type) {
  10603. return RICH_TEXT_TYPES[type];
  10604. });
  10605. };
  10606. /**
  10607. * Get raw text.
  10608. *
  10609. * @return {?string}
  10610. */
  10611. DataTransfer.prototype.getText = function getText() {
  10612. var text;
  10613. if (this.data.getData) {
  10614. if (!this.types.length) {
  10615. text = this.data.getData('Text');
  10616. } else if (this.types.indexOf('text/plain') != -1) {
  10617. text = this.data.getData('text/plain');
  10618. }
  10619. }
  10620. return text ? text.replace(CR_LF_REGEX, LF_ONLY) : null;
  10621. };
  10622. /**
  10623. * Get HTML paste data
  10624. *
  10625. * @return {?string}
  10626. */
  10627. DataTransfer.prototype.getHTML = function getHTML() {
  10628. if (this.data.getData) {
  10629. if (!this.types.length) {
  10630. return this.data.getData('Text');
  10631. } else if (this.types.indexOf('text/html') != -1) {
  10632. return this.data.getData('text/html');
  10633. }
  10634. }
  10635. };
  10636. /**
  10637. * Is this a link data transfer?
  10638. *
  10639. * @return {boolean}
  10640. */
  10641. DataTransfer.prototype.isLink = function isLink() {
  10642. return this.types.some(function (type) {
  10643. return type.indexOf('Url') != -1 || type.indexOf('text/uri-list') != -1 || type.indexOf('text/x-moz-url');
  10644. });
  10645. };
  10646. /**
  10647. * Get a link url.
  10648. *
  10649. * @return {?string}
  10650. */
  10651. DataTransfer.prototype.getLink = function getLink() {
  10652. if (this.data.getData) {
  10653. if (this.types.indexOf('text/x-moz-url') != -1) {
  10654. var url = this.data.getData('text/x-moz-url').split('\n');
  10655. return url[0];
  10656. }
  10657. return this.types.indexOf('text/uri-list') != -1 ? this.data.getData('text/uri-list') : this.data.getData('url');
  10658. }
  10659. return null;
  10660. };
  10661. /**
  10662. * Is this an image data transfer?
  10663. *
  10664. * @return {boolean}
  10665. */
  10666. DataTransfer.prototype.isImage = function isImage() {
  10667. var isImage = this.types.some(function (type) {
  10668. // Firefox will have a type of application/x-moz-file for images during
  10669. // dragging
  10670. return type.indexOf('application/x-moz-file') != -1;
  10671. });
  10672. if (isImage) {
  10673. return true;
  10674. }
  10675. var items = this.getFiles();
  10676. for (var i = 0; i < items.length; i++) {
  10677. var type = items[i].type;
  10678. if (!PhotosMimeType_1.isImage(type)) {
  10679. return false;
  10680. }
  10681. }
  10682. return true;
  10683. };
  10684. DataTransfer.prototype.getCount = function getCount() {
  10685. if (this.data.hasOwnProperty('items')) {
  10686. return this.data.items.length;
  10687. } else if (this.data.hasOwnProperty('mozItemCount')) {
  10688. return this.data.mozItemCount;
  10689. } else if (this.data.files) {
  10690. return this.data.files.length;
  10691. }
  10692. return null;
  10693. };
  10694. /**
  10695. * Get files.
  10696. *
  10697. * @return {array}
  10698. */
  10699. DataTransfer.prototype.getFiles = function getFiles() {
  10700. if (this.data.items) {
  10701. // createArrayFromMixed doesn't properly handle DataTransferItemLists.
  10702. return Array.prototype.slice.call(this.data.items).map(getFileFromDataTransfer).filter(emptyFunction_1.thatReturnsArgument);
  10703. } else if (this.data.files) {
  10704. return Array.prototype.slice.call(this.data.files);
  10705. } else {
  10706. return [];
  10707. }
  10708. };
  10709. /**
  10710. * Are there any files to fetch?
  10711. *
  10712. * @return {boolean}
  10713. */
  10714. DataTransfer.prototype.hasFiles = function hasFiles() {
  10715. return this.getFiles().length > 0;
  10716. };
  10717. return DataTransfer;
  10718. }();
  10719. var DataTransfer_1 = DataTransfer;
  10720. /**
  10721. * Copyright (c) 2013-present, Facebook, Inc.
  10722. * All rights reserved.
  10723. *
  10724. * This source code is licensed under the BSD-style license found in the
  10725. * LICENSE file in the root directory of this source tree. An additional grant
  10726. * of patent rights can be found in the PATENTS file in the same directory.
  10727. *
  10728. * @providesModule getSelectionOffsetKeyForNode
  10729. * @format
  10730. *
  10731. */
  10732. /**
  10733. * Get offset key from a node or it's child nodes. Return the first offset key
  10734. * found on the DOM tree of given node.
  10735. */
  10736. function getSelectionOffsetKeyForNode(node) {
  10737. if (node instanceof Element) {
  10738. var offsetKey = node.getAttribute('data-offset-key');
  10739. if (offsetKey) {
  10740. return offsetKey;
  10741. }
  10742. for (var ii = 0; ii < node.childNodes.length; ii++) {
  10743. var childOffsetKey = getSelectionOffsetKeyForNode(node.childNodes[ii]);
  10744. if (childOffsetKey) {
  10745. return childOffsetKey;
  10746. }
  10747. }
  10748. }
  10749. return null;
  10750. }
  10751. var getSelectionOffsetKeyForNode_1 = getSelectionOffsetKeyForNode;
  10752. /**
  10753. * Get the key from the node's nearest offset-aware ancestor.
  10754. */
  10755. function findAncestorOffsetKey(node) {
  10756. var searchNode = node;
  10757. while (searchNode && searchNode !== document.documentElement) {
  10758. var key = getSelectionOffsetKeyForNode_1(searchNode);
  10759. if (key != null) {
  10760. return key;
  10761. }
  10762. searchNode = searchNode.parentNode;
  10763. }
  10764. return null;
  10765. }
  10766. var findAncestorOffsetKey_1 = findAncestorOffsetKey;
  10767. var TEXT_CLIPPING_REGEX = /\.textClipping$/;
  10768. var TEXT_TYPES = {
  10769. 'text/plain': true,
  10770. 'text/html': true,
  10771. 'text/rtf': true
  10772. };
  10773. // Somewhat arbitrary upper bound on text size. Let's not lock up the browser.
  10774. var TEXT_SIZE_UPPER_BOUND = 5000;
  10775. /**
  10776. * Extract the text content from a file list.
  10777. */
  10778. function getTextContentFromFiles(files, callback) {
  10779. var readCount = 0;
  10780. var results = [];
  10781. files.forEach(function ( /*blob*/file) {
  10782. readFile(file, function ( /*string*/text) {
  10783. readCount++;
  10784. text && results.push(text.slice(0, TEXT_SIZE_UPPER_BOUND));
  10785. if (readCount == files.length) {
  10786. callback(results.join('\r'));
  10787. }
  10788. });
  10789. });
  10790. }
  10791. /**
  10792. * todo isaac: Do work to turn html/rtf into a content fragment.
  10793. */
  10794. function readFile(file, callback) {
  10795. if (!commonjsGlobal.FileReader || file.type && !(file.type in TEXT_TYPES)) {
  10796. callback('');
  10797. return;
  10798. }
  10799. if (file.type === '') {
  10800. var contents = '';
  10801. // Special-case text clippings, which have an empty type but include
  10802. // `.textClipping` in the file name. `readAsText` results in an empty
  10803. // string for text clippings, so we force the file name to serve
  10804. // as the text value for the file.
  10805. if (TEXT_CLIPPING_REGEX.test(file.name)) {
  10806. contents = file.name.replace(TEXT_CLIPPING_REGEX, '');
  10807. }
  10808. callback(contents);
  10809. return;
  10810. }
  10811. var reader = new FileReader();
  10812. reader.onload = function () {
  10813. var result = reader.result;
  10814. !(typeof result === 'string') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'We should be calling "FileReader.readAsText" which returns a string') : invariant_1(false) : void 0;
  10815. callback(result);
  10816. };
  10817. reader.onerror = function () {
  10818. callback('');
  10819. };
  10820. reader.readAsText(file);
  10821. }
  10822. var getTextContentFromFiles_1 = getTextContentFromFiles;
  10823. function getUpdatedSelectionState(editorState, anchorKey, anchorOffset, focusKey, focusOffset) {
  10824. var selection = nullthrows_1(editorState.getSelection());
  10825. if (process.env.NODE_ENV !== 'production') {
  10826. if (!anchorKey || !focusKey) {
  10827. /*eslint-disable no-console */
  10828. console.warn('Invalid selection state.', arguments, editorState.toJS());
  10829. /*eslint-enable no-console */
  10830. return selection;
  10831. }
  10832. }
  10833. var anchorPath = DraftOffsetKey_1.decode(anchorKey);
  10834. var anchorBlockKey = anchorPath.blockKey;
  10835. var anchorLeaf = editorState.getBlockTree(anchorBlockKey).getIn([anchorPath.decoratorKey, 'leaves', anchorPath.leafKey]);
  10836. var focusPath = DraftOffsetKey_1.decode(focusKey);
  10837. var focusBlockKey = focusPath.blockKey;
  10838. var focusLeaf = editorState.getBlockTree(focusBlockKey).getIn([focusPath.decoratorKey, 'leaves', focusPath.leafKey]);
  10839. var anchorLeafStart = anchorLeaf.get('start');
  10840. var focusLeafStart = focusLeaf.get('start');
  10841. var anchorBlockOffset = anchorLeaf ? anchorLeafStart + anchorOffset : null;
  10842. var focusBlockOffset = focusLeaf ? focusLeafStart + focusOffset : null;
  10843. var areEqual = selection.getAnchorKey() === anchorBlockKey && selection.getAnchorOffset() === anchorBlockOffset && selection.getFocusKey() === focusBlockKey && selection.getFocusOffset() === focusBlockOffset;
  10844. if (areEqual) {
  10845. return selection;
  10846. }
  10847. var isBackward = false;
  10848. if (anchorBlockKey === focusBlockKey) {
  10849. var anchorLeafEnd = anchorLeaf.get('end');
  10850. var focusLeafEnd = focusLeaf.get('end');
  10851. if (focusLeafStart === anchorLeafStart && focusLeafEnd === anchorLeafEnd) {
  10852. isBackward = focusOffset < anchorOffset;
  10853. } else {
  10854. isBackward = focusLeafStart < anchorLeafStart;
  10855. }
  10856. } else {
  10857. var startKey = editorState.getCurrentContent().getBlockMap().keySeq().skipUntil(function (v) {
  10858. return v === anchorBlockKey || v === focusBlockKey;
  10859. }).first();
  10860. isBackward = startKey === focusBlockKey;
  10861. }
  10862. return selection.merge({
  10863. anchorKey: anchorBlockKey,
  10864. anchorOffset: anchorBlockOffset,
  10865. focusKey: focusBlockKey,
  10866. focusOffset: focusBlockOffset,
  10867. isBackward: isBackward
  10868. });
  10869. }
  10870. var getUpdatedSelectionState_1 = getUpdatedSelectionState;
  10871. /**
  10872. * Get a SelectionState for the supplied mouse event.
  10873. */
  10874. function getSelectionForEvent(event, editorState) {
  10875. var node = null;
  10876. var offset = null;
  10877. if (typeof document.caretRangeFromPoint === 'function') {
  10878. var dropRange = document.caretRangeFromPoint(event.x, event.y);
  10879. node = dropRange.startContainer;
  10880. offset = dropRange.startOffset;
  10881. } else if (event.rangeParent) {
  10882. node = event.rangeParent;
  10883. offset = event.rangeOffset;
  10884. } else {
  10885. return null;
  10886. }
  10887. node = nullthrows_1(node);
  10888. offset = nullthrows_1(offset);
  10889. var offsetKey = nullthrows_1(findAncestorOffsetKey_1(node));
  10890. return getUpdatedSelectionState_1(editorState, offsetKey, offset, offsetKey, offset);
  10891. }
  10892. var DraftEditorDragHandler = {
  10893. /**
  10894. * Drag originating from input terminated.
  10895. */
  10896. onDragEnd: function onDragEnd(editor) {
  10897. editor.exitCurrentMode();
  10898. },
  10899. /**
  10900. * Handle data being dropped.
  10901. */
  10902. onDrop: function onDrop(editor, e) {
  10903. var data = new DataTransfer_1(e.nativeEvent.dataTransfer);
  10904. var editorState = editor._latestEditorState;
  10905. var dropSelection = getSelectionForEvent(e.nativeEvent, editorState);
  10906. e.preventDefault();
  10907. editor.exitCurrentMode();
  10908. if (dropSelection == null) {
  10909. return;
  10910. }
  10911. var files = data.getFiles();
  10912. if (files.length > 0) {
  10913. if (editor.props.handleDroppedFiles && isEventHandled_1(editor.props.handleDroppedFiles(dropSelection, files))) {
  10914. return;
  10915. }
  10916. getTextContentFromFiles_1(files, function (fileText) {
  10917. fileText && editor.update(insertTextAtSelection(editorState, dropSelection, fileText));
  10918. });
  10919. return;
  10920. }
  10921. var dragType = editor._internalDrag ? 'internal' : 'external';
  10922. if (editor.props.handleDrop && isEventHandled_1(editor.props.handleDrop(dropSelection, data, dragType))) {
  10923. return;
  10924. }
  10925. if (editor._internalDrag) {
  10926. editor.update(moveText(editorState, dropSelection));
  10927. return;
  10928. }
  10929. editor.update(insertTextAtSelection(editorState, dropSelection, data.getText()));
  10930. }
  10931. };
  10932. function moveText(editorState, targetSelection) {
  10933. var newContentState = DraftModifier_1.moveText(editorState.getCurrentContent(), editorState.getSelection(), targetSelection);
  10934. return EditorState_1.push(editorState, newContentState, 'insert-fragment');
  10935. }
  10936. /**
  10937. * Insert text at a specified selection.
  10938. */
  10939. function insertTextAtSelection(editorState, selection, text) {
  10940. var newContentState = DraftModifier_1.insertText(editorState.getCurrentContent(), selection, text, editorState.getCurrentInlineStyle());
  10941. return EditorState_1.push(editorState, newContentState, 'insert-fragment');
  10942. }
  10943. var DraftEditorDragHandler_1 = DraftEditorDragHandler;
  10944. (function (global, undefined$1) {
  10945. if (global.setImmediate) {
  10946. return;
  10947. }
  10948. var nextHandle = 1; // Spec says greater than zero
  10949. var tasksByHandle = {};
  10950. var currentlyRunningATask = false;
  10951. var doc = global.document;
  10952. var registerImmediate;
  10953. function setImmediate(callback) {
  10954. // Callback can either be a function or a string
  10955. if (typeof callback !== "function") {
  10956. callback = new Function("" + callback);
  10957. }
  10958. // Copy function arguments
  10959. var args = new Array(arguments.length - 1);
  10960. for (var i = 0; i < args.length; i++) {
  10961. args[i] = arguments[i + 1];
  10962. }
  10963. // Store and register the task
  10964. var task = { callback: callback, args: args };
  10965. tasksByHandle[nextHandle] = task;
  10966. registerImmediate(nextHandle);
  10967. return nextHandle++;
  10968. }
  10969. function clearImmediate(handle) {
  10970. delete tasksByHandle[handle];
  10971. }
  10972. function run(task) {
  10973. var callback = task.callback;
  10974. var args = task.args;
  10975. switch (args.length) {
  10976. case 0:
  10977. callback();
  10978. break;
  10979. case 1:
  10980. callback(args[0]);
  10981. break;
  10982. case 2:
  10983. callback(args[0], args[1]);
  10984. break;
  10985. case 3:
  10986. callback(args[0], args[1], args[2]);
  10987. break;
  10988. default:
  10989. callback.apply(undefined$1, args);
  10990. break;
  10991. }
  10992. }
  10993. function runIfPresent(handle) {
  10994. // From the spec: "Wait until any invocations of this algorithm started before this one have completed."
  10995. // So if we're currently running a task, we'll need to delay this invocation.
  10996. if (currentlyRunningATask) {
  10997. // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a
  10998. // "too much recursion" error.
  10999. setTimeout(runIfPresent, 0, handle);
  11000. } else {
  11001. var task = tasksByHandle[handle];
  11002. if (task) {
  11003. currentlyRunningATask = true;
  11004. try {
  11005. run(task);
  11006. } finally {
  11007. clearImmediate(handle);
  11008. currentlyRunningATask = false;
  11009. }
  11010. }
  11011. }
  11012. }
  11013. function installNextTickImplementation() {
  11014. registerImmediate = function(handle) {
  11015. process.nextTick(function () { runIfPresent(handle); });
  11016. };
  11017. }
  11018. function canUsePostMessage() {
  11019. // The test against `importScripts` prevents this implementation from being installed inside a web worker,
  11020. // where `global.postMessage` means something completely different and can't be used for this purpose.
  11021. if (global.postMessage && !global.importScripts) {
  11022. var postMessageIsAsynchronous = true;
  11023. var oldOnMessage = global.onmessage;
  11024. global.onmessage = function() {
  11025. postMessageIsAsynchronous = false;
  11026. };
  11027. global.postMessage("", "*");
  11028. global.onmessage = oldOnMessage;
  11029. return postMessageIsAsynchronous;
  11030. }
  11031. }
  11032. function installPostMessageImplementation() {
  11033. // Installs an event handler on `global` for the `message` event: see
  11034. // * https://developer.mozilla.org/en/DOM/window.postMessage
  11035. // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
  11036. var messagePrefix = "setImmediate$" + Math.random() + "$";
  11037. var onGlobalMessage = function(event) {
  11038. if (event.source === global &&
  11039. typeof event.data === "string" &&
  11040. event.data.indexOf(messagePrefix) === 0) {
  11041. runIfPresent(+event.data.slice(messagePrefix.length));
  11042. }
  11043. };
  11044. if (global.addEventListener) {
  11045. global.addEventListener("message", onGlobalMessage, false);
  11046. } else {
  11047. global.attachEvent("onmessage", onGlobalMessage);
  11048. }
  11049. registerImmediate = function(handle) {
  11050. global.postMessage(messagePrefix + handle, "*");
  11051. };
  11052. }
  11053. function installMessageChannelImplementation() {
  11054. var channel = new MessageChannel();
  11055. channel.port1.onmessage = function(event) {
  11056. var handle = event.data;
  11057. runIfPresent(handle);
  11058. };
  11059. registerImmediate = function(handle) {
  11060. channel.port2.postMessage(handle);
  11061. };
  11062. }
  11063. function installReadyStateChangeImplementation() {
  11064. var html = doc.documentElement;
  11065. registerImmediate = function(handle) {
  11066. // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
  11067. // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
  11068. var script = doc.createElement("script");
  11069. script.onreadystatechange = function () {
  11070. runIfPresent(handle);
  11071. script.onreadystatechange = null;
  11072. html.removeChild(script);
  11073. script = null;
  11074. };
  11075. html.appendChild(script);
  11076. };
  11077. }
  11078. function installSetTimeoutImplementation() {
  11079. registerImmediate = function(handle) {
  11080. setTimeout(runIfPresent, 0, handle);
  11081. };
  11082. }
  11083. // If supported, we should attach to the prototype of global, since that is where setTimeout et al. live.
  11084. var attachTo = Object.getPrototypeOf && Object.getPrototypeOf(global);
  11085. attachTo = attachTo && attachTo.setTimeout ? attachTo : global;
  11086. // Don't get fooled by e.g. browserify environments.
  11087. if ({}.toString.call(global.process) === "[object process]") {
  11088. // For Node.js before 0.9
  11089. installNextTickImplementation();
  11090. } else if (canUsePostMessage()) {
  11091. // For non-IE10 modern browsers
  11092. installPostMessageImplementation();
  11093. } else if (global.MessageChannel) {
  11094. // For web workers, where supported
  11095. installMessageChannelImplementation();
  11096. } else if (doc && "onreadystatechange" in doc.createElement("script")) {
  11097. // For IE 6–8
  11098. installReadyStateChangeImplementation();
  11099. } else {
  11100. // For older browsers
  11101. installSetTimeoutImplementation();
  11102. }
  11103. attachTo.setImmediate = setImmediate;
  11104. attachTo.clearImmediate = clearImmediate;
  11105. }(typeof self === "undefined" ? typeof commonjsGlobal === "undefined" ? commonjsGlobal : commonjsGlobal : self));
  11106. // setimmediate adds setImmediate to the global. We want to make sure we export
  11107. // the actual function.
  11108. var setImmediate = commonjsGlobal.setImmediate;
  11109. // When nothing is focused, Firefox regards two characters, `'` and `/`, as
  11110. // commands that should open and focus the "quickfind" search bar. This should
  11111. // *never* happen while a contenteditable is focused, but as of v28, it
  11112. // sometimes does, even when the keypress event target is the contenteditable.
  11113. // This breaks the input. Special case these characters to ensure that when
  11114. // they are typed, we prevent default on the event to make sure not to
  11115. // trigger quickfind.
  11116. var FF_QUICKFIND_CHAR = "'";
  11117. var FF_QUICKFIND_LINK_CHAR = '/';
  11118. var isFirefox = UserAgent_1.isBrowser('Firefox');
  11119. function mustPreventDefaultForCharacter(character) {
  11120. return isFirefox && (character == FF_QUICKFIND_CHAR || character == FF_QUICKFIND_LINK_CHAR);
  11121. }
  11122. /**
  11123. * Replace the current selection with the specified text string, with the
  11124. * inline style and entity key applied to the newly inserted text.
  11125. */
  11126. function replaceText(editorState, text, inlineStyle, entityKey) {
  11127. var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), text, inlineStyle, entityKey);
  11128. return EditorState_1.push(editorState, contentState, 'insert-characters');
  11129. }
  11130. /**
  11131. * When `onBeforeInput` executes, the browser is attempting to insert a
  11132. * character into the editor. Apply this character data to the document,
  11133. * allowing native insertion if possible.
  11134. *
  11135. * Native insertion is encouraged in order to limit re-rendering and to
  11136. * preserve spellcheck highlighting, which disappears or flashes if re-render
  11137. * occurs on the relevant text nodes.
  11138. */
  11139. function editOnBeforeInput(editor, e) {
  11140. if (editor._pendingStateFromBeforeInput !== undefined) {
  11141. editor.update(editor._pendingStateFromBeforeInput);
  11142. editor._pendingStateFromBeforeInput = undefined;
  11143. }
  11144. var editorState = editor._latestEditorState;
  11145. var chars = e.data;
  11146. // In some cases (ex: IE ideographic space insertion) no character data
  11147. // is provided. There's nothing to do when this happens.
  11148. if (!chars) {
  11149. return;
  11150. }
  11151. // Allow the top-level component to handle the insertion manually. This is
  11152. // useful when triggering interesting behaviors for a character insertion,
  11153. // Simple examples: replacing a raw text ':)' with a smile emoji or image
  11154. // decorator, or setting a block to be a list item after typing '- ' at the
  11155. // start of the block.
  11156. if (editor.props.handleBeforeInput && isEventHandled_1(editor.props.handleBeforeInput(chars, editorState))) {
  11157. e.preventDefault();
  11158. return;
  11159. }
  11160. // If selection is collapsed, conditionally allow native behavior. This
  11161. // reduces re-renders and preserves spellcheck highlighting. If the selection
  11162. // is not collapsed, we will re-render.
  11163. var selection = editorState.getSelection();
  11164. var selectionStart = selection.getStartOffset();
  11165. var selectionEnd = selection.getEndOffset();
  11166. var anchorKey = selection.getAnchorKey();
  11167. if (!selection.isCollapsed()) {
  11168. e.preventDefault();
  11169. // If the currently selected text matches what the user is trying to
  11170. // replace it with, let's just update the `SelectionState`. If not, update
  11171. // the `ContentState` with the new text.
  11172. var currentlySelectedChars = editorState.getCurrentContent().getPlainText().slice(selectionStart, selectionEnd);
  11173. if (chars === currentlySelectedChars) {
  11174. editor.update(EditorState_1.forceSelection(editorState, selection.merge({
  11175. focusOffset: selectionEnd
  11176. })));
  11177. } else {
  11178. editor.update(replaceText(editorState, chars, editorState.getCurrentInlineStyle(), getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())));
  11179. }
  11180. return;
  11181. }
  11182. var newEditorState = replaceText(editorState, chars, editorState.getCurrentInlineStyle(), getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection()));
  11183. // Bunch of different cases follow where we need to prevent native insertion.
  11184. var mustPreventNative = false;
  11185. if (!mustPreventNative) {
  11186. // Browsers tend to insert text in weird places in the DOM when typing at
  11187. // the start of a leaf, so we'll handle it ourselves.
  11188. mustPreventNative = isSelectionAtLeafStart_1(editor._latestCommittedEditorState);
  11189. }
  11190. if (!mustPreventNative) {
  11191. // Chrome will also split up a node into two pieces if it contains a Tab
  11192. // char, for no explicable reason. Seemingly caused by this commit:
  11193. // https://chromium.googlesource.com/chromium/src/+/013ac5eaf3%5E%21/
  11194. var nativeSelection = commonjsGlobal.getSelection();
  11195. // Selection is necessarily collapsed at this point due to earlier check.
  11196. if (nativeSelection.anchorNode && nativeSelection.anchorNode.nodeType === Node.TEXT_NODE) {
  11197. // See isTabHTMLSpanElement in chromium EditingUtilities.cpp.
  11198. var parentNode = nativeSelection.anchorNode.parentNode;
  11199. mustPreventNative = parentNode.nodeName === 'SPAN' && parentNode.firstChild.nodeType === Node.TEXT_NODE && parentNode.firstChild.nodeValue.indexOf('\t') !== -1;
  11200. }
  11201. }
  11202. if (!mustPreventNative) {
  11203. // Check the old and new "fingerprints" of the current block to determine
  11204. // whether this insertion requires any addition or removal of text nodes,
  11205. // in which case we would prevent the native character insertion.
  11206. var originalFingerprint = BlockTree_1.getFingerprint(editorState.getBlockTree(anchorKey));
  11207. var newFingerprint = BlockTree_1.getFingerprint(newEditorState.getBlockTree(anchorKey));
  11208. mustPreventNative = originalFingerprint !== newFingerprint;
  11209. }
  11210. if (!mustPreventNative) {
  11211. mustPreventNative = mustPreventDefaultForCharacter(chars);
  11212. }
  11213. if (!mustPreventNative) {
  11214. mustPreventNative = nullthrows_1(newEditorState.getDirectionMap()).get(anchorKey) !== nullthrows_1(editorState.getDirectionMap()).get(anchorKey);
  11215. }
  11216. if (mustPreventNative) {
  11217. e.preventDefault();
  11218. editor.update(newEditorState);
  11219. return;
  11220. }
  11221. // We made it all the way! Let the browser do its thing and insert the char.
  11222. newEditorState = EditorState_1.set(newEditorState, {
  11223. nativelyRenderedContent: newEditorState.getCurrentContent()
  11224. });
  11225. // The native event is allowed to occur. To allow user onChange handlers to
  11226. // change the inserted text, we wait until the text is actually inserted
  11227. // before we actually update our state. That way when we rerender, the text
  11228. // we see in the DOM will already have been inserted properly.
  11229. editor._pendingStateFromBeforeInput = newEditorState;
  11230. setImmediate(function () {
  11231. if (editor._pendingStateFromBeforeInput !== undefined) {
  11232. editor.update(editor._pendingStateFromBeforeInput);
  11233. editor._pendingStateFromBeforeInput = undefined;
  11234. }
  11235. });
  11236. }
  11237. var editOnBeforeInput_1 = editOnBeforeInput;
  11238. function editOnBlur(editor, e) {
  11239. // In a contentEditable element, when you select a range and then click
  11240. // another active element, this does trigger a `blur` event but will not
  11241. // remove the DOM selection from the contenteditable.
  11242. // This is consistent across all browsers, but we prefer that the editor
  11243. // behave like a textarea, where a `blur` event clears the DOM selection.
  11244. // We therefore force the issue to be certain, checking whether the active
  11245. // element is `body` to force it when blurring occurs within the window (as
  11246. // opposed to clicking to another tab or window).
  11247. if (getActiveElement_1() === document.body) {
  11248. var _selection = commonjsGlobal.getSelection();
  11249. var editorNode = editor.editor;
  11250. if (_selection.rangeCount === 1 && containsNode_1(editorNode, _selection.anchorNode) && containsNode_1(editorNode, _selection.focusNode)) {
  11251. _selection.removeAllRanges();
  11252. }
  11253. }
  11254. var editorState = editor._latestEditorState;
  11255. var currentSelection = editorState.getSelection();
  11256. if (!currentSelection.getHasFocus()) {
  11257. return;
  11258. }
  11259. var selection = currentSelection.set('hasFocus', false);
  11260. editor.props.onBlur && editor.props.onBlur(e);
  11261. editor.update(EditorState_1.acceptSelection(editorState, selection));
  11262. }
  11263. var editOnBlur_1 = editOnBlur;
  11264. /**
  11265. * The user has begun using an IME input system. Switching to `composite` mode
  11266. * allows handling composition input and disables other edit behavior.
  11267. */
  11268. function editOnCompositionStart(editor, e) {
  11269. editor.setMode('composite');
  11270. editor.update(EditorState_1.set(editor._latestEditorState, { inCompositionMode: true }));
  11271. // Allow composition handler to interpret the compositionstart event
  11272. editor._onCompositionStart(e);
  11273. }
  11274. var editOnCompositionStart_1 = editOnCompositionStart;
  11275. function getFragmentFromSelection(editorState) {
  11276. var selectionState = editorState.getSelection();
  11277. if (selectionState.isCollapsed()) {
  11278. return null;
  11279. }
  11280. return getContentStateFragment_1(editorState.getCurrentContent(), selectionState);
  11281. }
  11282. var getFragmentFromSelection_1 = getFragmentFromSelection;
  11283. /**
  11284. * If we have a selection, create a ContentState fragment and store
  11285. * it in our internal clipboard. Subsequent paste events will use this
  11286. * fragment if no external clipboard data is supplied.
  11287. */
  11288. function editOnCopy(editor, e) {
  11289. var editorState = editor._latestEditorState;
  11290. var selection = editorState.getSelection();
  11291. // No selection, so there's nothing to copy.
  11292. if (selection.isCollapsed()) {
  11293. e.preventDefault();
  11294. return;
  11295. }
  11296. editor.setClipboard(getFragmentFromSelection_1(editor._latestEditorState));
  11297. }
  11298. var editOnCopy_1 = editOnCopy;
  11299. /**
  11300. * On `cut` events, native behavior is allowed to occur so that the system
  11301. * clipboard is set properly. This means that we need to take steps to recover
  11302. * the editor DOM state after the `cut` has occurred in order to maintain
  11303. * control of the component.
  11304. *
  11305. * In addition, we can keep a copy of the removed fragment, including all
  11306. * styles and entities, for use as an internal paste.
  11307. */
  11308. function editOnCut(editor, e) {
  11309. var editorState = editor._latestEditorState;
  11310. var selection = editorState.getSelection();
  11311. var element = e.target;
  11312. var scrollPosition = void 0;
  11313. // No selection, so there's nothing to cut.
  11314. if (selection.isCollapsed()) {
  11315. e.preventDefault();
  11316. return;
  11317. }
  11318. // Track the current scroll position so that it can be forced back in place
  11319. // after the editor regains control of the DOM.
  11320. if (element instanceof Node) {
  11321. scrollPosition = getScrollPosition_1(Style_1.getScrollParent(element));
  11322. }
  11323. var fragment = getFragmentFromSelection_1(editorState);
  11324. editor.setClipboard(fragment);
  11325. // Set `cut` mode to disable all event handling temporarily.
  11326. editor.setMode('cut');
  11327. // Let native `cut` behavior occur, then recover control.
  11328. setTimeout(function () {
  11329. editor.restoreEditorDOM(scrollPosition);
  11330. editor.exitCurrentMode();
  11331. editor.update(removeFragment(editorState));
  11332. }, 0);
  11333. }
  11334. function removeFragment(editorState) {
  11335. var newContent = DraftModifier_1.removeRange(editorState.getCurrentContent(), editorState.getSelection(), 'forward');
  11336. return EditorState_1.push(editorState, newContent, 'remove-range');
  11337. }
  11338. var editOnCut_1 = editOnCut;
  11339. /**
  11340. * Copyright (c) 2013-present, Facebook, Inc.
  11341. * All rights reserved.
  11342. *
  11343. * This source code is licensed under the BSD-style license found in the
  11344. * LICENSE file in the root directory of this source tree. An additional grant
  11345. * of patent rights can be found in the PATENTS file in the same directory.
  11346. *
  11347. * @providesModule editOnDragOver
  11348. * @format
  11349. *
  11350. */
  11351. /**
  11352. * Drag behavior has begun from outside the editor element.
  11353. */
  11354. function editOnDragOver(editor, e) {
  11355. editor._internalDrag = false;
  11356. editor.setMode('drag');
  11357. e.preventDefault();
  11358. }
  11359. var editOnDragOver_1 = editOnDragOver;
  11360. /**
  11361. * Copyright (c) 2013-present, Facebook, Inc.
  11362. * All rights reserved.
  11363. *
  11364. * This source code is licensed under the BSD-style license found in the
  11365. * LICENSE file in the root directory of this source tree. An additional grant
  11366. * of patent rights can be found in the PATENTS file in the same directory.
  11367. *
  11368. * @providesModule editOnDragStart
  11369. * @format
  11370. *
  11371. */
  11372. /**
  11373. * A `dragstart` event has begun within the text editor component.
  11374. */
  11375. function editOnDragStart(editor) {
  11376. editor._internalDrag = true;
  11377. editor.setMode('drag');
  11378. }
  11379. var editOnDragStart_1 = editOnDragStart;
  11380. function editOnFocus(editor, e) {
  11381. var editorState = editor._latestEditorState;
  11382. var currentSelection = editorState.getSelection();
  11383. if (currentSelection.getHasFocus()) {
  11384. return;
  11385. }
  11386. var selection = currentSelection.set('hasFocus', true);
  11387. editor.props.onFocus && editor.props.onFocus(e);
  11388. // When the tab containing this text editor is hidden and the user does a
  11389. // find-in-page in a _different_ tab, Chrome on Mac likes to forget what the
  11390. // selection was right after sending this focus event and (if you let it)
  11391. // moves the cursor back to the beginning of the editor, so we force the
  11392. // selection here instead of simply accepting it in order to preserve the
  11393. // old cursor position. See https://crbug.com/540004.
  11394. // But it looks like this is fixed in Chrome 60.0.3081.0.
  11395. // Other browsers also don't have this bug, so we prefer to acceptSelection
  11396. // when possible, to ensure that unfocusing and refocusing a Draft editor
  11397. // doesn't preserve the selection, matching how textareas work.
  11398. if (UserAgent_1.isBrowser('Chrome < 60.0.3081.0')) {
  11399. editor.update(EditorState_1.forceSelection(editorState, selection));
  11400. } else {
  11401. editor.update(EditorState_1.acceptSelection(editorState, selection));
  11402. }
  11403. }
  11404. var editOnFocus_1 = editOnFocus;
  11405. var isGecko = UserAgent_1.isEngine('Gecko');
  11406. var DOUBLE_NEWLINE = '\n\n';
  11407. /**
  11408. * This function is intended to handle spellcheck and autocorrect changes,
  11409. * which occur in the DOM natively without any opportunity to observe or
  11410. * interpret the changes before they occur.
  11411. *
  11412. * The `input` event fires in contentEditable elements reliably for non-IE
  11413. * browsers, immediately after changes occur to the editor DOM. Since our other
  11414. * handlers override or otherwise handle cover other varieties of text input,
  11415. * the DOM state should match the model in all controlled input cases. Thus,
  11416. * when an `input` change leads to a DOM/model mismatch, the change should be
  11417. * due to a spellcheck change, and we can incorporate it into our model.
  11418. */
  11419. function editOnInput(editor) {
  11420. if (editor._pendingStateFromBeforeInput !== undefined) {
  11421. editor.update(editor._pendingStateFromBeforeInput);
  11422. editor._pendingStateFromBeforeInput = undefined;
  11423. }
  11424. var domSelection = commonjsGlobal.getSelection();
  11425. var anchorNode = domSelection.anchorNode,
  11426. isCollapsed = domSelection.isCollapsed;
  11427. var isNotTextNode = anchorNode.nodeType !== Node.TEXT_NODE;
  11428. var isNotTextOrElementNode = anchorNode.nodeType !== Node.TEXT_NODE && anchorNode.nodeType !== Node.ELEMENT_NODE;
  11429. {
  11430. if (isNotTextOrElementNode) {
  11431. // TODO: (t16149272) figure out context for this change
  11432. return;
  11433. }
  11434. }
  11435. if (anchorNode.nodeType === Node.TEXT_NODE && (anchorNode.previousSibling !== null || anchorNode.nextSibling !== null)) {
  11436. // When typing at the beginning of a visual line, Chrome splits the text
  11437. // nodes into two. Why? No one knows. This commit is suspicious:
  11438. // https://chromium.googlesource.com/chromium/src/+/a3b600981286b135632371477f902214c55a1724
  11439. // To work around, we'll merge the sibling text nodes back into this one.
  11440. var span = anchorNode.parentNode;
  11441. anchorNode.nodeValue = span.textContent;
  11442. for (var child = span.firstChild; child !== null; child = child.nextSibling) {
  11443. if (child !== anchorNode) {
  11444. span.removeChild(child);
  11445. }
  11446. }
  11447. }
  11448. var domText = anchorNode.textContent;
  11449. var editorState = editor._latestEditorState;
  11450. var offsetKey = nullthrows_1(findAncestorOffsetKey_1(anchorNode));
  11451. var _DraftOffsetKey$decod = DraftOffsetKey_1.decode(offsetKey),
  11452. blockKey = _DraftOffsetKey$decod.blockKey,
  11453. decoratorKey = _DraftOffsetKey$decod.decoratorKey,
  11454. leafKey = _DraftOffsetKey$decod.leafKey;
  11455. var _editorState$getBlock = editorState.getBlockTree(blockKey).getIn([decoratorKey, 'leaves', leafKey]),
  11456. start = _editorState$getBlock.start,
  11457. end = _editorState$getBlock.end;
  11458. var content = editorState.getCurrentContent();
  11459. var block = content.getBlockForKey(blockKey);
  11460. var modelText = block.getText().slice(start, end);
  11461. // Special-case soft newlines here. If the DOM text ends in a soft newline,
  11462. // we will have manually inserted an extra soft newline in DraftEditorLeaf.
  11463. // We want to remove this extra newline for the purpose of our comparison
  11464. // of DOM and model text.
  11465. if (domText.endsWith(DOUBLE_NEWLINE)) {
  11466. domText = domText.slice(0, -1);
  11467. }
  11468. // No change -- the DOM is up to date. Nothing to do here.
  11469. if (domText === modelText) {
  11470. // This can be buggy for some Android keyboards because they don't fire
  11471. // standard onkeydown/pressed events and only fired editOnInput
  11472. // so domText is already changed by the browser and ends up being equal
  11473. // to modelText unexpectedly
  11474. return;
  11475. }
  11476. var selection = editorState.getSelection();
  11477. // We'll replace the entire leaf with the text content of the target.
  11478. var targetRange = selection.merge({
  11479. anchorOffset: start,
  11480. focusOffset: end,
  11481. isBackward: false
  11482. });
  11483. var entityKey = block.getEntityAt(start);
  11484. var entity = entityKey && content.getEntity(entityKey);
  11485. var entityType = entity && entity.getMutability();
  11486. var preserveEntity = entityType === 'MUTABLE';
  11487. // Immutable or segmented entities cannot properly be handled by the
  11488. // default browser undo, so we have to use a different change type to
  11489. // force using our internal undo method instead of falling through to the
  11490. // native browser undo.
  11491. var changeType = preserveEntity ? 'spellcheck-change' : 'apply-entity';
  11492. var newContent = DraftModifier_1.replaceText(content, targetRange, domText, block.getInlineStyleAt(start), preserveEntity ? block.getEntityAt(start) : null);
  11493. var anchorOffset, focusOffset, startOffset, endOffset;
  11494. if (isGecko) {
  11495. // Firefox selection does not change while the context menu is open, so
  11496. // we preserve the anchor and focus values of the DOM selection.
  11497. anchorOffset = domSelection.anchorOffset;
  11498. focusOffset = domSelection.focusOffset;
  11499. startOffset = start + Math.min(anchorOffset, focusOffset);
  11500. endOffset = startOffset + Math.abs(anchorOffset - focusOffset);
  11501. anchorOffset = startOffset;
  11502. focusOffset = endOffset;
  11503. } else {
  11504. // Browsers other than Firefox may adjust DOM selection while the context
  11505. // menu is open, and Safari autocorrect is prone to providing an inaccurate
  11506. // DOM selection. Don't trust it. Instead, use our existing SelectionState
  11507. // and adjust it based on the number of characters changed during the
  11508. // mutation.
  11509. var charDelta = domText.length - modelText.length;
  11510. startOffset = selection.getStartOffset();
  11511. endOffset = selection.getEndOffset();
  11512. anchorOffset = isCollapsed ? endOffset + charDelta : startOffset;
  11513. focusOffset = endOffset + charDelta;
  11514. }
  11515. // Segmented entities are completely or partially removed when their
  11516. // text content changes. For this case we do not want any text to be selected
  11517. // after the change, so we are not merging the selection.
  11518. var contentWithAdjustedDOMSelection = newContent.merge({
  11519. selectionBefore: content.getSelectionAfter(),
  11520. selectionAfter: selection.merge({ anchorOffset: anchorOffset, focusOffset: focusOffset })
  11521. });
  11522. editor.update(EditorState_1.push(editorState, contentWithAdjustedDOMSelection, changeType));
  11523. }
  11524. var editOnInput_1 = editOnInput;
  11525. var isOSX = UserAgent_1.isPlatform('Mac OS X');
  11526. var KeyBindingUtil = {
  11527. /**
  11528. * Check whether the ctrlKey modifier is *not* being used in conjunction with
  11529. * the altKey modifier. If they are combined, the result is an `altGraph`
  11530. * key modifier, which should not be handled by this set of key bindings.
  11531. */
  11532. isCtrlKeyCommand: function isCtrlKeyCommand(e) {
  11533. return !!e.ctrlKey && !e.altKey;
  11534. },
  11535. isOptionKeyCommand: function isOptionKeyCommand(e) {
  11536. return isOSX && e.altKey;
  11537. },
  11538. hasCommandModifier: function hasCommandModifier(e) {
  11539. return isOSX ? !!e.metaKey && !e.altKey : KeyBindingUtil.isCtrlKeyCommand(e);
  11540. }
  11541. };
  11542. var KeyBindingUtil_1 = KeyBindingUtil;
  11543. var clipboard = null;
  11544. /**
  11545. * Some systems offer a "secondary" clipboard to allow quick internal cut
  11546. * and paste behavior. For instance, Ctrl+K (cut) and Ctrl+Y (paste).
  11547. */
  11548. var SecondaryClipboard = {
  11549. cut: function cut(editorState) {
  11550. var content = editorState.getCurrentContent();
  11551. var selection = editorState.getSelection();
  11552. var targetRange = null;
  11553. if (selection.isCollapsed()) {
  11554. var anchorKey = selection.getAnchorKey();
  11555. var blockEnd = content.getBlockForKey(anchorKey).getLength();
  11556. if (blockEnd === selection.getAnchorOffset()) {
  11557. return editorState;
  11558. }
  11559. targetRange = selection.set('focusOffset', blockEnd);
  11560. } else {
  11561. targetRange = selection;
  11562. }
  11563. targetRange = nullthrows_1(targetRange);
  11564. clipboard = getContentStateFragment_1(content, targetRange);
  11565. var afterRemoval = DraftModifier_1.removeRange(content, targetRange, 'forward');
  11566. if (afterRemoval === content) {
  11567. return editorState;
  11568. }
  11569. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  11570. },
  11571. paste: function paste(editorState) {
  11572. if (!clipboard) {
  11573. return editorState;
  11574. }
  11575. var newContent = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), clipboard);
  11576. return EditorState_1.push(editorState, newContent, 'insert-fragment');
  11577. }
  11578. };
  11579. var SecondaryClipboard_1 = SecondaryClipboard;
  11580. // These two ranges are consecutive so anything in [HIGH_START, LOW_END] is a
  11581. // surrogate code unit.
  11582. var SURROGATE_HIGH_START = 0xD800;
  11583. var SURROGATE_HIGH_END = 0xDBFF;
  11584. var SURROGATE_LOW_START = 0xDC00;
  11585. var SURROGATE_LOW_END = 0xDFFF;
  11586. var SURROGATE_UNITS_REGEX = /[\uD800-\uDFFF]/;
  11587. /**
  11588. * @param {number} codeUnit A Unicode code-unit, in range [0, 0x10FFFF]
  11589. * @return {boolean} Whether code-unit is in a surrogate (hi/low) range
  11590. */
  11591. function isCodeUnitInSurrogateRange(codeUnit) {
  11592. return SURROGATE_HIGH_START <= codeUnit && codeUnit <= SURROGATE_LOW_END;
  11593. }
  11594. /**
  11595. * Returns whether the two characters starting at `index` form a surrogate pair.
  11596. * For example, given the string s = "\uD83D\uDE0A", (s, 0) returns true and
  11597. * (s, 1) returns false.
  11598. *
  11599. * @param {string} str
  11600. * @param {number} index
  11601. * @return {boolean}
  11602. */
  11603. function isSurrogatePair(str, index) {
  11604. !(0 <= index && index < str.length) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'isSurrogatePair: Invalid index %s for string length %s.', index, str.length) : invariant_1(false) : void 0;
  11605. if (index + 1 === str.length) {
  11606. return false;
  11607. }
  11608. var first = str.charCodeAt(index);
  11609. var second = str.charCodeAt(index + 1);
  11610. return SURROGATE_HIGH_START <= first && first <= SURROGATE_HIGH_END && SURROGATE_LOW_START <= second && second <= SURROGATE_LOW_END;
  11611. }
  11612. /**
  11613. * @param {string} str Non-empty string
  11614. * @return {boolean} True if the input includes any surrogate code units
  11615. */
  11616. function hasSurrogateUnit(str) {
  11617. return SURROGATE_UNITS_REGEX.test(str);
  11618. }
  11619. /**
  11620. * Return the length of the original Unicode character at given position in the
  11621. * String by looking into the UTF-16 code unit; that is equal to 1 for any
  11622. * non-surrogate characters in BMP ([U+0000..U+D7FF] and [U+E000, U+FFFF]); and
  11623. * returns 2 for the hi/low surrogates ([U+D800..U+DFFF]), which are in fact
  11624. * representing non-BMP characters ([U+10000..U+10FFFF]).
  11625. *
  11626. * Examples:
  11627. * - '\u0020' => 1
  11628. * - '\u3020' => 1
  11629. * - '\uD835' => 2
  11630. * - '\uD835\uDDEF' => 2
  11631. * - '\uDDEF' => 2
  11632. *
  11633. * @param {string} str Non-empty string
  11634. * @param {number} pos Position in the string to look for one code unit
  11635. * @return {number} Number 1 or 2
  11636. */
  11637. function getUTF16Length(str, pos) {
  11638. return 1 + isCodeUnitInSurrogateRange(str.charCodeAt(pos));
  11639. }
  11640. /**
  11641. * Fully Unicode-enabled replacement for String#length
  11642. *
  11643. * @param {string} str Valid Unicode string
  11644. * @return {number} The number of Unicode characters in the string
  11645. */
  11646. function strlen(str) {
  11647. // Call the native functions if there's no surrogate char
  11648. if (!hasSurrogateUnit(str)) {
  11649. return str.length;
  11650. }
  11651. var len = 0;
  11652. for (var pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
  11653. len++;
  11654. }
  11655. return len;
  11656. }
  11657. /**
  11658. * Fully Unicode-enabled replacement for String#substr()
  11659. *
  11660. * @param {string} str Valid Unicode string
  11661. * @param {number} start Location in Unicode sequence to begin extracting
  11662. * @param {?number} length The number of Unicode characters to extract
  11663. * (default: to the end of the string)
  11664. * @return {string} Extracted sub-string
  11665. */
  11666. function substr(str, start, length) {
  11667. start = start || 0;
  11668. length = length === undefined ? Infinity : length || 0;
  11669. // Call the native functions if there's no surrogate char
  11670. if (!hasSurrogateUnit(str)) {
  11671. return str.substr(start, length);
  11672. }
  11673. // Obvious cases
  11674. var size = str.length;
  11675. if (size <= 0 || start > size || length <= 0) {
  11676. return '';
  11677. }
  11678. // Find the actual starting position
  11679. var posA = 0;
  11680. if (start > 0) {
  11681. for (; start > 0 && posA < size; start--) {
  11682. posA += getUTF16Length(str, posA);
  11683. }
  11684. if (posA >= size) {
  11685. return '';
  11686. }
  11687. } else if (start < 0) {
  11688. for (posA = size; start < 0 && 0 < posA; start++) {
  11689. posA -= getUTF16Length(str, posA - 1);
  11690. }
  11691. if (posA < 0) {
  11692. posA = 0;
  11693. }
  11694. }
  11695. // Find the actual ending position
  11696. var posB = size;
  11697. if (length < size) {
  11698. for (posB = posA; length > 0 && posB < size; length--) {
  11699. posB += getUTF16Length(str, posB);
  11700. }
  11701. }
  11702. return str.substring(posA, posB);
  11703. }
  11704. /**
  11705. * Fully Unicode-enabled replacement for String#substring()
  11706. *
  11707. * @param {string} str Valid Unicode string
  11708. * @param {number} start Location in Unicode sequence to begin extracting
  11709. * @param {?number} end Location in Unicode sequence to end extracting
  11710. * (default: end of the string)
  11711. * @return {string} Extracted sub-string
  11712. */
  11713. function substring(str, start, end) {
  11714. start = start || 0;
  11715. end = end === undefined ? Infinity : end || 0;
  11716. if (start < 0) {
  11717. start = 0;
  11718. }
  11719. if (end < 0) {
  11720. end = 0;
  11721. }
  11722. var length = Math.abs(end - start);
  11723. start = start < end ? start : end;
  11724. return substr(str, start, length);
  11725. }
  11726. /**
  11727. * Get a list of Unicode code-points from a String
  11728. *
  11729. * @param {string} str Valid Unicode string
  11730. * @return {array<number>} A list of code-points in [0..0x10FFFF]
  11731. */
  11732. function getCodePoints(str) {
  11733. var codePoints = [];
  11734. for (var pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
  11735. codePoints.push(str.codePointAt(pos));
  11736. }
  11737. return codePoints;
  11738. }
  11739. var UnicodeUtils = {
  11740. getCodePoints: getCodePoints,
  11741. getUTF16Length: getUTF16Length,
  11742. hasSurrogateUnit: hasSurrogateUnit,
  11743. isCodeUnitInSurrogateRange: isCodeUnitInSurrogateRange,
  11744. isSurrogatePair: isSurrogatePair,
  11745. strlen: strlen,
  11746. substring: substring,
  11747. substr: substr
  11748. };
  11749. var UnicodeUtils_1 = UnicodeUtils;
  11750. var isChrome = UserAgent_1.isBrowser('Chrome');
  11751. // In Chrome, the client rects will include the entire bounds of all nodes that
  11752. // begin (have a start tag) within the selection, even if the selection does
  11753. // not overlap the entire node. To resolve this, we split the range at each
  11754. // start tag and join the client rects together.
  11755. // https://code.google.com/p/chromium/issues/detail?id=324437
  11756. /* eslint-disable consistent-return */
  11757. function getRangeClientRectsChrome(range) {
  11758. var tempRange = range.cloneRange();
  11759. var clientRects = [];
  11760. for (var ancestor = range.endContainer; ancestor != null; ancestor = ancestor.parentNode) {
  11761. // If we've climbed up to the common ancestor, we can now use the
  11762. // original start point and stop climbing the tree.
  11763. var atCommonAncestor = ancestor === range.commonAncestorContainer;
  11764. if (atCommonAncestor) {
  11765. tempRange.setStart(range.startContainer, range.startOffset);
  11766. } else {
  11767. tempRange.setStart(tempRange.endContainer, 0);
  11768. }
  11769. var rects = Array.from(tempRange.getClientRects());
  11770. clientRects.push(rects);
  11771. if (atCommonAncestor) {
  11772. var _ref;
  11773. clientRects.reverse();
  11774. return (_ref = []).concat.apply(_ref, clientRects);
  11775. }
  11776. tempRange.setEndBefore(ancestor);
  11777. }
  11778. process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Found an unexpected detached subtree when getting range client rects.') : invariant_1(false) ;
  11779. }
  11780. /* eslint-enable consistent-return */
  11781. /**
  11782. * Like range.getClientRects() but normalizes for browser bugs.
  11783. */
  11784. var getRangeClientRects = isChrome ? getRangeClientRectsChrome : function (range) {
  11785. return Array.from(range.getClientRects());
  11786. };
  11787. var getRangeClientRects_1 = getRangeClientRects;
  11788. /**
  11789. * Copyright (c) 2013-present, Facebook, Inc.
  11790. * All rights reserved.
  11791. *
  11792. * This source code is licensed under the BSD-style license found in the
  11793. * LICENSE file in the root directory of this source tree. An additional grant
  11794. * of patent rights can be found in the PATENTS file in the same directory.
  11795. *
  11796. * @providesModule expandRangeToStartOfLine
  11797. * @format
  11798. *
  11799. */
  11800. /**
  11801. * Return the computed line height, in pixels, for the provided element.
  11802. */
  11803. function getLineHeightPx(element) {
  11804. var computed = getComputedStyle(element);
  11805. var div = document.createElement('div');
  11806. div.style.fontFamily = computed.fontFamily;
  11807. div.style.fontSize = computed.fontSize;
  11808. div.style.fontStyle = computed.fontStyle;
  11809. div.style.fontWeight = computed.fontWeight;
  11810. div.style.lineHeight = computed.lineHeight;
  11811. div.style.position = 'absolute';
  11812. div.textContent = 'M';
  11813. var documentBody = document.body;
  11814. !documentBody ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing document.body') : invariant_1(false) : void 0;
  11815. // forced layout here
  11816. documentBody.appendChild(div);
  11817. var rect = div.getBoundingClientRect();
  11818. documentBody.removeChild(div);
  11819. return rect.height;
  11820. }
  11821. /**
  11822. * Return whether every ClientRect in the provided list lies on the same line.
  11823. *
  11824. * We assume that the rects on the same line all contain the baseline, so the
  11825. * lowest top line needs to be above the highest bottom line (i.e., if you were
  11826. * to project the rects onto the y-axis, their intersection would be nonempty).
  11827. *
  11828. * In addition, we require that no two boxes are lineHeight (or more) apart at
  11829. * either top or bottom, which helps protect against false positives for fonts
  11830. * with extremely large glyph heights (e.g., with a font size of 17px, Zapfino
  11831. * produces rects of height 58px!).
  11832. */
  11833. function areRectsOnOneLine(rects, lineHeight) {
  11834. var minTop = Infinity;
  11835. var minBottom = Infinity;
  11836. var maxTop = -Infinity;
  11837. var maxBottom = -Infinity;
  11838. for (var ii = 0; ii < rects.length; ii++) {
  11839. var rect = rects[ii];
  11840. if (rect.width === 0 || rect.width === 1) {
  11841. // When a range starts or ends a soft wrap, many browsers (Chrome, IE,
  11842. // Safari) include an empty rect on the previous or next line. When the
  11843. // text lies in a container whose position is not integral (e.g., from
  11844. // margin: auto), Safari makes these empty rects have width 1 (instead of
  11845. // 0). Having one-pixel-wide characters seems unlikely (and most browsers
  11846. // report widths in subpixel precision anyway) so it's relatively safe to
  11847. // skip over them.
  11848. continue;
  11849. }
  11850. minTop = Math.min(minTop, rect.top);
  11851. minBottom = Math.min(minBottom, rect.bottom);
  11852. maxTop = Math.max(maxTop, rect.top);
  11853. maxBottom = Math.max(maxBottom, rect.bottom);
  11854. }
  11855. return maxTop <= minBottom && maxTop - minTop < lineHeight && maxBottom - minBottom < lineHeight;
  11856. }
  11857. /**
  11858. * Return the length of a node, as used by Range offsets.
  11859. */
  11860. function getNodeLength$1(node) {
  11861. // http://www.w3.org/TR/dom/#concept-node-length
  11862. switch (node.nodeType) {
  11863. case Node.DOCUMENT_TYPE_NODE:
  11864. return 0;
  11865. case Node.TEXT_NODE:
  11866. case Node.PROCESSING_INSTRUCTION_NODE:
  11867. case Node.COMMENT_NODE:
  11868. return node.length;
  11869. default:
  11870. return node.childNodes.length;
  11871. }
  11872. }
  11873. /**
  11874. * Given a collapsed range, move the start position backwards as far as
  11875. * possible while the range still spans only a single line.
  11876. */
  11877. function expandRangeToStartOfLine(range) {
  11878. !range.collapsed ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'expandRangeToStartOfLine: Provided range is not collapsed.') : invariant_1(false) : void 0;
  11879. range = range.cloneRange();
  11880. var containingElement = range.startContainer;
  11881. if (containingElement.nodeType !== 1) {
  11882. containingElement = containingElement.parentNode;
  11883. }
  11884. var lineHeight = getLineHeightPx(containingElement);
  11885. // Imagine our text looks like:
  11886. // <div><span>once upon a time, there was a <em>boy
  11887. // who lived</em> </span><q><strong>under^ the
  11888. // stairs</strong> in a small closet.</q></div>
  11889. // where the caret represents the cursor. First, we crawl up the tree until
  11890. // the range spans multiple lines (setting the start point to before
  11891. // "<strong>", then before "<div>"), then at each level we do a search to
  11892. // find the latest point which is still on a previous line. We'll find that
  11893. // the break point is inside the span, then inside the <em>, then in its text
  11894. // node child, the actual break point before "who".
  11895. var bestContainer = range.endContainer;
  11896. var bestOffset = range.endOffset;
  11897. range.setStart(range.startContainer, 0);
  11898. while (areRectsOnOneLine(getRangeClientRects_1(range), lineHeight)) {
  11899. bestContainer = range.startContainer;
  11900. bestOffset = range.startOffset;
  11901. !bestContainer.parentNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Found unexpected detached subtree when traversing.') : invariant_1(false) : void 0;
  11902. range.setStartBefore(bestContainer);
  11903. if (bestContainer.nodeType === 1 && getComputedStyle(bestContainer).display !== 'inline') {
  11904. // The start of the line is never in a different block-level container.
  11905. break;
  11906. }
  11907. }
  11908. // In the above example, range now spans from "<div>" to "under",
  11909. // bestContainer is <div>, and bestOffset is 1 (index of <q> inside <div>)].
  11910. // Picking out which child to recurse into here is a special case since we
  11911. // don't want to check past <q> -- once we find that the final range starts
  11912. // in <span>, we can look at all of its children (and all of their children)
  11913. // to find the break point.
  11914. // At all times, (bestContainer, bestOffset) is the latest single-line start
  11915. // point that we know of.
  11916. var currentContainer = bestContainer;
  11917. var maxIndexToConsider = bestOffset - 1;
  11918. do {
  11919. var nodeValue = currentContainer.nodeValue;
  11920. for (var ii = maxIndexToConsider; ii >= 0; ii--) {
  11921. if (nodeValue != null && ii > 0 && UnicodeUtils_1.isSurrogatePair(nodeValue, ii - 1)) {
  11922. // We're in the middle of a surrogate pair -- skip over so we never
  11923. // return a range with an endpoint in the middle of a code point.
  11924. continue;
  11925. }
  11926. range.setStart(currentContainer, ii);
  11927. if (areRectsOnOneLine(getRangeClientRects_1(range), lineHeight)) {
  11928. bestContainer = currentContainer;
  11929. bestOffset = ii;
  11930. } else {
  11931. break;
  11932. }
  11933. }
  11934. if (ii === -1 || currentContainer.childNodes.length === 0) {
  11935. // If ii === -1, then (bestContainer, bestOffset), which is equal to
  11936. // (currentContainer, 0), was a single-line start point but a start
  11937. // point before currentContainer wasn't, so the line break seems to
  11938. // have occurred immediately after currentContainer's start tag
  11939. //
  11940. // If currentContainer.childNodes.length === 0, we're already at a
  11941. // terminal node (e.g., text node) and should return our current best.
  11942. break;
  11943. }
  11944. currentContainer = currentContainer.childNodes[ii];
  11945. maxIndexToConsider = getNodeLength$1(currentContainer);
  11946. } while (true);
  11947. range.setStart(bestContainer, bestOffset);
  11948. return range;
  11949. }
  11950. var expandRangeToStartOfLine_1 = expandRangeToStartOfLine;
  11951. /**
  11952. * Convert the current selection range to an anchor/focus pair of offset keys
  11953. * and values that can be interpreted by components.
  11954. */
  11955. function getDraftEditorSelectionWithNodes(editorState, root, anchorNode, anchorOffset, focusNode, focusOffset) {
  11956. var anchorIsTextNode = anchorNode.nodeType === Node.TEXT_NODE;
  11957. var focusIsTextNode = focusNode.nodeType === Node.TEXT_NODE;
  11958. // If the selection range lies only on text nodes, the task is simple.
  11959. // Find the nearest offset-aware elements and use the
  11960. // offset values supplied by the selection range.
  11961. if (anchorIsTextNode && focusIsTextNode) {
  11962. return {
  11963. selectionState: getUpdatedSelectionState_1(editorState, nullthrows_1(findAncestorOffsetKey_1(anchorNode)), anchorOffset, nullthrows_1(findAncestorOffsetKey_1(focusNode)), focusOffset),
  11964. needsRecovery: false
  11965. };
  11966. }
  11967. var anchorPoint = null;
  11968. var focusPoint = null;
  11969. var needsRecovery = true;
  11970. // An element is selected. Convert this selection range into leaf offset
  11971. // keys and offset values for consumption at the component level. This
  11972. // is common in Firefox, where select-all and triple click behavior leads
  11973. // to entire elements being selected.
  11974. //
  11975. // Note that we use the `needsRecovery` parameter in the callback here. This
  11976. // is because when certain elements are selected, the behavior for subsequent
  11977. // cursor movement (e.g. via arrow keys) is uncertain and may not match
  11978. // expectations at the component level. For example, if an entire <div> is
  11979. // selected and the user presses the right arrow, Firefox keeps the selection
  11980. // on the <div>. If we allow subsequent keypresses to insert characters
  11981. // natively, they will be inserted into a browser-created text node to the
  11982. // right of that <div>. This is obviously undesirable.
  11983. //
  11984. // With the `needsRecovery` flag, we inform the caller that it is responsible
  11985. // for manually setting the selection state on the rendered document to
  11986. // ensure proper selection state maintenance.
  11987. if (anchorIsTextNode) {
  11988. anchorPoint = {
  11989. key: nullthrows_1(findAncestorOffsetKey_1(anchorNode)),
  11990. offset: anchorOffset
  11991. };
  11992. focusPoint = getPointForNonTextNode(root, focusNode, focusOffset);
  11993. } else if (focusIsTextNode) {
  11994. focusPoint = {
  11995. key: nullthrows_1(findAncestorOffsetKey_1(focusNode)),
  11996. offset: focusOffset
  11997. };
  11998. anchorPoint = getPointForNonTextNode(root, anchorNode, anchorOffset);
  11999. } else {
  12000. anchorPoint = getPointForNonTextNode(root, anchorNode, anchorOffset);
  12001. focusPoint = getPointForNonTextNode(root, focusNode, focusOffset);
  12002. // If the selection is collapsed on an empty block, don't force recovery.
  12003. // This way, on arrow key selection changes, the browser can move the
  12004. // cursor from a non-zero offset on one block, through empty blocks,
  12005. // to a matching non-zero offset on other text blocks.
  12006. if (anchorNode === focusNode && anchorOffset === focusOffset) {
  12007. needsRecovery = !!anchorNode.firstChild && anchorNode.firstChild.nodeName !== 'BR';
  12008. }
  12009. }
  12010. return {
  12011. selectionState: getUpdatedSelectionState_1(editorState, anchorPoint.key, anchorPoint.offset, focusPoint.key, focusPoint.offset),
  12012. needsRecovery: needsRecovery
  12013. };
  12014. }
  12015. /**
  12016. * Identify the first leaf descendant for the given node.
  12017. */
  12018. function getFirstLeaf(node) {
  12019. while (node.firstChild && (
  12020. // data-blocks has no offset
  12021. node.firstChild instanceof Element && node.firstChild.getAttribute('data-blocks') === 'true' || getSelectionOffsetKeyForNode_1(node.firstChild))) {
  12022. node = node.firstChild;
  12023. }
  12024. return node;
  12025. }
  12026. /**
  12027. * Identify the last leaf descendant for the given node.
  12028. */
  12029. function getLastLeaf(node) {
  12030. while (node.lastChild && (
  12031. // data-blocks has no offset
  12032. node.lastChild instanceof Element && node.lastChild.getAttribute('data-blocks') === 'true' || getSelectionOffsetKeyForNode_1(node.lastChild))) {
  12033. node = node.lastChild;
  12034. }
  12035. return node;
  12036. }
  12037. function getPointForNonTextNode(editorRoot, startNode, childOffset) {
  12038. var node = startNode;
  12039. var offsetKey = findAncestorOffsetKey_1(node);
  12040. !(offsetKey != null || editorRoot && (editorRoot === node || editorRoot.firstChild === node)) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Unknown node in selection range.') : invariant_1(false) : void 0;
  12041. // If the editorRoot is the selection, step downward into the content
  12042. // wrapper.
  12043. if (editorRoot === node) {
  12044. node = node.firstChild;
  12045. !(node instanceof Element && node.getAttribute('data-contents') === 'true') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid DraftEditorContents structure.') : invariant_1(false) : void 0;
  12046. if (childOffset > 0) {
  12047. childOffset = node.childNodes.length;
  12048. }
  12049. }
  12050. // If the child offset is zero and we have an offset key, we're done.
  12051. // If there's no offset key because the entire editor is selected,
  12052. // find the leftmost ("first") leaf in the tree and use that as the offset
  12053. // key.
  12054. if (childOffset === 0) {
  12055. var key = null;
  12056. if (offsetKey != null) {
  12057. key = offsetKey;
  12058. } else {
  12059. var firstLeaf = getFirstLeaf(node);
  12060. key = nullthrows_1(getSelectionOffsetKeyForNode_1(firstLeaf));
  12061. }
  12062. return { key: key, offset: 0 };
  12063. }
  12064. var nodeBeforeCursor = node.childNodes[childOffset - 1];
  12065. var leafKey = null;
  12066. var textLength = null;
  12067. if (!getSelectionOffsetKeyForNode_1(nodeBeforeCursor)) {
  12068. // Our target node may be a leaf or a text node, in which case we're
  12069. // already where we want to be and can just use the child's length as
  12070. // our offset.
  12071. leafKey = nullthrows_1(offsetKey);
  12072. textLength = getTextContentLength(nodeBeforeCursor);
  12073. } else {
  12074. // Otherwise, we'll look at the child to the left of the cursor and find
  12075. // the last leaf node in its subtree.
  12076. var lastLeaf = getLastLeaf(nodeBeforeCursor);
  12077. leafKey = nullthrows_1(getSelectionOffsetKeyForNode_1(lastLeaf));
  12078. textLength = getTextContentLength(lastLeaf);
  12079. }
  12080. return {
  12081. key: leafKey,
  12082. offset: textLength
  12083. };
  12084. }
  12085. /**
  12086. * Return the length of a node's textContent, regarding single newline
  12087. * characters as zero-length. This allows us to avoid problems with identifying
  12088. * the correct selection offset for empty blocks in IE, in which we
  12089. * render newlines instead of break tags.
  12090. */
  12091. function getTextContentLength(node) {
  12092. var textContent = node.textContent;
  12093. return textContent === '\n' ? 0 : textContent.length;
  12094. }
  12095. var getDraftEditorSelectionWithNodes_1 = getDraftEditorSelectionWithNodes;
  12096. /**
  12097. * Copyright (c) 2013-present, Facebook, Inc.
  12098. * All rights reserved.
  12099. *
  12100. * This source code is licensed under the BSD-style license found in the
  12101. * LICENSE file in the root directory of this source tree. An additional grant
  12102. * of patent rights can be found in the PATENTS file in the same directory.
  12103. *
  12104. * @providesModule moveSelectionBackward
  12105. * @format
  12106. *
  12107. */
  12108. /**
  12109. * Given a collapsed selection, move the focus `maxDistance` backward within
  12110. * the selected block. If the selection will go beyond the start of the block,
  12111. * move focus to the end of the previous block, but no further.
  12112. *
  12113. * This function is not Unicode-aware, so surrogate pairs will be treated
  12114. * as having length 2.
  12115. */
  12116. function moveSelectionBackward(editorState, maxDistance) {
  12117. var selection = editorState.getSelection();
  12118. var content = editorState.getCurrentContent();
  12119. var key = selection.getStartKey();
  12120. var offset = selection.getStartOffset();
  12121. var focusKey = key;
  12122. var focusOffset = 0;
  12123. if (maxDistance > offset) {
  12124. var keyBefore = content.getKeyBefore(key);
  12125. if (keyBefore == null) {
  12126. focusKey = key;
  12127. } else {
  12128. focusKey = keyBefore;
  12129. var blockBefore = content.getBlockForKey(keyBefore);
  12130. focusOffset = blockBefore.getText().length;
  12131. }
  12132. } else {
  12133. focusOffset = offset - maxDistance;
  12134. }
  12135. return selection.merge({
  12136. focusKey: focusKey,
  12137. focusOffset: focusOffset,
  12138. isBackward: true
  12139. });
  12140. }
  12141. var moveSelectionBackward_1 = moveSelectionBackward;
  12142. /**
  12143. * For a collapsed selection state, remove text based on the specified strategy.
  12144. * If the selection state is not collapsed, remove the entire selected range.
  12145. */
  12146. function removeTextWithStrategy(editorState, strategy, direction) {
  12147. var selection = editorState.getSelection();
  12148. var content = editorState.getCurrentContent();
  12149. var target = selection;
  12150. if (selection.isCollapsed()) {
  12151. if (direction === 'forward') {
  12152. if (editorState.isSelectionAtEndOfContent()) {
  12153. return content;
  12154. }
  12155. } else if (editorState.isSelectionAtStartOfContent()) {
  12156. return content;
  12157. }
  12158. target = strategy(editorState);
  12159. if (target === selection) {
  12160. return content;
  12161. }
  12162. }
  12163. return DraftModifier_1.removeRange(content, target, direction);
  12164. }
  12165. var removeTextWithStrategy_1 = removeTextWithStrategy;
  12166. function keyCommandBackspaceToStartOfLine(editorState) {
  12167. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12168. var selection = strategyState.getSelection();
  12169. if (selection.isCollapsed() && selection.getAnchorOffset() === 0) {
  12170. return moveSelectionBackward_1(strategyState, 1);
  12171. }
  12172. var domSelection = commonjsGlobal.getSelection();
  12173. var range = domSelection.getRangeAt(0);
  12174. range = expandRangeToStartOfLine_1(range);
  12175. return getDraftEditorSelectionWithNodes_1(strategyState, null, range.endContainer, range.endOffset, range.startContainer, range.startOffset).selectionState;
  12176. }, 'backward');
  12177. if (afterRemoval === editorState.getCurrentContent()) {
  12178. return editorState;
  12179. }
  12180. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  12181. }
  12182. var keyCommandBackspaceToStartOfLine_1 = keyCommandBackspaceToStartOfLine;
  12183. /**
  12184. * Copyright (c) 2013-present, Facebook, Inc.
  12185. *
  12186. * This source code is licensed under the MIT license found in the
  12187. * LICENSE file in the root directory of this source tree.
  12188. *
  12189. * @typechecks
  12190. * @stub
  12191. *
  12192. */
  12193. // \u00a1-\u00b1\u00b4-\u00b8\u00ba\u00bb\u00bf
  12194. // is latin supplement punctuation except fractions and superscript
  12195. // numbers
  12196. // \u2010-\u2027\u2030-\u205e
  12197. // is punctuation from the general punctuation block:
  12198. // weird quotes, commas, bullets, dashes, etc.
  12199. // \u30fb\u3001\u3002\u3008-\u3011\u3014-\u301f
  12200. // is CJK punctuation
  12201. // \uff1a-\uff1f\uff01-\uff0f\uff3b-\uff40\uff5b-\uff65
  12202. // is some full-width/half-width punctuation
  12203. // \u2E2E\u061f\u066a-\u066c\u061b\u060c\u060d\uFD3e\uFD3F
  12204. // is some Arabic punctuation marks
  12205. // \u1801\u0964\u104a\u104b
  12206. // is misc. other language punctuation marks
  12207. var PUNCTUATION = '[.,+*?$|#{}()\'\\^\\-\\[\\]\\\\\\/!@%"~=<>_:;' + '\u30FB\u3001\u3002\u3008-\u3011\u3014-\u301F\uFF1A-\uFF1F\uFF01-\uFF0F' + '\uFF3B-\uFF40\uFF5B-\uFF65\u2E2E\u061F\u066A-\u066C\u061B\u060C\u060D' + '\uFD3E\uFD3F\u1801\u0964\u104A\u104B\u2010-\u2027\u2030-\u205E' + '\xA1-\xB1\xB4-\xB8\xBA\xBB\xBF]';
  12208. var TokenizeUtil = {
  12209. getPunctuation: function getPunctuation() {
  12210. return PUNCTUATION;
  12211. }
  12212. };
  12213. var punctuation = TokenizeUtil.getPunctuation();
  12214. // The apostrophe and curly single quotes behave in a curious way: when
  12215. // surrounded on both sides by word characters, they behave as word chars; when
  12216. // either neighbor is punctuation or an end of the string, they behave as
  12217. // punctuation.
  12218. var CHAMELEON_CHARS = '[\'\u2018\u2019]';
  12219. // Remove the underscore, which should count as part of the removable word. The
  12220. // "chameleon chars" also count as punctuation in this regex.
  12221. var WHITESPACE_AND_PUNCTUATION = '\\s|(?![_])' + punctuation;
  12222. var DELETE_STRING = '^' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)';
  12223. var DELETE_REGEX = new RegExp(DELETE_STRING);
  12224. var BACKSPACE_STRING = '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '$';
  12225. var BACKSPACE_REGEX = new RegExp(BACKSPACE_STRING);
  12226. function getRemovableWord(text, isBackward) {
  12227. var matches = isBackward ? BACKSPACE_REGEX.exec(text) : DELETE_REGEX.exec(text);
  12228. return matches ? matches[0] : text;
  12229. }
  12230. var DraftRemovableWord = {
  12231. getBackward: function getBackward(text) {
  12232. return getRemovableWord(text, true);
  12233. },
  12234. getForward: function getForward(text) {
  12235. return getRemovableWord(text, false);
  12236. }
  12237. };
  12238. var DraftRemovableWord_1 = DraftRemovableWord;
  12239. /**
  12240. * Delete the word that is left of the cursor, as well as any spaces or
  12241. * punctuation after the word.
  12242. */
  12243. function keyCommandBackspaceWord(editorState) {
  12244. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12245. var selection = strategyState.getSelection();
  12246. var offset = selection.getStartOffset();
  12247. // If there are no words before the cursor, remove the preceding newline.
  12248. if (offset === 0) {
  12249. return moveSelectionBackward_1(strategyState, 1);
  12250. }
  12251. var key = selection.getStartKey();
  12252. var content = strategyState.getCurrentContent();
  12253. var text = content.getBlockForKey(key).getText().slice(0, offset);
  12254. var toRemove = DraftRemovableWord_1.getBackward(text);
  12255. return moveSelectionBackward_1(strategyState, toRemove.length || 1);
  12256. }, 'backward');
  12257. if (afterRemoval === editorState.getCurrentContent()) {
  12258. return editorState;
  12259. }
  12260. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  12261. }
  12262. var keyCommandBackspaceWord_1 = keyCommandBackspaceWord;
  12263. /**
  12264. * Copyright (c) 2013-present, Facebook, Inc.
  12265. * All rights reserved.
  12266. *
  12267. * This source code is licensed under the BSD-style license found in the
  12268. * LICENSE file in the root directory of this source tree. An additional grant
  12269. * of patent rights can be found in the PATENTS file in the same directory.
  12270. *
  12271. * @providesModule moveSelectionForward
  12272. * @format
  12273. *
  12274. */
  12275. /**
  12276. * Given a collapsed selection, move the focus `maxDistance` forward within
  12277. * the selected block. If the selection will go beyond the end of the block,
  12278. * move focus to the start of the next block, but no further.
  12279. *
  12280. * This function is not Unicode-aware, so surrogate pairs will be treated
  12281. * as having length 2.
  12282. */
  12283. function moveSelectionForward(editorState, maxDistance) {
  12284. var selection = editorState.getSelection();
  12285. var key = selection.getStartKey();
  12286. var offset = selection.getStartOffset();
  12287. var content = editorState.getCurrentContent();
  12288. var focusKey = key;
  12289. var focusOffset;
  12290. var block = content.getBlockForKey(key);
  12291. if (maxDistance > block.getText().length - offset) {
  12292. focusKey = content.getKeyAfter(key);
  12293. focusOffset = 0;
  12294. } else {
  12295. focusOffset = offset + maxDistance;
  12296. }
  12297. return selection.merge({ focusKey: focusKey, focusOffset: focusOffset });
  12298. }
  12299. var moveSelectionForward_1 = moveSelectionForward;
  12300. /**
  12301. * Delete the word that is right of the cursor, as well as any spaces or
  12302. * punctuation before the word.
  12303. */
  12304. function keyCommandDeleteWord(editorState) {
  12305. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12306. var selection = strategyState.getSelection();
  12307. var offset = selection.getStartOffset();
  12308. var key = selection.getStartKey();
  12309. var content = strategyState.getCurrentContent();
  12310. var text = content.getBlockForKey(key).getText().slice(offset);
  12311. var toRemove = DraftRemovableWord_1.getForward(text);
  12312. // If there are no words in front of the cursor, remove the newline.
  12313. return moveSelectionForward_1(strategyState, toRemove.length || 1);
  12314. }, 'forward');
  12315. if (afterRemoval === editorState.getCurrentContent()) {
  12316. return editorState;
  12317. }
  12318. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  12319. }
  12320. var keyCommandDeleteWord_1 = keyCommandDeleteWord;
  12321. function keyCommandInsertNewline(editorState) {
  12322. var contentState = DraftModifier_1.splitBlock(editorState.getCurrentContent(), editorState.getSelection());
  12323. return EditorState_1.push(editorState, contentState, 'split-block');
  12324. }
  12325. var keyCommandInsertNewline_1 = keyCommandInsertNewline;
  12326. /**
  12327. * See comment for `moveSelectionToStartOfBlock`.
  12328. */
  12329. function keyCommandMoveSelectionToEndOfBlock(editorState) {
  12330. var selection = editorState.getSelection();
  12331. var endKey = selection.getEndKey();
  12332. var content = editorState.getCurrentContent();
  12333. var textLength = content.getBlockForKey(endKey).getLength();
  12334. return EditorState_1.set(editorState, {
  12335. selection: selection.merge({
  12336. anchorKey: endKey,
  12337. anchorOffset: textLength,
  12338. focusKey: endKey,
  12339. focusOffset: textLength,
  12340. isBackward: false
  12341. }),
  12342. forceSelection: true
  12343. });
  12344. }
  12345. var keyCommandMoveSelectionToEndOfBlock_1 = keyCommandMoveSelectionToEndOfBlock;
  12346. /**
  12347. * Collapse selection at the start of the first selected block. This is used
  12348. * for Firefox versions that attempt to navigate forward/backward instead of
  12349. * moving the cursor. Other browsers are able to move the cursor natively.
  12350. */
  12351. function keyCommandMoveSelectionToStartOfBlock(editorState) {
  12352. var selection = editorState.getSelection();
  12353. var startKey = selection.getStartKey();
  12354. return EditorState_1.set(editorState, {
  12355. selection: selection.merge({
  12356. anchorKey: startKey,
  12357. anchorOffset: 0,
  12358. focusKey: startKey,
  12359. focusOffset: 0,
  12360. isBackward: false
  12361. }),
  12362. forceSelection: true
  12363. });
  12364. }
  12365. var keyCommandMoveSelectionToStartOfBlock_1 = keyCommandMoveSelectionToStartOfBlock;
  12366. /**
  12367. * Remove the selected range. If the cursor is collapsed, remove the preceding
  12368. * character. This operation is Unicode-aware, so removing a single character
  12369. * will remove a surrogate pair properly as well.
  12370. */
  12371. function keyCommandPlainBackspace(editorState) {
  12372. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12373. var selection = strategyState.getSelection();
  12374. var content = strategyState.getCurrentContent();
  12375. var key = selection.getAnchorKey();
  12376. var offset = selection.getAnchorOffset();
  12377. var charBehind = content.getBlockForKey(key).getText()[offset - 1];
  12378. return moveSelectionBackward_1(strategyState, charBehind ? UnicodeUtils_1.getUTF16Length(charBehind, 0) : 1);
  12379. }, 'backward');
  12380. if (afterRemoval === editorState.getCurrentContent()) {
  12381. return editorState;
  12382. }
  12383. var selection = editorState.getSelection();
  12384. return EditorState_1.push(editorState, afterRemoval.set('selectionBefore', selection), selection.isCollapsed() ? 'backspace-character' : 'remove-range');
  12385. }
  12386. var keyCommandPlainBackspace_1 = keyCommandPlainBackspace;
  12387. /**
  12388. * Remove the selected range. If the cursor is collapsed, remove the following
  12389. * character. This operation is Unicode-aware, so removing a single character
  12390. * will remove a surrogate pair properly as well.
  12391. */
  12392. function keyCommandPlainDelete(editorState) {
  12393. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12394. var selection = strategyState.getSelection();
  12395. var content = strategyState.getCurrentContent();
  12396. var key = selection.getAnchorKey();
  12397. var offset = selection.getAnchorOffset();
  12398. var charAhead = content.getBlockForKey(key).getText()[offset];
  12399. return moveSelectionForward_1(strategyState, charAhead ? UnicodeUtils_1.getUTF16Length(charAhead, 0) : 1);
  12400. }, 'forward');
  12401. if (afterRemoval === editorState.getCurrentContent()) {
  12402. return editorState;
  12403. }
  12404. var selection = editorState.getSelection();
  12405. return EditorState_1.push(editorState, afterRemoval.set('selectionBefore', selection), selection.isCollapsed() ? 'delete-character' : 'remove-range');
  12406. }
  12407. var keyCommandPlainDelete_1 = keyCommandPlainDelete;
  12408. /**
  12409. * Transpose the characters on either side of a collapsed cursor, or
  12410. * if the cursor is at the end of the block, transpose the last two
  12411. * characters.
  12412. */
  12413. function keyCommandTransposeCharacters(editorState) {
  12414. var selection = editorState.getSelection();
  12415. if (!selection.isCollapsed()) {
  12416. return editorState;
  12417. }
  12418. var offset = selection.getAnchorOffset();
  12419. if (offset === 0) {
  12420. return editorState;
  12421. }
  12422. var blockKey = selection.getAnchorKey();
  12423. var content = editorState.getCurrentContent();
  12424. var block = content.getBlockForKey(blockKey);
  12425. var length = block.getLength();
  12426. // Nothing to transpose if there aren't two characters.
  12427. if (length <= 1) {
  12428. return editorState;
  12429. }
  12430. var removalRange;
  12431. var finalSelection;
  12432. if (offset === length) {
  12433. // The cursor is at the end of the block. Swap the last two characters.
  12434. removalRange = selection.set('anchorOffset', offset - 1);
  12435. finalSelection = selection;
  12436. } else {
  12437. removalRange = selection.set('focusOffset', offset + 1);
  12438. finalSelection = removalRange.set('anchorOffset', offset + 1);
  12439. }
  12440. // Extract the character to move as a fragment. This preserves its
  12441. // styling and entity, if any.
  12442. var movedFragment = getContentStateFragment_1(content, removalRange);
  12443. var afterRemoval = DraftModifier_1.removeRange(content, removalRange, 'backward');
  12444. // After the removal, the insertion target is one character back.
  12445. var selectionAfter = afterRemoval.getSelectionAfter();
  12446. var targetOffset = selectionAfter.getAnchorOffset() - 1;
  12447. var targetRange = selectionAfter.merge({
  12448. anchorOffset: targetOffset,
  12449. focusOffset: targetOffset
  12450. });
  12451. var afterInsert = DraftModifier_1.replaceWithFragment(afterRemoval, targetRange, movedFragment);
  12452. var newEditorState = EditorState_1.push(editorState, afterInsert, 'insert-fragment');
  12453. return EditorState_1.acceptSelection(newEditorState, finalSelection);
  12454. }
  12455. var keyCommandTransposeCharacters_1 = keyCommandTransposeCharacters;
  12456. function keyCommandUndo(e, editorState, updateFn) {
  12457. var undoneState = EditorState_1.undo(editorState);
  12458. // If the last change to occur was a spellcheck change, allow the undo
  12459. // event to fall through to the browser. This allows the browser to record
  12460. // the unwanted change, which should soon lead it to learn not to suggest
  12461. // the correction again.
  12462. if (editorState.getLastChangeType() === 'spellcheck-change') {
  12463. var nativelyRenderedContent = undoneState.getCurrentContent();
  12464. updateFn(EditorState_1.set(undoneState, { nativelyRenderedContent: nativelyRenderedContent }));
  12465. return;
  12466. }
  12467. // Otheriwse, manage the undo behavior manually.
  12468. e.preventDefault();
  12469. if (!editorState.getNativelyRenderedContent()) {
  12470. updateFn(undoneState);
  12471. return;
  12472. }
  12473. // Trigger a re-render with the current content state to ensure that the
  12474. // component tree has up-to-date props for comparison.
  12475. updateFn(EditorState_1.set(editorState, { nativelyRenderedContent: null }));
  12476. // Wait to ensure that the re-render has occurred before performing
  12477. // the undo action.
  12478. setTimeout(function () {
  12479. updateFn(undoneState);
  12480. }, 0);
  12481. }
  12482. var keyCommandUndo_1 = keyCommandUndo;
  12483. var isOptionKeyCommand = KeyBindingUtil_1.isOptionKeyCommand;
  12484. var isChrome$1 = UserAgent_1.isBrowser('Chrome');
  12485. /**
  12486. * Map a `DraftEditorCommand` command value to a corresponding function.
  12487. */
  12488. function onKeyCommand(command, editorState) {
  12489. switch (command) {
  12490. case 'redo':
  12491. return EditorState_1.redo(editorState);
  12492. case 'delete':
  12493. return keyCommandPlainDelete_1(editorState);
  12494. case 'delete-word':
  12495. return keyCommandDeleteWord_1(editorState);
  12496. case 'backspace':
  12497. return keyCommandPlainBackspace_1(editorState);
  12498. case 'backspace-word':
  12499. return keyCommandBackspaceWord_1(editorState);
  12500. case 'backspace-to-start-of-line':
  12501. return keyCommandBackspaceToStartOfLine_1(editorState);
  12502. case 'split-block':
  12503. return keyCommandInsertNewline_1(editorState);
  12504. case 'transpose-characters':
  12505. return keyCommandTransposeCharacters_1(editorState);
  12506. case 'move-selection-to-start-of-block':
  12507. return keyCommandMoveSelectionToStartOfBlock_1(editorState);
  12508. case 'move-selection-to-end-of-block':
  12509. return keyCommandMoveSelectionToEndOfBlock_1(editorState);
  12510. case 'secondary-cut':
  12511. return SecondaryClipboard_1.cut(editorState);
  12512. case 'secondary-paste':
  12513. return SecondaryClipboard_1.paste(editorState);
  12514. default:
  12515. return editorState;
  12516. }
  12517. }
  12518. /**
  12519. * Intercept keydown behavior to handle keys and commands manually, if desired.
  12520. *
  12521. * Keydown combinations may be mapped to `DraftCommand` values, which may
  12522. * correspond to command functions that modify the editor or its contents.
  12523. *
  12524. * See `getDefaultKeyBinding` for defaults. Alternatively, the top-level
  12525. * component may provide a custom mapping via the `keyBindingFn` prop.
  12526. */
  12527. function editOnKeyDown(editor, e) {
  12528. var keyCode = e.which;
  12529. var editorState = editor._latestEditorState;
  12530. switch (keyCode) {
  12531. case Keys.RETURN:
  12532. e.preventDefault();
  12533. // The top-level component may manually handle newline insertion. If
  12534. // no special handling is performed, fall through to command handling.
  12535. if (editor.props.handleReturn && isEventHandled_1(editor.props.handleReturn(e, editorState))) {
  12536. return;
  12537. }
  12538. break;
  12539. case Keys.ESC:
  12540. e.preventDefault();
  12541. editor.props.onEscape && editor.props.onEscape(e);
  12542. return;
  12543. case Keys.TAB:
  12544. editor.props.onTab && editor.props.onTab(e);
  12545. return;
  12546. case Keys.UP:
  12547. editor.props.onUpArrow && editor.props.onUpArrow(e);
  12548. return;
  12549. case Keys.RIGHT:
  12550. editor.props.onRightArrow && editor.props.onRightArrow(e);
  12551. return;
  12552. case Keys.DOWN:
  12553. editor.props.onDownArrow && editor.props.onDownArrow(e);
  12554. return;
  12555. case Keys.LEFT:
  12556. editor.props.onLeftArrow && editor.props.onLeftArrow(e);
  12557. return;
  12558. case Keys.SPACE:
  12559. // Handling for OSX where option + space scrolls.
  12560. if (isChrome$1 && isOptionKeyCommand(e)) {
  12561. e.preventDefault();
  12562. // Insert a nbsp into the editor.
  12563. var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), '\xA0');
  12564. editor.update(EditorState_1.push(editorState, contentState, 'insert-characters'));
  12565. return;
  12566. }
  12567. }
  12568. var command = editor.props.keyBindingFn(e);
  12569. // If no command is specified, allow keydown event to continue.
  12570. if (!command) {
  12571. return;
  12572. }
  12573. if (command === 'undo') {
  12574. // Since undo requires some special updating behavior to keep the editor
  12575. // in sync, handle it separately.
  12576. keyCommandUndo_1(e, editorState, editor.update);
  12577. return;
  12578. }
  12579. // At this point, we know that we're handling a command of some kind, so
  12580. // we don't want to insert a character following the keydown.
  12581. e.preventDefault();
  12582. // Allow components higher up the tree to handle the command first.
  12583. if (editor.props.handleKeyCommand && isEventHandled_1(editor.props.handleKeyCommand(command, editorState))) {
  12584. return;
  12585. }
  12586. var newState = onKeyCommand(command, editorState);
  12587. if (newState !== editorState) {
  12588. editor.update(newState);
  12589. }
  12590. }
  12591. var editOnKeyDown_1 = editOnKeyDown;
  12592. /**
  12593. * Copyright (c) 2013-present, Facebook, Inc.
  12594. *
  12595. * This source code is licensed under the MIT license found in the
  12596. * LICENSE file in the root directory of this source tree.
  12597. *
  12598. *
  12599. */
  12600. function _classCallCheck$e(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12601. var URI = function () {
  12602. function URI(uri) {
  12603. _classCallCheck$e(this, URI);
  12604. this._uri = uri;
  12605. }
  12606. URI.prototype.toString = function toString() {
  12607. return this._uri;
  12608. };
  12609. return URI;
  12610. }();
  12611. var URI_1 = URI;
  12612. var isOldIE = UserAgent_1.isBrowser('IE <= 9');
  12613. // Provides a dom node that will not execute scripts
  12614. // https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation.createHTMLDocument
  12615. // https://developer.mozilla.org/en-US/Add-ons/Code_snippets/HTML_to_DOM
  12616. function getSafeBodyFromHTML(html) {
  12617. var doc;
  12618. var root = null;
  12619. // Provides a safe context
  12620. if (!isOldIE && document.implementation && document.implementation.createHTMLDocument) {
  12621. doc = document.implementation.createHTMLDocument('foo');
  12622. !doc.documentElement ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing doc.documentElement') : invariant_1(false) : void 0;
  12623. doc.documentElement.innerHTML = html;
  12624. root = doc.getElementsByTagName('body')[0];
  12625. }
  12626. return root;
  12627. }
  12628. var getSafeBodyFromHTML_1 = getSafeBodyFromHTML;
  12629. var _extends$4 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  12630. var _knownListItemDepthCl;
  12631. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  12632. var _require = immutable,
  12633. Set = _require.Set;
  12634. var experimentalTreeDataSupport = DraftFeatureFlags_1.draft_tree_data_support;
  12635. var List$a = immutable.List,
  12636. OrderedSet$5 = immutable.OrderedSet;
  12637. var NBSP = '&nbsp;';
  12638. var SPACE = ' ';
  12639. // Arbitrary max indent
  12640. var MAX_DEPTH = 4;
  12641. // used for replacing characters in HTML
  12642. var REGEX_CR = new RegExp('\r', 'g');
  12643. var REGEX_LF = new RegExp('\n', 'g');
  12644. var REGEX_NBSP = new RegExp(NBSP, 'g');
  12645. var REGEX_CARRIAGE = new RegExp('&#13;?', 'g');
  12646. var REGEX_ZWS = new RegExp('&#8203;?', 'g');
  12647. // https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight
  12648. var boldValues = ['bold', 'bolder', '500', '600', '700', '800', '900'];
  12649. var notBoldValues = ['light', 'lighter', '100', '200', '300', '400'];
  12650. // Block tag flow is different because LIs do not have
  12651. // a deterministic style ;_;
  12652. var inlineTags = {
  12653. b: 'BOLD',
  12654. code: 'CODE',
  12655. del: 'STRIKETHROUGH',
  12656. em: 'ITALIC',
  12657. i: 'ITALIC',
  12658. s: 'STRIKETHROUGH',
  12659. strike: 'STRIKETHROUGH',
  12660. strong: 'BOLD',
  12661. u: 'UNDERLINE'
  12662. };
  12663. var knownListItemDepthClasses = (_knownListItemDepthCl = {}, _defineProperty(_knownListItemDepthCl, cx_1('public/DraftStyleDefault/depth0'), 0), _defineProperty(_knownListItemDepthCl, cx_1('public/DraftStyleDefault/depth1'), 1), _defineProperty(_knownListItemDepthCl, cx_1('public/DraftStyleDefault/depth2'), 2), _defineProperty(_knownListItemDepthCl, cx_1('public/DraftStyleDefault/depth3'), 3), _defineProperty(_knownListItemDepthCl, cx_1('public/DraftStyleDefault/depth4'), 4), _knownListItemDepthCl);
  12664. var anchorAttr = ['className', 'href', 'rel', 'target', 'title'];
  12665. var imgAttr = ['alt', 'className', 'height', 'src', 'width'];
  12666. var lastBlock = void 0;
  12667. var EMPTY_CHUNK = {
  12668. text: '',
  12669. inlines: [],
  12670. entities: [],
  12671. blocks: []
  12672. };
  12673. var EMPTY_BLOCK = {
  12674. children: List$a(),
  12675. depth: 0,
  12676. key: '',
  12677. type: ''
  12678. };
  12679. var getListBlockType = function getListBlockType(tag, lastList) {
  12680. if (tag === 'li') {
  12681. return lastList === 'ol' ? 'ordered-list-item' : 'unordered-list-item';
  12682. }
  12683. return null;
  12684. };
  12685. var getBlockMapSupportedTags = function getBlockMapSupportedTags(blockRenderMap) {
  12686. var unstyledElement = blockRenderMap.get('unstyled').element;
  12687. var tags = Set([]);
  12688. blockRenderMap.forEach(function (draftBlock) {
  12689. if (draftBlock.aliasedElements) {
  12690. draftBlock.aliasedElements.forEach(function (tag) {
  12691. tags = tags.add(tag);
  12692. });
  12693. }
  12694. tags = tags.add(draftBlock.element);
  12695. });
  12696. return tags.filter(function (tag) {
  12697. return tag && tag !== unstyledElement;
  12698. }).toArray().sort();
  12699. };
  12700. // custom element conversions
  12701. var getMultiMatchedType = function getMultiMatchedType(tag, lastList, multiMatchExtractor) {
  12702. for (var ii = 0; ii < multiMatchExtractor.length; ii++) {
  12703. var matchType = multiMatchExtractor[ii](tag, lastList);
  12704. if (matchType) {
  12705. return matchType;
  12706. }
  12707. }
  12708. return null;
  12709. };
  12710. var getBlockTypeForTag = function getBlockTypeForTag(tag, lastList, blockRenderMap) {
  12711. var matchedTypes = blockRenderMap.filter(function (draftBlock) {
  12712. return draftBlock.element === tag || draftBlock.wrapper === tag || draftBlock.aliasedElements && draftBlock.aliasedElements.some(function (alias) {
  12713. return alias === tag;
  12714. });
  12715. }).keySeq().toSet().toArray().sort();
  12716. // if we dont have any matched type, return unstyled
  12717. // if we have one matched type return it
  12718. // if we have multi matched types use the multi-match function to gather type
  12719. switch (matchedTypes.length) {
  12720. case 0:
  12721. return 'unstyled';
  12722. case 1:
  12723. return matchedTypes[0];
  12724. default:
  12725. return getMultiMatchedType(tag, lastList, [getListBlockType]) || 'unstyled';
  12726. }
  12727. };
  12728. var processInlineTag = function processInlineTag(tag, node, currentStyle) {
  12729. var styleToCheck = inlineTags[tag];
  12730. if (styleToCheck) {
  12731. currentStyle = currentStyle.add(styleToCheck).toOrderedSet();
  12732. } else if (node instanceof HTMLElement) {
  12733. var htmlElement = node;
  12734. currentStyle = currentStyle.withMutations(function (style) {
  12735. var fontWeight = htmlElement.style.fontWeight;
  12736. var fontStyle = htmlElement.style.fontStyle;
  12737. var textDecoration = htmlElement.style.textDecoration;
  12738. if (boldValues.indexOf(fontWeight) >= 0) {
  12739. style.add('BOLD');
  12740. } else if (notBoldValues.indexOf(fontWeight) >= 0) {
  12741. style.remove('BOLD');
  12742. }
  12743. if (fontStyle === 'italic') {
  12744. style.add('ITALIC');
  12745. } else if (fontStyle === 'normal') {
  12746. style.remove('ITALIC');
  12747. }
  12748. if (textDecoration === 'underline') {
  12749. style.add('UNDERLINE');
  12750. }
  12751. if (textDecoration === 'line-through') {
  12752. style.add('STRIKETHROUGH');
  12753. }
  12754. if (textDecoration === 'none') {
  12755. style.remove('UNDERLINE');
  12756. style.remove('STRIKETHROUGH');
  12757. }
  12758. }).toOrderedSet();
  12759. }
  12760. return currentStyle;
  12761. };
  12762. var joinChunks = function joinChunks(A, B, experimentalHasNestedBlocks) {
  12763. // Sometimes two blocks will touch in the DOM and we need to strip the
  12764. // extra delimiter to preserve niceness.
  12765. var lastInA = A.text.slice(-1);
  12766. var firstInB = B.text.slice(0, 1);
  12767. if (lastInA === '\r' && firstInB === '\r' && !experimentalHasNestedBlocks) {
  12768. A.text = A.text.slice(0, -1);
  12769. A.inlines.pop();
  12770. A.entities.pop();
  12771. A.blocks.pop();
  12772. }
  12773. // Kill whitespace after blocks
  12774. if (lastInA === '\r') {
  12775. if (B.text === SPACE || B.text === '\n') {
  12776. return A;
  12777. } else if (firstInB === SPACE || firstInB === '\n') {
  12778. B.text = B.text.slice(1);
  12779. B.inlines.shift();
  12780. B.entities.shift();
  12781. }
  12782. }
  12783. return {
  12784. text: A.text + B.text,
  12785. inlines: A.inlines.concat(B.inlines),
  12786. entities: A.entities.concat(B.entities),
  12787. blocks: A.blocks.concat(B.blocks)
  12788. };
  12789. };
  12790. /**
  12791. * Check to see if we have anything like <p> <blockquote> <h1>... to create
  12792. * block tags from. If we do, we can use those and ignore <div> tags. If we
  12793. * don't, we can treat <div> tags as meaningful (unstyled) blocks.
  12794. */
  12795. var containsSemanticBlockMarkup = function containsSemanticBlockMarkup(html, blockTags) {
  12796. return blockTags.some(function (tag) {
  12797. return html.indexOf('<' + tag) !== -1;
  12798. });
  12799. };
  12800. var hasValidLinkText = function hasValidLinkText(link) {
  12801. !(link instanceof HTMLAnchorElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Link must be an HTMLAnchorElement.') : invariant_1(false) : void 0;
  12802. var protocol = link.protocol;
  12803. return protocol === 'http:' || protocol === 'https:' || protocol === 'mailto:';
  12804. };
  12805. var getWhitespaceChunk = function getWhitespaceChunk(inEntity) {
  12806. var entities = new Array(1);
  12807. if (inEntity) {
  12808. entities[0] = inEntity;
  12809. }
  12810. return _extends$4({}, EMPTY_CHUNK, {
  12811. text: SPACE,
  12812. inlines: [OrderedSet$5()],
  12813. entities: entities
  12814. });
  12815. };
  12816. var getSoftNewlineChunk = function getSoftNewlineChunk() {
  12817. return _extends$4({}, EMPTY_CHUNK, {
  12818. text: '\n',
  12819. inlines: [OrderedSet$5()],
  12820. entities: new Array(1)
  12821. });
  12822. };
  12823. var getChunkedBlock = function getChunkedBlock() {
  12824. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  12825. return _extends$4({}, EMPTY_BLOCK, props);
  12826. };
  12827. var getBlockDividerChunk = function getBlockDividerChunk(block, depth) {
  12828. var parentKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  12829. return {
  12830. text: '\r',
  12831. inlines: [OrderedSet$5()],
  12832. entities: new Array(1),
  12833. blocks: [getChunkedBlock({
  12834. parent: parentKey,
  12835. key: generateRandomKey_1(),
  12836. type: block,
  12837. depth: Math.max(0, Math.min(MAX_DEPTH, depth))
  12838. })]
  12839. };
  12840. };
  12841. /**
  12842. * If we're pasting from one DraftEditor to another we can check to see if
  12843. * existing list item depth classes are being used and preserve this style
  12844. */
  12845. var getListItemDepth = function getListItemDepth(node) {
  12846. var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  12847. Object.keys(knownListItemDepthClasses).some(function (depthClass) {
  12848. if (node.classList.contains(depthClass)) {
  12849. depth = knownListItemDepthClasses[depthClass];
  12850. }
  12851. });
  12852. return depth;
  12853. };
  12854. var genFragment = function genFragment(entityMap, node, inlineStyle, lastList, inBlock, blockTags, depth, blockRenderMap, inEntity, parentKey) {
  12855. var lastLastBlock = lastBlock;
  12856. var nodeName = node.nodeName.toLowerCase();
  12857. var newEntityMap = entityMap;
  12858. var nextBlockType = 'unstyled';
  12859. var newBlock = false;
  12860. var inBlockType = inBlock && getBlockTypeForTag(inBlock, lastList, blockRenderMap);
  12861. var chunk = _extends$4({}, EMPTY_CHUNK);
  12862. var newChunk = null;
  12863. var blockKey = void 0;
  12864. // Base Case
  12865. if (nodeName === '#text') {
  12866. var _text = node.textContent;
  12867. var nodeTextContent = _text.trim();
  12868. // We should not create blocks for leading spaces that are
  12869. // existing around ol/ul and their children list items
  12870. if (lastList && nodeTextContent === '' && node.parentElement) {
  12871. var parentNodeName = node.parentElement.nodeName.toLowerCase();
  12872. if (parentNodeName === 'ol' || parentNodeName === 'ul') {
  12873. return { chunk: _extends$4({}, EMPTY_CHUNK), entityMap: entityMap };
  12874. }
  12875. }
  12876. if (nodeTextContent === '' && inBlock !== 'pre') {
  12877. return { chunk: getWhitespaceChunk(inEntity), entityMap: entityMap };
  12878. }
  12879. if (inBlock !== 'pre') {
  12880. // Can't use empty string because MSWord
  12881. _text = _text.replace(REGEX_LF, SPACE);
  12882. }
  12883. // save the last block so we can use it later
  12884. lastBlock = nodeName;
  12885. return {
  12886. chunk: {
  12887. text: _text,
  12888. inlines: Array(_text.length).fill(inlineStyle),
  12889. entities: Array(_text.length).fill(inEntity),
  12890. blocks: []
  12891. },
  12892. entityMap: entityMap
  12893. };
  12894. }
  12895. // save the last block so we can use it later
  12896. lastBlock = nodeName;
  12897. // BR tags
  12898. if (nodeName === 'br') {
  12899. if (lastLastBlock === 'br' && (!inBlock || inBlockType === 'unstyled')) {
  12900. return {
  12901. chunk: getBlockDividerChunk('unstyled', depth, parentKey),
  12902. entityMap: entityMap
  12903. };
  12904. }
  12905. return { chunk: getSoftNewlineChunk(), entityMap: entityMap };
  12906. }
  12907. // IMG tags
  12908. if (nodeName === 'img' && node instanceof HTMLImageElement && node.attributes.getNamedItem('src') && node.attributes.getNamedItem('src').value) {
  12909. var image = node;
  12910. var entityConfig = {};
  12911. imgAttr.forEach(function (attr) {
  12912. var imageAttribute = image.getAttribute(attr);
  12913. if (imageAttribute) {
  12914. entityConfig[attr] = imageAttribute;
  12915. }
  12916. });
  12917. // Forcing this node to have children because otherwise no entity will be
  12918. // created for this node.
  12919. // The child text node cannot just have a space or return as content -
  12920. // we strip those out.
  12921. // See https://github.com/facebook/draft-js/issues/231 for some context.
  12922. node.textContent = '\uD83D\uDCF7';
  12923. // TODO: update this when we remove DraftEntity entirely
  12924. inEntity = DraftEntity_1.__create('IMAGE', 'MUTABLE', entityConfig || {});
  12925. }
  12926. // Inline tags
  12927. inlineStyle = processInlineTag(nodeName, node, inlineStyle);
  12928. // Handle lists
  12929. if (nodeName === 'ul' || nodeName === 'ol') {
  12930. if (lastList) {
  12931. depth += 1;
  12932. }
  12933. lastList = nodeName;
  12934. }
  12935. if ( nodeName === 'li' && node instanceof HTMLElement) {
  12936. depth = getListItemDepth(node, depth);
  12937. }
  12938. var blockType = getBlockTypeForTag(nodeName, lastList, blockRenderMap);
  12939. var inListBlock = lastList && inBlock === 'li' && nodeName === 'li';
  12940. var inBlockOrHasNestedBlocks = (!inBlock || experimentalTreeDataSupport) && blockTags.indexOf(nodeName) !== -1;
  12941. // Block Tags
  12942. if (inListBlock || inBlockOrHasNestedBlocks) {
  12943. chunk = getBlockDividerChunk(blockType, depth, parentKey);
  12944. blockKey = chunk.blocks[0].key;
  12945. inBlock = nodeName;
  12946. newBlock = !experimentalTreeDataSupport;
  12947. }
  12948. // this is required so that we can handle 'ul' and 'ol'
  12949. if (inListBlock) {
  12950. nextBlockType = lastList === 'ul' ? 'unordered-list-item' : 'ordered-list-item';
  12951. }
  12952. // Recurse through children
  12953. var child = node.firstChild;
  12954. if (child != null) {
  12955. nodeName = child.nodeName.toLowerCase();
  12956. }
  12957. var entityId = null;
  12958. while (child) {
  12959. if (child instanceof HTMLAnchorElement && child.href && hasValidLinkText(child)) {
  12960. (function () {
  12961. var anchor = child;
  12962. var entityConfig = {};
  12963. anchorAttr.forEach(function (attr) {
  12964. var anchorAttribute = anchor.getAttribute(attr);
  12965. if (anchorAttribute) {
  12966. entityConfig[attr] = anchorAttribute;
  12967. }
  12968. });
  12969. entityConfig.url = new URI_1(anchor.href).toString();
  12970. // TODO: update this when we remove DraftEntity completely
  12971. entityId = DraftEntity_1.__create('LINK', 'MUTABLE', entityConfig || {});
  12972. })();
  12973. } else {
  12974. entityId = undefined;
  12975. }
  12976. var _genFragment = genFragment(newEntityMap, child, inlineStyle, lastList, inBlock, blockTags, depth, blockRenderMap, entityId || inEntity, null),
  12977. generatedChunk = _genFragment.chunk,
  12978. maybeUpdatedEntityMap = _genFragment.entityMap;
  12979. newChunk = generatedChunk;
  12980. newEntityMap = maybeUpdatedEntityMap;
  12981. chunk = joinChunks(chunk, newChunk, experimentalTreeDataSupport);
  12982. var sibling = child.nextSibling;
  12983. // Put in a newline to break up blocks inside blocks
  12984. if (!parentKey && sibling && blockTags.indexOf(nodeName) >= 0 && inBlock) {
  12985. chunk = joinChunks(chunk, getSoftNewlineChunk());
  12986. }
  12987. if (sibling) {
  12988. nodeName = sibling.nodeName.toLowerCase();
  12989. }
  12990. child = sibling;
  12991. }
  12992. if (newBlock) {
  12993. chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, parentKey));
  12994. }
  12995. return { chunk: chunk, entityMap: newEntityMap };
  12996. };
  12997. var getChunkForHTML = function getChunkForHTML(html, DOMBuilder, blockRenderMap, entityMap) {
  12998. html = html.trim().replace(REGEX_CR, '').replace(REGEX_NBSP, SPACE).replace(REGEX_CARRIAGE, '').replace(REGEX_ZWS, '');
  12999. var supportedBlockTags = getBlockMapSupportedTags(blockRenderMap);
  13000. var safeBody = DOMBuilder(html);
  13001. if (!safeBody) {
  13002. return null;
  13003. }
  13004. lastBlock = null;
  13005. // Sometimes we aren't dealing with content that contains nice semantic
  13006. // tags. In this case, use divs to separate everything out into paragraphs
  13007. // and hope for the best.
  13008. var workingBlocks = containsSemanticBlockMarkup(html, supportedBlockTags) ? supportedBlockTags : ['div'];
  13009. // Start with -1 block depth to offset the fact that we are passing in a fake
  13010. // UL block to start with.
  13011. var fragment = genFragment(entityMap, safeBody, OrderedSet$5(), 'ul', null, workingBlocks, -1, blockRenderMap);
  13012. var chunk = fragment.chunk;
  13013. var newEntityMap = fragment.entityMap;
  13014. // join with previous block to prevent weirdness on paste
  13015. if (chunk.text.indexOf('\r') === 0) {
  13016. chunk = {
  13017. text: chunk.text.slice(1),
  13018. inlines: chunk.inlines.slice(1),
  13019. entities: chunk.entities.slice(1),
  13020. blocks: chunk.blocks
  13021. };
  13022. }
  13023. // Kill block delimiter at the end
  13024. if (chunk.text.slice(-1) === '\r') {
  13025. chunk.text = chunk.text.slice(0, -1);
  13026. chunk.inlines = chunk.inlines.slice(0, -1);
  13027. chunk.entities = chunk.entities.slice(0, -1);
  13028. chunk.blocks.pop();
  13029. }
  13030. // If we saw no block tags, put an unstyled one in
  13031. if (chunk.blocks.length === 0) {
  13032. chunk.blocks.push(_extends$4({}, EMPTY_CHUNK, {
  13033. type: 'unstyled',
  13034. depth: 0
  13035. }));
  13036. }
  13037. // Sometimes we start with text that isn't in a block, which is then
  13038. // followed by blocks. Need to fix up the blocks to add in
  13039. // an unstyled block for this content
  13040. if (chunk.text.split('\r').length === chunk.blocks.length + 1) {
  13041. chunk.blocks.unshift({ type: 'unstyled', depth: 0 });
  13042. }
  13043. return { chunk: chunk, entityMap: newEntityMap };
  13044. };
  13045. var convertChunkToContentBlocks = function convertChunkToContentBlocks(chunk) {
  13046. if (!chunk || !chunk.text || !Array.isArray(chunk.blocks)) {
  13047. return null;
  13048. }
  13049. var initialState = {
  13050. cacheRef: {},
  13051. contentBlocks: []
  13052. };
  13053. var start = 0;
  13054. var rawBlocks = chunk.blocks,
  13055. rawInlines = chunk.inlines,
  13056. rawEntities = chunk.entities;
  13057. var BlockNodeRecord = ContentBlock_1;
  13058. return chunk.text.split('\r').reduce(function (acc, textBlock, index) {
  13059. // Make absolutely certain that our text is acceptable.
  13060. textBlock = sanitizeDraftText_1(textBlock);
  13061. var block = rawBlocks[index];
  13062. var end = start + textBlock.length;
  13063. var inlines = rawInlines.slice(start, end);
  13064. var entities = rawEntities.slice(start, end);
  13065. var characterList = List$a(inlines.map(function (style, index) {
  13066. var data = { style: style, entity: null };
  13067. if (entities[index]) {
  13068. data.entity = entities[index];
  13069. }
  13070. return CharacterMetadata_1.create(data);
  13071. }));
  13072. start = end + 1;
  13073. var depth = block.depth,
  13074. type = block.type,
  13075. parent = block.parent;
  13076. var key = block.key || generateRandomKey_1();
  13077. var parentTextNodeKey = null; // will be used to store container text nodes
  13078. // childrens add themselves to their parents since we are iterating in order
  13079. if (parent) {
  13080. var parentIndex = acc.cacheRef[parent];
  13081. var parentRecord = acc.contentBlocks[parentIndex];
  13082. // if parent has text we need to split it into a separate unstyled element
  13083. if (parentRecord.getChildKeys().isEmpty() && parentRecord.getText()) {
  13084. var parentCharacterList = parentRecord.getCharacterList();
  13085. var parentText = parentRecord.getText();
  13086. parentTextNodeKey = generateRandomKey_1();
  13087. var textNode = new ContentBlockNode_1({
  13088. key: parentTextNodeKey,
  13089. text: parentText,
  13090. characterList: parentCharacterList,
  13091. parent: parent,
  13092. nextSibling: key
  13093. });
  13094. acc.contentBlocks.push(textNode);
  13095. parentRecord = parentRecord.withMutations(function (block) {
  13096. block.set('characterList', List$a()).set('text', '').set('children', parentRecord.children.push(textNode.getKey()));
  13097. });
  13098. }
  13099. acc.contentBlocks[parentIndex] = parentRecord.set('children', parentRecord.children.push(key));
  13100. }
  13101. var blockNode = new BlockNodeRecord({
  13102. key: key,
  13103. parent: parent,
  13104. type: type,
  13105. depth: depth,
  13106. text: textBlock,
  13107. characterList: characterList,
  13108. prevSibling: parentTextNodeKey || (index === 0 || rawBlocks[index - 1].parent !== parent ? null : rawBlocks[index - 1].key),
  13109. nextSibling: index === rawBlocks.length - 1 || rawBlocks[index + 1].parent !== parent ? null : rawBlocks[index + 1].key
  13110. });
  13111. // insert node
  13112. acc.contentBlocks.push(blockNode);
  13113. // cache ref for building links
  13114. acc.cacheRef[blockNode.key] = index;
  13115. return acc;
  13116. }, initialState).contentBlocks;
  13117. };
  13118. var convertFromHTMLtoContentBlocks = function convertFromHTMLtoContentBlocks(html) {
  13119. var DOMBuilder = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getSafeBodyFromHTML_1;
  13120. var blockRenderMap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DefaultDraftBlockRenderMap_1;
  13121. // Be ABSOLUTELY SURE that the dom builder you pass here won't execute
  13122. // arbitrary code in whatever environment you're running this in. For an
  13123. // example of how we try to do this in-browser, see getSafeBodyFromHTML.
  13124. // TODO: replace DraftEntity with an OrderedMap here
  13125. var chunkData = getChunkForHTML(html, DOMBuilder, blockRenderMap, DraftEntity_1);
  13126. if (chunkData == null) {
  13127. return null;
  13128. }
  13129. var chunk = chunkData.chunk,
  13130. entityMap = chunkData.entityMap;
  13131. var contentBlocks = convertChunkToContentBlocks(chunk);
  13132. return {
  13133. contentBlocks: contentBlocks,
  13134. entityMap: entityMap
  13135. };
  13136. };
  13137. var convertFromHTMLToContentBlocks = convertFromHTMLtoContentBlocks;
  13138. var List$b = immutable.List,
  13139. Repeat$6 = immutable.Repeat;
  13140. var ContentBlockRecord$2 = ContentBlock_1;
  13141. var DraftPasteProcessor = {
  13142. processHTML: function processHTML(html, blockRenderMap) {
  13143. return convertFromHTMLToContentBlocks(html, getSafeBodyFromHTML_1, blockRenderMap);
  13144. },
  13145. processText: function processText(textBlocks, character, type) {
  13146. return textBlocks.reduce(function (acc, textLine, index) {
  13147. textLine = sanitizeDraftText_1(textLine);
  13148. var key = generateRandomKey_1();
  13149. var blockNodeConfig = {
  13150. key: key,
  13151. type: type,
  13152. text: textLine,
  13153. characterList: List$b(Repeat$6(character, textLine.length))
  13154. };
  13155. acc.push(new ContentBlockRecord$2(blockNodeConfig));
  13156. return acc;
  13157. }, []);
  13158. }
  13159. };
  13160. var DraftPasteProcessor_1 = DraftPasteProcessor;
  13161. /**
  13162. * Copyright (c) 2013-present, Facebook, Inc.
  13163. * All rights reserved.
  13164. *
  13165. * This source code is licensed under the BSD-style license found in the
  13166. * LICENSE file in the root directory of this source tree. An additional grant
  13167. * of patent rights can be found in the PATENTS file in the same directory.
  13168. *
  13169. * @providesModule adjustBlockDepthForContentState
  13170. * @format
  13171. *
  13172. */
  13173. function adjustBlockDepthForContentState(contentState, selectionState, adjustment, maxDepth) {
  13174. var startKey = selectionState.getStartKey();
  13175. var endKey = selectionState.getEndKey();
  13176. var blockMap = contentState.getBlockMap();
  13177. var blocks = blockMap.toSeq().skipUntil(function (_, k) {
  13178. return k === startKey;
  13179. }).takeUntil(function (_, k) {
  13180. return k === endKey;
  13181. }).concat([[endKey, blockMap.get(endKey)]]).map(function (block) {
  13182. var depth = block.getDepth() + adjustment;
  13183. depth = Math.max(0, Math.min(depth, maxDepth));
  13184. return block.set('depth', depth);
  13185. });
  13186. blockMap = blockMap.merge(blocks);
  13187. return contentState.merge({
  13188. blockMap: blockMap,
  13189. selectionBefore: selectionState,
  13190. selectionAfter: selectionState
  13191. });
  13192. }
  13193. var adjustBlockDepthForContentState_1 = adjustBlockDepthForContentState;
  13194. var RichTextEditorUtil = {
  13195. currentBlockContainsLink: function currentBlockContainsLink(editorState) {
  13196. var selection = editorState.getSelection();
  13197. var contentState = editorState.getCurrentContent();
  13198. var entityMap = contentState.getEntityMap();
  13199. return contentState.getBlockForKey(selection.getAnchorKey()).getCharacterList().slice(selection.getStartOffset(), selection.getEndOffset()).some(function (v) {
  13200. var entity = v.getEntity();
  13201. return !!entity && entityMap.__get(entity).getType() === 'LINK';
  13202. });
  13203. },
  13204. getCurrentBlockType: function getCurrentBlockType(editorState) {
  13205. var selection = editorState.getSelection();
  13206. return editorState.getCurrentContent().getBlockForKey(selection.getStartKey()).getType();
  13207. },
  13208. getDataObjectForLinkURL: function getDataObjectForLinkURL(uri) {
  13209. return { url: uri.toString() };
  13210. },
  13211. handleKeyCommand: function handleKeyCommand(editorState, command) {
  13212. switch (command) {
  13213. case 'bold':
  13214. return RichTextEditorUtil.toggleInlineStyle(editorState, 'BOLD');
  13215. case 'italic':
  13216. return RichTextEditorUtil.toggleInlineStyle(editorState, 'ITALIC');
  13217. case 'underline':
  13218. return RichTextEditorUtil.toggleInlineStyle(editorState, 'UNDERLINE');
  13219. case 'code':
  13220. return RichTextEditorUtil.toggleCode(editorState);
  13221. case 'backspace':
  13222. case 'backspace-word':
  13223. case 'backspace-to-start-of-line':
  13224. return RichTextEditorUtil.onBackspace(editorState);
  13225. case 'delete':
  13226. case 'delete-word':
  13227. case 'delete-to-end-of-block':
  13228. return RichTextEditorUtil.onDelete(editorState);
  13229. default:
  13230. // they may have custom editor commands; ignore those
  13231. return null;
  13232. }
  13233. },
  13234. insertSoftNewline: function insertSoftNewline(editorState) {
  13235. var contentState = DraftModifier_1.insertText(editorState.getCurrentContent(), editorState.getSelection(), '\n', editorState.getCurrentInlineStyle(), null);
  13236. var newEditorState = EditorState_1.push(editorState, contentState, 'insert-characters');
  13237. return EditorState_1.forceSelection(newEditorState, contentState.getSelectionAfter());
  13238. },
  13239. /**
  13240. * For collapsed selections at the start of styled blocks, backspace should
  13241. * just remove the existing style.
  13242. */
  13243. onBackspace: function onBackspace(editorState) {
  13244. var selection = editorState.getSelection();
  13245. if (!selection.isCollapsed() || selection.getAnchorOffset() || selection.getFocusOffset()) {
  13246. return null;
  13247. }
  13248. // First, try to remove a preceding atomic block.
  13249. var content = editorState.getCurrentContent();
  13250. var startKey = selection.getStartKey();
  13251. var blockBefore = content.getBlockBefore(startKey);
  13252. if (blockBefore && blockBefore.getType() === 'atomic') {
  13253. var blockMap = content.getBlockMap()['delete'](blockBefore.getKey());
  13254. var withoutAtomicBlock = content.merge({
  13255. blockMap: blockMap,
  13256. selectionAfter: selection
  13257. });
  13258. if (withoutAtomicBlock !== content) {
  13259. return EditorState_1.push(editorState, withoutAtomicBlock, 'remove-range');
  13260. }
  13261. }
  13262. // If that doesn't succeed, try to remove the current block style.
  13263. var withoutBlockStyle = RichTextEditorUtil.tryToRemoveBlockStyle(editorState);
  13264. if (withoutBlockStyle) {
  13265. return EditorState_1.push(editorState, withoutBlockStyle, 'change-block-type');
  13266. }
  13267. return null;
  13268. },
  13269. onDelete: function onDelete(editorState) {
  13270. var selection = editorState.getSelection();
  13271. if (!selection.isCollapsed()) {
  13272. return null;
  13273. }
  13274. var content = editorState.getCurrentContent();
  13275. var startKey = selection.getStartKey();
  13276. var block = content.getBlockForKey(startKey);
  13277. var length = block.getLength();
  13278. // The cursor is somewhere within the text. Behave normally.
  13279. if (selection.getStartOffset() < length) {
  13280. return null;
  13281. }
  13282. var blockAfter = content.getBlockAfter(startKey);
  13283. if (!blockAfter || blockAfter.getType() !== 'atomic') {
  13284. return null;
  13285. }
  13286. var atomicBlockTarget = selection.merge({
  13287. focusKey: blockAfter.getKey(),
  13288. focusOffset: blockAfter.getLength()
  13289. });
  13290. var withoutAtomicBlock = DraftModifier_1.removeRange(content, atomicBlockTarget, 'forward');
  13291. if (withoutAtomicBlock !== content) {
  13292. return EditorState_1.push(editorState, withoutAtomicBlock, 'remove-range');
  13293. }
  13294. return null;
  13295. },
  13296. onTab: function onTab(event, editorState, maxDepth) {
  13297. var selection = editorState.getSelection();
  13298. var key = selection.getAnchorKey();
  13299. if (key !== selection.getFocusKey()) {
  13300. return editorState;
  13301. }
  13302. var content = editorState.getCurrentContent();
  13303. var block = content.getBlockForKey(key);
  13304. var type = block.getType();
  13305. if (type !== 'unordered-list-item' && type !== 'ordered-list-item') {
  13306. return editorState;
  13307. }
  13308. event.preventDefault();
  13309. // Only allow indenting one level beyond the block above, and only if
  13310. // the block above is a list item as well.
  13311. var blockAbove = content.getBlockBefore(key);
  13312. if (!blockAbove) {
  13313. return editorState;
  13314. }
  13315. var typeAbove = blockAbove.getType();
  13316. if (typeAbove !== 'unordered-list-item' && typeAbove !== 'ordered-list-item') {
  13317. return editorState;
  13318. }
  13319. var depth = block.getDepth();
  13320. if (!event.shiftKey && depth === maxDepth) {
  13321. return editorState;
  13322. }
  13323. maxDepth = Math.min(blockAbove.getDepth() + 1, maxDepth);
  13324. var withAdjustment = adjustBlockDepthForContentState_1(content, selection, event.shiftKey ? -1 : 1, maxDepth);
  13325. return EditorState_1.push(editorState, withAdjustment, 'adjust-depth');
  13326. },
  13327. toggleBlockType: function toggleBlockType(editorState, blockType) {
  13328. var selection = editorState.getSelection();
  13329. var startKey = selection.getStartKey();
  13330. var endKey = selection.getEndKey();
  13331. var content = editorState.getCurrentContent();
  13332. var target = selection;
  13333. // Triple-click can lead to a selection that includes offset 0 of the
  13334. // following block. The `SelectionState` for this case is accurate, but
  13335. // we should avoid toggling block type for the trailing block because it
  13336. // is a confusing interaction.
  13337. if (startKey !== endKey && selection.getEndOffset() === 0) {
  13338. var blockBefore = nullthrows_1(content.getBlockBefore(endKey));
  13339. endKey = blockBefore.getKey();
  13340. target = target.merge({
  13341. anchorKey: startKey,
  13342. anchorOffset: selection.getStartOffset(),
  13343. focusKey: endKey,
  13344. focusOffset: blockBefore.getLength(),
  13345. isBackward: false
  13346. });
  13347. }
  13348. var hasAtomicBlock = content.getBlockMap().skipWhile(function (_, k) {
  13349. return k !== startKey;
  13350. }).reverse().skipWhile(function (_, k) {
  13351. return k !== endKey;
  13352. }).some(function (v) {
  13353. return v.getType() === 'atomic';
  13354. });
  13355. if (hasAtomicBlock) {
  13356. return editorState;
  13357. }
  13358. var typeToSet = content.getBlockForKey(startKey).getType() === blockType ? 'unstyled' : blockType;
  13359. return EditorState_1.push(editorState, DraftModifier_1.setBlockType(content, target, typeToSet), 'change-block-type');
  13360. },
  13361. toggleCode: function toggleCode(editorState) {
  13362. var selection = editorState.getSelection();
  13363. var anchorKey = selection.getAnchorKey();
  13364. var focusKey = selection.getFocusKey();
  13365. if (selection.isCollapsed() || anchorKey !== focusKey) {
  13366. return RichTextEditorUtil.toggleBlockType(editorState, 'code-block');
  13367. }
  13368. return RichTextEditorUtil.toggleInlineStyle(editorState, 'CODE');
  13369. },
  13370. /**
  13371. * Toggle the specified inline style for the selection. If the
  13372. * user's selection is collapsed, apply or remove the style for the
  13373. * internal state. If it is not collapsed, apply the change directly
  13374. * to the document state.
  13375. */
  13376. toggleInlineStyle: function toggleInlineStyle(editorState, inlineStyle) {
  13377. var selection = editorState.getSelection();
  13378. var currentStyle = editorState.getCurrentInlineStyle();
  13379. // If the selection is collapsed, toggle the specified style on or off and
  13380. // set the result as the new inline style override. This will then be
  13381. // used as the inline style for the next character to be inserted.
  13382. if (selection.isCollapsed()) {
  13383. return EditorState_1.setInlineStyleOverride(editorState, currentStyle.has(inlineStyle) ? currentStyle.remove(inlineStyle) : currentStyle.add(inlineStyle));
  13384. }
  13385. // If characters are selected, immediately apply or remove the
  13386. // inline style on the document state itself.
  13387. var content = editorState.getCurrentContent();
  13388. var newContent;
  13389. // If the style is already present for the selection range, remove it.
  13390. // Otherwise, apply it.
  13391. if (currentStyle.has(inlineStyle)) {
  13392. newContent = DraftModifier_1.removeInlineStyle(content, selection, inlineStyle);
  13393. } else {
  13394. newContent = DraftModifier_1.applyInlineStyle(content, selection, inlineStyle);
  13395. }
  13396. return EditorState_1.push(editorState, newContent, 'change-inline-style');
  13397. },
  13398. toggleLink: function toggleLink(editorState, targetSelection, entityKey) {
  13399. var withoutLink = DraftModifier_1.applyEntity(editorState.getCurrentContent(), targetSelection, entityKey);
  13400. return EditorState_1.push(editorState, withoutLink, 'apply-entity');
  13401. },
  13402. /**
  13403. * When a collapsed cursor is at the start of the first styled block, or
  13404. * an empty styled block, changes block to 'unstyled'. Returns null if
  13405. * block or selection does not meet that criteria.
  13406. */
  13407. tryToRemoveBlockStyle: function tryToRemoveBlockStyle(editorState) {
  13408. var selection = editorState.getSelection();
  13409. var offset = selection.getAnchorOffset();
  13410. if (selection.isCollapsed() && offset === 0) {
  13411. var key = selection.getAnchorKey();
  13412. var content = editorState.getCurrentContent();
  13413. var block = content.getBlockForKey(key);
  13414. var firstBlock = content.getFirstBlock();
  13415. if (block.getLength() > 0 && block !== firstBlock) {
  13416. return null;
  13417. }
  13418. var type = block.getType();
  13419. var blockBefore = content.getBlockBefore(key);
  13420. if (type === 'code-block' && blockBefore && blockBefore.getType() === 'code-block' && blockBefore.getLength() !== 0) {
  13421. return null;
  13422. }
  13423. if (type !== 'unstyled') {
  13424. return DraftModifier_1.setBlockType(content, selection, 'unstyled');
  13425. }
  13426. }
  13427. return null;
  13428. }
  13429. };
  13430. var RichTextEditorUtil_1 = RichTextEditorUtil;
  13431. /**
  13432. * Copyright (c) 2013-present, Facebook, Inc.
  13433. * All rights reserved.
  13434. *
  13435. * This source code is licensed under the BSD-style license found in the
  13436. * LICENSE file in the root directory of this source tree. An additional grant
  13437. * of patent rights can be found in the PATENTS file in the same directory.
  13438. *
  13439. * @providesModule splitTextIntoTextBlocks
  13440. * @format
  13441. *
  13442. */
  13443. var NEWLINE_REGEX = /\r\n?|\n/g;
  13444. function splitTextIntoTextBlocks(text) {
  13445. return text.split(NEWLINE_REGEX);
  13446. }
  13447. var splitTextIntoTextBlocks_1 = splitTextIntoTextBlocks;
  13448. /**
  13449. * Paste content.
  13450. */
  13451. function editOnPaste(editor, e) {
  13452. e.preventDefault();
  13453. var data = new DataTransfer_1(e.clipboardData);
  13454. // Get files, unless this is likely to be a string the user wants inline.
  13455. if (!data.isRichText()) {
  13456. var files = data.getFiles();
  13457. var defaultFileText = data.getText();
  13458. if (files.length > 0) {
  13459. // Allow customized paste handling for images, etc. Otherwise, fall
  13460. // through to insert text contents into the editor.
  13461. if (editor.props.handlePastedFiles && isEventHandled_1(editor.props.handlePastedFiles(files))) {
  13462. return;
  13463. }
  13464. getTextContentFromFiles_1(files, function ( /*string*/fileText) {
  13465. fileText = fileText || defaultFileText;
  13466. if (!fileText) {
  13467. return;
  13468. }
  13469. var editorState = editor._latestEditorState;
  13470. var blocks = splitTextIntoTextBlocks_1(fileText);
  13471. var character = CharacterMetadata_1.create({
  13472. style: editorState.getCurrentInlineStyle(),
  13473. entity: getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())
  13474. });
  13475. var currentBlockType = RichTextEditorUtil_1.getCurrentBlockType(editorState);
  13476. var text = DraftPasteProcessor_1.processText(blocks, character, currentBlockType);
  13477. var fragment = BlockMapBuilder_1.createFromArray(text);
  13478. var withInsertedText = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), fragment);
  13479. editor.update(EditorState_1.push(editorState, withInsertedText, 'insert-fragment'));
  13480. });
  13481. return;
  13482. }
  13483. }
  13484. var textBlocks = [];
  13485. var text = data.getText();
  13486. var html = data.getHTML();
  13487. var editorState = editor._latestEditorState;
  13488. if (editor.props.handlePastedText && isEventHandled_1(editor.props.handlePastedText(text, html, editorState))) {
  13489. return;
  13490. }
  13491. if (text) {
  13492. textBlocks = splitTextIntoTextBlocks_1(text);
  13493. }
  13494. if (!editor.props.stripPastedStyles) {
  13495. // If the text from the paste event is rich content that matches what we
  13496. // already have on the internal clipboard, assume that we should just use
  13497. // the clipboard fragment for the paste. This will allow us to preserve
  13498. // styling and entities, if any are present. Note that newlines are
  13499. // stripped during comparison -- this is because copy/paste within the
  13500. // editor in Firefox and IE will not include empty lines. The resulting
  13501. // paste will preserve the newlines correctly.
  13502. var internalClipboard = editor.getClipboard();
  13503. if (data.isRichText() && internalClipboard) {
  13504. if (
  13505. // If the editorKey is present in the pasted HTML, it should be safe to
  13506. // assume this is an internal paste.
  13507. html.indexOf(editor.getEditorKey()) !== -1 ||
  13508. // The copy may have been made within a single block, in which case the
  13509. // editor key won't be part of the paste. In this case, just check
  13510. // whether the pasted text matches the internal clipboard.
  13511. textBlocks.length === 1 && internalClipboard.size === 1 && internalClipboard.first().getText() === text) {
  13512. editor.update(insertFragment$1(editor._latestEditorState, internalClipboard));
  13513. return;
  13514. }
  13515. } else if (internalClipboard && data.types.includes('com.apple.webarchive') && !data.types.includes('text/html') && areTextBlocksAndClipboardEqual(textBlocks, internalClipboard)) {
  13516. // Safari does not properly store text/html in some cases.
  13517. // Use the internalClipboard if present and equal to what is on
  13518. // the clipboard. See https://bugs.webkit.org/show_bug.cgi?id=19893.
  13519. editor.update(insertFragment$1(editor._latestEditorState, internalClipboard));
  13520. return;
  13521. }
  13522. // If there is html paste data, try to parse that.
  13523. if (html) {
  13524. var htmlFragment = DraftPasteProcessor_1.processHTML(html, editor.props.blockRenderMap);
  13525. if (htmlFragment) {
  13526. var contentBlocks = htmlFragment.contentBlocks,
  13527. entityMap = htmlFragment.entityMap;
  13528. if (contentBlocks) {
  13529. var htmlMap = BlockMapBuilder_1.createFromArray(contentBlocks);
  13530. editor.update(insertFragment$1(editor._latestEditorState, htmlMap, entityMap));
  13531. return;
  13532. }
  13533. }
  13534. }
  13535. // Otherwise, create a new fragment from our pasted text. Also
  13536. // empty the internal clipboard, since it's no longer valid.
  13537. editor.setClipboard(null);
  13538. }
  13539. if (textBlocks.length) {
  13540. var character = CharacterMetadata_1.create({
  13541. style: editorState.getCurrentInlineStyle(),
  13542. entity: getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())
  13543. });
  13544. var currentBlockType = RichTextEditorUtil_1.getCurrentBlockType(editorState);
  13545. var textFragment = DraftPasteProcessor_1.processText(textBlocks, character, currentBlockType);
  13546. var textMap = BlockMapBuilder_1.createFromArray(textFragment);
  13547. editor.update(insertFragment$1(editor._latestEditorState, textMap));
  13548. }
  13549. }
  13550. function insertFragment$1(editorState, fragment, entityMap) {
  13551. var newContent = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), fragment);
  13552. // TODO: merge the entity map once we stop using DraftEntity
  13553. // like this:
  13554. // const mergedEntityMap = newContent.getEntityMap().merge(entityMap);
  13555. return EditorState_1.push(editorState, newContent.set('entityMap', entityMap), 'insert-fragment');
  13556. }
  13557. function areTextBlocksAndClipboardEqual(textBlocks, blockMap) {
  13558. return textBlocks.length === blockMap.size && blockMap.valueSeq().every(function (block, ii) {
  13559. return block.getText() === textBlocks[ii];
  13560. });
  13561. }
  13562. var editOnPaste_1 = editOnPaste;
  13563. /**
  13564. * Convert the current selection range to an anchor/focus pair of offset keys
  13565. * and values that can be interpreted by components.
  13566. */
  13567. function getDraftEditorSelection(editorState, root) {
  13568. var selection = commonjsGlobal.getSelection();
  13569. // No active selection.
  13570. if (selection.rangeCount === 0) {
  13571. return {
  13572. selectionState: editorState.getSelection().set('hasFocus', false),
  13573. needsRecovery: false
  13574. };
  13575. }
  13576. return getDraftEditorSelectionWithNodes_1(editorState, root, selection.anchorNode, selection.anchorOffset, selection.focusNode, selection.focusOffset);
  13577. }
  13578. var getDraftEditorSelection_1 = getDraftEditorSelection;
  13579. function editOnSelect(editor) {
  13580. if (editor._blockSelectEvents || editor._latestEditorState !== editor.props.editorState) {
  13581. return;
  13582. }
  13583. var editorState = editor.props.editorState;
  13584. var editorNode = require$$3.findDOMNode(editor.editorContainer);
  13585. !editorNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing editorNode') : invariant_1(false) : void 0;
  13586. !(editorNode.firstChild instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode.firstChild is not an HTMLElement') : invariant_1(false) : void 0;
  13587. var documentSelection = getDraftEditorSelection_1(editorState, editorNode.firstChild);
  13588. var updatedSelectionState = documentSelection.selectionState;
  13589. if (updatedSelectionState !== editorState.getSelection()) {
  13590. if (documentSelection.needsRecovery) {
  13591. editorState = EditorState_1.forceSelection(editorState, updatedSelectionState);
  13592. } else {
  13593. editorState = EditorState_1.acceptSelection(editorState, updatedSelectionState);
  13594. }
  13595. editor.update(editorState);
  13596. }
  13597. }
  13598. var editOnSelect_1 = editOnSelect;
  13599. var DraftEditorEditHandler = {
  13600. onBeforeInput: editOnBeforeInput_1,
  13601. onBlur: editOnBlur_1,
  13602. onCompositionStart: editOnCompositionStart_1,
  13603. onCopy: editOnCopy_1,
  13604. onCut: editOnCut_1,
  13605. onDragOver: editOnDragOver_1,
  13606. onDragStart: editOnDragStart_1,
  13607. onFocus: editOnFocus_1,
  13608. onInput: editOnInput_1,
  13609. onKeyDown: editOnKeyDown_1,
  13610. onPaste: editOnPaste_1,
  13611. onSelect: editOnSelect_1
  13612. };
  13613. var DraftEditorEditHandler_1 = DraftEditorEditHandler;
  13614. function _classCallCheck$f(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13615. function _possibleConstructorReturn$a(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  13616. function _inherits$a(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  13617. /**
  13618. * This component is responsible for rendering placeholder text for the
  13619. * `DraftEditor` component.
  13620. *
  13621. * Override placeholder style via CSS.
  13622. */
  13623. var DraftEditorPlaceholder = function (_React$Component) {
  13624. _inherits$a(DraftEditorPlaceholder, _React$Component);
  13625. function DraftEditorPlaceholder() {
  13626. _classCallCheck$f(this, DraftEditorPlaceholder);
  13627. return _possibleConstructorReturn$a(this, _React$Component.apply(this, arguments));
  13628. }
  13629. DraftEditorPlaceholder.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  13630. return this.props.text !== nextProps.text || this.props.editorState.getSelection().getHasFocus() !== nextProps.editorState.getSelection().getHasFocus();
  13631. };
  13632. DraftEditorPlaceholder.prototype.render = function render() {
  13633. var hasFocus = this.props.editorState.getSelection().getHasFocus();
  13634. var className = cx_1({
  13635. 'public/DraftEditorPlaceholder/root': true,
  13636. 'public/DraftEditorPlaceholder/hasFocus': hasFocus
  13637. });
  13638. var contentStyle = {
  13639. whiteSpace: 'pre-wrap'
  13640. };
  13641. return React.createElement(
  13642. 'div',
  13643. { className: className },
  13644. React.createElement(
  13645. 'div',
  13646. {
  13647. className: cx_1('public/DraftEditorPlaceholder/inner'),
  13648. id: this.props.accessibilityID,
  13649. style: contentStyle },
  13650. this.props.text
  13651. )
  13652. );
  13653. };
  13654. return DraftEditorPlaceholder;
  13655. }(React.Component);
  13656. var DraftEditorPlaceholder_react = DraftEditorPlaceholder;
  13657. var isOSX$1 = UserAgent_1.isPlatform('Mac OS X');
  13658. var isWindows = UserAgent_1.isPlatform('Windows');
  13659. // Firefox on OSX had a bug resulting in navigation instead of cursor movement.
  13660. // This bug was fixed in Firefox 29. Feature detection is virtually impossible
  13661. // so we just check the version number. See #342765.
  13662. var shouldFixFirefoxMovement = isOSX$1 && UserAgent_1.isBrowser('Firefox < 29');
  13663. var hasCommandModifier = KeyBindingUtil_1.hasCommandModifier,
  13664. isCtrlKeyCommand = KeyBindingUtil_1.isCtrlKeyCommand;
  13665. function shouldRemoveWord(e) {
  13666. return isOSX$1 && e.altKey || isCtrlKeyCommand(e);
  13667. }
  13668. /**
  13669. * Get the appropriate undo/redo command for a Z key command.
  13670. */
  13671. function getZCommand(e) {
  13672. if (!hasCommandModifier(e)) {
  13673. return null;
  13674. }
  13675. return e.shiftKey ? 'redo' : 'undo';
  13676. }
  13677. function getDeleteCommand(e) {
  13678. // Allow default "cut" behavior for Windows on Shift + Delete.
  13679. if (isWindows && e.shiftKey) {
  13680. return null;
  13681. }
  13682. return shouldRemoveWord(e) ? 'delete-word' : 'delete';
  13683. }
  13684. function getBackspaceCommand(e) {
  13685. if (hasCommandModifier(e) && isOSX$1) {
  13686. return 'backspace-to-start-of-line';
  13687. }
  13688. return shouldRemoveWord(e) ? 'backspace-word' : 'backspace';
  13689. }
  13690. /**
  13691. * Retrieve a bound key command for the given event.
  13692. */
  13693. function getDefaultKeyBinding(e) {
  13694. switch (e.keyCode) {
  13695. case 66:
  13696. // B
  13697. return hasCommandModifier(e) ? 'bold' : null;
  13698. case 68:
  13699. // D
  13700. return isCtrlKeyCommand(e) ? 'delete' : null;
  13701. case 72:
  13702. // H
  13703. return isCtrlKeyCommand(e) ? 'backspace' : null;
  13704. case 73:
  13705. // I
  13706. return hasCommandModifier(e) ? 'italic' : null;
  13707. case 74:
  13708. // J
  13709. return hasCommandModifier(e) ? 'code' : null;
  13710. case 75:
  13711. // K
  13712. return !isWindows && isCtrlKeyCommand(e) ? 'secondary-cut' : null;
  13713. case 77:
  13714. // M
  13715. return isCtrlKeyCommand(e) ? 'split-block' : null;
  13716. case 79:
  13717. // O
  13718. return isCtrlKeyCommand(e) ? 'split-block' : null;
  13719. case 84:
  13720. // T
  13721. return isOSX$1 && isCtrlKeyCommand(e) ? 'transpose-characters' : null;
  13722. case 85:
  13723. // U
  13724. return hasCommandModifier(e) ? 'underline' : null;
  13725. case 87:
  13726. // W
  13727. return isOSX$1 && isCtrlKeyCommand(e) ? 'backspace-word' : null;
  13728. case 89:
  13729. // Y
  13730. if (isCtrlKeyCommand(e)) {
  13731. return isWindows ? 'redo' : 'secondary-paste';
  13732. }
  13733. return null;
  13734. case 90:
  13735. // Z
  13736. return getZCommand(e) || null;
  13737. case Keys.RETURN:
  13738. return 'split-block';
  13739. case Keys.DELETE:
  13740. return getDeleteCommand(e);
  13741. case Keys.BACKSPACE:
  13742. return getBackspaceCommand(e);
  13743. // LEFT/RIGHT handlers serve as a workaround for a Firefox bug.
  13744. case Keys.LEFT:
  13745. return shouldFixFirefoxMovement && hasCommandModifier(e) ? 'move-selection-to-start-of-block' : null;
  13746. case Keys.RIGHT:
  13747. return shouldFixFirefoxMovement && hasCommandModifier(e) ? 'move-selection-to-end-of-block' : null;
  13748. default:
  13749. return null;
  13750. }
  13751. }
  13752. var getDefaultKeyBinding_1 = getDefaultKeyBinding;
  13753. var _extends$5 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  13754. function _classCallCheck$g(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13755. function _possibleConstructorReturn$b(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  13756. function _inherits$b(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  13757. var isIE = UserAgent_1.isBrowser('IE');
  13758. // IE does not support the `input` event on contentEditable, so we can't
  13759. // observe spellcheck behavior.
  13760. var allowSpellCheck = !isIE;
  13761. // Define a set of handler objects to correspond to each possible `mode`
  13762. // of editor behavior.
  13763. var handlerMap = {
  13764. edit: DraftEditorEditHandler_1,
  13765. composite: DraftEditorCompositionHandler_1,
  13766. drag: DraftEditorDragHandler_1,
  13767. cut: null,
  13768. render: null
  13769. };
  13770. /**
  13771. * `DraftEditor` is the root editor component. It composes a `contentEditable`
  13772. * div, and provides a wide variety of useful function props for managing the
  13773. * state of the editor. See `DraftEditorProps` for details.
  13774. */
  13775. var DraftEditor = function (_React$Component) {
  13776. _inherits$b(DraftEditor, _React$Component);
  13777. function DraftEditor(props) {
  13778. _classCallCheck$g(this, DraftEditor);
  13779. var _this = _possibleConstructorReturn$b(this, _React$Component.call(this, props));
  13780. _this.focus = function (scrollPosition) {
  13781. var editorState = _this.props.editorState;
  13782. var alreadyHasFocus = editorState.getSelection().getHasFocus();
  13783. var editorNode = require$$3.findDOMNode(_this.editor);
  13784. if (!editorNode) {
  13785. // once in a while people call 'focus' in a setTimeout, and the node has
  13786. // been deleted, so it can be null in that case.
  13787. return;
  13788. }
  13789. var scrollParent = Style_1.getScrollParent(editorNode);
  13790. var _ref = scrollPosition || getScrollPosition_1(scrollParent),
  13791. x = _ref.x,
  13792. y = _ref.y;
  13793. !(editorNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode is not an HTMLElement') : invariant_1(false) : void 0;
  13794. editorNode.focus();
  13795. // Restore scroll position
  13796. if (scrollParent === window) {
  13797. window.scrollTo(x, y);
  13798. } else {
  13799. Scroll_1.setTop(scrollParent, y);
  13800. }
  13801. // On Chrome and Safari, calling focus on contenteditable focuses the
  13802. // cursor at the first character. This is something you don't expect when
  13803. // you're clicking on an input element but not directly on a character.
  13804. // Put the cursor back where it was before the blur.
  13805. if (!alreadyHasFocus) {
  13806. _this.update(EditorState_1.forceSelection(editorState, editorState.getSelection()));
  13807. }
  13808. };
  13809. _this.blur = function () {
  13810. var editorNode = require$$3.findDOMNode(_this.editor);
  13811. !(editorNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode is not an HTMLElement') : invariant_1(false) : void 0;
  13812. editorNode.blur();
  13813. };
  13814. _this.setMode = function (mode) {
  13815. _this._handler = handlerMap[mode];
  13816. };
  13817. _this.exitCurrentMode = function () {
  13818. _this.setMode('edit');
  13819. };
  13820. _this.restoreEditorDOM = function (scrollPosition) {
  13821. _this.setState({ contentsKey: _this.state.contentsKey + 1 }, function () {
  13822. _this.focus(scrollPosition);
  13823. });
  13824. };
  13825. _this.setClipboard = function (clipboard) {
  13826. _this._clipboard = clipboard;
  13827. };
  13828. _this.getClipboard = function () {
  13829. return _this._clipboard;
  13830. };
  13831. _this.update = function (editorState) {
  13832. _this._latestEditorState = editorState;
  13833. _this.props.onChange(editorState);
  13834. };
  13835. _this.onDragEnter = function () {
  13836. _this._dragCount++;
  13837. };
  13838. _this.onDragLeave = function () {
  13839. _this._dragCount--;
  13840. if (_this._dragCount === 0) {
  13841. _this.exitCurrentMode();
  13842. }
  13843. };
  13844. _this._blockSelectEvents = false;
  13845. _this._clipboard = null;
  13846. _this._handler = null;
  13847. _this._dragCount = 0;
  13848. _this._editorKey = props.editorKey || generateRandomKey_1();
  13849. _this._placeholderAccessibilityID = 'placeholder-' + _this._editorKey;
  13850. _this._latestEditorState = props.editorState;
  13851. _this._latestCommittedEditorState = props.editorState;
  13852. _this._onBeforeInput = _this._buildHandler('onBeforeInput');
  13853. _this._onBlur = _this._buildHandler('onBlur');
  13854. _this._onCharacterData = _this._buildHandler('onCharacterData');
  13855. _this._onCompositionEnd = _this._buildHandler('onCompositionEnd');
  13856. _this._onCompositionStart = _this._buildHandler('onCompositionStart');
  13857. _this._onCopy = _this._buildHandler('onCopy');
  13858. _this._onCut = _this._buildHandler('onCut');
  13859. _this._onDragEnd = _this._buildHandler('onDragEnd');
  13860. _this._onDragOver = _this._buildHandler('onDragOver');
  13861. _this._onDragStart = _this._buildHandler('onDragStart');
  13862. _this._onDrop = _this._buildHandler('onDrop');
  13863. _this._onInput = _this._buildHandler('onInput');
  13864. _this._onFocus = _this._buildHandler('onFocus');
  13865. _this._onKeyDown = _this._buildHandler('onKeyDown');
  13866. _this._onKeyPress = _this._buildHandler('onKeyPress');
  13867. _this._onKeyUp = _this._buildHandler('onKeyUp');
  13868. _this._onMouseDown = _this._buildHandler('onMouseDown');
  13869. _this._onMouseUp = _this._buildHandler('onMouseUp');
  13870. _this._onPaste = _this._buildHandler('onPaste');
  13871. _this._onSelect = _this._buildHandler('onSelect');
  13872. _this.getEditorKey = function () {
  13873. return _this._editorKey;
  13874. };
  13875. // See `restoreEditorDOM()`.
  13876. _this.state = { contentsKey: 0 };
  13877. return _this;
  13878. }
  13879. /**
  13880. * Build a method that will pass the event to the specified handler method.
  13881. * This allows us to look up the correct handler function for the current
  13882. * editor mode, if any has been specified.
  13883. */
  13884. /**
  13885. * Define proxies that can route events to the current handler.
  13886. */
  13887. DraftEditor.prototype._buildHandler = function _buildHandler(eventName) {
  13888. var _this2 = this;
  13889. return function (e) {
  13890. if (!_this2.props.readOnly) {
  13891. var method = _this2._handler && _this2._handler[eventName];
  13892. method && method(_this2, e);
  13893. }
  13894. };
  13895. };
  13896. DraftEditor.prototype._showPlaceholder = function _showPlaceholder() {
  13897. return !!this.props.placeholder && !this.props.editorState.isInCompositionMode() && !this.props.editorState.getCurrentContent().hasText();
  13898. };
  13899. DraftEditor.prototype._renderPlaceholder = function _renderPlaceholder() {
  13900. if (this._showPlaceholder()) {
  13901. var placeHolderProps = {
  13902. text: nullthrows_1(this.props.placeholder),
  13903. editorState: this.props.editorState,
  13904. textAlignment: this.props.textAlignment,
  13905. accessibilityID: this._placeholderAccessibilityID
  13906. };
  13907. return React.createElement(DraftEditorPlaceholder_react, placeHolderProps);
  13908. }
  13909. return null;
  13910. };
  13911. DraftEditor.prototype.render = function render() {
  13912. var _this3 = this;
  13913. var _props = this.props,
  13914. blockRenderMap = _props.blockRenderMap,
  13915. blockRendererFn = _props.blockRendererFn,
  13916. blockStyleFn = _props.blockStyleFn,
  13917. customStyleFn = _props.customStyleFn,
  13918. customStyleMap = _props.customStyleMap,
  13919. editorState = _props.editorState,
  13920. readOnly = _props.readOnly,
  13921. textAlignment = _props.textAlignment,
  13922. textDirectionality = _props.textDirectionality;
  13923. var rootClass = cx_1({
  13924. 'DraftEditor/root': true,
  13925. 'DraftEditor/alignLeft': textAlignment === 'left',
  13926. 'DraftEditor/alignRight': textAlignment === 'right',
  13927. 'DraftEditor/alignCenter': textAlignment === 'center'
  13928. });
  13929. var contentStyle = {
  13930. outline: 'none',
  13931. // fix parent-draggable Safari bug. #1326
  13932. userSelect: 'text',
  13933. WebkitUserSelect: 'text',
  13934. whiteSpace: 'pre-wrap',
  13935. wordWrap: 'break-word'
  13936. };
  13937. // The aria-expanded and aria-haspopup properties should only be rendered
  13938. // for a combobox.
  13939. var ariaRole = this.props.role || 'textbox';
  13940. var ariaExpanded = ariaRole === 'combobox' ? !!this.props.ariaExpanded : null;
  13941. var editorContentsProps = {
  13942. blockRenderMap: blockRenderMap,
  13943. blockRendererFn: blockRendererFn,
  13944. blockStyleFn: blockStyleFn,
  13945. customStyleMap: _extends$5({}, DefaultDraftInlineStyle, customStyleMap),
  13946. customStyleFn: customStyleFn,
  13947. editorKey: this._editorKey,
  13948. editorState: editorState,
  13949. key: 'contents' + this.state.contentsKey,
  13950. textDirectionality: textDirectionality
  13951. };
  13952. return React.createElement(
  13953. 'div',
  13954. { className: rootClass },
  13955. this._renderPlaceholder(),
  13956. React.createElement(
  13957. 'div',
  13958. {
  13959. className: cx_1('DraftEditor/editorContainer'),
  13960. ref: function ref(_ref3) {
  13961. return _this3.editorContainer = _ref3;
  13962. } },
  13963. React.createElement(
  13964. 'div',
  13965. {
  13966. 'aria-activedescendant': readOnly ? null : this.props.ariaActiveDescendantID,
  13967. 'aria-autocomplete': readOnly ? null : this.props.ariaAutoComplete,
  13968. 'aria-controls': readOnly ? null : this.props.ariaControls,
  13969. 'aria-describedby': this.props.ariaDescribedBy || this._placeholderAccessibilityID,
  13970. 'aria-expanded': readOnly ? null : ariaExpanded,
  13971. 'aria-label': this.props.ariaLabel,
  13972. 'aria-labelledby': this.props.ariaLabelledBy,
  13973. 'aria-multiline': this.props.ariaMultiline,
  13974. autoCapitalize: this.props.autoCapitalize,
  13975. autoComplete: this.props.autoComplete,
  13976. autoCorrect: this.props.autoCorrect,
  13977. className: cx_1({
  13978. // Chrome's built-in translation feature mutates the DOM in ways
  13979. // that Draft doesn't expect (ex: adding <font> tags inside
  13980. // DraftEditorLeaf spans) and causes problems. We add notranslate
  13981. // here which makes its autotranslation skip over this subtree.
  13982. notranslate: !readOnly,
  13983. 'public/DraftEditor/content': true
  13984. }),
  13985. contentEditable: !readOnly,
  13986. 'data-testid': this.props.webDriverTestID,
  13987. onBeforeInput: this._onBeforeInput,
  13988. onBlur: this._onBlur,
  13989. onCompositionEnd: this._onCompositionEnd,
  13990. onCompositionStart: this._onCompositionStart,
  13991. onCopy: this._onCopy,
  13992. onCut: this._onCut,
  13993. onDragEnd: this._onDragEnd,
  13994. onDragEnter: this.onDragEnter,
  13995. onDragLeave: this.onDragLeave,
  13996. onDragOver: this._onDragOver,
  13997. onDragStart: this._onDragStart,
  13998. onDrop: this._onDrop,
  13999. onFocus: this._onFocus,
  14000. onInput: this._onInput,
  14001. onKeyDown: this._onKeyDown,
  14002. onKeyPress: this._onKeyPress,
  14003. onKeyUp: this._onKeyUp,
  14004. onMouseUp: this._onMouseUp,
  14005. onPaste: this._onPaste,
  14006. onSelect: this._onSelect,
  14007. ref: function ref(_ref2) {
  14008. return _this3.editor = _ref2;
  14009. },
  14010. role: readOnly ? null : ariaRole,
  14011. spellCheck: allowSpellCheck && this.props.spellCheck,
  14012. style: contentStyle,
  14013. suppressContentEditableWarning: true,
  14014. tabIndex: this.props.tabIndex },
  14015. React.createElement(DraftEditorContents_react, editorContentsProps)
  14016. )
  14017. )
  14018. );
  14019. };
  14020. DraftEditor.prototype.componentDidMount = function componentDidMount() {
  14021. this.setMode('edit');
  14022. /**
  14023. * IE has a hardcoded "feature" that attempts to convert link text into
  14024. * anchors in contentEditable DOM. This breaks the editor's expectations of
  14025. * the DOM, and control is lost. Disable it to make IE behave.
  14026. * See: http://blogs.msdn.com/b/ieinternals/archive/2010/09/15/
  14027. * ie9-beta-minor-change-list.aspx
  14028. */
  14029. if (isIE) {
  14030. document.execCommand('AutoUrlDetect', false, false);
  14031. }
  14032. };
  14033. /**
  14034. * Prevent selection events from affecting the current editor state. This
  14035. * is mostly intended to defend against IE, which fires off `selectionchange`
  14036. * events regardless of whether the selection is set via the browser or
  14037. * programmatically. We only care about selection events that occur because
  14038. * of browser interaction, not re-renders and forced selections.
  14039. */
  14040. DraftEditor.prototype.componentWillUpdate = function componentWillUpdate(nextProps) {
  14041. this._blockSelectEvents = true;
  14042. this._latestEditorState = nextProps.editorState;
  14043. };
  14044. DraftEditor.prototype.componentDidUpdate = function componentDidUpdate() {
  14045. this._blockSelectEvents = false;
  14046. this._latestCommittedEditorState = this.props.editorState;
  14047. };
  14048. /**
  14049. * Used via `this.focus()`.
  14050. *
  14051. * Force focus back onto the editor node.
  14052. *
  14053. * We attempt to preserve scroll position when focusing. You can also pass
  14054. * a specified scroll position (for cases like `cut` behavior where it should
  14055. * be restored to a known position).
  14056. */
  14057. /**
  14058. * Used via `this.setMode(...)`.
  14059. *
  14060. * Set the behavior mode for the editor component. This switches the current
  14061. * handler module to ensure that DOM events are managed appropriately for
  14062. * the active mode.
  14063. */
  14064. /**
  14065. * Used via `this.restoreEditorDOM()`.
  14066. *
  14067. * Force a complete re-render of the DraftEditorContents based on the current
  14068. * EditorState. This is useful when we know we are going to lose control of
  14069. * the DOM state (cut command, IME) and we want to make sure that
  14070. * reconciliation occurs on a version of the DOM that is synchronized with
  14071. * our EditorState.
  14072. */
  14073. /**
  14074. * Used via `this.setClipboard(...)`.
  14075. *
  14076. * Set the clipboard state for a cut/copy event.
  14077. */
  14078. /**
  14079. * Used via `this.getClipboard()`.
  14080. *
  14081. * Retrieve the clipboard state for a cut/copy event.
  14082. */
  14083. /**
  14084. * Used via `this.update(...)`.
  14085. *
  14086. * Propagate a new `EditorState` object to higher-level components. This is
  14087. * the method by which event handlers inform the `DraftEditor` component of
  14088. * state changes. A component that composes a `DraftEditor` **must** provide
  14089. * an `onChange` prop to receive state updates passed along from this
  14090. * function.
  14091. */
  14092. /**
  14093. * Used in conjunction with `onDragLeave()`, by counting the number of times
  14094. * a dragged element enters and leaves the editor (or any of its children),
  14095. * to determine when the dragged element absolutely leaves the editor.
  14096. */
  14097. /**
  14098. * See `onDragEnter()`.
  14099. */
  14100. return DraftEditor;
  14101. }(React.Component);
  14102. DraftEditor.defaultProps = {
  14103. blockRenderMap: DefaultDraftBlockRenderMap_1,
  14104. blockRendererFn: emptyFunction_1.thatReturnsNull,
  14105. blockStyleFn: emptyFunction_1.thatReturns(''),
  14106. keyBindingFn: getDefaultKeyBinding_1,
  14107. readOnly: false,
  14108. spellCheck: false,
  14109. stripPastedStyles: false
  14110. };
  14111. var DraftEditor_react = DraftEditor;
  14112. /**
  14113. * Copyright (c) 2013-present, Facebook, Inc.
  14114. * All rights reserved.
  14115. *
  14116. * This source code is licensed under the BSD-style license found in the
  14117. * LICENSE file in the root directory of this source tree. An additional grant
  14118. * of patent rights can be found in the PATENTS file in the same directory.
  14119. *
  14120. * @providesModule DraftStringKey
  14121. * @format
  14122. *
  14123. */
  14124. var DraftStringKey = {
  14125. stringify: function stringify(key) {
  14126. return '_' + String(key);
  14127. },
  14128. unstringify: function unstringify(key) {
  14129. return key.slice(1);
  14130. }
  14131. };
  14132. var DraftStringKey_1 = DraftStringKey;
  14133. var strlen$1 = UnicodeUtils_1.strlen;
  14134. /**
  14135. * Convert to UTF-8 character counts for storage.
  14136. */
  14137. function encodeEntityRanges(block, storageMap) {
  14138. var encoded = [];
  14139. block.findEntityRanges(function (character) {
  14140. return !!character.getEntity();
  14141. }, function ( /*number*/start, /*number*/end) {
  14142. var text = block.getText();
  14143. var key = block.getEntityAt(start);
  14144. encoded.push({
  14145. offset: strlen$1(text.slice(0, start)),
  14146. length: strlen$1(text.slice(start, end)),
  14147. // Encode the key as a number for range storage.
  14148. key: Number(storageMap[DraftStringKey_1.stringify(key)])
  14149. });
  14150. });
  14151. return encoded;
  14152. }
  14153. var encodeEntityRanges_1 = encodeEntityRanges;
  14154. var areEqual$1 = function areEqual(a, b) {
  14155. return a === b;
  14156. };
  14157. var isTruthy = function isTruthy(a) {
  14158. return !!a;
  14159. };
  14160. var EMPTY_ARRAY = [];
  14161. /**
  14162. * Helper function for getting encoded styles for each inline style. Convert
  14163. * to UTF-8 character counts for storage.
  14164. */
  14165. function getEncodedInlinesForType(block, styleList, styleToEncode) {
  14166. var ranges = [];
  14167. // Obtain an array with ranges for only the specified style.
  14168. var filteredInlines = styleList.map(function (style) {
  14169. return style.has(styleToEncode);
  14170. }).toList();
  14171. findRangesImmutable_1(filteredInlines, areEqual$1,
  14172. // We only want to keep ranges with nonzero style values.
  14173. isTruthy, function (start, end) {
  14174. var text = block.getText();
  14175. ranges.push({
  14176. offset: UnicodeUtils_1.strlen(text.slice(0, start)),
  14177. length: UnicodeUtils_1.strlen(text.slice(start, end)),
  14178. style: styleToEncode
  14179. });
  14180. });
  14181. return ranges;
  14182. }
  14183. /*
  14184. * Retrieve the encoded arrays of inline styles, with each individual style
  14185. * treated separately.
  14186. */
  14187. function encodeInlineStyleRanges(block) {
  14188. var styleList = block.getCharacterList().map(function (c) {
  14189. return c.getStyle();
  14190. }).toList();
  14191. var ranges = styleList.flatten().toSet().map(function (style) {
  14192. return getEncodedInlinesForType(block, styleList, style);
  14193. });
  14194. return Array.prototype.concat.apply(EMPTY_ARRAY, ranges.toJS());
  14195. }
  14196. var encodeInlineStyleRanges_1 = encodeInlineStyleRanges;
  14197. var _extends$6 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  14198. var createRawBlock = function createRawBlock(block, entityStorageMap) {
  14199. return {
  14200. key: block.getKey(),
  14201. text: block.getText(),
  14202. type: block.getType(),
  14203. depth: block.getDepth(),
  14204. inlineStyleRanges: encodeInlineStyleRanges_1(block),
  14205. entityRanges: encodeEntityRanges_1(block, entityStorageMap),
  14206. data: block.getData().toObject()
  14207. };
  14208. };
  14209. var insertRawBlock = function insertRawBlock(block, entityMap, rawBlocks, blockCacheRef) {
  14210. if (block instanceof ContentBlock_1) {
  14211. rawBlocks.push(createRawBlock(block, entityMap));
  14212. return;
  14213. }
  14214. !(block instanceof ContentBlockNode_1) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'block is not a BlockNode') : invariant_1(false) : void 0;
  14215. var parentKey = block.getParentKey();
  14216. var rawBlock = blockCacheRef[block.getKey()] = _extends$6({}, createRawBlock(block, entityMap), {
  14217. children: []
  14218. });
  14219. if (parentKey) {
  14220. blockCacheRef[parentKey].children.push(rawBlock);
  14221. return;
  14222. }
  14223. rawBlocks.push(rawBlock);
  14224. };
  14225. var encodeRawBlocks = function encodeRawBlocks(contentState, rawState) {
  14226. var entityMap = rawState.entityMap;
  14227. var rawBlocks = [];
  14228. var blockCacheRef = {};
  14229. var entityCacheRef = {};
  14230. var entityStorageKey = 0;
  14231. contentState.getBlockMap().forEach(function (block) {
  14232. block.findEntityRanges(function (character) {
  14233. return character.getEntity() !== null;
  14234. }, function (start) {
  14235. var entityKey = block.getEntityAt(start);
  14236. // Stringify to maintain order of otherwise numeric keys.
  14237. var stringifiedEntityKey = DraftStringKey_1.stringify(entityKey);
  14238. // This makes this function resilient to two entities
  14239. // erroneously having the same key
  14240. if (entityCacheRef[stringifiedEntityKey]) {
  14241. return;
  14242. }
  14243. entityCacheRef[stringifiedEntityKey] = entityKey;
  14244. // we need the `any` casting here since this is a temporary state
  14245. // where we will later on flip the entity map and populate it with
  14246. // real entity, at this stage we just need to map back the entity
  14247. // key used by the BlockNode
  14248. entityMap[stringifiedEntityKey] = '' + entityStorageKey;
  14249. entityStorageKey++;
  14250. });
  14251. insertRawBlock(block, entityMap, rawBlocks, blockCacheRef);
  14252. });
  14253. return {
  14254. blocks: rawBlocks,
  14255. entityMap: entityMap
  14256. };
  14257. };
  14258. // Flip storage map so that our storage keys map to global
  14259. // DraftEntity keys.
  14260. var encodeRawEntityMap = function encodeRawEntityMap(contentState, rawState) {
  14261. var blocks = rawState.blocks,
  14262. entityMap = rawState.entityMap;
  14263. var rawEntityMap = {};
  14264. Object.keys(entityMap).forEach(function (key, index) {
  14265. var entity = contentState.getEntity(DraftStringKey_1.unstringify(key));
  14266. rawEntityMap[index] = {
  14267. type: entity.getType(),
  14268. mutability: entity.getMutability(),
  14269. data: entity.getData()
  14270. };
  14271. });
  14272. return {
  14273. blocks: blocks,
  14274. entityMap: rawEntityMap
  14275. };
  14276. };
  14277. var convertFromDraftStateToRaw = function convertFromDraftStateToRaw(contentState) {
  14278. var rawDraftContentState = {
  14279. entityMap: {},
  14280. blocks: []
  14281. };
  14282. // add blocks
  14283. rawDraftContentState = encodeRawBlocks(contentState, rawDraftContentState);
  14284. // add entities
  14285. rawDraftContentState = encodeRawEntityMap(contentState, rawDraftContentState);
  14286. return rawDraftContentState;
  14287. };
  14288. var convertFromDraftStateToRaw_1 = convertFromDraftStateToRaw;
  14289. var _extends$7 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  14290. /**
  14291. * Copyright (c) 2013-present, Facebook, Inc.
  14292. * All rights reserved.
  14293. *
  14294. * This source code is licensed under the BSD-style license found in the
  14295. * LICENSE file in the root directory of this source tree. An additional grant
  14296. * of patent rights can be found in the PATENTS file in the same directory.
  14297. *
  14298. * @providesModule DraftTreeAdapter
  14299. * @format
  14300. *
  14301. *
  14302. * This is unstable and not part of the public API and should not be used by
  14303. * production systems. This file may be update/removed without notice.
  14304. */
  14305. var traverseInDepthOrder = function traverseInDepthOrder(blocks, fn) {
  14306. var stack = [].concat(blocks).reverse();
  14307. while (stack.length) {
  14308. var _block = stack.pop();
  14309. fn(_block);
  14310. var children = _block.children;
  14311. !Array.isArray(children) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid tree raw block') : invariant_1(false) : void 0;
  14312. stack = stack.concat([].concat(children.reverse()));
  14313. }
  14314. };
  14315. var isListBlock = function isListBlock(block) {
  14316. if (!(block && block.type)) {
  14317. return false;
  14318. }
  14319. var type = block.type;
  14320. return type === 'unordered-list-item' || type === 'ordered-list-item';
  14321. };
  14322. var addDepthToChildren = function addDepthToChildren(block) {
  14323. if (Array.isArray(block.children)) {
  14324. block.children = block.children.map(function (child) {
  14325. return child.type === block.type ? _extends$7({}, child, { depth: (block.depth || 0) + 1 }) : child;
  14326. });
  14327. }
  14328. };
  14329. /**
  14330. * This adapter is intended to be be used as an adapter to draft tree data
  14331. *
  14332. * draft state <=====> draft tree state
  14333. */
  14334. var DraftTreeAdapter = {
  14335. /**
  14336. * Converts from a tree raw state back to draft raw state
  14337. */
  14338. fromRawTreeStateToRawState: function fromRawTreeStateToRawState(draftTreeState) {
  14339. var blocks = draftTreeState.blocks;
  14340. var transformedBlocks = [];
  14341. !Array.isArray(blocks) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid raw state') : invariant_1(false) : void 0;
  14342. if (!Array.isArray(blocks) || !blocks.length) {
  14343. return draftTreeState;
  14344. }
  14345. traverseInDepthOrder(blocks, function (block) {
  14346. var newBlock = _extends$7({}, block);
  14347. if (isListBlock(block)) {
  14348. newBlock.depth = newBlock.depth || 0;
  14349. addDepthToChildren(block);
  14350. }
  14351. delete newBlock.children;
  14352. transformedBlocks.push(newBlock);
  14353. });
  14354. draftTreeState.blocks = transformedBlocks;
  14355. return _extends$7({}, draftTreeState, {
  14356. blocks: transformedBlocks
  14357. });
  14358. },
  14359. /**
  14360. * Converts from draft raw state to tree draft state
  14361. */
  14362. fromRawStateToRawTreeState: function fromRawStateToRawTreeState(draftState) {
  14363. var lastListDepthCacheRef = {};
  14364. var transformedBlocks = [];
  14365. draftState.blocks.forEach(function (block) {
  14366. var isList = isListBlock(block);
  14367. var depth = block.depth || 0;
  14368. var treeBlock = _extends$7({}, block, {
  14369. children: []
  14370. });
  14371. if (!isList) {
  14372. // reset the cache path
  14373. lastListDepthCacheRef = {};
  14374. transformedBlocks.push(treeBlock);
  14375. return;
  14376. }
  14377. // update our depth cache reference path
  14378. lastListDepthCacheRef[depth] = treeBlock;
  14379. // if we are greater than zero we must have seen a parent already
  14380. if (depth > 0) {
  14381. var parent = lastListDepthCacheRef[depth - 1];
  14382. !parent ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid depth for RawDraftContentBlock') : invariant_1(false) : void 0;
  14383. // push nested list blocks
  14384. parent.children.push(treeBlock);
  14385. return;
  14386. }
  14387. // push root list blocks
  14388. transformedBlocks.push(treeBlock);
  14389. });
  14390. return _extends$7({}, draftState, {
  14391. blocks: transformedBlocks
  14392. });
  14393. }
  14394. };
  14395. var DraftTreeAdapter_1 = DraftTreeAdapter;
  14396. var List$c = immutable.List;
  14397. function createCharacterList(inlineStyles, entities) {
  14398. var characterArray = inlineStyles.map(function (style, ii) {
  14399. var entity = entities[ii];
  14400. return CharacterMetadata_1.create({ style: style, entity: entity });
  14401. });
  14402. return List$c(characterArray);
  14403. }
  14404. var createCharacterList_1 = createCharacterList;
  14405. var substr$1 = UnicodeUtils_1.substr;
  14406. /**
  14407. * Convert to native JavaScript string lengths to determine ranges.
  14408. */
  14409. function decodeEntityRanges(text, ranges) {
  14410. var entities = Array(text.length).fill(null);
  14411. if (ranges) {
  14412. ranges.forEach(function (range) {
  14413. // Using Unicode-enabled substrings converted to JavaScript lengths,
  14414. // fill the output array with entity keys.
  14415. var start = substr$1(text, 0, range.offset).length;
  14416. var end = start + substr$1(text, range.offset, range.length).length;
  14417. for (var ii = start; ii < end; ii++) {
  14418. entities[ii] = range.key;
  14419. }
  14420. });
  14421. }
  14422. return entities;
  14423. }
  14424. var decodeEntityRanges_1 = decodeEntityRanges;
  14425. var OrderedSet$6 = immutable.OrderedSet;
  14426. var substr$2 = UnicodeUtils_1.substr;
  14427. var EMPTY_SET$3 = OrderedSet$6();
  14428. /**
  14429. * Convert to native JavaScript string lengths to determine ranges.
  14430. */
  14431. function decodeInlineStyleRanges(text, ranges) {
  14432. var styles = Array(text.length).fill(EMPTY_SET$3);
  14433. if (ranges) {
  14434. ranges.forEach(function ( /*object*/range) {
  14435. var cursor = substr$2(text, 0, range.offset).length;
  14436. var end = cursor + substr$2(text, range.offset, range.length).length;
  14437. while (cursor < end) {
  14438. styles[cursor] = styles[cursor].add(range.style);
  14439. cursor++;
  14440. }
  14441. });
  14442. }
  14443. return styles;
  14444. }
  14445. var decodeInlineStyleRanges_1 = decodeInlineStyleRanges;
  14446. var _extends$8 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  14447. var List$d = immutable.List,
  14448. Map$9 = immutable.Map,
  14449. OrderedMap$4 = immutable.OrderedMap;
  14450. var decodeBlockNodeConfig = function decodeBlockNodeConfig(block, entityMap) {
  14451. var key = block.key,
  14452. type = block.type,
  14453. data = block.data,
  14454. text = block.text,
  14455. depth = block.depth;
  14456. var blockNodeConfig = {
  14457. text: text,
  14458. depth: depth || 0,
  14459. type: type || 'unstyled',
  14460. key: key || generateRandomKey_1(),
  14461. data: Map$9(data),
  14462. characterList: decodeCharacterList(block, entityMap)
  14463. };
  14464. return blockNodeConfig;
  14465. };
  14466. var decodeCharacterList = function decodeCharacterList(block, entityMap) {
  14467. var text = block.text,
  14468. rawEntityRanges = block.entityRanges,
  14469. rawInlineStyleRanges = block.inlineStyleRanges;
  14470. var entityRanges = rawEntityRanges || [];
  14471. var inlineStyleRanges = rawInlineStyleRanges || [];
  14472. // Translate entity range keys to the DraftEntity map.
  14473. return createCharacterList_1(decodeInlineStyleRanges_1(text, inlineStyleRanges), decodeEntityRanges_1(text, entityRanges.filter(function (range) {
  14474. return entityMap.hasOwnProperty(range.key);
  14475. }).map(function (range) {
  14476. return _extends$8({}, range, { key: entityMap[range.key] });
  14477. })));
  14478. };
  14479. var decodeContentBlocks = function decodeContentBlocks(blocks, entityMap) {
  14480. return OrderedMap$4(blocks.map(function (block) {
  14481. var contentBlock = new ContentBlock_1(decodeBlockNodeConfig(block, entityMap));
  14482. return [contentBlock.getKey(), contentBlock];
  14483. }));
  14484. };
  14485. var decodeRawBlocks = function decodeRawBlocks(rawState, entityMap) {
  14486. var isTreeRawBlock = Array.isArray(rawState.blocks[0].children);
  14487. var rawBlocks = rawState.blocks;
  14488. {
  14489. return decodeContentBlocks(isTreeRawBlock ? DraftTreeAdapter_1.fromRawTreeStateToRawState(rawState).blocks : rawBlocks, entityMap);
  14490. }
  14491. };
  14492. var decodeRawEntityMap = function decodeRawEntityMap(rawState) {
  14493. var rawEntityMap = rawState.entityMap;
  14494. var entityMap = {};
  14495. // TODO: Update this once we completely remove DraftEntity
  14496. Object.keys(rawEntityMap).forEach(function (rawEntityKey) {
  14497. var _rawEntityMap$rawEnti = rawEntityMap[rawEntityKey],
  14498. type = _rawEntityMap$rawEnti.type,
  14499. mutability = _rawEntityMap$rawEnti.mutability,
  14500. data = _rawEntityMap$rawEnti.data;
  14501. // get the key reference to created entity
  14502. entityMap[rawEntityKey] = DraftEntity_1.__create(type, mutability, data || {});
  14503. });
  14504. return entityMap;
  14505. };
  14506. var convertFromRawToDraftState = function convertFromRawToDraftState(rawState) {
  14507. !Array.isArray(rawState.blocks) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'invalid RawDraftContentState') : invariant_1(false) : void 0;
  14508. // decode entities
  14509. var entityMap = decodeRawEntityMap(rawState);
  14510. // decode blockMap
  14511. var blockMap = decodeRawBlocks(rawState, entityMap);
  14512. // create initial selection
  14513. var selectionState = blockMap.isEmpty() ? new SelectionState_1() : SelectionState_1.createEmpty(blockMap.first().getKey());
  14514. return new ContentState_1({
  14515. blockMap: blockMap,
  14516. entityMap: entityMap,
  14517. selectionBefore: selectionState,
  14518. selectionAfter: selectionState
  14519. });
  14520. };
  14521. var convertFromRawToDraftState_1 = convertFromRawToDraftState;
  14522. /**
  14523. * Like range.getBoundingClientRect() but normalizes for browser bugs.
  14524. */
  14525. function getRangeBoundingClientRect(range) {
  14526. // "Return a DOMRect object describing the smallest rectangle that includes
  14527. // the first rectangle in list and all of the remaining rectangles of which
  14528. // the height or width is not zero."
  14529. // http://www.w3.org/TR/cssom-view/#dom-range-getboundingclientrect
  14530. var rects = getRangeClientRects_1(range);
  14531. var top = 0;
  14532. var right = 0;
  14533. var bottom = 0;
  14534. var left = 0;
  14535. if (rects.length) {
  14536. // If the first rectangle has 0 width, we use the second, this is needed
  14537. // because Chrome renders a 0 width rectangle when the selection contains
  14538. // a line break.
  14539. if (rects.length > 1 && rects[0].width === 0) {
  14540. var _rects$ = rects[1];
  14541. top = _rects$.top;
  14542. right = _rects$.right;
  14543. bottom = _rects$.bottom;
  14544. left = _rects$.left;
  14545. } else {
  14546. var _rects$2 = rects[0];
  14547. top = _rects$2.top;
  14548. right = _rects$2.right;
  14549. bottom = _rects$2.bottom;
  14550. left = _rects$2.left;
  14551. }
  14552. for (var ii = 1; ii < rects.length; ii++) {
  14553. var rect = rects[ii];
  14554. if (rect.height !== 0 && rect.width !== 0) {
  14555. top = Math.min(top, rect.top);
  14556. right = Math.max(right, rect.right);
  14557. bottom = Math.max(bottom, rect.bottom);
  14558. left = Math.min(left, rect.left);
  14559. }
  14560. }
  14561. }
  14562. return {
  14563. top: top,
  14564. right: right,
  14565. bottom: bottom,
  14566. left: left,
  14567. width: right - left,
  14568. height: bottom - top
  14569. };
  14570. }
  14571. var getRangeBoundingClientRect_1 = getRangeBoundingClientRect;
  14572. /**
  14573. * Return the bounding ClientRect for the visible DOM selection, if any.
  14574. * In cases where there are no selected ranges or the bounding rect is
  14575. * temporarily invalid, return null.
  14576. */
  14577. function getVisibleSelectionRect(global) {
  14578. var selection = global.getSelection();
  14579. if (!selection.rangeCount) {
  14580. return null;
  14581. }
  14582. var range = selection.getRangeAt(0);
  14583. var boundingRect = getRangeBoundingClientRect_1(range);
  14584. var top = boundingRect.top,
  14585. right = boundingRect.right,
  14586. bottom = boundingRect.bottom,
  14587. left = boundingRect.left;
  14588. // When a re-render leads to a node being removed, the DOM selection will
  14589. // temporarily be placed on an ancestor node, which leads to an invalid
  14590. // bounding rect. Discard this state.
  14591. if (top === 0 && right === 0 && bottom === 0 && left === 0) {
  14592. return null;
  14593. }
  14594. return boundingRect;
  14595. }
  14596. var getVisibleSelectionRect_1 = getVisibleSelectionRect;
  14597. var DraftPublic = {
  14598. Editor: DraftEditor_react,
  14599. EditorBlock: DraftEditorBlock_react,
  14600. EditorState: EditorState_1,
  14601. CompositeDecorator: CompositeDraftDecorator_1,
  14602. Entity: DraftEntity_1,
  14603. EntityInstance: DraftEntityInstance_1,
  14604. BlockMapBuilder: BlockMapBuilder_1,
  14605. CharacterMetadata: CharacterMetadata_1,
  14606. ContentBlock: ContentBlock_1,
  14607. ContentState: ContentState_1,
  14608. SelectionState: SelectionState_1,
  14609. AtomicBlockUtils: AtomicBlockUtils_1,
  14610. KeyBindingUtil: KeyBindingUtil_1,
  14611. Modifier: DraftModifier_1,
  14612. RichUtils: RichTextEditorUtil_1,
  14613. DefaultDraftBlockRenderMap: DefaultDraftBlockRenderMap_1,
  14614. DefaultDraftInlineStyle: DefaultDraftInlineStyle,
  14615. convertFromHTML: convertFromHTMLToContentBlocks,
  14616. convertFromRaw: convertFromRawToDraftState_1,
  14617. convertToRaw: convertFromDraftStateToRaw_1,
  14618. genKey: generateRandomKey_1,
  14619. getDefaultKeyBinding: getDefaultKeyBinding_1,
  14620. getVisibleSelectionRect: getVisibleSelectionRect_1
  14621. };
  14622. var Draft = DraftPublic;
  14623. var Draft_1 = Draft.Editor;
  14624. var Draft_3 = Draft.EditorState;
  14625. var Draft_4 = Draft.CompositeDecorator;
  14626. var Draft_14 = Draft.Modifier;
  14627. var Draft_15 = Draft.RichUtils;
  14628. var Draft_20 = Draft.convertToRaw;
  14629. export { Draft as D, Draft_4 as a, Draft_3 as b, Draft_15 as c, Draft_14 as d, Draft_20 as e, Draft_1 as f };
  14630. //# sourceMappingURL=Draft-ec3417b2.js.map