node_modules

This commit is contained in:
saeid
2019-07-15 13:07:31 +04:30
parent d3735c6d30
commit ce1a3ebf9c
35713 changed files with 3639219 additions and 1 deletions
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016 Monterail
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+137
View File
@@ -0,0 +1,137 @@
# vuelidate
[![codecov](https://codecov.io/gh/monterail/vuelidate/branch/master/graph/badge.svg)](https://codecov.io/gh/monterail/vuelidate)
![gzip size](http://img.badgesize.io/monterail/vuelidate/master/dist/vuelidate.min.js.svg?compression=gzip)
> Simple, lightweight model-based validation for Vue.js
### Features & characteristics:
* Model based
* Decoupled from templates
* Dependency free, minimalistic library
* Support for collection validations
* Support for nested models
* Contextified validators
* Easy to use with custom validators (e.g. Moment.js)
* Support for function composition
* Validates different data sources: Vuex getters, computed values, etc.
## Demo & docs
[http://monterail.github.io/vuelidate/](http://monterail.github.io/vuelidate/)
## Installation
```bash
npm install vuelidate --save
```
You can import the library and use as a Vue plugin to enable the functionality globally on all components containing validation configuration.
```javascript
import Vue from 'vue'
import Vuelidate from 'vuelidate'
Vue.use(Vuelidate)
```
Alternatively it is possible to import a mixin directly to components in which it will be used.
```javascript
import { validationMixin } from 'vuelidate'
var Component = Vue.extend({
mixins: [validationMixin],
validations: { ... }
})
```
The browser-ready bundle is also provided in the package.
```html
<script src="vuelidate/dist/vuelidate.min.js"></script>
<!-- The builtin validators is added by adding the following line. -->
<script src="vuelidate/dist/validators.min.js"></script>
```
```javascript
Vue.use(window.vuelidate.default)
```
## Basic usage
For each value you want to validate, you have to create a key inside validations options. You can specify when input becomes dirty by using appropriate event on your input box.
```javascript
import { required, minLength, between } from 'vuelidate/lib/validators'
export default {
data () {
return {
name: '',
age: 0
}
},
validations: {
name: {
required,
minLength: minLength(4)
},
age: {
between: between(20, 30)
}
}
}
```
This will result in a validation object:
```javascript
$v: {
name: {
"required": false,
"minLength": false,
"$invalid": true,
"$dirty": false,
"$error": false,
"$pending": false
},
age: {
"between": false
"$invalid": true,
"$dirty": false,
"$error": false,
"$pending": false
}
}
```
Checkout the docs for more examples: [https://monterail.github.io/vuelidate/](https://monterail.github.io/vuelidate/)
## Contributing
``` bash
# install dependencies
npm install
# serve with hot reload at localhost:8080
npm run dev
# create UMD bundle.
npm run build
# Create docs inside /gh-pages ready to be published
npm run docs
# run unit tests
npm run unit
# run all tests
npm test
```
For detailed explanation on how things work, checkout the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
## License
[MIT](http://opensource.org/licenses/MIT)
Copyright (c) 2016 Paweł Grabarz & Damian Dulisz
File diff suppressed because one or more lines are too long
+1
View File
File diff suppressed because one or more lines are too long
+675
View File
@@ -0,0 +1,675 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Vuelidate = Vuelidate;
Object.defineProperty(exports, "withParams", {
enumerable: true,
get: function get() {
return _params.withParams;
}
});
exports.default = exports.validationMixin = void 0;
var _vval = require("./vval");
var _params = require("./params");
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
var NIL = function NIL() {
return null;
};
var buildFromKeys = function buildFromKeys(keys, fn, keyFn) {
return keys.reduce(function (build, key) {
build[keyFn ? keyFn(key) : key] = fn(key);
return build;
}, {});
};
function isFunction(val) {
return typeof val === 'function';
}
function isObject(val) {
return val !== null && (_typeof(val) === 'object' || isFunction(val));
}
function isPromise(object) {
return isObject(object) && isFunction(object.then);
}
var getPath = function getPath(ctx, obj, path, fallback) {
if (typeof path === 'function') {
return path.call(ctx, obj, fallback);
}
path = Array.isArray(path) ? path : path.split('.');
for (var i = 0; i < path.length; i++) {
if (obj && _typeof(obj) === 'object') {
obj = obj[path[i]];
} else {
return fallback;
}
}
return typeof obj === 'undefined' ? fallback : obj;
};
var __isVuelidateAsyncVm = '__isVuelidateAsyncVm';
function makePendingAsyncVm(Vue, promise) {
var asyncVm = new Vue({
data: {
p: true,
v: false
}
});
promise.then(function (value) {
asyncVm.p = false;
asyncVm.v = value;
}, function (error) {
asyncVm.p = false;
asyncVm.v = false;
throw error;
});
asyncVm[__isVuelidateAsyncVm] = true;
return asyncVm;
}
var validationGetters = {
$invalid: function $invalid() {
var _this = this;
var proxy = this.proxy;
return this.nestedKeys.some(function (nested) {
return _this.refProxy(nested).$invalid;
}) || this.ruleKeys.some(function (rule) {
return !proxy[rule];
});
},
$dirty: function $dirty() {
var _this2 = this;
if (this.dirty) {
return true;
}
if (this.nestedKeys.length === 0) {
return false;
}
return this.nestedKeys.every(function (key) {
return _this2.refProxy(key).$dirty;
});
},
$anyDirty: function $anyDirty() {
var _this3 = this;
if (this.dirty) {
return true;
}
if (this.nestedKeys.length === 0) {
return false;
}
return this.nestedKeys.some(function (key) {
return _this3.refProxy(key).$anyDirty;
});
},
$error: function $error() {
return this.$dirty && !this.$pending && this.$invalid;
},
$anyError: function $anyError() {
return this.$anyDirty && !this.$pending && this.$invalid;
},
$pending: function $pending() {
var _this4 = this;
return this.ruleKeys.some(function (key) {
return _this4.getRef(key).$pending;
}) || this.nestedKeys.some(function (key) {
return _this4.refProxy(key).$pending;
});
},
$params: function $params() {
var _this5 = this;
var vals = this.validations;
return _objectSpread({}, buildFromKeys(this.nestedKeys, function (key) {
return vals[key] && vals[key].$params || null;
}), buildFromKeys(this.ruleKeys, function (key) {
return _this5.getRef(key).$params;
}));
}
};
function setDirtyRecursive(newState) {
this.dirty = newState;
var proxy = this.proxy;
var method = newState ? '$touch' : '$reset';
this.nestedKeys.forEach(function (key) {
proxy[key][method]();
});
}
var validationMethods = {
$touch: function $touch() {
setDirtyRecursive.call(this, true);
},
$reset: function $reset() {
setDirtyRecursive.call(this, false);
},
$flattenParams: function $flattenParams() {
var proxy = this.proxy;
var params = [];
for (var key in this.$params) {
if (this.isNested(key)) {
var childParams = proxy[key].$flattenParams();
for (var j = 0; j < childParams.length; j++) {
childParams[j].path.unshift(key);
}
params = params.concat(childParams);
} else {
params.push({
path: [],
name: key,
params: this.$params[key]
});
}
}
return params;
}
};
var getterNames = Object.keys(validationGetters);
var methodNames = Object.keys(validationMethods);
var _cachedComponent = null;
var getComponent = function getComponent(Vue) {
if (_cachedComponent) {
return _cachedComponent;
}
var VBase = Vue.extend({
computed: {
refs: function refs() {
var oldVval = this._vval;
this._vval = this.children;
(0, _vval.patchChildren)(oldVval, this._vval);
var refs = {};
this._vval.forEach(function (c) {
refs[c.key] = c.vm;
});
return refs;
}
},
beforeCreate: function beforeCreate() {
this._vval = null;
},
beforeDestroy: function beforeDestroy() {
if (this._vval) {
(0, _vval.patchChildren)(this._vval);
this._vval = null;
}
},
methods: {
getModel: function getModel() {
return this.lazyModel ? this.lazyModel(this.prop) : this.model;
},
getModelKey: function getModelKey(key) {
var model = this.getModel();
if (model) {
return model[key];
}
},
hasIter: function hasIter() {
return false;
}
}
});
var ValidationRule = VBase.extend({
data: function data() {
return {
rule: null,
lazyModel: null,
model: null,
lazyParentModel: null,
rootModel: null
};
},
methods: {
runRule: function runRule(parent) {
var model = this.getModel();
(0, _params.pushParams)();
var rawOutput = this.rule.call(this.rootModel, model, parent);
var output = isPromise(rawOutput) ? makePendingAsyncVm(Vue, rawOutput) : rawOutput;
var rawParams = (0, _params.popParams)();
var params = rawParams && rawParams.$sub ? rawParams.$sub.length > 1 ? rawParams : rawParams.$sub[0] : null;
return {
output: output,
params: params
};
}
},
computed: {
run: function run() {
var _this6 = this;
var parent = this.lazyParentModel();
var isArrayDependant = Array.isArray(parent) && parent.__ob__;
if (isArrayDependant) {
var arrayDep = parent.__ob__.dep;
arrayDep.depend();
var target = arrayDep.constructor.target;
if (!this._indirectWatcher) {
var Watcher = target.constructor;
this._indirectWatcher = new Watcher(this, function () {
return _this6.runRule(parent);
}, null, {
lazy: true
});
}
var model = this.getModel();
if (!this._indirectWatcher.dirty && this._lastModel === model) {
this._indirectWatcher.depend();
return target.value;
}
this._lastModel = model;
this._indirectWatcher.evaluate();
this._indirectWatcher.depend();
} else if (this._indirectWatcher) {
this._indirectWatcher.teardown();
this._indirectWatcher = null;
}
return this._indirectWatcher ? this._indirectWatcher.value : this.runRule(parent);
},
$params: function $params() {
return this.run.params;
},
proxy: function proxy() {
var output = this.run.output;
if (output[__isVuelidateAsyncVm]) {
return !!output.v;
}
return !!output;
},
$pending: function $pending() {
var output = this.run.output;
if (output[__isVuelidateAsyncVm]) {
return output.p;
}
return false;
}
},
destroyed: function destroyed() {
if (this._indirectWatcher) {
this._indirectWatcher.teardown();
this._indirectWatcher = null;
}
}
});
var Validation = VBase.extend({
data: function data() {
return {
dirty: false,
validations: null,
lazyModel: null,
model: null,
prop: null,
lazyParentModel: null,
rootModel: null
};
},
methods: _objectSpread({}, validationMethods, {
refProxy: function refProxy(key) {
return this.getRef(key).proxy;
},
getRef: function getRef(key) {
return this.refs[key];
},
isNested: function isNested(key) {
return typeof this.validations[key] !== 'function';
}
}),
computed: _objectSpread({}, validationGetters, {
nestedKeys: function nestedKeys() {
return this.keys.filter(this.isNested);
},
ruleKeys: function ruleKeys() {
var _this7 = this;
return this.keys.filter(function (k) {
return !_this7.isNested(k);
});
},
keys: function keys() {
return Object.keys(this.validations).filter(function (k) {
return k !== '$params';
});
},
proxy: function proxy() {
var _this8 = this;
var keyDefs = buildFromKeys(this.keys, function (key) {
return {
enumerable: true,
configurable: true,
get: function get() {
return _this8.refProxy(key);
}
};
});
var getterDefs = buildFromKeys(getterNames, function (key) {
return {
enumerable: true,
configurable: true,
get: function get() {
return _this8[key];
}
};
});
var methodDefs = buildFromKeys(methodNames, function (key) {
return {
enumerable: false,
configurable: true,
get: function get() {
return _this8[key];
}
};
});
var iterDefs = this.hasIter() ? {
$iter: {
enumerable: true,
value: Object.defineProperties({}, _objectSpread({}, keyDefs))
}
} : {};
return Object.defineProperties({}, _objectSpread({}, keyDefs, iterDefs, {
$model: {
enumerable: true,
get: function get() {
var parent = _this8.lazyParentModel();
if (parent != null) {
return parent[_this8.prop];
} else {
return null;
}
},
set: function set(value) {
var parent = _this8.lazyParentModel();
if (parent != null) {
parent[_this8.prop] = value;
_this8.$touch();
}
}
}
}, getterDefs, methodDefs));
},
children: function children() {
var _this9 = this;
return _toConsumableArray(this.nestedKeys.map(function (key) {
return renderNested(_this9, key);
})).concat(_toConsumableArray(this.ruleKeys.map(function (key) {
return renderRule(_this9, key);
}))).filter(Boolean);
}
})
});
var GroupValidation = Validation.extend({
methods: {
isNested: function isNested(key) {
return typeof this.validations[key]() !== 'undefined';
},
getRef: function getRef(key) {
var vm = this;
return {
get proxy() {
return vm.validations[key]() || false;
}
};
}
}
});
var EachValidation = Validation.extend({
computed: {
keys: function keys() {
var model = this.getModel();
if (isObject(model)) {
return Object.keys(model);
} else {
return [];
}
},
tracker: function tracker() {
var _this10 = this;
var trackBy = this.validations.$trackBy;
return trackBy ? function (key) {
return "".concat(getPath(_this10.rootModel, _this10.getModelKey(key), trackBy));
} : function (x) {
return "".concat(x);
};
},
getModelLazy: function getModelLazy() {
var _this11 = this;
return function () {
return _this11.getModel();
};
},
children: function children() {
var _this12 = this;
var def = this.validations;
var model = this.getModel();
var validations = _objectSpread({}, def);
delete validations['$trackBy'];
var usedTracks = {};
return this.keys.map(function (key) {
var track = _this12.tracker(key);
if (usedTracks.hasOwnProperty(track)) {
return null;
}
usedTracks[track] = true;
return (0, _vval.h)(Validation, track, {
validations: validations,
prop: key,
lazyParentModel: _this12.getModelLazy,
model: model[key],
rootModel: _this12.rootModel
});
}).filter(Boolean);
}
},
methods: {
isNested: function isNested() {
return true;
},
getRef: function getRef(key) {
return this.refs[this.tracker(key)];
},
hasIter: function hasIter() {
return true;
}
}
});
var renderNested = function renderNested(vm, key) {
if (key === '$each') {
return (0, _vval.h)(EachValidation, key, {
validations: vm.validations[key],
lazyParentModel: vm.lazyParentModel,
prop: key,
lazyModel: vm.getModel,
rootModel: vm.rootModel
});
}
var validations = vm.validations[key];
if (Array.isArray(validations)) {
var root = vm.rootModel;
var refVals = buildFromKeys(validations, function (path) {
return function () {
return getPath(root, root.$v, path);
};
}, function (v) {
return Array.isArray(v) ? v.join('.') : v;
});
return (0, _vval.h)(GroupValidation, key, {
validations: refVals,
lazyParentModel: NIL,
prop: key,
lazyModel: NIL,
rootModel: root
});
}
return (0, _vval.h)(Validation, key, {
validations: validations,
lazyParentModel: vm.getModel,
prop: key,
lazyModel: vm.getModelKey,
rootModel: vm.rootModel
});
};
var renderRule = function renderRule(vm, key) {
return (0, _vval.h)(ValidationRule, key, {
rule: vm.validations[key],
lazyParentModel: vm.lazyParentModel,
lazyModel: vm.getModel,
rootModel: vm.rootModel
});
};
_cachedComponent = {
VBase: VBase,
Validation: Validation
};
return _cachedComponent;
};
var _cachedVue = null;
function getVue(rootVm) {
if (_cachedVue) return _cachedVue;
var Vue = rootVm.constructor;
while (Vue.super) {
Vue = Vue.super;
}
_cachedVue = Vue;
return Vue;
}
var validateModel = function validateModel(model, validations) {
var Vue = getVue(model);
var _getComponent = getComponent(Vue),
Validation = _getComponent.Validation,
VBase = _getComponent.VBase;
var root = new VBase({
computed: {
children: function children() {
var vals = typeof validations === 'function' ? validations.call(model) : validations;
return [(0, _vval.h)(Validation, '$v', {
validations: vals,
lazyParentModel: NIL,
prop: '$v',
model: model,
rootModel: model
})];
}
}
});
return root;
};
var validationMixin = {
data: function data() {
var vals = this.$options.validations;
if (vals) {
this._vuelidate = validateModel(this, vals);
}
return {};
},
beforeCreate: function beforeCreate() {
var options = this.$options;
var vals = options.validations;
if (!vals) return;
if (!options.computed) options.computed = {};
if (options.computed.$v) return;
options.computed.$v = function () {
return this._vuelidate ? this._vuelidate.refs.$v.proxy : null;
};
},
beforeDestroy: function beforeDestroy() {
if (this._vuelidate) {
this._vuelidate.$destroy();
this._vuelidate = null;
}
}
};
exports.validationMixin = validationMixin;
function Vuelidate(Vue) {
Vue.mixin(validationMixin);
}
var _default = Vuelidate;
exports.default = _default;
+95
View File
@@ -0,0 +1,95 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.pushParams = pushParams;
exports.popParams = popParams;
exports.withParams = withParams;
exports._setTarget = exports.target = void 0;
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
var stack = [];
var target = null;
exports.target = target;
var _setTarget = function _setTarget(x) {
exports.target = target = x;
};
exports._setTarget = _setTarget;
function pushParams() {
if (target !== null) {
stack.push(target);
}
exports.target = target = {};
}
function popParams() {
var lastTarget = target;
var newTarget = exports.target = target = stack.pop() || null;
if (newTarget) {
if (!Array.isArray(newTarget.$sub)) {
newTarget.$sub = [];
}
newTarget.$sub.push(lastTarget);
}
return lastTarget;
}
function addParams(params) {
if (_typeof(params) === 'object' && !Array.isArray(params)) {
exports.target = target = _objectSpread({}, target, params);
} else {
throw new Error('params must be an object');
}
}
function withParamsDirect(params, validator) {
return withParamsClosure(function (add) {
return function () {
add(params);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return validator.apply(this, args);
};
});
}
function withParamsClosure(closure) {
var validator = closure(addParams);
return function () {
pushParams();
try {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return validator.apply(this, args);
} finally {
popParams();
}
};
}
function withParams(paramsOrClosure, maybeValidator) {
if (_typeof(paramsOrClosure) === 'object' && maybeValidator !== undefined) {
return withParamsDirect(paramsOrClosure, maybeValidator);
}
return withParamsClosure(paramsOrClosure);
}
+12
View File
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _common = require("./common");
var _default = (0, _common.regex)('alpha', /^[a-zA-Z]*$/);
exports.default = _default;
+12
View File
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _common = require("./common");
var _default = (0, _common.regex)('alphaNum', /^[a-zA-Z0-9]*$/);
exports.default = _default;
+30
View File
@@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _common = require("./common");
var _default = function _default() {
for (var _len = arguments.length, validators = new Array(_len), _key = 0; _key < _len; _key++) {
validators[_key] = arguments[_key];
}
return (0, _common.withParams)({
type: 'and'
}, function () {
var _this = this;
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return validators.length > 0 && validators.reduce(function (valid, fn) {
return valid && fn.apply(_this, args);
}, true);
});
};
exports.default = _default;
+20
View File
@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _common = require("./common");
var _default = function _default(min, max) {
return (0, _common.withParams)({
type: 'between',
min: min,
max: max
}, function (value) {
return !(0, _common.req)(value) || (!/\s/.test(value) || value instanceof Date) && +min <= +value && +max >= +value;
});
};
exports.default = _default;
+74
View File
@@ -0,0 +1,74 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "withParams", {
enumerable: true,
get: function get() {
return _withParams.default;
}
});
exports.regex = exports.ref = exports.len = exports.req = void 0;
var _withParams = _interopRequireDefault(require("../withParams"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
var req = function req(value) {
if (Array.isArray(value)) return !!value.length;
if (value === undefined || value === null) {
return false;
}
if (value === false) {
return true;
}
if (value instanceof Date) {
return !isNaN(value.getTime());
}
if (_typeof(value) === 'object') {
for (var _ in value) {
return true;
}
return false;
}
return !!String(value).length;
};
exports.req = req;
var len = function len(value) {
if (Array.isArray(value)) return value.length;
if (_typeof(value) === 'object') {
return Object.keys(value).length;
}
return String(value).length;
};
exports.len = len;
var ref = function ref(reference, vm, parentVm) {
return typeof reference === 'function' ? reference.call(vm, parentVm) : parentVm[reference];
};
exports.ref = ref;
var regex = function regex(type, expr) {
return (0, _withParams.default)({
type: type
}, function (value) {
return !req(value) || expr.test(value);
});
};
exports.regex = regex;
+12
View File
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _common = require("./common");
var _default = (0, _common.regex)('decimal', /^[-]?\d*(\.\d+)?$/);
exports.default = _default;
+14
View File
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _common = require("./common");
var emailRegex = /(^$|^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$)/;
var _default = (0, _common.regex)('email', emailRegex);
exports.default = _default;
+182
View File
@@ -0,0 +1,182 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "alpha", {
enumerable: true,
get: function get() {
return _alpha.default;
}
});
Object.defineProperty(exports, "alphaNum", {
enumerable: true,
get: function get() {
return _alphaNum.default;
}
});
Object.defineProperty(exports, "numeric", {
enumerable: true,
get: function get() {
return _numeric.default;
}
});
Object.defineProperty(exports, "between", {
enumerable: true,
get: function get() {
return _between.default;
}
});
Object.defineProperty(exports, "email", {
enumerable: true,
get: function get() {
return _email.default;
}
});
Object.defineProperty(exports, "ipAddress", {
enumerable: true,
get: function get() {
return _ipAddress.default;
}
});
Object.defineProperty(exports, "macAddress", {
enumerable: true,
get: function get() {
return _macAddress.default;
}
});
Object.defineProperty(exports, "maxLength", {
enumerable: true,
get: function get() {
return _maxLength.default;
}
});
Object.defineProperty(exports, "minLength", {
enumerable: true,
get: function get() {
return _minLength.default;
}
});
Object.defineProperty(exports, "required", {
enumerable: true,
get: function get() {
return _required.default;
}
});
Object.defineProperty(exports, "requiredIf", {
enumerable: true,
get: function get() {
return _requiredIf.default;
}
});
Object.defineProperty(exports, "requiredUnless", {
enumerable: true,
get: function get() {
return _requiredUnless.default;
}
});
Object.defineProperty(exports, "sameAs", {
enumerable: true,
get: function get() {
return _sameAs.default;
}
});
Object.defineProperty(exports, "url", {
enumerable: true,
get: function get() {
return _url.default;
}
});
Object.defineProperty(exports, "or", {
enumerable: true,
get: function get() {
return _or.default;
}
});
Object.defineProperty(exports, "and", {
enumerable: true,
get: function get() {
return _and.default;
}
});
Object.defineProperty(exports, "not", {
enumerable: true,
get: function get() {
return _not.default;
}
});
Object.defineProperty(exports, "minValue", {
enumerable: true,
get: function get() {
return _minValue.default;
}
});
Object.defineProperty(exports, "maxValue", {
enumerable: true,
get: function get() {
return _maxValue.default;
}
});
Object.defineProperty(exports, "integer", {
enumerable: true,
get: function get() {
return _integer.default;
}
});
Object.defineProperty(exports, "decimal", {
enumerable: true,
get: function get() {
return _decimal.default;
}
});
exports.helpers = void 0;
var _alpha = _interopRequireDefault(require("./alpha"));
var _alphaNum = _interopRequireDefault(require("./alphaNum"));
var _numeric = _interopRequireDefault(require("./numeric"));
var _between = _interopRequireDefault(require("./between"));
var _email = _interopRequireDefault(require("./email"));
var _ipAddress = _interopRequireDefault(require("./ipAddress"));
var _macAddress = _interopRequireDefault(require("./macAddress"));
var _maxLength = _interopRequireDefault(require("./maxLength"));
var _minLength = _interopRequireDefault(require("./minLength"));
var _required = _interopRequireDefault(require("./required"));
var _requiredIf = _interopRequireDefault(require("./requiredIf"));
var _requiredUnless = _interopRequireDefault(require("./requiredUnless"));
var _sameAs = _interopRequireDefault(require("./sameAs"));
var _url = _interopRequireDefault(require("./url"));
var _or = _interopRequireDefault(require("./or"));
var _and = _interopRequireDefault(require("./and"));
var _not = _interopRequireDefault(require("./not"));
var _minValue = _interopRequireDefault(require("./minValue"));
var _maxValue = _interopRequireDefault(require("./maxValue"));
var _integer = _interopRequireDefault(require("./integer"));
var _decimal = _interopRequireDefault(require("./decimal"));
var helpers = _interopRequireWildcard(require("./common"));
exports.helpers = helpers;
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+12
View File
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _common = require("./common");
var _default = (0, _common.regex)('integer', /^-?[0-9]*$/);
exports.default = _default;
+42
View File
@@ -0,0 +1,42 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _common = require("./common");
var _default = (0, _common.withParams)({
type: 'ipAddress'
}, function (value) {
if (!(0, _common.req)(value)) {
return true;
}
if (typeof value !== 'string') {
return false;
}
var nibbles = value.split('.');
return nibbles.length === 4 && nibbles.every(nibbleValid);
});
exports.default = _default;
var nibbleValid = function nibbleValid(nibble) {
if (nibble.length > 3 || nibble.length === 0) {
return false;
}
if (nibble[0] === '0' && nibble !== '0') {
return false;
}
if (!nibble.match(/^\d+$/)) {
return false;
}
var numeric = +nibble | 0;
return numeric >= 0 && numeric <= 255;
};
+32
View File
@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _common = require("./common");
var _default = function _default() {
var separator = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ':';
return (0, _common.withParams)({
type: 'macAddress'
}, function (value) {
if (!(0, _common.req)(value)) {
return true;
}
if (typeof value !== 'string') {
return false;
}
var parts = typeof separator === 'string' && separator !== '' ? value.split(separator) : value.length === 12 || value.length === 16 ? value.match(/.{2}/g) : null;
return parts !== null && (parts.length === 6 || parts.length === 8) && parts.every(hexValid);
});
};
exports.default = _default;
var hexValid = function hexValid(hex) {
return hex.toLowerCase().match(/^[0-9a-f]{2}$/);
};
+19
View File
@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _common = require("./common");
var _default = function _default(length) {
return (0, _common.withParams)({
type: 'maxLength',
max: length
}, function (value) {
return !(0, _common.req)(value) || (0, _common.len)(value) <= length;
});
};
exports.default = _default;
+19
View File
@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _common = require("./common");
var _default = function _default(max) {
return (0, _common.withParams)({
type: 'maxValue',
max: max
}, function (value) {
return !(0, _common.req)(value) || (!/\s/.test(value) || value instanceof Date) && +value <= +max;
});
};
exports.default = _default;
+19
View File
@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _common = require("./common");
var _default = function _default(length) {
return (0, _common.withParams)({
type: 'minLength',
min: length
}, function (value) {
return !(0, _common.req)(value) || (0, _common.len)(value) >= length;
});
};
exports.default = _default;
+19
View File
@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _common = require("./common");
var _default = function _default(min) {
return (0, _common.withParams)({
type: 'minValue',
min: min
}, function (value) {
return !(0, _common.req)(value) || (!/\s/.test(value) || value instanceof Date) && +value >= +min;
});
};
exports.default = _default;
+18
View File
@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _common = require("./common");
var _default = function _default(validator) {
return (0, _common.withParams)({
type: 'not'
}, function (value, vm) {
return !(0, _common.req)(value) || !validator.call(this, value, vm);
});
};
exports.default = _default;
+12
View File
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _common = require("./common");
var _default = (0, _common.regex)('numeric', /^[0-9]*$/);
exports.default = _default;
+30
View File
@@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _common = require("./common");
var _default = function _default() {
for (var _len = arguments.length, validators = new Array(_len), _key = 0; _key < _len; _key++) {
validators[_key] = arguments[_key];
}
return (0, _common.withParams)({
type: 'or'
}, function () {
var _this = this;
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return validators.length > 0 && validators.reduce(function (valid, fn) {
return valid || fn.apply(_this, args);
}, false);
});
};
exports.default = _default;
+14
View File
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _common = require("./common");
var _default = (0, _common.withParams)({
type: 'required'
}, _common.req);
exports.default = _default;
+19
View File
@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _common = require("./common");
var _default = function _default(prop) {
return (0, _common.withParams)({
type: 'requiredIf',
prop: prop
}, function (value, parentVm) {
return (0, _common.ref)(prop, this, parentVm) ? (0, _common.req)(value) : true;
});
};
exports.default = _default;
+19
View File
@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _common = require("./common");
var _default = function _default(prop) {
return (0, _common.withParams)({
type: 'requiredUnless',
prop: prop
}, function (value, parentVm) {
return !(0, _common.ref)(prop, this, parentVm) ? (0, _common.req)(value) : true;
});
};
exports.default = _default;
+19
View File
@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _common = require("./common");
var _default = function _default(equalTo) {
return (0, _common.withParams)({
type: 'sameAs',
eq: equalTo
}, function (value, parentVm) {
return value === (0, _common.ref)(equalTo, this, parentVm);
});
};
exports.default = _default;
+14
View File
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _common = require("./common");
var urlRegex = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i;
var _default = (0, _common.regex)('url', urlRegex);
exports.default = _default;
+153
View File
@@ -0,0 +1,153 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.patchChildren = patchChildren;
exports.h = h;
function isUndef(v) {
return v === null || v === undefined;
}
function isDef(v) {
return v !== null && v !== undefined;
}
function sameVval(oldVval, vval) {
return vval.tag === oldVval.tag && vval.key === oldVval.key;
}
function createVm(vval) {
var Vm = vval.tag;
vval.vm = new Vm({
data: vval.args
});
}
function updateVval(vval) {
var keys = Object.keys(vval.args);
for (var i = 0; i < keys.length; i++) {
keys.forEach(function (k) {
vval.vm[k] = vval.args[k];
});
}
}
function createKeyToOldIdx(children, beginIdx, endIdx) {
var i, key;
var map = {};
for (i = beginIdx; i <= endIdx; ++i) {
key = children[i].key;
if (isDef(key)) map[key] = i;
}
return map;
}
function updateChildren(oldCh, newCh) {
var oldStartIdx = 0;
var newStartIdx = 0;
var oldEndIdx = oldCh.length - 1;
var oldStartVval = oldCh[0];
var oldEndVval = oldCh[oldEndIdx];
var newEndIdx = newCh.length - 1;
var newStartVval = newCh[0];
var newEndVval = newCh[newEndIdx];
var oldKeyToIdx, idxInOld, elmToMove;
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
if (isUndef(oldStartVval)) {
oldStartVval = oldCh[++oldStartIdx];
} else if (isUndef(oldEndVval)) {
oldEndVval = oldCh[--oldEndIdx];
} else if (sameVval(oldStartVval, newStartVval)) {
patchVval(oldStartVval, newStartVval);
oldStartVval = oldCh[++oldStartIdx];
newStartVval = newCh[++newStartIdx];
} else if (sameVval(oldEndVval, newEndVval)) {
patchVval(oldEndVval, newEndVval);
oldEndVval = oldCh[--oldEndIdx];
newEndVval = newCh[--newEndIdx];
} else if (sameVval(oldStartVval, newEndVval)) {
patchVval(oldStartVval, newEndVval);
oldStartVval = oldCh[++oldStartIdx];
newEndVval = newCh[--newEndIdx];
} else if (sameVval(oldEndVval, newStartVval)) {
patchVval(oldEndVval, newStartVval);
oldEndVval = oldCh[--oldEndIdx];
newStartVval = newCh[++newStartIdx];
} else {
if (isUndef(oldKeyToIdx)) oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
idxInOld = isDef(newStartVval.key) ? oldKeyToIdx[newStartVval.key] : null;
if (isUndef(idxInOld)) {
createVm(newStartVval);
newStartVval = newCh[++newStartIdx];
} else {
elmToMove = oldCh[idxInOld];
if (sameVval(elmToMove, newStartVval)) {
patchVval(elmToMove, newStartVval);
oldCh[idxInOld] = undefined;
newStartVval = newCh[++newStartIdx];
} else {
createVm(newStartVval);
newStartVval = newCh[++newStartIdx];
}
}
}
}
if (oldStartIdx > oldEndIdx) {
addVvals(newCh, newStartIdx, newEndIdx);
} else if (newStartIdx > newEndIdx) {
removeVvals(oldCh, oldStartIdx, oldEndIdx);
}
}
function addVvals(vvals, startIdx, endIdx) {
for (; startIdx <= endIdx; ++startIdx) {
createVm(vvals[startIdx]);
}
}
function removeVvals(vvals, startIdx, endIdx) {
for (; startIdx <= endIdx; ++startIdx) {
var ch = vvals[startIdx];
if (isDef(ch)) {
ch.vm.$destroy();
ch.vm = null;
}
}
}
function patchVval(oldVval, vval) {
if (oldVval === vval) {
return;
}
vval.vm = oldVval.vm;
updateVval(vval);
}
function patchChildren(oldCh, ch) {
if (isDef(oldCh) && isDef(ch)) {
if (oldCh !== ch) updateChildren(oldCh, ch);
} else if (isDef(ch)) {
addVvals(ch, 0, ch.length - 1);
} else if (isDef(oldCh)) {
removeVvals(oldCh, 0, oldCh.length - 1);
}
}
function h(tag, key, args) {
return {
tag: tag,
key: key,
args: args
};
}
+9
View File
@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var withParams = process.env.BUILD === 'web' ? require('./withParamsBrowser').withParams : require('./params').withParams;
var _default = withParams;
exports.default = _default;
+21
View File
@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.withParams = void 0;
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
var root = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : {};
var fakeWithParams = function fakeWithParams(paramsOrClosure, maybeValidator) {
if (_typeof(paramsOrClosure) === 'object' && maybeValidator !== undefined) {
return maybeValidator;
}
return paramsOrClosure(function () {});
};
var withParams = root.vuelidate ? root.vuelidate.withParams : fakeWithParams;
exports.withParams = withParams;
+127
View File
@@ -0,0 +1,127 @@
{
"_from": "vuelidate@^0.7.4",
"_id": "vuelidate@0.7.4",
"_inBundle": false,
"_integrity": "sha512-QHZWYOL325Zo+2K7VBNEJTZ496Kd8Z31p85aQJFldKudUUGBmgw4zu4ghl4CyqPwjRCmqZ9lDdx4FSdMnu4fGg==",
"_location": "/vuelidate",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "vuelidate@^0.7.4",
"name": "vuelidate",
"escapedName": "vuelidate",
"rawSpec": "^0.7.4",
"saveSpec": null,
"fetchSpec": "^0.7.4"
},
"_requiredBy": [
"#DEV:/"
],
"_resolved": "https://registry.npmjs.org/vuelidate/-/vuelidate-0.7.4.tgz",
"_shasum": "5a0e54be09ac0192f1aa3387d74b92e0945bf8aa",
"_spec": "vuelidate@^0.7.4",
"_where": "D:\\Atom\\Git\\Laravel_CSSd",
"author": {
"name": "Paweł Grabarz",
"email": "pawel.grabarz@monterail.com"
},
"bugs": {
"url": "https://github.com/monterail/vuelidate/issues"
},
"bundleDependencies": false,
"dependencies": {},
"deprecated": false,
"description": "Simple, lightweight model-based validation for Vue.js",
"devDependencies": {
"@babel/cli": "^7.0.0-beta.47",
"@babel/core": "^7.0.0-beta.47",
"@babel/plugin-proposal-export-default-from": "^7.0.0-beta.47",
"@babel/preset-env": "^7.0.0-beta.47",
"@babel/register": "^7.0.0-beta.47",
"autoprefixer": "^8.5.0",
"babel-loader": "^8.0.0-beta.3",
"chai": "^4.1.2",
"connect-history-api-fallback": "^1.5.0",
"copy-webpack-plugin": "^4.5.1",
"cross-env": "^5.1.5",
"css-loader": "^0.28.11",
"eslint": "^4.19.1",
"eslint-config-prettier": "^2.9.0",
"eslint-loader": "^2.0.0",
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-vue": "^4.5.0",
"express": "^4.16.3",
"file-loader": "^1.1.11",
"html-webpack-plugin": "^3.2.0",
"http-proxy-middleware": "^0.18.0",
"istanbul-instrumenter-loader": "^3.0.1",
"json-loader": "^0.5.7",
"karma": "^2.0.2",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage-istanbul-reporter": "^2.0.0",
"karma-mocha": "^1.3.0",
"karma-sinon-chai": "^1.3.4",
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "0.0.32",
"karma-webpack": "^3.0.0",
"lolex": "^2.6.0",
"mini-css-extract-plugin": "^0.4.0",
"mocha": "^5.2.0",
"node-sass": "^4.9.0",
"opn": "^5.3.0",
"ora": "^2.1.0",
"prettier": "^1.12.1",
"pug": "2.0.3",
"pug-loader": "^2.4.0",
"pug-plain-loader": "^1.0.0",
"puppeteer": "^1.4.0",
"raw-loader": "^0.5.1",
"rimraf": "^2.6.2",
"sass-loader": "^7.0.1",
"shelljs": "^0.8.2",
"sinon": "^5.0.7",
"sinon-chai": "^3.0.0",
"url-loader": "^1.0.1",
"vue": "^2.5.16",
"vue-json-tree-view": "^2.1.4",
"vue-loader": "^15.1.0",
"vue-server-renderer": "^2.5.16",
"vue-style-loader": "^4.1.0",
"vue-template-compiler": "^2.5.16",
"webpack": "^4.8.3",
"webpack-dev-middleware": "^3.1.3",
"webpack-hot-middleware": "^2.22.2",
"webpack-merge": "^4.1.2"
},
"engines": {
"node": ">= 4.0.0",
"npm": ">= 3.0.0"
},
"homepage": "https://github.com/monterail/vuelidate#readme",
"license": "MIT",
"main": "lib/index.js",
"name": "vuelidate",
"repository": {
"type": "git",
"url": "git+https://github.com/monterail/vuelidate.git"
},
"scripts": {
"build": "npm run bundle:lib && npm run bundle:web",
"bundle:lib": "rimraf lib && cross-env BUILD=lib babel src --out-dir lib",
"bundle:web": "rimraf dist && cross-env BUILD=web node build/build-bundle.js",
"dev": "node build/dev-server.js",
"docs": "rimraf gh-pages && mkdir gh-pages && node build/build-docs.js",
"lint": "eslint --ext .js,.vue src test/unit/specs",
"prepublishOnly": "npm run lint && npm test && npm run build",
"test": "npm run test-unit && npm run test-ssr",
"test-ssr": "cross-env BABEL_ENV=node mocha --require @babel/register test/ssr/index.js",
"test-unit": "karma start test/unit/karma.conf.js --single-run",
"unit": "karma start test/unit/karma.conf.js --watch"
},
"sideEffects": [
"*.sass",
"*.scss"
],
"version": "0.7.4"
}
+601
View File
@@ -0,0 +1,601 @@
import { h, patchChildren } from './vval'
const NIL = () => null
const buildFromKeys = (keys, fn, keyFn) =>
keys.reduce((build, key) => {
build[keyFn ? keyFn(key) : key] = fn(key)
return build
}, {})
function isFunction(val) {
return typeof val === 'function'
}
function isObject(val) {
return val !== null && (typeof val === 'object' || isFunction(val))
}
function isPromise(object) {
return isObject(object) && isFunction(object.then)
}
const getPath = (ctx, obj, path, fallback) => {
if (typeof path === 'function') {
return path.call(ctx, obj, fallback)
}
path = Array.isArray(path) ? path : path.split('.')
for (let i = 0; i < path.length; i++) {
if (obj && typeof obj === 'object') {
obj = obj[path[i]]
} else {
return fallback
}
}
return typeof obj === 'undefined' ? fallback : obj
}
import { withParams, pushParams, popParams } from './params'
const __isVuelidateAsyncVm = '__isVuelidateAsyncVm'
function makePendingAsyncVm(Vue, promise) {
const asyncVm = new Vue({
data: {
p: true, // pending
v: false // value
}
})
promise.then(
(value) => {
asyncVm.p = false
asyncVm.v = value
},
(error) => {
asyncVm.p = false
asyncVm.v = false
throw error
}
)
asyncVm[__isVuelidateAsyncVm] = true
return asyncVm
}
const validationGetters = {
$invalid() {
const proxy = this.proxy
return (
this.nestedKeys.some((nested) => this.refProxy(nested).$invalid) ||
this.ruleKeys.some((rule) => !proxy[rule])
)
},
$dirty() {
if (this.dirty) {
return true
}
if (this.nestedKeys.length === 0) {
return false
}
return this.nestedKeys.every((key) => this.refProxy(key).$dirty)
},
$anyDirty() {
if (this.dirty) {
return true
}
if (this.nestedKeys.length === 0) {
return false
}
return this.nestedKeys.some((key) => this.refProxy(key).$anyDirty)
},
$error() {
return this.$dirty && !this.$pending && this.$invalid
},
$anyError() {
return this.$anyDirty && !this.$pending && this.$invalid
},
$pending() {
return (
this.ruleKeys.some((key) => this.getRef(key).$pending) ||
this.nestedKeys.some((key) => this.refProxy(key).$pending)
)
},
$params() {
const vals = this.validations
return {
...buildFromKeys(
this.nestedKeys,
(key) => (vals[key] && vals[key].$params) || null
),
...buildFromKeys(this.ruleKeys, (key) => this.getRef(key).$params)
}
}
}
function setDirtyRecursive(newState) {
this.dirty = newState
const proxy = this.proxy
const method = newState ? '$touch' : '$reset'
this.nestedKeys.forEach((key) => {
proxy[key][method]()
})
}
const validationMethods = {
$touch() {
setDirtyRecursive.call(this, true)
},
$reset() {
setDirtyRecursive.call(this, false)
},
$flattenParams() {
const proxy = this.proxy
let params = []
for (const key in this.$params) {
if (this.isNested(key)) {
const childParams = proxy[key].$flattenParams()
for (let j = 0; j < childParams.length; j++) {
childParams[j].path.unshift(key)
}
params = params.concat(childParams)
} else {
params.push({ path: [], name: key, params: this.$params[key] })
}
}
return params
}
}
const getterNames = Object.keys(validationGetters)
const methodNames = Object.keys(validationMethods)
let _cachedComponent = null
const getComponent = (Vue) => {
if (_cachedComponent) {
return _cachedComponent
}
const VBase = Vue.extend({
computed: {
refs() {
const oldVval = this._vval
// eslint-disable-next-line vue/no-side-effects-in-computed-properties
this._vval = this.children
patchChildren(oldVval, this._vval)
const refs = {}
this._vval.forEach((c) => {
refs[c.key] = c.vm
})
return refs
}
},
beforeCreate() {
this._vval = null
},
beforeDestroy() {
if (this._vval) {
patchChildren(this._vval)
this._vval = null
}
},
methods: {
getModel() {
return this.lazyModel ? this.lazyModel(this.prop) : this.model
},
getModelKey(key) {
var model = this.getModel()
if (model) {
return model[key]
}
},
hasIter() {
return false
}
}
})
const ValidationRule = VBase.extend({
data() {
return {
rule: null,
lazyModel: null,
model: null,
lazyParentModel: null,
rootModel: null
}
},
methods: {
runRule(parent) {
// Avoid using this.lazyParentModel to not get dependent on it.
// Passed as an argument for workaround
const model = this.getModel()
pushParams()
const rawOutput = this.rule.call(this.rootModel, model, parent)
const output = isPromise(rawOutput)
? makePendingAsyncVm(Vue, rawOutput)
: rawOutput
const rawParams = popParams()
const params =
rawParams && rawParams.$sub
? rawParams.$sub.length > 1
? rawParams
: rawParams.$sub[0]
: null
return { output, params }
}
},
computed: {
run() {
const parent = this.lazyParentModel()
const isArrayDependant = Array.isArray(parent) && parent.__ob__
if (isArrayDependant) {
// force depend on the array
const arrayDep = parent.__ob__.dep
arrayDep.depend()
const target = arrayDep.constructor.target
if (!this._indirectWatcher) {
const Watcher = target.constructor
this._indirectWatcher = new Watcher(
this,
() => this.runRule(parent),
null,
{ lazy: true }
)
}
// if the update cause is only the array update
// and value stays the same, don't recalculate
const model = this.getModel()
if (!this._indirectWatcher.dirty && this._lastModel === model) {
this._indirectWatcher.depend()
return target.value
}
this._lastModel = model
this._indirectWatcher.evaluate()
this._indirectWatcher.depend()
} else if (this._indirectWatcher) {
// array was replaced with different type at runtime
this._indirectWatcher.teardown()
this._indirectWatcher = null
}
return this._indirectWatcher
? this._indirectWatcher.value
: this.runRule(parent)
},
$params() {
return this.run.params
},
proxy() {
const output = this.run.output
if (output[__isVuelidateAsyncVm]) {
return !!output.v
}
return !!output
},
$pending() {
const output = this.run.output
if (output[__isVuelidateAsyncVm]) {
return output.p
}
return false
}
},
destroyed() {
if (this._indirectWatcher) {
this._indirectWatcher.teardown()
this._indirectWatcher = null
}
}
})
const Validation = VBase.extend({
data() {
return {
dirty: false,
validations: null,
lazyModel: null,
model: null,
prop: null,
lazyParentModel: null,
rootModel: null
}
},
methods: {
...validationMethods,
refProxy(key) {
return this.getRef(key).proxy
},
getRef(key) {
return this.refs[key]
},
isNested(key) {
return typeof this.validations[key] !== 'function'
}
},
computed: {
...validationGetters,
nestedKeys() {
return this.keys.filter(this.isNested)
},
ruleKeys() {
return this.keys.filter((k) => !this.isNested(k))
},
keys() {
return Object.keys(this.validations).filter((k) => k !== '$params')
},
proxy() {
const keyDefs = buildFromKeys(this.keys, (key) => ({
enumerable: true,
configurable: true, // allow mocking lib calls
get: () => this.refProxy(key)
}))
const getterDefs = buildFromKeys(getterNames, (key) => ({
enumerable: true,
configurable: true,
get: () => this[key]
}))
const methodDefs = buildFromKeys(methodNames, (key) => ({
enumerable: false,
configurable: true,
get: () => this[key]
}))
const iterDefs = this.hasIter()
? {
$iter: {
enumerable: true,
value: Object.defineProperties(
{},
{
...keyDefs
}
)
}
}
: {}
return Object.defineProperties(
{},
{
...keyDefs,
...iterDefs,
$model: {
enumerable: true,
get: () => {
const parent = this.lazyParentModel()
if (parent != null) {
return parent[this.prop]
} else {
return null
}
},
set: (value) => {
const parent = this.lazyParentModel()
if (parent != null) {
parent[this.prop] = value
this.$touch()
}
}
},
...getterDefs,
...methodDefs
}
)
},
children() {
return [
...this.nestedKeys.map((key) => renderNested(this, key)),
...this.ruleKeys.map((key) => renderRule(this, key))
].filter(Boolean)
}
}
})
const GroupValidation = Validation.extend({
methods: {
isNested(key) {
return typeof this.validations[key]() !== 'undefined'
},
getRef(key) {
const vm = this
return {
get proxy() {
// default to invalid
return vm.validations[key]() || false
}
}
}
}
})
const EachValidation = Validation.extend({
computed: {
keys() {
var model = this.getModel()
if (isObject(model)) {
return Object.keys(model)
} else {
return []
}
},
tracker() {
const trackBy = this.validations.$trackBy
return trackBy
? (key) =>
`${getPath(this.rootModel, this.getModelKey(key), trackBy)}`
: (x) => `${x}`
},
getModelLazy() {
return () => this.getModel()
},
children() {
const def = this.validations
const model = this.getModel()
const validations = { ...def }
delete validations['$trackBy']
let usedTracks = {}
return this.keys
.map((key) => {
const track = this.tracker(key)
if (usedTracks.hasOwnProperty(track)) {
return null
}
usedTracks[track] = true
return h(Validation, track, {
validations,
prop: key,
lazyParentModel: this.getModelLazy,
model: model[key],
rootModel: this.rootModel
})
})
.filter(Boolean)
}
},
methods: {
isNested() {
return true
},
getRef(key) {
return this.refs[this.tracker(key)]
},
hasIter() {
return true
}
}
})
const renderNested = (vm, key) => {
if (key === '$each') {
return h(EachValidation, key, {
validations: vm.validations[key],
lazyParentModel: vm.lazyParentModel,
prop: key,
lazyModel: vm.getModel,
rootModel: vm.rootModel
})
}
const validations = vm.validations[key]
if (Array.isArray(validations)) {
const root = vm.rootModel
const refVals = buildFromKeys(
validations,
(path) =>
function() {
return getPath(root, root.$v, path)
},
(v) => (Array.isArray(v) ? v.join('.') : v)
)
return h(GroupValidation, key, {
validations: refVals,
lazyParentModel: NIL,
prop: key,
lazyModel: NIL,
rootModel: root
})
}
return h(Validation, key, {
validations,
lazyParentModel: vm.getModel,
prop: key,
lazyModel: vm.getModelKey,
rootModel: vm.rootModel
})
}
const renderRule = (vm, key) => {
return h(ValidationRule, key, {
rule: vm.validations[key],
lazyParentModel: vm.lazyParentModel,
lazyModel: vm.getModel,
rootModel: vm.rootModel
})
}
_cachedComponent = { VBase, Validation }
return _cachedComponent
}
let _cachedVue = null
function getVue(rootVm) {
if (_cachedVue) return _cachedVue
let Vue = rootVm.constructor
/* istanbul ignore next */
while (Vue.super) Vue = Vue.super
_cachedVue = Vue
return Vue
}
const validateModel = (model, validations) => {
const Vue = getVue(model)
const { Validation, VBase } = getComponent(Vue)
const root = new VBase({
computed: {
children() {
const vals =
typeof validations === 'function'
? validations.call(model)
: validations
return [
h(Validation, '$v', {
validations: vals,
lazyParentModel: NIL,
prop: '$v',
model,
rootModel: model
})
]
}
}
})
return root
}
const validationMixin = {
data() {
const vals = this.$options.validations
if (vals) {
this._vuelidate = validateModel(this, vals)
}
return {}
},
beforeCreate() {
const options = this.$options
const vals = options.validations
if (!vals) return
if (!options.computed) options.computed = {}
if (options.computed.$v) return
options.computed.$v = function() {
return this._vuelidate ? this._vuelidate.refs.$v.proxy : null
}
},
beforeDestroy() {
if (this._vuelidate) {
this._vuelidate.$destroy()
this._vuelidate = null
}
}
}
function Vuelidate(Vue) {
Vue.mixin(validationMixin)
}
export { Vuelidate, validationMixin, withParams }
export default Vuelidate
+62
View File
@@ -0,0 +1,62 @@
const stack = []
// exported for tests
export let target = null
export const _setTarget = (x) => {
target = x
}
export function pushParams() {
if (target !== null) {
stack.push(target)
}
target = {}
}
export function popParams() {
const lastTarget = target
const newTarget = (target = stack.pop() || null)
if (newTarget) {
if (!Array.isArray(newTarget.$sub)) {
newTarget.$sub = []
}
newTarget.$sub.push(lastTarget)
}
return lastTarget
}
function addParams(params) {
if (typeof params === 'object' && !Array.isArray(params)) {
target = { ...target, ...params }
} else {
throw new Error('params must be an object')
}
}
function withParamsDirect(params, validator) {
return withParamsClosure((add) => {
return function(...args) {
add(params)
return validator.apply(this, args)
}
})
}
function withParamsClosure(closure) {
const validator = closure(addParams)
return function(...args) {
pushParams()
try {
return validator.apply(this, args)
} finally {
popParams()
}
}
}
export function withParams(paramsOrClosure, maybeValidator) {
if (typeof paramsOrClosure === 'object' && maybeValidator !== undefined) {
return withParamsDirect(paramsOrClosure, maybeValidator)
}
return withParamsClosure(paramsOrClosure)
}
+2
View File
@@ -0,0 +1,2 @@
import { regex } from './common'
export default regex('alpha', /^[a-zA-Z]*$/)
+2
View File
@@ -0,0 +1,2 @@
import { regex } from './common'
export default regex('alphaNum', /^[a-zA-Z0-9]*$/)
+9
View File
@@ -0,0 +1,9 @@
import { withParams } from './common'
export default (...validators) => {
return withParams({ type: 'and' }, function(...args) {
return (
validators.length > 0 &&
validators.reduce((valid, fn) => valid && fn.apply(this, args), true)
)
})
}
+11
View File
@@ -0,0 +1,11 @@
import { req, withParams } from './common'
export default (min, max) =>
withParams(
{ type: 'between', min, max },
(value) =>
!req(value) ||
((!/\s/.test(value) || value instanceof Date) &&
+min <= +value &&
+max >= +value)
)
+45
View File
@@ -0,0 +1,45 @@
import withParams from '../withParams'
export { withParams }
// "required" core, used in almost every validator to allow empty values
export const req = (value) => {
if (Array.isArray(value)) return !!value.length
if (value === undefined || value === null) {
return false
}
if (value === false) {
return true
}
if (value instanceof Date) {
// invalid date won't pass
return !isNaN(value.getTime())
}
if (typeof value === 'object') {
for (let _ in value) return true
return false
}
return !!String(value).length
}
// get length in type-agnostic way
export const len = (value) => {
if (Array.isArray(value)) return value.length
if (typeof value === 'object') {
return Object.keys(value).length
}
return String(value).length
}
// resolve referenced value
export const ref = (reference, vm, parentVm) =>
typeof reference === 'function'
? reference.call(vm, parentVm)
: parentVm[reference]
// regex based validator template
export const regex = (type, expr) =>
withParams({ type }, (value) => !req(value) || expr.test(value))
+2
View File
@@ -0,0 +1,2 @@
import { regex } from './common'
export default regex('decimal', /^[-]?\d*(\.\d+)?$/)
+4
View File
@@ -0,0 +1,4 @@
import { regex } from './common'
const emailRegex = /(^$|^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$)/
export default regex('email', emailRegex)
+47
View File
@@ -0,0 +1,47 @@
import alpha from './alpha'
import alphaNum from './alphaNum'
import numeric from './numeric'
import between from './between'
import email from './email'
import ipAddress from './ipAddress'
import macAddress from './macAddress'
import maxLength from './maxLength'
import minLength from './minLength'
import required from './required'
import requiredIf from './requiredIf'
import requiredUnless from './requiredUnless'
import sameAs from './sameAs'
import url from './url'
import or from './or'
import and from './and'
import not from './not'
import minValue from './minValue'
import maxValue from './maxValue'
import integer from './integer'
import decimal from './decimal'
import * as helpers from './common'
export {
alpha,
alphaNum,
numeric,
between,
email,
ipAddress,
macAddress,
maxLength,
minLength,
required,
requiredIf,
requiredUnless,
sameAs,
url,
or,
and,
not,
minValue,
maxValue,
integer,
decimal,
helpers
}
+2
View File
@@ -0,0 +1,2 @@
import { regex } from './common'
export default regex('integer', /^-?[0-9]*$/)
+30
View File
@@ -0,0 +1,30 @@
import { req, withParams } from './common'
export default withParams({ type: 'ipAddress' }, (value) => {
if (!req(value)) {
return true
}
if (typeof value !== 'string') {
return false
}
const nibbles = value.split('.')
return nibbles.length === 4 && nibbles.every(nibbleValid)
})
const nibbleValid = (nibble) => {
if (nibble.length > 3 || nibble.length === 0) {
return false
}
if (nibble[0] === '0' && nibble !== '0') {
return false
}
if (!nibble.match(/^\d+$/)) {
return false
}
const numeric = +nibble | 0
return numeric >= 0 && numeric <= 255
}
+26
View File
@@ -0,0 +1,26 @@
import { req, withParams } from './common'
export default (separator = ':') =>
withParams({ type: 'macAddress' }, (value) => {
if (!req(value)) {
return true
}
if (typeof value !== 'string') {
return false
}
const parts =
typeof separator === 'string' && separator !== ''
? value.split(separator)
: value.length === 12 || value.length === 16
? value.match(/.{2}/g)
: null
return (
parts !== null &&
(parts.length === 6 || parts.length === 8) &&
parts.every(hexValid)
)
})
const hexValid = (hex) => hex.toLowerCase().match(/^[0-9a-f]{2}$/)
+6
View File
@@ -0,0 +1,6 @@
import { req, len, withParams } from './common'
export default (length) =>
withParams(
{ type: 'maxLength', max: length },
(value) => !req(value) || len(value) <= length
)
+8
View File
@@ -0,0 +1,8 @@
import { req, withParams } from './common'
export default (max) =>
withParams(
{ type: 'maxValue', max },
(value) =>
!req(value) ||
((!/\s/.test(value) || value instanceof Date) && +value <= +max)
)
+6
View File
@@ -0,0 +1,6 @@
import { req, len, withParams } from './common'
export default (length) =>
withParams(
{ type: 'minLength', min: length },
(value) => !req(value) || len(value) >= length
)
+8
View File
@@ -0,0 +1,8 @@
import { req, withParams } from './common'
export default (min) =>
withParams(
{ type: 'minValue', min },
(value) =>
!req(value) ||
((!/\s/.test(value) || value instanceof Date) && +value >= +min)
)
+7
View File
@@ -0,0 +1,7 @@
import { withParams, req } from './common'
export default (validator) => {
return withParams({ type: 'not' }, function(value, vm) {
return !req(value) || !validator.call(this, value, vm)
})
}
+2
View File
@@ -0,0 +1,2 @@
import { regex } from './common'
export default regex('numeric', /^[0-9]*$/)
+9
View File
@@ -0,0 +1,9 @@
import { withParams } from './common'
export default (...validators) => {
return withParams({ type: 'or' }, function(...args) {
return (
validators.length > 0 &&
validators.reduce((valid, fn) => valid || fn.apply(this, args), false)
)
})
}
+2
View File
@@ -0,0 +1,2 @@
import { withParams, req } from './common'
export default withParams({ type: 'required' }, req)
+6
View File
@@ -0,0 +1,6 @@
import { req, ref, withParams } from './common'
export default (prop) =>
withParams({ type: 'requiredIf', prop }, function(value, parentVm) {
return ref(prop, this, parentVm) ? req(value) : true
})
+5
View File
@@ -0,0 +1,5 @@
import { req, ref, withParams } from './common'
export default (prop) =>
withParams({ type: 'requiredUnless', prop }, function(value, parentVm) {
return !ref(prop, this, parentVm) ? req(value) : true
})
+5
View File
@@ -0,0 +1,5 @@
import { ref, withParams } from './common'
export default (equalTo) =>
withParams({ type: 'sameAs', eq: equalTo }, function(value, parentVm) {
return value === ref(equalTo, this, parentVm)
})
+4
View File
@@ -0,0 +1,4 @@
import { regex } from './common'
const urlRegex = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i
export default regex('url', urlRegex)
+140
View File
@@ -0,0 +1,140 @@
// a minimial single-layer implementation
// of virtual-validation patching,
// based on Vue's snabbdom clone
function isUndef(v) {
return v === null || v === undefined
}
function isDef(v) {
return v !== null && v !== undefined
}
function sameVval(oldVval, vval) {
return vval.tag === oldVval.tag && vval.key === oldVval.key
}
function createVm(vval) {
const Vm = vval.tag
vval.vm = new Vm({ data: vval.args })
}
function updateVval(vval) {
const keys = Object.keys(vval.args)
for (let i = 0; i < keys.length; i++) {
keys.forEach((k) => {
vval.vm[k] = vval.args[k]
})
}
}
function createKeyToOldIdx(children, beginIdx, endIdx) {
let i, key
const map = {}
for (i = beginIdx; i <= endIdx; ++i) {
key = children[i].key
if (isDef(key)) map[key] = i
}
return map
}
function updateChildren(oldCh, newCh) {
let oldStartIdx = 0
let newStartIdx = 0
let oldEndIdx = oldCh.length - 1
let oldStartVval = oldCh[0]
let oldEndVval = oldCh[oldEndIdx]
let newEndIdx = newCh.length - 1
let newStartVval = newCh[0]
let newEndVval = newCh[newEndIdx]
let oldKeyToIdx, idxInOld, elmToMove
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
if (isUndef(oldStartVval)) {
oldStartVval = oldCh[++oldStartIdx] // Vval has been moved left
} else if (isUndef(oldEndVval)) {
oldEndVval = oldCh[--oldEndIdx]
} else if (sameVval(oldStartVval, newStartVval)) {
patchVval(oldStartVval, newStartVval)
oldStartVval = oldCh[++oldStartIdx]
newStartVval = newCh[++newStartIdx]
} else if (sameVval(oldEndVval, newEndVval)) {
patchVval(oldEndVval, newEndVval)
oldEndVval = oldCh[--oldEndIdx]
newEndVval = newCh[--newEndIdx]
} else if (sameVval(oldStartVval, newEndVval)) {
// Vval moved right
patchVval(oldStartVval, newEndVval)
oldStartVval = oldCh[++oldStartIdx]
newEndVval = newCh[--newEndIdx]
} else if (sameVval(oldEndVval, newStartVval)) {
// Vval moved left
patchVval(oldEndVval, newStartVval)
oldEndVval = oldCh[--oldEndIdx]
newStartVval = newCh[++newStartIdx]
} else {
if (isUndef(oldKeyToIdx))
oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx)
idxInOld = isDef(newStartVval.key) ? oldKeyToIdx[newStartVval.key] : null
if (isUndef(idxInOld)) {
// New element
createVm(newStartVval)
newStartVval = newCh[++newStartIdx]
} else {
elmToMove = oldCh[idxInOld]
if (sameVval(elmToMove, newStartVval)) {
patchVval(elmToMove, newStartVval)
oldCh[idxInOld] = undefined
newStartVval = newCh[++newStartIdx]
} else {
// same key but different element. treat as new element
createVm(newStartVval)
newStartVval = newCh[++newStartIdx]
}
}
}
}
if (oldStartIdx > oldEndIdx) {
addVvals(newCh, newStartIdx, newEndIdx)
} else if (newStartIdx > newEndIdx) {
removeVvals(oldCh, oldStartIdx, oldEndIdx)
}
}
function addVvals(vvals, startIdx, endIdx) {
for (; startIdx <= endIdx; ++startIdx) {
createVm(vvals[startIdx])
}
}
function removeVvals(vvals, startIdx, endIdx) {
for (; startIdx <= endIdx; ++startIdx) {
const ch = vvals[startIdx]
if (isDef(ch)) {
ch.vm.$destroy()
ch.vm = null
}
}
}
function patchVval(oldVval, vval) {
if (oldVval === vval) {
return
}
vval.vm = oldVval.vm
updateVval(vval)
}
export function patchChildren(oldCh, ch) {
if (isDef(oldCh) && isDef(ch)) {
if (oldCh !== ch) updateChildren(oldCh, ch)
} else if (isDef(ch)) {
addVvals(ch, 0, ch.length - 1)
} else if (isDef(oldCh)) {
removeVvals(oldCh, 0, oldCh.length - 1)
}
}
export function h(tag, key, args) {
return { tag, key, args }
}
+7
View File
@@ -0,0 +1,7 @@
/* istanbul ignore next */
const withParams =
process.env.BUILD === 'web'
? require('./withParamsBrowser').withParams
: require('./params').withParams
export default withParams
+23
View File
@@ -0,0 +1,23 @@
// In browser, validators should be independent from Vuelidate.
// The only usecase those do need to be dependent is when you need $params.
// To make the dependency optional, try to grab Vuelidate from global object,
// fallback to stubbed WithParams on failure.
const root =
typeof window !== 'undefined'
? window
: typeof global !== 'undefined'
? global
: {}
/* istanbul ignore next */
const fakeWithParams = (paramsOrClosure, maybeValidator) => {
if (typeof paramsOrClosure === 'object' && maybeValidator !== undefined) {
return maybeValidator
}
return paramsOrClosure(() => {})
}
export const withParams = root.vuelidate
? root.vuelidate.withParams
: fakeWithParams