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

3 years ago
(()=>{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 o(t){Array.from(t).forEach(s)}const s=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,o=t===z?null:this.evaluate(t),u=o?Array.from(o):[],{newChildrenMap:l,batches:c,futureNodes:f}=(n.parentNode,function(t,e,n,r){const{condition:i,template:o,childrenMap:s,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:o}=e;t[n]=o,r&&(t[r]=i);return t}(Object.create(e),{itemName:a,indexName:l,index:r,item:t}),g=u?u(m):r,v=s.get(g);if(function(t,e){return!!t&&!1===Boolean(t(e))}(i,m))return;const b=v?v.template:o.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);s.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 o=n.length;let u=e.length,l=o,c=0,f=0,d=null;for(;c<u||f<l;)if(u===c){const t=l<o?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])||s(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,o=1;for(;++i<u&&i<l&&d.get(e[i])===t+o;)o++;if(o>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 s(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,o=()=>{const n=this.node.cloneNode();a(n,this.placeholder),this.template=this.template.clone(),this.template.mount(n,t,e)};switch(!0){case r:o();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 */
3 years ago
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:s,attributes:a,props:u}=t;if(r&&r[j])return function(t,e){let{slots:n,attributes:r,props:i,css:o,template:s}=e;s&&K("Pure components can not have html"),o&&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:s,attributes:a,props:u,css:e,template:n});const l=vt(r)||{},c=Vt({css:e,template:o,componentAPI:l,name:i})({slots:s,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 o=function(t){return[...c].reduce(((t,e)=>e(t)||t),t)}(yt(Object.create(t),{mount(e,o,s){return void 0===o&&(o={}),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(s),bt(this,O,Object.freeze(Object.assign({},kt(e,i),B(this[S].expressions)))),this.state=Ft(this.state,o),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]=s,this[M].mount(e,this,s),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=>{o[t]=o[t].bind(o)})),o;var o}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);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]);Array.from(this.elements).every((function(r){if(r.attributes.name.nodeValue==t.detail.name)return e.dispatchCustomEvent(n,r),!1}))}},{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
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/
*/
3 years ago
function(t,e,r){"use strict";var i=function(t,e,n){n=o.extend({},o.options,n);var r=o.runValidations(t,e,n);if(r.some((function(t){return o.isPromise(t.error)})))throw new Error("Use validate.async if you want support for promises");return i.processValidationResults(r,n)},o=i;o.extend=function(t){return[].slice.call(arguments,1).forEach((function(e){for(var n in e)t[n]=e[n]})),t},o.extend(i,{version:{major:0,minor:13,patch:1,metadata:null,toString:function(){var t=o.format("%{major}.%{minor}.%{patch}",o.version);return o.isEmpty(o.version.metadata)||(t+="+"+o.version.metadata),t}},Promise:"undefined"!=typeof Promise?Promise:null,EMPTY_STRING_REGEXP:/^\s*$/,runValidations:function(t,e,n){var r,i,s,a,u,l,c,f=[];for(r in(o.isDomElement(t)||o.isJqueryElement(t))&&(t=o.collectFormValues(t)),e)for(i in s=o.getDeepObjectValue(t,r),a=o.result(e[r],s,t,r,n,e)){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,t,r,n,e))&&f.push({attribute:r,value:s,validator:i,globalOptions:n,attributes:t,options:l,error:u.call(u,s,l,r,t,n)})}return f},processValidationResults:function(t,e){t=o.pruneEmptyErrors(t,e),t=o.expandMultipleErrors(t,e),t=o.convertErrorMessages(t,e);var n=e.format||"grouped";if("function"!=typeof o.formatters[n])throw new Error(o.format("Unknown format %{format}",e));return t=o.formatters[n](t),o.isEmpty(t)?void 0:t},async:function(t,e,n){var r=(n=o.extend({},o.async.options,n)).wrapErrors||function(t){return t};!1!==n.cleanAttributes&&(t=o.cleanAttributes(t,e));var i=o.runValidations(t,e,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,t,e)):s(t)}),(function(t){a(t)}))}))},single:function(t,e,n){return n=o.extend({},o.single.options,n,{format:"flat",fullMessages:!1}),o({single:t},{single:e},n)},waitForResults:function(t){return t.reduce((function(t,e){return o.isPromise(e.error)?t.then((function(){return e.error.then((function(t){e.error=t||null}))})):t}),new o.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 o.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&&o.isFunction(t.then)},isJqueryElement:function(t){return t&&o.isString(t.jquery)},isDomElement:function(t){return!!t&&(!(!t.querySelectorAll||!t.querySelector)&&(!(!o.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(!o.isDefined(t))return!0;if(o.isFunction(t))return!1;if(o.isString(t))return o.EMPTY_STRING_REGEXP.test(t);if(o.isArray(t))return 0===t.length;if(o.isDate(t))return!1;if(o.isObject(t)){for(e in t)return!1;return!0}return!1},format:o.extend((function(t,e){return o.isString(t)?t.replace(o.format.FORMAT_REGEXP,(function(t,n,r){return"%"===n?"%{"+r+"}":String(e[r])})):t}),{FORMAT_REGEXP:/(%?)%\{([^\}]+)\}/g}),prettify:function(t){return o.isNumber(t)?100*t%1==0?""+t:parseFloat(Math.round(100*t)/100).toFixed(2):o.isArray(t)?t.map((function(t){return o.prettify(t)})).join(", "):o.isObject(t)?o.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||o.prettify)(t)},isString:function(t){return"string"==typeof t},isArray:function(t){return"[object Array]"==={}.toString.call(t)},isHash:function(t){return o.isObject(t)&&!o.isArray(t)&&!o.isFunction(t)},contains:function(t,e){return!!o.isDefined(t)&&(o.isArray(t)?-1!==t.indexOf(e):e in t)},unique:function(t){ret