vue.js 248 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530
  1. /*!
  2. * Vue.js v1.0.15
  3. * (c) 2016 Evan You
  4. * Released under the MIT License.
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  8. typeof define === 'function' && define.amd ? define(factory) :
  9. global.Vue = factory();
  10. }(this, function () { 'use strict';
  11. function set(obj, key, val) {
  12. if (hasOwn(obj, key)) {
  13. obj[key] = val;
  14. return;
  15. }
  16. if (obj._isVue) {
  17. set(obj._data, key, val);
  18. return;
  19. }
  20. var ob = obj.__ob__;
  21. if (!ob) {
  22. obj[key] = val;
  23. return;
  24. }
  25. ob.convert(key, val);
  26. ob.dep.notify();
  27. if (ob.vms) {
  28. var i = ob.vms.length;
  29. while (i--) {
  30. var vm = ob.vms[i];
  31. vm._proxy(key);
  32. vm._digest();
  33. }
  34. }
  35. return val;
  36. }
  37. /**
  38. * Delete a property and trigger change if necessary.
  39. *
  40. * @param {Object} obj
  41. * @param {String} key
  42. */
  43. function del(obj, key) {
  44. if (!hasOwn(obj, key)) {
  45. return;
  46. }
  47. delete obj[key];
  48. var ob = obj.__ob__;
  49. if (!ob) {
  50. return;
  51. }
  52. ob.dep.notify();
  53. if (ob.vms) {
  54. var i = ob.vms.length;
  55. while (i--) {
  56. var vm = ob.vms[i];
  57. vm._unproxy(key);
  58. vm._digest();
  59. }
  60. }
  61. }
  62. var hasOwnProperty = Object.prototype.hasOwnProperty;
  63. /**
  64. * Check whether the object has the property.
  65. *
  66. * @param {Object} obj
  67. * @param {String} key
  68. * @return {Boolean}
  69. */
  70. function hasOwn(obj, key) {
  71. return hasOwnProperty.call(obj, key);
  72. }
  73. /**
  74. * Check if an expression is a literal value.
  75. *
  76. * @param {String} exp
  77. * @return {Boolean}
  78. */
  79. var literalValueRE = /^\s?(true|false|[\d\.]+|'[^']*'|"[^"]*")\s?$/;
  80. function isLiteral(exp) {
  81. return literalValueRE.test(exp);
  82. }
  83. /**
  84. * Check if a string starts with $ or _
  85. *
  86. * @param {String} str
  87. * @return {Boolean}
  88. */
  89. function isReserved(str) {
  90. var c = (str + '').charCodeAt(0);
  91. return c === 0x24 || c === 0x5F;
  92. }
  93. /**
  94. * Guard text output, make sure undefined outputs
  95. * empty string
  96. *
  97. * @param {*} value
  98. * @return {String}
  99. */
  100. function _toString(value) {
  101. return value == null ? '' : value.toString();
  102. }
  103. /**
  104. * Check and convert possible numeric strings to numbers
  105. * before setting back to data
  106. *
  107. * @param {*} value
  108. * @return {*|Number}
  109. */
  110. function toNumber(value) {
  111. if (typeof value !== 'string') {
  112. return value;
  113. } else {
  114. var parsed = Number(value);
  115. return isNaN(parsed) ? value : parsed;
  116. }
  117. }
  118. /**
  119. * Convert string boolean literals into real booleans.
  120. *
  121. * @param {*} value
  122. * @return {*|Boolean}
  123. */
  124. function toBoolean(value) {
  125. return value === 'true' ? true : value === 'false' ? false : value;
  126. }
  127. /**
  128. * Strip quotes from a string
  129. *
  130. * @param {String} str
  131. * @return {String | false}
  132. */
  133. function stripQuotes(str) {
  134. var a = str.charCodeAt(0);
  135. var b = str.charCodeAt(str.length - 1);
  136. return a === b && (a === 0x22 || a === 0x27) ? str.slice(1, -1) : str;
  137. }
  138. /**
  139. * Camelize a hyphen-delmited string.
  140. *
  141. * @param {String} str
  142. * @return {String}
  143. */
  144. var camelizeRE = /-(\w)/g;
  145. function camelize(str) {
  146. return str.replace(camelizeRE, toUpper);
  147. }
  148. function toUpper(_, c) {
  149. return c ? c.toUpperCase() : '';
  150. }
  151. /**
  152. * Hyphenate a camelCase string.
  153. *
  154. * @param {String} str
  155. * @return {String}
  156. */
  157. var hyphenateRE = /([a-z\d])([A-Z])/g;
  158. function hyphenate(str) {
  159. return str.replace(hyphenateRE, '$1-$2').toLowerCase();
  160. }
  161. /**
  162. * Converts hyphen/underscore/slash delimitered names into
  163. * camelized classNames.
  164. *
  165. * e.g. my-component => MyComponent
  166. * some_else => SomeElse
  167. * some/comp => SomeComp
  168. *
  169. * @param {String} str
  170. * @return {String}
  171. */
  172. var classifyRE = /(?:^|[-_\/])(\w)/g;
  173. function classify(str) {
  174. return str.replace(classifyRE, toUpper);
  175. }
  176. /**
  177. * Simple bind, faster than native
  178. *
  179. * @param {Function} fn
  180. * @param {Object} ctx
  181. * @return {Function}
  182. */
  183. function bind$1(fn, ctx) {
  184. return function (a) {
  185. var l = arguments.length;
  186. return l ? l > 1 ? fn.apply(ctx, arguments) : fn.call(ctx, a) : fn.call(ctx);
  187. };
  188. }
  189. /**
  190. * Convert an Array-like object to a real Array.
  191. *
  192. * @param {Array-like} list
  193. * @param {Number} [start] - start index
  194. * @return {Array}
  195. */
  196. function toArray(list, start) {
  197. start = start || 0;
  198. var i = list.length - start;
  199. var ret = new Array(i);
  200. while (i--) {
  201. ret[i] = list[i + start];
  202. }
  203. return ret;
  204. }
  205. /**
  206. * Mix properties into target object.
  207. *
  208. * @param {Object} to
  209. * @param {Object} from
  210. */
  211. function extend(to, from) {
  212. var keys = Object.keys(from);
  213. var i = keys.length;
  214. while (i--) {
  215. to[keys[i]] = from[keys[i]];
  216. }
  217. return to;
  218. }
  219. /**
  220. * Quick object check - this is primarily used to tell
  221. * Objects from primitive values when we know the value
  222. * is a JSON-compliant type.
  223. *
  224. * @param {*} obj
  225. * @return {Boolean}
  226. */
  227. function isObject(obj) {
  228. return obj !== null && typeof obj === 'object';
  229. }
  230. /**
  231. * Strict object type check. Only returns true
  232. * for plain JavaScript objects.
  233. *
  234. * @param {*} obj
  235. * @return {Boolean}
  236. */
  237. var toString = Object.prototype.toString;
  238. var OBJECT_STRING = '[object Object]';
  239. function isPlainObject(obj) {
  240. return toString.call(obj) === OBJECT_STRING;
  241. }
  242. /**
  243. * Array type check.
  244. *
  245. * @param {*} obj
  246. * @return {Boolean}
  247. */
  248. var isArray = Array.isArray;
  249. /**
  250. * Define a non-enumerable property
  251. *
  252. * @param {Object} obj
  253. * @param {String} key
  254. * @param {*} val
  255. * @param {Boolean} [enumerable]
  256. */
  257. function def(obj, key, val, enumerable) {
  258. Object.defineProperty(obj, key, {
  259. value: val,
  260. enumerable: !!enumerable,
  261. writable: true,
  262. configurable: true
  263. });
  264. }
  265. /**
  266. * Debounce a function so it only gets called after the
  267. * input stops arriving after the given wait period.
  268. *
  269. * @param {Function} func
  270. * @param {Number} wait
  271. * @return {Function} - the debounced function
  272. */
  273. function _debounce(func, wait) {
  274. var timeout, args, context, timestamp, result;
  275. var later = function later() {
  276. var last = Date.now() - timestamp;
  277. if (last < wait && last >= 0) {
  278. timeout = setTimeout(later, wait - last);
  279. } else {
  280. timeout = null;
  281. result = func.apply(context, args);
  282. if (!timeout) context = args = null;
  283. }
  284. };
  285. return function () {
  286. context = this;
  287. args = arguments;
  288. timestamp = Date.now();
  289. if (!timeout) {
  290. timeout = setTimeout(later, wait);
  291. }
  292. return result;
  293. };
  294. }
  295. /**
  296. * Manual indexOf because it's slightly faster than
  297. * native.
  298. *
  299. * @param {Array} arr
  300. * @param {*} obj
  301. */
  302. function indexOf(arr, obj) {
  303. var i = arr.length;
  304. while (i--) {
  305. if (arr[i] === obj) return i;
  306. }
  307. return -1;
  308. }
  309. /**
  310. * Make a cancellable version of an async callback.
  311. *
  312. * @param {Function} fn
  313. * @return {Function}
  314. */
  315. function cancellable(fn) {
  316. var cb = function cb() {
  317. if (!cb.cancelled) {
  318. return fn.apply(this, arguments);
  319. }
  320. };
  321. cb.cancel = function () {
  322. cb.cancelled = true;
  323. };
  324. return cb;
  325. }
  326. /**
  327. * Check if two values are loosely equal - that is,
  328. * if they are plain objects, do they have the same shape?
  329. *
  330. * @param {*} a
  331. * @param {*} b
  332. * @return {Boolean}
  333. */
  334. function looseEqual(a, b) {
  335. /* eslint-disable eqeqeq */
  336. return a == b || (isObject(a) && isObject(b) ? JSON.stringify(a) === JSON.stringify(b) : false);
  337. /* eslint-enable eqeqeq */
  338. }
  339. var hasProto = ('__proto__' in {});
  340. // Browser environment sniffing
  341. var inBrowser = typeof window !== 'undefined' && Object.prototype.toString.call(window) !== '[object Object]';
  342. var isIE9 = inBrowser && navigator.userAgent.toLowerCase().indexOf('msie 9.0') > 0;
  343. var isAndroid = inBrowser && navigator.userAgent.toLowerCase().indexOf('android') > 0;
  344. var transitionProp = undefined;
  345. var transitionEndEvent = undefined;
  346. var animationProp = undefined;
  347. var animationEndEvent = undefined;
  348. // Transition property/event sniffing
  349. if (inBrowser && !isIE9) {
  350. var isWebkitTrans = window.ontransitionend === undefined && window.onwebkittransitionend !== undefined;
  351. var isWebkitAnim = window.onanimationend === undefined && window.onwebkitanimationend !== undefined;
  352. transitionProp = isWebkitTrans ? 'WebkitTransition' : 'transition';
  353. transitionEndEvent = isWebkitTrans ? 'webkitTransitionEnd' : 'transitionend';
  354. animationProp = isWebkitAnim ? 'WebkitAnimation' : 'animation';
  355. animationEndEvent = isWebkitAnim ? 'webkitAnimationEnd' : 'animationend';
  356. }
  357. /**
  358. * Defer a task to execute it asynchronously. Ideally this
  359. * should be executed as a microtask, so we leverage
  360. * MutationObserver if it's available, and fallback to
  361. * setTimeout(0).
  362. *
  363. * @param {Function} cb
  364. * @param {Object} ctx
  365. */
  366. var nextTick = (function () {
  367. var callbacks = [];
  368. var pending = false;
  369. var timerFunc;
  370. function nextTickHandler() {
  371. pending = false;
  372. var copies = callbacks.slice(0);
  373. callbacks = [];
  374. for (var i = 0; i < copies.length; i++) {
  375. copies[i]();
  376. }
  377. }
  378. /* istanbul ignore if */
  379. if (typeof MutationObserver !== 'undefined') {
  380. var counter = 1;
  381. var observer = new MutationObserver(nextTickHandler);
  382. var textNode = document.createTextNode(counter);
  383. observer.observe(textNode, {
  384. characterData: true
  385. });
  386. timerFunc = function () {
  387. counter = (counter + 1) % 2;
  388. textNode.data = counter;
  389. };
  390. } else {
  391. timerFunc = setTimeout;
  392. }
  393. return function (cb, ctx) {
  394. var func = ctx ? function () {
  395. cb.call(ctx);
  396. } : cb;
  397. callbacks.push(func);
  398. if (pending) return;
  399. pending = true;
  400. timerFunc(nextTickHandler, 0);
  401. };
  402. })();
  403. function Cache(limit) {
  404. this.size = 0;
  405. this.limit = limit;
  406. this.head = this.tail = undefined;
  407. this._keymap = Object.create(null);
  408. }
  409. var p = Cache.prototype;
  410. /**
  411. * Put <value> into the cache associated with <key>.
  412. * Returns the entry which was removed to make room for
  413. * the new entry. Otherwise undefined is returned.
  414. * (i.e. if there was enough room already).
  415. *
  416. * @param {String} key
  417. * @param {*} value
  418. * @return {Entry|undefined}
  419. */
  420. p.put = function (key, value) {
  421. var removed;
  422. if (this.size === this.limit) {
  423. removed = this.shift();
  424. }
  425. var entry = this.get(key, true);
  426. if (!entry) {
  427. entry = {
  428. key: key
  429. };
  430. this._keymap[key] = entry;
  431. if (this.tail) {
  432. this.tail.newer = entry;
  433. entry.older = this.tail;
  434. } else {
  435. this.head = entry;
  436. }
  437. this.tail = entry;
  438. this.size++;
  439. }
  440. entry.value = value;
  441. return removed;
  442. };
  443. /**
  444. * Purge the least recently used (oldest) entry from the
  445. * cache. Returns the removed entry or undefined if the
  446. * cache was empty.
  447. */
  448. p.shift = function () {
  449. var entry = this.head;
  450. if (entry) {
  451. this.head = this.head.newer;
  452. this.head.older = undefined;
  453. entry.newer = entry.older = undefined;
  454. this._keymap[entry.key] = undefined;
  455. this.size--;
  456. }
  457. return entry;
  458. };
  459. /**
  460. * Get and register recent use of <key>. Returns the value
  461. * associated with <key> or undefined if not in cache.
  462. *
  463. * @param {String} key
  464. * @param {Boolean} returnEntry
  465. * @return {Entry|*}
  466. */
  467. p.get = function (key, returnEntry) {
  468. var entry = this._keymap[key];
  469. if (entry === undefined) return;
  470. if (entry === this.tail) {
  471. return returnEntry ? entry : entry.value;
  472. }
  473. // HEAD--------------TAIL
  474. // <.older .newer>
  475. // <--- add direction --
  476. // A B C <D> E
  477. if (entry.newer) {
  478. if (entry === this.head) {
  479. this.head = entry.newer;
  480. }
  481. entry.newer.older = entry.older; // C <-- E.
  482. }
  483. if (entry.older) {
  484. entry.older.newer = entry.newer; // C. --> E
  485. }
  486. entry.newer = undefined; // D --x
  487. entry.older = this.tail; // D. --> E
  488. if (this.tail) {
  489. this.tail.newer = entry; // E. <-- D
  490. }
  491. this.tail = entry;
  492. return returnEntry ? entry : entry.value;
  493. };
  494. var cache$1 = new Cache(1000);
  495. var filterTokenRE = /[^\s'"]+|'[^']*'|"[^"]*"/g;
  496. var reservedArgRE = /^in$|^-?\d+/;
  497. /**
  498. * Parser state
  499. */
  500. var str;
  501. var dir;
  502. var c;
  503. var prev;
  504. var i;
  505. var l;
  506. var lastFilterIndex;
  507. var inSingle;
  508. var inDouble;
  509. var curly;
  510. var square;
  511. var paren;
  512. /**
  513. * Push a filter to the current directive object
  514. */
  515. function pushFilter() {
  516. var exp = str.slice(lastFilterIndex, i).trim();
  517. var filter;
  518. if (exp) {
  519. filter = {};
  520. var tokens = exp.match(filterTokenRE);
  521. filter.name = tokens[0];
  522. if (tokens.length > 1) {
  523. filter.args = tokens.slice(1).map(processFilterArg);
  524. }
  525. }
  526. if (filter) {
  527. (dir.filters = dir.filters || []).push(filter);
  528. }
  529. lastFilterIndex = i + 1;
  530. }
  531. /**
  532. * Check if an argument is dynamic and strip quotes.
  533. *
  534. * @param {String} arg
  535. * @return {Object}
  536. */
  537. function processFilterArg(arg) {
  538. if (reservedArgRE.test(arg)) {
  539. return {
  540. value: toNumber(arg),
  541. dynamic: false
  542. };
  543. } else {
  544. var stripped = stripQuotes(arg);
  545. var dynamic = stripped === arg;
  546. return {
  547. value: dynamic ? arg : stripped,
  548. dynamic: dynamic
  549. };
  550. }
  551. }
  552. /**
  553. * Parse a directive value and extract the expression
  554. * and its filters into a descriptor.
  555. *
  556. * Example:
  557. *
  558. * "a + 1 | uppercase" will yield:
  559. * {
  560. * expression: 'a + 1',
  561. * filters: [
  562. * { name: 'uppercase', args: null }
  563. * ]
  564. * }
  565. *
  566. * @param {String} str
  567. * @return {Object}
  568. */
  569. function parseDirective(s) {
  570. var hit = cache$1.get(s);
  571. if (hit) {
  572. return hit;
  573. }
  574. // reset parser state
  575. str = s;
  576. inSingle = inDouble = false;
  577. curly = square = paren = 0;
  578. lastFilterIndex = 0;
  579. dir = {};
  580. for (i = 0, l = str.length; i < l; i++) {
  581. prev = c;
  582. c = str.charCodeAt(i);
  583. if (inSingle) {
  584. // check single quote
  585. if (c === 0x27 && prev !== 0x5C) inSingle = !inSingle;
  586. } else if (inDouble) {
  587. // check double quote
  588. if (c === 0x22 && prev !== 0x5C) inDouble = !inDouble;
  589. } else if (c === 0x7C && // pipe
  590. str.charCodeAt(i + 1) !== 0x7C && str.charCodeAt(i - 1) !== 0x7C) {
  591. if (dir.expression == null) {
  592. // first filter, end of expression
  593. lastFilterIndex = i + 1;
  594. dir.expression = str.slice(0, i).trim();
  595. } else {
  596. // already has filter
  597. pushFilter();
  598. }
  599. } else {
  600. switch (c) {
  601. case 0x22:
  602. inDouble = true;break; // "
  603. case 0x27:
  604. inSingle = true;break; // '
  605. case 0x28:
  606. paren++;break; // (
  607. case 0x29:
  608. paren--;break; // )
  609. case 0x5B:
  610. square++;break; // [
  611. case 0x5D:
  612. square--;break; // ]
  613. case 0x7B:
  614. curly++;break; // {
  615. case 0x7D:
  616. curly--;break; // }
  617. }
  618. }
  619. }
  620. if (dir.expression == null) {
  621. dir.expression = str.slice(0, i).trim();
  622. } else if (lastFilterIndex !== 0) {
  623. pushFilter();
  624. }
  625. cache$1.put(s, dir);
  626. return dir;
  627. }
  628. var directive = Object.freeze({
  629. parseDirective: parseDirective
  630. });
  631. var regexEscapeRE = /[-.*+?^${}()|[\]\/\\]/g;
  632. var cache = undefined;
  633. var tagRE = undefined;
  634. var htmlRE = undefined;
  635. /**
  636. * Escape a string so it can be used in a RegExp
  637. * constructor.
  638. *
  639. * @param {String} str
  640. */
  641. function escapeRegex(str) {
  642. return str.replace(regexEscapeRE, '\\$&');
  643. }
  644. function compileRegex() {
  645. var open = escapeRegex(config.delimiters[0]);
  646. var close = escapeRegex(config.delimiters[1]);
  647. var unsafeOpen = escapeRegex(config.unsafeDelimiters[0]);
  648. var unsafeClose = escapeRegex(config.unsafeDelimiters[1]);
  649. tagRE = new RegExp(unsafeOpen + '(.+?)' + unsafeClose + '|' + open + '(.+?)' + close, 'g');
  650. htmlRE = new RegExp('^' + unsafeOpen + '.*' + unsafeClose + '$');
  651. // reset cache
  652. cache = new Cache(1000);
  653. }
  654. /**
  655. * Parse a template text string into an array of tokens.
  656. *
  657. * @param {String} text
  658. * @return {Array<Object> | null}
  659. * - {String} type
  660. * - {String} value
  661. * - {Boolean} [html]
  662. * - {Boolean} [oneTime]
  663. */
  664. function parseText(text) {
  665. if (!cache) {
  666. compileRegex();
  667. }
  668. var hit = cache.get(text);
  669. if (hit) {
  670. return hit;
  671. }
  672. text = text.replace(/\n/g, '');
  673. if (!tagRE.test(text)) {
  674. return null;
  675. }
  676. var tokens = [];
  677. var lastIndex = tagRE.lastIndex = 0;
  678. var match, index, html, value, first, oneTime;
  679. /* eslint-disable no-cond-assign */
  680. while (match = tagRE.exec(text)) {
  681. /* eslint-enable no-cond-assign */
  682. index = match.index;
  683. // push text token
  684. if (index > lastIndex) {
  685. tokens.push({
  686. value: text.slice(lastIndex, index)
  687. });
  688. }
  689. // tag token
  690. html = htmlRE.test(match[0]);
  691. value = html ? match[1] : match[2];
  692. first = value.charCodeAt(0);
  693. oneTime = first === 42; // *
  694. value = oneTime ? value.slice(1) : value;
  695. tokens.push({
  696. tag: true,
  697. value: value.trim(),
  698. html: html,
  699. oneTime: oneTime
  700. });
  701. lastIndex = index + match[0].length;
  702. }
  703. if (lastIndex < text.length) {
  704. tokens.push({
  705. value: text.slice(lastIndex)
  706. });
  707. }
  708. cache.put(text, tokens);
  709. return tokens;
  710. }
  711. /**
  712. * Format a list of tokens into an expression.
  713. * e.g. tokens parsed from 'a {{b}} c' can be serialized
  714. * into one single expression as '"a " + b + " c"'.
  715. *
  716. * @param {Array} tokens
  717. * @param {Vue} [vm]
  718. * @return {String}
  719. */
  720. function tokensToExp(tokens, vm) {
  721. if (tokens.length > 1) {
  722. return tokens.map(function (token) {
  723. return formatToken(token, vm);
  724. }).join('+');
  725. } else {
  726. return formatToken(tokens[0], vm, true);
  727. }
  728. }
  729. /**
  730. * Format a single token.
  731. *
  732. * @param {Object} token
  733. * @param {Vue} [vm]
  734. * @param {Boolean} [single]
  735. * @return {String}
  736. */
  737. function formatToken(token, vm, single) {
  738. return token.tag ? token.oneTime && vm ? '"' + vm.$eval(token.value) + '"' : inlineFilters(token.value, single) : '"' + token.value + '"';
  739. }
  740. /**
  741. * For an attribute with multiple interpolation tags,
  742. * e.g. attr="some-{{thing | filter}}", in order to combine
  743. * the whole thing into a single watchable expression, we
  744. * have to inline those filters. This function does exactly
  745. * that. This is a bit hacky but it avoids heavy changes
  746. * to directive parser and watcher mechanism.
  747. *
  748. * @param {String} exp
  749. * @param {Boolean} single
  750. * @return {String}
  751. */
  752. var filterRE$1 = /[^|]\|[^|]/;
  753. function inlineFilters(exp, single) {
  754. if (!filterRE$1.test(exp)) {
  755. return single ? exp : '(' + exp + ')';
  756. } else {
  757. var dir = parseDirective(exp);
  758. if (!dir.filters) {
  759. return '(' + exp + ')';
  760. } else {
  761. return 'this._applyFilters(' + dir.expression + // value
  762. ',null,' + // oldValue (null for read)
  763. JSON.stringify(dir.filters) + // filter descriptors
  764. ',false)'; // write?
  765. }
  766. }
  767. }
  768. var text$1 = Object.freeze({
  769. compileRegex: compileRegex,
  770. parseText: parseText,
  771. tokensToExp: tokensToExp
  772. });
  773. var delimiters = ['{{', '}}'];
  774. var unsafeDelimiters = ['{{{', '}}}'];
  775. var config = Object.defineProperties({
  776. /**
  777. * Whether to print debug messages.
  778. * Also enables stack trace for warnings.
  779. *
  780. * @type {Boolean}
  781. */
  782. debug: false,
  783. /**
  784. * Whether to suppress warnings.
  785. *
  786. * @type {Boolean}
  787. */
  788. silent: false,
  789. /**
  790. * Whether to use async rendering.
  791. */
  792. async: true,
  793. /**
  794. * Whether to warn against errors caught when evaluating
  795. * expressions.
  796. */
  797. warnExpressionErrors: true,
  798. /**
  799. * Whether or not to handle fully object properties which
  800. * are already backed by getters and seters. Depending on
  801. * use case and environment, this might introduce non-neglible
  802. * performance penalties.
  803. */
  804. convertAllProperties: false,
  805. /**
  806. * Internal flag to indicate the delimiters have been
  807. * changed.
  808. *
  809. * @type {Boolean}
  810. */
  811. _delimitersChanged: true,
  812. /**
  813. * List of asset types that a component can own.
  814. *
  815. * @type {Array}
  816. */
  817. _assetTypes: ['component', 'directive', 'elementDirective', 'filter', 'transition', 'partial'],
  818. /**
  819. * prop binding modes
  820. */
  821. _propBindingModes: {
  822. ONE_WAY: 0,
  823. TWO_WAY: 1,
  824. ONE_TIME: 2
  825. },
  826. /**
  827. * Max circular updates allowed in a batcher flush cycle.
  828. */
  829. _maxUpdateCount: 100
  830. }, {
  831. delimiters: { /**
  832. * Interpolation delimiters. Changing these would trigger
  833. * the text parser to re-compile the regular expressions.
  834. *
  835. * @type {Array<String>}
  836. */
  837. get: function get() {
  838. return delimiters;
  839. },
  840. set: function set(val) {
  841. delimiters = val;
  842. compileRegex();
  843. },
  844. configurable: true,
  845. enumerable: true
  846. },
  847. unsafeDelimiters: {
  848. get: function get() {
  849. return unsafeDelimiters;
  850. },
  851. set: function set(val) {
  852. unsafeDelimiters = val;
  853. compileRegex();
  854. },
  855. configurable: true,
  856. enumerable: true
  857. }
  858. });
  859. var warn = undefined;
  860. if ('development' !== 'production') {
  861. (function () {
  862. var hasConsole = typeof console !== 'undefined';
  863. warn = function (msg, e) {
  864. if (hasConsole && (!config.silent || config.debug)) {
  865. console.warn('[Vue warn]: ' + msg);
  866. /* istanbul ignore if */
  867. if (config.debug) {
  868. if (e) {
  869. throw e;
  870. } else {
  871. console.warn(new Error('Warning Stack Trace').stack);
  872. }
  873. }
  874. }
  875. };
  876. })();
  877. }
  878. /**
  879. * Append with transition.
  880. *
  881. * @param {Element} el
  882. * @param {Element} target
  883. * @param {Vue} vm
  884. * @param {Function} [cb]
  885. */
  886. function appendWithTransition(el, target, vm, cb) {
  887. applyTransition(el, 1, function () {
  888. target.appendChild(el);
  889. }, vm, cb);
  890. }
  891. /**
  892. * InsertBefore with transition.
  893. *
  894. * @param {Element} el
  895. * @param {Element} target
  896. * @param {Vue} vm
  897. * @param {Function} [cb]
  898. */
  899. function beforeWithTransition(el, target, vm, cb) {
  900. applyTransition(el, 1, function () {
  901. before(el, target);
  902. }, vm, cb);
  903. }
  904. /**
  905. * Remove with transition.
  906. *
  907. * @param {Element} el
  908. * @param {Vue} vm
  909. * @param {Function} [cb]
  910. */
  911. function removeWithTransition(el, vm, cb) {
  912. applyTransition(el, -1, function () {
  913. remove(el);
  914. }, vm, cb);
  915. }
  916. /**
  917. * Apply transitions with an operation callback.
  918. *
  919. * @param {Element} el
  920. * @param {Number} direction
  921. * 1: enter
  922. * -1: leave
  923. * @param {Function} op - the actual DOM operation
  924. * @param {Vue} vm
  925. * @param {Function} [cb]
  926. */
  927. function applyTransition(el, direction, op, vm, cb) {
  928. var transition = el.__v_trans;
  929. if (!transition ||
  930. // skip if there are no js hooks and CSS transition is
  931. // not supported
  932. !transition.hooks && !transitionEndEvent ||
  933. // skip transitions for initial compile
  934. !vm._isCompiled ||
  935. // if the vm is being manipulated by a parent directive
  936. // during the parent's compilation phase, skip the
  937. // animation.
  938. vm.$parent && !vm.$parent._isCompiled) {
  939. op();
  940. if (cb) cb();
  941. return;
  942. }
  943. var action = direction > 0 ? 'enter' : 'leave';
  944. transition[action](op, cb);
  945. }
  946. /**
  947. * Query an element selector if it's not an element already.
  948. *
  949. * @param {String|Element} el
  950. * @return {Element}
  951. */
  952. function query(el) {
  953. if (typeof el === 'string') {
  954. var selector = el;
  955. el = document.querySelector(el);
  956. if (!el) {
  957. 'development' !== 'production' && warn('Cannot find element: ' + selector);
  958. }
  959. }
  960. return el;
  961. }
  962. /**
  963. * Check if a node is in the document.
  964. * Note: document.documentElement.contains should work here
  965. * but always returns false for comment nodes in phantomjs,
  966. * making unit tests difficult. This is fixed by doing the
  967. * contains() check on the node's parentNode instead of
  968. * the node itself.
  969. *
  970. * @param {Node} node
  971. * @return {Boolean}
  972. */
  973. function inDoc(node) {
  974. var doc = document.documentElement;
  975. var parent = node && node.parentNode;
  976. return doc === node || doc === parent || !!(parent && parent.nodeType === 1 && doc.contains(parent));
  977. }
  978. /**
  979. * Get and remove an attribute from a node.
  980. *
  981. * @param {Node} node
  982. * @param {String} _attr
  983. */
  984. function getAttr(node, _attr) {
  985. var val = node.getAttribute(_attr);
  986. if (val !== null) {
  987. node.removeAttribute(_attr);
  988. }
  989. return val;
  990. }
  991. /**
  992. * Get an attribute with colon or v-bind: prefix.
  993. *
  994. * @param {Node} node
  995. * @param {String} name
  996. * @return {String|null}
  997. */
  998. function getBindAttr(node, name) {
  999. var val = getAttr(node, ':' + name);
  1000. if (val === null) {
  1001. val = getAttr(node, 'v-bind:' + name);
  1002. }
  1003. return val;
  1004. }
  1005. /**
  1006. * Check the presence of a bind attribute.
  1007. *
  1008. * @param {Node} node
  1009. * @param {String} name
  1010. * @return {Boolean}
  1011. */
  1012. function hasBindAttr(node, name) {
  1013. return node.hasAttribute(name) || node.hasAttribute(':' + name) || node.hasAttribute('v-bind:' + name);
  1014. }
  1015. /**
  1016. * Insert el before target
  1017. *
  1018. * @param {Element} el
  1019. * @param {Element} target
  1020. */
  1021. function before(el, target) {
  1022. target.parentNode.insertBefore(el, target);
  1023. }
  1024. /**
  1025. * Insert el after target
  1026. *
  1027. * @param {Element} el
  1028. * @param {Element} target
  1029. */
  1030. function after(el, target) {
  1031. if (target.nextSibling) {
  1032. before(el, target.nextSibling);
  1033. } else {
  1034. target.parentNode.appendChild(el);
  1035. }
  1036. }
  1037. /**
  1038. * Remove el from DOM
  1039. *
  1040. * @param {Element} el
  1041. */
  1042. function remove(el) {
  1043. el.parentNode.removeChild(el);
  1044. }
  1045. /**
  1046. * Prepend el to target
  1047. *
  1048. * @param {Element} el
  1049. * @param {Element} target
  1050. */
  1051. function prepend(el, target) {
  1052. if (target.firstChild) {
  1053. before(el, target.firstChild);
  1054. } else {
  1055. target.appendChild(el);
  1056. }
  1057. }
  1058. /**
  1059. * Replace target with el
  1060. *
  1061. * @param {Element} target
  1062. * @param {Element} el
  1063. */
  1064. function replace(target, el) {
  1065. var parent = target.parentNode;
  1066. if (parent) {
  1067. parent.replaceChild(el, target);
  1068. }
  1069. }
  1070. /**
  1071. * Add event listener shorthand.
  1072. *
  1073. * @param {Element} el
  1074. * @param {String} event
  1075. * @param {Function} cb
  1076. */
  1077. function on$1(el, event, cb) {
  1078. el.addEventListener(event, cb);
  1079. }
  1080. /**
  1081. * Remove event listener shorthand.
  1082. *
  1083. * @param {Element} el
  1084. * @param {String} event
  1085. * @param {Function} cb
  1086. */
  1087. function off(el, event, cb) {
  1088. el.removeEventListener(event, cb);
  1089. }
  1090. /**
  1091. * In IE9, setAttribute('class') will result in empty class
  1092. * if the element also has the :class attribute; However in
  1093. * PhantomJS, setting `className` does not work on SVG elements...
  1094. * So we have to do a conditional check here.
  1095. *
  1096. * @param {Element} el
  1097. * @param {String} cls
  1098. */
  1099. function setClass(el, cls) {
  1100. /* istanbul ignore if */
  1101. if (isIE9 && !(el instanceof SVGElement)) {
  1102. el.className = cls;
  1103. } else {
  1104. el.setAttribute('class', cls);
  1105. }
  1106. }
  1107. /**
  1108. * Add class with compatibility for IE & SVG
  1109. *
  1110. * @param {Element} el
  1111. * @param {String} cls
  1112. */
  1113. function addClass(el, cls) {
  1114. if (el.classList) {
  1115. el.classList.add(cls);
  1116. } else {
  1117. var cur = ' ' + (el.getAttribute('class') || '') + ' ';
  1118. if (cur.indexOf(' ' + cls + ' ') < 0) {
  1119. setClass(el, (cur + cls).trim());
  1120. }
  1121. }
  1122. }
  1123. /**
  1124. * Remove class with compatibility for IE & SVG
  1125. *
  1126. * @param {Element} el
  1127. * @param {String} cls
  1128. */
  1129. function removeClass(el, cls) {
  1130. if (el.classList) {
  1131. el.classList.remove(cls);
  1132. } else {
  1133. var cur = ' ' + (el.getAttribute('class') || '') + ' ';
  1134. var tar = ' ' + cls + ' ';
  1135. while (cur.indexOf(tar) >= 0) {
  1136. cur = cur.replace(tar, ' ');
  1137. }
  1138. setClass(el, cur.trim());
  1139. }
  1140. if (!el.className) {
  1141. el.removeAttribute('class');
  1142. }
  1143. }
  1144. /**
  1145. * Extract raw content inside an element into a temporary
  1146. * container div
  1147. *
  1148. * @param {Element} el
  1149. * @param {Boolean} asFragment
  1150. * @return {Element}
  1151. */
  1152. function extractContent(el, asFragment) {
  1153. var child;
  1154. var rawContent;
  1155. /* istanbul ignore if */
  1156. if (isTemplate(el) && el.content instanceof DocumentFragment) {
  1157. el = el.content;
  1158. }
  1159. if (el.hasChildNodes()) {
  1160. trimNode(el);
  1161. rawContent = asFragment ? document.createDocumentFragment() : document.createElement('div');
  1162. /* eslint-disable no-cond-assign */
  1163. while (child = el.firstChild) {
  1164. /* eslint-enable no-cond-assign */
  1165. rawContent.appendChild(child);
  1166. }
  1167. }
  1168. return rawContent;
  1169. }
  1170. /**
  1171. * Trim possible empty head/tail textNodes inside a parent.
  1172. *
  1173. * @param {Node} node
  1174. */
  1175. function trimNode(node) {
  1176. trim(node, node.firstChild);
  1177. trim(node, node.lastChild);
  1178. }
  1179. function trim(parent, node) {
  1180. if (node && node.nodeType === 3 && !node.data.trim()) {
  1181. parent.removeChild(node);
  1182. }
  1183. }
  1184. /**
  1185. * Check if an element is a template tag.
  1186. * Note if the template appears inside an SVG its tagName
  1187. * will be in lowercase.
  1188. *
  1189. * @param {Element} el
  1190. */
  1191. function isTemplate(el) {
  1192. return el.tagName && el.tagName.toLowerCase() === 'template';
  1193. }
  1194. /**
  1195. * Create an "anchor" for performing dom insertion/removals.
  1196. * This is used in a number of scenarios:
  1197. * - fragment instance
  1198. * - v-html
  1199. * - v-if
  1200. * - v-for
  1201. * - component
  1202. *
  1203. * @param {String} content
  1204. * @param {Boolean} persist - IE trashes empty textNodes on
  1205. * cloneNode(true), so in certain
  1206. * cases the anchor needs to be
  1207. * non-empty to be persisted in
  1208. * templates.
  1209. * @return {Comment|Text}
  1210. */
  1211. function createAnchor(content, persist) {
  1212. var anchor = config.debug ? document.createComment(content) : document.createTextNode(persist ? ' ' : '');
  1213. anchor.__vue_anchor = true;
  1214. return anchor;
  1215. }
  1216. /**
  1217. * Find a component ref attribute that starts with $.
  1218. *
  1219. * @param {Element} node
  1220. * @return {String|undefined}
  1221. */
  1222. var refRE = /^v-ref:/;
  1223. function findRef(node) {
  1224. if (node.hasAttributes()) {
  1225. var attrs = node.attributes;
  1226. for (var i = 0, l = attrs.length; i < l; i++) {
  1227. var name = attrs[i].name;
  1228. if (refRE.test(name)) {
  1229. return camelize(name.replace(refRE, ''));
  1230. }
  1231. }
  1232. }
  1233. }
  1234. /**
  1235. * Map a function to a range of nodes .
  1236. *
  1237. * @param {Node} node
  1238. * @param {Node} end
  1239. * @param {Function} op
  1240. */
  1241. function mapNodeRange(node, end, op) {
  1242. var next;
  1243. while (node !== end) {
  1244. next = node.nextSibling;
  1245. op(node);
  1246. node = next;
  1247. }
  1248. op(end);
  1249. }
  1250. /**
  1251. * Remove a range of nodes with transition, store
  1252. * the nodes in a fragment with correct ordering,
  1253. * and call callback when done.
  1254. *
  1255. * @param {Node} start
  1256. * @param {Node} end
  1257. * @param {Vue} vm
  1258. * @param {DocumentFragment} frag
  1259. * @param {Function} cb
  1260. */
  1261. function removeNodeRange(start, end, vm, frag, cb) {
  1262. var done = false;
  1263. var removed = 0;
  1264. var nodes = [];
  1265. mapNodeRange(start, end, function (node) {
  1266. if (node === end) done = true;
  1267. nodes.push(node);
  1268. removeWithTransition(node, vm, onRemoved);
  1269. });
  1270. function onRemoved() {
  1271. removed++;
  1272. if (done && removed >= nodes.length) {
  1273. for (var i = 0; i < nodes.length; i++) {
  1274. frag.appendChild(nodes[i]);
  1275. }
  1276. cb && cb();
  1277. }
  1278. }
  1279. }
  1280. var commonTagRE = /^(div|p|span|img|a|b|i|br|ul|ol|li|h1|h2|h3|h4|h5|h6|code|pre|table|th|td|tr|form|label|input|select|option|nav|article|section|header|footer)$/;
  1281. var reservedTagRE = /^(slot|partial|component)$/;
  1282. /**
  1283. * Check if an element is a component, if yes return its
  1284. * component id.
  1285. *
  1286. * @param {Element} el
  1287. * @param {Object} options
  1288. * @return {Object|undefined}
  1289. */
  1290. function checkComponentAttr(el, options) {
  1291. var tag = el.tagName.toLowerCase();
  1292. var hasAttrs = el.hasAttributes();
  1293. if (!commonTagRE.test(tag) && !reservedTagRE.test(tag)) {
  1294. if (resolveAsset(options, 'components', tag)) {
  1295. return { id: tag };
  1296. } else {
  1297. var is = hasAttrs && getIsBinding(el);
  1298. if (is) {
  1299. return is;
  1300. } else if ('development' !== 'production') {
  1301. if (tag.indexOf('-') > -1 || /HTMLUnknownElement/.test(el.toString()) &&
  1302. // Chrome returns unknown for several HTML5 elements.
  1303. // https://code.google.com/p/chromium/issues/detail?id=540526
  1304. !/^(data|time|rtc|rb)$/.test(tag)) {
  1305. warn('Unknown custom element: <' + tag + '> - did you ' + 'register the component correctly?');
  1306. }
  1307. }
  1308. }
  1309. } else if (hasAttrs) {
  1310. return getIsBinding(el);
  1311. }
  1312. }
  1313. /**
  1314. * Get "is" binding from an element.
  1315. *
  1316. * @param {Element} el
  1317. * @return {Object|undefined}
  1318. */
  1319. function getIsBinding(el) {
  1320. // dynamic syntax
  1321. var exp = getAttr(el, 'is');
  1322. if (exp != null) {
  1323. return { id: exp };
  1324. } else {
  1325. exp = getBindAttr(el, 'is');
  1326. if (exp != null) {
  1327. return { id: exp, dynamic: true };
  1328. }
  1329. }
  1330. }
  1331. /**
  1332. * Set a prop's initial value on a vm and its data object.
  1333. *
  1334. * @param {Vue} vm
  1335. * @param {Object} prop
  1336. * @param {*} value
  1337. */
  1338. function initProp(vm, prop, value) {
  1339. var key = prop.path;
  1340. value = coerceProp(prop, value);
  1341. vm[key] = vm._data[key] = assertProp(prop, value) ? value : undefined;
  1342. }
  1343. /**
  1344. * Assert whether a prop is valid.
  1345. *
  1346. * @param {Object} prop
  1347. * @param {*} value
  1348. */
  1349. function assertProp(prop, value) {
  1350. // if a prop is not provided and is not required,
  1351. // skip the check.
  1352. if (prop.raw === null && !prop.required) {
  1353. return true;
  1354. }
  1355. var options = prop.options;
  1356. var type = options.type;
  1357. var valid = true;
  1358. var expectedType;
  1359. if (type) {
  1360. if (type === String) {
  1361. expectedType = 'string';
  1362. valid = typeof value === expectedType;
  1363. } else if (type === Number) {
  1364. expectedType = 'number';
  1365. valid = typeof value === 'number';
  1366. } else if (type === Boolean) {
  1367. expectedType = 'boolean';
  1368. valid = typeof value === 'boolean';
  1369. } else if (type === Function) {
  1370. expectedType = 'function';
  1371. valid = typeof value === 'function';
  1372. } else if (type === Object) {
  1373. expectedType = 'object';
  1374. valid = isPlainObject(value);
  1375. } else if (type === Array) {
  1376. expectedType = 'array';
  1377. valid = isArray(value);
  1378. } else {
  1379. valid = value instanceof type;
  1380. }
  1381. }
  1382. if (!valid) {
  1383. 'development' !== 'production' && warn('Invalid prop: type check failed for ' + prop.path + '="' + prop.raw + '".' + ' Expected ' + formatType(expectedType) + ', got ' + formatValue(value) + '.');
  1384. return false;
  1385. }
  1386. var validator = options.validator;
  1387. if (validator) {
  1388. if (!validator.call(null, value)) {
  1389. 'development' !== 'production' && warn('Invalid prop: custom validator check failed for ' + prop.path + '="' + prop.raw + '"');
  1390. return false;
  1391. }
  1392. }
  1393. return true;
  1394. }
  1395. /**
  1396. * Force parsing value with coerce option.
  1397. *
  1398. * @param {*} value
  1399. * @param {Object} options
  1400. * @return {*}
  1401. */
  1402. function coerceProp(prop, value) {
  1403. var coerce = prop.options.coerce;
  1404. if (!coerce) {
  1405. return value;
  1406. }
  1407. // coerce is a function
  1408. return coerce(value);
  1409. }
  1410. function formatType(val) {
  1411. return val ? val.charAt(0).toUpperCase() + val.slice(1) : 'custom type';
  1412. }
  1413. function formatValue(val) {
  1414. return Object.prototype.toString.call(val).slice(8, -1);
  1415. }
  1416. /**
  1417. * Option overwriting strategies are functions that handle
  1418. * how to merge a parent option value and a child option
  1419. * value into the final value.
  1420. *
  1421. * All strategy functions follow the same signature:
  1422. *
  1423. * @param {*} parentVal
  1424. * @param {*} childVal
  1425. * @param {Vue} [vm]
  1426. */
  1427. var strats = config.optionMergeStrategies = Object.create(null);
  1428. /**
  1429. * Helper that recursively merges two data objects together.
  1430. */
  1431. function mergeData(to, from) {
  1432. var key, toVal, fromVal;
  1433. for (key in from) {
  1434. toVal = to[key];
  1435. fromVal = from[key];
  1436. if (!hasOwn(to, key)) {
  1437. set(to, key, fromVal);
  1438. } else if (isObject(toVal) && isObject(fromVal)) {
  1439. mergeData(toVal, fromVal);
  1440. }
  1441. }
  1442. return to;
  1443. }
  1444. /**
  1445. * Data
  1446. */
  1447. strats.data = function (parentVal, childVal, vm) {
  1448. if (!vm) {
  1449. // in a Vue.extend merge, both should be functions
  1450. if (!childVal) {
  1451. return parentVal;
  1452. }
  1453. if (typeof childVal !== 'function') {
  1454. 'development' !== 'production' && warn('The "data" option should be a function ' + 'that returns a per-instance value in component ' + 'definitions.');
  1455. return parentVal;
  1456. }
  1457. if (!parentVal) {
  1458. return childVal;
  1459. }
  1460. // when parentVal & childVal are both present,
  1461. // we need to return a function that returns the
  1462. // merged result of both functions... no need to
  1463. // check if parentVal is a function here because
  1464. // it has to be a function to pass previous merges.
  1465. return function mergedDataFn() {
  1466. return mergeData(childVal.call(this), parentVal.call(this));
  1467. };
  1468. } else if (parentVal || childVal) {
  1469. return function mergedInstanceDataFn() {
  1470. // instance merge
  1471. var instanceData = typeof childVal === 'function' ? childVal.call(vm) : childVal;
  1472. var defaultData = typeof parentVal === 'function' ? parentVal.call(vm) : undefined;
  1473. if (instanceData) {
  1474. return mergeData(instanceData, defaultData);
  1475. } else {
  1476. return defaultData;
  1477. }
  1478. };
  1479. }
  1480. };
  1481. /**
  1482. * El
  1483. */
  1484. strats.el = function (parentVal, childVal, vm) {
  1485. if (!vm && childVal && typeof childVal !== 'function') {
  1486. 'development' !== 'production' && warn('The "el" option should be a function ' + 'that returns a per-instance value in component ' + 'definitions.');
  1487. return;
  1488. }
  1489. var ret = childVal || parentVal;
  1490. // invoke the element factory if this is instance merge
  1491. return vm && typeof ret === 'function' ? ret.call(vm) : ret;
  1492. };
  1493. /**
  1494. * Hooks and param attributes are merged as arrays.
  1495. */
  1496. strats.init = strats.created = strats.ready = strats.attached = strats.detached = strats.beforeCompile = strats.compiled = strats.beforeDestroy = strats.destroyed = function (parentVal, childVal) {
  1497. return childVal ? parentVal ? parentVal.concat(childVal) : isArray(childVal) ? childVal : [childVal] : parentVal;
  1498. };
  1499. /**
  1500. * 0.11 deprecation warning
  1501. */
  1502. strats.paramAttributes = function () {
  1503. /* istanbul ignore next */
  1504. 'development' !== 'production' && warn('"paramAttributes" option has been deprecated in 0.12. ' + 'Use "props" instead.');
  1505. };
  1506. /**
  1507. * Assets
  1508. *
  1509. * When a vm is present (instance creation), we need to do
  1510. * a three-way merge between constructor options, instance
  1511. * options and parent options.
  1512. */
  1513. function mergeAssets(parentVal, childVal) {
  1514. var res = Object.create(parentVal);
  1515. return childVal ? extend(res, guardArrayAssets(childVal)) : res;
  1516. }
  1517. config._assetTypes.forEach(function (type) {
  1518. strats[type + 's'] = mergeAssets;
  1519. });
  1520. /**
  1521. * Events & Watchers.
  1522. *
  1523. * Events & watchers hashes should not overwrite one
  1524. * another, so we merge them as arrays.
  1525. */
  1526. strats.watch = strats.events = function (parentVal, childVal) {
  1527. if (!childVal) return parentVal;
  1528. if (!parentVal) return childVal;
  1529. var ret = {};
  1530. extend(ret, parentVal);
  1531. for (var key in childVal) {
  1532. var parent = ret[key];
  1533. var child = childVal[key];
  1534. if (parent && !isArray(parent)) {
  1535. parent = [parent];
  1536. }
  1537. ret[key] = parent ? parent.concat(child) : [child];
  1538. }
  1539. return ret;
  1540. };
  1541. /**
  1542. * Other object hashes.
  1543. */
  1544. strats.props = strats.methods = strats.computed = function (parentVal, childVal) {
  1545. if (!childVal) return parentVal;
  1546. if (!parentVal) return childVal;
  1547. var ret = Object.create(null);
  1548. extend(ret, parentVal);
  1549. extend(ret, childVal);
  1550. return ret;
  1551. };
  1552. /**
  1553. * Default strategy.
  1554. */
  1555. var defaultStrat = function defaultStrat(parentVal, childVal) {
  1556. return childVal === undefined ? parentVal : childVal;
  1557. };
  1558. /**
  1559. * Make sure component options get converted to actual
  1560. * constructors.
  1561. *
  1562. * @param {Object} options
  1563. */
  1564. function guardComponents(options) {
  1565. if (options.components) {
  1566. var components = options.components = guardArrayAssets(options.components);
  1567. var def;
  1568. var ids = Object.keys(components);
  1569. for (var i = 0, l = ids.length; i < l; i++) {
  1570. var key = ids[i];
  1571. if (commonTagRE.test(key) || reservedTagRE.test(key)) {
  1572. 'development' !== 'production' && warn('Do not use built-in or reserved HTML elements as component ' + 'id: ' + key);
  1573. continue;
  1574. }
  1575. def = components[key];
  1576. if (isPlainObject(def)) {
  1577. components[key] = Vue.extend(def);
  1578. }
  1579. }
  1580. }
  1581. }
  1582. /**
  1583. * Ensure all props option syntax are normalized into the
  1584. * Object-based format.
  1585. *
  1586. * @param {Object} options
  1587. */
  1588. function guardProps(options) {
  1589. var props = options.props;
  1590. var i, val;
  1591. if (isArray(props)) {
  1592. options.props = {};
  1593. i = props.length;
  1594. while (i--) {
  1595. val = props[i];
  1596. if (typeof val === 'string') {
  1597. options.props[val] = null;
  1598. } else if (val.name) {
  1599. options.props[val.name] = val;
  1600. }
  1601. }
  1602. } else if (isPlainObject(props)) {
  1603. var keys = Object.keys(props);
  1604. i = keys.length;
  1605. while (i--) {
  1606. val = props[keys[i]];
  1607. if (typeof val === 'function') {
  1608. props[keys[i]] = { type: val };
  1609. }
  1610. }
  1611. }
  1612. }
  1613. /**
  1614. * Guard an Array-format assets option and converted it
  1615. * into the key-value Object format.
  1616. *
  1617. * @param {Object|Array} assets
  1618. * @return {Object}
  1619. */
  1620. function guardArrayAssets(assets) {
  1621. if (isArray(assets)) {
  1622. var res = {};
  1623. var i = assets.length;
  1624. var asset;
  1625. while (i--) {
  1626. asset = assets[i];
  1627. var id = typeof asset === 'function' ? asset.options && asset.options.name || asset.id : asset.name || asset.id;
  1628. if (!id) {
  1629. 'development' !== 'production' && warn('Array-syntax assets must provide a "name" or "id" field.');
  1630. } else {
  1631. res[id] = asset;
  1632. }
  1633. }
  1634. return res;
  1635. }
  1636. return assets;
  1637. }
  1638. /**
  1639. * Merge two option objects into a new one.
  1640. * Core utility used in both instantiation and inheritance.
  1641. *
  1642. * @param {Object} parent
  1643. * @param {Object} child
  1644. * @param {Vue} [vm] - if vm is present, indicates this is
  1645. * an instantiation merge.
  1646. */
  1647. function mergeOptions(parent, child, vm) {
  1648. guardComponents(child);
  1649. guardProps(child);
  1650. var options = {};
  1651. var key;
  1652. if (child.mixins) {
  1653. for (var i = 0, l = child.mixins.length; i < l; i++) {
  1654. parent = mergeOptions(parent, child.mixins[i], vm);
  1655. }
  1656. }
  1657. for (key in parent) {
  1658. mergeField(key);
  1659. }
  1660. for (key in child) {
  1661. if (!hasOwn(parent, key)) {
  1662. mergeField(key);
  1663. }
  1664. }
  1665. function mergeField(key) {
  1666. var strat = strats[key] || defaultStrat;
  1667. options[key] = strat(parent[key], child[key], vm, key);
  1668. }
  1669. return options;
  1670. }
  1671. /**
  1672. * Resolve an asset.
  1673. * This function is used because child instances need access
  1674. * to assets defined in its ancestor chain.
  1675. *
  1676. * @param {Object} options
  1677. * @param {String} type
  1678. * @param {String} id
  1679. * @return {Object|Function}
  1680. */
  1681. function resolveAsset(options, type, id) {
  1682. var assets = options[type];
  1683. var camelizedId;
  1684. return assets[id] ||
  1685. // camelCase ID
  1686. assets[camelizedId = camelize(id)] ||
  1687. // Pascal Case ID
  1688. assets[camelizedId.charAt(0).toUpperCase() + camelizedId.slice(1)];
  1689. }
  1690. /**
  1691. * Assert asset exists
  1692. */
  1693. function assertAsset(val, type, id) {
  1694. if (!val) {
  1695. 'development' !== 'production' && warn('Failed to resolve ' + type + ': ' + id);
  1696. }
  1697. }
  1698. var arrayProto = Array.prototype;
  1699. var arrayMethods = Object.create(arrayProto)
  1700. /**
  1701. * Intercept mutating methods and emit events
  1702. */
  1703. ;['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse'].forEach(function (method) {
  1704. // cache original method
  1705. var original = arrayProto[method];
  1706. def(arrayMethods, method, function mutator() {
  1707. // avoid leaking arguments:
  1708. // http://jsperf.com/closure-with-arguments
  1709. var i = arguments.length;
  1710. var args = new Array(i);
  1711. while (i--) {
  1712. args[i] = arguments[i];
  1713. }
  1714. var result = original.apply(this, args);
  1715. var ob = this.__ob__;
  1716. var inserted;
  1717. switch (method) {
  1718. case 'push':
  1719. inserted = args;
  1720. break;
  1721. case 'unshift':
  1722. inserted = args;
  1723. break;
  1724. case 'splice':
  1725. inserted = args.slice(2);
  1726. break;
  1727. }
  1728. if (inserted) ob.observeArray(inserted);
  1729. // notify change
  1730. ob.dep.notify();
  1731. return result;
  1732. });
  1733. });
  1734. /**
  1735. * Swap the element at the given index with a new value
  1736. * and emits corresponding event.
  1737. *
  1738. * @param {Number} index
  1739. * @param {*} val
  1740. * @return {*} - replaced element
  1741. */
  1742. def(arrayProto, '$set', function $set(index, val) {
  1743. if (index >= this.length) {
  1744. this.length = Number(index) + 1;
  1745. }
  1746. return this.splice(index, 1, val)[0];
  1747. });
  1748. /**
  1749. * Convenience method to remove the element at given index.
  1750. *
  1751. * @param {Number} index
  1752. * @param {*} val
  1753. */
  1754. def(arrayProto, '$remove', function $remove(item) {
  1755. /* istanbul ignore if */
  1756. if (!this.length) return;
  1757. var index = indexOf(this, item);
  1758. if (index > -1) {
  1759. return this.splice(index, 1);
  1760. }
  1761. });
  1762. var uid$3 = 0;
  1763. /**
  1764. * A dep is an observable that can have multiple
  1765. * directives subscribing to it.
  1766. *
  1767. * @constructor
  1768. */
  1769. function Dep() {
  1770. this.id = uid$3++;
  1771. this.subs = [];
  1772. }
  1773. // the current target watcher being evaluated.
  1774. // this is globally unique because there could be only one
  1775. // watcher being evaluated at any time.
  1776. Dep.target = null;
  1777. /**
  1778. * Add a directive subscriber.
  1779. *
  1780. * @param {Directive} sub
  1781. */
  1782. Dep.prototype.addSub = function (sub) {
  1783. this.subs.push(sub);
  1784. };
  1785. /**
  1786. * Remove a directive subscriber.
  1787. *
  1788. * @param {Directive} sub
  1789. */
  1790. Dep.prototype.removeSub = function (sub) {
  1791. this.subs.$remove(sub);
  1792. };
  1793. /**
  1794. * Add self as a dependency to the target watcher.
  1795. */
  1796. Dep.prototype.depend = function () {
  1797. Dep.target.addDep(this);
  1798. };
  1799. /**
  1800. * Notify all subscribers of a new value.
  1801. */
  1802. Dep.prototype.notify = function () {
  1803. // stablize the subscriber list first
  1804. var subs = toArray(this.subs);
  1805. for (var i = 0, l = subs.length; i < l; i++) {
  1806. subs[i].update();
  1807. }
  1808. };
  1809. var arrayKeys = Object.getOwnPropertyNames(arrayMethods);
  1810. /**
  1811. * Observer class that are attached to each observed
  1812. * object. Once attached, the observer converts target
  1813. * object's property keys into getter/setters that
  1814. * collect dependencies and dispatches updates.
  1815. *
  1816. * @param {Array|Object} value
  1817. * @constructor
  1818. */
  1819. function Observer(value) {
  1820. this.value = value;
  1821. this.dep = new Dep();
  1822. def(value, '__ob__', this);
  1823. if (isArray(value)) {
  1824. var augment = hasProto ? protoAugment : copyAugment;
  1825. augment(value, arrayMethods, arrayKeys);
  1826. this.observeArray(value);
  1827. } else {
  1828. this.walk(value);
  1829. }
  1830. }
  1831. // Instance methods
  1832. /**
  1833. * Walk through each property and convert them into
  1834. * getter/setters. This method should only be called when
  1835. * value type is Object.
  1836. *
  1837. * @param {Object} obj
  1838. */
  1839. Observer.prototype.walk = function (obj) {
  1840. var keys = Object.keys(obj);
  1841. for (var i = 0, l = keys.length; i < l; i++) {
  1842. this.convert(keys[i], obj[keys[i]]);
  1843. }
  1844. };
  1845. /**
  1846. * Observe a list of Array items.
  1847. *
  1848. * @param {Array} items
  1849. */
  1850. Observer.prototype.observeArray = function (items) {
  1851. for (var i = 0, l = items.length; i < l; i++) {
  1852. observe(items[i]);
  1853. }
  1854. };
  1855. /**
  1856. * Convert a property into getter/setter so we can emit
  1857. * the events when the property is accessed/changed.
  1858. *
  1859. * @param {String} key
  1860. * @param {*} val
  1861. */
  1862. Observer.prototype.convert = function (key, val) {
  1863. defineReactive(this.value, key, val);
  1864. };
  1865. /**
  1866. * Add an owner vm, so that when $set/$delete mutations
  1867. * happen we can notify owner vms to proxy the keys and
  1868. * digest the watchers. This is only called when the object
  1869. * is observed as an instance's root $data.
  1870. *
  1871. * @param {Vue} vm
  1872. */
  1873. Observer.prototype.addVm = function (vm) {
  1874. (this.vms || (this.vms = [])).push(vm);
  1875. };
  1876. /**
  1877. * Remove an owner vm. This is called when the object is
  1878. * swapped out as an instance's $data object.
  1879. *
  1880. * @param {Vue} vm
  1881. */
  1882. Observer.prototype.removeVm = function (vm) {
  1883. this.vms.$remove(vm);
  1884. };
  1885. // helpers
  1886. /**
  1887. * Augment an target Object or Array by intercepting
  1888. * the prototype chain using __proto__
  1889. *
  1890. * @param {Object|Array} target
  1891. * @param {Object} proto
  1892. */
  1893. function protoAugment(target, src) {
  1894. target.__proto__ = src;
  1895. }
  1896. /**
  1897. * Augment an target Object or Array by defining
  1898. * hidden properties.
  1899. *
  1900. * @param {Object|Array} target
  1901. * @param {Object} proto
  1902. */
  1903. function copyAugment(target, src, keys) {
  1904. for (var i = 0, l = keys.length; i < l; i++) {
  1905. var key = keys[i];
  1906. def(target, key, src[key]);
  1907. }
  1908. }
  1909. /**
  1910. * Attempt to create an observer instance for a value,
  1911. * returns the new observer if successfully observed,
  1912. * or the existing observer if the value already has one.
  1913. *
  1914. * @param {*} value
  1915. * @param {Vue} [vm]
  1916. * @return {Observer|undefined}
  1917. * @static
  1918. */
  1919. function observe(value, vm) {
  1920. if (!value || typeof value !== 'object') {
  1921. return;
  1922. }
  1923. var ob;
  1924. if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) {
  1925. ob = value.__ob__;
  1926. } else if ((isArray(value) || isPlainObject(value)) && Object.isExtensible(value) && !value._isVue) {
  1927. ob = new Observer(value);
  1928. }
  1929. if (ob && vm) {
  1930. ob.addVm(vm);
  1931. }
  1932. return ob;
  1933. }
  1934. /**
  1935. * Define a reactive property on an Object.
  1936. *
  1937. * @param {Object} obj
  1938. * @param {String} key
  1939. * @param {*} val
  1940. */
  1941. function defineReactive(obj, key, val) {
  1942. var dep = new Dep();
  1943. // cater for pre-defined getter/setters
  1944. var getter, setter;
  1945. if (config.convertAllProperties) {
  1946. var property = Object.getOwnPropertyDescriptor(obj, key);
  1947. if (property && property.configurable === false) {
  1948. return;
  1949. }
  1950. getter = property && property.get;
  1951. setter = property && property.set;
  1952. }
  1953. var childOb = observe(val);
  1954. Object.defineProperty(obj, key, {
  1955. enumerable: true,
  1956. configurable: true,
  1957. get: function reactiveGetter() {
  1958. var value = getter ? getter.call(obj) : val;
  1959. if (Dep.target) {
  1960. dep.depend();
  1961. if (childOb) {
  1962. childOb.dep.depend();
  1963. }
  1964. if (isArray(value)) {
  1965. for (var e, i = 0, l = value.length; i < l; i++) {
  1966. e = value[i];
  1967. e && e.__ob__ && e.__ob__.dep.depend();
  1968. }
  1969. }
  1970. }
  1971. return value;
  1972. },
  1973. set: function reactiveSetter(newVal) {
  1974. var value = getter ? getter.call(obj) : val;
  1975. if (newVal === value) {
  1976. return;
  1977. }
  1978. if (setter) {
  1979. setter.call(obj, newVal);
  1980. } else {
  1981. val = newVal;
  1982. }
  1983. childOb = observe(newVal);
  1984. dep.notify();
  1985. }
  1986. });
  1987. }
  1988. var util = Object.freeze({
  1989. defineReactive: defineReactive,
  1990. set: set,
  1991. del: del,
  1992. hasOwn: hasOwn,
  1993. isLiteral: isLiteral,
  1994. isReserved: isReserved,
  1995. _toString: _toString,
  1996. toNumber: toNumber,
  1997. toBoolean: toBoolean,
  1998. stripQuotes: stripQuotes,
  1999. camelize: camelize,
  2000. hyphenate: hyphenate,
  2001. classify: classify,
  2002. bind: bind$1,
  2003. toArray: toArray,
  2004. extend: extend,
  2005. isObject: isObject,
  2006. isPlainObject: isPlainObject,
  2007. def: def,
  2008. debounce: _debounce,
  2009. indexOf: indexOf,
  2010. cancellable: cancellable,
  2011. looseEqual: looseEqual,
  2012. isArray: isArray,
  2013. hasProto: hasProto,
  2014. inBrowser: inBrowser,
  2015. isIE9: isIE9,
  2016. isAndroid: isAndroid,
  2017. get transitionProp () { return transitionProp; },
  2018. get transitionEndEvent () { return transitionEndEvent; },
  2019. get animationProp () { return animationProp; },
  2020. get animationEndEvent () { return animationEndEvent; },
  2021. nextTick: nextTick,
  2022. query: query,
  2023. inDoc: inDoc,
  2024. getAttr: getAttr,
  2025. getBindAttr: getBindAttr,
  2026. hasBindAttr: hasBindAttr,
  2027. before: before,
  2028. after: after,
  2029. remove: remove,
  2030. prepend: prepend,
  2031. replace: replace,
  2032. on: on$1,
  2033. off: off,
  2034. setClass: setClass,
  2035. addClass: addClass,
  2036. removeClass: removeClass,
  2037. extractContent: extractContent,
  2038. trimNode: trimNode,
  2039. isTemplate: isTemplate,
  2040. createAnchor: createAnchor,
  2041. findRef: findRef,
  2042. mapNodeRange: mapNodeRange,
  2043. removeNodeRange: removeNodeRange,
  2044. mergeOptions: mergeOptions,
  2045. resolveAsset: resolveAsset,
  2046. assertAsset: assertAsset,
  2047. checkComponentAttr: checkComponentAttr,
  2048. initProp: initProp,
  2049. assertProp: assertProp,
  2050. coerceProp: coerceProp,
  2051. commonTagRE: commonTagRE,
  2052. reservedTagRE: reservedTagRE,
  2053. get warn () { return warn; }
  2054. });
  2055. var uid = 0;
  2056. function initMixin (Vue) {
  2057. /**
  2058. * The main init sequence. This is called for every
  2059. * instance, including ones that are created from extended
  2060. * constructors.
  2061. *
  2062. * @param {Object} options - this options object should be
  2063. * the result of merging class
  2064. * options and the options passed
  2065. * in to the constructor.
  2066. */
  2067. Vue.prototype._init = function (options) {
  2068. options = options || {};
  2069. this.$el = null;
  2070. this.$parent = options.parent;
  2071. this.$root = this.$parent ? this.$parent.$root : this;
  2072. this.$children = [];
  2073. this.$refs = {}; // child vm references
  2074. this.$els = {}; // element references
  2075. this._watchers = []; // all watchers as an array
  2076. this._directives = []; // all directives
  2077. // a uid
  2078. this._uid = uid++;
  2079. // a flag to avoid this being observed
  2080. this._isVue = true;
  2081. // events bookkeeping
  2082. this._events = {}; // registered callbacks
  2083. this._eventsCount = {}; // for $broadcast optimization
  2084. // fragment instance properties
  2085. this._isFragment = false;
  2086. this._fragment = // @type {DocumentFragment}
  2087. this._fragmentStart = // @type {Text|Comment}
  2088. this._fragmentEnd = null; // @type {Text|Comment}
  2089. // lifecycle state
  2090. this._isCompiled = this._isDestroyed = this._isReady = this._isAttached = this._isBeingDestroyed = false;
  2091. this._unlinkFn = null;
  2092. // context:
  2093. // if this is a transcluded component, context
  2094. // will be the common parent vm of this instance
  2095. // and its host.
  2096. this._context = options._context || this.$parent;
  2097. // scope:
  2098. // if this is inside an inline v-for, the scope
  2099. // will be the intermediate scope created for this
  2100. // repeat fragment. this is used for linking props
  2101. // and container directives.
  2102. this._scope = options._scope;
  2103. // fragment:
  2104. // if this instance is compiled inside a Fragment, it
  2105. // needs to reigster itself as a child of that fragment
  2106. // for attach/detach to work properly.
  2107. this._frag = options._frag;
  2108. if (this._frag) {
  2109. this._frag.children.push(this);
  2110. }
  2111. // push self into parent / transclusion host
  2112. if (this.$parent) {
  2113. this.$parent.$children.push(this);
  2114. }
  2115. // merge options.
  2116. options = this.$options = mergeOptions(this.constructor.options, options, this);
  2117. // set ref
  2118. this._updateRef();
  2119. // initialize data as empty object.
  2120. // it will be filled up in _initScope().
  2121. this._data = {};
  2122. // call init hook
  2123. this._callHook('init');
  2124. // initialize data observation and scope inheritance.
  2125. this._initState();
  2126. // setup event system and option events.
  2127. this._initEvents();
  2128. // call created hook
  2129. this._callHook('created');
  2130. // if `el` option is passed, start compilation.
  2131. if (options.el) {
  2132. this.$mount(options.el);
  2133. }
  2134. };
  2135. }
  2136. var pathCache = new Cache(1000);
  2137. // actions
  2138. var APPEND = 0;
  2139. var PUSH = 1;
  2140. var INC_SUB_PATH_DEPTH = 2;
  2141. var PUSH_SUB_PATH = 3;
  2142. // states
  2143. var BEFORE_PATH = 0;
  2144. var IN_PATH = 1;
  2145. var BEFORE_IDENT = 2;
  2146. var IN_IDENT = 3;
  2147. var IN_SUB_PATH = 4;
  2148. var IN_SINGLE_QUOTE = 5;
  2149. var IN_DOUBLE_QUOTE = 6;
  2150. var AFTER_PATH = 7;
  2151. var ERROR = 8;
  2152. var pathStateMachine = [];
  2153. pathStateMachine[BEFORE_PATH] = {
  2154. 'ws': [BEFORE_PATH],
  2155. 'ident': [IN_IDENT, APPEND],
  2156. '[': [IN_SUB_PATH],
  2157. 'eof': [AFTER_PATH]
  2158. };
  2159. pathStateMachine[IN_PATH] = {
  2160. 'ws': [IN_PATH],
  2161. '.': [BEFORE_IDENT],
  2162. '[': [IN_SUB_PATH],
  2163. 'eof': [AFTER_PATH]
  2164. };
  2165. pathStateMachine[BEFORE_IDENT] = {
  2166. 'ws': [BEFORE_IDENT],
  2167. 'ident': [IN_IDENT, APPEND]
  2168. };
  2169. pathStateMachine[IN_IDENT] = {
  2170. 'ident': [IN_IDENT, APPEND],
  2171. '0': [IN_IDENT, APPEND],
  2172. 'number': [IN_IDENT, APPEND],
  2173. 'ws': [IN_PATH, PUSH],
  2174. '.': [BEFORE_IDENT, PUSH],
  2175. '[': [IN_SUB_PATH, PUSH],
  2176. 'eof': [AFTER_PATH, PUSH]
  2177. };
  2178. pathStateMachine[IN_SUB_PATH] = {
  2179. "'": [IN_SINGLE_QUOTE, APPEND],
  2180. '"': [IN_DOUBLE_QUOTE, APPEND],
  2181. '[': [IN_SUB_PATH, INC_SUB_PATH_DEPTH],
  2182. ']': [IN_PATH, PUSH_SUB_PATH],
  2183. 'eof': ERROR,
  2184. 'else': [IN_SUB_PATH, APPEND]
  2185. };
  2186. pathStateMachine[IN_SINGLE_QUOTE] = {
  2187. "'": [IN_SUB_PATH, APPEND],
  2188. 'eof': ERROR,
  2189. 'else': [IN_SINGLE_QUOTE, APPEND]
  2190. };
  2191. pathStateMachine[IN_DOUBLE_QUOTE] = {
  2192. '"': [IN_SUB_PATH, APPEND],
  2193. 'eof': ERROR,
  2194. 'else': [IN_DOUBLE_QUOTE, APPEND]
  2195. };
  2196. /**
  2197. * Determine the type of a character in a keypath.
  2198. *
  2199. * @param {Char} ch
  2200. * @return {String} type
  2201. */
  2202. function getPathCharType(ch) {
  2203. if (ch === undefined) {
  2204. return 'eof';
  2205. }
  2206. var code = ch.charCodeAt(0);
  2207. switch (code) {
  2208. case 0x5B: // [
  2209. case 0x5D: // ]
  2210. case 0x2E: // .
  2211. case 0x22: // "
  2212. case 0x27: // '
  2213. case 0x30:
  2214. // 0
  2215. return ch;
  2216. case 0x5F: // _
  2217. case 0x24:
  2218. // $
  2219. return 'ident';
  2220. case 0x20: // Space
  2221. case 0x09: // Tab
  2222. case 0x0A: // Newline
  2223. case 0x0D: // Return
  2224. case 0xA0: // No-break space
  2225. case 0xFEFF: // Byte Order Mark
  2226. case 0x2028: // Line Separator
  2227. case 0x2029:
  2228. // Paragraph Separator
  2229. return 'ws';
  2230. }
  2231. // a-z, A-Z
  2232. if (code >= 0x61 && code <= 0x7A || code >= 0x41 && code <= 0x5A) {
  2233. return 'ident';
  2234. }
  2235. // 1-9
  2236. if (code >= 0x31 && code <= 0x39) {
  2237. return 'number';
  2238. }
  2239. return 'else';
  2240. }
  2241. /**
  2242. * Format a subPath, return its plain form if it is
  2243. * a literal string or number. Otherwise prepend the
  2244. * dynamic indicator (*).
  2245. *
  2246. * @param {String} path
  2247. * @return {String}
  2248. */
  2249. function formatSubPath(path) {
  2250. var trimmed = path.trim();
  2251. // invalid leading 0
  2252. if (path.charAt(0) === '0' && isNaN(path)) {
  2253. return false;
  2254. }
  2255. return isLiteral(trimmed) ? stripQuotes(trimmed) : '*' + trimmed;
  2256. }
  2257. /**
  2258. * Parse a string path into an array of segments
  2259. *
  2260. * @param {String} path
  2261. * @return {Array|undefined}
  2262. */
  2263. function parse(path) {
  2264. var keys = [];
  2265. var index = -1;
  2266. var mode = BEFORE_PATH;
  2267. var subPathDepth = 0;
  2268. var c, newChar, key, type, transition, action, typeMap;
  2269. var actions = [];
  2270. actions[PUSH] = function () {
  2271. if (key !== undefined) {
  2272. keys.push(key);
  2273. key = undefined;
  2274. }
  2275. };
  2276. actions[APPEND] = function () {
  2277. if (key === undefined) {
  2278. key = newChar;
  2279. } else {
  2280. key += newChar;
  2281. }
  2282. };
  2283. actions[INC_SUB_PATH_DEPTH] = function () {
  2284. actions[APPEND]();
  2285. subPathDepth++;
  2286. };
  2287. actions[PUSH_SUB_PATH] = function () {
  2288. if (subPathDepth > 0) {
  2289. subPathDepth--;
  2290. mode = IN_SUB_PATH;
  2291. actions[APPEND]();
  2292. } else {
  2293. subPathDepth = 0;
  2294. key = formatSubPath(key);
  2295. if (key === false) {
  2296. return false;
  2297. } else {
  2298. actions[PUSH]();
  2299. }
  2300. }
  2301. };
  2302. function maybeUnescapeQuote() {
  2303. var nextChar = path[index + 1];
  2304. if (mode === IN_SINGLE_QUOTE && nextChar === "'" || mode === IN_DOUBLE_QUOTE && nextChar === '"') {
  2305. index++;
  2306. newChar = '\\' + nextChar;
  2307. actions[APPEND]();
  2308. return true;
  2309. }
  2310. }
  2311. while (mode != null) {
  2312. index++;
  2313. c = path[index];
  2314. if (c === '\\' && maybeUnescapeQuote()) {
  2315. continue;
  2316. }
  2317. type = getPathCharType(c);
  2318. typeMap = pathStateMachine[mode];
  2319. transition = typeMap[type] || typeMap['else'] || ERROR;
  2320. if (transition === ERROR) {
  2321. return; // parse error
  2322. }
  2323. mode = transition[0];
  2324. action = actions[transition[1]];
  2325. if (action) {
  2326. newChar = transition[2];
  2327. newChar = newChar === undefined ? c : newChar;
  2328. if (action() === false) {
  2329. return;
  2330. }
  2331. }
  2332. if (mode === AFTER_PATH) {
  2333. keys.raw = path;
  2334. return keys;
  2335. }
  2336. }
  2337. }
  2338. /**
  2339. * External parse that check for a cache hit first
  2340. *
  2341. * @param {String} path
  2342. * @return {Array|undefined}
  2343. */
  2344. function parsePath(path) {
  2345. var hit = pathCache.get(path);
  2346. if (!hit) {
  2347. hit = parse(path);
  2348. if (hit) {
  2349. pathCache.put(path, hit);
  2350. }
  2351. }
  2352. return hit;
  2353. }
  2354. /**
  2355. * Get from an object from a path string
  2356. *
  2357. * @param {Object} obj
  2358. * @param {String} path
  2359. */
  2360. function getPath(obj, path) {
  2361. return parseExpression(path).get(obj);
  2362. }
  2363. /**
  2364. * Warn against setting non-existent root path on a vm.
  2365. */
  2366. var warnNonExistent;
  2367. if ('development' !== 'production') {
  2368. warnNonExistent = function (path) {
  2369. warn('You are setting a non-existent path "' + path.raw + '" ' + 'on a vm instance. Consider pre-initializing the property ' + 'with the "data" option for more reliable reactivity ' + 'and better performance.');
  2370. };
  2371. }
  2372. /**
  2373. * Set on an object from a path
  2374. *
  2375. * @param {Object} obj
  2376. * @param {String | Array} path
  2377. * @param {*} val
  2378. */
  2379. function setPath(obj, path, val) {
  2380. var original = obj;
  2381. if (typeof path === 'string') {
  2382. path = parse(path);
  2383. }
  2384. if (!path || !isObject(obj)) {
  2385. return false;
  2386. }
  2387. var last, key;
  2388. for (var i = 0, l = path.length; i < l; i++) {
  2389. last = obj;
  2390. key = path[i];
  2391. if (key.charAt(0) === '*') {
  2392. key = parseExpression(key.slice(1)).get.call(original, original);
  2393. }
  2394. if (i < l - 1) {
  2395. obj = obj[key];
  2396. if (!isObject(obj)) {
  2397. obj = {};
  2398. if ('development' !== 'production' && last._isVue) {
  2399. warnNonExistent(path);
  2400. }
  2401. set(last, key, obj);
  2402. }
  2403. } else {
  2404. if (isArray(obj)) {
  2405. obj.$set(key, val);
  2406. } else if (key in obj) {
  2407. obj[key] = val;
  2408. } else {
  2409. if ('development' !== 'production' && obj._isVue) {
  2410. warnNonExistent(path);
  2411. }
  2412. set(obj, key, val);
  2413. }
  2414. }
  2415. }
  2416. return true;
  2417. }
  2418. var path = Object.freeze({
  2419. parsePath: parsePath,
  2420. getPath: getPath,
  2421. setPath: setPath
  2422. });
  2423. var expressionCache = new Cache(1000);
  2424. var allowedKeywords = 'Math,Date,this,true,false,null,undefined,Infinity,NaN,' + 'isNaN,isFinite,decodeURI,decodeURIComponent,encodeURI,' + 'encodeURIComponent,parseInt,parseFloat';
  2425. var allowedKeywordsRE = new RegExp('^(' + allowedKeywords.replace(/,/g, '\\b|') + '\\b)');
  2426. // keywords that don't make sense inside expressions
  2427. var improperKeywords = 'break,case,class,catch,const,continue,debugger,default,' + 'delete,do,else,export,extends,finally,for,function,if,' + 'import,in,instanceof,let,return,super,switch,throw,try,' + 'var,while,with,yield,enum,await,implements,package,' + 'proctected,static,interface,private,public';
  2428. var improperKeywordsRE = new RegExp('^(' + improperKeywords.replace(/,/g, '\\b|') + '\\b)');
  2429. var wsRE = /\s/g;
  2430. var newlineRE = /\n/g;
  2431. var saveRE = /[\{,]\s*[\w\$_]+\s*:|('(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*")|new |typeof |void /g;
  2432. var restoreRE = /"(\d+)"/g;
  2433. var pathTestRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/;
  2434. var identRE = /[^\w$\.](?:[A-Za-z_$][\w$]*)/g;
  2435. var booleanLiteralRE = /^(?:true|false)$/;
  2436. /**
  2437. * Save / Rewrite / Restore
  2438. *
  2439. * When rewriting paths found in an expression, it is
  2440. * possible for the same letter sequences to be found in
  2441. * strings and Object literal property keys. Therefore we
  2442. * remove and store these parts in a temporary array, and
  2443. * restore them after the path rewrite.
  2444. */
  2445. var saved = [];
  2446. /**
  2447. * Save replacer
  2448. *
  2449. * The save regex can match two possible cases:
  2450. * 1. An opening object literal
  2451. * 2. A string
  2452. * If matched as a plain string, we need to escape its
  2453. * newlines, since the string needs to be preserved when
  2454. * generating the function body.
  2455. *
  2456. * @param {String} str
  2457. * @param {String} isString - str if matched as a string
  2458. * @return {String} - placeholder with index
  2459. */
  2460. function save(str, isString) {
  2461. var i = saved.length;
  2462. saved[i] = isString ? str.replace(newlineRE, '\\n') : str;
  2463. return '"' + i + '"';
  2464. }
  2465. /**
  2466. * Path rewrite replacer
  2467. *
  2468. * @param {String} raw
  2469. * @return {String}
  2470. */
  2471. function rewrite(raw) {
  2472. var c = raw.charAt(0);
  2473. var path = raw.slice(1);
  2474. if (allowedKeywordsRE.test(path)) {
  2475. return raw;
  2476. } else {
  2477. path = path.indexOf('"') > -1 ? path.replace(restoreRE, restore) : path;
  2478. return c + 'scope.' + path;
  2479. }
  2480. }
  2481. /**
  2482. * Restore replacer
  2483. *
  2484. * @param {String} str
  2485. * @param {String} i - matched save index
  2486. * @return {String}
  2487. */
  2488. function restore(str, i) {
  2489. return saved[i];
  2490. }
  2491. /**
  2492. * Rewrite an expression, prefixing all path accessors with
  2493. * `scope.` and generate getter/setter functions.
  2494. *
  2495. * @param {String} exp
  2496. * @return {Function}
  2497. */
  2498. function compileGetter(exp) {
  2499. if (improperKeywordsRE.test(exp)) {
  2500. 'development' !== 'production' && warn('Avoid using reserved keywords in expression: ' + exp);
  2501. }
  2502. // reset state
  2503. saved.length = 0;
  2504. // save strings and object literal keys
  2505. var body = exp.replace(saveRE, save).replace(wsRE, '');
  2506. // rewrite all paths
  2507. // pad 1 space here becaue the regex matches 1 extra char
  2508. body = (' ' + body).replace(identRE, rewrite).replace(restoreRE, restore);
  2509. return makeGetterFn(body);
  2510. }
  2511. /**
  2512. * Build a getter function. Requires eval.
  2513. *
  2514. * We isolate the try/catch so it doesn't affect the
  2515. * optimization of the parse function when it is not called.
  2516. *
  2517. * @param {String} body
  2518. * @return {Function|undefined}
  2519. */
  2520. function makeGetterFn(body) {
  2521. try {
  2522. return new Function('scope', 'return ' + body + ';');
  2523. } catch (e) {
  2524. 'development' !== 'production' && warn('Invalid expression. ' + 'Generated function body: ' + body);
  2525. }
  2526. }
  2527. /**
  2528. * Compile a setter function for the expression.
  2529. *
  2530. * @param {String} exp
  2531. * @return {Function|undefined}
  2532. */
  2533. function compileSetter(exp) {
  2534. var path = parsePath(exp);
  2535. if (path) {
  2536. return function (scope, val) {
  2537. setPath(scope, path, val);
  2538. };
  2539. } else {
  2540. 'development' !== 'production' && warn('Invalid setter expression: ' + exp);
  2541. }
  2542. }
  2543. /**
  2544. * Parse an expression into re-written getter/setters.
  2545. *
  2546. * @param {String} exp
  2547. * @param {Boolean} needSet
  2548. * @return {Function}
  2549. */
  2550. function parseExpression(exp, needSet) {
  2551. exp = exp.trim();
  2552. // try cache
  2553. var hit = expressionCache.get(exp);
  2554. if (hit) {
  2555. if (needSet && !hit.set) {
  2556. hit.set = compileSetter(hit.exp);
  2557. }
  2558. return hit;
  2559. }
  2560. var res = { exp: exp };
  2561. res.get = isSimplePath(exp) && exp.indexOf('[') < 0
  2562. // optimized super simple getter
  2563. ? makeGetterFn('scope.' + exp)
  2564. // dynamic getter
  2565. : compileGetter(exp);
  2566. if (needSet) {
  2567. res.set = compileSetter(exp);
  2568. }
  2569. expressionCache.put(exp, res);
  2570. return res;
  2571. }
  2572. /**
  2573. * Check if an expression is a simple path.
  2574. *
  2575. * @param {String} exp
  2576. * @return {Boolean}
  2577. */
  2578. function isSimplePath(exp) {
  2579. return pathTestRE.test(exp) &&
  2580. // don't treat true/false as paths
  2581. !booleanLiteralRE.test(exp) &&
  2582. // Math constants e.g. Math.PI, Math.E etc.
  2583. exp.slice(0, 5) !== 'Math.';
  2584. }
  2585. var expression = Object.freeze({
  2586. parseExpression: parseExpression,
  2587. isSimplePath: isSimplePath
  2588. });
  2589. // we have two separate queues: one for directive updates
  2590. // and one for user watcher registered via $watch().
  2591. // we want to guarantee directive updates to be called
  2592. // before user watchers so that when user watchers are
  2593. // triggered, the DOM would have already been in updated
  2594. // state.
  2595. var queue = [];
  2596. var userQueue = [];
  2597. var has = {};
  2598. var circular = {};
  2599. var waiting = false;
  2600. var internalQueueDepleted = false;
  2601. /**
  2602. * Reset the batcher's state.
  2603. */
  2604. function resetBatcherState() {
  2605. queue = [];
  2606. userQueue = [];
  2607. has = {};
  2608. circular = {};
  2609. waiting = internalQueueDepleted = false;
  2610. }
  2611. /**
  2612. * Flush both queues and run the watchers.
  2613. */
  2614. function flushBatcherQueue() {
  2615. runBatcherQueue(queue);
  2616. internalQueueDepleted = true;
  2617. runBatcherQueue(userQueue);
  2618. // dev tool hook
  2619. /* istanbul ignore if */
  2620. if ('development' !== 'production') {
  2621. if (inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__) {
  2622. window.__VUE_DEVTOOLS_GLOBAL_HOOK__.emit('flush');
  2623. }
  2624. }
  2625. resetBatcherState();
  2626. }
  2627. /**
  2628. * Run the watchers in a single queue.
  2629. *
  2630. * @param {Array} queue
  2631. */
  2632. function runBatcherQueue(queue) {
  2633. // do not cache length because more watchers might be pushed
  2634. // as we run existing watchers
  2635. for (var i = 0; i < queue.length; i++) {
  2636. var watcher = queue[i];
  2637. var id = watcher.id;
  2638. has[id] = null;
  2639. watcher.run();
  2640. // in dev build, check and stop circular updates.
  2641. if ('development' !== 'production' && has[id] != null) {
  2642. circular[id] = (circular[id] || 0) + 1;
  2643. if (circular[id] > config._maxUpdateCount) {
  2644. queue.splice(has[id], 1);
  2645. warn('You may have an infinite update loop for watcher ' + 'with expression: ' + watcher.expression);
  2646. }
  2647. }
  2648. }
  2649. }
  2650. /**
  2651. * Push a watcher into the watcher queue.
  2652. * Jobs with duplicate IDs will be skipped unless it's
  2653. * pushed when the queue is being flushed.
  2654. *
  2655. * @param {Watcher} watcher
  2656. * properties:
  2657. * - {Number} id
  2658. * - {Function} run
  2659. */
  2660. function pushWatcher(watcher) {
  2661. var id = watcher.id;
  2662. if (has[id] == null) {
  2663. // if an internal watcher is pushed, but the internal
  2664. // queue is already depleted, we run it immediately.
  2665. if (internalQueueDepleted && !watcher.user) {
  2666. watcher.run();
  2667. return;
  2668. }
  2669. // push watcher into appropriate queue
  2670. var q = watcher.user ? userQueue : queue;
  2671. has[id] = q.length;
  2672. q.push(watcher);
  2673. // queue the flush
  2674. if (!waiting) {
  2675. waiting = true;
  2676. nextTick(flushBatcherQueue);
  2677. }
  2678. }
  2679. }
  2680. var uid$2 = 0;
  2681. /**
  2682. * A watcher parses an expression, collects dependencies,
  2683. * and fires callback when the expression value changes.
  2684. * This is used for both the $watch() api and directives.
  2685. *
  2686. * @param {Vue} vm
  2687. * @param {String} expression
  2688. * @param {Function} cb
  2689. * @param {Object} options
  2690. * - {Array} filters
  2691. * - {Boolean} twoWay
  2692. * - {Boolean} deep
  2693. * - {Boolean} user
  2694. * - {Boolean} sync
  2695. * - {Boolean} lazy
  2696. * - {Function} [preProcess]
  2697. * - {Function} [postProcess]
  2698. * @constructor
  2699. */
  2700. function Watcher(vm, expOrFn, cb, options) {
  2701. // mix in options
  2702. if (options) {
  2703. extend(this, options);
  2704. }
  2705. var isFn = typeof expOrFn === 'function';
  2706. this.vm = vm;
  2707. vm._watchers.push(this);
  2708. this.expression = isFn ? expOrFn.toString() : expOrFn;
  2709. this.cb = cb;
  2710. this.id = ++uid$2; // uid for batching
  2711. this.active = true;
  2712. this.dirty = this.lazy; // for lazy watchers
  2713. this.deps = Object.create(null);
  2714. this.newDeps = null;
  2715. this.prevError = null; // for async error stacks
  2716. // parse expression for getter/setter
  2717. if (isFn) {
  2718. this.getter = expOrFn;
  2719. this.setter = undefined;
  2720. } else {
  2721. var res = parseExpression(expOrFn, this.twoWay);
  2722. this.getter = res.get;
  2723. this.setter = res.set;
  2724. }
  2725. this.value = this.lazy ? undefined : this.get();
  2726. // state for avoiding false triggers for deep and Array
  2727. // watchers during vm._digest()
  2728. this.queued = this.shallow = false;
  2729. }
  2730. /**
  2731. * Add a dependency to this directive.
  2732. *
  2733. * @param {Dep} dep
  2734. */
  2735. Watcher.prototype.addDep = function (dep) {
  2736. var id = dep.id;
  2737. if (!this.newDeps[id]) {
  2738. this.newDeps[id] = dep;
  2739. if (!this.deps[id]) {
  2740. this.deps[id] = dep;
  2741. dep.addSub(this);
  2742. }
  2743. }
  2744. };
  2745. /**
  2746. * Evaluate the getter, and re-collect dependencies.
  2747. */
  2748. Watcher.prototype.get = function () {
  2749. this.beforeGet();
  2750. var scope = this.scope || this.vm;
  2751. var value;
  2752. try {
  2753. value = this.getter.call(scope, scope);
  2754. } catch (e) {
  2755. if ('development' !== 'production' && config.warnExpressionErrors) {
  2756. warn('Error when evaluating expression "' + this.expression + '". ' + (config.debug ? '' : 'Turn on debug mode to see stack trace.'), e);
  2757. }
  2758. }
  2759. // "touch" every property so they are all tracked as
  2760. // dependencies for deep watching
  2761. if (this.deep) {
  2762. traverse(value);
  2763. }
  2764. if (this.preProcess) {
  2765. value = this.preProcess(value);
  2766. }
  2767. if (this.filters) {
  2768. value = scope._applyFilters(value, null, this.filters, false);
  2769. }
  2770. if (this.postProcess) {
  2771. value = this.postProcess(value);
  2772. }
  2773. this.afterGet();
  2774. return value;
  2775. };
  2776. /**
  2777. * Set the corresponding value with the setter.
  2778. *
  2779. * @param {*} value
  2780. */
  2781. Watcher.prototype.set = function (value) {
  2782. var scope = this.scope || this.vm;
  2783. if (this.filters) {
  2784. value = scope._applyFilters(value, this.value, this.filters, true);
  2785. }
  2786. try {
  2787. this.setter.call(scope, scope, value);
  2788. } catch (e) {
  2789. if ('development' !== 'production' && config.warnExpressionErrors) {
  2790. warn('Error when evaluating setter "' + this.expression + '"', e);
  2791. }
  2792. }
  2793. // two-way sync for v-for alias
  2794. var forContext = scope.$forContext;
  2795. if (forContext && forContext.alias === this.expression) {
  2796. if (forContext.filters) {
  2797. 'development' !== 'production' && warn('It seems you are using two-way binding on ' + 'a v-for alias (' + this.expression + '), and the ' + 'v-for has filters. This will not work properly. ' + 'Either remove the filters or use an array of ' + 'objects and bind to object properties instead.');
  2798. return;
  2799. }
  2800. forContext._withLock(function () {
  2801. if (scope.$key) {
  2802. // original is an object
  2803. forContext.rawValue[scope.$key] = value;
  2804. } else {
  2805. forContext.rawValue.$set(scope.$index, value);
  2806. }
  2807. });
  2808. }
  2809. };
  2810. /**
  2811. * Prepare for dependency collection.
  2812. */
  2813. Watcher.prototype.beforeGet = function () {
  2814. Dep.target = this;
  2815. this.newDeps = Object.create(null);
  2816. };
  2817. /**
  2818. * Clean up for dependency collection.
  2819. */
  2820. Watcher.prototype.afterGet = function () {
  2821. Dep.target = null;
  2822. var ids = Object.keys(this.deps);
  2823. var i = ids.length;
  2824. while (i--) {
  2825. var id = ids[i];
  2826. if (!this.newDeps[id]) {
  2827. this.deps[id].removeSub(this);
  2828. }
  2829. }
  2830. this.deps = this.newDeps;
  2831. };
  2832. /**
  2833. * Subscriber interface.
  2834. * Will be called when a dependency changes.
  2835. *
  2836. * @param {Boolean} shallow
  2837. */
  2838. Watcher.prototype.update = function (shallow) {
  2839. if (this.lazy) {
  2840. this.dirty = true;
  2841. } else if (this.sync || !config.async) {
  2842. this.run();
  2843. } else {
  2844. // if queued, only overwrite shallow with non-shallow,
  2845. // but not the other way around.
  2846. this.shallow = this.queued ? shallow ? this.shallow : false : !!shallow;
  2847. this.queued = true;
  2848. // record before-push error stack in debug mode
  2849. /* istanbul ignore if */
  2850. if ('development' !== 'production' && config.debug) {
  2851. this.prevError = new Error('[vue] async stack trace');
  2852. }
  2853. pushWatcher(this);
  2854. }
  2855. };
  2856. /**
  2857. * Batcher job interface.
  2858. * Will be called by the batcher.
  2859. */
  2860. Watcher.prototype.run = function () {
  2861. if (this.active) {
  2862. var value = this.get();
  2863. if (value !== this.value ||
  2864. // Deep watchers and watchers on Object/Arrays should fire even
  2865. // when the value is the same, because the value may
  2866. // have mutated; but only do so if this is a
  2867. // non-shallow update (caused by a vm digest).
  2868. (isObject(value) || this.deep) && !this.shallow) {
  2869. // set new value
  2870. var oldValue = this.value;
  2871. this.value = value;
  2872. // in debug + async mode, when a watcher callbacks
  2873. // throws, we also throw the saved before-push error
  2874. // so the full cross-tick stack trace is available.
  2875. var prevError = this.prevError;
  2876. /* istanbul ignore if */
  2877. if ('development' !== 'production' && config.debug && prevError) {
  2878. this.prevError = null;
  2879. try {
  2880. this.cb.call(this.vm, value, oldValue);
  2881. } catch (e) {
  2882. nextTick(function () {
  2883. throw prevError;
  2884. }, 0);
  2885. throw e;
  2886. }
  2887. } else {
  2888. this.cb.call(this.vm, value, oldValue);
  2889. }
  2890. }
  2891. this.queued = this.shallow = false;
  2892. }
  2893. };
  2894. /**
  2895. * Evaluate the value of the watcher.
  2896. * This only gets called for lazy watchers.
  2897. */
  2898. Watcher.prototype.evaluate = function () {
  2899. // avoid overwriting another watcher that is being
  2900. // collected.
  2901. var current = Dep.target;
  2902. this.value = this.get();
  2903. this.dirty = false;
  2904. Dep.target = current;
  2905. };
  2906. /**
  2907. * Depend on all deps collected by this watcher.
  2908. */
  2909. Watcher.prototype.depend = function () {
  2910. var depIds = Object.keys(this.deps);
  2911. var i = depIds.length;
  2912. while (i--) {
  2913. this.deps[depIds[i]].depend();
  2914. }
  2915. };
  2916. /**
  2917. * Remove self from all dependencies' subcriber list.
  2918. */
  2919. Watcher.prototype.teardown = function () {
  2920. if (this.active) {
  2921. // remove self from vm's watcher list
  2922. // we can skip this if the vm if being destroyed
  2923. // which can improve teardown performance.
  2924. if (!this.vm._isBeingDestroyed) {
  2925. this.vm._watchers.$remove(this);
  2926. }
  2927. var depIds = Object.keys(this.deps);
  2928. var i = depIds.length;
  2929. while (i--) {
  2930. this.deps[depIds[i]].removeSub(this);
  2931. }
  2932. this.active = false;
  2933. this.vm = this.cb = this.value = null;
  2934. }
  2935. };
  2936. /**
  2937. * Recrusively traverse an object to evoke all converted
  2938. * getters, so that every nested property inside the object
  2939. * is collected as a "deep" dependency.
  2940. *
  2941. * @param {*} val
  2942. */
  2943. function traverse(val) {
  2944. var i, keys;
  2945. if (isArray(val)) {
  2946. i = val.length;
  2947. while (i--) traverse(val[i]);
  2948. } else if (isObject(val)) {
  2949. keys = Object.keys(val);
  2950. i = keys.length;
  2951. while (i--) traverse(val[keys[i]]);
  2952. }
  2953. }
  2954. var cloak = {
  2955. bind: function bind() {
  2956. var el = this.el;
  2957. this.vm.$once('pre-hook:compiled', function () {
  2958. el.removeAttribute('v-cloak');
  2959. });
  2960. }
  2961. };
  2962. var ref = {
  2963. bind: function bind() {
  2964. 'development' !== 'production' && warn('v-ref:' + this.arg + ' must be used on a child ' + 'component. Found on <' + this.el.tagName.toLowerCase() + '>.');
  2965. }
  2966. };
  2967. var ON = 700;
  2968. var MODEL = 800;
  2969. var BIND = 850;
  2970. var TRANSITION = 1100;
  2971. var EL = 1500;
  2972. var COMPONENT = 1500;
  2973. var PARTIAL = 1750;
  2974. var FOR = 2000;
  2975. var IF = 2000;
  2976. var SLOT = 2100;
  2977. var el = {
  2978. priority: EL,
  2979. bind: function bind() {
  2980. /* istanbul ignore if */
  2981. if (!this.arg) {
  2982. return;
  2983. }
  2984. var id = this.id = camelize(this.arg);
  2985. var refs = (this._scope || this.vm).$els;
  2986. if (hasOwn(refs, id)) {
  2987. refs[id] = this.el;
  2988. } else {
  2989. defineReactive(refs, id, this.el);
  2990. }
  2991. },
  2992. unbind: function unbind() {
  2993. var refs = (this._scope || this.vm).$els;
  2994. if (refs[this.id] === this.el) {
  2995. refs[this.id] = null;
  2996. }
  2997. }
  2998. };
  2999. var prefixes = ['-webkit-', '-moz-', '-ms-'];
  3000. var camelPrefixes = ['Webkit', 'Moz', 'ms'];
  3001. var importantRE = /!important;?$/;
  3002. var propCache = Object.create(null);
  3003. var testEl = null;
  3004. var style = {
  3005. deep: true,
  3006. update: function update(value) {
  3007. if (typeof value === 'string') {
  3008. this.el.style.cssText = value;
  3009. } else if (isArray(value)) {
  3010. this.handleObject(value.reduce(extend, {}));
  3011. } else {
  3012. this.handleObject(value || {});
  3013. }
  3014. },
  3015. handleObject: function handleObject(value) {
  3016. // cache object styles so that only changed props
  3017. // are actually updated.
  3018. var cache = this.cache || (this.cache = {});
  3019. var name, val;
  3020. for (name in cache) {
  3021. if (!(name in value)) {
  3022. this.handleSingle(name, null);
  3023. delete cache[name];
  3024. }
  3025. }
  3026. for (name in value) {
  3027. val = value[name];
  3028. if (val !== cache[name]) {
  3029. cache[name] = val;
  3030. this.handleSingle(name, val);
  3031. }
  3032. }
  3033. },
  3034. handleSingle: function handleSingle(prop, value) {
  3035. prop = normalize(prop);
  3036. if (!prop) return; // unsupported prop
  3037. // cast possible numbers/booleans into strings
  3038. if (value != null) value += '';
  3039. if (value) {
  3040. var isImportant = importantRE.test(value) ? 'important' : '';
  3041. if (isImportant) {
  3042. value = value.replace(importantRE, '').trim();
  3043. }
  3044. this.el.style.setProperty(prop, value, isImportant);
  3045. } else {
  3046. this.el.style.removeProperty(prop);
  3047. }
  3048. }
  3049. };
  3050. /**
  3051. * Normalize a CSS property name.
  3052. * - cache result
  3053. * - auto prefix
  3054. * - camelCase -> dash-case
  3055. *
  3056. * @param {String} prop
  3057. * @return {String}
  3058. */
  3059. function normalize(prop) {
  3060. if (propCache[prop]) {
  3061. return propCache[prop];
  3062. }
  3063. var res = prefix(prop);
  3064. propCache[prop] = propCache[res] = res;
  3065. return res;
  3066. }
  3067. /**
  3068. * Auto detect the appropriate prefix for a CSS property.
  3069. * https://gist.github.com/paulirish/523692
  3070. *
  3071. * @param {String} prop
  3072. * @return {String}
  3073. */
  3074. function prefix(prop) {
  3075. prop = hyphenate(prop);
  3076. var camel = camelize(prop);
  3077. var upper = camel.charAt(0).toUpperCase() + camel.slice(1);
  3078. if (!testEl) {
  3079. testEl = document.createElement('div');
  3080. }
  3081. if (camel in testEl.style) {
  3082. return prop;
  3083. }
  3084. var i = prefixes.length;
  3085. var prefixed;
  3086. while (i--) {
  3087. prefixed = camelPrefixes[i] + upper;
  3088. if (prefixed in testEl.style) {
  3089. return prefixes[i] + prop;
  3090. }
  3091. }
  3092. }
  3093. // xlink
  3094. var xlinkNS = 'http://www.w3.org/1999/xlink';
  3095. var xlinkRE = /^xlink:/;
  3096. // check for attributes that prohibit interpolations
  3097. var disallowedInterpAttrRE = /^v-|^:|^@|^(?:is|transition|transition-mode|debounce|track-by|stagger|enter-stagger|leave-stagger)$/;
  3098. // these attributes should also set their corresponding properties
  3099. // because they only affect the initial state of the element
  3100. var attrWithPropsRE = /^(?:value|checked|selected|muted)$/;
  3101. // these attributes should set a hidden property for
  3102. // binding v-model to object values
  3103. var modelProps = {
  3104. value: '_value',
  3105. 'true-value': '_trueValue',
  3106. 'false-value': '_falseValue'
  3107. };
  3108. var bind = {
  3109. priority: BIND,
  3110. bind: function bind() {
  3111. var attr = this.arg;
  3112. var tag = this.el.tagName;
  3113. // should be deep watch on object mode
  3114. if (!attr) {
  3115. this.deep = true;
  3116. }
  3117. // handle interpolation bindings
  3118. var descriptor = this.descriptor;
  3119. var tokens = descriptor.interp;
  3120. if (tokens) {
  3121. // handle interpolations with one-time tokens
  3122. if (descriptor.hasOneTime) {
  3123. this.expression = tokensToExp(tokens, this._scope || this.vm);
  3124. }
  3125. // only allow binding on native attributes
  3126. if (disallowedInterpAttrRE.test(attr) || attr === 'name' && (tag === 'PARTIAL' || tag === 'SLOT')) {
  3127. 'development' !== 'production' && warn(attr + '="' + descriptor.raw + '": ' + 'attribute interpolation is not allowed in Vue.js ' + 'directives and special attributes.');
  3128. this.el.removeAttribute(attr);
  3129. this.invalid = true;
  3130. }
  3131. /* istanbul ignore if */
  3132. if ('development' !== 'production') {
  3133. var raw = attr + '="' + descriptor.raw + '": ';
  3134. // warn src
  3135. if (attr === 'src') {
  3136. warn(raw + 'interpolation in "src" attribute will cause ' + 'a 404 request. Use v-bind:src instead.');
  3137. }
  3138. // warn style
  3139. if (attr === 'style') {
  3140. warn(raw + 'interpolation in "style" attribute will cause ' + 'the attribute to be discarded in Internet Explorer. ' + 'Use v-bind:style instead.');
  3141. }
  3142. }
  3143. }
  3144. },
  3145. update: function update(value) {
  3146. if (this.invalid) {
  3147. return;
  3148. }
  3149. var attr = this.arg;
  3150. if (this.arg) {
  3151. this.handleSingle(attr, value);
  3152. } else {
  3153. this.handleObject(value || {});
  3154. }
  3155. },
  3156. // share object handler with v-bind:class
  3157. handleObject: style.handleObject,
  3158. handleSingle: function handleSingle(attr, value) {
  3159. var el = this.el;
  3160. var interp = this.descriptor.interp;
  3161. if (!interp && attrWithPropsRE.test(attr) && attr in el) {
  3162. el[attr] = attr === 'value' ? value == null // IE9 will set input.value to "null" for null...
  3163. ? '' : value : value;
  3164. }
  3165. // set model props
  3166. var modelProp = modelProps[attr];
  3167. if (!interp && modelProp) {
  3168. el[modelProp] = value;
  3169. // update v-model if present
  3170. var model = el.__v_model;
  3171. if (model) {
  3172. model.listener();
  3173. }
  3174. }
  3175. // do not set value attribute for textarea
  3176. if (attr === 'value' && el.tagName === 'TEXTAREA') {
  3177. el.removeAttribute(attr);
  3178. return;
  3179. }
  3180. // update attribute
  3181. if (value != null && value !== false) {
  3182. if (attr === 'class') {
  3183. // handle edge case #1960:
  3184. // class interpolation should not overwrite Vue transition class
  3185. if (el.__v_trans) {
  3186. value += ' ' + el.__v_trans.id + '-transition';
  3187. }
  3188. setClass(el, value);
  3189. } else if (xlinkRE.test(attr)) {
  3190. el.setAttributeNS(xlinkNS, attr, value);
  3191. } else {
  3192. el.setAttribute(attr, value);
  3193. }
  3194. } else {
  3195. el.removeAttribute(attr);
  3196. }
  3197. }
  3198. };
  3199. // keyCode aliases
  3200. var keyCodes = {
  3201. esc: 27,
  3202. tab: 9,
  3203. enter: 13,
  3204. space: 32,
  3205. 'delete': 46,
  3206. up: 38,
  3207. left: 37,
  3208. right: 39,
  3209. down: 40
  3210. };
  3211. function keyFilter(handler, keys) {
  3212. var codes = keys.map(function (key) {
  3213. var charCode = key.charCodeAt(0);
  3214. if (charCode > 47 && charCode < 58) {
  3215. return parseInt(key, 10);
  3216. }
  3217. if (key.length === 1) {
  3218. charCode = key.toUpperCase().charCodeAt(0);
  3219. if (charCode > 64 && charCode < 91) {
  3220. return charCode;
  3221. }
  3222. }
  3223. return keyCodes[key];
  3224. });
  3225. return function keyHandler(e) {
  3226. if (codes.indexOf(e.keyCode) > -1) {
  3227. return handler.call(this, e);
  3228. }
  3229. };
  3230. }
  3231. function stopFilter(handler) {
  3232. return function stopHandler(e) {
  3233. e.stopPropagation();
  3234. return handler.call(this, e);
  3235. };
  3236. }
  3237. function preventFilter(handler) {
  3238. return function preventHandler(e) {
  3239. e.preventDefault();
  3240. return handler.call(this, e);
  3241. };
  3242. }
  3243. var on = {
  3244. acceptStatement: true,
  3245. priority: ON,
  3246. bind: function bind() {
  3247. // deal with iframes
  3248. if (this.el.tagName === 'IFRAME' && this.arg !== 'load') {
  3249. var self = this;
  3250. this.iframeBind = function () {
  3251. on$1(self.el.contentWindow, self.arg, self.handler);
  3252. };
  3253. this.on('load', this.iframeBind);
  3254. }
  3255. },
  3256. update: function update(handler) {
  3257. // stub a noop for v-on with no value,
  3258. // e.g. @mousedown.prevent
  3259. if (!this.descriptor.raw) {
  3260. handler = function () {};
  3261. }
  3262. if (typeof handler !== 'function') {
  3263. 'development' !== 'production' && warn('v-on:' + this.arg + '="' + this.expression + '" expects a function value, ' + 'got ' + handler);
  3264. return;
  3265. }
  3266. // apply modifiers
  3267. if (this.modifiers.stop) {
  3268. handler = stopFilter(handler);
  3269. }
  3270. if (this.modifiers.prevent) {
  3271. handler = preventFilter(handler);
  3272. }
  3273. // key filter
  3274. var keys = Object.keys(this.modifiers).filter(function (key) {
  3275. return key !== 'stop' && key !== 'prevent';
  3276. });
  3277. if (keys.length) {
  3278. handler = keyFilter(handler, keys);
  3279. }
  3280. this.reset();
  3281. this.handler = handler;
  3282. if (this.iframeBind) {
  3283. this.iframeBind();
  3284. } else {
  3285. on$1(this.el, this.arg, this.handler);
  3286. }
  3287. },
  3288. reset: function reset() {
  3289. var el = this.iframeBind ? this.el.contentWindow : this.el;
  3290. if (this.handler) {
  3291. off(el, this.arg, this.handler);
  3292. }
  3293. },
  3294. unbind: function unbind() {
  3295. this.reset();
  3296. }
  3297. };
  3298. var checkbox = {
  3299. bind: function bind() {
  3300. var self = this;
  3301. var el = this.el;
  3302. this.getValue = function () {
  3303. return el.hasOwnProperty('_value') ? el._value : self.params.number ? toNumber(el.value) : el.value;
  3304. };
  3305. function getBooleanValue() {
  3306. var val = el.checked;
  3307. if (val && el.hasOwnProperty('_trueValue')) {
  3308. return el._trueValue;
  3309. }
  3310. if (!val && el.hasOwnProperty('_falseValue')) {
  3311. return el._falseValue;
  3312. }
  3313. return val;
  3314. }
  3315. this.listener = function () {
  3316. var model = self._watcher.value;
  3317. if (isArray(model)) {
  3318. var val = self.getValue();
  3319. if (el.checked) {
  3320. if (indexOf(model, val) < 0) {
  3321. model.push(val);
  3322. }
  3323. } else {
  3324. model.$remove(val);
  3325. }
  3326. } else {
  3327. self.set(getBooleanValue());
  3328. }
  3329. };
  3330. this.on('change', this.listener);
  3331. if (el.hasAttribute('checked')) {
  3332. this.afterBind = this.listener;
  3333. }
  3334. },
  3335. update: function update(value) {
  3336. var el = this.el;
  3337. if (isArray(value)) {
  3338. el.checked = indexOf(value, this.getValue()) > -1;
  3339. } else {
  3340. if (el.hasOwnProperty('_trueValue')) {
  3341. el.checked = looseEqual(value, el._trueValue);
  3342. } else {
  3343. el.checked = !!value;
  3344. }
  3345. }
  3346. }
  3347. };
  3348. var select = {
  3349. bind: function bind() {
  3350. var self = this;
  3351. var el = this.el;
  3352. // method to force update DOM using latest value.
  3353. this.forceUpdate = function () {
  3354. if (self._watcher) {
  3355. self.update(self._watcher.get());
  3356. }
  3357. };
  3358. // check if this is a multiple select
  3359. var multiple = this.multiple = el.hasAttribute('multiple');
  3360. // attach listener
  3361. this.listener = function () {
  3362. var value = getValue(el, multiple);
  3363. value = self.params.number ? isArray(value) ? value.map(toNumber) : toNumber(value) : value;
  3364. self.set(value);
  3365. };
  3366. this.on('change', this.listener);
  3367. // if has initial value, set afterBind
  3368. var initValue = getValue(el, multiple, true);
  3369. if (multiple && initValue.length || !multiple && initValue !== null) {
  3370. this.afterBind = this.listener;
  3371. }
  3372. // All major browsers except Firefox resets
  3373. // selectedIndex with value -1 to 0 when the element
  3374. // is appended to a new parent, therefore we have to
  3375. // force a DOM update whenever that happens...
  3376. this.vm.$on('hook:attached', this.forceUpdate);
  3377. },
  3378. update: function update(value) {
  3379. var el = this.el;
  3380. el.selectedIndex = -1;
  3381. var multi = this.multiple && isArray(value);
  3382. var options = el.options;
  3383. var i = options.length;
  3384. var op, val;
  3385. while (i--) {
  3386. op = options[i];
  3387. val = op.hasOwnProperty('_value') ? op._value : op.value;
  3388. /* eslint-disable eqeqeq */
  3389. op.selected = multi ? indexOf$1(value, val) > -1 : looseEqual(value, val);
  3390. /* eslint-enable eqeqeq */
  3391. }
  3392. },
  3393. unbind: function unbind() {
  3394. /* istanbul ignore next */
  3395. this.vm.$off('hook:attached', this.forceUpdate);
  3396. }
  3397. };
  3398. /**
  3399. * Get select value
  3400. *
  3401. * @param {SelectElement} el
  3402. * @param {Boolean} multi
  3403. * @param {Boolean} init
  3404. * @return {Array|*}
  3405. */
  3406. function getValue(el, multi, init) {
  3407. var res = multi ? [] : null;
  3408. var op, val, selected;
  3409. for (var i = 0, l = el.options.length; i < l; i++) {
  3410. op = el.options[i];
  3411. selected = init ? op.hasAttribute('selected') : op.selected;
  3412. if (selected) {
  3413. val = op.hasOwnProperty('_value') ? op._value : op.value;
  3414. if (multi) {
  3415. res.push(val);
  3416. } else {
  3417. return val;
  3418. }
  3419. }
  3420. }
  3421. return res;
  3422. }
  3423. /**
  3424. * Native Array.indexOf uses strict equal, but in this
  3425. * case we need to match string/numbers with custom equal.
  3426. *
  3427. * @param {Array} arr
  3428. * @param {*} val
  3429. */
  3430. function indexOf$1(arr, val) {
  3431. var i = arr.length;
  3432. while (i--) {
  3433. if (looseEqual(arr[i], val)) {
  3434. return i;
  3435. }
  3436. }
  3437. return -1;
  3438. }
  3439. var radio = {
  3440. bind: function bind() {
  3441. var self = this;
  3442. var el = this.el;
  3443. this.getValue = function () {
  3444. // value overwrite via v-bind:value
  3445. if (el.hasOwnProperty('_value')) {
  3446. return el._value;
  3447. }
  3448. var val = el.value;
  3449. if (self.params.number) {
  3450. val = toNumber(val);
  3451. }
  3452. return val;
  3453. };
  3454. this.listener = function () {
  3455. self.set(self.getValue());
  3456. };
  3457. this.on('change', this.listener);
  3458. if (el.hasAttribute('checked')) {
  3459. this.afterBind = this.listener;
  3460. }
  3461. },
  3462. update: function update(value) {
  3463. this.el.checked = looseEqual(value, this.getValue());
  3464. }
  3465. };
  3466. var text$2 = {
  3467. bind: function bind() {
  3468. var self = this;
  3469. var el = this.el;
  3470. var isRange = el.type === 'range';
  3471. var lazy = this.params.lazy;
  3472. var number = this.params.number;
  3473. var debounce = this.params.debounce;
  3474. // handle composition events.
  3475. // http://blog.evanyou.me/2014/01/03/composition-event/
  3476. // skip this for Android because it handles composition
  3477. // events quite differently. Android doesn't trigger
  3478. // composition events for language input methods e.g.
  3479. // Chinese, but instead triggers them for spelling
  3480. // suggestions... (see Discussion/#162)
  3481. var composing = false;
  3482. if (!isAndroid && !isRange) {
  3483. this.on('compositionstart', function () {
  3484. composing = true;
  3485. });
  3486. this.on('compositionend', function () {
  3487. composing = false;
  3488. // in IE11 the "compositionend" event fires AFTER
  3489. // the "input" event, so the input handler is blocked
  3490. // at the end... have to call it here.
  3491. //
  3492. // #1327: in lazy mode this is unecessary.
  3493. if (!lazy) {
  3494. self.listener();
  3495. }
  3496. });
  3497. }
  3498. // prevent messing with the input when user is typing,
  3499. // and force update on blur.
  3500. this.focused = false;
  3501. if (!isRange && !lazy) {
  3502. this.on('focus', function () {
  3503. self.focused = true;
  3504. });
  3505. this.on('blur', function () {
  3506. self.focused = false;
  3507. // do not sync value after fragment removal (#2017)
  3508. if (!self._frag || self._frag.inserted) {
  3509. self.rawListener();
  3510. }
  3511. });
  3512. }
  3513. // Now attach the main listener
  3514. this.listener = this.rawListener = function () {
  3515. if (composing || !self._bound) {
  3516. return;
  3517. }
  3518. var val = number || isRange ? toNumber(el.value) : el.value;
  3519. self.set(val);
  3520. // force update on next tick to avoid lock & same value
  3521. // also only update when user is not typing
  3522. nextTick(function () {
  3523. if (self._bound && !self.focused) {
  3524. self.update(self._watcher.value);
  3525. }
  3526. });
  3527. };
  3528. // apply debounce
  3529. if (debounce) {
  3530. this.listener = _debounce(this.listener, debounce);
  3531. }
  3532. // Support jQuery events, since jQuery.trigger() doesn't
  3533. // trigger native events in some cases and some plugins
  3534. // rely on $.trigger()
  3535. //
  3536. // We want to make sure if a listener is attached using
  3537. // jQuery, it is also removed with jQuery, that's why
  3538. // we do the check for each directive instance and
  3539. // store that check result on itself. This also allows
  3540. // easier test coverage control by unsetting the global
  3541. // jQuery variable in tests.
  3542. this.hasjQuery = typeof jQuery === 'function';
  3543. if (this.hasjQuery) {
  3544. jQuery(el).on('change', this.listener);
  3545. if (!lazy) {
  3546. jQuery(el).on('input', this.listener);
  3547. }
  3548. } else {
  3549. this.on('change', this.listener);
  3550. if (!lazy) {
  3551. this.on('input', this.listener);
  3552. }
  3553. }
  3554. // IE9 doesn't fire input event on backspace/del/cut
  3555. if (!lazy && isIE9) {
  3556. this.on('cut', function () {
  3557. nextTick(self.listener);
  3558. });
  3559. this.on('keyup', function (e) {
  3560. if (e.keyCode === 46 || e.keyCode === 8) {
  3561. self.listener();
  3562. }
  3563. });
  3564. }
  3565. // set initial value if present
  3566. if (el.hasAttribute('value') || el.tagName === 'TEXTAREA' && el.value.trim()) {
  3567. this.afterBind = this.listener;
  3568. }
  3569. },
  3570. update: function update(value) {
  3571. this.el.value = _toString(value);
  3572. },
  3573. unbind: function unbind() {
  3574. var el = this.el;
  3575. if (this.hasjQuery) {
  3576. jQuery(el).off('change', this.listener);
  3577. jQuery(el).off('input', this.listener);
  3578. }
  3579. }
  3580. };
  3581. var handlers = {
  3582. text: text$2,
  3583. radio: radio,
  3584. select: select,
  3585. checkbox: checkbox
  3586. };
  3587. var model = {
  3588. priority: MODEL,
  3589. twoWay: true,
  3590. handlers: handlers,
  3591. params: ['lazy', 'number', 'debounce'],
  3592. /**
  3593. * Possible elements:
  3594. * <select>
  3595. * <textarea>
  3596. * <input type="*">
  3597. * - text
  3598. * - checkbox
  3599. * - radio
  3600. * - number
  3601. */
  3602. bind: function bind() {
  3603. // friendly warning...
  3604. this.checkFilters();
  3605. if (this.hasRead && !this.hasWrite) {
  3606. 'development' !== 'production' && warn('It seems you are using a read-only filter with ' + 'v-model. You might want to use a two-way filter ' + 'to ensure correct behavior.');
  3607. }
  3608. var el = this.el;
  3609. var tag = el.tagName;
  3610. var handler;
  3611. if (tag === 'INPUT') {
  3612. handler = handlers[el.type] || handlers.text;
  3613. } else if (tag === 'SELECT') {
  3614. handler = handlers.select;
  3615. } else if (tag === 'TEXTAREA') {
  3616. handler = handlers.text;
  3617. } else {
  3618. 'development' !== 'production' && warn('v-model does not support element type: ' + tag);
  3619. return;
  3620. }
  3621. el.__v_model = this;
  3622. handler.bind.call(this);
  3623. this.update = handler.update;
  3624. this._unbind = handler.unbind;
  3625. },
  3626. /**
  3627. * Check read/write filter stats.
  3628. */
  3629. checkFilters: function checkFilters() {
  3630. var filters = this.filters;
  3631. if (!filters) return;
  3632. var i = filters.length;
  3633. while (i--) {
  3634. var filter = resolveAsset(this.vm.$options, 'filters', filters[i].name);
  3635. if (typeof filter === 'function' || filter.read) {
  3636. this.hasRead = true;
  3637. }
  3638. if (filter.write) {
  3639. this.hasWrite = true;
  3640. }
  3641. }
  3642. },
  3643. unbind: function unbind() {
  3644. this.el.__v_model = null;
  3645. this._unbind && this._unbind();
  3646. }
  3647. };
  3648. var show = {
  3649. bind: function bind() {
  3650. // check else block
  3651. var next = this.el.nextElementSibling;
  3652. if (next && getAttr(next, 'v-else') !== null) {
  3653. this.elseEl = next;
  3654. }
  3655. },
  3656. update: function update(value) {
  3657. this.apply(this.el, value);
  3658. if (this.elseEl) {
  3659. this.apply(this.elseEl, !value);
  3660. }
  3661. },
  3662. apply: function apply(el, value) {
  3663. if (inDoc(el)) {
  3664. applyTransition(el, value ? 1 : -1, toggle, this.vm);
  3665. } else {
  3666. toggle();
  3667. }
  3668. function toggle() {
  3669. el.style.display = value ? '' : 'none';
  3670. }
  3671. }
  3672. };
  3673. var templateCache = new Cache(1000);
  3674. var idSelectorCache = new Cache(1000);
  3675. var map = {
  3676. efault: [0, '', ''],
  3677. legend: [1, '<fieldset>', '</fieldset>'],
  3678. tr: [2, '<table><tbody>', '</tbody></table>'],
  3679. col: [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>']
  3680. };
  3681. map.td = map.th = [3, '<table><tbody><tr>', '</tr></tbody></table>'];
  3682. map.option = map.optgroup = [1, '<select multiple="multiple">', '</select>'];
  3683. map.thead = map.tbody = map.colgroup = map.caption = map.tfoot = [1, '<table>', '</table>'];
  3684. map.g = map.defs = map.symbol = map.use = map.image = map.text = map.circle = map.ellipse = map.line = map.path = map.polygon = map.polyline = map.rect = [1, '<svg ' + 'xmlns="http://www.w3.org/2000/svg" ' + 'xmlns:xlink="http://www.w3.org/1999/xlink" ' + 'xmlns:ev="http://www.w3.org/2001/xml-events"' + 'version="1.1">', '</svg>'];
  3685. /**
  3686. * Check if a node is a supported template node with a
  3687. * DocumentFragment content.
  3688. *
  3689. * @param {Node} node
  3690. * @return {Boolean}
  3691. */
  3692. function isRealTemplate(node) {
  3693. return isTemplate(node) && node.content instanceof DocumentFragment;
  3694. }
  3695. var tagRE$1 = /<([\w:]+)/;
  3696. var entityRE = /&#?\w+?;/;
  3697. /**
  3698. * Convert a string template to a DocumentFragment.
  3699. * Determines correct wrapping by tag types. Wrapping
  3700. * strategy found in jQuery & component/domify.
  3701. *
  3702. * @param {String} templateString
  3703. * @param {Boolean} raw
  3704. * @return {DocumentFragment}
  3705. */
  3706. function stringToFragment(templateString, raw) {
  3707. // try a cache hit first
  3708. var hit = templateCache.get(templateString);
  3709. if (hit) {
  3710. return hit;
  3711. }
  3712. var frag = document.createDocumentFragment();
  3713. var tagMatch = templateString.match(tagRE$1);
  3714. var entityMatch = entityRE.test(templateString);
  3715. if (!tagMatch && !entityMatch) {
  3716. // text only, return a single text node.
  3717. frag.appendChild(document.createTextNode(templateString));
  3718. } else {
  3719. var tag = tagMatch && tagMatch[1];
  3720. var wrap = map[tag] || map.efault;
  3721. var depth = wrap[0];
  3722. var prefix = wrap[1];
  3723. var suffix = wrap[2];
  3724. var node = document.createElement('div');
  3725. var templateStringToUse = raw ? templateString : templateString.trim();
  3726. node.innerHTML = prefix + templateStringToUse + suffix;
  3727. while (depth--) {
  3728. node = node.lastChild;
  3729. }
  3730. var child;
  3731. /* eslint-disable no-cond-assign */
  3732. while (child = node.firstChild) {
  3733. /* eslint-enable no-cond-assign */
  3734. frag.appendChild(child);
  3735. }
  3736. }
  3737. templateCache.put(templateString, frag);
  3738. return frag;
  3739. }
  3740. /**
  3741. * Convert a template node to a DocumentFragment.
  3742. *
  3743. * @param {Node} node
  3744. * @return {DocumentFragment}
  3745. */
  3746. function nodeToFragment(node) {
  3747. // if its a template tag and the browser supports it,
  3748. // its content is already a document fragment.
  3749. if (isRealTemplate(node)) {
  3750. trimNode(node.content);
  3751. return node.content;
  3752. }
  3753. // script template
  3754. if (node.tagName === 'SCRIPT') {
  3755. return stringToFragment(node.textContent);
  3756. }
  3757. // normal node, clone it to avoid mutating the original
  3758. var clonedNode = cloneNode(node);
  3759. var frag = document.createDocumentFragment();
  3760. var child;
  3761. /* eslint-disable no-cond-assign */
  3762. while (child = clonedNode.firstChild) {
  3763. /* eslint-enable no-cond-assign */
  3764. frag.appendChild(child);
  3765. }
  3766. trimNode(frag);
  3767. return frag;
  3768. }
  3769. // Test for the presence of the Safari template cloning bug
  3770. // https://bugs.webkit.org/showug.cgi?id=137755
  3771. var hasBrokenTemplate = (function () {
  3772. /* istanbul ignore else */
  3773. if (inBrowser) {
  3774. var a = document.createElement('div');
  3775. a.innerHTML = '<template>1</template>';
  3776. return !a.cloneNode(true).firstChild.innerHTML;
  3777. } else {
  3778. return false;
  3779. }
  3780. })();
  3781. // Test for IE10/11 textarea placeholder clone bug
  3782. var hasTextareaCloneBug = (function () {
  3783. /* istanbul ignore else */
  3784. if (inBrowser) {
  3785. var t = document.createElement('textarea');
  3786. t.placeholder = 't';
  3787. return t.cloneNode(true).value === 't';
  3788. } else {
  3789. return false;
  3790. }
  3791. })();
  3792. /**
  3793. * 1. Deal with Safari cloning nested <template> bug by
  3794. * manually cloning all template instances.
  3795. * 2. Deal with IE10/11 textarea placeholder bug by setting
  3796. * the correct value after cloning.
  3797. *
  3798. * @param {Element|DocumentFragment} node
  3799. * @return {Element|DocumentFragment}
  3800. */
  3801. function cloneNode(node) {
  3802. if (!node.querySelectorAll) {
  3803. return node.cloneNode();
  3804. }
  3805. var res = node.cloneNode(true);
  3806. var i, original, cloned;
  3807. /* istanbul ignore if */
  3808. if (hasBrokenTemplate) {
  3809. var tempClone = res;
  3810. if (isRealTemplate(node)) {
  3811. node = node.content;
  3812. tempClone = res.content;
  3813. }
  3814. original = node.querySelectorAll('template');
  3815. if (original.length) {
  3816. cloned = tempClone.querySelectorAll('template');
  3817. i = cloned.length;
  3818. while (i--) {
  3819. cloned[i].parentNode.replaceChild(cloneNode(original[i]), cloned[i]);
  3820. }
  3821. }
  3822. }
  3823. /* istanbul ignore if */
  3824. if (hasTextareaCloneBug) {
  3825. if (node.tagName === 'TEXTAREA') {
  3826. res.value = node.value;
  3827. } else {
  3828. original = node.querySelectorAll('textarea');
  3829. if (original.length) {
  3830. cloned = res.querySelectorAll('textarea');
  3831. i = cloned.length;
  3832. while (i--) {
  3833. cloned[i].value = original[i].value;
  3834. }
  3835. }
  3836. }
  3837. }
  3838. return res;
  3839. }
  3840. /**
  3841. * Process the template option and normalizes it into a
  3842. * a DocumentFragment that can be used as a partial or a
  3843. * instance template.
  3844. *
  3845. * @param {*} template
  3846. * Possible values include:
  3847. * - DocumentFragment object
  3848. * - Node object of type Template
  3849. * - id selector: '#some-template-id'
  3850. * - template string: '<div><span>{{msg}}</span></div>'
  3851. * @param {Boolean} shouldClone
  3852. * @param {Boolean} raw
  3853. * inline HTML interpolation. Do not check for id
  3854. * selector and keep whitespace in the string.
  3855. * @return {DocumentFragment|undefined}
  3856. */
  3857. function parseTemplate(template, shouldClone, raw) {
  3858. var node, frag;
  3859. // if the template is already a document fragment,
  3860. // do nothing
  3861. if (template instanceof DocumentFragment) {
  3862. trimNode(template);
  3863. return shouldClone ? cloneNode(template) : template;
  3864. }
  3865. if (typeof template === 'string') {
  3866. // id selector
  3867. if (!raw && template.charAt(0) === '#') {
  3868. // id selector can be cached too
  3869. frag = idSelectorCache.get(template);
  3870. if (!frag) {
  3871. node = document.getElementById(template.slice(1));
  3872. if (node) {
  3873. frag = nodeToFragment(node);
  3874. // save selector to cache
  3875. idSelectorCache.put(template, frag);
  3876. }
  3877. }
  3878. } else {
  3879. // normal string template
  3880. frag = stringToFragment(template, raw);
  3881. }
  3882. } else if (template.nodeType) {
  3883. // a direct node
  3884. frag = nodeToFragment(template);
  3885. }
  3886. return frag && shouldClone ? cloneNode(frag) : frag;
  3887. }
  3888. var template = Object.freeze({
  3889. cloneNode: cloneNode,
  3890. parseTemplate: parseTemplate
  3891. });
  3892. /**
  3893. * Abstraction for a partially-compiled fragment.
  3894. * Can optionally compile content with a child scope.
  3895. *
  3896. * @param {Function} linker
  3897. * @param {Vue} vm
  3898. * @param {DocumentFragment} frag
  3899. * @param {Vue} [host]
  3900. * @param {Object} [scope]
  3901. */
  3902. function Fragment(linker, vm, frag, host, scope, parentFrag) {
  3903. this.children = [];
  3904. this.childFrags = [];
  3905. this.vm = vm;
  3906. this.scope = scope;
  3907. this.inserted = false;
  3908. this.parentFrag = parentFrag;
  3909. if (parentFrag) {
  3910. parentFrag.childFrags.push(this);
  3911. }
  3912. this.unlink = linker(vm, frag, host, scope, this);
  3913. var single = this.single = frag.childNodes.length === 1 &&
  3914. // do not go single mode if the only node is an anchor
  3915. !frag.childNodes[0].__vue_anchor;
  3916. if (single) {
  3917. this.node = frag.childNodes[0];
  3918. this.before = singleBefore;
  3919. this.remove = singleRemove;
  3920. } else {
  3921. this.node = createAnchor('fragment-start');
  3922. this.end = createAnchor('fragment-end');
  3923. this.frag = frag;
  3924. prepend(this.node, frag);
  3925. frag.appendChild(this.end);
  3926. this.before = multiBefore;
  3927. this.remove = multiRemove;
  3928. }
  3929. this.node.__vfrag__ = this;
  3930. }
  3931. /**
  3932. * Call attach/detach for all components contained within
  3933. * this fragment. Also do so recursively for all child
  3934. * fragments.
  3935. *
  3936. * @param {Function} hook
  3937. */
  3938. Fragment.prototype.callHook = function (hook) {
  3939. var i, l;
  3940. for (i = 0, l = this.childFrags.length; i < l; i++) {
  3941. this.childFrags[i].callHook(hook);
  3942. }
  3943. for (i = 0, l = this.children.length; i < l; i++) {
  3944. hook(this.children[i]);
  3945. }
  3946. };
  3947. /**
  3948. * Insert fragment before target, single node version
  3949. *
  3950. * @param {Node} target
  3951. * @param {Boolean} withTransition
  3952. */
  3953. function singleBefore(target, withTransition) {
  3954. this.inserted = true;
  3955. var method = withTransition !== false ? beforeWithTransition : before;
  3956. method(this.node, target, this.vm);
  3957. if (inDoc(this.node)) {
  3958. this.callHook(attach);
  3959. }
  3960. }
  3961. /**
  3962. * Remove fragment, single node version
  3963. */
  3964. function singleRemove() {
  3965. this.inserted = false;
  3966. var shouldCallRemove = inDoc(this.node);
  3967. var self = this;
  3968. this.beforeRemove();
  3969. removeWithTransition(this.node, this.vm, function () {
  3970. if (shouldCallRemove) {
  3971. self.callHook(detach);
  3972. }
  3973. self.destroy();
  3974. });
  3975. }
  3976. /**
  3977. * Insert fragment before target, multi-nodes version
  3978. *
  3979. * @param {Node} target
  3980. * @param {Boolean} withTransition
  3981. */
  3982. function multiBefore(target, withTransition) {
  3983. this.inserted = true;
  3984. var vm = this.vm;
  3985. var method = withTransition !== false ? beforeWithTransition : before;
  3986. mapNodeRange(this.node, this.end, function (node) {
  3987. method(node, target, vm);
  3988. });
  3989. if (inDoc(this.node)) {
  3990. this.callHook(attach);
  3991. }
  3992. }
  3993. /**
  3994. * Remove fragment, multi-nodes version
  3995. */
  3996. function multiRemove() {
  3997. this.inserted = false;
  3998. var self = this;
  3999. var shouldCallRemove = inDoc(this.node);
  4000. this.beforeRemove();
  4001. removeNodeRange(this.node, this.end, this.vm, this.frag, function () {
  4002. if (shouldCallRemove) {
  4003. self.callHook(detach);
  4004. }
  4005. self.destroy();
  4006. });
  4007. }
  4008. /**
  4009. * Prepare the fragment for removal.
  4010. */
  4011. Fragment.prototype.beforeRemove = function () {
  4012. var i, l;
  4013. for (i = 0, l = this.childFrags.length; i < l; i++) {
  4014. // call the same method recursively on child
  4015. // fragments, depth-first
  4016. this.childFrags[i].beforeRemove(false);
  4017. }
  4018. for (i = 0, l = this.children.length; i < l; i++) {
  4019. // Call destroy for all contained instances,
  4020. // with remove:false and defer:true.
  4021. // Defer is necessary because we need to
  4022. // keep the children to call detach hooks
  4023. // on them.
  4024. this.children[i].$destroy(false, true);
  4025. }
  4026. var dirs = this.unlink.dirs;
  4027. for (i = 0, l = dirs.length; i < l; i++) {
  4028. // disable the watchers on all the directives
  4029. // so that the rendered content stays the same
  4030. // during removal.
  4031. dirs[i]._watcher && dirs[i]._watcher.teardown();
  4032. }
  4033. };
  4034. /**
  4035. * Destroy the fragment.
  4036. */
  4037. Fragment.prototype.destroy = function () {
  4038. if (this.parentFrag) {
  4039. this.parentFrag.childFrags.$remove(this);
  4040. }
  4041. this.node.__vfrag__ = null;
  4042. this.unlink();
  4043. };
  4044. /**
  4045. * Call attach hook for a Vue instance.
  4046. *
  4047. * @param {Vue} child
  4048. */
  4049. function attach(child) {
  4050. if (!child._isAttached) {
  4051. child._callHook('attached');
  4052. }
  4053. }
  4054. /**
  4055. * Call detach hook for a Vue instance.
  4056. *
  4057. * @param {Vue} child
  4058. */
  4059. function detach(child) {
  4060. if (child._isAttached) {
  4061. child._callHook('detached');
  4062. }
  4063. }
  4064. var linkerCache = new Cache(5000);
  4065. /**
  4066. * A factory that can be used to create instances of a
  4067. * fragment. Caches the compiled linker if possible.
  4068. *
  4069. * @param {Vue} vm
  4070. * @param {Element|String} el
  4071. */
  4072. function FragmentFactory(vm, el) {
  4073. this.vm = vm;
  4074. var template;
  4075. var isString = typeof el === 'string';
  4076. if (isString || isTemplate(el)) {
  4077. template = parseTemplate(el, true);
  4078. } else {
  4079. template = document.createDocumentFragment();
  4080. template.appendChild(el);
  4081. }
  4082. this.template = template;
  4083. // linker can be cached, but only for components
  4084. var linker;
  4085. var cid = vm.constructor.cid;
  4086. if (cid > 0) {
  4087. var cacheId = cid + (isString ? el : el.outerHTML);
  4088. linker = linkerCache.get(cacheId);
  4089. if (!linker) {
  4090. linker = compile(template, vm.$options, true);
  4091. linkerCache.put(cacheId, linker);
  4092. }
  4093. } else {
  4094. linker = compile(template, vm.$options, true);
  4095. }
  4096. this.linker = linker;
  4097. }
  4098. /**
  4099. * Create a fragment instance with given host and scope.
  4100. *
  4101. * @param {Vue} host
  4102. * @param {Object} scope
  4103. * @param {Fragment} parentFrag
  4104. */
  4105. FragmentFactory.prototype.create = function (host, scope, parentFrag) {
  4106. var frag = cloneNode(this.template);
  4107. return new Fragment(this.linker, this.vm, frag, host, scope, parentFrag);
  4108. };
  4109. var vIf = {
  4110. priority: IF,
  4111. bind: function bind() {
  4112. var el = this.el;
  4113. if (!el.__vue__) {
  4114. // check else block
  4115. var next = el.nextElementSibling;
  4116. if (next && getAttr(next, 'v-else') !== null) {
  4117. remove(next);
  4118. this.elseFactory = new FragmentFactory(this.vm, next);
  4119. }
  4120. // check main block
  4121. this.anchor = createAnchor('v-if');
  4122. replace(el, this.anchor);
  4123. this.factory = new FragmentFactory(this.vm, el);
  4124. } else {
  4125. 'development' !== 'production' && warn('v-if="' + this.expression + '" cannot be ' + 'used on an instance root element.');
  4126. this.invalid = true;
  4127. }
  4128. },
  4129. update: function update(value) {
  4130. if (this.invalid) return;
  4131. if (value) {
  4132. if (!this.frag) {
  4133. this.insert();
  4134. }
  4135. } else {
  4136. this.remove();
  4137. }
  4138. },
  4139. insert: function insert() {
  4140. if (this.elseFrag) {
  4141. this.elseFrag.remove();
  4142. this.elseFrag = null;
  4143. }
  4144. this.frag = this.factory.create(this._host, this._scope, this._frag);
  4145. this.frag.before(this.anchor);
  4146. },
  4147. remove: function remove() {
  4148. if (this.frag) {
  4149. this.frag.remove();
  4150. this.frag = null;
  4151. }
  4152. if (this.elseFactory && !this.elseFrag) {
  4153. this.elseFrag = this.elseFactory.create(this._host, this._scope, this._frag);
  4154. this.elseFrag.before(this.anchor);
  4155. }
  4156. },
  4157. unbind: function unbind() {
  4158. if (this.frag) {
  4159. this.frag.destroy();
  4160. }
  4161. }
  4162. };
  4163. var uid$1 = 0;
  4164. var vFor = {
  4165. priority: FOR,
  4166. params: ['track-by', 'stagger', 'enter-stagger', 'leave-stagger'],
  4167. bind: function bind() {
  4168. // support "item in items" syntax
  4169. var inMatch = this.expression.match(/(.*) in (.*)/);
  4170. if (inMatch) {
  4171. var itMatch = inMatch[1].match(/\((.*),(.*)\)/);
  4172. if (itMatch) {
  4173. this.iterator = itMatch[1].trim();
  4174. this.alias = itMatch[2].trim();
  4175. } else {
  4176. this.alias = inMatch[1].trim();
  4177. }
  4178. this.expression = inMatch[2];
  4179. }
  4180. if (!this.alias) {
  4181. 'development' !== 'production' && warn('Alias is required in v-for.');
  4182. return;
  4183. }
  4184. // uid as a cache identifier
  4185. this.id = '__v-for__' + ++uid$1;
  4186. // check if this is an option list,
  4187. // so that we know if we need to update the <select>'s
  4188. // v-model when the option list has changed.
  4189. // because v-model has a lower priority than v-for,
  4190. // the v-model is not bound here yet, so we have to
  4191. // retrive it in the actual updateModel() function.
  4192. var tag = this.el.tagName;
  4193. this.isOption = (tag === 'OPTION' || tag === 'OPTGROUP') && this.el.parentNode.tagName === 'SELECT';
  4194. // setup anchor nodes
  4195. this.start = createAnchor('v-for-start');
  4196. this.end = createAnchor('v-for-end');
  4197. replace(this.el, this.end);
  4198. before(this.start, this.end);
  4199. // cache
  4200. this.cache = Object.create(null);
  4201. // fragment factory
  4202. this.factory = new FragmentFactory(this.vm, this.el);
  4203. },
  4204. update: function update(data) {
  4205. this.diff(data);
  4206. this.updateRef();
  4207. this.updateModel();
  4208. },
  4209. /**
  4210. * Diff, based on new data and old data, determine the
  4211. * minimum amount of DOM manipulations needed to make the
  4212. * DOM reflect the new data Array.
  4213. *
  4214. * The algorithm diffs the new data Array by storing a
  4215. * hidden reference to an owner vm instance on previously
  4216. * seen data. This allows us to achieve O(n) which is
  4217. * better than a levenshtein distance based algorithm,
  4218. * which is O(m * n).
  4219. *
  4220. * @param {Array} data
  4221. */
  4222. diff: function diff(data) {
  4223. // check if the Array was converted from an Object
  4224. var item = data[0];
  4225. var convertedFromObject = this.fromObject = isObject(item) && hasOwn(item, '$key') && hasOwn(item, '$value');
  4226. var trackByKey = this.params.trackBy;
  4227. var oldFrags = this.frags;
  4228. var frags = this.frags = new Array(data.length);
  4229. var alias = this.alias;
  4230. var iterator = this.iterator;
  4231. var start = this.start;
  4232. var end = this.end;
  4233. var inDocument = inDoc(start);
  4234. var init = !oldFrags;
  4235. var i, l, frag, key, value, primitive;
  4236. // First pass, go through the new Array and fill up
  4237. // the new frags array. If a piece of data has a cached
  4238. // instance for it, we reuse it. Otherwise build a new
  4239. // instance.
  4240. for (i = 0, l = data.length; i < l; i++) {
  4241. item = data[i];
  4242. key = convertedFromObject ? item.$key : null;
  4243. value = convertedFromObject ? item.$value : item;
  4244. primitive = !isObject(value);
  4245. frag = !init && this.getCachedFrag(value, i, key);
  4246. if (frag) {
  4247. // reusable fragment
  4248. frag.reused = true;
  4249. // update $index
  4250. frag.scope.$index = i;
  4251. // update $key
  4252. if (key) {
  4253. frag.scope.$key = key;
  4254. }
  4255. // update iterator
  4256. if (iterator) {
  4257. frag.scope[iterator] = key !== null ? key : i;
  4258. }
  4259. // update data for track-by, object repeat &
  4260. // primitive values.
  4261. if (trackByKey || convertedFromObject || primitive) {
  4262. frag.scope[alias] = value;
  4263. }
  4264. } else {
  4265. // new isntance
  4266. frag = this.create(value, alias, i, key);
  4267. frag.fresh = !init;
  4268. }
  4269. frags[i] = frag;
  4270. if (init) {
  4271. frag.before(end);
  4272. }
  4273. }
  4274. // we're done for the initial render.
  4275. if (init) {
  4276. return;
  4277. }
  4278. // Second pass, go through the old fragments and
  4279. // destroy those who are not reused (and remove them
  4280. // from cache)
  4281. var removalIndex = 0;
  4282. var totalRemoved = oldFrags.length - frags.length;
  4283. for (i = 0, l = oldFrags.length; i < l; i++) {
  4284. frag = oldFrags[i];
  4285. if (!frag.reused) {
  4286. this.deleteCachedFrag(frag);
  4287. this.remove(frag, removalIndex++, totalRemoved, inDocument);
  4288. }
  4289. }
  4290. // Final pass, move/insert new fragments into the
  4291. // right place.
  4292. var targetPrev, prevEl, currentPrev;
  4293. var insertionIndex = 0;
  4294. for (i = 0, l = frags.length; i < l; i++) {
  4295. frag = frags[i];
  4296. // this is the frag that we should be after
  4297. targetPrev = frags[i - 1];
  4298. prevEl = targetPrev ? targetPrev.staggerCb ? targetPrev.staggerAnchor : targetPrev.end || targetPrev.node : start;
  4299. if (frag.reused && !frag.staggerCb) {
  4300. currentPrev = findPrevFrag(frag, start, this.id);
  4301. if (currentPrev !== targetPrev && (!currentPrev ||
  4302. // optimization for moving a single item.
  4303. // thanks to suggestions by @livoras in #1807
  4304. findPrevFrag(currentPrev, start, this.id) !== targetPrev)) {
  4305. this.move(frag, prevEl);
  4306. }
  4307. } else {
  4308. // new instance, or still in stagger.
  4309. // insert with updated stagger index.
  4310. this.insert(frag, insertionIndex++, prevEl, inDocument);
  4311. }
  4312. frag.reused = frag.fresh = false;
  4313. }
  4314. },
  4315. /**
  4316. * Create a new fragment instance.
  4317. *
  4318. * @param {*} value
  4319. * @param {String} alias
  4320. * @param {Number} index
  4321. * @param {String} [key]
  4322. * @return {Fragment}
  4323. */
  4324. create: function create(value, alias, index, key) {
  4325. var host = this._host;
  4326. // create iteration scope
  4327. var parentScope = this._scope || this.vm;
  4328. var scope = Object.create(parentScope);
  4329. // ref holder for the scope
  4330. scope.$refs = Object.create(parentScope.$refs);
  4331. scope.$els = Object.create(parentScope.$els);
  4332. // make sure point $parent to parent scope
  4333. scope.$parent = parentScope;
  4334. // for two-way binding on alias
  4335. scope.$forContext = this;
  4336. // define scope properties
  4337. defineReactive(scope, alias, value);
  4338. defineReactive(scope, '$index', index);
  4339. if (key) {
  4340. defineReactive(scope, '$key', key);
  4341. } else if (scope.$key) {
  4342. // avoid accidental fallback
  4343. def(scope, '$key', null);
  4344. }
  4345. if (this.iterator) {
  4346. defineReactive(scope, this.iterator, key !== null ? key : index);
  4347. }
  4348. var frag = this.factory.create(host, scope, this._frag);
  4349. frag.forId = this.id;
  4350. this.cacheFrag(value, frag, index, key);
  4351. return frag;
  4352. },
  4353. /**
  4354. * Update the v-ref on owner vm.
  4355. */
  4356. updateRef: function updateRef() {
  4357. var ref = this.descriptor.ref;
  4358. if (!ref) return;
  4359. var hash = (this._scope || this.vm).$refs;
  4360. var refs;
  4361. if (!this.fromObject) {
  4362. refs = this.frags.map(findVmFromFrag);
  4363. } else {
  4364. refs = {};
  4365. this.frags.forEach(function (frag) {
  4366. refs[frag.scope.$key] = findVmFromFrag(frag);
  4367. });
  4368. }
  4369. hash[ref] = refs;
  4370. },
  4371. /**
  4372. * For option lists, update the containing v-model on
  4373. * parent <select>.
  4374. */
  4375. updateModel: function updateModel() {
  4376. if (this.isOption) {
  4377. var parent = this.start.parentNode;
  4378. var model = parent && parent.__v_model;
  4379. if (model) {
  4380. model.forceUpdate();
  4381. }
  4382. }
  4383. },
  4384. /**
  4385. * Insert a fragment. Handles staggering.
  4386. *
  4387. * @param {Fragment} frag
  4388. * @param {Number} index
  4389. * @param {Node} prevEl
  4390. * @param {Boolean} inDocument
  4391. */
  4392. insert: function insert(frag, index, prevEl, inDocument) {
  4393. if (frag.staggerCb) {
  4394. frag.staggerCb.cancel();
  4395. frag.staggerCb = null;
  4396. }
  4397. var staggerAmount = this.getStagger(frag, index, null, 'enter');
  4398. if (inDocument && staggerAmount) {
  4399. // create an anchor and insert it synchronously,
  4400. // so that we can resolve the correct order without
  4401. // worrying about some elements not inserted yet
  4402. var anchor = frag.staggerAnchor;
  4403. if (!anchor) {
  4404. anchor = frag.staggerAnchor = createAnchor('stagger-anchor');
  4405. anchor.__vfrag__ = frag;
  4406. }
  4407. after(anchor, prevEl);
  4408. var op = frag.staggerCb = cancellable(function () {
  4409. frag.staggerCb = null;
  4410. frag.before(anchor);
  4411. remove(anchor);
  4412. });
  4413. setTimeout(op, staggerAmount);
  4414. } else {
  4415. frag.before(prevEl.nextSibling);
  4416. }
  4417. },
  4418. /**
  4419. * Remove a fragment. Handles staggering.
  4420. *
  4421. * @param {Fragment} frag
  4422. * @param {Number} index
  4423. * @param {Number} total
  4424. * @param {Boolean} inDocument
  4425. */
  4426. remove: function remove(frag, index, total, inDocument) {
  4427. if (frag.staggerCb) {
  4428. frag.staggerCb.cancel();
  4429. frag.staggerCb = null;
  4430. // it's not possible for the same frag to be removed
  4431. // twice, so if we have a pending stagger callback,
  4432. // it means this frag is queued for enter but removed
  4433. // before its transition started. Since it is already
  4434. // destroyed, we can just leave it in detached state.
  4435. return;
  4436. }
  4437. var staggerAmount = this.getStagger(frag, index, total, 'leave');
  4438. if (inDocument && staggerAmount) {
  4439. var op = frag.staggerCb = cancellable(function () {
  4440. frag.staggerCb = null;
  4441. frag.remove();
  4442. });
  4443. setTimeout(op, staggerAmount);
  4444. } else {
  4445. frag.remove();
  4446. }
  4447. },
  4448. /**
  4449. * Move a fragment to a new position.
  4450. * Force no transition.
  4451. *
  4452. * @param {Fragment} frag
  4453. * @param {Node} prevEl
  4454. */
  4455. move: function move(frag, prevEl) {
  4456. // fix a common issue with Sortable:
  4457. // if prevEl doesn't have nextSibling, this means it's
  4458. // been dragged after the end anchor. Just re-position
  4459. // the end anchor to the end of the container.
  4460. /* istanbul ignore if */
  4461. if (!prevEl.nextSibling) {
  4462. this.end.parentNode.appendChild(this.end);
  4463. }
  4464. frag.before(prevEl.nextSibling, false);
  4465. },
  4466. /**
  4467. * Cache a fragment using track-by or the object key.
  4468. *
  4469. * @param {*} value
  4470. * @param {Fragment} frag
  4471. * @param {Number} index
  4472. * @param {String} [key]
  4473. */
  4474. cacheFrag: function cacheFrag(value, frag, index, key) {
  4475. var trackByKey = this.params.trackBy;
  4476. var cache = this.cache;
  4477. var primitive = !isObject(value);
  4478. var id;
  4479. if (key || trackByKey || primitive) {
  4480. id = trackByKey ? trackByKey === '$index' ? index : value[trackByKey] : key || value;
  4481. if (!cache[id]) {
  4482. cache[id] = frag;
  4483. } else if (trackByKey !== '$index') {
  4484. 'development' !== 'production' && this.warnDuplicate(value);
  4485. }
  4486. } else {
  4487. id = this.id;
  4488. if (hasOwn(value, id)) {
  4489. if (value[id] === null) {
  4490. value[id] = frag;
  4491. } else {
  4492. 'development' !== 'production' && this.warnDuplicate(value);
  4493. }
  4494. } else {
  4495. def(value, id, frag);
  4496. }
  4497. }
  4498. frag.raw = value;
  4499. },
  4500. /**
  4501. * Get a cached fragment from the value/index/key
  4502. *
  4503. * @param {*} value
  4504. * @param {Number} index
  4505. * @param {String} key
  4506. * @return {Fragment}
  4507. */
  4508. getCachedFrag: function getCachedFrag(value, index, key) {
  4509. var trackByKey = this.params.trackBy;
  4510. var primitive = !isObject(value);
  4511. var frag;
  4512. if (key || trackByKey || primitive) {
  4513. var id = trackByKey ? trackByKey === '$index' ? index : value[trackByKey] : key || value;
  4514. frag = this.cache[id];
  4515. } else {
  4516. frag = value[this.id];
  4517. }
  4518. if (frag && (frag.reused || frag.fresh)) {
  4519. 'development' !== 'production' && this.warnDuplicate(value);
  4520. }
  4521. return frag;
  4522. },
  4523. /**
  4524. * Delete a fragment from cache.
  4525. *
  4526. * @param {Fragment} frag
  4527. */
  4528. deleteCachedFrag: function deleteCachedFrag(frag) {
  4529. var value = frag.raw;
  4530. var trackByKey = this.params.trackBy;
  4531. var scope = frag.scope;
  4532. var index = scope.$index;
  4533. // fix #948: avoid accidentally fall through to
  4534. // a parent repeater which happens to have $key.
  4535. var key = hasOwn(scope, '$key') && scope.$key;
  4536. var primitive = !isObject(value);
  4537. if (trackByKey || key || primitive) {
  4538. var id = trackByKey ? trackByKey === '$index' ? index : value[trackByKey] : key || value;
  4539. this.cache[id] = null;
  4540. } else {
  4541. value[this.id] = null;
  4542. frag.raw = null;
  4543. }
  4544. },
  4545. /**
  4546. * Get the stagger amount for an insertion/removal.
  4547. *
  4548. * @param {Fragment} frag
  4549. * @param {Number} index
  4550. * @param {Number} total
  4551. * @param {String} type
  4552. */
  4553. getStagger: function getStagger(frag, index, total, type) {
  4554. type = type + 'Stagger';
  4555. var trans = frag.node.__v_trans;
  4556. var hooks = trans && trans.hooks;
  4557. var hook = hooks && (hooks[type] || hooks.stagger);
  4558. return hook ? hook.call(frag, index, total) : index * parseInt(this.params[type] || this.params.stagger, 10);
  4559. },
  4560. /**
  4561. * Pre-process the value before piping it through the
  4562. * filters. This is passed to and called by the watcher.
  4563. */
  4564. _preProcess: function _preProcess(value) {
  4565. // regardless of type, store the un-filtered raw value.
  4566. this.rawValue = value;
  4567. return value;
  4568. },
  4569. /**
  4570. * Post-process the value after it has been piped through
  4571. * the filters. This is passed to and called by the watcher.
  4572. *
  4573. * It is necessary for this to be called during the
  4574. * wathcer's dependency collection phase because we want
  4575. * the v-for to update when the source Object is mutated.
  4576. */
  4577. _postProcess: function _postProcess(value) {
  4578. if (isArray(value)) {
  4579. return value;
  4580. } else if (isPlainObject(value)) {
  4581. // convert plain object to array.
  4582. var keys = Object.keys(value);
  4583. var i = keys.length;
  4584. var res = new Array(i);
  4585. var key;
  4586. while (i--) {
  4587. key = keys[i];
  4588. res[i] = {
  4589. $key: key,
  4590. $value: value[key]
  4591. };
  4592. }
  4593. return res;
  4594. } else {
  4595. if (typeof value === 'number') {
  4596. value = range(value);
  4597. }
  4598. return value || [];
  4599. }
  4600. },
  4601. unbind: function unbind() {
  4602. if (this.descriptor.ref) {
  4603. (this._scope || this.vm).$refs[this.descriptor.ref] = null;
  4604. }
  4605. if (this.frags) {
  4606. var i = this.frags.length;
  4607. var frag;
  4608. while (i--) {
  4609. frag = this.frags[i];
  4610. this.deleteCachedFrag(frag);
  4611. frag.destroy();
  4612. }
  4613. }
  4614. }
  4615. };
  4616. /**
  4617. * Helper to find the previous element that is a fragment
  4618. * anchor. This is necessary because a destroyed frag's
  4619. * element could still be lingering in the DOM before its
  4620. * leaving transition finishes, but its inserted flag
  4621. * should have been set to false so we can skip them.
  4622. *
  4623. * If this is a block repeat, we want to make sure we only
  4624. * return frag that is bound to this v-for. (see #929)
  4625. *
  4626. * @param {Fragment} frag
  4627. * @param {Comment|Text} anchor
  4628. * @param {String} id
  4629. * @return {Fragment}
  4630. */
  4631. function findPrevFrag(frag, anchor, id) {
  4632. var el = frag.node.previousSibling;
  4633. /* istanbul ignore if */
  4634. if (!el) return;
  4635. frag = el.__vfrag__;
  4636. while ((!frag || frag.forId !== id || !frag.inserted) && el !== anchor) {
  4637. el = el.previousSibling;
  4638. /* istanbul ignore if */
  4639. if (!el) return;
  4640. frag = el.__vfrag__;
  4641. }
  4642. return frag;
  4643. }
  4644. /**
  4645. * Find a vm from a fragment.
  4646. *
  4647. * @param {Fragment} frag
  4648. * @return {Vue|undefined}
  4649. */
  4650. function findVmFromFrag(frag) {
  4651. var node = frag.node;
  4652. // handle multi-node frag
  4653. if (frag.end) {
  4654. while (!node.__vue__ && node !== frag.end && node.nextSibling) {
  4655. node = node.nextSibling;
  4656. }
  4657. }
  4658. return node.__vue__;
  4659. }
  4660. /**
  4661. * Create a range array from given number.
  4662. *
  4663. * @param {Number} n
  4664. * @return {Array}
  4665. */
  4666. function range(n) {
  4667. var i = -1;
  4668. var ret = new Array(n);
  4669. while (++i < n) {
  4670. ret[i] = i;
  4671. }
  4672. return ret;
  4673. }
  4674. if ('development' !== 'production') {
  4675. vFor.warnDuplicate = function (value) {
  4676. warn('Duplicate value found in v-for="' + this.descriptor.raw + '": ' + JSON.stringify(value) + '. Use track-by="$index" if ' + 'you are expecting duplicate values.');
  4677. };
  4678. }
  4679. var html = {
  4680. bind: function bind() {
  4681. // a comment node means this is a binding for
  4682. // {{{ inline unescaped html }}}
  4683. if (this.el.nodeType === 8) {
  4684. // hold nodes
  4685. this.nodes = [];
  4686. // replace the placeholder with proper anchor
  4687. this.anchor = createAnchor('v-html');
  4688. replace(this.el, this.anchor);
  4689. }
  4690. },
  4691. update: function update(value) {
  4692. value = _toString(value);
  4693. if (this.nodes) {
  4694. this.swap(value);
  4695. } else {
  4696. this.el.innerHTML = value;
  4697. }
  4698. },
  4699. swap: function swap(value) {
  4700. // remove old nodes
  4701. var i = this.nodes.length;
  4702. while (i--) {
  4703. remove(this.nodes[i]);
  4704. }
  4705. // convert new value to a fragment
  4706. // do not attempt to retrieve from id selector
  4707. var frag = parseTemplate(value, true, true);
  4708. // save a reference to these nodes so we can remove later
  4709. this.nodes = toArray(frag.childNodes);
  4710. before(frag, this.anchor);
  4711. }
  4712. };
  4713. var text = {
  4714. bind: function bind() {
  4715. this.attr = this.el.nodeType === 3 ? 'data' : 'textContent';
  4716. },
  4717. update: function update(value) {
  4718. this.el[this.attr] = _toString(value);
  4719. }
  4720. };
  4721. // must export plain object
  4722. var publicDirectives = {
  4723. text: text,
  4724. html: html,
  4725. 'for': vFor,
  4726. 'if': vIf,
  4727. show: show,
  4728. model: model,
  4729. on: on,
  4730. bind: bind,
  4731. el: el,
  4732. ref: ref,
  4733. cloak: cloak
  4734. };
  4735. var queue$1 = [];
  4736. var queued = false;
  4737. /**
  4738. * Push a job into the queue.
  4739. *
  4740. * @param {Function} job
  4741. */
  4742. function pushJob(job) {
  4743. queue$1.push(job);
  4744. if (!queued) {
  4745. queued = true;
  4746. nextTick(flush);
  4747. }
  4748. }
  4749. /**
  4750. * Flush the queue, and do one forced reflow before
  4751. * triggering transitions.
  4752. */
  4753. function flush() {
  4754. // Force layout
  4755. var f = document.documentElement.offsetHeight;
  4756. for (var i = 0; i < queue$1.length; i++) {
  4757. queue$1[i]();
  4758. }
  4759. queue$1 = [];
  4760. queued = false;
  4761. // dummy return, so js linters don't complain about
  4762. // unused variable f
  4763. return f;
  4764. }
  4765. var TYPE_TRANSITION = 'transition';
  4766. var TYPE_ANIMATION = 'animation';
  4767. var transDurationProp = transitionProp + 'Duration';
  4768. var animDurationProp = animationProp + 'Duration';
  4769. /**
  4770. * A Transition object that encapsulates the state and logic
  4771. * of the transition.
  4772. *
  4773. * @param {Element} el
  4774. * @param {String} id
  4775. * @param {Object} hooks
  4776. * @param {Vue} vm
  4777. */
  4778. function Transition(el, id, hooks, vm) {
  4779. this.id = id;
  4780. this.el = el;
  4781. this.enterClass = hooks && hooks.enterClass || id + '-enter';
  4782. this.leaveClass = hooks && hooks.leaveClass || id + '-leave';
  4783. this.hooks = hooks;
  4784. this.vm = vm;
  4785. // async state
  4786. this.pendingCssEvent = this.pendingCssCb = this.cancel = this.pendingJsCb = this.op = this.cb = null;
  4787. this.justEntered = false;
  4788. this.entered = this.left = false;
  4789. this.typeCache = {};
  4790. // check css transition type
  4791. this.type = hooks && hooks.type;
  4792. /* istanbul ignore if */
  4793. if ('development' !== 'production') {
  4794. if (this.type && this.type !== TYPE_TRANSITION && this.type !== TYPE_ANIMATION) {
  4795. warn('invalid CSS transition type for transition="' + this.id + '": ' + this.type);
  4796. }
  4797. }
  4798. // bind
  4799. var self = this;['enterNextTick', 'enterDone', 'leaveNextTick', 'leaveDone'].forEach(function (m) {
  4800. self[m] = bind$1(self[m], self);
  4801. });
  4802. }
  4803. var p$1 = Transition.prototype;
  4804. /**
  4805. * Start an entering transition.
  4806. *
  4807. * 1. enter transition triggered
  4808. * 2. call beforeEnter hook
  4809. * 3. add enter class
  4810. * 4. insert/show element
  4811. * 5. call enter hook (with possible explicit js callback)
  4812. * 6. reflow
  4813. * 7. based on transition type:
  4814. * - transition:
  4815. * remove class now, wait for transitionend,
  4816. * then done if there's no explicit js callback.
  4817. * - animation:
  4818. * wait for animationend, remove class,
  4819. * then done if there's no explicit js callback.
  4820. * - no css transition:
  4821. * done now if there's no explicit js callback.
  4822. * 8. wait for either done or js callback, then call
  4823. * afterEnter hook.
  4824. *
  4825. * @param {Function} op - insert/show the element
  4826. * @param {Function} [cb]
  4827. */
  4828. p$1.enter = function (op, cb) {
  4829. this.cancelPending();
  4830. this.callHook('beforeEnter');
  4831. this.cb = cb;
  4832. addClass(this.el, this.enterClass);
  4833. op();
  4834. this.entered = false;
  4835. this.callHookWithCb('enter');
  4836. if (this.entered) {
  4837. return; // user called done synchronously.
  4838. }
  4839. this.cancel = this.hooks && this.hooks.enterCancelled;
  4840. pushJob(this.enterNextTick);
  4841. };
  4842. /**
  4843. * The "nextTick" phase of an entering transition, which is
  4844. * to be pushed into a queue and executed after a reflow so
  4845. * that removing the class can trigger a CSS transition.
  4846. */
  4847. p$1.enterNextTick = function () {
  4848. // Important hack:
  4849. // in Chrome, if a just-entered element is applied the
  4850. // leave class while its interpolated property still has
  4851. // a very small value (within one frame), Chrome will
  4852. // skip the leave transition entirely and not firing the
  4853. // transtionend event. Therefore we need to protected
  4854. // against such cases using a one-frame timeout.
  4855. this.justEntered = true;
  4856. var self = this;
  4857. setTimeout(function () {
  4858. self.justEntered = false;
  4859. }, 17);
  4860. var enterDone = this.enterDone;
  4861. var type = this.getCssTransitionType(this.enterClass);
  4862. if (!this.pendingJsCb) {
  4863. if (type === TYPE_TRANSITION) {
  4864. // trigger transition by removing enter class now
  4865. removeClass(this.el, this.enterClass);
  4866. this.setupCssCb(transitionEndEvent, enterDone);
  4867. } else if (type === TYPE_ANIMATION) {
  4868. this.setupCssCb(animationEndEvent, enterDone);
  4869. } else {
  4870. enterDone();
  4871. }
  4872. } else if (type === TYPE_TRANSITION) {
  4873. removeClass(this.el, this.enterClass);
  4874. }
  4875. };
  4876. /**
  4877. * The "cleanup" phase of an entering transition.
  4878. */
  4879. p$1.enterDone = function () {
  4880. this.entered = true;
  4881. this.cancel = this.pendingJsCb = null;
  4882. removeClass(this.el, this.enterClass);
  4883. this.callHook('afterEnter');
  4884. if (this.cb) this.cb();
  4885. };
  4886. /**
  4887. * Start a leaving transition.
  4888. *
  4889. * 1. leave transition triggered.
  4890. * 2. call beforeLeave hook
  4891. * 3. add leave class (trigger css transition)
  4892. * 4. call leave hook (with possible explicit js callback)
  4893. * 5. reflow if no explicit js callback is provided
  4894. * 6. based on transition type:
  4895. * - transition or animation:
  4896. * wait for end event, remove class, then done if
  4897. * there's no explicit js callback.
  4898. * - no css transition:
  4899. * done if there's no explicit js callback.
  4900. * 7. wait for either done or js callback, then call
  4901. * afterLeave hook.
  4902. *
  4903. * @param {Function} op - remove/hide the element
  4904. * @param {Function} [cb]
  4905. */
  4906. p$1.leave = function (op, cb) {
  4907. this.cancelPending();
  4908. this.callHook('beforeLeave');
  4909. this.op = op;
  4910. this.cb = cb;
  4911. addClass(this.el, this.leaveClass);
  4912. this.left = false;
  4913. this.callHookWithCb('leave');
  4914. if (this.left) {
  4915. return; // user called done synchronously.
  4916. }
  4917. this.cancel = this.hooks && this.hooks.leaveCancelled;
  4918. // only need to handle leaveDone if
  4919. // 1. the transition is already done (synchronously called
  4920. // by the user, which causes this.op set to null)
  4921. // 2. there's no explicit js callback
  4922. if (this.op && !this.pendingJsCb) {
  4923. // if a CSS transition leaves immediately after enter,
  4924. // the transitionend event never fires. therefore we
  4925. // detect such cases and end the leave immediately.
  4926. if (this.justEntered) {
  4927. this.leaveDone();
  4928. } else {
  4929. pushJob(this.leaveNextTick);
  4930. }
  4931. }
  4932. };
  4933. /**
  4934. * The "nextTick" phase of a leaving transition.
  4935. */
  4936. p$1.leaveNextTick = function () {
  4937. var type = this.getCssTransitionType(this.leaveClass);
  4938. if (type) {
  4939. var event = type === TYPE_TRANSITION ? transitionEndEvent : animationEndEvent;
  4940. this.setupCssCb(event, this.leaveDone);
  4941. } else {
  4942. this.leaveDone();
  4943. }
  4944. };
  4945. /**
  4946. * The "cleanup" phase of a leaving transition.
  4947. */
  4948. p$1.leaveDone = function () {
  4949. this.left = true;
  4950. this.cancel = this.pendingJsCb = null;
  4951. this.op();
  4952. removeClass(this.el, this.leaveClass);
  4953. this.callHook('afterLeave');
  4954. if (this.cb) this.cb();
  4955. this.op = null;
  4956. };
  4957. /**
  4958. * Cancel any pending callbacks from a previously running
  4959. * but not finished transition.
  4960. */
  4961. p$1.cancelPending = function () {
  4962. this.op = this.cb = null;
  4963. var hasPending = false;
  4964. if (this.pendingCssCb) {
  4965. hasPending = true;
  4966. off(this.el, this.pendingCssEvent, this.pendingCssCb);
  4967. this.pendingCssEvent = this.pendingCssCb = null;
  4968. }
  4969. if (this.pendingJsCb) {
  4970. hasPending = true;
  4971. this.pendingJsCb.cancel();
  4972. this.pendingJsCb = null;
  4973. }
  4974. if (hasPending) {
  4975. removeClass(this.el, this.enterClass);
  4976. removeClass(this.el, this.leaveClass);
  4977. }
  4978. if (this.cancel) {
  4979. this.cancel.call(this.vm, this.el);
  4980. this.cancel = null;
  4981. }
  4982. };
  4983. /**
  4984. * Call a user-provided synchronous hook function.
  4985. *
  4986. * @param {String} type
  4987. */
  4988. p$1.callHook = function (type) {
  4989. if (this.hooks && this.hooks[type]) {
  4990. this.hooks[type].call(this.vm, this.el);
  4991. }
  4992. };
  4993. /**
  4994. * Call a user-provided, potentially-async hook function.
  4995. * We check for the length of arguments to see if the hook
  4996. * expects a `done` callback. If true, the transition's end
  4997. * will be determined by when the user calls that callback;
  4998. * otherwise, the end is determined by the CSS transition or
  4999. * animation.
  5000. *
  5001. * @param {String} type
  5002. */
  5003. p$1.callHookWithCb = function (type) {
  5004. var hook = this.hooks && this.hooks[type];
  5005. if (hook) {
  5006. if (hook.length > 1) {
  5007. this.pendingJsCb = cancellable(this[type + 'Done']);
  5008. }
  5009. hook.call(this.vm, this.el, this.pendingJsCb);
  5010. }
  5011. };
  5012. /**
  5013. * Get an element's transition type based on the
  5014. * calculated styles.
  5015. *
  5016. * @param {String} className
  5017. * @return {Number}
  5018. */
  5019. p$1.getCssTransitionType = function (className) {
  5020. /* istanbul ignore if */
  5021. if (!transitionEndEvent ||
  5022. // skip CSS transitions if page is not visible -
  5023. // this solves the issue of transitionend events not
  5024. // firing until the page is visible again.
  5025. // pageVisibility API is supported in IE10+, same as
  5026. // CSS transitions.
  5027. document.hidden ||
  5028. // explicit js-only transition
  5029. this.hooks && this.hooks.css === false ||
  5030. // element is hidden
  5031. isHidden(this.el)) {
  5032. return;
  5033. }
  5034. var type = this.type || this.typeCache[className];
  5035. if (type) return type;
  5036. var inlineStyles = this.el.style;
  5037. var computedStyles = window.getComputedStyle(this.el);
  5038. var transDuration = inlineStyles[transDurationProp] || computedStyles[transDurationProp];
  5039. if (transDuration && transDuration !== '0s') {
  5040. type = TYPE_TRANSITION;
  5041. } else {
  5042. var animDuration = inlineStyles[animDurationProp] || computedStyles[animDurationProp];
  5043. if (animDuration && animDuration !== '0s') {
  5044. type = TYPE_ANIMATION;
  5045. }
  5046. }
  5047. if (type) {
  5048. this.typeCache[className] = type;
  5049. }
  5050. return type;
  5051. };
  5052. /**
  5053. * Setup a CSS transitionend/animationend callback.
  5054. *
  5055. * @param {String} event
  5056. * @param {Function} cb
  5057. */
  5058. p$1.setupCssCb = function (event, cb) {
  5059. this.pendingCssEvent = event;
  5060. var self = this;
  5061. var el = this.el;
  5062. var onEnd = this.pendingCssCb = function (e) {
  5063. if (e.target === el) {
  5064. off(el, event, onEnd);
  5065. self.pendingCssEvent = self.pendingCssCb = null;
  5066. if (!self.pendingJsCb && cb) {
  5067. cb();
  5068. }
  5069. }
  5070. };
  5071. on$1(el, event, onEnd);
  5072. };
  5073. /**
  5074. * Check if an element is hidden - in that case we can just
  5075. * skip the transition alltogether.
  5076. *
  5077. * @param {Element} el
  5078. * @return {Boolean}
  5079. */
  5080. function isHidden(el) {
  5081. return !(el.offsetWidth || el.offsetHeight || el.getClientRects().length);
  5082. }
  5083. var transition = {
  5084. priority: TRANSITION,
  5085. update: function update(id, oldId) {
  5086. var el = this.el;
  5087. // resolve on owner vm
  5088. var hooks = resolveAsset(this.vm.$options, 'transitions', id);
  5089. id = id || 'v';
  5090. // apply on closest vm
  5091. el.__v_trans = new Transition(el, id, hooks, this.el.__vue__ || this.vm);
  5092. if (oldId) {
  5093. removeClass(el, oldId + '-transition');
  5094. }
  5095. addClass(el, id + '-transition');
  5096. }
  5097. };
  5098. var bindingModes = config._propBindingModes;
  5099. var propDef = {
  5100. bind: function bind() {
  5101. var child = this.vm;
  5102. var parent = child._context;
  5103. // passed in from compiler directly
  5104. var prop = this.descriptor.prop;
  5105. var childKey = prop.path;
  5106. var parentKey = prop.parentPath;
  5107. var twoWay = prop.mode === bindingModes.TWO_WAY;
  5108. var parentWatcher = this.parentWatcher = new Watcher(parent, parentKey, function (val) {
  5109. val = coerceProp(prop, val);
  5110. if (assertProp(prop, val)) {
  5111. child[childKey] = val;
  5112. }
  5113. }, {
  5114. twoWay: twoWay,
  5115. filters: prop.filters,
  5116. // important: props need to be observed on the
  5117. // v-for scope if present
  5118. scope: this._scope
  5119. });
  5120. // set the child initial value.
  5121. initProp(child, prop, parentWatcher.value);
  5122. // setup two-way binding
  5123. if (twoWay) {
  5124. // important: defer the child watcher creation until
  5125. // the created hook (after data observation)
  5126. var self = this;
  5127. child.$once('pre-hook:created', function () {
  5128. self.childWatcher = new Watcher(child, childKey, function (val) {
  5129. parentWatcher.set(val);
  5130. }, {
  5131. // ensure sync upward before parent sync down.
  5132. // this is necessary in cases e.g. the child
  5133. // mutates a prop array, then replaces it. (#1683)
  5134. sync: true
  5135. });
  5136. });
  5137. }
  5138. },
  5139. unbind: function unbind() {
  5140. this.parentWatcher.teardown();
  5141. if (this.childWatcher) {
  5142. this.childWatcher.teardown();
  5143. }
  5144. }
  5145. };
  5146. var component = {
  5147. priority: COMPONENT,
  5148. params: ['keep-alive', 'transition-mode', 'inline-template'],
  5149. /**
  5150. * Setup. Two possible usages:
  5151. *
  5152. * - static:
  5153. * <comp> or <div v-component="comp">
  5154. *
  5155. * - dynamic:
  5156. * <component :is="view">
  5157. */
  5158. bind: function bind() {
  5159. if (!this.el.__vue__) {
  5160. // keep-alive cache
  5161. this.keepAlive = this.params.keepAlive;
  5162. if (this.keepAlive) {
  5163. this.cache = {};
  5164. }
  5165. // check inline-template
  5166. if (this.params.inlineTemplate) {
  5167. // extract inline template as a DocumentFragment
  5168. this.inlineTemplate = extractContent(this.el, true);
  5169. }
  5170. // component resolution related state
  5171. this.pendingComponentCb = this.Component = null;
  5172. // transition related state
  5173. this.pendingRemovals = 0;
  5174. this.pendingRemovalCb = null;
  5175. // create a ref anchor
  5176. this.anchor = createAnchor('v-component');
  5177. replace(this.el, this.anchor);
  5178. // remove is attribute.
  5179. // this is removed during compilation, but because compilation is
  5180. // cached, when the component is used elsewhere this attribute
  5181. // will remain at link time.
  5182. this.el.removeAttribute('is');
  5183. // remove ref, same as above
  5184. if (this.descriptor.ref) {
  5185. this.el.removeAttribute('v-ref:' + hyphenate(this.descriptor.ref));
  5186. }
  5187. // if static, build right now.
  5188. if (this.literal) {
  5189. this.setComponent(this.expression);
  5190. }
  5191. } else {
  5192. 'development' !== 'production' && warn('cannot mount component "' + this.expression + '" ' + 'on already mounted element: ' + this.el);
  5193. }
  5194. },
  5195. /**
  5196. * Public update, called by the watcher in the dynamic
  5197. * literal scenario, e.g. <component :is="view">
  5198. */
  5199. update: function update(value) {
  5200. if (!this.literal) {
  5201. this.setComponent(value);
  5202. }
  5203. },
  5204. /**
  5205. * Switch dynamic components. May resolve the component
  5206. * asynchronously, and perform transition based on
  5207. * specified transition mode. Accepts a few additional
  5208. * arguments specifically for vue-router.
  5209. *
  5210. * The callback is called when the full transition is
  5211. * finished.
  5212. *
  5213. * @param {String} value
  5214. * @param {Function} [cb]
  5215. */
  5216. setComponent: function setComponent(value, cb) {
  5217. this.invalidatePending();
  5218. if (!value) {
  5219. // just remove current
  5220. this.unbuild(true);
  5221. this.remove(this.childVM, cb);
  5222. this.childVM = null;
  5223. } else {
  5224. var self = this;
  5225. this.resolveComponent(value, function () {
  5226. self.mountComponent(cb);
  5227. });
  5228. }
  5229. },
  5230. /**
  5231. * Resolve the component constructor to use when creating
  5232. * the child vm.
  5233. */
  5234. resolveComponent: function resolveComponent(id, cb) {
  5235. var self = this;
  5236. this.pendingComponentCb = cancellable(function (Component) {
  5237. self.ComponentName = Component.options.name || id;
  5238. self.Component = Component;
  5239. cb();
  5240. });
  5241. this.vm._resolveComponent(id, this.pendingComponentCb);
  5242. },
  5243. /**
  5244. * Create a new instance using the current constructor and
  5245. * replace the existing instance. This method doesn't care
  5246. * whether the new component and the old one are actually
  5247. * the same.
  5248. *
  5249. * @param {Function} [cb]
  5250. */
  5251. mountComponent: function mountComponent(cb) {
  5252. // actual mount
  5253. this.unbuild(true);
  5254. var self = this;
  5255. var activateHook = this.Component.options.activate;
  5256. var cached = this.getCached();
  5257. var newComponent = this.build();
  5258. if (activateHook && !cached) {
  5259. this.waitingFor = newComponent;
  5260. activateHook.call(newComponent, function () {
  5261. if (self.waitingFor !== newComponent) {
  5262. return;
  5263. }
  5264. self.waitingFor = null;
  5265. self.transition(newComponent, cb);
  5266. });
  5267. } else {
  5268. // update ref for kept-alive component
  5269. if (cached) {
  5270. newComponent._updateRef();
  5271. }
  5272. this.transition(newComponent, cb);
  5273. }
  5274. },
  5275. /**
  5276. * When the component changes or unbinds before an async
  5277. * constructor is resolved, we need to invalidate its
  5278. * pending callback.
  5279. */
  5280. invalidatePending: function invalidatePending() {
  5281. if (this.pendingComponentCb) {
  5282. this.pendingComponentCb.cancel();
  5283. this.pendingComponentCb = null;
  5284. }
  5285. },
  5286. /**
  5287. * Instantiate/insert a new child vm.
  5288. * If keep alive and has cached instance, insert that
  5289. * instance; otherwise build a new one and cache it.
  5290. *
  5291. * @param {Object} [extraOptions]
  5292. * @return {Vue} - the created instance
  5293. */
  5294. build: function build(extraOptions) {
  5295. var cached = this.getCached();
  5296. if (cached) {
  5297. return cached;
  5298. }
  5299. if (this.Component) {
  5300. // default options
  5301. var options = {
  5302. name: this.ComponentName,
  5303. el: cloneNode(this.el),
  5304. template: this.inlineTemplate,
  5305. // make sure to add the child with correct parent
  5306. // if this is a transcluded component, its parent
  5307. // should be the transclusion host.
  5308. parent: this._host || this.vm,
  5309. // if no inline-template, then the compiled
  5310. // linker can be cached for better performance.
  5311. _linkerCachable: !this.inlineTemplate,
  5312. _ref: this.descriptor.ref,
  5313. _asComponent: true,
  5314. _isRouterView: this._isRouterView,
  5315. // if this is a transcluded component, context
  5316. // will be the common parent vm of this instance
  5317. // and its host.
  5318. _context: this.vm,
  5319. // if this is inside an inline v-for, the scope
  5320. // will be the intermediate scope created for this
  5321. // repeat fragment. this is used for linking props
  5322. // and container directives.
  5323. _scope: this._scope,
  5324. // pass in the owner fragment of this component.
  5325. // this is necessary so that the fragment can keep
  5326. // track of its contained components in order to
  5327. // call attach/detach hooks for them.
  5328. _frag: this._frag
  5329. };
  5330. // extra options
  5331. // in 1.0.0 this is used by vue-router only
  5332. /* istanbul ignore if */
  5333. if (extraOptions) {
  5334. extend(options, extraOptions);
  5335. }
  5336. var child = new this.Component(options);
  5337. if (this.keepAlive) {
  5338. this.cache[this.Component.cid] = child;
  5339. }
  5340. /* istanbul ignore if */
  5341. if ('development' !== 'production' && this.el.hasAttribute('transition') && child._isFragment) {
  5342. warn('Transitions will not work on a fragment instance. ' + 'Template: ' + child.$options.template);
  5343. }
  5344. return child;
  5345. }
  5346. },
  5347. /**
  5348. * Try to get a cached instance of the current component.
  5349. *
  5350. * @return {Vue|undefined}
  5351. */
  5352. getCached: function getCached() {
  5353. return this.keepAlive && this.cache[this.Component.cid];
  5354. },
  5355. /**
  5356. * Teardown the current child, but defers cleanup so
  5357. * that we can separate the destroy and removal steps.
  5358. *
  5359. * @param {Boolean} defer
  5360. */
  5361. unbuild: function unbuild(defer) {
  5362. if (this.waitingFor) {
  5363. this.waitingFor.$destroy();
  5364. this.waitingFor = null;
  5365. }
  5366. var child = this.childVM;
  5367. if (!child || this.keepAlive) {
  5368. if (child) {
  5369. // remove ref
  5370. child._updateRef(true);
  5371. }
  5372. return;
  5373. }
  5374. // the sole purpose of `deferCleanup` is so that we can
  5375. // "deactivate" the vm right now and perform DOM removal
  5376. // later.
  5377. child.$destroy(false, defer);
  5378. },
  5379. /**
  5380. * Remove current destroyed child and manually do
  5381. * the cleanup after removal.
  5382. *
  5383. * @param {Function} cb
  5384. */
  5385. remove: function remove(child, cb) {
  5386. var keepAlive = this.keepAlive;
  5387. if (child) {
  5388. // we may have a component switch when a previous
  5389. // component is still being transitioned out.
  5390. // we want to trigger only one lastest insertion cb
  5391. // when the existing transition finishes. (#1119)
  5392. this.pendingRemovals++;
  5393. this.pendingRemovalCb = cb;
  5394. var self = this;
  5395. child.$remove(function () {
  5396. self.pendingRemovals--;
  5397. if (!keepAlive) child._cleanup();
  5398. if (!self.pendingRemovals && self.pendingRemovalCb) {
  5399. self.pendingRemovalCb();
  5400. self.pendingRemovalCb = null;
  5401. }
  5402. });
  5403. } else if (cb) {
  5404. cb();
  5405. }
  5406. },
  5407. /**
  5408. * Actually swap the components, depending on the
  5409. * transition mode. Defaults to simultaneous.
  5410. *
  5411. * @param {Vue} target
  5412. * @param {Function} [cb]
  5413. */
  5414. transition: function transition(target, cb) {
  5415. var self = this;
  5416. var current = this.childVM;
  5417. // for devtool inspection
  5418. if ('development' !== 'production') {
  5419. if (current) current._inactive = true;
  5420. target._inactive = false;
  5421. }
  5422. this.childVM = target;
  5423. switch (self.params.transitionMode) {
  5424. case 'in-out':
  5425. target.$before(self.anchor, function () {
  5426. self.remove(current, cb);
  5427. });
  5428. break;
  5429. case 'out-in':
  5430. self.remove(current, function () {
  5431. target.$before(self.anchor, cb);
  5432. });
  5433. break;
  5434. default:
  5435. self.remove(current);
  5436. target.$before(self.anchor, cb);
  5437. }
  5438. },
  5439. /**
  5440. * Unbind.
  5441. */
  5442. unbind: function unbind() {
  5443. this.invalidatePending();
  5444. // Do not defer cleanup when unbinding
  5445. this.unbuild();
  5446. // destroy all keep-alive cached instances
  5447. if (this.cache) {
  5448. for (var key in this.cache) {
  5449. this.cache[key].$destroy();
  5450. }
  5451. this.cache = null;
  5452. }
  5453. }
  5454. };
  5455. var vClass = {
  5456. deep: true,
  5457. update: function update(value) {
  5458. if (value && typeof value === 'string') {
  5459. this.handleObject(stringToObject(value));
  5460. } else if (isPlainObject(value)) {
  5461. this.handleObject(value);
  5462. } else if (isArray(value)) {
  5463. this.handleArray(value);
  5464. } else {
  5465. this.cleanup();
  5466. }
  5467. },
  5468. handleObject: function handleObject(value) {
  5469. this.cleanup(value);
  5470. var keys = this.prevKeys = Object.keys(value);
  5471. for (var i = 0, l = keys.length; i < l; i++) {
  5472. var key = keys[i];
  5473. if (value[key]) {
  5474. addClass(this.el, key);
  5475. } else {
  5476. removeClass(this.el, key);
  5477. }
  5478. }
  5479. },
  5480. handleArray: function handleArray(value) {
  5481. this.cleanup(value);
  5482. for (var i = 0, l = value.length; i < l; i++) {
  5483. if (value[i]) {
  5484. addClass(this.el, value[i]);
  5485. }
  5486. }
  5487. this.prevKeys = value.slice();
  5488. },
  5489. cleanup: function cleanup(value) {
  5490. if (this.prevKeys) {
  5491. var i = this.prevKeys.length;
  5492. while (i--) {
  5493. var key = this.prevKeys[i];
  5494. if (key && (!value || !contains$1(value, key))) {
  5495. removeClass(this.el, key);
  5496. }
  5497. }
  5498. }
  5499. }
  5500. };
  5501. function stringToObject(value) {
  5502. var res = {};
  5503. var keys = value.trim().split(/\s+/);
  5504. var i = keys.length;
  5505. while (i--) {
  5506. res[keys[i]] = true;
  5507. }
  5508. return res;
  5509. }
  5510. function contains$1(value, key) {
  5511. return isArray(value) ? value.indexOf(key) > -1 : hasOwn(value, key);
  5512. }
  5513. var internalDirectives = {
  5514. style: style,
  5515. 'class': vClass,
  5516. component: component,
  5517. prop: propDef,
  5518. transition: transition
  5519. };
  5520. var propBindingModes = config._propBindingModes;
  5521. var empty = {};
  5522. // regexes
  5523. var identRE$1 = /^[$_a-zA-Z]+[\w$]*$/;
  5524. var settablePathRE = /^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*|\[[^\[\]]+\])*$/;
  5525. /**
  5526. * Compile props on a root element and return
  5527. * a props link function.
  5528. *
  5529. * @param {Element|DocumentFragment} el
  5530. * @param {Array} propOptions
  5531. * @return {Function} propsLinkFn
  5532. */
  5533. function compileProps(el, propOptions) {
  5534. var props = [];
  5535. var names = Object.keys(propOptions);
  5536. var i = names.length;
  5537. var options, name, attr, value, path, parsed, prop;
  5538. while (i--) {
  5539. name = names[i];
  5540. options = propOptions[name] || empty;
  5541. if ('development' !== 'production' && name === '$data') {
  5542. warn('Do not use $data as prop.');
  5543. continue;
  5544. }
  5545. // props could contain dashes, which will be
  5546. // interpreted as minus calculations by the parser
  5547. // so we need to camelize the path here
  5548. path = camelize(name);
  5549. if (!identRE$1.test(path)) {
  5550. 'development' !== 'production' && warn('Invalid prop key: "' + name + '". Prop keys ' + 'must be valid identifiers.');
  5551. continue;
  5552. }
  5553. prop = {
  5554. name: name,
  5555. path: path,
  5556. options: options,
  5557. mode: propBindingModes.ONE_WAY,
  5558. raw: null
  5559. };
  5560. attr = hyphenate(name);
  5561. // first check dynamic version
  5562. if ((value = getBindAttr(el, attr)) === null) {
  5563. if ((value = getBindAttr(el, attr + '.sync')) !== null) {
  5564. prop.mode = propBindingModes.TWO_WAY;
  5565. } else if ((value = getBindAttr(el, attr + '.once')) !== null) {
  5566. prop.mode = propBindingModes.ONE_TIME;
  5567. }
  5568. }
  5569. if (value !== null) {
  5570. // has dynamic binding!
  5571. prop.raw = value;
  5572. parsed = parseDirective(value);
  5573. value = parsed.expression;
  5574. prop.filters = parsed.filters;
  5575. // check binding type
  5576. if (isLiteral(value) && !parsed.filters) {
  5577. // for expressions containing literal numbers and
  5578. // booleans, there's no need to setup a prop binding,
  5579. // so we can optimize them as a one-time set.
  5580. prop.optimizedLiteral = true;
  5581. } else {
  5582. prop.dynamic = true;
  5583. // check non-settable path for two-way bindings
  5584. if ('development' !== 'production' && prop.mode === propBindingModes.TWO_WAY && !settablePathRE.test(value)) {
  5585. prop.mode = propBindingModes.ONE_WAY;
  5586. warn('Cannot bind two-way prop with non-settable ' + 'parent path: ' + value);
  5587. }
  5588. }
  5589. prop.parentPath = value;
  5590. // warn required two-way
  5591. if ('development' !== 'production' && options.twoWay && prop.mode !== propBindingModes.TWO_WAY) {
  5592. warn('Prop "' + name + '" expects a two-way binding type.');
  5593. }
  5594. } else if ((value = getAttr(el, attr)) !== null) {
  5595. // has literal binding!
  5596. prop.raw = value;
  5597. } else if (options.required) {
  5598. // warn missing required
  5599. 'development' !== 'production' && warn('Missing required prop: ' + name);
  5600. }
  5601. // push prop
  5602. props.push(prop);
  5603. }
  5604. return makePropsLinkFn(props);
  5605. }
  5606. /**
  5607. * Build a function that applies props to a vm.
  5608. *
  5609. * @param {Array} props
  5610. * @return {Function} propsLinkFn
  5611. */
  5612. function makePropsLinkFn(props) {
  5613. return function propsLinkFn(vm, scope) {
  5614. // store resolved props info
  5615. vm._props = {};
  5616. var i = props.length;
  5617. var prop, path, options, value, raw;
  5618. while (i--) {
  5619. prop = props[i];
  5620. raw = prop.raw;
  5621. path = prop.path;
  5622. options = prop.options;
  5623. vm._props[path] = prop;
  5624. if (raw === null) {
  5625. // initialize absent prop
  5626. initProp(vm, prop, getDefault(vm, options));
  5627. } else if (prop.dynamic) {
  5628. // dynamic prop
  5629. if (vm._context) {
  5630. if (prop.mode === propBindingModes.ONE_TIME) {
  5631. // one time binding
  5632. value = (scope || vm._context).$get(prop.parentPath);
  5633. initProp(vm, prop, value);
  5634. } else {
  5635. // dynamic binding
  5636. vm._bindDir({
  5637. name: 'prop',
  5638. def: propDef,
  5639. prop: prop
  5640. }, null, null, scope); // el, host, scope
  5641. }
  5642. } else {
  5643. 'development' !== 'production' && warn('Cannot bind dynamic prop on a root instance' + ' with no parent: ' + prop.name + '="' + raw + '"');
  5644. }
  5645. } else if (prop.optimizedLiteral) {
  5646. // optimized literal, cast it and just set once
  5647. var stripped = stripQuotes(raw);
  5648. value = stripped === raw ? toBoolean(toNumber(raw)) : stripped;
  5649. initProp(vm, prop, value);
  5650. } else {
  5651. // string literal, but we need to cater for
  5652. // Boolean props with no value
  5653. value = options.type === Boolean && raw === '' ? true : raw;
  5654. initProp(vm, prop, value);
  5655. }
  5656. }
  5657. };
  5658. }
  5659. /**
  5660. * Get the default value of a prop.
  5661. *
  5662. * @param {Vue} vm
  5663. * @param {Object} options
  5664. * @return {*}
  5665. */
  5666. function getDefault(vm, options) {
  5667. // no default, return undefined
  5668. if (!hasOwn(options, 'default')) {
  5669. // absent boolean value defaults to false
  5670. return options.type === Boolean ? false : undefined;
  5671. }
  5672. var def = options['default'];
  5673. // warn against non-factory defaults for Object & Array
  5674. if (isObject(def)) {
  5675. 'development' !== 'production' && warn('Object/Array as default prop values will be shared ' + 'across multiple instances. Use a factory function ' + 'to return the default value instead.');
  5676. }
  5677. // call factory function for non-Function types
  5678. return typeof def === 'function' && options.type !== Function ? def.call(vm) : def;
  5679. }
  5680. // special binding prefixes
  5681. var bindRE = /^v-bind:|^:/;
  5682. var onRE = /^v-on:|^@/;
  5683. var argRE = /:(.*)$/;
  5684. var modifierRE = /\.[^\.]+/g;
  5685. var transitionRE = /^(v-bind:|:)?transition$/;
  5686. // terminal directives
  5687. var terminalDirectives = ['for', 'if'];
  5688. // default directive priority
  5689. var DEFAULT_PRIORITY = 1000;
  5690. /**
  5691. * Compile a template and return a reusable composite link
  5692. * function, which recursively contains more link functions
  5693. * inside. This top level compile function would normally
  5694. * be called on instance root nodes, but can also be used
  5695. * for partial compilation if the partial argument is true.
  5696. *
  5697. * The returned composite link function, when called, will
  5698. * return an unlink function that tearsdown all directives
  5699. * created during the linking phase.
  5700. *
  5701. * @param {Element|DocumentFragment} el
  5702. * @param {Object} options
  5703. * @param {Boolean} partial
  5704. * @return {Function}
  5705. */
  5706. function compile(el, options, partial) {
  5707. // link function for the node itself.
  5708. var nodeLinkFn = partial || !options._asComponent ? compileNode(el, options) : null;
  5709. // link function for the childNodes
  5710. var childLinkFn = !(nodeLinkFn && nodeLinkFn.terminal) && el.tagName !== 'SCRIPT' && el.hasChildNodes() ? compileNodeList(el.childNodes, options) : null;
  5711. /**
  5712. * A composite linker function to be called on a already
  5713. * compiled piece of DOM, which instantiates all directive
  5714. * instances.
  5715. *
  5716. * @param {Vue} vm
  5717. * @param {Element|DocumentFragment} el
  5718. * @param {Vue} [host] - host vm of transcluded content
  5719. * @param {Object} [scope] - v-for scope
  5720. * @param {Fragment} [frag] - link context fragment
  5721. * @return {Function|undefined}
  5722. */
  5723. return function compositeLinkFn(vm, el, host, scope, frag) {
  5724. // cache childNodes before linking parent, fix #657
  5725. var childNodes = toArray(el.childNodes);
  5726. // link
  5727. var dirs = linkAndCapture(function compositeLinkCapturer() {
  5728. if (nodeLinkFn) nodeLinkFn(vm, el, host, scope, frag);
  5729. if (childLinkFn) childLinkFn(vm, childNodes, host, scope, frag);
  5730. }, vm);
  5731. return makeUnlinkFn(vm, dirs);
  5732. };
  5733. }
  5734. /**
  5735. * Apply a linker to a vm/element pair and capture the
  5736. * directives created during the process.
  5737. *
  5738. * @param {Function} linker
  5739. * @param {Vue} vm
  5740. */
  5741. function linkAndCapture(linker, vm) {
  5742. var originalDirCount = vm._directives.length;
  5743. linker();
  5744. var dirs = vm._directives.slice(originalDirCount);
  5745. dirs.sort(directiveComparator);
  5746. for (var i = 0, l = dirs.length; i < l; i++) {
  5747. dirs[i]._bind();
  5748. }
  5749. return dirs;
  5750. }
  5751. /**
  5752. * Directive priority sort comparator
  5753. *
  5754. * @param {Object} a
  5755. * @param {Object} b
  5756. */
  5757. function directiveComparator(a, b) {
  5758. a = a.descriptor.def.priority || DEFAULT_PRIORITY;
  5759. b = b.descriptor.def.priority || DEFAULT_PRIORITY;
  5760. return a > b ? -1 : a === b ? 0 : 1;
  5761. }
  5762. /**
  5763. * Linker functions return an unlink function that
  5764. * tearsdown all directives instances generated during
  5765. * the process.
  5766. *
  5767. * We create unlink functions with only the necessary
  5768. * information to avoid retaining additional closures.
  5769. *
  5770. * @param {Vue} vm
  5771. * @param {Array} dirs
  5772. * @param {Vue} [context]
  5773. * @param {Array} [contextDirs]
  5774. * @return {Function}
  5775. */
  5776. function makeUnlinkFn(vm, dirs, context, contextDirs) {
  5777. function unlink(destroying) {
  5778. teardownDirs(vm, dirs, destroying);
  5779. if (context && contextDirs) {
  5780. teardownDirs(context, contextDirs);
  5781. }
  5782. }
  5783. // expose linked directives
  5784. unlink.dirs = dirs;
  5785. return unlink;
  5786. }
  5787. /**
  5788. * Teardown partial linked directives.
  5789. *
  5790. * @param {Vue} vm
  5791. * @param {Array} dirs
  5792. * @param {Boolean} destroying
  5793. */
  5794. function teardownDirs(vm, dirs, destroying) {
  5795. var i = dirs.length;
  5796. while (i--) {
  5797. dirs[i]._teardown();
  5798. if (!destroying) {
  5799. vm._directives.$remove(dirs[i]);
  5800. }
  5801. }
  5802. }
  5803. /**
  5804. * Compile link props on an instance.
  5805. *
  5806. * @param {Vue} vm
  5807. * @param {Element} el
  5808. * @param {Object} props
  5809. * @param {Object} [scope]
  5810. * @return {Function}
  5811. */
  5812. function compileAndLinkProps(vm, el, props, scope) {
  5813. var propsLinkFn = compileProps(el, props);
  5814. var propDirs = linkAndCapture(function () {
  5815. propsLinkFn(vm, scope);
  5816. }, vm);
  5817. return makeUnlinkFn(vm, propDirs);
  5818. }
  5819. /**
  5820. * Compile the root element of an instance.
  5821. *
  5822. * 1. attrs on context container (context scope)
  5823. * 2. attrs on the component template root node, if
  5824. * replace:true (child scope)
  5825. *
  5826. * If this is a fragment instance, we only need to compile 1.
  5827. *
  5828. * @param {Vue} vm
  5829. * @param {Element} el
  5830. * @param {Object} options
  5831. * @param {Object} contextOptions
  5832. * @return {Function}
  5833. */
  5834. function compileRoot(el, options, contextOptions) {
  5835. var containerAttrs = options._containerAttrs;
  5836. var replacerAttrs = options._replacerAttrs;
  5837. var contextLinkFn, replacerLinkFn;
  5838. // only need to compile other attributes for
  5839. // non-fragment instances
  5840. if (el.nodeType !== 11) {
  5841. // for components, container and replacer need to be
  5842. // compiled separately and linked in different scopes.
  5843. if (options._asComponent) {
  5844. // 2. container attributes
  5845. if (containerAttrs && contextOptions) {
  5846. contextLinkFn = compileDirectives(containerAttrs, contextOptions);
  5847. }
  5848. if (replacerAttrs) {
  5849. // 3. replacer attributes
  5850. replacerLinkFn = compileDirectives(replacerAttrs, options);
  5851. }
  5852. } else {
  5853. // non-component, just compile as a normal element.
  5854. replacerLinkFn = compileDirectives(el.attributes, options);
  5855. }
  5856. } else if ('development' !== 'production' && containerAttrs) {
  5857. // warn container directives for fragment instances
  5858. var names = containerAttrs.filter(function (attr) {
  5859. // allow vue-loader/vueify scoped css attributes
  5860. return attr.name.indexOf('_v-') < 0 &&
  5861. // allow event listeners
  5862. !onRE.test(attr.name) &&
  5863. // allow slots
  5864. attr.name !== 'slot';
  5865. }).map(function (attr) {
  5866. return '"' + attr.name + '"';
  5867. });
  5868. if (names.length) {
  5869. var plural = names.length > 1;
  5870. warn('Attribute' + (plural ? 's ' : ' ') + names.join(', ') + (plural ? ' are' : ' is') + ' ignored on component ' + '<' + options.el.tagName.toLowerCase() + '> because ' + 'the component is a fragment instance: ' + 'http://vuejs.org/guide/components.html#Fragment_Instance');
  5871. }
  5872. }
  5873. options._containerAttrs = options._replacerAttrs = null;
  5874. return function rootLinkFn(vm, el, scope) {
  5875. // link context scope dirs
  5876. var context = vm._context;
  5877. var contextDirs;
  5878. if (context && contextLinkFn) {
  5879. contextDirs = linkAndCapture(function () {
  5880. contextLinkFn(context, el, null, scope);
  5881. }, context);
  5882. }
  5883. // link self
  5884. var selfDirs = linkAndCapture(function () {
  5885. if (replacerLinkFn) replacerLinkFn(vm, el);
  5886. }, vm);
  5887. // return the unlink function that tearsdown context
  5888. // container directives.
  5889. return makeUnlinkFn(vm, selfDirs, context, contextDirs);
  5890. };
  5891. }
  5892. /**
  5893. * Compile a node and return a nodeLinkFn based on the
  5894. * node type.
  5895. *
  5896. * @param {Node} node
  5897. * @param {Object} options
  5898. * @return {Function|null}
  5899. */
  5900. function compileNode(node, options) {
  5901. var type = node.nodeType;
  5902. if (type === 1 && node.tagName !== 'SCRIPT') {
  5903. return compileElement(node, options);
  5904. } else if (type === 3 && node.data.trim()) {
  5905. return compileTextNode(node, options);
  5906. } else {
  5907. return null;
  5908. }
  5909. }
  5910. /**
  5911. * Compile an element and return a nodeLinkFn.
  5912. *
  5913. * @param {Element} el
  5914. * @param {Object} options
  5915. * @return {Function|null}
  5916. */
  5917. function compileElement(el, options) {
  5918. // preprocess textareas.
  5919. // textarea treats its text content as the initial value.
  5920. // just bind it as an attr directive for value.
  5921. if (el.tagName === 'TEXTAREA') {
  5922. var tokens = parseText(el.value);
  5923. if (tokens) {
  5924. el.setAttribute(':value', tokensToExp(tokens));
  5925. el.value = '';
  5926. }
  5927. }
  5928. var linkFn;
  5929. var hasAttrs = el.hasAttributes();
  5930. // check terminal directives (for & if)
  5931. if (hasAttrs) {
  5932. linkFn = checkTerminalDirectives(el, options);
  5933. }
  5934. // check element directives
  5935. if (!linkFn) {
  5936. linkFn = checkElementDirectives(el, options);
  5937. }
  5938. // check component
  5939. if (!linkFn) {
  5940. linkFn = checkComponent(el, options);
  5941. }
  5942. // normal directives
  5943. if (!linkFn && hasAttrs) {
  5944. linkFn = compileDirectives(el.attributes, options);
  5945. }
  5946. return linkFn;
  5947. }
  5948. /**
  5949. * Compile a textNode and return a nodeLinkFn.
  5950. *
  5951. * @param {TextNode} node
  5952. * @param {Object} options
  5953. * @return {Function|null} textNodeLinkFn
  5954. */
  5955. function compileTextNode(node, options) {
  5956. // skip marked text nodes
  5957. if (node._skip) {
  5958. return removeText;
  5959. }
  5960. var tokens = parseText(node.wholeText);
  5961. if (!tokens) {
  5962. return null;
  5963. }
  5964. // mark adjacent text nodes as skipped,
  5965. // because we are using node.wholeText to compile
  5966. // all adjacent text nodes together. This fixes
  5967. // issues in IE where sometimes it splits up a single
  5968. // text node into multiple ones.
  5969. var next = node.nextSibling;
  5970. while (next && next.nodeType === 3) {
  5971. next._skip = true;
  5972. next = next.nextSibling;
  5973. }
  5974. var frag = document.createDocumentFragment();
  5975. var el, token;
  5976. for (var i = 0, l = tokens.length; i < l; i++) {
  5977. token = tokens[i];
  5978. el = token.tag ? processTextToken(token, options) : document.createTextNode(token.value);
  5979. frag.appendChild(el);
  5980. }
  5981. return makeTextNodeLinkFn(tokens, frag, options);
  5982. }
  5983. /**
  5984. * Linker for an skipped text node.
  5985. *
  5986. * @param {Vue} vm
  5987. * @param {Text} node
  5988. */
  5989. function removeText(vm, node) {
  5990. remove(node);
  5991. }
  5992. /**
  5993. * Process a single text token.
  5994. *
  5995. * @param {Object} token
  5996. * @param {Object} options
  5997. * @return {Node}
  5998. */
  5999. function processTextToken(token, options) {
  6000. var el;
  6001. if (token.oneTime) {
  6002. el = document.createTextNode(token.value);
  6003. } else {
  6004. if (token.html) {
  6005. el = document.createComment('v-html');
  6006. setTokenType('html');
  6007. } else {
  6008. // IE will clean up empty textNodes during
  6009. // frag.cloneNode(true), so we have to give it
  6010. // something here...
  6011. el = document.createTextNode(' ');
  6012. setTokenType('text');
  6013. }
  6014. }
  6015. function setTokenType(type) {
  6016. if (token.descriptor) return;
  6017. var parsed = parseDirective(token.value);
  6018. token.descriptor = {
  6019. name: type,
  6020. def: publicDirectives[type],
  6021. expression: parsed.expression,
  6022. filters: parsed.filters
  6023. };
  6024. }
  6025. return el;
  6026. }
  6027. /**
  6028. * Build a function that processes a textNode.
  6029. *
  6030. * @param {Array<Object>} tokens
  6031. * @param {DocumentFragment} frag
  6032. */
  6033. function makeTextNodeLinkFn(tokens, frag) {
  6034. return function textNodeLinkFn(vm, el, host, scope) {
  6035. var fragClone = frag.cloneNode(true);
  6036. var childNodes = toArray(fragClone.childNodes);
  6037. var token, value, node;
  6038. for (var i = 0, l = tokens.length; i < l; i++) {
  6039. token = tokens[i];
  6040. value = token.value;
  6041. if (token.tag) {
  6042. node = childNodes[i];
  6043. if (token.oneTime) {
  6044. value = (scope || vm).$eval(value);
  6045. if (token.html) {
  6046. replace(node, parseTemplate(value, true));
  6047. } else {
  6048. node.data = value;
  6049. }
  6050. } else {
  6051. vm._bindDir(token.descriptor, node, host, scope);
  6052. }
  6053. }
  6054. }
  6055. replace(el, fragClone);
  6056. };
  6057. }
  6058. /**
  6059. * Compile a node list and return a childLinkFn.
  6060. *
  6061. * @param {NodeList} nodeList
  6062. * @param {Object} options
  6063. * @return {Function|undefined}
  6064. */
  6065. function compileNodeList(nodeList, options) {
  6066. var linkFns = [];
  6067. var nodeLinkFn, childLinkFn, node;
  6068. for (var i = 0, l = nodeList.length; i < l; i++) {
  6069. node = nodeList[i];
  6070. nodeLinkFn = compileNode(node, options);
  6071. childLinkFn = !(nodeLinkFn && nodeLinkFn.terminal) && node.tagName !== 'SCRIPT' && node.hasChildNodes() ? compileNodeList(node.childNodes, options) : null;
  6072. linkFns.push(nodeLinkFn, childLinkFn);
  6073. }
  6074. return linkFns.length ? makeChildLinkFn(linkFns) : null;
  6075. }
  6076. /**
  6077. * Make a child link function for a node's childNodes.
  6078. *
  6079. * @param {Array<Function>} linkFns
  6080. * @return {Function} childLinkFn
  6081. */
  6082. function makeChildLinkFn(linkFns) {
  6083. return function childLinkFn(vm, nodes, host, scope, frag) {
  6084. var node, nodeLinkFn, childrenLinkFn;
  6085. for (var i = 0, n = 0, l = linkFns.length; i < l; n++) {
  6086. node = nodes[n];
  6087. nodeLinkFn = linkFns[i++];
  6088. childrenLinkFn = linkFns[i++];
  6089. // cache childNodes before linking parent, fix #657
  6090. var childNodes = toArray(node.childNodes);
  6091. if (nodeLinkFn) {
  6092. nodeLinkFn(vm, node, host, scope, frag);
  6093. }
  6094. if (childrenLinkFn) {
  6095. childrenLinkFn(vm, childNodes, host, scope, frag);
  6096. }
  6097. }
  6098. };
  6099. }
  6100. /**
  6101. * Check for element directives (custom elements that should
  6102. * be resovled as terminal directives).
  6103. *
  6104. * @param {Element} el
  6105. * @param {Object} options
  6106. */
  6107. function checkElementDirectives(el, options) {
  6108. var tag = el.tagName.toLowerCase();
  6109. if (commonTagRE.test(tag)) return;
  6110. // special case: give named slot a higher priority
  6111. // than unnamed slots
  6112. if (tag === 'slot' && hasBindAttr(el, 'name')) {
  6113. tag = '_namedSlot';
  6114. }
  6115. var def = resolveAsset(options, 'elementDirectives', tag);
  6116. if (def) {
  6117. return makeTerminalNodeLinkFn(el, tag, '', options, def);
  6118. }
  6119. }
  6120. /**
  6121. * Check if an element is a component. If yes, return
  6122. * a component link function.
  6123. *
  6124. * @param {Element} el
  6125. * @param {Object} options
  6126. * @return {Function|undefined}
  6127. */
  6128. function checkComponent(el, options) {
  6129. var component = checkComponentAttr(el, options);
  6130. if (component) {
  6131. var ref = findRef(el);
  6132. var descriptor = {
  6133. name: 'component',
  6134. ref: ref,
  6135. expression: component.id,
  6136. def: internalDirectives.component,
  6137. modifiers: {
  6138. literal: !component.dynamic
  6139. }
  6140. };
  6141. var componentLinkFn = function componentLinkFn(vm, el, host, scope, frag) {
  6142. if (ref) {
  6143. defineReactive((scope || vm).$refs, ref, null);
  6144. }
  6145. vm._bindDir(descriptor, el, host, scope, frag);
  6146. };
  6147. componentLinkFn.terminal = true;
  6148. return componentLinkFn;
  6149. }
  6150. }
  6151. /**
  6152. * Check an element for terminal directives in fixed order.
  6153. * If it finds one, return a terminal link function.
  6154. *
  6155. * @param {Element} el
  6156. * @param {Object} options
  6157. * @return {Function} terminalLinkFn
  6158. */
  6159. function checkTerminalDirectives(el, options) {
  6160. // skip v-pre
  6161. if (getAttr(el, 'v-pre') !== null) {
  6162. return skip;
  6163. }
  6164. // skip v-else block, but only if following v-if
  6165. if (el.hasAttribute('v-else')) {
  6166. var prev = el.previousElementSibling;
  6167. if (prev && prev.hasAttribute('v-if')) {
  6168. return skip;
  6169. }
  6170. }
  6171. var value, dirName;
  6172. for (var i = 0, l = terminalDirectives.length; i < l; i++) {
  6173. dirName = terminalDirectives[i];
  6174. value = el.getAttribute('v-' + dirName);
  6175. if (value != null) {
  6176. return makeTerminalNodeLinkFn(el, dirName, value, options);
  6177. }
  6178. }
  6179. }
  6180. function skip() {}
  6181. skip.terminal = true;
  6182. /**
  6183. * Build a node link function for a terminal directive.
  6184. * A terminal link function terminates the current
  6185. * compilation recursion and handles compilation of the
  6186. * subtree in the directive.
  6187. *
  6188. * @param {Element} el
  6189. * @param {String} dirName
  6190. * @param {String} value
  6191. * @param {Object} options
  6192. * @param {Object} [def]
  6193. * @return {Function} terminalLinkFn
  6194. */
  6195. function makeTerminalNodeLinkFn(el, dirName, value, options, def) {
  6196. var parsed = parseDirective(value);
  6197. var descriptor = {
  6198. name: dirName,
  6199. expression: parsed.expression,
  6200. filters: parsed.filters,
  6201. raw: value,
  6202. // either an element directive, or if/for
  6203. def: def || publicDirectives[dirName]
  6204. };
  6205. // check ref for v-for and router-view
  6206. if (dirName === 'for' || dirName === 'router-view') {
  6207. descriptor.ref = findRef(el);
  6208. }
  6209. var fn = function terminalNodeLinkFn(vm, el, host, scope, frag) {
  6210. if (descriptor.ref) {
  6211. defineReactive((scope || vm).$refs, descriptor.ref, null);
  6212. }
  6213. vm._bindDir(descriptor, el, host, scope, frag);
  6214. };
  6215. fn.terminal = true;
  6216. return fn;
  6217. }
  6218. /**
  6219. * Compile the directives on an element and return a linker.
  6220. *
  6221. * @param {Array|NamedNodeMap} attrs
  6222. * @param {Object} options
  6223. * @return {Function}
  6224. */
  6225. function compileDirectives(attrs, options) {
  6226. var i = attrs.length;
  6227. var dirs = [];
  6228. var attr, name, value, rawName, rawValue, dirName, arg, modifiers, dirDef, tokens;
  6229. while (i--) {
  6230. attr = attrs[i];
  6231. name = rawName = attr.name;
  6232. value = rawValue = attr.value;
  6233. tokens = parseText(value);
  6234. // reset arg
  6235. arg = null;
  6236. // check modifiers
  6237. modifiers = parseModifiers(name);
  6238. name = name.replace(modifierRE, '');
  6239. // attribute interpolations
  6240. if (tokens) {
  6241. value = tokensToExp(tokens);
  6242. arg = name;
  6243. pushDir('bind', publicDirectives.bind, tokens);
  6244. // warn against mixing mustaches with v-bind
  6245. if ('development' !== 'production') {
  6246. if (name === 'class' && Array.prototype.some.call(attrs, function (attr) {
  6247. return attr.name === ':class' || attr.name === 'v-bind:class';
  6248. })) {
  6249. warn('class="' + rawValue + '": Do not mix mustache interpolation ' + 'and v-bind for "class" on the same element. Use one or the other.');
  6250. }
  6251. }
  6252. } else
  6253. // special attribute: transition
  6254. if (transitionRE.test(name)) {
  6255. modifiers.literal = !bindRE.test(name);
  6256. pushDir('transition', internalDirectives.transition);
  6257. } else
  6258. // event handlers
  6259. if (onRE.test(name)) {
  6260. arg = name.replace(onRE, '');
  6261. pushDir('on', publicDirectives.on);
  6262. } else
  6263. // attribute bindings
  6264. if (bindRE.test(name)) {
  6265. dirName = name.replace(bindRE, '');
  6266. if (dirName === 'style' || dirName === 'class') {
  6267. pushDir(dirName, internalDirectives[dirName]);
  6268. } else {
  6269. arg = dirName;
  6270. pushDir('bind', publicDirectives.bind);
  6271. }
  6272. } else
  6273. // normal directives
  6274. if (name.indexOf('v-') === 0) {
  6275. // check arg
  6276. arg = (arg = name.match(argRE)) && arg[1];
  6277. if (arg) {
  6278. name = name.replace(argRE, '');
  6279. }
  6280. // extract directive name
  6281. dirName = name.slice(2);
  6282. // skip v-else (when used with v-show)
  6283. if (dirName === 'else') {
  6284. continue;
  6285. }
  6286. dirDef = resolveAsset(options, 'directives', dirName);
  6287. if ('development' !== 'production') {
  6288. assertAsset(dirDef, 'directive', dirName);
  6289. }
  6290. if (dirDef) {
  6291. pushDir(dirName, dirDef);
  6292. }
  6293. }
  6294. }
  6295. /**
  6296. * Push a directive.
  6297. *
  6298. * @param {String} dirName
  6299. * @param {Object|Function} def
  6300. * @param {Array} [interpTokens]
  6301. */
  6302. function pushDir(dirName, def, interpTokens) {
  6303. var hasOneTimeToken = interpTokens && hasOneTime(interpTokens);
  6304. var parsed = !hasOneTimeToken && parseDirective(value);
  6305. dirs.push({
  6306. name: dirName,
  6307. attr: rawName,
  6308. raw: rawValue,
  6309. def: def,
  6310. arg: arg,
  6311. modifiers: modifiers,
  6312. // conversion from interpolation strings with one-time token
  6313. // to expression is differed until directive bind time so that we
  6314. // have access to the actual vm context for one-time bindings.
  6315. expression: parsed && parsed.expression,
  6316. filters: parsed && parsed.filters,
  6317. interp: interpTokens,
  6318. hasOneTime: hasOneTimeToken
  6319. });
  6320. }
  6321. if (dirs.length) {
  6322. return makeNodeLinkFn(dirs);
  6323. }
  6324. }
  6325. /**
  6326. * Parse modifiers from directive attribute name.
  6327. *
  6328. * @param {String} name
  6329. * @return {Object}
  6330. */
  6331. function parseModifiers(name) {
  6332. var res = Object.create(null);
  6333. var match = name.match(modifierRE);
  6334. if (match) {
  6335. var i = match.length;
  6336. while (i--) {
  6337. res[match[i].slice(1)] = true;
  6338. }
  6339. }
  6340. return res;
  6341. }
  6342. /**
  6343. * Build a link function for all directives on a single node.
  6344. *
  6345. * @param {Array} directives
  6346. * @return {Function} directivesLinkFn
  6347. */
  6348. function makeNodeLinkFn(directives) {
  6349. return function nodeLinkFn(vm, el, host, scope, frag) {
  6350. // reverse apply because it's sorted low to high
  6351. var i = directives.length;
  6352. while (i--) {
  6353. vm._bindDir(directives[i], el, host, scope, frag);
  6354. }
  6355. };
  6356. }
  6357. /**
  6358. * Check if an interpolation string contains one-time tokens.
  6359. *
  6360. * @param {Array} tokens
  6361. * @return {Boolean}
  6362. */
  6363. function hasOneTime(tokens) {
  6364. var i = tokens.length;
  6365. while (i--) {
  6366. if (tokens[i].oneTime) return true;
  6367. }
  6368. }
  6369. var specialCharRE = /[^\w\-:\.]/;
  6370. /**
  6371. * Process an element or a DocumentFragment based on a
  6372. * instance option object. This allows us to transclude
  6373. * a template node/fragment before the instance is created,
  6374. * so the processed fragment can then be cloned and reused
  6375. * in v-for.
  6376. *
  6377. * @param {Element} el
  6378. * @param {Object} options
  6379. * @return {Element|DocumentFragment}
  6380. */
  6381. function transclude(el, options) {
  6382. // extract container attributes to pass them down
  6383. // to compiler, because they need to be compiled in
  6384. // parent scope. we are mutating the options object here
  6385. // assuming the same object will be used for compile
  6386. // right after this.
  6387. if (options) {
  6388. options._containerAttrs = extractAttrs(el);
  6389. }
  6390. // for template tags, what we want is its content as
  6391. // a documentFragment (for fragment instances)
  6392. if (isTemplate(el)) {
  6393. el = parseTemplate(el);
  6394. }
  6395. if (options) {
  6396. if (options._asComponent && !options.template) {
  6397. options.template = '<slot></slot>';
  6398. }
  6399. if (options.template) {
  6400. options._content = extractContent(el);
  6401. el = transcludeTemplate(el, options);
  6402. }
  6403. }
  6404. if (el instanceof DocumentFragment) {
  6405. // anchors for fragment instance
  6406. // passing in `persist: true` to avoid them being
  6407. // discarded by IE during template cloning
  6408. prepend(createAnchor('v-start', true), el);
  6409. el.appendChild(createAnchor('v-end', true));
  6410. }
  6411. return el;
  6412. }
  6413. /**
  6414. * Process the template option.
  6415. * If the replace option is true this will swap the $el.
  6416. *
  6417. * @param {Element} el
  6418. * @param {Object} options
  6419. * @return {Element|DocumentFragment}
  6420. */
  6421. function transcludeTemplate(el, options) {
  6422. var template = options.template;
  6423. var frag = parseTemplate(template, true);
  6424. if (frag) {
  6425. var replacer = frag.firstChild;
  6426. var tag = replacer.tagName && replacer.tagName.toLowerCase();
  6427. if (options.replace) {
  6428. /* istanbul ignore if */
  6429. if (el === document.body) {
  6430. 'development' !== 'production' && warn('You are mounting an instance with a template to ' + '<body>. This will replace <body> entirely. You ' + 'should probably use `replace: false` here.');
  6431. }
  6432. // there are many cases where the instance must
  6433. // become a fragment instance: basically anything that
  6434. // can create more than 1 root nodes.
  6435. if (
  6436. // multi-children template
  6437. frag.childNodes.length > 1 ||
  6438. // non-element template
  6439. replacer.nodeType !== 1 ||
  6440. // single nested component
  6441. tag === 'component' || resolveAsset(options, 'components', tag) || hasBindAttr(replacer, 'is') ||
  6442. // element directive
  6443. resolveAsset(options, 'elementDirectives', tag) ||
  6444. // for block
  6445. replacer.hasAttribute('v-for') ||
  6446. // if block
  6447. replacer.hasAttribute('v-if')) {
  6448. return frag;
  6449. } else {
  6450. options._replacerAttrs = extractAttrs(replacer);
  6451. mergeAttrs(el, replacer);
  6452. return replacer;
  6453. }
  6454. } else {
  6455. el.appendChild(frag);
  6456. return el;
  6457. }
  6458. } else {
  6459. 'development' !== 'production' && warn('Invalid template option: ' + template);
  6460. }
  6461. }
  6462. /**
  6463. * Helper to extract a component container's attributes
  6464. * into a plain object array.
  6465. *
  6466. * @param {Element} el
  6467. * @return {Array}
  6468. */
  6469. function extractAttrs(el) {
  6470. if (el.nodeType === 1 && el.hasAttributes()) {
  6471. return toArray(el.attributes);
  6472. }
  6473. }
  6474. /**
  6475. * Merge the attributes of two elements, and make sure
  6476. * the class names are merged properly.
  6477. *
  6478. * @param {Element} from
  6479. * @param {Element} to
  6480. */
  6481. function mergeAttrs(from, to) {
  6482. var attrs = from.attributes;
  6483. var i = attrs.length;
  6484. var name, value;
  6485. while (i--) {
  6486. name = attrs[i].name;
  6487. value = attrs[i].value;
  6488. if (!to.hasAttribute(name) && !specialCharRE.test(name)) {
  6489. to.setAttribute(name, value);
  6490. } else if (name === 'class' && !parseText(value)) {
  6491. value.split(/\s+/).forEach(function (cls) {
  6492. addClass(to, cls);
  6493. });
  6494. }
  6495. }
  6496. }
  6497. var compiler = Object.freeze({
  6498. compile: compile,
  6499. compileAndLinkProps: compileAndLinkProps,
  6500. compileRoot: compileRoot,
  6501. terminalDirectives: terminalDirectives,
  6502. transclude: transclude
  6503. });
  6504. function stateMixin (Vue) {
  6505. /**
  6506. * Accessor for `$data` property, since setting $data
  6507. * requires observing the new object and updating
  6508. * proxied properties.
  6509. */
  6510. Object.defineProperty(Vue.prototype, '$data', {
  6511. get: function get() {
  6512. return this._data;
  6513. },
  6514. set: function set(newData) {
  6515. if (newData !== this._data) {
  6516. this._setData(newData);
  6517. }
  6518. }
  6519. });
  6520. /**
  6521. * Setup the scope of an instance, which contains:
  6522. * - observed data
  6523. * - computed properties
  6524. * - user methods
  6525. * - meta properties
  6526. */
  6527. Vue.prototype._initState = function () {
  6528. this._initProps();
  6529. this._initMeta();
  6530. this._initMethods();
  6531. this._initData();
  6532. this._initComputed();
  6533. };
  6534. /**
  6535. * Initialize props.
  6536. */
  6537. Vue.prototype._initProps = function () {
  6538. var options = this.$options;
  6539. var el = options.el;
  6540. var props = options.props;
  6541. if (props && !el) {
  6542. 'development' !== 'production' && warn('Props will not be compiled if no `el` option is ' + 'provided at instantiation.');
  6543. }
  6544. // make sure to convert string selectors into element now
  6545. el = options.el = query(el);
  6546. this._propsUnlinkFn = el && el.nodeType === 1 && props
  6547. // props must be linked in proper scope if inside v-for
  6548. ? compileAndLinkProps(this, el, props, this._scope) : null;
  6549. };
  6550. /**
  6551. * Initialize the data.
  6552. */
  6553. Vue.prototype._initData = function () {
  6554. var propsData = this._data;
  6555. var optionsDataFn = this.$options.data;
  6556. var optionsData = optionsDataFn && optionsDataFn();
  6557. if (optionsData) {
  6558. this._data = optionsData;
  6559. for (var prop in propsData) {
  6560. if ('development' !== 'production' && hasOwn(optionsData, prop)) {
  6561. warn('Data field "' + prop + '" is already defined ' + 'as a prop. Use prop default value instead.');
  6562. }
  6563. if (this._props[prop].raw !== null || !hasOwn(optionsData, prop)) {
  6564. set(optionsData, prop, propsData[prop]);
  6565. }
  6566. }
  6567. }
  6568. var data = this._data;
  6569. // proxy data on instance
  6570. var keys = Object.keys(data);
  6571. var i, key;
  6572. i = keys.length;
  6573. while (i--) {
  6574. key = keys[i];
  6575. this._proxy(key);
  6576. }
  6577. // observe data
  6578. observe(data, this);
  6579. };
  6580. /**
  6581. * Swap the instance's $data. Called in $data's setter.
  6582. *
  6583. * @param {Object} newData
  6584. */
  6585. Vue.prototype._setData = function (newData) {
  6586. newData = newData || {};
  6587. var oldData = this._data;
  6588. this._data = newData;
  6589. var keys, key, i;
  6590. // unproxy keys not present in new data
  6591. keys = Object.keys(oldData);
  6592. i = keys.length;
  6593. while (i--) {
  6594. key = keys[i];
  6595. if (!(key in newData)) {
  6596. this._unproxy(key);
  6597. }
  6598. }
  6599. // proxy keys not already proxied,
  6600. // and trigger change for changed values
  6601. keys = Object.keys(newData);
  6602. i = keys.length;
  6603. while (i--) {
  6604. key = keys[i];
  6605. if (!hasOwn(this, key)) {
  6606. // new property
  6607. this._proxy(key);
  6608. }
  6609. }
  6610. oldData.__ob__.removeVm(this);
  6611. observe(newData, this);
  6612. this._digest();
  6613. };
  6614. /**
  6615. * Proxy a property, so that
  6616. * vm.prop === vm._data.prop
  6617. *
  6618. * @param {String} key
  6619. */
  6620. Vue.prototype._proxy = function (key) {
  6621. if (!isReserved(key)) {
  6622. // need to store ref to self here
  6623. // because these getter/setters might
  6624. // be called by child scopes via
  6625. // prototype inheritance.
  6626. var self = this;
  6627. Object.defineProperty(self, key, {
  6628. configurable: true,
  6629. enumerable: true,
  6630. get: function proxyGetter() {
  6631. return self._data[key];
  6632. },
  6633. set: function proxySetter(val) {
  6634. self._data[key] = val;
  6635. }
  6636. });
  6637. }
  6638. };
  6639. /**
  6640. * Unproxy a property.
  6641. *
  6642. * @param {String} key
  6643. */
  6644. Vue.prototype._unproxy = function (key) {
  6645. if (!isReserved(key)) {
  6646. delete this[key];
  6647. }
  6648. };
  6649. /**
  6650. * Force update on every watcher in scope.
  6651. */
  6652. Vue.prototype._digest = function () {
  6653. for (var i = 0, l = this._watchers.length; i < l; i++) {
  6654. this._watchers[i].update(true); // shallow updates
  6655. }
  6656. };
  6657. /**
  6658. * Setup computed properties. They are essentially
  6659. * special getter/setters
  6660. */
  6661. function noop() {}
  6662. Vue.prototype._initComputed = function () {
  6663. var computed = this.$options.computed;
  6664. if (computed) {
  6665. for (var key in computed) {
  6666. var userDef = computed[key];
  6667. var def = {
  6668. enumerable: true,
  6669. configurable: true
  6670. };
  6671. if (typeof userDef === 'function') {
  6672. def.get = makeComputedGetter(userDef, this);
  6673. def.set = noop;
  6674. } else {
  6675. def.get = userDef.get ? userDef.cache !== false ? makeComputedGetter(userDef.get, this) : bind$1(userDef.get, this) : noop;
  6676. def.set = userDef.set ? bind$1(userDef.set, this) : noop;
  6677. }
  6678. Object.defineProperty(this, key, def);
  6679. }
  6680. }
  6681. };
  6682. function makeComputedGetter(getter, owner) {
  6683. var watcher = new Watcher(owner, getter, null, {
  6684. lazy: true
  6685. });
  6686. return function computedGetter() {
  6687. if (watcher.dirty) {
  6688. watcher.evaluate();
  6689. }
  6690. if (Dep.target) {
  6691. watcher.depend();
  6692. }
  6693. return watcher.value;
  6694. };
  6695. }
  6696. /**
  6697. * Setup instance methods. Methods must be bound to the
  6698. * instance since they might be passed down as a prop to
  6699. * child components.
  6700. */
  6701. Vue.prototype._initMethods = function () {
  6702. var methods = this.$options.methods;
  6703. if (methods) {
  6704. for (var key in methods) {
  6705. this[key] = bind$1(methods[key], this);
  6706. }
  6707. }
  6708. };
  6709. /**
  6710. * Initialize meta information like $index, $key & $value.
  6711. */
  6712. Vue.prototype._initMeta = function () {
  6713. var metas = this.$options._meta;
  6714. if (metas) {
  6715. for (var key in metas) {
  6716. defineReactive(this, key, metas[key]);
  6717. }
  6718. }
  6719. };
  6720. }
  6721. var eventRE = /^v-on:|^@/;
  6722. function eventsMixin (Vue) {
  6723. /**
  6724. * Setup the instance's option events & watchers.
  6725. * If the value is a string, we pull it from the
  6726. * instance's methods by name.
  6727. */
  6728. Vue.prototype._initEvents = function () {
  6729. var options = this.$options;
  6730. if (options._asComponent) {
  6731. registerComponentEvents(this, options.el);
  6732. }
  6733. registerCallbacks(this, '$on', options.events);
  6734. registerCallbacks(this, '$watch', options.watch);
  6735. };
  6736. /**
  6737. * Register v-on events on a child component
  6738. *
  6739. * @param {Vue} vm
  6740. * @param {Element} el
  6741. */
  6742. function registerComponentEvents(vm, el) {
  6743. var attrs = el.attributes;
  6744. var name, handler;
  6745. for (var i = 0, l = attrs.length; i < l; i++) {
  6746. name = attrs[i].name;
  6747. if (eventRE.test(name)) {
  6748. name = name.replace(eventRE, '');
  6749. handler = (vm._scope || vm._context).$eval(attrs[i].value, true);
  6750. handler._fromParent = true;
  6751. vm.$on(name.replace(eventRE), handler);
  6752. }
  6753. }
  6754. }
  6755. /**
  6756. * Register callbacks for option events and watchers.
  6757. *
  6758. * @param {Vue} vm
  6759. * @param {String} action
  6760. * @param {Object} hash
  6761. */
  6762. function registerCallbacks(vm, action, hash) {
  6763. if (!hash) return;
  6764. var handlers, key, i, j;
  6765. for (key in hash) {
  6766. handlers = hash[key];
  6767. if (isArray(handlers)) {
  6768. for (i = 0, j = handlers.length; i < j; i++) {
  6769. register(vm, action, key, handlers[i]);
  6770. }
  6771. } else {
  6772. register(vm, action, key, handlers);
  6773. }
  6774. }
  6775. }
  6776. /**
  6777. * Helper to register an event/watch callback.
  6778. *
  6779. * @param {Vue} vm
  6780. * @param {String} action
  6781. * @param {String} key
  6782. * @param {Function|String|Object} handler
  6783. * @param {Object} [options]
  6784. */
  6785. function register(vm, action, key, handler, options) {
  6786. var type = typeof handler;
  6787. if (type === 'function') {
  6788. vm[action](key, handler, options);
  6789. } else if (type === 'string') {
  6790. var methods = vm.$options.methods;
  6791. var method = methods && methods[handler];
  6792. if (method) {
  6793. vm[action](key, method, options);
  6794. } else {
  6795. 'development' !== 'production' && warn('Unknown method: "' + handler + '" when ' + 'registering callback for ' + action + ': "' + key + '".');
  6796. }
  6797. } else if (handler && type === 'object') {
  6798. register(vm, action, key, handler.handler, handler);
  6799. }
  6800. }
  6801. /**
  6802. * Setup recursive attached/detached calls
  6803. */
  6804. Vue.prototype._initDOMHooks = function () {
  6805. this.$on('hook:attached', onAttached);
  6806. this.$on('hook:detached', onDetached);
  6807. };
  6808. /**
  6809. * Callback to recursively call attached hook on children
  6810. */
  6811. function onAttached() {
  6812. if (!this._isAttached) {
  6813. this._isAttached = true;
  6814. this.$children.forEach(callAttach);
  6815. }
  6816. }
  6817. /**
  6818. * Iterator to call attached hook
  6819. *
  6820. * @param {Vue} child
  6821. */
  6822. function callAttach(child) {
  6823. if (!child._isAttached && inDoc(child.$el)) {
  6824. child._callHook('attached');
  6825. }
  6826. }
  6827. /**
  6828. * Callback to recursively call detached hook on children
  6829. */
  6830. function onDetached() {
  6831. if (this._isAttached) {
  6832. this._isAttached = false;
  6833. this.$children.forEach(callDetach);
  6834. }
  6835. }
  6836. /**
  6837. * Iterator to call detached hook
  6838. *
  6839. * @param {Vue} child
  6840. */
  6841. function callDetach(child) {
  6842. if (child._isAttached && !inDoc(child.$el)) {
  6843. child._callHook('detached');
  6844. }
  6845. }
  6846. /**
  6847. * Trigger all handlers for a hook
  6848. *
  6849. * @param {String} hook
  6850. */
  6851. Vue.prototype._callHook = function (hook) {
  6852. this.$emit('pre-hook:' + hook);
  6853. var handlers = this.$options[hook];
  6854. if (handlers) {
  6855. for (var i = 0, j = handlers.length; i < j; i++) {
  6856. handlers[i].call(this);
  6857. }
  6858. }
  6859. this.$emit('hook:' + hook);
  6860. };
  6861. }
  6862. function noop() {}
  6863. /**
  6864. * A directive links a DOM element with a piece of data,
  6865. * which is the result of evaluating an expression.
  6866. * It registers a watcher with the expression and calls
  6867. * the DOM update function when a change is triggered.
  6868. *
  6869. * @param {String} name
  6870. * @param {Node} el
  6871. * @param {Vue} vm
  6872. * @param {Object} descriptor
  6873. * - {String} name
  6874. * - {Object} def
  6875. * - {String} expression
  6876. * - {Array<Object>} [filters]
  6877. * - {Boolean} literal
  6878. * - {String} attr
  6879. * - {String} raw
  6880. * @param {Object} def - directive definition object
  6881. * @param {Vue} [host] - transclusion host component
  6882. * @param {Object} [scope] - v-for scope
  6883. * @param {Fragment} [frag] - owner fragment
  6884. * @constructor
  6885. */
  6886. function Directive(descriptor, vm, el, host, scope, frag) {
  6887. this.vm = vm;
  6888. this.el = el;
  6889. // copy descriptor properties
  6890. this.descriptor = descriptor;
  6891. this.name = descriptor.name;
  6892. this.expression = descriptor.expression;
  6893. this.arg = descriptor.arg;
  6894. this.modifiers = descriptor.modifiers;
  6895. this.filters = descriptor.filters;
  6896. this.literal = this.modifiers && this.modifiers.literal;
  6897. // private
  6898. this._locked = false;
  6899. this._bound = false;
  6900. this._listeners = null;
  6901. // link context
  6902. this._host = host;
  6903. this._scope = scope;
  6904. this._frag = frag;
  6905. // store directives on node in dev mode
  6906. if ('development' !== 'production' && this.el) {
  6907. this.el._vue_directives = this.el._vue_directives || [];
  6908. this.el._vue_directives.push(this);
  6909. }
  6910. }
  6911. /**
  6912. * Initialize the directive, mixin definition properties,
  6913. * setup the watcher, call definition bind() and update()
  6914. * if present.
  6915. *
  6916. * @param {Object} def
  6917. */
  6918. Directive.prototype._bind = function () {
  6919. var name = this.name;
  6920. var descriptor = this.descriptor;
  6921. // remove attribute
  6922. if ((name !== 'cloak' || this.vm._isCompiled) && this.el && this.el.removeAttribute) {
  6923. var attr = descriptor.attr || 'v-' + name;
  6924. this.el.removeAttribute(attr);
  6925. }
  6926. // copy def properties
  6927. var def = descriptor.def;
  6928. if (typeof def === 'function') {
  6929. this.update = def;
  6930. } else {
  6931. extend(this, def);
  6932. }
  6933. // setup directive params
  6934. this._setupParams();
  6935. // initial bind
  6936. if (this.bind) {
  6937. this.bind();
  6938. }
  6939. this._bound = true;
  6940. if (this.literal) {
  6941. this.update && this.update(descriptor.raw);
  6942. } else if ((this.expression || this.modifiers) && (this.update || this.twoWay) && !this._checkStatement()) {
  6943. // wrapped updater for context
  6944. var dir = this;
  6945. if (this.update) {
  6946. this._update = function (val, oldVal) {
  6947. if (!dir._locked) {
  6948. dir.update(val, oldVal);
  6949. }
  6950. };
  6951. } else {
  6952. this._update = noop;
  6953. }
  6954. var preProcess = this._preProcess ? bind$1(this._preProcess, this) : null;
  6955. var postProcess = this._postProcess ? bind$1(this._postProcess, this) : null;
  6956. var watcher = this._watcher = new Watcher(this.vm, this.expression, this._update, // callback
  6957. {
  6958. filters: this.filters,
  6959. twoWay: this.twoWay,
  6960. deep: this.deep,
  6961. preProcess: preProcess,
  6962. postProcess: postProcess,
  6963. scope: this._scope
  6964. });
  6965. // v-model with inital inline value need to sync back to
  6966. // model instead of update to DOM on init. They would
  6967. // set the afterBind hook to indicate that.
  6968. if (this.afterBind) {
  6969. this.afterBind();
  6970. } else if (this.update) {
  6971. this.update(watcher.value);
  6972. }
  6973. }
  6974. };
  6975. /**
  6976. * Setup all param attributes, e.g. track-by,
  6977. * transition-mode, etc...
  6978. */
  6979. Directive.prototype._setupParams = function () {
  6980. if (!this.params) {
  6981. return;
  6982. }
  6983. var params = this.params;
  6984. // swap the params array with a fresh object.
  6985. this.params = Object.create(null);
  6986. var i = params.length;
  6987. var key, val, mappedKey;
  6988. while (i--) {
  6989. key = params[i];
  6990. mappedKey = camelize(key);
  6991. val = getBindAttr(this.el, key);
  6992. if (val != null) {
  6993. // dynamic
  6994. this._setupParamWatcher(mappedKey, val);
  6995. } else {
  6996. // static
  6997. val = getAttr(this.el, key);
  6998. if (val != null) {
  6999. this.params[mappedKey] = val === '' ? true : val;
  7000. }
  7001. }
  7002. }
  7003. };
  7004. /**
  7005. * Setup a watcher for a dynamic param.
  7006. *
  7007. * @param {String} key
  7008. * @param {String} expression
  7009. */
  7010. Directive.prototype._setupParamWatcher = function (key, expression) {
  7011. var self = this;
  7012. var called = false;
  7013. var unwatch = (this._scope || this.vm).$watch(expression, function (val, oldVal) {
  7014. self.params[key] = val;
  7015. // since we are in immediate mode,
  7016. // only call the param change callbacks if this is not the first update.
  7017. if (called) {
  7018. var cb = self.paramWatchers && self.paramWatchers[key];
  7019. if (cb) {
  7020. cb.call(self, val, oldVal);
  7021. }
  7022. } else {
  7023. called = true;
  7024. }
  7025. }, {
  7026. immediate: true,
  7027. user: false
  7028. });(this._paramUnwatchFns || (this._paramUnwatchFns = [])).push(unwatch);
  7029. };
  7030. /**
  7031. * Check if the directive is a function caller
  7032. * and if the expression is a callable one. If both true,
  7033. * we wrap up the expression and use it as the event
  7034. * handler.
  7035. *
  7036. * e.g. on-click="a++"
  7037. *
  7038. * @return {Boolean}
  7039. */
  7040. Directive.prototype._checkStatement = function () {
  7041. var expression = this.expression;
  7042. if (expression && this.acceptStatement && !isSimplePath(expression)) {
  7043. var fn = parseExpression(expression).get;
  7044. var scope = this._scope || this.vm;
  7045. var handler = function handler(e) {
  7046. scope.$event = e;
  7047. fn.call(scope, scope);
  7048. scope.$event = null;
  7049. };
  7050. if (this.filters) {
  7051. handler = scope._applyFilters(handler, null, this.filters);
  7052. }
  7053. this.update(handler);
  7054. return true;
  7055. }
  7056. };
  7057. /**
  7058. * Set the corresponding value with the setter.
  7059. * This should only be used in two-way directives
  7060. * e.g. v-model.
  7061. *
  7062. * @param {*} value
  7063. * @public
  7064. */
  7065. Directive.prototype.set = function (value) {
  7066. /* istanbul ignore else */
  7067. if (this.twoWay) {
  7068. this._withLock(function () {
  7069. this._watcher.set(value);
  7070. });
  7071. } else if ('development' !== 'production') {
  7072. warn('Directive.set() can only be used inside twoWay' + 'directives.');
  7073. }
  7074. };
  7075. /**
  7076. * Execute a function while preventing that function from
  7077. * triggering updates on this directive instance.
  7078. *
  7079. * @param {Function} fn
  7080. */
  7081. Directive.prototype._withLock = function (fn) {
  7082. var self = this;
  7083. self._locked = true;
  7084. fn.call(self);
  7085. nextTick(function () {
  7086. self._locked = false;
  7087. });
  7088. };
  7089. /**
  7090. * Convenience method that attaches a DOM event listener
  7091. * to the directive element and autometically tears it down
  7092. * during unbind.
  7093. *
  7094. * @param {String} event
  7095. * @param {Function} handler
  7096. */
  7097. Directive.prototype.on = function (event, handler) {
  7098. on$1(this.el, event, handler);(this._listeners || (this._listeners = [])).push([event, handler]);
  7099. };
  7100. /**
  7101. * Teardown the watcher and call unbind.
  7102. */
  7103. Directive.prototype._teardown = function () {
  7104. if (this._bound) {
  7105. this._bound = false;
  7106. if (this.unbind) {
  7107. this.unbind();
  7108. }
  7109. if (this._watcher) {
  7110. this._watcher.teardown();
  7111. }
  7112. var listeners = this._listeners;
  7113. var i;
  7114. if (listeners) {
  7115. i = listeners.length;
  7116. while (i--) {
  7117. off(this.el, listeners[i][0], listeners[i][1]);
  7118. }
  7119. }
  7120. var unwatchFns = this._paramUnwatchFns;
  7121. if (unwatchFns) {
  7122. i = unwatchFns.length;
  7123. while (i--) {
  7124. unwatchFns[i]();
  7125. }
  7126. }
  7127. if ('development' !== 'production' && this.el) {
  7128. this.el._vue_directives.$remove(this);
  7129. }
  7130. this.vm = this.el = this._watcher = this._listeners = null;
  7131. }
  7132. };
  7133. function lifecycleMixin (Vue) {
  7134. /**
  7135. * Update v-ref for component.
  7136. *
  7137. * @param {Boolean} remove
  7138. */
  7139. Vue.prototype._updateRef = function (remove) {
  7140. var ref = this.$options._ref;
  7141. if (ref) {
  7142. var refs = (this._scope || this._context).$refs;
  7143. if (remove) {
  7144. if (refs[ref] === this) {
  7145. refs[ref] = null;
  7146. }
  7147. } else {
  7148. refs[ref] = this;
  7149. }
  7150. }
  7151. };
  7152. /**
  7153. * Transclude, compile and link element.
  7154. *
  7155. * If a pre-compiled linker is available, that means the
  7156. * passed in element will be pre-transcluded and compiled
  7157. * as well - all we need to do is to call the linker.
  7158. *
  7159. * Otherwise we need to call transclude/compile/link here.
  7160. *
  7161. * @param {Element} el
  7162. * @return {Element}
  7163. */
  7164. Vue.prototype._compile = function (el) {
  7165. var options = this.$options;
  7166. // transclude and init element
  7167. // transclude can potentially replace original
  7168. // so we need to keep reference; this step also injects
  7169. // the template and caches the original attributes
  7170. // on the container node and replacer node.
  7171. var original = el;
  7172. el = transclude(el, options);
  7173. this._initElement(el);
  7174. // handle v-pre on root node (#2026)
  7175. if (el.nodeType === 1 && getAttr(el, 'v-pre') !== null) {
  7176. return;
  7177. }
  7178. // root is always compiled per-instance, because
  7179. // container attrs and props can be different every time.
  7180. var contextOptions = this._context && this._context.$options;
  7181. var rootLinker = compileRoot(el, options, contextOptions);
  7182. // compile and link the rest
  7183. var contentLinkFn;
  7184. var ctor = this.constructor;
  7185. // component compilation can be cached
  7186. // as long as it's not using inline-template
  7187. if (options._linkerCachable) {
  7188. contentLinkFn = ctor.linker;
  7189. if (!contentLinkFn) {
  7190. contentLinkFn = ctor.linker = compile(el, options);
  7191. }
  7192. }
  7193. // link phase
  7194. // make sure to link root with prop scope!
  7195. var rootUnlinkFn = rootLinker(this, el, this._scope);
  7196. var contentUnlinkFn = contentLinkFn ? contentLinkFn(this, el) : compile(el, options)(this, el);
  7197. // register composite unlink function
  7198. // to be called during instance destruction
  7199. this._unlinkFn = function () {
  7200. rootUnlinkFn();
  7201. // passing destroying: true to avoid searching and
  7202. // splicing the directives
  7203. contentUnlinkFn(true);
  7204. };
  7205. // finally replace original
  7206. if (options.replace) {
  7207. replace(original, el);
  7208. }
  7209. this._isCompiled = true;
  7210. this._callHook('compiled');
  7211. return el;
  7212. };
  7213. /**
  7214. * Initialize instance element. Called in the public
  7215. * $mount() method.
  7216. *
  7217. * @param {Element} el
  7218. */
  7219. Vue.prototype._initElement = function (el) {
  7220. if (el instanceof DocumentFragment) {
  7221. this._isFragment = true;
  7222. this.$el = this._fragmentStart = el.firstChild;
  7223. this._fragmentEnd = el.lastChild;
  7224. // set persisted text anchors to empty
  7225. if (this._fragmentStart.nodeType === 3) {
  7226. this._fragmentStart.data = this._fragmentEnd.data = '';
  7227. }
  7228. this._fragment = el;
  7229. } else {
  7230. this.$el = el;
  7231. }
  7232. this.$el.__vue__ = this;
  7233. this._callHook('beforeCompile');
  7234. };
  7235. /**
  7236. * Create and bind a directive to an element.
  7237. *
  7238. * @param {String} name - directive name
  7239. * @param {Node} node - target node
  7240. * @param {Object} desc - parsed directive descriptor
  7241. * @param {Object} def - directive definition object
  7242. * @param {Vue} [host] - transclusion host component
  7243. * @param {Object} [scope] - v-for scope
  7244. * @param {Fragment} [frag] - owner fragment
  7245. */
  7246. Vue.prototype._bindDir = function (descriptor, node, host, scope, frag) {
  7247. this._directives.push(new Directive(descriptor, this, node, host, scope, frag));
  7248. };
  7249. /**
  7250. * Teardown an instance, unobserves the data, unbind all the
  7251. * directives, turn off all the event listeners, etc.
  7252. *
  7253. * @param {Boolean} remove - whether to remove the DOM node.
  7254. * @param {Boolean} deferCleanup - if true, defer cleanup to
  7255. * be called later
  7256. */
  7257. Vue.prototype._destroy = function (remove, deferCleanup) {
  7258. if (this._isBeingDestroyed) {
  7259. if (!deferCleanup) {
  7260. this._cleanup();
  7261. }
  7262. return;
  7263. }
  7264. var destroyReady;
  7265. var pendingRemoval;
  7266. var self = this;
  7267. // Cleanup should be called either synchronously or asynchronoysly as
  7268. // callback of this.$remove(), or if remove and deferCleanup are false.
  7269. // In any case it should be called after all other removing, unbinding and
  7270. // turning of is done
  7271. var cleanupIfPossible = function cleanupIfPossible() {
  7272. if (destroyReady && !pendingRemoval && !deferCleanup) {
  7273. self._cleanup();
  7274. }
  7275. };
  7276. // remove DOM element
  7277. if (remove && this.$el) {
  7278. pendingRemoval = true;
  7279. this.$remove(function () {
  7280. pendingRemoval = false;
  7281. cleanupIfPossible();
  7282. });
  7283. }
  7284. this._callHook('beforeDestroy');
  7285. this._isBeingDestroyed = true;
  7286. var i;
  7287. // remove self from parent. only necessary
  7288. // if parent is not being destroyed as well.
  7289. var parent = this.$parent;
  7290. if (parent && !parent._isBeingDestroyed) {
  7291. parent.$children.$remove(this);
  7292. // unregister ref (remove: true)
  7293. this._updateRef(true);
  7294. }
  7295. // destroy all children.
  7296. i = this.$children.length;
  7297. while (i--) {
  7298. this.$children[i].$destroy();
  7299. }
  7300. // teardown props
  7301. if (this._propsUnlinkFn) {
  7302. this._propsUnlinkFn();
  7303. }
  7304. // teardown all directives. this also tearsdown all
  7305. // directive-owned watchers.
  7306. if (this._unlinkFn) {
  7307. this._unlinkFn();
  7308. }
  7309. i = this._watchers.length;
  7310. while (i--) {
  7311. this._watchers[i].teardown();
  7312. }
  7313. // remove reference to self on $el
  7314. if (this.$el) {
  7315. this.$el.__vue__ = null;
  7316. }
  7317. destroyReady = true;
  7318. cleanupIfPossible();
  7319. };
  7320. /**
  7321. * Clean up to ensure garbage collection.
  7322. * This is called after the leave transition if there
  7323. * is any.
  7324. */
  7325. Vue.prototype._cleanup = function () {
  7326. if (this._isDestroyed) {
  7327. return;
  7328. }
  7329. // remove self from owner fragment
  7330. // do it in cleanup so that we can call $destroy with
  7331. // defer right when a fragment is about to be removed.
  7332. if (this._frag) {
  7333. this._frag.children.$remove(this);
  7334. }
  7335. // remove reference from data ob
  7336. // frozen object may not have observer.
  7337. if (this._data.__ob__) {
  7338. this._data.__ob__.removeVm(this);
  7339. }
  7340. // Clean up references to private properties and other
  7341. // instances. preserve reference to _data so that proxy
  7342. // accessors still work. The only potential side effect
  7343. // here is that mutating the instance after it's destroyed
  7344. // may affect the state of other components that are still
  7345. // observing the same object, but that seems to be a
  7346. // reasonable responsibility for the user rather than
  7347. // always throwing an error on them.
  7348. this.$el = this.$parent = this.$root = this.$children = this._watchers = this._context = this._scope = this._directives = null;
  7349. // call the last hook...
  7350. this._isDestroyed = true;
  7351. this._callHook('destroyed');
  7352. // turn off all instance listeners.
  7353. this.$off();
  7354. };
  7355. }
  7356. function miscMixin (Vue) {
  7357. /**
  7358. * Apply a list of filter (descriptors) to a value.
  7359. * Using plain for loops here because this will be called in
  7360. * the getter of any watcher with filters so it is very
  7361. * performance sensitive.
  7362. *
  7363. * @param {*} value
  7364. * @param {*} [oldValue]
  7365. * @param {Array} filters
  7366. * @param {Boolean} write
  7367. * @return {*}
  7368. */
  7369. Vue.prototype._applyFilters = function (value, oldValue, filters, write) {
  7370. var filter, fn, args, arg, offset, i, l, j, k;
  7371. for (i = 0, l = filters.length; i < l; i++) {
  7372. filter = filters[i];
  7373. fn = resolveAsset(this.$options, 'filters', filter.name);
  7374. if ('development' !== 'production') {
  7375. assertAsset(fn, 'filter', filter.name);
  7376. }
  7377. if (!fn) continue;
  7378. fn = write ? fn.write : fn.read || fn;
  7379. if (typeof fn !== 'function') continue;
  7380. args = write ? [value, oldValue] : [value];
  7381. offset = write ? 2 : 1;
  7382. if (filter.args) {
  7383. for (j = 0, k = filter.args.length; j < k; j++) {
  7384. arg = filter.args[j];
  7385. args[j + offset] = arg.dynamic ? this.$get(arg.value) : arg.value;
  7386. }
  7387. }
  7388. value = fn.apply(this, args);
  7389. }
  7390. return value;
  7391. };
  7392. /**
  7393. * Resolve a component, depending on whether the component
  7394. * is defined normally or using an async factory function.
  7395. * Resolves synchronously if already resolved, otherwise
  7396. * resolves asynchronously and caches the resolved
  7397. * constructor on the factory.
  7398. *
  7399. * @param {String} id
  7400. * @param {Function} cb
  7401. */
  7402. Vue.prototype._resolveComponent = function (id, cb) {
  7403. var factory = resolveAsset(this.$options, 'components', id);
  7404. if ('development' !== 'production') {
  7405. assertAsset(factory, 'component', id);
  7406. }
  7407. if (!factory) {
  7408. return;
  7409. }
  7410. // async component factory
  7411. if (!factory.options) {
  7412. if (factory.resolved) {
  7413. // cached
  7414. cb(factory.resolved);
  7415. } else if (factory.requested) {
  7416. // pool callbacks
  7417. factory.pendingCallbacks.push(cb);
  7418. } else {
  7419. factory.requested = true;
  7420. var cbs = factory.pendingCallbacks = [cb];
  7421. factory(function resolve(res) {
  7422. if (isPlainObject(res)) {
  7423. res = Vue.extend(res);
  7424. }
  7425. // cache resolved
  7426. factory.resolved = res;
  7427. // invoke callbacks
  7428. for (var i = 0, l = cbs.length; i < l; i++) {
  7429. cbs[i](res);
  7430. }
  7431. }, function reject(reason) {
  7432. 'development' !== 'production' && warn('Failed to resolve async component: ' + id + '. ' + (reason ? '\nReason: ' + reason : ''));
  7433. });
  7434. }
  7435. } else {
  7436. // normal component
  7437. cb(factory);
  7438. }
  7439. };
  7440. }
  7441. function globalAPI (Vue) {
  7442. /**
  7443. * Expose useful internals
  7444. */
  7445. Vue.util = util;
  7446. Vue.config = config;
  7447. Vue.set = set;
  7448. Vue['delete'] = del;
  7449. Vue.nextTick = nextTick;
  7450. /**
  7451. * The following are exposed for advanced usage / plugins
  7452. */
  7453. Vue.compiler = compiler;
  7454. Vue.FragmentFactory = FragmentFactory;
  7455. Vue.internalDirectives = internalDirectives;
  7456. Vue.parsers = {
  7457. path: path,
  7458. text: text$1,
  7459. template: template,
  7460. directive: directive,
  7461. expression: expression
  7462. };
  7463. /**
  7464. * Each instance constructor, including Vue, has a unique
  7465. * cid. This enables us to create wrapped "child
  7466. * constructors" for prototypal inheritance and cache them.
  7467. */
  7468. Vue.cid = 0;
  7469. var cid = 1;
  7470. /**
  7471. * Class inheritance
  7472. *
  7473. * @param {Object} extendOptions
  7474. */
  7475. Vue.extend = function (extendOptions) {
  7476. extendOptions = extendOptions || {};
  7477. var Super = this;
  7478. var isFirstExtend = Super.cid === 0;
  7479. if (isFirstExtend && extendOptions._Ctor) {
  7480. return extendOptions._Ctor;
  7481. }
  7482. var name = extendOptions.name || Super.options.name;
  7483. if ('development' !== 'production') {
  7484. if (!/^[a-zA-Z][\w-]+$/.test(name)) {
  7485. warn('Invalid component name: ' + name);
  7486. name = null;
  7487. }
  7488. }
  7489. var Sub = createClass(name || 'VueComponent');
  7490. Sub.prototype = Object.create(Super.prototype);
  7491. Sub.prototype.constructor = Sub;
  7492. Sub.cid = cid++;
  7493. Sub.options = mergeOptions(Super.options, extendOptions);
  7494. Sub['super'] = Super;
  7495. // allow further extension
  7496. Sub.extend = Super.extend;
  7497. // create asset registers, so extended classes
  7498. // can have their private assets too.
  7499. config._assetTypes.forEach(function (type) {
  7500. Sub[type] = Super[type];
  7501. });
  7502. // enable recursive self-lookup
  7503. if (name) {
  7504. Sub.options.components[name] = Sub;
  7505. }
  7506. // cache constructor
  7507. if (isFirstExtend) {
  7508. extendOptions._Ctor = Sub;
  7509. }
  7510. return Sub;
  7511. };
  7512. /**
  7513. * A function that returns a sub-class constructor with the
  7514. * given name. This gives us much nicer output when
  7515. * logging instances in the console.
  7516. *
  7517. * @param {String} name
  7518. * @return {Function}
  7519. */
  7520. function createClass(name) {
  7521. return new Function('return function ' + classify(name) + ' (options) { this._init(options) }')();
  7522. }
  7523. /**
  7524. * Plugin system
  7525. *
  7526. * @param {Object} plugin
  7527. */
  7528. Vue.use = function (plugin) {
  7529. /* istanbul ignore if */
  7530. if (plugin.installed) {
  7531. return;
  7532. }
  7533. // additional parameters
  7534. var args = toArray(arguments, 1);
  7535. args.unshift(this);
  7536. if (typeof plugin.install === 'function') {
  7537. plugin.install.apply(plugin, args);
  7538. } else {
  7539. plugin.apply(null, args);
  7540. }
  7541. plugin.installed = true;
  7542. return this;
  7543. };
  7544. /**
  7545. * Apply a global mixin by merging it into the default
  7546. * options.
  7547. */
  7548. Vue.mixin = function (mixin) {
  7549. Vue.options = mergeOptions(Vue.options, mixin);
  7550. };
  7551. /**
  7552. * Create asset registration methods with the following
  7553. * signature:
  7554. *
  7555. * @param {String} id
  7556. * @param {*} definition
  7557. */
  7558. config._assetTypes.forEach(function (type) {
  7559. Vue[type] = function (id, definition) {
  7560. if (!definition) {
  7561. return this.options[type + 's'][id];
  7562. } else {
  7563. /* istanbul ignore if */
  7564. if ('development' !== 'production') {
  7565. if (type === 'component' && (commonTagRE.test(id) || reservedTagRE.test(id))) {
  7566. warn('Do not use built-in or reserved HTML elements as component ' + 'id: ' + id);
  7567. }
  7568. }
  7569. if (type === 'component' && isPlainObject(definition)) {
  7570. definition.name = id;
  7571. definition = Vue.extend(definition);
  7572. }
  7573. this.options[type + 's'][id] = definition;
  7574. return definition;
  7575. }
  7576. };
  7577. });
  7578. }
  7579. var filterRE = /[^|]\|[^|]/;
  7580. function dataAPI (Vue) {
  7581. /**
  7582. * Get the value from an expression on this vm.
  7583. *
  7584. * @param {String} exp
  7585. * @param {Boolean} [asStatement]
  7586. * @return {*}
  7587. */
  7588. Vue.prototype.$get = function (exp, asStatement) {
  7589. var res = parseExpression(exp);
  7590. if (res) {
  7591. if (asStatement && !isSimplePath(exp)) {
  7592. var self = this;
  7593. return function statementHandler() {
  7594. self.$arguments = toArray(arguments);
  7595. var result = res.get.call(self, self);
  7596. self.$arguments = null;
  7597. return result;
  7598. };
  7599. } else {
  7600. try {
  7601. return res.get.call(this, this);
  7602. } catch (e) {}
  7603. }
  7604. }
  7605. };
  7606. /**
  7607. * Set the value from an expression on this vm.
  7608. * The expression must be a valid left-hand
  7609. * expression in an assignment.
  7610. *
  7611. * @param {String} exp
  7612. * @param {*} val
  7613. */
  7614. Vue.prototype.$set = function (exp, val) {
  7615. var res = parseExpression(exp, true);
  7616. if (res && res.set) {
  7617. res.set.call(this, this, val);
  7618. }
  7619. };
  7620. /**
  7621. * Delete a property on the VM
  7622. *
  7623. * @param {String} key
  7624. */
  7625. Vue.prototype.$delete = function (key) {
  7626. del(this._data, key);
  7627. };
  7628. /**
  7629. * Watch an expression, trigger callback when its
  7630. * value changes.
  7631. *
  7632. * @param {String|Function} expOrFn
  7633. * @param {Function} cb
  7634. * @param {Object} [options]
  7635. * - {Boolean} deep
  7636. * - {Boolean} immediate
  7637. * @return {Function} - unwatchFn
  7638. */
  7639. Vue.prototype.$watch = function (expOrFn, cb, options) {
  7640. var vm = this;
  7641. var parsed;
  7642. if (typeof expOrFn === 'string') {
  7643. parsed = parseDirective(expOrFn);
  7644. expOrFn = parsed.expression;
  7645. }
  7646. var watcher = new Watcher(vm, expOrFn, cb, {
  7647. deep: options && options.deep,
  7648. sync: options && options.sync,
  7649. filters: parsed && parsed.filters,
  7650. user: !options || options.user !== false
  7651. });
  7652. if (options && options.immediate) {
  7653. cb.call(vm, watcher.value);
  7654. }
  7655. return function unwatchFn() {
  7656. watcher.teardown();
  7657. };
  7658. };
  7659. /**
  7660. * Evaluate a text directive, including filters.
  7661. *
  7662. * @param {String} text
  7663. * @param {Boolean} [asStatement]
  7664. * @return {String}
  7665. */
  7666. Vue.prototype.$eval = function (text, asStatement) {
  7667. // check for filters.
  7668. if (filterRE.test(text)) {
  7669. var dir = parseDirective(text);
  7670. // the filter regex check might give false positive
  7671. // for pipes inside strings, so it's possible that
  7672. // we don't get any filters here
  7673. var val = this.$get(dir.expression, asStatement);
  7674. return dir.filters ? this._applyFilters(val, null, dir.filters) : val;
  7675. } else {
  7676. // no filter
  7677. return this.$get(text, asStatement);
  7678. }
  7679. };
  7680. /**
  7681. * Interpolate a piece of template text.
  7682. *
  7683. * @param {String} text
  7684. * @return {String}
  7685. */
  7686. Vue.prototype.$interpolate = function (text) {
  7687. var tokens = parseText(text);
  7688. var vm = this;
  7689. if (tokens) {
  7690. if (tokens.length === 1) {
  7691. return vm.$eval(tokens[0].value) + '';
  7692. } else {
  7693. return tokens.map(function (token) {
  7694. return token.tag ? vm.$eval(token.value) : token.value;
  7695. }).join('');
  7696. }
  7697. } else {
  7698. return text;
  7699. }
  7700. };
  7701. /**
  7702. * Log instance data as a plain JS object
  7703. * so that it is easier to inspect in console.
  7704. * This method assumes console is available.
  7705. *
  7706. * @param {String} [path]
  7707. */
  7708. Vue.prototype.$log = function (path) {
  7709. var data = path ? getPath(this._data, path) : this._data;
  7710. if (data) {
  7711. data = clean(data);
  7712. }
  7713. // include computed fields
  7714. if (!path) {
  7715. for (var key in this.$options.computed) {
  7716. data[key] = clean(this[key]);
  7717. }
  7718. }
  7719. console.log(data);
  7720. };
  7721. /**
  7722. * "clean" a getter/setter converted object into a plain
  7723. * object copy.
  7724. *
  7725. * @param {Object} - obj
  7726. * @return {Object}
  7727. */
  7728. function clean(obj) {
  7729. return JSON.parse(JSON.stringify(obj));
  7730. }
  7731. }
  7732. function domAPI (Vue) {
  7733. /**
  7734. * Convenience on-instance nextTick. The callback is
  7735. * auto-bound to the instance, and this avoids component
  7736. * modules having to rely on the global Vue.
  7737. *
  7738. * @param {Function} fn
  7739. */
  7740. Vue.prototype.$nextTick = function (fn) {
  7741. nextTick(fn, this);
  7742. };
  7743. /**
  7744. * Append instance to target
  7745. *
  7746. * @param {Node} target
  7747. * @param {Function} [cb]
  7748. * @param {Boolean} [withTransition] - defaults to true
  7749. */
  7750. Vue.prototype.$appendTo = function (target, cb, withTransition) {
  7751. return insert(this, target, cb, withTransition, append, appendWithTransition);
  7752. };
  7753. /**
  7754. * Prepend instance to target
  7755. *
  7756. * @param {Node} target
  7757. * @param {Function} [cb]
  7758. * @param {Boolean} [withTransition] - defaults to true
  7759. */
  7760. Vue.prototype.$prependTo = function (target, cb, withTransition) {
  7761. target = query(target);
  7762. if (target.hasChildNodes()) {
  7763. this.$before(target.firstChild, cb, withTransition);
  7764. } else {
  7765. this.$appendTo(target, cb, withTransition);
  7766. }
  7767. return this;
  7768. };
  7769. /**
  7770. * Insert instance before target
  7771. *
  7772. * @param {Node} target
  7773. * @param {Function} [cb]
  7774. * @param {Boolean} [withTransition] - defaults to true
  7775. */
  7776. Vue.prototype.$before = function (target, cb, withTransition) {
  7777. return insert(this, target, cb, withTransition, beforeWithCb, beforeWithTransition);
  7778. };
  7779. /**
  7780. * Insert instance after target
  7781. *
  7782. * @param {Node} target
  7783. * @param {Function} [cb]
  7784. * @param {Boolean} [withTransition] - defaults to true
  7785. */
  7786. Vue.prototype.$after = function (target, cb, withTransition) {
  7787. target = query(target);
  7788. if (target.nextSibling) {
  7789. this.$before(target.nextSibling, cb, withTransition);
  7790. } else {
  7791. this.$appendTo(target.parentNode, cb, withTransition);
  7792. }
  7793. return this;
  7794. };
  7795. /**
  7796. * Remove instance from DOM
  7797. *
  7798. * @param {Function} [cb]
  7799. * @param {Boolean} [withTransition] - defaults to true
  7800. */
  7801. Vue.prototype.$remove = function (cb, withTransition) {
  7802. if (!this.$el.parentNode) {
  7803. return cb && cb();
  7804. }
  7805. var inDocument = this._isAttached && inDoc(this.$el);
  7806. // if we are not in document, no need to check
  7807. // for transitions
  7808. if (!inDocument) withTransition = false;
  7809. var self = this;
  7810. var realCb = function realCb() {
  7811. if (inDocument) self._callHook('detached');
  7812. if (cb) cb();
  7813. };
  7814. if (this._isFragment) {
  7815. removeNodeRange(this._fragmentStart, this._fragmentEnd, this, this._fragment, realCb);
  7816. } else {
  7817. var op = withTransition === false ? removeWithCb : removeWithTransition;
  7818. op(this.$el, this, realCb);
  7819. }
  7820. return this;
  7821. };
  7822. /**
  7823. * Shared DOM insertion function.
  7824. *
  7825. * @param {Vue} vm
  7826. * @param {Element} target
  7827. * @param {Function} [cb]
  7828. * @param {Boolean} [withTransition]
  7829. * @param {Function} op1 - op for non-transition insert
  7830. * @param {Function} op2 - op for transition insert
  7831. * @return vm
  7832. */
  7833. function insert(vm, target, cb, withTransition, op1, op2) {
  7834. target = query(target);
  7835. var targetIsDetached = !inDoc(target);
  7836. var op = withTransition === false || targetIsDetached ? op1 : op2;
  7837. var shouldCallHook = !targetIsDetached && !vm._isAttached && !inDoc(vm.$el);
  7838. if (vm._isFragment) {
  7839. mapNodeRange(vm._fragmentStart, vm._fragmentEnd, function (node) {
  7840. op(node, target, vm);
  7841. });
  7842. cb && cb();
  7843. } else {
  7844. op(vm.$el, target, vm, cb);
  7845. }
  7846. if (shouldCallHook) {
  7847. vm._callHook('attached');
  7848. }
  7849. return vm;
  7850. }
  7851. /**
  7852. * Check for selectors
  7853. *
  7854. * @param {String|Element} el
  7855. */
  7856. function query(el) {
  7857. return typeof el === 'string' ? document.querySelector(el) : el;
  7858. }
  7859. /**
  7860. * Append operation that takes a callback.
  7861. *
  7862. * @param {Node} el
  7863. * @param {Node} target
  7864. * @param {Vue} vm - unused
  7865. * @param {Function} [cb]
  7866. */
  7867. function append(el, target, vm, cb) {
  7868. target.appendChild(el);
  7869. if (cb) cb();
  7870. }
  7871. /**
  7872. * InsertBefore operation that takes a callback.
  7873. *
  7874. * @param {Node} el
  7875. * @param {Node} target
  7876. * @param {Vue} vm - unused
  7877. * @param {Function} [cb]
  7878. */
  7879. function beforeWithCb(el, target, vm, cb) {
  7880. before(el, target);
  7881. if (cb) cb();
  7882. }
  7883. /**
  7884. * Remove operation that takes a callback.
  7885. *
  7886. * @param {Node} el
  7887. * @param {Vue} vm - unused
  7888. * @param {Function} [cb]
  7889. */
  7890. function removeWithCb(el, vm, cb) {
  7891. remove(el);
  7892. if (cb) cb();
  7893. }
  7894. }
  7895. function eventsAPI (Vue) {
  7896. /**
  7897. * Listen on the given `event` with `fn`.
  7898. *
  7899. * @param {String} event
  7900. * @param {Function} fn
  7901. */
  7902. Vue.prototype.$on = function (event, fn) {
  7903. (this._events[event] || (this._events[event] = [])).push(fn);
  7904. modifyListenerCount(this, event, 1);
  7905. return this;
  7906. };
  7907. /**
  7908. * Adds an `event` listener that will be invoked a single
  7909. * time then automatically removed.
  7910. *
  7911. * @param {String} event
  7912. * @param {Function} fn
  7913. */
  7914. Vue.prototype.$once = function (event, fn) {
  7915. var self = this;
  7916. function on() {
  7917. self.$off(event, on);
  7918. fn.apply(this, arguments);
  7919. }
  7920. on.fn = fn;
  7921. this.$on(event, on);
  7922. return this;
  7923. };
  7924. /**
  7925. * Remove the given callback for `event` or all
  7926. * registered callbacks.
  7927. *
  7928. * @param {String} event
  7929. * @param {Function} fn
  7930. */
  7931. Vue.prototype.$off = function (event, fn) {
  7932. var cbs;
  7933. // all
  7934. if (!arguments.length) {
  7935. if (this.$parent) {
  7936. for (event in this._events) {
  7937. cbs = this._events[event];
  7938. if (cbs) {
  7939. modifyListenerCount(this, event, -cbs.length);
  7940. }
  7941. }
  7942. }
  7943. this._events = {};
  7944. return this;
  7945. }
  7946. // specific event
  7947. cbs = this._events[event];
  7948. if (!cbs) {
  7949. return this;
  7950. }
  7951. if (arguments.length === 1) {
  7952. modifyListenerCount(this, event, -cbs.length);
  7953. this._events[event] = null;
  7954. return this;
  7955. }
  7956. // specific handler
  7957. var cb;
  7958. var i = cbs.length;
  7959. while (i--) {
  7960. cb = cbs[i];
  7961. if (cb === fn || cb.fn === fn) {
  7962. modifyListenerCount(this, event, -1);
  7963. cbs.splice(i, 1);
  7964. break;
  7965. }
  7966. }
  7967. return this;
  7968. };
  7969. /**
  7970. * Trigger an event on self.
  7971. *
  7972. * @param {String|Object} event
  7973. * @return {Boolean} shouldPropagate
  7974. */
  7975. Vue.prototype.$emit = function (event) {
  7976. var isSource = typeof event === 'string';
  7977. event = isSource ? event : event.name;
  7978. var cbs = this._events[event];
  7979. var shouldPropagate = isSource || !cbs;
  7980. if (cbs) {
  7981. cbs = cbs.length > 1 ? toArray(cbs) : cbs;
  7982. // this is a somewhat hacky solution to the question raised
  7983. // in #2102: for an inline component listener like <comp @test="doThis">,
  7984. // the propagation handling is somewhat broken. Therefore we
  7985. // need to treat these inline callbacks differently.
  7986. var hasParentCbs = isSource && cbs.some(function (cb) {
  7987. return cb._fromParent;
  7988. });
  7989. if (hasParentCbs) {
  7990. shouldPropagate = false;
  7991. }
  7992. var args = toArray(arguments, 1);
  7993. for (var i = 0, l = cbs.length; i < l; i++) {
  7994. var cb = cbs[i];
  7995. var res = cb.apply(this, args);
  7996. if (res === true && (!hasParentCbs || cb._fromParent)) {
  7997. shouldPropagate = true;
  7998. }
  7999. }
  8000. }
  8001. return shouldPropagate;
  8002. };
  8003. /**
  8004. * Recursively broadcast an event to all children instances.
  8005. *
  8006. * @param {String|Object} event
  8007. * @param {...*} additional arguments
  8008. */
  8009. Vue.prototype.$broadcast = function (event) {
  8010. var isSource = typeof event === 'string';
  8011. event = isSource ? event : event.name;
  8012. // if no child has registered for this event,
  8013. // then there's no need to broadcast.
  8014. if (!this._eventsCount[event]) return;
  8015. var children = this.$children;
  8016. var args = toArray(arguments);
  8017. if (isSource) {
  8018. // use object event to indicate non-source emit
  8019. // on children
  8020. args[0] = { name: event, source: this };
  8021. }
  8022. for (var i = 0, l = children.length; i < l; i++) {
  8023. var child = children[i];
  8024. var shouldPropagate = child.$emit.apply(child, args);
  8025. if (shouldPropagate) {
  8026. child.$broadcast.apply(child, args);
  8027. }
  8028. }
  8029. return this;
  8030. };
  8031. /**
  8032. * Recursively propagate an event up the parent chain.
  8033. *
  8034. * @param {String} event
  8035. * @param {...*} additional arguments
  8036. */
  8037. Vue.prototype.$dispatch = function (event) {
  8038. var shouldPropagate = this.$emit.apply(this, arguments);
  8039. if (!shouldPropagate) return;
  8040. var parent = this.$parent;
  8041. var args = toArray(arguments);
  8042. // use object event to indicate non-source emit
  8043. // on parents
  8044. args[0] = { name: event, source: this };
  8045. while (parent) {
  8046. shouldPropagate = parent.$emit.apply(parent, args);
  8047. parent = shouldPropagate ? parent.$parent : null;
  8048. }
  8049. return this;
  8050. };
  8051. /**
  8052. * Modify the listener counts on all parents.
  8053. * This bookkeeping allows $broadcast to return early when
  8054. * no child has listened to a certain event.
  8055. *
  8056. * @param {Vue} vm
  8057. * @param {String} event
  8058. * @param {Number} count
  8059. */
  8060. var hookRE = /^hook:/;
  8061. function modifyListenerCount(vm, event, count) {
  8062. var parent = vm.$parent;
  8063. // hooks do not get broadcasted so no need
  8064. // to do bookkeeping for them
  8065. if (!parent || !count || hookRE.test(event)) return;
  8066. while (parent) {
  8067. parent._eventsCount[event] = (parent._eventsCount[event] || 0) + count;
  8068. parent = parent.$parent;
  8069. }
  8070. }
  8071. }
  8072. function lifecycleAPI (Vue) {
  8073. /**
  8074. * Set instance target element and kick off the compilation
  8075. * process. The passed in `el` can be a selector string, an
  8076. * existing Element, or a DocumentFragment (for block
  8077. * instances).
  8078. *
  8079. * @param {Element|DocumentFragment|string} el
  8080. * @public
  8081. */
  8082. Vue.prototype.$mount = function (el) {
  8083. if (this._isCompiled) {
  8084. 'development' !== 'production' && warn('$mount() should be called only once.');
  8085. return;
  8086. }
  8087. el = query(el);
  8088. if (!el) {
  8089. el = document.createElement('div');
  8090. }
  8091. this._compile(el);
  8092. this._initDOMHooks();
  8093. if (inDoc(this.$el)) {
  8094. this._callHook('attached');
  8095. ready.call(this);
  8096. } else {
  8097. this.$once('hook:attached', ready);
  8098. }
  8099. return this;
  8100. };
  8101. /**
  8102. * Mark an instance as ready.
  8103. */
  8104. function ready() {
  8105. this._isAttached = true;
  8106. this._isReady = true;
  8107. this._callHook('ready');
  8108. }
  8109. /**
  8110. * Teardown the instance, simply delegate to the internal
  8111. * _destroy.
  8112. */
  8113. Vue.prototype.$destroy = function (remove, deferCleanup) {
  8114. this._destroy(remove, deferCleanup);
  8115. };
  8116. /**
  8117. * Partially compile a piece of DOM and return a
  8118. * decompile function.
  8119. *
  8120. * @param {Element|DocumentFragment} el
  8121. * @param {Vue} [host]
  8122. * @return {Function}
  8123. */
  8124. Vue.prototype.$compile = function (el, host, scope, frag) {
  8125. return compile(el, this.$options, true)(this, el, host, scope, frag);
  8126. };
  8127. }
  8128. /**
  8129. * The exposed Vue constructor.
  8130. *
  8131. * API conventions:
  8132. * - public API methods/properties are prefixed with `$`
  8133. * - internal methods/properties are prefixed with `_`
  8134. * - non-prefixed properties are assumed to be proxied user
  8135. * data.
  8136. *
  8137. * @constructor
  8138. * @param {Object} [options]
  8139. * @public
  8140. */
  8141. function Vue(options) {
  8142. this._init(options);
  8143. }
  8144. // install internals
  8145. initMixin(Vue);
  8146. stateMixin(Vue);
  8147. eventsMixin(Vue);
  8148. lifecycleMixin(Vue);
  8149. miscMixin(Vue);
  8150. // install APIs
  8151. globalAPI(Vue);
  8152. dataAPI(Vue);
  8153. domAPI(Vue);
  8154. eventsAPI(Vue);
  8155. lifecycleAPI(Vue);
  8156. var convertArray = vFor._postProcess;
  8157. /**
  8158. * Limit filter for arrays
  8159. *
  8160. * @param {Number} n
  8161. * @param {Number} offset (Decimal expected)
  8162. */
  8163. function limitBy(arr, n, offset) {
  8164. offset = offset ? parseInt(offset, 10) : 0;
  8165. n = toNumber(n);
  8166. return typeof n === 'number' ? arr.slice(offset, offset + n) : arr;
  8167. }
  8168. /**
  8169. * Filter filter for arrays
  8170. *
  8171. * @param {String} search
  8172. * @param {String} [delimiter]
  8173. * @param {String} ...dataKeys
  8174. */
  8175. function filterBy(arr, search, delimiter) {
  8176. arr = convertArray(arr);
  8177. if (search == null) {
  8178. return arr;
  8179. }
  8180. if (typeof search === 'function') {
  8181. return arr.filter(search);
  8182. }
  8183. // cast to lowercase string
  8184. search = ('' + search).toLowerCase();
  8185. // allow optional `in` delimiter
  8186. // because why not
  8187. var n = delimiter === 'in' ? 3 : 2;
  8188. // extract and flatten keys
  8189. var keys = toArray(arguments, n).reduce(function (prev, cur) {
  8190. return prev.concat(cur);
  8191. }, []);
  8192. var res = [];
  8193. var item, key, val, j;
  8194. for (var i = 0, l = arr.length; i < l; i++) {
  8195. item = arr[i];
  8196. val = item && item.$value || item;
  8197. j = keys.length;
  8198. if (j) {
  8199. while (j--) {
  8200. key = keys[j];
  8201. if (key === '$key' && contains(item.$key, search) || contains(getPath(val, key), search)) {
  8202. res.push(item);
  8203. break;
  8204. }
  8205. }
  8206. } else if (contains(item, search)) {
  8207. res.push(item);
  8208. }
  8209. }
  8210. return res;
  8211. }
  8212. /**
  8213. * Filter filter for arrays
  8214. *
  8215. * @param {String} sortKey
  8216. * @param {String} reverse
  8217. */
  8218. function orderBy(arr, sortKey, reverse) {
  8219. arr = convertArray(arr);
  8220. if (!sortKey) {
  8221. return arr;
  8222. }
  8223. var order = reverse && reverse < 0 ? -1 : 1;
  8224. // sort on a copy to avoid mutating original array
  8225. return arr.slice().sort(function (a, b) {
  8226. if (sortKey !== '$key') {
  8227. if (isObject(a) && '$value' in a) a = a.$value;
  8228. if (isObject(b) && '$value' in b) b = b.$value;
  8229. }
  8230. a = isObject(a) ? getPath(a, sortKey) : a;
  8231. b = isObject(b) ? getPath(b, sortKey) : b;
  8232. return a === b ? 0 : a > b ? order : -order;
  8233. });
  8234. }
  8235. /**
  8236. * String contain helper
  8237. *
  8238. * @param {*} val
  8239. * @param {String} search
  8240. */
  8241. function contains(val, search) {
  8242. var i;
  8243. if (isPlainObject(val)) {
  8244. var keys = Object.keys(val);
  8245. i = keys.length;
  8246. while (i--) {
  8247. if (contains(val[keys[i]], search)) {
  8248. return true;
  8249. }
  8250. }
  8251. } else if (isArray(val)) {
  8252. i = val.length;
  8253. while (i--) {
  8254. if (contains(val[i], search)) {
  8255. return true;
  8256. }
  8257. }
  8258. } else if (val != null) {
  8259. return val.toString().toLowerCase().indexOf(search) > -1;
  8260. }
  8261. }
  8262. var digitsRE = /(\d{3})(?=\d)/g;
  8263. // asset collections must be a plain object.
  8264. var filters = {
  8265. orderBy: orderBy,
  8266. filterBy: filterBy,
  8267. limitBy: limitBy,
  8268. /**
  8269. * Stringify value.
  8270. *
  8271. * @param {Number} indent
  8272. */
  8273. json: {
  8274. read: function read(value, indent) {
  8275. return typeof value === 'string' ? value : JSON.stringify(value, null, Number(indent) || 2);
  8276. },
  8277. write: function write(value) {
  8278. try {
  8279. return JSON.parse(value);
  8280. } catch (e) {
  8281. return value;
  8282. }
  8283. }
  8284. },
  8285. /**
  8286. * 'abc' => 'Abc'
  8287. */
  8288. capitalize: function capitalize(value) {
  8289. if (!value && value !== 0) return '';
  8290. value = value.toString();
  8291. return value.charAt(0).toUpperCase() + value.slice(1);
  8292. },
  8293. /**
  8294. * 'abc' => 'ABC'
  8295. */
  8296. uppercase: function uppercase(value) {
  8297. return value || value === 0 ? value.toString().toUpperCase() : '';
  8298. },
  8299. /**
  8300. * 'AbC' => 'abc'
  8301. */
  8302. lowercase: function lowercase(value) {
  8303. return value || value === 0 ? value.toString().toLowerCase() : '';
  8304. },
  8305. /**
  8306. * 12345 => $12,345.00
  8307. *
  8308. * @param {String} sign
  8309. */
  8310. currency: function currency(value, _currency) {
  8311. value = parseFloat(value);
  8312. if (!isFinite(value) || !value && value !== 0) return '';
  8313. _currency = _currency != null ? _currency : '$';
  8314. var stringified = Math.abs(value).toFixed(2);
  8315. var _int = stringified.slice(0, -3);
  8316. var i = _int.length % 3;
  8317. var head = i > 0 ? _int.slice(0, i) + (_int.length > 3 ? ',' : '') : '';
  8318. var _float = stringified.slice(-3);
  8319. var sign = value < 0 ? '-' : '';
  8320. return _currency + sign + head + _int.slice(i).replace(digitsRE, '$1,') + _float;
  8321. },
  8322. /**
  8323. * 'item' => 'items'
  8324. *
  8325. * @params
  8326. * an array of strings corresponding to
  8327. * the single, double, triple ... forms of the word to
  8328. * be pluralized. When the number to be pluralized
  8329. * exceeds the length of the args, it will use the last
  8330. * entry in the array.
  8331. *
  8332. * e.g. ['single', 'double', 'triple', 'multiple']
  8333. */
  8334. pluralize: function pluralize(value) {
  8335. var args = toArray(arguments, 1);
  8336. return args.length > 1 ? args[value % 10 - 1] || args[args.length - 1] : args[0] + (value === 1 ? '' : 's');
  8337. },
  8338. /**
  8339. * Debounce a handler function.
  8340. *
  8341. * @param {Function} handler
  8342. * @param {Number} delay = 300
  8343. * @return {Function}
  8344. */
  8345. debounce: function debounce(handler, delay) {
  8346. if (!handler) return;
  8347. if (!delay) {
  8348. delay = 300;
  8349. }
  8350. return _debounce(handler, delay);
  8351. }
  8352. };
  8353. var partial = {
  8354. priority: PARTIAL,
  8355. params: ['name'],
  8356. // watch changes to name for dynamic partials
  8357. paramWatchers: {
  8358. name: function name(value) {
  8359. vIf.remove.call(this);
  8360. if (value) {
  8361. this.insert(value);
  8362. }
  8363. }
  8364. },
  8365. bind: function bind() {
  8366. this.anchor = createAnchor('v-partial');
  8367. replace(this.el, this.anchor);
  8368. this.insert(this.params.name);
  8369. },
  8370. insert: function insert(id) {
  8371. var partial = resolveAsset(this.vm.$options, 'partials', id);
  8372. if ('development' !== 'production') {
  8373. assertAsset(partial, 'partial', id);
  8374. }
  8375. if (partial) {
  8376. this.factory = new FragmentFactory(this.vm, partial);
  8377. vIf.insert.call(this);
  8378. }
  8379. },
  8380. unbind: function unbind() {
  8381. if (this.frag) {
  8382. this.frag.destroy();
  8383. }
  8384. }
  8385. };
  8386. // This is the elementDirective that handles <content>
  8387. // transclusions. It relies on the raw content of an
  8388. // instance being stored as `$options._content` during
  8389. // the transclude phase.
  8390. // We are exporting two versions, one for named and one
  8391. // for unnamed, because the unnamed slots must be compiled
  8392. // AFTER all named slots have selected their content. So
  8393. // we need to give them different priorities in the compilation
  8394. // process. (See #1965)
  8395. var slot = {
  8396. priority: SLOT,
  8397. bind: function bind() {
  8398. var host = this.vm;
  8399. var raw = host.$options._content;
  8400. if (!raw) {
  8401. this.fallback();
  8402. return;
  8403. }
  8404. var context = host._context;
  8405. var slotName = this.params && this.params.name;
  8406. if (!slotName) {
  8407. // Default slot
  8408. this.tryCompile(extractFragment(raw.childNodes, raw, true), context, host);
  8409. } else {
  8410. // Named slot
  8411. var selector = '[slot="' + slotName + '"]';
  8412. var nodes = raw.querySelectorAll(selector);
  8413. if (nodes.length) {
  8414. this.tryCompile(extractFragment(nodes, raw), context, host);
  8415. } else {
  8416. this.fallback();
  8417. }
  8418. }
  8419. },
  8420. tryCompile: function tryCompile(content, context, host) {
  8421. if (content.hasChildNodes()) {
  8422. this.compile(content, context, host);
  8423. } else {
  8424. this.fallback();
  8425. }
  8426. },
  8427. compile: function compile(content, context, host) {
  8428. if (content && context) {
  8429. var scope = host ? host._scope : this._scope;
  8430. this.unlink = context.$compile(content, host, scope, this._frag);
  8431. }
  8432. if (content) {
  8433. replace(this.el, content);
  8434. } else {
  8435. remove(this.el);
  8436. }
  8437. },
  8438. fallback: function fallback() {
  8439. this.compile(extractContent(this.el, true), this.vm);
  8440. },
  8441. unbind: function unbind() {
  8442. if (this.unlink) {
  8443. this.unlink();
  8444. }
  8445. }
  8446. };
  8447. var namedSlot = extend(extend({}, slot), {
  8448. priority: slot.priority + 1,
  8449. params: ['name']
  8450. });
  8451. /**
  8452. * Extract qualified content nodes from a node list.
  8453. *
  8454. * @param {NodeList} nodes
  8455. * @param {Element} parent
  8456. * @param {Boolean} main
  8457. * @return {DocumentFragment}
  8458. */
  8459. function extractFragment(nodes, parent, main) {
  8460. var frag = document.createDocumentFragment();
  8461. for (var i = 0, l = nodes.length; i < l; i++) {
  8462. var node = nodes[i];
  8463. // if this is the main outlet, we want to skip all
  8464. // previously selected nodes;
  8465. // otherwise, we want to mark the node as selected.
  8466. // clone the node so the original raw content remains
  8467. // intact. this ensures proper re-compilation in cases
  8468. // where the outlet is inside a conditional block
  8469. if (main && !node.__v_selected) {
  8470. append(node);
  8471. } else if (!main && node.parentNode === parent) {
  8472. node.__v_selected = true;
  8473. append(node);
  8474. }
  8475. }
  8476. return frag;
  8477. function append(node) {
  8478. if (isTemplate(node) && !node.hasAttribute('v-if') && !node.hasAttribute('v-for')) {
  8479. node = parseTemplate(node);
  8480. }
  8481. node = cloneNode(node);
  8482. frag.appendChild(node);
  8483. }
  8484. }
  8485. var elementDirectives = {
  8486. slot: slot,
  8487. _namedSlot: namedSlot, // same as slot but with higher priority
  8488. partial: partial
  8489. };
  8490. Vue.version = '1.0.15';
  8491. /**
  8492. * Vue and every constructor that extends Vue has an
  8493. * associated options object, which can be accessed during
  8494. * compilation steps as `this.constructor.options`.
  8495. *
  8496. * These can be seen as the default options of every
  8497. * Vue instance.
  8498. */
  8499. Vue.options = {
  8500. directives: publicDirectives,
  8501. elementDirectives: elementDirectives,
  8502. filters: filters,
  8503. transitions: {},
  8504. components: {},
  8505. partials: {},
  8506. replace: true
  8507. };
  8508. // devtools global hook
  8509. /* istanbul ignore if */
  8510. if ('development' !== 'production' && inBrowser) {
  8511. if (window.__VUE_DEVTOOLS_GLOBAL_HOOK__) {
  8512. window.__VUE_DEVTOOLS_GLOBAL_HOOK__.emit('init', Vue);
  8513. } else if (/Chrome\/\d+/.test(navigator.userAgent)) {
  8514. console.log('Download the Vue Devtools for a better development experience:\n' + 'https://github.com/vuejs/vue-devtools');
  8515. }
  8516. }
  8517. return Vue;
  8518. }));