vue.common.js 134 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410
  1. 'use strict';
  2. /* */
  3. /**
  4. * Convert a value to a string that is actually rendered.
  5. */
  6. function _toString (val) {
  7. return val == null
  8. ? ''
  9. : typeof val === 'object'
  10. ? JSON.stringify(val, null, 2)
  11. : String(val)
  12. }
  13. /**
  14. * Convert a input value to a number for persistence.
  15. * If the conversion fails, return original string.
  16. */
  17. function toNumber (val) {
  18. var n = parseFloat(val, 10)
  19. return (n || n === 0) ? n : val
  20. }
  21. /**
  22. * Make a map and return a function for checking if a key
  23. * is in that map.
  24. */
  25. function makeMap (
  26. str,
  27. expectsLowerCase
  28. ) {
  29. var map = Object.create(null)
  30. var list = str.split(',')
  31. for (var i = 0; i < list.length; i++) {
  32. map[list[i]] = true
  33. }
  34. return expectsLowerCase
  35. ? function (val) { return map[val.toLowerCase()]; }
  36. : function (val) { return map[val]; }
  37. }
  38. /**
  39. * Check if a tag is a built-in tag.
  40. */
  41. var isBuiltInTag = makeMap('slot,component', true)
  42. /**
  43. * Remove an item from an array
  44. */
  45. function remove (arr, item) {
  46. if (arr.length) {
  47. var index = arr.indexOf(item)
  48. if (index > -1) {
  49. return arr.splice(index, 1)
  50. }
  51. }
  52. }
  53. /**
  54. * Check whether the object has the property.
  55. */
  56. var hasOwnProperty = Object.prototype.hasOwnProperty
  57. function hasOwn (obj, key) {
  58. return hasOwnProperty.call(obj, key)
  59. }
  60. /**
  61. * Check if value is primitive
  62. */
  63. function isPrimitive (value) {
  64. return typeof value === 'string' || typeof value === 'number'
  65. }
  66. /**
  67. * Create a cached version of a pure function.
  68. */
  69. function cached (fn) {
  70. var cache = Object.create(null)
  71. return function cachedFn (str) {
  72. var hit = cache[str]
  73. return hit || (cache[str] = fn(str))
  74. }
  75. }
  76. /**
  77. * Camelize a hyphen-delmited string.
  78. */
  79. var camelizeRE = /-(\w)/g
  80. var camelize = cached(function (str) {
  81. return str.replace(camelizeRE, function (_, c) { return c ? c.toUpperCase() : ''; })
  82. })
  83. /**
  84. * Capitalize a string.
  85. */
  86. var capitalize = cached(function (str) {
  87. return str.charAt(0).toUpperCase() + str.slice(1)
  88. })
  89. /**
  90. * Hyphenate a camelCase string.
  91. */
  92. var hyphenateRE = /([^-])([A-Z])/g
  93. var hyphenate = cached(function (str) {
  94. return str
  95. .replace(hyphenateRE, '$1-$2')
  96. .replace(hyphenateRE, '$1-$2')
  97. .toLowerCase()
  98. })
  99. /**
  100. * Simple bind, faster than native
  101. */
  102. function bind (fn, ctx) {
  103. function boundFn (a) {
  104. var l = arguments.length
  105. return l
  106. ? l > 1
  107. ? fn.apply(ctx, arguments)
  108. : fn.call(ctx, a)
  109. : fn.call(ctx)
  110. }
  111. // record original fn length
  112. boundFn._length = fn.length
  113. return boundFn
  114. }
  115. /**
  116. * Convert an Array-like object to a real Array.
  117. */
  118. function toArray (list, start) {
  119. start = start || 0
  120. var i = list.length - start
  121. var ret = new Array(i)
  122. while (i--) {
  123. ret[i] = list[i + start]
  124. }
  125. return ret
  126. }
  127. /**
  128. * Mix properties into target object.
  129. */
  130. function extend (to, _from) {
  131. for (var key in _from) {
  132. to[key] = _from[key]
  133. }
  134. return to
  135. }
  136. /**
  137. * Quick object check - this is primarily used to tell
  138. * Objects from primitive values when we know the value
  139. * is a JSON-compliant type.
  140. */
  141. function isObject (obj) {
  142. return obj !== null && typeof obj === 'object'
  143. }
  144. /**
  145. * Strict object type check. Only returns true
  146. * for plain JavaScript objects.
  147. */
  148. var toString = Object.prototype.toString
  149. var OBJECT_STRING = '[object Object]'
  150. function isPlainObject (obj) {
  151. return toString.call(obj) === OBJECT_STRING
  152. }
  153. /**
  154. * Merge an Array of Objects into a single Object.
  155. */
  156. function toObject (arr) {
  157. var res = arr[0] || {}
  158. for (var i = 1; i < arr.length; i++) {
  159. if (arr[i]) {
  160. extend(res, arr[i])
  161. }
  162. }
  163. return res
  164. }
  165. /**
  166. * Perform no operation.
  167. */
  168. function noop () {}
  169. /**
  170. * Always return false.
  171. */
  172. var no = function () { return false; }
  173. /**
  174. * Generate a static keys string from compiler modules.
  175. */
  176. function genStaticKeys (modules) {
  177. return modules.reduce(function (keys, m) {
  178. return keys.concat(m.staticKeys || [])
  179. }, []).join(',')
  180. }
  181. /* */
  182. var config = {
  183. /**
  184. * Option merge strategies (used in core/util/options)
  185. */
  186. optionMergeStrategies: Object.create(null),
  187. /**
  188. * Whether to suppress warnings.
  189. */
  190. silent: false,
  191. /**
  192. * Whether to enable devtools
  193. */
  194. devtools: process.env.NODE_ENV !== 'production',
  195. /**
  196. * Error handler for watcher errors
  197. */
  198. errorHandler: null,
  199. /**
  200. * Ignore certain custom elements
  201. */
  202. ignoredElements: null,
  203. /**
  204. * Custom user key aliases for v-on
  205. */
  206. keyCodes: Object.create(null),
  207. /**
  208. * Check if a tag is reserved so that it cannot be registered as a
  209. * component. This is platform-dependent and may be overwritten.
  210. */
  211. isReservedTag: no,
  212. /**
  213. * Check if a tag is an unknown element.
  214. * Platform-dependent.
  215. */
  216. isUnknownElement: no,
  217. /**
  218. * Get the namespace of an element
  219. */
  220. getTagNamespace: noop,
  221. /**
  222. * Check if an attribute must be bound using property, e.g. value
  223. * Platform-dependent.
  224. */
  225. mustUseProp: no,
  226. /**
  227. * List of asset types that a component can own.
  228. */
  229. _assetTypes: [
  230. 'component',
  231. 'directive',
  232. 'filter'
  233. ],
  234. /**
  235. * List of lifecycle hooks.
  236. */
  237. _lifecycleHooks: [
  238. 'beforeCreate',
  239. 'created',
  240. 'beforeMount',
  241. 'mounted',
  242. 'beforeUpdate',
  243. 'updated',
  244. 'beforeDestroy',
  245. 'destroyed',
  246. 'activated',
  247. 'deactivated'
  248. ],
  249. /**
  250. * Max circular updates allowed in a scheduler flush cycle.
  251. */
  252. _maxUpdateCount: 100,
  253. /**
  254. * Server rendering?
  255. */
  256. _isServer: process.env.VUE_ENV === 'server'
  257. }
  258. /* */
  259. /**
  260. * Check if a string starts with $ or _
  261. */
  262. function isReserved (str) {
  263. var c = (str + '').charCodeAt(0)
  264. return c === 0x24 || c === 0x5F
  265. }
  266. /**
  267. * Define a property.
  268. */
  269. function def (obj, key, val, enumerable) {
  270. Object.defineProperty(obj, key, {
  271. value: val,
  272. enumerable: !!enumerable,
  273. writable: true,
  274. configurable: true
  275. })
  276. }
  277. /**
  278. * Parse simple path.
  279. */
  280. var bailRE = /[^\w\.\$]/
  281. function parsePath (path) {
  282. if (bailRE.test(path)) {
  283. return
  284. } else {
  285. var segments = path.split('.')
  286. return function (obj) {
  287. for (var i = 0; i < segments.length; i++) {
  288. if (!obj) return
  289. obj = obj[segments[i]]
  290. }
  291. return obj
  292. }
  293. }
  294. }
  295. /* */
  296. /* global MutationObserver */
  297. // can we use __proto__?
  298. var hasProto = '__proto__' in {}
  299. // Browser environment sniffing
  300. var inBrowser =
  301. typeof window !== 'undefined' &&
  302. Object.prototype.toString.call(window) !== '[object Object]'
  303. // detect devtools
  304. var devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__
  305. // UA sniffing for working around browser-specific quirks
  306. var UA = inBrowser && window.navigator.userAgent.toLowerCase()
  307. var isIos = UA && /(iphone|ipad|ipod|ios)/i.test(UA)
  308. var iosVersionMatch = UA && isIos && UA.match(/os ([\d_]+)/)
  309. var iosVersion = iosVersionMatch && iosVersionMatch[1].split('_')
  310. // MutationObserver is unreliable in iOS 9.3 UIWebView
  311. // detecting it by checking presence of IndexedDB
  312. // ref #3027
  313. var hasMutationObserverBug =
  314. iosVersion &&
  315. Number(iosVersion[0]) >= 9 &&
  316. Number(iosVersion[1]) >= 3 &&
  317. !window.indexedDB
  318. /**
  319. * Defer a task to execute it asynchronously. Ideally this
  320. * should be executed as a microtask, so we leverage
  321. * MutationObserver if it's available, and fallback to
  322. * setTimeout(0).
  323. *
  324. * @param {Function} cb
  325. * @param {Object} ctx
  326. */
  327. var nextTick = (function () {
  328. var callbacks = []
  329. var pending = false
  330. var timerFunc
  331. function nextTickHandler () {
  332. pending = false
  333. var copies = callbacks.slice(0)
  334. callbacks = []
  335. for (var i = 0; i < copies.length; i++) {
  336. copies[i]()
  337. }
  338. }
  339. /* istanbul ignore else */
  340. if (typeof MutationObserver !== 'undefined' && !hasMutationObserverBug) {
  341. var counter = 1
  342. var observer = new MutationObserver(nextTickHandler)
  343. var textNode = document.createTextNode(String(counter))
  344. observer.observe(textNode, {
  345. characterData: true
  346. })
  347. timerFunc = function () {
  348. counter = (counter + 1) % 2
  349. textNode.data = String(counter)
  350. }
  351. } else {
  352. // webpack attempts to inject a shim for setImmediate
  353. // if it is used as a global, so we have to work around that to
  354. // avoid bundling unnecessary code.
  355. var context = inBrowser
  356. ? window
  357. : typeof global !== 'undefined' ? global : {}
  358. timerFunc = context.setImmediate || setTimeout
  359. }
  360. return function (cb, ctx) {
  361. var func = ctx
  362. ? function () { cb.call(ctx) }
  363. : cb
  364. callbacks.push(func)
  365. if (pending) return
  366. pending = true
  367. timerFunc(nextTickHandler, 0)
  368. }
  369. })()
  370. var _Set
  371. /* istanbul ignore if */
  372. if (typeof Set !== 'undefined' && /native code/.test(Set.toString())) {
  373. // use native Set when available.
  374. _Set = Set
  375. } else {
  376. // a non-standard Set polyfill that only works with primitive keys.
  377. _Set = (function () {
  378. function Set () {
  379. this.set = Object.create(null)
  380. }
  381. Set.prototype.has = function has (key) {
  382. return this.set[key] !== undefined
  383. };
  384. Set.prototype.add = function add (key) {
  385. this.set[key] = 1
  386. };
  387. Set.prototype.clear = function clear () {
  388. this.set = Object.create(null)
  389. };
  390. return Set;
  391. }())
  392. }
  393. /* not type checking this file because flow doesn't play well with Proxy */
  394. var hasProxy;
  395. var proxyHandlers;
  396. var initProxy;
  397. if (process.env.NODE_ENV !== 'production') {
  398. var allowedGlobals = makeMap(
  399. 'Infinity,undefined,NaN,isFinite,isNaN,' +
  400. 'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
  401. 'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' +
  402. 'require' // for Webpack/Browserify
  403. )
  404. hasProxy =
  405. typeof Proxy !== 'undefined' &&
  406. Proxy.toString().match(/native code/)
  407. proxyHandlers = {
  408. has: function has (target, key) {
  409. var has = key in target
  410. var isAllowed = allowedGlobals(key) || key.charAt(0) === '_'
  411. if (!has && !isAllowed) {
  412. warn(
  413. "Property or method \"" + key + "\" is not defined on the instance but " +
  414. "referenced during render. Make sure to declare reactive data " +
  415. "properties in the data option.",
  416. target
  417. )
  418. }
  419. return has || !isAllowed
  420. }
  421. }
  422. initProxy = function initProxy (vm) {
  423. if (hasProxy) {
  424. vm._renderProxy = new Proxy(vm, proxyHandlers)
  425. } else {
  426. vm._renderProxy = vm
  427. }
  428. }
  429. }
  430. /* */
  431. var uid$2 = 0
  432. /**
  433. * A dep is an observable that can have multiple
  434. * directives subscribing to it.
  435. */
  436. var Dep = function Dep () {
  437. this.id = uid$2++
  438. this.subs = []
  439. };
  440. Dep.prototype.addSub = function addSub (sub) {
  441. this.subs.push(sub)
  442. };
  443. Dep.prototype.removeSub = function removeSub (sub) {
  444. remove(this.subs, sub)
  445. };
  446. Dep.prototype.depend = function depend () {
  447. if (Dep.target) {
  448. Dep.target.addDep(this)
  449. }
  450. };
  451. Dep.prototype.notify = function notify () {
  452. // stablize the subscriber list first
  453. var subs = this.subs.slice()
  454. for (var i = 0, l = subs.length; i < l; i++) {
  455. subs[i].update()
  456. }
  457. };
  458. // the current target watcher being evaluated.
  459. // this is globally unique because there could be only one
  460. // watcher being evaluated at any time.
  461. Dep.target = null
  462. var targetStack = []
  463. function pushTarget (_target) {
  464. if (Dep.target) targetStack.push(Dep.target)
  465. Dep.target = _target
  466. }
  467. function popTarget () {
  468. Dep.target = targetStack.pop()
  469. }
  470. /* */
  471. var queue = []
  472. var has = {}
  473. var circular = {}
  474. var waiting = false
  475. var flushing = false
  476. var index = 0
  477. /**
  478. * Reset the scheduler's state.
  479. */
  480. function resetSchedulerState () {
  481. queue.length = 0
  482. has = {}
  483. if (process.env.NODE_ENV !== 'production') {
  484. circular = {}
  485. }
  486. waiting = flushing = false
  487. }
  488. /**
  489. * Flush both queues and run the watchers.
  490. */
  491. function flushSchedulerQueue () {
  492. flushing = true
  493. // Sort queue before flush.
  494. // This ensures that:
  495. // 1. Components are updated from parent to child. (because parent is always
  496. // created before the child)
  497. // 2. A component's user watchers are run before its render watcher (because
  498. // user watchers are created before the render watcher)
  499. // 3. If a component is destroyed during a parent component's watcher run,
  500. // its watchers can be skipped.
  501. queue.sort(function (a, b) { return a.id - b.id; })
  502. // do not cache length because more watchers might be pushed
  503. // as we run existing watchers
  504. for (index = 0; index < queue.length; index++) {
  505. var watcher = queue[index]
  506. var id = watcher.id
  507. has[id] = null
  508. watcher.run()
  509. // in dev build, check and stop circular updates.
  510. if (process.env.NODE_ENV !== 'production' && has[id] != null) {
  511. circular[id] = (circular[id] || 0) + 1
  512. if (circular[id] > config._maxUpdateCount) {
  513. warn(
  514. 'You may have an infinite update loop ' + (
  515. watcher.user
  516. ? ("in watcher with expression \"" + (watcher.expression) + "\"")
  517. : "in a component render function."
  518. ),
  519. watcher.vm
  520. )
  521. break
  522. }
  523. }
  524. }
  525. // devtool hook
  526. /* istanbul ignore if */
  527. if (devtools && config.devtools) {
  528. devtools.emit('flush')
  529. }
  530. resetSchedulerState()
  531. }
  532. /**
  533. * Push a watcher into the watcher queue.
  534. * Jobs with duplicate IDs will be skipped unless it's
  535. * pushed when the queue is being flushed.
  536. */
  537. function queueWatcher (watcher) {
  538. var id = watcher.id
  539. if (has[id] == null) {
  540. has[id] = true
  541. if (!flushing) {
  542. queue.push(watcher)
  543. } else {
  544. // if already flushing, splice the watcher based on its id
  545. // if already past its id, it will be run next immediately.
  546. var i = queue.length - 1
  547. while (i >= 0 && queue[i].id > watcher.id) {
  548. i--
  549. }
  550. queue.splice(Math.max(i, index) + 1, 0, watcher)
  551. }
  552. // queue the flush
  553. if (!waiting) {
  554. waiting = true
  555. nextTick(flushSchedulerQueue)
  556. }
  557. }
  558. }
  559. /* */
  560. var uid$1 = 0
  561. /**
  562. * A watcher parses an expression, collects dependencies,
  563. * and fires callback when the expression value changes.
  564. * This is used for both the $watch() api and directives.
  565. */
  566. var Watcher = function Watcher (
  567. vm,
  568. expOrFn,
  569. cb,
  570. options
  571. ) {
  572. if ( options === void 0 ) options = {};
  573. this.vm = vm
  574. vm._watchers.push(this)
  575. // options
  576. this.deep = !!options.deep
  577. this.user = !!options.user
  578. this.lazy = !!options.lazy
  579. this.sync = !!options.sync
  580. this.expression = expOrFn.toString()
  581. this.cb = cb
  582. this.id = ++uid$1 // uid for batching
  583. this.active = true
  584. this.dirty = this.lazy // for lazy watchers
  585. this.deps = []
  586. this.newDeps = []
  587. this.depIds = new _Set()
  588. this.newDepIds = new _Set()
  589. // parse expression for getter
  590. if (typeof expOrFn === 'function') {
  591. this.getter = expOrFn
  592. } else {
  593. this.getter = parsePath(expOrFn)
  594. if (!this.getter) {
  595. this.getter = function () {}
  596. process.env.NODE_ENV !== 'production' && warn(
  597. "Failed watching path: \"" + expOrFn + "\" " +
  598. 'Watcher only accepts simple dot-delimited paths. ' +
  599. 'For full control, use a function instead.',
  600. vm
  601. )
  602. }
  603. }
  604. this.value = this.lazy
  605. ? undefined
  606. : this.get()
  607. };
  608. /**
  609. * Evaluate the getter, and re-collect dependencies.
  610. */
  611. Watcher.prototype.get = function get () {
  612. pushTarget(this)
  613. var value = this.getter.call(this.vm, this.vm)
  614. // "touch" every property so they are all tracked as
  615. // dependencies for deep watching
  616. if (this.deep) {
  617. traverse(value)
  618. }
  619. popTarget()
  620. this.cleanupDeps()
  621. return value
  622. };
  623. /**
  624. * Add a dependency to this directive.
  625. */
  626. Watcher.prototype.addDep = function addDep (dep) {
  627. var id = dep.id
  628. if (!this.newDepIds.has(id)) {
  629. this.newDepIds.add(id)
  630. this.newDeps.push(dep)
  631. if (!this.depIds.has(id)) {
  632. dep.addSub(this)
  633. }
  634. }
  635. };
  636. /**
  637. * Clean up for dependency collection.
  638. */
  639. Watcher.prototype.cleanupDeps = function cleanupDeps () {
  640. var this$1 = this;
  641. var i = this.deps.length
  642. while (i--) {
  643. var dep = this$1.deps[i]
  644. if (!this$1.newDepIds.has(dep.id)) {
  645. dep.removeSub(this$1)
  646. }
  647. }
  648. var tmp = this.depIds
  649. this.depIds = this.newDepIds
  650. this.newDepIds = tmp
  651. this.newDepIds.clear()
  652. tmp = this.deps
  653. this.deps = this.newDeps
  654. this.newDeps = tmp
  655. this.newDeps.length = 0
  656. };
  657. /**
  658. * Subscriber interface.
  659. * Will be called when a dependency changes.
  660. */
  661. Watcher.prototype.update = function update () {
  662. /* istanbul ignore else */
  663. if (this.lazy) {
  664. this.dirty = true
  665. } else if (this.sync) {
  666. this.run()
  667. } else {
  668. queueWatcher(this)
  669. }
  670. };
  671. /**
  672. * Scheduler job interface.
  673. * Will be called by the scheduler.
  674. */
  675. Watcher.prototype.run = function run () {
  676. if (this.active) {
  677. var value = this.get()
  678. if (
  679. value !== this.value ||
  680. // Deep watchers and watchers on Object/Arrays should fire even
  681. // when the value is the same, because the value may
  682. // have mutated.
  683. isObject(value) ||
  684. this.deep
  685. ) {
  686. // set new value
  687. var oldValue = this.value
  688. this.value = value
  689. if (this.user) {
  690. try {
  691. this.cb.call(this.vm, value, oldValue)
  692. } catch (e) {
  693. process.env.NODE_ENV !== 'production' && warn(
  694. ("Error in watcher \"" + (this.expression) + "\""),
  695. this.vm
  696. )
  697. /* istanbul ignore else */
  698. if (config.errorHandler) {
  699. config.errorHandler.call(null, e, this.vm)
  700. } else {
  701. throw e
  702. }
  703. }
  704. } else {
  705. this.cb.call(this.vm, value, oldValue)
  706. }
  707. }
  708. }
  709. };
  710. /**
  711. * Evaluate the value of the watcher.
  712. * This only gets called for lazy watchers.
  713. */
  714. Watcher.prototype.evaluate = function evaluate () {
  715. this.value = this.get()
  716. this.dirty = false
  717. };
  718. /**
  719. * Depend on all deps collected by this watcher.
  720. */
  721. Watcher.prototype.depend = function depend () {
  722. var this$1 = this;
  723. var i = this.deps.length
  724. while (i--) {
  725. this$1.deps[i].depend()
  726. }
  727. };
  728. /**
  729. * Remove self from all dependencies' subcriber list.
  730. */
  731. Watcher.prototype.teardown = function teardown () {
  732. var this$1 = this;
  733. if (this.active) {
  734. // remove self from vm's watcher list
  735. // this is a somewhat expensive operation so we skip it
  736. // if the vm is being destroyed or is performing a v-for
  737. // re-render (the watcher list is then filtered by v-for).
  738. if (!this.vm._isBeingDestroyed && !this.vm._vForRemoving) {
  739. remove(this.vm._watchers, this)
  740. }
  741. var i = this.deps.length
  742. while (i--) {
  743. this$1.deps[i].removeSub(this$1)
  744. }
  745. this.active = false
  746. }
  747. };
  748. /**
  749. * Recursively traverse an object to evoke all converted
  750. * getters, so that every nested property inside the object
  751. * is collected as a "deep" dependency.
  752. */
  753. var seenObjects = new _Set()
  754. function traverse (val, seen) {
  755. var i, keys
  756. if (!seen) {
  757. seen = seenObjects
  758. seen.clear()
  759. }
  760. var isA = Array.isArray(val)
  761. var isO = isObject(val)
  762. if ((isA || isO) && Object.isExtensible(val)) {
  763. if (val.__ob__) {
  764. var depId = val.__ob__.dep.id
  765. if (seen.has(depId)) {
  766. return
  767. } else {
  768. seen.add(depId)
  769. }
  770. }
  771. if (isA) {
  772. i = val.length
  773. while (i--) traverse(val[i], seen)
  774. } else if (isO) {
  775. keys = Object.keys(val)
  776. i = keys.length
  777. while (i--) traverse(val[keys[i]], seen)
  778. }
  779. }
  780. }
  781. /*
  782. * not type checking this file because flow doesn't play well with
  783. * dynamically accessing methods on Array prototype
  784. */
  785. var arrayProto = Array.prototype
  786. var arrayMethods = Object.create(arrayProto)
  787. /**
  788. * Intercept mutating methods and emit events
  789. */
  790. ;[
  791. 'push',
  792. 'pop',
  793. 'shift',
  794. 'unshift',
  795. 'splice',
  796. 'sort',
  797. 'reverse'
  798. ]
  799. .forEach(function (method) {
  800. // cache original method
  801. var original = arrayProto[method]
  802. def(arrayMethods, method, function mutator () {
  803. var arguments$1 = arguments;
  804. // avoid leaking arguments:
  805. // http://jsperf.com/closure-with-arguments
  806. var i = arguments.length
  807. var args = new Array(i)
  808. while (i--) {
  809. args[i] = arguments$1[i]
  810. }
  811. var result = original.apply(this, args)
  812. var ob = this.__ob__
  813. var inserted
  814. switch (method) {
  815. case 'push':
  816. inserted = args
  817. break
  818. case 'unshift':
  819. inserted = args
  820. break
  821. case 'splice':
  822. inserted = args.slice(2)
  823. break
  824. }
  825. if (inserted) ob.observeArray(inserted)
  826. // notify change
  827. ob.dep.notify()
  828. return result
  829. })
  830. })
  831. /* */
  832. var arrayKeys = Object.getOwnPropertyNames(arrayMethods)
  833. /**
  834. * By default, when a reactive property is set, the new value is
  835. * also converted to become reactive. However when passing down props,
  836. * we don't want to force conversion because the value may be a nested value
  837. * under a frozen data structure. Converting it would defeat the optimization.
  838. */
  839. var observerState = {
  840. shouldConvert: true,
  841. isSettingProps: false
  842. }
  843. /**
  844. * Observer class that are attached to each observed
  845. * object. Once attached, the observer converts target
  846. * object's property keys into getter/setters that
  847. * collect dependencies and dispatches updates.
  848. */
  849. var Observer = function Observer (value) {
  850. this.value = value
  851. this.dep = new Dep()
  852. this.vmCount = 0
  853. def(value, '__ob__', this)
  854. if (Array.isArray(value)) {
  855. var augment = hasProto
  856. ? protoAugment
  857. : copyAugment
  858. augment(value, arrayMethods, arrayKeys)
  859. this.observeArray(value)
  860. } else {
  861. this.walk(value)
  862. }
  863. };
  864. /**
  865. * Walk through each property and convert them into
  866. * getter/setters. This method should only be called when
  867. * value type is Object.
  868. */
  869. Observer.prototype.walk = function walk (obj) {
  870. var val = this.value
  871. for (var key in obj) {
  872. defineReactive(val, key, obj[key])
  873. }
  874. };
  875. /**
  876. * Observe a list of Array items.
  877. */
  878. Observer.prototype.observeArray = function observeArray (items) {
  879. for (var i = 0, l = items.length; i < l; i++) {
  880. observe(items[i])
  881. }
  882. };
  883. // helpers
  884. /**
  885. * Augment an target Object or Array by intercepting
  886. * the prototype chain using __proto__
  887. */
  888. function protoAugment (target, src) {
  889. /* eslint-disable no-proto */
  890. target.__proto__ = src
  891. /* eslint-enable no-proto */
  892. }
  893. /**
  894. * Augment an target Object or Array by defining
  895. * hidden properties.
  896. *
  897. * istanbul ignore next
  898. */
  899. function copyAugment (target, src, keys) {
  900. for (var i = 0, l = keys.length; i < l; i++) {
  901. var key = keys[i]
  902. def(target, key, src[key])
  903. }
  904. }
  905. /**
  906. * Attempt to create an observer instance for a value,
  907. * returns the new observer if successfully observed,
  908. * or the existing observer if the value already has one.
  909. */
  910. function observe (value) {
  911. if (!isObject(value)) {
  912. return
  913. }
  914. var ob
  915. if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) {
  916. ob = value.__ob__
  917. } else if (
  918. observerState.shouldConvert &&
  919. !config._isServer &&
  920. (Array.isArray(value) || isPlainObject(value)) &&
  921. Object.isExtensible(value) &&
  922. !value._isVue
  923. ) {
  924. ob = new Observer(value)
  925. }
  926. return ob
  927. }
  928. /**
  929. * Define a reactive property on an Object.
  930. */
  931. function defineReactive (
  932. obj,
  933. key,
  934. val,
  935. customSetter
  936. ) {
  937. var dep = new Dep()
  938. var property = Object.getOwnPropertyDescriptor(obj, key)
  939. if (property && property.configurable === false) {
  940. return
  941. }
  942. // cater for pre-defined getter/setters
  943. var getter = property && property.get
  944. var setter = property && property.set
  945. var childOb = observe(val)
  946. Object.defineProperty(obj, key, {
  947. enumerable: true,
  948. configurable: true,
  949. get: function reactiveGetter () {
  950. var value = getter ? getter.call(obj) : val
  951. if (Dep.target) {
  952. dep.depend()
  953. if (childOb) {
  954. childOb.dep.depend()
  955. }
  956. if (Array.isArray(value)) {
  957. for (var e, i = 0, l = value.length; i < l; i++) {
  958. e = value[i]
  959. e && e.__ob__ && e.__ob__.dep.depend()
  960. }
  961. }
  962. }
  963. return value
  964. },
  965. set: function reactiveSetter (newVal) {
  966. var value = getter ? getter.call(obj) : val
  967. if (newVal === value) {
  968. return
  969. }
  970. if (process.env.NODE_ENV !== 'production' && customSetter) {
  971. customSetter()
  972. }
  973. if (setter) {
  974. setter.call(obj, newVal)
  975. } else {
  976. val = newVal
  977. }
  978. childOb = observe(newVal)
  979. dep.notify()
  980. }
  981. })
  982. }
  983. /**
  984. * Set a property on an object. Adds the new property and
  985. * triggers change notification if the property doesn't
  986. * already exist.
  987. */
  988. function set (obj, key, val) {
  989. if (Array.isArray(obj)) {
  990. obj.splice(key, 1, val)
  991. return val
  992. }
  993. if (hasOwn(obj, key)) {
  994. obj[key] = val
  995. return
  996. }
  997. var ob = obj.__ob__
  998. if (obj._isVue || (ob && ob.vmCount)) {
  999. process.env.NODE_ENV !== 'production' && warn(
  1000. 'Avoid adding reactive properties to a Vue instance or its root $data ' +
  1001. 'at runtime - declare it upfront in the data option.'
  1002. )
  1003. return
  1004. }
  1005. if (!ob) {
  1006. obj[key] = val
  1007. return
  1008. }
  1009. defineReactive(ob.value, key, val)
  1010. ob.dep.notify()
  1011. return val
  1012. }
  1013. /**
  1014. * Delete a property and trigger change if necessary.
  1015. */
  1016. function del (obj, key) {
  1017. var ob = obj.__ob__
  1018. if (obj._isVue || (ob && ob.vmCount)) {
  1019. process.env.NODE_ENV !== 'production' && warn(
  1020. 'Avoid deleting properties on a Vue instance or its root $data ' +
  1021. '- just set it to null.'
  1022. )
  1023. return
  1024. }
  1025. if (!hasOwn(obj, key)) {
  1026. return
  1027. }
  1028. delete obj[key]
  1029. if (!ob) {
  1030. return
  1031. }
  1032. ob.dep.notify()
  1033. }
  1034. /* */
  1035. function initState (vm) {
  1036. vm._watchers = []
  1037. initProps(vm)
  1038. initData(vm)
  1039. initComputed(vm)
  1040. initMethods(vm)
  1041. initWatch(vm)
  1042. }
  1043. function initProps (vm) {
  1044. var props = vm.$options.props
  1045. var propsData = vm.$options.propsData
  1046. if (props) {
  1047. var keys = vm.$options._propKeys = Object.keys(props)
  1048. var isRoot = !vm.$parent
  1049. // root instance props should be converted
  1050. observerState.shouldConvert = isRoot
  1051. var loop = function ( i ) {
  1052. var key = keys[i]
  1053. /* istanbul ignore else */
  1054. if (process.env.NODE_ENV !== 'production') {
  1055. defineReactive(vm, key, validateProp(key, props, propsData, vm), function () {
  1056. if (vm.$parent && !observerState.isSettingProps) {
  1057. warn(
  1058. "Avoid mutating a prop directly since the value will be " +
  1059. "overwritten whenever the parent component re-renders. " +
  1060. "Instead, use a data or computed property based on the prop's " +
  1061. "value. Prop being mutated: \"" + key + "\"",
  1062. vm
  1063. )
  1064. }
  1065. })
  1066. } else {
  1067. defineReactive(vm, key, validateProp(key, props, propsData, vm))
  1068. }
  1069. };
  1070. for (var i = 0; i < keys.length; i++) loop( i );
  1071. observerState.shouldConvert = true
  1072. }
  1073. }
  1074. function initData (vm) {
  1075. var data = vm.$options.data
  1076. data = vm._data = typeof data === 'function'
  1077. ? data.call(vm)
  1078. : data || {}
  1079. if (!isPlainObject(data)) {
  1080. data = {}
  1081. process.env.NODE_ENV !== 'production' && warn(
  1082. 'data functions should return an object.',
  1083. vm
  1084. )
  1085. }
  1086. // proxy data on instance
  1087. var keys = Object.keys(data)
  1088. var props = vm.$options.props
  1089. var i = keys.length
  1090. while (i--) {
  1091. if (props && hasOwn(props, keys[i])) {
  1092. process.env.NODE_ENV !== 'production' && warn(
  1093. "The data property \"" + (keys[i]) + "\" is already declared as a prop. " +
  1094. "Use prop default value instead.",
  1095. vm
  1096. )
  1097. } else {
  1098. proxy(vm, keys[i])
  1099. }
  1100. }
  1101. // observe data
  1102. observe(data)
  1103. data.__ob__ && data.__ob__.vmCount++
  1104. }
  1105. var computedSharedDefinition = {
  1106. enumerable: true,
  1107. configurable: true,
  1108. get: noop,
  1109. set: noop
  1110. }
  1111. function initComputed (vm) {
  1112. var computed = vm.$options.computed
  1113. if (computed) {
  1114. for (var key in computed) {
  1115. var userDef = computed[key]
  1116. if (typeof userDef === 'function') {
  1117. computedSharedDefinition.get = makeComputedGetter(userDef, vm)
  1118. computedSharedDefinition.set = noop
  1119. } else {
  1120. computedSharedDefinition.get = userDef.get
  1121. ? userDef.cache !== false
  1122. ? makeComputedGetter(userDef.get, vm)
  1123. : bind(userDef.get, vm)
  1124. : noop
  1125. computedSharedDefinition.set = userDef.set
  1126. ? bind(userDef.set, vm)
  1127. : noop
  1128. }
  1129. Object.defineProperty(vm, key, computedSharedDefinition)
  1130. }
  1131. }
  1132. }
  1133. function makeComputedGetter (getter, owner) {
  1134. var watcher = new Watcher(owner, getter, noop, {
  1135. lazy: true
  1136. })
  1137. return function computedGetter () {
  1138. if (watcher.dirty) {
  1139. watcher.evaluate()
  1140. }
  1141. if (Dep.target) {
  1142. watcher.depend()
  1143. }
  1144. return watcher.value
  1145. }
  1146. }
  1147. function initMethods (vm) {
  1148. var methods = vm.$options.methods
  1149. if (methods) {
  1150. for (var key in methods) {
  1151. vm[key] = bind(methods[key], vm)
  1152. }
  1153. }
  1154. }
  1155. function initWatch (vm) {
  1156. var watch = vm.$options.watch
  1157. if (watch) {
  1158. for (var key in watch) {
  1159. var handler = watch[key]
  1160. if (Array.isArray(handler)) {
  1161. for (var i = 0; i < handler.length; i++) {
  1162. createWatcher(vm, key, handler[i])
  1163. }
  1164. } else {
  1165. createWatcher(vm, key, handler)
  1166. }
  1167. }
  1168. }
  1169. }
  1170. function createWatcher (vm, key, handler) {
  1171. var options
  1172. if (isPlainObject(handler)) {
  1173. options = handler
  1174. handler = handler.handler
  1175. }
  1176. if (typeof handler === 'string') {
  1177. handler = vm[handler]
  1178. }
  1179. vm.$watch(key, handler, options)
  1180. }
  1181. function stateMixin (Vue) {
  1182. // flow somehow has problems with directly declared definition object
  1183. // when using Object.defineProperty, so we have to procedurally build up
  1184. // the object here.
  1185. var dataDef = {}
  1186. dataDef.get = function () {
  1187. return this._data
  1188. }
  1189. if (process.env.NODE_ENV !== 'production') {
  1190. dataDef.set = function (newData) {
  1191. warn(
  1192. 'Avoid replacing instance root $data. ' +
  1193. 'Use nested data properties instead.',
  1194. this
  1195. )
  1196. }
  1197. }
  1198. Object.defineProperty(Vue.prototype, '$data', dataDef)
  1199. Vue.prototype.$set = set
  1200. Vue.prototype.$delete = del
  1201. Vue.prototype.$watch = function (
  1202. expOrFn,
  1203. cb,
  1204. options
  1205. ) {
  1206. var vm = this
  1207. options = options || {}
  1208. options.user = true
  1209. var watcher = new Watcher(vm, expOrFn, cb, options)
  1210. if (options.immediate) {
  1211. cb.call(vm, watcher.value)
  1212. }
  1213. return function unwatchFn () {
  1214. watcher.teardown()
  1215. }
  1216. }
  1217. }
  1218. function proxy (vm, key) {
  1219. if (!isReserved(key)) {
  1220. Object.defineProperty(vm, key, {
  1221. configurable: true,
  1222. enumerable: true,
  1223. get: function proxyGetter () {
  1224. return vm._data[key]
  1225. },
  1226. set: function proxySetter (val) {
  1227. vm._data[key] = val
  1228. }
  1229. })
  1230. }
  1231. }
  1232. /* */
  1233. var VNode = function VNode (
  1234. tag,
  1235. data,
  1236. children,
  1237. text,
  1238. elm,
  1239. ns,
  1240. context,
  1241. componentOptions
  1242. ) {
  1243. this.tag = tag
  1244. this.data = data
  1245. this.children = children
  1246. this.text = text
  1247. this.elm = elm
  1248. this.ns = ns
  1249. this.context = context
  1250. this.key = data && data.key
  1251. this.componentOptions = componentOptions
  1252. this.child = undefined
  1253. this.parent = undefined
  1254. this.raw = false
  1255. this.isStatic = false
  1256. this.isRootInsert = true
  1257. this.isComment = false
  1258. this.isCloned = false
  1259. // apply construct hook.
  1260. // this is applied during render, before patch happens.
  1261. // unlike other hooks, this is applied on both client and server.
  1262. var constructHook = data && data.hook && data.hook.construct
  1263. if (constructHook) {
  1264. constructHook(this)
  1265. }
  1266. };
  1267. var emptyVNode = function () {
  1268. var node = new VNode()
  1269. node.text = ''
  1270. node.isComment = true
  1271. return node
  1272. }
  1273. // optimized shallow clone
  1274. // used for static nodes and slot nodes because they may be reused across
  1275. // multiple renders, cloning them avoids errors when DOM manipulations rely
  1276. // on their elm reference.
  1277. function cloneVNode (vnode) {
  1278. var cloned = new VNode(
  1279. vnode.tag,
  1280. vnode.data,
  1281. vnode.children,
  1282. vnode.text,
  1283. vnode.elm,
  1284. vnode.ns,
  1285. vnode.context,
  1286. vnode.componentOptions
  1287. )
  1288. cloned.isStatic = vnode.isStatic
  1289. cloned.key = vnode.key
  1290. cloned.isCloned = true
  1291. return cloned
  1292. }
  1293. function cloneVNodes (vnodes) {
  1294. var res = new Array(vnodes.length)
  1295. for (var i = 0; i < vnodes.length; i++) {
  1296. res[i] = cloneVNode(vnodes[i])
  1297. }
  1298. return res
  1299. }
  1300. /* */
  1301. function normalizeChildren (
  1302. children,
  1303. ns
  1304. ) {
  1305. if (isPrimitive(children)) {
  1306. return [createTextVNode(children)]
  1307. }
  1308. if (Array.isArray(children)) {
  1309. var res = []
  1310. for (var i = 0, l = children.length; i < l; i++) {
  1311. var c = children[i]
  1312. var last = res[res.length - 1]
  1313. // nested
  1314. if (Array.isArray(c)) {
  1315. res.push.apply(res, normalizeChildren(c, ns))
  1316. } else if (isPrimitive(c)) {
  1317. if (last && last.text) {
  1318. last.text += String(c)
  1319. } else if (c !== '') {
  1320. // convert primitive to vnode
  1321. res.push(createTextVNode(c))
  1322. }
  1323. } else if (c instanceof VNode) {
  1324. if (c.text && last && last.text) {
  1325. last.text += c.text
  1326. } else {
  1327. // inherit parent namespace
  1328. if (ns) {
  1329. applyNS(c, ns)
  1330. }
  1331. res.push(c)
  1332. }
  1333. }
  1334. }
  1335. return res
  1336. }
  1337. }
  1338. function createTextVNode (val) {
  1339. return new VNode(undefined, undefined, undefined, String(val))
  1340. }
  1341. function applyNS (vnode, ns) {
  1342. if (vnode.tag && !vnode.ns) {
  1343. vnode.ns = ns
  1344. if (vnode.children) {
  1345. for (var i = 0, l = vnode.children.length; i < l; i++) {
  1346. applyNS(vnode.children[i], ns)
  1347. }
  1348. }
  1349. }
  1350. }
  1351. function getFirstComponentChild (children) {
  1352. return children && children.filter(function (c) { return c && c.componentOptions; })[0]
  1353. }
  1354. function mergeVNodeHook (def, key, hook) {
  1355. var oldHook = def[key]
  1356. if (oldHook) {
  1357. var injectedHash = def.__injected || (def.__injected = {})
  1358. if (!injectedHash[key]) {
  1359. injectedHash[key] = true
  1360. def[key] = function () {
  1361. oldHook.apply(this, arguments)
  1362. hook.apply(this, arguments)
  1363. }
  1364. }
  1365. } else {
  1366. def[key] = hook
  1367. }
  1368. }
  1369. function updateListeners (
  1370. on,
  1371. oldOn,
  1372. add,
  1373. remove
  1374. ) {
  1375. var name, cur, old, fn, event, capture
  1376. for (name in on) {
  1377. cur = on[name]
  1378. old = oldOn[name]
  1379. if (!cur) {
  1380. process.env.NODE_ENV !== 'production' && warn(
  1381. ("Handler for event \"" + name + "\" is undefined.")
  1382. )
  1383. } else if (!old) {
  1384. capture = name.charAt(0) === '!'
  1385. event = capture ? name.slice(1) : name
  1386. if (Array.isArray(cur)) {
  1387. add(event, (cur.invoker = arrInvoker(cur)), capture)
  1388. } else {
  1389. if (!cur.invoker) {
  1390. fn = cur
  1391. cur = on[name] = {}
  1392. cur.fn = fn
  1393. cur.invoker = fnInvoker(cur)
  1394. }
  1395. add(event, cur.invoker, capture)
  1396. }
  1397. } else if (Array.isArray(old)) {
  1398. old.length = cur.length
  1399. for (var i = 0; i < old.length; i++) old[i] = cur[i]
  1400. on[name] = old
  1401. } else {
  1402. old.fn = cur
  1403. on[name] = old
  1404. }
  1405. }
  1406. for (name in oldOn) {
  1407. if (!on[name]) {
  1408. event = name.charAt(0) === '!' ? name.slice(1) : name
  1409. remove(event, oldOn[name].invoker)
  1410. }
  1411. }
  1412. }
  1413. function arrInvoker (arr) {
  1414. return function (ev) {
  1415. var arguments$1 = arguments;
  1416. var single = arguments.length === 1
  1417. for (var i = 0; i < arr.length; i++) {
  1418. single ? arr[i](ev) : arr[i].apply(null, arguments$1)
  1419. }
  1420. }
  1421. }
  1422. function fnInvoker (o) {
  1423. return function (ev) {
  1424. var single = arguments.length === 1
  1425. single ? o.fn(ev) : o.fn.apply(null, arguments)
  1426. }
  1427. }
  1428. /* */
  1429. var activeInstance = null
  1430. function initLifecycle (vm) {
  1431. var options = vm.$options
  1432. // locate first non-abstract parent
  1433. var parent = options.parent
  1434. if (parent && !options.abstract) {
  1435. while (parent.$options.abstract && parent.$parent) {
  1436. parent = parent.$parent
  1437. }
  1438. parent.$children.push(vm)
  1439. }
  1440. vm.$parent = parent
  1441. vm.$root = parent ? parent.$root : vm
  1442. vm.$children = []
  1443. vm.$refs = {}
  1444. vm._watcher = null
  1445. vm._inactive = false
  1446. vm._isMounted = false
  1447. vm._isDestroyed = false
  1448. vm._isBeingDestroyed = false
  1449. }
  1450. function lifecycleMixin (Vue) {
  1451. Vue.prototype._mount = function (
  1452. el,
  1453. hydrating
  1454. ) {
  1455. var vm = this
  1456. vm.$el = el
  1457. if (!vm.$options.render) {
  1458. vm.$options.render = emptyVNode
  1459. if (process.env.NODE_ENV !== 'production') {
  1460. /* istanbul ignore if */
  1461. if (vm.$options.template) {
  1462. warn(
  1463. 'You are using the runtime-only build of Vue where the template ' +
  1464. 'option is not available. Either pre-compile the templates into ' +
  1465. 'render functions, or use the compiler-included build.',
  1466. vm
  1467. )
  1468. } else {
  1469. warn(
  1470. 'Failed to mount component: template or render function not defined.',
  1471. vm
  1472. )
  1473. }
  1474. }
  1475. }
  1476. callHook(vm, 'beforeMount')
  1477. vm._watcher = new Watcher(vm, function () {
  1478. vm._update(vm._render(), hydrating)
  1479. }, noop)
  1480. hydrating = false
  1481. // root instance, call mounted on self
  1482. // mounted is called for child components in its inserted hook
  1483. if (vm.$root === vm) {
  1484. vm._isMounted = true
  1485. callHook(vm, 'mounted')
  1486. }
  1487. return vm
  1488. }
  1489. Vue.prototype._update = function (vnode, hydrating) {
  1490. var vm = this
  1491. if (vm._isMounted) {
  1492. callHook(vm, 'beforeUpdate')
  1493. }
  1494. var prevEl = vm.$el
  1495. var prevActiveInstance = activeInstance
  1496. activeInstance = vm
  1497. var prevVnode = vm._vnode
  1498. vm._vnode = vnode
  1499. if (!prevVnode) {
  1500. // Vue.prototype.__patch__ is injected in entry points
  1501. // based on the rendering backend used.
  1502. vm.$el = vm.__patch__(vm.$el, vnode, hydrating)
  1503. } else {
  1504. vm.$el = vm.__patch__(prevVnode, vnode)
  1505. }
  1506. activeInstance = prevActiveInstance
  1507. // update __vue__ reference
  1508. if (prevEl) {
  1509. prevEl.__vue__ = null
  1510. }
  1511. if (vm.$el) {
  1512. vm.$el.__vue__ = vm
  1513. }
  1514. // if parent is an HOC, update its $el as well
  1515. if (vm.$vnode && vm.$parent && vm.$vnode === vm.$parent._vnode) {
  1516. vm.$parent.$el = vm.$el
  1517. }
  1518. if (vm._isMounted) {
  1519. callHook(vm, 'updated')
  1520. }
  1521. }
  1522. Vue.prototype._updateFromParent = function (
  1523. propsData,
  1524. listeners,
  1525. parentVnode,
  1526. renderChildren
  1527. ) {
  1528. var vm = this
  1529. var hasChildren = !!(vm.$options._renderChildren || renderChildren)
  1530. vm.$options._parentVnode = parentVnode
  1531. vm.$options._renderChildren = renderChildren
  1532. // update props
  1533. if (propsData && vm.$options.props) {
  1534. observerState.shouldConvert = false
  1535. if (process.env.NODE_ENV !== 'production') {
  1536. observerState.isSettingProps = true
  1537. }
  1538. var propKeys = vm.$options._propKeys || []
  1539. for (var i = 0; i < propKeys.length; i++) {
  1540. var key = propKeys[i]
  1541. vm[key] = validateProp(key, vm.$options.props, propsData, vm)
  1542. }
  1543. observerState.shouldConvert = true
  1544. if (process.env.NODE_ENV !== 'production') {
  1545. observerState.isSettingProps = false
  1546. }
  1547. }
  1548. // update listeners
  1549. if (listeners) {
  1550. var oldListeners = vm.$options._parentListeners
  1551. vm.$options._parentListeners = listeners
  1552. vm._updateListeners(listeners, oldListeners)
  1553. }
  1554. // resolve slots + force update if has children
  1555. if (hasChildren) {
  1556. vm.$slots = resolveSlots(renderChildren)
  1557. vm.$forceUpdate()
  1558. }
  1559. }
  1560. Vue.prototype.$forceUpdate = function () {
  1561. var vm = this
  1562. if (vm._watcher) {
  1563. vm._watcher.update()
  1564. }
  1565. }
  1566. Vue.prototype.$destroy = function () {
  1567. var vm = this
  1568. if (vm._isBeingDestroyed) {
  1569. return
  1570. }
  1571. callHook(vm, 'beforeDestroy')
  1572. vm._isBeingDestroyed = true
  1573. // remove self from parent
  1574. var parent = vm.$parent
  1575. if (parent && !parent._isBeingDestroyed && !vm.$options.abstract) {
  1576. remove(parent.$children, vm)
  1577. }
  1578. // teardown watchers
  1579. if (vm._watcher) {
  1580. vm._watcher.teardown()
  1581. }
  1582. var i = vm._watchers.length
  1583. while (i--) {
  1584. vm._watchers[i].teardown()
  1585. }
  1586. // remove reference from data ob
  1587. // frozen object may not have observer.
  1588. if (vm._data.__ob__) {
  1589. vm._data.__ob__.vmCount--
  1590. }
  1591. // call the last hook...
  1592. vm._isDestroyed = true
  1593. callHook(vm, 'destroyed')
  1594. // turn off all instance listeners.
  1595. vm.$off()
  1596. // remove __vue__ reference
  1597. if (vm.$el) {
  1598. vm.$el.__vue__ = null
  1599. }
  1600. }
  1601. }
  1602. function callHook (vm, hook) {
  1603. var handlers = vm.$options[hook]
  1604. if (handlers) {
  1605. for (var i = 0, j = handlers.length; i < j; i++) {
  1606. handlers[i].call(vm)
  1607. }
  1608. }
  1609. vm.$emit('hook:' + hook)
  1610. }
  1611. /* */
  1612. var hooks = { init: init, prepatch: prepatch, insert: insert, destroy: destroy }
  1613. var hooksToMerge = Object.keys(hooks)
  1614. function createComponent (
  1615. Ctor,
  1616. data,
  1617. context,
  1618. children,
  1619. tag
  1620. ) {
  1621. if (!Ctor) {
  1622. return
  1623. }
  1624. if (isObject(Ctor)) {
  1625. Ctor = Vue.extend(Ctor)
  1626. }
  1627. if (typeof Ctor !== 'function') {
  1628. if (process.env.NODE_ENV !== 'production') {
  1629. warn(("Invalid Component definition: " + (String(Ctor))), context)
  1630. }
  1631. return
  1632. }
  1633. // async component
  1634. if (!Ctor.cid) {
  1635. if (Ctor.resolved) {
  1636. Ctor = Ctor.resolved
  1637. } else {
  1638. Ctor = resolveAsyncComponent(Ctor, function () {
  1639. // it's ok to queue this on every render because
  1640. // $forceUpdate is buffered by the scheduler.
  1641. context.$forceUpdate()
  1642. })
  1643. if (!Ctor) {
  1644. // return nothing if this is indeed an async component
  1645. // wait for the callback to trigger parent update.
  1646. return
  1647. }
  1648. }
  1649. }
  1650. data = data || {}
  1651. // extract props
  1652. var propsData = extractProps(data, Ctor)
  1653. // functional component
  1654. if (Ctor.options.functional) {
  1655. return createFunctionalComponent(Ctor, propsData, data, context, children)
  1656. }
  1657. // extract listeners, since these needs to be treated as
  1658. // child component listeners instead of DOM listeners
  1659. var listeners = data.on
  1660. // replace with listeners with .native modifier
  1661. data.on = data.nativeOn
  1662. if (Ctor.options.abstract) {
  1663. // abstract components do not keep anything
  1664. // other than props & listeners
  1665. data = {}
  1666. }
  1667. // merge component management hooks onto the placeholder node
  1668. mergeHooks(data)
  1669. // return a placeholder vnode
  1670. var name = Ctor.options.name || tag
  1671. var vnode = new VNode(
  1672. ("vue-component-" + (Ctor.cid) + (name ? ("-" + name) : '')),
  1673. data, undefined, undefined, undefined, undefined, context,
  1674. { Ctor: Ctor, propsData: propsData, listeners: listeners, tag: tag, children: children }
  1675. )
  1676. return vnode
  1677. }
  1678. function createFunctionalComponent (
  1679. Ctor,
  1680. propsData,
  1681. data,
  1682. context,
  1683. children
  1684. ) {
  1685. var props = {}
  1686. var propOptions = Ctor.options.props
  1687. if (propOptions) {
  1688. for (var key in propOptions) {
  1689. props[key] = validateProp(key, propOptions, propsData)
  1690. }
  1691. }
  1692. return Ctor.options.render.call(
  1693. null,
  1694. context.$createElement,
  1695. {
  1696. props: props,
  1697. data: data,
  1698. parent: context,
  1699. children: normalizeChildren(children),
  1700. slots: function () { return resolveSlots(children); }
  1701. }
  1702. )
  1703. }
  1704. function createComponentInstanceForVnode (
  1705. vnode, // we know it's MountedComponentVNode but flow doesn't
  1706. parent // activeInstance in lifecycle state
  1707. ) {
  1708. var vnodeComponentOptions = vnode.componentOptions
  1709. var options = {
  1710. _isComponent: true,
  1711. parent: parent,
  1712. propsData: vnodeComponentOptions.propsData,
  1713. _componentTag: vnodeComponentOptions.tag,
  1714. _parentVnode: vnode,
  1715. _parentListeners: vnodeComponentOptions.listeners,
  1716. _renderChildren: vnodeComponentOptions.children
  1717. }
  1718. // check inline-template render functions
  1719. var inlineTemplate = vnode.data.inlineTemplate
  1720. if (inlineTemplate) {
  1721. options.render = inlineTemplate.render
  1722. options.staticRenderFns = inlineTemplate.staticRenderFns
  1723. }
  1724. return new vnodeComponentOptions.Ctor(options)
  1725. }
  1726. function init (vnode, hydrating) {
  1727. if (!vnode.child || vnode.child._isDestroyed) {
  1728. var child = vnode.child = createComponentInstanceForVnode(vnode, activeInstance)
  1729. child.$mount(hydrating ? vnode.elm : undefined, hydrating)
  1730. }
  1731. }
  1732. function prepatch (
  1733. oldVnode,
  1734. vnode
  1735. ) {
  1736. var options = vnode.componentOptions
  1737. var child = vnode.child = oldVnode.child
  1738. child._updateFromParent(
  1739. options.propsData, // updated props
  1740. options.listeners, // updated listeners
  1741. vnode, // new parent vnode
  1742. options.children // new children
  1743. )
  1744. }
  1745. function insert (vnode) {
  1746. if (!vnode.child._isMounted) {
  1747. vnode.child._isMounted = true
  1748. callHook(vnode.child, 'mounted')
  1749. }
  1750. if (vnode.data.keepAlive) {
  1751. vnode.child._inactive = false
  1752. callHook(vnode.child, 'activated')
  1753. }
  1754. }
  1755. function destroy (vnode) {
  1756. if (!vnode.child._isDestroyed) {
  1757. if (!vnode.data.keepAlive) {
  1758. vnode.child.$destroy()
  1759. } else {
  1760. vnode.child._inactive = true
  1761. callHook(vnode.child, 'deactivated')
  1762. }
  1763. }
  1764. }
  1765. function resolveAsyncComponent (
  1766. factory,
  1767. cb
  1768. ) {
  1769. if (factory.requested) {
  1770. // pool callbacks
  1771. factory.pendingCallbacks.push(cb)
  1772. } else {
  1773. factory.requested = true
  1774. var cbs = factory.pendingCallbacks = [cb]
  1775. var sync = true
  1776. var resolve = function (res) {
  1777. if (isObject(res)) {
  1778. res = Vue.extend(res)
  1779. }
  1780. // cache resolved
  1781. factory.resolved = res
  1782. // invoke callbacks only if this is not a synchronous resolve
  1783. // (async resolves are shimmed as synchronous during SSR)
  1784. if (!sync) {
  1785. for (var i = 0, l = cbs.length; i < l; i++) {
  1786. cbs[i](res)
  1787. }
  1788. }
  1789. }
  1790. var reject = function (reason) {
  1791. process.env.NODE_ENV !== 'production' && warn(
  1792. "Failed to resolve async component: " + (String(factory)) +
  1793. (reason ? ("\nReason: " + reason) : '')
  1794. )
  1795. }
  1796. var res = factory(resolve, reject)
  1797. // handle promise
  1798. if (res && typeof res.then === 'function' && !factory.resolved) {
  1799. res.then(resolve, reject)
  1800. }
  1801. sync = false
  1802. // return in case resolved synchronously
  1803. return factory.resolved
  1804. }
  1805. }
  1806. function extractProps (data, Ctor) {
  1807. // we are only extrating raw values here.
  1808. // validation and default values are handled in the child
  1809. // component itself.
  1810. var propOptions = Ctor.options.props
  1811. if (!propOptions) {
  1812. return
  1813. }
  1814. var res = {}
  1815. var attrs = data.attrs;
  1816. var props = data.props;
  1817. var domProps = data.domProps;
  1818. if (attrs || props || domProps) {
  1819. for (var key in propOptions) {
  1820. var altKey = hyphenate(key)
  1821. checkProp(res, props, key, altKey, true) ||
  1822. checkProp(res, attrs, key, altKey) ||
  1823. checkProp(res, domProps, key, altKey)
  1824. }
  1825. }
  1826. return res
  1827. }
  1828. function checkProp (
  1829. res,
  1830. hash,
  1831. key,
  1832. altKey,
  1833. preserve
  1834. ) {
  1835. if (hash) {
  1836. if (hasOwn(hash, key)) {
  1837. res[key] = hash[key]
  1838. if (!preserve) {
  1839. delete hash[key]
  1840. }
  1841. return true
  1842. } else if (hasOwn(hash, altKey)) {
  1843. res[key] = hash[altKey]
  1844. if (!preserve) {
  1845. delete hash[altKey]
  1846. }
  1847. return true
  1848. }
  1849. }
  1850. return false
  1851. }
  1852. function mergeHooks (data) {
  1853. if (!data.hook) {
  1854. data.hook = {}
  1855. }
  1856. for (var i = 0; i < hooksToMerge.length; i++) {
  1857. var key = hooksToMerge[i]
  1858. var fromParent = data.hook[key]
  1859. var ours = hooks[key]
  1860. data.hook[key] = fromParent ? mergeHook$1(ours, fromParent) : ours
  1861. }
  1862. }
  1863. function mergeHook$1 (a, b) {
  1864. // since all hooks have at most two args, use fixed args
  1865. // to avoid having to use fn.apply().
  1866. return function (_, __) {
  1867. a(_, __)
  1868. b(_, __)
  1869. }
  1870. }
  1871. /* */
  1872. // wrapper function for providing a more flexible interface
  1873. // without getting yelled at by flow
  1874. function createElement (
  1875. tag,
  1876. data,
  1877. children
  1878. ) {
  1879. if (data && (Array.isArray(data) || typeof data !== 'object')) {
  1880. children = data
  1881. data = undefined
  1882. }
  1883. // make sure to use real instance instead of proxy as context
  1884. return _createElement(this._self, tag, data, children)
  1885. }
  1886. function _createElement (
  1887. context,
  1888. tag,
  1889. data,
  1890. children
  1891. ) {
  1892. if (data && data.__ob__) {
  1893. process.env.NODE_ENV !== 'production' && warn(
  1894. "Avoid using observed data object as vnode data: " + (JSON.stringify(data)) + "\n" +
  1895. 'Always create fresh vnode data objects in each render!',
  1896. context
  1897. )
  1898. return
  1899. }
  1900. if (!tag) {
  1901. // in case of component :is set to falsy value
  1902. return emptyVNode()
  1903. }
  1904. if (typeof tag === 'string') {
  1905. var Ctor
  1906. var ns = config.getTagNamespace(tag)
  1907. if (config.isReservedTag(tag)) {
  1908. // platform built-in elements
  1909. return new VNode(
  1910. tag, data, normalizeChildren(children, ns),
  1911. undefined, undefined, ns, context
  1912. )
  1913. } else if ((Ctor = resolveAsset(context.$options, 'components', tag))) {
  1914. // component
  1915. return createComponent(Ctor, data, context, children, tag)
  1916. } else {
  1917. // unknown or unlisted namespaced elements
  1918. // check at runtime because it may get assigned a namespace when its
  1919. // parent normalizes children
  1920. return new VNode(
  1921. tag, data, normalizeChildren(children, ns),
  1922. undefined, undefined, ns, context
  1923. )
  1924. }
  1925. } else {
  1926. // direct component options / constructor
  1927. return createComponent(tag, data, context, children)
  1928. }
  1929. }
  1930. /* */
  1931. function initRender (vm) {
  1932. vm.$vnode = null // the placeholder node in parent tree
  1933. vm._vnode = null // the root of the child tree
  1934. vm._staticTrees = null
  1935. vm.$slots = resolveSlots(vm.$options._renderChildren)
  1936. // bind the public createElement fn to this instance
  1937. // so that we get proper render context inside it.
  1938. vm.$createElement = bind(createElement, vm)
  1939. if (vm.$options.el) {
  1940. vm.$mount(vm.$options.el)
  1941. }
  1942. }
  1943. function renderMixin (Vue) {
  1944. Vue.prototype.$nextTick = function (fn) {
  1945. nextTick(fn, this)
  1946. }
  1947. Vue.prototype._render = function () {
  1948. var vm = this
  1949. var ref = vm.$options;
  1950. var render = ref.render;
  1951. var staticRenderFns = ref.staticRenderFns;
  1952. var _parentVnode = ref._parentVnode;
  1953. if (vm._isMounted) {
  1954. // clone slot nodes on re-renders
  1955. for (var key in vm.$slots) {
  1956. vm.$slots[key] = cloneVNodes(vm.$slots[key])
  1957. }
  1958. }
  1959. if (staticRenderFns && !vm._staticTrees) {
  1960. vm._staticTrees = []
  1961. }
  1962. // set parent vnode. this allows render functions to have access
  1963. // to the data on the placeholder node.
  1964. vm.$vnode = _parentVnode
  1965. // render self
  1966. var vnode
  1967. try {
  1968. vnode = render.call(vm._renderProxy, vm.$createElement)
  1969. } catch (e) {
  1970. if (process.env.NODE_ENV !== 'production') {
  1971. warn(("Error when rendering " + (formatComponentName(vm)) + ":"))
  1972. }
  1973. /* istanbul ignore else */
  1974. if (config.errorHandler) {
  1975. config.errorHandler.call(null, e, vm)
  1976. } else {
  1977. if (config._isServer) {
  1978. throw e
  1979. } else {
  1980. setTimeout(function () { throw e }, 0)
  1981. }
  1982. }
  1983. // return previous vnode to prevent render error causing blank component
  1984. vnode = vm._vnode
  1985. }
  1986. // return empty vnode in case the render function errored out
  1987. if (!(vnode instanceof VNode)) {
  1988. if (process.env.NODE_ENV !== 'production' && Array.isArray(vnode)) {
  1989. warn(
  1990. 'Multiple root nodes returned from render function. Render function ' +
  1991. 'should return a single root node.',
  1992. vm
  1993. )
  1994. }
  1995. vnode = emptyVNode()
  1996. }
  1997. // set parent
  1998. vnode.parent = _parentVnode
  1999. return vnode
  2000. }
  2001. // shorthands used in render functions
  2002. Vue.prototype._h = createElement
  2003. // toString for mustaches
  2004. Vue.prototype._s = _toString
  2005. // number conversion
  2006. Vue.prototype._n = toNumber
  2007. // empty vnode
  2008. Vue.prototype._e = emptyVNode
  2009. // render static tree by index
  2010. Vue.prototype._m = function renderStatic (
  2011. index,
  2012. isInFor
  2013. ) {
  2014. var tree = this._staticTrees[index]
  2015. // if has already-rendered static tree and not inside v-for,
  2016. // we can reuse the same tree by doing a shallow clone.
  2017. if (tree && !isInFor) {
  2018. return Array.isArray(tree)
  2019. ? cloneVNodes(tree)
  2020. : cloneVNode(tree)
  2021. }
  2022. // otherwise, render a fresh tree.
  2023. tree = this._staticTrees[index] = this.$options.staticRenderFns[index].call(this._renderProxy)
  2024. if (Array.isArray(tree)) {
  2025. for (var i = 0; i < tree.length; i++) {
  2026. tree[i].isStatic = true
  2027. tree[i].key = "__static__" + index + "_" + i
  2028. }
  2029. } else {
  2030. tree.isStatic = true
  2031. tree.key = "__static__" + index
  2032. }
  2033. return tree
  2034. }
  2035. // filter resolution helper
  2036. var identity = function (_) { return _; }
  2037. Vue.prototype._f = function resolveFilter (id) {
  2038. return resolveAsset(this.$options, 'filters', id, true) || identity
  2039. }
  2040. // render v-for
  2041. Vue.prototype._l = function renderList (
  2042. val,
  2043. render
  2044. ) {
  2045. var ret, i, l, keys, key
  2046. if (Array.isArray(val)) {
  2047. ret = new Array(val.length)
  2048. for (i = 0, l = val.length; i < l; i++) {
  2049. ret[i] = render(val[i], i)
  2050. }
  2051. } else if (typeof val === 'number') {
  2052. ret = new Array(val)
  2053. for (i = 0; i < val; i++) {
  2054. ret[i] = render(i + 1, i)
  2055. }
  2056. } else if (isObject(val)) {
  2057. keys = Object.keys(val)
  2058. ret = new Array(keys.length)
  2059. for (i = 0, l = keys.length; i < l; i++) {
  2060. key = keys[i]
  2061. ret[i] = render(val[key], key, i)
  2062. }
  2063. }
  2064. return ret
  2065. }
  2066. // apply v-bind object
  2067. Vue.prototype._b = function bindProps (
  2068. vnode,
  2069. value,
  2070. asProp) {
  2071. if (value) {
  2072. if (!isObject(value)) {
  2073. process.env.NODE_ENV !== 'production' && warn(
  2074. 'v-bind without argument expects an Object or Array value',
  2075. this
  2076. )
  2077. } else {
  2078. if (Array.isArray(value)) {
  2079. value = toObject(value)
  2080. }
  2081. var data = vnode.data
  2082. for (var key in value) {
  2083. if (key === 'class' || key === 'style') {
  2084. data[key] = value[key]
  2085. } else {
  2086. var hash = asProp || config.mustUseProp(key)
  2087. ? data.domProps || (data.domProps = {})
  2088. : data.attrs || (data.attrs = {})
  2089. hash[key] = value[key]
  2090. }
  2091. }
  2092. }
  2093. }
  2094. }
  2095. // expose v-on keyCodes
  2096. Vue.prototype._k = function getKeyCodes (key) {
  2097. return config.keyCodes[key]
  2098. }
  2099. }
  2100. function resolveSlots (
  2101. renderChildren
  2102. ) {
  2103. var slots = {}
  2104. if (!renderChildren) {
  2105. return slots
  2106. }
  2107. var children = normalizeChildren(renderChildren) || []
  2108. var defaultSlot = []
  2109. var name, child
  2110. for (var i = 0, l = children.length; i < l; i++) {
  2111. child = children[i]
  2112. if (child.data && (name = child.data.slot)) {
  2113. delete child.data.slot
  2114. var slot = (slots[name] || (slots[name] = []))
  2115. if (child.tag === 'template') {
  2116. slot.push.apply(slot, child.children)
  2117. } else {
  2118. slot.push(child)
  2119. }
  2120. } else {
  2121. defaultSlot.push(child)
  2122. }
  2123. }
  2124. // ignore single whitespace
  2125. if (defaultSlot.length && !(
  2126. defaultSlot.length === 1 &&
  2127. (defaultSlot[0].text === ' ' || defaultSlot[0].isComment)
  2128. )) {
  2129. slots.default = defaultSlot
  2130. }
  2131. return slots
  2132. }
  2133. /* */
  2134. function initEvents (vm) {
  2135. vm._events = Object.create(null)
  2136. // init parent attached events
  2137. var listeners = vm.$options._parentListeners
  2138. var on = bind(vm.$on, vm)
  2139. var off = bind(vm.$off, vm)
  2140. vm._updateListeners = function (listeners, oldListeners) {
  2141. updateListeners(listeners, oldListeners || {}, on, off)
  2142. }
  2143. if (listeners) {
  2144. vm._updateListeners(listeners)
  2145. }
  2146. }
  2147. function eventsMixin (Vue) {
  2148. Vue.prototype.$on = function (event, fn) {
  2149. var vm = this
  2150. ;(vm._events[event] || (vm._events[event] = [])).push(fn)
  2151. return vm
  2152. }
  2153. Vue.prototype.$once = function (event, fn) {
  2154. var vm = this
  2155. function on () {
  2156. vm.$off(event, on)
  2157. fn.apply(vm, arguments)
  2158. }
  2159. on.fn = fn
  2160. vm.$on(event, on)
  2161. return vm
  2162. }
  2163. Vue.prototype.$off = function (event, fn) {
  2164. var vm = this
  2165. // all
  2166. if (!arguments.length) {
  2167. vm._events = Object.create(null)
  2168. return vm
  2169. }
  2170. // specific event
  2171. var cbs = vm._events[event]
  2172. if (!cbs) {
  2173. return vm
  2174. }
  2175. if (arguments.length === 1) {
  2176. vm._events[event] = null
  2177. return vm
  2178. }
  2179. // specific handler
  2180. var cb
  2181. var i = cbs.length
  2182. while (i--) {
  2183. cb = cbs[i]
  2184. if (cb === fn || cb.fn === fn) {
  2185. cbs.splice(i, 1)
  2186. break
  2187. }
  2188. }
  2189. return vm
  2190. }
  2191. Vue.prototype.$emit = function (event) {
  2192. var vm = this
  2193. var cbs = vm._events[event]
  2194. if (cbs) {
  2195. cbs = cbs.length > 1 ? toArray(cbs) : cbs
  2196. var args = toArray(arguments, 1)
  2197. for (var i = 0, l = cbs.length; i < l; i++) {
  2198. cbs[i].apply(vm, args)
  2199. }
  2200. }
  2201. return vm
  2202. }
  2203. }
  2204. /* */
  2205. var uid = 0
  2206. function initMixin (Vue) {
  2207. Vue.prototype._init = function (options) {
  2208. var vm = this
  2209. // a uid
  2210. vm._uid = uid++
  2211. // a flag to avoid this being observed
  2212. vm._isVue = true
  2213. // merge options
  2214. if (options && options._isComponent) {
  2215. // optimize internal component instantiation
  2216. // since dynamic options merging is pretty slow, and none of the
  2217. // internal component options needs special treatment.
  2218. initInternalComponent(vm, options)
  2219. } else {
  2220. vm.$options = mergeOptions(
  2221. resolveConstructorOptions(vm),
  2222. options || {},
  2223. vm
  2224. )
  2225. }
  2226. /* istanbul ignore else */
  2227. if (process.env.NODE_ENV !== 'production') {
  2228. initProxy(vm)
  2229. } else {
  2230. vm._renderProxy = vm
  2231. }
  2232. // expose real self
  2233. vm._self = vm
  2234. initLifecycle(vm)
  2235. initEvents(vm)
  2236. callHook(vm, 'beforeCreate')
  2237. initState(vm)
  2238. callHook(vm, 'created')
  2239. initRender(vm)
  2240. }
  2241. function initInternalComponent (vm, options) {
  2242. var opts = vm.$options = Object.create(resolveConstructorOptions(vm))
  2243. // doing this because it's faster than dynamic enumeration.
  2244. opts.parent = options.parent
  2245. opts.propsData = options.propsData
  2246. opts._parentVnode = options._parentVnode
  2247. opts._parentListeners = options._parentListeners
  2248. opts._renderChildren = options._renderChildren
  2249. opts._componentTag = options._componentTag
  2250. if (options.render) {
  2251. opts.render = options.render
  2252. opts.staticRenderFns = options.staticRenderFns
  2253. }
  2254. }
  2255. function resolveConstructorOptions (vm) {
  2256. var Ctor = vm.constructor
  2257. var options = Ctor.options
  2258. if (Ctor.super) {
  2259. var superOptions = Ctor.super.options
  2260. var cachedSuperOptions = Ctor.superOptions
  2261. if (superOptions !== cachedSuperOptions) {
  2262. // super option changed
  2263. Ctor.superOptions = superOptions
  2264. options = Ctor.options = mergeOptions(superOptions, Ctor.extendOptions)
  2265. if (options.name) {
  2266. options.components[options.name] = Ctor
  2267. }
  2268. }
  2269. }
  2270. return options
  2271. }
  2272. }
  2273. function Vue (options) {
  2274. this._init(options)
  2275. }
  2276. initMixin(Vue)
  2277. stateMixin(Vue)
  2278. eventsMixin(Vue)
  2279. lifecycleMixin(Vue)
  2280. renderMixin(Vue)
  2281. var warn
  2282. var formatComponentName
  2283. if (process.env.NODE_ENV !== 'production') {
  2284. var hasConsole = typeof console !== 'undefined'
  2285. warn = function (msg, vm) {
  2286. if (hasConsole && (!config.silent)) {
  2287. console.error("[Vue warn]: " + msg + " " + (
  2288. vm ? formatLocation(formatComponentName(vm)) : ''
  2289. ))
  2290. }
  2291. }
  2292. formatComponentName = function (vm) {
  2293. if (vm.$root === vm) {
  2294. return 'root instance'
  2295. }
  2296. var name = vm._isVue
  2297. ? vm.$options.name || vm.$options._componentTag
  2298. : vm.name
  2299. return name ? ("component <" + name + ">") : "anonymous component"
  2300. }
  2301. var formatLocation = function (str) {
  2302. if (str === 'anonymous component') {
  2303. str += " - use the \"name\" option for better debugging messages."
  2304. }
  2305. return ("(found in " + str + ")")
  2306. }
  2307. }
  2308. /* */
  2309. /**
  2310. * Option overwriting strategies are functions that handle
  2311. * how to merge a parent option value and a child option
  2312. * value into the final value.
  2313. */
  2314. var strats = config.optionMergeStrategies
  2315. /**
  2316. * Options with restrictions
  2317. */
  2318. if (process.env.NODE_ENV !== 'production') {
  2319. strats.el = strats.propsData = function (parent, child, vm, key) {
  2320. if (!vm) {
  2321. warn(
  2322. "option \"" + key + "\" can only be used during instance " +
  2323. 'creation with the `new` keyword.'
  2324. )
  2325. }
  2326. return defaultStrat(parent, child)
  2327. }
  2328. strats.name = function (parent, child, vm) {
  2329. if (vm && child) {
  2330. warn(
  2331. 'options "name" can only be used as a component definition option, ' +
  2332. 'not during instance creation.'
  2333. )
  2334. }
  2335. return defaultStrat(parent, child)
  2336. }
  2337. }
  2338. /**
  2339. * Helper that recursively merges two data objects together.
  2340. */
  2341. function mergeData (to, from) {
  2342. var key, toVal, fromVal
  2343. for (key in from) {
  2344. toVal = to[key]
  2345. fromVal = from[key]
  2346. if (!hasOwn(to, key)) {
  2347. set(to, key, fromVal)
  2348. } else if (isObject(toVal) && isObject(fromVal)) {
  2349. mergeData(toVal, fromVal)
  2350. }
  2351. }
  2352. return to
  2353. }
  2354. /**
  2355. * Data
  2356. */
  2357. strats.data = function (
  2358. parentVal,
  2359. childVal,
  2360. vm
  2361. ) {
  2362. if (!vm) {
  2363. // in a Vue.extend merge, both should be functions
  2364. if (!childVal) {
  2365. return parentVal
  2366. }
  2367. if (typeof childVal !== 'function') {
  2368. process.env.NODE_ENV !== 'production' && warn(
  2369. 'The "data" option should be a function ' +
  2370. 'that returns a per-instance value in component ' +
  2371. 'definitions.',
  2372. vm
  2373. )
  2374. return parentVal
  2375. }
  2376. if (!parentVal) {
  2377. return childVal
  2378. }
  2379. // when parentVal & childVal are both present,
  2380. // we need to return a function that returns the
  2381. // merged result of both functions... no need to
  2382. // check if parentVal is a function here because
  2383. // it has to be a function to pass previous merges.
  2384. return function mergedDataFn () {
  2385. return mergeData(
  2386. childVal.call(this),
  2387. parentVal.call(this)
  2388. )
  2389. }
  2390. } else if (parentVal || childVal) {
  2391. return function mergedInstanceDataFn () {
  2392. // instance merge
  2393. var instanceData = typeof childVal === 'function'
  2394. ? childVal.call(vm)
  2395. : childVal
  2396. var defaultData = typeof parentVal === 'function'
  2397. ? parentVal.call(vm)
  2398. : undefined
  2399. if (instanceData) {
  2400. return mergeData(instanceData, defaultData)
  2401. } else {
  2402. return defaultData
  2403. }
  2404. }
  2405. }
  2406. }
  2407. /**
  2408. * Hooks and param attributes are merged as arrays.
  2409. */
  2410. function mergeHook (
  2411. parentVal,
  2412. childVal
  2413. ) {
  2414. return childVal
  2415. ? parentVal
  2416. ? parentVal.concat(childVal)
  2417. : Array.isArray(childVal)
  2418. ? childVal
  2419. : [childVal]
  2420. : parentVal
  2421. }
  2422. config._lifecycleHooks.forEach(function (hook) {
  2423. strats[hook] = mergeHook
  2424. })
  2425. /**
  2426. * Assets
  2427. *
  2428. * When a vm is present (instance creation), we need to do
  2429. * a three-way merge between constructor options, instance
  2430. * options and parent options.
  2431. */
  2432. function mergeAssets (parentVal, childVal) {
  2433. var res = Object.create(parentVal || null)
  2434. return childVal
  2435. ? extend(res, childVal)
  2436. : res
  2437. }
  2438. config._assetTypes.forEach(function (type) {
  2439. strats[type + 's'] = mergeAssets
  2440. })
  2441. /**
  2442. * Watchers.
  2443. *
  2444. * Watchers hashes should not overwrite one
  2445. * another, so we merge them as arrays.
  2446. */
  2447. strats.watch = function (parentVal, childVal) {
  2448. /* istanbul ignore if */
  2449. if (!childVal) return parentVal
  2450. if (!parentVal) return childVal
  2451. var ret = {}
  2452. extend(ret, parentVal)
  2453. for (var key in childVal) {
  2454. var parent = ret[key]
  2455. var child = childVal[key]
  2456. if (parent && !Array.isArray(parent)) {
  2457. parent = [parent]
  2458. }
  2459. ret[key] = parent
  2460. ? parent.concat(child)
  2461. : [child]
  2462. }
  2463. return ret
  2464. }
  2465. /**
  2466. * Other object hashes.
  2467. */
  2468. strats.props =
  2469. strats.methods =
  2470. strats.computed = function (parentVal, childVal) {
  2471. if (!childVal) return parentVal
  2472. if (!parentVal) return childVal
  2473. var ret = Object.create(null)
  2474. extend(ret, parentVal)
  2475. extend(ret, childVal)
  2476. return ret
  2477. }
  2478. /**
  2479. * Default strategy.
  2480. */
  2481. var defaultStrat = function (parentVal, childVal) {
  2482. return childVal === undefined
  2483. ? parentVal
  2484. : childVal
  2485. }
  2486. /**
  2487. * Make sure component options get converted to actual
  2488. * constructors.
  2489. */
  2490. function normalizeComponents (options) {
  2491. if (options.components) {
  2492. var components = options.components
  2493. var def
  2494. for (var key in components) {
  2495. var lower = key.toLowerCase()
  2496. if (isBuiltInTag(lower) || config.isReservedTag(lower)) {
  2497. process.env.NODE_ENV !== 'production' && warn(
  2498. 'Do not use built-in or reserved HTML elements as component ' +
  2499. 'id: ' + key
  2500. )
  2501. continue
  2502. }
  2503. def = components[key]
  2504. if (isPlainObject(def)) {
  2505. components[key] = Vue.extend(def)
  2506. }
  2507. }
  2508. }
  2509. }
  2510. /**
  2511. * Ensure all props option syntax are normalized into the
  2512. * Object-based format.
  2513. */
  2514. function normalizeProps (options) {
  2515. var props = options.props
  2516. if (!props) return
  2517. var res = {}
  2518. var i, val, name
  2519. if (Array.isArray(props)) {
  2520. i = props.length
  2521. while (i--) {
  2522. val = props[i]
  2523. if (typeof val === 'string') {
  2524. name = camelize(val)
  2525. res[name] = { type: null }
  2526. } else if (process.env.NODE_ENV !== 'production') {
  2527. warn('props must be strings when using array syntax.')
  2528. }
  2529. }
  2530. } else if (isPlainObject(props)) {
  2531. for (var key in props) {
  2532. val = props[key]
  2533. name = camelize(key)
  2534. res[name] = isPlainObject(val)
  2535. ? val
  2536. : { type: val }
  2537. }
  2538. }
  2539. options.props = res
  2540. }
  2541. /**
  2542. * Normalize raw function directives into object format.
  2543. */
  2544. function normalizeDirectives (options) {
  2545. var dirs = options.directives
  2546. if (dirs) {
  2547. for (var key in dirs) {
  2548. var def = dirs[key]
  2549. if (typeof def === 'function') {
  2550. dirs[key] = { bind: def, update: def }
  2551. }
  2552. }
  2553. }
  2554. }
  2555. /**
  2556. * Merge two option objects into a new one.
  2557. * Core utility used in both instantiation and inheritance.
  2558. */
  2559. function mergeOptions (
  2560. parent,
  2561. child,
  2562. vm
  2563. ) {
  2564. normalizeComponents(child)
  2565. normalizeProps(child)
  2566. normalizeDirectives(child)
  2567. var extendsFrom = child.extends
  2568. if (extendsFrom) {
  2569. parent = typeof extendsFrom === 'function'
  2570. ? mergeOptions(parent, extendsFrom.options, vm)
  2571. : mergeOptions(parent, extendsFrom, vm)
  2572. }
  2573. if (child.mixins) {
  2574. for (var i = 0, l = child.mixins.length; i < l; i++) {
  2575. var mixin = child.mixins[i]
  2576. if (mixin.prototype instanceof Vue) {
  2577. mixin = mixin.options
  2578. }
  2579. parent = mergeOptions(parent, mixin, vm)
  2580. }
  2581. }
  2582. var options = {}
  2583. var key
  2584. for (key in parent) {
  2585. mergeField(key)
  2586. }
  2587. for (key in child) {
  2588. if (!hasOwn(parent, key)) {
  2589. mergeField(key)
  2590. }
  2591. }
  2592. function mergeField (key) {
  2593. var strat = strats[key] || defaultStrat
  2594. options[key] = strat(parent[key], child[key], vm, key)
  2595. }
  2596. return options
  2597. }
  2598. /**
  2599. * Resolve an asset.
  2600. * This function is used because child instances need access
  2601. * to assets defined in its ancestor chain.
  2602. */
  2603. function resolveAsset (
  2604. options,
  2605. type,
  2606. id,
  2607. warnMissing
  2608. ) {
  2609. /* istanbul ignore if */
  2610. if (typeof id !== 'string') {
  2611. return
  2612. }
  2613. var assets = options[type]
  2614. var res = assets[id] ||
  2615. // camelCase ID
  2616. assets[camelize(id)] ||
  2617. // Pascal Case ID
  2618. assets[capitalize(camelize(id))]
  2619. if (process.env.NODE_ENV !== 'production' && warnMissing && !res) {
  2620. warn(
  2621. 'Failed to resolve ' + type.slice(0, -1) + ': ' + id,
  2622. options
  2623. )
  2624. }
  2625. return res
  2626. }
  2627. /* */
  2628. function validateProp (
  2629. key,
  2630. propOptions,
  2631. propsData,
  2632. vm
  2633. ) {
  2634. /* istanbul ignore if */
  2635. if (!propsData) return
  2636. var prop = propOptions[key]
  2637. var absent = !hasOwn(propsData, key)
  2638. var value = propsData[key]
  2639. // handle boolean props
  2640. if (getType(prop.type) === 'Boolean') {
  2641. if (absent && !hasOwn(prop, 'default')) {
  2642. value = false
  2643. } else if (value === '' || value === hyphenate(key)) {
  2644. value = true
  2645. }
  2646. }
  2647. // check default value
  2648. if (value === undefined) {
  2649. value = getPropDefaultValue(vm, prop, key)
  2650. // since the default value is a fresh copy,
  2651. // make sure to observe it.
  2652. var prevShouldConvert = observerState.shouldConvert
  2653. observerState.shouldConvert = true
  2654. observe(value)
  2655. observerState.shouldConvert = prevShouldConvert
  2656. }
  2657. if (process.env.NODE_ENV !== 'production') {
  2658. assertProp(prop, key, value, vm, absent)
  2659. }
  2660. return value
  2661. }
  2662. /**
  2663. * Get the default value of a prop.
  2664. */
  2665. function getPropDefaultValue (vm, prop, name) {
  2666. // no default, return undefined
  2667. if (!hasOwn(prop, 'default')) {
  2668. return undefined
  2669. }
  2670. var def = prop.default
  2671. // warn against non-factory defaults for Object & Array
  2672. if (isObject(def)) {
  2673. process.env.NODE_ENV !== 'production' && warn(
  2674. 'Invalid default value for prop "' + name + '": ' +
  2675. 'Props with type Object/Array must use a factory function ' +
  2676. 'to return the default value.',
  2677. vm
  2678. )
  2679. }
  2680. // call factory function for non-Function types
  2681. return typeof def === 'function' && prop.type !== Function
  2682. ? def.call(vm)
  2683. : def
  2684. }
  2685. /**
  2686. * Assert whether a prop is valid.
  2687. */
  2688. function assertProp (
  2689. prop,
  2690. name,
  2691. value,
  2692. vm,
  2693. absent
  2694. ) {
  2695. if (prop.required && absent) {
  2696. warn(
  2697. 'Missing required prop: "' + name + '"',
  2698. vm
  2699. )
  2700. return
  2701. }
  2702. if (value == null && !prop.required) {
  2703. return
  2704. }
  2705. var type = prop.type
  2706. var valid = !type
  2707. var expectedTypes = []
  2708. if (type) {
  2709. if (!Array.isArray(type)) {
  2710. type = [type]
  2711. }
  2712. for (var i = 0; i < type.length && !valid; i++) {
  2713. var assertedType = assertType(value, type[i])
  2714. expectedTypes.push(assertedType.expectedType)
  2715. valid = assertedType.valid
  2716. }
  2717. }
  2718. if (!valid) {
  2719. warn(
  2720. 'Invalid prop: type check failed for prop "' + name + '".' +
  2721. ' Expected ' + expectedTypes.map(capitalize).join(', ') +
  2722. ', got ' + Object.prototype.toString.call(value).slice(8, -1) + '.',
  2723. vm
  2724. )
  2725. return
  2726. }
  2727. var validator = prop.validator
  2728. if (validator) {
  2729. if (!validator(value)) {
  2730. warn(
  2731. 'Invalid prop: custom validator check failed for prop "' + name + '".',
  2732. vm
  2733. )
  2734. }
  2735. }
  2736. }
  2737. /**
  2738. * Assert the type of a value
  2739. */
  2740. function assertType (value, type) {
  2741. var valid
  2742. var expectedType = getType(type)
  2743. if (expectedType === 'String') {
  2744. valid = typeof value === (expectedType = 'string')
  2745. } else if (expectedType === 'Number') {
  2746. valid = typeof value === (expectedType = 'number')
  2747. } else if (expectedType === 'Boolean') {
  2748. valid = typeof value === (expectedType = 'boolean')
  2749. } else if (expectedType === 'Function') {
  2750. valid = typeof value === (expectedType = 'function')
  2751. } else if (expectedType === 'Object') {
  2752. valid = isPlainObject(value)
  2753. } else if (expectedType === 'Array') {
  2754. valid = Array.isArray(value)
  2755. } else {
  2756. valid = value instanceof type
  2757. }
  2758. return {
  2759. valid: valid,
  2760. expectedType: expectedType
  2761. }
  2762. }
  2763. /**
  2764. * Use function string name to check built-in types,
  2765. * because a simple equality check will fail when running
  2766. * across different vms / iframes.
  2767. */
  2768. function getType (fn) {
  2769. var match = fn && fn.toString().match(/^\s*function (\w+)/)
  2770. return match && match[1]
  2771. }
  2772. var util = Object.freeze({
  2773. defineReactive: defineReactive,
  2774. _toString: _toString,
  2775. toNumber: toNumber,
  2776. makeMap: makeMap,
  2777. isBuiltInTag: isBuiltInTag,
  2778. remove: remove,
  2779. hasOwn: hasOwn,
  2780. isPrimitive: isPrimitive,
  2781. cached: cached,
  2782. camelize: camelize,
  2783. capitalize: capitalize,
  2784. hyphenate: hyphenate,
  2785. bind: bind,
  2786. toArray: toArray,
  2787. extend: extend,
  2788. isObject: isObject,
  2789. isPlainObject: isPlainObject,
  2790. toObject: toObject,
  2791. noop: noop,
  2792. no: no,
  2793. genStaticKeys: genStaticKeys,
  2794. isReserved: isReserved,
  2795. def: def,
  2796. parsePath: parsePath,
  2797. hasProto: hasProto,
  2798. inBrowser: inBrowser,
  2799. devtools: devtools,
  2800. UA: UA,
  2801. nextTick: nextTick,
  2802. get _Set () { return _Set; },
  2803. mergeOptions: mergeOptions,
  2804. resolveAsset: resolveAsset,
  2805. get warn () { return warn; },
  2806. get formatComponentName () { return formatComponentName; },
  2807. validateProp: validateProp
  2808. });
  2809. /* */
  2810. function initUse (Vue) {
  2811. Vue.use = function (plugin) {
  2812. /* istanbul ignore if */
  2813. if (plugin.installed) {
  2814. return
  2815. }
  2816. // additional parameters
  2817. var args = toArray(arguments, 1)
  2818. args.unshift(this)
  2819. if (typeof plugin.install === 'function') {
  2820. plugin.install.apply(plugin, args)
  2821. } else {
  2822. plugin.apply(null, args)
  2823. }
  2824. plugin.installed = true
  2825. return this
  2826. }
  2827. }
  2828. /* */
  2829. function initMixin$1 (Vue) {
  2830. Vue.mixin = function (mixin) {
  2831. Vue.options = mergeOptions(Vue.options, mixin)
  2832. }
  2833. }
  2834. /* */
  2835. function initExtend (Vue) {
  2836. /**
  2837. * Each instance constructor, including Vue, has a unique
  2838. * cid. This enables us to create wrapped "child
  2839. * constructors" for prototypal inheritance and cache them.
  2840. */
  2841. Vue.cid = 0
  2842. var cid = 1
  2843. /**
  2844. * Class inheritance
  2845. */
  2846. Vue.extend = function (extendOptions) {
  2847. extendOptions = extendOptions || {}
  2848. var Super = this
  2849. var isFirstExtend = Super.cid === 0
  2850. if (isFirstExtend && extendOptions._Ctor) {
  2851. return extendOptions._Ctor
  2852. }
  2853. var name = extendOptions.name || Super.options.name
  2854. if (process.env.NODE_ENV !== 'production') {
  2855. if (!/^[a-zA-Z][\w-]*$/.test(name)) {
  2856. warn(
  2857. 'Invalid component name: "' + name + '". Component names ' +
  2858. 'can only contain alphanumeric characaters and the hyphen.'
  2859. )
  2860. name = null
  2861. }
  2862. }
  2863. var Sub = function VueComponent (options) {
  2864. this._init(options)
  2865. }
  2866. Sub.prototype = Object.create(Super.prototype)
  2867. Sub.prototype.constructor = Sub
  2868. Sub.cid = cid++
  2869. Sub.options = mergeOptions(
  2870. Super.options,
  2871. extendOptions
  2872. )
  2873. Sub['super'] = Super
  2874. // allow further extension
  2875. Sub.extend = Super.extend
  2876. // create asset registers, so extended classes
  2877. // can have their private assets too.
  2878. config._assetTypes.forEach(function (type) {
  2879. Sub[type] = Super[type]
  2880. })
  2881. // enable recursive self-lookup
  2882. if (name) {
  2883. Sub.options.components[name] = Sub
  2884. }
  2885. // keep a reference to the super options at extension time.
  2886. // later at instantiation we can check if Super's options have
  2887. // been updated.
  2888. Sub.superOptions = Super.options
  2889. Sub.extendOptions = extendOptions
  2890. // cache constructor
  2891. if (isFirstExtend) {
  2892. extendOptions._Ctor = Sub
  2893. }
  2894. return Sub
  2895. }
  2896. }
  2897. /* */
  2898. function initAssetRegisters (Vue) {
  2899. /**
  2900. * Create asset registration methods.
  2901. */
  2902. config._assetTypes.forEach(function (type) {
  2903. Vue[type] = function (
  2904. id,
  2905. definition
  2906. ) {
  2907. if (!definition) {
  2908. return this.options[type + 's'][id]
  2909. } else {
  2910. /* istanbul ignore if */
  2911. if (process.env.NODE_ENV !== 'production') {
  2912. if (type === 'component' && config.isReservedTag(id)) {
  2913. warn(
  2914. 'Do not use built-in or reserved HTML elements as component ' +
  2915. 'id: ' + id
  2916. )
  2917. }
  2918. }
  2919. if (type === 'component' && isPlainObject(definition)) {
  2920. definition.name = definition.name || id
  2921. definition = Vue.extend(definition)
  2922. }
  2923. if (type === 'directive' && typeof definition === 'function') {
  2924. definition = { bind: definition, update: definition }
  2925. }
  2926. this.options[type + 's'][id] = definition
  2927. return definition
  2928. }
  2929. }
  2930. })
  2931. }
  2932. var KeepAlive = {
  2933. name: 'keep-alive',
  2934. abstract: true,
  2935. created: function created () {
  2936. this.cache = Object.create(null)
  2937. },
  2938. render: function render () {
  2939. var vnode = getFirstComponentChild(this.$slots.default)
  2940. if (vnode && vnode.componentOptions) {
  2941. var opts = vnode.componentOptions
  2942. var key = vnode.key == null
  2943. // same constructor may get registered as different local components
  2944. // so cid alone is not enough (#3269)
  2945. ? opts.Ctor.cid + '::' + opts.tag
  2946. : vnode.key
  2947. if (this.cache[key]) {
  2948. vnode.child = this.cache[key].child
  2949. } else {
  2950. this.cache[key] = vnode
  2951. }
  2952. vnode.data.keepAlive = true
  2953. }
  2954. return vnode
  2955. },
  2956. destroyed: function destroyed () {
  2957. var this$1 = this;
  2958. for (var key in this.cache) {
  2959. var vnode = this$1.cache[key]
  2960. callHook(vnode.child, 'deactivated')
  2961. vnode.child.$destroy()
  2962. }
  2963. }
  2964. }
  2965. var builtInComponents = {
  2966. KeepAlive: KeepAlive
  2967. }
  2968. /* */
  2969. function initGlobalAPI (Vue) {
  2970. // config
  2971. var configDef = {}
  2972. configDef.get = function () { return config; }
  2973. if (process.env.NODE_ENV !== 'production') {
  2974. configDef.set = function () {
  2975. warn(
  2976. 'Do not replace the Vue.config object, set individual fields instead.'
  2977. )
  2978. }
  2979. }
  2980. Object.defineProperty(Vue, 'config', configDef)
  2981. Vue.util = util
  2982. Vue.set = set
  2983. Vue.delete = del
  2984. Vue.nextTick = nextTick
  2985. Vue.options = Object.create(null)
  2986. config._assetTypes.forEach(function (type) {
  2987. Vue.options[type + 's'] = Object.create(null)
  2988. })
  2989. extend(Vue.options.components, builtInComponents)
  2990. initUse(Vue)
  2991. initMixin$1(Vue)
  2992. initExtend(Vue)
  2993. initAssetRegisters(Vue)
  2994. }
  2995. initGlobalAPI(Vue)
  2996. Object.defineProperty(Vue.prototype, '$isServer', {
  2997. get: function () { return config._isServer; }
  2998. })
  2999. Vue.version = '2.0.0-rc.4'
  3000. /* */
  3001. // attributes that should be using props for binding
  3002. var mustUseProp = makeMap('value,selected,checked,muted')
  3003. var isEnumeratedAttr = makeMap('contenteditable,draggable,spellcheck')
  3004. var isBooleanAttr = makeMap(
  3005. 'allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,' +
  3006. 'default,defaultchecked,defaultmuted,defaultselected,defer,disabled,' +
  3007. 'enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,' +
  3008. 'muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,' +
  3009. 'required,reversed,scoped,seamless,selected,sortable,translate,' +
  3010. 'truespeed,typemustmatch,visible'
  3011. )
  3012. var isAttr = makeMap(
  3013. 'accept,accept-charset,accesskey,action,align,alt,async,autocomplete,' +
  3014. 'autofocus,autoplay,autosave,bgcolor,border,buffered,challenge,charset,' +
  3015. 'checked,cite,class,code,codebase,color,cols,colspan,content,http-equiv,' +
  3016. 'name,contenteditable,contextmenu,controls,coords,data,datetime,default,' +
  3017. 'defer,dir,dirname,disabled,download,draggable,dropzone,enctype,method,for,' +
  3018. 'form,formaction,headers,<th>,height,hidden,high,href,hreflang,http-equiv,' +
  3019. 'icon,id,ismap,itemprop,keytype,kind,label,lang,language,list,loop,low,' +
  3020. 'manifest,max,maxlength,media,method,GET,POST,min,multiple,email,file,' +
  3021. 'muted,name,novalidate,open,optimum,pattern,ping,placeholder,poster,' +
  3022. 'preload,radiogroup,readonly,rel,required,reversed,rows,rowspan,sandbox,' +
  3023. 'scope,scoped,seamless,selected,shape,size,type,text,password,sizes,span,' +
  3024. 'spellcheck,src,srcdoc,srclang,srcset,start,step,style,summary,tabindex,' +
  3025. 'target,title,type,usemap,value,width,wrap'
  3026. )
  3027. var xlinkNS = 'http://www.w3.org/1999/xlink'
  3028. var isXlink = function (name) {
  3029. return name.charAt(5) === ':' && name.slice(0, 5) === 'xlink'
  3030. }
  3031. var getXlinkProp = function (name) {
  3032. return isXlink(name) ? name.slice(6, name.length) : ''
  3033. }
  3034. var isFalsyAttrValue = function (val) {
  3035. return val == null || val === false
  3036. }
  3037. /* */
  3038. function genClassForVnode (vnode) {
  3039. var data = vnode.data
  3040. var parentNode = vnode
  3041. var childNode = vnode
  3042. while (childNode.child) {
  3043. childNode = childNode.child._vnode
  3044. if (childNode.data) {
  3045. data = mergeClassData(childNode.data, data)
  3046. }
  3047. }
  3048. while ((parentNode = parentNode.parent)) {
  3049. if (parentNode.data) {
  3050. data = mergeClassData(data, parentNode.data)
  3051. }
  3052. }
  3053. return genClassFromData(data)
  3054. }
  3055. function mergeClassData (child, parent) {
  3056. return {
  3057. staticClass: concat(child.staticClass, parent.staticClass),
  3058. class: child.class
  3059. ? [child.class, parent.class]
  3060. : parent.class
  3061. }
  3062. }
  3063. function genClassFromData (data) {
  3064. var dynamicClass = data.class
  3065. var staticClass = data.staticClass
  3066. if (staticClass || dynamicClass) {
  3067. return concat(staticClass, stringifyClass(dynamicClass))
  3068. }
  3069. /* istanbul ignore next */
  3070. return ''
  3071. }
  3072. function concat (a, b) {
  3073. return a ? b ? (a + ' ' + b) : a : (b || '')
  3074. }
  3075. function stringifyClass (value) {
  3076. var res = ''
  3077. if (!value) {
  3078. return res
  3079. }
  3080. if (typeof value === 'string') {
  3081. return value
  3082. }
  3083. if (Array.isArray(value)) {
  3084. var stringified
  3085. for (var i = 0, l = value.length; i < l; i++) {
  3086. if (value[i]) {
  3087. if ((stringified = stringifyClass(value[i]))) {
  3088. res += stringified + ' '
  3089. }
  3090. }
  3091. }
  3092. return res.slice(0, -1)
  3093. }
  3094. if (isObject(value)) {
  3095. for (var key in value) {
  3096. if (value[key]) res += key + ' '
  3097. }
  3098. return res.slice(0, -1)
  3099. }
  3100. /* istanbul ignore next */
  3101. return res
  3102. }
  3103. /* */
  3104. var namespaceMap = {
  3105. svg: 'http://www.w3.org/2000/svg',
  3106. math: 'http://www.w3.org/1998/Math/MathML'
  3107. }
  3108. var isHTMLTag = makeMap(
  3109. 'html,body,base,head,link,meta,style,title,' +
  3110. 'address,article,aside,footer,header,h1,h2,h3,h4,h5,h6,hgroup,nav,section,' +
  3111. 'div,dd,dl,dt,figcaption,figure,hr,img,li,main,ol,p,pre,ul,' +
  3112. 'a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,rtc,ruby,' +
  3113. 's,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,' +
  3114. 'embed,object,param,source,canvas,script,noscript,del,ins,' +
  3115. 'caption,col,colgroup,table,thead,tbody,td,th,tr,' +
  3116. 'button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,' +
  3117. 'output,progress,select,textarea,' +
  3118. 'details,dialog,menu,menuitem,summary,' +
  3119. 'content,element,shadow,template'
  3120. )
  3121. var isUnaryTag = makeMap(
  3122. 'area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' +
  3123. 'link,meta,param,source,track,wbr',
  3124. true
  3125. )
  3126. // Elements that you can, intentionally, leave open
  3127. // (and which close themselves)
  3128. var canBeLeftOpenTag = makeMap(
  3129. 'colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source',
  3130. true
  3131. )
  3132. // HTML5 tags https://html.spec.whatwg.org/multipage/indices.html#elements-3
  3133. // Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content
  3134. var isNonPhrasingTag = makeMap(
  3135. 'address,article,aside,base,blockquote,body,caption,col,colgroup,dd,' +
  3136. 'details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,' +
  3137. 'h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,' +
  3138. 'optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,' +
  3139. 'title,tr,track',
  3140. true
  3141. )
  3142. // this map is intentionally selective, only covering SVG elements that may
  3143. // contain child elements.
  3144. var isSVG = makeMap(
  3145. 'svg,animate,circle,clippath,cursor,defs,desc,ellipse,filter,font,' +
  3146. 'font-face,g,glyph,image,line,marker,mask,missing-glyph,path,pattern,' +
  3147. 'polygon,polyline,rect,switch,symbol,text,textpath,tspan,use,view',
  3148. true
  3149. )
  3150. var isReservedTag = function (tag) {
  3151. return isHTMLTag(tag) || isSVG(tag)
  3152. }
  3153. function getTagNamespace (tag) {
  3154. if (isSVG(tag)) {
  3155. return 'svg'
  3156. }
  3157. // basic support for MathML
  3158. // note it doesn't support other MathML elements being component roots
  3159. if (tag === 'math') {
  3160. return 'math'
  3161. }
  3162. }
  3163. var unknownElementCache = Object.create(null)
  3164. function isUnknownElement (tag) {
  3165. /* istanbul ignore if */
  3166. if (!inBrowser) {
  3167. return true
  3168. }
  3169. if (isReservedTag(tag)) {
  3170. return false
  3171. }
  3172. tag = tag.toLowerCase()
  3173. /* istanbul ignore if */
  3174. if (unknownElementCache[tag] != null) {
  3175. return unknownElementCache[tag]
  3176. }
  3177. var el = document.createElement(tag)
  3178. if (tag.indexOf('-') > -1) {
  3179. // http://stackoverflow.com/a/28210364/1070244
  3180. return (unknownElementCache[tag] = (
  3181. el.constructor === window.HTMLUnknownElement ||
  3182. el.constructor === window.HTMLElement
  3183. ))
  3184. } else {
  3185. return (unknownElementCache[tag] = /HTMLUnknownElement/.test(el.toString()))
  3186. }
  3187. }
  3188. /* */
  3189. var UA$1 = inBrowser && window.navigator.userAgent.toLowerCase()
  3190. var isIE = UA$1 && /msie|trident/.test(UA$1)
  3191. var isIE9 = UA$1 && UA$1.indexOf('msie 9.0') > 0
  3192. var isAndroid = UA$1 && UA$1.indexOf('android') > 0
  3193. // According to
  3194. // https://w3c.github.io/DOM-Parsing/#dfn-serializing-an-attribute-value
  3195. // when serializing innerHTML, <, >, ", & should be encoded as entities.
  3196. // However, only some browsers, e.g. PhantomJS, encodes < and >.
  3197. // this causes problems with the in-browser parser.
  3198. var shouldDecodeTags = inBrowser ? (function () {
  3199. var div = document.createElement('div')
  3200. div.innerHTML = '<div a=">">'
  3201. return div.innerHTML.indexOf('&gt;') > 0
  3202. })() : false
  3203. /**
  3204. * Query an element selector if it's not an element already.
  3205. */
  3206. function query (el) {
  3207. if (typeof el === 'string') {
  3208. var selector = el
  3209. el = document.querySelector(el)
  3210. if (!el) {
  3211. process.env.NODE_ENV !== 'production' && warn(
  3212. 'Cannot find element: ' + selector
  3213. )
  3214. return document.createElement('div')
  3215. }
  3216. }
  3217. return el
  3218. }
  3219. /* */
  3220. function createElement$1 (tagName) {
  3221. return document.createElement(tagName)
  3222. }
  3223. function createElementNS (namespace, tagName) {
  3224. return document.createElementNS(namespaceMap[namespace], tagName)
  3225. }
  3226. function createTextNode (text) {
  3227. return document.createTextNode(text)
  3228. }
  3229. function createComment (text) {
  3230. return document.createComment(text)
  3231. }
  3232. function insertBefore (parentNode, newNode, referenceNode) {
  3233. parentNode.insertBefore(newNode, referenceNode)
  3234. }
  3235. function removeChild (node, child) {
  3236. node.removeChild(child)
  3237. }
  3238. function appendChild (node, child) {
  3239. node.appendChild(child)
  3240. }
  3241. function parentNode (node) {
  3242. return node.parentNode
  3243. }
  3244. function nextSibling (node) {
  3245. return node.nextSibling
  3246. }
  3247. function tagName (node) {
  3248. return node.tagName
  3249. }
  3250. function setTextContent (node, text) {
  3251. node.textContent = text
  3252. }
  3253. function childNodes (node) {
  3254. return node.childNodes
  3255. }
  3256. function setAttribute (node, key, val) {
  3257. node.setAttribute(key, val)
  3258. }
  3259. var nodeOps = Object.freeze({
  3260. createElement: createElement$1,
  3261. createElementNS: createElementNS,
  3262. createTextNode: createTextNode,
  3263. createComment: createComment,
  3264. insertBefore: insertBefore,
  3265. removeChild: removeChild,
  3266. appendChild: appendChild,
  3267. parentNode: parentNode,
  3268. nextSibling: nextSibling,
  3269. tagName: tagName,
  3270. setTextContent: setTextContent,
  3271. childNodes: childNodes,
  3272. setAttribute: setAttribute
  3273. });
  3274. /* */
  3275. var ref = {
  3276. create: function create (_, vnode) {
  3277. registerRef(vnode)
  3278. },
  3279. update: function update (oldVnode, vnode) {
  3280. if (oldVnode.data.ref !== vnode.data.ref) {
  3281. registerRef(oldVnode, true)
  3282. registerRef(vnode)
  3283. }
  3284. },
  3285. destroy: function destroy (vnode) {
  3286. registerRef(vnode, true)
  3287. }
  3288. }
  3289. function registerRef (vnode, isRemoval) {
  3290. var key = vnode.data.ref
  3291. if (!key) return
  3292. var vm = vnode.context
  3293. var ref = vnode.child || vnode.elm
  3294. var refs = vm.$refs
  3295. if (isRemoval) {
  3296. if (Array.isArray(refs[key])) {
  3297. remove(refs[key], ref)
  3298. } else if (refs[key] === ref) {
  3299. refs[key] = undefined
  3300. }
  3301. } else {
  3302. if (vnode.data.refInFor) {
  3303. if (Array.isArray(refs[key])) {
  3304. refs[key].push(ref)
  3305. } else {
  3306. refs[key] = [ref]
  3307. }
  3308. } else {
  3309. refs[key] = ref
  3310. }
  3311. }
  3312. }
  3313. /**
  3314. * Virtual DOM patching algorithm based on Snabbdom by
  3315. * Simon Friis Vindum (@paldepind)
  3316. * Licensed under the MIT License
  3317. * https://github.com/paldepind/snabbdom/blob/master/LICENSE
  3318. *
  3319. * modified by Evan You (@yyx990803)
  3320. *
  3321. /*
  3322. * Not type-checking this because this file is perf-critical and the cost
  3323. * of making flow understand it is not worth it.
  3324. */
  3325. var emptyData = {}
  3326. var emptyNode = new VNode('', emptyData, [])
  3327. var hooks$1 = ['create', 'update', 'postpatch', 'remove', 'destroy']
  3328. function isUndef (s) {
  3329. return s == null
  3330. }
  3331. function isDef (s) {
  3332. return s != null
  3333. }
  3334. function sameVnode (vnode1, vnode2) {
  3335. return (
  3336. vnode1.key === vnode2.key &&
  3337. vnode1.tag === vnode2.tag &&
  3338. vnode1.isComment === vnode2.isComment &&
  3339. !vnode1.data === !vnode2.data
  3340. )
  3341. }
  3342. function createKeyToOldIdx (children, beginIdx, endIdx) {
  3343. var i, key
  3344. var map = {}
  3345. for (i = beginIdx; i <= endIdx; ++i) {
  3346. key = children[i].key
  3347. if (isDef(key)) map[key] = i
  3348. }
  3349. return map
  3350. }
  3351. function createPatchFunction (backend) {
  3352. var i, j
  3353. var cbs = {}
  3354. var modules = backend.modules;
  3355. var nodeOps = backend.nodeOps;
  3356. for (i = 0; i < hooks$1.length; ++i) {
  3357. cbs[hooks$1[i]] = []
  3358. for (j = 0; j < modules.length; ++j) {
  3359. if (modules[j][hooks$1[i]] !== undefined) cbs[hooks$1[i]].push(modules[j][hooks$1[i]])
  3360. }
  3361. }
  3362. function emptyNodeAt (elm) {
  3363. return new VNode(nodeOps.tagName(elm).toLowerCase(), {}, [], undefined, elm)
  3364. }
  3365. function createRmCb (childElm, listeners) {
  3366. function remove () {
  3367. if (--remove.listeners === 0) {
  3368. removeElement(childElm)
  3369. }
  3370. }
  3371. remove.listeners = listeners
  3372. return remove
  3373. }
  3374. function removeElement (el) {
  3375. var parent = nodeOps.parentNode(el)
  3376. nodeOps.removeChild(parent, el)
  3377. }
  3378. function createElm (vnode, insertedVnodeQueue, nested) {
  3379. var i, elm
  3380. var data = vnode.data
  3381. vnode.isRootInsert = !nested
  3382. if (isDef(data)) {
  3383. if (isDef(i = data.hook) && isDef(i = i.init)) i(vnode)
  3384. // after calling the init hook, if the vnode is a child component
  3385. // it should've created a child instance and mounted it. the child
  3386. // component also has set the placeholder vnode's elm.
  3387. // in that case we can just return the element and be done.
  3388. if (isDef(i = vnode.child)) {
  3389. initComponent(vnode, insertedVnodeQueue)
  3390. return vnode.elm
  3391. }
  3392. }
  3393. var children = vnode.children
  3394. var tag = vnode.tag
  3395. if (isDef(tag)) {
  3396. if (process.env.NODE_ENV !== 'production') {
  3397. if (
  3398. !vnode.ns &&
  3399. !(config.ignoredElements && config.ignoredElements.indexOf(tag) > -1) &&
  3400. config.isUnknownElement(tag)
  3401. ) {
  3402. warn(
  3403. 'Unknown custom element: <' + tag + '> - did you ' +
  3404. 'register the component correctly? For recursive components, ' +
  3405. 'make sure to provide the "name" option.',
  3406. vnode.context
  3407. )
  3408. }
  3409. }
  3410. elm = vnode.elm = vnode.ns
  3411. ? nodeOps.createElementNS(vnode.ns, tag)
  3412. : nodeOps.createElement(tag)
  3413. setScope(vnode)
  3414. if (Array.isArray(children)) {
  3415. for (i = 0; i < children.length; ++i) {
  3416. nodeOps.appendChild(elm, createElm(children[i], insertedVnodeQueue, true))
  3417. }
  3418. } else if (isPrimitive(vnode.text)) {
  3419. nodeOps.appendChild(elm, nodeOps.createTextNode(vnode.text))
  3420. }
  3421. if (isDef(data)) {
  3422. invokeCreateHooks(vnode, insertedVnodeQueue)
  3423. }
  3424. } else if (vnode.isComment) {
  3425. elm = vnode.elm = nodeOps.createComment(vnode.text)
  3426. } else {
  3427. elm = vnode.elm = nodeOps.createTextNode(vnode.text)
  3428. }
  3429. return vnode.elm
  3430. }
  3431. function isPatchable (vnode) {
  3432. while (vnode.child) {
  3433. vnode = vnode.child._vnode
  3434. }
  3435. return isDef(vnode.tag)
  3436. }
  3437. function invokeCreateHooks (vnode, insertedVnodeQueue) {
  3438. for (var i$1 = 0; i$1 < cbs.create.length; ++i$1) {
  3439. cbs.create[i$1](emptyNode, vnode)
  3440. }
  3441. i = vnode.data.hook // Reuse variable
  3442. if (isDef(i)) {
  3443. if (i.create) i.create(emptyNode, vnode)
  3444. if (i.insert) insertedVnodeQueue.push(vnode)
  3445. }
  3446. }
  3447. function initComponent (vnode, insertedVnodeQueue) {
  3448. if (vnode.data.pendingInsert) {
  3449. insertedVnodeQueue.push.apply(insertedVnodeQueue, vnode.data.pendingInsert)
  3450. }
  3451. vnode.elm = vnode.child.$el
  3452. if (isPatchable(vnode)) {
  3453. invokeCreateHooks(vnode, insertedVnodeQueue)
  3454. setScope(vnode)
  3455. } else {
  3456. // empty component root.
  3457. // skip all element-related modules except for ref (#3455)
  3458. registerRef(vnode)
  3459. // make sure to invoke the insert hook
  3460. insertedVnodeQueue.push(vnode)
  3461. }
  3462. }
  3463. // set scope id attribute for scoped CSS.
  3464. // this is implemented as a special case to avoid the overhead
  3465. // of going through the normal attribute patching process.
  3466. function setScope (vnode) {
  3467. var i
  3468. if (isDef(i = vnode.context) && isDef(i = i.$options._scopeId)) {
  3469. nodeOps.setAttribute(vnode.elm, i, '')
  3470. }
  3471. if (isDef(i = activeInstance) &&
  3472. i !== vnode.context &&
  3473. isDef(i = i.$options._scopeId)) {
  3474. nodeOps.setAttribute(vnode.elm, i, '')
  3475. }
  3476. }
  3477. function addVnodes (parentElm, before, vnodes, startIdx, endIdx, insertedVnodeQueue) {
  3478. for (; startIdx <= endIdx; ++startIdx) {
  3479. nodeOps.insertBefore(parentElm, createElm(vnodes[startIdx], insertedVnodeQueue), before)
  3480. }
  3481. }
  3482. function invokeDestroyHook (vnode) {
  3483. var i, j
  3484. var data = vnode.data
  3485. if (isDef(data)) {
  3486. if (isDef(i = data.hook) && isDef(i = i.destroy)) i(vnode)
  3487. for (i = 0; i < cbs.destroy.length; ++i) cbs.destroy[i](vnode)
  3488. }
  3489. if (isDef(i = vnode.child) && !data.keepAlive) {
  3490. invokeDestroyHook(i._vnode)
  3491. }
  3492. if (isDef(i = vnode.children)) {
  3493. for (j = 0; j < vnode.children.length; ++j) {
  3494. invokeDestroyHook(vnode.children[j])
  3495. }
  3496. }
  3497. }
  3498. function removeVnodes (parentElm, vnodes, startIdx, endIdx) {
  3499. for (; startIdx <= endIdx; ++startIdx) {
  3500. var ch = vnodes[startIdx]
  3501. if (isDef(ch)) {
  3502. if (isDef(ch.tag)) {
  3503. removeAndInvokeRemoveHook(ch)
  3504. invokeDestroyHook(ch)
  3505. } else { // Text node
  3506. nodeOps.removeChild(parentElm, ch.elm)
  3507. }
  3508. }
  3509. }
  3510. }
  3511. function removeAndInvokeRemoveHook (vnode, rm) {
  3512. if (rm || isDef(vnode.data)) {
  3513. var listeners = cbs.remove.length + 1
  3514. if (!rm) {
  3515. // directly removing
  3516. rm = createRmCb(vnode.elm, listeners)
  3517. } else {
  3518. // we have a recursively passed down rm callback
  3519. // increase the listeners count
  3520. rm.listeners += listeners
  3521. }
  3522. // recursively invoke hooks on child component root node
  3523. if (isDef(i = vnode.child) && isDef(i = i._vnode) && isDef(i.data)) {
  3524. removeAndInvokeRemoveHook(i, rm)
  3525. }
  3526. for (i = 0; i < cbs.remove.length; ++i) {
  3527. cbs.remove[i](vnode, rm)
  3528. }
  3529. if (isDef(i = vnode.data.hook) && isDef(i = i.remove)) {
  3530. i(vnode, rm)
  3531. } else {
  3532. rm()
  3533. }
  3534. } else {
  3535. removeElement(vnode.elm)
  3536. }
  3537. }
  3538. function updateChildren (parentElm, oldCh, newCh, insertedVnodeQueue, removeOnly) {
  3539. var oldStartIdx = 0
  3540. var newStartIdx = 0
  3541. var oldEndIdx = oldCh.length - 1
  3542. var oldStartVnode = oldCh[0]
  3543. var oldEndVnode = oldCh[oldEndIdx]
  3544. var newEndIdx = newCh.length - 1
  3545. var newStartVnode = newCh[0]
  3546. var newEndVnode = newCh[newEndIdx]
  3547. var oldKeyToIdx, idxInOld, elmToMove, before
  3548. // removeOnly is a special flag used only by <transition-group>
  3549. // to ensure removed elements stay in correct relative positions
  3550. // during leaving transitions
  3551. var canMove = !removeOnly
  3552. while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
  3553. if (isUndef(oldStartVnode)) {
  3554. oldStartVnode = oldCh[++oldStartIdx] // Vnode has been moved left
  3555. } else if (isUndef(oldEndVnode)) {
  3556. oldEndVnode = oldCh[--oldEndIdx]
  3557. } else if (sameVnode(oldStartVnode, newStartVnode)) {
  3558. patchVnode(oldStartVnode, newStartVnode, insertedVnodeQueue)
  3559. oldStartVnode = oldCh[++oldStartIdx]
  3560. newStartVnode = newCh[++newStartIdx]
  3561. } else if (sameVnode(oldEndVnode, newEndVnode)) {
  3562. patchVnode(oldEndVnode, newEndVnode, insertedVnodeQueue)
  3563. oldEndVnode = oldCh[--oldEndIdx]
  3564. newEndVnode = newCh[--newEndIdx]
  3565. } else if (sameVnode(oldStartVnode, newEndVnode)) { // Vnode moved right
  3566. patchVnode(oldStartVnode, newEndVnode, insertedVnodeQueue)
  3567. canMove && nodeOps.insertBefore(parentElm, oldStartVnode.elm, nodeOps.nextSibling(oldEndVnode.elm))
  3568. oldStartVnode = oldCh[++oldStartIdx]
  3569. newEndVnode = newCh[--newEndIdx]
  3570. } else if (sameVnode(oldEndVnode, newStartVnode)) { // Vnode moved left
  3571. patchVnode(oldEndVnode, newStartVnode, insertedVnodeQueue)
  3572. canMove && nodeOps.insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm)
  3573. oldEndVnode = oldCh[--oldEndIdx]
  3574. newStartVnode = newCh[++newStartIdx]
  3575. } else {
  3576. if (isUndef(oldKeyToIdx)) oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx)
  3577. idxInOld = isDef(newStartVnode.key) ? oldKeyToIdx[newStartVnode.key] : null
  3578. if (isUndef(idxInOld)) { // New element
  3579. nodeOps.insertBefore(parentElm, createElm(newStartVnode, insertedVnodeQueue), oldStartVnode.elm)
  3580. newStartVnode = newCh[++newStartIdx]
  3581. } else {
  3582. elmToMove = oldCh[idxInOld]
  3583. /* istanbul ignore if */
  3584. if (process.env.NODE_ENV !== 'production' && !elmToMove) {
  3585. warn(
  3586. 'It seems there are duplicate keys that is causing an update error. ' +
  3587. 'Make sure each v-for item has a unique key.'
  3588. )
  3589. }
  3590. if (elmToMove.tag !== newStartVnode.tag) {
  3591. // same key but different element. treat as new element
  3592. nodeOps.insertBefore(parentElm, createElm(newStartVnode, insertedVnodeQueue), oldStartVnode.elm)
  3593. newStartVnode = newCh[++newStartIdx]
  3594. } else {
  3595. patchVnode(elmToMove, newStartVnode, insertedVnodeQueue)
  3596. oldCh[idxInOld] = undefined
  3597. canMove && nodeOps.insertBefore(parentElm, newStartVnode.elm, oldStartVnode.elm)
  3598. newStartVnode = newCh[++newStartIdx]
  3599. }
  3600. }
  3601. }
  3602. }
  3603. if (oldStartIdx > oldEndIdx) {
  3604. before = isUndef(newCh[newEndIdx + 1]) ? null : newCh[newEndIdx + 1].elm
  3605. addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx, insertedVnodeQueue)
  3606. } else if (newStartIdx > newEndIdx) {
  3607. removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx)
  3608. }
  3609. }
  3610. function patchVnode (oldVnode, vnode, insertedVnodeQueue, removeOnly) {
  3611. if (oldVnode === vnode) {
  3612. return
  3613. }
  3614. // reuse element for static trees.
  3615. // note we only do this if the vnode is cloned -
  3616. // if the new node is not cloned it means the render functions have been
  3617. // reset by the hot-reload-api and we need to a proper re-render.
  3618. if (vnode.isStatic &&
  3619. oldVnode.isStatic &&
  3620. vnode.key === oldVnode.key &&
  3621. vnode.isCloned) {
  3622. vnode.elm = oldVnode.elm
  3623. return
  3624. }
  3625. var i, hook
  3626. var hasData = isDef(i = vnode.data)
  3627. if (hasData && isDef(hook = i.hook) && isDef(i = hook.prepatch)) {
  3628. i(oldVnode, vnode)
  3629. }
  3630. var elm = vnode.elm = oldVnode.elm
  3631. var oldCh = oldVnode.children
  3632. var ch = vnode.children
  3633. if (hasData && isPatchable(vnode)) {
  3634. for (i = 0; i < cbs.update.length; ++i) cbs.update[i](oldVnode, vnode)
  3635. if (isDef(hook) && isDef(i = hook.update)) i(oldVnode, vnode)
  3636. }
  3637. if (isUndef(vnode.text)) {
  3638. if (isDef(oldCh) && isDef(ch)) {
  3639. if (oldCh !== ch) updateChildren(elm, oldCh, ch, insertedVnodeQueue, removeOnly)
  3640. } else if (isDef(ch)) {
  3641. if (isDef(oldVnode.text)) nodeOps.setTextContent(elm, '')
  3642. addVnodes(elm, null, ch, 0, ch.length - 1, insertedVnodeQueue)
  3643. } else if (isDef(oldCh)) {
  3644. removeVnodes(elm, oldCh, 0, oldCh.length - 1)
  3645. } else if (isDef(oldVnode.text)) {
  3646. nodeOps.setTextContent(elm, '')
  3647. }
  3648. } else if (oldVnode.text !== vnode.text) {
  3649. nodeOps.setTextContent(elm, vnode.text)
  3650. }
  3651. if (hasData) {
  3652. for (i = 0; i < cbs.postpatch.length; ++i) cbs.postpatch[i](oldVnode, vnode)
  3653. if (isDef(hook) && isDef(i = hook.postpatch)) i(oldVnode, vnode)
  3654. }
  3655. }
  3656. function invokeInsertHook (vnode, queue, initial) {
  3657. // delay insert hooks for component root nodes, invoke them after the
  3658. // element is really inserted
  3659. if (initial && vnode.parent) {
  3660. vnode.parent.data.pendingInsert = queue
  3661. } else {
  3662. for (var i = 0; i < queue.length; ++i) {
  3663. queue[i].data.hook.insert(queue[i])
  3664. }
  3665. }
  3666. }
  3667. var bailed = false
  3668. function hydrate (elm, vnode, insertedVnodeQueue) {
  3669. if (process.env.NODE_ENV !== 'production') {
  3670. if (!assertNodeMatch(elm, vnode)) {
  3671. return false
  3672. }
  3673. }
  3674. vnode.elm = elm
  3675. var tag = vnode.tag;
  3676. var data = vnode.data;
  3677. var children = vnode.children;
  3678. if (isDef(data)) {
  3679. if (isDef(i = data.hook) && isDef(i = i.init)) i(vnode, true /* hydrating */)
  3680. if (isDef(i = vnode.child)) {
  3681. // child component. it should have hydrated its own tree.
  3682. initComponent(vnode, insertedVnodeQueue)
  3683. return true
  3684. }
  3685. }
  3686. if (isDef(tag)) {
  3687. if (isDef(children)) {
  3688. var childNodes = nodeOps.childNodes(elm)
  3689. var childrenMatch = true
  3690. if (childNodes.length !== children.length) {
  3691. childrenMatch = false
  3692. } else {
  3693. for (var i$1 = 0; i$1 < children.length; i$1++) {
  3694. if (!hydrate(childNodes[i$1], children[i$1], insertedVnodeQueue)) {
  3695. childrenMatch = false
  3696. break
  3697. }
  3698. }
  3699. }
  3700. if (!childrenMatch) {
  3701. if (process.env.NODE_ENV !== 'production' &&
  3702. typeof console !== 'undefined' &&
  3703. !bailed) {
  3704. bailed = true
  3705. console.warn('Parent: ', elm)
  3706. console.warn('Mismatching childNodes vs. VNodes: ', childNodes, children)
  3707. }
  3708. return false
  3709. }
  3710. }
  3711. if (isDef(data)) {
  3712. invokeCreateHooks(vnode, insertedVnodeQueue)
  3713. }
  3714. }
  3715. return true
  3716. }
  3717. function assertNodeMatch (node, vnode) {
  3718. if (vnode.tag) {
  3719. return (
  3720. vnode.tag.indexOf('vue-component') === 0 ||
  3721. vnode.tag === nodeOps.tagName(node).toLowerCase()
  3722. )
  3723. } else {
  3724. return _toString(vnode.text) === node.data
  3725. }
  3726. }
  3727. return function patch (oldVnode, vnode, hydrating, removeOnly) {
  3728. var elm, parent
  3729. var isInitialPatch = false
  3730. var insertedVnodeQueue = []
  3731. if (!oldVnode) {
  3732. // empty mount, create new root element
  3733. isInitialPatch = true
  3734. createElm(vnode, insertedVnodeQueue)
  3735. } else {
  3736. var isRealElement = isDef(oldVnode.nodeType)
  3737. if (!isRealElement && sameVnode(oldVnode, vnode)) {
  3738. patchVnode(oldVnode, vnode, insertedVnodeQueue, removeOnly)
  3739. } else {
  3740. if (isRealElement) {
  3741. // mounting to a real element
  3742. // check if this is server-rendered content and if we can perform
  3743. // a successful hydration.
  3744. if (oldVnode.nodeType === 1 && oldVnode.hasAttribute('server-rendered')) {
  3745. oldVnode.removeAttribute('server-rendered')
  3746. hydrating = true
  3747. }
  3748. if (hydrating) {
  3749. if (hydrate(oldVnode, vnode, insertedVnodeQueue)) {
  3750. invokeInsertHook(vnode, insertedVnodeQueue, true)
  3751. return oldVnode
  3752. } else if (process.env.NODE_ENV !== 'production') {
  3753. warn(
  3754. 'The client-side rendered virtual DOM tree is not matching ' +
  3755. 'server-rendered content. This is likely caused by incorrect ' +
  3756. 'HTML markup, for example nesting block-level elements inside ' +
  3757. '<p>, or missing <tbody>. Bailing hydration and performing ' +
  3758. 'full client-side render.'
  3759. )
  3760. }
  3761. }
  3762. // either not server-rendered, or hydration failed.
  3763. // create an empty node and replace it
  3764. oldVnode = emptyNodeAt(oldVnode)
  3765. }
  3766. elm = oldVnode.elm
  3767. parent = nodeOps.parentNode(elm)
  3768. createElm(vnode, insertedVnodeQueue)
  3769. // component root element replaced.
  3770. // update parent placeholder node element.
  3771. if (vnode.parent) {
  3772. vnode.parent.elm = vnode.elm
  3773. if (isPatchable(vnode)) {
  3774. for (var i = 0; i < cbs.create.length; ++i) {
  3775. cbs.create[i](emptyNode, vnode.parent)
  3776. }
  3777. }
  3778. }
  3779. if (parent !== null) {
  3780. nodeOps.insertBefore(parent, vnode.elm, nodeOps.nextSibling(elm))
  3781. removeVnodes(parent, [oldVnode], 0, 0)
  3782. } else if (isDef(oldVnode.tag)) {
  3783. invokeDestroyHook(oldVnode)
  3784. }
  3785. }
  3786. }
  3787. invokeInsertHook(vnode, insertedVnodeQueue, isInitialPatch)
  3788. return vnode.elm
  3789. }
  3790. }
  3791. /* */
  3792. var directives = {
  3793. create: function bindDirectives (oldVnode, vnode) {
  3794. mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'insert', function () {
  3795. applyDirectives(oldVnode, vnode, 'bind')
  3796. })
  3797. },
  3798. update: function updateDirectives (oldVnode, vnode) {
  3799. applyDirectives(oldVnode, vnode, 'update')
  3800. // if old vnode has directives but new vnode doesn't
  3801. // we need to teardown the directives on the old one.
  3802. if (oldVnode.data.directives && !vnode.data.directives) {
  3803. applyDirectives(oldVnode, oldVnode, 'unbind')
  3804. }
  3805. },
  3806. postpatch: function postupdateDirectives (oldVnode, vnode) {
  3807. applyDirectives(oldVnode, vnode, 'componentUpdated')
  3808. },
  3809. destroy: function unbindDirectives (vnode) {
  3810. applyDirectives(vnode, vnode, 'unbind')
  3811. }
  3812. }
  3813. var emptyModifiers = Object.create(null)
  3814. function applyDirectives (
  3815. oldVnode,
  3816. vnode,
  3817. hook
  3818. ) {
  3819. var dirs = vnode.data.directives
  3820. if (dirs) {
  3821. var oldDirs = oldVnode.data.directives
  3822. var isUpdate = hook === 'update' || hook === 'componentUpdated'
  3823. for (var i = 0; i < dirs.length; i++) {
  3824. var dir = dirs[i]
  3825. var def = resolveAsset(vnode.context.$options, 'directives', dir.name, true)
  3826. var fn = def && def[hook]
  3827. if (fn) {
  3828. if (isUpdate && oldDirs) {
  3829. dir.oldValue = oldDirs[i].value
  3830. }
  3831. if (!dir.modifiers) {
  3832. dir.modifiers = emptyModifiers
  3833. }
  3834. fn(vnode.elm, dir, vnode, oldVnode)
  3835. }
  3836. }
  3837. }
  3838. }
  3839. var baseModules = [
  3840. ref,
  3841. directives
  3842. ]
  3843. /* */
  3844. function updateAttrs (oldVnode, vnode) {
  3845. if (!oldVnode.data.attrs && !vnode.data.attrs) {
  3846. return
  3847. }
  3848. var key, cur, old
  3849. var elm = vnode.elm
  3850. var oldAttrs = oldVnode.data.attrs || {}
  3851. var attrs = vnode.data.attrs || {}
  3852. // clone observed objects, as the user probably wants to mutate it
  3853. if (attrs.__ob__) {
  3854. attrs = vnode.data.attrs = extend({}, attrs)
  3855. }
  3856. for (key in attrs) {
  3857. cur = attrs[key]
  3858. old = oldAttrs[key]
  3859. if (old !== cur) {
  3860. setAttr(elm, key, cur)
  3861. }
  3862. }
  3863. for (key in oldAttrs) {
  3864. if (attrs[key] == null) {
  3865. if (isXlink(key)) {
  3866. elm.removeAttributeNS(xlinkNS, getXlinkProp(key))
  3867. } else if (!isEnumeratedAttr(key)) {
  3868. elm.removeAttribute(key)
  3869. }
  3870. }
  3871. }
  3872. }
  3873. function setAttr (el, key, value) {
  3874. if (isBooleanAttr(key)) {
  3875. // set attribute for blank value
  3876. // e.g. <option disabled>Select one</option>
  3877. if (isFalsyAttrValue(value)) {
  3878. el.removeAttribute(key)
  3879. } else {
  3880. el.setAttribute(key, key)
  3881. }
  3882. } else if (isEnumeratedAttr(key)) {
  3883. el.setAttribute(key, isFalsyAttrValue(value) || value === 'false' ? 'false' : 'true')
  3884. } else if (isXlink(key)) {
  3885. if (isFalsyAttrValue(value)) {
  3886. el.removeAttributeNS(xlinkNS, getXlinkProp(key))
  3887. } else {
  3888. el.setAttributeNS(xlinkNS, key, value)
  3889. }
  3890. } else {
  3891. if (isFalsyAttrValue(value)) {
  3892. el.removeAttribute(key)
  3893. } else {
  3894. el.setAttribute(key, value)
  3895. }
  3896. }
  3897. }
  3898. var attrs = {
  3899. create: updateAttrs,
  3900. update: updateAttrs
  3901. }
  3902. /* */
  3903. function updateClass (oldVnode, vnode) {
  3904. var el = vnode.elm
  3905. var data = vnode.data
  3906. var oldData = oldVnode.data
  3907. if (!data.staticClass && !data.class &&
  3908. (!oldData || (!oldData.staticClass && !oldData.class))) {
  3909. return
  3910. }
  3911. var cls = genClassForVnode(vnode)
  3912. // handle transition classes
  3913. var transitionClass = el._transitionClasses
  3914. if (transitionClass) {
  3915. cls = concat(cls, stringifyClass(transitionClass))
  3916. }
  3917. // set the class
  3918. if (cls !== el._prevClass) {
  3919. el.setAttribute('class', cls)
  3920. el._prevClass = cls
  3921. }
  3922. }
  3923. var klass = {
  3924. create: updateClass,
  3925. update: updateClass
  3926. }
  3927. // skip type checking this file because we need to attach private properties
  3928. // to elements
  3929. function updateDOMListeners (oldVnode, vnode) {
  3930. if (!oldVnode.data.on && !vnode.data.on) {
  3931. return
  3932. }
  3933. var on = vnode.data.on || {}
  3934. var oldOn = oldVnode.data.on || {}
  3935. var add = vnode.elm._v_add || (vnode.elm._v_add = function (event, handler, capture) {
  3936. vnode.elm.addEventListener(event, handler, capture)
  3937. })
  3938. var remove = vnode.elm._v_remove || (vnode.elm._v_remove = function (event, handler) {
  3939. vnode.elm.removeEventListener(event, handler)
  3940. })
  3941. updateListeners(on, oldOn, add, remove)
  3942. }
  3943. var events = {
  3944. create: updateDOMListeners,
  3945. update: updateDOMListeners
  3946. }
  3947. /* */
  3948. function updateDOMProps (oldVnode, vnode) {
  3949. if (!oldVnode.data.domProps && !vnode.data.domProps) {
  3950. return
  3951. }
  3952. var key, cur
  3953. var elm = vnode.elm
  3954. var oldProps = oldVnode.data.domProps || {}
  3955. var props = vnode.data.domProps || {}
  3956. // clone observed objects, as the user probably wants to mutate it
  3957. if (props.__ob__) {
  3958. props = vnode.data.domProps = extend({}, props)
  3959. }
  3960. for (key in oldProps) {
  3961. if (props[key] == null) {
  3962. elm[key] = undefined
  3963. }
  3964. }
  3965. for (key in props) {
  3966. // ignore children if the node has textContent or innerHTML,
  3967. // as these will throw away existing DOM nodes and cause removal errors
  3968. // on subsequent patches (#3360)
  3969. if ((key === 'textContent' || key === 'innerHTML') && vnode.children) {
  3970. vnode.children.length = 0
  3971. }
  3972. cur = props[key]
  3973. if (key === 'value') {
  3974. // store value as _value as well since
  3975. // non-string values will be stringified
  3976. elm._value = cur
  3977. // avoid resetting cursor position when value is the same
  3978. var strCur = cur == null ? '' : String(cur)
  3979. if (elm.value !== strCur) {
  3980. elm.value = strCur
  3981. }
  3982. } else {
  3983. elm[key] = cur
  3984. }
  3985. }
  3986. }
  3987. var domProps = {
  3988. create: updateDOMProps,
  3989. update: updateDOMProps
  3990. }
  3991. /* */
  3992. var prefixes = ['Webkit', 'Moz', 'ms']
  3993. var testEl
  3994. var normalize = cached(function (prop) {
  3995. testEl = testEl || document.createElement('div')
  3996. prop = camelize(prop)
  3997. if (prop !== 'filter' && (prop in testEl.style)) {
  3998. return prop
  3999. }
  4000. var upper = prop.charAt(0).toUpperCase() + prop.slice(1)
  4001. for (var i = 0; i < prefixes.length; i++) {
  4002. var prefixed = prefixes[i] + upper
  4003. if (prefixed in testEl.style) {
  4004. return prefixed
  4005. }
  4006. }
  4007. })
  4008. function updateStyle (oldVnode, vnode) {
  4009. if ((!oldVnode.data || !oldVnode.data.style) && !vnode.data.style) {
  4010. return
  4011. }
  4012. var cur, name
  4013. var el = vnode.elm
  4014. var oldStyle = oldVnode.data.style || {}
  4015. var style = vnode.data.style || {}
  4016. // handle string
  4017. if (typeof style === 'string') {
  4018. el.style.cssText = style
  4019. return
  4020. }
  4021. var needClone = style.__ob__
  4022. // handle array syntax
  4023. if (Array.isArray(style)) {
  4024. style = vnode.data.style = toObject(style)
  4025. }
  4026. // clone the style for future updates,
  4027. // in case the user mutates the style object in-place.
  4028. if (needClone) {
  4029. style = vnode.data.style = extend({}, style)
  4030. }
  4031. for (name in oldStyle) {
  4032. if (!style[name]) {
  4033. el.style[normalize(name)] = ''
  4034. }
  4035. }
  4036. for (name in style) {
  4037. cur = style[name]
  4038. if (cur !== oldStyle[name]) {
  4039. // ie9 setting to null has no effect, must use empty string
  4040. el.style[normalize(name)] = cur || ''
  4041. }
  4042. }
  4043. }
  4044. var style = {
  4045. create: updateStyle,
  4046. update: updateStyle
  4047. }
  4048. /* */
  4049. /**
  4050. * Add class with compatibility for SVG since classList is not supported on
  4051. * SVG elements in IE
  4052. */
  4053. function addClass (el, cls) {
  4054. /* istanbul ignore else */
  4055. if (el.classList) {
  4056. if (cls.indexOf(' ') > -1) {
  4057. cls.split(/\s+/).forEach(function (c) { return el.classList.add(c); })
  4058. } else {
  4059. el.classList.add(cls)
  4060. }
  4061. } else {
  4062. var cur = ' ' + el.getAttribute('class') + ' '
  4063. if (cur.indexOf(' ' + cls + ' ') < 0) {
  4064. el.setAttribute('class', (cur + cls).trim())
  4065. }
  4066. }
  4067. }
  4068. /**
  4069. * Remove class with compatibility for SVG since classList is not supported on
  4070. * SVG elements in IE
  4071. */
  4072. function removeClass (el, cls) {
  4073. /* istanbul ignore else */
  4074. if (el.classList) {
  4075. if (cls.indexOf(' ') > -1) {
  4076. cls.split(/\s+/).forEach(function (c) { return el.classList.remove(c); })
  4077. } else {
  4078. el.classList.remove(cls)
  4079. }
  4080. } else {
  4081. var cur = ' ' + el.getAttribute('class') + ' '
  4082. var tar = ' ' + cls + ' '
  4083. while (cur.indexOf(tar) >= 0) {
  4084. cur = cur.replace(tar, ' ')
  4085. }
  4086. el.setAttribute('class', cur.trim())
  4087. }
  4088. }
  4089. /* */
  4090. var hasTransition = inBrowser && !isIE9
  4091. var TRANSITION = 'transition'
  4092. var ANIMATION = 'animation'
  4093. // Transition property/event sniffing
  4094. var transitionProp = 'transition'
  4095. var transitionEndEvent = 'transitionend'
  4096. var animationProp = 'animation'
  4097. var animationEndEvent = 'animationend'
  4098. if (hasTransition) {
  4099. /* istanbul ignore if */
  4100. if (window.ontransitionend === undefined &&
  4101. window.onwebkittransitionend !== undefined) {
  4102. transitionProp = 'WebkitTransition'
  4103. transitionEndEvent = 'webkitTransitionEnd'
  4104. }
  4105. if (window.onanimationend === undefined &&
  4106. window.onwebkitanimationend !== undefined) {
  4107. animationProp = 'WebkitAnimation'
  4108. animationEndEvent = 'webkitAnimationEnd'
  4109. }
  4110. }
  4111. var raf = (inBrowser && window.requestAnimationFrame) || setTimeout
  4112. function nextFrame (fn) {
  4113. raf(function () {
  4114. raf(fn)
  4115. })
  4116. }
  4117. function addTransitionClass (el, cls) {
  4118. (el._transitionClasses || (el._transitionClasses = [])).push(cls)
  4119. addClass(el, cls)
  4120. }
  4121. function removeTransitionClass (el, cls) {
  4122. if (el._transitionClasses) {
  4123. remove(el._transitionClasses, cls)
  4124. }
  4125. removeClass(el, cls)
  4126. }
  4127. function whenTransitionEnds (
  4128. el,
  4129. expectedType,
  4130. cb
  4131. ) {
  4132. var ref = getTransitionInfo(el, expectedType);
  4133. var type = ref.type;
  4134. var timeout = ref.timeout;
  4135. var propCount = ref.propCount;
  4136. if (!type) return cb()
  4137. var event = type === TRANSITION ? transitionEndEvent : animationEndEvent
  4138. var ended = 0
  4139. var end = function () {
  4140. el.removeEventListener(event, onEnd)
  4141. cb()
  4142. }
  4143. var onEnd = function (e) {
  4144. if (e.target === el) {
  4145. if (++ended >= propCount) {
  4146. end()
  4147. }
  4148. }
  4149. }
  4150. setTimeout(function () {
  4151. if (ended < propCount) {
  4152. end()
  4153. }
  4154. }, timeout + 1)
  4155. el.addEventListener(event, onEnd)
  4156. }
  4157. var transformRE = /\b(transform|all)(,|$)/
  4158. function getTransitionInfo (el, expectedType) {
  4159. var styles = window.getComputedStyle(el)
  4160. var transitioneDelays = styles[transitionProp + 'Delay'].split(', ')
  4161. var transitionDurations = styles[transitionProp + 'Duration'].split(', ')
  4162. var transitionTimeout = getTimeout(transitioneDelays, transitionDurations)
  4163. var animationDelays = styles[animationProp + 'Delay'].split(', ')
  4164. var animationDurations = styles[animationProp + 'Duration'].split(', ')
  4165. var animationTimeout = getTimeout(animationDelays, animationDurations)
  4166. var type
  4167. var timeout = 0
  4168. var propCount = 0
  4169. /* istanbul ignore if */
  4170. if (expectedType === TRANSITION) {
  4171. if (transitionTimeout > 0) {
  4172. type = TRANSITION
  4173. timeout = transitionTimeout
  4174. propCount = transitionDurations.length
  4175. }
  4176. } else if (expectedType === ANIMATION) {
  4177. if (animationTimeout > 0) {
  4178. type = ANIMATION
  4179. timeout = animationTimeout
  4180. propCount = animationDurations.length
  4181. }
  4182. } else {
  4183. timeout = Math.max(transitionTimeout, animationTimeout)
  4184. type = timeout > 0
  4185. ? transitionTimeout > animationTimeout
  4186. ? TRANSITION
  4187. : ANIMATION
  4188. : null
  4189. propCount = type
  4190. ? type === TRANSITION
  4191. ? transitionDurations.length
  4192. : animationDurations.length
  4193. : 0
  4194. }
  4195. var hasTransform =
  4196. type === TRANSITION &&
  4197. transformRE.test(styles[transitionProp + 'Property'])
  4198. return {
  4199. type: type,
  4200. timeout: timeout,
  4201. propCount: propCount,
  4202. hasTransform: hasTransform
  4203. }
  4204. }
  4205. function getTimeout (delays, durations) {
  4206. return Math.max.apply(null, durations.map(function (d, i) {
  4207. return toMs(d) + toMs(delays[i])
  4208. }))
  4209. }
  4210. function toMs (s) {
  4211. return Number(s.slice(0, -1)) * 1000
  4212. }
  4213. /* */
  4214. function enter (vnode) {
  4215. var el = vnode.elm
  4216. // call leave callback now
  4217. if (el._leaveCb) {
  4218. el._leaveCb.cancelled = true
  4219. el._leaveCb()
  4220. }
  4221. var data = resolveTransition(vnode.data.transition)
  4222. if (!data) {
  4223. return
  4224. }
  4225. /* istanbul ignore if */
  4226. if (el._enterCb || el.nodeType !== 1) {
  4227. return
  4228. }
  4229. var css = data.css;
  4230. var type = data.type;
  4231. var enterClass = data.enterClass;
  4232. var enterActiveClass = data.enterActiveClass;
  4233. var appearClass = data.appearClass;
  4234. var appearActiveClass = data.appearActiveClass;
  4235. var beforeEnter = data.beforeEnter;
  4236. var enter = data.enter;
  4237. var afterEnter = data.afterEnter;
  4238. var enterCancelled = data.enterCancelled;
  4239. var beforeAppear = data.beforeAppear;
  4240. var appear = data.appear;
  4241. var afterAppear = data.afterAppear;
  4242. var appearCancelled = data.appearCancelled;
  4243. // activeInstance will always be the <transition> component managing this
  4244. // transition. One edge case to check is when the <transition> is placed
  4245. // as the root node of a child component. In that case we need to check
  4246. // <transition>'s parent for appear check.
  4247. var transitionNode = activeInstance.$vnode
  4248. var context = transitionNode && transitionNode.parent
  4249. ? transitionNode.parent.context
  4250. : activeInstance
  4251. var isAppear = !context._isMounted || !vnode.isRootInsert
  4252. if (isAppear && !appear && appear !== '') {
  4253. return
  4254. }
  4255. var startClass = isAppear ? appearClass : enterClass
  4256. var activeClass = isAppear ? appearActiveClass : enterActiveClass
  4257. var beforeEnterHook = isAppear ? (beforeAppear || beforeEnter) : beforeEnter
  4258. var enterHook = isAppear ? (typeof appear === 'function' ? appear : enter) : enter
  4259. var afterEnterHook = isAppear ? (afterAppear || afterEnter) : afterEnter
  4260. var enterCancelledHook = isAppear ? (appearCancelled || enterCancelled) : enterCancelled
  4261. var expectsCSS = css !== false && !isIE9
  4262. var userWantsControl =
  4263. enterHook &&
  4264. // enterHook may be a bound method which exposes
  4265. // the length of original fn as _length
  4266. (enterHook._length || enterHook.length) > 1
  4267. var cb = el._enterCb = once(function () {
  4268. if (expectsCSS) {
  4269. removeTransitionClass(el, activeClass)
  4270. }
  4271. if (cb.cancelled) {
  4272. if (expectsCSS) {
  4273. removeTransitionClass(el, startClass)
  4274. }
  4275. enterCancelledHook && enterCancelledHook(el)
  4276. } else {
  4277. afterEnterHook && afterEnterHook(el)
  4278. }
  4279. el._enterCb = null
  4280. })
  4281. if (!vnode.data.show) {
  4282. // remove pending leave element on enter by injecting an insert hook
  4283. mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'insert', function () {
  4284. var parent = el.parentNode
  4285. var pendingNode = parent && parent._pending && parent._pending[vnode.key]
  4286. if (pendingNode && pendingNode.tag === vnode.tag && pendingNode.elm._leaveCb) {
  4287. pendingNode.elm._leaveCb()
  4288. }
  4289. enterHook && enterHook(el, cb)
  4290. })
  4291. }
  4292. // start enter transition
  4293. beforeEnterHook && beforeEnterHook(el)
  4294. if (expectsCSS) {
  4295. addTransitionClass(el, startClass)
  4296. addTransitionClass(el, activeClass)
  4297. nextFrame(function () {
  4298. removeTransitionClass(el, startClass)
  4299. if (!cb.cancelled && !userWantsControl) {
  4300. whenTransitionEnds(el, type, cb)
  4301. }
  4302. })
  4303. }
  4304. if (vnode.data.show) {
  4305. enterHook && enterHook(el, cb)
  4306. }
  4307. if (!expectsCSS && !userWantsControl) {
  4308. cb()
  4309. }
  4310. }
  4311. function leave (vnode, rm) {
  4312. var el = vnode.elm
  4313. // call enter callback now
  4314. if (el._enterCb) {
  4315. el._enterCb.cancelled = true
  4316. el._enterCb()
  4317. }
  4318. var data = resolveTransition(vnode.data.transition)
  4319. if (!data) {
  4320. return rm()
  4321. }
  4322. /* istanbul ignore if */
  4323. if (el._leaveCb || el.nodeType !== 1) {
  4324. return
  4325. }
  4326. var css = data.css;
  4327. var type = data.type;
  4328. var leaveClass = data.leaveClass;
  4329. var leaveActiveClass = data.leaveActiveClass;
  4330. var beforeLeave = data.beforeLeave;
  4331. var leave = data.leave;
  4332. var afterLeave = data.afterLeave;
  4333. var leaveCancelled = data.leaveCancelled;
  4334. var delayLeave = data.delayLeave;
  4335. var expectsCSS = css !== false && !isIE9
  4336. var userWantsControl =
  4337. leave &&
  4338. // leave hook may be a bound method which exposes
  4339. // the length of original fn as _length
  4340. (leave._length || leave.length) > 1
  4341. var cb = el._leaveCb = once(function () {
  4342. if (el.parentNode && el.parentNode._pending) {
  4343. el.parentNode._pending[vnode.key] = null
  4344. }
  4345. if (expectsCSS) {
  4346. removeTransitionClass(el, leaveActiveClass)
  4347. }
  4348. if (cb.cancelled) {
  4349. if (expectsCSS) {
  4350. removeTransitionClass(el, leaveClass)
  4351. }
  4352. leaveCancelled && leaveCancelled(el)
  4353. } else {
  4354. rm()
  4355. afterLeave && afterLeave(el)
  4356. }
  4357. el._leaveCb = null
  4358. })
  4359. if (delayLeave) {
  4360. delayLeave(performLeave)
  4361. } else {
  4362. performLeave()
  4363. }
  4364. function performLeave () {
  4365. // the delayed leave may have already been cancelled
  4366. if (cb.cancelled) {
  4367. return
  4368. }
  4369. // record leaving element
  4370. if (!vnode.data.show) {
  4371. (el.parentNode._pending || (el.parentNode._pending = {}))[vnode.key] = vnode
  4372. }
  4373. beforeLeave && beforeLeave(el)
  4374. if (expectsCSS) {
  4375. addTransitionClass(el, leaveClass)
  4376. addTransitionClass(el, leaveActiveClass)
  4377. nextFrame(function () {
  4378. removeTransitionClass(el, leaveClass)
  4379. if (!cb.cancelled && !userWantsControl) {
  4380. whenTransitionEnds(el, type, cb)
  4381. }
  4382. })
  4383. }
  4384. leave && leave(el, cb)
  4385. if (!expectsCSS && !userWantsControl) {
  4386. cb()
  4387. }
  4388. }
  4389. }
  4390. function resolveTransition (def) {
  4391. if (!def) {
  4392. return
  4393. }
  4394. /* istanbul ignore else */
  4395. if (typeof def === 'object') {
  4396. var res = {}
  4397. if (def.css !== false) {
  4398. extend(res, autoCssTransition(def.name || 'v'))
  4399. }
  4400. extend(res, def)
  4401. return res
  4402. } else if (typeof def === 'string') {
  4403. return autoCssTransition(def)
  4404. }
  4405. }
  4406. var autoCssTransition = cached(function (name) {
  4407. return {
  4408. enterClass: (name + "-enter"),
  4409. leaveClass: (name + "-leave"),
  4410. appearClass: (name + "-enter"),
  4411. enterActiveClass: (name + "-enter-active"),
  4412. leaveActiveClass: (name + "-leave-active"),
  4413. appearActiveClass: (name + "-enter-active")
  4414. }
  4415. })
  4416. function once (fn) {
  4417. var called = false
  4418. return function () {
  4419. if (!called) {
  4420. called = true
  4421. fn()
  4422. }
  4423. }
  4424. }
  4425. var transition = inBrowser ? {
  4426. create: function create (_, vnode) {
  4427. if (!vnode.data.show) {
  4428. enter(vnode)
  4429. }
  4430. },
  4431. remove: function remove (vnode, rm) {
  4432. /* istanbul ignore else */
  4433. if (!vnode.data.show) {
  4434. leave(vnode, rm)
  4435. } else {
  4436. rm()
  4437. }
  4438. }
  4439. } : {}
  4440. var platformModules = [
  4441. attrs,
  4442. klass,
  4443. events,
  4444. domProps,
  4445. style,
  4446. transition
  4447. ]
  4448. /* */
  4449. // the directive module should be applied last, after all
  4450. // built-in modules have been applied.
  4451. var modules = platformModules.concat(baseModules)
  4452. var patch = createPatchFunction({ nodeOps: nodeOps, modules: modules })
  4453. /**
  4454. * Not type checking this file because flow doesn't like attaching
  4455. * properties to Elements.
  4456. */
  4457. var modelableTagRE = /^input|select|textarea|vue-component-[0-9]+(-[0-9a-zA-Z_\-]*)?$/
  4458. /* istanbul ignore if */
  4459. if (isIE9) {
  4460. // http://www.matts411.com/post/internet-explorer-9-oninput/
  4461. document.addEventListener('selectionchange', function () {
  4462. var el = document.activeElement
  4463. if (el && el.vmodel) {
  4464. trigger(el, 'input')
  4465. }
  4466. })
  4467. }
  4468. var model = {
  4469. bind: function bind (el, binding, vnode) {
  4470. if (process.env.NODE_ENV !== 'production') {
  4471. if (!modelableTagRE.test(vnode.tag)) {
  4472. warn(
  4473. "v-model is not supported on element type: <" + (vnode.tag) + ">. " +
  4474. 'If you are working with contenteditable, it\'s recommended to ' +
  4475. 'wrap a library dedicated for that purpose inside a custom component.',
  4476. vnode.context
  4477. )
  4478. }
  4479. }
  4480. if (vnode.tag === 'select') {
  4481. setSelected(el, binding, vnode.context)
  4482. } else {
  4483. if (!isAndroid) {
  4484. el.addEventListener('compositionstart', onCompositionStart)
  4485. el.addEventListener('compositionend', onCompositionEnd)
  4486. }
  4487. /* istanbul ignore if */
  4488. if (isIE9) {
  4489. el.vmodel = true
  4490. }
  4491. }
  4492. },
  4493. componentUpdated: function componentUpdated (el, binding, vnode) {
  4494. if (vnode.tag === 'select') {
  4495. setSelected(el, binding, vnode.context)
  4496. // in case the options rendered by v-for have changed,
  4497. // it's possible that the value is out-of-sync with the rendered options.
  4498. // detect such cases and filter out values that no longer has a matchig
  4499. // option in the DOM.
  4500. var needReset = el.multiple
  4501. ? binding.value.some(function (v) { return hasNoMatchingOption(v, el.options); })
  4502. : hasNoMatchingOption(binding.value, el.options)
  4503. if (needReset) {
  4504. trigger(el, 'change')
  4505. }
  4506. }
  4507. }
  4508. }
  4509. function setSelected (el, binding, vm) {
  4510. var value = binding.value
  4511. var isMultiple = el.multiple
  4512. if (isMultiple && !Array.isArray(value)) {
  4513. process.env.NODE_ENV !== 'production' && warn(
  4514. "<select multiple v-model=\"" + (binding.expression) + "\"> " +
  4515. "expects an Array value for its binding, but got " + (Object.prototype.toString.call(value).slice(8, -1)),
  4516. vm
  4517. )
  4518. return
  4519. }
  4520. var selected, option
  4521. for (var i = 0, l = el.options.length; i < l; i++) {
  4522. option = el.options[i]
  4523. if (isMultiple) {
  4524. selected = value.indexOf(getValue(option)) > -1
  4525. if (option.selected !== selected) {
  4526. option.selected = selected
  4527. }
  4528. } else {
  4529. if (getValue(option) === value) {
  4530. if (el.selectedIndex !== i) {
  4531. el.selectedIndex = i
  4532. }
  4533. return
  4534. }
  4535. }
  4536. }
  4537. if (!isMultiple) {
  4538. el.selectedIndex = -1
  4539. }
  4540. }
  4541. function hasNoMatchingOption (value, options) {
  4542. for (var i = 0, l = options.length; i < l; i++) {
  4543. if (getValue(options[i]) === value) {
  4544. return false
  4545. }
  4546. }
  4547. return true
  4548. }
  4549. function getValue (option) {
  4550. return '_value' in option
  4551. ? option._value
  4552. : option.value || option.text
  4553. }
  4554. function onCompositionStart (e) {
  4555. e.target.composing = true
  4556. }
  4557. function onCompositionEnd (e) {
  4558. e.target.composing = false
  4559. trigger(e.target, 'input')
  4560. }
  4561. function trigger (el, type) {
  4562. var e = document.createEvent('HTMLEvents')
  4563. e.initEvent(type, true, true)
  4564. el.dispatchEvent(e)
  4565. }
  4566. /* */
  4567. // recursively search for possible transition defined inside the component root
  4568. function locateNode (vnode) {
  4569. return vnode.child && (!vnode.data || !vnode.data.transition)
  4570. ? locateNode(vnode.child._vnode)
  4571. : vnode
  4572. }
  4573. var show = {
  4574. bind: function bind (el, ref, vnode) {
  4575. var value = ref.value;
  4576. vnode = locateNode(vnode)
  4577. var transition = vnode.data && vnode.data.transition
  4578. if (value && transition && transition.appear && !isIE9) {
  4579. enter(vnode)
  4580. }
  4581. var originalDisplay = el.style.display === 'none' ? '' : el.style.display
  4582. el.style.display = value ? originalDisplay : 'none'
  4583. el.__vOriginalDisplay = originalDisplay
  4584. },
  4585. update: function update (el, ref, vnode) {
  4586. var value = ref.value;
  4587. var oldValue = ref.oldValue;
  4588. /* istanbul ignore if */
  4589. if (value === oldValue) return
  4590. vnode = locateNode(vnode)
  4591. var transition = vnode.data && vnode.data.transition
  4592. if (transition && !isIE9) {
  4593. if (value) {
  4594. enter(vnode)
  4595. el.style.display = el.__vOriginalDisplay
  4596. } else {
  4597. leave(vnode, function () {
  4598. el.style.display = 'none'
  4599. })
  4600. }
  4601. } else {
  4602. el.style.display = value ? el.__vOriginalDisplay : 'none'
  4603. }
  4604. }
  4605. }
  4606. var platformDirectives = {
  4607. model: model,
  4608. show: show
  4609. }
  4610. /* */
  4611. // Provides transition support for a single element/component.
  4612. // supports transition mode (out-in / in-out)
  4613. var transitionProps = {
  4614. name: String,
  4615. appear: Boolean,
  4616. css: Boolean,
  4617. mode: String,
  4618. type: String,
  4619. enterClass: String,
  4620. leaveClass: String,
  4621. enterActiveClass: String,
  4622. leaveActiveClass: String,
  4623. appearClass: String,
  4624. appearActiveClass: String
  4625. }
  4626. // in case the child is also an abstract component, e.g. <keep-alive>
  4627. // we want to recrusively retrieve the real component to be rendered
  4628. function getRealChild (vnode) {
  4629. var compOptions = vnode && vnode.componentOptions
  4630. if (compOptions && compOptions.Ctor.options.abstract) {
  4631. return getRealChild(getFirstComponentChild(compOptions.children))
  4632. } else {
  4633. return vnode
  4634. }
  4635. }
  4636. function extractTransitionData (comp) {
  4637. var data = {}
  4638. var options = comp.$options
  4639. // props
  4640. for (var key in options.propsData) {
  4641. data[key] = comp[key]
  4642. }
  4643. // events.
  4644. // extract listeners and pass them directly to the transition methods
  4645. var listeners = options._parentListeners
  4646. for (var key$1 in listeners) {
  4647. data[camelize(key$1)] = listeners[key$1].fn
  4648. }
  4649. return data
  4650. }
  4651. function placeholder (h, rawChild) {
  4652. return /\d-keep-alive$/.test(rawChild.tag)
  4653. ? h('keep-alive')
  4654. : null
  4655. }
  4656. function hasParentTransition (vnode) {
  4657. while ((vnode = vnode.parent)) {
  4658. if (vnode.data.transition) {
  4659. return true
  4660. }
  4661. }
  4662. }
  4663. var Transition = {
  4664. name: 'transition',
  4665. props: transitionProps,
  4666. abstract: true,
  4667. render: function render (h) {
  4668. var this$1 = this;
  4669. var children = this.$slots.default
  4670. if (!children) {
  4671. return
  4672. }
  4673. // filter out text nodes (possible whitespaces)
  4674. children = children.filter(function (c) { return c.tag; })
  4675. /* istanbul ignore if */
  4676. if (!children.length) {
  4677. return
  4678. }
  4679. // warn multiple elements
  4680. if (process.env.NODE_ENV !== 'production' && children.length > 1) {
  4681. warn(
  4682. '<transition> can only be used on a single element. Use ' +
  4683. '<transition-group> for lists.',
  4684. this.$parent
  4685. )
  4686. }
  4687. var mode = this.mode
  4688. // warn invalid mode
  4689. if (process.env.NODE_ENV !== 'production' &&
  4690. mode && mode !== 'in-out' && mode !== 'out-in') {
  4691. warn(
  4692. 'invalid <transition> mode: ' + mode,
  4693. this.$parent
  4694. )
  4695. }
  4696. var rawChild = children[0]
  4697. // if this is a component root node and the component's
  4698. // parent container node also has transition, skip.
  4699. if (hasParentTransition(this.$vnode)) {
  4700. return rawChild
  4701. }
  4702. // apply transition data to child
  4703. // use getRealChild() to ignore abstract components e.g. keep-alive
  4704. var child = getRealChild(rawChild)
  4705. /* istanbul ignore if */
  4706. if (!child) {
  4707. return rawChild
  4708. }
  4709. if (this._leaving) {
  4710. return placeholder(h, rawChild)
  4711. }
  4712. child.key = child.key == null
  4713. ? ("__v" + (child.tag + this._uid) + "__")
  4714. : child.key
  4715. var data = (child.data || (child.data = {})).transition = extractTransitionData(this)
  4716. var oldRawChild = this._vnode
  4717. var oldChild = getRealChild(oldRawChild)
  4718. // mark v-show
  4719. // so that the transition module can hand over the control to the directive
  4720. if (child.data.directives && child.data.directives.some(function (d) { return d.name === 'show'; })) {
  4721. child.data.show = true
  4722. }
  4723. if (oldChild && oldChild.data && oldChild.key !== child.key) {
  4724. // replace old child transition data with fresh one
  4725. // important for dynamic transitions!
  4726. var oldData = oldChild.data.transition = extend({}, data)
  4727. // handle transition mode
  4728. if (mode === 'out-in') {
  4729. // return placeholder node and queue update when leave finishes
  4730. this._leaving = true
  4731. mergeVNodeHook(oldData, 'afterLeave', function () {
  4732. this$1._leaving = false
  4733. this$1.$forceUpdate()
  4734. })
  4735. return placeholder(h, rawChild)
  4736. } else if (mode === 'in-out') {
  4737. var delayedLeave
  4738. var performLeave = function () { delayedLeave() }
  4739. mergeVNodeHook(data, 'afterEnter', performLeave)
  4740. mergeVNodeHook(data, 'enterCancelled', performLeave)
  4741. mergeVNodeHook(oldData, 'delayLeave', function (leave) {
  4742. delayedLeave = leave
  4743. })
  4744. }
  4745. }
  4746. return rawChild
  4747. }
  4748. }
  4749. /* */
  4750. // Provides transition support for list items.
  4751. // supports move transitions using the FLIP technique.
  4752. // Because the vdom's children update algorithm is "unstable" - i.e.
  4753. // it doesn't guarantee the relative positioning of removed elements,
  4754. // we force transition-group to update its children into two passes:
  4755. // in the first pass, we remove all nodes that need to be removed,
  4756. // triggering their leaving transition; in the second pass, we insert/move
  4757. // into the final disired state. This way in the second pass removed
  4758. // nodes will remain where they should be.
  4759. var props = extend({
  4760. tag: String,
  4761. moveClass: String
  4762. }, transitionProps)
  4763. delete props.mode
  4764. var TransitionGroup = {
  4765. props: props,
  4766. render: function render (h) {
  4767. var tag = this.tag || this.$vnode.data.tag || 'span'
  4768. var map = Object.create(null)
  4769. var prevChildren = this.prevChildren = this.children
  4770. var rawChildren = this.$slots.default || []
  4771. var children = this.children = []
  4772. var transitionData = extractTransitionData(this)
  4773. for (var i = 0; i < rawChildren.length; i++) {
  4774. var c = rawChildren[i]
  4775. if (c.tag) {
  4776. if (c.key != null) {
  4777. children.push(c)
  4778. map[c.key] = c
  4779. ;(c.data || (c.data = {})).transition = transitionData
  4780. } else if (process.env.NODE_ENV !== 'production') {
  4781. var opts = c.componentOptions
  4782. var name = opts
  4783. ? (opts.Ctor.options.name || opts.tag)
  4784. : c.tag
  4785. warn(("<transition-group> children must be keyed: <" + name + ">"))
  4786. }
  4787. }
  4788. }
  4789. if (prevChildren) {
  4790. var kept = []
  4791. var removed = []
  4792. for (var i$1 = 0; i$1 < prevChildren.length; i$1++) {
  4793. var c$1 = prevChildren[i$1]
  4794. c$1.data.transition = transitionData
  4795. c$1.data.pos = c$1.elm.getBoundingClientRect()
  4796. if (map[c$1.key]) {
  4797. kept.push(c$1)
  4798. } else {
  4799. removed.push(c$1)
  4800. }
  4801. }
  4802. this.kept = h(tag, null, kept)
  4803. this.removed = removed
  4804. }
  4805. return h(tag, null, children)
  4806. },
  4807. beforeUpdate: function beforeUpdate () {
  4808. // force removing pass
  4809. this.__patch__(
  4810. this._vnode,
  4811. this.kept,
  4812. false, // hydrating
  4813. true // removeOnly (!important, avoids unnecessary moves)
  4814. )
  4815. this._vnode = this.kept
  4816. },
  4817. updated: function updated () {
  4818. var children = this.prevChildren
  4819. var moveClass = this.moveClass || (this.name + '-move')
  4820. if (!children.length || !this.hasMove(children[0].elm, moveClass)) {
  4821. return
  4822. }
  4823. children.forEach(function (c) {
  4824. /* istanbul ignore if */
  4825. if (c.elm._moveCb) {
  4826. c.elm._moveCb()
  4827. }
  4828. /* istanbul ignore if */
  4829. if (c.elm._enterCb) {
  4830. c.elm._enterCb()
  4831. }
  4832. var oldPos = c.data.pos
  4833. var newPos = c.data.pos = c.elm.getBoundingClientRect()
  4834. var dx = oldPos.left - newPos.left
  4835. var dy = oldPos.top - newPos.top
  4836. if (dx || dy) {
  4837. c.data.moved = true
  4838. var s = c.elm.style
  4839. s.transform = s.WebkitTransform = "translate(" + dx + "px," + dy + "px)"
  4840. s.transitionDuration = '0s'
  4841. }
  4842. })
  4843. // force reflow to put everything in position
  4844. var f = document.body.offsetHeight // eslint-disable-line
  4845. children.forEach(function (c) {
  4846. if (c.data.moved) {
  4847. var el = c.elm
  4848. var s = el.style
  4849. addTransitionClass(el, moveClass)
  4850. s.transform = s.WebkitTransform = s.transitionDuration = ''
  4851. el._moveDest = c.data.pos
  4852. el.addEventListener(transitionEndEvent, el._moveCb = function cb (e) {
  4853. if (!e || /transform$/.test(e.propertyName)) {
  4854. el.removeEventListener(transitionEndEvent, cb)
  4855. el._moveCb = null
  4856. removeTransitionClass(el, moveClass)
  4857. }
  4858. })
  4859. }
  4860. })
  4861. },
  4862. methods: {
  4863. hasMove: function hasMove (el, moveClass) {
  4864. /* istanbul ignore if */
  4865. if (!hasTransition) {
  4866. return false
  4867. }
  4868. if (this._hasMove != null) {
  4869. return this._hasMove
  4870. }
  4871. addTransitionClass(el, moveClass)
  4872. var info = getTransitionInfo(el)
  4873. removeTransitionClass(el, moveClass)
  4874. return (this._hasMove = info.hasTransform)
  4875. }
  4876. }
  4877. }
  4878. var platformComponents = {
  4879. Transition: Transition,
  4880. TransitionGroup: TransitionGroup
  4881. }
  4882. /* */
  4883. // install platform specific utils
  4884. Vue.config.isUnknownElement = isUnknownElement
  4885. Vue.config.isReservedTag = isReservedTag
  4886. Vue.config.getTagNamespace = getTagNamespace
  4887. Vue.config.mustUseProp = mustUseProp
  4888. // install platform runtime directives & components
  4889. extend(Vue.options.directives, platformDirectives)
  4890. extend(Vue.options.components, platformComponents)
  4891. // install platform patch function
  4892. Vue.prototype.__patch__ = config._isServer ? noop : patch
  4893. // wrap mount
  4894. Vue.prototype.$mount = function (
  4895. el,
  4896. hydrating
  4897. ) {
  4898. el = el && !config._isServer ? query(el) : undefined
  4899. return this._mount(el, hydrating)
  4900. }
  4901. // devtools global hook
  4902. /* istanbul ignore next */
  4903. setTimeout(function () {
  4904. if (config.devtools) {
  4905. if (devtools) {
  4906. devtools.emit('init', Vue)
  4907. } else if (
  4908. process.env.NODE_ENV !== 'production' &&
  4909. inBrowser && /Chrome\/\d+/.test(window.navigator.userAgent)
  4910. ) {
  4911. console.log(
  4912. 'Download the Vue Devtools for a better development experience:\n' +
  4913. 'https://github.com/vuejs/vue-devtools'
  4914. )
  4915. }
  4916. }
  4917. }, 0)
  4918. module.exports = Vue;