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

(()=>{var t={2:(t,e,n)=>{"use strict";function r(t){return t.replace(/-(\w)/g,((t,e)=>e.toUpperCase()))}function i(t,e){t.firstChild&&(e.appendChild(t.firstChild),i(t,e))}function s(t){Array.from(t).forEach(o)}const o=t=>t&&t.parentNode&&t.parentNode.removeChild(t),a=(t,e)=>e&&e.parentNode&&e.parentNode.insertBefore(t,e),u=new Map,l=Symbol("riot-component"),c=new Set,f="is",d="mount",h="update",p="unmount",m="shouldUpdate",g="onBeforeMount",v="onMounted",b="onBeforeUpdate",y="onUpdated",E="onBeforeUnmount",x="onUnmounted",O="props",N="state",w="slots",T="root",j=Symbol.for("pure"),A=Symbol("parent"),S=Symbol("attributes"),M=Symbol("template");var _=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:d,UPDATE_METHOD_KEY:h,UNMOUNT_METHOD_KEY:p,SHOULD_UPDATE_KEY:m,ON_BEFORE_MOUNT_KEY:g,ON_MOUNTED_KEY:v,ON_BEFORE_UPDATE_KEY:b,ON_UPDATED_KEY:y,ON_BEFORE_UNMOUNT_KEY:E,ON_UNMOUNTED_KEY:x,PROPS_KEY:O,STATE_KEY:N,SLOTS_KEY:w,ROOT_KEY:T,IS_PURE_SYMBOL:j,PARENT_KEY_SYMBOL:A,ATTRIBUTES_KEY_SYMBOL:S,TEMPLATE_KEY_SYMBOL:M});var D={EACH:0,IF:1,SIMPLE:2,TAG:3,SLOT:4};var P={ATTRIBUTE:0,EVENT:1,TEXT:2,VALUE:3};function C(t,e){return typeof t===e}function L(t){const e=t.ownerSVGElement;return!!e||null===e}function U(t){return!R(t.content)}function k(t){return C(t,"function")}function I(t){return!R(t)&&C(t,"object")}function R(t){return null==t}const z=Symbol("unmount"),V={nodes:[],mount(t,e){return this.update(t,e)},update(t,e){const{placeholder:n,nodes:r,childrenMap:i}=this,s=t===z?null:this.evaluate(t),u=s?Array.from(s):[],{newChildrenMap:l,batches:c,futureNodes:f}=(n.parentNode,function(t,e,n,r){const{condition:i,template:s,childrenMap:o,itemName:a,getKey:u,indexName:l,root:c,isTemplateTag:f}=r,d=new Map,h=[],p=[];return t.forEach(((t,r)=>{const m=function(t,e){let{itemName:n,indexName:r,index:i,item:s}=e;t[n]=s,r&&(t[r]=i);return t}(Object.create(e),{itemName:a,indexName:l,index:r,item:t}),g=u?u(m):r,v=o.get(g);if(function(t,e){return!!t&&!1===Boolean(t(e))}(i,m))return;const b=v?v.template:s.clone(),y=v?b.el:c.cloneNode(),E=!v,x=f&&E?function(t){const e=t.dom.cloneNode(!0);return{avoidDOMInjection:!0,fragment:e,children:Array.from(e.childNodes)}}(b):{};if(E?h.push((()=>b.mount(y,m,n,x))):h.push((()=>b.update(m,n))),f){const t=x.children||b.children;p.push(...t)}else p.push(y);o.delete(g),d.set(g,{template:b,context:m,index:r})})),{newChildrenMap:d,batches:h,futureNodes:p}}(u,t,e,this));return((t,e,n,r,i)=>{const s=n.length;let u=e.length,l=s,c=0,f=0,d=null;for(;c<u||f<l;)if(u===c){const t=l<s?f?r(n[f-1],-0).nextSibling:r(n[l-f],0):i;for(;f<l;)a(r(n[f++],1),t)}else if(l===f)for(;c<u;)d&&d.has(e[c])||o(r(e[c],-1)),c++;else if(e[c]===n[f])c++,f++;else if(e[u-1]===n[l-1])u--,l--;else if(e[c]===n[l-1]&&n[f]===e[u-1]){const t=r(e[--u],-1).nextSibling;a(r(n[f++],1),r(e[c++],-1).nextSibling),a(r(n[--l],1),t),e[u]=n[l]}else{if(!d){d=new Map;let t=f;for(;t<l;)d.set(n[t],t++)}if(d.has(e[c])){const t=d.get(e[c]);if(f<t&&t<l){let i=c,s=1;for(;++i<u&&i<l&&d.get(e[i])===t+s;)s++;if(s>t-f){const i=r(e[c],0);for(;f<t;)a(r(n[f++],1),i)}else h=r(n[f++],1),(p=r(e[c++],-1))&&p.parentNode&&p.parentNode.replaceChild(h,p)}else c++}else o(r(e[c++],-1))}var h,p})(0,r,f,function(t,e){return(n,r)=>{if(r<0){const n=t.pop();if(n){const{template:t,context:r}=n;t.unmount(r,e,null)}}return n}}(Array.from(i.values()),e),n),c.forEach((t=>t())),this.childrenMap=l,this.nodes=f,this},unmount(t,e){return this.update(z,e),this}};const F={mount(t,e){return this.update(t,e)},update(t,e){const n=!!this.evaluate(t),r=!this.value&&n,i=this.value&&!n,s=()=>{const n=this.node.cloneNode();a(n,this.placeholder),this.template=this.template.clone(),this.template.mount(n,t,e)};switch(!0){case r:s();break;case i:this.unmount(t);break;default:n&&this.template.update(t,e)}return this.value=n,this},unmount(t,e){return this.template.unmount(t,e,!0),this}};function K(t){throw new Error(t)}function B(t){return t.reduce(((t,e)=>{const{value:n,type:i}=e;switch(!0){case!e.name&&0==
4 years ago
/* Riot v5.1.2, @license MIT */
var i;return t[(i=n,i.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase())]=zt(r),t}),{})}(r.components):{}):Ut;return t=>{let{slots:o,attributes:a,props:u}=t;if(r&&r[j])return function(t,e){let{slots:n,attributes:r,props:i,css:s,template:o}=e;o&&K("Pure components can not have html"),s&&K("Pure components do not have css");const a=Et(t({slots:n,attributes:r,props:i}),Ct);return Rt((t=>function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];if(t===d){const[t]=n;t[j]=!0,It(t,a)}return a[t](...n),a}))}(r,{slots:o,attributes:a,props:u,css:e,template:n});const l=vt(r)||{},c=Vt({css:e,template:s,componentAPI:l,name:i})({slots:o,attributes:a,props:u});return{mount:(t,e,n)=>c.mount(t,n,e),update:(t,e)=>c.update(e,t),unmount:t=>c.unmount(t)}}}function Vt(t){let{css:e,template:n,componentAPI:r,name:i}=t;return e&&i&&Mt.add(i,e),_t(Kt)(yt(Et(r,Object.assign({},Lt,{[N]:{}})),Object.assign({[w]:null,[T]:null},Pt,{name:i,css:e,template:n})))}function Ft(t,e){return Object.assign({},t,vt(e))}function Kt(t,e){let{slots:n,attributes:r,props:i}=e;return s=function(t){return[...c].reduce(((t,e)=>e(t)||t),t)}(yt(Object.create(t),{mount(e,s,o){return void 0===s&&(s={}),this[S]=function(t,e){void 0===e&&(e=[]);const n=e.map((e=>rt(t,e))),r={};return Object.assign(r,Object.assign({expressions:n},Rt((t=>e=>(n.forEach((n=>n[t](e))),r)))))}(e,r).mount(o),bt(this,O,Object.freeze(Object.assign({},kt(e,i),B(this[S].expressions)))),this.state=Ft(this.state,s),this[M]=this.template.createDOM(e).clone(),It(e,this),t.name&&function(t,e){Dt(t)!==e&&wt(t,f,e)}(e,t.name),bt(this,T,e),bt(this,w,n),this.onBeforeMount(this.props,this.state),this[A]=o,this[M].mount(e,this,o),this.onMounted(this.props,this.state),this},update(t,e){void 0===t&&(t={}),e&&(this[A]=e,this[S].update(e));const n=B(this[S].expressions);if(!1!==this.shouldUpdate(n,this.props))return bt(this,O,Object.freeze(Object.assign({},this.props,n))),this.state=Ft(this.state,t),this.onBeforeUpdate(this.props,this.state),this[M].update(this,this[A]),this.onUpdated(this.props,this.state),this},unmount(t){return this.onBeforeUnmount(this.props,this.state),this[S].unmount(),this[M].unmount(this,this[A],null===t?null:!t),this.onUnmounted(this.props,this.state),this}})),Object.keys(t).filter((e=>k(t[e]))).forEach((t=>{s[t]=s[t].bind(s)})),s;var s}const{DOM_COMPONENT_INSTANCE_PROPERTY:Bt,COMPONENTS_IMPLEMENTATION_MAP:Yt,PLUGINS_SET:$t}=_;var qt=n(765),Ht=n.n(qt),Gt=n(422),Xt=n.n(Gt);function Jt(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}const Zt=function(){function t(e,n){var r=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.formSelector=e,this.constraits=n,this.form=document.querySelector(this.formSelector),this.elements=this.form.querySelectorAll("field-error"),this.form.addEventListener("submit",(function(t){r.onSubmit(t)})),this.form.addEventListener("field-update",(function(t){r.onFieldUpdate(t)}))}var e,n,r;return e=t,(n=[{key:"onSubmit",value:function(t){var e=this,n=Ht()(Xt()(t.target,{hash:!0}),this.constraits,{fullMessages:!1});n&&(t.preventDefault(),this.elements.forEach((function(t){var r=!1;n[t.attributes.name.nodeValue]&&(r=n[t.attributes.name.nodeValue]),e.dispatchCustomEvent(r,t)})))}},{key:"onFieldUpdate",value:function(t){var e=this;""==t.detail.value&&(t.detail.value=void 0);var n=Ht().single(t.detail.value,this.constraits[t.detail.name]);this.elements.forEach((function(r){r.attributes.name.nodeValue==t.detail.name&&e.dispatchCustomEvent(n,r)}))}},{key:"dispatchCustomEvent",value:function(t,e){var n=!1;t&&(n=t);var r=new CustomEvent("form-validation",{detail:n});e.dispatchEvent(r)}}])&&Jt(e.prototype,n),r&&Jt(e,r),t}();var Wt,Qt;!function(t,e){let{css:n,template:r,exports:i}=e;Yt.has(t)&&K(`The component "${t}" was already registered`),Yt.set(t,zt({name:t,css:n,template:r,exports:i}))}("field-error",{css:null,exports:{state:{errors:[]},onMounted(t,e){const n=this.root.closest(".field"),r
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/
*/
function(t,e,r){"use strict";var i=function(t,e,n){n=s.extend({},s.options,n);var r=s.runValidations(t,e,n);if(r.some((function(t){return s.isPromise(t.error)})))throw new Error("Use validate.async if you want support for promises");return i.processValidationResults(r,n)},s=i;s.extend=function(t){return[].slice.call(arguments,1).forEach((function(e){for(var n in e)t[n]=e[n]})),t},s.extend(i,{version:{major:0,minor:13,patch:1,metadata:null,toString:function(){var t=s.format("%{major}.%{minor}.%{patch}",s.version);return s.isEmpty(s.version.metadata)||(t+="+"+s.version.metadata),t}},Promise:"undefined"!=typeof Promise?Promise:null,EMPTY_STRING_REGEXP:/^\s*$/,runValidations:function(t,e,n){var r,i,o,a,u,l,c,f=[];for(r in(s.isDomElement(t)||s.isJqueryElement(t))&&(t=s.collectFormValues(t)),e)for(i in o=s.getDeepObjectValue(t,r),a=s.result(e[r],o,t,r,n,e)){if(!(u=s.validators[i]))throw c=s.format("Unknown validator %{name}",{name:i}),new Error(c);l=a[i],(l=s.result(l,o,t,r,n,e))&&f.push({attribute:r,value:o,validator:i,globalOptions:n,attributes:t,options:l,error:u.call(u,o,l,r,t,n)})}return f},processValidationResults:function(t,e){t=s.pruneEmptyErrors(t,e),t=s.expandMultipleErrors(t,e),t=s.convertErrorMessages(t,e);var n=e.format||"grouped";if("function"!=typeof s.formatters[n])throw new Error(s.format("Unknown format %{format}",e));return t=s.formatters[n](t),s.isEmpty(t)?void 0:t},async:function(t,e,n){var r=(n=s.extend({},s.async.options,n)).wrapErrors||function(t){return t};!1!==n.cleanAttributes&&(t=s.cleanAttributes(t,e));var i=s.runValidations(t,e,n);return new s.Promise((function(o,a){s.waitForResults(i).then((function(){var u=s.processValidationResults(i,n);u?a(new r(u,n,t,e)):o(t)}),(function(t){a(t)}))}))},single:function(t,e,n){return n=s.extend({},s.single.options,n,{format:"flat",fullMessages:!1}),s({single:t},{single:e},n)},waitForResults:function(t){return t.reduce((function(t,e){return s.isPromise(e.error)?t.then((function(){return e.error.then((function(t){e.error=t||null}))})):t}),new s.Promise((function(t){t()})))},result:function(t){var e=[].slice.call(arguments,1);return"function"==typeof t&&(t=t.apply(null,e)),t},isNumber:function(t){return"number"==typeof t&&!isNaN(t)},isFunction:function(t){return"function"==typeof t},isInteger:function(t){return s.isNumber(t)&&t%1==0},isBoolean:function(t){return"boolean"==typeof t},isObject:function(t){return t===Object(t)},isDate:function(t){return t instanceof Date},isDefined:function(t){return null!=t},isPromise:function(t){return!!t&&s.isFunction(t.then)},isJqueryElement:function(t){return t&&s.isString(t.jquery)},isDomElement:function(t){return!!t&&(!(!t.querySelectorAll||!t.querySelector)&&(!(!s.isObject(document)||t!==document)||("object"==typeof HTMLElement?t instanceof HTMLElement:t&&"object"==typeof t&&null!==t&&1===t.nodeType&&"string"==typeof t.nodeName)))},isEmpty:function(t){var e;if(!s.isDefined(t))return!0;if(s.isFunction(t))return!1;if(s.isString(t))return s.EMPTY_STRING_REGEXP.test(t);if(s.isArray(t))return 0===t.length;if(s.isDate(t))return!1;if(s.isObject(t)){for(e in t)return!1;return!0}return!1},format:s.extend((function(t,e){return s.isString(t)?t.replace(s.format.FORMAT_REGEXP,(function(t,n,r){return"%"===n?"%{"+r+"}":String(e[r])})):t}),{FORMAT_REGEXP:/(%?)%\{([^\}]+)\}/g}),prettify:function(t){return s.isNumber(t)?100*t%1==0?""+t:parseFloat(Math.round(100*t)/100).toFixed(2):s.isArray(t)?t.map((function(t){return s.prettify(t)})).join(", "):s.isObject(t)?s.isDefined(t.toString)?t.toString():JSON.stringify(t):(t=""+t).replace(/([^\s])\.([^\s])/g,"$1 $2").replace(/\\+/g,"").replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,(function(t,e,n){return e+" "+n.toLowerCase()})).toLowerCase()},stringifyValue:function(t,e){return(e&&e.prettify||s.prettify)(t)},isString:function(t){return"string"==typeof t},isArray:function(t){return"[object Array]"==={}.toString.call(t)},isHash:function(t){return s.isObject(t)&&!s.isArray(t)&&!s.isFunction(t)},contains:function(t,e){return!!s.isDefined(t)&&(s.isArray(t)?-1!==t.indexOf(e):e in t)},unique:function(t){ret