vuejs 1.0.36 → 1.0.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,13 @@
1
1
  /**
2
- * vue-router v2.1.1
3
- * (c) 2016 Evan You
2
+ * vue-router v2.1.3
3
+ * (c) 2017 Evan You
4
4
  * @license MIT
5
5
  */
6
- 'use strict';
6
+ (function (global, factory) {
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';
7
11
 
8
12
  var View = {
9
13
  name: 'router-view',
@@ -22,11 +26,14 @@ var View = {
22
26
 
23
27
  data.routerView = true
24
28
 
29
+ var name = props.name
25
30
  var route = parent.$route
26
31
  var cache = parent._routerViewCache || (parent._routerViewCache = {})
32
+
33
+ // determine current view depth, also check to see if the tree
34
+ // has been toggled inactive but kept-alive.
27
35
  var depth = 0
28
36
  var inactive = false
29
-
30
37
  while (parent) {
31
38
  if (parent.$vnode && parent.$vnode.data.routerView) {
32
39
  depth++
@@ -36,30 +43,33 @@ var View = {
36
43
  }
37
44
  parent = parent.$parent
38
45
  }
39
-
40
46
  data.routerViewDepth = depth
47
+
48
+ // render previous view if the tree is inactive and kept-alive
49
+ if (inactive) {
50
+ return h(cache[name], data, children)
51
+ }
52
+
41
53
  var matched = route.matched[depth]
54
+ // render empty node if no matched route
42
55
  if (!matched) {
56
+ cache[name] = null
43
57
  return h()
44
58
  }
45
59
 
46
- var name = props.name
47
- var component = inactive
48
- ? cache[name]
49
- : (cache[name] = matched.components[name])
50
-
51
- if (!inactive) {
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
- }
60
+ var component = cache[name] = matched.components[name]
61
+
62
+ // inject instance registration hooks
63
+ var hooks = data.hook || (data.hook = {})
64
+ hooks.init = function (vnode) {
65
+ matched.instances[name] = vnode.child
66
+ }
67
+ hooks.prepatch = function (oldVnode, vnode) {
68
+ matched.instances[name] = vnode.child
69
+ }
70
+ hooks.destroy = function (vnode) {
71
+ if (matched.instances[name] === vnode.child) {
72
+ matched.instances[name] = undefined
63
73
  }
64
74
  }
65
75
 
@@ -97,7 +107,7 @@ function resolveQuery (
97
107
  try {
98
108
  parsedQuery = parseQuery(query)
99
109
  } catch (e) {
100
- process.env.NODE_ENV !== 'production' && warn(false, e.message)
110
+ "development" !== 'production' && warn(false, e.message)
101
111
  parsedQuery = {}
102
112
  }
103
113
  for (var key in extraQuery) {
@@ -171,6 +181,8 @@ function stringifyQuery (obj) {
171
181
 
172
182
  /* */
173
183
 
184
+ var trailingSlashRE = /\/?$/
185
+
174
186
  function createRoute (
175
187
  record,
176
188
  location,
@@ -214,7 +226,6 @@ function getFullPath (ref) {
214
226
  return (path || '/') + stringifyQuery(query) + hash
215
227
  }
216
228
 
217
- var trailingSlashRE = /\/$/
218
229
  function isSameRoute (a, b) {
219
230
  if (b === START) {
220
231
  return a === b
@@ -252,7 +263,9 @@ function isObjectEqual (a, b) {
252
263
 
253
264
  function isIncludedRoute (current, target) {
254
265
  return (
255
- current.path.indexOf(target.path.replace(/\/$/, '')) === 0 &&
266
+ current.path.replace(trailingSlashRE, '/').indexOf(
267
+ target.path.replace(trailingSlashRE, '/')
268
+ ) === 0 &&
256
269
  (!target.hash || current.hash === target.hash) &&
257
270
  queryIncludes(current.query, target.query)
258
271
  )
@@ -362,11 +375,13 @@ function guardEvent (e) {
362
375
  if (e.defaultPrevented) { return }
363
376
  // don't redirect on right click
364
377
  /* istanbul ignore if */
365
- if (e.button !== 0) { return }
378
+ if (e.button !== undefined && e.button !== 0) { return }
366
379
  // don't redirect if `target="_blank"`
367
380
  /* istanbul ignore if */
368
- var target = e.target.getAttribute('target')
369
- if (/\b_blank\b/i.test(target)) { return }
381
+ if (e.target && e.target.getAttribute) {
382
+ var target = e.target.getAttribute('target')
383
+ if (/\b_blank\b/i.test(target)) { return }
384
+ }
370
385
 
371
386
  e.preventDefault()
372
387
  return true
@@ -518,7 +533,7 @@ function addRouteRecord (
518
533
  ) {
519
534
  var path = route.path;
520
535
  var name = route.name;
521
- if (process.env.NODE_ENV !== 'production') {
536
+ if ("development" !== 'production') {
522
537
  assert(path != null, "\"path\" is required in a route configuration.")
523
538
  assert(
524
539
  typeof route.component !== 'string',
@@ -543,35 +558,57 @@ function addRouteRecord (
543
558
  // Warn if route is named and has a default child route.
544
559
  // If users navigate to this route by name, the default child will
545
560
  // not be rendered (GH Issue #629)
546
- if (process.env.NODE_ENV !== 'production') {
561
+ if ("development" !== 'production') {
547
562
  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.")
563
+ warn(
564
+ false,
565
+ "Named Route '" + (route.name) + "' has a default child route. " +
566
+ "When navigating to this named route (:to=\"{name: '" + (route.name) + "'\"), " +
567
+ "the default child route will not be rendered. Remove the name from " +
568
+ "this route and use the name of the default child route for named " +
569
+ "links instead."
549
570
  )
550
571
  }
551
572
  }
552
573
  route.children.forEach(function (child) {
553
- addRouteRecord(pathMap, nameMap, child, record)
574
+ var childMatchAs = matchAs
575
+ ? cleanPath((matchAs + "/" + (child.path)))
576
+ : undefined
577
+ addRouteRecord(pathMap, nameMap, child, record, childMatchAs)
554
578
  })
555
579
  }
556
580
 
557
581
  if (route.alias !== undefined) {
558
582
  if (Array.isArray(route.alias)) {
559
583
  route.alias.forEach(function (alias) {
560
- addRouteRecord(pathMap, nameMap, { path: alias }, parent, record.path)
584
+ var aliasRoute = {
585
+ path: alias,
586
+ children: route.children
587
+ }
588
+ addRouteRecord(pathMap, nameMap, aliasRoute, parent, record.path)
561
589
  })
562
590
  } else {
563
- addRouteRecord(pathMap, nameMap, { path: route.alias }, parent, record.path)
591
+ var aliasRoute = {
592
+ path: route.alias,
593
+ children: route.children
594
+ }
595
+ addRouteRecord(pathMap, nameMap, aliasRoute, parent, record.path)
564
596
  }
565
597
  }
566
598
 
567
599
  if (!pathMap[record.path]) {
568
600
  pathMap[record.path] = record
569
601
  }
602
+
570
603
  if (name) {
571
604
  if (!nameMap[name]) {
572
605
  nameMap[name] = record
573
- } else if (process.env.NODE_ENV !== 'production') {
574
- warn(false, ("Duplicate named routes definition: { name: \"" + name + "\", path: \"" + (record.path) + "\" }"))
606
+ } else if ("development" !== 'production') {
607
+ warn(
608
+ false,
609
+ "Duplicate named routes definition: " +
610
+ "{ name: \"" + name + "\", path: \"" + (record.path) + "\" }"
611
+ )
575
612
  }
576
613
  }
577
614
  }
@@ -1052,7 +1089,7 @@ function fillParams (
1052
1089
  (regexpCompileCache[path] = index.compile(path))
1053
1090
  return filler(params || {}, { pretty: true })
1054
1091
  } catch (e) {
1055
- if (process.env.NODE_ENV !== 'production') {
1092
+ if ("development" !== 'production') {
1056
1093
  warn(false, ("missing param for " + routeMsg + ": " + (e.message)))
1057
1094
  }
1058
1095
  return ''
@@ -1083,7 +1120,7 @@ function normalizeLocation (
1083
1120
  } else if (current.matched) {
1084
1121
  var rawPath = current.matched[current.matched.length - 1].path
1085
1122
  next.path = fillParams(rawPath, params, ("path " + (current.path)))
1086
- } else if (process.env.NODE_ENV !== 'production') {
1123
+ } else if ("development" !== 'production') {
1087
1124
  warn(false, "relative params navigation requires a current route.")
1088
1125
  }
1089
1126
  return next
@@ -1132,6 +1169,9 @@ function createMatcher (routes) {
1132
1169
 
1133
1170
  if (name) {
1134
1171
  var record = nameMap[name]
1172
+ if ("development" !== 'production') {
1173
+ warn(record, ("Route with name '" + name + "' does not exist"))
1174
+ }
1135
1175
  var paramNames = getRouteRegex(record.path).keys
1136
1176
  .filter(function (key) { return !key.optional; })
1137
1177
  .map(function (key) { return key.name; })
@@ -1178,7 +1218,7 @@ function createMatcher (routes) {
1178
1218
  }
1179
1219
 
1180
1220
  if (!redirect || typeof redirect !== 'object') {
1181
- process.env.NODE_ENV !== 'production' && warn(
1221
+ "development" !== 'production' && warn(
1182
1222
  false, ("invalid redirect option: " + (JSON.stringify(redirect)))
1183
1223
  )
1184
1224
  return _createRoute(null, location)
@@ -1197,7 +1237,7 @@ function createMatcher (routes) {
1197
1237
  if (name) {
1198
1238
  // resolved named direct
1199
1239
  var targetRecord = nameMap[name]
1200
- if (process.env.NODE_ENV !== 'production') {
1240
+ if ("development" !== 'production') {
1201
1241
  assert(targetRecord, ("redirect failed: named route \"" + name + "\" not found."))
1202
1242
  }
1203
1243
  return match({
@@ -1640,7 +1680,12 @@ function isNumber (v) {
1640
1680
  /* */
1641
1681
 
1642
1682
 
1643
- var genKey = function () { return String(Date.now()); }
1683
+ // use User Timing api (if present) for more accurate key precision
1684
+ var Time = inBrowser && window.performance && window.performance.now
1685
+ ? window.performance
1686
+ : Date
1687
+
1688
+ var genKey = function () { return String(Time.now()); }
1644
1689
  var _key = genKey()
1645
1690
 
1646
1691
  var HTML5History = (function (History) {
@@ -1712,7 +1757,7 @@ var HTML5History = (function (History) {
1712
1757
  if (!behavior) {
1713
1758
  return
1714
1759
  }
1715
- if (process.env.NODE_ENV !== 'production') {
1760
+ if ("development" !== 'production') {
1716
1761
  assert(typeof behavior === 'function', "scrollBehavior must be a function")
1717
1762
  }
1718
1763
 
@@ -1765,7 +1810,7 @@ function pushState (url, replace) {
1765
1810
  }
1766
1811
  saveScrollPosition(_key)
1767
1812
  } catch (e) {
1768
- window.location[replace ? 'assign' : 'replace'](url)
1813
+ window.location[replace ? 'replace' : 'assign'](url)
1769
1814
  }
1770
1815
  }
1771
1816
 
@@ -1867,8 +1912,8 @@ function replaceHash (path) {
1867
1912
 
1868
1913
 
1869
1914
  var AbstractHistory = (function (History) {
1870
- function AbstractHistory (router) {
1871
- History.call(this, router)
1915
+ function AbstractHistory (router, base) {
1916
+ History.call(this, router, base)
1872
1917
  this.stack = []
1873
1918
  this.index = -1
1874
1919
  }
@@ -1944,10 +1989,10 @@ var VueRouter = function VueRouter (options) {
1944
1989
  this.history = new HashHistory(this, options.base, this.fallback)
1945
1990
  break
1946
1991
  case 'abstract':
1947
- this.history = new AbstractHistory(this)
1992
+ this.history = new AbstractHistory(this, options.base)
1948
1993
  break
1949
1994
  default:
1950
- process.env.NODE_ENV !== 'production' && assert(false, ("invalid mode: " + mode))
1995
+ "development" !== 'production' && assert(false, ("invalid mode: " + mode))
1951
1996
  }
1952
1997
  };
1953
1998
 
@@ -1960,7 +2005,7 @@ prototypeAccessors.currentRoute.get = function () {
1960
2005
  VueRouter.prototype.init = function init (app /* Vue component instance */) {
1961
2006
  var this$1 = this;
1962
2007
 
1963
- process.env.NODE_ENV !== 'production' && assert(
2008
+ "development" !== 'production' && assert(
1964
2009
  install.installed,
1965
2010
  "not installed. Make sure to call `Vue.use(VueRouter)` " +
1966
2011
  "before creating root instance."
@@ -2052,11 +2097,13 @@ function createHref (base, fullPath, mode) {
2052
2097
  return base ? cleanPath(base + '/' + path) : path
2053
2098
  }
2054
2099
 
2055
- VueRouter.install = install;
2056
- VueRouter.version = 'v2.1.1'
2100
+ VueRouter.install = install
2101
+ VueRouter.version = '2.1.3'
2057
2102
 
2058
2103
  if (inBrowser && window.Vue) {
2059
2104
  window.Vue.use(VueRouter)
2060
2105
  }
2061
2106
 
2062
- module.exports = VueRouter;
2107
+ return VueRouter;
2108
+
2109
+ })));
@@ -1,2054 +1,910 @@
1
- /*!
2
- * vue-validator v3.0.0-alpha.2
3
- * (c) 2016 kazuya kawaguchi
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.VueValidator = factory());
10
- }(this, (function () { 'use strict';
11
-
12
- /* */
13
-
14
- function warn (msg, err) {
15
- if (window.console) {
16
- console.warn('[vue-validator] ' + msg);
17
- if (err) {
18
- console.warn(err.stack);
19
- }
20
- }
21
- }
22
-
23
- /* */
24
-
25
- // validator configrations
26
- var validator = {
27
- classes: {}
28
- };
29
-
30
- var Config = function (Vue) {
31
- // define Vue.config.validator configration
32
- // $FlowFixMe: https://github.com/facebook/flow/issues/285
33
- Object.defineProperty(Vue.config, 'validator', {
34
- enumerable: true,
35
- configurable: true,
36
- get: function () { return validator },
37
- set: function (val) { validator = val; }
38
- });
39
- };
40
-
41
- /* */
42
- /**
43
- * build-in validators
44
- */
45
-
46
- /**
47
- * required
48
- * This function validate whether the value has been filled out.
49
- */
50
- function required (val, arg) {
51
- var isRequired = arg === undefined ? true : arg;
52
- if (Array.isArray(val)) {
53
- if (val.length !== 0) {
54
- var valid = true;
55
- for (var i = 0, l = val.length; i < l; i++) {
56
- valid = required(val[i], isRequired);
57
- if ((isRequired && !valid) || (!isRequired && valid)) {
58
- break
59
- }
60
- }
61
- return valid
62
- } else {
63
- return !isRequired
64
- }
65
- } else if (typeof val === 'number' || typeof val === 'function') {
66
- return isRequired
67
- } else if (typeof val === 'boolean') {
68
- return val === isRequired
69
- } else if (typeof val === 'string') {
70
- return isRequired ? (val.length > 0) : (val.length <= 0)
71
- } else if (val !== null && typeof val === 'object') {
72
- return isRequired ? (Object.keys(val).length > 0) : (Object.keys(val).length <= 0)
73
- } else if (val === null || val === undefined) {
74
- return !isRequired
75
- } else {
76
- return !isRequired
77
- }
78
- }
79
-
80
1
  /**
81
- * pattern
82
- * This function validate whether the value matches the regex pattern
83
- */
84
- function pattern (val, pat) {
85
- if (typeof pat !== 'string') { return false }
86
-
87
- var match = pat.match(new RegExp('^/(.*?)/([gimy]*)$'));
88
- if (!match) { return false }
89
-
90
- return new RegExp(match[1], match[2]).test(val)
91
- }
92
-
93
- /**
94
- * minlength
95
- * This function validate whether the minimum length.
96
- */
97
- function minlength (val, min) {
98
- if (typeof val === 'string') {
99
- return isInteger(min, 10) && val.length >= parseInt(min, 10)
100
- } else if (Array.isArray(val)) {
101
- return val.length >= parseInt(min, 10)
102
- } else {
103
- return false
104
- }
105
- }
106
-
107
- /**
108
- * maxlength
109
- * This function validate whether the maximum length.
110
- */
111
- function maxlength (val, max) {
112
- if (typeof val === 'string') {
113
- return isInteger(max, 10) && val.length <= parseInt(max, 10)
114
- } else if (Array.isArray(val)) {
115
- return val.length <= parseInt(max, 10)
116
- } else {
117
- return false
118
- }
119
- }
120
-
121
- /**
122
- * min
123
- * This function validate whether the minimum value of the numberable value.
124
- */
125
- function min (val, arg) {
126
- return !isNaN(+(val)) && !isNaN(+(arg)) && (+(val) >= +(arg))
127
- }
128
-
129
- /**
130
- * max
131
- * This function validate whether the maximum value of the numberable value.
2
+ * vue-validator v1.4.4
3
+ * (c) 2014-2015 kazuya kawaguchi
4
+ * Released under the MIT License.
132
5
  */
133
- function max (val, arg) {
134
- return !isNaN(+(val)) && !isNaN(+(arg)) && (+(val) <= +(arg))
135
- }
136
6
 
137
- /**
138
- * isInteger
139
- * This function check whether the value of the string is integer.
140
- */
141
- function isInteger (val) {
142
- return /^(-?[1-9]\d*|0)$/.test(val)
143
- }
144
-
145
-
146
- var validators = Object.freeze({
147
- required: required,
148
- pattern: pattern,
149
- minlength: minlength,
150
- maxlength: maxlength,
151
- min: min,
152
- max: max
7
+ (function webpackUniversalModuleDefinition(root, factory) {
8
+ if(typeof exports === 'object' && typeof module === 'object')
9
+ module.exports = factory();
10
+ else if(typeof define === 'function' && define.amd)
11
+ define([], factory);
12
+ else if(typeof exports === 'object')
13
+ exports["vue-validator"] = factory();
14
+ else
15
+ root["vue-validator"] = factory();
16
+ })(this, function() {
17
+ return /******/ (function(modules) { // webpackBootstrap
18
+ /******/ // The module cache
19
+ /******/ var installedModules = {};
20
+
21
+ /******/ // The require function
22
+ /******/ function __webpack_require__(moduleId) {
23
+
24
+ /******/ // Check if module is in cache
25
+ /******/ if(installedModules[moduleId])
26
+ /******/ return installedModules[moduleId].exports;
27
+
28
+ /******/ // Create a new module (and put it into the cache)
29
+ /******/ var module = installedModules[moduleId] = {
30
+ /******/ exports: {},
31
+ /******/ id: moduleId,
32
+ /******/ loaded: false
33
+ /******/ };
34
+
35
+ /******/ // Execute the module function
36
+ /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
37
+
38
+ /******/ // Flag the module as loaded
39
+ /******/ module.loaded = true;
40
+
41
+ /******/ // Return the exports of the module
42
+ /******/ return module.exports;
43
+ /******/ }
44
+
45
+
46
+ /******/ // expose the modules object (__webpack_modules__)
47
+ /******/ __webpack_require__.m = modules;
48
+
49
+ /******/ // expose the module cache
50
+ /******/ __webpack_require__.c = installedModules;
51
+
52
+ /******/ // __webpack_public_path__
53
+ /******/ __webpack_require__.p = "";
54
+
55
+ /******/ // Load entry module and return exports
56
+ /******/ return __webpack_require__(0);
57
+ /******/ })
58
+ /************************************************************************/
59
+ /******/ ([
60
+ /* 0 */
61
+ /***/ function(module, exports, __webpack_require__) {
62
+
63
+ /**
64
+ * Import(s)
65
+ */
66
+
67
+ var validates = __webpack_require__(1)
68
+ var _ = __webpack_require__(2)
69
+
70
+
71
+ /**
72
+ * Export(s)
73
+ */
74
+
75
+ module.exports = install
76
+
77
+
78
+ /**
79
+ * Install plugin
80
+ */
81
+
82
+ function install (Vue, options) {
83
+ options = options || {}
84
+ var componentName = options.component = options.component || '$validator'
85
+ var directiveName = options.directive = options.directive || 'validate'
86
+ var path = Vue.parsers.path
87
+ var util = Vue.util
88
+
89
+
90
+ // custom validators merge strategy setting
91
+ Vue.config.optionMergeStrategies.validator = function (parent, child, vm, k) {
92
+ var validatorOptions = { validates: {}, namespace: {} }
93
+ if (!parent && !child) {
94
+ return validatorOptions
95
+ } else if (!parent && child) {
96
+ util.extend(validatorOptions['validates'], child['validates'])
97
+ util.extend(validatorOptions['namespace'], child['namespace'])
98
+ return validatorOptions
99
+ } else if (parent && !child) {
100
+ util.extend(validatorOptions['validates'], parent['validates'])
101
+ util.extend(validatorOptions['namespace'], parent['namespace'])
102
+ return validatorOptions
103
+ } else if (parent && child) {
104
+ var key
105
+ if ('validates' in parent) {
106
+ util.extend(validatorOptions['validates'], parent['validates'])
107
+ }
108
+ if ('namespace' in parent) {
109
+ util.extend(validatorOptions['namespace'], parent['namespace'])
110
+ }
111
+ if ('validates' in child) {
112
+ for (key in child['validates']) {
113
+ if ('validates' in parent && !parent['validates'].hasOwnProperty(key)) {
114
+ validatorOptions['validates'][key] = child['validates'][key]
115
+ }
116
+ }
117
+ }
118
+ if ('namespace' in child) {
119
+ for (key in child['namespace']) {
120
+ if ('namespace' in parent && !parent['namespace'].hasOwnProperty(key)) {
121
+ validatorOptions['namespace'][key] = child['namespace'][key]
122
+ }
123
+ }
124
+ }
125
+ return validatorOptions
126
+ } else {
127
+ _.warn('unexpected validator option merge strategy')
128
+ return validatorOptions
129
+ }
130
+ }
131
+
132
+
133
+ function getVal (obj, keypath) {
134
+ var ret = null
135
+ try {
136
+ ret = path.get(obj, keypath)
137
+ } catch (e) { }
138
+ return ret
139
+ }
140
+
141
+
142
+ Vue.directive(directiveName, {
143
+
144
+ priority: 1024,
145
+
146
+ bind: function () {
147
+ var vm = this.vm
148
+ var el = this.el
149
+ var $validator = vm[componentName]
150
+ var keypath = this._keypath = this._parseModelAttribute(el.getAttribute(Vue.config.prefix + 'model'))
151
+ var validator = this.arg ? this.arg : this.expression
152
+ var arg = this.arg ? this.expression : null
153
+
154
+ var customs = _.getCustomValidators(vm.$options)
155
+ if (!this._checkValidator(validator, validates, customs)) {
156
+ _.warn("specified invalid '"
157
+ + validator + "' validator at v-validate directive !! please check '"
158
+ + validator + "' validator !!")
159
+ this._ignore = true
160
+ return
161
+ }
162
+
163
+ if (!$validator) {
164
+ vm[componentName] = $validator = vm.$addChild(
165
+ {}, // null option
166
+ Vue.extend(__webpack_require__(3))
167
+ )
168
+ }
169
+
170
+ var value = el.getAttribute('value')
171
+ if (el.getAttribute('number') !== null) {
172
+ value = util.toNumber(value)
173
+ }
174
+ this._init = value
175
+
176
+ var validation = $validator._getValidationNamespace('validation')
177
+ var init = value || vm.$get(keypath)
178
+ var readyEvent = el.getAttribute('wait-for')
179
+
180
+ if (readyEvent && !$validator._isRegistedReadyEvent(keypath)) {
181
+ $validator._addReadyEvents(keypath, this._checkParam('wait-for'))
182
+ }
183
+
184
+ this._setupValidator($validator, keypath, validation, validator, el, arg, init)
185
+ },
186
+
187
+ update: function (val, old) {
188
+ if (this._ignore) { return }
189
+
190
+ var self = this
191
+ var vm = this.vm
192
+ var keypath = this._keypath
193
+ var validator = this.arg ? this.arg : this.expression
194
+ var $validator = vm[componentName]
195
+
196
+ $validator._changeValidator(keypath, validator, val)
197
+ if (!$validator._isRegistedReadyEvent(keypath)) { // normal
198
+ this._updateValidator($validator, validator, keypath)
199
+ } else { // wait-for
200
+ vm.$once($validator._getReadyEvents(keypath), function (val) {
201
+ $validator._setInitialValue(keypath, val)
202
+ vm.$set(keypath, val)
203
+ self._updateValidator($validator, validator, keypath)
204
+ })
205
+ }
206
+ },
207
+
208
+
209
+ unbind: function () {
210
+ if (this._ignore) { return }
211
+
212
+ var vm = this.vm
213
+ var keypath = this._keypath
214
+ var validator = this.arg ? this.arg : this.expression
215
+ var $validator = vm[componentName]
216
+
217
+ this._teardownValidator(vm, $validator, keypath, validator)
218
+ },
219
+
220
+ _parseModelAttribute: function (attr) {
221
+ var res = Vue.parsers.directive.parse(attr)
222
+ return res[0].arg ? res[0].arg : res[0].expression
223
+ },
224
+
225
+ _checkValidator: function (validator, validates, customs) {
226
+ var items = Object.keys(validates).concat(Object.keys(customs))
227
+ return items.some(function (item) {
228
+ return item === validator
229
+ })
230
+ },
231
+
232
+ _setupValidator: function ($validator, keypath, validation, validator, el, arg, init) {
233
+ var vm = this.vm
234
+
235
+ if (!getVal($validator[validation], keypath)) {
236
+ $validator._defineModelValidationScope(keypath)
237
+ if (el.tagName === 'INPUT' && el.type === 'radio') {
238
+ if (getVal(vm, keypath) === init) {
239
+ $validator._setInitialValue(keypath, init)
240
+ }
241
+ } else {
242
+ $validator._setInitialValue(keypath, init)
243
+ }
244
+ }
245
+
246
+ if (!getVal($validator[validation], [keypath, validator].join('.'))) {
247
+ $validator._defineValidatorToValidationScope(keypath, validator)
248
+ $validator._addValidator(keypath, validator, getVal(vm, arg) || arg)
249
+ }
250
+ },
251
+
252
+ _updateValidator: function ($validator, validator, keypath) {
253
+ var value = $validator.$get(keypath)
254
+ var el = this.el
255
+
256
+ if (this._init) {
257
+ value = this._init
258
+ delete this._init
259
+ }
260
+
261
+ if (el.tagName === 'INPUT' && el.type === 'radio') {
262
+ if (value === $validator.$get(keypath)) {
263
+ $validator._updateDirtyProperty(keypath, value)
264
+ }
265
+ } else {
266
+ $validator._updateDirtyProperty(keypath, value)
267
+ }
268
+
269
+ $validator._doValidate(keypath, validator, $validator.$get(keypath))
270
+ },
271
+
272
+ _teardownValidator: function (vm, $validator, keypath, validator) {
273
+ $validator._undefineValidatorToValidationScope(keypath, validator)
274
+ $validator._undefineModelValidationScope(keypath, validator)
275
+ }
276
+ })
277
+ }
278
+
279
+
280
+ /***/ },
281
+ /* 1 */
282
+ /***/ function(module, exports) {
283
+
284
+ /**
285
+ * Fundamental validate functions
286
+ */
287
+
288
+
289
+ /**
290
+ * required
291
+ *
292
+ * This function validate whether the value has been filled out.
293
+ *
294
+ * @param val
295
+ * @return {Boolean}
296
+ */
297
+
298
+ function required (val) {
299
+ if (Array.isArray(val)) {
300
+ return val.length > 0
301
+ } else if (typeof val === 'number') {
302
+ return true
303
+ } else if ((val !== null) && (typeof val === 'object')) {
304
+ return Object.keys(val).length > 0
305
+ } else {
306
+ return !val
307
+ ? false
308
+ : true
309
+ }
310
+ }
311
+
312
+
313
+ /**
314
+ * pattern
315
+ *
316
+ * This function validate whether the value matches the regex pattern
317
+ *
318
+ * @param val
319
+ * @param {String} pat
320
+ * @return {Boolean}
321
+ */
322
+
323
+ function pattern (val, pat) {
324
+ if (typeof pat !== 'string') { return false }
325
+
326
+ var match = pat.match(new RegExp('^/(.*?)/([gimy]*)$'))
327
+ if (!match) { return false }
328
+
329
+ return new RegExp(match[1], match[2]).test(val)
330
+ }
331
+
332
+
333
+ /**
334
+ * minLength
335
+ *
336
+ * This function validate whether the minimum length of the string.
337
+ *
338
+ * @param {String} val
339
+ * @param {String|Number} min
340
+ * @return {Boolean}
341
+ */
342
+
343
+ function minLength (val, min) {
344
+ return typeof val === 'string' &&
345
+ isInteger(min, 10) &&
346
+ val.length >= parseInt(min, 10)
347
+ }
348
+
349
+
350
+ /**
351
+ * maxLength
352
+ *
353
+ * This function validate whether the maximum length of the string.
354
+ *
355
+ * @param {String} val
356
+ * @param {String|Number} max
357
+ * @return {Boolean}
358
+ */
359
+
360
+ function maxLength (val, max) {
361
+ return typeof val === 'string' &&
362
+ isInteger(max, 10) &&
363
+ val.length <= parseInt(max, 10)
364
+ }
365
+
366
+
367
+ /**
368
+ * min
369
+ *
370
+ * This function validate whether the minimum value of the numberable value.
371
+ *
372
+ * @param {*} val
373
+ * @param {*} arg minimum
374
+ * @return {Boolean}
375
+ */
376
+
377
+ function min (val, arg) {
378
+ return !isNaN(+(val)) && !isNaN(+(arg)) && (+(val) >= +(arg))
379
+ }
380
+
381
+
382
+ /**
383
+ * max
384
+ *
385
+ * This function validate whether the maximum value of the numberable value.
386
+ *
387
+ * @param {*} val
388
+ * @param {*} arg maximum
389
+ * @return {Boolean}
390
+ */
391
+
392
+ function max (val, arg) {
393
+ return !isNaN(+(val)) && !isNaN(+(arg)) && (+(val) <= +(arg))
394
+ }
395
+
396
+
397
+ /**
398
+ * isInteger
399
+ *
400
+ * This function check whether the value of the string is integer.
401
+ *
402
+ * @param {String} val
403
+ * @return {Boolean}
404
+ * @private
405
+ */
406
+
407
+ function isInteger (val) {
408
+ return /^(-?[1-9]\d*|0)$/.test(val)
409
+ }
410
+
411
+
412
+ /**
413
+ * export(s)
414
+ */
415
+ module.exports = {
416
+ required: required,
417
+ pattern: pattern,
418
+ minLength: minLength,
419
+ maxLength: maxLength,
420
+ min: min,
421
+ max: max
422
+ }
423
+
424
+
425
+ /***/ },
426
+ /* 2 */
427
+ /***/ function(module, exports) {
428
+
429
+ /**
430
+ * Utilties
431
+ */
432
+
433
+
434
+ /**
435
+ * warn
436
+ *
437
+ * @param {String} msg
438
+ * @param {Error} [err]
439
+ *
440
+ */
441
+
442
+ exports.warn = function (msg, err) {
443
+ if (window.console) {
444
+ console.warn('[vue-validator] ' + msg)
445
+ if (err) {
446
+ console.warn(err.stack)
447
+ }
448
+ }
449
+ }
450
+
451
+ /**
452
+ * Get target validatable object
453
+ *
454
+ * @param {Object} validation
455
+ * @param {String} keypath
456
+ * @return {Object} validatable object
457
+ */
458
+
459
+ exports.getTarget = function (validation, keypath) {
460
+ var last = validation
461
+ var keys = keypath.split('.')
462
+ var key, obj
463
+ for (var i = 0; i < keys.length; i++) {
464
+ key = keys[i]
465
+ obj = last[key]
466
+ last = obj
467
+ if (!last) {
468
+ break
469
+ }
470
+ }
471
+ return last
472
+ }
473
+
474
+ /**
475
+ * Get custom validators
476
+ *
477
+ * @param {Object} options
478
+ * @return {Object}
479
+ */
480
+
481
+ exports.getCustomValidators = function (options) {
482
+ var opts = options
483
+ var validators = {}
484
+ var key
485
+ var context
486
+ do {
487
+ if (opts['validator'] && opts['validator']['validates']) {
488
+ for (key in opts['validator']['validates']) {
489
+ if (!validators.hasOwnProperty(key)) {
490
+ validators[key] = opts['validator']['validates'][key]
491
+ }
492
+ }
493
+ }
494
+ context = opts._context || opts._parent
495
+ if (context) {
496
+ opts = context.$options
497
+ }
498
+ } while (context || opts._parent)
499
+ return validators
500
+ }
501
+
502
+
503
+ /***/ },
504
+ /* 3 */
505
+ /***/ function(module, exports, __webpack_require__) {
506
+
507
+ /**
508
+ * Import(s)
509
+ */
510
+
511
+ var validates = __webpack_require__(1)
512
+ var _ = __webpack_require__(2)
513
+
514
+
515
+ /**
516
+ * Export(s)
517
+ */
518
+
519
+
520
+ /**
521
+ * `v-validator` component with mixin
522
+ */
523
+
524
+ module.exports = {
525
+ inherit: true,
526
+
527
+ created: function () {
528
+ this._initValidationVariables()
529
+ this._initOptions()
530
+ this._mixinCustomValidates()
531
+ this._defineProperties()
532
+ this._defineValidationScope()
533
+ },
534
+
535
+ methods: {
536
+ _getValidationNamespace: function (key) {
537
+ return this._namespace[key]
538
+ },
539
+
540
+ _initValidationVariables: function () {
541
+ this._validators = {}
542
+ this._validates = {}
543
+ this._initialValues = {}
544
+ for (var key in validates) {
545
+ this._validates[key] = validates[key]
546
+ }
547
+ this._validatorWatchers = {}
548
+ this._readyEvents = {}
549
+ },
550
+
551
+ _initOptions: function () {
552
+ this._namespace = getCustomNamespace(this.$options)
553
+ this._namespace.validation = this._namespace.validation || 'validation'
554
+ this._namespace.valid = this._namespace.valid || 'valid'
555
+ this._namespace.invalid = this._namespace.invalid || 'invalid'
556
+ this._namespace.dirty = this._namespace.dirty || 'dirty'
557
+ },
558
+
559
+ _mixinCustomValidates: function () {
560
+ var customs = _.getCustomValidators(this.$options)
561
+ for (var key in customs) {
562
+ this._validates[key] = customs[key]
563
+ }
564
+ },
565
+
566
+ _defineValidProperty: function (target, getter) {
567
+ Object.defineProperty(target, this._getValidationNamespace('valid'), {
568
+ enumerable: true,
569
+ configurable: true,
570
+ get: getter
571
+ })
572
+ },
573
+
574
+ _undefineValidProperty: function (target) {
575
+ delete target[this._getValidationNamespace('valid')]
576
+ },
577
+
578
+ _defineInvalidProperty: function (target) {
579
+ var self = this
580
+ Object.defineProperty(target, this._getValidationNamespace('invalid'), {
581
+ enumerable: true,
582
+ configurable: true,
583
+ get: function () {
584
+ return !target[self._getValidationNamespace('valid')]
585
+ }
586
+ })
587
+ },
588
+
589
+ _undefineInvalidProperty: function (target) {
590
+ delete target[this._getValidationNamespace('invalid')]
591
+ },
592
+
593
+ _defineDirtyProperty: function (target, getter) {
594
+ Object.defineProperty(target, this._getValidationNamespace('dirty'), {
595
+ enumerable: true,
596
+ configurable: true,
597
+ get: getter
598
+ })
599
+ },
600
+
601
+ _undefineDirtyProperty: function (target) {
602
+ delete target[this._getValidationNamespace('dirty')]
603
+ },
604
+
605
+ _defineProperties: function () {
606
+ var self = this
607
+
608
+ var walk = function (obj, propName, namespaces) {
609
+ var ret = false
610
+ var keys = Object.keys(obj)
611
+ var i = keys.length
612
+ var key, last
613
+ while (i--) {
614
+ key = keys[i]
615
+ last = obj[key]
616
+ if (!(key in namespaces) && typeof last === 'object') {
617
+ ret = walk(last, propName, namespaces)
618
+ if ((propName === self._getValidationNamespace('valid') && !ret) ||
619
+ (propName === self._getValidationNamespace('dirty') && ret)) {
620
+ break
621
+ }
622
+ } else if (key === propName && typeof last !== 'object') {
623
+ ret = last
624
+ if ((key === self._getValidationNamespace('valid') && !ret) ||
625
+ (key === self._getValidationNamespace('dirty') && ret)) {
626
+ break
627
+ }
628
+ }
629
+ }
630
+ return ret
631
+ }
632
+
633
+ this._defineValidProperty(this.$parent, function () {
634
+ var validationName = self._getValidationNamespace('validation')
635
+ var validName = self._getValidationNamespace('valid')
636
+ return walk(this[validationName], validName, self._namespace)
637
+ })
638
+
639
+ this._defineInvalidProperty(this.$parent)
640
+
641
+ this._defineDirtyProperty(this.$parent, function () {
642
+ var validationName = self._getValidationNamespace('validation')
643
+ var dirtyName = self._getValidationNamespace('dirty')
644
+ return walk(this[validationName], dirtyName, self._namespace)
645
+ })
646
+ },
647
+
648
+ _undefineProperties: function () {
649
+ this._undefineDirtyProperty(this.$parent)
650
+ this._undefineInvalidProperty(this.$parent)
651
+ this._undefineValidProperty(this.$parent)
652
+ },
653
+
654
+ _defineValidationScope: function () {
655
+ this.$parent.$add(this._getValidationNamespace('validation'), {})
656
+ },
657
+
658
+ _undefineValidationScope: function () {
659
+ var validationName = this._getValidationNamespace('validation')
660
+ this.$parent.$delete(validationName)
661
+ },
662
+
663
+ _defineModelValidationScope: function (keypath) {
664
+ var self = this
665
+ var validationName = this._getValidationNamespace('validation')
666
+ var dirtyName = this._getValidationNamespace('dirty')
667
+
668
+ var keys = keypath.split('.')
669
+ var last = this[validationName]
670
+ var obj, key
671
+ for (var i = 0; i < keys.length; i++) {
672
+ key = keys[i]
673
+ obj = last[key]
674
+ if (!obj) {
675
+ obj = {}
676
+ last.$add(key, obj)
677
+ }
678
+ last = obj
679
+ }
680
+ last.$add(dirtyName, false)
681
+
682
+ this._defineValidProperty(last, function () {
683
+ var ret = true
684
+ var validators = self._validators[keypath]
685
+ var i = validators.length
686
+ var validator
687
+ while (i--) {
688
+ validator = validators[i]
689
+ if (last[validator.name]) {
690
+ ret = false
691
+ break
692
+ }
693
+ }
694
+ return ret
695
+ })
696
+ this._defineInvalidProperty(last)
697
+
698
+ this._validators[keypath] = []
699
+
700
+ this._watchModel(keypath, function (val, old) {
701
+ self._updateDirtyProperty(keypath, val)
702
+ self._validators[keypath].forEach(function (validator) {
703
+ self._doValidate(keypath, validator.name, val)
704
+ })
705
+ })
706
+ },
707
+
708
+ _undefineModelValidationScope: function (keypath, validator) {
709
+ if (this.$parent) {
710
+ var targetPath = [this._getValidationNamespace('validation'), keypath].join('.')
711
+ var target = this.$parent.$get(targetPath)
712
+ if (target && Object.keys(target).length === 3 &&
713
+ this._getValidationNamespace('valid') in target &&
714
+ this._getValidationNamespace('invalid') in target &&
715
+ this._getValidationNamespace('dirty') in target) {
716
+ this._unwatchModel(keypath)
717
+ this._undefineDirtyProperty(target)
718
+ this._undefineInvalidProperty(target)
719
+ this._undefineValidProperty(target)
720
+ removeValidationProperties(
721
+ this.$parent.$get(this._getValidationNamespace('validation')),
722
+ keypath
723
+ )
724
+ }
725
+ }
726
+ },
727
+
728
+ _defineValidatorToValidationScope: function (keypath, validator) {
729
+ var target = _.getTarget(this[this._getValidationNamespace('validation')], keypath)
730
+ target.$add(validator, null)
731
+ },
732
+
733
+ _undefineValidatorToValidationScope: function (keypath, validator) {
734
+ var validationName = this._getValidationNamespace('validation')
735
+ if (this.$parent) {
736
+ var targetPath = [validationName, keypath].join('.')
737
+ var target = this.$parent.$get(targetPath)
738
+ if (target) {
739
+ target.$delete(validator)
740
+ }
741
+ }
742
+ },
743
+
744
+ _getInitialValue: function (keypath) {
745
+ return this._initialValues[keypath]
746
+ },
747
+
748
+ _setInitialValue: function (keypath, val) {
749
+ this._initialValues[keypath] = val
750
+ },
751
+
752
+ _addValidator: function (keypath, validator, arg) {
753
+ this._validators[keypath].push({ name: validator, arg: arg })
754
+ },
755
+
756
+ _changeValidator: function (keypath, validator, arg) {
757
+ var validators = this._validators[keypath]
758
+ var i = validators.length
759
+ while (i--) {
760
+ if (validators[i].name === validator) {
761
+ validators[i].arg = arg
762
+ break
763
+ }
764
+ }
765
+ },
766
+
767
+ _findValidator: function (keypath, validator) {
768
+ var found = null
769
+ var validators = this._validators[keypath]
770
+ var i = validators.length
771
+ while (i--) {
772
+ if (validators[i].name === validator) {
773
+ found = validators[i]
774
+ break
775
+ }
776
+ }
777
+ return found
778
+ },
779
+
780
+ _watchModel: function (keypath, fn) {
781
+ this._validatorWatchers[keypath] =
782
+ this.$watch(keypath, fn, { deep: false, immediate: true })
783
+ },
784
+
785
+ _unwatchModel: function (keypath) {
786
+ var unwatch = this._validatorWatchers[keypath]
787
+ if (unwatch) {
788
+ unwatch()
789
+ delete this._validatorWatchers[keypath]
790
+ }
791
+ },
792
+
793
+ _addReadyEvents: function (id, event) {
794
+ this._readyEvents[id] = event
795
+ },
796
+
797
+ _getReadyEvents: function (id) {
798
+ return this._readyEvents[id]
799
+ },
800
+
801
+ _isRegistedReadyEvent: function (id) {
802
+ return id in this._readyEvents
803
+ },
804
+
805
+ _updateDirtyProperty: function (keypath, val) {
806
+ var validationName = this._getValidationNamespace('validation')
807
+ var dirtyName = this._getValidationNamespace('dirty')
808
+
809
+ var target = _.getTarget(this[validationName], keypath)
810
+ if (target) {
811
+ target.$set(dirtyName, this._getInitialValue(keypath) !== val)
812
+ }
813
+ },
814
+
815
+ _doValidate: function (keypath, validateName, val) {
816
+ var validationName = this._getValidationNamespace('validation')
817
+
818
+ var target = _.getTarget(this[validationName], keypath)
819
+ var validator = this._findValidator(keypath, validateName)
820
+ if (target && validator) {
821
+ this._invokeValidator(
822
+ this._validates[validateName],
823
+ val, validator.arg,
824
+ function (result) {
825
+ target.$set(validateName, !result)
826
+ })
827
+ }
828
+ },
829
+
830
+ _invokeValidator: function (validator, val, arg, fn) {
831
+ var future = validator.call(this, val, arg)
832
+ if (typeof future === 'function') { // async
833
+ if (future.resolved) {
834
+ // cached
835
+ fn(future.resolved)
836
+ } else if (future.requested) {
837
+ // pool callbacks
838
+ future.pendingCallbacks.push(fn)
839
+ } else {
840
+ future.requested = true
841
+ var fns = future.pendingCallbacks = [fn]
842
+ future(function resolve () {
843
+ future.resolved = true
844
+ for (var i = 0, l = fns.length; i < l; i++) {
845
+ fns[i](true)
846
+ }
847
+ }, function reject () {
848
+ fn(false)
849
+ })
850
+ }
851
+ } else { // sync
852
+ fn(future)
853
+ }
854
+ }
855
+ }
856
+ }
857
+
858
+ /**
859
+ * Remove properties from target validation
860
+ *
861
+ * @param {Object} validation
862
+ * @param {String} keypath
863
+ */
864
+
865
+ function removeValidationProperties (validation, keypath) {
866
+ var keys = keypath.split('.')
867
+ var key, obj
868
+ while (keys.length) {
869
+ key = keys.pop()
870
+ if (keys.length !== 0) {
871
+ obj = _.getTarget(validation, keys.join('.'))
872
+ obj.$delete(key)
873
+ } else {
874
+ validation.$delete(key)
875
+ }
876
+ }
877
+ }
878
+
879
+ /**
880
+ * Get custom namespace
881
+ *
882
+ * @param {Object} options
883
+ * @return {Object}
884
+ */
885
+
886
+ function getCustomNamespace (options) {
887
+ var namespace = {}
888
+ var key
889
+ var context
890
+ do {
891
+ if (options['validator'] && options['validator']['namespace']) {
892
+ for (key in options['validator']['namespace']) {
893
+ if (!namespace.hasOwnProperty(key)) {
894
+ namespace[key] = options['validator']['namespace'][key]
895
+ }
896
+ }
897
+ }
898
+ context = options._context || options._parent
899
+ if (context) {
900
+ options = context.$options
901
+ }
902
+ } while (context || options._parent)
903
+ return namespace
904
+ }
905
+
906
+
907
+ /***/ }
908
+ /******/ ])
153
909
  });
154
-
155
- /* */
156
- var Asset = function (Vue) {
157
- var ref = Vue.util;
158
- var extend = ref.extend;
159
-
160
- // set global validators asset
161
- var assets = Object.create(null);
162
- extend(assets, validators);
163
- Vue.options.validators = assets;
164
-
165
- // set option merge strategy
166
- var strats = Vue.config.optionMergeStrategies;
167
- if (strats) {
168
- strats.validators = function (parent, child) {
169
- if (!child) { return parent }
170
- if (!parent) { return child }
171
- var ret = Object.create(null);
172
- extend(ret, parent);
173
- var key;
174
- for (key in child) {
175
- ret[key] = child[key];
176
- }
177
- return ret
178
- };
179
- }
180
-
181
- /**
182
- * Register or retrieve a global validator definition.
183
- */
184
- function validator (
185
- id,
186
- def
187
- ) {
188
- if (def === undefined) {
189
- return Vue.options['validators'][id]
190
- } else {
191
- Vue.options['validators'][id] = def;
192
- if (def === null) {
193
- delete Vue.options['validators']['id'];
194
- }
195
- }
196
- }
197
- Vue['validator'] = validator;
198
- };
199
-
200
- /* */
201
-
202
- var Group = function (Vue) {
203
- var ref = Vue.util;
204
- var extend = ref.extend;
205
-
206
- return {
207
- data: function data () {
208
- return {
209
- valid: true,
210
- dirty: false,
211
- touched: false,
212
- modified: false,
213
- results: {}
214
- }
215
- },
216
- computed: {
217
- invalid: function invalid () { return !this.valid },
218
- pristine: function pristine () { return !this.dirty },
219
- untouched: function untouched () { return !this.touched },
220
- result: function result () {
221
- var ret = {
222
- valid: this.valid,
223
- invalid: this.invalid,
224
- dirty: this.dirty,
225
- pristine: this.pristine,
226
- touched: this.touched,
227
- untouched: this.untouched,
228
- modified: this.modified
229
- };
230
- var results = this.results;
231
- this._validityKeys.forEach(function (key) {
232
- ret[key] = results[key];
233
- if (ret[key].errors) {
234
- var errors = ret.errors || [];
235
- ret[key].errors.forEach(function (error) {
236
- errors.push(error);
237
- });
238
- ret.errors = errors;
239
- }
240
- });
241
- return ret
242
- }
243
- },
244
- watch: {
245
- results: function results (val, old) {
246
- var keys = this._validityKeys;
247
- var results = this.results;
248
- this.valid = this.checkResults(keys, results, 'valid', true);
249
- this.dirty = this.checkResults(keys, results, 'dirty', false);
250
- this.touched = this.checkResults(keys, results, 'touched', false);
251
- this.modified = this.checkResults(keys, results, 'modified', false);
252
- }
253
- },
254
- created: function created () {
255
- this._validities = Object.create(null);
256
- this._validityWatchers = Object.create(null);
257
- this._validityKeys = [];
258
- this._committing = false;
259
- },
260
- destroyed: function destroyed () {
261
- var this$1 = this;
262
-
263
- this._validityKeys.forEach(function (key) {
264
- this$1._validityWatchers[key]();
265
- delete this$1._validityWatchers[key];
266
- delete this$1._validities[key];
267
- });
268
- delete this._validityWatchers;
269
- delete this._validities;
270
- delete this._validityKeys;
271
- },
272
- methods: {
273
- register: function register (name, validity) {
274
- var this$1 = this;
275
-
276
- this._validities[name] = validity;
277
- this._validityKeys = Object.keys(this._validities);
278
- this.setResults(name, {});
279
- this.withCommit(function () {
280
- this$1._validityWatchers[name] = validity.$watch('result', function (val, old) {
281
- this$1.setResults(name, val);
282
- }, { deep: true, immediate: true });
283
- });
284
- },
285
- unregister: function unregister (name) {
286
- var this$1 = this;
287
-
288
- this._validityWatchers[name]();
289
- delete this._validityWatchers[name];
290
- delete this._validities[name];
291
- this._validityKeys = Object.keys(this._validities);
292
- this.withCommit(function () {
293
- this$1.resetResults(name);
294
- });
295
- },
296
- validityCount: function validityCount () {
297
- return this._validityKeys.length
298
- },
299
- isRegistered: function isRegistered (name) {
300
- return name in this._validities
301
- },
302
- getValidityKeys: function getValidityKeys () {
303
- return this._validityKeys
304
- },
305
- checkResults: function checkResults (
306
- keys,
307
- results,
308
- prop,
309
- checking
310
- ) {
311
- var ret = checking;
312
- for (var i = 0; i < keys.length; i++) {
313
- var result = results[keys[i]];
314
- if (result[prop] !== checking) {
315
- ret = !checking;
316
- break
317
- }
318
- }
319
- return ret
320
- },
321
- setResults: function setResults (name, val) {
322
- var this$1 = this;
323
-
324
- var newVal = {};
325
- this._validityKeys.forEach(function (key) {
326
- newVal[key] = extend({}, this$1.results[key]);
327
- });
328
- newVal[name] = extend({}, val);
329
- this.results = newVal;
330
- },
331
- resetResults: function resetResults (ignore) {
332
- var this$1 = this;
333
-
334
- var newVal = {};
335
- this._validityKeys.forEach(function (key) {
336
- if (ignore && ignore !== key) {
337
- newVal[key] = extend({}, this$1.results[key]);
338
- }
339
- });
340
- this.results = newVal;
341
- },
342
- withCommit: function withCommit (fn) {
343
- var committing = this._committing;
344
- this._committing = true;
345
- fn();
346
- this._committing = committing;
347
- }
348
- }
349
- }
350
- };
351
-
352
- /* */
353
- var ValidationClass = function (Vue) {
354
- var ValidityGroup = Group(Vue);
355
-
356
- var Validation = function Validation (options) {
357
- if ( options === void 0 ) options = {};
358
-
359
- this._result = {};
360
- this._host = options.host;
361
- this._named = Object.create(null);
362
- this._group = Object.create(null);
363
- this._validities = Object.create(null);
364
- this._beginDestroy = false;
365
- Vue.util.defineReactive(this._host, '$validation', this._result);
366
- };
367
-
368
- Validation.prototype.register = function register (
369
- field,
370
- validity,
371
- options
372
- ) {
373
- if ( options === void 0 ) options = {};
374
-
375
- // NOTE: lazy setup (in constructor, occured callstack recursive errors ...)
376
- if (!this._validityManager) {
377
- this._validityManager = new Vue(ValidityGroup);
378
- this._watchValidityResult();
379
- }
380
-
381
- if (this._validities[field]) {
382
- // TODO: should be output console.error
383
- return
384
- }
385
- this._validities[field] = validity;
386
-
387
- var named = options.named;
388
- var group = options.group;
389
- var groupValidity = group
390
- ? this._getValidityGroup('group', group) || this._registerValidityGroup('group', group)
391
- : null;
392
- var namedValidity = named
393
- ? this._getValidityGroup('named', named) || this._registerValidityGroup('named', named)
394
- : null;
395
- if (named && group && namedValidity && groupValidity) {
396
- groupValidity.register(field, validity);
397
- !namedValidity.isRegistered(group) && namedValidity.register(group, groupValidity);
398
- !this._validityManager.isRegistered(named) && this._validityManager.register(named, namedValidity);
399
- } else if (namedValidity) {
400
- namedValidity.register(field, validity);
401
- !this._validityManager.isRegistered(named) && this._validityManager.register(named, namedValidity);
402
- } else if (groupValidity) {
403
- groupValidity.register(field, validity);
404
- !this._validityManager.isRegistered(group) && this._validityManager.register(group, groupValidity);
405
- } else {
406
- this._validityManager.register(field, validity);
407
- }
408
- };
409
-
410
- Validation.prototype.unregister = function unregister (
411
- field,
412
- options
413
- ) {
414
- if ( options === void 0 ) options = {};
415
-
416
- if (!this._validityManager) {
417
- // TODO: should be output error
418
- return
419
- }
420
-
421
- if (!this._validities[field]) {
422
- // TODO: should be output error
423
- return
424
- }
425
- delete this._validities[field];
426
-
427
- var named = options.named;
428
- var group = options.group;
429
- var groupValidity = group ? this._getValidityGroup('group', group) : null;
430
- var namedValidity = named ? this._getValidityGroup('named', named) : null;
431
- if (named && group && namedValidity && groupValidity) {
432
- groupValidity.unregister(field);
433
- if (groupValidity.validityCount() === 0) {
434
- namedValidity.isRegistered(group) && namedValidity.unregister(group);
435
- this._unregisterValidityGroup('group', group);
436
- }
437
- if (namedValidity.validityCount() === 0) {
438
- this._validityManager.isRegistered(named) && this._validityManager.unregister(named);
439
- this._unregisterValidityGroup('named', named);
440
- }
441
- } else if (named && namedValidity) {
442
- namedValidity.unregister(field);
443
- if (namedValidity.validityCount() === 0) {
444
- this._validityManager.isRegistered(named) && this._validityManager.unregister(named);
445
- this._unregisterValidityGroup('named', named);
446
- }
447
- } else if (group && groupValidity) {
448
- groupValidity.unregister(field);
449
- if (groupValidity.validityCount() === 0) {
450
- this._validityManager.isRegistered(group) && this._validityManager.unregister(group);
451
- this._unregisterValidityGroup('group', group);
452
- }
453
- } else {
454
- this._validityManager.unregister(field);
455
- }
456
- };
457
-
458
- Validation.prototype.destroy = function destroy () {
459
- var this$1 = this;
460
-
461
- var validityKeys = Object.keys(this._validities);
462
- var namedKeys = Object.keys(this._named);
463
- var groupKeys = Object.keys(this._group);
464
-
465
- // unregister validity
466
- validityKeys.forEach(function (validityKey) {
467
- groupKeys.forEach(function (groupKey) {
468
- var group = this$1._getValidityGroup('group', groupKey);
469
- if (group && group.isRegistered(groupKey)) {
470
- group.unregister(validityKey);
471
- }
472
- });
473
- namedKeys.forEach(function (namedKey) {
474
- var named = this$1._getValidityGroup('named', namedKey);
475
- if (named && named.isRegistered(validityKey)) {
476
- named.unregister(validityKey);
477
- }
478
- });
479
- if (this$1._validityManager.isRegistered(validityKey)) {
480
- this$1._validityManager.unregister(validityKey);
481
- }
482
- delete this$1._validities[validityKey];
483
- });
484
-
485
- // unregister grouped validity
486
- groupKeys.forEach(function (groupKey) {
487
- namedKeys.forEach(function (namedKey) {
488
- var named = this$1._getValidityGroup('named', namedKey);
489
- if (named && named.isRegistered(groupKey)) {
490
- named.unregister(groupKey);
491
- }
492
- });
493
- if (this$1._validityManager.isRegistered(groupKey)) {
494
- this$1._validityManager.unregister(groupKey);
495
- }
496
- this$1._unregisterValidityGroup('group', groupKey);
497
- });
498
-
499
- // unregister named validity
500
- namedKeys.forEach(function (namedKey) {
501
- if (this$1._validityManager.isRegistered(namedKey)) {
502
- this$1._validityManager.unregister(namedKey);
503
- }
504
- this$1._unregisterValidityGroup('named', namedKey);
505
- });
506
-
507
- this._beginDestroy = true;
508
- };
509
-
510
- Validation.prototype._getValidityGroup = function _getValidityGroup (type, name) {
511
- return type === 'named' ? this._named[name] : this._group[name]
512
- };
513
-
514
- Validation.prototype._registerValidityGroup = function _registerValidityGroup (type, name) {
515
- var groups = type === 'named' ? this._named : this._group;
516
- groups[name] = new Vue(ValidityGroup);
517
- return groups[name]
518
- };
519
-
520
- Validation.prototype._unregisterValidityGroup = function _unregisterValidityGroup (type, name) {
521
- var groups = type === 'named' ? this._named : this._group;
522
- if (!groups[name]) {
523
- // TODO: should be warn
524
- return
525
- }
526
-
527
- groups[name].$destroy();
528
- delete groups[name];
529
- };
530
-
531
- Validation.prototype._watchValidityResult = function _watchValidityResult () {
532
- var this$1 = this;
533
-
534
- this._watcher = this._validityManager.$watch('results', function (val, old) {
535
- Vue.set(this$1._host, '$validation', val);
536
- if (this$1._beginDestroy) {
537
- this$1._destroyValidityMananger();
538
- }
539
- }, { deep: true });
540
- };
541
-
542
- Validation.prototype._unwatchValidityResult = function _unwatchValidityResult () {
543
- this._watcher();
544
- delete this._watcher;
545
- };
546
-
547
- Validation.prototype._destroyValidityMananger = function _destroyValidityMananger () {
548
- this._unwatchValidityResult();
549
- this._validityManager.$destroy();
550
- this._validityManager = null;
551
- };
552
-
553
- return Validation
554
- };
555
-
556
- /* */
557
-
558
- var Mixin = function (Vue) {
559
- var Validation = ValidationClass(Vue);
560
-
561
- return {
562
- beforeCreate: function beforeCreate () {
563
- this._validation = new Validation({ host: this });
564
- }
565
- }
566
- };
567
-
568
- /* */
569
-
570
- var baseProps = {
571
- field: {
572
- type: String,
573
- required: true
574
- },
575
- validators: {
576
- type: [String, Array, Object],
577
- required: true
578
- },
579
- group: {
580
- type: String
581
- },
582
- multiple: {
583
- type: Boolean
584
- },
585
- autotouch: {
586
- type: String,
587
- default: function () {
588
- return 'on'
589
- }
590
- },
591
- classes: {
592
- type: Object,
593
- default: function () {
594
- return {}
595
- }
596
- }
597
- };
598
-
599
- var DEFAULT_CLASSES = {
600
- valid: 'valid',
601
- invalid: 'invalid',
602
- touched: 'touched',
603
- untouched: 'untouched',
604
- pristine: 'pristine',
605
- dirty: 'dirty',
606
- modified: 'modified'
607
- };
608
-
609
- /* */
610
- var States = function (Vue) {
611
- var ref = Vue.util;
612
- var extend = ref.extend;
613
- var isPlainObject = ref.isPlainObject;
614
-
615
- function initialStates (states, validators, init) {
616
- if ( init === void 0 ) init = undefined;
617
-
618
- if (Array.isArray(validators)) {
619
- validators.forEach(function (validator) {
620
- states[validator] = init;
621
- });
622
- } else {
623
- Object.keys(validators).forEach(function (validator) {
624
- var props = (validators[validator] &&
625
- validators[validator]['props'] &&
626
- isPlainObject(validators[validator]['props']))
627
- ? validators[validator]['props']
628
- : null;
629
- if (props) {
630
- Object.keys(props).forEach(function (prop) {
631
- states[validator] = {};
632
- states[validator][prop] = init;
633
- });
634
- } else {
635
- states[validator] = init;
636
- }
637
- });
638
- }
639
- }
640
-
641
- function getInitialResults (validators) {
642
- var results = {};
643
- initialStates(results, validators, undefined);
644
- return results
645
- }
646
-
647
- function getInitialProgresses (validators) {
648
- var progresses = {};
649
- initialStates(progresses, validators, '');
650
- return progresses
651
- }
652
-
653
- var props = extend({
654
- child: {
655
- type: Object,
656
- required: true
657
- },
658
- value: {
659
- type: Object
660
- }
661
- }, baseProps);
662
-
663
- function data () {
664
- var validators = nomalizeValidators(this.validators);
665
- return {
666
- results: getInitialResults(validators),
667
- valid: true,
668
- dirty: false,
669
- touched: false,
670
- modified: false,
671
- progresses: getInitialProgresses(validators)
672
- }
673
- }
674
-
675
- return {
676
- props: props,
677
- data: data
678
- }
679
- };
680
-
681
- function nomalizeValidators (target) {
682
- return typeof target === 'string' ? [target] : target
683
- }
684
-
685
- /* */
686
-
687
- var Computed = function (Vue) {
688
- var ref = Vue.util;
689
- var isPlainObject = ref.isPlainObject;
690
-
691
- function setError (
692
- result,
693
- field,
694
- validator,
695
- message,
696
- prop
697
- ) {
698
- var error = { field: field, validator: validator };
699
- if (message) {
700
- error.message = message;
701
- }
702
- if (prop) {
703
- error.prop = prop;
704
- }
705
- result.errors = result.errors || [];
706
- result.errors.push(error);
707
- }
708
-
709
- function walkProgresses (keys, target) {
710
- var progress = '';
711
- for (var i = 0; i < keys.length; i++) {
712
- var result = target[keys[i]];
713
- if (typeof result === 'string' && result) {
714
- progress = result;
715
- break
716
- }
717
- if (isPlainObject(result)) {
718
- var nestedKeys = Object.keys(result);
719
- progress = walkProgresses(nestedKeys, result);
720
- if (!progress) {
721
- break
722
- }
723
- }
724
- }
725
- return progress
726
- }
727
-
728
- function invalid () {
729
- return !this.valid
730
- }
731
-
732
- function pristine () {
733
- return !this.dirty
734
- }
735
-
736
- function untouched () {
737
- return !this.touched
738
- }
739
-
740
- function result () {
741
- var this$1 = this;
742
-
743
- var ret = {
744
- valid: this.valid,
745
- invalid: this.invalid,
746
- dirty: this.dirty,
747
- pristine: this.pristine,
748
- touched: this.touched,
749
- untouched: this.untouched,
750
- modified: this.modified
751
- };
752
-
753
- var keys = this._keysCached(this._uid.toString(), this.results);
754
- keys.forEach(function (validator) {
755
- var result = this$1.results[validator];
756
- if (typeof result === 'boolean') {
757
- if (result) {
758
- ret[validator] = false;
759
- } else {
760
- setError(ret, this$1.field, validator);
761
- ret[validator] = !result;
762
- }
763
- } else if (typeof result === 'string') {
764
- setError(ret, this$1.field, validator, result);
765
- ret[validator] = result;
766
- } else if (isPlainObject(result)) { // object
767
- var props = Object.keys(result);
768
- props.forEach(function (prop) {
769
- var propRet = result[prop];
770
- ret[prop] = ret[prop] || {};
771
- if (typeof propRet === 'boolean') {
772
- if (propRet) {
773
- ret[prop][validator] = false;
774
- } else {
775
- setError(ret, this$1.field, validator, undefined, prop);
776
- ret[prop][validator] = !propRet;
777
- }
778
- } else if (typeof propRet === 'string') {
779
- setError(ret, this$1.field, validator, propRet, prop);
780
- ret[prop][validator] = propRet;
781
- } else {
782
- ret[prop][validator] = false;
783
- }
784
- });
785
- } else {
786
- ret[validator] = false;
787
- }
788
- });
789
-
790
- return ret
791
- }
792
-
793
- function progress () {
794
- var ret = '';
795
- ret = walkProgresses(
796
- this._keysCached(this._uid.toString(), this.results),
797
- this.progresses
798
- );
799
- return ret
800
- }
801
-
802
- return {
803
- invalid: invalid,
804
- pristine: pristine,
805
- untouched: untouched,
806
- result: result,
807
- progress: progress
808
- }
809
- };
810
-
811
- /* */
812
-
813
- var Render = function (Vue) {
814
- return {
815
- render: function render (h) {
816
- return this.child
817
- }
818
- }
819
- };
820
-
821
- /* */
822
-
823
- var SingleElementClass = function (Vue) {
824
- var ref = Vue.util;
825
- var looseEqual = ref.looseEqual;
826
-
827
- var SingleElement = function SingleElement (vm) {
828
- this._vm = vm;
829
- this.initValue = this.getValue();
830
- this.attachValidity();
831
- };
832
-
833
- SingleElement.prototype.attachValidity = function attachValidity () {
834
- this._vm.$el.$validity = this._vm;
835
- };
836
-
837
- SingleElement.prototype.getValue = function getValue () {
838
- var el = this._vm.$el;
839
- if (el.tagName === 'SELECT') {
840
- return getSelectValue(el)
841
- } else {
842
- if (el.type === 'checkbox') {
843
- return el.checked
844
- } else {
845
- return el.value
846
- }
847
- }
848
- };
849
-
850
- SingleElement.prototype.checkModified = function checkModified () {
851
- var el = this._vm.$el;
852
- if (el.tagName === 'SELECT') {
853
- return !looseEqual(this.initValue, getSelectValue(el))
854
- } else {
855
- if (el.type === 'checkbox') {
856
- return !looseEqual(this.initValue, el.checked)
857
- } else {
858
- return !looseEqual(this.initValue, el.value)
859
- }
860
- }
861
- };
862
-
863
- SingleElement.prototype.listenToucheableEvent = function listenToucheableEvent () {
864
- this._vm.$el.addEventListener('focusout', this._vm.willUpdateTouched);
865
- };
866
-
867
- SingleElement.prototype.unlistenToucheableEvent = function unlistenToucheableEvent () {
868
- this._vm.$el.removeEventListener('focusout', this._vm.willUpdateTouched);
869
- };
870
-
871
- SingleElement.prototype.listenInputableEvent = function listenInputableEvent () {
872
- var vm = this._vm;
873
- var el = vm.$el;
874
- if (el.tagName === 'SELECT') {
875
- el.addEventListener('change', vm.handleInputable);
876
- } else {
877
- if (el.type === 'checkbox') {
878
- el.addEventListener('change', vm.handleInputable);
879
- } else {
880
- el.addEventListener('input', vm.handleInputable);
881
- }
882
- }
883
- };
884
-
885
- SingleElement.prototype.unlistenInputableEvent = function unlistenInputableEvent () {
886
- var vm = this._vm;
887
- var el = vm.$el;
888
- if (el.tagName === 'SELECT') {
889
- el.removeEventListener('change', vm.handleInputable);
890
- } else {
891
- if (el.type === 'checkbox') {
892
- el.removeEventListener('change', vm.handleInputable);
893
- } else {
894
- el.removeEventListener('input', vm.handleInputable);
895
- }
896
- }
897
- };
898
-
899
- return SingleElement
900
- };
901
-
902
- function getSelectValue (el) {
903
- var value = [];
904
- for (var i = 0, l = el.options.length; i < l; i++) {
905
- var option = el.options[i];
906
- if (!option.disabled && option.selected) {
907
- value.push(option.value);
908
- }
909
- }
910
- return value
911
- }
912
-
913
- /* */
914
-
915
- var MultiElementClass = function (Vue) {
916
- var ref = Vue.util;
917
- var looseEqual = ref.looseEqual;
918
-
919
- var MultiElement = function MultiElement (vm) {
920
- // TODO: should be checked whether included radio or checkbox
921
- this._vm = vm;
922
- this.initValue = this.getValue();
923
- this.attachValidity();
924
- };
925
-
926
- MultiElement.prototype.attachValidity = function attachValidity () {
927
- var this$1 = this;
928
-
929
- this._vm.$el.$validity = this._vm;
930
- this._eachItems(function (item) {
931
- item.$validity = this$1._vm;
932
- });
933
- };
934
-
935
- MultiElement.prototype.getValue = function getValue () {
936
- return this._getCheckedValue()
937
- };
938
-
939
- MultiElement.prototype.checkModified = function checkModified () {
940
- return !looseEqual(this.initValue, this._getCheckedValue())
941
- };
942
-
943
- MultiElement.prototype.listenToucheableEvent = function listenToucheableEvent () {
944
- var this$1 = this;
945
-
946
- this._eachItems(function (item) {
947
- item.addEventListener('focusout', this$1._vm.willUpdateTouched);
948
- });
949
- };
950
-
951
- MultiElement.prototype.unlistenToucheableEvent = function unlistenToucheableEvent () {
952
- var this$1 = this;
953
-
954
- this._eachItems(function (item) {
955
- item.removeEventListener('focusout', this$1._vm.willUpdateTouched);
956
- });
957
- };
958
-
959
- MultiElement.prototype.listenInputableEvent = function listenInputableEvent () {
960
- var this$1 = this;
961
-
962
- this._eachItems(function (item) {
963
- item.addEventListener('change', this$1._vm.handleInputable);
964
- });
965
- };
966
-
967
- MultiElement.prototype.unlistenInputableEvent = function unlistenInputableEvent () {
968
- var this$1 = this;
969
-
970
- this._eachItems(function (item) {
971
- item.removeEventListener('change', this$1._vm.handleInputable);
972
- });
973
- };
974
-
975
- MultiElement.prototype._getCheckedValue = function _getCheckedValue () {
976
- var value = [];
977
- this._eachItems(function (item) {
978
- if (!item.disabled && item.checked) {
979
- value.push(item.value);
980
- }
981
- });
982
- return value
983
- };
984
-
985
- MultiElement.prototype._getItems = function _getItems () {
986
- return this._vm.$el.querySelectorAll('input[type="checkbox"], input[type="radio"]')
987
- };
988
-
989
- MultiElement.prototype._eachItems = function _eachItems (cb) {
990
- var items = this._getItems();
991
- for (var i = 0; i < items.length; i++) {
992
- cb(items[i]);
993
- }
994
- };
995
-
996
- return MultiElement
997
- };
998
-
999
- /* */
1000
-
1001
- var inBrowser =
1002
- typeof window !== 'undefined' &&
1003
- Object.prototype.toString.call(window) !== '[object Object]';
1004
- var UA = inBrowser && window.navigator.userAgent.toLowerCase();
1005
- var isIE9 = UA && UA.indexOf('msie 9.0') > 0;
1006
-
1007
- function getClass (el) {
1008
- var classname = el.className;
1009
- if (typeof classname === 'object') {
1010
- classname = classname.baseVal || '';
1011
- }
1012
- return classname
1013
- }
1014
-
1015
- function setClass (el, cls) {
1016
- if (isIE9 && !/svg$/.test(el.namespaceURI)) {
1017
- el.className = cls;
1018
- } else {
1019
- el.setAttribute('class', cls);
1020
- }
1021
- }
1022
-
1023
- function addClass (el, cls) {
1024
- if (el.classList) {
1025
- el.classList.add(cls);
1026
- } else {
1027
- var cur = ' ' + getClass(el) + ' ';
1028
- if (cur.indexOf(' ' + cls + ' ') < 0) {
1029
- setClass(el, (cur + cls).trim());
1030
- }
1031
- }
1032
- }
1033
-
1034
- function removeClass (el, cls) {
1035
- if (el.classList) {
1036
- el.classList.remove(cls);
1037
- } else {
1038
- var cur = ' ' + getClass(el) + ' ';
1039
- var tar = ' ' + cls + ' ';
1040
- while (cur.indexOf(tar) >= 0) {
1041
- cur = cur.replace(tar, ' ');
1042
- }
1043
- setClass(el, cur.trim());
1044
- }
1045
- if (!el.className) {
1046
- el.removeAttribute('class');
1047
- }
1048
- }
1049
-
1050
- function toggleClasses (el, key, fn) {
1051
- if (!el) { return }
1052
-
1053
- key = key.trim();
1054
- if (key.indexOf(' ') === -1) {
1055
- fn(el, key);
1056
- return
1057
- }
1058
-
1059
- var keys = key.split(/\s+/);
1060
- for (var i = 0, l = keys.length; i < l; i++) {
1061
- fn(el, keys[i]);
1062
- }
1063
- }
1064
-
1065
- function memoize (fn) {
1066
- var cache = Object.create(null);
1067
- return function memoizeFn (id) {
1068
- var args = [], len = arguments.length - 1;
1069
- while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ];
1070
-
1071
- var hit = cache[id];
1072
- return hit || (cache[id] = fn.apply(void 0, args))
1073
- }
1074
- }
1075
-
1076
- /* */
1077
- var ComponentElementClass = function (Vue) {
1078
- var ref = Vue.util;
1079
- var looseEqual = ref.looseEqual;
1080
- var isPlainObject = ref.isPlainObject;
1081
-
1082
- function getValidatorProps (validators) {
1083
- var normalized = typeof validators === 'string' ? [validators] : validators;
1084
- var targets = [];
1085
- if (isPlainObject(normalized)) {
1086
- Object.keys(normalized).forEach(function (validator) {
1087
- var props = (normalized[validator] &&
1088
- normalized[validator]['props'] &&
1089
- isPlainObject(normalized[validator]['props']))
1090
- ? normalized[validator]['props']
1091
- : null;
1092
- if (props) {
1093
- Object.keys(props).forEach(function (prop) {
1094
- if (!~targets.indexOf(prop)) {
1095
- targets.push(prop);
1096
- }
1097
- });
1098
- }
1099
- });
1100
- }
1101
- return targets
1102
- }
1103
-
1104
- var ComponentElement = function ComponentElement (vm, vnode, validatorProps) {
1105
- this._vm = vm;
1106
- this._vnode = vnode;
1107
- this._validatorProps = validatorProps || memoize(getValidatorProps);
1108
- this.initValue = this.getValue();
1109
- this._watchers = [];
1110
- this.attachValidity();
1111
- };
1112
-
1113
- ComponentElement.prototype.attachValidity = function attachValidity () {
1114
- this._vm.$el.$validity = this._vm;
1115
- };
1116
-
1117
- ComponentElement.prototype.getValidatorProps = function getValidatorProps$1 () {
1118
- var vm = this._vm;
1119
- return this._validatorProps(vm._uid.toString(), vm.validators)
1120
- };
1121
-
1122
- ComponentElement.prototype.getValue = function getValue () {
1123
- var this$1 = this;
1124
-
1125
- var value = {};
1126
- this.getValidatorProps().forEach(function (prop) {
1127
- value[prop] = this$1._vnode.child[prop];
1128
- });
1129
- return value
1130
- };
1131
-
1132
- ComponentElement.prototype.checkModified = function checkModified () {
1133
- return !looseEqual(this.initValue, this.getValue())
1134
- };
1135
-
1136
- ComponentElement.prototype.listenToucheableEvent = function listenToucheableEvent () {
1137
- this._vm.$el.addEventListener('focusout', this._vm.willUpdateTouched);
1138
- };
1139
-
1140
- ComponentElement.prototype.unlistenToucheableEvent = function unlistenToucheableEvent () {
1141
- this._vm.$el.removeEventListener('focusout', this._vm.willUpdateTouched);
1142
- };
1143
-
1144
- ComponentElement.prototype.listenInputableEvent = function listenInputableEvent () {
1145
- var this$1 = this;
1146
-
1147
- this.getValidatorProps().forEach(function (prop) {
1148
- this$1._watchers.push(this$1._vnode.child.$watch(prop, this$1._vm.watchInputable));
1149
- });
1150
- };
1151
-
1152
- ComponentElement.prototype.unlistenInputableEvent = function unlistenInputableEvent () {
1153
- this._watchers.forEach(function (watcher) { watcher(); });
1154
- this._watchers = [];
1155
- };
1156
-
1157
- return ComponentElement
1158
- };
1159
-
1160
- /* */
1161
- var Elements = function (Vue) {
1162
- var SingleElement = SingleElementClass(Vue);
1163
- var MultiElement = MultiElementClass(Vue);
1164
- var ComponentElement = ComponentElementClass(Vue);
1165
-
1166
- return {
1167
- SingleElement: SingleElement,
1168
- MultiElement: MultiElement,
1169
- ComponentElement: ComponentElement
1170
- }
1171
- };
1172
-
1173
- /* */
1174
- var Lifecycles = function (Vue) {
1175
- var ref = Elements(Vue);
1176
- var SingleElement = ref.SingleElement;
1177
- var MultiElement = ref.MultiElement;
1178
- var ComponentElement = ref.ComponentElement;
1179
-
1180
- function createValidityElement (vm, vnode) {
1181
- return vm.multiple
1182
- ? new MultiElement(vm)
1183
- : checkBuiltInElement(vnode)
1184
- ? new SingleElement(vm)
1185
- : checkComponentElement(vnode)
1186
- ? new ComponentElement(vm, vnode)
1187
- : null
1188
- }
1189
-
1190
- function watchModelable (val) {
1191
- this.$emit('input', {
1192
- result: this.result,
1193
- progress: this.progress,
1194
- progresses: this.progresses
1195
- });
1196
- }
1197
-
1198
- function created () {
1199
- this._elementable = null;
1200
-
1201
- this._keysCached = memoize(function (results) {
1202
- return Object.keys(results)
1203
- });
1204
-
1205
- // for event control flags
1206
- this._modified = false;
1207
-
1208
- // watch validation raw results
1209
- this._watchValidationRawResults();
1210
-
1211
- var validation = this.$options.propsData ? this.$options.propsData.validation : null;
1212
- if (validation) {
1213
- var instance = validation.instance;
1214
- var name = validation.name;
1215
- var group = this.group;
1216
- instance.register(this.field, this, { named: name, group: group });
1217
- }
1218
- }
1219
-
1220
- function destroyed () {
1221
- var validation = this.$options.propsData ? this.$options.propsData.validation : null;
1222
- if (validation) {
1223
- var instance = validation.instance;
1224
- var name = validation.name;
1225
- var group = this.group;
1226
- instance.unregister(this.field, { named: name, group: group });
1227
- }
1228
-
1229
- if (this._unwatchResultProp) {
1230
- this._unwatchResultProp();
1231
- this._unwatchResultProp = null;
1232
- }
1233
-
1234
- if (this._unwatchProgressProp) {
1235
- this._unwatchProgressProp();
1236
- this._unwatchProgressProp = null;
1237
- }
1238
-
1239
- this._unwatchValidationRawResults();
1240
-
1241
- this._elementable.unlistenInputableEvent();
1242
- if (this.autotouch === 'on') {
1243
- this._elementable.unlistenToucheableEvent();
1244
- }
1245
- this._elementable = null;
1246
- }
1247
-
1248
- function mounted () {
1249
- this._elementable = createValidityElement(this, this._vnode);
1250
- if (this._elementable) {
1251
- if (this.autotouch === 'on') {
1252
- this._elementable.listenToucheableEvent();
1253
- }
1254
- this._elementable.listenInputableEvent();
1255
- } else {
1256
- // TODO: should be warn
1257
- }
1258
-
1259
- if (hasModelDirective(this.$vnode)) {
1260
- this._unwatchResultProp = this.$watch('result', watchModelable);
1261
- this._unwatchProgressProp = this.$watch('progress', watchModelable);
1262
- }
1263
-
1264
- toggleClasses(this.$el, this.classes.untouched, addClass);
1265
- toggleClasses(this.$el, this.classes.pristine, addClass);
1266
- }
1267
-
1268
- return {
1269
- created: created,
1270
- destroyed: destroyed,
1271
- mounted: mounted
1272
- }
1273
- };
1274
-
1275
- function checkComponentElement (vnode) {
1276
- return vnode.child &&
1277
- vnode.componentOptions &&
1278
- vnode.tag &&
1279
- vnode.tag.match(/vue-component/)
1280
- }
1281
-
1282
- function checkBuiltInElement (vnode) {
1283
- return !vnode.child &&
1284
- !vnode.componentOptions &&
1285
- vnode.tag
1286
- }
1287
-
1288
- function hasModelDirective (vnode) {
1289
- return ((vnode && vnode.data && vnode.data.directives) || []).find(function (dir) { return dir.name === 'model'; })
1290
- }
1291
-
1292
- /* */
1293
-
1294
- var Event = function (Vue) {
1295
- function _fireEvent (type) {
1296
- var args = [], len = arguments.length - 1;
1297
- while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ];
1298
-
1299
- (ref = this).$emit.apply(ref, [ type ].concat( args ));
1300
- var ref;
1301
- }
1302
-
1303
- return {
1304
- _fireEvent: _fireEvent
1305
- }
1306
- };
1307
-
1308
- /* */
1309
- var State = function (Vue) {
1310
- var ref = Vue.util;
1311
- var isPlainObject = ref.isPlainObject;
1312
-
1313
- function getValue (options) {
1314
- return this._elementable.getValue()
1315
- }
1316
-
1317
- function checkModified () {
1318
- return this._elementable.checkModified()
1319
- }
1320
-
1321
- function willUpdateTouched (options) {
1322
- if (!this.touched) {
1323
- this.touched = true;
1324
- toggleClasses(this.$el, this.classes.touched, addClass);
1325
- toggleClasses(this.$el, this.classes.untouched, removeClass);
1326
- this._fireEvent('touched');
1327
- }
1328
- }
1329
-
1330
- function willUpdateDirty () {
1331
- if (!this.dirty && this.checkModified()) {
1332
- this.dirty = true;
1333
- toggleClasses(this.$el, this.classes.dirty, addClass);
1334
- toggleClasses(this.$el, this.classes.pristine, removeClass);
1335
- this._fireEvent('dirty');
1336
- }
1337
- }
1338
-
1339
- function willUpdateModified () {
1340
- var modified = this.modified = this.checkModified();
1341
- if (this._modified !== modified) {
1342
- this._modified = modified;
1343
- toggleClasses(this.$el, this.classes.modified, modified ? addClass : removeClass);
1344
- this._fireEvent('modified', modified);
1345
- }
1346
- }
1347
-
1348
- function handleInputable (e) {
1349
- this.willUpdateDirty();
1350
- this.willUpdateModified();
1351
- }
1352
-
1353
- function watchInputable (val) {
1354
- this.willUpdateDirty();
1355
- this.willUpdateModified();
1356
- }
1357
-
1358
- function _initStates (keys, target, init) {
1359
- if ( init === void 0 ) init = undefined;
1360
-
1361
- for (var i = 0; i < keys.length; i++) {
1362
- var result = target[keys[i]];
1363
- if (isPlainObject(result)) {
1364
- var nestedKeys = Object.keys(result);
1365
- _initStates(nestedKeys, result, init);
1366
- } else {
1367
- target[keys[i]] = init;
1368
- }
1369
- }
1370
- }
1371
-
1372
- function reset () {
1373
- this._unwatchValidationRawResults();
1374
- var keys = this._keysCached(this._uid.toString(), this.results);
1375
- _initStates(keys, this.results, undefined);
1376
- _initStates(keys, this.progresses, '');
1377
- toggleClasses(this.$el, this.classes.valid, removeClass);
1378
- toggleClasses(this.$el, this.classes.invalid, removeClass);
1379
- toggleClasses(this.$el, this.classes.touched, removeClass);
1380
- toggleClasses(this.$el, this.classes.untouched, addClass);
1381
- toggleClasses(this.$el, this.classes.dirty, removeClass);
1382
- toggleClasses(this.$el, this.classes.pristine, addClass);
1383
- toggleClasses(this.$el, this.classes.modified, removeClass);
1384
- this.valid = true;
1385
- this.dirty = false;
1386
- this.touched = false;
1387
- this.modified = false;
1388
- this._modified = false;
1389
- this._watchValidationRawResults();
1390
- }
1391
-
1392
- function _walkValid (keys, target) {
1393
- var valid = true;
1394
- for (var i = 0; i < keys.length; i++) {
1395
- var result = target[keys[i]];
1396
- if (typeof result === 'boolean' && !result) {
1397
- valid = false;
1398
- break
1399
- }
1400
- if (typeof result === 'string' && result) {
1401
- valid = false;
1402
- break
1403
- }
1404
- if (isPlainObject(result)) {
1405
- var nestedKeys = Object.keys(result);
1406
- valid = _walkValid(nestedKeys, result);
1407
- if (!valid) {
1408
- break
1409
- }
1410
- }
1411
- }
1412
- return valid
1413
- }
1414
-
1415
- function _watchValidationRawResults () {
1416
- var this$1 = this;
1417
-
1418
- this._unwatchResults = this.$watch('results', function (val) {
1419
- this$1.valid = _walkValid(
1420
- this$1._keysCached(this$1._uid.toString(), this$1.results),
1421
- this$1.results
1422
- );
1423
- if (this$1.valid) {
1424
- toggleClasses(this$1.$el, this$1.classes.valid, addClass);
1425
- toggleClasses(this$1.$el, this$1.classes.invalid, removeClass);
1426
- } else {
1427
- toggleClasses(this$1.$el, this$1.classes.valid, removeClass);
1428
- toggleClasses(this$1.$el, this$1.classes.invalid, addClass);
1429
- }
1430
-
1431
- this$1._fireEvent(this$1.valid ? 'valid' : 'invalid');
1432
- }, { deep: true });
1433
- }
1434
-
1435
- function _unwatchValidationRawResults () {
1436
- this._unwatchResults();
1437
- this._unwatchResults = undefined;
1438
- delete this._unwatchResults;
1439
- }
1440
-
1441
- function touch () {
1442
- this.willUpdateTouched();
1443
- }
1444
-
1445
- return {
1446
- getValue: getValue,
1447
- checkModified: checkModified,
1448
- willUpdateTouched: willUpdateTouched,
1449
- willUpdateDirty: willUpdateDirty,
1450
- willUpdateModified: willUpdateModified,
1451
- handleInputable: handleInputable,
1452
- watchInputable: watchInputable,
1453
- reset: reset,
1454
- _walkValid: _walkValid,
1455
- _watchValidationRawResults: _watchValidationRawResults,
1456
- _unwatchValidationRawResults: _unwatchValidationRawResults,
1457
- touch: touch
1458
- }
1459
- };
1460
-
1461
- /* */
1462
-
1463
- /**
1464
- * Forgiving check for a promise
1465
- */
1466
- function isPromise (p) {
1467
- return p && typeof p.then === 'function'
1468
- }
1469
-
1470
- var Validate = function (Vue) {
1471
- var ref = Vue.util;
1472
- var extend = ref.extend;
1473
- var isPlainObject = ref.isPlainObject;
1474
- var resolveAsset = ref.resolveAsset;
1475
-
1476
- function _resolveValidator (name) {
1477
- var options = (this.child && this.child.context)
1478
- ? this.child.context.$options
1479
- : this.$options;
1480
- return resolveAsset(options, 'validators', name)
1481
- }
1482
-
1483
- function _getValidateRawDescriptor (
1484
- validator,
1485
- field,
1486
- value
1487
- ) {
1488
- var asset = this._resolveValidator(validator);
1489
- if (!asset) {
1490
- // TODO: should be warned
1491
- return null
1492
- }
1493
-
1494
- var fn = null;
1495
- var rule = null;
1496
- var msg = null;
1497
- if (isPlainObject(asset)) {
1498
- if (asset.check && typeof asset.check === 'function') {
1499
- fn = asset.check;
1500
- }
1501
- if (asset.message) {
1502
- msg = asset.message;
1503
- }
1504
- } else if (typeof asset === 'function') {
1505
- fn = asset;
1506
- } else {
1507
- // TODO: should be warned
1508
- return null
1509
- }
1510
-
1511
- if (!fn) {
1512
- // TODO: should be warned
1513
- return null
1514
- }
1515
-
1516
- var props = null;
1517
- var validators = this.validators;
1518
- if (isPlainObject(validators)) {
1519
- if (isPlainObject(validators[validator])) {
1520
- if (validators[validator].props && isPlainObject(validators[validator].props)) {
1521
- props = validators[validator].props;
1522
- } else {
1523
- if (validators[validator].rule) {
1524
- rule = validators[validator].rule;
1525
- }
1526
- if (validators[validator].message) {
1527
- msg = validators[validator].message;
1528
- }
1529
- }
1530
- } else {
1531
- rule = validators[validator];
1532
- }
1533
- }
1534
-
1535
- var descriptor = { fn: fn, value: value, field: field };
1536
- if (rule) {
1537
- descriptor.rule = rule;
1538
- }
1539
- if (msg) {
1540
- descriptor.msg = msg;
1541
- }
1542
- if (props) {
1543
- descriptor.props = props;
1544
- }
1545
-
1546
- return descriptor
1547
- }
1548
-
1549
- function _resolveMessage (
1550
- field,
1551
- msg,
1552
- override
1553
- ) {
1554
- if (override) { return override }
1555
- return msg
1556
- ? typeof msg === 'function'
1557
- ? msg(field)
1558
- : msg
1559
- : undefined
1560
- }
1561
-
1562
- function _invokeValidator (
1563
- ref,
1564
- value,
1565
- cb
1566
- ) {
1567
- var this$1 = this;
1568
- var fn = ref.fn;
1569
- var field = ref.field;
1570
- var rule = ref.rule;
1571
- var msg = ref.msg;
1572
-
1573
- var future = fn.call(this.child.context, value, rule);
1574
- if (typeof future === 'function') { // function
1575
- future(function () { // resolve
1576
- cb(true);
1577
- }, function (err) { // reject
1578
- cb(false, this$1._resolveMessage(field, msg, err));
1579
- });
1580
- } else if (isPromise(future)) { // promise
1581
- future.then(function () { // resolve
1582
- cb(true);
1583
- }, function (err) { // reject
1584
- cb(false, this$1._resolveMessage(field, msg, err));
1585
- }).catch(function (err) {
1586
- cb(false, this$1._resolveMessage(field, msg, err.message));
1587
- });
1588
- } else { // sync
1589
- cb(future, future === false ? this._resolveMessage(field, msg) : undefined);
1590
- }
1591
- }
1592
-
1593
- function _getValidateDescriptors (
1594
- validator,
1595
- field,
1596
- value
1597
- ) {
1598
- var descriptors = [];
1599
-
1600
- var rawDescriptor = this._getValidateRawDescriptor(validator, this.field, value);
1601
- if (!rawDescriptor) { return descriptors }
1602
-
1603
- if (!rawDescriptor.props) {
1604
- var descriptor = { name: validator };
1605
- extend(descriptor, rawDescriptor);
1606
- descriptors.push(descriptor);
1607
- } else {
1608
- var propsKeys = Object.keys(!rawDescriptor.props);
1609
- propsKeys.forEach(function (prop) {
1610
- var descriptor = {
1611
- fn: rawDescriptor.fn,
1612
- name: validator,
1613
- value: rawDescriptor.value[prop],
1614
- field: rawDescriptor.field,
1615
- prop: prop
1616
- };
1617
- if (rawDescriptor.props[prop].rule) {
1618
- descriptor.rule = rawDescriptor.props[prop].rule;
1619
- }
1620
- if (rawDescriptor.props[prop].message) {
1621
- descriptor.msg = rawDescriptor.props[prop].message;
1622
- }
1623
- descriptors.push(descriptor);
1624
- });
1625
- }
1626
-
1627
- return descriptors
1628
- }
1629
-
1630
- function _syncValidates (field, cb) {
1631
- var this$1 = this;
1632
-
1633
- var validators = this._keysCached(this._uid.toString(), this.results);
1634
- var value = this.getValue();
1635
- var descriptors = [];
1636
- validators.forEach(function (validator) {
1637
- this$1._getValidateDescriptors(validator, field, value).forEach(function (desc) {
1638
- descriptors.push(desc);
1639
- });
1640
- });
1641
-
1642
- var count = 0;
1643
- var len = descriptors.length;
1644
- descriptors.forEach(function (desc) {
1645
- var validator = desc.name;
1646
- var prop = desc.prop;
1647
- if ((!prop && this$1.progresses[validator]) || (prop && this$1.progresses[validator][prop])) {
1648
- count++;
1649
- if (count === len) {
1650
- cb(this$1._walkValid(this$1._keysCached(this$1._uid.toString(), this$1.results), this$1.results));
1651
- }
1652
- return
1653
- }
1654
-
1655
- if (!prop) {
1656
- this$1.progresses[validator] = 'running';
1657
- } else {
1658
- this$1.progresses[validator][prop] = 'running';
1659
- }
1660
-
1661
- this$1.$nextTick(function () {
1662
- this$1._invokeValidator(desc, desc.value, function (ret, msg) {
1663
- if (!prop) {
1664
- this$1.progresses[validator] = '';
1665
- this$1.results[validator] = msg || ret;
1666
- } else {
1667
- this$1.progresses[validator][prop] = '';
1668
- this$1.results[validator][prop] = msg || ret;
1669
- }
1670
-
1671
- count++;
1672
- if (count === len) {
1673
- cb(this$1._walkValid(this$1._keysCached(this$1._uid.toString(), this$1.results), this$1.results));
1674
- }
1675
- });
1676
- });
1677
- });
1678
- }
1679
-
1680
- // TODO:should be refactor!!
1681
- function _validate (validator, value, cb) {
1682
- var this$1 = this;
1683
-
1684
- var descriptor = this._getValidateRawDescriptor(validator, this.field, value);
1685
- if (descriptor && !descriptor.props) {
1686
- if (this.progresses[validator]) { return false }
1687
- this.progresses[validator] = 'running';
1688
- this.$nextTick(function () {
1689
- this$1._invokeValidator(descriptor, descriptor.value, function (ret, msg) {
1690
- this$1.progresses[validator] = '';
1691
- this$1.results[validator] = msg || ret;
1692
- if (cb) {
1693
- this$1.$nextTick(function () {
1694
- cb.call(this$1, null, ret, msg);
1695
- });
1696
- } else {
1697
- var e = { result: ret };
1698
- if (msg) {
1699
- e['msg'] = msg;
1700
- }
1701
- this$1._fireEvent('validate', validator, e);
1702
- }
1703
- });
1704
- });
1705
- } else if (descriptor && descriptor.props) {
1706
- var propsKeys = Object.keys(descriptor.props);
1707
- propsKeys.forEach(function (prop) {
1708
- if (this$1.progresses[validator][prop]) { return }
1709
- this$1.progresses[validator][prop] = 'running';
1710
- var values = descriptor.value;
1711
- var propDescriptor = {
1712
- fn: descriptor.fn,
1713
- value: values[prop],
1714
- field: descriptor.field
1715
- };
1716
- if (descriptor.props[prop].rule) {
1717
- propDescriptor.rule = descriptor.props[prop].rule;
1718
- }
1719
- if (descriptor.props[prop].message) {
1720
- propDescriptor.msg = descriptor.props[prop].message;
1721
- }
1722
- this$1.$nextTick(function () {
1723
- this$1._invokeValidator(propDescriptor, propDescriptor.value, function (result, msg) {
1724
- this$1.progresses[validator][prop] = '';
1725
- this$1.results[validator][prop] = msg || result;
1726
- var e = { prop: prop, result: result };
1727
- if (msg) {
1728
- e['msg'] = msg;
1729
- }
1730
- this$1._fireEvent('validate', validator, e);
1731
- });
1732
- });
1733
- });
1734
- } else {
1735
- // TODO:
1736
- var err = new Error();
1737
- cb ? cb.call(this, err) : this._fireEvent('validate', validator, err);
1738
- }
1739
- return true
1740
- }
1741
-
1742
- // TODO: should be re-design of API
1743
- function validate () {
1744
- var this$1 = this;
1745
- var args = [], len = arguments.length;
1746
- while ( len-- ) args[ len ] = arguments[ len ];
1747
-
1748
- var validators;
1749
- var value;
1750
- var cb;
1751
- var ret = true;
1752
-
1753
- if (args.length === 3) {
1754
- validators = [args[0]];
1755
- value = args[1];
1756
- cb = args[2];
1757
- } else if (args.length === 2) {
1758
- if (isPlainObject(args[0])) {
1759
- validators = [args[0].validator];
1760
- value = args[0].value || this.getValue();
1761
- cb = args[1];
1762
- } else {
1763
- validators = this._keysCached(this._uid.toString(), this.results);
1764
- value = args[0];
1765
- cb = args[1];
1766
- }
1767
- } else if (args.length === 1) {
1768
- validators = this._keysCached(this._uid.toString(), this.results);
1769
- value = this.getValue();
1770
- cb = args[0];
1771
- } else {
1772
- validators = this._keysCached(this._uid.toString(), this.results);
1773
- value = this.getValue();
1774
- cb = null;
1775
- }
1776
-
1777
- if (args.length === 3 || (args.length === 2 && isPlainObject(args[0]))) {
1778
- ret = this._validate(validators[0], value, cb);
1779
- } else {
1780
- validators.forEach(function (validator) {
1781
- ret = this$1._validate(validator, value, cb);
1782
- });
1783
- }
1784
-
1785
- return ret
1786
- }
1787
-
1788
- return {
1789
- _resolveValidator: _resolveValidator,
1790
- _getValidateRawDescriptor: _getValidateRawDescriptor,
1791
- _getValidateDescriptors: _getValidateDescriptors,
1792
- _resolveMessage: _resolveMessage,
1793
- _invokeValidator: _invokeValidator,
1794
- _validate: _validate,
1795
- _syncValidates: _syncValidates,
1796
- validate: validate
1797
- }
1798
- };
1799
-
1800
- /* */
1801
-
1802
- var Methods = function (Vue) {
1803
- var ref = Vue.util;
1804
- var extend = ref.extend;
1805
-
1806
- var methods = {};
1807
- extend(methods, Event(Vue));
1808
- extend(methods, State(Vue));
1809
- extend(methods, Validate(Vue));
1810
-
1811
- return methods
1812
- };
1813
-
1814
- /* */
1815
-
1816
- var ValidityControl = function (Vue) {
1817
- var ref = Vue.util;
1818
- var extend = ref.extend;
1819
-
1820
- var ref$1 = States(Vue);
1821
- var props = ref$1.props;
1822
- var data = ref$1.data;
1823
- var computed = Computed(Vue);
1824
- var lifecycles = Lifecycles(Vue);
1825
- var ref$2 = Render(Vue);
1826
- var render = ref$2.render;
1827
- var methods = Methods(Vue);
1828
-
1829
- var validity = {
1830
- props: props,
1831
- data: data,
1832
- render: render,
1833
- computed: computed,
1834
- methods: methods
1835
- };
1836
- extend(validity, lifecycles);
1837
-
1838
- return validity
1839
- };
1840
-
1841
- /* */
1842
- var Validity = function (Vue) {
1843
- var ref = Vue.util;
1844
- var extend = ref.extend;
1845
-
1846
- return {
1847
- functional: true,
1848
- props: baseProps,
1849
- render: function render (
1850
- h,
1851
- ref
1852
- ) {
1853
- var props = ref.props;
1854
- var data = ref.data;
1855
- var children = ref.children;
1856
-
1857
- return children.map(function (child) {
1858
- if (!child.tag) { return child }
1859
- var newData = extend({}, data);
1860
- newData.props = extend({}, props);
1861
- // TODO: should be refactored
1862
- newData.props.classes = extend(extend(extend({}, DEFAULT_CLASSES), Vue.config.validator.classes), newData.props.classes);
1863
- newData.props.child = child;
1864
- return h('validity-control', newData)
1865
- })
1866
- }
1867
- }
1868
- };
1869
-
1870
- /* */
1871
- var ValidityGroup = function (Vue) {
1872
- var ref = Vue.util;
1873
- var extend = ref.extend;
1874
-
1875
- var props = extend({
1876
- tag: {
1877
- type: String,
1878
- default: 'fieldset'
1879
- }
1880
- }, baseProps);
1881
-
1882
- return {
1883
- functional: true,
1884
- props: props,
1885
- render: function render (
1886
- h,
1887
- ref
1888
- ) {
1889
- var props = ref.props;
1890
- var data = ref.data;
1891
- var children = ref.children;
1892
-
1893
- var child = h(props.tag, children);
1894
- var newData = extend({}, data);
1895
- newData.props = extend({}, props);
1896
- // TODO: should be refactored
1897
- newData.props.classes = extend(extend(extend({}, DEFAULT_CLASSES), Vue.config.validator.classes), newData.props.classes);
1898
- newData.props.child = child;
1899
- newData.props.multiple = true;
1900
- return h('validity-control', newData)
1901
- }
1902
- }
1903
- };
1904
-
1905
- /* */
1906
-
1907
- var Validation = function (Vue) {
1908
- var ref = Vue.util;
1909
- var extend = ref.extend;
1910
-
1911
- return {
1912
- functional: true,
1913
- props: {
1914
- name: {
1915
- type: String
1916
- },
1917
- tag: {
1918
- type: String,
1919
- default: 'form'
1920
- }
1921
- },
1922
- render: function render (
1923
- h,
1924
- ref
1925
- ) {
1926
- var props = ref.props;
1927
- var data = ref.data;
1928
- var parent = ref.parent;
1929
- var children = ref.children;
1930
- var slots = ref.slots;
1931
-
1932
- if (!parent._validation) {
1933
- // TODO: should be warned
1934
- return children
1935
- }
1936
- var tag = props.tag || 'form';
1937
- walkChildren(parent._validation, props.name, children);
1938
- var newData = extend({ attrs: {}}, data);
1939
- if (tag === 'form') {
1940
- newData.attrs.novalidate = true;
1941
- }
1942
- return h(tag, newData, children)
1943
- }
1944
- }
1945
- };
1946
-
1947
- function walkChildren (validation, name, children) {
1948
- children.forEach(function (child) {
1949
- if (child &&
1950
- child.componentOptions &&
1951
- child.componentOptions.propsData && child.componentOptions.tag === 'validity-control') {
1952
- child.componentOptions.propsData.validation = {
1953
- instance: validation,
1954
- name: name
1955
- };
1956
- }
1957
- child.children && walkChildren(validation, name, child.children);
1958
- });
1959
- }
1960
-
1961
- /* */
1962
- var Component = function (Vue) {
1963
- return {
1964
- 'validity-control': ValidityControl(Vue),
1965
- 'validity': Validity(Vue),
1966
- 'validity-group': ValidityGroup(Vue),
1967
- 'validation': Validation(Vue)
1968
- }
1969
- };
1970
-
1971
- /* */
1972
- // TODO: should be defined strict type
1973
- function mapValidation (results) {
1974
- var res = {};
1975
-
1976
- normalizeMap(results).forEach(function (ref) {
1977
- var key = ref.key;
1978
- var val = ref.val;
1979
-
1980
- res[key] = function mappedValidation () {
1981
- var validation = this.$validation;
1982
- if (!this._isMounted) {
1983
- return null
1984
- }
1985
- var paths = val.split('.');
1986
- var first = paths.shift();
1987
- if (first !== '$validation') {
1988
- warn(("unknown validation result path: " + val));
1989
- return null
1990
- }
1991
- var path;
1992
- var value = validation;
1993
- do {
1994
- path = paths.shift();
1995
- value = value[path];
1996
- } while (paths.length > 0 && value !== undefined)
1997
- return value
1998
- };
1999
- });
2000
-
2001
- return res
2002
- }
2003
-
2004
- // TODO: should be defined strict type
2005
- function normalizeMap (map) {
2006
- return Array.isArray(map)
2007
- ? map.map(function (key) { return ({ key: key, val: key }); })
2008
- : Object.keys(map).map(function (key) { return ({ key: key, val: map[key] }); })
2009
- }
2010
-
2011
- /* */
2012
- var installed = false;
2013
-
2014
- function plugin (Vue, options) {
2015
- if ( options === void 0 ) options = {};
2016
-
2017
- if (installed) {
2018
- warn('already installed.');
2019
- return
2020
- }
2021
-
2022
- Config(Vue);
2023
- Asset(Vue);
2024
- installMixin(Vue);
2025
- installComponent(Vue);
2026
- installed = true;
2027
- }
2028
-
2029
- function installMixin (Vue) {
2030
- Vue.mixin(Mixin(Vue));
2031
- }
2032
-
2033
- function installComponent (Vue) {
2034
- var components = Component(Vue);
2035
- Object.keys(components).forEach(function (id) {
2036
- Vue.component(id, components[id]);
2037
- });
2038
- }
2039
-
2040
- plugin.mapValidation = mapValidation; // for standalone
2041
- plugin.version = '3.0.0-alpha.2';
2042
-
2043
- if (typeof window !== 'undefined' && window.Vue) {
2044
- window.Vue.use(plugin);
2045
- }
2046
-
2047
- var index = {
2048
- install: plugin,
2049
- mapValidation: mapValidation
2050
- };
2051
-
2052
- return index;
2053
-
2054
- })));
910
+ ;