You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
validator/dist/js/demo.js

12 lines
34 KiB

4 years ago
(()=>{var e={422:e=>{var t=/^(?:submit|button|image|reset|file)$/i,n=/^(?:input|select|textarea|keygen)/i,r=/(\[[^\[\]]*\])/g;function i(e,t,n){if(0===t.length)return e=n;var r=t.shift(),o=r.match(/^\[(.+?)\]$/);if("[]"===r)return e=e||[],Array.isArray(e)?e.push(i(null,t,n)):(e._values=e._values||[],e._values.push(i(null,t,n))),e;if(o){var s=o[1],a=+s;isNaN(a)?(e=e||{})[s]=i(e[s],t,n):(e=e||[])[a]=i(e[a],t,n)}else e[r]=i(e[r],t,n);return e}function o(e,t,n){if(t.match(r)){i(e,function(e){var t=[],n=new RegExp(r),i=/^([^\[\]]*)/.exec(e);for(i[1]&&t.push(i[1]);null!==(i=n.exec(e));)t.push(i[1]);return t}(t),n)}else{var o=e[t];o?(Array.isArray(o)||(e[t]=[o]),e[t].push(n)):e[t]=n}return e}function s(e,t,n){return n=n.replace(/(\r)?\n/g,"\r\n"),n=(n=encodeURIComponent(n)).replace(/%20/g,"+"),e+(e?"&":"")+encodeURIComponent(t)+"="+n}e.exports=function(e,r){"object"!=typeof r?r={hash:!!r}:void 0===r.hash&&(r.hash=!0);for(var i=r.hash?{}:"",a=r.serializer||(r.hash?o:s),u=e&&e.elements?e.elements:[],l=Object.create(null),c=0;c<u.length;++c){var f=u[c];if((r.disabled||!f.disabled)&&f.name&&(n.test(f.nodeName)&&!t.test(f.type))){var p=f.name,d=f.value;if("checkbox"!==f.type&&"radio"!==f.type||f.checked||(d=void 0),r.empty){if("checkbox"!==f.type||f.checked||(d=""),"radio"===f.type&&(l[f.name]||f.checked?f.checked&&(l[f.name]=!0):l[f.name]=!1),null==d&&"radio"==f.type)continue}else if(!d)continue;if("select-multiple"!==f.type)i=a(i,p,d);else{d=[];for(var h=f.options,m=!1,g=0;g<h.length;++g){var b=h[g],v=r.empty&&!b.value,y=b.value||v;b.selected&&y&&(m=!0,i=r.hash&&"[]"!==p.slice(p.length-2)?a(i,p+"[]",b.value):a(i,p,b.value))}!m&&r.empty&&(i=a(i,p,""))}}}if(r.empty)for(var p in l)l[p]||(i=a(i,p,""));return i}},765:function(e,t,n){e=n.nmd(e),
/*!
* validate.js 0.13.1
*
* (c) 2013-2019 Nicklas Ansman, 2013 Wrapp
* Validate.js may be freely distributed under the MIT license.
* For all details and documentation:
* http://validatejs.org/
*/
function(e,t,r){"use strict";var i=function(e,t,n){n=o.extend({},o.options,n);var r=o.runValidations(e,t,n);if(r.some((function(e){return o.isPromise(e.error)})))throw new Error("Use validate.async if you want support for promises");return i.processValidationResults(r,n)},o=i;o.extend=function(e){return[].slice.call(arguments,1).forEach((function(t){for(var n in t)e[n]=t[n]})),e},o.extend(i,{version:{major:0,minor:13,patch:1,metadata:null,toString:function(){var e=o.format("%{major}.%{minor}.%{patch}",o.version);return o.isEmpty(o.version.metadata)||(e+="+"+o.version.metadata),e}},Promise:"undefined"!=typeof Promise?Promise:null,EMPTY_STRING_REGEXP:/^\s*$/,runValidations:function(e,t,n){var r,i,s,a,u,l,c,f=[];for(r in(o.isDomElement(e)||o.isJqueryElement(e))&&(e=o.collectFormValues(e)),t)for(i in s=o.getDeepObjectValue(e,r),a=o.result(t[r],s,e,r,n,t)){if(!(u=o.validators[i]))throw c=o.format("Unknown validator %{name}",{name:i}),new Error(c);l=a[i],(l=o.result(l,s,e,r,n,t))&&f.push({attribute:r,value:s,validator:i,globalOptions:n,attributes:e,options:l,error:u.call(u,s,l,r,e,n)})}return f},processValidationResults:function(e,t){e=o.pruneEmptyErrors(e,t),e=o.expandMultipleErrors(e,t),e=o.convertErrorMessages(e,t);var n=t.format||"grouped";if("function"!=typeof o.formatters[n])throw new Error(o.format("Unknown format %{format}",t));return e=o.formatters[n](e),o.isEmpty(e)?void 0:e},async:function(e,t,n){var r=(n=o.extend({},o.async.options,n)).wrapErrors||function(e){return e};!1!==n.cleanAttributes&&(e=o.cleanAttributes(e,t));var i=o.runValidations(e,t,n);return new o.Promise((function(s,a){o.waitForResults(i).then((function(){var u=o.processValidationResults(i,n);u?a(new r(u,n,e,t)):s(e)}),(function(e){a(e)}))}))},single:function(e,t,n){return n=o.extend({},o.single.options,n,{format:"flat",fullMessages:!1}),o({single:e},{single:t},n)},waitForResults:function(e){return e.reduce((function(e,t){return o.isPromise(t.error)?e.then((function(){return t.error.then((function(e){t.error=e||null}))})):e}),new o.Promise((function(e){e()})))},result:function(e){var t=[].slice.call(arguments,1);return"function"==typeof e&&(e=e.apply(null,t)),e},isNumber:function(e){return"number"==typeof e&&!isNaN(e)},isFunction:function(e){return"function"==typeof e},isInteger:function(e){return o.isNumber(e)&&e%1==0},isBoolean:function(e){return"boolean"==typeof e},isObject:function(e){return e===Object(e)},isDate:function(e){return e instanceof Date},isDefined:function(e){return null!=e},isPromise:function(e){return!!e&&o.isFunction(e.then)},isJqueryElement:function(e){return e&&o.isString(e.jquery)},isDomElement:function(e){return!!e&&(!(!e.querySelectorAll||!e.querySelector)&&(!(!o.isObject(document)||e!==document)||("object"==typeof HTMLElement?e instanceof HTMLElement:e&&"object"==typeof e&&null!==e&&1===e.nodeType&&"string"==typeof e.nodeName)))},isEmpty:function(e){var t;if(!o.isDefined(e))return!0;if(o.isFunction(e))return!1;if(o.isString(e))return o.EMPTY_STRING_REGEXP.test(e);if(o.isArray(e))return 0===e.length;if(o.isDate(e))return!1;if(o.isObject(e)){for(t in e)return!1;return!0}return!1},format:o.extend((function(e,t){return o.isString(e)?e.replace(o.format.FORMAT_REGEXP,(function(e,n,r){return"%"===n?"%{"+r+"}":String(t[r])})):e}),{FORMAT_REGEXP:/(%?)%\{([^\}]+)\}/g}),prettify:function(e){return o.isNumber(e)?100*e%1==0?""+e:parseFloat(Math.round(100*e)/100).toFixed(2):o.isArray(e)?e.map((function(e){return o.prettify(e)})).join(", "):o.isObject(e)?o.isDefined(e.toString)?e.toString():JSON.stringify(e):(e=""+e).replace(/([^\s])\.([^\s])/g,"$1 $2").replace(/\\+/g,"").replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,(function(e,t,n){return t+" "+n.toLowerCase()})).toLowerCase()},stringifyValue:function(e,t){return(t&&t.prettify||o.prettify)(e)},isString:function(e){return"string"==typeof e},isArray:function(e){return"[object Array]"==={}.toString.call(e)},isHash:function(e){return o.isObject(e)&&!o.isArray(e)&&!o.isFunction(e)},contains:function(e,t){return!!o.isDefined(e)&&(o.isArray(e)?-1!==e.indexOf(t):t in e)},unique:function(e){ret
/* Riot v5.1.2, @license MIT */
var i;return e[(i=n,i.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase())]=ke(r),e}),{})}(r.components):{}):Ie;return e=>{let{slots:s,attributes:a,props:u}=e;if(r&&r[T])return function(e,t){let{slots:n,attributes:r,props:i,css:o,template:s}=t;s&&V("Pure components can not have html"),o&&V("Pure components do not have css");const a=ve(e({slots:n,attributes:r,props:i}),De);return Ce((e=>function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];if(e===c){const[e]=n;e[T]=!0,Re(e,a)}return a[e](...n),a}))}(r,{slots:s,attributes:a,props:u,css:t,template:n});const l=me(r)||{},f=Le({css:t,template:o,componentAPI:l,name:i})({slots:s,attributes:a,props:u});return{mount:(e,t,n)=>f.mount(e,n,t),update:(e,t)=>f.update(t,e),unmount:e=>f.unmount(e)}}}function Le(e){let{css:t,template:n,componentAPI:r,name:i}=e;return t&&i&&je.add(i,t),_e(Ve)(be(ve(r,Object.assign({},Pe,{[x]:{}})),Object.assign({[O]:null,[N]:null},Me,{name:i,css:t,template:n})))}function ze(e,t){return Object.assign({},e,me(t))}function Ve(e,t){let{slots:n,attributes:r,props:i}=t;return o=function(e){return[...u].reduce(((e,t)=>t(e)||e),e)}(be(Object.create(e),{mount(t,o,s){return void 0===o&&(o={}),this[A]=function(e,t){void 0===t&&(t=[]);const n=t.map((t=>te(e,t))),r={};return Object.assign(r,Object.assign({expressions:n},Ce((e=>t=>(n.forEach((n=>n[e](t))),r)))))}(t,r).mount(s),ge(this,E,Object.freeze(Object.assign({},Ue(t,i),B(this[A].expressions)))),this.state=ze(this.state,o),this[j]=this.template.createDOM(t).clone(),Re(t,this),e.name&&function(e,t){Se(e)!==t&&Oe(e,l,t)}(t,e.name),ge(this,N,t),ge(this,O,n),this.onBeforeMount(this.props,this.state),this[w]=s,this[j].mount(t,this,s),this.onMounted(this.props,this.state),this},update(e,t){void 0===e&&(e={}),t&&(this[w]=t,this[A].update(t));const n=B(this[A].expressions);if(!1!==this.shouldUpdate(n,this.props))return ge(this,E,Object.freeze(Object.assign({},this.props,n))),this.state=ze(this.state,e),this.onBeforeUpdate(this.props,this.state),this[j].update(this,this[w]),this.onUpdated(this.props,this.state),this},unmount(e){return this.onBeforeUnmount(this.props,this.state),this[A].unmount(),this[j].unmount(this,this[w],null===e?null:!e),this.onUnmounted(this.props,this.state),this}})),Object.keys(e).filter((t=>U(e[t]))).forEach((e=>{o[e]=o[e].bind(o)})),o;var o}const{DOM_COMPONENT_INSTANCE_PROPERTY:Be,COMPONENTS_IMPLEMENTATION_MAP:Fe,PLUGINS_SET:Ke}=_;function Ye(e,t){let{css:n,template:r,exports:i}=t;return Fe.has(e)&&V(`The component "${e}" was already registered`),Fe.set(e,ke({name:e,css:n,template:r,exports:i})),Fe}function $e(e,t,n){return Ee(e).map((e=>function(e,t,n){const r=n||Se(e);return s.has(r)||V(`The component named "${r}" was never registered`),s.get(r)({props:t}).mount(e)}(e,t,n)))}var qe=n(765),Ge=n.n(qe),He=n(422),Xe=n.n(He);function Je(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}const Ze=function(){function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._rules=t,this._component=n,this._errors={}}var t,n,r;return t=e,(n=[{key:"handle",value:function(e,t){e.preventDefault();var n,r,i=null;t?e.target.value&&(i=e.target.value):i=Xe()(e.target,{hash:!0}),t?(n=this._rules[t],(r=Ge().single(i,n,{flat:!0}))?this._errors[t]=r:delete this._errors[t]):this._errors=Ge()(i,this._rules),this._component.update()}},{key:"errors",value:function(e){return e?this._errors[e]:this._errors}}])&&Je(t.prototype,n),r&&Je(t,r),e}(),We={css:null,exports:{onBeforeMount(){this.state.validator=new Ze({name:{presence:!0,email:!0},password:{presence:!0}},this)}},template:function(e,t,n,r){return e('<form expr0="expr0" novalidate><div class="field"><label>\n email\n <input expr1="expr1" type="email" name="email"/></label><field-error expr2="expr2"></field-error></div><div class="field"><label>\n password\n <input expr3="expr3" type="password" name="email"/></label><field-e