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
+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