vueonrails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +70 -0
- data/app/controllers/vue_controller.rb +2 -0
- data/app/helpers/syntax_helper.rb +28 -0
- data/app/views/vue/index.html.erb +1 -0
- data/config/routes.rb +5 -0
- data/lib/generators/generator_templates/packs/index.css +4 -0
- data/lib/generators/generator_templates/packs/index.js +30 -0
- data/lib/generators/generator_templates/packs/index.vue +13 -0
- data/lib/generators/generator_templates/packs/pack.js.erb +18 -0
- data/lib/generators/generator_templates/sfc/single-file-component.vue +45 -0
- data/lib/generators/generator_templates/tests/unit.test.js.erb +17 -0
- data/lib/generators/generator_templates/turbolinks/turbolinks-pack.js.erb +23 -0
- data/lib/generators/options/click.rb +10 -0
- data/lib/generators/options/form.rb +19 -0
- data/lib/generators/options/list.rb +32 -0
- data/lib/generators/options/modal.rb +26 -0
- data/lib/generators/options/seperate.rb +5 -0
- data/lib/generators/options/single.rb +3 -0
- data/lib/generators/options/table.rb +10 -0
- data/lib/generators/options/test.rb +2 -0
- data/lib/generators/options/turbolinks-seperate.rb +5 -0
- data/lib/generators/options/turbolinks-single.rb +3 -0
- data/lib/generators/options/vuex.rb +10 -0
- data/lib/generators/vue/USAGE +17 -0
- data/lib/generators/vue/vue_generator.rb +60 -0
- data/lib/install/Procfile +2 -0
- data/lib/install/config/alias.js +9 -0
- data/lib/install/setup.rb +78 -0
- data/lib/install/spv.rb +20 -0
- data/lib/install/test.rb +46 -0
- data/lib/install/turbolinks.rb +3 -0
- data/lib/install/ui.rb +4 -0
- data/lib/install/vuex.rb +12 -0
- data/lib/tasks/assets.rake +12 -0
- data/lib/tasks/info.rake +21 -0
- data/lib/tasks/vue.rake +27 -0
- data/lib/vueonrails.rb +13 -0
- data/lib/vueonrails/post_message.rb +4 -0
- data/lib/vueonrails/version.rb +3 -0
- data/vendor/assets/javascripts/axios.js +1545 -0
- data/vendor/assets/javascripts/axios.map +1 -0
- data/vendor/assets/javascripts/element-ui.js +12 -0
- data/vendor/assets/javascripts/vue-resource.js +1531 -0
- data/vendor/assets/javascripts/vue-router.js +2709 -0
- data/vendor/assets/javascripts/vue-router2.js +2284 -0
- data/vendor/assets/javascripts/vue-validator.js +910 -0
- data/vendor/assets/javascripts/vue-validator2.js +2615 -0
- data/vendor/assets/javascripts/vue-validator3.js +2054 -0
- data/vendor/assets/javascripts/vue.js +10237 -0
- data/vendor/assets/javascripts/vue.min.js +9 -0
- data/vendor/assets/javascripts/vue2.js +8568 -0
- data/vendor/assets/javascripts/vue2.min.js +8 -0
- data/vendor/assets/javascripts/vueonrails.js +39 -0
- data/vendor/assets/javascripts/vuex.js +722 -0
- data/vendor/assets/javascripts/vuex2.js +805 -0
- data/vendor/assets/stylesheets/element-ui.css +1 -0
- metadata +128 -0
@@ -0,0 +1,2054 @@
|
|
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
|
+
/**
|
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.
|
132
|
+
*/
|
133
|
+
function max (val, arg) {
|
134
|
+
return !isNaN(+(val)) && !isNaN(+(arg)) && (+(val) <= +(arg))
|
135
|
+
}
|
136
|
+
|
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
|
153
|
+
});
|
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
|
+
})));
|