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/demo/demo.js

12 lines
35 KiB

4 years ago
(()=>{var e={619:(e,t,n)=>{"use strict";function r(e){return e.replace(/-(\w)/g,((e,t)=>t.toUpperCase()))}function i(e,t){e.firstChild&&(t.appendChild(e.firstChild),i(e,t))}function o(e){Array.from(e).forEach(s)}const s=e=>e&&e.parentNode&&e.parentNode.removeChild(e),a=(e,t)=>t&&t.parentNode&&t.parentNode.insertBefore(e,t),u=new Map,l=Symbol("riot-component"),c=new Set,f="is",p="mount",d="update",h="unmount",m="shouldUpdate",g="onBeforeMount",b="onMounted",v="onBeforeUpdate",y="onUpdated",E="onBeforeUnmount",x="onUnmounted",O="props",N="state",T="slots",w="root",A=Symbol.for("pure"),j=Symbol("parent"),_=Symbol("attributes"),S=Symbol("template");var M=Object.freeze({__proto__:null,COMPONENTS_IMPLEMENTATION_MAP:u,DOM_COMPONENT_INSTANCE_PROPERTY:l,PLUGINS_SET:c,IS_DIRECTIVE:f,VALUE_ATTRIBUTE:"value",MOUNT_METHOD_KEY:p,UPDATE_METHOD_KEY:d,UNMOUNT_METHOD_KEY:h,SHOULD_UPDATE_KEY:m,ON_BEFORE_MOUNT_KEY:g,ON_MOUNTED_KEY:b,ON_BEFORE_UPDATE_KEY:v,ON_UPDATED_KEY:y,ON_BEFORE_UNMOUNT_KEY:E,ON_UNMOUNTED_KEY:x,PROPS_KEY:O,STATE_KEY:N,SLOTS_KEY:T,ROOT_KEY:w,IS_PURE_SYMBOL:A,PARENT_KEY_SYMBOL:j,ATTRIBUTES_KEY_SYMBOL:_,TEMPLATE_KEY_SYMBOL:S});var D={EACH:0,IF:1,SIMPLE:2,TAG:3,SLOT:4};var P={ATTRIBUTE:0,EVENT:1,TEXT:2,VALUE:3};function I(e,t){return typeof e===t}function U(e){const t=e.ownerSVGElement;return!!t||null===t}function C(e){return!L(e.content)}function k(e){return I(e,"function")}function R(e){return!L(e)&&I(e,"object")}function L(e){return null==e}const z=Symbol("unmount"),V={nodes:[],mount(e,t){return this.update(e,t)},update(e,t){const{placeholder:n,nodes:r,childrenMap:i}=this,o=e===z?null:this.evaluate(e),u=o?Array.from(o):[],{newChildrenMap:l,batches:c,futureNodes:f}=(n.parentNode,function(e,t,n,r){const{condition:i,template:o,childrenMap:s,itemName:a,getKey:u,indexName:l,root:c,isTemplateTag:f}=r,p=new Map,d=[],h=[];return e.forEach(((e,r)=>{const m=function(e,t){let{itemName:n,indexName:r,index:i,item:o}=t;e[n]=o,r&&(e[r]=i);return e}(Object.create(t),{itemName:a,indexName:l,index:r,item:e}),g=u?u(m):r,b=s.get(g);if(function(e,t){return!!e&&!1===Boolean(e(t))}(i,m))return;const v=b?b.template:o.clone(),y=b?v.el:c.cloneNode(),E=!b,x=f&&E?function(e){const t=e.dom.cloneNode(!0);return{avoidDOMInjection:!0,fragment:t,children:Array.from(t.childNodes)}}(v):{};if(E?d.push((()=>v.mount(y,m,n,x))):d.push((()=>v.update(m,n))),f){const e=x.children||v.children;h.push(...e)}else h.push(y);s.delete(g),p.set(g,{template:v,context:m,index:r})})),{newChildrenMap:p,batches:d,futureNodes:h}}(u,e,t,this));return((e,t,n,r,i)=>{const o=n.length;let u=t.length,l=o,c=0,f=0,p=null;for(;c<u||f<l;)if(u===c){const e=l<o?f?r(n[f-1],-0).nextSibling:r(n[l-f],0):i;for(;f<l;)a(r(n[f++],1),e)}else if(l===f)for(;c<u;)p&&p.has(t[c])||s(r(t[c],-1)),c++;else if(t[c]===n[f])c++,f++;else if(t[u-1]===n[l-1])u--,l--;else if(t[c]===n[l-1]&&n[f]===t[u-1]){const e=r(t[--u],-1).nextSibling;a(r(n[f++],1),r(t[c++],-1).nextSibling),a(r(n[--l],1),e),t[u]=n[l]}else{if(!p){p=new Map;let e=f;for(;e<l;)p.set(n[e],e++)}if(p.has(t[c])){const e=p.get(t[c]);if(f<e&&e<l){let i=c,o=1;for(;++i<u&&i<l&&p.get(t[i])===e+o;)o++;if(o>e-f){const i=r(t[c],0);for(;f<e;)a(r(n[f++],1),i)}else d=r(n[f++],1),(h=r(t[c++],-1))&&h.parentNode&&h.parentNode.replaceChild(d,h)}else c++}else s(r(t[c++],-1))}var d,h})(0,r,f,function(e,t){return(n,r)=>{if(r<0){const n=e.pop();if(n){const{template:e,context:r}=n;e.unmount(r,t,null)}}return n}}(Array.from(i.values()),t),n),c.forEach((e=>e())),this.childrenMap=l,this.nodes=f,this},unmount(e,t){return this.update(z,t),this}};const B={mount(e,t){return this.update(e,t)},update(e,t){const n=!!this.evaluate(e),r=!this.value&&n,i=this.value&&!n,o=()=>{const n=this.node.cloneNode();a(n,this.placeholder),this.template=this.template.clone(),this.template.mount(n,e,t)};switch(!0){case r:o();break;case i:this.unmount(e);break;default:n&&this.template.update(e,t)}return this.value=n,this},unmount(e,t){return this.template.unmount(e,t,!0),this}};function F(e){throw new Error(e)}function K(e){return e.reduce(((e,t)=>{const{value:n,type:i}=t;switch(!0){case!t.name&&0
/* Riot v5.1.2, @license MIT */
var i;return e[(i=n,i.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase())]=ze(r),e}),{})}(r.components):{}):Ce;return e=>{let{slots:s,attributes:a,props:u}=e;if(r&&r[A])return function(e,t){let{slots:n,attributes:r,props:i,css:o,template:s}=t;s&&F("Pure components can not have html"),o&&F("Pure components do not have css");const a=Ee(e({slots:n,attributes:r,props:i}),Ie);return Le((e=>function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];if(e===p){const[e]=n;e[A]=!0,Re(e,a)}return a[e](...n),a}))}(r,{slots:s,attributes:a,props:u,css:t,template:n});const l=be(r)||{},c=Ve({css:t,template:o,componentAPI:l,name:i})({slots:s,attributes:a,props:u});return{mount:(e,t,n)=>c.mount(e,n,t),update:(e,t)=>c.update(t,e),unmount:e=>c.unmount(e)}}}function Ve(e){let{css:t,template:n,componentAPI:r,name:i}=e;return t&&i&&Se.add(i,t),Me(Fe)(ye(Ee(r,Object.assign({},Ue,{[N]:{}})),Object.assign({[T]:null,[w]:null},Pe,{name:i,css:t,template:n})))}function Be(e,t){return Object.assign({},e,be(t))}function Fe(e,t){let{slots:n,attributes:r,props:i}=t;return o=function(e){return[...c].reduce(((e,t)=>t(e)||e),e)}(ye(Object.create(e),{mount(t,o,s){return void 0===o&&(o={}),this[_]=function(e,t){void 0===t&&(t=[]);const n=t.map((t=>re(e,t))),r={};return Object.assign(r,Object.assign({expressions:n},Le((e=>t=>(n.forEach((n=>n[e](t))),r)))))}(t,r).mount(s),ve(this,O,Object.freeze(Object.assign({},ke(t,i),K(this[_].expressions)))),this.state=Be(this.state,o),this[S]=this.template.createDOM(t).clone(),Re(t,this),e.name&&function(e,t){De(e)!==t&&Te(e,f,t)}(t,e.name),ve(this,w,t),ve(this,T,n),this.onBeforeMount(this.props,this.state),this[j]=s,this[S].mount(t,this,s),this.onMounted(this.props,this.state),this},update(e,t){void 0===e&&(e={}),t&&(this[j]=t,this[_].update(t));const n=K(this[_].expressions);if(!1!==this.shouldUpdate(n,this.props))return ve(this,O,Object.freeze(Object.assign({},this.props,n))),this.state=Be(this.state,e),this.onBeforeUpdate(this.props,this.state),this[S].update(this,this[j]),this.onUpdated(this.props,this.state),this},unmount(e){return this.onBeforeUnmount(this.props,this.state),this[_].unmount(),this[S].unmount(this,this[j],null===e?null:!e),this.onUnmounted(this.props,this.state),this}})),Object.keys(e).filter((t=>k(e[t]))).forEach((e=>{o[e]=o[e].bind(o)})),o;var o}const{DOM_COMPONENT_INSTANCE_PROPERTY:Ke,COMPONENTS_IMPLEMENTATION_MAP:Ye,PLUGINS_SET:$e}=M;function qe(e,t){let{css:n,template:r,exports:i}=t;return Ye.has(e)&&F(`The component "${e}" was already registered`),Ye.set(e,ze({name:e,css:n,template:r,exports:i})),Ye}function Ge(e,t,n){return Oe(e).map((e=>function(e,t,n){const r=n||De(e);return u.has(r)||F(`The component named "${r}" was never registered`),u.get(r)({props:t}).mount(e)}(e,t,n)))}var He=n(765),Xe=n.n(He),Je=n(422),Ze=n.n(Je);function We(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 Qe=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=Ze()(e.target,{hash:!0}),t?(n=this._rules[t],(r=Xe().single(i,n,{flat:!0}))?this._errors[t]=r:delete this._errors[t]):this._errors=Xe()(i,this._rules),this._component.update()}},{key:"errors",value:function(e){return e?this._errors[e]:this._errors}}])&&We(t.prototype,n),r&&We(t,r),e}(),et={css:null,exports:{onBeforeMount(){this.state.validator=new Qe({email:{presence:!0,email:!0},password:{presence:!0}},this)}},template:function(e,t,n,r){return e('<form expr2="expr2" novalidate><div class="field"><label>\n email\n <input expr3="expr3" type="email" name="email"/></label><field-error expr4="expr4"></field-error></div><div class="field"><label>\n password\n <input expr5="expr5" type="password" name="email"/></label><field-
4 years ago
/*!
* 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/
*/
4 years ago
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