vuejs 1.0.31 → 1.0.33
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/helpers/syntax_helper.rb +7 -0
- data/lib/vuejs.rb +28 -1
- data/lib/vuejs/version.rb +1 -1
- data/vendor/assets/javascripts/vue-resource.js +1 -1
- data/vendor/assets/javascripts/vue-router2.js +558 -333
- data/vendor/assets/javascripts/vue-validator.js +1811 -11
- data/vendor/assets/javascripts/vue2.js +788 -578
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe041e1a6b68a6696d909a9fca031365eb253e3e
|
4
|
+
data.tar.gz: 6931c0cc73878f29662cbc1c0d4cafe5352740b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a561d056defcc05587efcbd7584745ad2e30be5b18faf38ac2b9ccc1ae765457f14f22b6affc8a78c8cd8b7b15a68f890517287dcbfa7376d7b3b84c202ed32
|
7
|
+
data.tar.gz: 5433cbe1231f2add28c136fa2bb3a3f449250c3004b1b42cc8e47f199c22e53a6eddad0e1029771b90e08a9f4d3a28433b3c56018e3a8be3c2dc29529c2aa01d
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
gem `vuejs` ships with the 1.x & 2.x latest [Vue.js + vue-router + vue-resource + vue-validator + vuex](http://vuejs.org/) and integrate with Rails' asset pipeline. Vue.js is created by Evan You and the vuejs team.
|
6
6
|
|
7
|
-
The current 2.x version is `Vue.js` (v2.1.
|
7
|
+
The current 2.x version is `Vue.js` (v2.1.4) + `vue-router` (v2.1.1) + `vue-validator` (v2.1.3) + `vuex` (v2.0.0).
|
8
8
|
> Note that Vue 2.x is not compatible with 1.x. vue-router 2.0 only works with Vue 2.x`
|
9
9
|
|
10
10
|
The current 1.x version is `Vue.js` (v1.0.28) + `vue-router` (v0.7.13) + `vue-resource` (v1.0.3)
|
data/lib/vuejs.rb
CHANGED
@@ -1,6 +1,33 @@
|
|
1
1
|
require "vuejs/version"
|
2
|
+
require "thor"
|
2
3
|
|
3
4
|
module Vuejs
|
4
|
-
class Engine <
|
5
|
+
class Engine < Rails::Engine
|
5
6
|
end
|
7
|
+
|
8
|
+
class Base < Thor
|
9
|
+
check_unknown_options!
|
10
|
+
package_name 'vuejs'
|
11
|
+
default_task :info
|
12
|
+
|
13
|
+
desc :info, ""
|
14
|
+
def info
|
15
|
+
puts "version: "
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
# class Base < Thor
|
24
|
+
# check_unknown_options!
|
25
|
+
# package_name 'vuejs'
|
26
|
+
# default_task :info
|
27
|
+
#
|
28
|
+
# desc :info
|
29
|
+
# def info
|
30
|
+
# puts "version: "
|
31
|
+
# end
|
32
|
+
# end
|
6
33
|
end
|
data/lib/vuejs/version.rb
CHANGED
@@ -1,13 +1,9 @@
|
|
1
1
|
/**
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
8
|
-
typeof define === 'function' && define.amd ? define(factory) :
|
9
|
-
(global.VueRouter = factory());
|
10
|
-
}(this, (function () { 'use strict';
|
2
|
+
* vue-router v2.1.1
|
3
|
+
* (c) 2016 Evan You
|
4
|
+
* @license MIT
|
5
|
+
*/
|
6
|
+
'use strict';
|
11
7
|
|
12
8
|
var View = {
|
13
9
|
name: 'router-view',
|
@@ -47,13 +43,23 @@ var View = {
|
|
47
43
|
return h()
|
48
44
|
}
|
49
45
|
|
46
|
+
var name = props.name
|
50
47
|
var component = inactive
|
51
|
-
? cache[
|
52
|
-
: (cache[
|
48
|
+
? cache[name]
|
49
|
+
: (cache[name] = matched.components[name])
|
53
50
|
|
54
51
|
if (!inactive) {
|
55
|
-
|
56
|
-
|
52
|
+
var hooks = data.hook || (data.hook = {})
|
53
|
+
hooks.init = function (vnode) {
|
54
|
+
matched.instances[name] = vnode.child
|
55
|
+
}
|
56
|
+
hooks.prepatch = function (oldVnode, vnode) {
|
57
|
+
matched.instances[name] = vnode.child
|
58
|
+
}
|
59
|
+
hooks.destroy = function (vnode) {
|
60
|
+
if (matched.instances[name] === vnode.child) {
|
61
|
+
matched.instances[name] = undefined
|
62
|
+
}
|
57
63
|
}
|
58
64
|
}
|
59
65
|
|
@@ -63,78 +69,6 @@ var View = {
|
|
63
69
|
|
64
70
|
/* */
|
65
71
|
|
66
|
-
function resolvePath (
|
67
|
-
relative,
|
68
|
-
base,
|
69
|
-
append
|
70
|
-
) {
|
71
|
-
if (relative.charAt(0) === '/') {
|
72
|
-
return relative
|
73
|
-
}
|
74
|
-
|
75
|
-
if (relative.charAt(0) === '?' || relative.charAt(0) === '#') {
|
76
|
-
return base + relative
|
77
|
-
}
|
78
|
-
|
79
|
-
var stack = base.split('/')
|
80
|
-
|
81
|
-
// remove trailing segment if:
|
82
|
-
// - not appending
|
83
|
-
// - appending to trailing slash (last segment is empty)
|
84
|
-
if (!append || !stack[stack.length - 1]) {
|
85
|
-
stack.pop()
|
86
|
-
}
|
87
|
-
|
88
|
-
// resolve relative path
|
89
|
-
var segments = relative.replace(/^\//, '').split('/')
|
90
|
-
for (var i = 0; i < segments.length; i++) {
|
91
|
-
var segment = segments[i]
|
92
|
-
if (segment === '.') {
|
93
|
-
continue
|
94
|
-
} else if (segment === '..') {
|
95
|
-
stack.pop()
|
96
|
-
} else {
|
97
|
-
stack.push(segment)
|
98
|
-
}
|
99
|
-
}
|
100
|
-
|
101
|
-
// ensure leading slash
|
102
|
-
if (stack[0] !== '') {
|
103
|
-
stack.unshift('')
|
104
|
-
}
|
105
|
-
|
106
|
-
return stack.join('/')
|
107
|
-
}
|
108
|
-
|
109
|
-
function parsePath (path) {
|
110
|
-
var hash = ''
|
111
|
-
var query = ''
|
112
|
-
|
113
|
-
var hashIndex = path.indexOf('#')
|
114
|
-
if (hashIndex >= 0) {
|
115
|
-
hash = path.slice(hashIndex)
|
116
|
-
path = path.slice(0, hashIndex)
|
117
|
-
}
|
118
|
-
|
119
|
-
var queryIndex = path.indexOf('?')
|
120
|
-
if (queryIndex >= 0) {
|
121
|
-
query = path.slice(queryIndex + 1)
|
122
|
-
path = path.slice(0, queryIndex)
|
123
|
-
}
|
124
|
-
|
125
|
-
return {
|
126
|
-
path: path,
|
127
|
-
query: query,
|
128
|
-
hash: hash
|
129
|
-
}
|
130
|
-
}
|
131
|
-
|
132
|
-
function cleanPath (path) {
|
133
|
-
return path.replace(/\/\//g, '/')
|
134
|
-
}
|
135
|
-
|
136
|
-
/* */
|
137
|
-
|
138
72
|
function assert (condition, message) {
|
139
73
|
if (!condition) {
|
140
74
|
throw new Error(("[vue-router] " + message))
|
@@ -163,7 +97,7 @@ function resolveQuery (
|
|
163
97
|
try {
|
164
98
|
parsedQuery = parseQuery(query)
|
165
99
|
} catch (e) {
|
166
|
-
warn(false, e.message)
|
100
|
+
process.env.NODE_ENV !== 'production' && warn(false, e.message)
|
167
101
|
parsedQuery = {}
|
168
102
|
}
|
169
103
|
for (var key in extraQuery) {
|
@@ -176,7 +110,7 @@ function resolveQuery (
|
|
176
110
|
}
|
177
111
|
|
178
112
|
function parseQuery (query) {
|
179
|
-
var res =
|
113
|
+
var res = {}
|
180
114
|
|
181
115
|
query = query.trim().replace(/^(\?|#|&)/, '')
|
182
116
|
|
@@ -204,7 +138,7 @@ function parseQuery (query) {
|
|
204
138
|
}
|
205
139
|
|
206
140
|
function stringifyQuery (obj) {
|
207
|
-
var res = obj ? Object.keys(obj).
|
141
|
+
var res = obj ? Object.keys(obj).map(function (key) {
|
208
142
|
var val = obj[key]
|
209
143
|
|
210
144
|
if (val === undefined) {
|
@@ -318,7 +252,7 @@ function isObjectEqual (a, b) {
|
|
318
252
|
|
319
253
|
function isIncludedRoute (current, target) {
|
320
254
|
return (
|
321
|
-
current.path.indexOf(target.path) === 0 &&
|
255
|
+
current.path.indexOf(target.path.replace(/\/$/, '')) === 0 &&
|
322
256
|
(!target.hash || current.hash === target.hash) &&
|
323
257
|
queryIncludes(current.query, target.query)
|
324
258
|
)
|
@@ -335,37 +269,6 @@ function queryIncludes (current, target) {
|
|
335
269
|
|
336
270
|
/* */
|
337
271
|
|
338
|
-
function normalizeLocation (
|
339
|
-
raw,
|
340
|
-
current,
|
341
|
-
append
|
342
|
-
) {
|
343
|
-
var next = typeof raw === 'string' ? { path: raw } : raw
|
344
|
-
if (next.name || next._normalized) {
|
345
|
-
return next
|
346
|
-
}
|
347
|
-
|
348
|
-
var parsedPath = parsePath(next.path || '')
|
349
|
-
var basePath = (current && current.path) || '/'
|
350
|
-
var path = parsedPath.path
|
351
|
-
? resolvePath(parsedPath.path, basePath, append)
|
352
|
-
: (current && current.path) || '/'
|
353
|
-
var query = resolveQuery(parsedPath.query, next.query)
|
354
|
-
var hash = next.hash || parsedPath.hash
|
355
|
-
if (hash && hash.charAt(0) !== '#') {
|
356
|
-
hash = "#" + hash
|
357
|
-
}
|
358
|
-
|
359
|
-
return {
|
360
|
-
_normalized: true,
|
361
|
-
path: path,
|
362
|
-
query: query,
|
363
|
-
hash: hash
|
364
|
-
}
|
365
|
-
}
|
366
|
-
|
367
|
-
/* */
|
368
|
-
|
369
272
|
// work around weird flow bug
|
370
273
|
var toTypes = [String, Object]
|
371
274
|
|
@@ -383,36 +286,45 @@ var Link = {
|
|
383
286
|
exact: Boolean,
|
384
287
|
append: Boolean,
|
385
288
|
replace: Boolean,
|
386
|
-
activeClass: String
|
289
|
+
activeClass: String,
|
290
|
+
event: {
|
291
|
+
type: [String, Array],
|
292
|
+
default: 'click'
|
293
|
+
}
|
387
294
|
},
|
388
295
|
render: function render (h) {
|
389
296
|
var this$1 = this;
|
390
297
|
|
391
298
|
var router = this.$router
|
392
299
|
var current = this.$route
|
393
|
-
var
|
394
|
-
var
|
395
|
-
var
|
396
|
-
var
|
397
|
-
var href = base ? cleanPath(base + fullPath) : fullPath
|
300
|
+
var ref = router.resolve(this.to, current, this.append);
|
301
|
+
var normalizedTo = ref.normalizedTo;
|
302
|
+
var resolved = ref.resolved;
|
303
|
+
var href = ref.href;
|
398
304
|
var classes = {}
|
399
305
|
var activeClass = this.activeClass || router.options.linkActiveClass || 'router-link-active'
|
400
|
-
var compareTarget =
|
306
|
+
var compareTarget = normalizedTo.path ? createRoute(null, normalizedTo) : resolved
|
401
307
|
classes[activeClass] = this.exact
|
402
308
|
? isSameRoute(current, compareTarget)
|
403
309
|
: isIncludedRoute(current, compareTarget)
|
404
310
|
|
405
|
-
var
|
406
|
-
|
407
|
-
e.preventDefault()
|
311
|
+
var handler = function (e) {
|
312
|
+
if (guardEvent(e)) {
|
408
313
|
if (this$1.replace) {
|
409
|
-
router.replace(
|
314
|
+
router.replace(normalizedTo)
|
410
315
|
} else {
|
411
|
-
router.push(
|
316
|
+
router.push(normalizedTo)
|
412
317
|
}
|
413
318
|
}
|
414
319
|
}
|
415
320
|
|
321
|
+
var on = { click: guardEvent }
|
322
|
+
if (Array.isArray(this.event)) {
|
323
|
+
this.event.forEach(function (e) { on[e] = handler })
|
324
|
+
} else {
|
325
|
+
on[this.event] = handler
|
326
|
+
}
|
327
|
+
|
416
328
|
var data = {
|
417
329
|
class: classes
|
418
330
|
}
|
@@ -424,10 +336,16 @@ var Link = {
|
|
424
336
|
// find the first <a> child and apply listener and href
|
425
337
|
var a = findAnchor(this.$slots.default)
|
426
338
|
if (a) {
|
427
|
-
|
339
|
+
// in case the <a> is a static node
|
340
|
+
a.isStatic = false
|
341
|
+
var extend = _Vue.util.extend
|
342
|
+
var aData = a.data = extend({}, a.data)
|
428
343
|
aData.on = on
|
429
|
-
var aAttrs =
|
344
|
+
var aAttrs = a.data.attrs = extend({}, a.data.attrs)
|
430
345
|
aAttrs.href = href
|
346
|
+
} else {
|
347
|
+
// doesn't have <a> child, apply listener to self
|
348
|
+
data.on = on
|
431
349
|
}
|
432
350
|
}
|
433
351
|
|
@@ -435,6 +353,25 @@ var Link = {
|
|
435
353
|
}
|
436
354
|
}
|
437
355
|
|
356
|
+
function guardEvent (e) {
|
357
|
+
// don't redirect with control keys
|
358
|
+
/* istanbul ignore if */
|
359
|
+
if (e.metaKey || e.ctrlKey || e.shiftKey) { return }
|
360
|
+
// don't redirect when preventDefault called
|
361
|
+
/* istanbul ignore if */
|
362
|
+
if (e.defaultPrevented) { return }
|
363
|
+
// don't redirect on right click
|
364
|
+
/* istanbul ignore if */
|
365
|
+
if (e.button !== 0) { return }
|
366
|
+
// don't redirect if `target="_blank"`
|
367
|
+
/* istanbul ignore if */
|
368
|
+
var target = e.target.getAttribute('target')
|
369
|
+
if (/\b_blank\b/i.test(target)) { return }
|
370
|
+
|
371
|
+
e.preventDefault()
|
372
|
+
return true
|
373
|
+
}
|
374
|
+
|
438
375
|
function findAnchor (children) {
|
439
376
|
if (children) {
|
440
377
|
var child
|
@@ -450,10 +387,14 @@ function findAnchor (children) {
|
|
450
387
|
}
|
451
388
|
}
|
452
389
|
|
390
|
+
var _Vue
|
391
|
+
|
453
392
|
function install (Vue) {
|
454
393
|
if (install.installed) { return }
|
455
394
|
install.installed = true
|
456
395
|
|
396
|
+
_Vue = Vue
|
397
|
+
|
457
398
|
Object.defineProperty(Vue.prototype, '$router', {
|
458
399
|
get: function get () { return this.$root._router }
|
459
400
|
})
|
@@ -474,6 +415,172 @@ function install (Vue) {
|
|
474
415
|
|
475
416
|
Vue.component('router-view', View)
|
476
417
|
Vue.component('router-link', Link)
|
418
|
+
|
419
|
+
var strats = Vue.config.optionMergeStrategies
|
420
|
+
// use the same hook merging strategy for route hooks
|
421
|
+
strats.beforeRouteEnter = strats.beforeRouteLeave = strats.created
|
422
|
+
}
|
423
|
+
|
424
|
+
/* */
|
425
|
+
|
426
|
+
function resolvePath (
|
427
|
+
relative,
|
428
|
+
base,
|
429
|
+
append
|
430
|
+
) {
|
431
|
+
if (relative.charAt(0) === '/') {
|
432
|
+
return relative
|
433
|
+
}
|
434
|
+
|
435
|
+
if (relative.charAt(0) === '?' || relative.charAt(0) === '#') {
|
436
|
+
return base + relative
|
437
|
+
}
|
438
|
+
|
439
|
+
var stack = base.split('/')
|
440
|
+
|
441
|
+
// remove trailing segment if:
|
442
|
+
// - not appending
|
443
|
+
// - appending to trailing slash (last segment is empty)
|
444
|
+
if (!append || !stack[stack.length - 1]) {
|
445
|
+
stack.pop()
|
446
|
+
}
|
447
|
+
|
448
|
+
// resolve relative path
|
449
|
+
var segments = relative.replace(/^\//, '').split('/')
|
450
|
+
for (var i = 0; i < segments.length; i++) {
|
451
|
+
var segment = segments[i]
|
452
|
+
if (segment === '.') {
|
453
|
+
continue
|
454
|
+
} else if (segment === '..') {
|
455
|
+
stack.pop()
|
456
|
+
} else {
|
457
|
+
stack.push(segment)
|
458
|
+
}
|
459
|
+
}
|
460
|
+
|
461
|
+
// ensure leading slash
|
462
|
+
if (stack[0] !== '') {
|
463
|
+
stack.unshift('')
|
464
|
+
}
|
465
|
+
|
466
|
+
return stack.join('/')
|
467
|
+
}
|
468
|
+
|
469
|
+
function parsePath (path) {
|
470
|
+
var hash = ''
|
471
|
+
var query = ''
|
472
|
+
|
473
|
+
var hashIndex = path.indexOf('#')
|
474
|
+
if (hashIndex >= 0) {
|
475
|
+
hash = path.slice(hashIndex)
|
476
|
+
path = path.slice(0, hashIndex)
|
477
|
+
}
|
478
|
+
|
479
|
+
var queryIndex = path.indexOf('?')
|
480
|
+
if (queryIndex >= 0) {
|
481
|
+
query = path.slice(queryIndex + 1)
|
482
|
+
path = path.slice(0, queryIndex)
|
483
|
+
}
|
484
|
+
|
485
|
+
return {
|
486
|
+
path: path,
|
487
|
+
query: query,
|
488
|
+
hash: hash
|
489
|
+
}
|
490
|
+
}
|
491
|
+
|
492
|
+
function cleanPath (path) {
|
493
|
+
return path.replace(/\/\//g, '/')
|
494
|
+
}
|
495
|
+
|
496
|
+
/* */
|
497
|
+
|
498
|
+
function createRouteMap (routes) {
|
499
|
+
var pathMap = Object.create(null)
|
500
|
+
var nameMap = Object.create(null)
|
501
|
+
|
502
|
+
routes.forEach(function (route) {
|
503
|
+
addRouteRecord(pathMap, nameMap, route)
|
504
|
+
})
|
505
|
+
|
506
|
+
return {
|
507
|
+
pathMap: pathMap,
|
508
|
+
nameMap: nameMap
|
509
|
+
}
|
510
|
+
}
|
511
|
+
|
512
|
+
function addRouteRecord (
|
513
|
+
pathMap,
|
514
|
+
nameMap,
|
515
|
+
route,
|
516
|
+
parent,
|
517
|
+
matchAs
|
518
|
+
) {
|
519
|
+
var path = route.path;
|
520
|
+
var name = route.name;
|
521
|
+
if (process.env.NODE_ENV !== 'production') {
|
522
|
+
assert(path != null, "\"path\" is required in a route configuration.")
|
523
|
+
assert(
|
524
|
+
typeof route.component !== 'string',
|
525
|
+
"route config \"component\" for path: " + (String(path || name)) + " cannot be a " +
|
526
|
+
"string id. Use an actual component instead."
|
527
|
+
)
|
528
|
+
}
|
529
|
+
|
530
|
+
var record = {
|
531
|
+
path: normalizePath(path, parent),
|
532
|
+
components: route.components || { default: route.component },
|
533
|
+
instances: {},
|
534
|
+
name: name,
|
535
|
+
parent: parent,
|
536
|
+
matchAs: matchAs,
|
537
|
+
redirect: route.redirect,
|
538
|
+
beforeEnter: route.beforeEnter,
|
539
|
+
meta: route.meta || {}
|
540
|
+
}
|
541
|
+
|
542
|
+
if (route.children) {
|
543
|
+
// Warn if route is named and has a default child route.
|
544
|
+
// If users navigate to this route by name, the default child will
|
545
|
+
// not be rendered (GH Issue #629)
|
546
|
+
if (process.env.NODE_ENV !== 'production') {
|
547
|
+
if (route.name && route.children.some(function (child) { return /^\/?$/.test(child.path); })) {
|
548
|
+
warn(false, ("Named Route '" + (route.name) + "' has a default child route.\n When navigating to this named route (:to=\"{name: '" + (route.name) + "'\"), the default child route will not be rendered.\n Remove the name from this route and use the name of the default child route for named links instead.")
|
549
|
+
)
|
550
|
+
}
|
551
|
+
}
|
552
|
+
route.children.forEach(function (child) {
|
553
|
+
addRouteRecord(pathMap, nameMap, child, record)
|
554
|
+
})
|
555
|
+
}
|
556
|
+
|
557
|
+
if (route.alias !== undefined) {
|
558
|
+
if (Array.isArray(route.alias)) {
|
559
|
+
route.alias.forEach(function (alias) {
|
560
|
+
addRouteRecord(pathMap, nameMap, { path: alias }, parent, record.path)
|
561
|
+
})
|
562
|
+
} else {
|
563
|
+
addRouteRecord(pathMap, nameMap, { path: route.alias }, parent, record.path)
|
564
|
+
}
|
565
|
+
}
|
566
|
+
|
567
|
+
if (!pathMap[record.path]) {
|
568
|
+
pathMap[record.path] = record
|
569
|
+
}
|
570
|
+
if (name) {
|
571
|
+
if (!nameMap[name]) {
|
572
|
+
nameMap[name] = record
|
573
|
+
} else if (process.env.NODE_ENV !== 'production') {
|
574
|
+
warn(false, ("Duplicate named routes definition: { name: \"" + name + "\", path: \"" + (record.path) + "\" }"))
|
575
|
+
}
|
576
|
+
}
|
577
|
+
}
|
578
|
+
|
579
|
+
function normalizePath (path, parent) {
|
580
|
+
path = path.replace(/\/$/, '')
|
581
|
+
if (path[0] === '/') { return path }
|
582
|
+
if (parent == null) { return path }
|
583
|
+
return cleanPath(((parent.path) + "/" + path))
|
477
584
|
}
|
478
585
|
|
479
586
|
var __moduleExports = Array.isArray || function (arr) {
|
@@ -512,14 +619,16 @@ var PATH_REGEXP = new RegExp([
|
|
512
619
|
/**
|
513
620
|
* Parse a string for the raw tokens.
|
514
621
|
*
|
515
|
-
* @param {string}
|
622
|
+
* @param {string} str
|
623
|
+
* @param {Object=} options
|
516
624
|
* @return {!Array}
|
517
625
|
*/
|
518
|
-
function parse (str) {
|
626
|
+
function parse (str, options) {
|
519
627
|
var tokens = []
|
520
628
|
var key = 0
|
521
629
|
var index = 0
|
522
630
|
var path = ''
|
631
|
+
var defaultDelimiter = options && options.delimiter || '/'
|
523
632
|
var res
|
524
633
|
|
525
634
|
while ((res = PATH_REGEXP.exec(str)) != null) {
|
@@ -552,8 +661,8 @@ function parse (str) {
|
|
552
661
|
var partial = prefix != null && next != null && next !== prefix
|
553
662
|
var repeat = modifier === '+' || modifier === '*'
|
554
663
|
var optional = modifier === '?' || modifier === '*'
|
555
|
-
var delimiter = res[2] ||
|
556
|
-
var pattern = capture || group
|
664
|
+
var delimiter = res[2] || defaultDelimiter
|
665
|
+
var pattern = capture || group
|
557
666
|
|
558
667
|
tokens.push({
|
559
668
|
name: name || key++,
|
@@ -563,7 +672,7 @@ function parse (str) {
|
|
563
672
|
repeat: repeat,
|
564
673
|
partial: partial,
|
565
674
|
asterisk: !!asterisk,
|
566
|
-
pattern: escapeGroup(pattern)
|
675
|
+
pattern: pattern ? escapeGroup(pattern) : (asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?')
|
567
676
|
})
|
568
677
|
}
|
569
678
|
|
@@ -584,10 +693,11 @@ function parse (str) {
|
|
584
693
|
* Compile a string to a template function for the path.
|
585
694
|
*
|
586
695
|
* @param {string} str
|
696
|
+
* @param {Object=} options
|
587
697
|
* @return {!function(Object=, Object=)}
|
588
698
|
*/
|
589
|
-
function compile (str) {
|
590
|
-
return tokensToFunction(parse(str))
|
699
|
+
function compile (str, options) {
|
700
|
+
return tokensToFunction(parse(str, options))
|
591
701
|
}
|
592
702
|
|
593
703
|
/**
|
@@ -798,34 +908,28 @@ function arrayToRegexp (path, keys, options) {
|
|
798
908
|
* @return {!RegExp}
|
799
909
|
*/
|
800
910
|
function stringToRegexp (path, keys, options) {
|
801
|
-
|
802
|
-
var re = tokensToRegExp(tokens, options)
|
803
|
-
|
804
|
-
// Attach keys back to the regexp.
|
805
|
-
for (var i = 0; i < tokens.length; i++) {
|
806
|
-
if (typeof tokens[i] !== 'string') {
|
807
|
-
keys.push(tokens[i])
|
808
|
-
}
|
809
|
-
}
|
810
|
-
|
811
|
-
return attachKeys(re, keys)
|
911
|
+
return tokensToRegExp(parse(path, options), keys, options)
|
812
912
|
}
|
813
913
|
|
814
914
|
/**
|
815
915
|
* Expose a function for taking tokens and returning a RegExp.
|
816
916
|
*
|
817
|
-
* @param {!Array}
|
818
|
-
* @param {Object=}
|
917
|
+
* @param {!Array} tokens
|
918
|
+
* @param {(Array|Object)=} keys
|
919
|
+
* @param {Object=} options
|
819
920
|
* @return {!RegExp}
|
820
921
|
*/
|
821
|
-
function tokensToRegExp (tokens, options) {
|
922
|
+
function tokensToRegExp (tokens, keys, options) {
|
923
|
+
if (!isarray(keys)) {
|
924
|
+
options = /** @type {!Object} */ (keys || options)
|
925
|
+
keys = []
|
926
|
+
}
|
927
|
+
|
822
928
|
options = options || {}
|
823
929
|
|
824
930
|
var strict = options.strict
|
825
931
|
var end = options.end !== false
|
826
932
|
var route = ''
|
827
|
-
var lastToken = tokens[tokens.length - 1]
|
828
|
-
var endsWithSlash = typeof lastToken === 'string' && /\/$/.test(lastToken)
|
829
933
|
|
830
934
|
// Iterate over the tokens and create our regexp string.
|
831
935
|
for (var i = 0; i < tokens.length; i++) {
|
@@ -837,6 +941,8 @@ function tokensToRegExp (tokens, options) {
|
|
837
941
|
var prefix = escapeString(token.prefix)
|
838
942
|
var capture = '(?:' + token.pattern + ')'
|
839
943
|
|
944
|
+
keys.push(token)
|
945
|
+
|
840
946
|
if (token.repeat) {
|
841
947
|
capture += '(?:' + prefix + capture + ')*'
|
842
948
|
}
|
@@ -855,12 +961,15 @@ function tokensToRegExp (tokens, options) {
|
|
855
961
|
}
|
856
962
|
}
|
857
963
|
|
964
|
+
var delimiter = escapeString(options.delimiter || '/')
|
965
|
+
var endsWithDelimiter = route.slice(-delimiter.length) === delimiter
|
966
|
+
|
858
967
|
// In non-strict mode we allow a slash at the end of match. If the path to
|
859
968
|
// match already ends with a slash, we remove it for consistency. The slash
|
860
969
|
// is valid at the end of a path match, not in the middle. This is important
|
861
970
|
// in non-ending mode, where "/test/" shouldn't match "/test//route".
|
862
971
|
if (!strict) {
|
863
|
-
route = (
|
972
|
+
route = (endsWithDelimiter ? route.slice(0, -delimiter.length) : route) + '(?:' + delimiter + '(?=$))?'
|
864
973
|
}
|
865
974
|
|
866
975
|
if (end) {
|
@@ -868,10 +977,10 @@ function tokensToRegExp (tokens, options) {
|
|
868
977
|
} else {
|
869
978
|
// In non-ending mode, we need the capturing groups to match as much as
|
870
979
|
// possible by using a positive lookahead to the end or next path segment.
|
871
|
-
route += strict &&
|
980
|
+
route += strict && endsWithDelimiter ? '' : '(?=' + delimiter + '|$)'
|
872
981
|
}
|
873
982
|
|
874
|
-
return new RegExp('^' + route, flags(options))
|
983
|
+
return attachKeys(new RegExp('^' + route, flags(options)), keys)
|
875
984
|
}
|
876
985
|
|
877
986
|
/**
|
@@ -887,15 +996,13 @@ function tokensToRegExp (tokens, options) {
|
|
887
996
|
* @return {!RegExp}
|
888
997
|
*/
|
889
998
|
function pathToRegexp (path, keys, options) {
|
890
|
-
keys = keys || []
|
891
|
-
|
892
999
|
if (!isarray(keys)) {
|
893
|
-
options = /** @type {!Object} */ (keys)
|
1000
|
+
options = /** @type {!Object} */ (keys || options)
|
894
1001
|
keys = []
|
895
|
-
} else if (!options) {
|
896
|
-
options = {}
|
897
1002
|
}
|
898
1003
|
|
1004
|
+
options = options || {}
|
1005
|
+
|
899
1006
|
if (path instanceof RegExp) {
|
900
1007
|
return regexpToRegexp(path, /** @type {!Array} */ (keys))
|
901
1008
|
}
|
@@ -914,80 +1021,102 @@ index.tokensToRegExp = tokensToRegExp_1;
|
|
914
1021
|
|
915
1022
|
/* */
|
916
1023
|
|
917
|
-
|
918
|
-
var pathMap = Object.create(null)
|
919
|
-
var nameMap = Object.create(null)
|
1024
|
+
var regexpCache = Object.create(null)
|
920
1025
|
|
921
|
-
|
922
|
-
|
923
|
-
|
1026
|
+
function getRouteRegex (path) {
|
1027
|
+
var hit = regexpCache[path]
|
1028
|
+
var keys, regexp
|
924
1029
|
|
925
|
-
|
926
|
-
|
927
|
-
|
1030
|
+
if (hit) {
|
1031
|
+
keys = hit.keys
|
1032
|
+
regexp = hit.regexp
|
1033
|
+
} else {
|
1034
|
+
keys = []
|
1035
|
+
regexp = index(path, keys)
|
1036
|
+
regexpCache[path] = { keys: keys, regexp: regexp }
|
928
1037
|
}
|
1038
|
+
|
1039
|
+
return { keys: keys, regexp: regexp }
|
929
1040
|
}
|
930
1041
|
|
931
|
-
|
932
|
-
pathMap,
|
933
|
-
nameMap,
|
934
|
-
route,
|
935
|
-
parent,
|
936
|
-
matchAs
|
937
|
-
) {
|
938
|
-
var path = route.path;
|
939
|
-
var name = route.name;
|
940
|
-
assert(path != null, "\"path\" is required in a route configuration.")
|
1042
|
+
var regexpCompileCache = Object.create(null)
|
941
1043
|
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
1044
|
+
function fillParams (
|
1045
|
+
path,
|
1046
|
+
params,
|
1047
|
+
routeMsg
|
1048
|
+
) {
|
1049
|
+
try {
|
1050
|
+
var filler =
|
1051
|
+
regexpCompileCache[path] ||
|
1052
|
+
(regexpCompileCache[path] = index.compile(path))
|
1053
|
+
return filler(params || {}, { pretty: true })
|
1054
|
+
} catch (e) {
|
1055
|
+
if (process.env.NODE_ENV !== 'production') {
|
1056
|
+
warn(false, ("missing param for " + routeMsg + ": " + (e.message)))
|
1057
|
+
}
|
1058
|
+
return ''
|
952
1059
|
}
|
1060
|
+
}
|
953
1061
|
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
1062
|
+
/* */
|
1063
|
+
|
1064
|
+
function normalizeLocation (
|
1065
|
+
raw,
|
1066
|
+
current,
|
1067
|
+
append
|
1068
|
+
) {
|
1069
|
+
var next = typeof raw === 'string' ? { path: raw } : raw
|
1070
|
+
// named target
|
1071
|
+
if (next.name || next._normalized) {
|
1072
|
+
return next
|
962
1073
|
}
|
963
1074
|
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
1075
|
+
// relative params
|
1076
|
+
if (!next.path && next.params && current) {
|
1077
|
+
next = assign({}, next)
|
1078
|
+
next._normalized = true
|
1079
|
+
var params = assign(assign({}, current.params), next.params)
|
1080
|
+
if (current.name) {
|
1081
|
+
next.name = current.name
|
1082
|
+
next.params = params
|
1083
|
+
} else if (current.matched) {
|
1084
|
+
var rawPath = current.matched[current.matched.length - 1].path
|
1085
|
+
next.path = fillParams(rawPath, params, ("path " + (current.path)))
|
1086
|
+
} else if (process.env.NODE_ENV !== 'production') {
|
1087
|
+
warn(false, "relative params navigation requires a current route.")
|
971
1088
|
}
|
1089
|
+
return next
|
972
1090
|
}
|
973
1091
|
|
974
|
-
|
975
|
-
|
1092
|
+
var parsedPath = parsePath(next.path || '')
|
1093
|
+
var basePath = (current && current.path) || '/'
|
1094
|
+
var path = parsedPath.path
|
1095
|
+
? resolvePath(parsedPath.path, basePath, append || next.append)
|
1096
|
+
: (current && current.path) || '/'
|
1097
|
+
var query = resolveQuery(parsedPath.query, next.query)
|
1098
|
+
var hash = next.hash || parsedPath.hash
|
1099
|
+
if (hash && hash.charAt(0) !== '#') {
|
1100
|
+
hash = "#" + hash
|
1101
|
+
}
|
1102
|
+
|
1103
|
+
return {
|
1104
|
+
_normalized: true,
|
1105
|
+
path: path,
|
1106
|
+
query: query,
|
1107
|
+
hash: hash
|
1108
|
+
}
|
976
1109
|
}
|
977
1110
|
|
978
|
-
function
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
return
|
1111
|
+
function assign (a, b) {
|
1112
|
+
for (var key in b) {
|
1113
|
+
a[key] = b[key]
|
1114
|
+
}
|
1115
|
+
return a
|
983
1116
|
}
|
984
1117
|
|
985
1118
|
/* */
|
986
1119
|
|
987
|
-
var regexpCache = Object.create(null)
|
988
|
-
|
989
|
-
var regexpCompileCache = Object.create(null)
|
990
|
-
|
991
1120
|
function createMatcher (routes) {
|
992
1121
|
var ref = createRouteMap(routes);
|
993
1122
|
var pathMap = ref.pathMap;
|
@@ -1003,6 +1132,22 @@ function createMatcher (routes) {
|
|
1003
1132
|
|
1004
1133
|
if (name) {
|
1005
1134
|
var record = nameMap[name]
|
1135
|
+
var paramNames = getRouteRegex(record.path).keys
|
1136
|
+
.filter(function (key) { return !key.optional; })
|
1137
|
+
.map(function (key) { return key.name; })
|
1138
|
+
|
1139
|
+
if (typeof location.params !== 'object') {
|
1140
|
+
location.params = {}
|
1141
|
+
}
|
1142
|
+
|
1143
|
+
if (currentRoute && typeof currentRoute.params === 'object') {
|
1144
|
+
for (var key in currentRoute.params) {
|
1145
|
+
if (!(key in location.params) && paramNames.indexOf(key) > -1) {
|
1146
|
+
location.params[key] = currentRoute.params[key]
|
1147
|
+
}
|
1148
|
+
}
|
1149
|
+
}
|
1150
|
+
|
1006
1151
|
if (record) {
|
1007
1152
|
location.path = fillParams(record.path, location.params, ("named route \"" + name + "\""))
|
1008
1153
|
return _createRoute(record, location, redirectedFrom)
|
@@ -1033,7 +1178,9 @@ function createMatcher (routes) {
|
|
1033
1178
|
}
|
1034
1179
|
|
1035
1180
|
if (!redirect || typeof redirect !== 'object') {
|
1036
|
-
|
1181
|
+
process.env.NODE_ENV !== 'production' && warn(
|
1182
|
+
false, ("invalid redirect option: " + (JSON.stringify(redirect)))
|
1183
|
+
)
|
1037
1184
|
return _createRoute(null, location)
|
1038
1185
|
}
|
1039
1186
|
|
@@ -1050,7 +1197,9 @@ function createMatcher (routes) {
|
|
1050
1197
|
if (name) {
|
1051
1198
|
// resolved named direct
|
1052
1199
|
var targetRecord = nameMap[name]
|
1053
|
-
|
1200
|
+
if (process.env.NODE_ENV !== 'production') {
|
1201
|
+
assert(targetRecord, ("redirect failed: named route \"" + name + "\" not found."))
|
1202
|
+
}
|
1054
1203
|
return match({
|
1055
1204
|
_normalized: true,
|
1056
1205
|
name: name,
|
@@ -1117,16 +1266,9 @@ function matchRoute (
|
|
1117
1266
|
params,
|
1118
1267
|
pathname
|
1119
1268
|
) {
|
1120
|
-
var
|
1121
|
-
var
|
1122
|
-
|
1123
|
-
keys = hit.keys
|
1124
|
-
regexp = hit.regexp
|
1125
|
-
} else {
|
1126
|
-
keys = []
|
1127
|
-
regexp = index(path, keys)
|
1128
|
-
regexpCache[path] = { keys: keys, regexp: regexp }
|
1129
|
-
}
|
1269
|
+
var ref = getRouteRegex(path);
|
1270
|
+
var regexp = ref.regexp;
|
1271
|
+
var keys = ref.keys;
|
1130
1272
|
var m = pathname.match(regexp)
|
1131
1273
|
|
1132
1274
|
if (!m) {
|
@@ -1144,22 +1286,6 @@ function matchRoute (
|
|
1144
1286
|
return true
|
1145
1287
|
}
|
1146
1288
|
|
1147
|
-
function fillParams (
|
1148
|
-
path,
|
1149
|
-
params,
|
1150
|
-
routeMsg
|
1151
|
-
) {
|
1152
|
-
try {
|
1153
|
-
var filler =
|
1154
|
-
regexpCompileCache[path] ||
|
1155
|
-
(regexpCompileCache[path] = index.compile(path))
|
1156
|
-
return filler(params || {}, { pretty: true })
|
1157
|
-
} catch (e) {
|
1158
|
-
assert(false, ("missing param for " + routeMsg + ": " + (e.message)))
|
1159
|
-
return ''
|
1160
|
-
}
|
1161
|
-
}
|
1162
|
-
|
1163
1289
|
function resolveRecordPath (path, record) {
|
1164
1290
|
return resolvePath(path, record.parent ? record.parent.path : '/', true)
|
1165
1291
|
}
|
@@ -1217,24 +1343,25 @@ History.prototype.listen = function listen (cb) {
|
|
1217
1343
|
this.cb = cb
|
1218
1344
|
};
|
1219
1345
|
|
1220
|
-
History.prototype.transitionTo = function transitionTo (location,
|
1346
|
+
History.prototype.transitionTo = function transitionTo (location, onComplete, onAbort) {
|
1221
1347
|
var this$1 = this;
|
1222
1348
|
|
1223
1349
|
var route = this.router.match(location, this.current)
|
1224
1350
|
this.confirmTransition(route, function () {
|
1225
1351
|
this$1.updateRoute(route)
|
1226
|
-
|
1352
|
+
onComplete && onComplete(route)
|
1227
1353
|
this$1.ensureURL()
|
1228
|
-
})
|
1354
|
+
}, onAbort)
|
1229
1355
|
};
|
1230
1356
|
|
1231
|
-
History.prototype.confirmTransition = function confirmTransition (route,
|
1357
|
+
History.prototype.confirmTransition = function confirmTransition (route, onComplete, onAbort) {
|
1232
1358
|
var this$1 = this;
|
1233
1359
|
|
1234
1360
|
var current = this.current
|
1361
|
+
var abort = function () { onAbort && onAbort() }
|
1235
1362
|
if (isSameRoute(route, current)) {
|
1236
1363
|
this.ensureURL()
|
1237
|
-
return
|
1364
|
+
return abort()
|
1238
1365
|
}
|
1239
1366
|
|
1240
1367
|
var ref = resolveQueue(this.current.matched, route.matched);
|
@@ -1254,14 +1381,18 @@ History.prototype.confirmTransition = function confirmTransition (route, cb) {
|
|
1254
1381
|
|
1255
1382
|
this.pending = route
|
1256
1383
|
var iterator = function (hook, next) {
|
1257
|
-
if (this$1.pending !== route) {
|
1384
|
+
if (this$1.pending !== route) {
|
1385
|
+
return abort()
|
1386
|
+
}
|
1258
1387
|
hook(route, current, function (to) {
|
1259
1388
|
if (to === false) {
|
1260
1389
|
// next(false) -> abort navigation, ensure current URL
|
1261
|
-
this$1.ensureURL()
|
1390
|
+
this$1.ensureURL(true)
|
1391
|
+
abort()
|
1262
1392
|
} else if (typeof to === 'string' || typeof to === 'object') {
|
1263
1393
|
// next('/') or next({ path: '/' }) -> redirect
|
1264
|
-
this$1.push(to)
|
1394
|
+
(typeof to === 'object' && to.replace) ? this$1.replace(to) : this$1.push(to)
|
1395
|
+
abort()
|
1265
1396
|
} else {
|
1266
1397
|
// confirm transition and pass on the value
|
1267
1398
|
next(to)
|
@@ -1271,12 +1402,18 @@ History.prototype.confirmTransition = function confirmTransition (route, cb) {
|
|
1271
1402
|
|
1272
1403
|
runQueue(queue, iterator, function () {
|
1273
1404
|
var postEnterCbs = []
|
1405
|
+
var enterGuards = extractEnterGuards(activated, postEnterCbs, function () {
|
1406
|
+
return this$1.current === route
|
1407
|
+
})
|
1274
1408
|
// wait until async components are resolved before
|
1275
1409
|
// extracting in-component enter guards
|
1276
|
-
runQueue(
|
1277
|
-
if (this$1.pending
|
1278
|
-
|
1279
|
-
|
1410
|
+
runQueue(enterGuards, iterator, function () {
|
1411
|
+
if (this$1.pending !== route) {
|
1412
|
+
return abort()
|
1413
|
+
}
|
1414
|
+
this$1.pending = null
|
1415
|
+
onComplete(route)
|
1416
|
+
if (this$1.router.app) {
|
1280
1417
|
this$1.router.app.$nextTick(function () {
|
1281
1418
|
postEnterCbs.forEach(function (cb) { return cb(); })
|
1282
1419
|
})
|
@@ -1329,33 +1466,89 @@ function resolveQueue (
|
|
1329
1466
|
}
|
1330
1467
|
}
|
1331
1468
|
|
1469
|
+
function extractGuard (
|
1470
|
+
def,
|
1471
|
+
key
|
1472
|
+
) {
|
1473
|
+
if (typeof def !== 'function') {
|
1474
|
+
// extend now so that global mixins are applied.
|
1475
|
+
def = _Vue.extend(def)
|
1476
|
+
}
|
1477
|
+
return def.options[key]
|
1478
|
+
}
|
1479
|
+
|
1332
1480
|
function extractLeaveGuards (matched) {
|
1333
|
-
return flatMapComponents(matched, function (def, instance) {
|
1334
|
-
var guard = def
|
1481
|
+
return flatten(flatMapComponents(matched, function (def, instance) {
|
1482
|
+
var guard = extractGuard(def, 'beforeRouteLeave')
|
1335
1483
|
if (guard) {
|
1336
|
-
return
|
1337
|
-
|
1338
|
-
|
1484
|
+
return Array.isArray(guard)
|
1485
|
+
? guard.map(function (guard) { return wrapLeaveGuard(guard, instance); })
|
1486
|
+
: wrapLeaveGuard(guard, instance)
|
1339
1487
|
}
|
1340
|
-
}).reverse()
|
1488
|
+
}).reverse())
|
1341
1489
|
}
|
1342
1490
|
|
1343
|
-
function
|
1344
|
-
|
1345
|
-
|
1491
|
+
function wrapLeaveGuard (
|
1492
|
+
guard,
|
1493
|
+
instance
|
1494
|
+
) {
|
1495
|
+
return function routeLeaveGuard () {
|
1496
|
+
return guard.apply(instance, arguments)
|
1497
|
+
}
|
1498
|
+
}
|
1499
|
+
|
1500
|
+
function extractEnterGuards (
|
1501
|
+
matched,
|
1502
|
+
cbs,
|
1503
|
+
isValid
|
1504
|
+
) {
|
1505
|
+
return flatten(flatMapComponents(matched, function (def, _, match, key) {
|
1506
|
+
var guard = extractGuard(def, 'beforeRouteEnter')
|
1346
1507
|
if (guard) {
|
1347
|
-
return
|
1348
|
-
return guard
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1508
|
+
return Array.isArray(guard)
|
1509
|
+
? guard.map(function (guard) { return wrapEnterGuard(guard, cbs, match, key, isValid); })
|
1510
|
+
: wrapEnterGuard(guard, cbs, match, key, isValid)
|
1511
|
+
}
|
1512
|
+
}))
|
1513
|
+
}
|
1514
|
+
|
1515
|
+
function wrapEnterGuard (
|
1516
|
+
guard,
|
1517
|
+
cbs,
|
1518
|
+
match,
|
1519
|
+
key,
|
1520
|
+
isValid
|
1521
|
+
) {
|
1522
|
+
return function routeEnterGuard (to, from, next) {
|
1523
|
+
return guard(to, from, function (cb) {
|
1524
|
+
next(cb)
|
1525
|
+
if (typeof cb === 'function') {
|
1526
|
+
cbs.push(function () {
|
1527
|
+
// #750
|
1528
|
+
// if a router-view is wrapped with an out-in transition,
|
1529
|
+
// the instance may not have been registered at this time.
|
1530
|
+
// we will need to poll for registration until current route
|
1531
|
+
// is no longer valid.
|
1532
|
+
poll(cb, match.instances, key, isValid)
|
1355
1533
|
})
|
1356
1534
|
}
|
1357
|
-
}
|
1358
|
-
}
|
1535
|
+
})
|
1536
|
+
}
|
1537
|
+
}
|
1538
|
+
|
1539
|
+
function poll (
|
1540
|
+
cb, // somehow flow cannot infer this is a function
|
1541
|
+
instances,
|
1542
|
+
key,
|
1543
|
+
isValid
|
1544
|
+
) {
|
1545
|
+
if (instances[key]) {
|
1546
|
+
cb(instances[key])
|
1547
|
+
} else if (isValid()) {
|
1548
|
+
setTimeout(function () {
|
1549
|
+
poll(cb, instances, key, isValid)
|
1550
|
+
}, 16)
|
1551
|
+
}
|
1359
1552
|
}
|
1360
1553
|
|
1361
1554
|
function resolveAsyncComponents (matched) {
|
@@ -1390,7 +1583,7 @@ function flatMapComponents (
|
|
1390
1583
|
matched,
|
1391
1584
|
fn
|
1392
1585
|
) {
|
1393
|
-
return
|
1586
|
+
return flatten(matched.map(function (m) {
|
1394
1587
|
return Object.keys(m.components).map(function (key) { return fn(
|
1395
1588
|
m.components[key],
|
1396
1589
|
m.instances[key],
|
@@ -1399,19 +1592,25 @@ function flatMapComponents (
|
|
1399
1592
|
}))
|
1400
1593
|
}
|
1401
1594
|
|
1595
|
+
function flatten (arr) {
|
1596
|
+
return Array.prototype.concat.apply([], arr)
|
1597
|
+
}
|
1598
|
+
|
1402
1599
|
/* */
|
1403
1600
|
|
1601
|
+
var positionStore = Object.create(null)
|
1602
|
+
|
1404
1603
|
function saveScrollPosition (key) {
|
1405
1604
|
if (!key) { return }
|
1406
|
-
|
1605
|
+
positionStore[key] = {
|
1407
1606
|
x: window.pageXOffset,
|
1408
1607
|
y: window.pageYOffset
|
1409
|
-
}
|
1608
|
+
}
|
1410
1609
|
}
|
1411
1610
|
|
1412
1611
|
function getScrollPosition (key) {
|
1413
1612
|
if (!key) { return }
|
1414
|
-
return
|
1613
|
+
return positionStore[key]
|
1415
1614
|
}
|
1416
1615
|
|
1417
1616
|
function getElementPosition (el) {
|
@@ -1450,8 +1649,6 @@ var HTML5History = (function (History) {
|
|
1450
1649
|
|
1451
1650
|
History.call(this, router, base)
|
1452
1651
|
|
1453
|
-
this.transitionTo(getLocation(this.base))
|
1454
|
-
|
1455
1652
|
var expectScroll = router.options.scrollBehavior
|
1456
1653
|
window.addEventListener('popstate', function (e) {
|
1457
1654
|
_key = e.state && e.state.key
|
@@ -1498,9 +1695,10 @@ var HTML5History = (function (History) {
|
|
1498
1695
|
})
|
1499
1696
|
};
|
1500
1697
|
|
1501
|
-
HTML5History.prototype.ensureURL = function ensureURL () {
|
1698
|
+
HTML5History.prototype.ensureURL = function ensureURL (push) {
|
1502
1699
|
if (getLocation(this.base) !== this.current.fullPath) {
|
1503
|
-
|
1700
|
+
var current = cleanPath(this.base + this.current.fullPath)
|
1701
|
+
push ? pushState(current) : replaceState(current)
|
1504
1702
|
}
|
1505
1703
|
};
|
1506
1704
|
|
@@ -1514,7 +1712,9 @@ var HTML5History = (function (History) {
|
|
1514
1712
|
if (!behavior) {
|
1515
1713
|
return
|
1516
1714
|
}
|
1517
|
-
|
1715
|
+
if (process.env.NODE_ENV !== 'production') {
|
1716
|
+
assert(typeof behavior === 'function', "scrollBehavior must be a function")
|
1717
|
+
}
|
1518
1718
|
|
1519
1719
|
// wait until re-render finishes before scrolling
|
1520
1720
|
router.app.$nextTick(function () {
|
@@ -1578,21 +1778,12 @@ function replaceState (url) {
|
|
1578
1778
|
|
1579
1779
|
var HashHistory = (function (History) {
|
1580
1780
|
function HashHistory (router, base, fallback) {
|
1581
|
-
var this$1 = this;
|
1582
|
-
|
1583
1781
|
History.call(this, router, base)
|
1584
|
-
|
1585
1782
|
// check history fallback deeplinking
|
1586
1783
|
if (fallback && this.checkFallback()) {
|
1587
1784
|
return
|
1588
1785
|
}
|
1589
|
-
|
1590
1786
|
ensureSlash()
|
1591
|
-
this.transitionTo(getHash())
|
1592
|
-
|
1593
|
-
window.addEventListener('hashchange', function () {
|
1594
|
-
this$1.onHashChange()
|
1595
|
-
})
|
1596
1787
|
}
|
1597
1788
|
|
1598
1789
|
if ( History ) HashHistory.__proto__ = History;
|
@@ -1619,13 +1810,13 @@ var HashHistory = (function (History) {
|
|
1619
1810
|
};
|
1620
1811
|
|
1621
1812
|
HashHistory.prototype.push = function push (location) {
|
1622
|
-
|
1813
|
+
this.transitionTo(location, function (route) {
|
1623
1814
|
pushHash(route.fullPath)
|
1624
1815
|
})
|
1625
1816
|
};
|
1626
1817
|
|
1627
1818
|
HashHistory.prototype.replace = function replace (location) {
|
1628
|
-
|
1819
|
+
this.transitionTo(location, function (route) {
|
1629
1820
|
replaceHash(route.fullPath)
|
1630
1821
|
})
|
1631
1822
|
};
|
@@ -1634,9 +1825,10 @@ var HashHistory = (function (History) {
|
|
1634
1825
|
window.history.go(n)
|
1635
1826
|
};
|
1636
1827
|
|
1637
|
-
HashHistory.prototype.ensureURL = function ensureURL () {
|
1638
|
-
|
1639
|
-
|
1828
|
+
HashHistory.prototype.ensureURL = function ensureURL (push) {
|
1829
|
+
var current = this.current.fullPath
|
1830
|
+
if (getHash() !== current) {
|
1831
|
+
push ? pushHash(current) : replaceHash(current)
|
1640
1832
|
}
|
1641
1833
|
};
|
1642
1834
|
|
@@ -1678,7 +1870,7 @@ var AbstractHistory = (function (History) {
|
|
1678
1870
|
function AbstractHistory (router) {
|
1679
1871
|
History.call(this, router)
|
1680
1872
|
this.stack = []
|
1681
|
-
this.index =
|
1873
|
+
this.index = -1
|
1682
1874
|
}
|
1683
1875
|
|
1684
1876
|
if ( History ) AbstractHistory.__proto__ = History;
|
@@ -1688,7 +1880,7 @@ var AbstractHistory = (function (History) {
|
|
1688
1880
|
AbstractHistory.prototype.push = function push (location) {
|
1689
1881
|
var this$1 = this;
|
1690
1882
|
|
1691
|
-
|
1883
|
+
this.transitionTo(location, function (route) {
|
1692
1884
|
this$1.stack = this$1.stack.slice(0, this$1.index + 1).concat(route)
|
1693
1885
|
this$1.index++
|
1694
1886
|
})
|
@@ -1697,7 +1889,7 @@ var AbstractHistory = (function (History) {
|
|
1697
1889
|
AbstractHistory.prototype.replace = function replace (location) {
|
1698
1890
|
var this$1 = this;
|
1699
1891
|
|
1700
|
-
|
1892
|
+
this.transitionTo(location, function (route) {
|
1701
1893
|
this$1.stack = this$1.stack.slice(0, this$1.index).concat(route)
|
1702
1894
|
})
|
1703
1895
|
};
|
@@ -1709,10 +1901,10 @@ var AbstractHistory = (function (History) {
|
|
1709
1901
|
if (targetIndex < 0 || targetIndex >= this.stack.length) {
|
1710
1902
|
return
|
1711
1903
|
}
|
1712
|
-
var
|
1713
|
-
this.confirmTransition(
|
1904
|
+
var route = this.stack[targetIndex]
|
1905
|
+
this.confirmTransition(route, function () {
|
1714
1906
|
this$1.index = targetIndex
|
1715
|
-
this$1.updateRoute(
|
1907
|
+
this$1.updateRoute(route)
|
1716
1908
|
})
|
1717
1909
|
};
|
1718
1910
|
|
@@ -1743,6 +1935,20 @@ var VueRouter = function VueRouter (options) {
|
|
1743
1935
|
mode = 'abstract'
|
1744
1936
|
}
|
1745
1937
|
this.mode = mode
|
1938
|
+
|
1939
|
+
switch (mode) {
|
1940
|
+
case 'history':
|
1941
|
+
this.history = new HTML5History(this, options.base)
|
1942
|
+
break
|
1943
|
+
case 'hash':
|
1944
|
+
this.history = new HashHistory(this, options.base, this.fallback)
|
1945
|
+
break
|
1946
|
+
case 'abstract':
|
1947
|
+
this.history = new AbstractHistory(this)
|
1948
|
+
break
|
1949
|
+
default:
|
1950
|
+
process.env.NODE_ENV !== 'production' && assert(false, ("invalid mode: " + mode))
|
1951
|
+
}
|
1746
1952
|
};
|
1747
1953
|
|
1748
1954
|
var prototypeAccessors = { currentRoute: {} };
|
@@ -1754,7 +1960,7 @@ prototypeAccessors.currentRoute.get = function () {
|
|
1754
1960
|
VueRouter.prototype.init = function init (app /* Vue component instance */) {
|
1755
1961
|
var this$1 = this;
|
1756
1962
|
|
1757
|
-
assert(
|
1963
|
+
process.env.NODE_ENV !== 'production' && assert(
|
1758
1964
|
install.installed,
|
1759
1965
|
"not installed. Make sure to call `Vue.use(VueRouter)` " +
|
1760
1966
|
"before creating root instance."
|
@@ -1762,25 +1968,20 @@ VueRouter.prototype.init = function init (app /* Vue component instance */) {
|
|
1762
1968
|
|
1763
1969
|
this.app = app
|
1764
1970
|
|
1765
|
-
var
|
1766
|
-
|
1767
|
-
|
1768
|
-
|
1769
|
-
|
1770
|
-
|
1771
|
-
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1775
|
-
|
1776
|
-
case 'abstract':
|
1777
|
-
this.history = new AbstractHistory(this)
|
1778
|
-
break
|
1779
|
-
default:
|
1780
|
-
assert(false, ("invalid mode: " + mode))
|
1971
|
+
var history = this.history
|
1972
|
+
|
1973
|
+
if (history instanceof HTML5History) {
|
1974
|
+
history.transitionTo(getLocation(history.base))
|
1975
|
+
} else if (history instanceof HashHistory) {
|
1976
|
+
var setupHashListener = function () {
|
1977
|
+
window.addEventListener('hashchange', function () {
|
1978
|
+
history.onHashChange()
|
1979
|
+
})
|
1980
|
+
}
|
1981
|
+
history.transitionTo(getHash(), setupHashListener, setupHashListener)
|
1781
1982
|
}
|
1782
1983
|
|
1783
|
-
|
1984
|
+
history.listen(function (route) {
|
1784
1985
|
this$1.app._route = route
|
1785
1986
|
})
|
1786
1987
|
};
|
@@ -1813,25 +2014,49 @@ VueRouter.prototype.forward = function forward () {
|
|
1813
2014
|
this.go(1)
|
1814
2015
|
};
|
1815
2016
|
|
1816
|
-
VueRouter.prototype.getMatchedComponents = function getMatchedComponents () {
|
1817
|
-
|
2017
|
+
VueRouter.prototype.getMatchedComponents = function getMatchedComponents (to) {
|
2018
|
+
var route = to
|
2019
|
+
? this.resolve(to).resolved
|
2020
|
+
: this.currentRoute
|
2021
|
+
if (!route) {
|
1818
2022
|
return []
|
1819
2023
|
}
|
1820
|
-
return [].concat.apply([],
|
2024
|
+
return [].concat.apply([], route.matched.map(function (m) {
|
1821
2025
|
return Object.keys(m.components).map(function (key) {
|
1822
2026
|
return m.components[key]
|
1823
2027
|
})
|
1824
2028
|
}))
|
1825
2029
|
};
|
1826
2030
|
|
2031
|
+
VueRouter.prototype.resolve = function resolve (
|
2032
|
+
to,
|
2033
|
+
current,
|
2034
|
+
append
|
2035
|
+
) {
|
2036
|
+
var normalizedTo = normalizeLocation(to, current || this.history.current, append)
|
2037
|
+
var resolved = this.match(normalizedTo, current)
|
2038
|
+
var fullPath = resolved.redirectedFrom || resolved.fullPath
|
2039
|
+
var base = this.history.base
|
2040
|
+
var href = createHref(base, fullPath, this.mode)
|
2041
|
+
return {
|
2042
|
+
normalizedTo: normalizedTo,
|
2043
|
+
resolved: resolved,
|
2044
|
+
href: href
|
2045
|
+
}
|
2046
|
+
};
|
2047
|
+
|
1827
2048
|
Object.defineProperties( VueRouter.prototype, prototypeAccessors );
|
1828
2049
|
|
1829
|
-
|
2050
|
+
function createHref (base, fullPath, mode) {
|
2051
|
+
var path = mode === 'hash' ? '#' + fullPath : fullPath
|
2052
|
+
return base ? cleanPath(base + '/' + path) : path
|
2053
|
+
}
|
2054
|
+
|
2055
|
+
VueRouter.install = install;
|
2056
|
+
VueRouter.version = 'v2.1.1'
|
1830
2057
|
|
1831
2058
|
if (inBrowser && window.Vue) {
|
1832
2059
|
window.Vue.use(VueRouter)
|
1833
2060
|
}
|
1834
2061
|
|
1835
|
-
|
1836
|
-
|
1837
|
-
})));
|
2062
|
+
module.exports = VueRouter;
|