43 lines
34 KiB
JavaScript
43 lines
34 KiB
JavaScript
|
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define("vue-formulate",[],r):"object"==typeof exports?exports["vue-formulate"]=r():t["vue-formulate"]=r()}("undefined"!=typeof self?self:this,function(){return function(t){function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}var e={};return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},r.p="",r(r.s=9)}([function(t,r,e){"use strict";function n(){p=!1}function o(t){if(!t)return void(f!==h&&(f=h,n()));if(t!==f){if(t.length!==h.length)throw new Error("Custom alphabet for shortid must be "+h.length+" unique characters. You submitted "+t.length+" characters: "+t);var r=t.split("").filter(function(t,r,e){return r!==e.lastIndexOf(t)});if(r.length)throw new Error("Custom alphabet for shortid must be "+h.length+" unique characters. These characters were not unique: "+r.join(", "));f=t,n()}}function i(t){return o(t),f}function a(t){d.seed(t),l!==t&&(n(),l=t)}function u(){f||o(h);for(var t,r=f.split(""),e=[],n=d.nextValue();r.length>0;)n=d.nextValue(),t=Math.floor(n*r.length),e.push(r.splice(t,1)[0]);return e.join("")}function s(){return p||(p=u())}function c(t){return s()[t]}var f,l,p,d=e(27),h="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";t.exports={characters:i,seed:a,lookup:c,shuffled:s}},function(t,r,e){t.exports=e(10)},function(t,r,e){"use strict";function n(t){return!0===o(t)&&"[object Object]"===Object.prototype.toString.call(t)}/*!
|
||
|
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
||
|
*
|
||
|
* Copyright (c) 2014-2017, Jon Schlinkert.
|
||
|
* Released under the MIT License.
|
||
|
*/
|
||
|
var o=e(15);t.exports=function(t){var r,e;return!1!==n(t)&&("function"==typeof(r=t.constructor)&&(e=r.prototype,!1!==n(e)&&!1!==e.hasOwnProperty("isPrototypeOf")))}},function(t,r){t.exports=function(t,r,e,n,o,i){var a,u=t=t||{},s=typeof t.default;"object"!==s&&"function"!==s||(a=t,u=t.default);var c="function"==typeof u?u.options:u;r&&(c.render=r.render,c.staticRenderFns=r.staticRenderFns,c._compiled=!0),e&&(c.functional=!0),o&&(c._scopeId=o);var f;if(i?(f=function(t){t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,t||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),n&&n.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(i)},c._ssrRegister=f):n&&(f=n),f){var l=c.functional,p=l?c.render:c.beforeCreate;l?(c._injectStyles=f,c.render=function(t,r){return f.call(r),p(t,r)}):c.beforeCreate=p?[].concat(p,f):[f]}return{esModule:a,exports:u,options:c}}},function(t,r,e){"use strict";function n(t){return function(){var r=t.apply(this,arguments);return new Promise(function(t,e){function n(o,i){try{var a=r[o](i),u=a.value}catch(t){return void e(t)}if(!a.done)return Promise.resolve(u).then(function(t){n("next",t)},function(t){n("throw",t)});t(u)}return n("next")})}}Object.defineProperty(r,"__esModule",{value:!0});var o=e(1),i=function(t){return t&&t.__esModule?t:{default:t}}(o),a=e(5);r.default={props:{name:{type:String,required:!0},module:{type:[String,Boolean],default:function(){return this.$formulate.options.vuexModule}},initial:{type:Object,default:function(){return{}}}},data:function(){return{parentIdentifier:"vue-formulate-wrapper-element"}},computed:{m:function(){return this.module?this.module+"/":""},hasErrors:function(){return this.$store.getters[this.m+"hasErrors"][this.name]||!1},values:function(){return this.$store.getters[this.m+"formValues"][this.name]||{}},errors:function(){return this.$store.getters[this.m+"formErrors"][this.name]||{}},validationErrors:function(){return this.$store.getters[this.m+"formValidationErrors"][this.name]||{}},fields:function(){return this.$formulate.fields(this.$vnode)}},created:function(){this.hydrate(this.initial)},methods:{hydrate:function(t){var r=!0,e=!1,n=void 0;try{for(var o,i=this.fields[Symbol.iterator]();!(r=(o=i.next()).done);r=!0){var a=o.value;this.$store.commit(this.m+"setFieldValue",{field:a.name,value:t[a.name],form:this.name})}}catch(t){e=!0,n=t}finally{try{!r&&i.return&&i.return()}finally{if(e)throw n}}this.updateFormValidation()},update:function(t){this.$store.commit(this.m+"setFieldValue",Object.assign(t,{form:this.name})),this.updateFormValidation()},updateFieldErrors:function(t){this.$store.commit(this.m+"setFieldErrors",Object.assign(t,{form:this.name}))},updateFieldValidationErrors:function(t){this.$store.commit(this.m+"setFieldValidationErrors",Object.assign(t,{form:this.name}))},validateField:function(){function t(t){return r.apply(this,arguments)}var r=n(i.default.mark(function t(r){var e,n=r.field,o=r.validation;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.$formulate.validationErrors({field:n,value:this.values[n]},o,this.values);case 2:return e=t.sent,(0,a.equals)(e,this.validationErrors[n]||[])||this.updateFieldValidationErrors({field:n,errors:e}),t.abrupt("return",e);case 5:case"end":return t.stop()}},t,this)}));return t}(),updateFormValidation:function(){var t=this;this.fields.map(function(){var r=n(i.default.mark(function r(e){return i.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",t.validateField({field:e.name,validation:e.validation}));case 1:case"end":return r.stop()}},r,t)}));return function(t){return r.apply(this,arguments)}}())},submit:function(){alert("submitting form")}}}},function(t,r,e){"use strict";function n(t,r){var e=t.length;if(e!==r.length)return!1;for(var n=0;n<e;n++)if(t[n]!==r[n])return!1;return!0}function o(t,r){var e=(0,s.default)(t);for(var n in e)e[n]=r(n,e[n]);return e}function i(t,r){var e={};for(var n in t)r(n,t[n])&&(e[n]=t[n]);return e}function a(t,r,e){for(va
|
||
|
* for-in <https://github.com/jonschlinkert/for-in>
|
||
|
*
|
||
|
* Copyright (c) 2014-2017, Jon Schlinkert.
|
||
|
* Released under the MIT License.
|
||
|
*/
|
||
|
t.exports=function(t,r,e){for(var n in t)if(!1===r.call(e,t[n],n,t))break}},function(t,r,e){"use strict";function n(t,r,e){return r in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}Object.defineProperty(r,"__esModule",{value:!0});var o=e(5),i=e(25),a=function(t){return t&&t.__esModule?t:{default:t}}(i);r.default={props:{type:{type:[String,Boolean],default:"text"},name:{type:String,required:!0},initial:{type:[String,Boolean],default:!1},validation:{type:[String,Boolean],default:!1},errors:{type:Array,default:function(){return[]}},label:{type:[String,Boolean],default:!1},id:{type:[String],default:function(){return a.default.generate()}}},computed:{hasCustomInput:function(){return this.$slots.default&&this.$slots.default.length},isTextInput:function(){return!this.hasCustomInput&&o.inputTypes.text.includes(this.type)},isButtonInput:function(){return!this.hasCustomInput&&o.inputTypes.button.includes(this.type)},isListInput:function(){return!this.hasCustomInput&&o.inputTypes.list.includes(this.type)},form:function(){for(var t=this.$parent;t&&t.$data&&"vue-formulate-wrapper-element"!==t.$data.parentIdentifier;)t=t.$parent;if(!t.$data||"vue-formulate-wrapper-element"!==t.$data.parentIdentifier)throw new Error("FormulateElement has no FormulateWrapper element");return t},values:function(){return this.form.values},value:function(){return this.values[this.name]},module:function(){return this.form.$props.module},formName:function(){return this.form.$props.name},validationErrors:function(){return this.form.validationErrors[this.name]||[]},storeErrors:function(){return this.form.errors[this.name]||[]},localAndValidationErrors:function(){return this.errors.concat(this.validationErrors)},attributes:function(){return this.$props},val:{set:function(t){this.form.update({field:this.name,value:t}),this.$refs.input.value=t},get:function(){return this.value}}},watch:{errors:function(){this.form.updateFieldErrors({field:this.name,errors:this.localAndValidationErrors})}},created:function(){!1!==this.initial&&this.form.hydrate(n({},this.name,this.initial))}}},function(t,r,e){"use strict";function n(t,r){for(var e,n=0,i="";!e;)i+=t(r>>4*n&15|o()),e=r<Math.pow(16,n+1),n++;return i}var o=e(28);t.exports=n},function(t,r,e){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}function o(t){if(Array.isArray(t)){for(var r=0,e=Array(t.length);r<t.length;r++)e[r]=t[r];return e}return Array.from(t)}function i(t){return function(){var r=t.apply(this,arguments);return new Promise(function(t,e){function n(o,i){try{var a=r[o](i),u=a.value}catch(t){return void e(t)}if(!a.done)return Promise.resolve(u).then(function(t){n("next",t)},function(t){n("throw",t)});t(u)}return n("next")})}}function a(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0}),r.mapModels=void 0;var u=e(1),s=n(u),c=function(){function t(t,r){var e=[],n=!0,o=!1,i=void 0;try{for(var a,u=t[Symbol.iterator]();!(n=(a=u.next()).done)&&(e.push(a.value),!r||e.length!==r);n=!0);}catch(t){o=!0,i=t}finally{try{!n&&u.return&&u.return()}finally{if(o)throw i}}return e}return function(r,e){if(Array.isArray(r))return r;if(Symbol.iterator in Object(r))return t(r,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),f=function(){function t(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(r,e,n){return e&&t(r.prototype,e),n&&t(r,n),r}}(),l=e(12);Object.keys(l).forEach(function(t){"default"!==t&&"__esModule"!==t&&Object.defineProperty(r,t,{enumerable:!0,get:function(){return l[t]}})});var p=e(13),d=n(p),h=e(24),m=n(h),v=e(34),y=n(v),g=e(35),b=n(g),x=function(){function t(){a(this,t),this.defaultOptions={registerComponents:!0,tags:{Formulate:"formulate",FormulateElement:"formulate-element"},errors:{},rules:{},vuexModule:!1},this.errors=b.default,this.rules=y.default}return f(t,[{key:"install",value:function(t){var r=arguments.length>
|
||
|
* isobject <https://github.com/jonschlinkert/isobject>
|
||
|
*
|
||
|
* Copyright (c) 2014-2017, Jon Schlinkert.
|
||
|
* Released under the MIT License.
|
||
|
*/
|
||
|
t.exports=function(t){return null!=t&&"object"==typeof t&&!1===Array.isArray(t)}},function(t,r,e){"use strict";function n(t){var r=a(t);return n.hasOwnProperty(r)?n[r](t):t}/*!
|
||
|
* shallow-clone <https://github.com/jonschlinkert/shallow-clone>
|
||
|
*
|
||
|
* Copyright (c) 2015-2017, Jon Schlinkert.
|
||
|
* Released under the MIT License.
|
||
|
*/
|
||
|
var o=e(17),i=e(18),a=e(20);n.array=function(t){return t.slice()},n.date=function(t){return new Date(+t)},n.object=function(t){return o(t)?i({},t):t},n.map=function(t){return new Map(t)},n.regexp=function(t){var r="";return r+=t.multiline?"m":"",r+=t.global?"g":"",r+=t.ignoreCase?"i":"",new RegExp(t.source,r)},n.set=function(t){return new Set(t)},t.exports=n},function(t,r,e){"use strict";/*!
|
||
|
* is-extendable <https://github.com/jonschlinkert/is-extendable>
|
||
|
*
|
||
|
* Copyright (c) 2015-2017, Jon Schlinkert.
|
||
|
* Released under the MIT License.
|
||
|
*/
|
||
|
var n=e(2);t.exports=function(t){return n(t)||"function"==typeof t||Array.isArray(t)}},function(t,r,e){"use strict";function n(t,r){o(r)&&i(r,function(r,e){t[e]=r})}var o=e(19),i=e(6);t.exports=function(t,r){if(!o(t))throw new TypeError("expected the first argument to be an object");for(var e=arguments.length,i=0;++i<e;)n(t,arguments[i]);return t}},function(t,r,e){"use strict";/*!
|
||
|
* is-extendable <https://github.com/jonschlinkert/is-extendable>
|
||
|
*
|
||
|
* Copyright (c) 2015-2017, Jon Schlinkert.
|
||
|
* Released under the MIT License.
|
||
|
*/
|
||
|
var n=e(2);t.exports=function(t){return n(t)||"function"==typeof t||Array.isArray(t)}},function(t,r){function e(t){return t.constructor?t.constructor.name:null}function n(t){return Array.isArray?Array.isArray(t):t instanceof Array}function o(t){return t instanceof Error||"string"==typeof t.message&&t.constructor&&"number"==typeof t.constructor.stackTraceLimit}function i(t){return t instanceof Date||"function"==typeof t.toDateString&&"function"==typeof t.getDate&&"function"==typeof t.setDate}function a(t){return t instanceof RegExp||"string"==typeof t.flags&&"boolean"==typeof t.ignoreCase&&"boolean"==typeof t.multiline&&"boolean"==typeof t.global}function u(t,r){return"GeneratorFunction"===e(t)}function s(t){return"function"==typeof t.throw&&"function"==typeof t.return&&"function"==typeof t.next}function c(t){try{if("number"==typeof t.length&&"function"==typeof t.callee)return!0}catch(t){if(-1!==t.message.indexOf("callee"))return!0}return!1}function f(t){return!(!t.constructor||"function"!=typeof t.constructor.isBuffer)&&t.constructor.isBuffer(t)}var l=Object.prototype.toString;t.exports=function(t){if(void 0===t)return"undefined";if(null===t)return"null";var r=typeof t;if("boolean"===r)return"boolean";if("string"===r)return"string";if("number"===r)return"number";if("symbol"===r)return"symbol";if("function"===r)return u(t)?"generatorfunction":"function";if(n(t))return"array";if(f(t))return"buffer";if(c(t))return"arguments";if(i(t))return"date";if(o(t))return"error";if(a(t))return"regexp";switch(e(t)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(s(t))return"generator";switch(r=l.call(t)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return r.slice(8,-1).toLowerCase().replace(/\s/g,"")}},function(t,r){function e(t){return t.constructor?t.constructor.name:null}function n(t){return Array.isArray?Array.isArray(t):t instanceof Array}function o(t){return t instanceof Error||"string"==typeof t.message&&t.constructor&&"number"==typeof t.constructor.stackTraceLimit}function i(t){return t instanceof Date||"function"==typeof t.toDateString&&"function"==typeof t.getDate&&"function"==typeof t.setDate}function a(t){return t instanceof RegExp||"string"==typeof t.flags&&"boolean"==typeof t.ignoreCase&&"boolean"==typeof t.multiline&&"boolean"==typeof t.global}function u(t,r){return"GeneratorFunction"===e(t)}function s(t){return"function"==typeof t.throw&&"function"==typeof t.return&&"function"==typeof t.next}function c(t){try{if("number"==typeof t.length&&"function"==typeof t.callee)return!0}catch(t){if(-1!==t.message.indexOf("callee"))return!0}return!1}function f(t){return!(!t.constructor||"function"!=typeof t.constructor.isBuffer)&&t.constructor.isBuffer(t)}var l=Object.prototype.toString;t.exports=function(t){if(void 0===t)return"undefined";if(null===t)return"null";var r=typeof t;if("boolean"===r)return"boolean";if("string"===r)return"string";if("number"===r)return"number";if("symbol"===r)return"symbol";if("function"===r)return u(t)?"generatorfunction":"function";if(n(t))return"array";if(f(t))return"buffer";if(c(t))return"arguments";if(i(t))return"date";if(o(t))return"error";if(a(t))return"regexp";switch(e(t)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";
|
||
|
* for-own <https://github.com/jonschlinkert/for-own>
|
||
|
*
|
||
|
* Copyright (c) 2014-2017, Jon Schlinkert.
|
||
|
* Released under the MIT License.
|
||
|
*/
|
||
|
var n=e(6),o=Object.prototype.hasOwnProperty;t.exports=function(t,r,e){n(t,function(n,i){if(o.call(t,i))return r.call(e,t[i],i,t)})}},function(t,r,e){"use strict";var n=function(){var t=this,r=t.$createElement;return(t._self._c||r)("form",{staticClass:"formulate-element",on:{submit:function(r){r.preventDefault(),t.submit(r)}}},[t._t("default")],2)},o=[];n._withStripped=!0;var i={render:n,staticRenderFns:o};r.a=i},function(t,r,e){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=e(7),o=e.n(n);for(var i in n)"default"!==i&&function(t){e.d(r,t,function(){return n[t]})}(i);var a=e(33),u=e(3),s=u(o.a,a.a,!1,null,null,null);s.options.__file="src/components/FormulateElement.vue",r.default=s.exports},function(t,r,e){"use strict";t.exports=e(26)},function(t,r,e){"use strict";function n(r){return u.seed(r),t.exports}function o(r){return l=r,t.exports}function i(t){return void 0!==t&&u.characters(t),u.shuffled()}function a(){return c(l)}var u=e(0),s=(e(8),e(29)),c=e(30),f=e(31),l=e(32)||0;t.exports=a,t.exports.generate=a,t.exports.seed=n,t.exports.worker=o,t.exports.characters=i,t.exports.decode=s,t.exports.isValid=f},function(t,r,e){"use strict";function n(){return(i=(9301*i+49297)%233280)/233280}function o(t){i=t}var i=1;t.exports={nextValue:n,seed:o}},function(t,r,e){"use strict";function n(){if(!o||!o.getRandomValues)return 48&Math.floor(256*Math.random());var t=new Uint8Array(1);return o.getRandomValues(t),48&t[0]}var o="object"==typeof window&&(window.crypto||window.msCrypto);t.exports=n},function(t,r,e){"use strict";function n(t){var r=o.shuffled();return{version:15&r.indexOf(t.substr(0,1)),worker:15&r.indexOf(t.substr(1,1))}}var o=e(0);t.exports=n},function(t,r,e){"use strict";function n(t){var r="",e=Math.floor(.001*(Date.now()-s));return e===i?o++:(o=0,i=e),r+=a(u.lookup,c),r+=a(u.lookup,t),o>0&&(r+=a(u.lookup,o)),r+=a(u.lookup,e)}var o,i,a=e(8),u=e(0),s=1459707606518,c=6;t.exports=n},function(t,r,e){"use strict";function n(t){if(!t||"string"!=typeof t||t.length<6)return!1;for(var r=o.characters(),e=t.length,n=0;n<e;n++)if(-1===r.indexOf(t[n]))return!1;return!0}var o=e(0);t.exports=n},function(t,r,e){"use strict";t.exports=0},function(t,r,e){"use strict";var n=function(){var t=this,r=t.$createElement,e=t._self._c||r;return e("div",{staticClass:"formulate-element"},[e("div",{staticClass:"formulate-element-input-wrapper"},[t.label&&t.isTextInput?e("label",{attrs:{for:t.id},domProps:{textContent:t._s(t.label)}}):t._e(),t._v(" "),"checkbox"===t.type&&t.isTextInput?e("input",{directives:[{name:"model",rawName:"v-model",value:t.val,expression:"val"}],ref:"input",attrs:{name:t.name,id:t.id,type:"checkbox"},domProps:{checked:Array.isArray(t.val)?t._i(t.val,null)>-1:t.val},on:{change:function(r){var e=t.val,n=r.target,o=!!n.checked;if(Array.isArray(e)){var i=t._i(e,null);n.checked?i<0&&(t.val=e.concat([null])):i>-1&&(t.val=e.slice(0,i).concat(e.slice(i+1)))}else t.val=o}}}):"radio"===t.type&&t.isTextInput?e("input",{directives:[{name:"model",rawName:"v-model",value:t.val,expression:"val"}],ref:"input",attrs:{name:t.name,id:t.id,type:"radio"},domProps:{checked:t._q(t.val,null)},on:{change:function(r){t.val=null}}}):t.isTextInput?e("input",{directives:[{name:"model",rawName:"v-model",value:t.val,expression:"val"}],ref:"input",attrs:{name:t.name,id:t.id,type:t.type},domProps:{value:t.val},on:{input:function(r){r.target.composing||(t.val=r.target.value)}}}):t._e(),t._v(" "),t.isButtonInput?e("button",{attrs:{type:t.type,disabled:"submit"===t.type&&t.form.hasErrors},domProps:{textContent:t._s(t.label||t.name)}}):t._e(),t._v(" "),t.hasCustomInput?t._t("default"):t._e()],2),t._v(" "),t.localAndValidationErrors.length?e("ul",{staticClass:"formulate-errors"},t._l(t.localAndValidationErrors,function(r){return e("li",{key:r,domProps:{textContent:t._s(r)}})})):t._e()])},o=[];n._withStripped=!0;var i={render:n,staticRenderFns:o};r.a=i},function(t,r,e){"use strict";function n(t){return function(){var r=t.apply(this,arguments);return new Promise(function(t,e){function n(o,i){try{var a=r[o](i),u=a.value}catch(t){return void e(t
|