From 34898a8bd12db22716bc53bd810c28f369686a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Fri, 4 Jun 2021 15:47:52 +0200 Subject: [PATCH] adding --- demo/demo.js | 6 +-- main.js | 4 -- src/FormValidator.js | 58 ++++++++++++-------------- src/field-error.riot | 97 +++++++++++++++++++++++++++++++------------- src/validator.js | 92 ----------------------------------------- 5 files changed, 97 insertions(+), 160 deletions(-) delete mode 100644 main.js delete mode 100644 src/validator.js diff --git a/demo/demo.js b/demo/demo.js index 23b577a..64d5f14 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -1,6 +1,6 @@ -(()=>{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 k(t,e){return typeof t===e}function C(t){const e=t.ownerSVGElement;return!!e||null===e}function L(t){return!R(t.content)}function U(t){return k(t,"function")}function I(t){return!R(t)&&k(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(;ct-f){const i=r(e[c],0);for(;f{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 B(t){throw new Error(t)}function K(t){return t.reduce(((t,e)=>{const{value:n,type:i}=e;switch(!0){case!e.name&&0===i:return Object.assign({},t,n);case 3===i:t.value=e.value;break;default:t[r(e.name)]=e.value}return t}),{})}const Y="removeAttribute",$="setAttribute",q="undefined"==typeof Element?{}:Element.prototype,H=function(t){const e=new Map,n=n=>(e.has(n)||e.set(n,t.call(this,n)))&&e.get(n);return n.cache=e,n}((t=>q.hasOwnProperty(t)));function G(t,e,n,r){let{name:i}=e;if(!i)return r&&function(t,e,n){const r=e?Object.keys(e):[];Object.keys(n).filter((t=>!r.includes(t))).forEach((e=>t.removeAttribute(e)))}(t,n,r),void(n&&function(t,e){Object.entries(e).forEach((e=>{let[n,r]=e;return G(t,{name:n},r)}))}(t,n));!H(i)&&(function(t){return k(t,"boolean")}(n)||I(n)||U(n))&&(t[i]=n),t[function(t){return R(t)||!1===t||""===t||I(t)||U(t)?Y:$}(n)](i,function(t,e){return!0===e?t:e}(i,n))}const X=/^on/,J={handleEvent(t){this[t.type](t)}},Z=new WeakMap;function W(t){return R(t)?"":t}const Q=(t,e)=>{const n=t.childNodes[e];if(n.nodeType===Node.COMMENT_NODE){const e=document.createTextNode("");return t.replaceChild(e,n),e}return n};var tt={0:G,1:function(t,e,n){let{name:r}=e;const i=r.replace(X,""),s=Z.get(t)||(t=>{const e=Object.create(J);return Z.set(t,e),e})(t),[o,a]=(t=>Array.isArray(t)?t:[t,!1])(n),u=s[i],l=o&&!u;u&&!o&&t.removeEventListener(i,s),l&&t.addEventListener(i,s,a),s[i]=o},2:function(t,e,n){t.data=W(n)},3:function(t,e,n){t.value=W(n)}};const et={mount(t){return this.value=this.evaluate(t),nt(this,this.value),this},update(t){const e=this.evaluate(t);return this.value!==e&&(nt(this,e),this.value=e),this},unmount(){return 1===this.type&&nt(this,null),this}};function nt(t,e){return tt[t.type](t.node,t,e,t.value)}function rt(t,e){return Object.assign({},et,e,{node:2===e.type?Q(t,e.childNodeIndex):t})}const it=(t,e)=>t[A]||e,st={attributes:[],getTemplateScope(t,e){return function(t,e,n){if(!t||!t.length)return n;const r=t.map((t=>Object.assign({},t,{value:t.evaluate(e)})));return Object.assign(Object.create(n||null),K(r))}(this.attributes,t,e)},mount(t,e){const n=!!t.slots&&t.slots.find((t=>{let{id:e}=t;return e===this.name})),{parentNode:r}=this.node,i=it(t,e);return this.template=n&&mt(n.html,n.bindings).createDOM(r),this.template&&(this.template.mount(this.node,this.getTemplateScope(t,i),i),this.template.children=Array.from(this.node.childNodes),ot(this.node)),o(this.node),this},update(t,e){if(this.template){const n=it(t,e);this.template.update(this.getTemplateScope(t,n),n)}return this},unmount(t,e,n){return this.template&&this.template.unmount(this.getTemplateScope(t,e),null,n),this}};function ot(t){const e=t&&t.firstChild;e&&(a(e,t),ot(t))}function at(t){return t.reduce(((t,e)=>{let{bindings:n}=e;return t.concat(n)}),[])}const ut={mount(t){return this.update(t)},update(t,e){const n=this.evaluate(t);return n===this.name?this.tag.update(t):(this.unmount(t,e,!0),this.name=n,this.tag=function(t,e,n){return void 0===e&&(e=[]),void 0===n&&(n=[]),t?t({slots:e,attributes:n}):mt(function(t){return t.reduce(((t,e)=>t+e.html),"")}(e),[...at(e),{expressions:n.map((t=>Object.assign({type:0},t)))}])}(this.getComponent(n),this.slots,this.attributes),this.tag.mount(this.node,t)),this},unmount(t,e,n){return this.tag&&this.tag.unmount(n),this}};var lt={1:function(t,e){let{evaluate:n,template:r}=e;const i=document.createTextNode("");return a(i,t),o(t),Object.assign({},F,{node:t,evaluate:n,placeholder:i,template:r.createDOM(t)})},2:function(t,e){let{expressions:n}=e;return Object.assign({},(r=n.map((e=>rt(t,e))),["mount","update","unmount"].reduce(((t,e)=>Object.assign({},t,{[e]:t=>r.map((n=>n[e](t)))&&i})),{})));var r,i},0:function(t,e){let{evaluate:n,condition:r,itemName:i,indexName:s,getKey:u,template:l}=e;const c=document.createTextNode(""),f=t.cloneNode();return a(c,t),o(t),Object.assign({},V,{childrenMap:new Map,node:t,root:f,condition:r,evaluate:n,isTemplateTag:L(f),template:l.createDOM(t),getKey:u,indexName:s,itemName:i,placeholder:c})},3:function(t,e){let{evaluate:n,getComponent:r,slots:i,attributes:s}=e;return Object.assign({},ut,{node:t,evaluate:n,slots:i,attributes:s,getComponent:r})},4:function(t,e){let{name:n,attributes:r}=e;return Object.assign({},st,{attributes:r,node:t,name:n})}};function ct(t,e){return t.map((t=>2===t.type?Object.assign({},t,{childNodeIndex:t.childNodeIndex+e}):t))}function ft(t,e,n){const{selector:r,type:i,redundantAttribute:s,expressions:o}=e,a=r?t.querySelector(r):t;s&&a.removeAttribute(s);const u=o||[];return(lt[i]||lt[2])(a,Object.assign({},e,{expressions:n&&!r?ct(u,n):u}))}function dt(t,e){return C(t)?function(t,e){return e.ownerDocument.importNode((new window.DOMParser).parseFromString(`${t}`,"application/xml").documentElement,!0)}(e,t):function(t,e){const n=L(e)?e:document.createElement("template");return n.innerHTML=t,n.content}(e,t)}function ht(t,e){switch(!0){case C(t):i(e,t);break;case L(t):t.parentNode.replaceChild(e,t);break;default:t.appendChild(e)}}const pt=Object.freeze({createDOM(t){return this.dom=this.dom||function(t,e){return e&&("string"==typeof e?dt(t,e):e)}(t,this.html),this},mount(t,e,n,r){if(void 0===r&&(r={}),!t)throw new Error("Please provide DOM node to mount properly your template");this.el&&this.unmount(e);const{fragment:i,children:s,avoidDOMInjection:o}=r,{parentNode:a}=s?s[0]:t,u=L(t),l=u?Math.max(Array.from(a.childNodes).indexOf(t),0):null;return this.isTemplateTag=u,this.createDOM(t),this.dom&&(this.fragment=i||this.dom.cloneNode(!0)),this.el=this.isTemplateTag?a:t,this.children=this.isTemplateTag?s||Array.from(this.fragment.childNodes):null,!o&&this.fragment&&ht(t,this.fragment),this.bindings=this.bindingsData.map((t=>ft(this.el,t,l))),this.bindings.forEach((t=>t.mount(e,n))),this},update(t,e){return this.bindings.forEach((n=>n.update(t,e))),this},unmount(t,e,n){if(this.el){switch(this.bindings.forEach((r=>r.unmount(t,e,n))),!0){case this.el[j]:break;case this.children&&null!==n:s(this.children);break;case!0===n:o(this.el);break;case null!==n:s(this.el.childNodes)}this.el=null}return this},clone(){return Object.assign({},this,{el:null})}});function mt(t,e){return void 0===e&&(e=[]),Object.assign({},pt,{html:t,bindingsData:e})}function gt(){return this}function vt(t){return U(t)?t.prototype&&t.prototype.constructor?new t:t():t}function bt(t,e,n,r){return void 0===r&&(r={}),Object.defineProperty(t,e,Object.assign({value:n,enumerable:!1,writable:!1,configurable:!0},r)),t}function yt(t,e,n){return Object.entries(e).forEach((e=>{let[r,i]=e;bt(t,r,i,n)})),t}function Et(t,e){return Object.entries(e).forEach((e=>{let[n,r]=e;t[n]||(t[n]=r)})),t}function xt(t){return Array.isArray(t)?t:/^\[object (HTMLCollection|NodeList|Object)\]$/.test(Object.prototype.toString.call(t))&&"number"==typeof t.length?Array.from(t):[t]}function Ot(t,e){return xt("string"==typeof t?(e||document).querySelectorAll(t):t)}const Nt=t=>1===t.length?t[0]:t;function wt(t,e,n){const r="object"==typeof e?e:{[e]:n},i=Object.keys(r);return xt(t).forEach((t=>{i.forEach((e=>t.setAttribute(e,r[e])))})),t}function Tt(t,e){return function(t,e,n){const r="string"==typeof e?[e]:e;return Nt(xt(t).map((t=>Nt(r.map((e=>t[n](e)))))))}(t,e,"getAttribute")}const jt=new Map,At=()=>St||(wt(St=Ot("style[riot]")[0]||document.createElement("style"),"type","text/css"),St.parentNode||document.head.appendChild(St),St);var St,Mt={CSS_BY_NAME:jt,add(t,e){return jt.has(t)||(jt.set(t,e),this.inject()),this},inject(){return At().innerHTML=[...jt.values()].join("\n"),this},remove(t){return jt.has(t)&&(jt.delete(t),this.inject()),this}};function _t(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r(t[r(e.name)]=e.value,t)),{})}(t),vt(e))}const It=(t,e)=>t[l]=e;function Rt(t){return[d,h,p].reduce(((e,n)=>(e[n]=t(n),e)),{})}function zt(t){let{css:e,template:n,exports:r,name:i}=t;const s=n?function(t,e){return t(mt,P,D,(t=>e[t]||u.get(t)))}(n,r?function(t){void 0===t&&(t={});return Object.entries(vt(t)).reduce(((t,e)=>{let[n,r]=e; +(()=>{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(;ct-f){const i=r(e[c],0);for(;f{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===i:return Object.assign({},t,n);case 3===i:t.value=e.value;break;default:t[r(e.name)]=e.value}return t}),{})}const Y="removeAttribute",$="setAttribute",q="undefined"==typeof Element?{}:Element.prototype,H=function(t){const e=new Map,n=n=>(e.has(n)||e.set(n,t.call(this,n)))&&e.get(n);return n.cache=e,n}((t=>q.hasOwnProperty(t)));function G(t,e,n,r){let{name:i}=e;if(!i)return r&&function(t,e,n){const r=e?Object.keys(e):[];Object.keys(n).filter((t=>!r.includes(t))).forEach((e=>t.removeAttribute(e)))}(t,n,r),void(n&&function(t,e){Object.entries(e).forEach((e=>{let[n,r]=e;return G(t,{name:n},r)}))}(t,n));!H(i)&&(function(t){return C(t,"boolean")}(n)||I(n)||k(n))&&(t[i]=n),t[function(t){return R(t)||!1===t||""===t||I(t)||k(t)?Y:$}(n)](i,function(t,e){return!0===e?t:e}(i,n))}const X=/^on/,J={handleEvent(t){this[t.type](t)}},Z=new WeakMap;function W(t){return R(t)?"":t}const Q=(t,e)=>{const n=t.childNodes[e];if(n.nodeType===Node.COMMENT_NODE){const e=document.createTextNode("");return t.replaceChild(e,n),e}return n};var tt={0:G,1:function(t,e,n){let{name:r}=e;const i=r.replace(X,""),o=Z.get(t)||(t=>{const e=Object.create(J);return Z.set(t,e),e})(t),[s,a]=(t=>Array.isArray(t)?t:[t,!1])(n),u=o[i],l=s&&!u;u&&!s&&t.removeEventListener(i,o),l&&t.addEventListener(i,o,a),o[i]=s},2:function(t,e,n){t.data=W(n)},3:function(t,e,n){t.value=W(n)}};const et={mount(t){return this.value=this.evaluate(t),nt(this,this.value),this},update(t){const e=this.evaluate(t);return this.value!==e&&(nt(this,e),this.value=e),this},unmount(){return 1===this.type&&nt(this,null),this}};function nt(t,e){return tt[t.type](t.node,t,e,t.value)}function rt(t,e){return Object.assign({},et,e,{node:2===e.type?Q(t,e.childNodeIndex):t})}const it=(t,e)=>t[A]||e,ot={attributes:[],getTemplateScope(t,e){return function(t,e,n){if(!t||!t.length)return n;const r=t.map((t=>Object.assign({},t,{value:t.evaluate(e)})));return Object.assign(Object.create(n||null),B(r))}(this.attributes,t,e)},mount(t,e){const n=!!t.slots&&t.slots.find((t=>{let{id:e}=t;return e===this.name})),{parentNode:r}=this.node,i=it(t,e);return this.template=n&&mt(n.html,n.bindings).createDOM(r),this.template&&(this.template.mount(this.node,this.getTemplateScope(t,i),i),this.template.children=Array.from(this.node.childNodes),st(this.node)),s(this.node),this},update(t,e){if(this.template){const n=it(t,e);this.template.update(this.getTemplateScope(t,n),n)}return this},unmount(t,e,n){return this.template&&this.template.unmount(this.getTemplateScope(t,e),null,n),this}};function st(t){const e=t&&t.firstChild;e&&(a(e,t),st(t))}function at(t){return t.reduce(((t,e)=>{let{bindings:n}=e;return t.concat(n)}),[])}const ut={mount(t){return this.update(t)},update(t,e){const n=this.evaluate(t);return n===this.name?this.tag.update(t):(this.unmount(t,e,!0),this.name=n,this.tag=function(t,e,n){return void 0===e&&(e=[]),void 0===n&&(n=[]),t?t({slots:e,attributes:n}):mt(function(t){return t.reduce(((t,e)=>t+e.html),"")}(e),[...at(e),{expressions:n.map((t=>Object.assign({type:0},t)))}])}(this.getComponent(n),this.slots,this.attributes),this.tag.mount(this.node,t)),this},unmount(t,e,n){return this.tag&&this.tag.unmount(n),this}};var lt={1:function(t,e){let{evaluate:n,template:r}=e;const i=document.createTextNode("");return a(i,t),s(t),Object.assign({},F,{node:t,evaluate:n,placeholder:i,template:r.createDOM(t)})},2:function(t,e){let{expressions:n}=e;return Object.assign({},(r=n.map((e=>rt(t,e))),["mount","update","unmount"].reduce(((t,e)=>Object.assign({},t,{[e]:t=>r.map((n=>n[e](t)))&&i})),{})));var r,i},0:function(t,e){let{evaluate:n,condition:r,itemName:i,indexName:o,getKey:u,template:l}=e;const c=document.createTextNode(""),f=t.cloneNode();return a(c,t),s(t),Object.assign({},V,{childrenMap:new Map,node:t,root:f,condition:r,evaluate:n,isTemplateTag:U(f),template:l.createDOM(t),getKey:u,indexName:o,itemName:i,placeholder:c})},3:function(t,e){let{evaluate:n,getComponent:r,slots:i,attributes:o}=e;return Object.assign({},ut,{node:t,evaluate:n,slots:i,attributes:o,getComponent:r})},4:function(t,e){let{name:n,attributes:r}=e;return Object.assign({},ot,{attributes:r,node:t,name:n})}};function ct(t,e){return t.map((t=>2===t.type?Object.assign({},t,{childNodeIndex:t.childNodeIndex+e}):t))}function ft(t,e,n){const{selector:r,type:i,redundantAttribute:o,expressions:s}=e,a=r?t.querySelector(r):t;o&&a.removeAttribute(o);const u=s||[];return(lt[i]||lt[2])(a,Object.assign({},e,{expressions:n&&!r?ct(u,n):u}))}function dt(t,e){return L(t)?function(t,e){return e.ownerDocument.importNode((new window.DOMParser).parseFromString(`${t}`,"application/xml").documentElement,!0)}(e,t):function(t,e){const n=U(e)?e:document.createElement("template");return n.innerHTML=t,n.content}(e,t)}function ht(t,e){switch(!0){case L(t):i(e,t);break;case U(t):t.parentNode.replaceChild(e,t);break;default:t.appendChild(e)}}const pt=Object.freeze({createDOM(t){return this.dom=this.dom||function(t,e){return e&&("string"==typeof e?dt(t,e):e)}(t,this.html),this},mount(t,e,n,r){if(void 0===r&&(r={}),!t)throw new Error("Please provide DOM node to mount properly your template");this.el&&this.unmount(e);const{fragment:i,children:o,avoidDOMInjection:s}=r,{parentNode:a}=o?o[0]:t,u=U(t),l=u?Math.max(Array.from(a.childNodes).indexOf(t),0):null;return this.isTemplateTag=u,this.createDOM(t),this.dom&&(this.fragment=i||this.dom.cloneNode(!0)),this.el=this.isTemplateTag?a:t,this.children=this.isTemplateTag?o||Array.from(this.fragment.childNodes):null,!s&&this.fragment&&ht(t,this.fragment),this.bindings=this.bindingsData.map((t=>ft(this.el,t,l))),this.bindings.forEach((t=>t.mount(e,n))),this},update(t,e){return this.bindings.forEach((n=>n.update(t,e))),this},unmount(t,e,n){if(this.el){switch(this.bindings.forEach((r=>r.unmount(t,e,n))),!0){case this.el[j]:break;case this.children&&null!==n:o(this.children);break;case!0===n:s(this.el);break;case null!==n:o(this.el.childNodes)}this.el=null}return this},clone(){return Object.assign({},this,{el:null})}});function mt(t,e){return void 0===e&&(e=[]),Object.assign({},pt,{html:t,bindingsData:e})}function gt(){return this}function vt(t){return k(t)?t.prototype&&t.prototype.constructor?new t:t():t}function bt(t,e,n,r){return void 0===r&&(r={}),Object.defineProperty(t,e,Object.assign({value:n,enumerable:!1,writable:!1,configurable:!0},r)),t}function yt(t,e,n){return Object.entries(e).forEach((e=>{let[r,i]=e;bt(t,r,i,n)})),t}function Et(t,e){return Object.entries(e).forEach((e=>{let[n,r]=e;t[n]||(t[n]=r)})),t}function xt(t){return Array.isArray(t)?t:/^\[object (HTMLCollection|NodeList|Object)\]$/.test(Object.prototype.toString.call(t))&&"number"==typeof t.length?Array.from(t):[t]}function Ot(t,e){return xt("string"==typeof t?(e||document).querySelectorAll(t):t)}const Nt=t=>1===t.length?t[0]:t;function wt(t,e,n){const r="object"==typeof e?e:{[e]:n},i=Object.keys(r);return xt(t).forEach((t=>{i.forEach((e=>t.setAttribute(e,r[e])))})),t}function Tt(t,e){return function(t,e,n){const r="string"==typeof e?[e]:e;return Nt(xt(t).map((t=>Nt(r.map((e=>t[n](e)))))))}(t,e,"getAttribute")}const jt=new Map,At=()=>St||(wt(St=Ot("style[riot]")[0]||document.createElement("style"),"type","text/css"),St.parentNode||document.head.appendChild(St),St);var St,Mt={CSS_BY_NAME:jt,add(t,e){return jt.has(t)||(jt.set(t,e),this.inject()),this},inject(){return At().innerHTML=[...jt.values()].join("\n"),this},remove(t){return jt.has(t)&&(jt.delete(t),this.inject()),this}};function _t(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r(t[r(e.name)]=e.value,t)),{})}(t),vt(e))}const It=(t,e)=>t[l]=e;function Rt(t){return[d,h,p].reduce(((e,n)=>(e[n]=t(n),e)),{})}function zt(t){let{css:e,template:n,exports:r,name:i}=t;const o=n?function(t,e){return t(mt,P,D,(t=>e[t]||u.get(t)))}(n,r?function(t){void 0===t&&(t={});return Object.entries(vt(t)).reduce(((t,e)=>{let[n,r]=e; /* 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):{}):Lt;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&&B("Pure components can not have html"),s&&B("Pure components do not have css");const a=Et(t({slots:n,attributes:r,props:i}),kt);return Rt((t=>function(){for(var e=arguments.length,n=new Array(e),r=0;rc.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(Bt)(yt(Et(r,Object.assign({},Ct,{[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 Bt(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({},Ut(e,i),K(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=K(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=>U(t[e]))).forEach((t=>{s[t]=s[t].bind(s)})),s;var s}const{DOM_COMPONENT_INSTANCE_PROPERTY:Kt,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{t.detail?(this.state.errors=t.detail,n.classList.add("field--error"),n.classList.remove("field--valid")):(this.state.errors=[],n.classList.remove("field--error"),n.classList.add("field--valid")),this.update()}))}},template:function(t,e,n,r){return t('
',[{type:n.IF,evaluate:function(t){return t.state.errors.length>0},redundantAttribute:"expr0",selector:"[expr0]",template:t('
',[{type:n.EACH,getKey:null,condition:null,template:t(" ",[{expressions:[{type:e.TEXT,childNodeIndex:0,evaluate:function(t){return[t.error].join("")}}]}]),redundantAttribute:"expr1",selector:"[expr1]",itemName:"error",indexName:null,evaluate:function(t){return t.state.errors}}])}])},name:"field-error"}),Ot("field-error").map((t=>function(t,e,n){const r=n||Dt(t);return u.has(r)||B(`The component named "${r}" was never registered`),u.get(r)({props:e}).mount(t)}(t,Wt,Qt)));new Zt("form",{email:{presence:!0,email:!0},password:{presence:!0}})},422:t=>{var e=/^(?:submit|button|image|reset|file)$/i,n=/^(?:input|select|textarea|keygen)/i,r=/(\[[^\[\]]*\])/g;function i(t,e,n){if(0===e.length)return t=n;var r=e.shift(),s=r.match(/^\[(.+?)\]$/);if("[]"===r)return t=t||[],Array.isArray(t)?t.push(i(null,e,n)):(t._values=t._values||[],t._values.push(i(null,e,n))),t;if(s){var o=s[1],a=+o;isNaN(a)?(t=t||{})[o]=i(t[o],e,n):(t=t||[])[a]=i(t[a],e,n)}else t[r]=i(t[r],e,n);return t}function s(t,e,n){if(e.match(r)){i(t,function(t){var e=[],n=new RegExp(r),i=/^([^\[\]]*)/.exec(t);for(i[1]&&e.push(i[1]);null!==(i=n.exec(t));)e.push(i[1]);return e}(e),n)}else{var s=t[e];s?(Array.isArray(s)||(t[e]=[s]),t[e].push(n)):t[e]=n}return t}function o(t,e,n){return n=n.replace(/(\r)?\n/g,"\r\n"),n=(n=encodeURIComponent(n)).replace(/%20/g,"+"),t+(t?"&":"")+encodeURIComponent(e)+"="+n}t.exports=function(t,r){"object"!=typeof r?r={hash:!!r}:void 0===r.hash&&(r.hash=!0);for(var i=r.hash?{}:"",a=r.serializer||(r.hash?s:o),u=t&&t.elements?t.elements:[],l=Object.create(null),c=0;c{},765:function(t,e,n){t=n.nmd(t), +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;rc.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{this.dispatchCustomEvent(e,i,t.name)})),this.root.addEventListener("form-validation",(t=>{this.onFormValidation(t,n)}))},onFormValidation(t,e){t.detail?(this.state.errors=t.detail,e.classList.add("field--error"),e.classList.remove("field--valid")):(this.state.errors=[],e.classList.remove("field--error"),e.classList.add("field--valid")),this.update()},dispatchCustomEvent(t,e,n){const r=new CustomEvent("field-update",{detail:{name:n,value:t.target.value}});e.dispatchEvent(r)}},template:function(t,e,n,r){return t('
',[{type:n.IF,evaluate:function(t){return t.state.errors.length>0},redundantAttribute:"expr0",selector:"[expr0]",template:t('
',[{type:n.EACH,getKey:null,condition:null,template:t(" ",[{expressions:[{type:e.TEXT,childNodeIndex:0,evaluate:function(t){return[t.error].join("")}}]}]),redundantAttribute:"expr1",selector:"[expr1]",itemName:"error",indexName:null,evaluate:function(t){return t.state.errors}}])}])},name:"field-error"}),Ot("field-error").map((t=>function(t,e,n){const r=n||Dt(t);return u.has(r)||K(`The component named "${r}" was never registered`),u.get(r)({props:e}).mount(t)}(t,Wt,Qt)));new Zt("form",{email:{presence:!0,email:!0},password:{presence:!0}})},422:t=>{var e=/^(?:submit|button|image|reset|file)$/i,n=/^(?:input|select|textarea|keygen)/i,r=/(\[[^\[\]]*\])/g;function i(t,e,n){if(0===e.length)return t=n;var r=e.shift(),o=r.match(/^\[(.+?)\]$/);if("[]"===r)return t=t||[],Array.isArray(t)?t.push(i(null,e,n)):(t._values=t._values||[],t._values.push(i(null,e,n))),t;if(o){var s=o[1],a=+s;isNaN(a)?(t=t||{})[s]=i(t[s],e,n):(t=t||[])[a]=i(t[a],e,n)}else t[r]=i(t[r],e,n);return t}function o(t,e,n){if(e.match(r)){i(t,function(t){var e=[],n=new RegExp(r),i=/^([^\[\]]*)/.exec(t);for(i[1]&&e.push(i[1]);null!==(i=n.exec(t));)e.push(i[1]);return e}(e),n)}else{var o=t[e];o?(Array.isArray(o)||(t[e]=[o]),t[e].push(n)):t[e]=n}return t}function s(t,e,n){return n=n.replace(/(\r)?\n/g,"\r\n"),n=(n=encodeURIComponent(n)).replace(/%20/g,"+"),t+(t?"&":"")+encodeURIComponent(e)+"="+n}t.exports=function(t,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=t&&t.elements?t.elements:[],l=Object.create(null),c=0;c{},765:function(t,e,n){t=n.nmd(t), /*! * validate.js 0.13.1 * @@ -9,4 +9,4 @@ var i;return t[(i=n,i.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase())]=zt(r),t * 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){return s.isArray(t)?t.filter((function(t,e,n){return n.indexOf(t)==e})):t},forEachKeyInKeypath:function(t,e,n){if(s.isString(e)){var r,i="",o=!1;for(r=0;ro&&(r=e.tooLong||this.tooLong||"is too long (maximum is %{count} characters)",u.push(s.format(r,{count:o}))),u.length>0?e.message||u:void 0):e.message||this.notValid||"has an incorrect length"}},numericality:function(t,e,n,r,i){if(s.isDefined(t)){var o,a,u=[],l={greaterThan:function(t,e){return t>e},greaterThanOrEqualTo:function(t,e){return t>=e},equalTo:function(t,e){return t===e},lessThan:function(t,e){return to&&(n=e.tooLate||e.message||this.tooLate||"must be no later than %{date}",n=s.format(n,{date:this.format(o,e),value:this.format(t,e)}),r.push(n)),r.length?s.unique(r):void 0)}}),{parse:null,format:null}),date:function(t,e){return e=s.extend({},e,{dateOnly:!0}),s.validators.datetime.call(s.validators.datetime,t,e)},format:function(t,e){(s.isString(e)||e instanceof RegExp)&&(e={pattern:e});var n,r=(e=s.extend({},this.options,e)).message||this.message||"is invalid",i=e.pattern;if(s.isDefined(t))return s.isString(t)?(s.isString(i)&&(i=new RegExp(e.pattern,e.flags)),(n=i.exec(t))&&n[0].length==t.length?void 0:r):r},inclusion:function(t,e){if(s.isDefined(t)&&(s.isArray(e)&&(e={within:e}),e=s.extend({},this.options,e),!s.contains(e.within,t))){var n=e.message||this.message||"^%{value} is not included in the list";return s.format(n,{value:t})}},exclusion:function(t,e){if(s.isDefined(t)&&(s.isArray(e)&&(e={within:e}),e=s.extend({},this.options,e),s.contains(e.within,t))){var n=e.message||this.message||"^%{value} is restricted";return s.isString(e.within[t])&&(t=e.within[t]),s.format(n,{value:t})}},email:s.extend((function(t,e){var n=(e=s.extend({},this.options,e)).message||this.message||"is not a valid email";if(s.isDefined(t))return s.isString(t)&&this.PATTERN.exec(t)?void 0:n}),{PATTERN:/^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i}),equality:function(t,e,n,r,i){if(s.isDefined(t)){s.isString(e)&&(e={attribute:e});var o=(e=s.extend({},this.options,e)).message||this.message||"is not equal to %{attribute}";if(s.isEmpty(e.attribute)||!s.isString(e.attribute))throw new Error("The attribute must be a non empty string");var a=s.getDeepObjectValue(r,e.attribute),u=e.comparator||function(t,e){return t===e},l=e.prettify||i&&i.prettify||s.prettify;return u(t,a,e,n,r)?void 0:s.format(o,{attribute:l(e.attribute)})}},url:function(t,e){if(s.isDefined(t)){var n=(e=s.extend({},this.options,e)).message||this.message||"is not a valid url",r=e.schemes||this.schemes||["http","https"],i=e.allowLocal||this.allowLocal||!1,o=e.allowDataUrl||this.allowDataUrl||!1;if(!s.isString(t))return n;var a="^(?:(?:"+r.join("|")+")://)(?:\\S+(?::\\S*)?@)?(?:",u="(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))";if(i?u+="?":a+="(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})",a+="(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*"+u+")(?::\\d{2,5})?(?:[/?#]\\S*)?$",o){a="(?:"+a+")|(?:^data:(?:\\w+\\/[-+.\\w]+(?:;[\\w=]+)*)?(?:;base64)?,[A-Za-z0-9-_.!~\\*'();\\/?:@&=+$,%]*$)"}return new RegExp(a,"i").exec(t)?void 0:n}},type:s.extend((function(t,e,n,r,i){if(s.isString(e)&&(e={type:e}),s.isDefined(t)){var o,a=s.extend({},this.options,e),u=a.type;if(!s.isDefined(u))throw new Error("No type was specified");if(o=s.isFunction(u)?u:this.types[u],!s.isFunction(o))throw new Error("validate.validators.type.types."+u+" must be a function.");if(!o(t,a,n,r,i)){var l=e.message||this.messages[u]||this.message||a.message||(s.isFunction(u)?"must be of the correct type":"must be of type %{type}");return s.isFunction(l)&&(l=l(t,e,n,r,i)),s.format(l,{attribute:s.prettify(n),type:u})}}}),{types:{object:function(t){return s.isObject(t)&&!s.isArray(t)},array:s.isArray,integer:s.isInteger,number:s.isNumber,string:s.isString,date:s.isDate,boolean:s.isBoolean},messages:{}})},i.formatters={detailed:function(t){return t},flat:s.flattenErrorsToArray,grouped:function(t){var e;for(e in t=s.groupErrorsByAttribute(t))t[e]=s.flattenErrorsToArray(t[e]);return t},constraint:function(t){var e;for(e in t=s.groupErrorsByAttribute(t))t[e]=t[e].map((function(t){return t.validator})).sort();return t}},i.exposeModule(i,this,t,e,n.amdD)}.call(this,e,t,n.amdD)}},e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={id:r,loaded:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.loaded=!0,i.exports}n.m=t,n.x=t=>{},n.amdD=function(){throw new Error("define cannot be used indirect")},n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.nmd=t=>(t.paths=[],t.children||(t.children=[]),t),(()=>{var t={669:0},e=[[2],[837]],r=t=>{},i=(i,s)=>{for(var o,a,[u,l,c,f]=s,d=0,h=[];d{}),r}s.forEach(i.bind(null,0)),s.push=i.bind(null,s.push.bind(s));var a=n.x;n.x=()=>(n.x=a||(t=>{}),(r=o)())})(),n.x()})(); \ No newline at end of file +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){return o.isArray(t)?t.filter((function(t,e,n){return n.indexOf(t)==e})):t},forEachKeyInKeypath:function(t,e,n){if(o.isString(e)){var r,i="",s=!1;for(r=0;rs&&(r=e.tooLong||this.tooLong||"is too long (maximum is %{count} characters)",u.push(o.format(r,{count:s}))),u.length>0?e.message||u:void 0):e.message||this.notValid||"has an incorrect length"}},numericality:function(t,e,n,r,i){if(o.isDefined(t)){var s,a,u=[],l={greaterThan:function(t,e){return t>e},greaterThanOrEqualTo:function(t,e){return t>=e},equalTo:function(t,e){return t===e},lessThan:function(t,e){return ts&&(n=e.tooLate||e.message||this.tooLate||"must be no later than %{date}",n=o.format(n,{date:this.format(s,e),value:this.format(t,e)}),r.push(n)),r.length?o.unique(r):void 0)}}),{parse:null,format:null}),date:function(t,e){return e=o.extend({},e,{dateOnly:!0}),o.validators.datetime.call(o.validators.datetime,t,e)},format:function(t,e){(o.isString(e)||e instanceof RegExp)&&(e={pattern:e});var n,r=(e=o.extend({},this.options,e)).message||this.message||"is invalid",i=e.pattern;if(o.isDefined(t))return o.isString(t)?(o.isString(i)&&(i=new RegExp(e.pattern,e.flags)),(n=i.exec(t))&&n[0].length==t.length?void 0:r):r},inclusion:function(t,e){if(o.isDefined(t)&&(o.isArray(e)&&(e={within:e}),e=o.extend({},this.options,e),!o.contains(e.within,t))){var n=e.message||this.message||"^%{value} is not included in the list";return o.format(n,{value:t})}},exclusion:function(t,e){if(o.isDefined(t)&&(o.isArray(e)&&(e={within:e}),e=o.extend({},this.options,e),o.contains(e.within,t))){var n=e.message||this.message||"^%{value} is restricted";return o.isString(e.within[t])&&(t=e.within[t]),o.format(n,{value:t})}},email:o.extend((function(t,e){var n=(e=o.extend({},this.options,e)).message||this.message||"is not a valid email";if(o.isDefined(t))return o.isString(t)&&this.PATTERN.exec(t)?void 0:n}),{PATTERN:/^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i}),equality:function(t,e,n,r,i){if(o.isDefined(t)){o.isString(e)&&(e={attribute:e});var s=(e=o.extend({},this.options,e)).message||this.message||"is not equal to %{attribute}";if(o.isEmpty(e.attribute)||!o.isString(e.attribute))throw new Error("The attribute must be a non empty string");var a=o.getDeepObjectValue(r,e.attribute),u=e.comparator||function(t,e){return t===e},l=e.prettify||i&&i.prettify||o.prettify;return u(t,a,e,n,r)?void 0:o.format(s,{attribute:l(e.attribute)})}},url:function(t,e){if(o.isDefined(t)){var n=(e=o.extend({},this.options,e)).message||this.message||"is not a valid url",r=e.schemes||this.schemes||["http","https"],i=e.allowLocal||this.allowLocal||!1,s=e.allowDataUrl||this.allowDataUrl||!1;if(!o.isString(t))return n;var a="^(?:(?:"+r.join("|")+")://)(?:\\S+(?::\\S*)?@)?(?:",u="(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))";if(i?u+="?":a+="(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})",a+="(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*"+u+")(?::\\d{2,5})?(?:[/?#]\\S*)?$",s){a="(?:"+a+")|(?:^data:(?:\\w+\\/[-+.\\w]+(?:;[\\w=]+)*)?(?:;base64)?,[A-Za-z0-9-_.!~\\*'();\\/?:@&=+$,%]*$)"}return new RegExp(a,"i").exec(t)?void 0:n}},type:o.extend((function(t,e,n,r,i){if(o.isString(e)&&(e={type:e}),o.isDefined(t)){var s,a=o.extend({},this.options,e),u=a.type;if(!o.isDefined(u))throw new Error("No type was specified");if(s=o.isFunction(u)?u:this.types[u],!o.isFunction(s))throw new Error("validate.validators.type.types."+u+" must be a function.");if(!s(t,a,n,r,i)){var l=e.message||this.messages[u]||this.message||a.message||(o.isFunction(u)?"must be of the correct type":"must be of type %{type}");return o.isFunction(l)&&(l=l(t,e,n,r,i)),o.format(l,{attribute:o.prettify(n),type:u})}}}),{types:{object:function(t){return o.isObject(t)&&!o.isArray(t)},array:o.isArray,integer:o.isInteger,number:o.isNumber,string:o.isString,date:o.isDate,boolean:o.isBoolean},messages:{}})},i.formatters={detailed:function(t){return t},flat:o.flattenErrorsToArray,grouped:function(t){var e;for(e in t=o.groupErrorsByAttribute(t))t[e]=o.flattenErrorsToArray(t[e]);return t},constraint:function(t){var e;for(e in t=o.groupErrorsByAttribute(t))t[e]=t[e].map((function(t){return t.validator})).sort();return t}},i.exposeModule(i,this,t,e,n.amdD)}.call(this,e,t,n.amdD)}},e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={id:r,loaded:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.loaded=!0,i.exports}n.m=t,n.x=t=>{},n.amdD=function(){throw new Error("define cannot be used indirect")},n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.nmd=t=>(t.paths=[],t.children||(t.children=[]),t),(()=>{var t={669:0},e=[[2],[837]],r=t=>{},i=(i,o)=>{for(var s,a,[u,l,c,f]=o,d=0,h=[];d{}),r}o.forEach(i.bind(null,0)),o.push=i.bind(null,o.push.bind(o));var a=n.x;n.x=()=>(n.x=a||(t=>{}),(r=s)())})(),n.x()})(); \ No newline at end of file diff --git a/main.js b/main.js deleted file mode 100644 index 9967aa3..0000000 --- a/main.js +++ /dev/null @@ -1,4 +0,0 @@ -/******/ (() => { // webpackBootstrap -/******/ "use strict"; -/******/ })() -; \ No newline at end of file diff --git a/src/FormValidator.js b/src/FormValidator.js index 7920faf..e2a2573 100644 --- a/src/FormValidator.js +++ b/src/FormValidator.js @@ -2,6 +2,8 @@ import validate from 'validate.js' import serialize from 'form-serialize' /** + * Form Validator with RiotJS Components + * * * * @@ -15,8 +17,6 @@ class FormValidator */ constructor(formSelector, constraits) { - this.errors = [] - // getting selector to find form-element this.formSelector = formSelector @@ -38,31 +38,13 @@ class FormValidator }) } - /** - * - * @param {[type]} name [description] - * @return {[type]} [description] - */ - findElementByName(name) { - - let result - - this.elements.forEach((element) => { - if (element.attributes.name.nodeValue == name) { - result = element - return false - } - }) - - return result - } - /** * * @param {[type]} event [description] * @return {[type]} [description] */ - onSubmit(event) { + onSubmit(event) + { let errors = validate(serialize(event.target, { hash: true }), this.constraits) @@ -70,9 +52,11 @@ class FormValidator if (errors) { event.preventDefault() + // send each element a event this.elements.forEach((element) => { let elementErrors = false + // check for errors by name if (errors[element.attributes.name.nodeValue]) { elementErrors = errors[element.attributes.name.nodeValue] } @@ -84,27 +68,35 @@ class FormValidator /** * - * @param {[type]} event [description] - * @return {[type]} [description] + * + * @param {Event} event + * */ - onFieldUpdate(event) { - + onFieldUpdate(event) + { // if value is a empty string make him undefined - if (!event.detail.value) { + if (event.detail.value == '') { event.detail.value = undefined } - let errors = validate.single(event.detail.value, this.constraits[event.detail.name]) - let element = this.findElementByName(event.detail.name) + let errors = validate.single(event.detail.value, this.constraits[event.detail.name]), + element - this.dispatchCustomEvent(errors, element) + // search for element by name and dispatch event + Array.from(this.elements).every((e) => { + if (e.attributes.name.nodeValue == event.detail.name) { + this.dispatchCustomEvent(errors, e) + return false + } + }) } /** + * dispatch event to single element + * + * @param {Array} errors + * @param {Element} element * - * @param {[type]} errors [description] - * @param {[type]} element [description] - * @return {[type]} [description] */ dispatchCustomEvent(errors, element) { diff --git a/src/field-error.riot b/src/field-error.riot index ed4f707..1096272 100644 --- a/src/field-error.riot +++ b/src/field-error.riot @@ -9,9 +9,12 @@ diff --git a/src/validator.js b/src/validator.js deleted file mode 100644 index e459d48..0000000 --- a/src/validator.js +++ /dev/null @@ -1,92 +0,0 @@ -import validate from 'validate.js' -import serialize from 'form-serialize' - -/** - * Validate entire Form or a single Element - * - * Using validator.js - * - * @author Björn Hase, Tentakelfabrik, me@tentakelfabrik.de - * - */ -class Validator { - - /** - * - * @param {array} rules - */ - constructor(rules, component) { - this._rules = rules - this._component = component - - this._errors = { - - } - } - - /** - * handle validation - * - * if key not set, - * - * @param {object} event - * @param {object} key - * - */ - handle(event, key) { - - event.preventDefault() - - let data = null, rules, errors - - if (key) { - if (event.target.value) { - data = event.target.value - } - } else { - data = serialize(event.target, { - hash: true - }) - } - - // validate single - if (key) { - rules = this._rules[key] - - errors = validate.single(data, rules, { - flat: true - }) - - if (errors) { - this._errors[key] = errors - } else { - delete this._errors[key] - } - - // validate entire form - } else { - this._errors = validate(data, this._rules) - } - - // update component - this._component.update() - } - - /** - * - * - * @param {[type]} key - * @return {[type]} - */ - errors(key) { - - if (key) { - return this._errors[key] - } - - return this._errors - - } -} - -export default Validator \ No newline at end of file