@formvuelate/plugin-vee-validate
Advanced tools
Comparing version 2.4.0 to 3.3.1
/** | ||
* @formvuelate/plugin-vee-validate v2.4.0 | ||
* (c) 2021 Abdelrahman Awad <logaretm1@gmail.com> | ||
* @license MIT | ||
*/ | ||
* plugin-vee-validate v3.3.1 | ||
*/ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var vue = require('vue'); | ||
@@ -21,3 +16,3 @@ var veeValidate = require('vee-validate'); | ||
*/ | ||
var mapElementsInSchema = function (schema, fn) { return schema.map(function (row) { return row.map(function (el) { return fn(el); }); }); }; | ||
const mapElementsInSchema = (schema, fn) => schema.map(row => row.map(el => fn(el))); | ||
@@ -29,22 +24,20 @@ /** | ||
return { | ||
validation: validation | ||
validation | ||
} | ||
} | ||
var VEE_VALIDATE_FVL_FORM_KEY = 'vee-validate-fvl-form-context'; | ||
const VEE_VALIDATE_FVL_FORM_KEY = 'vee-validate-fvl-form-context'; | ||
function VeeValidatePlugin (opts) { | ||
// Maps the validation state exposed by vee-validate to components | ||
var mapProps = (opts && opts.mapProps) || defaultMapProps; | ||
const mapProps = (opts && opts.mapProps) || defaultMapProps; | ||
return function veeValidatePlugin (baseReturns) { | ||
// Take the parsed schema from SchemaForm setup returns | ||
var parsedSchema = baseReturns.parsedSchema; | ||
var formBinds = baseReturns.formBinds; | ||
const { parsedSchema, formBinds } = baseReturns; | ||
// Get additional properties not defined on the `SchemaForm` derivatives | ||
var ref = vue.getCurrentInstance(); | ||
var formAttrs = ref.attrs; | ||
const { attrs: formAttrs } = vue.getCurrentInstance() || { attrs: {} }; | ||
// try to retrieve vee-validate form from the root schema if possible | ||
var formContext = vue.inject(VEE_VALIDATE_FVL_FORM_KEY, undefined); | ||
let formContext = vue.inject(VEE_VALIDATE_FVL_FORM_KEY, undefined); | ||
if (!formContext) { | ||
@@ -61,7 +54,5 @@ // if non-existent create one and provide it for nested schemas | ||
var handleSubmit = formContext.handleSubmit; | ||
const { handleSubmit } = formContext; | ||
function mapField (el, path) { | ||
if ( path === void 0 ) path = ''; | ||
function mapField (el, path = '') { | ||
// Handles nested schemas | ||
@@ -71,42 +62,52 @@ // doesn't treat nested forms as fields | ||
if (el.schema) { | ||
path = path ? (path + "." + (el.model)) : el.model; | ||
path = path ? `${path}.${el.model}` : el.model; | ||
// Make sure we only deal with schema arrays and not nested objects | ||
var schemaArray = Array.isArray(el.schema) ? el.schema : Object.keys(el.schema).map(function (model) { | ||
return Object.assign({}, {model: model}, | ||
el.schema[model]) | ||
}); | ||
const schemaArray = Array.isArray(el.schema) | ||
? el.schema | ||
: Object.keys(el.schema).map(model => { | ||
return { | ||
model, | ||
...el.schema[model] | ||
} | ||
}); | ||
return Object.assign({}, el, | ||
{schema: schemaArray.map(function (nestedField) { return mapField(nestedField, path); })}) | ||
return { | ||
...el, | ||
schema: schemaArray.map(nestedField => mapField(nestedField, path)) | ||
} | ||
} | ||
return Object.assign({}, el, | ||
return { | ||
...el, | ||
// namespaced prop to avoid clash with users' props | ||
{_veeValidateConfig: { | ||
mapProps: mapProps, | ||
path: path | ||
_veeValidateConfig: { | ||
mapProps, | ||
path | ||
}, | ||
component: withField(el)}) | ||
component: withField(el) | ||
} | ||
} | ||
// Map components in schema to enhanced versions with `useField` | ||
var formSchemaWithVeeValidate = vue.computed(function () { return mapElementsInSchema(parsedSchema.value, mapField); }); | ||
const formSchemaWithVeeValidate = vue.computed(() => mapElementsInSchema(parsedSchema.value, mapField)); | ||
// override the submit function with one that triggers validation | ||
var formSubmit = formBinds.value.onSubmit; | ||
var onSubmit = handleSubmit(function (_, ref) { | ||
var evt = ref.evt; | ||
const formSubmit = formBinds.value.onSubmit; | ||
const onSubmit = handleSubmit((_, { evt }) => { | ||
formSubmit(evt); | ||
}); | ||
return Object.assign({}, baseReturns, | ||
{formBinds: vue.computed(function () { | ||
return Object.assign({}, baseReturns.formBinds.value, | ||
{onSubmit: onSubmit}) | ||
return { | ||
...baseReturns, | ||
formBinds: vue.computed(() => { | ||
return { | ||
...baseReturns.formBinds.value, | ||
onSubmit | ||
} | ||
}), | ||
slotBinds: vue.computed(function () { | ||
return Object.assign({}, baseReturns.slotBinds.value, | ||
{validation: { | ||
slotBinds: vue.computed(() => { | ||
return { | ||
...baseReturns.slotBinds.value, | ||
validation: { | ||
errors: formContext.errors.value, | ||
@@ -117,5 +118,7 @@ values: formContext.values, | ||
meta: formContext.meta.value | ||
}}) | ||
} | ||
} | ||
}), | ||
parsedSchema: formSchemaWithVeeValidate}) | ||
parsedSchema: formSchemaWithVeeValidate | ||
} | ||
} | ||
@@ -126,6 +129,6 @@ } | ||
// very important to avoid re-creating components when re-rendering | ||
var COMPONENT_LOOKUP = new Map(); | ||
const COMPONENT_LOOKUP = new Map(); | ||
function withField (el) { | ||
var Comp = el.component; | ||
const Comp = el.component; | ||
@@ -136,9 +139,5 @@ if (COMPONENT_LOOKUP.has(Comp)) { | ||
var wrappedComponent = vue.markRaw({ | ||
const wrappedComponent = vue.markRaw({ | ||
name: 'withFieldWrapper', | ||
props: { | ||
label: { | ||
type: String, | ||
default: undefined | ||
}, | ||
modelValue: { | ||
@@ -157,28 +156,15 @@ type: null, | ||
}, | ||
setup: function setup (props, ref) { | ||
var attrs = ref.attrs; | ||
var ref$1 = props._veeValidateConfig; | ||
var path = ref$1.path; | ||
var mapProps = ref$1.mapProps; | ||
var ref$2 = vue.toRefs(props); | ||
var validations = ref$2.validations; | ||
var modelValue = ref$2.modelValue; | ||
var initialValue = modelValue ? modelValue.value : undefined; | ||
var label = vue.computed(function () { return props.label; }); | ||
setup (props, { attrs }) { | ||
const { path, mapProps } = props._veeValidateConfig; | ||
const { validations, modelValue } = vue.toRefs(props); | ||
const initialValue = modelValue ? modelValue.value : undefined; | ||
// Build a fully qualified field name using dot notation for nested fields | ||
// ex: user.name | ||
var name = path ? (path + "." + (attrs.model)) : attrs.model; | ||
var ref$3 = veeValidate.useField(name, validations, { | ||
initialValue: initialValue, | ||
label: label | ||
const name = path ? `${path}.${attrs.model}` : attrs.model; | ||
const { value, errorMessage, meta, setTouched, errors } = veeValidate.useField(name, validations, { | ||
initialValue | ||
}); | ||
var value = ref$3.value; | ||
var errorMessage = ref$3.errorMessage; | ||
var meta = ref$3.meta; | ||
var setTouched = ref$3.setTouched; | ||
var errors = ref$3.errors; | ||
if (modelValue) { | ||
vue.watch(modelValue, function (val) { | ||
vue.watch(modelValue, (val) => { | ||
value.value = val; | ||
@@ -188,13 +174,15 @@ }); | ||
var resolvedComponent = vue.resolveDynamicComponent(Comp); | ||
const resolvedComponent = vue.resolveDynamicComponent(Comp); | ||
return function renderWithField () { | ||
return vue.h(resolvedComponent, Object.assign({}, props, | ||
attrs, | ||
mapProps({ | ||
return vue.h(resolvedComponent, { | ||
...props, | ||
...attrs, | ||
...mapProps({ | ||
errorMessage: vue.unref(errorMessage), | ||
errors: vue.unref(errors), | ||
meta: meta, | ||
setTouched: setTouched | ||
}, el))) | ||
meta, | ||
setTouched | ||
}, el) | ||
}) | ||
} | ||
@@ -210,4 +198,2 @@ } | ||
exports.mapElementsInSchema = mapElementsInSchema; | ||
exports['default'] = VeeValidatePlugin; | ||
exports.withField = withField; | ||
module.exports = VeeValidatePlugin; |
/** | ||
* @formvuelate/plugin-vee-validate v2.4.0 | ||
* (c) 2021 Abdelrahman Awad <logaretm1@gmail.com> | ||
* @license MIT | ||
*/ | ||
* plugin-vee-validate v3.3.1 | ||
*/ | ||
import { getCurrentInstance, inject, provide, computed, markRaw, toRefs, watch, resolveDynamicComponent, h, unref } from 'vue'; | ||
import { useForm, useField } from 'vee-validate'; | ||
import { computed, getCurrentInstance, h, inject, markRaw, provide, resolveDynamicComponent, toRefs, unref, watch } from 'vue'; | ||
import { useField, useForm } from 'vee-validate'; | ||
/** | ||
@@ -17,3 +14,3 @@ * For a Schema, find the elements in each of the rows and remap the element with the given function | ||
*/ | ||
var mapElementsInSchema = function (schema, fn) { return schema.map(function (row) { return row.map(function (el) { return fn(el); }); }); }; | ||
const mapElementsInSchema = (schema, fn) => schema.map(row => row.map(el => fn(el))); | ||
@@ -25,22 +22,20 @@ /** | ||
return { | ||
validation: validation | ||
validation | ||
} | ||
} | ||
var VEE_VALIDATE_FVL_FORM_KEY = 'vee-validate-fvl-form-context'; | ||
const VEE_VALIDATE_FVL_FORM_KEY = 'vee-validate-fvl-form-context'; | ||
function VeeValidatePlugin (opts) { | ||
// Maps the validation state exposed by vee-validate to components | ||
var mapProps = (opts && opts.mapProps) || defaultMapProps; | ||
const mapProps = (opts && opts.mapProps) || defaultMapProps; | ||
return function veeValidatePlugin (baseReturns) { | ||
// Take the parsed schema from SchemaForm setup returns | ||
var parsedSchema = baseReturns.parsedSchema; | ||
var formBinds = baseReturns.formBinds; | ||
const { parsedSchema, formBinds } = baseReturns; | ||
// Get additional properties not defined on the `SchemaForm` derivatives | ||
var ref = getCurrentInstance(); | ||
var formAttrs = ref.attrs; | ||
const { attrs: formAttrs } = getCurrentInstance() || { attrs: {} }; | ||
// try to retrieve vee-validate form from the root schema if possible | ||
var formContext = inject(VEE_VALIDATE_FVL_FORM_KEY, undefined); | ||
let formContext = inject(VEE_VALIDATE_FVL_FORM_KEY, undefined); | ||
if (!formContext) { | ||
@@ -57,7 +52,5 @@ // if non-existent create one and provide it for nested schemas | ||
var handleSubmit = formContext.handleSubmit; | ||
const { handleSubmit } = formContext; | ||
function mapField (el, path) { | ||
if ( path === void 0 ) path = ''; | ||
function mapField (el, path = '') { | ||
// Handles nested schemas | ||
@@ -67,42 +60,52 @@ // doesn't treat nested forms as fields | ||
if (el.schema) { | ||
path = path ? (path + "." + (el.model)) : el.model; | ||
path = path ? `${path}.${el.model}` : el.model; | ||
// Make sure we only deal with schema arrays and not nested objects | ||
var schemaArray = Array.isArray(el.schema) ? el.schema : Object.keys(el.schema).map(function (model) { | ||
return Object.assign({}, {model: model}, | ||
el.schema[model]) | ||
}); | ||
const schemaArray = Array.isArray(el.schema) | ||
? el.schema | ||
: Object.keys(el.schema).map(model => { | ||
return { | ||
model, | ||
...el.schema[model] | ||
} | ||
}); | ||
return Object.assign({}, el, | ||
{schema: schemaArray.map(function (nestedField) { return mapField(nestedField, path); })}) | ||
return { | ||
...el, | ||
schema: schemaArray.map(nestedField => mapField(nestedField, path)) | ||
} | ||
} | ||
return Object.assign({}, el, | ||
return { | ||
...el, | ||
// namespaced prop to avoid clash with users' props | ||
{_veeValidateConfig: { | ||
mapProps: mapProps, | ||
path: path | ||
_veeValidateConfig: { | ||
mapProps, | ||
path | ||
}, | ||
component: withField(el)}) | ||
component: withField(el) | ||
} | ||
} | ||
// Map components in schema to enhanced versions with `useField` | ||
var formSchemaWithVeeValidate = computed(function () { return mapElementsInSchema(parsedSchema.value, mapField); }); | ||
const formSchemaWithVeeValidate = computed(() => mapElementsInSchema(parsedSchema.value, mapField)); | ||
// override the submit function with one that triggers validation | ||
var formSubmit = formBinds.value.onSubmit; | ||
var onSubmit = handleSubmit(function (_, ref) { | ||
var evt = ref.evt; | ||
const formSubmit = formBinds.value.onSubmit; | ||
const onSubmit = handleSubmit((_, { evt }) => { | ||
formSubmit(evt); | ||
}); | ||
return Object.assign({}, baseReturns, | ||
{formBinds: computed(function () { | ||
return Object.assign({}, baseReturns.formBinds.value, | ||
{onSubmit: onSubmit}) | ||
return { | ||
...baseReturns, | ||
formBinds: computed(() => { | ||
return { | ||
...baseReturns.formBinds.value, | ||
onSubmit | ||
} | ||
}), | ||
slotBinds: computed(function () { | ||
return Object.assign({}, baseReturns.slotBinds.value, | ||
{validation: { | ||
slotBinds: computed(() => { | ||
return { | ||
...baseReturns.slotBinds.value, | ||
validation: { | ||
errors: formContext.errors.value, | ||
@@ -113,5 +116,7 @@ values: formContext.values, | ||
meta: formContext.meta.value | ||
}}) | ||
} | ||
} | ||
}), | ||
parsedSchema: formSchemaWithVeeValidate}) | ||
parsedSchema: formSchemaWithVeeValidate | ||
} | ||
} | ||
@@ -122,6 +127,6 @@ } | ||
// very important to avoid re-creating components when re-rendering | ||
var COMPONENT_LOOKUP = new Map(); | ||
const COMPONENT_LOOKUP = new Map(); | ||
function withField (el) { | ||
var Comp = el.component; | ||
const Comp = el.component; | ||
@@ -132,9 +137,5 @@ if (COMPONENT_LOOKUP.has(Comp)) { | ||
var wrappedComponent = markRaw({ | ||
const wrappedComponent = markRaw({ | ||
name: 'withFieldWrapper', | ||
props: { | ||
label: { | ||
type: String, | ||
default: undefined | ||
}, | ||
modelValue: { | ||
@@ -153,28 +154,15 @@ type: null, | ||
}, | ||
setup: function setup (props, ref) { | ||
var attrs = ref.attrs; | ||
var ref$1 = props._veeValidateConfig; | ||
var path = ref$1.path; | ||
var mapProps = ref$1.mapProps; | ||
var ref$2 = toRefs(props); | ||
var validations = ref$2.validations; | ||
var modelValue = ref$2.modelValue; | ||
var initialValue = modelValue ? modelValue.value : undefined; | ||
var label = computed(function () { return props.label; }); | ||
setup (props, { attrs }) { | ||
const { path, mapProps } = props._veeValidateConfig; | ||
const { validations, modelValue } = toRefs(props); | ||
const initialValue = modelValue ? modelValue.value : undefined; | ||
// Build a fully qualified field name using dot notation for nested fields | ||
// ex: user.name | ||
var name = path ? (path + "." + (attrs.model)) : attrs.model; | ||
var ref$3 = useField(name, validations, { | ||
initialValue: initialValue, | ||
label: label | ||
const name = path ? `${path}.${attrs.model}` : attrs.model; | ||
const { value, errorMessage, meta, setTouched, errors } = useField(name, validations, { | ||
initialValue | ||
}); | ||
var value = ref$3.value; | ||
var errorMessage = ref$3.errorMessage; | ||
var meta = ref$3.meta; | ||
var setTouched = ref$3.setTouched; | ||
var errors = ref$3.errors; | ||
if (modelValue) { | ||
watch(modelValue, function (val) { | ||
watch(modelValue, (val) => { | ||
value.value = val; | ||
@@ -184,13 +172,15 @@ }); | ||
var resolvedComponent = resolveDynamicComponent(Comp); | ||
const resolvedComponent = resolveDynamicComponent(Comp); | ||
return function renderWithField () { | ||
return h(resolvedComponent, Object.assign({}, props, | ||
attrs, | ||
mapProps({ | ||
return h(resolvedComponent, { | ||
...props, | ||
...attrs, | ||
...mapProps({ | ||
errorMessage: unref(errorMessage), | ||
errors: unref(errors), | ||
meta: meta, | ||
setTouched: setTouched | ||
}, el))) | ||
meta, | ||
setTouched | ||
}, el) | ||
}) | ||
} | ||
@@ -206,3 +196,2 @@ } | ||
export { mapElementsInSchema, withField }; | ||
export default VeeValidatePlugin; | ||
export { VeeValidatePlugin as default }; |
/** | ||
* @formvuelate/plugin-vee-validate v2.4.0 | ||
* (c) 2021 Abdelrahman Awad <logaretm1@gmail.com> | ||
* @license MIT | ||
*/ | ||
* plugin-vee-validate v3.3.1 | ||
*/ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('vee-validate')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'vue', 'vee-validate'], factory) : | ||
(factory((global['@formvuelate/pluginVeeValidate'] = {}),global.Vue,global.VeeValidate)); | ||
}(this, (function (exports,vue,veeValidate) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('vue'), require('vee-validate')) : | ||
typeof define === 'function' && define.amd ? define(['vue', 'vee-validate'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.FormvuelatePluginVeeValidate = factory(global.Vue, global.VeeValidate)); | ||
}(this, (function (vue, veeValidate) { 'use strict'; | ||
/** | ||
* For a Schema, find the elements in each of the rows and remap the element with the given function | ||
* @param {Array} schema | ||
* @param {Function} fn | ||
* | ||
* @returns {Array} | ||
*/ | ||
var mapElementsInSchema = function (schema, fn) { return schema.map(function (row) { return row.map(function (el) { return fn(el); }); }); }; | ||
/** | ||
* For a Schema, find the elements in each of the rows and remap the element with the given function | ||
* @param {Array} schema | ||
* @param {Function} fn | ||
* | ||
* @returns {Array} | ||
*/ | ||
const mapElementsInSchema = (schema, fn) => schema.map(row => row.map(el => fn(el))); | ||
/** | ||
* Maps the validation state to props | ||
*/ | ||
function defaultMapProps (validation) { | ||
return { | ||
validation: validation | ||
/** | ||
* Maps the validation state to props | ||
*/ | ||
function defaultMapProps (validation) { | ||
return { | ||
validation | ||
} | ||
} | ||
} | ||
var VEE_VALIDATE_FVL_FORM_KEY = 'vee-validate-fvl-form-context'; | ||
const VEE_VALIDATE_FVL_FORM_KEY = 'vee-validate-fvl-form-context'; | ||
function VeeValidatePlugin (opts) { | ||
// Maps the validation state exposed by vee-validate to components | ||
var mapProps = (opts && opts.mapProps) || defaultMapProps; | ||
function VeeValidatePlugin (opts) { | ||
// Maps the validation state exposed by vee-validate to components | ||
const mapProps = (opts && opts.mapProps) || defaultMapProps; | ||
return function veeValidatePlugin (baseReturns) { | ||
// Take the parsed schema from SchemaForm setup returns | ||
var parsedSchema = baseReturns.parsedSchema; | ||
var formBinds = baseReturns.formBinds; | ||
return function veeValidatePlugin (baseReturns) { | ||
// Take the parsed schema from SchemaForm setup returns | ||
const { parsedSchema, formBinds } = baseReturns; | ||
// Get additional properties not defined on the `SchemaForm` derivatives | ||
var ref = vue.getCurrentInstance(); | ||
var formAttrs = ref.attrs; | ||
// try to retrieve vee-validate form from the root schema if possible | ||
var formContext = vue.inject(VEE_VALIDATE_FVL_FORM_KEY, undefined); | ||
if (!formContext) { | ||
// if non-existent create one and provide it for nested schemas | ||
formContext = veeValidate.useForm({ | ||
validationSchema: formAttrs['validation-schema'] || formAttrs.validationSchema, | ||
initialErrors: formAttrs['initial-errors'] || formAttrs.initialErrors, | ||
initialTouched: formAttrs['initial-touched'] || formAttrs.initialTouched | ||
}); | ||
// Get additional properties not defined on the `SchemaForm` derivatives | ||
const { attrs: formAttrs } = vue.getCurrentInstance() || { attrs: {} }; | ||
// try to retrieve vee-validate form from the root schema if possible | ||
let formContext = vue.inject(VEE_VALIDATE_FVL_FORM_KEY, undefined); | ||
if (!formContext) { | ||
// if non-existent create one and provide it for nested schemas | ||
formContext = veeValidate.useForm({ | ||
validationSchema: formAttrs['validation-schema'] || formAttrs.validationSchema, | ||
initialErrors: formAttrs['initial-errors'] || formAttrs.initialErrors, | ||
initialTouched: formAttrs['initial-touched'] || formAttrs.initialTouched | ||
}); | ||
vue.provide(VEE_VALIDATE_FVL_FORM_KEY, formContext); | ||
} | ||
vue.provide(VEE_VALIDATE_FVL_FORM_KEY, formContext); | ||
} | ||
var handleSubmit = formContext.handleSubmit; | ||
const { handleSubmit } = formContext; | ||
function mapField (el, path) { | ||
if ( path === void 0 ) path = ''; | ||
function mapField (el, path = '') { | ||
// Handles nested schemas | ||
// doesn't treat nested forms as fields | ||
// instead goes over their fields and maps them recursively | ||
if (el.schema) { | ||
path = path ? `${path}.${el.model}` : el.model; | ||
// Handles nested schemas | ||
// doesn't treat nested forms as fields | ||
// instead goes over their fields and maps them recursively | ||
if (el.schema) { | ||
path = path ? (path + "." + (el.model)) : el.model; | ||
// Make sure we only deal with schema arrays and not nested objects | ||
const schemaArray = Array.isArray(el.schema) | ||
? el.schema | ||
: Object.keys(el.schema).map(model => { | ||
return { | ||
model, | ||
...el.schema[model] | ||
} | ||
}); | ||
// Make sure we only deal with schema arrays and not nested objects | ||
var schemaArray = Array.isArray(el.schema) ? el.schema : Object.keys(el.schema).map(function (model) { | ||
return Object.assign({}, {model: model}, | ||
el.schema[model]) | ||
}); | ||
return { | ||
...el, | ||
schema: schemaArray.map(nestedField => mapField(nestedField, path)) | ||
} | ||
} | ||
return Object.assign({}, el, | ||
{schema: schemaArray.map(function (nestedField) { return mapField(nestedField, path); })}) | ||
return { | ||
...el, | ||
// namespaced prop to avoid clash with users' props | ||
_veeValidateConfig: { | ||
mapProps, | ||
path | ||
}, | ||
component: withField(el) | ||
} | ||
} | ||
return Object.assign({}, el, | ||
// namespaced prop to avoid clash with users' props | ||
{_veeValidateConfig: { | ||
mapProps: mapProps, | ||
path: path | ||
}, | ||
component: withField(el)}) | ||
} | ||
// Map components in schema to enhanced versions with `useField` | ||
const formSchemaWithVeeValidate = vue.computed(() => mapElementsInSchema(parsedSchema.value, mapField)); | ||
// Map components in schema to enhanced versions with `useField` | ||
var formSchemaWithVeeValidate = vue.computed(function () { return mapElementsInSchema(parsedSchema.value, mapField); }); | ||
// override the submit function with one that triggers validation | ||
const formSubmit = formBinds.value.onSubmit; | ||
const onSubmit = handleSubmit((_, { evt }) => { | ||
formSubmit(evt); | ||
}); | ||
// override the submit function with one that triggers validation | ||
var formSubmit = formBinds.value.onSubmit; | ||
var onSubmit = handleSubmit(function (_, ref) { | ||
var evt = ref.evt; | ||
formSubmit(evt); | ||
}); | ||
return Object.assign({}, baseReturns, | ||
{formBinds: vue.computed(function () { | ||
return Object.assign({}, baseReturns.formBinds.value, | ||
{onSubmit: onSubmit}) | ||
}), | ||
slotBinds: vue.computed(function () { | ||
return Object.assign({}, baseReturns.slotBinds.value, | ||
{validation: { | ||
errors: formContext.errors.value, | ||
values: formContext.values, | ||
isSubmitting: formContext.isSubmitting.value, | ||
submitCount: formContext.submitCount.value, | ||
meta: formContext.meta.value | ||
}}) | ||
}), | ||
parsedSchema: formSchemaWithVeeValidate}) | ||
return { | ||
...baseReturns, | ||
formBinds: vue.computed(() => { | ||
return { | ||
...baseReturns.formBinds.value, | ||
onSubmit | ||
} | ||
}), | ||
slotBinds: vue.computed(() => { | ||
return { | ||
...baseReturns.slotBinds.value, | ||
validation: { | ||
errors: formContext.errors.value, | ||
values: formContext.values, | ||
isSubmitting: formContext.isSubmitting.value, | ||
submitCount: formContext.submitCount.value, | ||
meta: formContext.meta.value | ||
} | ||
} | ||
}), | ||
parsedSchema: formSchemaWithVeeValidate | ||
} | ||
} | ||
} | ||
} | ||
// Used to track if a component was already marked | ||
// very important to avoid re-creating components when re-rendering | ||
var COMPONENT_LOOKUP = new Map(); | ||
// Used to track if a component was already marked | ||
// very important to avoid re-creating components when re-rendering | ||
const COMPONENT_LOOKUP = new Map(); | ||
function withField (el) { | ||
var Comp = el.component; | ||
function withField (el) { | ||
const Comp = el.component; | ||
if (COMPONENT_LOOKUP.has(Comp)) { | ||
return COMPONENT_LOOKUP.get(Comp) | ||
} | ||
if (COMPONENT_LOOKUP.has(Comp)) { | ||
return COMPONENT_LOOKUP.get(Comp) | ||
} | ||
var wrappedComponent = vue.markRaw({ | ||
name: 'withFieldWrapper', | ||
props: { | ||
label: { | ||
type: String, | ||
default: undefined | ||
const wrappedComponent = vue.markRaw({ | ||
name: 'withFieldWrapper', | ||
props: { | ||
modelValue: { | ||
type: null, | ||
default: undefined | ||
}, | ||
validations: { | ||
type: [String, Object, Function], | ||
default: undefined | ||
}, | ||
_veeValidateConfig: { | ||
type: Object, | ||
required: true | ||
} | ||
}, | ||
modelValue: { | ||
type: null, | ||
default: undefined | ||
}, | ||
validations: { | ||
type: [String, Object, Function], | ||
default: undefined | ||
}, | ||
_veeValidateConfig: { | ||
type: Object, | ||
required: true | ||
} | ||
}, | ||
setup: function setup (props, ref) { | ||
var attrs = ref.attrs; | ||
setup (props, { attrs }) { | ||
const { path, mapProps } = props._veeValidateConfig; | ||
const { validations, modelValue } = vue.toRefs(props); | ||
const initialValue = modelValue ? modelValue.value : undefined; | ||
// Build a fully qualified field name using dot notation for nested fields | ||
// ex: user.name | ||
const name = path ? `${path}.${attrs.model}` : attrs.model; | ||
const { value, errorMessage, meta, setTouched, errors } = veeValidate.useField(name, validations, { | ||
initialValue | ||
}); | ||
var ref$1 = props._veeValidateConfig; | ||
var path = ref$1.path; | ||
var mapProps = ref$1.mapProps; | ||
var ref$2 = vue.toRefs(props); | ||
var validations = ref$2.validations; | ||
var modelValue = ref$2.modelValue; | ||
var initialValue = modelValue ? modelValue.value : undefined; | ||
var label = vue.computed(function () { return props.label; }); | ||
// Build a fully qualified field name using dot notation for nested fields | ||
// ex: user.name | ||
var name = path ? (path + "." + (attrs.model)) : attrs.model; | ||
var ref$3 = veeValidate.useField(name, validations, { | ||
initialValue: initialValue, | ||
label: label | ||
}); | ||
var value = ref$3.value; | ||
var errorMessage = ref$3.errorMessage; | ||
var meta = ref$3.meta; | ||
var setTouched = ref$3.setTouched; | ||
var errors = ref$3.errors; | ||
if (modelValue) { | ||
vue.watch(modelValue, (val) => { | ||
value.value = val; | ||
}); | ||
} | ||
if (modelValue) { | ||
vue.watch(modelValue, function (val) { | ||
value.value = val; | ||
}); | ||
} | ||
const resolvedComponent = vue.resolveDynamicComponent(Comp); | ||
var resolvedComponent = vue.resolveDynamicComponent(Comp); | ||
return function renderWithField () { | ||
return vue.h(resolvedComponent, Object.assign({}, props, | ||
attrs, | ||
mapProps({ | ||
errorMessage: vue.unref(errorMessage), | ||
errors: vue.unref(errors), | ||
meta: meta, | ||
setTouched: setTouched | ||
}, el))) | ||
return function renderWithField () { | ||
return vue.h(resolvedComponent, { | ||
...props, | ||
...attrs, | ||
...mapProps({ | ||
errorMessage: vue.unref(errorMessage), | ||
errors: vue.unref(errors), | ||
meta, | ||
setTouched | ||
}, el) | ||
}) | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
// Assign it to the cache to avoid re-creating it | ||
COMPONENT_LOOKUP.set(Comp, wrappedComponent); | ||
// Assign it to the cache to avoid re-creating it | ||
COMPONENT_LOOKUP.set(Comp, wrappedComponent); | ||
return wrappedComponent | ||
} | ||
return wrappedComponent | ||
} | ||
exports.mapElementsInSchema = mapElementsInSchema; | ||
exports['default'] = VeeValidatePlugin; | ||
exports.withField = withField; | ||
return VeeValidatePlugin; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); |
@@ -1,7 +0,1 @@ | ||
/** | ||
* @formvuelate/plugin-vee-validate v2.4.0 | ||
* (c) 2021 Abdelrahman Awad <logaretm1@gmail.com> | ||
* @license MIT | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue"),require("vee-validate")):"function"==typeof define&&define.amd?define(["exports","vue","vee-validate"],t):t(e["@formvuelate/pluginVeeValidate"]={},e.Vue,e.VeeValidate)}(this,function(e,S,O){"use strict";var d=function(e,t){return e.map(function(e){return e.map(function(e){return t(e)})})};function t(e){return{validation:e}}var m="vee-validate-fvl-form-context";var a=new Map;function v(j){var y=j.component;if(a.has(y))return a.get(y);var e=S.markRaw({name:"withFieldWrapper",props:{label:{type:String,default:void 0},modelValue:{type:null,default:void 0},validations:{type:[String,Object,Function],default:void 0},_veeValidateConfig:{type:Object,required:!0}},setup:function(e,t){var a=t.attrs,n=e._veeValidateConfig,i=n.path,r=n.mapProps,o=S.toRefs(e),u=o.validations,s=o.modelValue,l=s?s.value:void 0,c=S.computed(function(){return e.label}),d=i?i+"."+a.model:a.model,m=O.useField(d,u,{initialValue:l,label:c}),v=m.value,f=m.errorMessage,p=m.meta,h=m.setTouched,b=m.errors;s&&S.watch(s,function(e){v.value=e});var g=S.resolveDynamicComponent(y);return function(){return S.h(g,Object.assign({},e,a,r({errorMessage:S.unref(f),errors:S.unref(b),meta:p,setTouched:h},j)))}}});return a.set(y,e),e}e.mapElementsInSchema=d,e.default=function(e){var c=e&&e.mapProps||t;return function(e){var t=e.parsedSchema,a=e.formBinds,n=S.getCurrentInstance().attrs,i=S.inject(m,void 0);i||(i=O.useForm({validationSchema:n["validation-schema"]||n.validationSchema,initialErrors:n["initial-errors"]||n.initialErrors,initialTouched:n["initial-touched"]||n.initialTouched}),S.provide(m,i));var r=i.handleSubmit;function o(t,a){if(void 0===a&&(a=""),t.schema){a=a?a+"."+t.model:t.model;var e=Array.isArray(t.schema)?t.schema:Object.keys(t.schema).map(function(e){return Object.assign({},{model:e},t.schema[e])});return Object.assign({},t,{schema:e.map(function(e){return o(e,a)})})}return Object.assign({},t,{_veeValidateConfig:{mapProps:c,path:a},component:v(t)})}var u=S.computed(function(){return d(t.value,o)}),s=a.value.onSubmit,l=r(function(e,t){var a=t.evt;s(a)});return Object.assign({},e,{formBinds:S.computed(function(){return Object.assign({},e.formBinds.value,{onSubmit:l})}),slotBinds:S.computed(function(){return Object.assign({},e.slotBinds.value,{validation:{errors:i.errors.value,values:i.values,isSubmitting:i.isSubmitting.value,submitCount:i.submitCount.value,meta:i.meta.value}})}),parsedSchema:u})}},e.withField=v,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("vue"),require("vee-validate")):"function"==typeof define&&define.amd?define(["vue","vee-validate"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).FormvuelatePluginVeeValidate=t(e.Vue,e.VeeValidate)}(this,(function(e,t){"use strict";function a(e){return{validation:e}}const i="vee-validate-fvl-form-context";const n=new Map;function o(a){const i=a.component;if(n.has(i))return n.get(i);const o=e.markRaw({name:"withFieldWrapper",props:{modelValue:{type:null,default:void 0},validations:{type:[String,Object,Function],default:void 0},_veeValidateConfig:{type:Object,required:!0}},setup(n,{attrs:o}){const{path:r,mapProps:u}=n._veeValidateConfig,{validations:s,modelValue:l}=e.toRefs(n),d=l?l.value:void 0,m=r?`${r}.${o.model}`:o.model,{value:c,errorMessage:v,meta:p,setTouched:f,errors:h}=t.useField(m,s,{initialValue:d});l&&e.watch(l,(e=>{c.value=e}));const b=e.resolveDynamicComponent(i);return function(){return e.h(b,{...n,...o,...u({errorMessage:e.unref(v),errors:e.unref(h),meta:p,setTouched:f},a)})}}});return n.set(i,o),o}return function(n){const r=n&&n.mapProps||a;return function(a){const{parsedSchema:n,formBinds:u}=a,{attrs:s}=e.getCurrentInstance()||{attrs:{}};let l=e.inject(i,void 0);l||(l=t.useForm({validationSchema:s["validation-schema"]||s.validationSchema,initialErrors:s["initial-errors"]||s.initialErrors,initialTouched:s["initial-touched"]||s.initialTouched}),e.provide(i,l));const{handleSubmit:d}=l;function m(e,t=""){if(e.schema){t=t?`${t}.${e.model}`:e.model;const a=Array.isArray(e.schema)?e.schema:Object.keys(e.schema).map((t=>({model:t,...e.schema[t]})));return{...e,schema:a.map((e=>m(e,t)))}}return{...e,_veeValidateConfig:{mapProps:r,path:t},component:o(e)}}const c=e.computed((()=>{return e=n.value,t=m,e.map((e=>e.map((e=>t(e)))));var e,t})),v=u.value.onSubmit,p=d(((e,{evt:t})=>{v(t)}));return{...a,formBinds:e.computed((()=>({...a.formBinds.value,onSubmit:p}))),slotBinds:e.computed((()=>({...a.slotBinds.value,validation:{errors:l.errors.value,values:l.values,isSubmitting:l.isSubmitting.value,submitCount:l.submitCount.value,meta:l.meta.value}}))),parsedSchema:c}}}})); |
{ | ||
"name": "@formvuelate/plugin-vee-validate", | ||
"version": "2.4.0", | ||
"version": "3.3.1", | ||
"description": "FormVueLate Vee-validate plugin", | ||
@@ -12,3 +12,3 @@ "main": "dist/formvuelate-plugin-vee-validate.cjs.js", | ||
"type": "git", | ||
"url": "git+ssh://git@github.com/formvuelate/formvuelate-plugin-vee-validate.git" | ||
"url": "git+ssh://git@github.com/formvuelate/formvuelate.git" | ||
}, | ||
@@ -21,3 +21,2 @@ "author": { | ||
"scripts": { | ||
"build": "rollit --global vee-validate:VeeValidate vue:Vue --externals vee-validate vue", | ||
"test": "yarn test:unit", | ||
@@ -29,19 +28,2 @@ "test:unit": "jest --coverage", | ||
"devDependencies": { | ||
"@babel/preset-env": "^7.9.0", | ||
"@vue/test-utils": "^2.0.0-alpha.7", | ||
"babel-eslint": "^10.1.0", | ||
"babel-jest": "^25.2.6", | ||
"eslint": "^7.3.1", | ||
"eslint-config-standard": "^14.1.1", | ||
"eslint-plugin-import": "^2.22.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^4.2.1", | ||
"eslint-plugin-standard": "^4.0.1", | ||
"flush-promises": "^1.0.2", | ||
"formvuelate": "^3.0.0", | ||
"jest": "^26.6.3", | ||
"rollit": "^0.0.9", | ||
"vee-validate": "^4.0.0-beta.16", | ||
"vue": "^3.0.0-beta.12", | ||
"vue-jest": "^5.0.0-alpha.0", | ||
"yup": "^0.29.3" | ||
@@ -59,8 +41,9 @@ }, | ||
"bugs": { | ||
"url": "https://github.com/formvuelate/formvuelate-plugin-vee-validate/issues" | ||
"url": "https://github.com/formvuelate/formvuelate/issues" | ||
}, | ||
"homepage": "https://github.com/formvuelate/formvuelate-plugin-vee-validate#readme", | ||
"homepage": "https://github.com/formvuelate/formvuelate#readme", | ||
"module": "dist/formvuelate-plugin-vee-validate.es.js", | ||
"unpkg": "dist/formvuelate-plugin-vee-validate.js", | ||
"browser": "dist/formvuelate-plugin-vee-validate.es.js" | ||
"browser": "dist/formvuelate-plugin-vee-validate.es.js", | ||
"gitHead": "450946767fd09b7d26a43c3e320c563388785b9d" | ||
} |
@@ -11,3 +11,3 @@ import { toRefs, h, computed, markRaw, watch, getCurrentInstance, unref, resolveDynamicComponent, inject, provide } from 'vue' | ||
*/ | ||
export const mapElementsInSchema = (schema, fn) => schema.map(row => row.map(el => fn(el))) | ||
const mapElementsInSchema = (schema, fn) => schema.map(row => row.map(el => fn(el))) | ||
@@ -34,3 +34,3 @@ /** | ||
// Get additional properties not defined on the `SchemaForm` derivatives | ||
const { attrs: formAttrs } = getCurrentInstance() | ||
const { attrs: formAttrs } = getCurrentInstance() || { attrs: {} } | ||
// try to retrieve vee-validate form from the root schema if possible | ||
@@ -59,8 +59,10 @@ let formContext = inject(VEE_VALIDATE_FVL_FORM_KEY, undefined) | ||
// Make sure we only deal with schema arrays and not nested objects | ||
const schemaArray = Array.isArray(el.schema) ? el.schema : Object.keys(el.schema).map(model => { | ||
return { | ||
model, | ||
...el.schema[model] | ||
} | ||
}) | ||
const schemaArray = Array.isArray(el.schema) | ||
? el.schema | ||
: Object.keys(el.schema).map(model => { | ||
return { | ||
model, | ||
...el.schema[model] | ||
} | ||
}) | ||
@@ -122,3 +124,3 @@ return { | ||
export function withField (el) { | ||
function withField (el) { | ||
const Comp = el.component | ||
@@ -133,6 +135,2 @@ | ||
props: { | ||
label: { | ||
type: String, | ||
default: undefined | ||
}, | ||
modelValue: { | ||
@@ -155,3 +153,2 @@ type: null, | ||
const initialValue = modelValue ? modelValue.value : undefined | ||
const label = computed(() => props.label) | ||
// Build a fully qualified field name using dot notation for nested fields | ||
@@ -161,4 +158,3 @@ // ex: user.name | ||
const { value, errorMessage, meta, setTouched, errors } = useField(name, validations, { | ||
initialValue, | ||
label | ||
initialValue | ||
}) | ||
@@ -165,0 +161,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
8
27506
649