12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698 |
- 'use strict';
-
- require('react');
- var _commonjsHelpers = require('./_commonjsHelpers-72d386ba.js');
- require('react-dom');
- var _reactDom_commonjsExternal = require('./_react-dom_commonjs-external-55867475.js');
-
- /*
- object-assign
- (c) Sindre Sorhus
- @license MIT
- */
- /* eslint-disable no-unused-vars */
- var getOwnPropertySymbols = Object.getOwnPropertySymbols;
- var hasOwnProperty = Object.prototype.hasOwnProperty;
- var propIsEnumerable = Object.prototype.propertyIsEnumerable;
-
- function toObject(val) {
- if (val === null || val === undefined) {
- throw new TypeError('Object.assign cannot be called with null or undefined');
- }
-
- return Object(val);
- }
-
- function shouldUseNative() {
- try {
- if (!Object.assign) {
- return false;
- }
-
- // Detect buggy property enumeration order in older V8 versions.
-
- // https://bugs.chromium.org/p/v8/issues/detail?id=4118
- var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
- test1[5] = 'de';
- if (Object.getOwnPropertyNames(test1)[0] === '5') {
- return false;
- }
-
- // https://bugs.chromium.org/p/v8/issues/detail?id=3056
- var test2 = {};
- for (var i = 0; i < 10; i++) {
- test2['_' + String.fromCharCode(i)] = i;
- }
- var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
- return test2[n];
- });
- if (order2.join('') !== '0123456789') {
- return false;
- }
-
- // https://bugs.chromium.org/p/v8/issues/detail?id=3056
- var test3 = {};
- 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
- test3[letter] = letter;
- });
- if (Object.keys(Object.assign({}, test3)).join('') !==
- 'abcdefghijklmnopqrst') {
- return false;
- }
-
- return true;
- } catch (err) {
- // We don't expect any of the above to throw, but better to be safe.
- return false;
- }
- }
-
- var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
- var from;
- var to = toObject(target);
- var symbols;
-
- for (var s = 1; s < arguments.length; s++) {
- from = Object(arguments[s]);
-
- for (var key in from) {
- if (hasOwnProperty.call(from, key)) {
- to[key] = from[key];
- }
- }
-
- if (getOwnPropertySymbols) {
- symbols = getOwnPropertySymbols(from);
- for (var i = 0; i < symbols.length; i++) {
- if (propIsEnumerable.call(from, symbols[i])) {
- to[symbols[i]] = from[symbols[i]];
- }
- }
- }
- }
-
- return to;
- };
-
- var immutable = _commonjsHelpers.createCommonjsModule(function (module, exports) {
- /**
- * Copyright (c) 2014-2015, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- */
-
- (function (global, factory) {
- module.exports = factory() ;
- }(_commonjsHelpers.commonjsGlobal, function () {var SLICE$0 = Array.prototype.slice;
-
- function createClass(ctor, superClass) {
- if (superClass) {
- ctor.prototype = Object.create(superClass.prototype);
- }
- ctor.prototype.constructor = ctor;
- }
-
- function Iterable(value) {
- return isIterable(value) ? value : Seq(value);
- }
-
-
- createClass(KeyedIterable, Iterable);
- function KeyedIterable(value) {
- return isKeyed(value) ? value : KeyedSeq(value);
- }
-
-
- createClass(IndexedIterable, Iterable);
- function IndexedIterable(value) {
- return isIndexed(value) ? value : IndexedSeq(value);
- }
-
-
- createClass(SetIterable, Iterable);
- function SetIterable(value) {
- return isIterable(value) && !isAssociative(value) ? value : SetSeq(value);
- }
-
-
-
- function isIterable(maybeIterable) {
- return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]);
- }
-
- function isKeyed(maybeKeyed) {
- return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
- }
-
- function isIndexed(maybeIndexed) {
- return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
- }
-
- function isAssociative(maybeAssociative) {
- return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
- }
-
- function isOrdered(maybeOrdered) {
- return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
- }
-
- Iterable.isIterable = isIterable;
- Iterable.isKeyed = isKeyed;
- Iterable.isIndexed = isIndexed;
- Iterable.isAssociative = isAssociative;
- Iterable.isOrdered = isOrdered;
-
- Iterable.Keyed = KeyedIterable;
- Iterable.Indexed = IndexedIterable;
- Iterable.Set = SetIterable;
-
-
- var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
- var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
- var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
- var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
-
- // Used for setting prototype methods that IE8 chokes on.
- var DELETE = 'delete';
-
- // Constants describing the size of trie nodes.
- var SHIFT = 5; // Resulted in best performance after ______?
- var SIZE = 1 << SHIFT;
- var MASK = SIZE - 1;
-
- // A consistent shared value representing "not set" which equals nothing other
- // than itself, and nothing that could be provided externally.
- var NOT_SET = {};
-
- // Boolean references, Rough equivalent of `bool &`.
- var CHANGE_LENGTH = { value: false };
- var DID_ALTER = { value: false };
-
- function MakeRef(ref) {
- ref.value = false;
- return ref;
- }
-
- function SetRef(ref) {
- ref && (ref.value = true);
- }
-
- // A function which returns a value representing an "owner" for transient writes
- // to tries. The return value will only ever equal itself, and will not equal
- // the return of any subsequent call of this function.
- function OwnerID() {}
-
- // http://jsperf.com/copy-array-inline
- function arrCopy(arr, offset) {
- offset = offset || 0;
- var len = Math.max(0, arr.length - offset);
- var newArr = new Array(len);
- for (var ii = 0; ii < len; ii++) {
- newArr[ii] = arr[ii + offset];
- }
- return newArr;
- }
-
- function ensureSize(iter) {
- if (iter.size === undefined) {
- iter.size = iter.__iterate(returnTrue);
- }
- return iter.size;
- }
-
- function wrapIndex(iter, index) {
- // This implements "is array index" which the ECMAString spec defines as:
- //
- // A String property name P is an array index if and only if
- // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
- // to 2^32−1.
- //
- // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
- if (typeof index !== 'number') {
- var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
- if ('' + uint32Index !== index || uint32Index === 4294967295) {
- return NaN;
- }
- index = uint32Index;
- }
- return index < 0 ? ensureSize(iter) + index : index;
- }
-
- function returnTrue() {
- return true;
- }
-
- function wholeSlice(begin, end, size) {
- return (begin === 0 || (size !== undefined && begin <= -size)) &&
- (end === undefined || (size !== undefined && end >= size));
- }
-
- function resolveBegin(begin, size) {
- return resolveIndex(begin, size, 0);
- }
-
- function resolveEnd(end, size) {
- return resolveIndex(end, size, size);
- }
-
- function resolveIndex(index, size, defaultIndex) {
- return index === undefined ?
- defaultIndex :
- index < 0 ?
- Math.max(0, size + index) :
- size === undefined ?
- index :
- Math.min(size, index);
- }
-
- /* global Symbol */
-
- var ITERATE_KEYS = 0;
- var ITERATE_VALUES = 1;
- var ITERATE_ENTRIES = 2;
-
- var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
- var FAUX_ITERATOR_SYMBOL = '@@iterator';
-
- var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
-
-
- function Iterator(next) {
- this.next = next;
- }
-
- Iterator.prototype.toString = function() {
- return '[Iterator]';
- };
-
-
- Iterator.KEYS = ITERATE_KEYS;
- Iterator.VALUES = ITERATE_VALUES;
- Iterator.ENTRIES = ITERATE_ENTRIES;
-
- Iterator.prototype.inspect =
- Iterator.prototype.toSource = function () { return this.toString(); };
- Iterator.prototype[ITERATOR_SYMBOL] = function () {
- return this;
- };
-
-
- function iteratorValue(type, k, v, iteratorResult) {
- var value = type === 0 ? k : type === 1 ? v : [k, v];
- iteratorResult ? (iteratorResult.value = value) : (iteratorResult = {
- value: value, done: false
- });
- return iteratorResult;
- }
-
- function iteratorDone() {
- return { value: undefined, done: true };
- }
-
- function hasIterator(maybeIterable) {
- return !!getIteratorFn(maybeIterable);
- }
-
- function isIterator(maybeIterator) {
- return maybeIterator && typeof maybeIterator.next === 'function';
- }
-
- function getIterator(iterable) {
- var iteratorFn = getIteratorFn(iterable);
- return iteratorFn && iteratorFn.call(iterable);
- }
-
- function getIteratorFn(iterable) {
- var iteratorFn = iterable && (
- (REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
- iterable[FAUX_ITERATOR_SYMBOL]
- );
- if (typeof iteratorFn === 'function') {
- return iteratorFn;
- }
- }
-
- function isArrayLike(value) {
- return value && typeof value.length === 'number';
- }
-
- createClass(Seq, Iterable);
- function Seq(value) {
- return value === null || value === undefined ? emptySequence() :
- isIterable(value) ? value.toSeq() : seqFromValue(value);
- }
-
- Seq.of = function(/*...values*/) {
- return Seq(arguments);
- };
-
- Seq.prototype.toSeq = function() {
- return this;
- };
-
- Seq.prototype.toString = function() {
- return this.__toString('Seq {', '}');
- };
-
- Seq.prototype.cacheResult = function() {
- if (!this._cache && this.__iterateUncached) {
- this._cache = this.entrySeq().toArray();
- this.size = this._cache.length;
- }
- return this;
- };
-
- // abstract __iterateUncached(fn, reverse)
-
- Seq.prototype.__iterate = function(fn, reverse) {
- return seqIterate(this, fn, reverse, true);
- };
-
- // abstract __iteratorUncached(type, reverse)
-
- Seq.prototype.__iterator = function(type, reverse) {
- return seqIterator(this, type, reverse, true);
- };
-
-
-
- createClass(KeyedSeq, Seq);
- function KeyedSeq(value) {
- return value === null || value === undefined ?
- emptySequence().toKeyedSeq() :
- isIterable(value) ?
- (isKeyed(value) ? value.toSeq() : value.fromEntrySeq()) :
- keyedSeqFromValue(value);
- }
-
- KeyedSeq.prototype.toKeyedSeq = function() {
- return this;
- };
-
-
-
- createClass(IndexedSeq, Seq);
- function IndexedSeq(value) {
- return value === null || value === undefined ? emptySequence() :
- !isIterable(value) ? indexedSeqFromValue(value) :
- isKeyed(value) ? value.entrySeq() : value.toIndexedSeq();
- }
-
- IndexedSeq.of = function(/*...values*/) {
- return IndexedSeq(arguments);
- };
-
- IndexedSeq.prototype.toIndexedSeq = function() {
- return this;
- };
-
- IndexedSeq.prototype.toString = function() {
- return this.__toString('Seq [', ']');
- };
-
- IndexedSeq.prototype.__iterate = function(fn, reverse) {
- return seqIterate(this, fn, reverse, false);
- };
-
- IndexedSeq.prototype.__iterator = function(type, reverse) {
- return seqIterator(this, type, reverse, false);
- };
-
-
-
- createClass(SetSeq, Seq);
- function SetSeq(value) {
- return (
- value === null || value === undefined ? emptySequence() :
- !isIterable(value) ? indexedSeqFromValue(value) :
- isKeyed(value) ? value.entrySeq() : value
- ).toSetSeq();
- }
-
- SetSeq.of = function(/*...values*/) {
- return SetSeq(arguments);
- };
-
- SetSeq.prototype.toSetSeq = function() {
- return this;
- };
-
-
-
- Seq.isSeq = isSeq;
- Seq.Keyed = KeyedSeq;
- Seq.Set = SetSeq;
- Seq.Indexed = IndexedSeq;
-
- var IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
-
- Seq.prototype[IS_SEQ_SENTINEL] = true;
-
-
-
- createClass(ArraySeq, IndexedSeq);
- function ArraySeq(array) {
- this._array = array;
- this.size = array.length;
- }
-
- ArraySeq.prototype.get = function(index, notSetValue) {
- return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
- };
-
- ArraySeq.prototype.__iterate = function(fn, reverse) {
- var array = this._array;
- var maxIndex = array.length - 1;
- for (var ii = 0; ii <= maxIndex; ii++) {
- if (fn(array[reverse ? maxIndex - ii : ii], ii, this) === false) {
- return ii + 1;
- }
- }
- return ii;
- };
-
- ArraySeq.prototype.__iterator = function(type, reverse) {
- var array = this._array;
- var maxIndex = array.length - 1;
- var ii = 0;
- return new Iterator(function()
- {return ii > maxIndex ?
- iteratorDone() :
- iteratorValue(type, ii, array[reverse ? maxIndex - ii++ : ii++])}
- );
- };
-
-
-
- createClass(ObjectSeq, KeyedSeq);
- function ObjectSeq(object) {
- var keys = Object.keys(object);
- this._object = object;
- this._keys = keys;
- this.size = keys.length;
- }
-
- ObjectSeq.prototype.get = function(key, notSetValue) {
- if (notSetValue !== undefined && !this.has(key)) {
- return notSetValue;
- }
- return this._object[key];
- };
-
- ObjectSeq.prototype.has = function(key) {
- return this._object.hasOwnProperty(key);
- };
-
- ObjectSeq.prototype.__iterate = function(fn, reverse) {
- var object = this._object;
- var keys = this._keys;
- var maxIndex = keys.length - 1;
- for (var ii = 0; ii <= maxIndex; ii++) {
- var key = keys[reverse ? maxIndex - ii : ii];
- if (fn(object[key], key, this) === false) {
- return ii + 1;
- }
- }
- return ii;
- };
-
- ObjectSeq.prototype.__iterator = function(type, reverse) {
- var object = this._object;
- var keys = this._keys;
- var maxIndex = keys.length - 1;
- var ii = 0;
- return new Iterator(function() {
- var key = keys[reverse ? maxIndex - ii : ii];
- return ii++ > maxIndex ?
- iteratorDone() :
- iteratorValue(type, key, object[key]);
- });
- };
-
- ObjectSeq.prototype[IS_ORDERED_SENTINEL] = true;
-
-
- createClass(IterableSeq, IndexedSeq);
- function IterableSeq(iterable) {
- this._iterable = iterable;
- this.size = iterable.length || iterable.size;
- }
-
- IterableSeq.prototype.__iterateUncached = function(fn, reverse) {
- if (reverse) {
- return this.cacheResult().__iterate(fn, reverse);
- }
- var iterable = this._iterable;
- var iterator = getIterator(iterable);
- var iterations = 0;
- if (isIterator(iterator)) {
- var step;
- while (!(step = iterator.next()).done) {
- if (fn(step.value, iterations++, this) === false) {
- break;
- }
- }
- }
- return iterations;
- };
-
- IterableSeq.prototype.__iteratorUncached = function(type, reverse) {
- if (reverse) {
- return this.cacheResult().__iterator(type, reverse);
- }
- var iterable = this._iterable;
- var iterator = getIterator(iterable);
- if (!isIterator(iterator)) {
- return new Iterator(iteratorDone);
- }
- var iterations = 0;
- return new Iterator(function() {
- var step = iterator.next();
- return step.done ? step : iteratorValue(type, iterations++, step.value);
- });
- };
-
-
-
- createClass(IteratorSeq, IndexedSeq);
- function IteratorSeq(iterator) {
- this._iterator = iterator;
- this._iteratorCache = [];
- }
-
- IteratorSeq.prototype.__iterateUncached = function(fn, reverse) {
- if (reverse) {
- return this.cacheResult().__iterate(fn, reverse);
- }
- var iterator = this._iterator;
- var cache = this._iteratorCache;
- var iterations = 0;
- while (iterations < cache.length) {
- if (fn(cache[iterations], iterations++, this) === false) {
- return iterations;
- }
- }
- var step;
- while (!(step = iterator.next()).done) {
- var val = step.value;
- cache[iterations] = val;
- if (fn(val, iterations++, this) === false) {
- break;
- }
- }
- return iterations;
- };
-
- IteratorSeq.prototype.__iteratorUncached = function(type, reverse) {
- if (reverse) {
- return this.cacheResult().__iterator(type, reverse);
- }
- var iterator = this._iterator;
- var cache = this._iteratorCache;
- var iterations = 0;
- return new Iterator(function() {
- if (iterations >= cache.length) {
- var step = iterator.next();
- if (step.done) {
- return step;
- }
- cache[iterations] = step.value;
- }
- return iteratorValue(type, iterations, cache[iterations++]);
- });
- };
-
-
-
-
- // # pragma Helper functions
-
- function isSeq(maybeSeq) {
- return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]);
- }
-
- var EMPTY_SEQ;
-
- function emptySequence() {
- return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
- }
-
- function keyedSeqFromValue(value) {
- var seq =
- Array.isArray(value) ? new ArraySeq(value).fromEntrySeq() :
- isIterator(value) ? new IteratorSeq(value).fromEntrySeq() :
- hasIterator(value) ? new IterableSeq(value).fromEntrySeq() :
- typeof value === 'object' ? new ObjectSeq(value) :
- undefined;
- if (!seq) {
- throw new TypeError(
- 'Expected Array or iterable object of [k, v] entries, '+
- 'or keyed object: ' + value
- );
- }
- return seq;
- }
-
- function indexedSeqFromValue(value) {
- var seq = maybeIndexedSeqFromValue(value);
- if (!seq) {
- throw new TypeError(
- 'Expected Array or iterable object of values: ' + value
- );
- }
- return seq;
- }
-
- function seqFromValue(value) {
- var seq = maybeIndexedSeqFromValue(value) ||
- (typeof value === 'object' && new ObjectSeq(value));
- if (!seq) {
- throw new TypeError(
- 'Expected Array or iterable object of values, or keyed object: ' + value
- );
- }
- return seq;
- }
-
- function maybeIndexedSeqFromValue(value) {
- return (
- isArrayLike(value) ? new ArraySeq(value) :
- isIterator(value) ? new IteratorSeq(value) :
- hasIterator(value) ? new IterableSeq(value) :
- undefined
- );
- }
-
- function seqIterate(seq, fn, reverse, useKeys) {
- var cache = seq._cache;
- if (cache) {
- var maxIndex = cache.length - 1;
- for (var ii = 0; ii <= maxIndex; ii++) {
- var entry = cache[reverse ? maxIndex - ii : ii];
- if (fn(entry[1], useKeys ? entry[0] : ii, seq) === false) {
- return ii + 1;
- }
- }
- return ii;
- }
- return seq.__iterateUncached(fn, reverse);
- }
-
- function seqIterator(seq, type, reverse, useKeys) {
- var cache = seq._cache;
- if (cache) {
- var maxIndex = cache.length - 1;
- var ii = 0;
- return new Iterator(function() {
- var entry = cache[reverse ? maxIndex - ii : ii];
- return ii++ > maxIndex ?
- iteratorDone() :
- iteratorValue(type, useKeys ? entry[0] : ii - 1, entry[1]);
- });
- }
- return seq.__iteratorUncached(type, reverse);
- }
-
- function fromJS(json, converter) {
- return converter ?
- fromJSWith(converter, json, '', {'': json}) :
- fromJSDefault(json);
- }
-
- function fromJSWith(converter, json, key, parentJSON) {
- if (Array.isArray(json)) {
- return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
- }
- if (isPlainObj(json)) {
- return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
- }
- return json;
- }
-
- function fromJSDefault(json) {
- if (Array.isArray(json)) {
- return IndexedSeq(json).map(fromJSDefault).toList();
- }
- if (isPlainObj(json)) {
- return KeyedSeq(json).map(fromJSDefault).toMap();
- }
- return json;
- }
-
- function isPlainObj(value) {
- return value && (value.constructor === Object || value.constructor === undefined);
- }
-
- /**
- * An extension of the "same-value" algorithm as [described for use by ES6 Map
- * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
- *
- * NaN is considered the same as NaN, however -0 and 0 are considered the same
- * value, which is different from the algorithm described by
- * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
- *
- * This is extended further to allow Objects to describe the values they
- * represent, by way of `valueOf` or `equals` (and `hashCode`).
- *
- * Note: because of this extension, the key equality of Immutable.Map and the
- * value equality of Immutable.Set will differ from ES6 Map and Set.
- *
- * ### Defining custom values
- *
- * The easiest way to describe the value an object represents is by implementing
- * `valueOf`. For example, `Date` represents a value by returning a unix
- * timestamp for `valueOf`:
- *
- * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
- * var date2 = new Date(1234567890000);
- * date1.valueOf(); // 1234567890000
- * assert( date1 !== date2 );
- * assert( Immutable.is( date1, date2 ) );
- *
- * Note: overriding `valueOf` may have other implications if you use this object
- * where JavaScript expects a primitive, such as implicit string coercion.
- *
- * For more complex types, especially collections, implementing `valueOf` may
- * not be performant. An alternative is to implement `equals` and `hashCode`.
- *
- * `equals` takes another object, presumably of similar type, and returns true
- * if the it is equal. Equality is symmetrical, so the same result should be
- * returned if this and the argument are flipped.
- *
- * assert( a.equals(b) === b.equals(a) );
- *
- * `hashCode` returns a 32bit integer number representing the object which will
- * be used to determine how to store the value object in a Map or Set. You must
- * provide both or neither methods, one must not exist without the other.
- *
- * Also, an important relationship between these methods must be upheld: if two
- * values are equal, they *must* return the same hashCode. If the values are not
- * equal, they might have the same hashCode; this is called a hash collision,
- * and while undesirable for performance reasons, it is acceptable.
- *
- * if (a.equals(b)) {
- * assert( a.hashCode() === b.hashCode() );
- * }
- *
- * All Immutable collections implement `equals` and `hashCode`.
- *
- */
- function is(valueA, valueB) {
- if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
- return true;
- }
- if (!valueA || !valueB) {
- return false;
- }
- if (typeof valueA.valueOf === 'function' &&
- typeof valueB.valueOf === 'function') {
- valueA = valueA.valueOf();
- valueB = valueB.valueOf();
- if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
- return true;
- }
- if (!valueA || !valueB) {
- return false;
- }
- }
- if (typeof valueA.equals === 'function' &&
- typeof valueB.equals === 'function' &&
- valueA.equals(valueB)) {
- return true;
- }
- return false;
- }
-
- function deepEqual(a, b) {
- if (a === b) {
- return true;
- }
-
- if (
- !isIterable(b) ||
- a.size !== undefined && b.size !== undefined && a.size !== b.size ||
- a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
- isKeyed(a) !== isKeyed(b) ||
- isIndexed(a) !== isIndexed(b) ||
- isOrdered(a) !== isOrdered(b)
- ) {
- return false;
- }
-
- if (a.size === 0 && b.size === 0) {
- return true;
- }
-
- var notAssociative = !isAssociative(a);
-
- if (isOrdered(a)) {
- var entries = a.entries();
- return b.every(function(v, k) {
- var entry = entries.next().value;
- return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
- }) && entries.next().done;
- }
-
- var flipped = false;
-
- if (a.size === undefined) {
- if (b.size === undefined) {
- if (typeof a.cacheResult === 'function') {
- a.cacheResult();
- }
- } else {
- flipped = true;
- var _ = a;
- a = b;
- b = _;
- }
- }
-
- var allEqual = true;
- var bSize = b.__iterate(function(v, k) {
- if (notAssociative ? !a.has(v) :
- flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
- allEqual = false;
- return false;
- }
- });
-
- return allEqual && a.size === bSize;
- }
-
- createClass(Repeat, IndexedSeq);
-
- function Repeat(value, times) {
- if (!(this instanceof Repeat)) {
- return new Repeat(value, times);
- }
- this._value = value;
- this.size = times === undefined ? Infinity : Math.max(0, times);
- if (this.size === 0) {
- if (EMPTY_REPEAT) {
- return EMPTY_REPEAT;
- }
- EMPTY_REPEAT = this;
- }
- }
-
- Repeat.prototype.toString = function() {
- if (this.size === 0) {
- return 'Repeat []';
- }
- return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
- };
-
- Repeat.prototype.get = function(index, notSetValue) {
- return this.has(index) ? this._value : notSetValue;
- };
-
- Repeat.prototype.includes = function(searchValue) {
- return is(this._value, searchValue);
- };
-
- Repeat.prototype.slice = function(begin, end) {
- var size = this.size;
- return wholeSlice(begin, end, size) ? this :
- new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
- };
-
- Repeat.prototype.reverse = function() {
- return this;
- };
-
- Repeat.prototype.indexOf = function(searchValue) {
- if (is(this._value, searchValue)) {
- return 0;
- }
- return -1;
- };
-
- Repeat.prototype.lastIndexOf = function(searchValue) {
- if (is(this._value, searchValue)) {
- return this.size;
- }
- return -1;
- };
-
- Repeat.prototype.__iterate = function(fn, reverse) {
- for (var ii = 0; ii < this.size; ii++) {
- if (fn(this._value, ii, this) === false) {
- return ii + 1;
- }
- }
- return ii;
- };
-
- Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
- var ii = 0;
- return new Iterator(function()
- {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
- );
- };
-
- Repeat.prototype.equals = function(other) {
- return other instanceof Repeat ?
- is(this._value, other._value) :
- deepEqual(other);
- };
-
-
- var EMPTY_REPEAT;
-
- function invariant(condition, error) {
- if (!condition) throw new Error(error);
- }
-
- createClass(Range, IndexedSeq);
-
- function Range(start, end, step) {
- if (!(this instanceof Range)) {
- return new Range(start, end, step);
- }
- invariant(step !== 0, 'Cannot step a Range by 0');
- start = start || 0;
- if (end === undefined) {
- end = Infinity;
- }
- step = step === undefined ? 1 : Math.abs(step);
- if (end < start) {
- step = -step;
- }
- this._start = start;
- this._end = end;
- this._step = step;
- this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
- if (this.size === 0) {
- if (EMPTY_RANGE) {
- return EMPTY_RANGE;
- }
- EMPTY_RANGE = this;
- }
- }
-
- Range.prototype.toString = function() {
- if (this.size === 0) {
- return 'Range []';
- }
- return 'Range [ ' +
- this._start + '...' + this._end +
- (this._step > 1 ? ' by ' + this._step : '') +
- ' ]';
- };
-
- Range.prototype.get = function(index, notSetValue) {
- return this.has(index) ?
- this._start + wrapIndex(this, index) * this._step :
- notSetValue;
- };
-
- Range.prototype.includes = function(searchValue) {
- var possibleIndex = (searchValue - this._start) / this._step;
- return possibleIndex >= 0 &&
- possibleIndex < this.size &&
- possibleIndex === Math.floor(possibleIndex);
- };
-
- Range.prototype.slice = function(begin, end) {
- if (wholeSlice(begin, end, this.size)) {
- return this;
- }
- begin = resolveBegin(begin, this.size);
- end = resolveEnd(end, this.size);
- if (end <= begin) {
- return new Range(0, 0);
- }
- return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
- };
-
- Range.prototype.indexOf = function(searchValue) {
- var offsetValue = searchValue - this._start;
- if (offsetValue % this._step === 0) {
- var index = offsetValue / this._step;
- if (index >= 0 && index < this.size) {
- return index
- }
- }
- return -1;
- };
-
- Range.prototype.lastIndexOf = function(searchValue) {
- return this.indexOf(searchValue);
- };
-
- Range.prototype.__iterate = function(fn, reverse) {
- var maxIndex = this.size - 1;
- var step = this._step;
- var value = reverse ? this._start + maxIndex * step : this._start;
- for (var ii = 0; ii <= maxIndex; ii++) {
- if (fn(value, ii, this) === false) {
- return ii + 1;
- }
- value += reverse ? -step : step;
- }
- return ii;
- };
-
- Range.prototype.__iterator = function(type, reverse) {
- var maxIndex = this.size - 1;
- var step = this._step;
- var value = reverse ? this._start + maxIndex * step : this._start;
- var ii = 0;
- return new Iterator(function() {
- var v = value;
- value += reverse ? -step : step;
- return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
- });
- };
-
- Range.prototype.equals = function(other) {
- return other instanceof Range ?
- this._start === other._start &&
- this._end === other._end &&
- this._step === other._step :
- deepEqual(this, other);
- };
-
-
- var EMPTY_RANGE;
-
- createClass(Collection, Iterable);
- function Collection() {
- throw TypeError('Abstract');
- }
-
-
- createClass(KeyedCollection, Collection);function KeyedCollection() {}
-
- createClass(IndexedCollection, Collection);function IndexedCollection() {}
-
- createClass(SetCollection, Collection);function SetCollection() {}
-
-
- Collection.Keyed = KeyedCollection;
- Collection.Indexed = IndexedCollection;
- Collection.Set = SetCollection;
-
- var imul =
- typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
- Math.imul :
- function imul(a, b) {
- a = a | 0; // int
- b = b | 0; // int
- var c = a & 0xffff;
- var d = b & 0xffff;
- // Shift by 0 fixes the sign on the high part.
- return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int
- };
-
- // v8 has an optimization for storing 31-bit signed numbers.
- // Values which have either 00 or 11 as the high order bits qualify.
- // This function drops the highest order bit in a signed number, maintaining
- // the sign bit.
- function smi(i32) {
- return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
- }
-
- function hash(o) {
- if (o === false || o === null || o === undefined) {
- return 0;
- }
- if (typeof o.valueOf === 'function') {
- o = o.valueOf();
- if (o === false || o === null || o === undefined) {
- return 0;
- }
- }
- if (o === true) {
- return 1;
- }
- var type = typeof o;
- if (type === 'number') {
- var h = o | 0;
- if (h !== o) {
- h ^= o * 0xFFFFFFFF;
- }
- while (o > 0xFFFFFFFF) {
- o /= 0xFFFFFFFF;
- h ^= o;
- }
- return smi(h);
- }
- if (type === 'string') {
- return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
- }
- if (typeof o.hashCode === 'function') {
- return o.hashCode();
- }
- if (type === 'object') {
- return hashJSObj(o);
- }
- if (typeof o.toString === 'function') {
- return hashString(o.toString());
- }
- throw new Error('Value type ' + type + ' cannot be hashed.');
- }
-
- function cachedHashString(string) {
- var hash = stringHashCache[string];
- if (hash === undefined) {
- hash = hashString(string);
- if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
- STRING_HASH_CACHE_SIZE = 0;
- stringHashCache = {};
- }
- STRING_HASH_CACHE_SIZE++;
- stringHashCache[string] = hash;
- }
- return hash;
- }
-
- // http://jsperf.com/hashing-strings
- function hashString(string) {
- // This is the hash from JVM
- // The hash code for a string is computed as
- // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
- // where s[i] is the ith character of the string and n is the length of
- // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
- // (exclusive) by dropping high bits.
- var hash = 0;
- for (var ii = 0; ii < string.length; ii++) {
- hash = 31 * hash + string.charCodeAt(ii) | 0;
- }
- return smi(hash);
- }
-
- function hashJSObj(obj) {
- var hash;
- if (usingWeakMap) {
- hash = weakMap.get(obj);
- if (hash !== undefined) {
- return hash;
- }
- }
-
- hash = obj[UID_HASH_KEY];
- if (hash !== undefined) {
- return hash;
- }
-
- if (!canDefineProperty) {
- hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
- if (hash !== undefined) {
- return hash;
- }
-
- hash = getIENodeHash(obj);
- if (hash !== undefined) {
- return hash;
- }
- }
-
- hash = ++objHashUID;
- if (objHashUID & 0x40000000) {
- objHashUID = 0;
- }
-
- if (usingWeakMap) {
- weakMap.set(obj, hash);
- } else if (isExtensible !== undefined && isExtensible(obj) === false) {
- throw new Error('Non-extensible objects are not allowed as keys.');
- } else if (canDefineProperty) {
- Object.defineProperty(obj, UID_HASH_KEY, {
- 'enumerable': false,
- 'configurable': false,
- 'writable': false,
- 'value': hash
- });
- } else if (obj.propertyIsEnumerable !== undefined &&
- obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
- // Since we can't define a non-enumerable property on the object
- // we'll hijack one of the less-used non-enumerable properties to
- // save our hash on it. Since this is a function it will not show up in
- // `JSON.stringify` which is what we want.
- obj.propertyIsEnumerable = function() {
- return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
- };
- obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
- } else if (obj.nodeType !== undefined) {
- // At this point we couldn't get the IE `uniqueID` to use as a hash
- // and we couldn't use a non-enumerable property to exploit the
- // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
- // itself.
- obj[UID_HASH_KEY] = hash;
- } else {
- throw new Error('Unable to set a non-enumerable property on object.');
- }
-
- return hash;
- }
-
- // Get references to ES5 object methods.
- var isExtensible = Object.isExtensible;
-
- // True if Object.defineProperty works as expected. IE8 fails this test.
- var canDefineProperty = (function() {
- try {
- Object.defineProperty({}, '@', {});
- return true;
- } catch (e) {
- return false;
- }
- }());
-
- // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
- // and avoid memory leaks from the IE cloneNode bug.
- function getIENodeHash(node) {
- if (node && node.nodeType > 0) {
- switch (node.nodeType) {
- case 1: // Element
- return node.uniqueID;
- case 9: // Document
- return node.documentElement && node.documentElement.uniqueID;
- }
- }
- }
-
- // If possible, use a WeakMap.
- var usingWeakMap = typeof WeakMap === 'function';
- var weakMap;
- if (usingWeakMap) {
- weakMap = new WeakMap();
- }
-
- var objHashUID = 0;
-
- var UID_HASH_KEY = '__immutablehash__';
- if (typeof Symbol === 'function') {
- UID_HASH_KEY = Symbol(UID_HASH_KEY);
- }
-
- var STRING_HASH_CACHE_MIN_STRLEN = 16;
- var STRING_HASH_CACHE_MAX_SIZE = 255;
- var STRING_HASH_CACHE_SIZE = 0;
- var stringHashCache = {};
-
- function assertNotInfinite(size) {
- invariant(
- size !== Infinity,
- 'Cannot perform this action with an infinite size.'
- );
- }
-
- createClass(Map, KeyedCollection);
-
- // @pragma Construction
-
- function Map(value) {
- return value === null || value === undefined ? emptyMap() :
- isMap(value) && !isOrdered(value) ? value :
- emptyMap().withMutations(function(map ) {
- var iter = KeyedIterable(value);
- assertNotInfinite(iter.size);
- iter.forEach(function(v, k) {return map.set(k, v)});
- });
- }
-
- Map.prototype.toString = function() {
- return this.__toString('Map {', '}');
- };
-
- // @pragma Access
-
- Map.prototype.get = function(k, notSetValue) {
- return this._root ?
- this._root.get(0, undefined, k, notSetValue) :
- notSetValue;
- };
-
- // @pragma Modification
-
- Map.prototype.set = function(k, v) {
- return updateMap(this, k, v);
- };
-
- Map.prototype.setIn = function(keyPath, v) {
- return this.updateIn(keyPath, NOT_SET, function() {return v});
- };
-
- Map.prototype.remove = function(k) {
- return updateMap(this, k, NOT_SET);
- };
-
- Map.prototype.deleteIn = function(keyPath) {
- return this.updateIn(keyPath, function() {return NOT_SET});
- };
-
- Map.prototype.update = function(k, notSetValue, updater) {
- return arguments.length === 1 ?
- k(this) :
- this.updateIn([k], notSetValue, updater);
- };
-
- Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
- if (!updater) {
- updater = notSetValue;
- notSetValue = undefined;
- }
- var updatedValue = updateInDeepMap(
- this,
- forceIterator(keyPath),
- notSetValue,
- updater
- );
- return updatedValue === NOT_SET ? undefined : updatedValue;
- };
-
- Map.prototype.clear = function() {
- if (this.size === 0) {
- return this;
- }
- if (this.__ownerID) {
- this.size = 0;
- this._root = null;
- this.__hash = undefined;
- this.__altered = true;
- return this;
- }
- return emptyMap();
- };
-
- // @pragma Composition
-
- Map.prototype.merge = function(/*...iters*/) {
- return mergeIntoMapWith(this, undefined, arguments);
- };
-
- Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
- return mergeIntoMapWith(this, merger, iters);
- };
-
- Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
- return this.updateIn(
- keyPath,
- emptyMap(),
- function(m ) {return typeof m.merge === 'function' ?
- m.merge.apply(m, iters) :
- iters[iters.length - 1]}
- );
- };
-
- Map.prototype.mergeDeep = function(/*...iters*/) {
- return mergeIntoMapWith(this, deepMerger, arguments);
- };
-
- Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
- return mergeIntoMapWith(this, deepMergerWith(merger), iters);
- };
-
- Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
- return this.updateIn(
- keyPath,
- emptyMap(),
- function(m ) {return typeof m.mergeDeep === 'function' ?
- m.mergeDeep.apply(m, iters) :
- iters[iters.length - 1]}
- );
- };
-
- Map.prototype.sort = function(comparator) {
- // Late binding
- return OrderedMap(sortFactory(this, comparator));
- };
-
- Map.prototype.sortBy = function(mapper, comparator) {
- // Late binding
- return OrderedMap(sortFactory(this, comparator, mapper));
- };
-
- // @pragma Mutability
-
- Map.prototype.withMutations = function(fn) {
- var mutable = this.asMutable();
- fn(mutable);
- return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
- };
-
- Map.prototype.asMutable = function() {
- return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
- };
-
- Map.prototype.asImmutable = function() {
- return this.__ensureOwner();
- };
-
- Map.prototype.wasAltered = function() {
- return this.__altered;
- };
-
- Map.prototype.__iterator = function(type, reverse) {
- return new MapIterator(this, type, reverse);
- };
-
- Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
- var iterations = 0;
- this._root && this._root.iterate(function(entry ) {
- iterations++;
- return fn(entry[1], entry[0], this$0);
- }, reverse);
- return iterations;
- };
-
- Map.prototype.__ensureOwner = function(ownerID) {
- if (ownerID === this.__ownerID) {
- return this;
- }
- if (!ownerID) {
- this.__ownerID = ownerID;
- this.__altered = false;
- return this;
- }
- return makeMap(this.size, this._root, ownerID, this.__hash);
- };
-
-
- function isMap(maybeMap) {
- return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
- }
-
- Map.isMap = isMap;
-
- var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
-
- var MapPrototype = Map.prototype;
- MapPrototype[IS_MAP_SENTINEL] = true;
- MapPrototype[DELETE] = MapPrototype.remove;
- MapPrototype.removeIn = MapPrototype.deleteIn;
-
-
- // #pragma Trie Nodes
-
-
-
- function ArrayMapNode(ownerID, entries) {
- this.ownerID = ownerID;
- this.entries = entries;
- }
-
- ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
- var entries = this.entries;
- for (var ii = 0, len = entries.length; ii < len; ii++) {
- if (is(key, entries[ii][0])) {
- return entries[ii][1];
- }
- }
- return notSetValue;
- };
-
- ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
- var removed = value === NOT_SET;
-
- var entries = this.entries;
- var idx = 0;
- for (var len = entries.length; idx < len; idx++) {
- if (is(key, entries[idx][0])) {
- break;
- }
- }
- var exists = idx < len;
-
- if (exists ? entries[idx][1] === value : removed) {
- return this;
- }
-
- SetRef(didAlter);
- (removed || !exists) && SetRef(didChangeSize);
-
- if (removed && entries.length === 1) {
- return; // undefined
- }
-
- if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
- return createNodes(ownerID, entries, key, value);
- }
-
- var isEditable = ownerID && ownerID === this.ownerID;
- var newEntries = isEditable ? entries : arrCopy(entries);
-
- if (exists) {
- if (removed) {
- idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
- } else {
- newEntries[idx] = [key, value];
- }
- } else {
- newEntries.push([key, value]);
- }
-
- if (isEditable) {
- this.entries = newEntries;
- return this;
- }
-
- return new ArrayMapNode(ownerID, newEntries);
- };
-
-
-
-
- function BitmapIndexedNode(ownerID, bitmap, nodes) {
- this.ownerID = ownerID;
- this.bitmap = bitmap;
- this.nodes = nodes;
- }
-
- BitmapIndexedNode.prototype.get = function(shift, keyHash, key, notSetValue) {
- if (keyHash === undefined) {
- keyHash = hash(key);
- }
- var bit = (1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK));
- var bitmap = this.bitmap;
- return (bitmap & bit) === 0 ? notSetValue :
- this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue);
- };
-
- BitmapIndexedNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
- if (keyHash === undefined) {
- keyHash = hash(key);
- }
- var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
- var bit = 1 << keyHashFrag;
- var bitmap = this.bitmap;
- var exists = (bitmap & bit) !== 0;
-
- if (!exists && value === NOT_SET) {
- return this;
- }
-
- var idx = popCount(bitmap & (bit - 1));
- var nodes = this.nodes;
- var node = exists ? nodes[idx] : undefined;
- var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
-
- if (newNode === node) {
- return this;
- }
-
- if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
- return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
- }
-
- if (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) {
- return nodes[idx ^ 1];
- }
-
- if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
- return newNode;
- }
-
- var isEditable = ownerID && ownerID === this.ownerID;
- var newBitmap = exists ? newNode ? bitmap : bitmap ^ bit : bitmap | bit;
- var newNodes = exists ? newNode ?
- setIn(nodes, idx, newNode, isEditable) :
- spliceOut(nodes, idx, isEditable) :
- spliceIn(nodes, idx, newNode, isEditable);
-
- if (isEditable) {
- this.bitmap = newBitmap;
- this.nodes = newNodes;
- return this;
- }
-
- return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
- };
-
-
-
-
- function HashArrayMapNode(ownerID, count, nodes) {
- this.ownerID = ownerID;
- this.count = count;
- this.nodes = nodes;
- }
-
- HashArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
- if (keyHash === undefined) {
- keyHash = hash(key);
- }
- var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
- var node = this.nodes[idx];
- return node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue;
- };
-
- HashArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
- if (keyHash === undefined) {
- keyHash = hash(key);
- }
- var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
- var removed = value === NOT_SET;
- var nodes = this.nodes;
- var node = nodes[idx];
-
- if (removed && !node) {
- return this;
- }
-
- var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
- if (newNode === node) {
- return this;
- }
-
- var newCount = this.count;
- if (!node) {
- newCount++;
- } else if (!newNode) {
- newCount--;
- if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
- return packNodes(ownerID, nodes, newCount, idx);
- }
- }
-
- var isEditable = ownerID && ownerID === this.ownerID;
- var newNodes = setIn(nodes, idx, newNode, isEditable);
-
- if (isEditable) {
- this.count = newCount;
- this.nodes = newNodes;
- return this;
- }
-
- return new HashArrayMapNode(ownerID, newCount, newNodes);
- };
-
-
-
-
- function HashCollisionNode(ownerID, keyHash, entries) {
- this.ownerID = ownerID;
- this.keyHash = keyHash;
- this.entries = entries;
- }
-
- HashCollisionNode.prototype.get = function(shift, keyHash, key, notSetValue) {
- var entries = this.entries;
- for (var ii = 0, len = entries.length; ii < len; ii++) {
- if (is(key, entries[ii][0])) {
- return entries[ii][1];
- }
- }
- return notSetValue;
- };
-
- HashCollisionNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
- if (keyHash === undefined) {
- keyHash = hash(key);
- }
-
- var removed = value === NOT_SET;
-
- if (keyHash !== this.keyHash) {
- if (removed) {
- return this;
- }
- SetRef(didAlter);
- SetRef(didChangeSize);
- return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
- }
-
- var entries = this.entries;
- var idx = 0;
- for (var len = entries.length; idx < len; idx++) {
- if (is(key, entries[idx][0])) {
- break;
- }
- }
- var exists = idx < len;
-
- if (exists ? entries[idx][1] === value : removed) {
- return this;
- }
-
- SetRef(didAlter);
- (removed || !exists) && SetRef(didChangeSize);
-
- if (removed && len === 2) {
- return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
- }
-
- var isEditable = ownerID && ownerID === this.ownerID;
- var newEntries = isEditable ? entries : arrCopy(entries);
-
- if (exists) {
- if (removed) {
- idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
- } else {
- newEntries[idx] = [key, value];
- }
- } else {
- newEntries.push([key, value]);
- }
-
- if (isEditable) {
- this.entries = newEntries;
- return this;
- }
-
- return new HashCollisionNode(ownerID, this.keyHash, newEntries);
- };
-
-
-
-
- function ValueNode(ownerID, keyHash, entry) {
- this.ownerID = ownerID;
- this.keyHash = keyHash;
- this.entry = entry;
- }
-
- ValueNode.prototype.get = function(shift, keyHash, key, notSetValue) {
- return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
- };
-
- ValueNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
- var removed = value === NOT_SET;
- var keyMatch = is(key, this.entry[0]);
- if (keyMatch ? value === this.entry[1] : removed) {
- return this;
- }
-
- SetRef(didAlter);
-
- if (removed) {
- SetRef(didChangeSize);
- return; // undefined
- }
-
- if (keyMatch) {
- if (ownerID && ownerID === this.ownerID) {
- this.entry[1] = value;
- return this;
- }
- return new ValueNode(ownerID, this.keyHash, [key, value]);
- }
-
- SetRef(didChangeSize);
- return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
- };
-
-
-
- // #pragma Iterators
-
- ArrayMapNode.prototype.iterate =
- HashCollisionNode.prototype.iterate = function (fn, reverse) {
- var entries = this.entries;
- for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
- if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
- return false;
- }
- }
- };
-
- BitmapIndexedNode.prototype.iterate =
- HashArrayMapNode.prototype.iterate = function (fn, reverse) {
- var nodes = this.nodes;
- for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
- var node = nodes[reverse ? maxIndex - ii : ii];
- if (node && node.iterate(fn, reverse) === false) {
- return false;
- }
- }
- };
-
- ValueNode.prototype.iterate = function (fn, reverse) {
- return fn(this.entry);
- };
-
- createClass(MapIterator, Iterator);
-
- function MapIterator(map, type, reverse) {
- this._type = type;
- this._reverse = reverse;
- this._stack = map._root && mapIteratorFrame(map._root);
- }
-
- MapIterator.prototype.next = function() {
- var type = this._type;
- var stack = this._stack;
- while (stack) {
- var node = stack.node;
- var index = stack.index++;
- var maxIndex;
- if (node.entry) {
- if (index === 0) {
- return mapIteratorValue(type, node.entry);
- }
- } else if (node.entries) {
- maxIndex = node.entries.length - 1;
- if (index <= maxIndex) {
- return mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index]);
- }
- } else {
- maxIndex = node.nodes.length - 1;
- if (index <= maxIndex) {
- var subNode = node.nodes[this._reverse ? maxIndex - index : index];
- if (subNode) {
- if (subNode.entry) {
- return mapIteratorValue(type, subNode.entry);
- }
- stack = this._stack = mapIteratorFrame(subNode, stack);
- }
- continue;
- }
- }
- stack = this._stack = this._stack.__prev;
- }
- return iteratorDone();
- };
-
-
- function mapIteratorValue(type, entry) {
- return iteratorValue(type, entry[0], entry[1]);
- }
-
- function mapIteratorFrame(node, prev) {
- return {
- node: node,
- index: 0,
- __prev: prev
- };
- }
-
- function makeMap(size, root, ownerID, hash) {
- var map = Object.create(MapPrototype);
- map.size = size;
- map._root = root;
- map.__ownerID = ownerID;
- map.__hash = hash;
- map.__altered = false;
- return map;
- }
-
- var EMPTY_MAP;
- function emptyMap() {
- return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
- }
-
- function updateMap(map, k, v) {
- var newRoot;
- var newSize;
- if (!map._root) {
- if (v === NOT_SET) {
- return map;
- }
- newSize = 1;
- newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
- } else {
- var didChangeSize = MakeRef(CHANGE_LENGTH);
- var didAlter = MakeRef(DID_ALTER);
- newRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter);
- if (!didAlter.value) {
- return map;
- }
- newSize = map.size + (didChangeSize.value ? v === NOT_SET ? -1 : 1 : 0);
- }
- if (map.__ownerID) {
- map.size = newSize;
- map._root = newRoot;
- map.__hash = undefined;
- map.__altered = true;
- return map;
- }
- return newRoot ? makeMap(newSize, newRoot) : emptyMap();
- }
-
- function updateNode(node, ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
- if (!node) {
- if (value === NOT_SET) {
- return node;
- }
- SetRef(didAlter);
- SetRef(didChangeSize);
- return new ValueNode(ownerID, keyHash, [key, value]);
- }
- return node.update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter);
- }
-
- function isLeafNode(node) {
- return node.constructor === ValueNode || node.constructor === HashCollisionNode;
- }
-
- function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
- if (node.keyHash === keyHash) {
- return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
- }
-
- var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
- var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
-
- var newNode;
- var nodes = idx1 === idx2 ?
- [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)] :
- ((newNode = new ValueNode(ownerID, keyHash, entry)), idx1 < idx2 ? [node, newNode] : [newNode, node]);
-
- return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
- }
-
- function createNodes(ownerID, entries, key, value) {
- if (!ownerID) {
- ownerID = new OwnerID();
- }
- var node = new ValueNode(ownerID, hash(key), [key, value]);
- for (var ii = 0; ii < entries.length; ii++) {
- var entry = entries[ii];
- node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
- }
- return node;
- }
-
- function packNodes(ownerID, nodes, count, excluding) {
- var bitmap = 0;
- var packedII = 0;
- var packedNodes = new Array(count);
- for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
- var node = nodes[ii];
- if (node !== undefined && ii !== excluding) {
- bitmap |= bit;
- packedNodes[packedII++] = node;
- }
- }
- return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
- }
-
- function expandNodes(ownerID, nodes, bitmap, including, node) {
- var count = 0;
- var expandedNodes = new Array(SIZE);
- for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
- expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
- }
- expandedNodes[including] = node;
- return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
- }
-
- function mergeIntoMapWith(map, merger, iterables) {
- var iters = [];
- for (var ii = 0; ii < iterables.length; ii++) {
- var value = iterables[ii];
- var iter = KeyedIterable(value);
- if (!isIterable(value)) {
- iter = iter.map(function(v ) {return fromJS(v)});
- }
- iters.push(iter);
- }
- return mergeIntoCollectionWith(map, merger, iters);
- }
-
- function deepMerger(existing, value, key) {
- return existing && existing.mergeDeep && isIterable(value) ?
- existing.mergeDeep(value) :
- is(existing, value) ? existing : value;
- }
-
- function deepMergerWith(merger) {
- return function(existing, value, key) {
- if (existing && existing.mergeDeepWith && isIterable(value)) {
- return existing.mergeDeepWith(merger, value);
- }
- var nextValue = merger(existing, value, key);
- return is(existing, nextValue) ? existing : nextValue;
- };
- }
-
- function mergeIntoCollectionWith(collection, merger, iters) {
- iters = iters.filter(function(x ) {return x.size !== 0});
- if (iters.length === 0) {
- return collection;
- }
- if (collection.size === 0 && !collection.__ownerID && iters.length === 1) {
- return collection.constructor(iters[0]);
- }
- return collection.withMutations(function(collection ) {
- var mergeIntoMap = merger ?
- function(value, key) {
- collection.update(key, NOT_SET, function(existing )
- {return existing === NOT_SET ? value : merger(existing, value, key)}
- );
- } :
- function(value, key) {
- collection.set(key, value);
- };
- for (var ii = 0; ii < iters.length; ii++) {
- iters[ii].forEach(mergeIntoMap);
- }
- });
- }
-
- function updateInDeepMap(existing, keyPathIter, notSetValue, updater) {
- var isNotSet = existing === NOT_SET;
- var step = keyPathIter.next();
- if (step.done) {
- var existingValue = isNotSet ? notSetValue : existing;
- var newValue = updater(existingValue);
- return newValue === existingValue ? existing : newValue;
- }
- invariant(
- isNotSet || (existing && existing.set),
- 'invalid keyPath'
- );
- var key = step.value;
- var nextExisting = isNotSet ? NOT_SET : existing.get(key, NOT_SET);
- var nextUpdated = updateInDeepMap(
- nextExisting,
- keyPathIter,
- notSetValue,
- updater
- );
- return nextUpdated === nextExisting ? existing :
- nextUpdated === NOT_SET ? existing.remove(key) :
- (isNotSet ? emptyMap() : existing).set(key, nextUpdated);
- }
-
- function popCount(x) {
- x = x - ((x >> 1) & 0x55555555);
- x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
- x = (x + (x >> 4)) & 0x0f0f0f0f;
- x = x + (x >> 8);
- x = x + (x >> 16);
- return x & 0x7f;
- }
-
- function setIn(array, idx, val, canEdit) {
- var newArray = canEdit ? array : arrCopy(array);
- newArray[idx] = val;
- return newArray;
- }
-
- function spliceIn(array, idx, val, canEdit) {
- var newLen = array.length + 1;
- if (canEdit && idx + 1 === newLen) {
- array[idx] = val;
- return array;
- }
- var newArray = new Array(newLen);
- var after = 0;
- for (var ii = 0; ii < newLen; ii++) {
- if (ii === idx) {
- newArray[ii] = val;
- after = -1;
- } else {
- newArray[ii] = array[ii + after];
- }
- }
- return newArray;
- }
-
- function spliceOut(array, idx, canEdit) {
- var newLen = array.length - 1;
- if (canEdit && idx === newLen) {
- array.pop();
- return array;
- }
- var newArray = new Array(newLen);
- var after = 0;
- for (var ii = 0; ii < newLen; ii++) {
- if (ii === idx) {
- after = 1;
- }
- newArray[ii] = array[ii + after];
- }
- return newArray;
- }
-
- var MAX_ARRAY_MAP_SIZE = SIZE / 4;
- var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
- var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
-
- createClass(List, IndexedCollection);
-
- // @pragma Construction
-
- function List(value) {
- var empty = emptyList();
- if (value === null || value === undefined) {
- return empty;
- }
- if (isList(value)) {
- return value;
- }
- var iter = IndexedIterable(value);
- var size = iter.size;
- if (size === 0) {
- return empty;
- }
- assertNotInfinite(size);
- if (size > 0 && size < SIZE) {
- return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
- }
- return empty.withMutations(function(list ) {
- list.setSize(size);
- iter.forEach(function(v, i) {return list.set(i, v)});
- });
- }
-
- List.of = function(/*...values*/) {
- return this(arguments);
- };
-
- List.prototype.toString = function() {
- return this.__toString('List [', ']');
- };
-
- // @pragma Access
-
- List.prototype.get = function(index, notSetValue) {
- index = wrapIndex(this, index);
- if (index >= 0 && index < this.size) {
- index += this._origin;
- var node = listNodeFor(this, index);
- return node && node.array[index & MASK];
- }
- return notSetValue;
- };
-
- // @pragma Modification
-
- List.prototype.set = function(index, value) {
- return updateList(this, index, value);
- };
-
- List.prototype.remove = function(index) {
- return !this.has(index) ? this :
- index === 0 ? this.shift() :
- index === this.size - 1 ? this.pop() :
- this.splice(index, 1);
- };
-
- List.prototype.insert = function(index, value) {
- return this.splice(index, 0, value);
- };
-
- List.prototype.clear = function() {
- if (this.size === 0) {
- return this;
- }
- if (this.__ownerID) {
- this.size = this._origin = this._capacity = 0;
- this._level = SHIFT;
- this._root = this._tail = null;
- this.__hash = undefined;
- this.__altered = true;
- return this;
- }
- return emptyList();
- };
-
- List.prototype.push = function(/*...values*/) {
- var values = arguments;
- var oldSize = this.size;
- return this.withMutations(function(list ) {
- setListBounds(list, 0, oldSize + values.length);
- for (var ii = 0; ii < values.length; ii++) {
- list.set(oldSize + ii, values[ii]);
- }
- });
- };
-
- List.prototype.pop = function() {
- return setListBounds(this, 0, -1);
- };
-
- List.prototype.unshift = function(/*...values*/) {
- var values = arguments;
- return this.withMutations(function(list ) {
- setListBounds(list, -values.length);
- for (var ii = 0; ii < values.length; ii++) {
- list.set(ii, values[ii]);
- }
- });
- };
-
- List.prototype.shift = function() {
- return setListBounds(this, 1);
- };
-
- // @pragma Composition
-
- List.prototype.merge = function(/*...iters*/) {
- return mergeIntoListWith(this, undefined, arguments);
- };
-
- List.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
- return mergeIntoListWith(this, merger, iters);
- };
-
- List.prototype.mergeDeep = function(/*...iters*/) {
- return mergeIntoListWith(this, deepMerger, arguments);
- };
-
- List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
- return mergeIntoListWith(this, deepMergerWith(merger), iters);
- };
-
- List.prototype.setSize = function(size) {
- return setListBounds(this, 0, size);
- };
-
- // @pragma Iteration
-
- List.prototype.slice = function(begin, end) {
- var size = this.size;
- if (wholeSlice(begin, end, size)) {
- return this;
- }
- return setListBounds(
- this,
- resolveBegin(begin, size),
- resolveEnd(end, size)
- );
- };
-
- List.prototype.__iterator = function(type, reverse) {
- var index = 0;
- var values = iterateList(this, reverse);
- return new Iterator(function() {
- var value = values();
- return value === DONE ?
- iteratorDone() :
- iteratorValue(type, index++, value);
- });
- };
-
- List.prototype.__iterate = function(fn, reverse) {
- var index = 0;
- var values = iterateList(this, reverse);
- var value;
- while ((value = values()) !== DONE) {
- if (fn(value, index++, this) === false) {
- break;
- }
- }
- return index;
- };
-
- List.prototype.__ensureOwner = function(ownerID) {
- if (ownerID === this.__ownerID) {
- return this;
- }
- if (!ownerID) {
- this.__ownerID = ownerID;
- return this;
- }
- return makeList(this._origin, this._capacity, this._level, this._root, this._tail, ownerID, this.__hash);
- };
-
-
- function isList(maybeList) {
- return !!(maybeList && maybeList[IS_LIST_SENTINEL]);
- }
-
- List.isList = isList;
-
- var IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
-
- var ListPrototype = List.prototype;
- ListPrototype[IS_LIST_SENTINEL] = true;
- ListPrototype[DELETE] = ListPrototype.remove;
- ListPrototype.setIn = MapPrototype.setIn;
- ListPrototype.deleteIn =
- ListPrototype.removeIn = MapPrototype.removeIn;
- ListPrototype.update = MapPrototype.update;
- ListPrototype.updateIn = MapPrototype.updateIn;
- ListPrototype.mergeIn = MapPrototype.mergeIn;
- ListPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
- ListPrototype.withMutations = MapPrototype.withMutations;
- ListPrototype.asMutable = MapPrototype.asMutable;
- ListPrototype.asImmutable = MapPrototype.asImmutable;
- ListPrototype.wasAltered = MapPrototype.wasAltered;
-
-
-
- function VNode(array, ownerID) {
- this.array = array;
- this.ownerID = ownerID;
- }
-
- // TODO: seems like these methods are very similar
-
- VNode.prototype.removeBefore = function(ownerID, level, index) {
- if (index === level ? 1 << level : this.array.length === 0) {
- return this;
- }
- var originIndex = (index >>> level) & MASK;
- if (originIndex >= this.array.length) {
- return new VNode([], ownerID);
- }
- var removingFirst = originIndex === 0;
- var newChild;
- if (level > 0) {
- var oldChild = this.array[originIndex];
- newChild = oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
- if (newChild === oldChild && removingFirst) {
- return this;
- }
- }
- if (removingFirst && !newChild) {
- return this;
- }
- var editable = editableVNode(this, ownerID);
- if (!removingFirst) {
- for (var ii = 0; ii < originIndex; ii++) {
- editable.array[ii] = undefined;
- }
- }
- if (newChild) {
- editable.array[originIndex] = newChild;
- }
- return editable;
- };
-
- VNode.prototype.removeAfter = function(ownerID, level, index) {
- if (index === (level ? 1 << level : 0) || this.array.length === 0) {
- return this;
- }
- var sizeIndex = ((index - 1) >>> level) & MASK;
- if (sizeIndex >= this.array.length) {
- return this;
- }
-
- var newChild;
- if (level > 0) {
- var oldChild = this.array[sizeIndex];
- newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
- if (newChild === oldChild && sizeIndex === this.array.length - 1) {
- return this;
- }
- }
-
- var editable = editableVNode(this, ownerID);
- editable.array.splice(sizeIndex + 1);
- if (newChild) {
- editable.array[sizeIndex] = newChild;
- }
- return editable;
- };
-
-
-
- var DONE = {};
-
- function iterateList(list, reverse) {
- var left = list._origin;
- var right = list._capacity;
- var tailPos = getTailOffset(right);
- var tail = list._tail;
-
- return iterateNodeOrLeaf(list._root, list._level, 0);
-
- function iterateNodeOrLeaf(node, level, offset) {
- return level === 0 ?
- iterateLeaf(node, offset) :
- iterateNode(node, level, offset);
- }
-
- function iterateLeaf(node, offset) {
- var array = offset === tailPos ? tail && tail.array : node && node.array;
- var from = offset > left ? 0 : left - offset;
- var to = right - offset;
- if (to > SIZE) {
- to = SIZE;
- }
- return function() {
- if (from === to) {
- return DONE;
- }
- var idx = reverse ? --to : from++;
- return array && array[idx];
- };
- }
-
- function iterateNode(node, level, offset) {
- var values;
- var array = node && node.array;
- var from = offset > left ? 0 : (left - offset) >> level;
- var to = ((right - offset) >> level) + 1;
- if (to > SIZE) {
- to = SIZE;
- }
- return function() {
- do {
- if (values) {
- var value = values();
- if (value !== DONE) {
- return value;
- }
- values = null;
- }
- if (from === to) {
- return DONE;
- }
- var idx = reverse ? --to : from++;
- values = iterateNodeOrLeaf(
- array && array[idx], level - SHIFT, offset + (idx << level)
- );
- } while (true);
- };
- }
- }
-
- function makeList(origin, capacity, level, root, tail, ownerID, hash) {
- var list = Object.create(ListPrototype);
- list.size = capacity - origin;
- list._origin = origin;
- list._capacity = capacity;
- list._level = level;
- list._root = root;
- list._tail = tail;
- list.__ownerID = ownerID;
- list.__hash = hash;
- list.__altered = false;
- return list;
- }
-
- var EMPTY_LIST;
- function emptyList() {
- return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
- }
-
- function updateList(list, index, value) {
- index = wrapIndex(list, index);
-
- if (index !== index) {
- return list;
- }
-
- if (index >= list.size || index < 0) {
- return list.withMutations(function(list ) {
- index < 0 ?
- setListBounds(list, index).set(0, value) :
- setListBounds(list, 0, index + 1).set(index, value);
- });
- }
-
- index += list._origin;
-
- var newTail = list._tail;
- var newRoot = list._root;
- var didAlter = MakeRef(DID_ALTER);
- if (index >= getTailOffset(list._capacity)) {
- newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
- } else {
- newRoot = updateVNode(newRoot, list.__ownerID, list._level, index, value, didAlter);
- }
-
- if (!didAlter.value) {
- return list;
- }
-
- if (list.__ownerID) {
- list._root = newRoot;
- list._tail = newTail;
- list.__hash = undefined;
- list.__altered = true;
- return list;
- }
- return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
- }
-
- function updateVNode(node, ownerID, level, index, value, didAlter) {
- var idx = (index >>> level) & MASK;
- var nodeHas = node && idx < node.array.length;
- if (!nodeHas && value === undefined) {
- return node;
- }
-
- var newNode;
-
- if (level > 0) {
- var lowerNode = node && node.array[idx];
- var newLowerNode = updateVNode(lowerNode, ownerID, level - SHIFT, index, value, didAlter);
- if (newLowerNode === lowerNode) {
- return node;
- }
- newNode = editableVNode(node, ownerID);
- newNode.array[idx] = newLowerNode;
- return newNode;
- }
-
- if (nodeHas && node.array[idx] === value) {
- return node;
- }
-
- SetRef(didAlter);
-
- newNode = editableVNode(node, ownerID);
- if (value === undefined && idx === newNode.array.length - 1) {
- newNode.array.pop();
- } else {
- newNode.array[idx] = value;
- }
- return newNode;
- }
-
- function editableVNode(node, ownerID) {
- if (ownerID && node && ownerID === node.ownerID) {
- return node;
- }
- return new VNode(node ? node.array.slice() : [], ownerID);
- }
-
- function listNodeFor(list, rawIndex) {
- if (rawIndex >= getTailOffset(list._capacity)) {
- return list._tail;
- }
- if (rawIndex < 1 << (list._level + SHIFT)) {
- var node = list._root;
- var level = list._level;
- while (node && level > 0) {
- node = node.array[(rawIndex >>> level) & MASK];
- level -= SHIFT;
- }
- return node;
- }
- }
-
- function setListBounds(list, begin, end) {
- // Sanitize begin & end using this shorthand for ToInt32(argument)
- // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
- if (begin !== undefined) {
- begin = begin | 0;
- }
- if (end !== undefined) {
- end = end | 0;
- }
- var owner = list.__ownerID || new OwnerID();
- var oldOrigin = list._origin;
- var oldCapacity = list._capacity;
- var newOrigin = oldOrigin + begin;
- var newCapacity = end === undefined ? oldCapacity : end < 0 ? oldCapacity + end : oldOrigin + end;
- if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
- return list;
- }
-
- // If it's going to end after it starts, it's empty.
- if (newOrigin >= newCapacity) {
- return list.clear();
- }
-
- var newLevel = list._level;
- var newRoot = list._root;
-
- // New origin might need creating a higher root.
- var offsetShift = 0;
- while (newOrigin + offsetShift < 0) {
- newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner);
- newLevel += SHIFT;
- offsetShift += 1 << newLevel;
- }
- if (offsetShift) {
- newOrigin += offsetShift;
- oldOrigin += offsetShift;
- newCapacity += offsetShift;
- oldCapacity += offsetShift;
- }
-
- var oldTailOffset = getTailOffset(oldCapacity);
- var newTailOffset = getTailOffset(newCapacity);
-
- // New size might need creating a higher root.
- while (newTailOffset >= 1 << (newLevel + SHIFT)) {
- newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner);
- newLevel += SHIFT;
- }
-
- // Locate or create the new tail.
- var oldTail = list._tail;
- var newTail = newTailOffset < oldTailOffset ?
- listNodeFor(list, newCapacity - 1) :
- newTailOffset > oldTailOffset ? new VNode([], owner) : oldTail;
-
- // Merge Tail into tree.
- if (oldTail && newTailOffset > oldTailOffset && newOrigin < oldCapacity && oldTail.array.length) {
- newRoot = editableVNode(newRoot, owner);
- var node = newRoot;
- for (var level = newLevel; level > SHIFT; level -= SHIFT) {
- var idx = (oldTailOffset >>> level) & MASK;
- node = node.array[idx] = editableVNode(node.array[idx], owner);
- }
- node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
- }
-
- // If the size has been reduced, there's a chance the tail needs to be trimmed.
- if (newCapacity < oldCapacity) {
- newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
- }
-
- // If the new origin is within the tail, then we do not need a root.
- if (newOrigin >= newTailOffset) {
- newOrigin -= newTailOffset;
- newCapacity -= newTailOffset;
- newLevel = SHIFT;
- newRoot = null;
- newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
-
- // Otherwise, if the root has been trimmed, garbage collect.
- } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
- offsetShift = 0;
-
- // Identify the new top root node of the subtree of the old root.
- while (newRoot) {
- var beginIndex = (newOrigin >>> newLevel) & MASK;
- if (beginIndex !== (newTailOffset >>> newLevel) & MASK) {
- break;
- }
- if (beginIndex) {
- offsetShift += (1 << newLevel) * beginIndex;
- }
- newLevel -= SHIFT;
- newRoot = newRoot.array[beginIndex];
- }
-
- // Trim the new sides of the new root.
- if (newRoot && newOrigin > oldOrigin) {
- newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
- }
- if (newRoot && newTailOffset < oldTailOffset) {
- newRoot = newRoot.removeAfter(owner, newLevel, newTailOffset - offsetShift);
- }
- if (offsetShift) {
- newOrigin -= offsetShift;
- newCapacity -= offsetShift;
- }
- }
-
- if (list.__ownerID) {
- list.size = newCapacity - newOrigin;
- list._origin = newOrigin;
- list._capacity = newCapacity;
- list._level = newLevel;
- list._root = newRoot;
- list._tail = newTail;
- list.__hash = undefined;
- list.__altered = true;
- return list;
- }
- return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
- }
-
- function mergeIntoListWith(list, merger, iterables) {
- var iters = [];
- var maxSize = 0;
- for (var ii = 0; ii < iterables.length; ii++) {
- var value = iterables[ii];
- var iter = IndexedIterable(value);
- if (iter.size > maxSize) {
- maxSize = iter.size;
- }
- if (!isIterable(value)) {
- iter = iter.map(function(v ) {return fromJS(v)});
- }
- iters.push(iter);
- }
- if (maxSize > list.size) {
- list = list.setSize(maxSize);
- }
- return mergeIntoCollectionWith(list, merger, iters);
- }
-
- function getTailOffset(size) {
- return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
- }
-
- createClass(OrderedMap, Map);
-
- // @pragma Construction
-
- function OrderedMap(value) {
- return value === null || value === undefined ? emptyOrderedMap() :
- isOrderedMap(value) ? value :
- emptyOrderedMap().withMutations(function(map ) {
- var iter = KeyedIterable(value);
- assertNotInfinite(iter.size);
- iter.forEach(function(v, k) {return map.set(k, v)});
- });
- }
-
- OrderedMap.of = function(/*...values*/) {
- return this(arguments);
- };
-
- OrderedMap.prototype.toString = function() {
- return this.__toString('OrderedMap {', '}');
- };
-
- // @pragma Access
-
- OrderedMap.prototype.get = function(k, notSetValue) {
- var index = this._map.get(k);
- return index !== undefined ? this._list.get(index)[1] : notSetValue;
- };
-
- // @pragma Modification
-
- OrderedMap.prototype.clear = function() {
- if (this.size === 0) {
- return this;
- }
- if (this.__ownerID) {
- this.size = 0;
- this._map.clear();
- this._list.clear();
- return this;
- }
- return emptyOrderedMap();
- };
-
- OrderedMap.prototype.set = function(k, v) {
- return updateOrderedMap(this, k, v);
- };
-
- OrderedMap.prototype.remove = function(k) {
- return updateOrderedMap(this, k, NOT_SET);
- };
-
- OrderedMap.prototype.wasAltered = function() {
- return this._map.wasAltered() || this._list.wasAltered();
- };
-
- OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this;
- return this._list.__iterate(
- function(entry ) {return entry && fn(entry[1], entry[0], this$0)},
- reverse
- );
- };
-
- OrderedMap.prototype.__iterator = function(type, reverse) {
- return this._list.fromEntrySeq().__iterator(type, reverse);
- };
-
- OrderedMap.prototype.__ensureOwner = function(ownerID) {
- if (ownerID === this.__ownerID) {
- return this;
- }
- var newMap = this._map.__ensureOwner(ownerID);
- var newList = this._list.__ensureOwner(ownerID);
- if (!ownerID) {
- this.__ownerID = ownerID;
- this._map = newMap;
- this._list = newList;
- return this;
- }
- return makeOrderedMap(newMap, newList, ownerID, this.__hash);
- };
-
-
- function isOrderedMap(maybeOrderedMap) {
- return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
- }
-
- OrderedMap.isOrderedMap = isOrderedMap;
-
- OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
- OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
-
-
-
- function makeOrderedMap(map, list, ownerID, hash) {
- var omap = Object.create(OrderedMap.prototype);
- omap.size = map ? map.size : 0;
- omap._map = map;
- omap._list = list;
- omap.__ownerID = ownerID;
- omap.__hash = hash;
- return omap;
- }
-
- var EMPTY_ORDERED_MAP;
- function emptyOrderedMap() {
- return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()));
- }
-
- function updateOrderedMap(omap, k, v) {
- var map = omap._map;
- var list = omap._list;
- var i = map.get(k);
- var has = i !== undefined;
- var newMap;
- var newList;
- if (v === NOT_SET) { // removed
- if (!has) {
- return omap;
- }
- if (list.size >= SIZE && list.size >= map.size * 2) {
- newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx});
- newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap();
- if (omap.__ownerID) {
- newMap.__ownerID = newList.__ownerID = omap.__ownerID;
- }
- } else {
- newMap = map.remove(k);
- newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
- }
- } else {
- if (has) {
- if (v === list.get(i)[1]) {
- return omap;
- }
- newMap = map;
- newList = list.set(i, [k, v]);
- } else {
- newMap = map.set(k, list.size);
- newList = list.set(list.size, [k, v]);
- }
- }
- if (omap.__ownerID) {
- omap.size = newMap.size;
- omap._map = newMap;
- omap._list = newList;
- omap.__hash = undefined;
- return omap;
- }
- return makeOrderedMap(newMap, newList);
- }
-
- createClass(ToKeyedSequence, KeyedSeq);
- function ToKeyedSequence(indexed, useKeys) {
- this._iter = indexed;
- this._useKeys = useKeys;
- this.size = indexed.size;
- }
-
- ToKeyedSequence.prototype.get = function(key, notSetValue) {
- return this._iter.get(key, notSetValue);
- };
-
- ToKeyedSequence.prototype.has = function(key) {
- return this._iter.has(key);
- };
-
- ToKeyedSequence.prototype.valueSeq = function() {
- return this._iter.valueSeq();
- };
-
- ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
- var reversedSequence = reverseFactory(this, true);
- if (!this._useKeys) {
- reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
- }
- return reversedSequence;
- };
-
- ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
- var mappedSequence = mapFactory(this, mapper, context);
- if (!this._useKeys) {
- mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
- }
- return mappedSequence;
- };
-
- ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
- var ii;
- return this._iter.__iterate(
- this._useKeys ?
- function(v, k) {return fn(v, k, this$0)} :
- ((ii = reverse ? resolveSize(this) : 0),
- function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
- reverse
- );
- };
-
- ToKeyedSequence.prototype.__iterator = function(type, reverse) {
- if (this._useKeys) {
- return this._iter.__iterator(type, reverse);
- }
- var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
- var ii = reverse ? resolveSize(this) : 0;
- return new Iterator(function() {
- var step = iterator.next();
- return step.done ? step :
- iteratorValue(type, reverse ? --ii : ii++, step.value, step);
- });
- };
-
- ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
-
-
- createClass(ToIndexedSequence, IndexedSeq);
- function ToIndexedSequence(iter) {
- this._iter = iter;
- this.size = iter.size;
- }
-
- ToIndexedSequence.prototype.includes = function(value) {
- return this._iter.includes(value);
- };
-
- ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
- var iterations = 0;
- return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
- };
-
- ToIndexedSequence.prototype.__iterator = function(type, reverse) {
- var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
- var iterations = 0;
- return new Iterator(function() {
- var step = iterator.next();
- return step.done ? step :
- iteratorValue(type, iterations++, step.value, step)
- });
- };
-
-
-
- createClass(ToSetSequence, SetSeq);
- function ToSetSequence(iter) {
- this._iter = iter;
- this.size = iter.size;
- }
-
- ToSetSequence.prototype.has = function(key) {
- return this._iter.includes(key);
- };
-
- ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
- return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
- };
-
- ToSetSequence.prototype.__iterator = function(type, reverse) {
- var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
- return new Iterator(function() {
- var step = iterator.next();
- return step.done ? step :
- iteratorValue(type, step.value, step.value, step);
- });
- };
-
-
-
- createClass(FromEntriesSequence, KeyedSeq);
- function FromEntriesSequence(entries) {
- this._iter = entries;
- this.size = entries.size;
- }
-
- FromEntriesSequence.prototype.entrySeq = function() {
- return this._iter.toSeq();
- };
-
- FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
- return this._iter.__iterate(function(entry ) {
- // Check if entry exists first so array access doesn't throw for holes
- // in the parent iteration.
- if (entry) {
- validateEntry(entry);
- var indexedIterable = isIterable(entry);
- return fn(
- indexedIterable ? entry.get(1) : entry[1],
- indexedIterable ? entry.get(0) : entry[0],
- this$0
- );
- }
- }, reverse);
- };
-
- FromEntriesSequence.prototype.__iterator = function(type, reverse) {
- var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
- return new Iterator(function() {
- while (true) {
- var step = iterator.next();
- if (step.done) {
- return step;
- }
- var entry = step.value;
- // Check if entry exists first so array access doesn't throw for holes
- // in the parent iteration.
- if (entry) {
- validateEntry(entry);
- var indexedIterable = isIterable(entry);
- return iteratorValue(
- type,
- indexedIterable ? entry.get(0) : entry[0],
- indexedIterable ? entry.get(1) : entry[1],
- step
- );
- }
- }
- });
- };
-
-
- ToIndexedSequence.prototype.cacheResult =
- ToKeyedSequence.prototype.cacheResult =
- ToSetSequence.prototype.cacheResult =
- FromEntriesSequence.prototype.cacheResult =
- cacheResultThrough;
-
-
- function flipFactory(iterable) {
- var flipSequence = makeSequence(iterable);
- flipSequence._iter = iterable;
- flipSequence.size = iterable.size;
- flipSequence.flip = function() {return iterable};
- flipSequence.reverse = function () {
- var reversedSequence = iterable.reverse.apply(this); // super.reverse()
- reversedSequence.flip = function() {return iterable.reverse()};
- return reversedSequence;
- };
- flipSequence.has = function(key ) {return iterable.includes(key)};
- flipSequence.includes = function(key ) {return iterable.has(key)};
- flipSequence.cacheResult = cacheResultThrough;
- flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
- return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
- };
- flipSequence.__iteratorUncached = function(type, reverse) {
- if (type === ITERATE_ENTRIES) {
- var iterator = iterable.__iterator(type, reverse);
- return new Iterator(function() {
- var step = iterator.next();
- if (!step.done) {
- var k = step.value[0];
- step.value[0] = step.value[1];
- step.value[1] = k;
- }
- return step;
- });
- }
- return iterable.__iterator(
- type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
- reverse
- );
- };
- return flipSequence;
- }
-
-
- function mapFactory(iterable, mapper, context) {
- var mappedSequence = makeSequence(iterable);
- mappedSequence.size = iterable.size;
- mappedSequence.has = function(key ) {return iterable.has(key)};
- mappedSequence.get = function(key, notSetValue) {
- var v = iterable.get(key, NOT_SET);
- return v === NOT_SET ?
- notSetValue :
- mapper.call(context, v, key, iterable);
- };
- mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
- return iterable.__iterate(
- function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
- reverse
- );
- };
- mappedSequence.__iteratorUncached = function (type, reverse) {
- var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
- return new Iterator(function() {
- var step = iterator.next();
- if (step.done) {
- return step;
- }
- var entry = step.value;
- var key = entry[0];
- return iteratorValue(
- type,
- key,
- mapper.call(context, entry[1], key, iterable),
- step
- );
- });
- };
- return mappedSequence;
- }
-
-
- function reverseFactory(iterable, useKeys) {
- var reversedSequence = makeSequence(iterable);
- reversedSequence._iter = iterable;
- reversedSequence.size = iterable.size;
- reversedSequence.reverse = function() {return iterable};
- if (iterable.flip) {
- reversedSequence.flip = function () {
- var flipSequence = flipFactory(iterable);
- flipSequence.reverse = function() {return iterable.flip()};
- return flipSequence;
- };
- }
- reversedSequence.get = function(key, notSetValue)
- {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
- reversedSequence.has = function(key )
- {return iterable.has(useKeys ? key : -1 - key)};
- reversedSequence.includes = function(value ) {return iterable.includes(value)};
- reversedSequence.cacheResult = cacheResultThrough;
- reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
- return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
- };
- reversedSequence.__iterator =
- function(type, reverse) {return iterable.__iterator(type, !reverse)};
- return reversedSequence;
- }
-
-
- function filterFactory(iterable, predicate, context, useKeys) {
- var filterSequence = makeSequence(iterable);
- if (useKeys) {
- filterSequence.has = function(key ) {
- var v = iterable.get(key, NOT_SET);
- return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
- };
- filterSequence.get = function(key, notSetValue) {
- var v = iterable.get(key, NOT_SET);
- return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
- v : notSetValue;
- };
- }
- filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
- var iterations = 0;
- iterable.__iterate(function(v, k, c) {
- if (predicate.call(context, v, k, c)) {
- iterations++;
- return fn(v, useKeys ? k : iterations - 1, this$0);
- }
- }, reverse);
- return iterations;
- };
- filterSequence.__iteratorUncached = function (type, reverse) {
- var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
- var iterations = 0;
- return new Iterator(function() {
- while (true) {
- var step = iterator.next();
- if (step.done) {
- return step;
- }
- var entry = step.value;
- var key = entry[0];
- var value = entry[1];
- if (predicate.call(context, value, key, iterable)) {
- return iteratorValue(type, useKeys ? key : iterations++, value, step);
- }
- }
- });
- };
- return filterSequence;
- }
-
-
- function countByFactory(iterable, grouper, context) {
- var groups = Map().asMutable();
- iterable.__iterate(function(v, k) {
- groups.update(
- grouper.call(context, v, k, iterable),
- 0,
- function(a ) {return a + 1}
- );
- });
- return groups.asImmutable();
- }
-
-
- function groupByFactory(iterable, grouper, context) {
- var isKeyedIter = isKeyed(iterable);
- var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable();
- iterable.__iterate(function(v, k) {
- groups.update(
- grouper.call(context, v, k, iterable),
- function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
- );
- });
- var coerce = iterableClass(iterable);
- return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
- }
-
-
- function sliceFactory(iterable, begin, end, useKeys) {
- var originalSize = iterable.size;
-
- // Sanitize begin & end using this shorthand for ToInt32(argument)
- // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
- if (begin !== undefined) {
- begin = begin | 0;
- }
- if (end !== undefined) {
- end = end | 0;
- }
-
- if (wholeSlice(begin, end, originalSize)) {
- return iterable;
- }
-
- var resolvedBegin = resolveBegin(begin, originalSize);
- var resolvedEnd = resolveEnd(end, originalSize);
-
- // begin or end will be NaN if they were provided as negative numbers and
- // this iterable's size is unknown. In that case, cache first so there is
- // a known size and these do not resolve to NaN.
- if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
- return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
- }
-
- // Note: resolvedEnd is undefined when the original sequence's length is
- // unknown and this slice did not supply an end and should contain all
- // elements after resolvedBegin.
- // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
- var resolvedSize = resolvedEnd - resolvedBegin;
- var sliceSize;
- if (resolvedSize === resolvedSize) {
- sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
- }
-
- var sliceSeq = makeSequence(iterable);
-
- // If iterable.size is undefined, the size of the realized sliceSeq is
- // unknown at this point unless the number of items to slice is 0
- sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
-
- if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
- sliceSeq.get = function (index, notSetValue) {
- index = wrapIndex(this, index);
- return index >= 0 && index < sliceSize ?
- iterable.get(index + resolvedBegin, notSetValue) :
- notSetValue;
- };
- }
-
- sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
- if (sliceSize === 0) {
- return 0;
- }
- if (reverse) {
- return this.cacheResult().__iterate(fn, reverse);
- }
- var skipped = 0;
- var isSkipping = true;
- var iterations = 0;
- iterable.__iterate(function(v, k) {
- if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
- iterations++;
- return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
- iterations !== sliceSize;
- }
- });
- return iterations;
- };
-
- sliceSeq.__iteratorUncached = function(type, reverse) {
- if (sliceSize !== 0 && reverse) {
- return this.cacheResult().__iterator(type, reverse);
- }
- // Don't bother instantiating parent iterator if taking 0.
- var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
- var skipped = 0;
- var iterations = 0;
- return new Iterator(function() {
- while (skipped++ < resolvedBegin) {
- iterator.next();
- }
- if (++iterations > sliceSize) {
- return iteratorDone();
- }
- var step = iterator.next();
- if (useKeys || type === ITERATE_VALUES) {
- return step;
- } else if (type === ITERATE_KEYS) {
- return iteratorValue(type, iterations - 1, undefined, step);
- } else {
- return iteratorValue(type, iterations - 1, step.value[1], step);
- }
- });
- };
-
- return sliceSeq;
- }
-
-
- function takeWhileFactory(iterable, predicate, context) {
- var takeSequence = makeSequence(iterable);
- takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
- if (reverse) {
- return this.cacheResult().__iterate(fn, reverse);
- }
- var iterations = 0;
- iterable.__iterate(function(v, k, c)
- {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
- );
- return iterations;
- };
- takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
- if (reverse) {
- return this.cacheResult().__iterator(type, reverse);
- }
- var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
- var iterating = true;
- return new Iterator(function() {
- if (!iterating) {
- return iteratorDone();
- }
- var step = iterator.next();
- if (step.done) {
- return step;
- }
- var entry = step.value;
- var k = entry[0];
- var v = entry[1];
- if (!predicate.call(context, v, k, this$0)) {
- iterating = false;
- return iteratorDone();
- }
- return type === ITERATE_ENTRIES ? step :
- iteratorValue(type, k, v, step);
- });
- };
- return takeSequence;
- }
-
-
- function skipWhileFactory(iterable, predicate, context, useKeys) {
- var skipSequence = makeSequence(iterable);
- skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
- if (reverse) {
- return this.cacheResult().__iterate(fn, reverse);
- }
- var isSkipping = true;
- var iterations = 0;
- iterable.__iterate(function(v, k, c) {
- if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
- iterations++;
- return fn(v, useKeys ? k : iterations - 1, this$0);
- }
- });
- return iterations;
- };
- skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
- if (reverse) {
- return this.cacheResult().__iterator(type, reverse);
- }
- var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
- var skipping = true;
- var iterations = 0;
- return new Iterator(function() {
- var step, k, v;
- do {
- step = iterator.next();
- if (step.done) {
- if (useKeys || type === ITERATE_VALUES) {
- return step;
- } else if (type === ITERATE_KEYS) {
- return iteratorValue(type, iterations++, undefined, step);
- } else {
- return iteratorValue(type, iterations++, step.value[1], step);
- }
- }
- var entry = step.value;
- k = entry[0];
- v = entry[1];
- skipping && (skipping = predicate.call(context, v, k, this$0));
- } while (skipping);
- return type === ITERATE_ENTRIES ? step :
- iteratorValue(type, k, v, step);
- });
- };
- return skipSequence;
- }
-
-
- function concatFactory(iterable, values) {
- var isKeyedIterable = isKeyed(iterable);
- var iters = [iterable].concat(values).map(function(v ) {
- if (!isIterable(v)) {
- v = isKeyedIterable ?
- keyedSeqFromValue(v) :
- indexedSeqFromValue(Array.isArray(v) ? v : [v]);
- } else if (isKeyedIterable) {
- v = KeyedIterable(v);
- }
- return v;
- }).filter(function(v ) {return v.size !== 0});
-
- if (iters.length === 0) {
- return iterable;
- }
-
- if (iters.length === 1) {
- var singleton = iters[0];
- if (singleton === iterable ||
- isKeyedIterable && isKeyed(singleton) ||
- isIndexed(iterable) && isIndexed(singleton)) {
- return singleton;
- }
- }
-
- var concatSeq = new ArraySeq(iters);
- if (isKeyedIterable) {
- concatSeq = concatSeq.toKeyedSeq();
- } else if (!isIndexed(iterable)) {
- concatSeq = concatSeq.toSetSeq();
- }
- concatSeq = concatSeq.flatten(true);
- concatSeq.size = iters.reduce(
- function(sum, seq) {
- if (sum !== undefined) {
- var size = seq.size;
- if (size !== undefined) {
- return sum + size;
- }
- }
- },
- 0
- );
- return concatSeq;
- }
-
-
- function flattenFactory(iterable, depth, useKeys) {
- var flatSequence = makeSequence(iterable);
- flatSequence.__iterateUncached = function(fn, reverse) {
- var iterations = 0;
- var stopped = false;
- function flatDeep(iter, currentDepth) {var this$0 = this;
- iter.__iterate(function(v, k) {
- if ((!depth || currentDepth < depth) && isIterable(v)) {
- flatDeep(v, currentDepth + 1);
- } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
- stopped = true;
- }
- return !stopped;
- }, reverse);
- }
- flatDeep(iterable, 0);
- return iterations;
- };
- flatSequence.__iteratorUncached = function(type, reverse) {
- var iterator = iterable.__iterator(type, reverse);
- var stack = [];
- var iterations = 0;
- return new Iterator(function() {
- while (iterator) {
- var step = iterator.next();
- if (step.done !== false) {
- iterator = stack.pop();
- continue;
- }
- var v = step.value;
- if (type === ITERATE_ENTRIES) {
- v = v[1];
- }
- if ((!depth || stack.length < depth) && isIterable(v)) {
- stack.push(iterator);
- iterator = v.__iterator(type, reverse);
- } else {
- return useKeys ? step : iteratorValue(type, iterations++, v, step);
- }
- }
- return iteratorDone();
- });
- };
- return flatSequence;
- }
-
-
- function flatMapFactory(iterable, mapper, context) {
- var coerce = iterableClass(iterable);
- return iterable.toSeq().map(
- function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
- ).flatten(true);
- }
-
-
- function interposeFactory(iterable, separator) {
- var interposedSequence = makeSequence(iterable);
- interposedSequence.size = iterable.size && iterable.size * 2 -1;
- interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
- var iterations = 0;
- iterable.__iterate(function(v, k)
- {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
- fn(v, iterations++, this$0) !== false},
- reverse
- );
- return iterations;
- };
- interposedSequence.__iteratorUncached = function(type, reverse) {
- var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
- var iterations = 0;
- var step;
- return new Iterator(function() {
- if (!step || iterations % 2) {
- step = iterator.next();
- if (step.done) {
- return step;
- }
- }
- return iterations % 2 ?
- iteratorValue(type, iterations++, separator) :
- iteratorValue(type, iterations++, step.value, step);
- });
- };
- return interposedSequence;
- }
-
-
- function sortFactory(iterable, comparator, mapper) {
- if (!comparator) {
- comparator = defaultComparator;
- }
- var isKeyedIterable = isKeyed(iterable);
- var index = 0;
- var entries = iterable.toSeq().map(
- function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
- ).toArray();
- entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
- isKeyedIterable ?
- function(v, i) { entries[i].length = 2; } :
- function(v, i) { entries[i] = v[1]; }
- );
- return isKeyedIterable ? KeyedSeq(entries) :
- isIndexed(iterable) ? IndexedSeq(entries) :
- SetSeq(entries);
- }
-
-
- function maxFactory(iterable, comparator, mapper) {
- if (!comparator) {
- comparator = defaultComparator;
- }
- if (mapper) {
- var entry = iterable.toSeq()
- .map(function(v, k) {return [v, mapper(v, k, iterable)]})
- .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
- return entry && entry[0];
- } else {
- return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
- }
- }
-
- function maxCompare(comparator, a, b) {
- var comp = comparator(b, a);
- // b is considered the new max if the comparator declares them equal, but
- // they are not equal and b is in fact a nullish value.
- return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
- }
-
-
- function zipWithFactory(keyIter, zipper, iters) {
- var zipSequence = makeSequence(keyIter);
- zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
- // Note: this a generic base implementation of __iterate in terms of
- // __iterator which may be more generically useful in the future.
- zipSequence.__iterate = function(fn, reverse) {
- /* generic:
- var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
- var step;
- var iterations = 0;
- while (!(step = iterator.next()).done) {
- iterations++;
- if (fn(step.value[1], step.value[0], this) === false) {
- break;
- }
- }
- return iterations;
- */
- // indexed:
- var iterator = this.__iterator(ITERATE_VALUES, reverse);
- var step;
- var iterations = 0;
- while (!(step = iterator.next()).done) {
- if (fn(step.value, iterations++, this) === false) {
- break;
- }
- }
- return iterations;
- };
- zipSequence.__iteratorUncached = function(type, reverse) {
- var iterators = iters.map(function(i )
- {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
- );
- var iterations = 0;
- var isDone = false;
- return new Iterator(function() {
- var steps;
- if (!isDone) {
- steps = iterators.map(function(i ) {return i.next()});
- isDone = steps.some(function(s ) {return s.done});
- }
- if (isDone) {
- return iteratorDone();
- }
- return iteratorValue(
- type,
- iterations++,
- zipper.apply(null, steps.map(function(s ) {return s.value}))
- );
- });
- };
- return zipSequence
- }
-
-
- // #pragma Helper Functions
-
- function reify(iter, seq) {
- return isSeq(iter) ? seq : iter.constructor(seq);
- }
-
- function validateEntry(entry) {
- if (entry !== Object(entry)) {
- throw new TypeError('Expected [K, V] tuple: ' + entry);
- }
- }
-
- function resolveSize(iter) {
- assertNotInfinite(iter.size);
- return ensureSize(iter);
- }
-
- function iterableClass(iterable) {
- return isKeyed(iterable) ? KeyedIterable :
- isIndexed(iterable) ? IndexedIterable :
- SetIterable;
- }
-
- function makeSequence(iterable) {
- return Object.create(
- (
- isKeyed(iterable) ? KeyedSeq :
- isIndexed(iterable) ? IndexedSeq :
- SetSeq
- ).prototype
- );
- }
-
- function cacheResultThrough() {
- if (this._iter.cacheResult) {
- this._iter.cacheResult();
- this.size = this._iter.size;
- return this;
- } else {
- return Seq.prototype.cacheResult.call(this);
- }
- }
-
- function defaultComparator(a, b) {
- return a > b ? 1 : a < b ? -1 : 0;
- }
-
- function forceIterator(keyPath) {
- var iter = getIterator(keyPath);
- if (!iter) {
- // Array might not be iterable in this environment, so we need a fallback
- // to our wrapped type.
- if (!isArrayLike(keyPath)) {
- throw new TypeError('Expected iterable or array-like: ' + keyPath);
- }
- iter = getIterator(Iterable(keyPath));
- }
- return iter;
- }
-
- createClass(Record, KeyedCollection);
-
- function Record(defaultValues, name) {
- var hasInitialized;
-
- var RecordType = function Record(values) {
- if (values instanceof RecordType) {
- return values;
- }
- if (!(this instanceof RecordType)) {
- return new RecordType(values);
- }
- if (!hasInitialized) {
- hasInitialized = true;
- var keys = Object.keys(defaultValues);
- setProps(RecordTypePrototype, keys);
- RecordTypePrototype.size = keys.length;
- RecordTypePrototype._name = name;
- RecordTypePrototype._keys = keys;
- RecordTypePrototype._defaultValues = defaultValues;
- }
- this._map = Map(values);
- };
-
- var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
- RecordTypePrototype.constructor = RecordType;
-
- return RecordType;
- }
-
- Record.prototype.toString = function() {
- return this.__toString(recordName(this) + ' {', '}');
- };
-
- // @pragma Access
-
- Record.prototype.has = function(k) {
- return this._defaultValues.hasOwnProperty(k);
- };
-
- Record.prototype.get = function(k, notSetValue) {
- if (!this.has(k)) {
- return notSetValue;
- }
- var defaultVal = this._defaultValues[k];
- return this._map ? this._map.get(k, defaultVal) : defaultVal;
- };
-
- // @pragma Modification
-
- Record.prototype.clear = function() {
- if (this.__ownerID) {
- this._map && this._map.clear();
- return this;
- }
- var RecordType = this.constructor;
- return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap()));
- };
-
- Record.prototype.set = function(k, v) {
- if (!this.has(k)) {
- throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
- }
- var newMap = this._map && this._map.set(k, v);
- if (this.__ownerID || newMap === this._map) {
- return this;
- }
- return makeRecord(this, newMap);
- };
-
- Record.prototype.remove = function(k) {
- if (!this.has(k)) {
- return this;
- }
- var newMap = this._map && this._map.remove(k);
- if (this.__ownerID || newMap === this._map) {
- return this;
- }
- return makeRecord(this, newMap);
- };
-
- Record.prototype.wasAltered = function() {
- return this._map.wasAltered();
- };
-
- Record.prototype.__iterator = function(type, reverse) {var this$0 = this;
- return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse);
- };
-
- Record.prototype.__iterate = function(fn, reverse) {var this$0 = this;
- return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse);
- };
-
- Record.prototype.__ensureOwner = function(ownerID) {
- if (ownerID === this.__ownerID) {
- return this;
- }
- var newMap = this._map && this._map.__ensureOwner(ownerID);
- if (!ownerID) {
- this.__ownerID = ownerID;
- this._map = newMap;
- return this;
- }
- return makeRecord(this, newMap, ownerID);
- };
-
-
- var RecordPrototype = Record.prototype;
- RecordPrototype[DELETE] = RecordPrototype.remove;
- RecordPrototype.deleteIn =
- RecordPrototype.removeIn = MapPrototype.removeIn;
- RecordPrototype.merge = MapPrototype.merge;
- RecordPrototype.mergeWith = MapPrototype.mergeWith;
- RecordPrototype.mergeIn = MapPrototype.mergeIn;
- RecordPrototype.mergeDeep = MapPrototype.mergeDeep;
- RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith;
- RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
- RecordPrototype.setIn = MapPrototype.setIn;
- RecordPrototype.update = MapPrototype.update;
- RecordPrototype.updateIn = MapPrototype.updateIn;
- RecordPrototype.withMutations = MapPrototype.withMutations;
- RecordPrototype.asMutable = MapPrototype.asMutable;
- RecordPrototype.asImmutable = MapPrototype.asImmutable;
-
-
- function makeRecord(likeRecord, map, ownerID) {
- var record = Object.create(Object.getPrototypeOf(likeRecord));
- record._map = map;
- record.__ownerID = ownerID;
- return record;
- }
-
- function recordName(record) {
- return record._name || record.constructor.name || 'Record';
- }
-
- function setProps(prototype, names) {
- try {
- names.forEach(setProp.bind(undefined, prototype));
- } catch (error) {
- // Object.defineProperty failed. Probably IE8.
- }
- }
-
- function setProp(prototype, name) {
- Object.defineProperty(prototype, name, {
- get: function() {
- return this.get(name);
- },
- set: function(value) {
- invariant(this.__ownerID, 'Cannot set on an immutable record.');
- this.set(name, value);
- }
- });
- }
-
- createClass(Set, SetCollection);
-
- // @pragma Construction
-
- function Set(value) {
- return value === null || value === undefined ? emptySet() :
- isSet(value) && !isOrdered(value) ? value :
- emptySet().withMutations(function(set ) {
- var iter = SetIterable(value);
- assertNotInfinite(iter.size);
- iter.forEach(function(v ) {return set.add(v)});
- });
- }
-
- Set.of = function(/*...values*/) {
- return this(arguments);
- };
-
- Set.fromKeys = function(value) {
- return this(KeyedIterable(value).keySeq());
- };
-
- Set.prototype.toString = function() {
- return this.__toString('Set {', '}');
- };
-
- // @pragma Access
-
- Set.prototype.has = function(value) {
- return this._map.has(value);
- };
-
- // @pragma Modification
-
- Set.prototype.add = function(value) {
- return updateSet(this, this._map.set(value, true));
- };
-
- Set.prototype.remove = function(value) {
- return updateSet(this, this._map.remove(value));
- };
-
- Set.prototype.clear = function() {
- return updateSet(this, this._map.clear());
- };
-
- // @pragma Composition
-
- Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
- iters = iters.filter(function(x ) {return x.size !== 0});
- if (iters.length === 0) {
- return this;
- }
- if (this.size === 0 && !this.__ownerID && iters.length === 1) {
- return this.constructor(iters[0]);
- }
- return this.withMutations(function(set ) {
- for (var ii = 0; ii < iters.length; ii++) {
- SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)});
- }
- });
- };
-
- Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
- if (iters.length === 0) {
- return this;
- }
- iters = iters.map(function(iter ) {return SetIterable(iter)});
- var originalSet = this;
- return this.withMutations(function(set ) {
- originalSet.forEach(function(value ) {
- if (!iters.every(function(iter ) {return iter.includes(value)})) {
- set.remove(value);
- }
- });
- });
- };
-
- Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
- if (iters.length === 0) {
- return this;
- }
- iters = iters.map(function(iter ) {return SetIterable(iter)});
- var originalSet = this;
- return this.withMutations(function(set ) {
- originalSet.forEach(function(value ) {
- if (iters.some(function(iter ) {return iter.includes(value)})) {
- set.remove(value);
- }
- });
- });
- };
-
- Set.prototype.merge = function() {
- return this.union.apply(this, arguments);
- };
-
- Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
- return this.union.apply(this, iters);
- };
-
- Set.prototype.sort = function(comparator) {
- // Late binding
- return OrderedSet(sortFactory(this, comparator));
- };
-
- Set.prototype.sortBy = function(mapper, comparator) {
- // Late binding
- return OrderedSet(sortFactory(this, comparator, mapper));
- };
-
- Set.prototype.wasAltered = function() {
- return this._map.wasAltered();
- };
-
- Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
- return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
- };
-
- Set.prototype.__iterator = function(type, reverse) {
- return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
- };
-
- Set.prototype.__ensureOwner = function(ownerID) {
- if (ownerID === this.__ownerID) {
- return this;
- }
- var newMap = this._map.__ensureOwner(ownerID);
- if (!ownerID) {
- this.__ownerID = ownerID;
- this._map = newMap;
- return this;
- }
- return this.__make(newMap, ownerID);
- };
-
-
- function isSet(maybeSet) {
- return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
- }
-
- Set.isSet = isSet;
-
- var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
-
- var SetPrototype = Set.prototype;
- SetPrototype[IS_SET_SENTINEL] = true;
- SetPrototype[DELETE] = SetPrototype.remove;
- SetPrototype.mergeDeep = SetPrototype.merge;
- SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
- SetPrototype.withMutations = MapPrototype.withMutations;
- SetPrototype.asMutable = MapPrototype.asMutable;
- SetPrototype.asImmutable = MapPrototype.asImmutable;
-
- SetPrototype.__empty = emptySet;
- SetPrototype.__make = makeSet;
-
- function updateSet(set, newMap) {
- if (set.__ownerID) {
- set.size = newMap.size;
- set._map = newMap;
- return set;
- }
- return newMap === set._map ? set :
- newMap.size === 0 ? set.__empty() :
- set.__make(newMap);
- }
-
- function makeSet(map, ownerID) {
- var set = Object.create(SetPrototype);
- set.size = map ? map.size : 0;
- set._map = map;
- set.__ownerID = ownerID;
- return set;
- }
-
- var EMPTY_SET;
- function emptySet() {
- return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
- }
-
- createClass(OrderedSet, Set);
-
- // @pragma Construction
-
- function OrderedSet(value) {
- return value === null || value === undefined ? emptyOrderedSet() :
- isOrderedSet(value) ? value :
- emptyOrderedSet().withMutations(function(set ) {
- var iter = SetIterable(value);
- assertNotInfinite(iter.size);
- iter.forEach(function(v ) {return set.add(v)});
- });
- }
-
- OrderedSet.of = function(/*...values*/) {
- return this(arguments);
- };
-
- OrderedSet.fromKeys = function(value) {
- return this(KeyedIterable(value).keySeq());
- };
-
- OrderedSet.prototype.toString = function() {
- return this.__toString('OrderedSet {', '}');
- };
-
-
- function isOrderedSet(maybeOrderedSet) {
- return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
- }
-
- OrderedSet.isOrderedSet = isOrderedSet;
-
- var OrderedSetPrototype = OrderedSet.prototype;
- OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
-
- OrderedSetPrototype.__empty = emptyOrderedSet;
- OrderedSetPrototype.__make = makeOrderedSet;
-
- function makeOrderedSet(map, ownerID) {
- var set = Object.create(OrderedSetPrototype);
- set.size = map ? map.size : 0;
- set._map = map;
- set.__ownerID = ownerID;
- return set;
- }
-
- var EMPTY_ORDERED_SET;
- function emptyOrderedSet() {
- return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
- }
-
- createClass(Stack, IndexedCollection);
-
- // @pragma Construction
-
- function Stack(value) {
- return value === null || value === undefined ? emptyStack() :
- isStack(value) ? value :
- emptyStack().unshiftAll(value);
- }
-
- Stack.of = function(/*...values*/) {
- return this(arguments);
- };
-
- Stack.prototype.toString = function() {
- return this.__toString('Stack [', ']');
- };
-
- // @pragma Access
-
- Stack.prototype.get = function(index, notSetValue) {
- var head = this._head;
- index = wrapIndex(this, index);
- while (head && index--) {
- head = head.next;
- }
- return head ? head.value : notSetValue;
- };
-
- Stack.prototype.peek = function() {
- return this._head && this._head.value;
- };
-
- // @pragma Modification
-
- Stack.prototype.push = function(/*...values*/) {
- if (arguments.length === 0) {
- return this;
- }
- var newSize = this.size + arguments.length;
- var head = this._head;
- for (var ii = arguments.length - 1; ii >= 0; ii--) {
- head = {
- value: arguments[ii],
- next: head
- };
- }
- if (this.__ownerID) {
- this.size = newSize;
- this._head = head;
- this.__hash = undefined;
- this.__altered = true;
- return this;
- }
- return makeStack(newSize, head);
- };
-
- Stack.prototype.pushAll = function(iter) {
- iter = IndexedIterable(iter);
- if (iter.size === 0) {
- return this;
- }
- assertNotInfinite(iter.size);
- var newSize = this.size;
- var head = this._head;
- iter.reverse().forEach(function(value ) {
- newSize++;
- head = {
- value: value,
- next: head
- };
- });
- if (this.__ownerID) {
- this.size = newSize;
- this._head = head;
- this.__hash = undefined;
- this.__altered = true;
- return this;
- }
- return makeStack(newSize, head);
- };
-
- Stack.prototype.pop = function() {
- return this.slice(1);
- };
-
- Stack.prototype.unshift = function(/*...values*/) {
- return this.push.apply(this, arguments);
- };
-
- Stack.prototype.unshiftAll = function(iter) {
- return this.pushAll(iter);
- };
-
- Stack.prototype.shift = function() {
- return this.pop.apply(this, arguments);
- };
-
- Stack.prototype.clear = function() {
- if (this.size === 0) {
- return this;
- }
- if (this.__ownerID) {
- this.size = 0;
- this._head = undefined;
- this.__hash = undefined;
- this.__altered = true;
- return this;
- }
- return emptyStack();
- };
-
- Stack.prototype.slice = function(begin, end) {
- if (wholeSlice(begin, end, this.size)) {
- return this;
- }
- var resolvedBegin = resolveBegin(begin, this.size);
- var resolvedEnd = resolveEnd(end, this.size);
- if (resolvedEnd !== this.size) {
- // super.slice(begin, end);
- return IndexedCollection.prototype.slice.call(this, begin, end);
- }
- var newSize = this.size - resolvedBegin;
- var head = this._head;
- while (resolvedBegin--) {
- head = head.next;
- }
- if (this.__ownerID) {
- this.size = newSize;
- this._head = head;
- this.__hash = undefined;
- this.__altered = true;
- return this;
- }
- return makeStack(newSize, head);
- };
-
- // @pragma Mutability
-
- Stack.prototype.__ensureOwner = function(ownerID) {
- if (ownerID === this.__ownerID) {
- return this;
- }
- if (!ownerID) {
- this.__ownerID = ownerID;
- this.__altered = false;
- return this;
- }
- return makeStack(this.size, this._head, ownerID, this.__hash);
- };
-
- // @pragma Iteration
-
- Stack.prototype.__iterate = function(fn, reverse) {
- if (reverse) {
- return this.reverse().__iterate(fn);
- }
- var iterations = 0;
- var node = this._head;
- while (node) {
- if (fn(node.value, iterations++, this) === false) {
- break;
- }
- node = node.next;
- }
- return iterations;
- };
-
- Stack.prototype.__iterator = function(type, reverse) {
- if (reverse) {
- return this.reverse().__iterator(type);
- }
- var iterations = 0;
- var node = this._head;
- return new Iterator(function() {
- if (node) {
- var value = node.value;
- node = node.next;
- return iteratorValue(type, iterations++, value);
- }
- return iteratorDone();
- });
- };
-
-
- function isStack(maybeStack) {
- return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
- }
-
- Stack.isStack = isStack;
-
- var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
-
- var StackPrototype = Stack.prototype;
- StackPrototype[IS_STACK_SENTINEL] = true;
- StackPrototype.withMutations = MapPrototype.withMutations;
- StackPrototype.asMutable = MapPrototype.asMutable;
- StackPrototype.asImmutable = MapPrototype.asImmutable;
- StackPrototype.wasAltered = MapPrototype.wasAltered;
-
-
- function makeStack(size, head, ownerID, hash) {
- var map = Object.create(StackPrototype);
- map.size = size;
- map._head = head;
- map.__ownerID = ownerID;
- map.__hash = hash;
- map.__altered = false;
- return map;
- }
-
- var EMPTY_STACK;
- function emptyStack() {
- return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
- }
-
- /**
- * Contributes additional methods to a constructor
- */
- function mixin(ctor, methods) {
- var keyCopier = function(key ) { ctor.prototype[key] = methods[key]; };
- Object.keys(methods).forEach(keyCopier);
- Object.getOwnPropertySymbols &&
- Object.getOwnPropertySymbols(methods).forEach(keyCopier);
- return ctor;
- }
-
- Iterable.Iterator = Iterator;
-
- mixin(Iterable, {
-
- // ### Conversion to other types
-
- toArray: function() {
- assertNotInfinite(this.size);
- var array = new Array(this.size || 0);
- this.valueSeq().__iterate(function(v, i) { array[i] = v; });
- return array;
- },
-
- toIndexedSeq: function() {
- return new ToIndexedSequence(this);
- },
-
- toJS: function() {
- return this.toSeq().map(
- function(value ) {return value && typeof value.toJS === 'function' ? value.toJS() : value}
- ).__toJS();
- },
-
- toJSON: function() {
- return this.toSeq().map(
- function(value ) {return value && typeof value.toJSON === 'function' ? value.toJSON() : value}
- ).__toJS();
- },
-
- toKeyedSeq: function() {
- return new ToKeyedSequence(this, true);
- },
-
- toMap: function() {
- // Use Late Binding here to solve the circular dependency.
- return Map(this.toKeyedSeq());
- },
-
- toObject: function() {
- assertNotInfinite(this.size);
- var object = {};
- this.__iterate(function(v, k) { object[k] = v; });
- return object;
- },
-
- toOrderedMap: function() {
- // Use Late Binding here to solve the circular dependency.
- return OrderedMap(this.toKeyedSeq());
- },
-
- toOrderedSet: function() {
- // Use Late Binding here to solve the circular dependency.
- return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
- },
-
- toSet: function() {
- // Use Late Binding here to solve the circular dependency.
- return Set(isKeyed(this) ? this.valueSeq() : this);
- },
-
- toSetSeq: function() {
- return new ToSetSequence(this);
- },
-
- toSeq: function() {
- return isIndexed(this) ? this.toIndexedSeq() :
- isKeyed(this) ? this.toKeyedSeq() :
- this.toSetSeq();
- },
-
- toStack: function() {
- // Use Late Binding here to solve the circular dependency.
- return Stack(isKeyed(this) ? this.valueSeq() : this);
- },
-
- toList: function() {
- // Use Late Binding here to solve the circular dependency.
- return List(isKeyed(this) ? this.valueSeq() : this);
- },
-
-
- // ### Common JavaScript methods and properties
-
- toString: function() {
- return '[Iterable]';
- },
-
- __toString: function(head, tail) {
- if (this.size === 0) {
- return head + tail;
- }
- return head + ' ' + this.toSeq().map(this.__toStringMapper).join(', ') + ' ' + tail;
- },
-
-
- // ### ES6 Collection methods (ES6 Array and Map)
-
- concat: function() {var values = SLICE$0.call(arguments, 0);
- return reify(this, concatFactory(this, values));
- },
-
- includes: function(searchValue) {
- return this.some(function(value ) {return is(value, searchValue)});
- },
-
- entries: function() {
- return this.__iterator(ITERATE_ENTRIES);
- },
-
- every: function(predicate, context) {
- assertNotInfinite(this.size);
- var returnValue = true;
- this.__iterate(function(v, k, c) {
- if (!predicate.call(context, v, k, c)) {
- returnValue = false;
- return false;
- }
- });
- return returnValue;
- },
-
- filter: function(predicate, context) {
- return reify(this, filterFactory(this, predicate, context, true));
- },
-
- find: function(predicate, context, notSetValue) {
- var entry = this.findEntry(predicate, context);
- return entry ? entry[1] : notSetValue;
- },
-
- findEntry: function(predicate, context) {
- var found;
- this.__iterate(function(v, k, c) {
- if (predicate.call(context, v, k, c)) {
- found = [k, v];
- return false;
- }
- });
- return found;
- },
-
- findLastEntry: function(predicate, context) {
- return this.toSeq().reverse().findEntry(predicate, context);
- },
-
- forEach: function(sideEffect, context) {
- assertNotInfinite(this.size);
- return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
- },
-
- join: function(separator) {
- assertNotInfinite(this.size);
- separator = separator !== undefined ? '' + separator : ',';
- var joined = '';
- var isFirst = true;
- this.__iterate(function(v ) {
- isFirst ? (isFirst = false) : (joined += separator);
- joined += v !== null && v !== undefined ? v.toString() : '';
- });
- return joined;
- },
-
- keys: function() {
- return this.__iterator(ITERATE_KEYS);
- },
-
- map: function(mapper, context) {
- return reify(this, mapFactory(this, mapper, context));
- },
-
- reduce: function(reducer, initialReduction, context) {
- assertNotInfinite(this.size);
- var reduction;
- var useFirst;
- if (arguments.length < 2) {
- useFirst = true;
- } else {
- reduction = initialReduction;
- }
- this.__iterate(function(v, k, c) {
- if (useFirst) {
- useFirst = false;
- reduction = v;
- } else {
- reduction = reducer.call(context, reduction, v, k, c);
- }
- });
- return reduction;
- },
-
- reduceRight: function(reducer, initialReduction, context) {
- var reversed = this.toKeyedSeq().reverse();
- return reversed.reduce.apply(reversed, arguments);
- },
-
- reverse: function() {
- return reify(this, reverseFactory(this, true));
- },
-
- slice: function(begin, end) {
- return reify(this, sliceFactory(this, begin, end, true));
- },
-
- some: function(predicate, context) {
- return !this.every(not(predicate), context);
- },
-
- sort: function(comparator) {
- return reify(this, sortFactory(this, comparator));
- },
-
- values: function() {
- return this.__iterator(ITERATE_VALUES);
- },
-
-
- // ### More sequential methods
-
- butLast: function() {
- return this.slice(0, -1);
- },
-
- isEmpty: function() {
- return this.size !== undefined ? this.size === 0 : !this.some(function() {return true});
- },
-
- count: function(predicate, context) {
- return ensureSize(
- predicate ? this.toSeq().filter(predicate, context) : this
- );
- },
-
- countBy: function(grouper, context) {
- return countByFactory(this, grouper, context);
- },
-
- equals: function(other) {
- return deepEqual(this, other);
- },
-
- entrySeq: function() {
- var iterable = this;
- if (iterable._cache) {
- // We cache as an entries array, so we can just return the cache!
- return new ArraySeq(iterable._cache);
- }
- var entriesSequence = iterable.toSeq().map(entryMapper).toIndexedSeq();
- entriesSequence.fromEntrySeq = function() {return iterable.toSeq()};
- return entriesSequence;
- },
-
- filterNot: function(predicate, context) {
- return this.filter(not(predicate), context);
- },
-
- findLast: function(predicate, context, notSetValue) {
- return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
- },
-
- first: function() {
- return this.find(returnTrue);
- },
-
- flatMap: function(mapper, context) {
- return reify(this, flatMapFactory(this, mapper, context));
- },
-
- flatten: function(depth) {
- return reify(this, flattenFactory(this, depth, true));
- },
-
- fromEntrySeq: function() {
- return new FromEntriesSequence(this);
- },
-
- get: function(searchKey, notSetValue) {
- return this.find(function(_, key) {return is(key, searchKey)}, undefined, notSetValue);
- },
-
- getIn: function(searchKeyPath, notSetValue) {
- var nested = this;
- // Note: in an ES6 environment, we would prefer:
- // for (var key of searchKeyPath) {
- var iter = forceIterator(searchKeyPath);
- var step;
- while (!(step = iter.next()).done) {
- var key = step.value;
- nested = nested && nested.get ? nested.get(key, NOT_SET) : NOT_SET;
- if (nested === NOT_SET) {
- return notSetValue;
- }
- }
- return nested;
- },
-
- groupBy: function(grouper, context) {
- return groupByFactory(this, grouper, context);
- },
-
- has: function(searchKey) {
- return this.get(searchKey, NOT_SET) !== NOT_SET;
- },
-
- hasIn: function(searchKeyPath) {
- return this.getIn(searchKeyPath, NOT_SET) !== NOT_SET;
- },
-
- isSubset: function(iter) {
- iter = typeof iter.includes === 'function' ? iter : Iterable(iter);
- return this.every(function(value ) {return iter.includes(value)});
- },
-
- isSuperset: function(iter) {
- iter = typeof iter.isSubset === 'function' ? iter : Iterable(iter);
- return iter.isSubset(this);
- },
-
- keySeq: function() {
- return this.toSeq().map(keyMapper).toIndexedSeq();
- },
-
- last: function() {
- return this.toSeq().reverse().first();
- },
-
- max: function(comparator) {
- return maxFactory(this, comparator);
- },
-
- maxBy: function(mapper, comparator) {
- return maxFactory(this, comparator, mapper);
- },
-
- min: function(comparator) {
- return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator);
- },
-
- minBy: function(mapper, comparator) {
- return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator, mapper);
- },
-
- rest: function() {
- return this.slice(1);
- },
-
- skip: function(amount) {
- return this.slice(Math.max(0, amount));
- },
-
- skipLast: function(amount) {
- return reify(this, this.toSeq().reverse().skip(amount).reverse());
- },
-
- skipWhile: function(predicate, context) {
- return reify(this, skipWhileFactory(this, predicate, context, true));
- },
-
- skipUntil: function(predicate, context) {
- return this.skipWhile(not(predicate), context);
- },
-
- sortBy: function(mapper, comparator) {
- return reify(this, sortFactory(this, comparator, mapper));
- },
-
- take: function(amount) {
- return this.slice(0, Math.max(0, amount));
- },
-
- takeLast: function(amount) {
- return reify(this, this.toSeq().reverse().take(amount).reverse());
- },
-
- takeWhile: function(predicate, context) {
- return reify(this, takeWhileFactory(this, predicate, context));
- },
-
- takeUntil: function(predicate, context) {
- return this.takeWhile(not(predicate), context);
- },
-
- valueSeq: function() {
- return this.toIndexedSeq();
- },
-
-
- // ### Hashable Object
-
- hashCode: function() {
- return this.__hash || (this.__hash = hashIterable(this));
- }
-
-
- // ### Internal
-
- // abstract __iterate(fn, reverse)
-
- // abstract __iterator(type, reverse)
- });
-
- // var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
- // var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
- // var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
- // var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
-
- var IterablePrototype = Iterable.prototype;
- IterablePrototype[IS_ITERABLE_SENTINEL] = true;
- IterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.values;
- IterablePrototype.__toJS = IterablePrototype.toArray;
- IterablePrototype.__toStringMapper = quoteString;
- IterablePrototype.inspect =
- IterablePrototype.toSource = function() { return this.toString(); };
- IterablePrototype.chain = IterablePrototype.flatMap;
- IterablePrototype.contains = IterablePrototype.includes;
-
- // Temporary warning about using length
- (function () {
- try {
- Object.defineProperty(IterablePrototype, 'length', {
- get: function () {
- if (!Iterable.noLengthWarning) {
- var stack;
- try {
- throw new Error();
- } catch (error) {
- stack = error.stack;
- }
- if (stack.indexOf('_wrapObject') === -1) {
- console && console.warn && console.warn(
- 'iterable.length has been deprecated, '+
- 'use iterable.size or iterable.count(). '+
- 'This warning will become a silent error in a future version. ' +
- stack
- );
- return this.size;
- }
- }
- }
- });
- } catch (e) {}
- })();
-
-
-
- mixin(KeyedIterable, {
-
- // ### More sequential methods
-
- flip: function() {
- return reify(this, flipFactory(this));
- },
-
- findKey: function(predicate, context) {
- var entry = this.findEntry(predicate, context);
- return entry && entry[0];
- },
-
- findLastKey: function(predicate, context) {
- return this.toSeq().reverse().findKey(predicate, context);
- },
-
- keyOf: function(searchValue) {
- return this.findKey(function(value ) {return is(value, searchValue)});
- },
-
- lastKeyOf: function(searchValue) {
- return this.findLastKey(function(value ) {return is(value, searchValue)});
- },
-
- mapEntries: function(mapper, context) {var this$0 = this;
- var iterations = 0;
- return reify(this,
- this.toSeq().map(
- function(v, k) {return mapper.call(context, [k, v], iterations++, this$0)}
- ).fromEntrySeq()
- );
- },
-
- mapKeys: function(mapper, context) {var this$0 = this;
- return reify(this,
- this.toSeq().flip().map(
- function(k, v) {return mapper.call(context, k, v, this$0)}
- ).flip()
- );
- }
-
- });
-
- var KeyedIterablePrototype = KeyedIterable.prototype;
- KeyedIterablePrototype[IS_KEYED_SENTINEL] = true;
- KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries;
- KeyedIterablePrototype.__toJS = IterablePrototype.toObject;
- KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)};
-
-
-
- mixin(IndexedIterable, {
-
- // ### Conversion to other types
-
- toKeyedSeq: function() {
- return new ToKeyedSequence(this, false);
- },
-
-
- // ### ES6 Collection methods (ES6 Array and Map)
-
- filter: function(predicate, context) {
- return reify(this, filterFactory(this, predicate, context, false));
- },
-
- findIndex: function(predicate, context) {
- var entry = this.findEntry(predicate, context);
- return entry ? entry[0] : -1;
- },
-
- indexOf: function(searchValue) {
- var key = this.toKeyedSeq().keyOf(searchValue);
- return key === undefined ? -1 : key;
- },
-
- lastIndexOf: function(searchValue) {
- var key = this.toKeyedSeq().reverse().keyOf(searchValue);
- return key === undefined ? -1 : key;
-
- // var index =
- // return this.toSeq().reverse().indexOf(searchValue);
- },
-
- reverse: function() {
- return reify(this, reverseFactory(this, false));
- },
-
- slice: function(begin, end) {
- return reify(this, sliceFactory(this, begin, end, false));
- },
-
- splice: function(index, removeNum /*, ...values*/) {
- var numArgs = arguments.length;
- removeNum = Math.max(removeNum | 0, 0);
- if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
- return this;
- }
- // If index is negative, it should resolve relative to the size of the
- // collection. However size may be expensive to compute if not cached, so
- // only call count() if the number is in fact negative.
- index = resolveBegin(index, index < 0 ? this.count() : this.size);
- var spliced = this.slice(0, index);
- return reify(
- this,
- numArgs === 1 ?
- spliced :
- spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
- );
- },
-
-
- // ### More collection methods
-
- findLastIndex: function(predicate, context) {
- var key = this.toKeyedSeq().findLastKey(predicate, context);
- return key === undefined ? -1 : key;
- },
-
- first: function() {
- return this.get(0);
- },
-
- flatten: function(depth) {
- return reify(this, flattenFactory(this, depth, false));
- },
-
- get: function(index, notSetValue) {
- index = wrapIndex(this, index);
- return (index < 0 || (this.size === Infinity ||
- (this.size !== undefined && index > this.size))) ?
- notSetValue :
- this.find(function(_, key) {return key === index}, undefined, notSetValue);
- },
-
- has: function(index) {
- index = wrapIndex(this, index);
- return index >= 0 && (this.size !== undefined ?
- this.size === Infinity || index < this.size :
- this.indexOf(index) !== -1
- );
- },
-
- interpose: function(separator) {
- return reify(this, interposeFactory(this, separator));
- },
-
- interleave: function(/*...iterables*/) {
- var iterables = [this].concat(arrCopy(arguments));
- var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, iterables);
- var interleaved = zipped.flatten(true);
- if (zipped.size) {
- interleaved.size = zipped.size * iterables.length;
- }
- return reify(this, interleaved);
- },
-
- last: function() {
- return this.get(-1);
- },
-
- skipWhile: function(predicate, context) {
- return reify(this, skipWhileFactory(this, predicate, context, false));
- },
-
- zip: function(/*, ...iterables */) {
- var iterables = [this].concat(arrCopy(arguments));
- return reify(this, zipWithFactory(this, defaultZipper, iterables));
- },
-
- zipWith: function(zipper/*, ...iterables */) {
- var iterables = arrCopy(arguments);
- iterables[0] = this;
- return reify(this, zipWithFactory(this, zipper, iterables));
- }
-
- });
-
- IndexedIterable.prototype[IS_INDEXED_SENTINEL] = true;
- IndexedIterable.prototype[IS_ORDERED_SENTINEL] = true;
-
-
-
- mixin(SetIterable, {
-
- // ### ES6 Collection methods (ES6 Array and Map)
-
- get: function(value, notSetValue) {
- return this.has(value) ? value : notSetValue;
- },
-
- includes: function(value) {
- return this.has(value);
- },
-
-
- // ### More sequential methods
-
- keySeq: function() {
- return this.valueSeq();
- }
-
- });
-
- SetIterable.prototype.has = IterablePrototype.includes;
-
-
- // Mixin subclasses
-
- mixin(KeyedSeq, KeyedIterable.prototype);
- mixin(IndexedSeq, IndexedIterable.prototype);
- mixin(SetSeq, SetIterable.prototype);
-
- mixin(KeyedCollection, KeyedIterable.prototype);
- mixin(IndexedCollection, IndexedIterable.prototype);
- mixin(SetCollection, SetIterable.prototype);
-
-
- // #pragma Helper functions
-
- function keyMapper(v, k) {
- return k;
- }
-
- function entryMapper(v, k) {
- return [k, v];
- }
-
- function not(predicate) {
- return function() {
- return !predicate.apply(this, arguments);
- }
- }
-
- function neg(predicate) {
- return function() {
- return -predicate.apply(this, arguments);
- }
- }
-
- function quoteString(value) {
- return typeof value === 'string' ? JSON.stringify(value) : value;
- }
-
- function defaultZipper() {
- return arrCopy(arguments);
- }
-
- function defaultNegComparator(a, b) {
- return a < b ? 1 : a > b ? -1 : 0;
- }
-
- function hashIterable(iterable) {
- if (iterable.size === Infinity) {
- return 0;
- }
- var ordered = isOrdered(iterable);
- var keyed = isKeyed(iterable);
- var h = ordered ? 1 : 0;
- var size = iterable.__iterate(
- keyed ?
- ordered ?
- function(v, k) { h = 31 * h + hashMerge(hash(v), hash(k)) | 0; } :
- function(v, k) { h = h + hashMerge(hash(v), hash(k)) | 0; } :
- ordered ?
- function(v ) { h = 31 * h + hash(v) | 0; } :
- function(v ) { h = h + hash(v) | 0; }
- );
- return murmurHashOfSize(size, h);
- }
-
- function murmurHashOfSize(size, h) {
- h = imul(h, 0xCC9E2D51);
- h = imul(h << 15 | h >>> -15, 0x1B873593);
- h = imul(h << 13 | h >>> -13, 5);
- h = (h + 0xE6546B64 | 0) ^ size;
- h = imul(h ^ h >>> 16, 0x85EBCA6B);
- h = imul(h ^ h >>> 13, 0xC2B2AE35);
- h = smi(h ^ h >>> 16);
- return h;
- }
-
- function hashMerge(a, b) {
- return a ^ b + 0x9E3779B9 + (a << 6) + (a >> 2) | 0; // int
- }
-
- var Immutable = {
-
- Iterable: Iterable,
-
- Seq: Seq,
- Collection: Collection,
- Map: Map,
- OrderedMap: OrderedMap,
- List: List,
- Stack: Stack,
- Set: Set,
- OrderedSet: OrderedSet,
-
- Record: Record,
- Range: Range,
- Repeat: Repeat,
-
- is: is,
- fromJS: fromJS
-
- };
-
- return Immutable;
-
- }));
- });
-
- var OrderedMap = immutable.OrderedMap;
-
-
- var BlockMapBuilder = {
- createFromArray: function createFromArray(blocks) {
- return OrderedMap(blocks.map(function (block) {
- return [block.getKey(), block];
- }));
- }
- };
-
- var BlockMapBuilder_1 = BlockMapBuilder;
-
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
- 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; }
-
- 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; }
-
- var Map = immutable.Map,
- OrderedSet = immutable.OrderedSet,
- Record = immutable.Record;
-
- // Immutable.map is typed such that the value for every key in the map
- // must be the same type
-
-
- var EMPTY_SET = OrderedSet();
-
- var defaultRecord = {
- style: EMPTY_SET,
- entity: null
- };
-
- var CharacterMetadataRecord = Record(defaultRecord);
-
- var CharacterMetadata = function (_CharacterMetadataRec) {
- _inherits(CharacterMetadata, _CharacterMetadataRec);
-
- function CharacterMetadata() {
- _classCallCheck(this, CharacterMetadata);
-
- return _possibleConstructorReturn(this, _CharacterMetadataRec.apply(this, arguments));
- }
-
- CharacterMetadata.prototype.getStyle = function getStyle() {
- return this.get('style');
- };
-
- CharacterMetadata.prototype.getEntity = function getEntity() {
- return this.get('entity');
- };
-
- CharacterMetadata.prototype.hasStyle = function hasStyle(style) {
- return this.getStyle().includes(style);
- };
-
- CharacterMetadata.applyStyle = function applyStyle(record, style) {
- var withStyle = record.set('style', record.getStyle().add(style));
- return CharacterMetadata.create(withStyle);
- };
-
- CharacterMetadata.removeStyle = function removeStyle(record, style) {
- var withoutStyle = record.set('style', record.getStyle().remove(style));
- return CharacterMetadata.create(withoutStyle);
- };
-
- CharacterMetadata.applyEntity = function applyEntity(record, entityKey) {
- var withEntity = record.getEntity() === entityKey ? record : record.set('entity', entityKey);
- return CharacterMetadata.create(withEntity);
- };
-
- /**
- * Use this function instead of the `CharacterMetadata` constructor.
- * Since most content generally uses only a very small number of
- * style/entity permutations, we can reuse these objects as often as
- * possible.
- */
-
-
- CharacterMetadata.create = function create(config) {
- if (!config) {
- return EMPTY;
- }
-
- var defaultConfig = {
- style: EMPTY_SET,
- entity: null
- };
-
- // Fill in unspecified properties, if necessary.
- var configMap = Map(defaultConfig).merge(config);
-
- var existing = pool.get(configMap);
- if (existing) {
- return existing;
- }
-
- var newCharacter = new CharacterMetadata(configMap);
- pool = pool.set(configMap, newCharacter);
- return newCharacter;
- };
-
- return CharacterMetadata;
- }(CharacterMetadataRecord);
-
- var EMPTY = new CharacterMetadata();
- var pool = Map([[Map(defaultRecord), EMPTY]]);
-
- CharacterMetadata.EMPTY = EMPTY;
-
- var CharacterMetadata_1 = CharacterMetadata;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule findRangesImmutable
- * @format
- *
- */
-
- /**
- * Search through an array to find contiguous stretches of elements that
- * match a specified filter function.
- *
- * When ranges are found, execute a specified `found` function to supply
- * the values to the caller.
- */
- function findRangesImmutable(haystack, areEqualFn, filterFn, foundFn) {
- if (!haystack.size) {
- return;
- }
-
- var cursor = 0;
-
- haystack.reduce(function (value, nextValue, nextIndex) {
- if (!areEqualFn(value, nextValue)) {
- if (filterFn(value)) {
- foundFn(cursor, nextIndex);
- }
- cursor = nextIndex;
- }
- return nextValue;
- });
-
- filterFn(haystack.last()) && foundFn(cursor, haystack.count());
- }
-
- var findRangesImmutable_1 = findRangesImmutable;
-
- function _classCallCheck$1(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
- 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; }
-
- 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; }
-
-
-
-
-
-
- var List = immutable.List,
- Map$1 = immutable.Map,
- OrderedSet$1 = immutable.OrderedSet,
- Record$1 = immutable.Record,
- Repeat = immutable.Repeat;
-
-
- var EMPTY_SET$1 = OrderedSet$1();
-
- var defaultRecord$1 = {
- key: '',
- type: 'unstyled',
- text: '',
- characterList: List(),
- depth: 0,
- data: Map$1()
- };
-
- var ContentBlockRecord = Record$1(defaultRecord$1);
-
- var decorateCharacterList = function decorateCharacterList(config) {
- if (!config) {
- return config;
- }
-
- var characterList = config.characterList,
- text = config.text;
-
-
- if (text && !characterList) {
- config.characterList = List(Repeat(CharacterMetadata_1.EMPTY, text.length));
- }
-
- return config;
- };
-
- var ContentBlock = function (_ContentBlockRecord) {
- _inherits$1(ContentBlock, _ContentBlockRecord);
-
- function ContentBlock(config) {
- _classCallCheck$1(this, ContentBlock);
-
- return _possibleConstructorReturn$1(this, _ContentBlockRecord.call(this, decorateCharacterList(config)));
- }
-
- ContentBlock.prototype.getKey = function getKey() {
- return this.get('key');
- };
-
- ContentBlock.prototype.getType = function getType() {
- return this.get('type');
- };
-
- ContentBlock.prototype.getText = function getText() {
- return this.get('text');
- };
-
- ContentBlock.prototype.getCharacterList = function getCharacterList() {
- return this.get('characterList');
- };
-
- ContentBlock.prototype.getLength = function getLength() {
- return this.getText().length;
- };
-
- ContentBlock.prototype.getDepth = function getDepth() {
- return this.get('depth');
- };
-
- ContentBlock.prototype.getData = function getData() {
- return this.get('data');
- };
-
- ContentBlock.prototype.getInlineStyleAt = function getInlineStyleAt(offset) {
- var character = this.getCharacterList().get(offset);
- return character ? character.getStyle() : EMPTY_SET$1;
- };
-
- ContentBlock.prototype.getEntityAt = function getEntityAt(offset) {
- var character = this.getCharacterList().get(offset);
- return character ? character.getEntity() : null;
- };
-
- /**
- * Execute a callback for every contiguous range of styles within the block.
- */
-
-
- ContentBlock.prototype.findStyleRanges = function findStyleRanges(filterFn, callback) {
- findRangesImmutable_1(this.getCharacterList(), haveEqualStyle, filterFn, callback);
- };
-
- /**
- * Execute a callback for every contiguous range of entities within the block.
- */
-
-
- ContentBlock.prototype.findEntityRanges = function findEntityRanges(filterFn, callback) {
- findRangesImmutable_1(this.getCharacterList(), haveEqualEntity, filterFn, callback);
- };
-
- return ContentBlock;
- }(ContentBlockRecord);
-
- function haveEqualStyle(charA, charB) {
- return charA.getStyle() === charB.getStyle();
- }
-
- function haveEqualEntity(charA, charB) {
- return charA.getEntity() === charB.getEntity();
- }
-
- var ContentBlock_1 = ContentBlock;
-
- function _classCallCheck$2(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
- 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; }
-
- 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; }
-
-
-
-
-
-
- var List$1 = immutable.List,
- Map$2 = immutable.Map,
- OrderedSet$2 = immutable.OrderedSet,
- Record$2 = immutable.Record,
- Repeat$1 = immutable.Repeat;
-
-
- var EMPTY_SET$2 = OrderedSet$2();
-
- var defaultRecord$2 = {
- parent: null,
- characterList: List$1(),
- data: Map$2(),
- depth: 0,
- key: '',
- text: '',
- type: 'unstyled',
- children: List$1(),
- prevSibling: null,
- nextSibling: null
- };
-
- var haveEqualStyle$1 = function haveEqualStyle(charA, charB) {
- return charA.getStyle() === charB.getStyle();
- };
-
- var haveEqualEntity$1 = function haveEqualEntity(charA, charB) {
- return charA.getEntity() === charB.getEntity();
- };
-
- var decorateCharacterList$1 = function decorateCharacterList(config) {
- if (!config) {
- return config;
- }
-
- var characterList = config.characterList,
- text = config.text;
-
-
- if (text && !characterList) {
- config.characterList = List$1(Repeat$1(CharacterMetadata_1.EMPTY, text.length));
- }
-
- return config;
- };
-
- var ContentBlockNode = function (_Record) {
- _inherits$2(ContentBlockNode, _Record);
-
- function ContentBlockNode() {
- var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultRecord$2;
-
- _classCallCheck$2(this, ContentBlockNode);
-
- return _possibleConstructorReturn$2(this, _Record.call(this, decorateCharacterList$1(props)));
- }
-
- ContentBlockNode.prototype.getKey = function getKey() {
- return this.get('key');
- };
-
- ContentBlockNode.prototype.getType = function getType() {
- return this.get('type');
- };
-
- ContentBlockNode.prototype.getText = function getText() {
- return this.get('text');
- };
-
- ContentBlockNode.prototype.getCharacterList = function getCharacterList() {
- return this.get('characterList');
- };
-
- ContentBlockNode.prototype.getLength = function getLength() {
- return this.getText().length;
- };
-
- ContentBlockNode.prototype.getDepth = function getDepth() {
- return this.get('depth');
- };
-
- ContentBlockNode.prototype.getData = function getData() {
- return this.get('data');
- };
-
- ContentBlockNode.prototype.getInlineStyleAt = function getInlineStyleAt(offset) {
- var character = this.getCharacterList().get(offset);
- return character ? character.getStyle() : EMPTY_SET$2;
- };
-
- ContentBlockNode.prototype.getEntityAt = function getEntityAt(offset) {
- var character = this.getCharacterList().get(offset);
- return character ? character.getEntity() : null;
- };
-
- ContentBlockNode.prototype.getChildKeys = function getChildKeys() {
- return this.get('children');
- };
-
- ContentBlockNode.prototype.getParentKey = function getParentKey() {
- return this.get('parent');
- };
-
- ContentBlockNode.prototype.getPrevSiblingKey = function getPrevSiblingKey() {
- return this.get('prevSibling');
- };
-
- ContentBlockNode.prototype.getNextSiblingKey = function getNextSiblingKey() {
- return this.get('nextSibling');
- };
-
- ContentBlockNode.prototype.findStyleRanges = function findStyleRanges(filterFn, callback) {
- findRangesImmutable_1(this.getCharacterList(), haveEqualStyle$1, filterFn, callback);
- };
-
- ContentBlockNode.prototype.findEntityRanges = function findEntityRanges(filterFn, callback) {
- findRangesImmutable_1(this.getCharacterList(), haveEqualEntity$1, filterFn, callback);
- };
-
- return ContentBlockNode;
- }(Record$2(defaultRecord$2));
-
- var ContentBlockNode_1 = ContentBlockNode;
-
- /**
- * Copyright 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule DraftFeatureFlags-core
- * @format
- *
- */
-
- var DraftFeatureFlags = {
- draft_killswitch_allow_nontextnodes: false,
- draft_segmented_entities_behavior: false,
- draft_handlebeforeinput_composed_text: false,
- draft_tree_data_support: false
- };
-
- var DraftFeatureFlagsCore = DraftFeatureFlags;
-
- var DraftFeatureFlags_1 = DraftFeatureFlagsCore;
-
- var Map$3 = immutable.Map;
-
- var ContentStateInlineStyle = {
- add: function add(contentState, selectionState, inlineStyle) {
- return modifyInlineStyle(contentState, selectionState, inlineStyle, true);
- },
-
- remove: function remove(contentState, selectionState, inlineStyle) {
- return modifyInlineStyle(contentState, selectionState, inlineStyle, false);
- }
- };
-
- function modifyInlineStyle(contentState, selectionState, inlineStyle, addOrRemove) {
- var blockMap = contentState.getBlockMap();
- var startKey = selectionState.getStartKey();
- var startOffset = selectionState.getStartOffset();
- var endKey = selectionState.getEndKey();
- var endOffset = selectionState.getEndOffset();
-
- var newBlocks = blockMap.skipUntil(function (_, k) {
- return k === startKey;
- }).takeUntil(function (_, k) {
- return k === endKey;
- }).concat(Map$3([[endKey, blockMap.get(endKey)]])).map(function (block, blockKey) {
- var sliceStart;
- var sliceEnd;
-
- if (startKey === endKey) {
- sliceStart = startOffset;
- sliceEnd = endOffset;
- } else {
- sliceStart = blockKey === startKey ? startOffset : 0;
- sliceEnd = blockKey === endKey ? endOffset : block.getLength();
- }
-
- var chars = block.getCharacterList();
- var current;
- while (sliceStart < sliceEnd) {
- current = chars.get(sliceStart);
- chars = chars.set(sliceStart, addOrRemove ? CharacterMetadata_1.applyStyle(current, inlineStyle) : CharacterMetadata_1.removeStyle(current, inlineStyle));
- sliceStart++;
- }
-
- return block.set('characterList', chars);
- });
-
- return contentState.merge({
- blockMap: blockMap.merge(newBlocks),
- selectionBefore: selectionState,
- selectionAfter: selectionState
- });
- }
-
- var ContentStateInlineStyle_1 = ContentStateInlineStyle;
-
- function applyEntityToContentBlock(contentBlock, start, end, entityKey) {
- var characterList = contentBlock.getCharacterList();
- while (start < end) {
- characterList = characterList.set(start, CharacterMetadata_1.applyEntity(characterList.get(start), entityKey));
- start++;
- }
- return contentBlock.set('characterList', characterList);
- }
-
- var applyEntityToContentBlock_1 = applyEntityToContentBlock;
-
- function applyEntityToContentState(contentState, selectionState, entityKey) {
- var blockMap = contentState.getBlockMap();
- var startKey = selectionState.getStartKey();
- var startOffset = selectionState.getStartOffset();
- var endKey = selectionState.getEndKey();
- var endOffset = selectionState.getEndOffset();
-
- var newBlocks = blockMap.skipUntil(function (_, k) {
- return k === startKey;
- }).takeUntil(function (_, k) {
- return k === endKey;
- }).toOrderedMap().merge(immutable.OrderedMap([[endKey, blockMap.get(endKey)]])).map(function (block, blockKey) {
- var sliceStart = blockKey === startKey ? startOffset : 0;
- var sliceEnd = blockKey === endKey ? endOffset : block.getLength();
- return applyEntityToContentBlock_1(block, sliceStart, sliceEnd, entityKey);
- });
-
- return contentState.merge({
- blockMap: blockMap.merge(newBlocks),
- selectionBefore: selectionState,
- selectionAfter: selectionState
- });
- }
-
- var applyEntityToContentState_1 = applyEntityToContentState;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule DraftEntitySegments
- * @format
- *
- */
-
- /**
- * Identify the range to delete from a segmented entity.
- *
- * Rules:
- *
- * Example: 'John F. Kennedy'
- *
- * - Deletion from within any non-whitespace (i.e. ['John', 'F.', 'Kennedy'])
- * will return the range of that text.
- *
- * 'John F. Kennedy' -> 'John F.'
- * ^
- *
- * - Forward deletion of whitespace will remove the following section:
- *
- * 'John F. Kennedy' -> 'John Kennedy'
- * ^
- *
- * - Backward deletion of whitespace will remove the previous section:
- *
- * 'John F. Kennedy' -> 'F. Kennedy'
- * ^
- */
- var DraftEntitySegments = {
- getRemovalRange: function getRemovalRange(selectionStart, selectionEnd, text, entityStart, direction) {
- var segments = text.split(' ');
- segments = segments.map(function ( /*string*/segment, /*number*/ii) {
- if (direction === 'forward') {
- if (ii > 0) {
- return ' ' + segment;
- }
- } else if (ii < segments.length - 1) {
- return segment + ' ';
- }
- return segment;
- });
-
- var segmentStart = entityStart;
- var segmentEnd;
- var segment;
- var removalStart = null;
- var removalEnd = null;
-
- for (var jj = 0; jj < segments.length; jj++) {
- segment = segments[jj];
- segmentEnd = segmentStart + segment.length;
-
- // Our selection overlaps this segment.
- if (selectionStart < segmentEnd && segmentStart < selectionEnd) {
- if (removalStart !== null) {
- removalEnd = segmentEnd;
- } else {
- removalStart = segmentStart;
- removalEnd = segmentEnd;
- }
- } else if (removalStart !== null) {
- break;
- }
-
- segmentStart = segmentEnd;
- }
-
- var entityEnd = entityStart + text.length;
- var atStart = removalStart === entityStart;
- var atEnd = removalEnd === entityEnd;
-
- if (!atStart && atEnd || atStart && !atEnd) {
- if (direction === 'forward') {
- if (removalEnd !== entityEnd) {
- removalEnd++;
- }
- } else if (removalStart !== entityStart) {
- removalStart--;
- }
- }
-
- return {
- start: removalStart,
- end: removalEnd
- };
- }
- };
-
- var DraftEntitySegments_1 = DraftEntitySegments;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- */
-
- /**
- * Use invariant() to assert state which your program assumes to be true.
- *
- * Provide sprintf-style format (only %s is supported) and arguments
- * to provide information about what broke and what you were
- * expecting.
- *
- * The invariant message will be stripped in production, but the invariant
- * will remain to ensure logic does not differ in production.
- */
-
- var validateFormat = function validateFormat(format) {};
-
- if (process.env.NODE_ENV !== 'production') {
- validateFormat = function validateFormat(format) {
- if (format === undefined) {
- throw new Error('invariant requires an error message argument');
- }
- };
- }
-
- function invariant(condition, format, a, b, c, d, e, f) {
- validateFormat(format);
-
- if (!condition) {
- var error;
- if (format === undefined) {
- error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
- } else {
- var args = [a, b, c, d, e, f];
- var argIndex = 0;
- error = new Error(format.replace(/%s/g, function () {
- return args[argIndex++];
- }));
- error.name = 'Invariant Violation';
- }
-
- error.framesToPop = 1; // we don't care about invariant's own frame
- throw error;
- }
- }
-
- var invariant_1 = invariant;
-
- /**
- * Obtain the start and end positions of the range that has the
- * specified entity applied to it.
- *
- * Entity keys are applied only to contiguous stretches of text, so this
- * method searches for the first instance of the entity key and returns
- * the subsequent range.
- */
- function getRangesForDraftEntity(block, key) {
- var ranges = [];
- block.findEntityRanges(function (c) {
- return c.getEntity() === key;
- }, function (start, end) {
- ranges.push({ start: start, end: end });
- });
-
- !!!ranges.length ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Entity key not found in this range.') : invariant_1(false) : void 0;
-
- return ranges;
- }
-
- var getRangesForDraftEntity_1 = getRangesForDraftEntity;
-
- /**
- * Given a SelectionState and a removal direction, determine the entire range
- * that should be removed from a ContentState. This is based on any entities
- * within the target, with their `mutability` values taken into account.
- *
- * For instance, if we are attempting to remove part of an "immutable" entity
- * range, the entire entity must be removed. The returned `SelectionState`
- * will be adjusted accordingly.
- */
- function getCharacterRemovalRange(entityMap, startBlock, endBlock, selectionState, direction) {
- var start = selectionState.getStartOffset();
- var end = selectionState.getEndOffset();
- var startEntityKey = startBlock.getEntityAt(start);
- var endEntityKey = endBlock.getEntityAt(end - 1);
- if (!startEntityKey && !endEntityKey) {
- return selectionState;
- }
- var newSelectionState = selectionState;
- if (startEntityKey && startEntityKey === endEntityKey) {
- newSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, true, true);
- } else if (startEntityKey && endEntityKey) {
- var startSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, false, true);
- var endSelectionState = getEntityRemovalRange(entityMap, endBlock, newSelectionState, direction, endEntityKey, false, false);
- newSelectionState = newSelectionState.merge({
- anchorOffset: startSelectionState.getAnchorOffset(),
- focusOffset: endSelectionState.getFocusOffset(),
- isBackward: false
- });
- } else if (startEntityKey) {
- var _startSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, false, true);
- newSelectionState = newSelectionState.merge({
- anchorOffset: _startSelectionState.getStartOffset(),
- isBackward: false
- });
- } else if (endEntityKey) {
- var _endSelectionState = getEntityRemovalRange(entityMap, endBlock, newSelectionState, direction, endEntityKey, false, false);
- newSelectionState = newSelectionState.merge({
- focusOffset: _endSelectionState.getEndOffset(),
- isBackward: false
- });
- }
- return newSelectionState;
- }
-
- function getEntityRemovalRange(entityMap, block, selectionState, direction, entityKey, isEntireSelectionWithinEntity, isEntityAtStart) {
- var start = selectionState.getStartOffset();
- var end = selectionState.getEndOffset();
- var entity = entityMap.__get(entityKey);
- var mutability = entity.getMutability();
- var sideToConsider = isEntityAtStart ? start : end;
-
- // `MUTABLE` entities can just have the specified range of text removed
- // directly. No adjustments are needed.
- if (mutability === 'MUTABLE') {
- return selectionState;
- }
-
- // Find the entity range that overlaps with our removal range.
- var entityRanges = getRangesForDraftEntity_1(block, entityKey).filter(function (range) {
- return sideToConsider <= range.end && sideToConsider >= range.start;
- });
-
- !(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;
-
- var entityRange = entityRanges[0];
-
- // For `IMMUTABLE` entity types, we will remove the entire entity range.
- if (mutability === 'IMMUTABLE') {
- return selectionState.merge({
- anchorOffset: entityRange.start,
- focusOffset: entityRange.end,
- isBackward: false
- });
- }
-
- // For `SEGMENTED` entity types, determine the appropriate segment to
- // remove.
- if (!isEntireSelectionWithinEntity) {
- if (isEntityAtStart) {
- end = entityRange.end;
- } else {
- start = entityRange.start;
- }
- }
-
- var removalRange = DraftEntitySegments_1.getRemovalRange(start, end, block.getText().slice(entityRange.start, entityRange.end), entityRange.start, direction);
-
- return selectionState.merge({
- anchorOffset: removalRange.start,
- focusOffset: removalRange.end,
- isBackward: false
- });
- }
-
- var getCharacterRemovalRange_1 = getCharacterRemovalRange;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule generateRandomKey
- * @format
- *
- */
-
- var seenKeys = {};
- var MULTIPLIER = Math.pow(2, 24);
-
- function generateRandomKey() {
- var key = void 0;
- while (key === undefined || seenKeys.hasOwnProperty(key) || !isNaN(+key)) {
- key = Math.floor(Math.random() * MULTIPLIER).toString(32);
- }
- seenKeys[key] = true;
- return key;
- }
-
- var generateRandomKey_1 = generateRandomKey;
-
- var OrderedMap$1 = immutable.OrderedMap;
-
-
- var randomizeContentBlockNodeKeys = function randomizeContentBlockNodeKeys(blockMap) {
- var newKeysRef = {};
-
- // we keep track of root blocks in order to update subsequent sibling links
- var lastRootBlock = void 0;
-
- return OrderedMap$1(blockMap.withMutations(function (blockMapState) {
- blockMapState.forEach(function (block, index) {
- var oldKey = block.getKey();
- var nextKey = block.getNextSiblingKey();
- var prevKey = block.getPrevSiblingKey();
- var childrenKeys = block.getChildKeys();
- var parentKey = block.getParentKey();
-
- // new key that we will use to build linking
- var key = generateRandomKey_1();
-
- // we will add it here to re-use it later
- newKeysRef[oldKey] = key;
-
- if (nextKey) {
- var nextBlock = blockMapState.get(nextKey);
- if (nextBlock) {
- blockMapState.setIn([nextKey, 'prevSibling'], key);
- } else {
- // this can happen when generating random keys for fragments
- blockMapState.setIn([oldKey, 'nextSibling'], null);
- }
- }
-
- if (prevKey) {
- var prevBlock = blockMapState.get(prevKey);
- if (prevBlock) {
- blockMapState.setIn([prevKey, 'nextSibling'], key);
- } else {
- // this can happen when generating random keys for fragments
- blockMapState.setIn([oldKey, 'prevSibling'], null);
- }
- }
-
- if (parentKey && blockMapState.get(parentKey)) {
- var parentBlock = blockMapState.get(parentKey);
- var parentChildrenList = parentBlock.getChildKeys();
- blockMapState.setIn([parentKey, 'children'], parentChildrenList.set(parentChildrenList.indexOf(block.getKey()), key));
- } else {
- // blocks will then be treated as root block nodes
- blockMapState.setIn([oldKey, 'parent'], null);
-
- if (lastRootBlock) {
- blockMapState.setIn([lastRootBlock.getKey(), 'nextSibling'], key);
- blockMapState.setIn([oldKey, 'prevSibling'], newKeysRef[lastRootBlock.getKey()]);
- }
-
- lastRootBlock = blockMapState.get(oldKey);
- }
-
- childrenKeys.forEach(function (childKey) {
- var childBlock = blockMapState.get(childKey);
- if (childBlock) {
- blockMapState.setIn([childKey, 'parent'], key);
- } else {
- blockMapState.setIn([oldKey, 'children'], block.getChildKeys().filter(function (child) {
- return child !== childKey;
- }));
- }
- });
- });
- }).toArray().map(function (block) {
- return [newKeysRef[block.getKey()], block.set('key', newKeysRef[block.getKey()])];
- }));
- };
-
- var randomizeContentBlockKeys = function randomizeContentBlockKeys(blockMap) {
- return OrderedMap$1(blockMap.toArray().map(function (block) {
- var key = generateRandomKey_1();
- return [key, block.set('key', key)];
- }));
- };
-
- var randomizeBlockMapKeys = function randomizeBlockMapKeys(blockMap) {
- var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode_1;
-
- if (!isTreeBasedBlockMap) {
- return randomizeContentBlockKeys(blockMap);
- }
-
- return randomizeContentBlockNodeKeys(blockMap);
- };
-
- var randomizeBlockMapKeys_1 = randomizeBlockMapKeys;
-
- function removeEntitiesAtEdges(contentState, selectionState) {
- var blockMap = contentState.getBlockMap();
- var entityMap = contentState.getEntityMap();
-
- var updatedBlocks = {};
-
- var startKey = selectionState.getStartKey();
- var startOffset = selectionState.getStartOffset();
- var startBlock = blockMap.get(startKey);
- var updatedStart = removeForBlock(entityMap, startBlock, startOffset);
-
- if (updatedStart !== startBlock) {
- updatedBlocks[startKey] = updatedStart;
- }
-
- var endKey = selectionState.getEndKey();
- var endOffset = selectionState.getEndOffset();
- var endBlock = blockMap.get(endKey);
- if (startKey === endKey) {
- endBlock = updatedStart;
- }
-
- var updatedEnd = removeForBlock(entityMap, endBlock, endOffset);
-
- if (updatedEnd !== endBlock) {
- updatedBlocks[endKey] = updatedEnd;
- }
-
- if (!Object.keys(updatedBlocks).length) {
- return contentState.set('selectionAfter', selectionState);
- }
-
- return contentState.merge({
- blockMap: blockMap.merge(updatedBlocks),
- selectionAfter: selectionState
- });
- }
-
- function getRemovalRange(characters, key, offset) {
- var removalRange;
- findRangesImmutable_1(characters, function (a, b) {
- return a.getEntity() === b.getEntity();
- }, function (element) {
- return element.getEntity() === key;
- }, function (start, end) {
- if (start <= offset && end >= offset) {
- removalRange = { start: start, end: end };
- }
- });
- !(typeof removalRange === 'object') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Removal range must exist within character list.') : invariant_1(false) : void 0;
- return removalRange;
- }
-
- function removeForBlock(entityMap, block, offset) {
- var chars = block.getCharacterList();
- var charBefore = offset > 0 ? chars.get(offset - 1) : undefined;
- var charAfter = offset < chars.count() ? chars.get(offset) : undefined;
- var entityBeforeCursor = charBefore ? charBefore.getEntity() : undefined;
- var entityAfterCursor = charAfter ? charAfter.getEntity() : undefined;
-
- if (entityAfterCursor && entityAfterCursor === entityBeforeCursor) {
- var entity = entityMap.__get(entityAfterCursor);
- if (entity.getMutability() !== 'MUTABLE') {
- var _getRemovalRange = getRemovalRange(chars, entityAfterCursor, offset),
- start = _getRemovalRange.start,
- end = _getRemovalRange.end;
-
- var current;
- while (start < end) {
- current = chars.get(start);
- chars = chars.set(start, CharacterMetadata_1.applyEntity(current, null));
- start++;
- }
- return block.set('characterList', chars);
- }
- }
-
- return block;
- }
-
- var removeEntitiesAtEdges_1 = removeEntitiesAtEdges;
-
- var getContentStateFragment = function getContentStateFragment(contentState, selectionState) {
- var startKey = selectionState.getStartKey();
- var startOffset = selectionState.getStartOffset();
- var endKey = selectionState.getEndKey();
- var endOffset = selectionState.getEndOffset();
-
- // Edge entities should be stripped to ensure that we don't preserve
- // invalid partial entities when the fragment is reused. We do, however,
- // preserve entities that are entirely within the selection range.
- var contentWithoutEdgeEntities = removeEntitiesAtEdges_1(contentState, selectionState);
-
- var blockMap = contentWithoutEdgeEntities.getBlockMap();
- var blockKeys = blockMap.keySeq();
- var startIndex = blockKeys.indexOf(startKey);
- var endIndex = blockKeys.indexOf(endKey) + 1;
-
- return randomizeBlockMapKeys_1(blockMap.slice(startIndex, endIndex).map(function (block, blockKey) {
- var text = block.getText();
- var chars = block.getCharacterList();
-
- if (startKey === endKey) {
- return block.merge({
- text: text.slice(startOffset, endOffset),
- characterList: chars.slice(startOffset, endOffset)
- });
- }
-
- if (blockKey === startKey) {
- return block.merge({
- text: text.slice(startOffset),
- characterList: chars.slice(startOffset)
- });
- }
-
- if (blockKey === endKey) {
- return block.merge({
- text: text.slice(0, endOffset),
- characterList: chars.slice(0, endOffset)
- });
- }
-
- return block;
- }));
- };
-
- var getContentStateFragment_1 = getContentStateFragment;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule insertIntoList
- * @format
- *
- */
-
- /**
- * Maintain persistence for target list when appending and prepending.
- */
- function insertIntoList(targetList, toInsert, offset) {
- if (offset === targetList.count()) {
- toInsert.forEach(function (c) {
- targetList = targetList.push(c);
- });
- } else if (offset === 0) {
- toInsert.reverse().forEach(function (c) {
- targetList = targetList.unshift(c);
- });
- } else {
- var head = targetList.slice(0, offset);
- var tail = targetList.slice(offset);
- targetList = head.concat(toInsert, tail).toList();
- }
- return targetList;
- }
-
- var insertIntoList_1 = insertIntoList;
-
- var List$2 = immutable.List;
-
-
- var updateExistingBlock = function updateExistingBlock(contentState, selectionState, blockMap, fragmentBlock, targetKey, targetOffset) {
- var targetBlock = blockMap.get(targetKey);
- var text = targetBlock.getText();
- var chars = targetBlock.getCharacterList();
- var finalKey = targetKey;
- var finalOffset = targetOffset + fragmentBlock.getText().length;
-
- var newBlock = targetBlock.merge({
- text: text.slice(0, targetOffset) + fragmentBlock.getText() + text.slice(targetOffset),
- characterList: insertIntoList_1(chars, fragmentBlock.getCharacterList(), targetOffset),
- data: fragmentBlock.getData()
- });
-
- return contentState.merge({
- blockMap: blockMap.set(targetKey, newBlock),
- selectionBefore: selectionState,
- selectionAfter: selectionState.merge({
- anchorKey: finalKey,
- anchorOffset: finalOffset,
- focusKey: finalKey,
- focusOffset: finalOffset,
- isBackward: false
- })
- });
- };
-
- /**
- * Appends text/characterList from the fragment first block to
- * target block.
- */
- var updateHead = function updateHead(block, targetOffset, fragment) {
- var text = block.getText();
- var chars = block.getCharacterList();
-
- // Modify head portion of block.
- var headText = text.slice(0, targetOffset);
- var headCharacters = chars.slice(0, targetOffset);
- var appendToHead = fragment.first();
-
- return block.merge({
- text: headText + appendToHead.getText(),
- characterList: headCharacters.concat(appendToHead.getCharacterList()),
- type: headText ? block.getType() : appendToHead.getType(),
- data: appendToHead.getData()
- });
- };
-
- /**
- * Appends offset text/characterList from the target block to the last
- * fragment block.
- */
- var updateTail = function updateTail(block, targetOffset, fragment) {
- // Modify tail portion of block.
- var text = block.getText();
- var chars = block.getCharacterList();
-
- // Modify head portion of block.
- var blockSize = text.length;
- var tailText = text.slice(targetOffset, blockSize);
- var tailCharacters = chars.slice(targetOffset, blockSize);
- var prependToTail = fragment.last();
-
- return prependToTail.merge({
- text: prependToTail.getText() + tailText,
- characterList: prependToTail.getCharacterList().concat(tailCharacters),
- data: prependToTail.getData()
- });
- };
-
- var getRootBlocks = function getRootBlocks(block, blockMap) {
- var headKey = block.getKey();
- var rootBlock = block;
- var rootBlocks = [];
-
- // sometimes the fragment head block will not be part of the blockMap itself this can happen when
- // the fragment head is used to update the target block, however when this does not happen we need
- // to make sure that we include it on the rootBlocks since the first block of a fragment is always a
- // fragment root block
- if (blockMap.get(headKey)) {
- rootBlocks.push(headKey);
- }
-
- while (rootBlock && rootBlock.getNextSiblingKey()) {
- var lastSiblingKey = rootBlock.getNextSiblingKey();
-
- if (!lastSiblingKey) {
- break;
- }
-
- rootBlocks.push(lastSiblingKey);
- rootBlock = blockMap.get(lastSiblingKey);
- }
-
- return rootBlocks;
- };
-
- var updateBlockMapLinks = function updateBlockMapLinks(blockMap, originalBlockMap, targetBlock, fragmentHeadBlock) {
- return blockMap.withMutations(function (blockMapState) {
- var targetKey = targetBlock.getKey();
- var headKey = fragmentHeadBlock.getKey();
- var targetNextKey = targetBlock.getNextSiblingKey();
- var targetParentKey = targetBlock.getParentKey();
- var fragmentRootBlocks = getRootBlocks(fragmentHeadBlock, blockMap);
- var lastRootFragmentBlockKey = fragmentRootBlocks[fragmentRootBlocks.length - 1];
-
- if (blockMapState.get(headKey)) {
- // update the fragment head when it is part of the blockMap otherwise
- blockMapState.setIn([targetKey, 'nextSibling'], headKey);
- blockMapState.setIn([headKey, 'prevSibling'], targetKey);
- } else {
- // update the target block that had the fragment head contents merged into it
- blockMapState.setIn([targetKey, 'nextSibling'], fragmentHeadBlock.getNextSiblingKey());
- blockMapState.setIn([fragmentHeadBlock.getNextSiblingKey(), 'prevSibling'], targetKey);
- }
-
- // update the last root block fragment
- blockMapState.setIn([lastRootFragmentBlockKey, 'nextSibling'], targetNextKey);
-
- // update the original target next block
- if (targetNextKey) {
- blockMapState.setIn([targetNextKey, 'prevSibling'], lastRootFragmentBlockKey);
- }
-
- // update fragment parent links
- fragmentRootBlocks.forEach(function (blockKey) {
- return blockMapState.setIn([blockKey, 'parent'], targetParentKey);
- });
-
- // update targetBlock parent child links
- if (targetParentKey) {
- var targetParent = blockMap.get(targetParentKey);
- var originalTargetParentChildKeys = targetParent.getChildKeys();
-
- var targetBlockIndex = originalTargetParentChildKeys.indexOf(targetKey);
- var insertionIndex = targetBlockIndex + 1;
-
- var newChildrenKeysArray = originalTargetParentChildKeys.toArray();
-
- // insert fragment children
- newChildrenKeysArray.splice.apply(newChildrenKeysArray, [insertionIndex, 0].concat(fragmentRootBlocks));
-
- blockMapState.setIn([targetParentKey, 'children'], List$2(newChildrenKeysArray));
- }
- });
- };
-
- var insertFragment = function insertFragment(contentState, selectionState, blockMap, fragment, targetKey, targetOffset) {
- var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode_1;
- var newBlockArr = [];
- var fragmentSize = fragment.size;
- var target = blockMap.get(targetKey);
- var head = fragment.first();
- var tail = fragment.last();
- var finalOffset = tail.getLength();
- var finalKey = tail.getKey();
- var shouldNotUpdateFromFragmentBlock = isTreeBasedBlockMap && (!target.getChildKeys().isEmpty() || !head.getChildKeys().isEmpty());
-
- blockMap.forEach(function (block, blockKey) {
- if (blockKey !== targetKey) {
- newBlockArr.push(block);
- return;
- }
-
- if (shouldNotUpdateFromFragmentBlock) {
- newBlockArr.push(block);
- } else {
- newBlockArr.push(updateHead(block, targetOffset, fragment));
- }
-
- // Insert fragment blocks after the head and before the tail.
- fragment
- // when we are updating the target block with the head fragment block we skip the first fragment
- // head since its contents have already been merged with the target block otherwise we include
- // the whole fragment
- .slice(shouldNotUpdateFromFragmentBlock ? 0 : 1, fragmentSize - 1).forEach(function (fragmentBlock) {
- return newBlockArr.push(fragmentBlock);
- });
-
- // update tail
- newBlockArr.push(updateTail(block, targetOffset, fragment));
- });
-
- var updatedBlockMap = BlockMapBuilder_1.createFromArray(newBlockArr);
-
- if (isTreeBasedBlockMap) {
- updatedBlockMap = updateBlockMapLinks(updatedBlockMap, blockMap, target, head);
- }
-
- return contentState.merge({
- blockMap: updatedBlockMap,
- selectionBefore: selectionState,
- selectionAfter: selectionState.merge({
- anchorKey: finalKey,
- anchorOffset: finalOffset,
- focusKey: finalKey,
- focusOffset: finalOffset,
- isBackward: false
- })
- });
- };
-
- var insertFragmentIntoContentState = function insertFragmentIntoContentState(contentState, selectionState, fragmentBlockMap) {
- !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;
-
- var blockMap = contentState.getBlockMap();
- var fragment = randomizeBlockMapKeys_1(fragmentBlockMap);
- var targetKey = selectionState.getStartKey();
- var targetOffset = selectionState.getStartOffset();
-
- var targetBlock = blockMap.get(targetKey);
-
- if (targetBlock instanceof ContentBlockNode_1) {
- !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;
- }
-
- // When we insert a fragment with a single block we simply update the target block
- // with the contents of the inserted fragment block
- if (fragment.size === 1) {
- return updateExistingBlock(contentState, selectionState, blockMap, fragment.first(), targetKey, targetOffset);
- }
-
- return insertFragment(contentState, selectionState, blockMap, fragment, targetKey, targetOffset);
- };
-
- var insertFragmentIntoContentState_1 = insertFragmentIntoContentState;
-
- var Repeat$2 = immutable.Repeat;
-
-
- function insertTextIntoContentState(contentState, selectionState, text, characterMetadata) {
- !selectionState.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`insertText` should only be called with a collapsed range.') : invariant_1(false) : void 0;
-
- var len = text.length;
- if (!len) {
- return contentState;
- }
-
- var blockMap = contentState.getBlockMap();
- var key = selectionState.getStartKey();
- var offset = selectionState.getStartOffset();
- var block = blockMap.get(key);
- var blockText = block.getText();
-
- var newBlock = block.merge({
- text: blockText.slice(0, offset) + text + blockText.slice(offset, block.getLength()),
- characterList: insertIntoList_1(block.getCharacterList(), Repeat$2(characterMetadata, len).toList(), offset)
- });
-
- var newOffset = offset + len;
-
- return contentState.merge({
- blockMap: blockMap.set(key, newBlock),
- selectionAfter: selectionState.merge({
- anchorOffset: newOffset,
- focusOffset: newOffset
- })
- });
- }
-
- var insertTextIntoContentState_1 = insertTextIntoContentState;
-
- var Map$4 = immutable.Map;
-
-
- function modifyBlockForContentState(contentState, selectionState, operation) {
- var startKey = selectionState.getStartKey();
- var endKey = selectionState.getEndKey();
- var blockMap = contentState.getBlockMap();
- var newBlocks = blockMap.toSeq().skipUntil(function (_, k) {
- return k === startKey;
- }).takeUntil(function (_, k) {
- return k === endKey;
- }).concat(Map$4([[endKey, blockMap.get(endKey)]])).map(operation);
-
- return contentState.merge({
- blockMap: blockMap.merge(newBlocks),
- selectionBefore: selectionState,
- selectionAfter: selectionState
- });
- }
-
- var modifyBlockForContentState_1 = modifyBlockForContentState;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule getNextDelimiterBlockKey
- * @format
- *
- *
- * This is unstable and not part of the public API and should not be used by
- * production systems. This file may be update/removed without notice.
- */
-
-
-
- var getNextDelimiterBlockKey = function getNextDelimiterBlockKey(block, blockMap) {
- var isExperimentalTreeBlock = block instanceof ContentBlockNode_1;
-
- if (!isExperimentalTreeBlock) {
- return null;
- }
-
- var nextSiblingKey = block.getNextSiblingKey();
-
- if (nextSiblingKey) {
- return nextSiblingKey;
- }
-
- var parent = block.getParentKey();
-
- if (!parent) {
- return null;
- }
-
- var nextNonDescendantBlock = blockMap.get(parent);
- while (nextNonDescendantBlock && !nextNonDescendantBlock.getNextSiblingKey()) {
- var parentKey = nextNonDescendantBlock.getParentKey();
- nextNonDescendantBlock = parentKey ? blockMap.get(parentKey) : null;
- }
-
- if (!nextNonDescendantBlock) {
- return null;
- }
-
- return nextNonDescendantBlock.getNextSiblingKey();
- };
-
- var getNextDelimiterBlockKey_1 = getNextDelimiterBlockKey;
-
- var List$3 = immutable.List,
- Map$5 = immutable.Map;
-
-
- var transformBlock = function transformBlock(key, blockMap, func) {
- if (!key) {
- return;
- }
-
- var block = blockMap.get(key);
-
- if (!block) {
- return;
- }
-
- blockMap.set(key, func(block));
- };
-
- /**
- * Ancestors needs to be preserved when there are non selected
- * children to make sure we do not leave any orphans behind
- */
- var getAncestorsKeys = function getAncestorsKeys(blockKey, blockMap) {
- var parents = [];
-
- if (!blockKey) {
- return parents;
- }
-
- var blockNode = blockMap.get(blockKey);
- while (blockNode && blockNode.getParentKey()) {
- var parentKey = blockNode.getParentKey();
- if (parentKey) {
- parents.push(parentKey);
- }
- blockNode = parentKey ? blockMap.get(parentKey) : null;
- }
-
- return parents;
- };
-
- /**
- * Get all next delimiter keys until we hit a root delimiter and return
- * an array of key references
- */
- var getNextDelimitersBlockKeys = function getNextDelimitersBlockKeys(block, blockMap) {
- var nextDelimiters = [];
-
- if (!block) {
- return nextDelimiters;
- }
-
- var nextDelimiter = getNextDelimiterBlockKey_1(block, blockMap);
- while (nextDelimiter && blockMap.get(nextDelimiter)) {
- var _block = blockMap.get(nextDelimiter);
- nextDelimiters.push(nextDelimiter);
-
- // we do not need to keep checking all root node siblings, just the first occurance
- nextDelimiter = _block.getParentKey() ? getNextDelimiterBlockKey_1(_block, blockMap) : null;
- }
-
- return nextDelimiters;
- };
-
- var getNextValidSibling = function getNextValidSibling(block, blockMap, originalBlockMap) {
- if (!block) {
- return null;
- }
-
- // note that we need to make sure we refer to the original block since this
- // function is called within a withMutations
- var nextValidSiblingKey = originalBlockMap.get(block.getKey()).getNextSiblingKey();
-
- while (nextValidSiblingKey && !blockMap.get(nextValidSiblingKey)) {
- nextValidSiblingKey = originalBlockMap.get(nextValidSiblingKey).getNextSiblingKey() || null;
- }
-
- return nextValidSiblingKey;
- };
-
- var getPrevValidSibling = function getPrevValidSibling(block, blockMap, originalBlockMap) {
- if (!block) {
- return null;
- }
-
- // note that we need to make sure we refer to the original block since this
- // function is called within a withMutations
- var prevValidSiblingKey = originalBlockMap.get(block.getKey()).getPrevSiblingKey();
-
- while (prevValidSiblingKey && !blockMap.get(prevValidSiblingKey)) {
- prevValidSiblingKey = originalBlockMap.get(prevValidSiblingKey).getPrevSiblingKey() || null;
- }
-
- return prevValidSiblingKey;
- };
-
- var updateBlockMapLinks$1 = function updateBlockMapLinks(blockMap, startBlock, endBlock, originalBlockMap) {
- return blockMap.withMutations(function (blocks) {
- // update start block if its retained
- transformBlock(startBlock.getKey(), blocks, function (block) {
- return block.merge({
- nextSibling: getNextValidSibling(startBlock, blocks, originalBlockMap),
- prevSibling: getPrevValidSibling(startBlock, blocks, originalBlockMap)
- });
- });
-
- // update endblock if its retained
- transformBlock(endBlock.getKey(), blocks, function (block) {
- return block.merge({
- nextSibling: getNextValidSibling(endBlock, blocks, originalBlockMap),
- prevSibling: getPrevValidSibling(endBlock, blocks, originalBlockMap)
- });
- });
-
- // update start block parent ancestors
- getAncestorsKeys(startBlock.getKey(), originalBlockMap).forEach(function (parentKey) {
- return transformBlock(parentKey, blocks, function (block) {
- return block.merge({
- children: block.getChildKeys().filter(function (key) {
- return blocks.get(key);
- }),
- nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
- prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
- });
- });
- });
-
- // update start block next - can only happen if startBlock == endBlock
- transformBlock(startBlock.getNextSiblingKey(), blocks, function (block) {
- return block.merge({
- prevSibling: startBlock.getPrevSiblingKey()
- });
- });
-
- // update start block prev
- transformBlock(startBlock.getPrevSiblingKey(), blocks, function (block) {
- return block.merge({
- nextSibling: getNextValidSibling(startBlock, blocks, originalBlockMap)
- });
- });
-
- // update end block next
- transformBlock(endBlock.getNextSiblingKey(), blocks, function (block) {
- return block.merge({
- prevSibling: getPrevValidSibling(endBlock, blocks, originalBlockMap)
- });
- });
-
- // update end block prev
- transformBlock(endBlock.getPrevSiblingKey(), blocks, function (block) {
- return block.merge({
- nextSibling: endBlock.getNextSiblingKey()
- });
- });
-
- // update end block parent ancestors
- getAncestorsKeys(endBlock.getKey(), originalBlockMap).forEach(function (parentKey) {
- transformBlock(parentKey, blocks, function (block) {
- return block.merge({
- children: block.getChildKeys().filter(function (key) {
- return blocks.get(key);
- }),
- nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
- prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
- });
- });
- });
-
- // update next delimiters all the way to a root delimiter
- getNextDelimitersBlockKeys(endBlock, originalBlockMap).forEach(function (delimiterKey) {
- return transformBlock(delimiterKey, blocks, function (block) {
- return block.merge({
- nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
- prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
- });
- });
- });
- });
- };
-
- var removeRangeFromContentState = function removeRangeFromContentState(contentState, selectionState) {
- if (selectionState.isCollapsed()) {
- return contentState;
- }
-
- var blockMap = contentState.getBlockMap();
- var startKey = selectionState.getStartKey();
- var startOffset = selectionState.getStartOffset();
- var endKey = selectionState.getEndKey();
- var endOffset = selectionState.getEndOffset();
-
- var startBlock = blockMap.get(startKey);
- var endBlock = blockMap.get(endKey);
-
- // we assume that ContentBlockNode and ContentBlocks are not mixed together
- var isExperimentalTreeBlock = startBlock instanceof ContentBlockNode_1;
-
- // used to retain blocks that should not be deleted to avoid orphan children
- var parentAncestors = [];
-
- if (isExperimentalTreeBlock) {
- var endBlockchildrenKeys = endBlock.getChildKeys();
- var endBlockAncestors = getAncestorsKeys(endKey, blockMap);
-
- // endBlock has unselected sibblings so we can not remove its ancestors parents
- if (endBlock.getNextSiblingKey()) {
- parentAncestors = parentAncestors.concat(endBlockAncestors);
- }
-
- // endBlock has children so can not remove this block or any of its ancestors
- if (!endBlockchildrenKeys.isEmpty()) {
- parentAncestors = parentAncestors.concat(endBlockAncestors.concat([endKey]));
- }
-
- // we need to retain all ancestors of the next delimiter block
- parentAncestors = parentAncestors.concat(getAncestorsKeys(getNextDelimiterBlockKey_1(endBlock, blockMap), blockMap));
- }
-
- var characterList = void 0;
-
- if (startBlock === endBlock) {
- characterList = removeFromList(startBlock.getCharacterList(), startOffset, endOffset);
- } else {
- characterList = startBlock.getCharacterList().slice(0, startOffset).concat(endBlock.getCharacterList().slice(endOffset));
- }
-
- var modifiedStart = startBlock.merge({
- text: startBlock.getText().slice(0, startOffset) + endBlock.getText().slice(endOffset),
- characterList: characterList
- });
-
- var newBlocks = blockMap.toSeq().skipUntil(function (_, k) {
- return k === startKey;
- }).takeUntil(function (_, k) {
- return k === endKey;
- }).filter(function (_, k) {
- return parentAncestors.indexOf(k) === -1;
- }).concat(Map$5([[endKey, null]])).map(function (_, k) {
- return k === startKey ? modifiedStart : null;
- });
-
- var updatedBlockMap = blockMap.merge(newBlocks).filter(function (block) {
- return !!block;
- });
-
- if (isExperimentalTreeBlock) {
- updatedBlockMap = updateBlockMapLinks$1(updatedBlockMap, startBlock, endBlock, blockMap);
- }
-
- return contentState.merge({
- blockMap: updatedBlockMap,
- selectionBefore: selectionState,
- selectionAfter: selectionState.merge({
- anchorKey: startKey,
- anchorOffset: startOffset,
- focusKey: startKey,
- focusOffset: startOffset,
- isBackward: false
- })
- });
- };
-
- /**
- * Maintain persistence for target list when removing characters on the
- * head and tail of the character list.
- */
- var removeFromList = function removeFromList(targetList, startOffset, endOffset) {
- if (startOffset === 0) {
- while (startOffset < endOffset) {
- targetList = targetList.shift();
- startOffset++;
- }
- } else if (endOffset === targetList.count()) {
- while (endOffset > startOffset) {
- targetList = targetList.pop();
- endOffset--;
- }
- } else {
- var head = targetList.slice(0, startOffset);
- var tail = targetList.slice(endOffset);
- targetList = head.concat(tail).toList();
- }
- return targetList;
- };
-
- var removeRangeFromContentState_1 = removeRangeFromContentState;
-
- var List$4 = immutable.List,
- Map$6 = immutable.Map;
-
-
- var transformBlock$1 = function transformBlock(key, blockMap, func) {
- if (!key) {
- return;
- }
-
- var block = blockMap.get(key);
-
- if (!block) {
- return;
- }
-
- blockMap.set(key, func(block));
- };
-
- var updateBlockMapLinks$2 = function updateBlockMapLinks(blockMap, originalBlock, belowBlock) {
- return blockMap.withMutations(function (blocks) {
- var originalBlockKey = originalBlock.getKey();
- var belowBlockKey = belowBlock.getKey();
-
- // update block parent
- transformBlock$1(originalBlock.getParentKey(), blocks, function (block) {
- var parentChildrenList = block.getChildKeys();
- var insertionIndex = parentChildrenList.indexOf(originalBlockKey) + 1;
- var newChildrenArray = parentChildrenList.toArray();
-
- newChildrenArray.splice(insertionIndex, 0, belowBlockKey);
-
- return block.merge({
- children: List$4(newChildrenArray)
- });
- });
-
- // update original next block
- transformBlock$1(originalBlock.getNextSiblingKey(), blocks, function (block) {
- return block.merge({
- prevSibling: belowBlockKey
- });
- });
-
- // update original block
- transformBlock$1(originalBlockKey, blocks, function (block) {
- return block.merge({
- nextSibling: belowBlockKey
- });
- });
-
- // update below block
- transformBlock$1(belowBlockKey, blocks, function (block) {
- return block.merge({
- prevSibling: originalBlockKey
- });
- });
- });
- };
-
- var splitBlockInContentState = function splitBlockInContentState(contentState, selectionState) {
- !selectionState.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Selection range must be collapsed.') : invariant_1(false) : void 0;
-
- var key = selectionState.getAnchorKey();
- var offset = selectionState.getAnchorOffset();
- var blockMap = contentState.getBlockMap();
- var blockToSplit = blockMap.get(key);
- var text = blockToSplit.getText();
- var chars = blockToSplit.getCharacterList();
- var keyBelow = generateRandomKey_1();
- var isExperimentalTreeBlock = blockToSplit instanceof ContentBlockNode_1;
-
- var blockAbove = blockToSplit.merge({
- text: text.slice(0, offset),
- characterList: chars.slice(0, offset)
- });
- var blockBelow = blockAbove.merge({
- key: keyBelow,
- text: text.slice(offset),
- characterList: chars.slice(offset),
- data: Map$6()
- });
-
- var blocksBefore = blockMap.toSeq().takeUntil(function (v) {
- return v === blockToSplit;
- });
- var blocksAfter = blockMap.toSeq().skipUntil(function (v) {
- return v === blockToSplit;
- }).rest();
- var newBlocks = blocksBefore.concat([[key, blockAbove], [keyBelow, blockBelow]], blocksAfter).toOrderedMap();
-
- if (isExperimentalTreeBlock) {
- !blockToSplit.getChildKeys().isEmpty() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'ContentBlockNode must not have children') : invariant_1(false) : void 0;
-
- newBlocks = updateBlockMapLinks$2(newBlocks, blockAbove, blockBelow);
- }
-
- return contentState.merge({
- blockMap: newBlocks,
- selectionBefore: selectionState,
- selectionAfter: selectionState.merge({
- anchorKey: keyBelow,
- anchorOffset: 0,
- focusKey: keyBelow,
- focusOffset: 0,
- isBackward: false
- })
- });
- };
-
- var splitBlockInContentState_1 = splitBlockInContentState;
-
- var OrderedSet$3 = immutable.OrderedSet;
-
- /**
- * `DraftModifier` provides a set of convenience methods that apply
- * modifications to a `ContentState` object based on a target `SelectionState`.
- *
- * Any change to a `ContentState` should be decomposable into a series of
- * transaction functions that apply the required changes and return output
- * `ContentState` objects.
- *
- * These functions encapsulate some of the most common transaction sequences.
- */
-
- var DraftModifier = {
- replaceText: function replaceText(contentState, rangeToReplace, text, inlineStyle, entityKey) {
- var withoutEntities = removeEntitiesAtEdges_1(contentState, rangeToReplace);
- var withoutText = removeRangeFromContentState_1(withoutEntities, rangeToReplace);
-
- var character = CharacterMetadata_1.create({
- style: inlineStyle || OrderedSet$3(),
- entity: entityKey || null
- });
-
- return insertTextIntoContentState_1(withoutText, withoutText.getSelectionAfter(), text, character);
- },
-
- insertText: function insertText(contentState, targetRange, text, inlineStyle, entityKey) {
- !targetRange.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Target range must be collapsed for `insertText`.') : invariant_1(false) : void 0;
- return DraftModifier.replaceText(contentState, targetRange, text, inlineStyle, entityKey);
- },
-
- moveText: function moveText(contentState, removalRange, targetRange) {
- var movedFragment = getContentStateFragment_1(contentState, removalRange);
-
- var afterRemoval = DraftModifier.removeRange(contentState, removalRange, 'backward');
-
- return DraftModifier.replaceWithFragment(afterRemoval, targetRange, movedFragment);
- },
-
- replaceWithFragment: function replaceWithFragment(contentState, targetRange, fragment) {
- var withoutEntities = removeEntitiesAtEdges_1(contentState, targetRange);
- var withoutText = removeRangeFromContentState_1(withoutEntities, targetRange);
-
- return insertFragmentIntoContentState_1(withoutText, withoutText.getSelectionAfter(), fragment);
- },
-
- removeRange: function removeRange(contentState, rangeToRemove, removalDirection) {
- var startKey = void 0,
- endKey = void 0,
- startBlock = void 0,
- endBlock = void 0;
- if (rangeToRemove.getIsBackward()) {
- rangeToRemove = rangeToRemove.merge({
- anchorKey: rangeToRemove.getFocusKey(),
- anchorOffset: rangeToRemove.getFocusOffset(),
- focusKey: rangeToRemove.getAnchorKey(),
- focusOffset: rangeToRemove.getAnchorOffset(),
- isBackward: false
- });
- }
- startKey = rangeToRemove.getAnchorKey();
- endKey = rangeToRemove.getFocusKey();
- startBlock = contentState.getBlockForKey(startKey);
- endBlock = contentState.getBlockForKey(endKey);
- var startOffset = rangeToRemove.getStartOffset();
- var endOffset = rangeToRemove.getEndOffset();
-
- var startEntityKey = startBlock.getEntityAt(startOffset);
- var endEntityKey = endBlock.getEntityAt(endOffset - 1);
-
- // Check whether the selection state overlaps with a single entity.
- // If so, try to remove the appropriate substring of the entity text.
- if (startKey === endKey) {
- if (startEntityKey && startEntityKey === endEntityKey) {
- var _adjustedRemovalRange = getCharacterRemovalRange_1(contentState.getEntityMap(), startBlock, endBlock, rangeToRemove, removalDirection);
- return removeRangeFromContentState_1(contentState, _adjustedRemovalRange);
- }
- }
- var adjustedRemovalRange = rangeToRemove;
-
- var withoutEntities = removeEntitiesAtEdges_1(contentState, adjustedRemovalRange);
- return removeRangeFromContentState_1(withoutEntities, adjustedRemovalRange);
- },
-
- splitBlock: function splitBlock(contentState, selectionState) {
- var withoutEntities = removeEntitiesAtEdges_1(contentState, selectionState);
- var withoutText = removeRangeFromContentState_1(withoutEntities, selectionState);
-
- return splitBlockInContentState_1(withoutText, withoutText.getSelectionAfter());
- },
-
- applyInlineStyle: function applyInlineStyle(contentState, selectionState, inlineStyle) {
- return ContentStateInlineStyle_1.add(contentState, selectionState, inlineStyle);
- },
-
- removeInlineStyle: function removeInlineStyle(contentState, selectionState, inlineStyle) {
- return ContentStateInlineStyle_1.remove(contentState, selectionState, inlineStyle);
- },
-
- setBlockType: function setBlockType(contentState, selectionState, blockType) {
- return modifyBlockForContentState_1(contentState, selectionState, function (block) {
- return block.merge({ type: blockType, depth: 0 });
- });
- },
-
- setBlockData: function setBlockData(contentState, selectionState, blockData) {
- return modifyBlockForContentState_1(contentState, selectionState, function (block) {
- return block.merge({ data: blockData });
- });
- },
-
- mergeBlockData: function mergeBlockData(contentState, selectionState, blockData) {
- return modifyBlockForContentState_1(contentState, selectionState, function (block) {
- return block.merge({ data: block.getData().merge(blockData) });
- });
- },
-
- applyEntity: function applyEntity(contentState, selectionState, entityKey) {
- var withoutEntities = removeEntitiesAtEdges_1(contentState, selectionState);
- return applyEntityToContentState_1(withoutEntities, selectionState, entityKey);
- }
- };
-
- var DraftModifier_1 = DraftModifier;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- *
- */
-
- function makeEmptyFunction(arg) {
- return function () {
- return arg;
- };
- }
-
- /**
- * This function accepts and discards inputs; it has no side effects. This is
- * primarily useful idiomatically for overridable function endpoints which
- * always need to be callable, since JS lacks a null-call idiom ala Cocoa.
- */
- var emptyFunction = function emptyFunction() {};
-
- emptyFunction.thatReturns = makeEmptyFunction;
- emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
- emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
- emptyFunction.thatReturnsNull = makeEmptyFunction(null);
- emptyFunction.thatReturnsThis = function () {
- return this;
- };
- emptyFunction.thatReturnsArgument = function (arg) {
- return arg;
- };
-
- var emptyFunction_1 = emptyFunction;
-
- var List$5 = immutable.List,
- Repeat$3 = immutable.Repeat,
- Record$3 = immutable.Record;
-
-
- var returnTrue = emptyFunction_1.thatReturnsTrue;
-
- var FINGERPRINT_DELIMITER = '-';
-
- var defaultLeafRange = {
- start: null,
- end: null
- };
-
- var LeafRange = Record$3(defaultLeafRange);
-
- var defaultDecoratorRange = {
- start: null,
- end: null,
- decoratorKey: null,
- leaves: null
- };
-
- var DecoratorRange = Record$3(defaultDecoratorRange);
-
- var BlockTree = {
- /**
- * Generate a block tree for a given ContentBlock/decorator pair.
- */
- generate: function generate(contentState, block, decorator) {
- var textLength = block.getLength();
- if (!textLength) {
- return List$5.of(new DecoratorRange({
- start: 0,
- end: 0,
- decoratorKey: null,
- leaves: List$5.of(new LeafRange({ start: 0, end: 0 }))
- }));
- }
-
- var leafSets = [];
- var decorations = decorator ? decorator.getDecorations(block, contentState) : List$5(Repeat$3(null, textLength));
-
- var chars = block.getCharacterList();
-
- findRangesImmutable_1(decorations, areEqual, returnTrue, function (start, end) {
- leafSets.push(new DecoratorRange({
- start: start,
- end: end,
- decoratorKey: decorations.get(start),
- leaves: generateLeaves(chars.slice(start, end).toList(), start)
- }));
- });
-
- return List$5(leafSets);
- },
-
- /**
- * Create a string representation of the given tree map. This allows us
- * to rapidly determine whether a tree has undergone a significant
- * structural change.
- */
- getFingerprint: function getFingerprint(tree) {
- return tree.map(function (leafSet) {
- var decoratorKey = leafSet.get('decoratorKey');
- var fingerprintString = decoratorKey !== null ? decoratorKey + '.' + (leafSet.get('end') - leafSet.get('start')) : '';
- return '' + fingerprintString + '.' + leafSet.get('leaves').size;
- }).join(FINGERPRINT_DELIMITER);
- }
- };
-
- /**
- * Generate LeafRange records for a given character list.
- */
- function generateLeaves(characters, offset) {
- var leaves = [];
- var inlineStyles = characters.map(function (c) {
- return c.getStyle();
- }).toList();
- findRangesImmutable_1(inlineStyles, areEqual, returnTrue, function (start, end) {
- leaves.push(new LeafRange({
- start: start + offset,
- end: end + offset
- }));
- });
- return List$5(leaves);
- }
-
- function areEqual(a, b) {
- return a === b;
- }
-
- var BlockTree_1 = BlockTree;
-
- function _classCallCheck$3(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
- 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; }
-
- 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; }
-
-
-
- var Record$4 = immutable.Record;
-
-
- var DraftEntityInstanceRecord = Record$4({
- type: 'TOKEN',
- mutability: 'IMMUTABLE',
- data: Object
- });
-
- /**
- * An instance of a document entity, consisting of a `type` and relevant
- * `data`, metadata about the entity.
- *
- * For instance, a "link" entity might provide a URI, and a "mention"
- * entity might provide the mentioned user's ID. These pieces of data
- * may be used when rendering the entity as part of a ContentBlock DOM
- * representation. For a link, the data would be used as an href for
- * the rendered anchor. For a mention, the ID could be used to retrieve
- * a hovercard.
- */
-
- var DraftEntityInstance = function (_DraftEntityInstanceR) {
- _inherits$3(DraftEntityInstance, _DraftEntityInstanceR);
-
- function DraftEntityInstance() {
- _classCallCheck$3(this, DraftEntityInstance);
-
- return _possibleConstructorReturn$3(this, _DraftEntityInstanceR.apply(this, arguments));
- }
-
- DraftEntityInstance.prototype.getType = function getType() {
- return this.get('type');
- };
-
- DraftEntityInstance.prototype.getMutability = function getMutability() {
- return this.get('mutability');
- };
-
- DraftEntityInstance.prototype.getData = function getData() {
- return this.get('data');
- };
-
- return DraftEntityInstance;
- }(DraftEntityInstanceRecord);
-
- var DraftEntityInstance_1 = DraftEntityInstance;
-
- 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; };
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule DraftEntity
- * @format
- *
- */
-
-
-
-
-
-
- var Map$7 = immutable.Map;
-
-
- var instances = Map$7();
- var instanceKey = 0;
-
- /**
- * Temporary utility for generating the warnings
- */
- function logWarning(oldMethodCall, newMethodCall) {
- console.warn('WARNING: ' + oldMethodCall + ' will be deprecated soon!\nPlease use "' + newMethodCall + '" instead.');
- }
-
- /**
- * A "document entity" is an object containing metadata associated with a
- * piece of text in a ContentBlock.
- *
- * For example, a `link` entity might include a `uri` property. When a
- * ContentBlock is rendered in the browser, text that refers to that link
- * entity may be rendered as an anchor, with the `uri` as the href value.
- *
- * In a ContentBlock, every position in the text may correspond to zero
- * or one entities. This correspondence is tracked using a key string,
- * generated via DraftEntity.create() and used to obtain entity metadata
- * via DraftEntity.get().
- */
- var DraftEntity = {
- /**
- * WARNING: This method will be deprecated soon!
- * Please use 'contentState.getLastCreatedEntityKey' instead.
- * ---
- * Get the random key string from whatever entity was last created.
- * We need this to support the new API, as part of transitioning to put Entity
- * storage in contentState.
- */
- getLastCreatedEntityKey: function getLastCreatedEntityKey() {
- logWarning('DraftEntity.getLastCreatedEntityKey', 'contentState.getLastCreatedEntityKey');
- return DraftEntity.__getLastCreatedEntityKey();
- },
-
- /**
- * WARNING: This method will be deprecated soon!
- * Please use 'contentState.createEntity' instead.
- * ---
- * Create a DraftEntityInstance and store it for later retrieval.
- *
- * A random key string will be generated and returned. This key may
- * be used to track the entity's usage in a ContentBlock, and for
- * retrieving data about the entity at render time.
- */
- create: function create(type, mutability, data) {
- logWarning('DraftEntity.create', 'contentState.createEntity');
- return DraftEntity.__create(type, mutability, data);
- },
-
- /**
- * WARNING: This method will be deprecated soon!
- * Please use 'contentState.addEntity' instead.
- * ---
- * Add an existing DraftEntityInstance to the DraftEntity map. This is
- * useful when restoring instances from the server.
- */
- add: function add(instance) {
- logWarning('DraftEntity.add', 'contentState.addEntity');
- return DraftEntity.__add(instance);
- },
-
- /**
- * WARNING: This method will be deprecated soon!
- * Please use 'contentState.getEntity' instead.
- * ---
- * Retrieve the entity corresponding to the supplied key string.
- */
- get: function get(key) {
- logWarning('DraftEntity.get', 'contentState.getEntity');
- return DraftEntity.__get(key);
- },
-
- /**
- * WARNING: This method will be deprecated soon!
- * Please use 'contentState.mergeEntityData' instead.
- * ---
- * Entity instances are immutable. If you need to update the data for an
- * instance, this method will merge your data updates and return a new
- * instance.
- */
- mergeData: function mergeData(key, toMerge) {
- logWarning('DraftEntity.mergeData', 'contentState.mergeEntityData');
- return DraftEntity.__mergeData(key, toMerge);
- },
-
- /**
- * WARNING: This method will be deprecated soon!
- * Please use 'contentState.replaceEntityData' instead.
- * ---
- * Completely replace the data for a given instance.
- */
- replaceData: function replaceData(key, newData) {
- logWarning('DraftEntity.replaceData', 'contentState.replaceEntityData');
- return DraftEntity.__replaceData(key, newData);
- },
-
- // ***********************************WARNING******************************
- // --- the above public API will be deprecated in the next version of Draft!
- // The methods below this line are private - don't call them directly.
-
- /**
- * Get the random key string from whatever entity was last created.
- * We need this to support the new API, as part of transitioning to put Entity
- * storage in contentState.
- */
- __getLastCreatedEntityKey: function __getLastCreatedEntityKey() {
- return '' + instanceKey;
- },
-
- /**
- * Create a DraftEntityInstance and store it for later retrieval.
- *
- * A random key string will be generated and returned. This key may
- * be used to track the entity's usage in a ContentBlock, and for
- * retrieving data about the entity at render time.
- */
- __create: function __create(type, mutability, data) {
- return DraftEntity.__add(new DraftEntityInstance_1({ type: type, mutability: mutability, data: data || {} }));
- },
-
- /**
- * Add an existing DraftEntityInstance to the DraftEntity map. This is
- * useful when restoring instances from the server.
- */
- __add: function __add(instance) {
- var key = '' + ++instanceKey;
- instances = instances.set(key, instance);
- return key;
- },
-
- /**
- * Retrieve the entity corresponding to the supplied key string.
- */
- __get: function __get(key) {
- var instance = instances.get(key);
- !!!instance ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Unknown DraftEntity key: %s.', key) : invariant_1(false) : void 0;
- return instance;
- },
-
- /**
- * Entity instances are immutable. If you need to update the data for an
- * instance, this method will merge your data updates and return a new
- * instance.
- */
- __mergeData: function __mergeData(key, toMerge) {
- var instance = DraftEntity.__get(key);
- var newData = _extends({}, instance.getData(), toMerge);
- var newInstance = instance.set('data', newData);
- instances = instances.set(key, newInstance);
- return newInstance;
- },
-
- /**
- * Completely replace the data for a given instance.
- */
- __replaceData: function __replaceData(key, newData) {
- var instance = DraftEntity.__get(key);
- var newInstance = instance.set('data', newData);
- instances = instances.set(key, newInstance);
- return newInstance;
- }
- };
-
- var DraftEntity_1 = DraftEntity;
-
- function _classCallCheck$4(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
- 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; }
-
- 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; }
-
-
-
- var Record$5 = immutable.Record;
-
-
- var defaultRecord$3 = {
- anchorKey: '',
- anchorOffset: 0,
- focusKey: '',
- focusOffset: 0,
- isBackward: false,
- hasFocus: false
- };
-
- var SelectionStateRecord = Record$5(defaultRecord$3);
-
- var SelectionState = function (_SelectionStateRecord) {
- _inherits$4(SelectionState, _SelectionStateRecord);
-
- function SelectionState() {
- _classCallCheck$4(this, SelectionState);
-
- return _possibleConstructorReturn$4(this, _SelectionStateRecord.apply(this, arguments));
- }
-
- SelectionState.prototype.serialize = function serialize() {
- return 'Anchor: ' + this.getAnchorKey() + ':' + this.getAnchorOffset() + ', ' + 'Focus: ' + this.getFocusKey() + ':' + this.getFocusOffset() + ', ' + 'Is Backward: ' + String(this.getIsBackward()) + ', ' + 'Has Focus: ' + String(this.getHasFocus());
- };
-
- SelectionState.prototype.getAnchorKey = function getAnchorKey() {
- return this.get('anchorKey');
- };
-
- SelectionState.prototype.getAnchorOffset = function getAnchorOffset() {
- return this.get('anchorOffset');
- };
-
- SelectionState.prototype.getFocusKey = function getFocusKey() {
- return this.get('focusKey');
- };
-
- SelectionState.prototype.getFocusOffset = function getFocusOffset() {
- return this.get('focusOffset');
- };
-
- SelectionState.prototype.getIsBackward = function getIsBackward() {
- return this.get('isBackward');
- };
-
- SelectionState.prototype.getHasFocus = function getHasFocus() {
- return this.get('hasFocus');
- };
-
- /**
- * Return whether the specified range overlaps with an edge of the
- * SelectionState.
- */
-
-
- SelectionState.prototype.hasEdgeWithin = function hasEdgeWithin(blockKey, start, end) {
- var anchorKey = this.getAnchorKey();
- var focusKey = this.getFocusKey();
-
- if (anchorKey === focusKey && anchorKey === blockKey) {
- var selectionStart = this.getStartOffset();
- var selectionEnd = this.getEndOffset();
- return start <= selectionEnd && selectionStart <= end;
- }
-
- if (blockKey !== anchorKey && blockKey !== focusKey) {
- return false;
- }
-
- var offsetToCheck = blockKey === anchorKey ? this.getAnchorOffset() : this.getFocusOffset();
-
- return start <= offsetToCheck && end >= offsetToCheck;
- };
-
- SelectionState.prototype.isCollapsed = function isCollapsed() {
- return this.getAnchorKey() === this.getFocusKey() && this.getAnchorOffset() === this.getFocusOffset();
- };
-
- SelectionState.prototype.getStartKey = function getStartKey() {
- return this.getIsBackward() ? this.getFocusKey() : this.getAnchorKey();
- };
-
- SelectionState.prototype.getStartOffset = function getStartOffset() {
- return this.getIsBackward() ? this.getFocusOffset() : this.getAnchorOffset();
- };
-
- SelectionState.prototype.getEndKey = function getEndKey() {
- return this.getIsBackward() ? this.getAnchorKey() : this.getFocusKey();
- };
-
- SelectionState.prototype.getEndOffset = function getEndOffset() {
- return this.getIsBackward() ? this.getAnchorOffset() : this.getFocusOffset();
- };
-
- SelectionState.createEmpty = function createEmpty(key) {
- return new SelectionState({
- anchorKey: key,
- anchorOffset: 0,
- focusKey: key,
- focusOffset: 0,
- isBackward: false,
- hasFocus: false
- });
- };
-
- return SelectionState;
- }(SelectionStateRecord);
-
- var SelectionState_1 = SelectionState;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule sanitizeDraftText
- * @format
- *
- */
-
- var REGEX_BLOCK_DELIMITER = new RegExp('\r', 'g');
-
- function sanitizeDraftText(input) {
- return input.replace(REGEX_BLOCK_DELIMITER, '');
- }
-
- var sanitizeDraftText_1 = sanitizeDraftText;
-
- function _classCallCheck$5(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
- 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; }
-
- 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; }
-
-
-
-
-
-
-
-
-
-
-
-
-
- var List$6 = immutable.List,
- Record$6 = immutable.Record,
- Repeat$4 = immutable.Repeat;
-
- var defaultRecord$4 = {
- entityMap: null,
- blockMap: null,
- selectionBefore: null,
- selectionAfter: null
- };
-
- var ContentBlockNodeRecord = ContentBlock_1;
-
- var ContentStateRecord = Record$6(defaultRecord$4);
-
- var ContentState = function (_ContentStateRecord) {
- _inherits$5(ContentState, _ContentStateRecord);
-
- function ContentState() {
- _classCallCheck$5(this, ContentState);
-
- return _possibleConstructorReturn$5(this, _ContentStateRecord.apply(this, arguments));
- }
-
- ContentState.prototype.getEntityMap = function getEntityMap() {
- // TODO: update this when we fully remove DraftEntity
- return DraftEntity_1;
- };
-
- ContentState.prototype.getBlockMap = function getBlockMap() {
- return this.get('blockMap');
- };
-
- ContentState.prototype.getSelectionBefore = function getSelectionBefore() {
- return this.get('selectionBefore');
- };
-
- ContentState.prototype.getSelectionAfter = function getSelectionAfter() {
- return this.get('selectionAfter');
- };
-
- ContentState.prototype.getBlockForKey = function getBlockForKey(key) {
- var block = this.getBlockMap().get(key);
- return block;
- };
-
- ContentState.prototype.getKeyBefore = function getKeyBefore(key) {
- return this.getBlockMap().reverse().keySeq().skipUntil(function (v) {
- return v === key;
- }).skip(1).first();
- };
-
- ContentState.prototype.getKeyAfter = function getKeyAfter(key) {
- return this.getBlockMap().keySeq().skipUntil(function (v) {
- return v === key;
- }).skip(1).first();
- };
-
- ContentState.prototype.getBlockAfter = function getBlockAfter(key) {
- return this.getBlockMap().skipUntil(function (_, k) {
- return k === key;
- }).skip(1).first();
- };
-
- ContentState.prototype.getBlockBefore = function getBlockBefore(key) {
- return this.getBlockMap().reverse().skipUntil(function (_, k) {
- return k === key;
- }).skip(1).first();
- };
-
- ContentState.prototype.getBlocksAsArray = function getBlocksAsArray() {
- return this.getBlockMap().toArray();
- };
-
- ContentState.prototype.getFirstBlock = function getFirstBlock() {
- return this.getBlockMap().first();
- };
-
- ContentState.prototype.getLastBlock = function getLastBlock() {
- return this.getBlockMap().last();
- };
-
- ContentState.prototype.getPlainText = function getPlainText(delimiter) {
- return this.getBlockMap().map(function (block) {
- return block ? block.getText() : '';
- }).join(delimiter || '\n');
- };
-
- ContentState.prototype.getLastCreatedEntityKey = function getLastCreatedEntityKey() {
- // TODO: update this when we fully remove DraftEntity
- return DraftEntity_1.__getLastCreatedEntityKey();
- };
-
- ContentState.prototype.hasText = function hasText() {
- var blockMap = this.getBlockMap();
- return blockMap.size > 1 || blockMap.first().getLength() > 0;
- };
-
- ContentState.prototype.createEntity = function createEntity(type, mutability, data) {
- // TODO: update this when we fully remove DraftEntity
- DraftEntity_1.__create(type, mutability, data);
- return this;
- };
-
- ContentState.prototype.mergeEntityData = function mergeEntityData(key, toMerge) {
- // TODO: update this when we fully remove DraftEntity
- DraftEntity_1.__mergeData(key, toMerge);
- return this;
- };
-
- ContentState.prototype.replaceEntityData = function replaceEntityData(key, newData) {
- // TODO: update this when we fully remove DraftEntity
- DraftEntity_1.__replaceData(key, newData);
- return this;
- };
-
- ContentState.prototype.addEntity = function addEntity(instance) {
- // TODO: update this when we fully remove DraftEntity
- DraftEntity_1.__add(instance);
- return this;
- };
-
- ContentState.prototype.getEntity = function getEntity(key) {
- // TODO: update this when we fully remove DraftEntity
- return DraftEntity_1.__get(key);
- };
-
- ContentState.createFromBlockArray = function createFromBlockArray(
- // TODO: update flow type when we completely deprecate the old entity API
- blocks, entityMap) {
- // TODO: remove this when we completely deprecate the old entity API
- var theBlocks = Array.isArray(blocks) ? blocks : blocks.contentBlocks;
- var blockMap = BlockMapBuilder_1.createFromArray(theBlocks);
- var selectionState = blockMap.isEmpty() ? new SelectionState_1() : SelectionState_1.createEmpty(blockMap.first().getKey());
- return new ContentState({
- blockMap: blockMap,
- entityMap: entityMap || DraftEntity_1,
- selectionBefore: selectionState,
- selectionAfter: selectionState
- });
- };
-
- ContentState.createFromText = function createFromText(text) {
- var delimiter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : /\r\n?|\n/g;
-
- var strings = text.split(delimiter);
- var blocks = strings.map(function (block) {
- block = sanitizeDraftText_1(block);
- return new ContentBlockNodeRecord({
- key: generateRandomKey_1(),
- text: block,
- type: 'unstyled',
- characterList: List$6(Repeat$4(CharacterMetadata_1.EMPTY, block.length))
- });
- });
- return ContentState.createFromBlockArray(blocks);
- };
-
- return ContentState;
- }(ContentStateRecord);
-
- var ContentState_1 = ContentState;
-
- var NEUTRAL = 'NEUTRAL'; // No strong direction
- var LTR = 'LTR'; // Left-to-Right direction
- var RTL = 'RTL'; // Right-to-Left direction
-
- var globalDir = null;
-
- // == Helpers ==
-
- /**
- * Check if a directionality value is a Strong one
- */
- function isStrong(dir) {
- return dir === LTR || dir === RTL;
- }
-
- /**
- * Get string value to be used for `dir` HTML attribute or `direction` CSS
- * property.
- */
- function getHTMLDir(dir) {
- !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;
- return dir === LTR ? 'ltr' : 'rtl';
- }
-
- /**
- * Get string value to be used for `dir` HTML attribute or `direction` CSS
- * property, but returns null if `dir` has same value as `otherDir`.
- * `null`.
- */
- function getHTMLDirIfDifferent(dir, otherDir) {
- !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;
- !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;
- return dir === otherDir ? null : getHTMLDir(dir);
- }
-
- // == Global Direction ==
-
- /**
- * Set the global direction.
- */
- function setGlobalDir(dir) {
- globalDir = dir;
- }
-
- /**
- * Initialize the global direction
- */
- function initGlobalDir() {
- setGlobalDir(LTR);
- }
-
- /**
- * Get the global direction
- */
- function getGlobalDir() {
- if (!globalDir) {
- this.initGlobalDir();
- }
- !globalDir ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Global direction not set.') : invariant_1(false) : void 0;
- return globalDir;
- }
-
- var UnicodeBidiDirection = {
- // Values
- NEUTRAL: NEUTRAL,
- LTR: LTR,
- RTL: RTL,
- // Helpers
- isStrong: isStrong,
- getHTMLDir: getHTMLDir,
- getHTMLDirIfDifferent: getHTMLDirIfDifferent,
- // Global Direction
- setGlobalDir: setGlobalDir,
- initGlobalDir: initGlobalDir,
- getGlobalDir: getGlobalDir
- };
-
- var UnicodeBidiDirection_1 = UnicodeBidiDirection;
-
- /**
- * RegExp ranges of characters with a *Strong* Bidi_Class value.
- *
- * Data is based on DerivedBidiClass.txt in UCD version 7.0.0.
- *
- * NOTE: For performance reasons, we only support Unicode's
- * Basic Multilingual Plane (BMP) for now.
- */
- var RANGE_BY_BIDI_TYPE = {
-
- 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',
-
- 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',
-
- 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'
-
- };
-
- var REGEX_STRONG = new RegExp('[' + RANGE_BY_BIDI_TYPE.L + RANGE_BY_BIDI_TYPE.R + RANGE_BY_BIDI_TYPE.AL + ']');
-
- var REGEX_RTL = new RegExp('[' + RANGE_BY_BIDI_TYPE.R + RANGE_BY_BIDI_TYPE.AL + ']');
-
- /**
- * Returns the first strong character (has Bidi_Class value of L, R, or AL).
- *
- * @param str A text block; e.g. paragraph, table cell, tag
- * @return A character with strong bidi direction, or null if not found
- */
- function firstStrongChar(str) {
- var match = REGEX_STRONG.exec(str);
- return match == null ? null : match[0];
- }
-
- /**
- * Returns the direction of a block of text, based on the direction of its
- * first strong character (has Bidi_Class value of L, R, or AL).
- *
- * @param str A text block; e.g. paragraph, table cell, tag
- * @return The resolved direction
- */
- function firstStrongCharDir(str) {
- var strongChar = firstStrongChar(str);
- if (strongChar == null) {
- return UnicodeBidiDirection_1.NEUTRAL;
- }
- return REGEX_RTL.exec(strongChar) ? UnicodeBidiDirection_1.RTL : UnicodeBidiDirection_1.LTR;
- }
-
- /**
- * Returns the direction of a block of text, based on the direction of its
- * first strong character (has Bidi_Class value of L, R, or AL), or a fallback
- * direction, if no strong character is found.
- *
- * This function is supposed to be used in respect to Higher-Level Protocol
- * rule HL1. (http://www.unicode.org/reports/tr9/#HL1)
- *
- * @param str A text block; e.g. paragraph, table cell, tag
- * @param fallback Fallback direction, used if no strong direction detected
- * for the block (default = NEUTRAL)
- * @return The resolved direction
- */
- function resolveBlockDir(str, fallback) {
- fallback = fallback || UnicodeBidiDirection_1.NEUTRAL;
- if (!str.length) {
- return fallback;
- }
- var blockDir = firstStrongCharDir(str);
- return blockDir === UnicodeBidiDirection_1.NEUTRAL ? fallback : blockDir;
- }
-
- /**
- * Returns the direction of a block of text, based on the direction of its
- * first strong character (has Bidi_Class value of L, R, or AL), or a fallback
- * direction, if no strong character is found.
- *
- * NOTE: This function is similar to resolveBlockDir(), but uses the global
- * direction as the fallback, so it *always* returns a Strong direction,
- * making it useful for integration in places that you need to make the final
- * decision, like setting some CSS class.
- *
- * This function is supposed to be used in respect to Higher-Level Protocol
- * rule HL1. (http://www.unicode.org/reports/tr9/#HL1)
- *
- * @param str A text block; e.g. paragraph, table cell
- * @param strongFallback Fallback direction, used if no strong direction
- * detected for the block (default = global direction)
- * @return The resolved Strong direction
- */
- function getDirection(str, strongFallback) {
- if (!strongFallback) {
- strongFallback = UnicodeBidiDirection_1.getGlobalDir();
- }
- !UnicodeBidiDirection_1.isStrong(strongFallback) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Fallback direction must be a strong direction') : invariant_1(false) : void 0;
- return resolveBlockDir(str, strongFallback);
- }
-
- /**
- * Returns true if getDirection(arguments...) returns LTR.
- *
- * @param str A text block; e.g. paragraph, table cell
- * @param strongFallback Fallback direction, used if no strong direction
- * detected for the block (default = global direction)
- * @return True if the resolved direction is LTR
- */
- function isDirectionLTR(str, strongFallback) {
- return getDirection(str, strongFallback) === UnicodeBidiDirection_1.LTR;
- }
-
- /**
- * Returns true if getDirection(arguments...) returns RTL.
- *
- * @param str A text block; e.g. paragraph, table cell
- * @param strongFallback Fallback direction, used if no strong direction
- * detected for the block (default = global direction)
- * @return True if the resolved direction is RTL
- */
- function isDirectionRTL(str, strongFallback) {
- return getDirection(str, strongFallback) === UnicodeBidiDirection_1.RTL;
- }
-
- var UnicodeBidi = {
- firstStrongChar: firstStrongChar,
- firstStrongCharDir: firstStrongCharDir,
- resolveBlockDir: resolveBlockDir,
- getDirection: getDirection,
- isDirectionLTR: isDirectionLTR,
- isDirectionRTL: isDirectionRTL
- };
-
- var UnicodeBidi_1 = UnicodeBidi;
-
- function _classCallCheck$6(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
-
-
-
-
-
- var UnicodeBidiService = function () {
-
- /**
- * Stateful class for paragraph direction detection
- *
- * @param defaultDir Default direction of the service
- */
- function UnicodeBidiService(defaultDir) {
- _classCallCheck$6(this, UnicodeBidiService);
-
- if (!defaultDir) {
- defaultDir = UnicodeBidiDirection_1.getGlobalDir();
- } else {
- !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;
- }
- this._defaultDir = defaultDir;
- this.reset();
- }
-
- /**
- * Reset the internal state
- *
- * Instead of creating a new instance, you can just reset() your instance
- * everytime you start a new loop.
- */
-
-
- UnicodeBidiService.prototype.reset = function reset() {
- this._lastDir = this._defaultDir;
- };
-
- /**
- * Returns the direction of a block of text, and remembers it as the
- * fall-back direction for the next paragraph.
- *
- * @param str A text block, e.g. paragraph, table cell, tag
- * @return The resolved direction
- */
-
-
- UnicodeBidiService.prototype.getDirection = function getDirection(str) {
- this._lastDir = UnicodeBidi_1.getDirection(str, this._lastDir);
- return this._lastDir;
- };
-
- return UnicodeBidiService;
- }();
-
- var UnicodeBidiService_1 = UnicodeBidiService;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- *
- */
-
- var nullthrows = function nullthrows(x) {
- if (x != null) {
- return x;
- }
- throw new Error("Got unexpected null or undefined");
- };
-
- var nullthrows_1 = nullthrows;
-
- var OrderedMap$2 = immutable.OrderedMap;
-
-
- var bidiService;
-
- var EditorBidiService = {
- getDirectionMap: function getDirectionMap(content, prevBidiMap) {
- if (!bidiService) {
- bidiService = new UnicodeBidiService_1();
- } else {
- bidiService.reset();
- }
-
- var blockMap = content.getBlockMap();
- var nextBidi = blockMap.valueSeq().map(function (block) {
- return nullthrows_1(bidiService).getDirection(block.getText());
- });
- var bidiMap = OrderedMap$2(blockMap.keySeq().zip(nextBidi));
-
- if (prevBidiMap != null && immutable.is(prevBidiMap, bidiMap)) {
- return prevBidiMap;
- }
-
- return bidiMap;
- }
- };
-
- var EditorBidiService_1 = EditorBidiService;
-
- 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; };
-
- function _classCallCheck$7(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
-
-
-
-
-
-
- var OrderedSet$4 = immutable.OrderedSet,
- Record$7 = immutable.Record,
- Stack = immutable.Stack;
-
-
- var defaultRecord$5 = {
- allowUndo: true,
- currentContent: null,
- decorator: null,
- directionMap: null,
- forceSelection: false,
- inCompositionMode: false,
- inlineStyleOverride: null,
- lastChangeType: null,
- nativelyRenderedContent: null,
- redoStack: Stack(),
- selection: null,
- treeMap: null,
- undoStack: Stack()
- };
-
- var EditorStateRecord = Record$7(defaultRecord$5);
-
- var EditorState = function () {
- EditorState.createEmpty = function createEmpty(decorator) {
- return EditorState.createWithContent(ContentState_1.createFromText(''), decorator);
- };
-
- EditorState.createWithContent = function createWithContent(contentState, decorator) {
- var firstKey = contentState.getBlockMap().first().getKey();
- return EditorState.create({
- currentContent: contentState,
- undoStack: Stack(),
- redoStack: Stack(),
- decorator: decorator || null,
- selection: SelectionState_1.createEmpty(firstKey)
- });
- };
-
- EditorState.create = function create(config) {
- var currentContent = config.currentContent,
- decorator = config.decorator;
-
- var recordConfig = _extends$1({}, config, {
- treeMap: generateNewTreeMap(currentContent, decorator),
- directionMap: EditorBidiService_1.getDirectionMap(currentContent)
- });
- return new EditorState(new EditorStateRecord(recordConfig));
- };
-
- EditorState.set = function set(editorState, put) {
- var map = editorState.getImmutable().withMutations(function (state) {
- var existingDecorator = state.get('decorator');
- var decorator = existingDecorator;
- if (put.decorator === null) {
- decorator = null;
- } else if (put.decorator) {
- decorator = put.decorator;
- }
-
- var newContent = put.currentContent || editorState.getCurrentContent();
-
- if (decorator !== existingDecorator) {
- var treeMap = state.get('treeMap');
- var newTreeMap;
- if (decorator && existingDecorator) {
- newTreeMap = regenerateTreeForNewDecorator(newContent, newContent.getBlockMap(), treeMap, decorator, existingDecorator);
- } else {
- newTreeMap = generateNewTreeMap(newContent, decorator);
- }
-
- state.merge({
- decorator: decorator,
- treeMap: newTreeMap,
- nativelyRenderedContent: null
- });
- return;
- }
-
- var existingContent = editorState.getCurrentContent();
- if (newContent !== existingContent) {
- state.set('treeMap', regenerateTreeForNewBlocks(editorState, newContent.getBlockMap(), newContent.getEntityMap(), decorator));
- }
-
- state.merge(put);
- });
-
- return new EditorState(map);
- };
-
- EditorState.prototype.toJS = function toJS() {
- return this.getImmutable().toJS();
- };
-
- EditorState.prototype.getAllowUndo = function getAllowUndo() {
- return this.getImmutable().get('allowUndo');
- };
-
- EditorState.prototype.getCurrentContent = function getCurrentContent() {
- return this.getImmutable().get('currentContent');
- };
-
- EditorState.prototype.getUndoStack = function getUndoStack() {
- return this.getImmutable().get('undoStack');
- };
-
- EditorState.prototype.getRedoStack = function getRedoStack() {
- return this.getImmutable().get('redoStack');
- };
-
- EditorState.prototype.getSelection = function getSelection() {
- return this.getImmutable().get('selection');
- };
-
- EditorState.prototype.getDecorator = function getDecorator() {
- return this.getImmutable().get('decorator');
- };
-
- EditorState.prototype.isInCompositionMode = function isInCompositionMode() {
- return this.getImmutable().get('inCompositionMode');
- };
-
- EditorState.prototype.mustForceSelection = function mustForceSelection() {
- return this.getImmutable().get('forceSelection');
- };
-
- EditorState.prototype.getNativelyRenderedContent = function getNativelyRenderedContent() {
- return this.getImmutable().get('nativelyRenderedContent');
- };
-
- EditorState.prototype.getLastChangeType = function getLastChangeType() {
- return this.getImmutable().get('lastChangeType');
- };
-
- /**
- * While editing, the user may apply inline style commands with a collapsed
- * cursor, intending to type text that adopts the specified style. In this
- * case, we track the specified style as an "override" that takes precedence
- * over the inline style of the text adjacent to the cursor.
- *
- * If null, there is no override in place.
- */
-
-
- EditorState.prototype.getInlineStyleOverride = function getInlineStyleOverride() {
- return this.getImmutable().get('inlineStyleOverride');
- };
-
- EditorState.setInlineStyleOverride = function setInlineStyleOverride(editorState, inlineStyleOverride) {
- return EditorState.set(editorState, { inlineStyleOverride: inlineStyleOverride });
- };
-
- /**
- * Get the appropriate inline style for the editor state. If an
- * override is in place, use it. Otherwise, the current style is
- * based on the location of the selection state.
- */
-
-
- EditorState.prototype.getCurrentInlineStyle = function getCurrentInlineStyle() {
- var override = this.getInlineStyleOverride();
- if (override != null) {
- return override;
- }
-
- var content = this.getCurrentContent();
- var selection = this.getSelection();
-
- if (selection.isCollapsed()) {
- return getInlineStyleForCollapsedSelection(content, selection);
- }
-
- return getInlineStyleForNonCollapsedSelection(content, selection);
- };
-
- EditorState.prototype.getBlockTree = function getBlockTree(blockKey) {
- return this.getImmutable().getIn(['treeMap', blockKey]);
- };
-
- EditorState.prototype.isSelectionAtStartOfContent = function isSelectionAtStartOfContent() {
- var firstKey = this.getCurrentContent().getBlockMap().first().getKey();
- return this.getSelection().hasEdgeWithin(firstKey, 0, 0);
- };
-
- EditorState.prototype.isSelectionAtEndOfContent = function isSelectionAtEndOfContent() {
- var content = this.getCurrentContent();
- var blockMap = content.getBlockMap();
- var last = blockMap.last();
- var end = last.getLength();
- return this.getSelection().hasEdgeWithin(last.getKey(), end, end);
- };
-
- EditorState.prototype.getDirectionMap = function getDirectionMap() {
- return this.getImmutable().get('directionMap');
- };
-
- /**
- * Incorporate native DOM selection changes into the EditorState. This
- * method can be used when we simply want to accept whatever the DOM
- * has given us to represent selection, and we do not need to re-render
- * the editor.
- *
- * To forcibly move the DOM selection, see `EditorState.forceSelection`.
- */
-
-
- EditorState.acceptSelection = function acceptSelection(editorState, selection) {
- return updateSelection(editorState, selection, false);
- };
-
- /**
- * At times, we need to force the DOM selection to be where we
- * need it to be. This can occur when the anchor or focus nodes
- * are non-text nodes, for instance. In this case, we want to trigger
- * a re-render of the editor, which in turn forces selection into
- * the correct place in the DOM. The `forceSelection` method
- * accomplishes this.
- *
- * This method should be used in cases where you need to explicitly
- * move the DOM selection from one place to another without a change
- * in ContentState.
- */
-
-
- EditorState.forceSelection = function forceSelection(editorState, selection) {
- if (!selection.getHasFocus()) {
- selection = selection.set('hasFocus', true);
- }
- return updateSelection(editorState, selection, true);
- };
-
- /**
- * Move selection to the end of the editor without forcing focus.
- */
-
-
- EditorState.moveSelectionToEnd = function moveSelectionToEnd(editorState) {
- var content = editorState.getCurrentContent();
- var lastBlock = content.getLastBlock();
- var lastKey = lastBlock.getKey();
- var length = lastBlock.getLength();
-
- return EditorState.acceptSelection(editorState, new SelectionState_1({
- anchorKey: lastKey,
- anchorOffset: length,
- focusKey: lastKey,
- focusOffset: length,
- isBackward: false
- }));
- };
-
- /**
- * Force focus to the end of the editor. This is useful in scenarios
- * where we want to programmatically focus the input and it makes sense
- * to allow the user to continue working seamlessly.
- */
-
-
- EditorState.moveFocusToEnd = function moveFocusToEnd(editorState) {
- var afterSelectionMove = EditorState.moveSelectionToEnd(editorState);
- return EditorState.forceSelection(afterSelectionMove, afterSelectionMove.getSelection());
- };
-
- /**
- * Push the current ContentState onto the undo stack if it should be
- * considered a boundary state, and set the provided ContentState as the
- * new current content.
- */
-
-
- EditorState.push = function push(editorState, contentState, changeType) {
- if (editorState.getCurrentContent() === contentState) {
- return editorState;
- }
-
- var forceSelection = changeType !== 'insert-characters';
- var directionMap = EditorBidiService_1.getDirectionMap(contentState, editorState.getDirectionMap());
-
- if (!editorState.getAllowUndo()) {
- return EditorState.set(editorState, {
- currentContent: contentState,
- directionMap: directionMap,
- lastChangeType: changeType,
- selection: contentState.getSelectionAfter(),
- forceSelection: forceSelection,
- inlineStyleOverride: null
- });
- }
-
- var selection = editorState.getSelection();
- var currentContent = editorState.getCurrentContent();
- var undoStack = editorState.getUndoStack();
- var newContent = contentState;
-
- if (selection !== currentContent.getSelectionAfter() || mustBecomeBoundary(editorState, changeType)) {
- undoStack = undoStack.push(currentContent);
- newContent = newContent.set('selectionBefore', selection);
- } else if (changeType === 'insert-characters' || changeType === 'backspace-character' || changeType === 'delete-character') {
- // Preserve the previous selection.
- newContent = newContent.set('selectionBefore', currentContent.getSelectionBefore());
- }
-
- var inlineStyleOverride = editorState.getInlineStyleOverride();
-
- // Don't discard inline style overrides for the following change types:
- var overrideChangeTypes = ['adjust-depth', 'change-block-type', 'split-block'];
-
- if (overrideChangeTypes.indexOf(changeType) === -1) {
- inlineStyleOverride = null;
- }
-
- var editorStateChanges = {
- currentContent: newContent,
- directionMap: directionMap,
- undoStack: undoStack,
- redoStack: Stack(),
- lastChangeType: changeType,
- selection: contentState.getSelectionAfter(),
- forceSelection: forceSelection,
- inlineStyleOverride: inlineStyleOverride
- };
-
- return EditorState.set(editorState, editorStateChanges);
- };
-
- /**
- * Make the top ContentState in the undo stack the new current content and
- * push the current content onto the redo stack.
- */
-
-
- EditorState.undo = function undo(editorState) {
- if (!editorState.getAllowUndo()) {
- return editorState;
- }
-
- var undoStack = editorState.getUndoStack();
- var newCurrentContent = undoStack.peek();
- if (!newCurrentContent) {
- return editorState;
- }
-
- var currentContent = editorState.getCurrentContent();
- var directionMap = EditorBidiService_1.getDirectionMap(newCurrentContent, editorState.getDirectionMap());
-
- return EditorState.set(editorState, {
- currentContent: newCurrentContent,
- directionMap: directionMap,
- undoStack: undoStack.shift(),
- redoStack: editorState.getRedoStack().push(currentContent),
- forceSelection: true,
- inlineStyleOverride: null,
- lastChangeType: 'undo',
- nativelyRenderedContent: null,
- selection: currentContent.getSelectionBefore()
- });
- };
-
- /**
- * Make the top ContentState in the redo stack the new current content and
- * push the current content onto the undo stack.
- */
-
-
- EditorState.redo = function redo(editorState) {
- if (!editorState.getAllowUndo()) {
- return editorState;
- }
-
- var redoStack = editorState.getRedoStack();
- var newCurrentContent = redoStack.peek();
- if (!newCurrentContent) {
- return editorState;
- }
-
- var currentContent = editorState.getCurrentContent();
- var directionMap = EditorBidiService_1.getDirectionMap(newCurrentContent, editorState.getDirectionMap());
-
- return EditorState.set(editorState, {
- currentContent: newCurrentContent,
- directionMap: directionMap,
- undoStack: editorState.getUndoStack().push(currentContent),
- redoStack: redoStack.shift(),
- forceSelection: true,
- inlineStyleOverride: null,
- lastChangeType: 'redo',
- nativelyRenderedContent: null,
- selection: newCurrentContent.getSelectionAfter()
- });
- };
-
- /**
- * Not for public consumption.
- */
-
-
- function EditorState(immutable) {
- _classCallCheck$7(this, EditorState);
-
- this._immutable = immutable;
- }
-
- /**
- * Not for public consumption.
- */
-
-
- EditorState.prototype.getImmutable = function getImmutable() {
- return this._immutable;
- };
-
- return EditorState;
- }();
-
- /**
- * Set the supplied SelectionState as the new current selection, and set
- * the `force` flag to trigger manual selection placement by the view.
- */
-
-
- function updateSelection(editorState, selection, forceSelection) {
- return EditorState.set(editorState, {
- selection: selection,
- forceSelection: forceSelection,
- nativelyRenderedContent: null,
- inlineStyleOverride: null
- });
- }
-
- /**
- * Regenerate the entire tree map for a given ContentState and decorator.
- * Returns an OrderedMap that maps all available ContentBlock objects.
- */
- function generateNewTreeMap(contentState, decorator) {
- return contentState.getBlockMap().map(function (block) {
- return BlockTree_1.generate(contentState, block, decorator);
- }).toOrderedMap();
- }
-
- /**
- * Regenerate tree map objects for all ContentBlocks that have changed
- * between the current editorState and newContent. Returns an OrderedMap
- * with only changed regenerated tree map objects.
- */
- function regenerateTreeForNewBlocks(editorState, newBlockMap, newEntityMap, decorator) {
- var contentState = editorState.getCurrentContent().set('entityMap', newEntityMap);
- var prevBlockMap = contentState.getBlockMap();
- var prevTreeMap = editorState.getImmutable().get('treeMap');
- return prevTreeMap.merge(newBlockMap.toSeq().filter(function (block, key) {
- return block !== prevBlockMap.get(key);
- }).map(function (block) {
- return BlockTree_1.generate(contentState, block, decorator);
- }));
- }
-
- /**
- * Generate tree map objects for a new decorator object, preserving any
- * decorations that are unchanged from the previous decorator.
- *
- * Note that in order for this to perform optimally, decoration Lists for
- * decorators should be preserved when possible to allow for direct immutable
- * List comparison.
- */
- function regenerateTreeForNewDecorator(content, blockMap, previousTreeMap, decorator, existingDecorator) {
- return previousTreeMap.merge(blockMap.toSeq().filter(function (block) {
- return decorator.getDecorations(block, content) !== existingDecorator.getDecorations(block, content);
- }).map(function (block) {
- return BlockTree_1.generate(content, block, decorator);
- }));
- }
-
- /**
- * Return whether a change should be considered a boundary state, given
- * the previous change type. Allows us to discard potential boundary states
- * during standard typing or deletion behavior.
- */
- function mustBecomeBoundary(editorState, changeType) {
- var lastChangeType = editorState.getLastChangeType();
- return changeType !== lastChangeType || changeType !== 'insert-characters' && changeType !== 'backspace-character' && changeType !== 'delete-character';
- }
-
- function getInlineStyleForCollapsedSelection(content, selection) {
- var startKey = selection.getStartKey();
- var startOffset = selection.getStartOffset();
- var startBlock = content.getBlockForKey(startKey);
-
- // If the cursor is not at the start of the block, look backward to
- // preserve the style of the preceding character.
- if (startOffset > 0) {
- return startBlock.getInlineStyleAt(startOffset - 1);
- }
-
- // The caret is at position zero in this block. If the block has any
- // text at all, use the style of the first character.
- if (startBlock.getLength()) {
- return startBlock.getInlineStyleAt(0);
- }
-
- // Otherwise, look upward in the document to find the closest character.
- return lookUpwardForInlineStyle(content, startKey);
- }
-
- function getInlineStyleForNonCollapsedSelection(content, selection) {
- var startKey = selection.getStartKey();
- var startOffset = selection.getStartOffset();
- var startBlock = content.getBlockForKey(startKey);
-
- // If there is a character just inside the selection, use its style.
- if (startOffset < startBlock.getLength()) {
- return startBlock.getInlineStyleAt(startOffset);
- }
-
- // Check if the selection at the end of a non-empty block. Use the last
- // style in the block.
- if (startOffset > 0) {
- return startBlock.getInlineStyleAt(startOffset - 1);
- }
-
- // Otherwise, look upward in the document to find the closest character.
- return lookUpwardForInlineStyle(content, startKey);
- }
-
- function lookUpwardForInlineStyle(content, fromKey) {
- var lastNonEmpty = content.getBlockMap().reverse().skipUntil(function (_, k) {
- return k === fromKey;
- }).skip(1).skipUntil(function (block, _) {
- return block.getLength();
- }).first();
-
- if (lastNonEmpty) return lastNonEmpty.getInlineStyleAt(lastNonEmpty.getLength() - 1);
- return OrderedSet$4();
- }
-
- var EditorState_1 = EditorState;
-
- var OrderedMap$3 = immutable.OrderedMap,
- List$7 = immutable.List;
-
-
- var transformBlock$2 = function transformBlock(key, blockMap, func) {
- if (!key) {
- return;
- }
-
- var block = blockMap.get(key);
-
- if (!block) {
- return;
- }
-
- blockMap.set(key, func(block));
- };
-
- var updateBlockMapLinks$3 = function updateBlockMapLinks(blockMap, originalBlockToBeMoved, originalTargetBlock, insertionMode, isExperimentalTreeBlock) {
- if (!isExperimentalTreeBlock) {
- return blockMap;
- }
- // possible values of 'insertionMode' are: 'after', 'before'
- var isInsertedAfterTarget = insertionMode === 'after';
-
- var originalBlockKey = originalBlockToBeMoved.getKey();
- var originalTargetKey = originalTargetBlock.getKey();
- var originalParentKey = originalBlockToBeMoved.getParentKey();
- var originalNextSiblingKey = originalBlockToBeMoved.getNextSiblingKey();
- var originalPrevSiblingKey = originalBlockToBeMoved.getPrevSiblingKey();
- var newParentKey = originalTargetBlock.getParentKey();
- var newNextSiblingKey = isInsertedAfterTarget ? originalTargetBlock.getNextSiblingKey() : originalTargetKey;
- var newPrevSiblingKey = isInsertedAfterTarget ? originalTargetKey : originalTargetBlock.getPrevSiblingKey();
-
- return blockMap.withMutations(function (blocks) {
- // update old parent
- transformBlock$2(originalParentKey, blocks, function (block) {
- var parentChildrenList = block.getChildKeys();
- return block.merge({
- children: parentChildrenList['delete'](parentChildrenList.indexOf(originalBlockKey))
- });
- });
-
- // update old prev
- transformBlock$2(originalPrevSiblingKey, blocks, function (block) {
- return block.merge({
- nextSibling: originalNextSiblingKey
- });
- });
-
- // update old next
- transformBlock$2(originalNextSiblingKey, blocks, function (block) {
- return block.merge({
- prevSibling: originalPrevSiblingKey
- });
- });
-
- // update new next
- transformBlock$2(newNextSiblingKey, blocks, function (block) {
- return block.merge({
- prevSibling: originalBlockKey
- });
- });
-
- // update new prev
- transformBlock$2(newPrevSiblingKey, blocks, function (block) {
- return block.merge({
- nextSibling: originalBlockKey
- });
- });
-
- // update new parent
- transformBlock$2(newParentKey, blocks, function (block) {
- var newParentChildrenList = block.getChildKeys();
- var targetBlockIndex = newParentChildrenList.indexOf(originalTargetKey);
-
- var insertionIndex = isInsertedAfterTarget ? targetBlockIndex + 1 : targetBlockIndex !== 0 ? targetBlockIndex - 1 : 0;
-
- var newChildrenArray = newParentChildrenList.toArray();
- newChildrenArray.splice(insertionIndex, 0, originalBlockKey);
-
- return block.merge({
- children: List$7(newChildrenArray)
- });
- });
-
- // update block
- transformBlock$2(originalBlockKey, blocks, function (block) {
- return block.merge({
- nextSibling: newNextSiblingKey,
- prevSibling: newPrevSiblingKey,
- parent: newParentKey
- });
- });
- });
- };
-
- var moveBlockInContentState = function moveBlockInContentState(contentState, blockToBeMoved, targetBlock, insertionMode) {
- !(insertionMode !== 'replace') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Replacing blocks is not supported.') : invariant_1(false) : void 0;
-
- var targetKey = targetBlock.getKey();
- var blockKey = blockToBeMoved.getKey();
-
- !(blockKey !== targetKey) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Block cannot be moved next to itself.') : invariant_1(false) : void 0;
-
- var blockMap = contentState.getBlockMap();
- var isExperimentalTreeBlock = blockToBeMoved instanceof ContentBlockNode_1;
-
- var blocksToBeMoved = [blockToBeMoved];
- var blockMapWithoutBlocksToBeMoved = blockMap['delete'](blockKey);
-
- if (isExperimentalTreeBlock) {
- blocksToBeMoved = [];
- blockMapWithoutBlocksToBeMoved = blockMap.withMutations(function (blocks) {
- var nextSiblingKey = blockToBeMoved.getNextSiblingKey();
- var nextDelimiterBlockKey = getNextDelimiterBlockKey_1(blockToBeMoved, blocks);
-
- blocks.toSeq().skipUntil(function (block) {
- return block.getKey() === blockKey;
- }).takeWhile(function (block) {
- var key = block.getKey();
- var isBlockToBeMoved = key === blockKey;
- var hasNextSiblingAndIsNotNextSibling = nextSiblingKey && key !== nextSiblingKey;
- var doesNotHaveNextSiblingAndIsNotDelimiter = !nextSiblingKey && block.getParentKey() && (!nextDelimiterBlockKey || key !== nextDelimiterBlockKey);
-
- return !!(isBlockToBeMoved || hasNextSiblingAndIsNotNextSibling || doesNotHaveNextSiblingAndIsNotDelimiter);
- }).forEach(function (block) {
- blocksToBeMoved.push(block);
- blocks['delete'](block.getKey());
- });
- });
- }
-
- var blocksBefore = blockMapWithoutBlocksToBeMoved.toSeq().takeUntil(function (v) {
- return v === targetBlock;
- });
-
- var blocksAfter = blockMapWithoutBlocksToBeMoved.toSeq().skipUntil(function (v) {
- return v === targetBlock;
- }).skip(1);
-
- var slicedBlocks = blocksToBeMoved.map(function (block) {
- return [block.getKey(), block];
- });
-
- var newBlocks = OrderedMap$3();
-
- if (insertionMode === 'before') {
- var blockBefore = contentState.getBlockBefore(targetKey);
-
- !(!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;
-
- newBlocks = blocksBefore.concat([].concat(slicedBlocks, [[targetKey, targetBlock]]), blocksAfter).toOrderedMap();
- } else if (insertionMode === 'after') {
- var blockAfter = contentState.getBlockAfter(targetKey);
-
- !(!blockAfter || blockAfter.getKey() !== blockKey) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Block cannot be moved next to itself.') : invariant_1(false) : void 0;
-
- newBlocks = blocksBefore.concat([[targetKey, targetBlock]].concat(slicedBlocks), blocksAfter).toOrderedMap();
- }
-
- return contentState.merge({
- blockMap: updateBlockMapLinks$3(newBlocks, blockToBeMoved, targetBlock, insertionMode, isExperimentalTreeBlock),
- selectionBefore: contentState.getSelectionAfter(),
- selectionAfter: contentState.getSelectionAfter().merge({
- anchorKey: blockKey,
- focusKey: blockKey
- })
- });
- };
-
- var moveBlockInContentState_1 = moveBlockInContentState;
-
- var ContentBlockRecord$1 = ContentBlock_1;
-
- var List$8 = immutable.List,
- Repeat$5 = immutable.Repeat;
-
-
- var AtomicBlockUtils = {
- insertAtomicBlock: function insertAtomicBlock(editorState, entityKey, character) {
- var contentState = editorState.getCurrentContent();
- var selectionState = editorState.getSelection();
-
- var afterRemoval = DraftModifier_1.removeRange(contentState, selectionState, 'backward');
-
- var targetSelection = afterRemoval.getSelectionAfter();
- var afterSplit = DraftModifier_1.splitBlock(afterRemoval, targetSelection);
- var insertionTarget = afterSplit.getSelectionAfter();
-
- var asAtomicBlock = DraftModifier_1.setBlockType(afterSplit, insertionTarget, 'atomic');
-
- var charData = CharacterMetadata_1.create({ entity: entityKey });
-
- var atomicBlockConfig = {
- key: generateRandomKey_1(),
- type: 'atomic',
- text: character,
- characterList: List$8(Repeat$5(charData, character.length))
- };
-
- var atomicDividerBlockConfig = {
- key: generateRandomKey_1(),
- type: 'unstyled'
- };
-
- var fragmentArray = [new ContentBlockRecord$1(atomicBlockConfig), new ContentBlockRecord$1(atomicDividerBlockConfig)];
-
- var fragment = BlockMapBuilder_1.createFromArray(fragmentArray);
-
- var withAtomicBlock = DraftModifier_1.replaceWithFragment(asAtomicBlock, insertionTarget, fragment);
-
- var newContent = withAtomicBlock.merge({
- selectionBefore: selectionState,
- selectionAfter: withAtomicBlock.getSelectionAfter().set('hasFocus', true)
- });
-
- return EditorState_1.push(editorState, newContent, 'insert-fragment');
- },
-
- moveAtomicBlock: function moveAtomicBlock(editorState, atomicBlock, targetRange, insertionMode) {
- var contentState = editorState.getCurrentContent();
- var selectionState = editorState.getSelection();
-
- var withMovedAtomicBlock = void 0;
-
- if (insertionMode === 'before' || insertionMode === 'after') {
- var targetBlock = contentState.getBlockForKey(insertionMode === 'before' ? targetRange.getStartKey() : targetRange.getEndKey());
-
- withMovedAtomicBlock = moveBlockInContentState_1(contentState, atomicBlock, targetBlock, insertionMode);
- } else {
- var afterRemoval = DraftModifier_1.removeRange(contentState, targetRange, 'backward');
-
- var selectionAfterRemoval = afterRemoval.getSelectionAfter();
- var _targetBlock = afterRemoval.getBlockForKey(selectionAfterRemoval.getFocusKey());
-
- if (selectionAfterRemoval.getStartOffset() === 0) {
- withMovedAtomicBlock = moveBlockInContentState_1(afterRemoval, atomicBlock, _targetBlock, 'before');
- } else if (selectionAfterRemoval.getEndOffset() === _targetBlock.getLength()) {
- withMovedAtomicBlock = moveBlockInContentState_1(afterRemoval, atomicBlock, _targetBlock, 'after');
- } else {
- var afterSplit = DraftModifier_1.splitBlock(afterRemoval, selectionAfterRemoval);
-
- var selectionAfterSplit = afterSplit.getSelectionAfter();
- var _targetBlock2 = afterSplit.getBlockForKey(selectionAfterSplit.getFocusKey());
-
- withMovedAtomicBlock = moveBlockInContentState_1(afterSplit, atomicBlock, _targetBlock2, 'before');
- }
- }
-
- var newContent = withMovedAtomicBlock.merge({
- selectionBefore: selectionState,
- selectionAfter: withMovedAtomicBlock.getSelectionAfter().set('hasFocus', true)
- });
-
- return EditorState_1.push(editorState, newContent, 'move-block');
- }
- };
-
- var AtomicBlockUtils_1 = AtomicBlockUtils;
-
- function _classCallCheck$8(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
-
-
- var List$9 = immutable.List;
-
-
- var DELIMITER = '.';
-
- /**
- * A CompositeDraftDecorator traverses through a list of DraftDecorator
- * instances to identify sections of a ContentBlock that should be rendered
- * in a "decorated" manner. For example, hashtags, mentions, and links may
- * be intended to stand out visually, be rendered as anchors, etc.
- *
- * The list of decorators supplied to the constructor will be used in the
- * order they are provided. This allows the caller to specify a priority for
- * string matching, in case of match collisions among decorators.
- *
- * For instance, I may have a link with a `#` in its text. Though this section
- * of text may match our hashtag decorator, it should not be treated as a
- * hashtag. I should therefore list my link DraftDecorator
- * before my hashtag DraftDecorator when constructing this composite
- * decorator instance.
- *
- * Thus, when a collision like this is encountered, the earlier match is
- * preserved and the new match is discarded.
- */
-
- var CompositeDraftDecorator = function () {
- function CompositeDraftDecorator(decorators) {
- _classCallCheck$8(this, CompositeDraftDecorator);
-
- // Copy the decorator array, since we use this array order to determine
- // precedence of decoration matching. If the array is mutated externally,
- // we don't want to be affected here.
- this._decorators = decorators.slice();
- }
-
- CompositeDraftDecorator.prototype.getDecorations = function getDecorations(block, contentState) {
- var decorations = Array(block.getText().length).fill(null);
-
- this._decorators.forEach(function ( /*object*/decorator, /*number*/ii) {
- var counter = 0;
- var strategy = decorator.strategy;
- var callback = function callback( /*number*/start, /*number*/end) {
- // Find out if any of our matching range is already occupied
- // by another decorator. If so, discard the match. Otherwise, store
- // the component key for rendering.
- if (canOccupySlice(decorations, start, end)) {
- occupySlice(decorations, start, end, ii + DELIMITER + counter);
- counter++;
- }
- };
- strategy(block, callback, contentState);
- });
-
- return List$9(decorations);
- };
-
- CompositeDraftDecorator.prototype.getComponentForKey = function getComponentForKey(key) {
- var componentKey = parseInt(key.split(DELIMITER)[0], 10);
- return this._decorators[componentKey].component;
- };
-
- CompositeDraftDecorator.prototype.getPropsForKey = function getPropsForKey(key) {
- var componentKey = parseInt(key.split(DELIMITER)[0], 10);
- return this._decorators[componentKey].props;
- };
-
- return CompositeDraftDecorator;
- }();
-
- /**
- * Determine whether we can occupy the specified slice of the decorations
- * array.
- */
-
-
- function canOccupySlice(decorations, start, end) {
- for (var ii = start; ii < end; ii++) {
- if (decorations[ii] != null) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Splice the specified component into our decoration array at the desired
- * range.
- */
- function occupySlice(targetArr, start, end, componentKey) {
- for (var ii = start; ii < end; ii++) {
- targetArr[ii] = componentKey;
- }
- }
-
- var CompositeDraftDecorator_1 = CompositeDraftDecorator;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- */
-
- /**
- * This function is used to mark string literals representing CSS class names
- * so that they can be transformed statically. This allows for modularization
- * and minification of CSS class names.
- *
- * In static_upstream, this function is actually implemented, but it should
- * eventually be replaced with something more descriptive, and the transform
- * that is used in the main stack should be ported for use elsewhere.
- *
- * @param string|object className to modularize, or an object of key/values.
- * In the object case, the values are conditions that
- * determine if the className keys should be included.
- * @param [string ...] Variable list of classNames in the string case.
- * @return string Renderable space-separated CSS className.
- */
- function cx(classNames) {
- if (typeof classNames == 'object') {
- return Object.keys(classNames).filter(function (className) {
- return classNames[className];
- }).map(replace).join(' ');
- }
- return Array.prototype.map.call(arguments, replace).join(' ');
- }
-
- function replace(str) {
- return str.replace(/\//g, '-');
- }
-
- var cx_1 = cx;
-
- var Map$8 = immutable.Map;
-
-
-
-
-
- var UL_WRAP = _reactDom_commonjsExternal.React.createElement('ul', { className: cx_1('public/DraftStyleDefault/ul') });
- var OL_WRAP = _reactDom_commonjsExternal.React.createElement('ol', { className: cx_1('public/DraftStyleDefault/ol') });
- var PRE_WRAP = _reactDom_commonjsExternal.React.createElement('pre', { className: cx_1('public/DraftStyleDefault/pre') });
-
- var DefaultDraftBlockRenderMap = Map$8({
- 'header-one': {
- element: 'h1'
- },
- 'header-two': {
- element: 'h2'
- },
- 'header-three': {
- element: 'h3'
- },
- 'header-four': {
- element: 'h4'
- },
- 'header-five': {
- element: 'h5'
- },
- 'header-six': {
- element: 'h6'
- },
- 'unordered-list-item': {
- element: 'li',
- wrapper: UL_WRAP
- },
- 'ordered-list-item': {
- element: 'li',
- wrapper: OL_WRAP
- },
- blockquote: {
- element: 'blockquote'
- },
- atomic: {
- element: 'figure'
- },
- 'code-block': {
- element: 'pre',
- wrapper: PRE_WRAP
- },
- unstyled: {
- element: 'div',
- aliasedElements: ['p']
- }
- });
-
- var DefaultDraftBlockRenderMap_1 = DefaultDraftBlockRenderMap;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule DefaultDraftInlineStyle
- * @format
- *
- */
-
- var DefaultDraftInlineStyle = {
- BOLD: {
- fontWeight: 'bold'
- },
-
- CODE: {
- fontFamily: 'monospace',
- wordWrap: 'break-word'
- },
-
- ITALIC: {
- fontStyle: 'italic'
- },
-
- STRIKETHROUGH: {
- textDecoration: 'line-through'
- },
-
- UNDERLINE: {
- textDecoration: 'underline'
- }
- };
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- */
-
- var Keys = {
- BACKSPACE: 8,
- TAB: 9,
- RETURN: 13,
- ALT: 18,
- ESC: 27,
- SPACE: 32,
- PAGE_UP: 33,
- PAGE_DOWN: 34,
- END: 35,
- HOME: 36,
- LEFT: 37,
- UP: 38,
- RIGHT: 39,
- DOWN: 40,
- DELETE: 46,
- COMMA: 188,
- PERIOD: 190,
- A: 65,
- Z: 90,
- ZERO: 48,
- NUMPAD_0: 96,
- NUMPAD_9: 105
- };
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule getEntityKeyForSelection
- * @format
- *
- */
-
- /**
- * Return the entity key that should be used when inserting text for the
- * specified target selection, only if the entity is `MUTABLE`. `IMMUTABLE`
- * and `SEGMENTED` entities should not be used for insertion behavior.
- */
- function getEntityKeyForSelection(contentState, targetSelection) {
- var entityKey;
-
- if (targetSelection.isCollapsed()) {
- var key = targetSelection.getAnchorKey();
- var offset = targetSelection.getAnchorOffset();
- if (offset > 0) {
- entityKey = contentState.getBlockForKey(key).getEntityAt(offset - 1);
- if (entityKey !== contentState.getBlockForKey(key).getEntityAt(offset)) {
- return null;
- }
- return filterKey(contentState.getEntityMap(), entityKey);
- }
- return null;
- }
-
- var startKey = targetSelection.getStartKey();
- var startOffset = targetSelection.getStartOffset();
- var startBlock = contentState.getBlockForKey(startKey);
-
- entityKey = startOffset === startBlock.getLength() ? null : startBlock.getEntityAt(startOffset);
-
- return filterKey(contentState.getEntityMap(), entityKey);
- }
-
- /**
- * Determine whether an entity key corresponds to a `MUTABLE` entity. If so,
- * return it. If not, return null.
- */
- function filterKey(entityMap, entityKey) {
- if (entityKey) {
- var entity = entityMap.__get(entityKey);
- return entity.getMutability() === 'MUTABLE' ? entityKey : null;
- }
- return null;
- }
-
- var getEntityKeyForSelection_1 = getEntityKeyForSelection;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule isEventHandled
- * @format
- *
- */
-
- /**
- * Utility method for determining whether or not the value returned
- * from a handler indicates that it was handled.
- */
- function isEventHandled(value) {
- return value === 'handled' || value === true;
- }
-
- var isEventHandled_1 = isEventHandled;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule isSelectionAtLeafStart
- * @format
- *
- */
-
- function isSelectionAtLeafStart(editorState) {
- var selection = editorState.getSelection();
- var anchorKey = selection.getAnchorKey();
- var blockTree = editorState.getBlockTree(anchorKey);
- var offset = selection.getStartOffset();
-
- var isAtStart = false;
-
- blockTree.some(function (leafSet) {
- if (offset === leafSet.get('start')) {
- isAtStart = true;
- return true;
- }
-
- if (offset < leafSet.get('end')) {
- return leafSet.get('leaves').some(function (leaf) {
- var leafStart = leaf.get('start');
- if (offset === leafStart) {
- isAtStart = true;
- return true;
- }
-
- return false;
- });
- }
-
- return false;
- });
-
- return isAtStart;
- }
-
- var isSelectionAtLeafStart_1 = isSelectionAtLeafStart;
-
- /**
- * Millisecond delay to allow `compositionstart` to fire again upon
- * `compositionend`.
- *
- * This is used for Korean input to ensure that typing can continue without
- * the editor trying to render too quickly. More specifically, Safari 7.1+
- * triggers `compositionstart` a little slower than Chrome/FF, which
- * leads to composed characters being resolved and re-render occurring
- * sooner than we want.
- */
- var RESOLVE_DELAY = 20;
-
- /**
- * A handful of variables used to track the current composition and its
- * resolution status. These exist at the module level because it is not
- * possible to have compositions occurring in multiple editors simultaneously,
- * and it simplifies state management with respect to the DraftEditor component.
- */
- var resolved = false;
- var stillComposing = false;
- var textInputData = '';
-
- var DraftEditorCompositionHandler = {
- onBeforeInput: function onBeforeInput(editor, e) {
- textInputData = (textInputData || '') + e.data;
- },
-
- /**
- * A `compositionstart` event has fired while we're still in composition
- * mode. Continue the current composition session to prevent a re-render.
- */
- onCompositionStart: function onCompositionStart(editor) {
- stillComposing = true;
- },
-
- /**
- * Attempt to end the current composition session.
- *
- * Defer handling because browser will still insert the chars into active
- * element after `compositionend`. If a `compositionstart` event fires
- * before `resolveComposition` executes, our composition session will
- * continue.
- *
- * The `resolved` flag is useful because certain IME interfaces fire the
- * `compositionend` event multiple times, thus queueing up multiple attempts
- * at handling the composition. Since handling the same composition event
- * twice could break the DOM, we only use the first event. Example: Arabic
- * Google Input Tools on Windows 8.1 fires `compositionend` three times.
- */
- onCompositionEnd: function onCompositionEnd(editor) {
- resolved = false;
- stillComposing = false;
- setTimeout(function () {
- if (!resolved) {
- DraftEditorCompositionHandler.resolveComposition(editor);
- }
- }, RESOLVE_DELAY);
- },
-
- /**
- * In Safari, keydown events may fire when committing compositions. If
- * the arrow keys are used to commit, prevent default so that the cursor
- * doesn't move, otherwise it will jump back noticeably on re-render.
- */
- onKeyDown: function onKeyDown(editor, e) {
- if (!stillComposing) {
- // If a keydown event is received after compositionend but before the
- // 20ms timer expires (ex: type option-E then backspace, or type A then
- // backspace in 2-Set Korean), we should immediately resolve the
- // composition and reinterpret the key press in edit mode.
- DraftEditorCompositionHandler.resolveComposition(editor);
- editor._onKeyDown(e);
- return;
- }
- if (e.which === Keys.RIGHT || e.which === Keys.LEFT) {
- e.preventDefault();
- }
- },
-
- /**
- * Keypress events may fire when committing compositions. In Firefox,
- * pressing RETURN commits the composition and inserts extra newline
- * characters that we do not want. `preventDefault` allows the composition
- * to be committed while preventing the extra characters.
- */
- onKeyPress: function onKeyPress(editor, e) {
- if (e.which === Keys.RETURN) {
- e.preventDefault();
- }
- },
-
- /**
- * Attempt to insert composed characters into the document.
- *
- * If we are still in a composition session, do nothing. Otherwise, insert
- * the characters into the document and terminate the composition session.
- *
- * If no characters were composed -- for instance, the user
- * deleted all composed characters and committed nothing new --
- * force a re-render. We also re-render when the composition occurs
- * at the beginning of a leaf, to ensure that if the browser has
- * created a new text node for the composition, we will discard it.
- *
- * Resetting innerHTML will move focus to the beginning of the editor,
- * so we update to force it back to the correct place.
- */
- resolveComposition: function resolveComposition(editor) {
- if (stillComposing) {
- return;
- }
-
- resolved = true;
- var composedChars = textInputData;
- textInputData = '';
-
- var editorState = EditorState_1.set(editor._latestEditorState, {
- inCompositionMode: false
- });
-
- var currentStyle = editorState.getCurrentInlineStyle();
- var entityKey = getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection());
-
- var mustReset = !composedChars || isSelectionAtLeafStart_1(editorState) || currentStyle.size > 0 || entityKey !== null;
-
- if (mustReset) {
- editor.restoreEditorDOM();
- }
-
- editor.exitCurrentMode();
-
- if (composedChars) {
- // If characters have been composed, re-rendering with the update
- // is sufficient to reset the editor.
- var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), composedChars, currentStyle, entityKey);
- editor.update(EditorState_1.push(editorState, contentState, 'insert-characters'));
- return;
- }
-
- if (mustReset) {
- editor.update(EditorState_1.set(editorState, {
- nativelyRenderedContent: null,
- forceSelection: true
- }));
- }
- }
- };
-
- var DraftEditorCompositionHandler_1 = DraftEditorCompositionHandler;
-
- var uaParser = _commonjsHelpers.createCommonjsModule(function (module, exports) {
- /*!
- * UAParser.js v0.7.21
- * Lightweight JavaScript-based User-Agent string parser
- * https://github.com/faisalman/ua-parser-js
- *
- * Copyright © 2012-2019 Faisal Salman <f@faisalman.com>
- * Licensed under MIT License
- */
-
- (function (window, undefined$1) {
-
- //////////////
- // Constants
- /////////////
-
-
- var LIBVERSION = '0.7.21',
- EMPTY = '',
- UNKNOWN = '?',
- FUNC_TYPE = 'function',
- OBJ_TYPE = 'object',
- STR_TYPE = 'string',
- MAJOR = 'major', // deprecated
- MODEL = 'model',
- NAME = 'name',
- TYPE = 'type',
- VENDOR = 'vendor',
- VERSION = 'version',
- ARCHITECTURE= 'architecture',
- CONSOLE = 'console',
- MOBILE = 'mobile',
- TABLET = 'tablet',
- SMARTTV = 'smarttv',
- WEARABLE = 'wearable',
- EMBEDDED = 'embedded';
-
-
- ///////////
- // Helper
- //////////
-
-
- var util = {
- extend : function (regexes, extensions) {
- var mergedRegexes = {};
- for (var i in regexes) {
- if (extensions[i] && extensions[i].length % 2 === 0) {
- mergedRegexes[i] = extensions[i].concat(regexes[i]);
- } else {
- mergedRegexes[i] = regexes[i];
- }
- }
- return mergedRegexes;
- },
- has : function (str1, str2) {
- if (typeof str1 === "string") {
- return str2.toLowerCase().indexOf(str1.toLowerCase()) !== -1;
- } else {
- return false;
- }
- },
- lowerize : function (str) {
- return str.toLowerCase();
- },
- major : function (version) {
- return typeof(version) === STR_TYPE ? version.replace(/[^\d\.]/g,'').split(".")[0] : undefined$1;
- },
- trim : function (str) {
- return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
- }
- };
-
-
- ///////////////
- // Map helper
- //////////////
-
-
- var mapper = {
-
- rgx : function (ua, arrays) {
-
- var i = 0, j, k, p, q, matches, match;
-
- // loop through all regexes maps
- while (i < arrays.length && !matches) {
-
- var regex = arrays[i], // even sequence (0,2,4,..)
- props = arrays[i + 1]; // odd sequence (1,3,5,..)
- j = k = 0;
-
- // try matching uastring with regexes
- while (j < regex.length && !matches) {
-
- matches = regex[j++].exec(ua);
-
- if (!!matches) {
- for (p = 0; p < props.length; p++) {
- match = matches[++k];
- q = props[p];
- // check if given property is actually array
- if (typeof q === OBJ_TYPE && q.length > 0) {
- if (q.length == 2) {
- if (typeof q[1] == FUNC_TYPE) {
- // assign modified match
- this[q[0]] = q[1].call(this, match);
- } else {
- // assign given value, ignore regex match
- this[q[0]] = q[1];
- }
- } else if (q.length == 3) {
- // check whether function or regex
- if (typeof q[1] === FUNC_TYPE && !(q[1].exec && q[1].test)) {
- // call function (usually string mapper)
- this[q[0]] = match ? q[1].call(this, match, q[2]) : undefined$1;
- } else {
- // sanitize match using given regex
- this[q[0]] = match ? match.replace(q[1], q[2]) : undefined$1;
- }
- } else if (q.length == 4) {
- this[q[0]] = match ? q[3].call(this, match.replace(q[1], q[2])) : undefined$1;
- }
- } else {
- this[q] = match ? match : undefined$1;
- }
- }
- }
- }
- i += 2;
- }
- },
-
- str : function (str, map) {
-
- for (var i in map) {
- // check if array
- if (typeof map[i] === OBJ_TYPE && map[i].length > 0) {
- for (var j = 0; j < map[i].length; j++) {
- if (util.has(map[i][j], str)) {
- return (i === UNKNOWN) ? undefined$1 : i;
- }
- }
- } else if (util.has(map[i], str)) {
- return (i === UNKNOWN) ? undefined$1 : i;
- }
- }
- return str;
- }
- };
-
-
- ///////////////
- // String map
- //////////////
-
-
- var maps = {
-
- browser : {
- oldsafari : {
- version : {
- '1.0' : '/8',
- '1.2' : '/1',
- '1.3' : '/3',
- '2.0' : '/412',
- '2.0.2' : '/416',
- '2.0.3' : '/417',
- '2.0.4' : '/419',
- '?' : '/'
- }
- }
- },
-
- device : {
- amazon : {
- model : {
- 'Fire Phone' : ['SD', 'KF']
- }
- },
- sprint : {
- model : {
- 'Evo Shift 4G' : '7373KT'
- },
- vendor : {
- 'HTC' : 'APA',
- 'Sprint' : 'Sprint'
- }
- }
- },
-
- os : {
- windows : {
- version : {
- 'ME' : '4.90',
- 'NT 3.11' : 'NT3.51',
- 'NT 4.0' : 'NT4.0',
- '2000' : 'NT 5.0',
- 'XP' : ['NT 5.1', 'NT 5.2'],
- 'Vista' : 'NT 6.0',
- '7' : 'NT 6.1',
- '8' : 'NT 6.2',
- '8.1' : 'NT 6.3',
- '10' : ['NT 6.4', 'NT 10.0'],
- 'RT' : 'ARM'
- }
- }
- }
- };
-
-
- //////////////
- // Regex map
- /////////////
-
-
- var regexes = {
-
- browser : [[
-
- // Presto based
- /(opera\smini)\/([\w\.-]+)/i, // Opera Mini
- /(opera\s[mobiletab]+).+version\/([\w\.-]+)/i, // Opera Mobi/Tablet
- /(opera).+version\/([\w\.]+)/i, // Opera > 9.80
- /(opera)[\/\s]+([\w\.]+)/i // Opera < 9.80
- ], [NAME, VERSION], [
-
- /(opios)[\/\s]+([\w\.]+)/i // Opera mini on iphone >= 8.0
- ], [[NAME, 'Opera Mini'], VERSION], [
-
- /\s(opr)\/([\w\.]+)/i // Opera Webkit
- ], [[NAME, 'Opera'], VERSION], [
-
- // Mixed
- /(kindle)\/([\w\.]+)/i, // Kindle
- /(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?([\w\.]*)/i,
- // Lunascape/Maxthon/Netfront/Jasmine/Blazer
- // Trident based
- /(avant\s|iemobile|slim)(?:browser)?[\/\s]?([\w\.]*)/i,
- // Avant/IEMobile/SlimBrowser
- /(bidubrowser|baidubrowser)[\/\s]?([\w\.]+)/i, // Baidu Browser
- /(?:ms|\()(ie)\s([\w\.]+)/i, // Internet Explorer
-
- // Webkit/KHTML based
- /(rekonq)\/([\w\.]*)/i, // Rekonq
- /(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt|iron|vivaldi|iridium|phantomjs|bowser|quark|qupzilla|falkon)\/([\w\.-]+)/i
- // Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt/Iron/Iridium/PhantomJS/Bowser/QupZilla/Falkon
- ], [NAME, VERSION], [
-
- /(konqueror)\/([\w\.]+)/i // Konqueror
- ], [[NAME, 'Konqueror'], VERSION], [
-
- /(trident).+rv[:\s]([\w\.]+).+like\sgecko/i // IE11
- ], [[NAME, 'IE'], VERSION], [
-
- /(edge|edgios|edga|edg)\/((\d+)?[\w\.]+)/i // Microsoft Edge
- ], [[NAME, 'Edge'], VERSION], [
-
- /(yabrowser)\/([\w\.]+)/i // Yandex
- ], [[NAME, 'Yandex'], VERSION], [
-
- /(Avast)\/([\w\.]+)/i // Avast Secure Browser
- ], [[NAME, 'Avast Secure Browser'], VERSION], [
-
- /(AVG)\/([\w\.]+)/i // AVG Secure Browser
- ], [[NAME, 'AVG Secure Browser'], VERSION], [
-
- /(puffin)\/([\w\.]+)/i // Puffin
- ], [[NAME, 'Puffin'], VERSION], [
-
- /(focus)\/([\w\.]+)/i // Firefox Focus
- ], [[NAME, 'Firefox Focus'], VERSION], [
-
- /(opt)\/([\w\.]+)/i // Opera Touch
- ], [[NAME, 'Opera Touch'], VERSION], [
-
- /((?:[\s\/])uc?\s?browser|(?:juc.+)ucweb)[\/\s]?([\w\.]+)/i // UCBrowser
- ], [[NAME, 'UCBrowser'], VERSION], [
-
- /(comodo_dragon)\/([\w\.]+)/i // Comodo Dragon
- ], [[NAME, /_/g, ' '], VERSION], [
-
- /(windowswechat qbcore)\/([\w\.]+)/i // WeChat Desktop for Windows Built-in Browser
- ], [[NAME, 'WeChat(Win) Desktop'], VERSION], [
-
- /(micromessenger)\/([\w\.]+)/i // WeChat
- ], [[NAME, 'WeChat'], VERSION], [
-
- /(brave)\/([\w\.]+)/i // Brave browser
- ], [[NAME, 'Brave'], VERSION], [
-
- /(qqbrowserlite)\/([\w\.]+)/i // QQBrowserLite
- ], [NAME, VERSION], [
-
- /(QQ)\/([\d\.]+)/i // QQ, aka ShouQ
- ], [NAME, VERSION], [
-
- /m?(qqbrowser)[\/\s]?([\w\.]+)/i // QQBrowser
- ], [NAME, VERSION], [
-
- /(baiduboxapp)[\/\s]?([\w\.]+)/i // Baidu App
- ], [NAME, VERSION], [
-
- /(2345Explorer)[\/\s]?([\w\.]+)/i // 2345 Browser
- ], [NAME, VERSION], [
-
- /(MetaSr)[\/\s]?([\w\.]+)/i // SouGouBrowser
- ], [NAME], [
-
- /(LBBROWSER)/i // LieBao Browser
- ], [NAME], [
-
- /xiaomi\/miuibrowser\/([\w\.]+)/i // MIUI Browser
- ], [VERSION, [NAME, 'MIUI Browser']], [
-
- /;fbav\/([\w\.]+);/i // Facebook App for iOS & Android
- ], [VERSION, [NAME, 'Facebook']], [
-
- /safari\s(line)\/([\w\.]+)/i, // Line App for iOS
- /android.+(line)\/([\w\.]+)\/iab/i // Line App for Android
- ], [NAME, VERSION], [
-
- /headlesschrome(?:\/([\w\.]+)|\s)/i // Chrome Headless
- ], [VERSION, [NAME, 'Chrome Headless']], [
-
- /\swv\).+(chrome)\/([\w\.]+)/i // Chrome WebView
- ], [[NAME, /(.+)/, '$1 WebView'], VERSION], [
-
- /((?:oculus|samsung)browser)\/([\w\.]+)/i
- ], [[NAME, /(.+(?:g|us))(.+)/, '$1 $2'], VERSION], [ // Oculus / Samsung Browser
-
- /android.+version\/([\w\.]+)\s+(?:mobile\s?safari|safari)*/i // Android Browser
- ], [VERSION, [NAME, 'Android Browser']], [
-
- /(sailfishbrowser)\/([\w\.]+)/i // Sailfish Browser
- ], [[NAME, 'Sailfish Browser'], VERSION], [
-
- /(chrome|omniweb|arora|[tizenoka]{5}\s?browser)\/v?([\w\.]+)/i
- // Chrome/OmniWeb/Arora/Tizen/Nokia
- ], [NAME, VERSION], [
-
- /(dolfin)\/([\w\.]+)/i // Dolphin
- ], [[NAME, 'Dolphin'], VERSION], [
-
- /(qihu|qhbrowser|qihoobrowser|360browser)/i // 360
- ], [[NAME, '360 Browser']], [
-
- /((?:android.+)crmo|crios)\/([\w\.]+)/i // Chrome for Android/iOS
- ], [[NAME, 'Chrome'], VERSION], [
-
- /(coast)\/([\w\.]+)/i // Opera Coast
- ], [[NAME, 'Opera Coast'], VERSION], [
-
- /fxios\/([\w\.-]+)/i // Firefox for iOS
- ], [VERSION, [NAME, 'Firefox']], [
-
- /version\/([\w\.]+).+?mobile\/\w+\s(safari)/i // Mobile Safari
- ], [VERSION, [NAME, 'Mobile Safari']], [
-
- /version\/([\w\.]+).+?(mobile\s?safari|safari)/i // Safari & Safari Mobile
- ], [VERSION, NAME], [
-
- /webkit.+?(gsa)\/([\w\.]+).+?(mobile\s?safari|safari)(\/[\w\.]+)/i // Google Search Appliance on iOS
- ], [[NAME, 'GSA'], VERSION], [
-
- /webkit.+?(mobile\s?safari|safari)(\/[\w\.]+)/i // Safari < 3.0
- ], [NAME, [VERSION, mapper.str, maps.browser.oldsafari.version]], [
-
- /(webkit|khtml)\/([\w\.]+)/i
- ], [NAME, VERSION], [
-
- // Gecko based
- /(navigator|netscape)\/([\w\.-]+)/i // Netscape
- ], [[NAME, 'Netscape'], VERSION], [
- /(swiftfox)/i, // Swiftfox
- /(icedragon|iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo|conkeror)[\/\s]?([\w\.\+]+)/i,
- // IceDragon/Iceweasel/Camino/Chimera/Fennec/Maemo/Minimo/Conkeror
- /(firefox|seamonkey|k-meleon|icecat|iceape|firebird|phoenix|palemoon|basilisk|waterfox)\/([\w\.-]+)$/i,
-
- // Firefox/SeaMonkey/K-Meleon/IceCat/IceApe/Firebird/Phoenix
- /(mozilla)\/([\w\.]+).+rv\:.+gecko\/\d+/i, // Mozilla
-
- // Other
- /(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|sleipnir)[\/\s]?([\w\.]+)/i,
- // Polaris/Lynx/Dillo/iCab/Doris/Amaya/w3m/NetSurf/Sleipnir
- /(links)\s\(([\w\.]+)/i, // Links
- /(gobrowser)\/?([\w\.]*)/i, // GoBrowser
- /(ice\s?browser)\/v?([\w\._]+)/i, // ICE Browser
- /(mosaic)[\/\s]([\w\.]+)/i // Mosaic
- ], [NAME, VERSION]
- ],
-
- cpu : [[
-
- /(?:(amd|x(?:(?:86|64)[_-])?|wow|win)64)[;\)]/i // AMD64
- ], [[ARCHITECTURE, 'amd64']], [
-
- /(ia32(?=;))/i // IA32 (quicktime)
- ], [[ARCHITECTURE, util.lowerize]], [
-
- /((?:i[346]|x)86)[;\)]/i // IA32
- ], [[ARCHITECTURE, 'ia32']], [
-
- // PocketPC mistakenly identified as PowerPC
- /windows\s(ce|mobile);\sppc;/i
- ], [[ARCHITECTURE, 'arm']], [
-
- /((?:ppc|powerpc)(?:64)?)(?:\smac|;|\))/i // PowerPC
- ], [[ARCHITECTURE, /ower/, '', util.lowerize]], [
-
- /(sun4\w)[;\)]/i // SPARC
- ], [[ARCHITECTURE, 'sparc']], [
-
- /((?:avr32|ia64(?=;))|68k(?=\))|arm(?:64|(?=v\d+[;l]))|(?=atmel\s)avr|(?:irix|mips|sparc)(?:64)?(?=;)|pa-risc)/i
- // IA64, 68K, ARM/64, AVR/32, IRIX/64, MIPS/64, SPARC/64, PA-RISC
- ], [[ARCHITECTURE, util.lowerize]]
- ],
-
- device : [[
-
- /\((ipad|playbook);[\w\s\),;-]+(rim|apple)/i // iPad/PlayBook
- ], [MODEL, VENDOR, [TYPE, TABLET]], [
-
- /applecoremedia\/[\w\.]+ \((ipad)/ // iPad
- ], [MODEL, [VENDOR, 'Apple'], [TYPE, TABLET]], [
-
- /(apple\s{0,1}tv)/i // Apple TV
- ], [[MODEL, 'Apple TV'], [VENDOR, 'Apple'], [TYPE, SMARTTV]], [
-
- /(archos)\s(gamepad2?)/i, // Archos
- /(hp).+(touchpad)/i, // HP TouchPad
- /(hp).+(tablet)/i, // HP Tablet
- /(kindle)\/([\w\.]+)/i, // Kindle
- /\s(nook)[\w\s]+build\/(\w+)/i, // Nook
- /(dell)\s(strea[kpr\s\d]*[\dko])/i // Dell Streak
- ], [VENDOR, MODEL, [TYPE, TABLET]], [
-
- /(kf[A-z]+)\sbuild\/.+silk\//i // Kindle Fire HD
- ], [MODEL, [VENDOR, 'Amazon'], [TYPE, TABLET]], [
- /(sd|kf)[0349hijorstuw]+\sbuild\/.+silk\//i // Fire Phone
- ], [[MODEL, mapper.str, maps.device.amazon.model], [VENDOR, 'Amazon'], [TYPE, MOBILE]], [
- /android.+aft([bms])\sbuild/i // Fire TV
- ], [MODEL, [VENDOR, 'Amazon'], [TYPE, SMARTTV]], [
-
- /\((ip[honed|\s\w*]+);.+(apple)/i // iPod/iPhone
- ], [MODEL, VENDOR, [TYPE, MOBILE]], [
- /\((ip[honed|\s\w*]+);/i // iPod/iPhone
- ], [MODEL, [VENDOR, 'Apple'], [TYPE, MOBILE]], [
-
- /(blackberry)[\s-]?(\w+)/i, // BlackBerry
- /(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|meizu|motorola|polytron)[\s_-]?([\w-]*)/i,
- // BenQ/Palm/Sony-Ericsson/Acer/Asus/Dell/Meizu/Motorola/Polytron
- /(hp)\s([\w\s]+\w)/i, // HP iPAQ
- /(asus)-?(\w+)/i // Asus
- ], [VENDOR, MODEL, [TYPE, MOBILE]], [
- /\(bb10;\s(\w+)/i // BlackBerry 10
- ], [MODEL, [VENDOR, 'BlackBerry'], [TYPE, MOBILE]], [
- // Asus Tablets
- /android.+(transfo[prime\s]{4,10}\s\w+|eeepc|slider\s\w+|nexus 7|padfone|p00c)/i
- ], [MODEL, [VENDOR, 'Asus'], [TYPE, TABLET]], [
-
- /(sony)\s(tablet\s[ps])\sbuild\//i, // Sony
- /(sony)?(?:sgp.+)\sbuild\//i
- ], [[VENDOR, 'Sony'], [MODEL, 'Xperia Tablet'], [TYPE, TABLET]], [
- /android.+\s([c-g]\d{4}|so[-l]\w+)(?=\sbuild\/|\).+chrome\/(?![1-6]{0,1}\d\.))/i
- ], [MODEL, [VENDOR, 'Sony'], [TYPE, MOBILE]], [
-
- /\s(ouya)\s/i, // Ouya
- /(nintendo)\s([wids3u]+)/i // Nintendo
- ], [VENDOR, MODEL, [TYPE, CONSOLE]], [
-
- /android.+;\s(shield)\sbuild/i // Nvidia
- ], [MODEL, [VENDOR, 'Nvidia'], [TYPE, CONSOLE]], [
-
- /(playstation\s[34portablevi]+)/i // Playstation
- ], [MODEL, [VENDOR, 'Sony'], [TYPE, CONSOLE]], [
-
- /(sprint\s(\w+))/i // Sprint Phones
- ], [[VENDOR, mapper.str, maps.device.sprint.vendor], [MODEL, mapper.str, maps.device.sprint.model], [TYPE, MOBILE]], [
-
- /(htc)[;_\s-]+([\w\s]+(?=\)|\sbuild)|\w+)/i, // HTC
- /(zte)-(\w*)/i, // ZTE
- /(alcatel|geeksphone|nexian|panasonic|(?=;\s)sony)[_\s-]?([\w-]*)/i
- // Alcatel/GeeksPhone/Nexian/Panasonic/Sony
- ], [VENDOR, [MODEL, /_/g, ' '], [TYPE, MOBILE]], [
-
- /(nexus\s9)/i // HTC Nexus 9
- ], [MODEL, [VENDOR, 'HTC'], [TYPE, TABLET]], [
-
- /d\/huawei([\w\s-]+)[;\)]/i,
- /(nexus\s6p|vog-l29|ane-lx1|eml-l29)/i // Huawei
- ], [MODEL, [VENDOR, 'Huawei'], [TYPE, MOBILE]], [
-
- /android.+(bah2?-a?[lw]\d{2})/i // Huawei MediaPad
- ], [MODEL, [VENDOR, 'Huawei'], [TYPE, TABLET]], [
-
- /(microsoft);\s(lumia[\s\w]+)/i // Microsoft Lumia
- ], [VENDOR, MODEL, [TYPE, MOBILE]], [
-
- /[\s\(;](xbox(?:\sone)?)[\s\);]/i // Microsoft Xbox
- ], [MODEL, [VENDOR, 'Microsoft'], [TYPE, CONSOLE]], [
- /(kin\.[onetw]{3})/i // Microsoft Kin
- ], [[MODEL, /\./g, ' '], [VENDOR, 'Microsoft'], [TYPE, MOBILE]], [
-
- // Motorola
- /\s(milestone|droid(?:[2-4x]|\s(?:bionic|x2|pro|razr))?:?(\s4g)?)[\w\s]+build\//i,
- /mot[\s-]?(\w*)/i,
- /(XT\d{3,4}) build\//i,
- /(nexus\s6)/i
- ], [MODEL, [VENDOR, 'Motorola'], [TYPE, MOBILE]], [
- /android.+\s(mz60\d|xoom[\s2]{0,2})\sbuild\//i
- ], [MODEL, [VENDOR, 'Motorola'], [TYPE, TABLET]], [
-
- /hbbtv\/\d+\.\d+\.\d+\s+\([\w\s]*;\s*(\w[^;]*);([^;]*)/i // HbbTV devices
- ], [[VENDOR, util.trim], [MODEL, util.trim], [TYPE, SMARTTV]], [
-
- /hbbtv.+maple;(\d+)/i
- ], [[MODEL, /^/, 'SmartTV'], [VENDOR, 'Samsung'], [TYPE, SMARTTV]], [
-
- /\(dtv[\);].+(aquos)/i // Sharp
- ], [MODEL, [VENDOR, 'Sharp'], [TYPE, SMARTTV]], [
-
- /android.+((sch-i[89]0\d|shw-m380s|gt-p\d{4}|gt-n\d+|sgh-t8[56]9|nexus 10))/i,
- /((SM-T\w+))/i
- ], [[VENDOR, 'Samsung'], MODEL, [TYPE, TABLET]], [ // Samsung
- /smart-tv.+(samsung)/i
- ], [VENDOR, [TYPE, SMARTTV], MODEL], [
- /((s[cgp]h-\w+|gt-\w+|galaxy\snexus|sm-\w[\w\d]+))/i,
- /(sam[sung]*)[\s-]*(\w+-?[\w-]*)/i,
- /sec-((sgh\w+))/i
- ], [[VENDOR, 'Samsung'], MODEL, [TYPE, MOBILE]], [
-
- /sie-(\w*)/i // Siemens
- ], [MODEL, [VENDOR, 'Siemens'], [TYPE, MOBILE]], [
-
- /(maemo|nokia).*(n900|lumia\s\d+)/i, // Nokia
- /(nokia)[\s_-]?([\w-]*)/i
- ], [[VENDOR, 'Nokia'], MODEL, [TYPE, MOBILE]], [
-
- /android[x\d\.\s;]+\s([ab][1-7]\-?[0178a]\d\d?)/i // Acer
- ], [MODEL, [VENDOR, 'Acer'], [TYPE, TABLET]], [
-
- /android.+([vl]k\-?\d{3})\s+build/i // LG Tablet
- ], [MODEL, [VENDOR, 'LG'], [TYPE, TABLET]], [
- /android\s3\.[\s\w;-]{10}(lg?)-([06cv9]{3,4})/i // LG Tablet
- ], [[VENDOR, 'LG'], MODEL, [TYPE, TABLET]], [
- /(lg) netcast\.tv/i // LG SmartTV
- ], [VENDOR, MODEL, [TYPE, SMARTTV]], [
- /(nexus\s[45])/i, // LG
- /lg[e;\s\/-]+(\w*)/i,
- /android.+lg(\-?[\d\w]+)\s+build/i
- ], [MODEL, [VENDOR, 'LG'], [TYPE, MOBILE]], [
-
- /(lenovo)\s?(s(?:5000|6000)(?:[\w-]+)|tab(?:[\s\w]+))/i // Lenovo tablets
- ], [VENDOR, MODEL, [TYPE, TABLET]], [
- /android.+(ideatab[a-z0-9\-\s]+)/i // Lenovo
- ], [MODEL, [VENDOR, 'Lenovo'], [TYPE, TABLET]], [
- /(lenovo)[_\s-]?([\w-]+)/i
- ], [VENDOR, MODEL, [TYPE, MOBILE]], [
-
- /linux;.+((jolla));/i // Jolla
- ], [VENDOR, MODEL, [TYPE, MOBILE]], [
-
- /((pebble))app\/[\d\.]+\s/i // Pebble
- ], [VENDOR, MODEL, [TYPE, WEARABLE]], [
-
- /android.+;\s(oppo)\s?([\w\s]+)\sbuild/i // OPPO
- ], [VENDOR, MODEL, [TYPE, MOBILE]], [
-
- /crkey/i // Google Chromecast
- ], [[MODEL, 'Chromecast'], [VENDOR, 'Google'], [TYPE, SMARTTV]], [
-
- /android.+;\s(glass)\s\d/i // Google Glass
- ], [MODEL, [VENDOR, 'Google'], [TYPE, WEARABLE]], [
-
- /android.+;\s(pixel c)[\s)]/i // Google Pixel C
- ], [MODEL, [VENDOR, 'Google'], [TYPE, TABLET]], [
-
- /android.+;\s(pixel( [23])?( xl)?)[\s)]/i // Google Pixel
- ], [MODEL, [VENDOR, 'Google'], [TYPE, MOBILE]], [
-
- /android.+;\s(\w+)\s+build\/hm\1/i, // Xiaomi Hongmi 'numeric' models
- /android.+(hm[\s\-_]*note?[\s_]*(?:\d\w)?)\s+build/i, // Xiaomi Hongmi
- /android.+(mi[\s\-_]*(?:a\d|one|one[\s_]plus|note lte)?[\s_]*(?:\d?\w?)[\s_]*(?:plus)?)\s+build/i,
- // Xiaomi Mi
- /android.+(redmi[\s\-_]*(?:note)?(?:[\s_]*[\w\s]+))\s+build/i // Redmi Phones
- ], [[MODEL, /_/g, ' '], [VENDOR, 'Xiaomi'], [TYPE, MOBILE]], [
- /android.+(mi[\s\-_]*(?:pad)(?:[\s_]*[\w\s]+))\s+build/i // Mi Pad tablets
- ],[[MODEL, /_/g, ' '], [VENDOR, 'Xiaomi'], [TYPE, TABLET]], [
- /android.+;\s(m[1-5]\snote)\sbuild/i // Meizu
- ], [MODEL, [VENDOR, 'Meizu'], [TYPE, MOBILE]], [
- /(mz)-([\w-]{2,})/i
- ], [[VENDOR, 'Meizu'], MODEL, [TYPE, MOBILE]], [
-
- /android.+a000(1)\s+build/i, // OnePlus
- /android.+oneplus\s(a\d{4})[\s)]/i
- ], [MODEL, [VENDOR, 'OnePlus'], [TYPE, MOBILE]], [
-
- /android.+[;\/]\s*(RCT[\d\w]+)\s+build/i // RCA Tablets
- ], [MODEL, [VENDOR, 'RCA'], [TYPE, TABLET]], [
-
- /android.+[;\/\s]+(Venue[\d\s]{2,7})\s+build/i // Dell Venue Tablets
- ], [MODEL, [VENDOR, 'Dell'], [TYPE, TABLET]], [
-
- /android.+[;\/]\s*(Q[T|M][\d\w]+)\s+build/i // Verizon Tablet
- ], [MODEL, [VENDOR, 'Verizon'], [TYPE, TABLET]], [
-
- /android.+[;\/]\s+(Barnes[&\s]+Noble\s+|BN[RT])(V?.*)\s+build/i // Barnes & Noble Tablet
- ], [[VENDOR, 'Barnes & Noble'], MODEL, [TYPE, TABLET]], [
-
- /android.+[;\/]\s+(TM\d{3}.*\b)\s+build/i // Barnes & Noble Tablet
- ], [MODEL, [VENDOR, 'NuVision'], [TYPE, TABLET]], [
-
- /android.+;\s(k88)\sbuild/i // ZTE K Series Tablet
- ], [MODEL, [VENDOR, 'ZTE'], [TYPE, TABLET]], [
-
- /android.+[;\/]\s*(gen\d{3})\s+build.*49h/i // Swiss GEN Mobile
- ], [MODEL, [VENDOR, 'Swiss'], [TYPE, MOBILE]], [
-
- /android.+[;\/]\s*(zur\d{3})\s+build/i // Swiss ZUR Tablet
- ], [MODEL, [VENDOR, 'Swiss'], [TYPE, TABLET]], [
-
- /android.+[;\/]\s*((Zeki)?TB.*\b)\s+build/i // Zeki Tablets
- ], [MODEL, [VENDOR, 'Zeki'], [TYPE, TABLET]], [
-
- /(android).+[;\/]\s+([YR]\d{2})\s+build/i,
- /android.+[;\/]\s+(Dragon[\-\s]+Touch\s+|DT)(\w{5})\sbuild/i // Dragon Touch Tablet
- ], [[VENDOR, 'Dragon Touch'], MODEL, [TYPE, TABLET]], [
-
- /android.+[;\/]\s*(NS-?\w{0,9})\sbuild/i // Insignia Tablets
- ], [MODEL, [VENDOR, 'Insignia'], [TYPE, TABLET]], [
-
- /android.+[;\/]\s*((NX|Next)-?\w{0,9})\s+build/i // NextBook Tablets
- ], [MODEL, [VENDOR, 'NextBook'], [TYPE, TABLET]], [
-
- /android.+[;\/]\s*(Xtreme\_)?(V(1[045]|2[015]|30|40|60|7[05]|90))\s+build/i
- ], [[VENDOR, 'Voice'], MODEL, [TYPE, MOBILE]], [ // Voice Xtreme Phones
-
- /android.+[;\/]\s*(LVTEL\-)?(V1[12])\s+build/i // LvTel Phones
- ], [[VENDOR, 'LvTel'], MODEL, [TYPE, MOBILE]], [
-
- /android.+;\s(PH-1)\s/i
- ], [MODEL, [VENDOR, 'Essential'], [TYPE, MOBILE]], [ // Essential PH-1
-
- /android.+[;\/]\s*(V(100MD|700NA|7011|917G).*\b)\s+build/i // Envizen Tablets
- ], [MODEL, [VENDOR, 'Envizen'], [TYPE, TABLET]], [
-
- /android.+[;\/]\s*(Le[\s\-]+Pan)[\s\-]+(\w{1,9})\s+build/i // Le Pan Tablets
- ], [VENDOR, MODEL, [TYPE, TABLET]], [
-
- /android.+[;\/]\s*(Trio[\s\-]*.*)\s+build/i // MachSpeed Tablets
- ], [MODEL, [VENDOR, 'MachSpeed'], [TYPE, TABLET]], [
-
- /android.+[;\/]\s*(Trinity)[\-\s]*(T\d{3})\s+build/i // Trinity Tablets
- ], [VENDOR, MODEL, [TYPE, TABLET]], [
-
- /android.+[;\/]\s*TU_(1491)\s+build/i // Rotor Tablets
- ], [MODEL, [VENDOR, 'Rotor'], [TYPE, TABLET]], [
-
- /android.+(KS(.+))\s+build/i // Amazon Kindle Tablets
- ], [MODEL, [VENDOR, 'Amazon'], [TYPE, TABLET]], [
-
- /android.+(Gigaset)[\s\-]+(Q\w{1,9})\s+build/i // Gigaset Tablets
- ], [VENDOR, MODEL, [TYPE, TABLET]], [
-
- /\s(tablet|tab)[;\/]/i, // Unidentifiable Tablet
- /\s(mobile)(?:[;\/]|\ssafari)/i // Unidentifiable Mobile
- ], [[TYPE, util.lowerize], VENDOR, MODEL], [
-
- /[\s\/\(](smart-?tv)[;\)]/i // SmartTV
- ], [[TYPE, SMARTTV]], [
-
- /(android[\w\.\s\-]{0,9});.+build/i // Generic Android Device
- ], [MODEL, [VENDOR, 'Generic']]
- ],
-
- engine : [[
-
- /windows.+\sedge\/([\w\.]+)/i // EdgeHTML
- ], [VERSION, [NAME, 'EdgeHTML']], [
-
- /webkit\/537\.36.+chrome\/(?!27)([\w\.]+)/i // Blink
- ], [VERSION, [NAME, 'Blink']], [
-
- /(presto)\/([\w\.]+)/i, // Presto
- /(webkit|trident|netfront|netsurf|amaya|lynx|w3m|goanna)\/([\w\.]+)/i,
- // WebKit/Trident/NetFront/NetSurf/Amaya/Lynx/w3m/Goanna
- /(khtml|tasman|links)[\/\s]\(?([\w\.]+)/i, // KHTML/Tasman/Links
- /(icab)[\/\s]([23]\.[\d\.]+)/i // iCab
- ], [NAME, VERSION], [
-
- /rv\:([\w\.]{1,9}).+(gecko)/i // Gecko
- ], [VERSION, NAME]
- ],
-
- os : [[
-
- // Windows based
- /microsoft\s(windows)\s(vista|xp)/i // Windows (iTunes)
- ], [NAME, VERSION], [
- /(windows)\snt\s6\.2;\s(arm)/i, // Windows RT
- /(windows\sphone(?:\sos)*)[\s\/]?([\d\.\s\w]*)/i, // Windows Phone
- /(windows\smobile|windows)[\s\/]?([ntce\d\.\s]+\w)/i
- ], [NAME, [VERSION, mapper.str, maps.os.windows.version]], [
- /(win(?=3|9|n)|win\s9x\s)([nt\d\.]+)/i
- ], [[NAME, 'Windows'], [VERSION, mapper.str, maps.os.windows.version]], [
-
- // Mobile/Embedded OS
- /\((bb)(10);/i // BlackBerry 10
- ], [[NAME, 'BlackBerry'], VERSION], [
- /(blackberry)\w*\/?([\w\.]*)/i, // Blackberry
- /(tizen|kaios)[\/\s]([\w\.]+)/i, // Tizen/KaiOS
- /(android|webos|palm\sos|qnx|bada|rim\stablet\sos|meego|sailfish|contiki)[\/\s-]?([\w\.]*)/i
- // Android/WebOS/Palm/QNX/Bada/RIM/MeeGo/Contiki/Sailfish OS
- ], [NAME, VERSION], [
- /(symbian\s?os|symbos|s60(?=;))[\/\s-]?([\w\.]*)/i // Symbian
- ], [[NAME, 'Symbian'], VERSION], [
- /\((series40);/i // Series 40
- ], [NAME], [
- /mozilla.+\(mobile;.+gecko.+firefox/i // Firefox OS
- ], [[NAME, 'Firefox OS'], VERSION], [
-
- // Console
- /(nintendo|playstation)\s([wids34portablevu]+)/i, // Nintendo/Playstation
-
- // GNU/Linux based
- /(mint)[\/\s\(]?(\w*)/i, // Mint
- /(mageia|vectorlinux)[;\s]/i, // Mageia/VectorLinux
- /(joli|[kxln]?ubuntu|debian|suse|opensuse|gentoo|(?=\s)arch|slackware|fedora|mandriva|centos|pclinuxos|redhat|zenwalk|linpus)[\/\s-]?(?!chrom)([\w\.-]*)/i,
- // Joli/Ubuntu/Debian/SUSE/Gentoo/Arch/Slackware
- // Fedora/Mandriva/CentOS/PCLinuxOS/RedHat/Zenwalk/Linpus
- /(hurd|linux)\s?([\w\.]*)/i, // Hurd/Linux
- /(gnu)\s?([\w\.]*)/i // GNU
- ], [NAME, VERSION], [
-
- /(cros)\s[\w]+\s([\w\.]+\w)/i // Chromium OS
- ], [[NAME, 'Chromium OS'], VERSION],[
-
- // Solaris
- /(sunos)\s?([\w\.\d]*)/i // Solaris
- ], [[NAME, 'Solaris'], VERSION], [
-
- // BSD based
- /\s([frentopc-]{0,4}bsd|dragonfly)\s?([\w\.]*)/i // FreeBSD/NetBSD/OpenBSD/PC-BSD/DragonFly
- ], [NAME, VERSION],[
-
- /(haiku)\s(\w+)/i // Haiku
- ], [NAME, VERSION],[
-
- /cfnetwork\/.+darwin/i,
- /ip[honead]{2,4}(?:.*os\s([\w]+)\slike\smac|;\sopera)/i // iOS
- ], [[VERSION, /_/g, '.'], [NAME, 'iOS']], [
-
- /(mac\sos\sx)\s?([\w\s\.]*)/i,
- /(macintosh|mac(?=_powerpc)\s)/i // Mac OS
- ], [[NAME, 'Mac OS'], [VERSION, /_/g, '.']], [
-
- // Other
- /((?:open)?solaris)[\/\s-]?([\w\.]*)/i, // Solaris
- /(aix)\s((\d)(?=\.|\)|\s)[\w\.])*/i, // AIX
- /(plan\s9|minix|beos|os\/2|amigaos|morphos|risc\sos|openvms|fuchsia)/i,
- // Plan9/Minix/BeOS/OS2/AmigaOS/MorphOS/RISCOS/OpenVMS/Fuchsia
- /(unix)\s?([\w\.]*)/i // UNIX
- ], [NAME, VERSION]
- ]
- };
-
-
- /////////////////
- // Constructor
- ////////////////
- var UAParser = function (uastring, extensions) {
-
- if (typeof uastring === 'object') {
- extensions = uastring;
- uastring = undefined$1;
- }
-
- if (!(this instanceof UAParser)) {
- return new UAParser(uastring, extensions).getResult();
- }
-
- var ua = uastring || ((window && window.navigator && window.navigator.userAgent) ? window.navigator.userAgent : EMPTY);
- var rgxmap = extensions ? util.extend(regexes, extensions) : regexes;
-
- this.getBrowser = function () {
- var browser = { name: undefined$1, version: undefined$1 };
- mapper.rgx.call(browser, ua, rgxmap.browser);
- browser.major = util.major(browser.version); // deprecated
- return browser;
- };
- this.getCPU = function () {
- var cpu = { architecture: undefined$1 };
- mapper.rgx.call(cpu, ua, rgxmap.cpu);
- return cpu;
- };
- this.getDevice = function () {
- var device = { vendor: undefined$1, model: undefined$1, type: undefined$1 };
- mapper.rgx.call(device, ua, rgxmap.device);
- return device;
- };
- this.getEngine = function () {
- var engine = { name: undefined$1, version: undefined$1 };
- mapper.rgx.call(engine, ua, rgxmap.engine);
- return engine;
- };
- this.getOS = function () {
- var os = { name: undefined$1, version: undefined$1 };
- mapper.rgx.call(os, ua, rgxmap.os);
- return os;
- };
- this.getResult = function () {
- return {
- ua : this.getUA(),
- browser : this.getBrowser(),
- engine : this.getEngine(),
- os : this.getOS(),
- device : this.getDevice(),
- cpu : this.getCPU()
- };
- };
- this.getUA = function () {
- return ua;
- };
- this.setUA = function (uastring) {
- ua = uastring;
- return this;
- };
- return this;
- };
-
- UAParser.VERSION = LIBVERSION;
- UAParser.BROWSER = {
- NAME : NAME,
- MAJOR : MAJOR, // deprecated
- VERSION : VERSION
- };
- UAParser.CPU = {
- ARCHITECTURE : ARCHITECTURE
- };
- UAParser.DEVICE = {
- MODEL : MODEL,
- VENDOR : VENDOR,
- TYPE : TYPE,
- CONSOLE : CONSOLE,
- MOBILE : MOBILE,
- SMARTTV : SMARTTV,
- TABLET : TABLET,
- WEARABLE: WEARABLE,
- EMBEDDED: EMBEDDED
- };
- UAParser.ENGINE = {
- NAME : NAME,
- VERSION : VERSION
- };
- UAParser.OS = {
- NAME : NAME,
- VERSION : VERSION
- };
-
- ///////////
- // Export
- //////////
-
-
- // check js environment
- {
- // nodejs env
- if ( module.exports) {
- exports = module.exports = UAParser;
- }
- exports.UAParser = UAParser;
- }
-
- // jQuery/Zepto specific (optional)
- // Note:
- // In AMD env the global scope should be kept clean, but jQuery is an exception.
- // jQuery always exports to global scope, unless jQuery.noConflict(true) is used,
- // and we should catch that.
- var $ = window && (window.jQuery || window.Zepto);
- if ($ && !$.ua) {
- var parser = new UAParser();
- $.ua = parser.getResult();
- $.ua.get = function () {
- return parser.getUA();
- };
- $.ua.set = function (uastring) {
- parser.setUA(uastring);
- var result = parser.getResult();
- for (var prop in result) {
- $.ua[prop] = result[prop];
- }
- };
- }
-
- })(typeof window === 'object' ? window : _commonjsHelpers.commonjsGlobal);
- });
- var uaParser_1 = uaParser.UAParser;
-
- var UNKNOWN = 'Unknown';
-
- var PLATFORM_MAP = {
- 'Mac OS': 'Mac OS X'
- };
-
- /**
- * Convert from UAParser platform name to what we expect.
- */
- function convertPlatformName(name) {
- return PLATFORM_MAP[name] || name;
- }
-
- /**
- * Get the version number in parts. This is very naive. We actually get major
- * version as a part of UAParser already, which is generally good enough, but
- * let's get the minor just in case.
- */
- function getBrowserVersion(version) {
- if (!version) {
- return {
- major: '',
- minor: ''
- };
- }
- var parts = version.split('.');
- return {
- major: parts[0],
- minor: parts[1]
- };
- }
-
- /**
- * Get the UA data fom UAParser and then convert it to the format we're
- * expecting for our APIS.
- */
- var parser = new uaParser();
- var results = parser.getResult();
-
- // Do some conversion first.
- var browserVersionData = getBrowserVersion(results.browser.version);
- var uaData = {
- browserArchitecture: results.cpu.architecture || UNKNOWN,
- browserFullVersion: results.browser.version || UNKNOWN,
- browserMinorVersion: browserVersionData.minor || UNKNOWN,
- browserName: results.browser.name || UNKNOWN,
- browserVersion: results.browser.major || UNKNOWN,
- deviceName: results.device.model || UNKNOWN,
- engineName: results.engine.name || UNKNOWN,
- engineVersion: results.engine.version || UNKNOWN,
- platformArchitecture: results.cpu.architecture || UNKNOWN,
- platformName: convertPlatformName(results.os.name) || UNKNOWN,
- platformVersion: results.os.version || UNKNOWN,
- platformFullVersion: results.os.version || UNKNOWN
- };
-
- var UserAgentData = uaData;
-
- var componentRegex = /\./;
- var orRegex = /\|\|/;
- var rangeRegex = /\s+\-\s+/;
- var modifierRegex = /^(<=|<|=|>=|~>|~|>|)?\s*(.+)/;
- var numericRegex = /^(\d*)(.*)/;
-
- /**
- * Splits input `range` on "||" and returns true if any subrange matches
- * `version`.
- *
- * @param {string} range
- * @param {string} version
- * @returns {boolean}
- */
- function checkOrExpression(range, version) {
- var expressions = range.split(orRegex);
-
- if (expressions.length > 1) {
- return expressions.some(function (range) {
- return VersionRange.contains(range, version);
- });
- } else {
- range = expressions[0].trim();
- return checkRangeExpression(range, version);
- }
- }
-
- /**
- * Splits input `range` on " - " (the surrounding whitespace is required) and
- * returns true if version falls between the two operands.
- *
- * @param {string} range
- * @param {string} version
- * @returns {boolean}
- */
- function checkRangeExpression(range, version) {
- var expressions = range.split(rangeRegex);
-
- !(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;
-
- if (expressions.length === 1) {
- return checkSimpleExpression(expressions[0], version);
- } else {
- var startVersion = expressions[0],
- endVersion = expressions[1];
-
- !(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;
-
- return checkSimpleExpression('>=' + startVersion, version) && checkSimpleExpression('<=' + endVersion, version);
- }
- }
-
- /**
- * Checks if `range` matches `version`. `range` should be a "simple" range (ie.
- * not a compound range using the " - " or "||" operators).
- *
- * @param {string} range
- * @param {string} version
- * @returns {boolean}
- */
- function checkSimpleExpression(range, version) {
- range = range.trim();
- if (range === '') {
- return true;
- }
-
- var versionComponents = version.split(componentRegex);
-
- var _getModifierAndCompon = getModifierAndComponents(range),
- modifier = _getModifierAndCompon.modifier,
- rangeComponents = _getModifierAndCompon.rangeComponents;
-
- switch (modifier) {
- case '<':
- return checkLessThan(versionComponents, rangeComponents);
- case '<=':
- return checkLessThanOrEqual(versionComponents, rangeComponents);
- case '>=':
- return checkGreaterThanOrEqual(versionComponents, rangeComponents);
- case '>':
- return checkGreaterThan(versionComponents, rangeComponents);
- case '~':
- case '~>':
- return checkApproximateVersion(versionComponents, rangeComponents);
- default:
- return checkEqual(versionComponents, rangeComponents);
- }
- }
-
- /**
- * Checks whether `a` is less than `b`.
- *
- * @param {array<string>} a
- * @param {array<string>} b
- * @returns {boolean}
- */
- function checkLessThan(a, b) {
- return compareComponents(a, b) === -1;
- }
-
- /**
- * Checks whether `a` is less than or equal to `b`.
- *
- * @param {array<string>} a
- * @param {array<string>} b
- * @returns {boolean}
- */
- function checkLessThanOrEqual(a, b) {
- var result = compareComponents(a, b);
- return result === -1 || result === 0;
- }
-
- /**
- * Checks whether `a` is equal to `b`.
- *
- * @param {array<string>} a
- * @param {array<string>} b
- * @returns {boolean}
- */
- function checkEqual(a, b) {
- return compareComponents(a, b) === 0;
- }
-
- /**
- * Checks whether `a` is greater than or equal to `b`.
- *
- * @param {array<string>} a
- * @param {array<string>} b
- * @returns {boolean}
- */
- function checkGreaterThanOrEqual(a, b) {
- var result = compareComponents(a, b);
- return result === 1 || result === 0;
- }
-
- /**
- * Checks whether `a` is greater than `b`.
- *
- * @param {array<string>} a
- * @param {array<string>} b
- * @returns {boolean}
- */
- function checkGreaterThan(a, b) {
- return compareComponents(a, b) === 1;
- }
-
- /**
- * Checks whether `a` is "reasonably close" to `b` (as described in
- * https://www.npmjs.org/doc/misc/semver.html). For example, if `b` is "1.3.1"
- * then "reasonably close" is defined as ">= 1.3.1 and < 1.4".
- *
- * @param {array<string>} a
- * @param {array<string>} b
- * @returns {boolean}
- */
- function checkApproximateVersion(a, b) {
- var lowerBound = b.slice();
- var upperBound = b.slice();
-
- if (upperBound.length > 1) {
- upperBound.pop();
- }
- var lastIndex = upperBound.length - 1;
- var numeric = parseInt(upperBound[lastIndex], 10);
- if (isNumber(numeric)) {
- upperBound[lastIndex] = numeric + 1 + '';
- }
-
- return checkGreaterThanOrEqual(a, lowerBound) && checkLessThan(a, upperBound);
- }
-
- /**
- * Extracts the optional modifier (<, <=, =, >=, >, ~, ~>) and version
- * components from `range`.
- *
- * For example, given `range` ">= 1.2.3" returns an object with a `modifier` of
- * `">="` and `components` of `[1, 2, 3]`.
- *
- * @param {string} range
- * @returns {object}
- */
- function getModifierAndComponents(range) {
- var rangeComponents = range.split(componentRegex);
- var matches = rangeComponents[0].match(modifierRegex);
- !matches ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'expected regex to match but it did not') : invariant_1(false) : void 0;
-
- return {
- modifier: matches[1],
- rangeComponents: [matches[2]].concat(rangeComponents.slice(1))
- };
- }
-
- /**
- * Determines if `number` is a number.
- *
- * @param {mixed} number
- * @returns {boolean}
- */
- function isNumber(number) {
- return !isNaN(number) && isFinite(number);
- }
-
- /**
- * Tests whether `range` is a "simple" version number without any modifiers
- * (">", "~" etc).
- *
- * @param {string} range
- * @returns {boolean}
- */
- function isSimpleVersion(range) {
- return !getModifierAndComponents(range).modifier;
- }
-
- /**
- * Zero-pads array `array` until it is at least `length` long.
- *
- * @param {array} array
- * @param {number} length
- */
- function zeroPad(array, length) {
- for (var i = array.length; i < length; i++) {
- array[i] = '0';
- }
- }
-
- /**
- * Normalizes `a` and `b` in preparation for comparison by doing the following:
- *
- * - zero-pads `a` and `b`
- * - marks any "x", "X" or "*" component in `b` as equivalent by zero-ing it out
- * in both `a` and `b`
- * - marks any final "*" component in `b` as a greedy wildcard by zero-ing it
- * and all of its successors in `a`
- *
- * @param {array<string>} a
- * @param {array<string>} b
- * @returns {array<array<string>>}
- */
- function normalizeVersions(a, b) {
- a = a.slice();
- b = b.slice();
-
- zeroPad(a, b.length);
-
- // mark "x" and "*" components as equal
- for (var i = 0; i < b.length; i++) {
- var matches = b[i].match(/^[x*]$/i);
- if (matches) {
- b[i] = a[i] = '0';
-
- // final "*" greedily zeros all remaining components
- if (matches[0] === '*' && i === b.length - 1) {
- for (var j = i; j < a.length; j++) {
- a[j] = '0';
- }
- }
- }
- }
-
- zeroPad(b, a.length);
-
- return [a, b];
- }
-
- /**
- * Returns the numerical -- not the lexicographical -- ordering of `a` and `b`.
- *
- * For example, `10-alpha` is greater than `2-beta`.
- *
- * @param {string} a
- * @param {string} b
- * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
- * or greater than `b`, respectively
- */
- function compareNumeric(a, b) {
- var aPrefix = a.match(numericRegex)[1];
- var bPrefix = b.match(numericRegex)[1];
- var aNumeric = parseInt(aPrefix, 10);
- var bNumeric = parseInt(bPrefix, 10);
-
- if (isNumber(aNumeric) && isNumber(bNumeric) && aNumeric !== bNumeric) {
- return compare(aNumeric, bNumeric);
- } else {
- return compare(a, b);
- }
- }
-
- /**
- * Returns the ordering of `a` and `b`.
- *
- * @param {string|number} a
- * @param {string|number} b
- * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
- * or greater than `b`, respectively
- */
- function compare(a, b) {
- !(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;
-
- if (a > b) {
- return 1;
- } else if (a < b) {
- return -1;
- } else {
- return 0;
- }
- }
-
- /**
- * Compares arrays of version components.
- *
- * @param {array<string>} a
- * @param {array<string>} b
- * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
- * or greater than `b`, respectively
- */
- function compareComponents(a, b) {
- var _normalizeVersions = normalizeVersions(a, b),
- aNormalized = _normalizeVersions[0],
- bNormalized = _normalizeVersions[1];
-
- for (var i = 0; i < bNormalized.length; i++) {
- var result = compareNumeric(aNormalized[i], bNormalized[i]);
- if (result) {
- return result;
- }
- }
-
- return 0;
- }
-
- var VersionRange = {
- /**
- * Checks whether `version` satisfies the `range` specification.
- *
- * We support a subset of the expressions defined in
- * https://www.npmjs.org/doc/misc/semver.html:
- *
- * version Must match version exactly
- * =version Same as just version
- * >version Must be greater than version
- * >=version Must be greater than or equal to version
- * <version Must be less than version
- * <=version Must be less than or equal to version
- * ~version Must be at least version, but less than the next significant
- * revision above version:
- * "~1.2.3" is equivalent to ">= 1.2.3 and < 1.3"
- * ~>version Equivalent to ~version
- * 1.2.x Must match "1.2.x", where "x" is a wildcard that matches
- * anything
- * 1.2.* Similar to "1.2.x", but "*" in the trailing position is a
- * "greedy" wildcard, so will match any number of additional
- * components:
- * "1.2.*" will match "1.2.1", "1.2.1.1", "1.2.1.1.1" etc
- * * Any version
- * "" (Empty string) Same as *
- * v1 - v2 Equivalent to ">= v1 and <= v2"
- * r1 || r2 Passes if either r1 or r2 are satisfied
- *
- * @param {string} range
- * @param {string} version
- * @returns {boolean}
- */
- contains: function contains(range, version) {
- return checkOrExpression(range.trim(), version.trim());
- }
- };
-
- var VersionRange_1 = VersionRange;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- */
-
- var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
-
- /**
- * Executes the provided `callback` once for each enumerable own property in the
- * object and constructs a new object from the results. The `callback` is
- * invoked with three arguments:
- *
- * - the property value
- * - the property name
- * - the object being traversed
- *
- * Properties that are added after the call to `mapObject` will not be visited
- * by `callback`. If the values of existing properties are changed, the value
- * passed to `callback` will be the value at the time `mapObject` visits them.
- * Properties that are deleted before being visited are not visited.
- *
- * @grep function objectMap()
- * @grep function objMap()
- *
- * @param {?object} object
- * @param {function} callback
- * @param {*} context
- * @return {?object}
- */
- function mapObject(object, callback, context) {
- if (!object) {
- return null;
- }
- var result = {};
- for (var name in object) {
- if (hasOwnProperty$1.call(object, name)) {
- result[name] = callback.call(context, object[name], name, object);
- }
- }
- return result;
- }
-
- var mapObject_1 = mapObject;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- *
- * @typechecks static-only
- */
-
- /**
- * Memoizes the return value of a function that accepts one string argument.
- */
-
- function memoizeStringOnly(callback) {
- var cache = {};
- return function (string) {
- if (!cache.hasOwnProperty(string)) {
- cache[string] = callback.call(this, string);
- }
- return cache[string];
- };
- }
-
- var memoizeStringOnly_1 = memoizeStringOnly;
-
- /**
- * Checks to see whether `name` and `version` satisfy `query`.
- *
- * @param {string} name Name of the browser, device, engine or platform
- * @param {?string} version Version of the browser, engine or platform
- * @param {string} query Query of form "Name [range expression]"
- * @param {?function} normalizer Optional pre-processor for range expression
- * @return {boolean}
- */
- function compare$1(name, version, query, normalizer) {
- // check for exact match with no version
- if (name === query) {
- return true;
- }
-
- // check for non-matching names
- if (!query.startsWith(name)) {
- return false;
- }
-
- // full comparison with version
- var range = query.slice(name.length);
- if (version) {
- range = normalizer ? normalizer(range) : range;
- return VersionRange_1.contains(range, version);
- }
-
- return false;
- }
-
- /**
- * Normalizes `version` by stripping any "NT" prefix, but only on the Windows
- * platform.
- *
- * Mimics the stripping performed by the `UserAgentWindowsPlatform` PHP class.
- *
- * @param {string} version
- * @return {string}
- */
- function normalizePlatformVersion(version) {
- if (UserAgentData.platformName === 'Windows') {
- return version.replace(/^\s*NT/, '');
- }
-
- return version;
- }
-
- /**
- * Provides client-side access to the authoritative PHP-generated User Agent
- * information supplied by the server.
- */
- var UserAgent = {
- /**
- * Check if the User Agent browser matches `query`.
- *
- * `query` should be a string like "Chrome" or "Chrome > 33".
- *
- * Valid browser names include:
- *
- * - ACCESS NetFront
- * - AOL
- * - Amazon Silk
- * - Android
- * - BlackBerry
- * - BlackBerry PlayBook
- * - Chrome
- * - Chrome for iOS
- * - Chrome frame
- * - Facebook PHP SDK
- * - Facebook for iOS
- * - Firefox
- * - IE
- * - IE Mobile
- * - Mobile Safari
- * - Motorola Internet Browser
- * - Nokia
- * - Openwave Mobile Browser
- * - Opera
- * - Opera Mini
- * - Opera Mobile
- * - Safari
- * - UIWebView
- * - Unknown
- * - webOS
- * - etc...
- *
- * An authoritative list can be found in the PHP `BrowserDetector` class and
- * related classes in the same file (see calls to `new UserAgentBrowser` here:
- * https://fburl.com/50728104).
- *
- * @note Function results are memoized
- *
- * @param {string} query Query of the form "Name [range expression]"
- * @return {boolean}
- */
- isBrowser: function isBrowser(query) {
- return compare$1(UserAgentData.browserName, UserAgentData.browserFullVersion, query);
- },
-
-
- /**
- * Check if the User Agent browser uses a 32 or 64 bit architecture.
- *
- * @note Function results are memoized
- *
- * @param {string} query Query of the form "32" or "64".
- * @return {boolean}
- */
- isBrowserArchitecture: function isBrowserArchitecture(query) {
- return compare$1(UserAgentData.browserArchitecture, null, query);
- },
-
-
- /**
- * Check if the User Agent device matches `query`.
- *
- * `query` should be a string like "iPhone" or "iPad".
- *
- * Valid device names include:
- *
- * - Kindle
- * - Kindle Fire
- * - Unknown
- * - iPad
- * - iPhone
- * - iPod
- * - etc...
- *
- * An authoritative list can be found in the PHP `DeviceDetector` class and
- * related classes in the same file (see calls to `new UserAgentDevice` here:
- * https://fburl.com/50728332).
- *
- * @note Function results are memoized
- *
- * @param {string} query Query of the form "Name"
- * @return {boolean}
- */
- isDevice: function isDevice(query) {
- return compare$1(UserAgentData.deviceName, null, query);
- },
-
-
- /**
- * Check if the User Agent rendering engine matches `query`.
- *
- * `query` should be a string like "WebKit" or "WebKit >= 537".
- *
- * Valid engine names include:
- *
- * - Gecko
- * - Presto
- * - Trident
- * - WebKit
- * - etc...
- *
- * An authoritative list can be found in the PHP `RenderingEngineDetector`
- * class related classes in the same file (see calls to `new
- * UserAgentRenderingEngine` here: https://fburl.com/50728617).
- *
- * @note Function results are memoized
- *
- * @param {string} query Query of the form "Name [range expression]"
- * @return {boolean}
- */
- isEngine: function isEngine(query) {
- return compare$1(UserAgentData.engineName, UserAgentData.engineVersion, query);
- },
-
-
- /**
- * Check if the User Agent platform matches `query`.
- *
- * `query` should be a string like "Windows" or "iOS 5 - 6".
- *
- * Valid platform names include:
- *
- * - Android
- * - BlackBerry OS
- * - Java ME
- * - Linux
- * - Mac OS X
- * - Mac OS X Calendar
- * - Mac OS X Internet Account
- * - Symbian
- * - SymbianOS
- * - Windows
- * - Windows Mobile
- * - Windows Phone
- * - iOS
- * - iOS Facebook Integration Account
- * - iOS Facebook Social Sharing UI
- * - webOS
- * - Chrome OS
- * - etc...
- *
- * An authoritative list can be found in the PHP `PlatformDetector` class and
- * related classes in the same file (see calls to `new UserAgentPlatform`
- * here: https://fburl.com/50729226).
- *
- * @note Function results are memoized
- *
- * @param {string} query Query of the form "Name [range expression]"
- * @return {boolean}
- */
- isPlatform: function isPlatform(query) {
- return compare$1(UserAgentData.platformName, UserAgentData.platformFullVersion, query, normalizePlatformVersion);
- },
-
-
- /**
- * Check if the User Agent platform is a 32 or 64 bit architecture.
- *
- * @note Function results are memoized
- *
- * @param {string} query Query of the form "32" or "64".
- * @return {boolean}
- */
- isPlatformArchitecture: function isPlatformArchitecture(query) {
- return compare$1(UserAgentData.platformArchitecture, null, query);
- }
- };
-
- var UserAgent_1 = mapObject_1(UserAgent, memoizeStringOnly_1);
-
- function _classCallCheck$9(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
- 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; }
-
- 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; }
-
-
-
-
-
-
-
- // In IE, spans with <br> tags render as two newlines. By rendering a span
- // with only a newline character, we can be sure to render a single line.
- var useNewlineChar = UserAgent_1.isBrowser('IE <= 11');
-
- /**
- * Check whether the node should be considered a newline.
- */
- function isNewline(node) {
- return useNewlineChar ? node.textContent === '\n' : node.tagName === 'BR';
- }
-
- /**
- * Placeholder elements for empty text content.
- *
- * What is this `data-text` attribute, anyway? It turns out that we need to
- * put an attribute on the lowest-level text node in order to preserve correct
- * spellcheck handling. If the <span> is naked, Chrome and Safari may do
- * bizarre things to do the DOM -- split text nodes, create extra spans, etc.
- * If the <span> has an attribute, this appears not to happen.
- * See http://jsfiddle.net/9khdavod/ for the failure case, and
- * http://jsfiddle.net/7pg143f7/ for the fixed case.
- */
- var NEWLINE_A = useNewlineChar ? _reactDom_commonjsExternal.React.createElement(
- 'span',
- { key: 'A', 'data-text': 'true' },
- '\n'
- ) : _reactDom_commonjsExternal.React.createElement('br', { key: 'A', 'data-text': 'true' });
-
- var NEWLINE_B = useNewlineChar ? _reactDom_commonjsExternal.React.createElement(
- 'span',
- { key: 'B', 'data-text': 'true' },
- '\n'
- ) : _reactDom_commonjsExternal.React.createElement('br', { key: 'B', 'data-text': 'true' });
-
- /**
- * The lowest-level component in a `DraftEditor`, the text node component
- * replaces the default React text node implementation. This allows us to
- * perform custom handling of newline behavior and avoid re-rendering text
- * nodes with DOM state that already matches the expectations of our immutable
- * editor state.
- */
- var DraftEditorTextNode = function (_React$Component) {
- _inherits$6(DraftEditorTextNode, _React$Component);
-
- function DraftEditorTextNode(props) {
- _classCallCheck$9(this, DraftEditorTextNode);
-
- // By flipping this flag, we also keep flipping keys which forces
- // React to remount this node every time it rerenders.
- var _this = _possibleConstructorReturn$6(this, _React$Component.call(this, props));
-
- _this._forceFlag = false;
- return _this;
- }
-
- DraftEditorTextNode.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
- var node = _reactDom_commonjsExternal.require$$3.findDOMNode(this);
- var shouldBeNewline = nextProps.children === '';
- !(node instanceof Element) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'node is not an Element') : invariant_1(false) : void 0;
- if (shouldBeNewline) {
- return !isNewline(node);
- }
- return node.textContent !== nextProps.children;
- };
-
- DraftEditorTextNode.prototype.componentDidMount = function componentDidMount() {
- this._forceFlag = !this._forceFlag;
- };
-
- DraftEditorTextNode.prototype.componentDidUpdate = function componentDidUpdate() {
- this._forceFlag = !this._forceFlag;
- };
-
- DraftEditorTextNode.prototype.render = function render() {
- if (this.props.children === '') {
- return this._forceFlag ? NEWLINE_A : NEWLINE_B;
- }
- return _reactDom_commonjsExternal.React.createElement(
- 'span',
- { key: this._forceFlag ? 'A' : 'B', 'data-text': 'true' },
- this.props.children
- );
- };
-
- return DraftEditorTextNode;
- }(_reactDom_commonjsExternal.React.Component);
-
- var DraftEditorTextNode_react = DraftEditorTextNode;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule DraftJsDebugLogging
- */
-
- var DraftJsDebugLogging = {
- logSelectionStateFailure: function logSelectionStateFailure() {
- return null;
- }
- };
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- * @typechecks
- */
-
- /**
- * @param {*} object The object to check.
- * @return {boolean} Whether or not the object is a DOM node.
- */
- function isNode(object) {
- var doc = object ? object.ownerDocument || object : document;
- var defaultView = doc.defaultView || window;
- return !!(object && (typeof defaultView.Node === 'function' ? object instanceof defaultView.Node : typeof object === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string'));
- }
-
- var isNode_1 = isNode;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- * @typechecks
- */
-
-
-
- /**
- * @param {*} object The object to check.
- * @return {boolean} Whether or not the object is a DOM text node.
- */
- function isTextNode(object) {
- return isNode_1(object) && object.nodeType == 3;
- }
-
- var isTextNode_1 = isTextNode;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- *
- */
-
-
-
- /*eslint-disable no-bitwise */
-
- /**
- * Checks if a given DOM node contains or is another DOM node.
- */
- function containsNode(outerNode, innerNode) {
- if (!outerNode || !innerNode) {
- return false;
- } else if (outerNode === innerNode) {
- return true;
- } else if (isTextNode_1(outerNode)) {
- return false;
- } else if (isTextNode_1(innerNode)) {
- return containsNode(outerNode, innerNode.parentNode);
- } else if ('contains' in outerNode) {
- return outerNode.contains(innerNode);
- } else if (outerNode.compareDocumentPosition) {
- return !!(outerNode.compareDocumentPosition(innerNode) & 16);
- } else {
- return false;
- }
- }
-
- var containsNode_1 = containsNode;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- * @typechecks
- */
-
- /* eslint-disable fb-www/typeof-undefined */
-
- /**
- * Same as document.activeElement but wraps in a try-catch block. In IE it is
- * not safe to call document.activeElement if there is nothing focused.
- *
- * The activeElement will be null only if the document or document body is not
- * yet defined.
- *
- * @param {?DOMDocument} doc Defaults to current document.
- * @return {?DOMElement}
- */
- function getActiveElement(doc) /*?DOMElement*/{
- doc = doc || (typeof document !== 'undefined' ? document : undefined);
- if (typeof doc === 'undefined') {
- return null;
- }
- try {
- return doc.activeElement || doc.body;
- } catch (e) {
- return doc.body;
- }
- }
-
- var getActiveElement_1 = getActiveElement;
-
- function getAnonymizedDOM(node, getNodeLabels) {
- if (!node) {
- return '[empty]';
- }
-
- var anonymized = anonymizeTextWithin(node, getNodeLabels);
- if (anonymized.nodeType === Node.TEXT_NODE) {
- return anonymized.textContent;
- }
-
- !(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;
- return anonymized.outerHTML;
- }
-
- function anonymizeTextWithin(node, getNodeLabels) {
- var labels = getNodeLabels !== undefined ? getNodeLabels(node) : [];
-
- if (node.nodeType === Node.TEXT_NODE) {
- var length = node.textContent.length;
- return document.createTextNode('[text ' + length + (labels.length ? ' | ' + labels.join(', ') : '') + ']');
- }
-
- var clone = node.cloneNode();
- if (clone.nodeType === 1 && labels.length) {
- clone.setAttribute('data-labels', labels.join(', '));
- }
- var childNodes = node.childNodes;
- for (var ii = 0; ii < childNodes.length; ii++) {
- clone.appendChild(anonymizeTextWithin(childNodes[ii], getNodeLabels));
- }
-
- return clone;
- }
-
- function getAnonymizedEditorDOM(node, getNodeLabels) {
- // grabbing the DOM content of the Draft editor
- var currentNode = node;
- while (currentNode) {
- if (currentNode instanceof Element && currentNode.hasAttribute('contenteditable')) {
- // found the Draft editor container
- return getAnonymizedDOM(currentNode, getNodeLabels);
- } else {
- currentNode = currentNode.parentNode;
- }
- }
- return 'Could not find contentEditable parent of node';
- }
-
- function getNodeLength(node) {
- return node.nodeValue === null ? node.childNodes.length : node.nodeValue.length;
- }
-
- /**
- * In modern non-IE browsers, we can support both forward and backward
- * selections.
- *
- * Note: IE10+ supports the Selection object, but it does not support
- * the `extend` method, which means that even in modern IE, it's not possible
- * to programatically create a backward selection. Thus, for all IE
- * versions, we use the old IE API to create our selections.
- */
- function setDraftEditorSelection(selectionState, node, blockKey, nodeStart, nodeEnd) {
- // It's possible that the editor has been removed from the DOM but
- // our selection code doesn't know it yet. Forcing selection in
- // this case may lead to errors, so just bail now.
- if (!containsNode_1(document.documentElement, node)) {
- return;
- }
-
- var selection = _commonjsHelpers.commonjsGlobal.getSelection();
- var anchorKey = selectionState.getAnchorKey();
- var anchorOffset = selectionState.getAnchorOffset();
- var focusKey = selectionState.getFocusKey();
- var focusOffset = selectionState.getFocusOffset();
- var isBackward = selectionState.getIsBackward();
-
- // IE doesn't support backward selection. Swap key/offset pairs.
- if (!selection.extend && isBackward) {
- var tempKey = anchorKey;
- var tempOffset = anchorOffset;
- anchorKey = focusKey;
- anchorOffset = focusOffset;
- focusKey = tempKey;
- focusOffset = tempOffset;
- isBackward = false;
- }
-
- var hasAnchor = anchorKey === blockKey && nodeStart <= anchorOffset && nodeEnd >= anchorOffset;
-
- var hasFocus = focusKey === blockKey && nodeStart <= focusOffset && nodeEnd >= focusOffset;
-
- // If the selection is entirely bound within this node, set the selection
- // and be done.
- if (hasAnchor && hasFocus) {
- selection.removeAllRanges();
- addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
- addFocusToSelection(selection, node, focusOffset - nodeStart, selectionState);
- return;
- }
-
- if (!isBackward) {
- // If the anchor is within this node, set the range start.
- if (hasAnchor) {
- selection.removeAllRanges();
- addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
- }
-
- // If the focus is within this node, we can assume that we have
- // already set the appropriate start range on the selection, and
- // can simply extend the selection.
- if (hasFocus) {
- addFocusToSelection(selection, node, focusOffset - nodeStart, selectionState);
- }
- } else {
- // If this node has the focus, set the selection range to be a
- // collapsed range beginning here. Later, when we encounter the anchor,
- // we'll use this information to extend the selection.
- if (hasFocus) {
- selection.removeAllRanges();
- addPointToSelection(selection, node, focusOffset - nodeStart, selectionState);
- }
-
- // If this node has the anchor, we may assume that the correct
- // focus information is already stored on the selection object.
- // We keep track of it, reset the selection range, and extend it
- // back to the focus point.
- if (hasAnchor) {
- var storedFocusNode = selection.focusNode;
- var storedFocusOffset = selection.focusOffset;
-
- selection.removeAllRanges();
- addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
- addFocusToSelection(selection, storedFocusNode, storedFocusOffset, selectionState);
- }
- }
- }
-
- /**
- * Extend selection towards focus point.
- */
- function addFocusToSelection(selection, node, offset, selectionState) {
- var activeElement = getActiveElement_1();
- if (selection.extend && containsNode_1(activeElement, node)) {
- // If `extend` is called while another element has focus, an error is
- // thrown. We therefore disable `extend` if the active element is somewhere
- // other than the node we are selecting. This should only occur in Firefox,
- // since it is the only browser to support multiple selections.
- // See https://bugzilla.mozilla.org/show_bug.cgi?id=921444.
-
- // logging to catch bug that is being reported in t16250795
- if (offset > getNodeLength(node)) {
- // the call to 'selection.extend' is about to throw
- DraftJsDebugLogging.logSelectionStateFailure({
- anonymizedDom: getAnonymizedEditorDOM(node),
- extraParams: JSON.stringify({ offset: offset }),
- selectionState: JSON.stringify(selectionState.toJS())
- });
- }
-
- // logging to catch bug that is being reported in t18110632
- var nodeWasFocus = node === selection.focusNode;
- try {
- selection.extend(node, offset);
- } catch (e) {
- DraftJsDebugLogging.logSelectionStateFailure({
- anonymizedDom: getAnonymizedEditorDOM(node, function (n) {
- var labels = [];
- if (n === activeElement) {
- labels.push('active element');
- }
- if (n === selection.anchorNode) {
- labels.push('selection anchor node');
- }
- if (n === selection.focusNode) {
- labels.push('selection focus node');
- }
- return labels;
- }),
- extraParams: JSON.stringify({
- activeElementName: activeElement ? activeElement.nodeName : null,
- nodeIsFocus: node === selection.focusNode,
- nodeWasFocus: nodeWasFocus,
- selectionRangeCount: selection.rangeCount,
- selectionAnchorNodeName: selection.anchorNode ? selection.anchorNode.nodeName : null,
- selectionAnchorOffset: selection.anchorOffset,
- selectionFocusNodeName: selection.focusNode ? selection.focusNode.nodeName : null,
- selectionFocusOffset: selection.focusOffset,
- message: e ? '' + e : null,
- offset: offset
- }, null, 2),
- selectionState: JSON.stringify(selectionState.toJS(), null, 2)
- });
- // allow the error to be thrown -
- // better than continuing in a broken state
- throw e;
- }
- } else {
- // IE doesn't support extend. This will mean no backward selection.
- // Extract the existing selection range and add focus to it.
- // Additionally, clone the selection range. IE11 throws an
- // InvalidStateError when attempting to access selection properties
- // after the range is detached.
- var range = selection.getRangeAt(0);
- range.setEnd(node, offset);
- selection.addRange(range.cloneRange());
- }
- }
-
- function addPointToSelection(selection, node, offset, selectionState) {
- var range = document.createRange();
- // logging to catch bug that is being reported in t16250795
- if (offset > getNodeLength(node)) {
- // in this case we know that the call to 'range.setStart' is about to throw
- DraftJsDebugLogging.logSelectionStateFailure({
- anonymizedDom: getAnonymizedEditorDOM(node),
- extraParams: JSON.stringify({ offset: offset }),
- selectionState: JSON.stringify(selectionState.toJS())
- });
- }
- range.setStart(node, offset);
- selection.addRange(range);
- }
-
- var setDraftEditorSelection_1 = setDraftEditorSelection;
-
- function _classCallCheck$a(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
- 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; }
-
- 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; }
-
-
-
-
-
-
-
-
- /**
- * All leaf nodes in the editor are spans with single text nodes. Leaf
- * elements are styled based on the merging of an optional custom style map
- * and a default style map.
- *
- * `DraftEditorLeaf` also provides a wrapper for calling into the imperative
- * DOM Selection API. In this way, top-level components can declaratively
- * maintain the selection state.
- */
- var DraftEditorLeaf = function (_React$Component) {
- _inherits$7(DraftEditorLeaf, _React$Component);
-
- function DraftEditorLeaf() {
- _classCallCheck$a(this, DraftEditorLeaf);
-
- return _possibleConstructorReturn$7(this, _React$Component.apply(this, arguments));
- }
-
- DraftEditorLeaf.prototype._setSelection = function _setSelection() {
- var selection = this.props.selection;
-
- // If selection state is irrelevant to the parent block, no-op.
-
- if (selection == null || !selection.getHasFocus()) {
- return;
- }
-
- var _props = this.props,
- block = _props.block,
- start = _props.start,
- text = _props.text;
-
- var blockKey = block.getKey();
- var end = start + text.length;
- if (!selection.hasEdgeWithin(blockKey, start, end)) {
- return;
- }
-
- // Determine the appropriate target node for selection. If the child
- // is not a text node, it is a <br /> spacer. In this case, use the
- // <span> itself as the selection target.
- var node = _reactDom_commonjsExternal.require$$3.findDOMNode(this);
- !node ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing node') : invariant_1(false) : void 0;
- var child = node.firstChild;
- !child ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing child') : invariant_1(false) : void 0;
- var targetNode = void 0;
-
- if (child.nodeType === Node.TEXT_NODE) {
- targetNode = child;
- } else if (child.tagName === 'BR') {
- targetNode = node;
- } else {
- targetNode = child.firstChild;
- !targetNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing targetNode') : invariant_1(false) : void 0;
- }
-
- setDraftEditorSelection_1(selection, targetNode, blockKey, start, end);
- };
- /**
- * By making individual leaf instances aware of their context within
- * the text of the editor, we can set our selection range more
- * easily than we could in the non-React world.
- *
- * Note that this depends on our maintaining tight control over the
- * DOM structure of the DraftEditor component. If leaves had multiple
- * text nodes, this would be harder.
- */
-
- DraftEditorLeaf.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
- var leafNode = _reactDom_commonjsExternal.require$$3.findDOMNode(this.leaf);
- !leafNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing leafNode') : invariant_1(false) : void 0;
- return leafNode.textContent !== nextProps.text || nextProps.styleSet !== this.props.styleSet || nextProps.forceSelection;
- };
-
- DraftEditorLeaf.prototype.componentDidUpdate = function componentDidUpdate() {
- this._setSelection();
- };
-
- DraftEditorLeaf.prototype.componentDidMount = function componentDidMount() {
- this._setSelection();
- };
-
- DraftEditorLeaf.prototype.render = function render() {
- var _this2 = this;
-
- var block = this.props.block;
- var text = this.props.text;
-
- // If the leaf is at the end of its block and ends in a soft newline, append
- // an extra line feed character. Browsers collapse trailing newline
- // characters, which leaves the cursor in the wrong place after a
- // shift+enter. The extra character repairs this.
-
- if (text.endsWith('\n') && this.props.isLast) {
- text += '\n';
- }
-
- var _props2 = this.props,
- customStyleMap = _props2.customStyleMap,
- customStyleFn = _props2.customStyleFn,
- offsetKey = _props2.offsetKey,
- styleSet = _props2.styleSet;
-
- var styleObj = styleSet.reduce(function (map, styleName) {
- var mergedStyles = {};
- var style = customStyleMap[styleName];
-
- if (style !== undefined && map.textDecoration !== style.textDecoration) {
- // .trim() is necessary for IE9/10/11 and Edge
- mergedStyles.textDecoration = [map.textDecoration, style.textDecoration].join(' ').trim();
- }
-
- return objectAssign(map, style, mergedStyles);
- }, {});
-
- if (customStyleFn) {
- var newStyles = customStyleFn(styleSet, block);
- styleObj = objectAssign(styleObj, newStyles);
- }
-
- return _reactDom_commonjsExternal.React.createElement(
- 'span',
- {
- 'data-offset-key': offsetKey,
- ref: function ref(_ref) {
- return _this2.leaf = _ref;
- },
- style: styleObj },
- _reactDom_commonjsExternal.React.createElement(
- DraftEditorTextNode_react,
- null,
- text
- )
- );
- };
-
- return DraftEditorLeaf;
- }(_reactDom_commonjsExternal.React.Component);
-
- var DraftEditorLeaf_react = DraftEditorLeaf;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule DraftOffsetKey
- * @format
- *
- */
-
- var KEY_DELIMITER = '-';
-
- var DraftOffsetKey = {
- encode: function encode(blockKey, decoratorKey, leafKey) {
- return blockKey + KEY_DELIMITER + decoratorKey + KEY_DELIMITER + leafKey;
- },
-
- decode: function decode(offsetKey) {
- var _offsetKey$split = offsetKey.split(KEY_DELIMITER),
- blockKey = _offsetKey$split[0],
- decoratorKey = _offsetKey$split[1],
- leafKey = _offsetKey$split[2];
-
- return {
- blockKey: blockKey,
- decoratorKey: parseInt(decoratorKey, 10),
- leafKey: parseInt(leafKey, 10)
- };
- }
- };
-
- var DraftOffsetKey_1 = DraftOffsetKey;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- */
-
- /**
- * @param {DOMElement} element
- * @param {DOMDocument} doc
- * @return {boolean}
- */
- function _isViewportScrollElement(element, doc) {
- return !!doc && (element === doc.documentElement || element === doc.body);
- }
-
- /**
- * Scroll Module. This class contains 4 simple static functions
- * to be used to access Element.scrollTop/scrollLeft properties.
- * To solve the inconsistencies between browsers when either
- * document.body or document.documentElement is supplied,
- * below logic will be used to alleviate the issue:
- *
- * 1. If 'element' is either 'document.body' or 'document.documentElement,
- * get whichever element's 'scroll{Top,Left}' is larger.
- * 2. If 'element' is either 'document.body' or 'document.documentElement',
- * set the 'scroll{Top,Left}' on both elements.
- */
-
- var Scroll = {
- /**
- * @param {DOMElement} element
- * @return {number}
- */
- getTop: function getTop(element) {
- var doc = element.ownerDocument;
- return _isViewportScrollElement(element, doc) ?
- // In practice, they will either both have the same value,
- // or one will be zero and the other will be the scroll position
- // of the viewport. So we can use `X || Y` instead of `Math.max(X, Y)`
- doc.body.scrollTop || doc.documentElement.scrollTop : element.scrollTop;
- },
-
- /**
- * @param {DOMElement} element
- * @param {number} newTop
- */
- setTop: function setTop(element, newTop) {
- var doc = element.ownerDocument;
- if (_isViewportScrollElement(element, doc)) {
- doc.body.scrollTop = doc.documentElement.scrollTop = newTop;
- } else {
- element.scrollTop = newTop;
- }
- },
-
- /**
- * @param {DOMElement} element
- * @return {number}
- */
- getLeft: function getLeft(element) {
- var doc = element.ownerDocument;
- return _isViewportScrollElement(element, doc) ? doc.body.scrollLeft || doc.documentElement.scrollLeft : element.scrollLeft;
- },
-
- /**
- * @param {DOMElement} element
- * @param {number} newLeft
- */
- setLeft: function setLeft(element, newLeft) {
- var doc = element.ownerDocument;
- if (_isViewportScrollElement(element, doc)) {
- doc.body.scrollLeft = doc.documentElement.scrollLeft = newLeft;
- } else {
- element.scrollLeft = newLeft;
- }
- }
- };
-
- var Scroll_1 = Scroll;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- * @typechecks
- */
-
- var _hyphenPattern = /-(.)/g;
-
- /**
- * Camelcases a hyphenated string, for example:
- *
- * > camelize('background-color')
- * < "backgroundColor"
- *
- * @param {string} string
- * @return {string}
- */
- function camelize(string) {
- return string.replace(_hyphenPattern, function (_, character) {
- return character.toUpperCase();
- });
- }
-
- var camelize_1 = camelize;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- * @typechecks
- */
-
- var _uppercasePattern = /([A-Z])/g;
-
- /**
- * Hyphenates a camelcased string, for example:
- *
- * > hyphenate('backgroundColor')
- * < "background-color"
- *
- * For CSS style names, use `hyphenateStyleName` instead which works properly
- * with all vendor prefixes, including `ms`.
- *
- * @param {string} string
- * @return {string}
- */
- function hyphenate(string) {
- return string.replace(_uppercasePattern, '-$1').toLowerCase();
- }
-
- var hyphenate_1 = hyphenate;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- * @typechecks
- */
-
-
-
-
- function asString(value) /*?string*/{
- return value == null ? value : String(value);
- }
-
- function getStyleProperty( /*DOMNode*/node, /*string*/name) /*?string*/{
- var computedStyle = void 0;
-
- // W3C Standard
- if (window.getComputedStyle) {
- // In certain cases such as within an iframe in FF3, this returns null.
- computedStyle = window.getComputedStyle(node, null);
- if (computedStyle) {
- return asString(computedStyle.getPropertyValue(hyphenate_1(name)));
- }
- }
- // Safari
- if (document.defaultView && document.defaultView.getComputedStyle) {
- computedStyle = document.defaultView.getComputedStyle(node, null);
- // A Safari bug causes this to return null for `display: none` elements.
- if (computedStyle) {
- return asString(computedStyle.getPropertyValue(hyphenate_1(name)));
- }
- if (name === 'display') {
- return 'none';
- }
- }
- // Internet Explorer
- if (node.currentStyle) {
- if (name === 'float') {
- return asString(node.currentStyle.cssFloat || node.currentStyle.styleFloat);
- }
- return asString(node.currentStyle[camelize_1(name)]);
- }
- return asString(node.style && node.style[camelize_1(name)]);
- }
-
- var getStyleProperty_1 = getStyleProperty;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- * @typechecks
- */
-
-
-
- /**
- * @param {DOMNode} element [description]
- * @param {string} name Overflow style property name.
- * @return {boolean} True if the supplied ndoe is scrollable.
- */
- function _isNodeScrollable(element, name) {
- var overflow = Style.get(element, name);
- return overflow === 'auto' || overflow === 'scroll';
- }
-
- /**
- * Utilities for querying and mutating style properties.
- */
- var Style = {
- /**
- * Gets the style property for the supplied node. This will return either the
- * computed style, if available, or the declared style.
- *
- * @param {DOMNode} node
- * @param {string} name Style property name.
- * @return {?string} Style property value.
- */
- get: getStyleProperty_1,
-
- /**
- * Determines the nearest ancestor of a node that is scrollable.
- *
- * NOTE: This can be expensive if used repeatedly or on a node nested deeply.
- *
- * @param {?DOMNode} node Node from which to start searching.
- * @return {?DOMWindow|DOMElement} Scroll parent of the supplied node.
- */
- getScrollParent: function getScrollParent(node) {
- if (!node) {
- return null;
- }
- var ownerDocument = node.ownerDocument;
- while (node && node !== ownerDocument.body) {
- if (_isNodeScrollable(node, 'overflow') || _isNodeScrollable(node, 'overflowY') || _isNodeScrollable(node, 'overflowX')) {
- return node;
- }
- node = node.parentNode;
- }
- return ownerDocument.defaultView || ownerDocument.parentWindow;
- }
-
- };
-
- var Style_1 = Style;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- * @typechecks
- */
-
-
-
- /**
- * Gets an element's bounding rect in pixels relative to the viewport.
- *
- * @param {DOMElement} elem
- * @return {object}
- */
- function getElementRect(elem) {
- var docElem = elem.ownerDocument.documentElement;
-
- // FF 2, Safari 3 and Opera 9.5- do not support getBoundingClientRect().
- // IE9- will throw if the element is not in the document.
- if (!('getBoundingClientRect' in elem) || !containsNode_1(docElem, elem)) {
- return {
- left: 0,
- right: 0,
- top: 0,
- bottom: 0
- };
- }
-
- // Subtracts clientTop/Left because IE8- added a 2px border to the
- // <html> element (see http://fburl.com/1493213). IE 7 in
- // Quicksmode does not report clientLeft/clientTop so there
- // will be an unaccounted offset of 2px when in quirksmode
- var rect = elem.getBoundingClientRect();
-
- return {
- left: Math.round(rect.left) - docElem.clientLeft,
- right: Math.round(rect.right) - docElem.clientLeft,
- top: Math.round(rect.top) - docElem.clientTop,
- bottom: Math.round(rect.bottom) - docElem.clientTop
- };
- }
-
- var getElementRect_1 = getElementRect;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- * @typechecks
- */
-
-
-
- /**
- * Gets an element's position in pixels relative to the viewport. The returned
- * object represents the position of the element's top left corner.
- *
- * @param {DOMElement} element
- * @return {object}
- */
- function getElementPosition(element) {
- var rect = getElementRect_1(element);
- return {
- x: rect.left,
- y: rect.top,
- width: rect.right - rect.left,
- height: rect.bottom - rect.top
- };
- }
-
- var getElementPosition_1 = getElementPosition;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- * @typechecks
- */
-
- var isWebkit = typeof navigator !== 'undefined' && navigator.userAgent.indexOf('AppleWebKit') > -1;
-
- /**
- * Gets the element with the document scroll properties such as `scrollLeft` and
- * `scrollHeight`. This may differ across different browsers.
- *
- * NOTE: The return value can be null if the DOM is not yet ready.
- *
- * @param {?DOMDocument} doc Defaults to current document.
- * @return {?DOMElement}
- */
- function getDocumentScrollElement(doc) {
- doc = doc || document;
- if (doc.scrollingElement) {
- return doc.scrollingElement;
- }
- return !isWebkit && doc.compatMode === 'CSS1Compat' ? doc.documentElement : doc.body;
- }
-
- var getDocumentScrollElement_1 = getDocumentScrollElement;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- * @typechecks
- */
-
- /**
- * Gets the scroll position of the supplied element or window.
- *
- * The return values are unbounded, unlike `getScrollPosition`. This means they
- * may be negative or exceed the element boundaries (which is possible using
- * inertial scrolling).
- *
- * @param {DOMWindow|DOMElement} scrollable
- * @return {object} Map with `x` and `y` keys.
- */
-
- function getUnboundedScrollPosition(scrollable) {
- if (scrollable.Window && scrollable instanceof scrollable.Window) {
- return {
- x: scrollable.pageXOffset || scrollable.document.documentElement.scrollLeft,
- y: scrollable.pageYOffset || scrollable.document.documentElement.scrollTop
- };
- }
- return {
- x: scrollable.scrollLeft,
- y: scrollable.scrollTop
- };
- }
-
- var getUnboundedScrollPosition_1 = getUnboundedScrollPosition;
-
- /**
- * Gets the scroll position of the supplied element or window.
- *
- * The return values are bounded. This means that if the scroll position is
- * negative or exceeds the element boundaries (which is possible using inertial
- * scrolling), you will get zero or the maximum scroll position, respectively.
- *
- * If you need the unbound scroll position, use `getUnboundedScrollPosition`.
- *
- * @param {DOMWindow|DOMElement} scrollable
- * @return {object} Map with `x` and `y` keys.
- */
- function getScrollPosition(scrollable) {
- var documentScrollElement = getDocumentScrollElement_1(scrollable.ownerDocument || scrollable.document);
- if (scrollable.Window && scrollable instanceof scrollable.Window) {
- scrollable = documentScrollElement;
- }
- var scrollPosition = getUnboundedScrollPosition_1(scrollable);
-
- var viewport = scrollable === documentScrollElement ? scrollable.ownerDocument.documentElement : scrollable;
-
- var xMax = scrollable.scrollWidth - viewport.clientWidth;
- var yMax = scrollable.scrollHeight - viewport.clientHeight;
-
- scrollPosition.x = Math.max(0, Math.min(scrollPosition.x, xMax));
- scrollPosition.y = Math.max(0, Math.min(scrollPosition.y, yMax));
-
- return scrollPosition;
- }
-
- var getScrollPosition_1 = getScrollPosition;
-
- function getViewportWidth() {
- var width = void 0;
- if (document.documentElement) {
- width = document.documentElement.clientWidth;
- }
-
- if (!width && document.body) {
- width = document.body.clientWidth;
- }
-
- return width || 0;
- } /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- *
- * @typechecks
- */
-
- function getViewportHeight() {
- var height = void 0;
- if (document.documentElement) {
- height = document.documentElement.clientHeight;
- }
-
- if (!height && document.body) {
- height = document.body.clientHeight;
- }
-
- return height || 0;
- }
-
- /**
- * Gets the viewport dimensions including any scrollbars.
- */
- function getViewportDimensions() {
- return {
- width: window.innerWidth || getViewportWidth(),
- height: window.innerHeight || getViewportHeight()
- };
- }
-
- /**
- * Gets the viewport dimensions excluding any scrollbars.
- */
- getViewportDimensions.withoutScrollbars = function () {
- return {
- width: getViewportWidth(),
- height: getViewportHeight()
- };
- };
-
- var getViewportDimensions_1 = getViewportDimensions;
-
- 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; };
-
- function _classCallCheck$b(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
- 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; }
-
- 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; }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var SCROLL_BUFFER = 10;
-
- /**
- * Return whether a block overlaps with either edge of the `SelectionState`.
- */
- var isBlockOnSelectionEdge = function isBlockOnSelectionEdge(selection, key) {
- return selection.getAnchorKey() === key || selection.getFocusKey() === key;
- };
-
- /**
- * The default block renderer for a `DraftEditor` component.
- *
- * A `DraftEditorBlock` is able to render a given `ContentBlock` to its
- * appropriate decorator and inline style components.
- */
-
- var DraftEditorBlock = function (_React$Component) {
- _inherits$8(DraftEditorBlock, _React$Component);
-
- function DraftEditorBlock() {
- _classCallCheck$b(this, DraftEditorBlock);
-
- return _possibleConstructorReturn$8(this, _React$Component.apply(this, arguments));
- }
-
- DraftEditorBlock.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
- return this.props.block !== nextProps.block || this.props.tree !== nextProps.tree || this.props.direction !== nextProps.direction || isBlockOnSelectionEdge(nextProps.selection, nextProps.block.getKey()) && nextProps.forceSelection;
- };
-
- /**
- * When a block is mounted and overlaps the selection state, we need to make
- * sure that the cursor is visible to match native behavior. This may not
- * be the case if the user has pressed `RETURN` or pasted some content, since
- * programatically creating these new blocks and setting the DOM selection
- * will miss out on the browser natively scrolling to that position.
- *
- * To replicate native behavior, if the block overlaps the selection state
- * on mount, force the scroll position. Check the scroll state of the scroll
- * parent, and adjust it to align the entire block to the bottom of the
- * scroll parent.
- */
-
-
- DraftEditorBlock.prototype.componentDidMount = function componentDidMount() {
- var selection = this.props.selection;
- var endKey = selection.getEndKey();
- if (!selection.getHasFocus() || endKey !== this.props.block.getKey()) {
- return;
- }
-
- var blockNode = _reactDom_commonjsExternal.require$$3.findDOMNode(this);
- var scrollParent = Style_1.getScrollParent(blockNode);
- var scrollPosition = getScrollPosition_1(scrollParent);
- var scrollDelta = void 0;
-
- if (scrollParent === window) {
- var nodePosition = getElementPosition_1(blockNode);
- var nodeBottom = nodePosition.y + nodePosition.height;
- var viewportHeight = getViewportDimensions_1().height;
- scrollDelta = nodeBottom - viewportHeight;
- if (scrollDelta > 0) {
- window.scrollTo(scrollPosition.x, scrollPosition.y + scrollDelta + SCROLL_BUFFER);
- }
- } else {
- !(blockNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'blockNode is not an HTMLElement') : invariant_1(false) : void 0;
- var blockBottom = blockNode.offsetHeight + blockNode.offsetTop;
- var scrollBottom = scrollParent.offsetHeight + scrollPosition.y;
- scrollDelta = blockBottom - scrollBottom;
- if (scrollDelta > 0) {
- Scroll_1.setTop(scrollParent, Scroll_1.getTop(scrollParent) + scrollDelta + SCROLL_BUFFER);
- }
- }
- };
-
- DraftEditorBlock.prototype._renderChildren = function _renderChildren() {
- var _this2 = this;
-
- var block = this.props.block;
- var blockKey = block.getKey();
- var text = block.getText();
- var lastLeafSet = this.props.tree.size - 1;
- var hasSelection = isBlockOnSelectionEdge(this.props.selection, blockKey);
-
- return this.props.tree.map(function (leafSet, ii) {
- var leavesForLeafSet = leafSet.get('leaves');
- var lastLeaf = leavesForLeafSet.size - 1;
- var leaves = leavesForLeafSet.map(function (leaf, jj) {
- var offsetKey = DraftOffsetKey_1.encode(blockKey, ii, jj);
- var start = leaf.get('start');
- var end = leaf.get('end');
- return _reactDom_commonjsExternal.React.createElement(DraftEditorLeaf_react, {
- key: offsetKey,
- offsetKey: offsetKey,
- block: block,
- start: start,
- selection: hasSelection ? _this2.props.selection : null,
- forceSelection: _this2.props.forceSelection,
- text: text.slice(start, end),
- styleSet: block.getInlineStyleAt(start),
- customStyleMap: _this2.props.customStyleMap,
- customStyleFn: _this2.props.customStyleFn,
- isLast: ii === lastLeafSet && jj === lastLeaf
- });
- }).toArray();
-
- var decoratorKey = leafSet.get('decoratorKey');
- if (decoratorKey == null) {
- return leaves;
- }
-
- if (!_this2.props.decorator) {
- return leaves;
- }
-
- var decorator = nullthrows_1(_this2.props.decorator);
-
- var DecoratorComponent = decorator.getComponentForKey(decoratorKey);
- if (!DecoratorComponent) {
- return leaves;
- }
-
- var decoratorProps = decorator.getPropsForKey(decoratorKey);
- var decoratorOffsetKey = DraftOffsetKey_1.encode(blockKey, ii, 0);
- var decoratedText = text.slice(leavesForLeafSet.first().get('start'), leavesForLeafSet.last().get('end'));
-
- // Resetting dir to the same value on a child node makes Chrome/Firefox
- // confused on cursor movement. See http://jsfiddle.net/d157kLck/3/
- var dir = UnicodeBidiDirection_1.getHTMLDirIfDifferent(UnicodeBidi_1.getDirection(decoratedText), _this2.props.direction);
-
- return _reactDom_commonjsExternal.React.createElement(
- DecoratorComponent,
- _extends$2({}, decoratorProps, {
- contentState: _this2.props.contentState,
- decoratedText: decoratedText,
- dir: dir,
- key: decoratorOffsetKey,
- entityKey: block.getEntityAt(leafSet.get('start')),
- offsetKey: decoratorOffsetKey }),
- leaves
- );
- }).toArray();
- };
-
- DraftEditorBlock.prototype.render = function render() {
- var _props = this.props,
- direction = _props.direction,
- offsetKey = _props.offsetKey;
-
- var className = cx_1({
- 'public/DraftStyleDefault/block': true,
- 'public/DraftStyleDefault/ltr': direction === 'LTR',
- 'public/DraftStyleDefault/rtl': direction === 'RTL'
- });
-
- return _reactDom_commonjsExternal.React.createElement(
- 'div',
- { 'data-offset-key': offsetKey, className: className },
- this._renderChildren()
- );
- };
-
- return DraftEditorBlock;
- }(_reactDom_commonjsExternal.React.Component);
-
- var DraftEditorBlock_react = DraftEditorBlock;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- * @typechecks static-only
- */
-
- /**
- * Combines multiple className strings into one.
- * http://jsperf.com/joinclasses-args-vs-array
- *
- * @param {...?string} className
- * @return {string}
- */
-
- function joinClasses(className /*, ... */) {
- if (!className) {
- className = '';
- }
- var nextClass = void 0;
- var argLength = arguments.length;
- if (argLength > 1) {
- for (var ii = 1; ii < argLength; ii++) {
- nextClass = arguments[ii];
- if (nextClass) {
- className = (className ? className + ' ' : '') + nextClass;
- }
- }
- }
- return className;
- }
-
- var joinClasses_1 = joinClasses;
-
- 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; };
-
- function _classCallCheck$c(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
- 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; }
-
- 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; }
-
-
-
-
-
-
-
-
-
-
- /**
- * Provide default styling for list items. This way, lists will be styled with
- * proper counters and indentation even if the caller does not specify
- * their own styling at all. If more than five levels of nesting are needed,
- * the necessary CSS classes can be provided via `blockStyleFn` configuration.
- */
- var getListItemClasses = function getListItemClasses(type, depth, shouldResetCount, direction) {
- return cx_1({
- 'public/DraftStyleDefault/unorderedListItem': type === 'unordered-list-item',
- 'public/DraftStyleDefault/orderedListItem': type === 'ordered-list-item',
- 'public/DraftStyleDefault/reset': shouldResetCount,
- 'public/DraftStyleDefault/depth0': depth === 0,
- 'public/DraftStyleDefault/depth1': depth === 1,
- 'public/DraftStyleDefault/depth2': depth === 2,
- 'public/DraftStyleDefault/depth3': depth === 3,
- 'public/DraftStyleDefault/depth4': depth === 4,
- 'public/DraftStyleDefault/listLTR': direction === 'LTR',
- 'public/DraftStyleDefault/listRTL': direction === 'RTL'
- });
- };
-
- /**
- * `DraftEditorContents` is the container component for all block components
- * rendered for a `DraftEditor`. It is optimized to aggressively avoid
- * re-rendering blocks whenever possible.
- *
- * This component is separate from `DraftEditor` because certain props
- * (for instance, ARIA props) must be allowed to update without affecting
- * the contents of the editor.
- */
-
- var DraftEditorContents = function (_React$Component) {
- _inherits$9(DraftEditorContents, _React$Component);
-
- function DraftEditorContents() {
- _classCallCheck$c(this, DraftEditorContents);
-
- return _possibleConstructorReturn$9(this, _React$Component.apply(this, arguments));
- }
-
- DraftEditorContents.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
- var prevEditorState = this.props.editorState;
- var nextEditorState = nextProps.editorState;
-
- var prevDirectionMap = prevEditorState.getDirectionMap();
- var nextDirectionMap = nextEditorState.getDirectionMap();
-
- // Text direction has changed for one or more blocks. We must re-render.
- if (prevDirectionMap !== nextDirectionMap) {
- return true;
- }
-
- var didHaveFocus = prevEditorState.getSelection().getHasFocus();
- var nowHasFocus = nextEditorState.getSelection().getHasFocus();
-
- if (didHaveFocus !== nowHasFocus) {
- return true;
- }
-
- var nextNativeContent = nextEditorState.getNativelyRenderedContent();
-
- var wasComposing = prevEditorState.isInCompositionMode();
- var nowComposing = nextEditorState.isInCompositionMode();
-
- // If the state is unchanged or we're currently rendering a natively
- // rendered state, there's nothing new to be done.
- if (prevEditorState === nextEditorState || nextNativeContent !== null && nextEditorState.getCurrentContent() === nextNativeContent || wasComposing && nowComposing) {
- return false;
- }
-
- var prevContent = prevEditorState.getCurrentContent();
- var nextContent = nextEditorState.getCurrentContent();
- var prevDecorator = prevEditorState.getDecorator();
- var nextDecorator = nextEditorState.getDecorator();
- return wasComposing !== nowComposing || prevContent !== nextContent || prevDecorator !== nextDecorator || nextEditorState.mustForceSelection();
- };
-
- DraftEditorContents.prototype.render = function render() {
- var _props = this.props,
- blockRenderMap = _props.blockRenderMap,
- blockRendererFn = _props.blockRendererFn,
- blockStyleFn = _props.blockStyleFn,
- customStyleMap = _props.customStyleMap,
- customStyleFn = _props.customStyleFn,
- editorState = _props.editorState,
- editorKey = _props.editorKey,
- textDirectionality = _props.textDirectionality;
-
-
- var content = editorState.getCurrentContent();
- var selection = editorState.getSelection();
- var forceSelection = editorState.mustForceSelection();
- var decorator = editorState.getDecorator();
- var directionMap = nullthrows_1(editorState.getDirectionMap());
-
- var blocksAsArray = content.getBlocksAsArray();
- var processedBlocks = [];
-
- var currentDepth = null;
- var lastWrapperTemplate = null;
-
- for (var ii = 0; ii < blocksAsArray.length; ii++) {
- var _block = blocksAsArray[ii];
- var key = _block.getKey();
- var blockType = _block.getType();
-
- var customRenderer = blockRendererFn(_block);
- var CustomComponent = void 0,
- customProps = void 0,
- customEditable = void 0;
- if (customRenderer) {
- CustomComponent = customRenderer.component;
- customProps = customRenderer.props;
- customEditable = customRenderer.editable;
- }
-
- var direction = textDirectionality ? textDirectionality : directionMap.get(key);
- var offsetKey = DraftOffsetKey_1.encode(key, 0, 0);
- var componentProps = {
- contentState: content,
- block: _block,
- blockProps: customProps,
- blockStyleFn: blockStyleFn,
- customStyleMap: customStyleMap,
- customStyleFn: customStyleFn,
- decorator: decorator,
- direction: direction,
- forceSelection: forceSelection,
- key: key,
- offsetKey: offsetKey,
- selection: selection,
- tree: editorState.getBlockTree(key)
- };
-
- var configForType = blockRenderMap.get(blockType) || blockRenderMap.get('unstyled');
- var wrapperTemplate = configForType.wrapper;
-
- var Element = configForType.element || blockRenderMap.get('unstyled').element;
-
- var depth = _block.getDepth();
- var className = '';
- if (blockStyleFn) {
- className = blockStyleFn(_block);
- }
-
- // List items are special snowflakes, since we handle nesting and
- // counters manually.
- if (Element === 'li') {
- var shouldResetCount = lastWrapperTemplate !== wrapperTemplate || currentDepth === null || depth > currentDepth;
- className = joinClasses_1(className, getListItemClasses(blockType, depth, shouldResetCount, direction));
- }
-
- var Component = CustomComponent || DraftEditorBlock_react;
- var childProps = {
- className: className,
- 'data-block': true,
- 'data-editor': editorKey,
- 'data-offset-key': offsetKey,
- key: key
- };
- if (customEditable !== undefined) {
- childProps = _extends$3({}, childProps, {
- contentEditable: customEditable,
- suppressContentEditableWarning: true
- });
- }
-
- var child = _reactDom_commonjsExternal.React.createElement(Element, childProps, _reactDom_commonjsExternal.React.createElement(Component, componentProps));
-
- processedBlocks.push({
- block: child,
- wrapperTemplate: wrapperTemplate,
- key: key,
- offsetKey: offsetKey
- });
-
- if (wrapperTemplate) {
- currentDepth = _block.getDepth();
- } else {
- currentDepth = null;
- }
- lastWrapperTemplate = wrapperTemplate;
- }
-
- // Group contiguous runs of blocks that have the same wrapperTemplate
- var outputBlocks = [];
- for (var _ii = 0; _ii < processedBlocks.length;) {
- var info = processedBlocks[_ii];
- if (info.wrapperTemplate) {
- var blocks = [];
- do {
- blocks.push(processedBlocks[_ii].block);
- _ii++;
- } while (_ii < processedBlocks.length && processedBlocks[_ii].wrapperTemplate === info.wrapperTemplate);
- var wrapperElement = _reactDom_commonjsExternal.React.cloneElement(info.wrapperTemplate, {
- key: info.key + '-wrap',
- 'data-offset-key': info.offsetKey
- }, blocks);
- outputBlocks.push(wrapperElement);
- } else {
- outputBlocks.push(info.block);
- _ii++;
- }
- }
-
- return _reactDom_commonjsExternal.React.createElement(
- 'div',
- { 'data-contents': 'true' },
- outputBlocks
- );
- };
-
- return DraftEditorContents;
- }(_reactDom_commonjsExternal.React.Component);
-
- var DraftEditorContentsCore_react = DraftEditorContents;
-
- var DraftEditorContents_react = DraftEditorContentsCore_react;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- */
- var PhotosMimeType = {
- isImage: function isImage(mimeString) {
- return getParts(mimeString)[0] === 'image';
- },
- isJpeg: function isJpeg(mimeString) {
- var parts = getParts(mimeString);
- return PhotosMimeType.isImage(mimeString) && (
- // see http://fburl.com/10972194
- parts[1] === 'jpeg' || parts[1] === 'pjpeg');
- }
- };
-
- function getParts(mimeString) {
- return mimeString.split('/');
- }
-
- var PhotosMimeType_1 = PhotosMimeType;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- * @typechecks
- */
-
-
-
- /**
- * Convert array-like objects to arrays.
- *
- * This API assumes the caller knows the contents of the data type. For less
- * well defined inputs use createArrayFromMixed.
- *
- * @param {object|function|filelist} obj
- * @return {array}
- */
- function toArray(obj) {
- var length = obj.length;
-
- // Some browsers builtin objects can report typeof 'function' (e.g. NodeList
- // in old versions of Safari).
- !(!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;
-
- !(typeof length === 'number') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'toArray: Object needs a length property') : invariant_1(false) : void 0;
-
- !(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;
-
- !(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;
-
- // Old IE doesn't give collections access to hasOwnProperty. Assume inputs
- // without method will throw during the slice call and skip straight to the
- // fallback.
- if (obj.hasOwnProperty) {
- try {
- return Array.prototype.slice.call(obj);
- } catch (e) {
- // IE < 9 does not support Array#slice on collections objects
- }
- }
-
- // Fall back to copying key by key. This assumes all keys have a value,
- // so will not preserve sparsely populated inputs.
- var ret = Array(length);
- for (var ii = 0; ii < length; ii++) {
- ret[ii] = obj[ii];
- }
- return ret;
- }
-
- /**
- * Perform a heuristic test to determine if an object is "array-like".
- *
- * A monk asked Joshu, a Zen master, "Has a dog Buddha nature?"
- * Joshu replied: "Mu."
- *
- * This function determines if its argument has "array nature": it returns
- * true if the argument is an actual array, an `arguments' object, or an
- * HTMLCollection (e.g. node.childNodes or node.getElementsByTagName()).
- *
- * It will return false for other array-like objects like Filelist.
- *
- * @param {*} obj
- * @return {boolean}
- */
- function hasArrayNature(obj) {
- return (
- // not null/false
- !!obj && (
- // arrays are objects, NodeLists are functions in Safari
- typeof obj == 'object' || typeof obj == 'function') &&
- // quacks like an array
- 'length' in obj &&
- // not window
- !('setInterval' in obj) &&
- // no DOM node should be considered an array-like
- // a 'select' element has 'length' and 'item' properties on IE8
- typeof obj.nodeType != 'number' && (
- // a real array
- Array.isArray(obj) ||
- // arguments
- 'callee' in obj ||
- // HTMLCollection/NodeList
- 'item' in obj)
- );
- }
-
- /**
- * Ensure that the argument is an array by wrapping it in an array if it is not.
- * Creates a copy of the argument if it is already an array.
- *
- * This is mostly useful idiomatically:
- *
- * var createArrayFromMixed = require('createArrayFromMixed');
- *
- * function takesOneOrMoreThings(things) {
- * things = createArrayFromMixed(things);
- * ...
- * }
- *
- * This allows you to treat `things' as an array, but accept scalars in the API.
- *
- * If you need to convert an array-like object, like `arguments`, into an array
- * use toArray instead.
- *
- * @param {*} obj
- * @return {array}
- */
- function createArrayFromMixed(obj) {
- if (!hasArrayNature(obj)) {
- return [obj];
- } else if (Array.isArray(obj)) {
- return obj.slice();
- } else {
- return toArray(obj);
- }
- }
-
- var createArrayFromMixed_1 = createArrayFromMixed;
-
- function _classCallCheck$d(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- * @typechecks
- */
-
-
-
-
-
-
- var CR_LF_REGEX = new RegExp('\r\n', 'g');
- var LF_ONLY = '\n';
-
- var RICH_TEXT_TYPES = {
- 'text/rtf': 1,
- 'text/html': 1
- };
-
- /**
- * If DataTransferItem is a file then return the Blob of data.
- *
- * @param {object} item
- * @return {?blob}
- */
- function getFileFromDataTransfer(item) {
- if (item.kind == 'file') {
- return item.getAsFile();
- }
- }
-
- var DataTransfer = function () {
- /**
- * @param {object} data
- */
- function DataTransfer(data) {
- _classCallCheck$d(this, DataTransfer);
-
- this.data = data;
-
- // Types could be DOMStringList or array
- this.types = data.types ? createArrayFromMixed_1(data.types) : [];
- }
-
- /**
- * Is this likely to be a rich text data transfer?
- *
- * @return {boolean}
- */
-
-
- DataTransfer.prototype.isRichText = function isRichText() {
- // If HTML is available, treat this data as rich text. This way, we avoid
- // using a pasted image if it is packaged with HTML -- this may occur with
- // pastes from MS Word, for example. However this is only rich text if
- // there's accompanying text.
- if (this.getHTML() && this.getText()) {
- return true;
- }
-
- // When an image is copied from a preview window, you end up with two
- // DataTransferItems one of which is a file's metadata as text. Skip those.
- if (this.isImage()) {
- return false;
- }
-
- return this.types.some(function (type) {
- return RICH_TEXT_TYPES[type];
- });
- };
-
- /**
- * Get raw text.
- *
- * @return {?string}
- */
-
-
- DataTransfer.prototype.getText = function getText() {
- var text;
- if (this.data.getData) {
- if (!this.types.length) {
- text = this.data.getData('Text');
- } else if (this.types.indexOf('text/plain') != -1) {
- text = this.data.getData('text/plain');
- }
- }
- return text ? text.replace(CR_LF_REGEX, LF_ONLY) : null;
- };
-
- /**
- * Get HTML paste data
- *
- * @return {?string}
- */
-
-
- DataTransfer.prototype.getHTML = function getHTML() {
- if (this.data.getData) {
- if (!this.types.length) {
- return this.data.getData('Text');
- } else if (this.types.indexOf('text/html') != -1) {
- return this.data.getData('text/html');
- }
- }
- };
-
- /**
- * Is this a link data transfer?
- *
- * @return {boolean}
- */
-
-
- DataTransfer.prototype.isLink = function isLink() {
- return this.types.some(function (type) {
- return type.indexOf('Url') != -1 || type.indexOf('text/uri-list') != -1 || type.indexOf('text/x-moz-url');
- });
- };
-
- /**
- * Get a link url.
- *
- * @return {?string}
- */
-
-
- DataTransfer.prototype.getLink = function getLink() {
- if (this.data.getData) {
- if (this.types.indexOf('text/x-moz-url') != -1) {
- var url = this.data.getData('text/x-moz-url').split('\n');
- return url[0];
- }
- return this.types.indexOf('text/uri-list') != -1 ? this.data.getData('text/uri-list') : this.data.getData('url');
- }
-
- return null;
- };
-
- /**
- * Is this an image data transfer?
- *
- * @return {boolean}
- */
-
-
- DataTransfer.prototype.isImage = function isImage() {
- var isImage = this.types.some(function (type) {
- // Firefox will have a type of application/x-moz-file for images during
- // dragging
- return type.indexOf('application/x-moz-file') != -1;
- });
-
- if (isImage) {
- return true;
- }
-
- var items = this.getFiles();
- for (var i = 0; i < items.length; i++) {
- var type = items[i].type;
- if (!PhotosMimeType_1.isImage(type)) {
- return false;
- }
- }
-
- return true;
- };
-
- DataTransfer.prototype.getCount = function getCount() {
- if (this.data.hasOwnProperty('items')) {
- return this.data.items.length;
- } else if (this.data.hasOwnProperty('mozItemCount')) {
- return this.data.mozItemCount;
- } else if (this.data.files) {
- return this.data.files.length;
- }
- return null;
- };
-
- /**
- * Get files.
- *
- * @return {array}
- */
-
-
- DataTransfer.prototype.getFiles = function getFiles() {
- if (this.data.items) {
- // createArrayFromMixed doesn't properly handle DataTransferItemLists.
- return Array.prototype.slice.call(this.data.items).map(getFileFromDataTransfer).filter(emptyFunction_1.thatReturnsArgument);
- } else if (this.data.files) {
- return Array.prototype.slice.call(this.data.files);
- } else {
- return [];
- }
- };
-
- /**
- * Are there any files to fetch?
- *
- * @return {boolean}
- */
-
-
- DataTransfer.prototype.hasFiles = function hasFiles() {
- return this.getFiles().length > 0;
- };
-
- return DataTransfer;
- }();
-
- var DataTransfer_1 = DataTransfer;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule getSelectionOffsetKeyForNode
- * @format
- *
- */
-
- /**
- * Get offset key from a node or it's child nodes. Return the first offset key
- * found on the DOM tree of given node.
- */
-
- function getSelectionOffsetKeyForNode(node) {
- if (node instanceof Element) {
- var offsetKey = node.getAttribute('data-offset-key');
- if (offsetKey) {
- return offsetKey;
- }
- for (var ii = 0; ii < node.childNodes.length; ii++) {
- var childOffsetKey = getSelectionOffsetKeyForNode(node.childNodes[ii]);
- if (childOffsetKey) {
- return childOffsetKey;
- }
- }
- }
- return null;
- }
-
- var getSelectionOffsetKeyForNode_1 = getSelectionOffsetKeyForNode;
-
- /**
- * Get the key from the node's nearest offset-aware ancestor.
- */
- function findAncestorOffsetKey(node) {
- var searchNode = node;
- while (searchNode && searchNode !== document.documentElement) {
- var key = getSelectionOffsetKeyForNode_1(searchNode);
- if (key != null) {
- return key;
- }
- searchNode = searchNode.parentNode;
- }
- return null;
- }
-
- var findAncestorOffsetKey_1 = findAncestorOffsetKey;
-
- var TEXT_CLIPPING_REGEX = /\.textClipping$/;
-
- var TEXT_TYPES = {
- 'text/plain': true,
- 'text/html': true,
- 'text/rtf': true
- };
-
- // Somewhat arbitrary upper bound on text size. Let's not lock up the browser.
- var TEXT_SIZE_UPPER_BOUND = 5000;
-
- /**
- * Extract the text content from a file list.
- */
- function getTextContentFromFiles(files, callback) {
- var readCount = 0;
- var results = [];
- files.forEach(function ( /*blob*/file) {
- readFile(file, function ( /*string*/text) {
- readCount++;
- text && results.push(text.slice(0, TEXT_SIZE_UPPER_BOUND));
- if (readCount == files.length) {
- callback(results.join('\r'));
- }
- });
- });
- }
-
- /**
- * todo isaac: Do work to turn html/rtf into a content fragment.
- */
- function readFile(file, callback) {
- if (!_commonjsHelpers.commonjsGlobal.FileReader || file.type && !(file.type in TEXT_TYPES)) {
- callback('');
- return;
- }
-
- if (file.type === '') {
- var contents = '';
- // Special-case text clippings, which have an empty type but include
- // `.textClipping` in the file name. `readAsText` results in an empty
- // string for text clippings, so we force the file name to serve
- // as the text value for the file.
- if (TEXT_CLIPPING_REGEX.test(file.name)) {
- contents = file.name.replace(TEXT_CLIPPING_REGEX, '');
- }
- callback(contents);
- return;
- }
-
- var reader = new FileReader();
- reader.onload = function () {
- var result = reader.result;
- !(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;
- callback(result);
- };
- reader.onerror = function () {
- callback('');
- };
- reader.readAsText(file);
- }
-
- var getTextContentFromFiles_1 = getTextContentFromFiles;
-
- function getUpdatedSelectionState(editorState, anchorKey, anchorOffset, focusKey, focusOffset) {
- var selection = nullthrows_1(editorState.getSelection());
- if (process.env.NODE_ENV !== 'production') {
- if (!anchorKey || !focusKey) {
- /*eslint-disable no-console */
- console.warn('Invalid selection state.', arguments, editorState.toJS());
- /*eslint-enable no-console */
- return selection;
- }
- }
-
- var anchorPath = DraftOffsetKey_1.decode(anchorKey);
- var anchorBlockKey = anchorPath.blockKey;
- var anchorLeaf = editorState.getBlockTree(anchorBlockKey).getIn([anchorPath.decoratorKey, 'leaves', anchorPath.leafKey]);
-
- var focusPath = DraftOffsetKey_1.decode(focusKey);
- var focusBlockKey = focusPath.blockKey;
- var focusLeaf = editorState.getBlockTree(focusBlockKey).getIn([focusPath.decoratorKey, 'leaves', focusPath.leafKey]);
-
- var anchorLeafStart = anchorLeaf.get('start');
- var focusLeafStart = focusLeaf.get('start');
-
- var anchorBlockOffset = anchorLeaf ? anchorLeafStart + anchorOffset : null;
- var focusBlockOffset = focusLeaf ? focusLeafStart + focusOffset : null;
-
- var areEqual = selection.getAnchorKey() === anchorBlockKey && selection.getAnchorOffset() === anchorBlockOffset && selection.getFocusKey() === focusBlockKey && selection.getFocusOffset() === focusBlockOffset;
-
- if (areEqual) {
- return selection;
- }
-
- var isBackward = false;
- if (anchorBlockKey === focusBlockKey) {
- var anchorLeafEnd = anchorLeaf.get('end');
- var focusLeafEnd = focusLeaf.get('end');
- if (focusLeafStart === anchorLeafStart && focusLeafEnd === anchorLeafEnd) {
- isBackward = focusOffset < anchorOffset;
- } else {
- isBackward = focusLeafStart < anchorLeafStart;
- }
- } else {
- var startKey = editorState.getCurrentContent().getBlockMap().keySeq().skipUntil(function (v) {
- return v === anchorBlockKey || v === focusBlockKey;
- }).first();
- isBackward = startKey === focusBlockKey;
- }
-
- return selection.merge({
- anchorKey: anchorBlockKey,
- anchorOffset: anchorBlockOffset,
- focusKey: focusBlockKey,
- focusOffset: focusBlockOffset,
- isBackward: isBackward
- });
- }
-
- var getUpdatedSelectionState_1 = getUpdatedSelectionState;
-
- /**
- * Get a SelectionState for the supplied mouse event.
- */
- function getSelectionForEvent(event, editorState) {
- var node = null;
- var offset = null;
-
- if (typeof document.caretRangeFromPoint === 'function') {
- var dropRange = document.caretRangeFromPoint(event.x, event.y);
- node = dropRange.startContainer;
- offset = dropRange.startOffset;
- } else if (event.rangeParent) {
- node = event.rangeParent;
- offset = event.rangeOffset;
- } else {
- return null;
- }
-
- node = nullthrows_1(node);
- offset = nullthrows_1(offset);
- var offsetKey = nullthrows_1(findAncestorOffsetKey_1(node));
-
- return getUpdatedSelectionState_1(editorState, offsetKey, offset, offsetKey, offset);
- }
-
- var DraftEditorDragHandler = {
- /**
- * Drag originating from input terminated.
- */
- onDragEnd: function onDragEnd(editor) {
- editor.exitCurrentMode();
- },
-
- /**
- * Handle data being dropped.
- */
- onDrop: function onDrop(editor, e) {
- var data = new DataTransfer_1(e.nativeEvent.dataTransfer);
-
- var editorState = editor._latestEditorState;
- var dropSelection = getSelectionForEvent(e.nativeEvent, editorState);
-
- e.preventDefault();
- editor.exitCurrentMode();
-
- if (dropSelection == null) {
- return;
- }
-
- var files = data.getFiles();
- if (files.length > 0) {
- if (editor.props.handleDroppedFiles && isEventHandled_1(editor.props.handleDroppedFiles(dropSelection, files))) {
- return;
- }
-
- getTextContentFromFiles_1(files, function (fileText) {
- fileText && editor.update(insertTextAtSelection(editorState, dropSelection, fileText));
- });
- return;
- }
-
- var dragType = editor._internalDrag ? 'internal' : 'external';
- if (editor.props.handleDrop && isEventHandled_1(editor.props.handleDrop(dropSelection, data, dragType))) {
- return;
- }
-
- if (editor._internalDrag) {
- editor.update(moveText(editorState, dropSelection));
- return;
- }
-
- editor.update(insertTextAtSelection(editorState, dropSelection, data.getText()));
- }
- };
-
- function moveText(editorState, targetSelection) {
- var newContentState = DraftModifier_1.moveText(editorState.getCurrentContent(), editorState.getSelection(), targetSelection);
- return EditorState_1.push(editorState, newContentState, 'insert-fragment');
- }
-
- /**
- * Insert text at a specified selection.
- */
- function insertTextAtSelection(editorState, selection, text) {
- var newContentState = DraftModifier_1.insertText(editorState.getCurrentContent(), selection, text, editorState.getCurrentInlineStyle());
- return EditorState_1.push(editorState, newContentState, 'insert-fragment');
- }
-
- var DraftEditorDragHandler_1 = DraftEditorDragHandler;
-
- (function (global, undefined$1) {
-
- if (global.setImmediate) {
- return;
- }
-
- var nextHandle = 1; // Spec says greater than zero
- var tasksByHandle = {};
- var currentlyRunningATask = false;
- var doc = global.document;
- var registerImmediate;
-
- function setImmediate(callback) {
- // Callback can either be a function or a string
- if (typeof callback !== "function") {
- callback = new Function("" + callback);
- }
- // Copy function arguments
- var args = new Array(arguments.length - 1);
- for (var i = 0; i < args.length; i++) {
- args[i] = arguments[i + 1];
- }
- // Store and register the task
- var task = { callback: callback, args: args };
- tasksByHandle[nextHandle] = task;
- registerImmediate(nextHandle);
- return nextHandle++;
- }
-
- function clearImmediate(handle) {
- delete tasksByHandle[handle];
- }
-
- function run(task) {
- var callback = task.callback;
- var args = task.args;
- switch (args.length) {
- case 0:
- callback();
- break;
- case 1:
- callback(args[0]);
- break;
- case 2:
- callback(args[0], args[1]);
- break;
- case 3:
- callback(args[0], args[1], args[2]);
- break;
- default:
- callback.apply(undefined$1, args);
- break;
- }
- }
-
- function runIfPresent(handle) {
- // From the spec: "Wait until any invocations of this algorithm started before this one have completed."
- // So if we're currently running a task, we'll need to delay this invocation.
- if (currentlyRunningATask) {
- // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a
- // "too much recursion" error.
- setTimeout(runIfPresent, 0, handle);
- } else {
- var task = tasksByHandle[handle];
- if (task) {
- currentlyRunningATask = true;
- try {
- run(task);
- } finally {
- clearImmediate(handle);
- currentlyRunningATask = false;
- }
- }
- }
- }
-
- function installNextTickImplementation() {
- registerImmediate = function(handle) {
- process.nextTick(function () { runIfPresent(handle); });
- };
- }
-
- function canUsePostMessage() {
- // The test against `importScripts` prevents this implementation from being installed inside a web worker,
- // where `global.postMessage` means something completely different and can't be used for this purpose.
- if (global.postMessage && !global.importScripts) {
- var postMessageIsAsynchronous = true;
- var oldOnMessage = global.onmessage;
- global.onmessage = function() {
- postMessageIsAsynchronous = false;
- };
- global.postMessage("", "*");
- global.onmessage = oldOnMessage;
- return postMessageIsAsynchronous;
- }
- }
-
- function installPostMessageImplementation() {
- // Installs an event handler on `global` for the `message` event: see
- // * https://developer.mozilla.org/en/DOM/window.postMessage
- // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
-
- var messagePrefix = "setImmediate$" + Math.random() + "$";
- var onGlobalMessage = function(event) {
- if (event.source === global &&
- typeof event.data === "string" &&
- event.data.indexOf(messagePrefix) === 0) {
- runIfPresent(+event.data.slice(messagePrefix.length));
- }
- };
-
- if (global.addEventListener) {
- global.addEventListener("message", onGlobalMessage, false);
- } else {
- global.attachEvent("onmessage", onGlobalMessage);
- }
-
- registerImmediate = function(handle) {
- global.postMessage(messagePrefix + handle, "*");
- };
- }
-
- function installMessageChannelImplementation() {
- var channel = new MessageChannel();
- channel.port1.onmessage = function(event) {
- var handle = event.data;
- runIfPresent(handle);
- };
-
- registerImmediate = function(handle) {
- channel.port2.postMessage(handle);
- };
- }
-
- function installReadyStateChangeImplementation() {
- var html = doc.documentElement;
- registerImmediate = function(handle) {
- // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
- // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
- var script = doc.createElement("script");
- script.onreadystatechange = function () {
- runIfPresent(handle);
- script.onreadystatechange = null;
- html.removeChild(script);
- script = null;
- };
- html.appendChild(script);
- };
- }
-
- function installSetTimeoutImplementation() {
- registerImmediate = function(handle) {
- setTimeout(runIfPresent, 0, handle);
- };
- }
-
- // If supported, we should attach to the prototype of global, since that is where setTimeout et al. live.
- var attachTo = Object.getPrototypeOf && Object.getPrototypeOf(global);
- attachTo = attachTo && attachTo.setTimeout ? attachTo : global;
-
- // Don't get fooled by e.g. browserify environments.
- if ({}.toString.call(global.process) === "[object process]") {
- // For Node.js before 0.9
- installNextTickImplementation();
-
- } else if (canUsePostMessage()) {
- // For non-IE10 modern browsers
- installPostMessageImplementation();
-
- } else if (global.MessageChannel) {
- // For web workers, where supported
- installMessageChannelImplementation();
-
- } else if (doc && "onreadystatechange" in doc.createElement("script")) {
- // For IE 6–8
- installReadyStateChangeImplementation();
-
- } else {
- // For older browsers
- installSetTimeoutImplementation();
- }
-
- attachTo.setImmediate = setImmediate;
- attachTo.clearImmediate = clearImmediate;
- }(typeof self === "undefined" ? typeof _commonjsHelpers.commonjsGlobal === "undefined" ? _commonjsHelpers.commonjsGlobal : _commonjsHelpers.commonjsGlobal : self));
-
- // setimmediate adds setImmediate to the global. We want to make sure we export
- // the actual function.
-
-
- var setImmediate = _commonjsHelpers.commonjsGlobal.setImmediate;
-
- // When nothing is focused, Firefox regards two characters, `'` and `/`, as
- // commands that should open and focus the "quickfind" search bar. This should
- // *never* happen while a contenteditable is focused, but as of v28, it
- // sometimes does, even when the keypress event target is the contenteditable.
- // This breaks the input. Special case these characters to ensure that when
- // they are typed, we prevent default on the event to make sure not to
- // trigger quickfind.
- var FF_QUICKFIND_CHAR = "'";
- var FF_QUICKFIND_LINK_CHAR = '/';
- var isFirefox = UserAgent_1.isBrowser('Firefox');
-
- function mustPreventDefaultForCharacter(character) {
- return isFirefox && (character == FF_QUICKFIND_CHAR || character == FF_QUICKFIND_LINK_CHAR);
- }
-
- /**
- * Replace the current selection with the specified text string, with the
- * inline style and entity key applied to the newly inserted text.
- */
- function replaceText(editorState, text, inlineStyle, entityKey) {
- var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), text, inlineStyle, entityKey);
- return EditorState_1.push(editorState, contentState, 'insert-characters');
- }
-
- /**
- * When `onBeforeInput` executes, the browser is attempting to insert a
- * character into the editor. Apply this character data to the document,
- * allowing native insertion if possible.
- *
- * Native insertion is encouraged in order to limit re-rendering and to
- * preserve spellcheck highlighting, which disappears or flashes if re-render
- * occurs on the relevant text nodes.
- */
- function editOnBeforeInput(editor, e) {
- if (editor._pendingStateFromBeforeInput !== undefined) {
- editor.update(editor._pendingStateFromBeforeInput);
- editor._pendingStateFromBeforeInput = undefined;
- }
-
- var editorState = editor._latestEditorState;
-
- var chars = e.data;
-
- // In some cases (ex: IE ideographic space insertion) no character data
- // is provided. There's nothing to do when this happens.
- if (!chars) {
- return;
- }
-
- // Allow the top-level component to handle the insertion manually. This is
- // useful when triggering interesting behaviors for a character insertion,
- // Simple examples: replacing a raw text ':)' with a smile emoji or image
- // decorator, or setting a block to be a list item after typing '- ' at the
- // start of the block.
- if (editor.props.handleBeforeInput && isEventHandled_1(editor.props.handleBeforeInput(chars, editorState))) {
- e.preventDefault();
- return;
- }
-
- // If selection is collapsed, conditionally allow native behavior. This
- // reduces re-renders and preserves spellcheck highlighting. If the selection
- // is not collapsed, we will re-render.
- var selection = editorState.getSelection();
- var selectionStart = selection.getStartOffset();
- var selectionEnd = selection.getEndOffset();
- var anchorKey = selection.getAnchorKey();
-
- if (!selection.isCollapsed()) {
- e.preventDefault();
-
- // If the currently selected text matches what the user is trying to
- // replace it with, let's just update the `SelectionState`. If not, update
- // the `ContentState` with the new text.
- var currentlySelectedChars = editorState.getCurrentContent().getPlainText().slice(selectionStart, selectionEnd);
- if (chars === currentlySelectedChars) {
- editor.update(EditorState_1.forceSelection(editorState, selection.merge({
- focusOffset: selectionEnd
- })));
- } else {
- editor.update(replaceText(editorState, chars, editorState.getCurrentInlineStyle(), getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())));
- }
- return;
- }
-
- var newEditorState = replaceText(editorState, chars, editorState.getCurrentInlineStyle(), getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection()));
-
- // Bunch of different cases follow where we need to prevent native insertion.
- var mustPreventNative = false;
- if (!mustPreventNative) {
- // Browsers tend to insert text in weird places in the DOM when typing at
- // the start of a leaf, so we'll handle it ourselves.
- mustPreventNative = isSelectionAtLeafStart_1(editor._latestCommittedEditorState);
- }
- if (!mustPreventNative) {
- // Chrome will also split up a node into two pieces if it contains a Tab
- // char, for no explicable reason. Seemingly caused by this commit:
- // https://chromium.googlesource.com/chromium/src/+/013ac5eaf3%5E%21/
- var nativeSelection = _commonjsHelpers.commonjsGlobal.getSelection();
- // Selection is necessarily collapsed at this point due to earlier check.
- if (nativeSelection.anchorNode && nativeSelection.anchorNode.nodeType === Node.TEXT_NODE) {
- // See isTabHTMLSpanElement in chromium EditingUtilities.cpp.
- var parentNode = nativeSelection.anchorNode.parentNode;
- mustPreventNative = parentNode.nodeName === 'SPAN' && parentNode.firstChild.nodeType === Node.TEXT_NODE && parentNode.firstChild.nodeValue.indexOf('\t') !== -1;
- }
- }
- if (!mustPreventNative) {
- // Check the old and new "fingerprints" of the current block to determine
- // whether this insertion requires any addition or removal of text nodes,
- // in which case we would prevent the native character insertion.
- var originalFingerprint = BlockTree_1.getFingerprint(editorState.getBlockTree(anchorKey));
- var newFingerprint = BlockTree_1.getFingerprint(newEditorState.getBlockTree(anchorKey));
- mustPreventNative = originalFingerprint !== newFingerprint;
- }
- if (!mustPreventNative) {
- mustPreventNative = mustPreventDefaultForCharacter(chars);
- }
- if (!mustPreventNative) {
- mustPreventNative = nullthrows_1(newEditorState.getDirectionMap()).get(anchorKey) !== nullthrows_1(editorState.getDirectionMap()).get(anchorKey);
- }
-
- if (mustPreventNative) {
- e.preventDefault();
- editor.update(newEditorState);
- return;
- }
-
- // We made it all the way! Let the browser do its thing and insert the char.
- newEditorState = EditorState_1.set(newEditorState, {
- nativelyRenderedContent: newEditorState.getCurrentContent()
- });
- // The native event is allowed to occur. To allow user onChange handlers to
- // change the inserted text, we wait until the text is actually inserted
- // before we actually update our state. That way when we rerender, the text
- // we see in the DOM will already have been inserted properly.
- editor._pendingStateFromBeforeInput = newEditorState;
- setImmediate(function () {
- if (editor._pendingStateFromBeforeInput !== undefined) {
- editor.update(editor._pendingStateFromBeforeInput);
- editor._pendingStateFromBeforeInput = undefined;
- }
- });
- }
-
- var editOnBeforeInput_1 = editOnBeforeInput;
-
- function editOnBlur(editor, e) {
- // In a contentEditable element, when you select a range and then click
- // another active element, this does trigger a `blur` event but will not
- // remove the DOM selection from the contenteditable.
- // This is consistent across all browsers, but we prefer that the editor
- // behave like a textarea, where a `blur` event clears the DOM selection.
- // We therefore force the issue to be certain, checking whether the active
- // element is `body` to force it when blurring occurs within the window (as
- // opposed to clicking to another tab or window).
- if (getActiveElement_1() === document.body) {
- var _selection = _commonjsHelpers.commonjsGlobal.getSelection();
- var editorNode = editor.editor;
- if (_selection.rangeCount === 1 && containsNode_1(editorNode, _selection.anchorNode) && containsNode_1(editorNode, _selection.focusNode)) {
- _selection.removeAllRanges();
- }
- }
-
- var editorState = editor._latestEditorState;
- var currentSelection = editorState.getSelection();
- if (!currentSelection.getHasFocus()) {
- return;
- }
-
- var selection = currentSelection.set('hasFocus', false);
- editor.props.onBlur && editor.props.onBlur(e);
- editor.update(EditorState_1.acceptSelection(editorState, selection));
- }
-
- var editOnBlur_1 = editOnBlur;
-
- /**
- * The user has begun using an IME input system. Switching to `composite` mode
- * allows handling composition input and disables other edit behavior.
- */
- function editOnCompositionStart(editor, e) {
- editor.setMode('composite');
- editor.update(EditorState_1.set(editor._latestEditorState, { inCompositionMode: true }));
- // Allow composition handler to interpret the compositionstart event
- editor._onCompositionStart(e);
- }
-
- var editOnCompositionStart_1 = editOnCompositionStart;
-
- function getFragmentFromSelection(editorState) {
- var selectionState = editorState.getSelection();
-
- if (selectionState.isCollapsed()) {
- return null;
- }
-
- return getContentStateFragment_1(editorState.getCurrentContent(), selectionState);
- }
-
- var getFragmentFromSelection_1 = getFragmentFromSelection;
-
- /**
- * If we have a selection, create a ContentState fragment and store
- * it in our internal clipboard. Subsequent paste events will use this
- * fragment if no external clipboard data is supplied.
- */
- function editOnCopy(editor, e) {
- var editorState = editor._latestEditorState;
- var selection = editorState.getSelection();
-
- // No selection, so there's nothing to copy.
- if (selection.isCollapsed()) {
- e.preventDefault();
- return;
- }
-
- editor.setClipboard(getFragmentFromSelection_1(editor._latestEditorState));
- }
-
- var editOnCopy_1 = editOnCopy;
-
- /**
- * On `cut` events, native behavior is allowed to occur so that the system
- * clipboard is set properly. This means that we need to take steps to recover
- * the editor DOM state after the `cut` has occurred in order to maintain
- * control of the component.
- *
- * In addition, we can keep a copy of the removed fragment, including all
- * styles and entities, for use as an internal paste.
- */
- function editOnCut(editor, e) {
- var editorState = editor._latestEditorState;
- var selection = editorState.getSelection();
- var element = e.target;
- var scrollPosition = void 0;
-
- // No selection, so there's nothing to cut.
- if (selection.isCollapsed()) {
- e.preventDefault();
- return;
- }
-
- // Track the current scroll position so that it can be forced back in place
- // after the editor regains control of the DOM.
- if (element instanceof Node) {
- scrollPosition = getScrollPosition_1(Style_1.getScrollParent(element));
- }
-
- var fragment = getFragmentFromSelection_1(editorState);
- editor.setClipboard(fragment);
-
- // Set `cut` mode to disable all event handling temporarily.
- editor.setMode('cut');
-
- // Let native `cut` behavior occur, then recover control.
- setTimeout(function () {
- editor.restoreEditorDOM(scrollPosition);
- editor.exitCurrentMode();
- editor.update(removeFragment(editorState));
- }, 0);
- }
-
- function removeFragment(editorState) {
- var newContent = DraftModifier_1.removeRange(editorState.getCurrentContent(), editorState.getSelection(), 'forward');
- return EditorState_1.push(editorState, newContent, 'remove-range');
- }
-
- var editOnCut_1 = editOnCut;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule editOnDragOver
- * @format
- *
- */
-
- /**
- * Drag behavior has begun from outside the editor element.
- */
- function editOnDragOver(editor, e) {
- editor._internalDrag = false;
- editor.setMode('drag');
- e.preventDefault();
- }
-
- var editOnDragOver_1 = editOnDragOver;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule editOnDragStart
- * @format
- *
- */
-
- /**
- * A `dragstart` event has begun within the text editor component.
- */
- function editOnDragStart(editor) {
- editor._internalDrag = true;
- editor.setMode('drag');
- }
-
- var editOnDragStart_1 = editOnDragStart;
-
- function editOnFocus(editor, e) {
- var editorState = editor._latestEditorState;
- var currentSelection = editorState.getSelection();
- if (currentSelection.getHasFocus()) {
- return;
- }
-
- var selection = currentSelection.set('hasFocus', true);
- editor.props.onFocus && editor.props.onFocus(e);
-
- // When the tab containing this text editor is hidden and the user does a
- // find-in-page in a _different_ tab, Chrome on Mac likes to forget what the
- // selection was right after sending this focus event and (if you let it)
- // moves the cursor back to the beginning of the editor, so we force the
- // selection here instead of simply accepting it in order to preserve the
- // old cursor position. See https://crbug.com/540004.
- // But it looks like this is fixed in Chrome 60.0.3081.0.
- // Other browsers also don't have this bug, so we prefer to acceptSelection
- // when possible, to ensure that unfocusing and refocusing a Draft editor
- // doesn't preserve the selection, matching how textareas work.
- if (UserAgent_1.isBrowser('Chrome < 60.0.3081.0')) {
- editor.update(EditorState_1.forceSelection(editorState, selection));
- } else {
- editor.update(EditorState_1.acceptSelection(editorState, selection));
- }
- }
-
- var editOnFocus_1 = editOnFocus;
-
- var isGecko = UserAgent_1.isEngine('Gecko');
-
- var DOUBLE_NEWLINE = '\n\n';
-
- /**
- * This function is intended to handle spellcheck and autocorrect changes,
- * which occur in the DOM natively without any opportunity to observe or
- * interpret the changes before they occur.
- *
- * The `input` event fires in contentEditable elements reliably for non-IE
- * browsers, immediately after changes occur to the editor DOM. Since our other
- * handlers override or otherwise handle cover other varieties of text input,
- * the DOM state should match the model in all controlled input cases. Thus,
- * when an `input` change leads to a DOM/model mismatch, the change should be
- * due to a spellcheck change, and we can incorporate it into our model.
- */
- function editOnInput(editor) {
- if (editor._pendingStateFromBeforeInput !== undefined) {
- editor.update(editor._pendingStateFromBeforeInput);
- editor._pendingStateFromBeforeInput = undefined;
- }
-
- var domSelection = _commonjsHelpers.commonjsGlobal.getSelection();
-
- var anchorNode = domSelection.anchorNode,
- isCollapsed = domSelection.isCollapsed;
-
- var isNotTextNode = anchorNode.nodeType !== Node.TEXT_NODE;
- var isNotTextOrElementNode = anchorNode.nodeType !== Node.TEXT_NODE && anchorNode.nodeType !== Node.ELEMENT_NODE;
-
- {
- if (isNotTextOrElementNode) {
- // TODO: (t16149272) figure out context for this change
- return;
- }
- }
-
- if (anchorNode.nodeType === Node.TEXT_NODE && (anchorNode.previousSibling !== null || anchorNode.nextSibling !== null)) {
- // When typing at the beginning of a visual line, Chrome splits the text
- // nodes into two. Why? No one knows. This commit is suspicious:
- // https://chromium.googlesource.com/chromium/src/+/a3b600981286b135632371477f902214c55a1724
- // To work around, we'll merge the sibling text nodes back into this one.
- var span = anchorNode.parentNode;
- anchorNode.nodeValue = span.textContent;
- for (var child = span.firstChild; child !== null; child = child.nextSibling) {
- if (child !== anchorNode) {
- span.removeChild(child);
- }
- }
- }
-
- var domText = anchorNode.textContent;
- var editorState = editor._latestEditorState;
- var offsetKey = nullthrows_1(findAncestorOffsetKey_1(anchorNode));
-
- var _DraftOffsetKey$decod = DraftOffsetKey_1.decode(offsetKey),
- blockKey = _DraftOffsetKey$decod.blockKey,
- decoratorKey = _DraftOffsetKey$decod.decoratorKey,
- leafKey = _DraftOffsetKey$decod.leafKey;
-
- var _editorState$getBlock = editorState.getBlockTree(blockKey).getIn([decoratorKey, 'leaves', leafKey]),
- start = _editorState$getBlock.start,
- end = _editorState$getBlock.end;
-
- var content = editorState.getCurrentContent();
- var block = content.getBlockForKey(blockKey);
- var modelText = block.getText().slice(start, end);
-
- // Special-case soft newlines here. If the DOM text ends in a soft newline,
- // we will have manually inserted an extra soft newline in DraftEditorLeaf.
- // We want to remove this extra newline for the purpose of our comparison
- // of DOM and model text.
- if (domText.endsWith(DOUBLE_NEWLINE)) {
- domText = domText.slice(0, -1);
- }
-
- // No change -- the DOM is up to date. Nothing to do here.
- if (domText === modelText) {
- // This can be buggy for some Android keyboards because they don't fire
- // standard onkeydown/pressed events and only fired editOnInput
- // so domText is already changed by the browser and ends up being equal
- // to modelText unexpectedly
- return;
- }
-
- var selection = editorState.getSelection();
-
- // We'll replace the entire leaf with the text content of the target.
- var targetRange = selection.merge({
- anchorOffset: start,
- focusOffset: end,
- isBackward: false
- });
-
- var entityKey = block.getEntityAt(start);
- var entity = entityKey && content.getEntity(entityKey);
- var entityType = entity && entity.getMutability();
- var preserveEntity = entityType === 'MUTABLE';
-
- // Immutable or segmented entities cannot properly be handled by the
- // default browser undo, so we have to use a different change type to
- // force using our internal undo method instead of falling through to the
- // native browser undo.
- var changeType = preserveEntity ? 'spellcheck-change' : 'apply-entity';
-
- var newContent = DraftModifier_1.replaceText(content, targetRange, domText, block.getInlineStyleAt(start), preserveEntity ? block.getEntityAt(start) : null);
-
- var anchorOffset, focusOffset, startOffset, endOffset;
-
- if (isGecko) {
- // Firefox selection does not change while the context menu is open, so
- // we preserve the anchor and focus values of the DOM selection.
- anchorOffset = domSelection.anchorOffset;
- focusOffset = domSelection.focusOffset;
- startOffset = start + Math.min(anchorOffset, focusOffset);
- endOffset = startOffset + Math.abs(anchorOffset - focusOffset);
- anchorOffset = startOffset;
- focusOffset = endOffset;
- } else {
- // Browsers other than Firefox may adjust DOM selection while the context
- // menu is open, and Safari autocorrect is prone to providing an inaccurate
- // DOM selection. Don't trust it. Instead, use our existing SelectionState
- // and adjust it based on the number of characters changed during the
- // mutation.
- var charDelta = domText.length - modelText.length;
- startOffset = selection.getStartOffset();
- endOffset = selection.getEndOffset();
-
- anchorOffset = isCollapsed ? endOffset + charDelta : startOffset;
- focusOffset = endOffset + charDelta;
- }
-
- // Segmented entities are completely or partially removed when their
- // text content changes. For this case we do not want any text to be selected
- // after the change, so we are not merging the selection.
- var contentWithAdjustedDOMSelection = newContent.merge({
- selectionBefore: content.getSelectionAfter(),
- selectionAfter: selection.merge({ anchorOffset: anchorOffset, focusOffset: focusOffset })
- });
-
- editor.update(EditorState_1.push(editorState, contentWithAdjustedDOMSelection, changeType));
- }
-
- var editOnInput_1 = editOnInput;
-
- var isOSX = UserAgent_1.isPlatform('Mac OS X');
-
- var KeyBindingUtil = {
- /**
- * Check whether the ctrlKey modifier is *not* being used in conjunction with
- * the altKey modifier. If they are combined, the result is an `altGraph`
- * key modifier, which should not be handled by this set of key bindings.
- */
- isCtrlKeyCommand: function isCtrlKeyCommand(e) {
- return !!e.ctrlKey && !e.altKey;
- },
-
- isOptionKeyCommand: function isOptionKeyCommand(e) {
- return isOSX && e.altKey;
- },
-
- hasCommandModifier: function hasCommandModifier(e) {
- return isOSX ? !!e.metaKey && !e.altKey : KeyBindingUtil.isCtrlKeyCommand(e);
- }
- };
-
- var KeyBindingUtil_1 = KeyBindingUtil;
-
- var clipboard = null;
-
- /**
- * Some systems offer a "secondary" clipboard to allow quick internal cut
- * and paste behavior. For instance, Ctrl+K (cut) and Ctrl+Y (paste).
- */
- var SecondaryClipboard = {
- cut: function cut(editorState) {
- var content = editorState.getCurrentContent();
- var selection = editorState.getSelection();
- var targetRange = null;
-
- if (selection.isCollapsed()) {
- var anchorKey = selection.getAnchorKey();
- var blockEnd = content.getBlockForKey(anchorKey).getLength();
-
- if (blockEnd === selection.getAnchorOffset()) {
- return editorState;
- }
-
- targetRange = selection.set('focusOffset', blockEnd);
- } else {
- targetRange = selection;
- }
-
- targetRange = nullthrows_1(targetRange);
- clipboard = getContentStateFragment_1(content, targetRange);
-
- var afterRemoval = DraftModifier_1.removeRange(content, targetRange, 'forward');
-
- if (afterRemoval === content) {
- return editorState;
- }
-
- return EditorState_1.push(editorState, afterRemoval, 'remove-range');
- },
-
- paste: function paste(editorState) {
- if (!clipboard) {
- return editorState;
- }
-
- var newContent = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), clipboard);
-
- return EditorState_1.push(editorState, newContent, 'insert-fragment');
- }
- };
-
- var SecondaryClipboard_1 = SecondaryClipboard;
-
- // These two ranges are consecutive so anything in [HIGH_START, LOW_END] is a
- // surrogate code unit.
- var SURROGATE_HIGH_START = 0xD800;
- var SURROGATE_HIGH_END = 0xDBFF;
- var SURROGATE_LOW_START = 0xDC00;
- var SURROGATE_LOW_END = 0xDFFF;
- var SURROGATE_UNITS_REGEX = /[\uD800-\uDFFF]/;
-
- /**
- * @param {number} codeUnit A Unicode code-unit, in range [0, 0x10FFFF]
- * @return {boolean} Whether code-unit is in a surrogate (hi/low) range
- */
- function isCodeUnitInSurrogateRange(codeUnit) {
- return SURROGATE_HIGH_START <= codeUnit && codeUnit <= SURROGATE_LOW_END;
- }
-
- /**
- * Returns whether the two characters starting at `index` form a surrogate pair.
- * For example, given the string s = "\uD83D\uDE0A", (s, 0) returns true and
- * (s, 1) returns false.
- *
- * @param {string} str
- * @param {number} index
- * @return {boolean}
- */
- function isSurrogatePair(str, index) {
- !(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;
- if (index + 1 === str.length) {
- return false;
- }
- var first = str.charCodeAt(index);
- var second = str.charCodeAt(index + 1);
- return SURROGATE_HIGH_START <= first && first <= SURROGATE_HIGH_END && SURROGATE_LOW_START <= second && second <= SURROGATE_LOW_END;
- }
-
- /**
- * @param {string} str Non-empty string
- * @return {boolean} True if the input includes any surrogate code units
- */
- function hasSurrogateUnit(str) {
- return SURROGATE_UNITS_REGEX.test(str);
- }
-
- /**
- * Return the length of the original Unicode character at given position in the
- * String by looking into the UTF-16 code unit; that is equal to 1 for any
- * non-surrogate characters in BMP ([U+0000..U+D7FF] and [U+E000, U+FFFF]); and
- * returns 2 for the hi/low surrogates ([U+D800..U+DFFF]), which are in fact
- * representing non-BMP characters ([U+10000..U+10FFFF]).
- *
- * Examples:
- * - '\u0020' => 1
- * - '\u3020' => 1
- * - '\uD835' => 2
- * - '\uD835\uDDEF' => 2
- * - '\uDDEF' => 2
- *
- * @param {string} str Non-empty string
- * @param {number} pos Position in the string to look for one code unit
- * @return {number} Number 1 or 2
- */
- function getUTF16Length(str, pos) {
- return 1 + isCodeUnitInSurrogateRange(str.charCodeAt(pos));
- }
-
- /**
- * Fully Unicode-enabled replacement for String#length
- *
- * @param {string} str Valid Unicode string
- * @return {number} The number of Unicode characters in the string
- */
- function strlen(str) {
- // Call the native functions if there's no surrogate char
- if (!hasSurrogateUnit(str)) {
- return str.length;
- }
-
- var len = 0;
- for (var pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
- len++;
- }
- return len;
- }
-
- /**
- * Fully Unicode-enabled replacement for String#substr()
- *
- * @param {string} str Valid Unicode string
- * @param {number} start Location in Unicode sequence to begin extracting
- * @param {?number} length The number of Unicode characters to extract
- * (default: to the end of the string)
- * @return {string} Extracted sub-string
- */
- function substr(str, start, length) {
- start = start || 0;
- length = length === undefined ? Infinity : length || 0;
-
- // Call the native functions if there's no surrogate char
- if (!hasSurrogateUnit(str)) {
- return str.substr(start, length);
- }
-
- // Obvious cases
- var size = str.length;
- if (size <= 0 || start > size || length <= 0) {
- return '';
- }
-
- // Find the actual starting position
- var posA = 0;
- if (start > 0) {
- for (; start > 0 && posA < size; start--) {
- posA += getUTF16Length(str, posA);
- }
- if (posA >= size) {
- return '';
- }
- } else if (start < 0) {
- for (posA = size; start < 0 && 0 < posA; start++) {
- posA -= getUTF16Length(str, posA - 1);
- }
- if (posA < 0) {
- posA = 0;
- }
- }
-
- // Find the actual ending position
- var posB = size;
- if (length < size) {
- for (posB = posA; length > 0 && posB < size; length--) {
- posB += getUTF16Length(str, posB);
- }
- }
-
- return str.substring(posA, posB);
- }
-
- /**
- * Fully Unicode-enabled replacement for String#substring()
- *
- * @param {string} str Valid Unicode string
- * @param {number} start Location in Unicode sequence to begin extracting
- * @param {?number} end Location in Unicode sequence to end extracting
- * (default: end of the string)
- * @return {string} Extracted sub-string
- */
- function substring(str, start, end) {
- start = start || 0;
- end = end === undefined ? Infinity : end || 0;
-
- if (start < 0) {
- start = 0;
- }
- if (end < 0) {
- end = 0;
- }
-
- var length = Math.abs(end - start);
- start = start < end ? start : end;
- return substr(str, start, length);
- }
-
- /**
- * Get a list of Unicode code-points from a String
- *
- * @param {string} str Valid Unicode string
- * @return {array<number>} A list of code-points in [0..0x10FFFF]
- */
- function getCodePoints(str) {
- var codePoints = [];
- for (var pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
- codePoints.push(str.codePointAt(pos));
- }
- return codePoints;
- }
-
- var UnicodeUtils = {
- getCodePoints: getCodePoints,
- getUTF16Length: getUTF16Length,
- hasSurrogateUnit: hasSurrogateUnit,
- isCodeUnitInSurrogateRange: isCodeUnitInSurrogateRange,
- isSurrogatePair: isSurrogatePair,
- strlen: strlen,
- substring: substring,
- substr: substr
- };
-
- var UnicodeUtils_1 = UnicodeUtils;
-
- var isChrome = UserAgent_1.isBrowser('Chrome');
-
- // In Chrome, the client rects will include the entire bounds of all nodes that
- // begin (have a start tag) within the selection, even if the selection does
- // not overlap the entire node. To resolve this, we split the range at each
- // start tag and join the client rects together.
- // https://code.google.com/p/chromium/issues/detail?id=324437
- /* eslint-disable consistent-return */
- function getRangeClientRectsChrome(range) {
- var tempRange = range.cloneRange();
- var clientRects = [];
-
- for (var ancestor = range.endContainer; ancestor != null; ancestor = ancestor.parentNode) {
- // If we've climbed up to the common ancestor, we can now use the
- // original start point and stop climbing the tree.
- var atCommonAncestor = ancestor === range.commonAncestorContainer;
- if (atCommonAncestor) {
- tempRange.setStart(range.startContainer, range.startOffset);
- } else {
- tempRange.setStart(tempRange.endContainer, 0);
- }
- var rects = Array.from(tempRange.getClientRects());
- clientRects.push(rects);
- if (atCommonAncestor) {
- var _ref;
-
- clientRects.reverse();
- return (_ref = []).concat.apply(_ref, clientRects);
- }
- tempRange.setEndBefore(ancestor);
- }
-
- process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Found an unexpected detached subtree when getting range client rects.') : invariant_1(false) ;
- }
- /* eslint-enable consistent-return */
-
- /**
- * Like range.getClientRects() but normalizes for browser bugs.
- */
- var getRangeClientRects = isChrome ? getRangeClientRectsChrome : function (range) {
- return Array.from(range.getClientRects());
- };
-
- var getRangeClientRects_1 = getRangeClientRects;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule expandRangeToStartOfLine
- * @format
- *
- */
-
-
-
-
-
-
- /**
- * Return the computed line height, in pixels, for the provided element.
- */
- function getLineHeightPx(element) {
- var computed = getComputedStyle(element);
- var div = document.createElement('div');
- div.style.fontFamily = computed.fontFamily;
- div.style.fontSize = computed.fontSize;
- div.style.fontStyle = computed.fontStyle;
- div.style.fontWeight = computed.fontWeight;
- div.style.lineHeight = computed.lineHeight;
- div.style.position = 'absolute';
- div.textContent = 'M';
-
- var documentBody = document.body;
- !documentBody ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing document.body') : invariant_1(false) : void 0;
-
- // forced layout here
- documentBody.appendChild(div);
- var rect = div.getBoundingClientRect();
- documentBody.removeChild(div);
-
- return rect.height;
- }
-
- /**
- * Return whether every ClientRect in the provided list lies on the same line.
- *
- * We assume that the rects on the same line all contain the baseline, so the
- * lowest top line needs to be above the highest bottom line (i.e., if you were
- * to project the rects onto the y-axis, their intersection would be nonempty).
- *
- * In addition, we require that no two boxes are lineHeight (or more) apart at
- * either top or bottom, which helps protect against false positives for fonts
- * with extremely large glyph heights (e.g., with a font size of 17px, Zapfino
- * produces rects of height 58px!).
- */
- function areRectsOnOneLine(rects, lineHeight) {
- var minTop = Infinity;
- var minBottom = Infinity;
- var maxTop = -Infinity;
- var maxBottom = -Infinity;
-
- for (var ii = 0; ii < rects.length; ii++) {
- var rect = rects[ii];
- if (rect.width === 0 || rect.width === 1) {
- // When a range starts or ends a soft wrap, many browsers (Chrome, IE,
- // Safari) include an empty rect on the previous or next line. When the
- // text lies in a container whose position is not integral (e.g., from
- // margin: auto), Safari makes these empty rects have width 1 (instead of
- // 0). Having one-pixel-wide characters seems unlikely (and most browsers
- // report widths in subpixel precision anyway) so it's relatively safe to
- // skip over them.
- continue;
- }
- minTop = Math.min(minTop, rect.top);
- minBottom = Math.min(minBottom, rect.bottom);
- maxTop = Math.max(maxTop, rect.top);
- maxBottom = Math.max(maxBottom, rect.bottom);
- }
-
- return maxTop <= minBottom && maxTop - minTop < lineHeight && maxBottom - minBottom < lineHeight;
- }
-
- /**
- * Return the length of a node, as used by Range offsets.
- */
- function getNodeLength$1(node) {
- // http://www.w3.org/TR/dom/#concept-node-length
- switch (node.nodeType) {
- case Node.DOCUMENT_TYPE_NODE:
- return 0;
- case Node.TEXT_NODE:
- case Node.PROCESSING_INSTRUCTION_NODE:
- case Node.COMMENT_NODE:
- return node.length;
- default:
- return node.childNodes.length;
- }
- }
-
- /**
- * Given a collapsed range, move the start position backwards as far as
- * possible while the range still spans only a single line.
- */
- function expandRangeToStartOfLine(range) {
- !range.collapsed ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'expandRangeToStartOfLine: Provided range is not collapsed.') : invariant_1(false) : void 0;
- range = range.cloneRange();
-
- var containingElement = range.startContainer;
- if (containingElement.nodeType !== 1) {
- containingElement = containingElement.parentNode;
- }
- var lineHeight = getLineHeightPx(containingElement);
-
- // Imagine our text looks like:
- // <div><span>once upon a time, there was a <em>boy
- // who lived</em> </span><q><strong>under^ the
- // stairs</strong> in a small closet.</q></div>
- // where the caret represents the cursor. First, we crawl up the tree until
- // the range spans multiple lines (setting the start point to before
- // "<strong>", then before "<div>"), then at each level we do a search to
- // find the latest point which is still on a previous line. We'll find that
- // the break point is inside the span, then inside the <em>, then in its text
- // node child, the actual break point before "who".
-
- var bestContainer = range.endContainer;
- var bestOffset = range.endOffset;
- range.setStart(range.startContainer, 0);
-
- while (areRectsOnOneLine(getRangeClientRects_1(range), lineHeight)) {
- bestContainer = range.startContainer;
- bestOffset = range.startOffset;
- !bestContainer.parentNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Found unexpected detached subtree when traversing.') : invariant_1(false) : void 0;
- range.setStartBefore(bestContainer);
- if (bestContainer.nodeType === 1 && getComputedStyle(bestContainer).display !== 'inline') {
- // The start of the line is never in a different block-level container.
- break;
- }
- }
-
- // In the above example, range now spans from "<div>" to "under",
- // bestContainer is <div>, and bestOffset is 1 (index of <q> inside <div>)].
- // Picking out which child to recurse into here is a special case since we
- // don't want to check past <q> -- once we find that the final range starts
- // in <span>, we can look at all of its children (and all of their children)
- // to find the break point.
-
- // At all times, (bestContainer, bestOffset) is the latest single-line start
- // point that we know of.
- var currentContainer = bestContainer;
- var maxIndexToConsider = bestOffset - 1;
-
- do {
- var nodeValue = currentContainer.nodeValue;
-
- for (var ii = maxIndexToConsider; ii >= 0; ii--) {
- if (nodeValue != null && ii > 0 && UnicodeUtils_1.isSurrogatePair(nodeValue, ii - 1)) {
- // We're in the middle of a surrogate pair -- skip over so we never
- // return a range with an endpoint in the middle of a code point.
- continue;
- }
-
- range.setStart(currentContainer, ii);
- if (areRectsOnOneLine(getRangeClientRects_1(range), lineHeight)) {
- bestContainer = currentContainer;
- bestOffset = ii;
- } else {
- break;
- }
- }
-
- if (ii === -1 || currentContainer.childNodes.length === 0) {
- // If ii === -1, then (bestContainer, bestOffset), which is equal to
- // (currentContainer, 0), was a single-line start point but a start
- // point before currentContainer wasn't, so the line break seems to
- // have occurred immediately after currentContainer's start tag
- //
- // If currentContainer.childNodes.length === 0, we're already at a
- // terminal node (e.g., text node) and should return our current best.
- break;
- }
-
- currentContainer = currentContainer.childNodes[ii];
- maxIndexToConsider = getNodeLength$1(currentContainer);
- } while (true);
-
- range.setStart(bestContainer, bestOffset);
- return range;
- }
-
- var expandRangeToStartOfLine_1 = expandRangeToStartOfLine;
-
- /**
- * Convert the current selection range to an anchor/focus pair of offset keys
- * and values that can be interpreted by components.
- */
- function getDraftEditorSelectionWithNodes(editorState, root, anchorNode, anchorOffset, focusNode, focusOffset) {
- var anchorIsTextNode = anchorNode.nodeType === Node.TEXT_NODE;
- var focusIsTextNode = focusNode.nodeType === Node.TEXT_NODE;
-
- // If the selection range lies only on text nodes, the task is simple.
- // Find the nearest offset-aware elements and use the
- // offset values supplied by the selection range.
- if (anchorIsTextNode && focusIsTextNode) {
- return {
- selectionState: getUpdatedSelectionState_1(editorState, nullthrows_1(findAncestorOffsetKey_1(anchorNode)), anchorOffset, nullthrows_1(findAncestorOffsetKey_1(focusNode)), focusOffset),
- needsRecovery: false
- };
- }
-
- var anchorPoint = null;
- var focusPoint = null;
- var needsRecovery = true;
-
- // An element is selected. Convert this selection range into leaf offset
- // keys and offset values for consumption at the component level. This
- // is common in Firefox, where select-all and triple click behavior leads
- // to entire elements being selected.
- //
- // Note that we use the `needsRecovery` parameter in the callback here. This
- // is because when certain elements are selected, the behavior for subsequent
- // cursor movement (e.g. via arrow keys) is uncertain and may not match
- // expectations at the component level. For example, if an entire <div> is
- // selected and the user presses the right arrow, Firefox keeps the selection
- // on the <div>. If we allow subsequent keypresses to insert characters
- // natively, they will be inserted into a browser-created text node to the
- // right of that <div>. This is obviously undesirable.
- //
- // With the `needsRecovery` flag, we inform the caller that it is responsible
- // for manually setting the selection state on the rendered document to
- // ensure proper selection state maintenance.
-
- if (anchorIsTextNode) {
- anchorPoint = {
- key: nullthrows_1(findAncestorOffsetKey_1(anchorNode)),
- offset: anchorOffset
- };
- focusPoint = getPointForNonTextNode(root, focusNode, focusOffset);
- } else if (focusIsTextNode) {
- focusPoint = {
- key: nullthrows_1(findAncestorOffsetKey_1(focusNode)),
- offset: focusOffset
- };
- anchorPoint = getPointForNonTextNode(root, anchorNode, anchorOffset);
- } else {
- anchorPoint = getPointForNonTextNode(root, anchorNode, anchorOffset);
- focusPoint = getPointForNonTextNode(root, focusNode, focusOffset);
-
- // If the selection is collapsed on an empty block, don't force recovery.
- // This way, on arrow key selection changes, the browser can move the
- // cursor from a non-zero offset on one block, through empty blocks,
- // to a matching non-zero offset on other text blocks.
- if (anchorNode === focusNode && anchorOffset === focusOffset) {
- needsRecovery = !!anchorNode.firstChild && anchorNode.firstChild.nodeName !== 'BR';
- }
- }
-
- return {
- selectionState: getUpdatedSelectionState_1(editorState, anchorPoint.key, anchorPoint.offset, focusPoint.key, focusPoint.offset),
- needsRecovery: needsRecovery
- };
- }
-
- /**
- * Identify the first leaf descendant for the given node.
- */
- function getFirstLeaf(node) {
- while (node.firstChild && (
- // data-blocks has no offset
- node.firstChild instanceof Element && node.firstChild.getAttribute('data-blocks') === 'true' || getSelectionOffsetKeyForNode_1(node.firstChild))) {
- node = node.firstChild;
- }
- return node;
- }
-
- /**
- * Identify the last leaf descendant for the given node.
- */
- function getLastLeaf(node) {
- while (node.lastChild && (
- // data-blocks has no offset
- node.lastChild instanceof Element && node.lastChild.getAttribute('data-blocks') === 'true' || getSelectionOffsetKeyForNode_1(node.lastChild))) {
- node = node.lastChild;
- }
- return node;
- }
-
- function getPointForNonTextNode(editorRoot, startNode, childOffset) {
- var node = startNode;
- var offsetKey = findAncestorOffsetKey_1(node);
-
- !(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;
-
- // If the editorRoot is the selection, step downward into the content
- // wrapper.
- if (editorRoot === node) {
- node = node.firstChild;
- !(node instanceof Element && node.getAttribute('data-contents') === 'true') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid DraftEditorContents structure.') : invariant_1(false) : void 0;
- if (childOffset > 0) {
- childOffset = node.childNodes.length;
- }
- }
-
- // If the child offset is zero and we have an offset key, we're done.
- // If there's no offset key because the entire editor is selected,
- // find the leftmost ("first") leaf in the tree and use that as the offset
- // key.
- if (childOffset === 0) {
- var key = null;
- if (offsetKey != null) {
- key = offsetKey;
- } else {
- var firstLeaf = getFirstLeaf(node);
- key = nullthrows_1(getSelectionOffsetKeyForNode_1(firstLeaf));
- }
- return { key: key, offset: 0 };
- }
-
- var nodeBeforeCursor = node.childNodes[childOffset - 1];
- var leafKey = null;
- var textLength = null;
-
- if (!getSelectionOffsetKeyForNode_1(nodeBeforeCursor)) {
- // Our target node may be a leaf or a text node, in which case we're
- // already where we want to be and can just use the child's length as
- // our offset.
- leafKey = nullthrows_1(offsetKey);
- textLength = getTextContentLength(nodeBeforeCursor);
- } else {
- // Otherwise, we'll look at the child to the left of the cursor and find
- // the last leaf node in its subtree.
- var lastLeaf = getLastLeaf(nodeBeforeCursor);
- leafKey = nullthrows_1(getSelectionOffsetKeyForNode_1(lastLeaf));
- textLength = getTextContentLength(lastLeaf);
- }
-
- return {
- key: leafKey,
- offset: textLength
- };
- }
-
- /**
- * Return the length of a node's textContent, regarding single newline
- * characters as zero-length. This allows us to avoid problems with identifying
- * the correct selection offset for empty blocks in IE, in which we
- * render newlines instead of break tags.
- */
- function getTextContentLength(node) {
- var textContent = node.textContent;
- return textContent === '\n' ? 0 : textContent.length;
- }
-
- var getDraftEditorSelectionWithNodes_1 = getDraftEditorSelectionWithNodes;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule moveSelectionBackward
- * @format
- *
- */
-
- /**
- * Given a collapsed selection, move the focus `maxDistance` backward within
- * the selected block. If the selection will go beyond the start of the block,
- * move focus to the end of the previous block, but no further.
- *
- * This function is not Unicode-aware, so surrogate pairs will be treated
- * as having length 2.
- */
- function moveSelectionBackward(editorState, maxDistance) {
- var selection = editorState.getSelection();
- var content = editorState.getCurrentContent();
- var key = selection.getStartKey();
- var offset = selection.getStartOffset();
-
- var focusKey = key;
- var focusOffset = 0;
-
- if (maxDistance > offset) {
- var keyBefore = content.getKeyBefore(key);
- if (keyBefore == null) {
- focusKey = key;
- } else {
- focusKey = keyBefore;
- var blockBefore = content.getBlockForKey(keyBefore);
- focusOffset = blockBefore.getText().length;
- }
- } else {
- focusOffset = offset - maxDistance;
- }
-
- return selection.merge({
- focusKey: focusKey,
- focusOffset: focusOffset,
- isBackward: true
- });
- }
-
- var moveSelectionBackward_1 = moveSelectionBackward;
-
- /**
- * For a collapsed selection state, remove text based on the specified strategy.
- * If the selection state is not collapsed, remove the entire selected range.
- */
- function removeTextWithStrategy(editorState, strategy, direction) {
- var selection = editorState.getSelection();
- var content = editorState.getCurrentContent();
- var target = selection;
- if (selection.isCollapsed()) {
- if (direction === 'forward') {
- if (editorState.isSelectionAtEndOfContent()) {
- return content;
- }
- } else if (editorState.isSelectionAtStartOfContent()) {
- return content;
- }
-
- target = strategy(editorState);
- if (target === selection) {
- return content;
- }
- }
- return DraftModifier_1.removeRange(content, target, direction);
- }
-
- var removeTextWithStrategy_1 = removeTextWithStrategy;
-
- function keyCommandBackspaceToStartOfLine(editorState) {
- var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
- var selection = strategyState.getSelection();
- if (selection.isCollapsed() && selection.getAnchorOffset() === 0) {
- return moveSelectionBackward_1(strategyState, 1);
- }
-
- var domSelection = _commonjsHelpers.commonjsGlobal.getSelection();
- var range = domSelection.getRangeAt(0);
- range = expandRangeToStartOfLine_1(range);
-
- return getDraftEditorSelectionWithNodes_1(strategyState, null, range.endContainer, range.endOffset, range.startContainer, range.startOffset).selectionState;
- }, 'backward');
-
- if (afterRemoval === editorState.getCurrentContent()) {
- return editorState;
- }
-
- return EditorState_1.push(editorState, afterRemoval, 'remove-range');
- }
-
- var keyCommandBackspaceToStartOfLine_1 = keyCommandBackspaceToStartOfLine;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- * @typechecks
- * @stub
- *
- */
-
- // \u00a1-\u00b1\u00b4-\u00b8\u00ba\u00bb\u00bf
- // is latin supplement punctuation except fractions and superscript
- // numbers
- // \u2010-\u2027\u2030-\u205e
- // is punctuation from the general punctuation block:
- // weird quotes, commas, bullets, dashes, etc.
- // \u30fb\u3001\u3002\u3008-\u3011\u3014-\u301f
- // is CJK punctuation
- // \uff1a-\uff1f\uff01-\uff0f\uff3b-\uff40\uff5b-\uff65
- // is some full-width/half-width punctuation
- // \u2E2E\u061f\u066a-\u066c\u061b\u060c\u060d\uFD3e\uFD3F
- // is some Arabic punctuation marks
- // \u1801\u0964\u104a\u104b
- // is misc. other language punctuation marks
-
- 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]';
-
- var TokenizeUtil = {
- getPunctuation: function getPunctuation() {
- return PUNCTUATION;
- }
- };
-
- var punctuation = TokenizeUtil.getPunctuation();
-
- // The apostrophe and curly single quotes behave in a curious way: when
- // surrounded on both sides by word characters, they behave as word chars; when
- // either neighbor is punctuation or an end of the string, they behave as
- // punctuation.
- var CHAMELEON_CHARS = '[\'\u2018\u2019]';
-
- // Remove the underscore, which should count as part of the removable word. The
- // "chameleon chars" also count as punctuation in this regex.
- var WHITESPACE_AND_PUNCTUATION = '\\s|(?![_])' + punctuation;
-
- var DELETE_STRING = '^' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)';
- var DELETE_REGEX = new RegExp(DELETE_STRING);
-
- var BACKSPACE_STRING = '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '$';
- var BACKSPACE_REGEX = new RegExp(BACKSPACE_STRING);
-
- function getRemovableWord(text, isBackward) {
- var matches = isBackward ? BACKSPACE_REGEX.exec(text) : DELETE_REGEX.exec(text);
- return matches ? matches[0] : text;
- }
-
- var DraftRemovableWord = {
- getBackward: function getBackward(text) {
- return getRemovableWord(text, true);
- },
-
- getForward: function getForward(text) {
- return getRemovableWord(text, false);
- }
- };
-
- var DraftRemovableWord_1 = DraftRemovableWord;
-
- /**
- * Delete the word that is left of the cursor, as well as any spaces or
- * punctuation after the word.
- */
- function keyCommandBackspaceWord(editorState) {
- var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
- var selection = strategyState.getSelection();
- var offset = selection.getStartOffset();
- // If there are no words before the cursor, remove the preceding newline.
- if (offset === 0) {
- return moveSelectionBackward_1(strategyState, 1);
- }
- var key = selection.getStartKey();
- var content = strategyState.getCurrentContent();
- var text = content.getBlockForKey(key).getText().slice(0, offset);
- var toRemove = DraftRemovableWord_1.getBackward(text);
- return moveSelectionBackward_1(strategyState, toRemove.length || 1);
- }, 'backward');
-
- if (afterRemoval === editorState.getCurrentContent()) {
- return editorState;
- }
-
- return EditorState_1.push(editorState, afterRemoval, 'remove-range');
- }
-
- var keyCommandBackspaceWord_1 = keyCommandBackspaceWord;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule moveSelectionForward
- * @format
- *
- */
-
- /**
- * Given a collapsed selection, move the focus `maxDistance` forward within
- * the selected block. If the selection will go beyond the end of the block,
- * move focus to the start of the next block, but no further.
- *
- * This function is not Unicode-aware, so surrogate pairs will be treated
- * as having length 2.
- */
- function moveSelectionForward(editorState, maxDistance) {
- var selection = editorState.getSelection();
- var key = selection.getStartKey();
- var offset = selection.getStartOffset();
- var content = editorState.getCurrentContent();
-
- var focusKey = key;
- var focusOffset;
-
- var block = content.getBlockForKey(key);
-
- if (maxDistance > block.getText().length - offset) {
- focusKey = content.getKeyAfter(key);
- focusOffset = 0;
- } else {
- focusOffset = offset + maxDistance;
- }
-
- return selection.merge({ focusKey: focusKey, focusOffset: focusOffset });
- }
-
- var moveSelectionForward_1 = moveSelectionForward;
-
- /**
- * Delete the word that is right of the cursor, as well as any spaces or
- * punctuation before the word.
- */
- function keyCommandDeleteWord(editorState) {
- var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
- var selection = strategyState.getSelection();
- var offset = selection.getStartOffset();
- var key = selection.getStartKey();
- var content = strategyState.getCurrentContent();
- var text = content.getBlockForKey(key).getText().slice(offset);
- var toRemove = DraftRemovableWord_1.getForward(text);
-
- // If there are no words in front of the cursor, remove the newline.
- return moveSelectionForward_1(strategyState, toRemove.length || 1);
- }, 'forward');
-
- if (afterRemoval === editorState.getCurrentContent()) {
- return editorState;
- }
-
- return EditorState_1.push(editorState, afterRemoval, 'remove-range');
- }
-
- var keyCommandDeleteWord_1 = keyCommandDeleteWord;
-
- function keyCommandInsertNewline(editorState) {
- var contentState = DraftModifier_1.splitBlock(editorState.getCurrentContent(), editorState.getSelection());
- return EditorState_1.push(editorState, contentState, 'split-block');
- }
-
- var keyCommandInsertNewline_1 = keyCommandInsertNewline;
-
- /**
- * See comment for `moveSelectionToStartOfBlock`.
- */
- function keyCommandMoveSelectionToEndOfBlock(editorState) {
- var selection = editorState.getSelection();
- var endKey = selection.getEndKey();
- var content = editorState.getCurrentContent();
- var textLength = content.getBlockForKey(endKey).getLength();
- return EditorState_1.set(editorState, {
- selection: selection.merge({
- anchorKey: endKey,
- anchorOffset: textLength,
- focusKey: endKey,
- focusOffset: textLength,
- isBackward: false
- }),
- forceSelection: true
- });
- }
-
- var keyCommandMoveSelectionToEndOfBlock_1 = keyCommandMoveSelectionToEndOfBlock;
-
- /**
- * Collapse selection at the start of the first selected block. This is used
- * for Firefox versions that attempt to navigate forward/backward instead of
- * moving the cursor. Other browsers are able to move the cursor natively.
- */
- function keyCommandMoveSelectionToStartOfBlock(editorState) {
- var selection = editorState.getSelection();
- var startKey = selection.getStartKey();
- return EditorState_1.set(editorState, {
- selection: selection.merge({
- anchorKey: startKey,
- anchorOffset: 0,
- focusKey: startKey,
- focusOffset: 0,
- isBackward: false
- }),
- forceSelection: true
- });
- }
-
- var keyCommandMoveSelectionToStartOfBlock_1 = keyCommandMoveSelectionToStartOfBlock;
-
- /**
- * Remove the selected range. If the cursor is collapsed, remove the preceding
- * character. This operation is Unicode-aware, so removing a single character
- * will remove a surrogate pair properly as well.
- */
- function keyCommandPlainBackspace(editorState) {
- var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
- var selection = strategyState.getSelection();
- var content = strategyState.getCurrentContent();
- var key = selection.getAnchorKey();
- var offset = selection.getAnchorOffset();
- var charBehind = content.getBlockForKey(key).getText()[offset - 1];
- return moveSelectionBackward_1(strategyState, charBehind ? UnicodeUtils_1.getUTF16Length(charBehind, 0) : 1);
- }, 'backward');
-
- if (afterRemoval === editorState.getCurrentContent()) {
- return editorState;
- }
-
- var selection = editorState.getSelection();
- return EditorState_1.push(editorState, afterRemoval.set('selectionBefore', selection), selection.isCollapsed() ? 'backspace-character' : 'remove-range');
- }
-
- var keyCommandPlainBackspace_1 = keyCommandPlainBackspace;
-
- /**
- * Remove the selected range. If the cursor is collapsed, remove the following
- * character. This operation is Unicode-aware, so removing a single character
- * will remove a surrogate pair properly as well.
- */
- function keyCommandPlainDelete(editorState) {
- var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
- var selection = strategyState.getSelection();
- var content = strategyState.getCurrentContent();
- var key = selection.getAnchorKey();
- var offset = selection.getAnchorOffset();
- var charAhead = content.getBlockForKey(key).getText()[offset];
- return moveSelectionForward_1(strategyState, charAhead ? UnicodeUtils_1.getUTF16Length(charAhead, 0) : 1);
- }, 'forward');
-
- if (afterRemoval === editorState.getCurrentContent()) {
- return editorState;
- }
-
- var selection = editorState.getSelection();
-
- return EditorState_1.push(editorState, afterRemoval.set('selectionBefore', selection), selection.isCollapsed() ? 'delete-character' : 'remove-range');
- }
-
- var keyCommandPlainDelete_1 = keyCommandPlainDelete;
-
- /**
- * Transpose the characters on either side of a collapsed cursor, or
- * if the cursor is at the end of the block, transpose the last two
- * characters.
- */
- function keyCommandTransposeCharacters(editorState) {
- var selection = editorState.getSelection();
- if (!selection.isCollapsed()) {
- return editorState;
- }
-
- var offset = selection.getAnchorOffset();
- if (offset === 0) {
- return editorState;
- }
-
- var blockKey = selection.getAnchorKey();
- var content = editorState.getCurrentContent();
- var block = content.getBlockForKey(blockKey);
- var length = block.getLength();
-
- // Nothing to transpose if there aren't two characters.
- if (length <= 1) {
- return editorState;
- }
-
- var removalRange;
- var finalSelection;
-
- if (offset === length) {
- // The cursor is at the end of the block. Swap the last two characters.
- removalRange = selection.set('anchorOffset', offset - 1);
- finalSelection = selection;
- } else {
- removalRange = selection.set('focusOffset', offset + 1);
- finalSelection = removalRange.set('anchorOffset', offset + 1);
- }
-
- // Extract the character to move as a fragment. This preserves its
- // styling and entity, if any.
- var movedFragment = getContentStateFragment_1(content, removalRange);
- var afterRemoval = DraftModifier_1.removeRange(content, removalRange, 'backward');
-
- // After the removal, the insertion target is one character back.
- var selectionAfter = afterRemoval.getSelectionAfter();
- var targetOffset = selectionAfter.getAnchorOffset() - 1;
- var targetRange = selectionAfter.merge({
- anchorOffset: targetOffset,
- focusOffset: targetOffset
- });
-
- var afterInsert = DraftModifier_1.replaceWithFragment(afterRemoval, targetRange, movedFragment);
-
- var newEditorState = EditorState_1.push(editorState, afterInsert, 'insert-fragment');
-
- return EditorState_1.acceptSelection(newEditorState, finalSelection);
- }
-
- var keyCommandTransposeCharacters_1 = keyCommandTransposeCharacters;
-
- function keyCommandUndo(e, editorState, updateFn) {
- var undoneState = EditorState_1.undo(editorState);
-
- // If the last change to occur was a spellcheck change, allow the undo
- // event to fall through to the browser. This allows the browser to record
- // the unwanted change, which should soon lead it to learn not to suggest
- // the correction again.
- if (editorState.getLastChangeType() === 'spellcheck-change') {
- var nativelyRenderedContent = undoneState.getCurrentContent();
- updateFn(EditorState_1.set(undoneState, { nativelyRenderedContent: nativelyRenderedContent }));
- return;
- }
-
- // Otheriwse, manage the undo behavior manually.
- e.preventDefault();
- if (!editorState.getNativelyRenderedContent()) {
- updateFn(undoneState);
- return;
- }
-
- // Trigger a re-render with the current content state to ensure that the
- // component tree has up-to-date props for comparison.
- updateFn(EditorState_1.set(editorState, { nativelyRenderedContent: null }));
-
- // Wait to ensure that the re-render has occurred before performing
- // the undo action.
- setTimeout(function () {
- updateFn(undoneState);
- }, 0);
- }
-
- var keyCommandUndo_1 = keyCommandUndo;
-
- var isOptionKeyCommand = KeyBindingUtil_1.isOptionKeyCommand;
-
- var isChrome$1 = UserAgent_1.isBrowser('Chrome');
-
- /**
- * Map a `DraftEditorCommand` command value to a corresponding function.
- */
- function onKeyCommand(command, editorState) {
- switch (command) {
- case 'redo':
- return EditorState_1.redo(editorState);
- case 'delete':
- return keyCommandPlainDelete_1(editorState);
- case 'delete-word':
- return keyCommandDeleteWord_1(editorState);
- case 'backspace':
- return keyCommandPlainBackspace_1(editorState);
- case 'backspace-word':
- return keyCommandBackspaceWord_1(editorState);
- case 'backspace-to-start-of-line':
- return keyCommandBackspaceToStartOfLine_1(editorState);
- case 'split-block':
- return keyCommandInsertNewline_1(editorState);
- case 'transpose-characters':
- return keyCommandTransposeCharacters_1(editorState);
- case 'move-selection-to-start-of-block':
- return keyCommandMoveSelectionToStartOfBlock_1(editorState);
- case 'move-selection-to-end-of-block':
- return keyCommandMoveSelectionToEndOfBlock_1(editorState);
- case 'secondary-cut':
- return SecondaryClipboard_1.cut(editorState);
- case 'secondary-paste':
- return SecondaryClipboard_1.paste(editorState);
- default:
- return editorState;
- }
- }
-
- /**
- * Intercept keydown behavior to handle keys and commands manually, if desired.
- *
- * Keydown combinations may be mapped to `DraftCommand` values, which may
- * correspond to command functions that modify the editor or its contents.
- *
- * See `getDefaultKeyBinding` for defaults. Alternatively, the top-level
- * component may provide a custom mapping via the `keyBindingFn` prop.
- */
- function editOnKeyDown(editor, e) {
- var keyCode = e.which;
- var editorState = editor._latestEditorState;
-
- switch (keyCode) {
- case Keys.RETURN:
- e.preventDefault();
- // The top-level component may manually handle newline insertion. If
- // no special handling is performed, fall through to command handling.
- if (editor.props.handleReturn && isEventHandled_1(editor.props.handleReturn(e, editorState))) {
- return;
- }
- break;
- case Keys.ESC:
- e.preventDefault();
- editor.props.onEscape && editor.props.onEscape(e);
- return;
- case Keys.TAB:
- editor.props.onTab && editor.props.onTab(e);
- return;
- case Keys.UP:
- editor.props.onUpArrow && editor.props.onUpArrow(e);
- return;
- case Keys.RIGHT:
- editor.props.onRightArrow && editor.props.onRightArrow(e);
- return;
- case Keys.DOWN:
- editor.props.onDownArrow && editor.props.onDownArrow(e);
- return;
- case Keys.LEFT:
- editor.props.onLeftArrow && editor.props.onLeftArrow(e);
- return;
- case Keys.SPACE:
- // Handling for OSX where option + space scrolls.
- if (isChrome$1 && isOptionKeyCommand(e)) {
- e.preventDefault();
- // Insert a nbsp into the editor.
- var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), '\xA0');
- editor.update(EditorState_1.push(editorState, contentState, 'insert-characters'));
- return;
- }
- }
-
- var command = editor.props.keyBindingFn(e);
-
- // If no command is specified, allow keydown event to continue.
- if (!command) {
- return;
- }
-
- if (command === 'undo') {
- // Since undo requires some special updating behavior to keep the editor
- // in sync, handle it separately.
- keyCommandUndo_1(e, editorState, editor.update);
- return;
- }
-
- // At this point, we know that we're handling a command of some kind, so
- // we don't want to insert a character following the keydown.
- e.preventDefault();
-
- // Allow components higher up the tree to handle the command first.
- if (editor.props.handleKeyCommand && isEventHandled_1(editor.props.handleKeyCommand(command, editorState))) {
- return;
- }
-
- var newState = onKeyCommand(command, editorState);
- if (newState !== editorState) {
- editor.update(newState);
- }
- }
-
- var editOnKeyDown_1 = editOnKeyDown;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- *
- */
-
- function _classCallCheck$e(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
- var URI = function () {
- function URI(uri) {
- _classCallCheck$e(this, URI);
-
- this._uri = uri;
- }
-
- URI.prototype.toString = function toString() {
- return this._uri;
- };
-
- return URI;
- }();
-
- var URI_1 = URI;
-
- var isOldIE = UserAgent_1.isBrowser('IE <= 9');
-
- // Provides a dom node that will not execute scripts
- // https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation.createHTMLDocument
- // https://developer.mozilla.org/en-US/Add-ons/Code_snippets/HTML_to_DOM
-
- function getSafeBodyFromHTML(html) {
- var doc;
- var root = null;
- // Provides a safe context
- if (!isOldIE && document.implementation && document.implementation.createHTMLDocument) {
- doc = document.implementation.createHTMLDocument('foo');
- !doc.documentElement ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing doc.documentElement') : invariant_1(false) : void 0;
- doc.documentElement.innerHTML = html;
- root = doc.getElementsByTagName('body')[0];
- }
- return root;
- }
-
- var getSafeBodyFromHTML_1 = getSafeBodyFromHTML;
-
- 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; };
-
- var _knownListItemDepthCl;
-
- 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; }
-
-
-
-
-
-
-
-
-
- var _require = immutable,
- Set = _require.Set;
-
-
-
-
-
-
-
-
-
- var experimentalTreeDataSupport = DraftFeatureFlags_1.draft_tree_data_support;
-
- var List$a = immutable.List,
- OrderedSet$5 = immutable.OrderedSet;
-
-
- var NBSP = ' ';
- var SPACE = ' ';
-
- // Arbitrary max indent
- var MAX_DEPTH = 4;
-
- // used for replacing characters in HTML
- var REGEX_CR = new RegExp('\r', 'g');
- var REGEX_LF = new RegExp('\n', 'g');
- var REGEX_NBSP = new RegExp(NBSP, 'g');
- var REGEX_CARRIAGE = new RegExp(' ?', 'g');
- var REGEX_ZWS = new RegExp('​?', 'g');
-
- // https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight
- var boldValues = ['bold', 'bolder', '500', '600', '700', '800', '900'];
- var notBoldValues = ['light', 'lighter', '100', '200', '300', '400'];
-
- // Block tag flow is different because LIs do not have
- // a deterministic style ;_;
- var inlineTags = {
- b: 'BOLD',
- code: 'CODE',
- del: 'STRIKETHROUGH',
- em: 'ITALIC',
- i: 'ITALIC',
- s: 'STRIKETHROUGH',
- strike: 'STRIKETHROUGH',
- strong: 'BOLD',
- u: 'UNDERLINE'
- };
-
- 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);
-
- var anchorAttr = ['className', 'href', 'rel', 'target', 'title'];
-
- var imgAttr = ['alt', 'className', 'height', 'src', 'width'];
-
- var lastBlock = void 0;
-
- var EMPTY_CHUNK = {
- text: '',
- inlines: [],
- entities: [],
- blocks: []
- };
-
- var EMPTY_BLOCK = {
- children: List$a(),
- depth: 0,
- key: '',
- type: ''
- };
-
- var getListBlockType = function getListBlockType(tag, lastList) {
- if (tag === 'li') {
- return lastList === 'ol' ? 'ordered-list-item' : 'unordered-list-item';
- }
- return null;
- };
-
- var getBlockMapSupportedTags = function getBlockMapSupportedTags(blockRenderMap) {
- var unstyledElement = blockRenderMap.get('unstyled').element;
- var tags = Set([]);
-
- blockRenderMap.forEach(function (draftBlock) {
- if (draftBlock.aliasedElements) {
- draftBlock.aliasedElements.forEach(function (tag) {
- tags = tags.add(tag);
- });
- }
-
- tags = tags.add(draftBlock.element);
- });
-
- return tags.filter(function (tag) {
- return tag && tag !== unstyledElement;
- }).toArray().sort();
- };
-
- // custom element conversions
- var getMultiMatchedType = function getMultiMatchedType(tag, lastList, multiMatchExtractor) {
- for (var ii = 0; ii < multiMatchExtractor.length; ii++) {
- var matchType = multiMatchExtractor[ii](tag, lastList);
- if (matchType) {
- return matchType;
- }
- }
- return null;
- };
-
- var getBlockTypeForTag = function getBlockTypeForTag(tag, lastList, blockRenderMap) {
- var matchedTypes = blockRenderMap.filter(function (draftBlock) {
- return draftBlock.element === tag || draftBlock.wrapper === tag || draftBlock.aliasedElements && draftBlock.aliasedElements.some(function (alias) {
- return alias === tag;
- });
- }).keySeq().toSet().toArray().sort();
-
- // if we dont have any matched type, return unstyled
- // if we have one matched type return it
- // if we have multi matched types use the multi-match function to gather type
- switch (matchedTypes.length) {
- case 0:
- return 'unstyled';
- case 1:
- return matchedTypes[0];
- default:
- return getMultiMatchedType(tag, lastList, [getListBlockType]) || 'unstyled';
- }
- };
-
- var processInlineTag = function processInlineTag(tag, node, currentStyle) {
- var styleToCheck = inlineTags[tag];
- if (styleToCheck) {
- currentStyle = currentStyle.add(styleToCheck).toOrderedSet();
- } else if (node instanceof HTMLElement) {
- var htmlElement = node;
- currentStyle = currentStyle.withMutations(function (style) {
- var fontWeight = htmlElement.style.fontWeight;
- var fontStyle = htmlElement.style.fontStyle;
- var textDecoration = htmlElement.style.textDecoration;
-
- if (boldValues.indexOf(fontWeight) >= 0) {
- style.add('BOLD');
- } else if (notBoldValues.indexOf(fontWeight) >= 0) {
- style.remove('BOLD');
- }
-
- if (fontStyle === 'italic') {
- style.add('ITALIC');
- } else if (fontStyle === 'normal') {
- style.remove('ITALIC');
- }
-
- if (textDecoration === 'underline') {
- style.add('UNDERLINE');
- }
- if (textDecoration === 'line-through') {
- style.add('STRIKETHROUGH');
- }
- if (textDecoration === 'none') {
- style.remove('UNDERLINE');
- style.remove('STRIKETHROUGH');
- }
- }).toOrderedSet();
- }
- return currentStyle;
- };
-
- var joinChunks = function joinChunks(A, B, experimentalHasNestedBlocks) {
- // Sometimes two blocks will touch in the DOM and we need to strip the
- // extra delimiter to preserve niceness.
- var lastInA = A.text.slice(-1);
- var firstInB = B.text.slice(0, 1);
-
- if (lastInA === '\r' && firstInB === '\r' && !experimentalHasNestedBlocks) {
- A.text = A.text.slice(0, -1);
- A.inlines.pop();
- A.entities.pop();
- A.blocks.pop();
- }
-
- // Kill whitespace after blocks
- if (lastInA === '\r') {
- if (B.text === SPACE || B.text === '\n') {
- return A;
- } else if (firstInB === SPACE || firstInB === '\n') {
- B.text = B.text.slice(1);
- B.inlines.shift();
- B.entities.shift();
- }
- }
-
- return {
- text: A.text + B.text,
- inlines: A.inlines.concat(B.inlines),
- entities: A.entities.concat(B.entities),
- blocks: A.blocks.concat(B.blocks)
- };
- };
-
- /**
- * Check to see if we have anything like <p> <blockquote> <h1>... to create
- * block tags from. If we do, we can use those and ignore <div> tags. If we
- * don't, we can treat <div> tags as meaningful (unstyled) blocks.
- */
- var containsSemanticBlockMarkup = function containsSemanticBlockMarkup(html, blockTags) {
- return blockTags.some(function (tag) {
- return html.indexOf('<' + tag) !== -1;
- });
- };
-
- var hasValidLinkText = function hasValidLinkText(link) {
- !(link instanceof HTMLAnchorElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Link must be an HTMLAnchorElement.') : invariant_1(false) : void 0;
- var protocol = link.protocol;
- return protocol === 'http:' || protocol === 'https:' || protocol === 'mailto:';
- };
-
- var getWhitespaceChunk = function getWhitespaceChunk(inEntity) {
- var entities = new Array(1);
- if (inEntity) {
- entities[0] = inEntity;
- }
- return _extends$4({}, EMPTY_CHUNK, {
- text: SPACE,
- inlines: [OrderedSet$5()],
- entities: entities
- });
- };
-
- var getSoftNewlineChunk = function getSoftNewlineChunk() {
- return _extends$4({}, EMPTY_CHUNK, {
- text: '\n',
- inlines: [OrderedSet$5()],
- entities: new Array(1)
- });
- };
-
- var getChunkedBlock = function getChunkedBlock() {
- var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
-
- return _extends$4({}, EMPTY_BLOCK, props);
- };
-
- var getBlockDividerChunk = function getBlockDividerChunk(block, depth) {
- var parentKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
-
- return {
- text: '\r',
- inlines: [OrderedSet$5()],
- entities: new Array(1),
- blocks: [getChunkedBlock({
- parent: parentKey,
- key: generateRandomKey_1(),
- type: block,
- depth: Math.max(0, Math.min(MAX_DEPTH, depth))
- })]
- };
- };
-
- /**
- * If we're pasting from one DraftEditor to another we can check to see if
- * existing list item depth classes are being used and preserve this style
- */
- var getListItemDepth = function getListItemDepth(node) {
- var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
-
- Object.keys(knownListItemDepthClasses).some(function (depthClass) {
- if (node.classList.contains(depthClass)) {
- depth = knownListItemDepthClasses[depthClass];
- }
- });
- return depth;
- };
-
- var genFragment = function genFragment(entityMap, node, inlineStyle, lastList, inBlock, blockTags, depth, blockRenderMap, inEntity, parentKey) {
- var lastLastBlock = lastBlock;
- var nodeName = node.nodeName.toLowerCase();
- var newEntityMap = entityMap;
- var nextBlockType = 'unstyled';
- var newBlock = false;
- var inBlockType = inBlock && getBlockTypeForTag(inBlock, lastList, blockRenderMap);
- var chunk = _extends$4({}, EMPTY_CHUNK);
- var newChunk = null;
- var blockKey = void 0;
-
- // Base Case
- if (nodeName === '#text') {
- var _text = node.textContent;
- var nodeTextContent = _text.trim();
-
- // We should not create blocks for leading spaces that are
- // existing around ol/ul and their children list items
- if (lastList && nodeTextContent === '' && node.parentElement) {
- var parentNodeName = node.parentElement.nodeName.toLowerCase();
- if (parentNodeName === 'ol' || parentNodeName === 'ul') {
- return { chunk: _extends$4({}, EMPTY_CHUNK), entityMap: entityMap };
- }
- }
-
- if (nodeTextContent === '' && inBlock !== 'pre') {
- return { chunk: getWhitespaceChunk(inEntity), entityMap: entityMap };
- }
- if (inBlock !== 'pre') {
- // Can't use empty string because MSWord
- _text = _text.replace(REGEX_LF, SPACE);
- }
-
- // save the last block so we can use it later
- lastBlock = nodeName;
-
- return {
- chunk: {
- text: _text,
- inlines: Array(_text.length).fill(inlineStyle),
- entities: Array(_text.length).fill(inEntity),
- blocks: []
- },
- entityMap: entityMap
- };
- }
-
- // save the last block so we can use it later
- lastBlock = nodeName;
-
- // BR tags
- if (nodeName === 'br') {
- if (lastLastBlock === 'br' && (!inBlock || inBlockType === 'unstyled')) {
- return {
- chunk: getBlockDividerChunk('unstyled', depth, parentKey),
- entityMap: entityMap
- };
- }
- return { chunk: getSoftNewlineChunk(), entityMap: entityMap };
- }
-
- // IMG tags
- if (nodeName === 'img' && node instanceof HTMLImageElement && node.attributes.getNamedItem('src') && node.attributes.getNamedItem('src').value) {
- var image = node;
- var entityConfig = {};
-
- imgAttr.forEach(function (attr) {
- var imageAttribute = image.getAttribute(attr);
- if (imageAttribute) {
- entityConfig[attr] = imageAttribute;
- }
- });
- // Forcing this node to have children because otherwise no entity will be
- // created for this node.
- // The child text node cannot just have a space or return as content -
- // we strip those out.
- // See https://github.com/facebook/draft-js/issues/231 for some context.
- node.textContent = '\uD83D\uDCF7';
-
- // TODO: update this when we remove DraftEntity entirely
- inEntity = DraftEntity_1.__create('IMAGE', 'MUTABLE', entityConfig || {});
- }
-
- // Inline tags
- inlineStyle = processInlineTag(nodeName, node, inlineStyle);
-
- // Handle lists
- if (nodeName === 'ul' || nodeName === 'ol') {
- if (lastList) {
- depth += 1;
- }
- lastList = nodeName;
- }
-
- if ( nodeName === 'li' && node instanceof HTMLElement) {
- depth = getListItemDepth(node, depth);
- }
-
- var blockType = getBlockTypeForTag(nodeName, lastList, blockRenderMap);
- var inListBlock = lastList && inBlock === 'li' && nodeName === 'li';
- var inBlockOrHasNestedBlocks = (!inBlock || experimentalTreeDataSupport) && blockTags.indexOf(nodeName) !== -1;
-
- // Block Tags
- if (inListBlock || inBlockOrHasNestedBlocks) {
- chunk = getBlockDividerChunk(blockType, depth, parentKey);
- blockKey = chunk.blocks[0].key;
- inBlock = nodeName;
- newBlock = !experimentalTreeDataSupport;
- }
-
- // this is required so that we can handle 'ul' and 'ol'
- if (inListBlock) {
- nextBlockType = lastList === 'ul' ? 'unordered-list-item' : 'ordered-list-item';
- }
-
- // Recurse through children
- var child = node.firstChild;
- if (child != null) {
- nodeName = child.nodeName.toLowerCase();
- }
-
- var entityId = null;
-
- while (child) {
- if (child instanceof HTMLAnchorElement && child.href && hasValidLinkText(child)) {
- (function () {
- var anchor = child;
- var entityConfig = {};
-
- anchorAttr.forEach(function (attr) {
- var anchorAttribute = anchor.getAttribute(attr);
- if (anchorAttribute) {
- entityConfig[attr] = anchorAttribute;
- }
- });
-
- entityConfig.url = new URI_1(anchor.href).toString();
- // TODO: update this when we remove DraftEntity completely
- entityId = DraftEntity_1.__create('LINK', 'MUTABLE', entityConfig || {});
- })();
- } else {
- entityId = undefined;
- }
-
- var _genFragment = genFragment(newEntityMap, child, inlineStyle, lastList, inBlock, blockTags, depth, blockRenderMap, entityId || inEntity, null),
- generatedChunk = _genFragment.chunk,
- maybeUpdatedEntityMap = _genFragment.entityMap;
-
- newChunk = generatedChunk;
- newEntityMap = maybeUpdatedEntityMap;
-
- chunk = joinChunks(chunk, newChunk, experimentalTreeDataSupport);
- var sibling = child.nextSibling;
-
- // Put in a newline to break up blocks inside blocks
- if (!parentKey && sibling && blockTags.indexOf(nodeName) >= 0 && inBlock) {
- chunk = joinChunks(chunk, getSoftNewlineChunk());
- }
- if (sibling) {
- nodeName = sibling.nodeName.toLowerCase();
- }
- child = sibling;
- }
-
- if (newBlock) {
- chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, parentKey));
- }
-
- return { chunk: chunk, entityMap: newEntityMap };
- };
-
- var getChunkForHTML = function getChunkForHTML(html, DOMBuilder, blockRenderMap, entityMap) {
- html = html.trim().replace(REGEX_CR, '').replace(REGEX_NBSP, SPACE).replace(REGEX_CARRIAGE, '').replace(REGEX_ZWS, '');
-
- var supportedBlockTags = getBlockMapSupportedTags(blockRenderMap);
-
- var safeBody = DOMBuilder(html);
- if (!safeBody) {
- return null;
- }
- lastBlock = null;
-
- // Sometimes we aren't dealing with content that contains nice semantic
- // tags. In this case, use divs to separate everything out into paragraphs
- // and hope for the best.
- var workingBlocks = containsSemanticBlockMarkup(html, supportedBlockTags) ? supportedBlockTags : ['div'];
-
- // Start with -1 block depth to offset the fact that we are passing in a fake
- // UL block to start with.
- var fragment = genFragment(entityMap, safeBody, OrderedSet$5(), 'ul', null, workingBlocks, -1, blockRenderMap);
-
- var chunk = fragment.chunk;
- var newEntityMap = fragment.entityMap;
-
- // join with previous block to prevent weirdness on paste
- if (chunk.text.indexOf('\r') === 0) {
- chunk = {
- text: chunk.text.slice(1),
- inlines: chunk.inlines.slice(1),
- entities: chunk.entities.slice(1),
- blocks: chunk.blocks
- };
- }
-
- // Kill block delimiter at the end
- if (chunk.text.slice(-1) === '\r') {
- chunk.text = chunk.text.slice(0, -1);
- chunk.inlines = chunk.inlines.slice(0, -1);
- chunk.entities = chunk.entities.slice(0, -1);
- chunk.blocks.pop();
- }
-
- // If we saw no block tags, put an unstyled one in
- if (chunk.blocks.length === 0) {
- chunk.blocks.push(_extends$4({}, EMPTY_CHUNK, {
- type: 'unstyled',
- depth: 0
- }));
- }
-
- // Sometimes we start with text that isn't in a block, which is then
- // followed by blocks. Need to fix up the blocks to add in
- // an unstyled block for this content
- if (chunk.text.split('\r').length === chunk.blocks.length + 1) {
- chunk.blocks.unshift({ type: 'unstyled', depth: 0 });
- }
-
- return { chunk: chunk, entityMap: newEntityMap };
- };
-
- var convertChunkToContentBlocks = function convertChunkToContentBlocks(chunk) {
- if (!chunk || !chunk.text || !Array.isArray(chunk.blocks)) {
- return null;
- }
-
- var initialState = {
- cacheRef: {},
- contentBlocks: []
- };
-
- var start = 0;
-
- var rawBlocks = chunk.blocks,
- rawInlines = chunk.inlines,
- rawEntities = chunk.entities;
-
-
- var BlockNodeRecord = ContentBlock_1;
-
- return chunk.text.split('\r').reduce(function (acc, textBlock, index) {
- // Make absolutely certain that our text is acceptable.
- textBlock = sanitizeDraftText_1(textBlock);
-
- var block = rawBlocks[index];
- var end = start + textBlock.length;
- var inlines = rawInlines.slice(start, end);
- var entities = rawEntities.slice(start, end);
- var characterList = List$a(inlines.map(function (style, index) {
- var data = { style: style, entity: null };
- if (entities[index]) {
- data.entity = entities[index];
- }
- return CharacterMetadata_1.create(data);
- }));
- start = end + 1;
-
- var depth = block.depth,
- type = block.type,
- parent = block.parent;
-
-
- var key = block.key || generateRandomKey_1();
- var parentTextNodeKey = null; // will be used to store container text nodes
-
- // childrens add themselves to their parents since we are iterating in order
- if (parent) {
- var parentIndex = acc.cacheRef[parent];
- var parentRecord = acc.contentBlocks[parentIndex];
-
- // if parent has text we need to split it into a separate unstyled element
- if (parentRecord.getChildKeys().isEmpty() && parentRecord.getText()) {
- var parentCharacterList = parentRecord.getCharacterList();
- var parentText = parentRecord.getText();
- parentTextNodeKey = generateRandomKey_1();
-
- var textNode = new ContentBlockNode_1({
- key: parentTextNodeKey,
- text: parentText,
- characterList: parentCharacterList,
- parent: parent,
- nextSibling: key
- });
-
- acc.contentBlocks.push(textNode);
-
- parentRecord = parentRecord.withMutations(function (block) {
- block.set('characterList', List$a()).set('text', '').set('children', parentRecord.children.push(textNode.getKey()));
- });
- }
-
- acc.contentBlocks[parentIndex] = parentRecord.set('children', parentRecord.children.push(key));
- }
-
- var blockNode = new BlockNodeRecord({
- key: key,
- parent: parent,
- type: type,
- depth: depth,
- text: textBlock,
- characterList: characterList,
- prevSibling: parentTextNodeKey || (index === 0 || rawBlocks[index - 1].parent !== parent ? null : rawBlocks[index - 1].key),
- nextSibling: index === rawBlocks.length - 1 || rawBlocks[index + 1].parent !== parent ? null : rawBlocks[index + 1].key
- });
-
- // insert node
- acc.contentBlocks.push(blockNode);
-
- // cache ref for building links
- acc.cacheRef[blockNode.key] = index;
-
- return acc;
- }, initialState).contentBlocks;
- };
-
- var convertFromHTMLtoContentBlocks = function convertFromHTMLtoContentBlocks(html) {
- var DOMBuilder = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getSafeBodyFromHTML_1;
- var blockRenderMap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DefaultDraftBlockRenderMap_1;
-
- // Be ABSOLUTELY SURE that the dom builder you pass here won't execute
- // arbitrary code in whatever environment you're running this in. For an
- // example of how we try to do this in-browser, see getSafeBodyFromHTML.
-
- // TODO: replace DraftEntity with an OrderedMap here
- var chunkData = getChunkForHTML(html, DOMBuilder, blockRenderMap, DraftEntity_1);
-
- if (chunkData == null) {
- return null;
- }
-
- var chunk = chunkData.chunk,
- entityMap = chunkData.entityMap;
-
- var contentBlocks = convertChunkToContentBlocks(chunk);
-
- return {
- contentBlocks: contentBlocks,
- entityMap: entityMap
- };
- };
-
- var convertFromHTMLToContentBlocks = convertFromHTMLtoContentBlocks;
-
- var List$b = immutable.List,
- Repeat$6 = immutable.Repeat;
- var ContentBlockRecord$2 = ContentBlock_1;
-
- var DraftPasteProcessor = {
- processHTML: function processHTML(html, blockRenderMap) {
- return convertFromHTMLToContentBlocks(html, getSafeBodyFromHTML_1, blockRenderMap);
- },
- processText: function processText(textBlocks, character, type) {
- return textBlocks.reduce(function (acc, textLine, index) {
- textLine = sanitizeDraftText_1(textLine);
- var key = generateRandomKey_1();
-
- var blockNodeConfig = {
- key: key,
- type: type,
- text: textLine,
- characterList: List$b(Repeat$6(character, textLine.length))
- };
-
- acc.push(new ContentBlockRecord$2(blockNodeConfig));
-
- return acc;
- }, []);
- }
- };
-
- var DraftPasteProcessor_1 = DraftPasteProcessor;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule adjustBlockDepthForContentState
- * @format
- *
- */
-
- function adjustBlockDepthForContentState(contentState, selectionState, adjustment, maxDepth) {
- var startKey = selectionState.getStartKey();
- var endKey = selectionState.getEndKey();
- var blockMap = contentState.getBlockMap();
- var blocks = blockMap.toSeq().skipUntil(function (_, k) {
- return k === startKey;
- }).takeUntil(function (_, k) {
- return k === endKey;
- }).concat([[endKey, blockMap.get(endKey)]]).map(function (block) {
- var depth = block.getDepth() + adjustment;
- depth = Math.max(0, Math.min(depth, maxDepth));
- return block.set('depth', depth);
- });
-
- blockMap = blockMap.merge(blocks);
-
- return contentState.merge({
- blockMap: blockMap,
- selectionBefore: selectionState,
- selectionAfter: selectionState
- });
- }
-
- var adjustBlockDepthForContentState_1 = adjustBlockDepthForContentState;
-
- var RichTextEditorUtil = {
- currentBlockContainsLink: function currentBlockContainsLink(editorState) {
- var selection = editorState.getSelection();
- var contentState = editorState.getCurrentContent();
- var entityMap = contentState.getEntityMap();
- return contentState.getBlockForKey(selection.getAnchorKey()).getCharacterList().slice(selection.getStartOffset(), selection.getEndOffset()).some(function (v) {
- var entity = v.getEntity();
- return !!entity && entityMap.__get(entity).getType() === 'LINK';
- });
- },
-
- getCurrentBlockType: function getCurrentBlockType(editorState) {
- var selection = editorState.getSelection();
- return editorState.getCurrentContent().getBlockForKey(selection.getStartKey()).getType();
- },
-
- getDataObjectForLinkURL: function getDataObjectForLinkURL(uri) {
- return { url: uri.toString() };
- },
-
- handleKeyCommand: function handleKeyCommand(editorState, command) {
- switch (command) {
- case 'bold':
- return RichTextEditorUtil.toggleInlineStyle(editorState, 'BOLD');
- case 'italic':
- return RichTextEditorUtil.toggleInlineStyle(editorState, 'ITALIC');
- case 'underline':
- return RichTextEditorUtil.toggleInlineStyle(editorState, 'UNDERLINE');
- case 'code':
- return RichTextEditorUtil.toggleCode(editorState);
- case 'backspace':
- case 'backspace-word':
- case 'backspace-to-start-of-line':
- return RichTextEditorUtil.onBackspace(editorState);
- case 'delete':
- case 'delete-word':
- case 'delete-to-end-of-block':
- return RichTextEditorUtil.onDelete(editorState);
- default:
- // they may have custom editor commands; ignore those
- return null;
- }
- },
-
- insertSoftNewline: function insertSoftNewline(editorState) {
- var contentState = DraftModifier_1.insertText(editorState.getCurrentContent(), editorState.getSelection(), '\n', editorState.getCurrentInlineStyle(), null);
-
- var newEditorState = EditorState_1.push(editorState, contentState, 'insert-characters');
-
- return EditorState_1.forceSelection(newEditorState, contentState.getSelectionAfter());
- },
-
- /**
- * For collapsed selections at the start of styled blocks, backspace should
- * just remove the existing style.
- */
- onBackspace: function onBackspace(editorState) {
- var selection = editorState.getSelection();
- if (!selection.isCollapsed() || selection.getAnchorOffset() || selection.getFocusOffset()) {
- return null;
- }
-
- // First, try to remove a preceding atomic block.
- var content = editorState.getCurrentContent();
- var startKey = selection.getStartKey();
- var blockBefore = content.getBlockBefore(startKey);
-
- if (blockBefore && blockBefore.getType() === 'atomic') {
- var blockMap = content.getBlockMap()['delete'](blockBefore.getKey());
- var withoutAtomicBlock = content.merge({
- blockMap: blockMap,
- selectionAfter: selection
- });
- if (withoutAtomicBlock !== content) {
- return EditorState_1.push(editorState, withoutAtomicBlock, 'remove-range');
- }
- }
-
- // If that doesn't succeed, try to remove the current block style.
- var withoutBlockStyle = RichTextEditorUtil.tryToRemoveBlockStyle(editorState);
-
- if (withoutBlockStyle) {
- return EditorState_1.push(editorState, withoutBlockStyle, 'change-block-type');
- }
-
- return null;
- },
-
- onDelete: function onDelete(editorState) {
- var selection = editorState.getSelection();
- if (!selection.isCollapsed()) {
- return null;
- }
-
- var content = editorState.getCurrentContent();
- var startKey = selection.getStartKey();
- var block = content.getBlockForKey(startKey);
- var length = block.getLength();
-
- // The cursor is somewhere within the text. Behave normally.
- if (selection.getStartOffset() < length) {
- return null;
- }
-
- var blockAfter = content.getBlockAfter(startKey);
-
- if (!blockAfter || blockAfter.getType() !== 'atomic') {
- return null;
- }
-
- var atomicBlockTarget = selection.merge({
- focusKey: blockAfter.getKey(),
- focusOffset: blockAfter.getLength()
- });
-
- var withoutAtomicBlock = DraftModifier_1.removeRange(content, atomicBlockTarget, 'forward');
-
- if (withoutAtomicBlock !== content) {
- return EditorState_1.push(editorState, withoutAtomicBlock, 'remove-range');
- }
-
- return null;
- },
-
- onTab: function onTab(event, editorState, maxDepth) {
- var selection = editorState.getSelection();
- var key = selection.getAnchorKey();
- if (key !== selection.getFocusKey()) {
- return editorState;
- }
-
- var content = editorState.getCurrentContent();
- var block = content.getBlockForKey(key);
- var type = block.getType();
- if (type !== 'unordered-list-item' && type !== 'ordered-list-item') {
- return editorState;
- }
-
- event.preventDefault();
-
- // Only allow indenting one level beyond the block above, and only if
- // the block above is a list item as well.
- var blockAbove = content.getBlockBefore(key);
- if (!blockAbove) {
- return editorState;
- }
-
- var typeAbove = blockAbove.getType();
- if (typeAbove !== 'unordered-list-item' && typeAbove !== 'ordered-list-item') {
- return editorState;
- }
-
- var depth = block.getDepth();
- if (!event.shiftKey && depth === maxDepth) {
- return editorState;
- }
-
- maxDepth = Math.min(blockAbove.getDepth() + 1, maxDepth);
-
- var withAdjustment = adjustBlockDepthForContentState_1(content, selection, event.shiftKey ? -1 : 1, maxDepth);
-
- return EditorState_1.push(editorState, withAdjustment, 'adjust-depth');
- },
-
- toggleBlockType: function toggleBlockType(editorState, blockType) {
- var selection = editorState.getSelection();
- var startKey = selection.getStartKey();
- var endKey = selection.getEndKey();
- var content = editorState.getCurrentContent();
- var target = selection;
-
- // Triple-click can lead to a selection that includes offset 0 of the
- // following block. The `SelectionState` for this case is accurate, but
- // we should avoid toggling block type for the trailing block because it
- // is a confusing interaction.
- if (startKey !== endKey && selection.getEndOffset() === 0) {
- var blockBefore = nullthrows_1(content.getBlockBefore(endKey));
- endKey = blockBefore.getKey();
- target = target.merge({
- anchorKey: startKey,
- anchorOffset: selection.getStartOffset(),
- focusKey: endKey,
- focusOffset: blockBefore.getLength(),
- isBackward: false
- });
- }
-
- var hasAtomicBlock = content.getBlockMap().skipWhile(function (_, k) {
- return k !== startKey;
- }).reverse().skipWhile(function (_, k) {
- return k !== endKey;
- }).some(function (v) {
- return v.getType() === 'atomic';
- });
-
- if (hasAtomicBlock) {
- return editorState;
- }
-
- var typeToSet = content.getBlockForKey(startKey).getType() === blockType ? 'unstyled' : blockType;
-
- return EditorState_1.push(editorState, DraftModifier_1.setBlockType(content, target, typeToSet), 'change-block-type');
- },
-
- toggleCode: function toggleCode(editorState) {
- var selection = editorState.getSelection();
- var anchorKey = selection.getAnchorKey();
- var focusKey = selection.getFocusKey();
-
- if (selection.isCollapsed() || anchorKey !== focusKey) {
- return RichTextEditorUtil.toggleBlockType(editorState, 'code-block');
- }
-
- return RichTextEditorUtil.toggleInlineStyle(editorState, 'CODE');
- },
-
- /**
- * Toggle the specified inline style for the selection. If the
- * user's selection is collapsed, apply or remove the style for the
- * internal state. If it is not collapsed, apply the change directly
- * to the document state.
- */
- toggleInlineStyle: function toggleInlineStyle(editorState, inlineStyle) {
- var selection = editorState.getSelection();
- var currentStyle = editorState.getCurrentInlineStyle();
-
- // If the selection is collapsed, toggle the specified style on or off and
- // set the result as the new inline style override. This will then be
- // used as the inline style for the next character to be inserted.
- if (selection.isCollapsed()) {
- return EditorState_1.setInlineStyleOverride(editorState, currentStyle.has(inlineStyle) ? currentStyle.remove(inlineStyle) : currentStyle.add(inlineStyle));
- }
-
- // If characters are selected, immediately apply or remove the
- // inline style on the document state itself.
- var content = editorState.getCurrentContent();
- var newContent;
-
- // If the style is already present for the selection range, remove it.
- // Otherwise, apply it.
- if (currentStyle.has(inlineStyle)) {
- newContent = DraftModifier_1.removeInlineStyle(content, selection, inlineStyle);
- } else {
- newContent = DraftModifier_1.applyInlineStyle(content, selection, inlineStyle);
- }
-
- return EditorState_1.push(editorState, newContent, 'change-inline-style');
- },
-
- toggleLink: function toggleLink(editorState, targetSelection, entityKey) {
- var withoutLink = DraftModifier_1.applyEntity(editorState.getCurrentContent(), targetSelection, entityKey);
-
- return EditorState_1.push(editorState, withoutLink, 'apply-entity');
- },
-
- /**
- * When a collapsed cursor is at the start of the first styled block, or
- * an empty styled block, changes block to 'unstyled'. Returns null if
- * block or selection does not meet that criteria.
- */
- tryToRemoveBlockStyle: function tryToRemoveBlockStyle(editorState) {
- var selection = editorState.getSelection();
- var offset = selection.getAnchorOffset();
- if (selection.isCollapsed() && offset === 0) {
- var key = selection.getAnchorKey();
- var content = editorState.getCurrentContent();
- var block = content.getBlockForKey(key);
-
- var firstBlock = content.getFirstBlock();
- if (block.getLength() > 0 && block !== firstBlock) {
- return null;
- }
-
- var type = block.getType();
- var blockBefore = content.getBlockBefore(key);
- if (type === 'code-block' && blockBefore && blockBefore.getType() === 'code-block' && blockBefore.getLength() !== 0) {
- return null;
- }
-
- if (type !== 'unstyled') {
- return DraftModifier_1.setBlockType(content, selection, 'unstyled');
- }
- }
- return null;
- }
- };
-
- var RichTextEditorUtil_1 = RichTextEditorUtil;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule splitTextIntoTextBlocks
- * @format
- *
- */
-
- var NEWLINE_REGEX = /\r\n?|\n/g;
-
- function splitTextIntoTextBlocks(text) {
- return text.split(NEWLINE_REGEX);
- }
-
- var splitTextIntoTextBlocks_1 = splitTextIntoTextBlocks;
-
- /**
- * Paste content.
- */
- function editOnPaste(editor, e) {
- e.preventDefault();
- var data = new DataTransfer_1(e.clipboardData);
-
- // Get files, unless this is likely to be a string the user wants inline.
- if (!data.isRichText()) {
- var files = data.getFiles();
- var defaultFileText = data.getText();
- if (files.length > 0) {
- // Allow customized paste handling for images, etc. Otherwise, fall
- // through to insert text contents into the editor.
- if (editor.props.handlePastedFiles && isEventHandled_1(editor.props.handlePastedFiles(files))) {
- return;
- }
-
- getTextContentFromFiles_1(files, function ( /*string*/fileText) {
- fileText = fileText || defaultFileText;
- if (!fileText) {
- return;
- }
-
- var editorState = editor._latestEditorState;
- var blocks = splitTextIntoTextBlocks_1(fileText);
- var character = CharacterMetadata_1.create({
- style: editorState.getCurrentInlineStyle(),
- entity: getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())
- });
- var currentBlockType = RichTextEditorUtil_1.getCurrentBlockType(editorState);
-
- var text = DraftPasteProcessor_1.processText(blocks, character, currentBlockType);
- var fragment = BlockMapBuilder_1.createFromArray(text);
-
- var withInsertedText = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), fragment);
-
- editor.update(EditorState_1.push(editorState, withInsertedText, 'insert-fragment'));
- });
-
- return;
- }
- }
-
- var textBlocks = [];
- var text = data.getText();
- var html = data.getHTML();
- var editorState = editor._latestEditorState;
-
- if (editor.props.handlePastedText && isEventHandled_1(editor.props.handlePastedText(text, html, editorState))) {
- return;
- }
-
- if (text) {
- textBlocks = splitTextIntoTextBlocks_1(text);
- }
-
- if (!editor.props.stripPastedStyles) {
- // If the text from the paste event is rich content that matches what we
- // already have on the internal clipboard, assume that we should just use
- // the clipboard fragment for the paste. This will allow us to preserve
- // styling and entities, if any are present. Note that newlines are
- // stripped during comparison -- this is because copy/paste within the
- // editor in Firefox and IE will not include empty lines. The resulting
- // paste will preserve the newlines correctly.
- var internalClipboard = editor.getClipboard();
- if (data.isRichText() && internalClipboard) {
- if (
- // If the editorKey is present in the pasted HTML, it should be safe to
- // assume this is an internal paste.
- html.indexOf(editor.getEditorKey()) !== -1 ||
- // The copy may have been made within a single block, in which case the
- // editor key won't be part of the paste. In this case, just check
- // whether the pasted text matches the internal clipboard.
- textBlocks.length === 1 && internalClipboard.size === 1 && internalClipboard.first().getText() === text) {
- editor.update(insertFragment$1(editor._latestEditorState, internalClipboard));
- return;
- }
- } else if (internalClipboard && data.types.includes('com.apple.webarchive') && !data.types.includes('text/html') && areTextBlocksAndClipboardEqual(textBlocks, internalClipboard)) {
- // Safari does not properly store text/html in some cases.
- // Use the internalClipboard if present and equal to what is on
- // the clipboard. See https://bugs.webkit.org/show_bug.cgi?id=19893.
- editor.update(insertFragment$1(editor._latestEditorState, internalClipboard));
- return;
- }
-
- // If there is html paste data, try to parse that.
- if (html) {
- var htmlFragment = DraftPasteProcessor_1.processHTML(html, editor.props.blockRenderMap);
- if (htmlFragment) {
- var contentBlocks = htmlFragment.contentBlocks,
- entityMap = htmlFragment.entityMap;
-
- if (contentBlocks) {
- var htmlMap = BlockMapBuilder_1.createFromArray(contentBlocks);
- editor.update(insertFragment$1(editor._latestEditorState, htmlMap, entityMap));
- return;
- }
- }
- }
-
- // Otherwise, create a new fragment from our pasted text. Also
- // empty the internal clipboard, since it's no longer valid.
- editor.setClipboard(null);
- }
-
- if (textBlocks.length) {
- var character = CharacterMetadata_1.create({
- style: editorState.getCurrentInlineStyle(),
- entity: getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())
- });
-
- var currentBlockType = RichTextEditorUtil_1.getCurrentBlockType(editorState);
-
- var textFragment = DraftPasteProcessor_1.processText(textBlocks, character, currentBlockType);
-
- var textMap = BlockMapBuilder_1.createFromArray(textFragment);
- editor.update(insertFragment$1(editor._latestEditorState, textMap));
- }
- }
-
- function insertFragment$1(editorState, fragment, entityMap) {
- var newContent = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), fragment);
- // TODO: merge the entity map once we stop using DraftEntity
- // like this:
- // const mergedEntityMap = newContent.getEntityMap().merge(entityMap);
-
- return EditorState_1.push(editorState, newContent.set('entityMap', entityMap), 'insert-fragment');
- }
-
- function areTextBlocksAndClipboardEqual(textBlocks, blockMap) {
- return textBlocks.length === blockMap.size && blockMap.valueSeq().every(function (block, ii) {
- return block.getText() === textBlocks[ii];
- });
- }
-
- var editOnPaste_1 = editOnPaste;
-
- /**
- * Convert the current selection range to an anchor/focus pair of offset keys
- * and values that can be interpreted by components.
- */
- function getDraftEditorSelection(editorState, root) {
- var selection = _commonjsHelpers.commonjsGlobal.getSelection();
-
- // No active selection.
- if (selection.rangeCount === 0) {
- return {
- selectionState: editorState.getSelection().set('hasFocus', false),
- needsRecovery: false
- };
- }
-
- return getDraftEditorSelectionWithNodes_1(editorState, root, selection.anchorNode, selection.anchorOffset, selection.focusNode, selection.focusOffset);
- }
-
- var getDraftEditorSelection_1 = getDraftEditorSelection;
-
- function editOnSelect(editor) {
- if (editor._blockSelectEvents || editor._latestEditorState !== editor.props.editorState) {
- return;
- }
-
- var editorState = editor.props.editorState;
- var editorNode = _reactDom_commonjsExternal.require$$3.findDOMNode(editor.editorContainer);
- !editorNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing editorNode') : invariant_1(false) : void 0;
- !(editorNode.firstChild instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode.firstChild is not an HTMLElement') : invariant_1(false) : void 0;
- var documentSelection = getDraftEditorSelection_1(editorState, editorNode.firstChild);
- var updatedSelectionState = documentSelection.selectionState;
-
- if (updatedSelectionState !== editorState.getSelection()) {
- if (documentSelection.needsRecovery) {
- editorState = EditorState_1.forceSelection(editorState, updatedSelectionState);
- } else {
- editorState = EditorState_1.acceptSelection(editorState, updatedSelectionState);
- }
- editor.update(editorState);
- }
- }
-
- var editOnSelect_1 = editOnSelect;
-
- var DraftEditorEditHandler = {
- onBeforeInput: editOnBeforeInput_1,
- onBlur: editOnBlur_1,
- onCompositionStart: editOnCompositionStart_1,
- onCopy: editOnCopy_1,
- onCut: editOnCut_1,
- onDragOver: editOnDragOver_1,
- onDragStart: editOnDragStart_1,
- onFocus: editOnFocus_1,
- onInput: editOnInput_1,
- onKeyDown: editOnKeyDown_1,
- onPaste: editOnPaste_1,
- onSelect: editOnSelect_1
- };
-
- var DraftEditorEditHandler_1 = DraftEditorEditHandler;
-
- function _classCallCheck$f(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
- 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; }
-
- 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; }
-
-
-
-
-
- /**
- * This component is responsible for rendering placeholder text for the
- * `DraftEditor` component.
- *
- * Override placeholder style via CSS.
- */
- var DraftEditorPlaceholder = function (_React$Component) {
- _inherits$a(DraftEditorPlaceholder, _React$Component);
-
- function DraftEditorPlaceholder() {
- _classCallCheck$f(this, DraftEditorPlaceholder);
-
- return _possibleConstructorReturn$a(this, _React$Component.apply(this, arguments));
- }
-
- DraftEditorPlaceholder.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
- return this.props.text !== nextProps.text || this.props.editorState.getSelection().getHasFocus() !== nextProps.editorState.getSelection().getHasFocus();
- };
-
- DraftEditorPlaceholder.prototype.render = function render() {
- var hasFocus = this.props.editorState.getSelection().getHasFocus();
-
- var className = cx_1({
- 'public/DraftEditorPlaceholder/root': true,
- 'public/DraftEditorPlaceholder/hasFocus': hasFocus
- });
-
- var contentStyle = {
- whiteSpace: 'pre-wrap'
- };
-
- return _reactDom_commonjsExternal.React.createElement(
- 'div',
- { className: className },
- _reactDom_commonjsExternal.React.createElement(
- 'div',
- {
- className: cx_1('public/DraftEditorPlaceholder/inner'),
- id: this.props.accessibilityID,
- style: contentStyle },
- this.props.text
- )
- );
- };
-
- return DraftEditorPlaceholder;
- }(_reactDom_commonjsExternal.React.Component);
-
- var DraftEditorPlaceholder_react = DraftEditorPlaceholder;
-
- var isOSX$1 = UserAgent_1.isPlatform('Mac OS X');
- var isWindows = UserAgent_1.isPlatform('Windows');
-
- // Firefox on OSX had a bug resulting in navigation instead of cursor movement.
- // This bug was fixed in Firefox 29. Feature detection is virtually impossible
- // so we just check the version number. See #342765.
- var shouldFixFirefoxMovement = isOSX$1 && UserAgent_1.isBrowser('Firefox < 29');
-
- var hasCommandModifier = KeyBindingUtil_1.hasCommandModifier,
- isCtrlKeyCommand = KeyBindingUtil_1.isCtrlKeyCommand;
-
-
- function shouldRemoveWord(e) {
- return isOSX$1 && e.altKey || isCtrlKeyCommand(e);
- }
-
- /**
- * Get the appropriate undo/redo command for a Z key command.
- */
- function getZCommand(e) {
- if (!hasCommandModifier(e)) {
- return null;
- }
- return e.shiftKey ? 'redo' : 'undo';
- }
-
- function getDeleteCommand(e) {
- // Allow default "cut" behavior for Windows on Shift + Delete.
- if (isWindows && e.shiftKey) {
- return null;
- }
- return shouldRemoveWord(e) ? 'delete-word' : 'delete';
- }
-
- function getBackspaceCommand(e) {
- if (hasCommandModifier(e) && isOSX$1) {
- return 'backspace-to-start-of-line';
- }
- return shouldRemoveWord(e) ? 'backspace-word' : 'backspace';
- }
-
- /**
- * Retrieve a bound key command for the given event.
- */
- function getDefaultKeyBinding(e) {
- switch (e.keyCode) {
- case 66:
- // B
- return hasCommandModifier(e) ? 'bold' : null;
- case 68:
- // D
- return isCtrlKeyCommand(e) ? 'delete' : null;
- case 72:
- // H
- return isCtrlKeyCommand(e) ? 'backspace' : null;
- case 73:
- // I
- return hasCommandModifier(e) ? 'italic' : null;
- case 74:
- // J
- return hasCommandModifier(e) ? 'code' : null;
- case 75:
- // K
- return !isWindows && isCtrlKeyCommand(e) ? 'secondary-cut' : null;
- case 77:
- // M
- return isCtrlKeyCommand(e) ? 'split-block' : null;
- case 79:
- // O
- return isCtrlKeyCommand(e) ? 'split-block' : null;
- case 84:
- // T
- return isOSX$1 && isCtrlKeyCommand(e) ? 'transpose-characters' : null;
- case 85:
- // U
- return hasCommandModifier(e) ? 'underline' : null;
- case 87:
- // W
- return isOSX$1 && isCtrlKeyCommand(e) ? 'backspace-word' : null;
- case 89:
- // Y
- if (isCtrlKeyCommand(e)) {
- return isWindows ? 'redo' : 'secondary-paste';
- }
- return null;
- case 90:
- // Z
- return getZCommand(e) || null;
- case Keys.RETURN:
- return 'split-block';
- case Keys.DELETE:
- return getDeleteCommand(e);
- case Keys.BACKSPACE:
- return getBackspaceCommand(e);
- // LEFT/RIGHT handlers serve as a workaround for a Firefox bug.
- case Keys.LEFT:
- return shouldFixFirefoxMovement && hasCommandModifier(e) ? 'move-selection-to-start-of-block' : null;
- case Keys.RIGHT:
- return shouldFixFirefoxMovement && hasCommandModifier(e) ? 'move-selection-to-end-of-block' : null;
- default:
- return null;
- }
- }
-
- var getDefaultKeyBinding_1 = getDefaultKeyBinding;
-
- 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; };
-
- function _classCallCheck$g(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
- 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; }
-
- 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; }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var isIE = UserAgent_1.isBrowser('IE');
-
- // IE does not support the `input` event on contentEditable, so we can't
- // observe spellcheck behavior.
- var allowSpellCheck = !isIE;
-
- // Define a set of handler objects to correspond to each possible `mode`
- // of editor behavior.
- var handlerMap = {
- edit: DraftEditorEditHandler_1,
- composite: DraftEditorCompositionHandler_1,
- drag: DraftEditorDragHandler_1,
- cut: null,
- render: null
- };
-
- /**
- * `DraftEditor` is the root editor component. It composes a `contentEditable`
- * div, and provides a wide variety of useful function props for managing the
- * state of the editor. See `DraftEditorProps` for details.
- */
- var DraftEditor = function (_React$Component) {
- _inherits$b(DraftEditor, _React$Component);
-
- function DraftEditor(props) {
- _classCallCheck$g(this, DraftEditor);
-
- var _this = _possibleConstructorReturn$b(this, _React$Component.call(this, props));
-
- _this.focus = function (scrollPosition) {
- var editorState = _this.props.editorState;
-
- var alreadyHasFocus = editorState.getSelection().getHasFocus();
- var editorNode = _reactDom_commonjsExternal.require$$3.findDOMNode(_this.editor);
-
- if (!editorNode) {
- // once in a while people call 'focus' in a setTimeout, and the node has
- // been deleted, so it can be null in that case.
- return;
- }
-
- var scrollParent = Style_1.getScrollParent(editorNode);
-
- var _ref = scrollPosition || getScrollPosition_1(scrollParent),
- x = _ref.x,
- y = _ref.y;
-
- !(editorNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode is not an HTMLElement') : invariant_1(false) : void 0;
- editorNode.focus();
-
- // Restore scroll position
- if (scrollParent === window) {
- window.scrollTo(x, y);
- } else {
- Scroll_1.setTop(scrollParent, y);
- }
-
- // On Chrome and Safari, calling focus on contenteditable focuses the
- // cursor at the first character. This is something you don't expect when
- // you're clicking on an input element but not directly on a character.
- // Put the cursor back where it was before the blur.
- if (!alreadyHasFocus) {
- _this.update(EditorState_1.forceSelection(editorState, editorState.getSelection()));
- }
- };
-
- _this.blur = function () {
- var editorNode = _reactDom_commonjsExternal.require$$3.findDOMNode(_this.editor);
- !(editorNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode is not an HTMLElement') : invariant_1(false) : void 0;
- editorNode.blur();
- };
-
- _this.setMode = function (mode) {
- _this._handler = handlerMap[mode];
- };
-
- _this.exitCurrentMode = function () {
- _this.setMode('edit');
- };
-
- _this.restoreEditorDOM = function (scrollPosition) {
- _this.setState({ contentsKey: _this.state.contentsKey + 1 }, function () {
- _this.focus(scrollPosition);
- });
- };
-
- _this.setClipboard = function (clipboard) {
- _this._clipboard = clipboard;
- };
-
- _this.getClipboard = function () {
- return _this._clipboard;
- };
-
- _this.update = function (editorState) {
- _this._latestEditorState = editorState;
- _this.props.onChange(editorState);
- };
-
- _this.onDragEnter = function () {
- _this._dragCount++;
- };
-
- _this.onDragLeave = function () {
- _this._dragCount--;
- if (_this._dragCount === 0) {
- _this.exitCurrentMode();
- }
- };
-
- _this._blockSelectEvents = false;
- _this._clipboard = null;
- _this._handler = null;
- _this._dragCount = 0;
- _this._editorKey = props.editorKey || generateRandomKey_1();
- _this._placeholderAccessibilityID = 'placeholder-' + _this._editorKey;
- _this._latestEditorState = props.editorState;
- _this._latestCommittedEditorState = props.editorState;
-
- _this._onBeforeInput = _this._buildHandler('onBeforeInput');
- _this._onBlur = _this._buildHandler('onBlur');
- _this._onCharacterData = _this._buildHandler('onCharacterData');
- _this._onCompositionEnd = _this._buildHandler('onCompositionEnd');
- _this._onCompositionStart = _this._buildHandler('onCompositionStart');
- _this._onCopy = _this._buildHandler('onCopy');
- _this._onCut = _this._buildHandler('onCut');
- _this._onDragEnd = _this._buildHandler('onDragEnd');
- _this._onDragOver = _this._buildHandler('onDragOver');
- _this._onDragStart = _this._buildHandler('onDragStart');
- _this._onDrop = _this._buildHandler('onDrop');
- _this._onInput = _this._buildHandler('onInput');
- _this._onFocus = _this._buildHandler('onFocus');
- _this._onKeyDown = _this._buildHandler('onKeyDown');
- _this._onKeyPress = _this._buildHandler('onKeyPress');
- _this._onKeyUp = _this._buildHandler('onKeyUp');
- _this._onMouseDown = _this._buildHandler('onMouseDown');
- _this._onMouseUp = _this._buildHandler('onMouseUp');
- _this._onPaste = _this._buildHandler('onPaste');
- _this._onSelect = _this._buildHandler('onSelect');
-
- _this.getEditorKey = function () {
- return _this._editorKey;
- };
-
- // See `restoreEditorDOM()`.
- _this.state = { contentsKey: 0 };
- return _this;
- }
-
- /**
- * Build a method that will pass the event to the specified handler method.
- * This allows us to look up the correct handler function for the current
- * editor mode, if any has been specified.
- */
-
-
- /**
- * Define proxies that can route events to the current handler.
- */
-
-
- DraftEditor.prototype._buildHandler = function _buildHandler(eventName) {
- var _this2 = this;
-
- return function (e) {
- if (!_this2.props.readOnly) {
- var method = _this2._handler && _this2._handler[eventName];
- method && method(_this2, e);
- }
- };
- };
-
- DraftEditor.prototype._showPlaceholder = function _showPlaceholder() {
- return !!this.props.placeholder && !this.props.editorState.isInCompositionMode() && !this.props.editorState.getCurrentContent().hasText();
- };
-
- DraftEditor.prototype._renderPlaceholder = function _renderPlaceholder() {
- if (this._showPlaceholder()) {
- var placeHolderProps = {
- text: nullthrows_1(this.props.placeholder),
- editorState: this.props.editorState,
- textAlignment: this.props.textAlignment,
- accessibilityID: this._placeholderAccessibilityID
- };
-
- return _reactDom_commonjsExternal.React.createElement(DraftEditorPlaceholder_react, placeHolderProps);
- }
- return null;
- };
-
- DraftEditor.prototype.render = function render() {
- var _this3 = this;
-
- var _props = this.props,
- blockRenderMap = _props.blockRenderMap,
- blockRendererFn = _props.blockRendererFn,
- blockStyleFn = _props.blockStyleFn,
- customStyleFn = _props.customStyleFn,
- customStyleMap = _props.customStyleMap,
- editorState = _props.editorState,
- readOnly = _props.readOnly,
- textAlignment = _props.textAlignment,
- textDirectionality = _props.textDirectionality;
-
-
- var rootClass = cx_1({
- 'DraftEditor/root': true,
- 'DraftEditor/alignLeft': textAlignment === 'left',
- 'DraftEditor/alignRight': textAlignment === 'right',
- 'DraftEditor/alignCenter': textAlignment === 'center'
- });
-
- var contentStyle = {
- outline: 'none',
- // fix parent-draggable Safari bug. #1326
- userSelect: 'text',
- WebkitUserSelect: 'text',
- whiteSpace: 'pre-wrap',
- wordWrap: 'break-word'
- };
-
- // The aria-expanded and aria-haspopup properties should only be rendered
- // for a combobox.
- var ariaRole = this.props.role || 'textbox';
- var ariaExpanded = ariaRole === 'combobox' ? !!this.props.ariaExpanded : null;
-
- var editorContentsProps = {
- blockRenderMap: blockRenderMap,
- blockRendererFn: blockRendererFn,
- blockStyleFn: blockStyleFn,
- customStyleMap: _extends$5({}, DefaultDraftInlineStyle, customStyleMap),
- customStyleFn: customStyleFn,
- editorKey: this._editorKey,
- editorState: editorState,
- key: 'contents' + this.state.contentsKey,
- textDirectionality: textDirectionality
- };
-
- return _reactDom_commonjsExternal.React.createElement(
- 'div',
- { className: rootClass },
- this._renderPlaceholder(),
- _reactDom_commonjsExternal.React.createElement(
- 'div',
- {
- className: cx_1('DraftEditor/editorContainer'),
- ref: function ref(_ref3) {
- return _this3.editorContainer = _ref3;
- } },
- _reactDom_commonjsExternal.React.createElement(
- 'div',
- {
- 'aria-activedescendant': readOnly ? null : this.props.ariaActiveDescendantID,
- 'aria-autocomplete': readOnly ? null : this.props.ariaAutoComplete,
- 'aria-controls': readOnly ? null : this.props.ariaControls,
- 'aria-describedby': this.props.ariaDescribedBy || this._placeholderAccessibilityID,
- 'aria-expanded': readOnly ? null : ariaExpanded,
- 'aria-label': this.props.ariaLabel,
- 'aria-labelledby': this.props.ariaLabelledBy,
- 'aria-multiline': this.props.ariaMultiline,
- autoCapitalize: this.props.autoCapitalize,
- autoComplete: this.props.autoComplete,
- autoCorrect: this.props.autoCorrect,
- className: cx_1({
- // Chrome's built-in translation feature mutates the DOM in ways
- // that Draft doesn't expect (ex: adding <font> tags inside
- // DraftEditorLeaf spans) and causes problems. We add notranslate
- // here which makes its autotranslation skip over this subtree.
- notranslate: !readOnly,
- 'public/DraftEditor/content': true
- }),
- contentEditable: !readOnly,
- 'data-testid': this.props.webDriverTestID,
- onBeforeInput: this._onBeforeInput,
- onBlur: this._onBlur,
- onCompositionEnd: this._onCompositionEnd,
- onCompositionStart: this._onCompositionStart,
- onCopy: this._onCopy,
- onCut: this._onCut,
- onDragEnd: this._onDragEnd,
- onDragEnter: this.onDragEnter,
- onDragLeave: this.onDragLeave,
- onDragOver: this._onDragOver,
- onDragStart: this._onDragStart,
- onDrop: this._onDrop,
- onFocus: this._onFocus,
- onInput: this._onInput,
- onKeyDown: this._onKeyDown,
- onKeyPress: this._onKeyPress,
- onKeyUp: this._onKeyUp,
- onMouseUp: this._onMouseUp,
- onPaste: this._onPaste,
- onSelect: this._onSelect,
- ref: function ref(_ref2) {
- return _this3.editor = _ref2;
- },
- role: readOnly ? null : ariaRole,
- spellCheck: allowSpellCheck && this.props.spellCheck,
- style: contentStyle,
- suppressContentEditableWarning: true,
- tabIndex: this.props.tabIndex },
- _reactDom_commonjsExternal.React.createElement(DraftEditorContents_react, editorContentsProps)
- )
- )
- );
- };
-
- DraftEditor.prototype.componentDidMount = function componentDidMount() {
- this.setMode('edit');
-
- /**
- * IE has a hardcoded "feature" that attempts to convert link text into
- * anchors in contentEditable DOM. This breaks the editor's expectations of
- * the DOM, and control is lost. Disable it to make IE behave.
- * See: http://blogs.msdn.com/b/ieinternals/archive/2010/09/15/
- * ie9-beta-minor-change-list.aspx
- */
- if (isIE) {
- document.execCommand('AutoUrlDetect', false, false);
- }
- };
-
- /**
- * Prevent selection events from affecting the current editor state. This
- * is mostly intended to defend against IE, which fires off `selectionchange`
- * events regardless of whether the selection is set via the browser or
- * programmatically. We only care about selection events that occur because
- * of browser interaction, not re-renders and forced selections.
- */
-
-
- DraftEditor.prototype.componentWillUpdate = function componentWillUpdate(nextProps) {
- this._blockSelectEvents = true;
- this._latestEditorState = nextProps.editorState;
- };
-
- DraftEditor.prototype.componentDidUpdate = function componentDidUpdate() {
- this._blockSelectEvents = false;
- this._latestCommittedEditorState = this.props.editorState;
- };
-
- /**
- * Used via `this.focus()`.
- *
- * Force focus back onto the editor node.
- *
- * We attempt to preserve scroll position when focusing. You can also pass
- * a specified scroll position (for cases like `cut` behavior where it should
- * be restored to a known position).
- */
-
-
- /**
- * Used via `this.setMode(...)`.
- *
- * Set the behavior mode for the editor component. This switches the current
- * handler module to ensure that DOM events are managed appropriately for
- * the active mode.
- */
-
-
- /**
- * Used via `this.restoreEditorDOM()`.
- *
- * Force a complete re-render of the DraftEditorContents based on the current
- * EditorState. This is useful when we know we are going to lose control of
- * the DOM state (cut command, IME) and we want to make sure that
- * reconciliation occurs on a version of the DOM that is synchronized with
- * our EditorState.
- */
-
-
- /**
- * Used via `this.setClipboard(...)`.
- *
- * Set the clipboard state for a cut/copy event.
- */
-
-
- /**
- * Used via `this.getClipboard()`.
- *
- * Retrieve the clipboard state for a cut/copy event.
- */
-
-
- /**
- * Used via `this.update(...)`.
- *
- * Propagate a new `EditorState` object to higher-level components. This is
- * the method by which event handlers inform the `DraftEditor` component of
- * state changes. A component that composes a `DraftEditor` **must** provide
- * an `onChange` prop to receive state updates passed along from this
- * function.
- */
-
-
- /**
- * Used in conjunction with `onDragLeave()`, by counting the number of times
- * a dragged element enters and leaves the editor (or any of its children),
- * to determine when the dragged element absolutely leaves the editor.
- */
-
-
- /**
- * See `onDragEnter()`.
- */
-
-
- return DraftEditor;
- }(_reactDom_commonjsExternal.React.Component);
-
- DraftEditor.defaultProps = {
- blockRenderMap: DefaultDraftBlockRenderMap_1,
- blockRendererFn: emptyFunction_1.thatReturnsNull,
- blockStyleFn: emptyFunction_1.thatReturns(''),
- keyBindingFn: getDefaultKeyBinding_1,
- readOnly: false,
- spellCheck: false,
- stripPastedStyles: false
- };
-
-
- var DraftEditor_react = DraftEditor;
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule DraftStringKey
- * @format
- *
- */
-
- var DraftStringKey = {
- stringify: function stringify(key) {
- return '_' + String(key);
- },
-
- unstringify: function unstringify(key) {
- return key.slice(1);
- }
- };
-
- var DraftStringKey_1 = DraftStringKey;
-
- var strlen$1 = UnicodeUtils_1.strlen;
-
- /**
- * Convert to UTF-8 character counts for storage.
- */
-
- function encodeEntityRanges(block, storageMap) {
- var encoded = [];
- block.findEntityRanges(function (character) {
- return !!character.getEntity();
- }, function ( /*number*/start, /*number*/end) {
- var text = block.getText();
- var key = block.getEntityAt(start);
- encoded.push({
- offset: strlen$1(text.slice(0, start)),
- length: strlen$1(text.slice(start, end)),
- // Encode the key as a number for range storage.
- key: Number(storageMap[DraftStringKey_1.stringify(key)])
- });
- });
- return encoded;
- }
-
- var encodeEntityRanges_1 = encodeEntityRanges;
-
- var areEqual$1 = function areEqual(a, b) {
- return a === b;
- };
- var isTruthy = function isTruthy(a) {
- return !!a;
- };
- var EMPTY_ARRAY = [];
-
- /**
- * Helper function for getting encoded styles for each inline style. Convert
- * to UTF-8 character counts for storage.
- */
- function getEncodedInlinesForType(block, styleList, styleToEncode) {
- var ranges = [];
-
- // Obtain an array with ranges for only the specified style.
- var filteredInlines = styleList.map(function (style) {
- return style.has(styleToEncode);
- }).toList();
-
- findRangesImmutable_1(filteredInlines, areEqual$1,
- // We only want to keep ranges with nonzero style values.
- isTruthy, function (start, end) {
- var text = block.getText();
- ranges.push({
- offset: UnicodeUtils_1.strlen(text.slice(0, start)),
- length: UnicodeUtils_1.strlen(text.slice(start, end)),
- style: styleToEncode
- });
- });
-
- return ranges;
- }
-
- /*
- * Retrieve the encoded arrays of inline styles, with each individual style
- * treated separately.
- */
- function encodeInlineStyleRanges(block) {
- var styleList = block.getCharacterList().map(function (c) {
- return c.getStyle();
- }).toList();
- var ranges = styleList.flatten().toSet().map(function (style) {
- return getEncodedInlinesForType(block, styleList, style);
- });
-
- return Array.prototype.concat.apply(EMPTY_ARRAY, ranges.toJS());
- }
-
- var encodeInlineStyleRanges_1 = encodeInlineStyleRanges;
-
- 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; };
-
-
-
-
-
-
-
-
-
- var createRawBlock = function createRawBlock(block, entityStorageMap) {
- return {
- key: block.getKey(),
- text: block.getText(),
- type: block.getType(),
- depth: block.getDepth(),
- inlineStyleRanges: encodeInlineStyleRanges_1(block),
- entityRanges: encodeEntityRanges_1(block, entityStorageMap),
- data: block.getData().toObject()
- };
- };
-
- var insertRawBlock = function insertRawBlock(block, entityMap, rawBlocks, blockCacheRef) {
- if (block instanceof ContentBlock_1) {
- rawBlocks.push(createRawBlock(block, entityMap));
- return;
- }
-
- !(block instanceof ContentBlockNode_1) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'block is not a BlockNode') : invariant_1(false) : void 0;
-
- var parentKey = block.getParentKey();
- var rawBlock = blockCacheRef[block.getKey()] = _extends$6({}, createRawBlock(block, entityMap), {
- children: []
- });
-
- if (parentKey) {
- blockCacheRef[parentKey].children.push(rawBlock);
- return;
- }
-
- rawBlocks.push(rawBlock);
- };
-
- var encodeRawBlocks = function encodeRawBlocks(contentState, rawState) {
- var entityMap = rawState.entityMap;
-
-
- var rawBlocks = [];
-
- var blockCacheRef = {};
- var entityCacheRef = {};
- var entityStorageKey = 0;
-
- contentState.getBlockMap().forEach(function (block) {
- block.findEntityRanges(function (character) {
- return character.getEntity() !== null;
- }, function (start) {
- var entityKey = block.getEntityAt(start);
- // Stringify to maintain order of otherwise numeric keys.
- var stringifiedEntityKey = DraftStringKey_1.stringify(entityKey);
- // This makes this function resilient to two entities
- // erroneously having the same key
- if (entityCacheRef[stringifiedEntityKey]) {
- return;
- }
- entityCacheRef[stringifiedEntityKey] = entityKey;
- // we need the `any` casting here since this is a temporary state
- // where we will later on flip the entity map and populate it with
- // real entity, at this stage we just need to map back the entity
- // key used by the BlockNode
- entityMap[stringifiedEntityKey] = '' + entityStorageKey;
- entityStorageKey++;
- });
-
- insertRawBlock(block, entityMap, rawBlocks, blockCacheRef);
- });
-
- return {
- blocks: rawBlocks,
- entityMap: entityMap
- };
- };
-
- // Flip storage map so that our storage keys map to global
- // DraftEntity keys.
- var encodeRawEntityMap = function encodeRawEntityMap(contentState, rawState) {
- var blocks = rawState.blocks,
- entityMap = rawState.entityMap;
-
-
- var rawEntityMap = {};
-
- Object.keys(entityMap).forEach(function (key, index) {
- var entity = contentState.getEntity(DraftStringKey_1.unstringify(key));
- rawEntityMap[index] = {
- type: entity.getType(),
- mutability: entity.getMutability(),
- data: entity.getData()
- };
- });
-
- return {
- blocks: blocks,
- entityMap: rawEntityMap
- };
- };
-
- var convertFromDraftStateToRaw = function convertFromDraftStateToRaw(contentState) {
- var rawDraftContentState = {
- entityMap: {},
- blocks: []
- };
-
- // add blocks
- rawDraftContentState = encodeRawBlocks(contentState, rawDraftContentState);
-
- // add entities
- rawDraftContentState = encodeRawEntityMap(contentState, rawDraftContentState);
-
- return rawDraftContentState;
- };
-
- var convertFromDraftStateToRaw_1 = convertFromDraftStateToRaw;
-
- 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; };
-
- /**
- * Copyright (c) 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule DraftTreeAdapter
- * @format
- *
- *
- * This is unstable and not part of the public API and should not be used by
- * production systems. This file may be update/removed without notice.
- */
-
-
-
- var traverseInDepthOrder = function traverseInDepthOrder(blocks, fn) {
- var stack = [].concat(blocks).reverse();
- while (stack.length) {
- var _block = stack.pop();
-
- fn(_block);
-
- var children = _block.children;
-
- !Array.isArray(children) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid tree raw block') : invariant_1(false) : void 0;
-
- stack = stack.concat([].concat(children.reverse()));
- }
- };
-
- var isListBlock = function isListBlock(block) {
- if (!(block && block.type)) {
- return false;
- }
- var type = block.type;
-
- return type === 'unordered-list-item' || type === 'ordered-list-item';
- };
-
- var addDepthToChildren = function addDepthToChildren(block) {
- if (Array.isArray(block.children)) {
- block.children = block.children.map(function (child) {
- return child.type === block.type ? _extends$7({}, child, { depth: (block.depth || 0) + 1 }) : child;
- });
- }
- };
-
- /**
- * This adapter is intended to be be used as an adapter to draft tree data
- *
- * draft state <=====> draft tree state
- */
- var DraftTreeAdapter = {
- /**
- * Converts from a tree raw state back to draft raw state
- */
- fromRawTreeStateToRawState: function fromRawTreeStateToRawState(draftTreeState) {
- var blocks = draftTreeState.blocks;
-
- var transformedBlocks = [];
-
- !Array.isArray(blocks) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid raw state') : invariant_1(false) : void 0;
-
- if (!Array.isArray(blocks) || !blocks.length) {
- return draftTreeState;
- }
-
- traverseInDepthOrder(blocks, function (block) {
- var newBlock = _extends$7({}, block);
-
- if (isListBlock(block)) {
- newBlock.depth = newBlock.depth || 0;
- addDepthToChildren(block);
- }
-
- delete newBlock.children;
-
- transformedBlocks.push(newBlock);
- });
-
- draftTreeState.blocks = transformedBlocks;
-
- return _extends$7({}, draftTreeState, {
- blocks: transformedBlocks
- });
- },
-
-
- /**
- * Converts from draft raw state to tree draft state
- */
- fromRawStateToRawTreeState: function fromRawStateToRawTreeState(draftState) {
- var lastListDepthCacheRef = {};
- var transformedBlocks = [];
-
- draftState.blocks.forEach(function (block) {
- var isList = isListBlock(block);
- var depth = block.depth || 0;
- var treeBlock = _extends$7({}, block, {
- children: []
- });
-
- if (!isList) {
- // reset the cache path
- lastListDepthCacheRef = {};
- transformedBlocks.push(treeBlock);
- return;
- }
-
- // update our depth cache reference path
- lastListDepthCacheRef[depth] = treeBlock;
-
- // if we are greater than zero we must have seen a parent already
- if (depth > 0) {
- var parent = lastListDepthCacheRef[depth - 1];
-
- !parent ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid depth for RawDraftContentBlock') : invariant_1(false) : void 0;
-
- // push nested list blocks
- parent.children.push(treeBlock);
- return;
- }
-
- // push root list blocks
- transformedBlocks.push(treeBlock);
- });
-
- return _extends$7({}, draftState, {
- blocks: transformedBlocks
- });
- }
- };
-
- var DraftTreeAdapter_1 = DraftTreeAdapter;
-
- var List$c = immutable.List;
-
-
- function createCharacterList(inlineStyles, entities) {
- var characterArray = inlineStyles.map(function (style, ii) {
- var entity = entities[ii];
- return CharacterMetadata_1.create({ style: style, entity: entity });
- });
- return List$c(characterArray);
- }
-
- var createCharacterList_1 = createCharacterList;
-
- var substr$1 = UnicodeUtils_1.substr;
-
- /**
- * Convert to native JavaScript string lengths to determine ranges.
- */
-
- function decodeEntityRanges(text, ranges) {
- var entities = Array(text.length).fill(null);
- if (ranges) {
- ranges.forEach(function (range) {
- // Using Unicode-enabled substrings converted to JavaScript lengths,
- // fill the output array with entity keys.
- var start = substr$1(text, 0, range.offset).length;
- var end = start + substr$1(text, range.offset, range.length).length;
- for (var ii = start; ii < end; ii++) {
- entities[ii] = range.key;
- }
- });
- }
- return entities;
- }
-
- var decodeEntityRanges_1 = decodeEntityRanges;
-
- var OrderedSet$6 = immutable.OrderedSet;
-
-
-
- var substr$2 = UnicodeUtils_1.substr;
-
-
- var EMPTY_SET$3 = OrderedSet$6();
-
- /**
- * Convert to native JavaScript string lengths to determine ranges.
- */
- function decodeInlineStyleRanges(text, ranges) {
- var styles = Array(text.length).fill(EMPTY_SET$3);
- if (ranges) {
- ranges.forEach(function ( /*object*/range) {
- var cursor = substr$2(text, 0, range.offset).length;
- var end = cursor + substr$2(text, range.offset, range.length).length;
- while (cursor < end) {
- styles[cursor] = styles[cursor].add(range.style);
- cursor++;
- }
- });
- }
- return styles;
- }
-
- var decodeInlineStyleRanges_1 = decodeInlineStyleRanges;
-
- 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; };
-
- var List$d = immutable.List,
- Map$9 = immutable.Map,
- OrderedMap$4 = immutable.OrderedMap;
-
-
- var decodeBlockNodeConfig = function decodeBlockNodeConfig(block, entityMap) {
- var key = block.key,
- type = block.type,
- data = block.data,
- text = block.text,
- depth = block.depth;
-
-
- var blockNodeConfig = {
- text: text,
- depth: depth || 0,
- type: type || 'unstyled',
- key: key || generateRandomKey_1(),
- data: Map$9(data),
- characterList: decodeCharacterList(block, entityMap)
- };
-
- return blockNodeConfig;
- };
-
- var decodeCharacterList = function decodeCharacterList(block, entityMap) {
- var text = block.text,
- rawEntityRanges = block.entityRanges,
- rawInlineStyleRanges = block.inlineStyleRanges;
-
-
- var entityRanges = rawEntityRanges || [];
- var inlineStyleRanges = rawInlineStyleRanges || [];
-
- // Translate entity range keys to the DraftEntity map.
- return createCharacterList_1(decodeInlineStyleRanges_1(text, inlineStyleRanges), decodeEntityRanges_1(text, entityRanges.filter(function (range) {
- return entityMap.hasOwnProperty(range.key);
- }).map(function (range) {
- return _extends$8({}, range, { key: entityMap[range.key] });
- })));
- };
-
- var decodeContentBlocks = function decodeContentBlocks(blocks, entityMap) {
- return OrderedMap$4(blocks.map(function (block) {
- var contentBlock = new ContentBlock_1(decodeBlockNodeConfig(block, entityMap));
- return [contentBlock.getKey(), contentBlock];
- }));
- };
-
- var decodeRawBlocks = function decodeRawBlocks(rawState, entityMap) {
- var isTreeRawBlock = Array.isArray(rawState.blocks[0].children);
- var rawBlocks = rawState.blocks;
-
- {
- return decodeContentBlocks(isTreeRawBlock ? DraftTreeAdapter_1.fromRawTreeStateToRawState(rawState).blocks : rawBlocks, entityMap);
- }
- };
-
- var decodeRawEntityMap = function decodeRawEntityMap(rawState) {
- var rawEntityMap = rawState.entityMap;
-
- var entityMap = {};
-
- // TODO: Update this once we completely remove DraftEntity
- Object.keys(rawEntityMap).forEach(function (rawEntityKey) {
- var _rawEntityMap$rawEnti = rawEntityMap[rawEntityKey],
- type = _rawEntityMap$rawEnti.type,
- mutability = _rawEntityMap$rawEnti.mutability,
- data = _rawEntityMap$rawEnti.data;
-
- // get the key reference to created entity
-
- entityMap[rawEntityKey] = DraftEntity_1.__create(type, mutability, data || {});
- });
-
- return entityMap;
- };
-
- var convertFromRawToDraftState = function convertFromRawToDraftState(rawState) {
- !Array.isArray(rawState.blocks) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'invalid RawDraftContentState') : invariant_1(false) : void 0;
-
- // decode entities
- var entityMap = decodeRawEntityMap(rawState);
-
- // decode blockMap
- var blockMap = decodeRawBlocks(rawState, entityMap);
-
- // create initial selection
- var selectionState = blockMap.isEmpty() ? new SelectionState_1() : SelectionState_1.createEmpty(blockMap.first().getKey());
-
- return new ContentState_1({
- blockMap: blockMap,
- entityMap: entityMap,
- selectionBefore: selectionState,
- selectionAfter: selectionState
- });
- };
-
- var convertFromRawToDraftState_1 = convertFromRawToDraftState;
-
- /**
- * Like range.getBoundingClientRect() but normalizes for browser bugs.
- */
- function getRangeBoundingClientRect(range) {
- // "Return a DOMRect object describing the smallest rectangle that includes
- // the first rectangle in list and all of the remaining rectangles of which
- // the height or width is not zero."
- // http://www.w3.org/TR/cssom-view/#dom-range-getboundingclientrect
- var rects = getRangeClientRects_1(range);
- var top = 0;
- var right = 0;
- var bottom = 0;
- var left = 0;
-
- if (rects.length) {
- // If the first rectangle has 0 width, we use the second, this is needed
- // because Chrome renders a 0 width rectangle when the selection contains
- // a line break.
- if (rects.length > 1 && rects[0].width === 0) {
- var _rects$ = rects[1];
- top = _rects$.top;
- right = _rects$.right;
- bottom = _rects$.bottom;
- left = _rects$.left;
- } else {
- var _rects$2 = rects[0];
- top = _rects$2.top;
- right = _rects$2.right;
- bottom = _rects$2.bottom;
- left = _rects$2.left;
- }
-
- for (var ii = 1; ii < rects.length; ii++) {
- var rect = rects[ii];
- if (rect.height !== 0 && rect.width !== 0) {
- top = Math.min(top, rect.top);
- right = Math.max(right, rect.right);
- bottom = Math.max(bottom, rect.bottom);
- left = Math.min(left, rect.left);
- }
- }
- }
-
- return {
- top: top,
- right: right,
- bottom: bottom,
- left: left,
- width: right - left,
- height: bottom - top
- };
- }
-
- var getRangeBoundingClientRect_1 = getRangeBoundingClientRect;
-
- /**
- * Return the bounding ClientRect for the visible DOM selection, if any.
- * In cases where there are no selected ranges or the bounding rect is
- * temporarily invalid, return null.
- */
- function getVisibleSelectionRect(global) {
- var selection = global.getSelection();
- if (!selection.rangeCount) {
- return null;
- }
-
- var range = selection.getRangeAt(0);
- var boundingRect = getRangeBoundingClientRect_1(range);
- var top = boundingRect.top,
- right = boundingRect.right,
- bottom = boundingRect.bottom,
- left = boundingRect.left;
-
- // When a re-render leads to a node being removed, the DOM selection will
- // temporarily be placed on an ancestor node, which leads to an invalid
- // bounding rect. Discard this state.
-
- if (top === 0 && right === 0 && bottom === 0 && left === 0) {
- return null;
- }
-
- return boundingRect;
- }
-
- var getVisibleSelectionRect_1 = getVisibleSelectionRect;
-
- var DraftPublic = {
- Editor: DraftEditor_react,
- EditorBlock: DraftEditorBlock_react,
- EditorState: EditorState_1,
-
- CompositeDecorator: CompositeDraftDecorator_1,
- Entity: DraftEntity_1,
- EntityInstance: DraftEntityInstance_1,
-
- BlockMapBuilder: BlockMapBuilder_1,
- CharacterMetadata: CharacterMetadata_1,
- ContentBlock: ContentBlock_1,
- ContentState: ContentState_1,
- SelectionState: SelectionState_1,
-
- AtomicBlockUtils: AtomicBlockUtils_1,
- KeyBindingUtil: KeyBindingUtil_1,
- Modifier: DraftModifier_1,
- RichUtils: RichTextEditorUtil_1,
-
- DefaultDraftBlockRenderMap: DefaultDraftBlockRenderMap_1,
- DefaultDraftInlineStyle: DefaultDraftInlineStyle,
-
- convertFromHTML: convertFromHTMLToContentBlocks,
- convertFromRaw: convertFromRawToDraftState_1,
- convertToRaw: convertFromDraftStateToRaw_1,
- genKey: generateRandomKey_1,
- getDefaultKeyBinding: getDefaultKeyBinding_1,
- getVisibleSelectionRect: getVisibleSelectionRect_1
- };
-
- var Draft = DraftPublic;
- var Draft_1 = Draft.Editor;
- var Draft_3 = Draft.EditorState;
- var Draft_4 = Draft.CompositeDecorator;
- var Draft_14 = Draft.Modifier;
- var Draft_15 = Draft.RichUtils;
- var Draft_20 = Draft.convertToRaw;
-
- exports.Draft = Draft;
- exports.Draft_1 = Draft_1;
- exports.Draft_14 = Draft_14;
- exports.Draft_15 = Draft_15;
- exports.Draft_20 = Draft_20;
- exports.Draft_3 = Draft_3;
- exports.Draft_4 = Draft_4;
- //# sourceMappingURL=Draft-a5afe13a.js.map
|