@evs-chris/raui
Advanced tools
Comparing version 0.15.1 to 0.15.2
@@ -396,3 +396,3 @@ import Ractive from 'ractive'; | ||
if (key && key.group) { key = keysForGroup(this, key.group); } | ||
if (key && key.group && typeof key.group !== 'function') { key = keysForGroup(this, key.group); } | ||
if (typeof key === 'boolean') { | ||
@@ -446,3 +446,3 @@ recurse = key; | ||
if (key.group) { key = keysForGroup(this, key.group); } | ||
if (key.group && typeof key.group !== 'function') { key = keysForGroup(this, key.group); } | ||
var keys = Array.isArray(key) ? key : [key]; | ||
@@ -473,3 +473,3 @@ var res = []; | ||
if (keys && keys.group) { | ||
if (keys && keys.group && typeof keys.group !== 'function') { | ||
var gs = Array.isArray(keys.group) ? keys.group : [keys.group]; | ||
@@ -502,3 +502,3 @@ gs.forEach(function (g) { return (this$1.groupHooks[g] || (this$1.groupHooks[g] = [])).push(fn); }); | ||
if (disposer) { dispose(this, disposer); } | ||
if (keys && keys.group) { | ||
if (keys && keys.group && typeof keys.group !== 'function') { | ||
var gs = Array.isArray(keys.group) ? keys.group : [keys.group]; | ||
@@ -505,0 +505,0 @@ gs.forEach(function (key) { |
@@ -1,1 +0,1 @@ | ||
import Ractive from"ractive";function dispose(validator,disposer){var idx=validator.disposers.indexOf(disposer);if(~idx&&validator.disposing){validator.disposers.splice(idx,1)}}export var Validator=function Validator(ractive,debounce){if(debounce===void 0)debounce=500;this.ractive=ractive;this.debounce=debounce;this.state={};this.hooks={};this.patternHooks=[];this.groupHooks={};this.checks=[];this.fns=[];this.many=[];this.disposers=[];this.watchers=[]};Validator.prototype.reset=function reset(){this.disposing=true;this.disposers.slice().forEach(function(d){return d.cancel()});this.state={};this.hooks={};this.patternHooks=[];this.groupHooks={};this.checks=[];this.fns=[];this.many=[];this.disposing=false;this.watchers.forEach(function(w){return w.reset()})};Validator.prototype.check=function check(keys,deps,fn,opts){var this$1=this;var ks=Array.isArray(keys)?keys.slice():[keys];var all=ks.concat(Array.isArray(deps)?deps:typeof deps==="string"?[deps]:[]);if(typeof deps==="function"){opts=fn;fn=deps;deps=[]}var set=[ks,deps,fn,opts&&opts.group&&(Array.isArray(opts.group)?opts.group:[opts.group])];this.fns.push(set);var handle=this.ractive.observe(all.join(" "),debounce(this.debounce,function(){var this$1=this;if(set.disposed){return}checker.call(this,fn,ks,all.map(function(k){return this$1.ractive.get(k)}))},this),{init:opts&&opts.init===false?false:true});var disposer={cancel:function(){dispose(this$1,disposer);set.disposed=true;var idx=this$1.fns.indexOf(set);if(~idx){this$1.fns.splice(idx,1)}handle.cancel()}};this.disposers.push(disposer);return disposer};Validator.prototype.checkList=function checkList(path,fn,opts){var this$1=this;var checks={};var len=0;var callback=function(v,o,k){if(!Array.isArray(v)){return}if(v.length!==len){if(len>v.length){for(var i=v.length;i<len;i++){if(checks[i]){checks[i].forEach(function(ref){var ks=ref[0];var handle=ref[1];handle.cancel();ks.forEach(function(k){this$1.clear(k,true);this$1.notify(k,true,true)});var idx=this$1.fns.findIndex(function(ref){var k=ref[0];return k===ks});if(~idx){this$1.fns.splice(idx,1)}});delete checks[i]}}}else{var loop=function(i){var k$1=path+"."+i;var chks=[];var o$1={check:function(keys,deps,fn,opts){var ks=(Array.isArray(keys)?keys.slice():[keys]).map(function(s){return s[0]==="."?k$1+s:s});var all=ks.concat((Array.isArray(deps)?deps:typeof deps==="string"?[deps]:[]).map(function(s){return s[0]==="."?k$1+s:s}));if(typeof deps==="function"){opts=fn;fn=deps;deps=[]}chks.push([ks,this$1.ractive.observe(all.join(" "),debounce(this$1.debounce,function(){var this$1=this;checker.call(this,fn,ks,all.map(function(k){return this$1.ractive.get(k)}),k$1)},this$1),{init:opts&&opts.init===false?false:true})]);this$1.fns.push([ks,deps,fn,opts&&opts.group&&(Array.isArray(opts.group)?opts.group:[opts.group])]);ks.prefix=k$1},checkList:function(path,fn,opts){chks.push([[],this$1.checkList(path[0]==="."?k$1+path:path,fn,opts)])},checkDefer:function(path,fn,opts){chks.push([[],this$1.checkDefer(path[0]==="."?k$1+path:path,fn,opts)])},checkCondition:function(path,deps,cond,fn,opts){chks.push([[],this$1.checkCondition(path[0]==="."?k$1+path:path,deps,cond,fn,opts)])}};fn(k$1,o$1,i);checks[i]=chks};for(var i$1=len;i$1<v.length;i$1++)loop(i$1)}len=v.length}};var observer=this.ractive.observe(path,debounceMany(this.debounce,callback,this,2),{init:opts&&opts.init===false?false:true});var paths=path.split(/\s+/);var handle=[paths,function(){paths.forEach(function(path){var arr=this$1.ractive.get(path);if(!Array.isArray(arr)){return}for(var i=0;i<arr.length;i++){callback(arr[i],undefined,path+"."+i)}})}];this.many.push(handle);var disposer={cancel:function(){dispose(this$1,disposer);var cks=Object.keys(checks);cks.forEach(function(c){checks[c]&&checks[c].forEach(function(ref){var ks=ref[0];var handle=ref[1];handle.cancel();var idx=this$1.fns.findIndex(function(ref){var k=ref[0];return k===ks});if(~idx){this$1.fns.splice(idx,1)}})});var i=this$1.many.length;while(i--){if(this$1.many[i][1]===callback){this$1.many.splice(i,1)}}observer.cancel()}};this.disposers.push(disposer);return disposer};Validator.prototype.checkDefer=function checkDefer(path,fn,opts){return this.checkCondition(path,function(v){return v!=null},fn,opts)};Validator.prototype.checkCondition=function checkCondition(path,deps,cond,fn,opts){var this$1=this;if(typeof deps==="function"){opts=fn;fn=cond;cond=deps;deps=[]}if(typeof deps==="string"){deps=[deps]}var keys=[path].concat(deps);var checks={};var callback=function(_v,_o,ck,p){var primary=!~deps.indexOf(ck);if(primary&&!(ck in checks)){checks[ck]=undefined}var tocheck=primary?[ck]:Object.keys(checks);var loop=function(i){var k=tocheck[i];var cc=cond.apply(this$1.ractive,[k].concat(deps).map(function(k){return this$1.ractive.get(k)}));if(!cc&&checks[k]){checks[k].forEach(function(ref){var ks=ref[0];var handle=ref[1];handle.cancel();ks.forEach(function(k){this$1.clear(k,true);this$1.notify(k,true,true)});var idx=this$1.fns.findIndex(function(ref){var k=ref[0];return k===ks});if(~idx){this$1.fns.splice(idx,1)}});checks[k]=undefined}else if(cc&&!checks[k]){var chks=[];var o={check:function(keys,deps,fn,opts){var ks=(Array.isArray(keys)?keys.slice():[keys]).map(function(s){return s[0]==="."?k+s:s});var all=ks.concat((Array.isArray(deps)?deps:typeof deps==="string"?[deps]:[]).map(function(s){return s[0]==="."?k+s:s}));if(typeof deps==="function"){opts=fn;fn=deps;deps=[]}chks.push([ks,this$1.ractive.observe(all.join(" "),debounce(this$1.debounce,function(){var this$1=this;checker.call(this,fn,ks,all.map(function(k){return this$1.ractive.get(k)}),k)},this$1),{init:opts&&opts.init===false?false:true})]);this$1.fns.push([ks,deps,fn,opts&&opts.group&&(Array.isArray(opts.group)?opts.group:[opts.group])]);ks.prefix=k},checkList:function(path,fn,opts){chks.push([[],this$1.checkList(path[0]==="."?k+path:path,fn,opts)])},checkDefer:function(path,fn,opts){chks.push([[],this$1.checkDefer(path[0]==="."?k+path:path,fn,opts)])},checkCondition:function(path,deps,cond,fn,opts){chks.push([[],this$1.checkCondition(path[0]==="."?k+path:path,deps,cond,fn,opts)])}};fn(k,o,p);checks[k]=chks}};for(var i=0;i<tocheck.length;i++)loop(i)};var observer=this.ractive.observe(keys.join(" "),debounceMany(this.debounce,callback,this,2),{init:opts&&opts.init===false?false:true});var parent=path.split(/\s+/);var handle=[parent,function(){parent.forEach(function(path){var obj=this$1.ractive.get(path);if(obj){callback(obj,undefined,path)}})}];this.many.push(handle);var disposer={cancel:function(){dispose(this$1,disposer);var cks=Object.keys(checks);cks.forEach(function(c){checks[c]&&checks[c].forEach(function(ref){var ks=ref[0];var handle=ref[1];handle.cancel();var idx=this$1.fns.findIndex(function(ref){var k=ref[0];return k===ks});if(~idx){this$1.fns.splice(idx,1)}})});var i=this$1.many.length;while(i--){if(this$1.many[i][1]===callback){this$1.many.splice(i,1)}}observer.cancel()}};this.disposers.push(disposer);return disposer};Validator.prototype.refresh=function refresh(path,recurse){var this$1=this;if(recurse===void 0)recurse=true;var paths=Array.isArray(path)?path:[path];paths.forEach(function(path){if(path.test){for(var i=0;i<this$1.many.length;i++){var ref=this$1.many[i];var kk=ref[0];var refresh=ref[1];kk.find(function(k){return path.test(k)})&&refresh()}}else{for(var i$1=0;i$1<this$1.many.length;i$1++){var ref$1=this$1.many[i$1];var ks=ref$1[0];var refresh$1=ref$1[1];ks.includes(path)&&refresh$1()}}});paths.forEach(function(path){if(path.test){this$1.fns.forEach(function(ref){var ks=ref[0];var deps=ref[1];var fn=ref[2];return ks.find(function(k){return path.test(k)})&&checker.call(this$1,fn,ks,ks.concat(deps).map(function(k){return this$1.ractive.get(k)}),ks.prefix)})}else{this$1.fns.forEach(function(ref){var ks=ref[0];var deps=ref[1];var fn=ref[2];return ks.includes(path)&&checker.call(this$1,fn,ks,ks.concat(deps).map(function(k){return this$1.ractive.get(k)}),ks.prefix)})}})};Validator.prototype.notify=function notify(key,up,recurse){var this$1=this;if(up){var path=Ractive.splitKeypath(key);path.pop();while(path.length){var p=Ractive.joinKeys.apply(Ractive,path);var hooks=this.hooks[p];if(hooks){hooks.forEach(function(h){return h()})}path.pop()}}if(this.hooks[key]){this.hooks[key].forEach(function(h){return h()})}if(recurse){var keys=Object.keys(this.hooks);var start=key+".";keys.forEach(function(k){if(k.startsWith(start)){this$1.hooks[k].forEach(function(h){return h()})}})}var pats=this.patternHooks;for(var i=0;i<pats.length;i++){if(pats[i][0].test(key)){pats[i][1]()}}var groups=[];for(var i$1=0;i$1<this.fns.length;i$1++){var ref=this.fns[i$1];var ks=ref[0];var gs=ref[3];if(gs&&Array.isArray(ks)&&ks.includes(key)){gs.forEach(function(g){return!groups.includes(g)&&groups.push(g)})}}for(var i$2=0;i$2<groups.length;i$2++){var hooks$1=this.groupHooks[groups[i$2]]||[];hooks$1.forEach(function(h){return h()})}};Validator.prototype.clear=function clear(key,recurse){var this$1=this;delete this.state[key];if(recurse){var keys=Object.keys(this.state);var start=key+".";keys.forEach(function(k){if(k.startsWith(start)){delete this$1.state[k]}})}this.notify(key,true,recurse)};Validator.prototype.level=function level(key,recurse){if(recurse===void 0)recurse=true;if(key&&key.group){key=keysForGroup(this,key.group)}if(typeof key==="boolean"){recurse=key;key=/.*/}else if(key===undefined){key=/.*/}var keys=Array.isArray(key)?key:[key];var level="none";for(var i=0;i<keys.length;i++){var key$1=keys[i];if(typeof key$1==="string"){var msgs=this.state[key$1]||[];for(var j=0;j<msgs.length;j++){var t=msgs[j][0];if(t==="error"){return"error"}else if(t==="warn"){level="warn"}else if(t==="info"&&level!=="warn"){level="warn"}}}if(recurse||key$1.test){var state=this.state;var ks=Object.keys(state);var start=key$1+".";for(var j$1=0;j$1<ks.length;j$1++){var k=ks[j$1];if(key$1.test?key$1.test(k):k.startsWith(start)){var msgs$1=state[k];for(var c=0;c<msgs$1.length;c++){var t$1=msgs$1[c][0];if(t$1==="error"){return"error"}else if(t$1==="warn"){level="warn"}else if(t$1==="info"&&level!=="warn"){level="info"}}}}}}return level};Validator.prototype.messages=function messages(key,recurse){var this$1=this;if(key.group){key=keysForGroup(this,key.group)}var keys=Array.isArray(key)?key:[key];var res=[];keys.forEach(function(key){if(typeof key==="string"){var msgs=this$1.state[key]||[];res.push.apply(res,msgs)}if(recurse||key.test){var state=this$1.state;var keys=Object.keys(state);var start=key+".";keys.forEach(function(k){if(key.test?key.test(k):k.startsWith(start)){res.push.apply(res,state[k])}})}});return res};Validator.prototype.hook=function hook(keys,fn,opts){var this$1=this;if(keys&&keys.group){var gs=Array.isArray(keys.group)?keys.group:[keys.group];gs.forEach(function(g){return(this$1.groupHooks[g]||(this$1.groupHooks[g]=[])).push(fn)})}else{if(typeof keys==="function"){opts=fn;fn=keys;keys=/.*/}var ks=Array.isArray(keys)?keys:[keys];ks.forEach(function(key){if(typeof key==="string"){(this$1.hooks[key]||(this$1.hooks[key]=[])).push(fn)}else if(key.test){this$1.patternHooks.push([key,fn])}})}var disposer={cancel:function(){return this$1.unhook(keys,fn,disposer)}};this.disposers.push(disposer);if(!opts||opts.lazy!==true){fn()}return disposer};Validator.prototype.unhook=function unhook(keys,fn,disposer){var this$1=this;if(disposer){dispose(this,disposer)}if(keys&&keys.group){var gs=Array.isArray(keys.group)?keys.group:[keys.group];gs.forEach(function(key){var arr=this$1.groupHooks[key]||[];var idx=arr.indexOf(fn);if(~idx){arr.splice(idx,1)}})}else{if(typeof keys==="function"){fn=keys;keys=/.*/}var ks=Array.isArray(keys)?keys:[keys];ks.forEach(function(key){if(typeof key==="string"){var arr=this$1.hooks[key]||[];var idx=arr.indexOf(fn);if(~idx){arr.splice(idx,1)}}else if(key.test){var idx$1=this$1.patternHooks.findIndex(function(h){return h[0].toString()===key.toString()&&h[1]===fn});if(~idx$1){this$1.patternHooks.splice(idx$1,1)}}})}};Validator.prototype.register=function register(what){this.watchers.push(what)};Validator.prototype.unregister=function unregister(what){var idx=this.watchers.indexOf(what);if(~idx){this.watchers.splice(idx,1)}};Validator.prototype.decorator=function decorator(opts){if(opts===void 0)opts={};var v=this;return function(node){var keys=[],len=arguments.length-1;while(len-- >0)keys[len]=arguments[len+1];var ctx=this.getLocalContext();var root=ctx.resolve();var ks;var keyList;function setKeys(keys){var list=keys.join(",");if(keyList===list){return false}keyList=list;if(opts.regex){ks=keys.map(function(k){return typeof k==="string"?new RegExp(k):k})}else if(opts.group){ks={group:keys}}else{ks=keys.map(function(k){return ctx.resolve(k)})}return true}setKeys(keys);var levels=opts.levels||Validator.defaults.levels;var position=node.style.position;var indicator;if(opts.indicator&&!position){node.style.position="relative"}if(opts.indicator){register();indicator=document.createElement("span");indicator.setAttribute("class","valid-indicator");node.appendChild(indicator)}var tab;if(opts.tab&&!opts.regex){var n=node.querySelector("input,select,textarea");if(n){var fn;fn=function(ev){n.removeEventListener("blur",fn);n.removeEventListener("input",fn);tab=null;if(ev.type==="blur"){v.refresh(ks);hook()}};tab=[n,fn];n.addEventListener("blur",fn);n.addEventListener("input",fn)}}function hook(){if(tab){return}var level=v.level(ks,true);syncClass(node,levels,levels[levelMap[level]]);if(opts.indicator){if(level!=="none"){indicator.setAttribute("title",messageGroupString(groupMessages(v.messages(ks,true))))}else{indicator.setAttribute("title","")}}}v.hook(ks,hook);if(!opts.tab&&!opts.regex){setTimeout(hook,v.debounce||500)}var res={update:function update(){var keys=[],len=arguments.length;while(len--)keys[len]=arguments[len];var old=ks;if(setKeys(keys)){v.unhook(old,hook);v.hook(ks,hook);hook()}},teardown:function teardown(){v.unhook(ks,hook);syncClass(node,levels);node.style.position=position;if(indicator){indicator.remove()}if(tab){tab[0].removeEventListener("blur",tab[1])}v.unregister(res)},reset:function reset(){v.hook(ks,hook);hook()}};if(opts.regex){res.update=function update(){var keys=[],len=arguments.length;while(len--)keys[len]=arguments[len];var next=ctx.resolve();v.unhook(ks,hook);ks=opts.regex?keys.map(function(k){return typeof k==="string"?new RegExp(k):k}):keys.map(function(k){return ctx.resolve(k)});v.hook(ks,hook);root=next;hook()}}else if(!opts.group){res.shuffled=function shuffled(){var next=ctx.resolve();if(next!==root){v.unhook(ks,hook);ks=opts.regex?keys.map(function(k){return typeof k==="string"?new RegExp(k):k}):keys.map(function(k){return ctx.resolve(k)});v.hook(ks,hook);root=next;hook()}}}v.register(res);return res}};Validator.defaults={levels:["","info","warn","error"]};function checker(fn,keys,values,prefix){var this$1=this;var changed=false;var notifies;var checks=this.checks.find(function(c){return c.keys===keys});if(!checks){checks={keys:keys,messages:[]};this.checks.push(checks)}var res=fn.apply(this.ractive,values)||[];if(prefix){for(var i=0;i<res.length;i++){if(!res[i][2]){continue}var ks=Array.isArray(res[i][2])?res[i][2]:[res[i][2]];res[i][2]=ks.map(function(k){return k[0]==="."?prefix+k:k})}}for(var i$1=0;i$1<checks.messages.length;i$1++){var ref=checks.messages[i$1];var t=ref[0];var m=ref[1];var k=ref[2];var go=true;for(var j=0;j<res.length;j++){var ref$1=res[j];var type=ref$1[0];var msg=ref$1[1];var key=ref$1[2];if(t===type&&m===msg&&keysStr(k)===keysStr(key)){go=false;break}}if(!go){continue}changed=true;notifies=notifies||keys.slice();var ks$1=k?Array.isArray(k)?k:[k]:keys;for(var j$1=0;j$1<ks$1.length;j$1++){var key$1=ks$1[j$1];if(!notifies.includes(key$1)){notifies.push(key$1)}var state=this.state[key$1]||[];for(var i$2=0;i$2<state.length;i$2++){if(state[i$2][0]===t&&state[i$2][1]===m){state.splice(i$2,1);break}}}}for(var i$3=0;i$3<res.length;i$3++){var ref$2=res[i$3];var t$1=ref$2[0];var m$1=ref$2[1];var k$1=ref$2[2];var go$1=true;for(var j$2=0;j$2<checks.messages.length;j$2++){var ref$3=checks.messages[j$2];var type$1=ref$3[0];var msg$1=ref$3[1];var key$2=ref$3[2];if(t$1===type$1&&m$1===msg$1&&keysStr(k$1)===keysStr(key$2)){go$1=false;break}}if(!go$1){continue}changed=true;notifies=notifies||keys.slice();var ks$2=k$1?Array.isArray(k$1)?k$1:[k$1]:keys;for(var j$3=0;j$3<ks$2.length;j$3++){var key$3=ks$2[j$3];if(!notifies.includes(key$3)){notifies.push(key$3)}(this.state[key$3]||(this.state[key$3]=[])).push([t$1,m$1])}}checks.messages=res;if(changed){notifies.forEach(function(key){return this$1.notify(key,true)})}}function debounce(time,fn,context){var tm;return function(){var args=[],len=arguments.length;while(len--)args[len]=arguments[len];if(tm){return}else{tm=setTimeout(function(){fn.apply(context,args);tm=null},time)}}}function debounceMany(time,fn,context,which){var tms={};return function(){var args=[],len=arguments.length;while(len--)args[len]=arguments[len];if(tms[args[which]]){return}else{tms[args[which]]=setTimeout(function(){fn.apply(context,args);tms[args[which]]=null},time)}}}var levelMap={none:0,info:1,warn:2,error:3};function syncClass(node,list,cls){var cl=node.classList;list.forEach(function(c){if(c&&cls!==c&&cl.contains(c)){cl.remove(c)}});if(cls&&!cl.contains(cls)){cl.add(cls)}}function keysStr(keys){if(typeof keys==="string"){return keys}if(Array.isArray(keys)){return keys.join(",")}}function keysForGroup(validator,group){var grps=Array.isArray(group)?group:[group];var res=[];for(var i=0;i<grps.length;i++){var fns=validator.fns;for(var j=0;j<fns.length;j++){var ks=fns[j][0];if(Array.isArray(ks)&&fns[j][3]&&fns[j][3].includes(grps[i])){for(var c=0;c<ks.length;c++){if(!res.includes(ks[c])){res.push(ks[c])}}}}}return res}function groupMessages(messages){var res=[];var cur=messages.filter(function(m){return m[0]==="error"});if(cur.length){res.push(["Errors",cur.map(function(m){return m[1]})])}cur=messages.filter(function(m){return m[0]==="warn"});if(cur.length){res.push(["Warnings",cur.map(function(m){return m[1]})])}cur=messages.filter(function(m){return m[0]==="info"||m[0]==="none"});if(cur.length){res.push(["Info",cur.map(function(m){return m[1]})])}return res}function messageGroupString(groups){if(groups.length===1){return groups[0][1].join("\n")}return groups.map(function(g){return g[0]+":\n"+g[1].join("\n")}).join("\n\n")}var registered=false;function register(){if(!registered){Ractive.addCSS("validation-decorator","\n span.valid-indicator {\n display: none;\n position: absolute;\n top: 0.25em;\n right: 0.5em;\n width: 1em;\n height: 1em;\n border-radius: 1em;\n z-index: 19;\n }\n span.valid-indicator:after {\n color: #fff;\n width: 100%;\n display: block;\n font-weight: bold;\n text-align: center;\n line-height: 1.1em;\n font-size: 1.1em;\n }\n .none > span.valid-indicator {\n display: flex;\n background-color: #16ab39;\n }\n .error > span.valid-indicator {\n display: flex;\n background-color: #ca3c3c;\n }\n .warn > span.valid-indicator {\n display: flex;\n background-color: #f79e0b;\n }\n .info > span.valid-indicator {\n display: flex;\n background-color: #1f5b93;\n }\n ");registered=true}}var probably="should probably";export function required(name,level){if(level===void 0)level="error";return function(v){if(!v){return[[level,name+" "+(level!=="error"?"should probably be provided":"is required")]]}}}export function lt(name,num,level){if(level===void 0)level="error";return function(v){if(v>=num){return[[level,name+" "+(level!=="error"?probably:"must")+" be at most "+(num-1)]]}}}export function lte(name,num,level){if(level===void 0)level="error";return function(v){if(v>num){return[[level,name+" "+(level!=="error"?probably:"must")+" be at most "+num]]}}}export function gt(name,num,level){if(level===void 0)level="error";return function(v){if(v<=num){return[[level,name+" "+(level!=="error"?probably:"must")+" be at least "+(num+1)]]}}}export function gte(name,num,level){if(level===void 0)level="error";return function(v){if(v<=num){return[[level,name+" "+(level!=="error"?probably:"must")+" be at least "+num]]}}}export function between(name,lower,upper,level){if(level===void 0)level="error";return function(v){if(v<lower||v>upper){return[[level,name+" "+(level!=="error"?probably:"must")+" be between "+lower+" and "+upper]]}}} | ||
import Ractive from"ractive";function dispose(validator,disposer){var idx=validator.disposers.indexOf(disposer);if(~idx&&validator.disposing){validator.disposers.splice(idx,1)}}export var Validator=function Validator(ractive,debounce){if(debounce===void 0)debounce=500;this.ractive=ractive;this.debounce=debounce;this.state={};this.hooks={};this.patternHooks=[];this.groupHooks={};this.checks=[];this.fns=[];this.many=[];this.disposers=[];this.watchers=[]};Validator.prototype.reset=function reset(){this.disposing=true;this.disposers.slice().forEach(function(d){return d.cancel()});this.state={};this.hooks={};this.patternHooks=[];this.groupHooks={};this.checks=[];this.fns=[];this.many=[];this.disposing=false;this.watchers.forEach(function(w){return w.reset()})};Validator.prototype.check=function check(keys,deps,fn,opts){var this$1=this;var ks=Array.isArray(keys)?keys.slice():[keys];var all=ks.concat(Array.isArray(deps)?deps:typeof deps==="string"?[deps]:[]);if(typeof deps==="function"){opts=fn;fn=deps;deps=[]}var set=[ks,deps,fn,opts&&opts.group&&(Array.isArray(opts.group)?opts.group:[opts.group])];this.fns.push(set);var handle=this.ractive.observe(all.join(" "),debounce(this.debounce,function(){var this$1=this;if(set.disposed){return}checker.call(this,fn,ks,all.map(function(k){return this$1.ractive.get(k)}))},this),{init:opts&&opts.init===false?false:true});var disposer={cancel:function(){dispose(this$1,disposer);set.disposed=true;var idx=this$1.fns.indexOf(set);if(~idx){this$1.fns.splice(idx,1)}handle.cancel()}};this.disposers.push(disposer);return disposer};Validator.prototype.checkList=function checkList(path,fn,opts){var this$1=this;var checks={};var len=0;var callback=function(v,o,k){if(!Array.isArray(v)){return}if(v.length!==len){if(len>v.length){for(var i=v.length;i<len;i++){if(checks[i]){checks[i].forEach(function(ref){var ks=ref[0];var handle=ref[1];handle.cancel();ks.forEach(function(k){this$1.clear(k,true);this$1.notify(k,true,true)});var idx=this$1.fns.findIndex(function(ref){var k=ref[0];return k===ks});if(~idx){this$1.fns.splice(idx,1)}});delete checks[i]}}}else{var loop=function(i){var k$1=path+"."+i;var chks=[];var o$1={check:function(keys,deps,fn,opts){var ks=(Array.isArray(keys)?keys.slice():[keys]).map(function(s){return s[0]==="."?k$1+s:s});var all=ks.concat((Array.isArray(deps)?deps:typeof deps==="string"?[deps]:[]).map(function(s){return s[0]==="."?k$1+s:s}));if(typeof deps==="function"){opts=fn;fn=deps;deps=[]}chks.push([ks,this$1.ractive.observe(all.join(" "),debounce(this$1.debounce,function(){var this$1=this;checker.call(this,fn,ks,all.map(function(k){return this$1.ractive.get(k)}),k$1)},this$1),{init:opts&&opts.init===false?false:true})]);this$1.fns.push([ks,deps,fn,opts&&opts.group&&(Array.isArray(opts.group)?opts.group:[opts.group])]);ks.prefix=k$1},checkList:function(path,fn,opts){chks.push([[],this$1.checkList(path[0]==="."?k$1+path:path,fn,opts)])},checkDefer:function(path,fn,opts){chks.push([[],this$1.checkDefer(path[0]==="."?k$1+path:path,fn,opts)])},checkCondition:function(path,deps,cond,fn,opts){chks.push([[],this$1.checkCondition(path[0]==="."?k$1+path:path,deps,cond,fn,opts)])}};fn(k$1,o$1,i);checks[i]=chks};for(var i$1=len;i$1<v.length;i$1++)loop(i$1)}len=v.length}};var observer=this.ractive.observe(path,debounceMany(this.debounce,callback,this,2),{init:opts&&opts.init===false?false:true});var paths=path.split(/\s+/);var handle=[paths,function(){paths.forEach(function(path){var arr=this$1.ractive.get(path);if(!Array.isArray(arr)){return}for(var i=0;i<arr.length;i++){callback(arr[i],undefined,path+"."+i)}})}];this.many.push(handle);var disposer={cancel:function(){dispose(this$1,disposer);var cks=Object.keys(checks);cks.forEach(function(c){checks[c]&&checks[c].forEach(function(ref){var ks=ref[0];var handle=ref[1];handle.cancel();var idx=this$1.fns.findIndex(function(ref){var k=ref[0];return k===ks});if(~idx){this$1.fns.splice(idx,1)}})});var i=this$1.many.length;while(i--){if(this$1.many[i][1]===callback){this$1.many.splice(i,1)}}observer.cancel()}};this.disposers.push(disposer);return disposer};Validator.prototype.checkDefer=function checkDefer(path,fn,opts){return this.checkCondition(path,function(v){return v!=null},fn,opts)};Validator.prototype.checkCondition=function checkCondition(path,deps,cond,fn,opts){var this$1=this;if(typeof deps==="function"){opts=fn;fn=cond;cond=deps;deps=[]}if(typeof deps==="string"){deps=[deps]}var keys=[path].concat(deps);var checks={};var callback=function(_v,_o,ck,p){var primary=!~deps.indexOf(ck);if(primary&&!(ck in checks)){checks[ck]=undefined}var tocheck=primary?[ck]:Object.keys(checks);var loop=function(i){var k=tocheck[i];var cc=cond.apply(this$1.ractive,[k].concat(deps).map(function(k){return this$1.ractive.get(k)}));if(!cc&&checks[k]){checks[k].forEach(function(ref){var ks=ref[0];var handle=ref[1];handle.cancel();ks.forEach(function(k){this$1.clear(k,true);this$1.notify(k,true,true)});var idx=this$1.fns.findIndex(function(ref){var k=ref[0];return k===ks});if(~idx){this$1.fns.splice(idx,1)}});checks[k]=undefined}else if(cc&&!checks[k]){var chks=[];var o={check:function(keys,deps,fn,opts){var ks=(Array.isArray(keys)?keys.slice():[keys]).map(function(s){return s[0]==="."?k+s:s});var all=ks.concat((Array.isArray(deps)?deps:typeof deps==="string"?[deps]:[]).map(function(s){return s[0]==="."?k+s:s}));if(typeof deps==="function"){opts=fn;fn=deps;deps=[]}chks.push([ks,this$1.ractive.observe(all.join(" "),debounce(this$1.debounce,function(){var this$1=this;checker.call(this,fn,ks,all.map(function(k){return this$1.ractive.get(k)}),k)},this$1),{init:opts&&opts.init===false?false:true})]);this$1.fns.push([ks,deps,fn,opts&&opts.group&&(Array.isArray(opts.group)?opts.group:[opts.group])]);ks.prefix=k},checkList:function(path,fn,opts){chks.push([[],this$1.checkList(path[0]==="."?k+path:path,fn,opts)])},checkDefer:function(path,fn,opts){chks.push([[],this$1.checkDefer(path[0]==="."?k+path:path,fn,opts)])},checkCondition:function(path,deps,cond,fn,opts){chks.push([[],this$1.checkCondition(path[0]==="."?k+path:path,deps,cond,fn,opts)])}};fn(k,o,p);checks[k]=chks}};for(var i=0;i<tocheck.length;i++)loop(i)};var observer=this.ractive.observe(keys.join(" "),debounceMany(this.debounce,callback,this,2),{init:opts&&opts.init===false?false:true});var parent=path.split(/\s+/);var handle=[parent,function(){parent.forEach(function(path){var obj=this$1.ractive.get(path);if(obj){callback(obj,undefined,path)}})}];this.many.push(handle);var disposer={cancel:function(){dispose(this$1,disposer);var cks=Object.keys(checks);cks.forEach(function(c){checks[c]&&checks[c].forEach(function(ref){var ks=ref[0];var handle=ref[1];handle.cancel();var idx=this$1.fns.findIndex(function(ref){var k=ref[0];return k===ks});if(~idx){this$1.fns.splice(idx,1)}})});var i=this$1.many.length;while(i--){if(this$1.many[i][1]===callback){this$1.many.splice(i,1)}}observer.cancel()}};this.disposers.push(disposer);return disposer};Validator.prototype.refresh=function refresh(path,recurse){var this$1=this;if(recurse===void 0)recurse=true;var paths=Array.isArray(path)?path:[path];paths.forEach(function(path){if(path.test){for(var i=0;i<this$1.many.length;i++){var ref=this$1.many[i];var kk=ref[0];var refresh=ref[1];kk.find(function(k){return path.test(k)})&&refresh()}}else{for(var i$1=0;i$1<this$1.many.length;i$1++){var ref$1=this$1.many[i$1];var ks=ref$1[0];var refresh$1=ref$1[1];ks.includes(path)&&refresh$1()}}});paths.forEach(function(path){if(path.test){this$1.fns.forEach(function(ref){var ks=ref[0];var deps=ref[1];var fn=ref[2];return ks.find(function(k){return path.test(k)})&&checker.call(this$1,fn,ks,ks.concat(deps).map(function(k){return this$1.ractive.get(k)}),ks.prefix)})}else{this$1.fns.forEach(function(ref){var ks=ref[0];var deps=ref[1];var fn=ref[2];return ks.includes(path)&&checker.call(this$1,fn,ks,ks.concat(deps).map(function(k){return this$1.ractive.get(k)}),ks.prefix)})}})};Validator.prototype.notify=function notify(key,up,recurse){var this$1=this;if(up){var path=Ractive.splitKeypath(key);path.pop();while(path.length){var p=Ractive.joinKeys.apply(Ractive,path);var hooks=this.hooks[p];if(hooks){hooks.forEach(function(h){return h()})}path.pop()}}if(this.hooks[key]){this.hooks[key].forEach(function(h){return h()})}if(recurse){var keys=Object.keys(this.hooks);var start=key+".";keys.forEach(function(k){if(k.startsWith(start)){this$1.hooks[k].forEach(function(h){return h()})}})}var pats=this.patternHooks;for(var i=0;i<pats.length;i++){if(pats[i][0].test(key)){pats[i][1]()}}var groups=[];for(var i$1=0;i$1<this.fns.length;i$1++){var ref=this.fns[i$1];var ks=ref[0];var gs=ref[3];if(gs&&Array.isArray(ks)&&ks.includes(key)){gs.forEach(function(g){return!groups.includes(g)&&groups.push(g)})}}for(var i$2=0;i$2<groups.length;i$2++){var hooks$1=this.groupHooks[groups[i$2]]||[];hooks$1.forEach(function(h){return h()})}};Validator.prototype.clear=function clear(key,recurse){var this$1=this;delete this.state[key];if(recurse){var keys=Object.keys(this.state);var start=key+".";keys.forEach(function(k){if(k.startsWith(start)){delete this$1.state[k]}})}this.notify(key,true,recurse)};Validator.prototype.level=function level(key,recurse){if(recurse===void 0)recurse=true;if(key&&key.group&&typeof key.group!=="function"){key=keysForGroup(this,key.group)}if(typeof key==="boolean"){recurse=key;key=/.*/}else if(key===undefined){key=/.*/}var keys=Array.isArray(key)?key:[key];var level="none";for(var i=0;i<keys.length;i++){var key$1=keys[i];if(typeof key$1==="string"){var msgs=this.state[key$1]||[];for(var j=0;j<msgs.length;j++){var t=msgs[j][0];if(t==="error"){return"error"}else if(t==="warn"){level="warn"}else if(t==="info"&&level!=="warn"){level="warn"}}}if(recurse||key$1.test){var state=this.state;var ks=Object.keys(state);var start=key$1+".";for(var j$1=0;j$1<ks.length;j$1++){var k=ks[j$1];if(key$1.test?key$1.test(k):k.startsWith(start)){var msgs$1=state[k];for(var c=0;c<msgs$1.length;c++){var t$1=msgs$1[c][0];if(t$1==="error"){return"error"}else if(t$1==="warn"){level="warn"}else if(t$1==="info"&&level!=="warn"){level="info"}}}}}}return level};Validator.prototype.messages=function messages(key,recurse){var this$1=this;if(key.group&&typeof key.group!=="function"){key=keysForGroup(this,key.group)}var keys=Array.isArray(key)?key:[key];var res=[];keys.forEach(function(key){if(typeof key==="string"){var msgs=this$1.state[key]||[];res.push.apply(res,msgs)}if(recurse||key.test){var state=this$1.state;var keys=Object.keys(state);var start=key+".";keys.forEach(function(k){if(key.test?key.test(k):k.startsWith(start)){res.push.apply(res,state[k])}})}});return res};Validator.prototype.hook=function hook(keys,fn,opts){var this$1=this;if(keys&&keys.group&&typeof keys.group!=="function"){var gs=Array.isArray(keys.group)?keys.group:[keys.group];gs.forEach(function(g){return(this$1.groupHooks[g]||(this$1.groupHooks[g]=[])).push(fn)})}else{if(typeof keys==="function"){opts=fn;fn=keys;keys=/.*/}var ks=Array.isArray(keys)?keys:[keys];ks.forEach(function(key){if(typeof key==="string"){(this$1.hooks[key]||(this$1.hooks[key]=[])).push(fn)}else if(key.test){this$1.patternHooks.push([key,fn])}})}var disposer={cancel:function(){return this$1.unhook(keys,fn,disposer)}};this.disposers.push(disposer);if(!opts||opts.lazy!==true){fn()}return disposer};Validator.prototype.unhook=function unhook(keys,fn,disposer){var this$1=this;if(disposer){dispose(this,disposer)}if(keys&&keys.group&&typeof keys.group!=="function"){var gs=Array.isArray(keys.group)?keys.group:[keys.group];gs.forEach(function(key){var arr=this$1.groupHooks[key]||[];var idx=arr.indexOf(fn);if(~idx){arr.splice(idx,1)}})}else{if(typeof keys==="function"){fn=keys;keys=/.*/}var ks=Array.isArray(keys)?keys:[keys];ks.forEach(function(key){if(typeof key==="string"){var arr=this$1.hooks[key]||[];var idx=arr.indexOf(fn);if(~idx){arr.splice(idx,1)}}else if(key.test){var idx$1=this$1.patternHooks.findIndex(function(h){return h[0].toString()===key.toString()&&h[1]===fn});if(~idx$1){this$1.patternHooks.splice(idx$1,1)}}})}};Validator.prototype.register=function register(what){this.watchers.push(what)};Validator.prototype.unregister=function unregister(what){var idx=this.watchers.indexOf(what);if(~idx){this.watchers.splice(idx,1)}};Validator.prototype.decorator=function decorator(opts){if(opts===void 0)opts={};var v=this;return function(node){var keys=[],len=arguments.length-1;while(len-- >0)keys[len]=arguments[len+1];var ctx=this.getLocalContext();var root=ctx.resolve();var ks;var keyList;function setKeys(keys){var list=keys.join(",");if(keyList===list){return false}keyList=list;if(opts.regex){ks=keys.map(function(k){return typeof k==="string"?new RegExp(k):k})}else if(opts.group){ks={group:keys}}else{ks=keys.map(function(k){return ctx.resolve(k)})}return true}setKeys(keys);var levels=opts.levels||Validator.defaults.levels;var position=node.style.position;var indicator;if(opts.indicator&&!position){node.style.position="relative"}if(opts.indicator){register();indicator=document.createElement("span");indicator.setAttribute("class","valid-indicator");node.appendChild(indicator)}var tab;if(opts.tab&&!opts.regex){var n=node.querySelector("input,select,textarea");if(n){var fn;fn=function(ev){n.removeEventListener("blur",fn);n.removeEventListener("input",fn);tab=null;if(ev.type==="blur"){v.refresh(ks);hook()}};tab=[n,fn];n.addEventListener("blur",fn);n.addEventListener("input",fn)}}function hook(){if(tab){return}var level=v.level(ks,true);syncClass(node,levels,levels[levelMap[level]]);if(opts.indicator){if(level!=="none"){indicator.setAttribute("title",messageGroupString(groupMessages(v.messages(ks,true))))}else{indicator.setAttribute("title","")}}}v.hook(ks,hook);if(!opts.tab&&!opts.regex){setTimeout(hook,v.debounce||500)}var res={update:function update(){var keys=[],len=arguments.length;while(len--)keys[len]=arguments[len];var old=ks;if(setKeys(keys)){v.unhook(old,hook);v.hook(ks,hook);hook()}},teardown:function teardown(){v.unhook(ks,hook);syncClass(node,levels);node.style.position=position;if(indicator){indicator.remove()}if(tab){tab[0].removeEventListener("blur",tab[1])}v.unregister(res)},reset:function reset(){v.hook(ks,hook);hook()}};if(opts.regex){res.update=function update(){var keys=[],len=arguments.length;while(len--)keys[len]=arguments[len];var next=ctx.resolve();v.unhook(ks,hook);ks=opts.regex?keys.map(function(k){return typeof k==="string"?new RegExp(k):k}):keys.map(function(k){return ctx.resolve(k)});v.hook(ks,hook);root=next;hook()}}else if(!opts.group){res.shuffled=function shuffled(){var next=ctx.resolve();if(next!==root){v.unhook(ks,hook);ks=opts.regex?keys.map(function(k){return typeof k==="string"?new RegExp(k):k}):keys.map(function(k){return ctx.resolve(k)});v.hook(ks,hook);root=next;hook()}}}v.register(res);return res}};Validator.defaults={levels:["","info","warn","error"]};function checker(fn,keys,values,prefix){var this$1=this;var changed=false;var notifies;var checks=this.checks.find(function(c){return c.keys===keys});if(!checks){checks={keys:keys,messages:[]};this.checks.push(checks)}var res=fn.apply(this.ractive,values)||[];if(prefix){for(var i=0;i<res.length;i++){if(!res[i][2]){continue}var ks=Array.isArray(res[i][2])?res[i][2]:[res[i][2]];res[i][2]=ks.map(function(k){return k[0]==="."?prefix+k:k})}}for(var i$1=0;i$1<checks.messages.length;i$1++){var ref=checks.messages[i$1];var t=ref[0];var m=ref[1];var k=ref[2];var go=true;for(var j=0;j<res.length;j++){var ref$1=res[j];var type=ref$1[0];var msg=ref$1[1];var key=ref$1[2];if(t===type&&m===msg&&keysStr(k)===keysStr(key)){go=false;break}}if(!go){continue}changed=true;notifies=notifies||keys.slice();var ks$1=k?Array.isArray(k)?k:[k]:keys;for(var j$1=0;j$1<ks$1.length;j$1++){var key$1=ks$1[j$1];if(!notifies.includes(key$1)){notifies.push(key$1)}var state=this.state[key$1]||[];for(var i$2=0;i$2<state.length;i$2++){if(state[i$2][0]===t&&state[i$2][1]===m){state.splice(i$2,1);break}}}}for(var i$3=0;i$3<res.length;i$3++){var ref$2=res[i$3];var t$1=ref$2[0];var m$1=ref$2[1];var k$1=ref$2[2];var go$1=true;for(var j$2=0;j$2<checks.messages.length;j$2++){var ref$3=checks.messages[j$2];var type$1=ref$3[0];var msg$1=ref$3[1];var key$2=ref$3[2];if(t$1===type$1&&m$1===msg$1&&keysStr(k$1)===keysStr(key$2)){go$1=false;break}}if(!go$1){continue}changed=true;notifies=notifies||keys.slice();var ks$2=k$1?Array.isArray(k$1)?k$1:[k$1]:keys;for(var j$3=0;j$3<ks$2.length;j$3++){var key$3=ks$2[j$3];if(!notifies.includes(key$3)){notifies.push(key$3)}(this.state[key$3]||(this.state[key$3]=[])).push([t$1,m$1])}}checks.messages=res;if(changed){notifies.forEach(function(key){return this$1.notify(key,true)})}}function debounce(time,fn,context){var tm;return function(){var args=[],len=arguments.length;while(len--)args[len]=arguments[len];if(tm){return}else{tm=setTimeout(function(){fn.apply(context,args);tm=null},time)}}}function debounceMany(time,fn,context,which){var tms={};return function(){var args=[],len=arguments.length;while(len--)args[len]=arguments[len];if(tms[args[which]]){return}else{tms[args[which]]=setTimeout(function(){fn.apply(context,args);tms[args[which]]=null},time)}}}var levelMap={none:0,info:1,warn:2,error:3};function syncClass(node,list,cls){var cl=node.classList;list.forEach(function(c){if(c&&cls!==c&&cl.contains(c)){cl.remove(c)}});if(cls&&!cl.contains(cls)){cl.add(cls)}}function keysStr(keys){if(typeof keys==="string"){return keys}if(Array.isArray(keys)){return keys.join(",")}}function keysForGroup(validator,group){var grps=Array.isArray(group)?group:[group];var res=[];for(var i=0;i<grps.length;i++){var fns=validator.fns;for(var j=0;j<fns.length;j++){var ks=fns[j][0];if(Array.isArray(ks)&&fns[j][3]&&fns[j][3].includes(grps[i])){for(var c=0;c<ks.length;c++){if(!res.includes(ks[c])){res.push(ks[c])}}}}}return res}function groupMessages(messages){var res=[];var cur=messages.filter(function(m){return m[0]==="error"});if(cur.length){res.push(["Errors",cur.map(function(m){return m[1]})])}cur=messages.filter(function(m){return m[0]==="warn"});if(cur.length){res.push(["Warnings",cur.map(function(m){return m[1]})])}cur=messages.filter(function(m){return m[0]==="info"||m[0]==="none"});if(cur.length){res.push(["Info",cur.map(function(m){return m[1]})])}return res}function messageGroupString(groups){if(groups.length===1){return groups[0][1].join("\n")}return groups.map(function(g){return g[0]+":\n"+g[1].join("\n")}).join("\n\n")}var registered=false;function register(){if(!registered){Ractive.addCSS("validation-decorator","\n span.valid-indicator {\n display: none;\n position: absolute;\n top: 0.25em;\n right: 0.5em;\n width: 1em;\n height: 1em;\n border-radius: 1em;\n z-index: 19;\n }\n span.valid-indicator:after {\n color: #fff;\n width: 100%;\n display: block;\n font-weight: bold;\n text-align: center;\n line-height: 1.1em;\n font-size: 1.1em;\n }\n .none > span.valid-indicator {\n display: flex;\n background-color: #16ab39;\n }\n .error > span.valid-indicator {\n display: flex;\n background-color: #ca3c3c;\n }\n .warn > span.valid-indicator {\n display: flex;\n background-color: #f79e0b;\n }\n .info > span.valid-indicator {\n display: flex;\n background-color: #1f5b93;\n }\n ");registered=true}}var probably="should probably";export function required(name,level){if(level===void 0)level="error";return function(v){if(!v){return[[level,name+" "+(level!=="error"?"should probably be provided":"is required")]]}}}export function lt(name,num,level){if(level===void 0)level="error";return function(v){if(v>=num){return[[level,name+" "+(level!=="error"?probably:"must")+" be at most "+(num-1)]]}}}export function lte(name,num,level){if(level===void 0)level="error";return function(v){if(v>num){return[[level,name+" "+(level!=="error"?probably:"must")+" be at most "+num]]}}}export function gt(name,num,level){if(level===void 0)level="error";return function(v){if(v<=num){return[[level,name+" "+(level!=="error"?probably:"must")+" be at least "+(num+1)]]}}}export function gte(name,num,level){if(level===void 0)level="error";return function(v){if(v<=num){return[[level,name+" "+(level!=="error"?probably:"must")+" be at least "+num]]}}}export function between(name,lower,upper,level){if(level===void 0)level="error";return function(v){if(v<lower||v>upper){return[[level,name+" "+(level!=="error"?probably:"must")+" be between "+lower+" and "+upper]]}}} |
{ | ||
"name": "@evs-chris/raui", | ||
"version": "0.15.1", | ||
"version": "0.15.2", | ||
"description": "Components, decorators, and helpers for Ractive apps that are generally Material-ish", | ||
@@ -5,0 +5,0 @@ "homepage": "https://evs-chris.github.io/raui/demo", |
@@ -324,3 +324,3 @@ import Ractive from 'ractive'; | ||
level(key, recurse = true) { | ||
if (key && key.group) key = keysForGroup(this, key.group); | ||
if (key && key.group && typeof key.group !== 'function') key = keysForGroup(this, key.group); | ||
if (typeof key === 'boolean') { | ||
@@ -372,3 +372,3 @@ recurse = key; | ||
messages(key, recurse) { | ||
if (key.group) key = keysForGroup(this, key.group); | ||
if (key.group && typeof key.group !== 'function') key = keysForGroup(this, key.group); | ||
const keys = Array.isArray(key) ? key : [key]; | ||
@@ -397,3 +397,3 @@ const res = []; | ||
hook(keys, fn, opts) { | ||
if (keys && keys.group) { | ||
if (keys && keys.group && typeof keys.group !== 'function') { | ||
const gs = Array.isArray(keys.group) ? keys.group : [keys.group]; | ||
@@ -424,3 +424,3 @@ gs.forEach(g => (this.groupHooks[g] || (this.groupHooks[g] = [])).push(fn)); | ||
if (disposer) dispose(this, disposer); | ||
if (keys && keys.group) { | ||
if (keys && keys.group && typeof keys.group !== 'function') { | ||
const gs = Array.isArray(keys.group) ? keys.group : [keys.group]; | ||
@@ -427,0 +427,0 @@ gs.forEach(key => { |
@@ -402,3 +402,3 @@ (function (global, factory) { | ||
if (key && key.group) { key = keysForGroup(this, key.group); } | ||
if (key && key.group && typeof key.group !== 'function') { key = keysForGroup(this, key.group); } | ||
if (typeof key === 'boolean') { | ||
@@ -452,3 +452,3 @@ recurse = key; | ||
if (key.group) { key = keysForGroup(this, key.group); } | ||
if (key.group && typeof key.group !== 'function') { key = keysForGroup(this, key.group); } | ||
var keys = Array.isArray(key) ? key : [key]; | ||
@@ -479,3 +479,3 @@ var res = []; | ||
if (keys && keys.group) { | ||
if (keys && keys.group && typeof keys.group !== 'function') { | ||
var gs = Array.isArray(keys.group) ? keys.group : [keys.group]; | ||
@@ -508,3 +508,3 @@ gs.forEach(function (g) { return (this$1.groupHooks[g] || (this$1.groupHooks[g] = [])).push(fn); }); | ||
if (disposer) { dispose(this, disposer); } | ||
if (keys && keys.group) { | ||
if (keys && keys.group && typeof keys.group !== 'function') { | ||
var gs = Array.isArray(keys.group) ? keys.group : [keys.group]; | ||
@@ -511,0 +511,0 @@ gs.forEach(function (key) { |
@@ -1,1 +0,1 @@ | ||
!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("ractive")):"function"==typeof define&&define.amd?define(["exports","ractive"],n):n(r.RauiValidate={},r.Ractive)}(this,function(r,n){"use strict";function t(r,n){var t=r.disposers.indexOf(n);~t&&r.disposing&&r.disposers.splice(t,1)}n=n&&n.hasOwnProperty("default")?n.default:n;var e=function(r,n){void 0===n&&(n=500),this.ractive=r,this.debounce=n,this.state={},this.hooks={},this.patternHooks=[],this.groupHooks={},this.checks=[],this.fns=[],this.many=[],this.disposers=[],this.watchers=[]};function i(r,n,t,e){var i,o=this,s=!1,a=this.checks.find(function(r){return r.keys===n});a||(a={keys:n,messages:[]},this.checks.push(a));var c=r.apply(this.ractive,t)||[];if(e)for(var f=0;f<c.length;f++)if(c[f][2]){var h=Array.isArray(c[f][2])?c[f][2]:[c[f][2]];c[f][2]=h.map(function(r){return"."===r[0]?e+r:r})}for(var p=0;p<a.messages.length;p++){for(var l=a.messages[p],v=l[0],d=l[1],y=l[2],g=!0,k=0;k<c.length;k++){var m=c[k],b=m[0],A=m[1],E=m[2];if(v===b&&d===A&&u(y)===u(E)){g=!1;break}}if(g){s=!0,i=i||n.slice();for(var x=y?Array.isArray(y)?y:[y]:n,w=0;w<x.length;w++){var j=x[w];i.includes(j)||i.push(j);for(var O=this.state[j]||[],H=0;H<O.length;H++)if(O[H][0]===v&&O[H][1]===d){O.splice(H,1);break}}}}for(var L=0;L<c.length;L++){for(var C=c[L],I=C[0],D=C[1],R=C[2],S=!0,W=0;W<a.messages.length;W++){var q=a.messages[W],z=q[0],T=q[1],K=q[2];if(I===z&&D===T&&u(R)===u(K)){S=!1;break}}if(S){s=!0,i=i||n.slice();for(var P=R?Array.isArray(R)?R:[R]:n,V=0;V<P.length;V++){var _=P[V];i.includes(_)||i.push(_),(this.state[_]||(this.state[_]=[])).push([I,D])}}}a.messages=c,s&&i.forEach(function(r){return o.notify(r,!0)})}function o(r,n,t){var e;return function(){for(var i=[],o=arguments.length;o--;)i[o]=arguments[o];e||(e=setTimeout(function(){n.apply(t,i),e=null},r))}}function s(r,n,t,e){var i={};return function(){for(var o=[],s=arguments.length;s--;)o[s]=arguments[s];i[o[e]]||(i[o[e]]=setTimeout(function(){n.apply(t,o),i[o[e]]=null},r))}}e.prototype.reset=function(){this.disposing=!0,this.disposers.slice().forEach(function(r){return r.cancel()}),this.state={},this.hooks={},this.patternHooks=[],this.groupHooks={},this.checks=[],this.fns=[],this.many=[],this.disposing=!1,this.watchers.forEach(function(r){return r.reset()})},e.prototype.check=function(r,n,e,s){var a=this,c=Array.isArray(r)?r.slice():[r],u=c.concat(Array.isArray(n)?n:"string"==typeof n?[n]:[]);"function"==typeof n&&(s=e,e=n,n=[]);var f=[c,n,e,s&&s.group&&(Array.isArray(s.group)?s.group:[s.group])];this.fns.push(f);var h=this.ractive.observe(u.join(" "),o(this.debounce,function(){var r=this;f.disposed||i.call(this,e,c,u.map(function(n){return r.ractive.get(n)}))},this),{init:!s||!1!==s.init}),p={cancel:function(){t(a,p),f.disposed=!0;var r=a.fns.indexOf(f);~r&&a.fns.splice(r,1),h.cancel()}};return this.disposers.push(p),p},e.prototype.checkList=function(r,n,e){var a=this,c={},u=0,f=function(t,e,s){if(Array.isArray(t)&&t.length!==u){if(u>t.length)for(var f=t.length;f<u;f++)c[f]&&(c[f].forEach(function(r){var n=r[0];r[1].cancel(),n.forEach(function(r){a.clear(r,!0),a.notify(r,!0,!0)});var t=a.fns.findIndex(function(r){return r[0]===n});~t&&a.fns.splice(t,1)}),delete c[f]);else for(var h=function(t){var e=r+"."+t,s=[],u={check:function(r,n,t,c){var u=(Array.isArray(r)?r.slice():[r]).map(function(r){return"."===r[0]?e+r:r}),f=u.concat((Array.isArray(n)?n:"string"==typeof n?[n]:[]).map(function(r){return"."===r[0]?e+r:r}));"function"==typeof n&&(c=t,t=n,n=[]),s.push([u,a.ractive.observe(f.join(" "),o(a.debounce,function(){var r=this;i.call(this,t,u,f.map(function(n){return r.ractive.get(n)}),e)},a),{init:!c||!1!==c.init})]),a.fns.push([u,n,t,c&&c.group&&(Array.isArray(c.group)?c.group:[c.group])]),u.prefix=e},checkList:function(r,n,t){s.push([[],a.checkList("."===r[0]?e+r:r,n,t)])},checkDefer:function(r,n,t){s.push([[],a.checkDefer("."===r[0]?e+r:r,n,t)])},checkCondition:function(r,n,t,i,o){s.push([[],a.checkCondition("."===r[0]?e+r:r,n,t,i,o)])}};n(e,u,t),c[t]=s},p=u;p<t.length;p++)h(p);u=t.length}},h=this.ractive.observe(r,s(this.debounce,f,this,2),{init:!e||!1!==e.init}),p=r.split(/\s+/),l=[p,function(){p.forEach(function(r){var n=a.ractive.get(r);if(Array.isArray(n))for(var t=0;t<n.length;t++)f(n[t])})}];this.many.push(l);var v={cancel:function(){t(a,v),Object.keys(c).forEach(function(r){c[r]&&c[r].forEach(function(r){var n=r[0];r[1].cancel();var t=a.fns.findIndex(function(r){return r[0]===n});~t&&a.fns.splice(t,1)})});for(var r=a.many.length;r--;)a.many[r][1]===f&&a.many.splice(r,1);h.cancel()}};return this.disposers.push(v),v},e.prototype.checkDefer=function(r,n,t){return this.checkCondition(r,function(r){return null!=r},n,t)},e.prototype.checkCondition=function(r,n,e,a,c){var u=this;"function"==typeof n&&(c=a,a=e,e=n,n=[]),"string"==typeof n&&(n=[n]);var f=[r].concat(n),h={},p=function(r,t,s,c){var f=!~n.indexOf(s);!f||s in h||(h[s]=void 0);for(var p=f?[s]:Object.keys(h),l=function(r){var t=p[r],s=e.apply(u.ractive,[t].concat(n).map(function(r){return u.ractive.get(r)}));if(!s&&h[t])h[t].forEach(function(r){var n=r[0];r[1].cancel(),n.forEach(function(r){u.clear(r,!0),u.notify(r,!0,!0)});var t=u.fns.findIndex(function(r){return r[0]===n});~t&&u.fns.splice(t,1)}),h[t]=void 0;else if(s&&!h[t]){var f=[],l={check:function(r,n,e,s){var a=(Array.isArray(r)?r.slice():[r]).map(function(r){return"."===r[0]?t+r:r}),c=a.concat((Array.isArray(n)?n:"string"==typeof n?[n]:[]).map(function(r){return"."===r[0]?t+r:r}));"function"==typeof n&&(s=e,e=n,n=[]),f.push([a,u.ractive.observe(c.join(" "),o(u.debounce,function(){var r=this;i.call(this,e,a,c.map(function(n){return r.ractive.get(n)}),t)},u),{init:!s||!1!==s.init})]),u.fns.push([a,n,e,s&&s.group&&(Array.isArray(s.group)?s.group:[s.group])]),a.prefix=t},checkList:function(r,n,e){f.push([[],u.checkList("."===r[0]?t+r:r,n,e)])},checkDefer:function(r,n,e){f.push([[],u.checkDefer("."===r[0]?t+r:r,n,e)])},checkCondition:function(r,n,e,i,o){f.push([[],u.checkCondition("."===r[0]?t+r:r,n,e,i,o)])}};a(t,l,c),h[t]=f}},v=0;v<p.length;v++)l(v)},l=this.ractive.observe(f.join(" "),s(this.debounce,p,this,2),{init:!c||!1!==c.init}),v=r.split(/\s+/),d=[v,function(){v.forEach(function(r){var n=u.ractive.get(r);n&&p(0,0,r)})}];this.many.push(d);var y={cancel:function(){t(u,y),Object.keys(h).forEach(function(r){h[r]&&h[r].forEach(function(r){var n=r[0];r[1].cancel();var t=u.fns.findIndex(function(r){return r[0]===n});~t&&u.fns.splice(t,1)})});for(var r=u.many.length;r--;)u.many[r][1]===p&&u.many.splice(r,1);l.cancel()}};return this.disposers.push(y),y},e.prototype.refresh=function(r,n){var t=this;void 0===n&&(n=!0);var e=Array.isArray(r)?r:[r];e.forEach(function(r){if(r.test)for(var n=0;n<t.many.length;n++){var e=t.many[n],i=e[0],o=e[1];i.find(function(n){return r.test(n)})&&o()}else for(var s=0;s<t.many.length;s++){var a=t.many[s],c=a[0],u=a[1];c.includes(r)&&u()}}),e.forEach(function(r){r.test?t.fns.forEach(function(n){var e=n[0],o=n[1],s=n[2];return e.find(function(n){return r.test(n)})&&i.call(t,s,e,e.concat(o).map(function(r){return t.ractive.get(r)}),e.prefix)}):t.fns.forEach(function(n){var e=n[0],o=n[1],s=n[2];return e.includes(r)&&i.call(t,s,e,e.concat(o).map(function(r){return t.ractive.get(r)}),e.prefix)})})},e.prototype.notify=function(r,t,e){var i=this;if(t){var o=n.splitKeypath(r);for(o.pop();o.length;){var s=n.joinKeys.apply(n,o),a=this.hooks[s];a&&a.forEach(function(r){return r()}),o.pop()}}if(this.hooks[r]&&this.hooks[r].forEach(function(r){return r()}),e){var c=r+".";Object.keys(this.hooks).forEach(function(r){r.startsWith(c)&&i.hooks[r].forEach(function(r){return r()})})}for(var u=this.patternHooks,f=0;f<u.length;f++)u[f][0].test(r)&&u[f][1]();for(var h=[],p=0;p<this.fns.length;p++){var l=this.fns[p],v=l[0],d=l[3];d&&Array.isArray(v)&&v.includes(r)&&d.forEach(function(r){return!h.includes(r)&&h.push(r)})}for(var y=0;y<h.length;y++){(this.groupHooks[h[y]]||[]).forEach(function(r){return r()})}},e.prototype.clear=function(r,n){var t=this;if(delete this.state[r],n){var e=r+".";Object.keys(this.state).forEach(function(r){r.startsWith(e)&&delete t.state[r]})}this.notify(r,!0,n)},e.prototype.level=function(r,n){void 0===n&&(n=!0),r&&r.group&&(r=f(this,r.group)),"boolean"==typeof r?(n=r,r=/.*/):void 0===r&&(r=/.*/);for(var t=Array.isArray(r)?r:[r],e="none",i=0;i<t.length;i++){var o=t[i];if("string"==typeof o)for(var s=this.state[o]||[],a=0;a<s.length;a++){var c=s[a][0];if("error"===c)return"error";"warn"===c?e="warn":"info"===c&&"warn"!==e&&(e="warn")}if(n||o.test)for(var u=this.state,h=Object.keys(u),p=o+".",l=0;l<h.length;l++){var v=h[l];if(o.test?o.test(v):v.startsWith(p))for(var d=u[v],y=0;y<d.length;y++){var g=d[y][0];if("error"===g)return"error";"warn"===g?e="warn":"info"===g&&"warn"!==e&&(e="info")}}}return e},e.prototype.messages=function(r,n){var t=this;r.group&&(r=f(this,r.group));var e=[];return(Array.isArray(r)?r:[r]).forEach(function(r){if("string"==typeof r){var i=t.state[r]||[];e.push.apply(e,i)}if(n||r.test){var o=t.state,s=Object.keys(o),a=r+".";s.forEach(function(n){(r.test?r.test(n):n.startsWith(a))&&e.push.apply(e,o[n])})}}),e},e.prototype.hook=function(r,n,t){var e=this;r&&r.group?(Array.isArray(r.group)?r.group:[r.group]).forEach(function(r){return(e.groupHooks[r]||(e.groupHooks[r]=[])).push(n)}):("function"==typeof r&&(t=n,n=r,r=/.*/),(Array.isArray(r)?r:[r]).forEach(function(r){"string"==typeof r?(e.hooks[r]||(e.hooks[r]=[])).push(n):r.test&&e.patternHooks.push([r,n])}));var i={cancel:function(){return e.unhook(r,n,i)}};return this.disposers.push(i),t&&!0===t.lazy||n(),i},e.prototype.unhook=function(r,n,e){var i=this;(e&&t(this,e),r&&r.group)?(Array.isArray(r.group)?r.group:[r.group]).forEach(function(r){var t=i.groupHooks[r]||[],e=t.indexOf(n);~e&&t.splice(e,1)}):("function"==typeof r&&(n=r,r=/.*/),(Array.isArray(r)?r:[r]).forEach(function(r){if("string"==typeof r){var t=i.hooks[r]||[],e=t.indexOf(n);~e&&t.splice(e,1)}else if(r.test){var o=i.patternHooks.findIndex(function(t){return t[0].toString()===r.toString()&&t[1]===n});~o&&i.patternHooks.splice(o,1)}}))},e.prototype.register=function(r){this.watchers.push(r)},e.prototype.unregister=function(r){var n=this.watchers.indexOf(r);~n&&this.watchers.splice(n,1)},e.prototype.decorator=function(r){void 0===r&&(r={});var t=this;return function(i){for(var o=[],s=arguments.length-1;s-- >0;)o[s]=arguments[s+1];var u,f,p=this.getLocalContext(),l=p.resolve();function v(n){var t=n.join(",");return f!==t&&(f=t,u=r.regex?n.map(function(r){return"string"==typeof r?new RegExp(r):r}):r.group?{group:n}:n.map(function(r){return p.resolve(r)}),!0)}v(o);var d,y,g=r.levels||e.defaults.levels,k=i.style.position;if(r.indicator&&!k&&(i.style.position="relative"),r.indicator&&(h||(n.addCSS("validation-decorator","\n span.valid-indicator {\n display: none;\n position: absolute;\n top: 0.25em;\n right: 0.5em;\n width: 1em;\n height: 1em;\n border-radius: 1em;\n z-index: 19;\n }\n span.valid-indicator:after {\n color: #fff;\n width: 100%;\n display: block;\n font-weight: bold;\n text-align: center;\n line-height: 1.1em;\n font-size: 1.1em;\n }\n .none > span.valid-indicator {\n display: flex;\n background-color: #16ab39;\n }\n .error > span.valid-indicator {\n display: flex;\n background-color: #ca3c3c;\n }\n .warn > span.valid-indicator {\n display: flex;\n background-color: #f79e0b;\n }\n .info > span.valid-indicator {\n display: flex;\n background-color: #1f5b93;\n }\n "),h=!0),(d=document.createElement("span")).setAttribute("class","valid-indicator"),i.appendChild(d)),r.tab&&!r.regex){var m,b=i.querySelector("input,select,textarea");if(b)m=function(r){b.removeEventListener("blur",m),b.removeEventListener("input",m),y=null,"blur"===r.type&&(t.refresh(u),A())},y=[b,m],b.addEventListener("blur",m),b.addEventListener("input",m)}function A(){if(!y){var n=t.level(u,!0);c(i,g,g[a[n]]),r.indicator&&("none"!==n?d.setAttribute("title",function(r){if(1===r.length)return r[0][1].join("\n");return r.map(function(r){return r[0]+":\n"+r[1].join("\n")}).join("\n\n")}(function(r){var n=[],t=r.filter(function(r){return"error"===r[0]});t.length&&n.push(["Errors",t.map(function(r){return r[1]})]);(t=r.filter(function(r){return"warn"===r[0]})).length&&n.push(["Warnings",t.map(function(r){return r[1]})]);(t=r.filter(function(r){return"info"===r[0]||"none"===r[0]})).length&&n.push(["Info",t.map(function(r){return r[1]})]);return n}(t.messages(u,!0)))):d.setAttribute("title",""))}}t.hook(u,A),r.tab||r.regex||setTimeout(A,t.debounce||500);var E={update:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=u;v(r)&&(t.unhook(e,A),t.hook(u,A),A())},teardown:function(){t.unhook(u,A),c(i,g),i.style.position=k,d&&d.remove(),y&&y[0].removeEventListener("blur",y[1]),t.unregister(E)},reset:function(){t.hook(u,A),A()}};return r.regex?E.update=function(){for(var n=[],e=arguments.length;e--;)n[e]=arguments[e];var i=p.resolve();t.unhook(u,A),u=r.regex?n.map(function(r){return"string"==typeof r?new RegExp(r):r}):n.map(function(r){return p.resolve(r)}),t.hook(u,A),l=i,A()}:r.group||(E.shuffled=function(){var n=p.resolve();n!==l&&(t.unhook(u,A),u=r.regex?o.map(function(r){return"string"==typeof r?new RegExp(r):r}):o.map(function(r){return p.resolve(r)}),t.hook(u,A),l=n,A())}),t.register(E),E}},e.defaults={levels:["","info","warn","error"]};var a={none:0,info:1,warn:2,error:3};function c(r,n,t){var e=r.classList;n.forEach(function(r){r&&t!==r&&e.contains(r)&&e.remove(r)}),t&&!e.contains(t)&&e.add(t)}function u(r){return"string"==typeof r?r:Array.isArray(r)?r.join(","):void 0}function f(r,n){for(var t=Array.isArray(n)?n:[n],e=[],i=0;i<t.length;i++)for(var o=r.fns,s=0;s<o.length;s++){var a=o[s][0];if(Array.isArray(a)&&o[s][3]&&o[s][3].includes(t[i]))for(var c=0;c<a.length;c++)e.includes(a[c])||e.push(a[c])}return e}var h=!1;var p="should probably";r.Validator=e,r.required=function(r,n){return void 0===n&&(n="error"),function(t){if(!t)return[[n,r+" "+("error"!==n?"should probably be provided":"is required")]]}},r.lt=function(r,n,t){return void 0===t&&(t="error"),function(e){if(e>=n)return[[t,r+" "+("error"!==t?p:"must")+" be at most "+(n-1)]]}},r.lte=function(r,n,t){return void 0===t&&(t="error"),function(e){if(e>n)return[[t,r+" "+("error"!==t?p:"must")+" be at most "+n]]}},r.gt=function(r,n,t){return void 0===t&&(t="error"),function(e){if(e<=n)return[[t,r+" "+("error"!==t?p:"must")+" be at least "+(n+1)]]}},r.gte=function(r,n,t){return void 0===t&&(t="error"),function(e){if(e<=n)return[[t,r+" "+("error"!==t?p:"must")+" be at least "+n]]}},r.between=function(r,n,t,e){return void 0===e&&(e="error"),function(i){if(i<n||i>t)return[[e,r+" "+("error"!==e?p:"must")+" be between "+n+" and "+t]]}},Object.defineProperty(r,"__esModule",{value:!0})}); | ||
!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("ractive")):"function"==typeof define&&define.amd?define(["exports","ractive"],n):n(r.RauiValidate={},r.Ractive)}(this,function(r,n){"use strict";function t(r,n){var t=r.disposers.indexOf(n);~t&&r.disposing&&r.disposers.splice(t,1)}n=n&&n.hasOwnProperty("default")?n.default:n;var e=function(r,n){void 0===n&&(n=500),this.ractive=r,this.debounce=n,this.state={},this.hooks={},this.patternHooks=[],this.groupHooks={},this.checks=[],this.fns=[],this.many=[],this.disposers=[],this.watchers=[]};function o(r,n,t,e){var o,i=this,s=!1,a=this.checks.find(function(r){return r.keys===n});a||(a={keys:n,messages:[]},this.checks.push(a));var c=r.apply(this.ractive,t)||[];if(e)for(var f=0;f<c.length;f++)if(c[f][2]){var h=Array.isArray(c[f][2])?c[f][2]:[c[f][2]];c[f][2]=h.map(function(r){return"."===r[0]?e+r:r})}for(var p=0;p<a.messages.length;p++){for(var l=a.messages[p],v=l[0],d=l[1],y=l[2],g=!0,k=0;k<c.length;k++){var m=c[k],b=m[0],A=m[1],E=m[2];if(v===b&&d===A&&u(y)===u(E)){g=!1;break}}if(g){s=!0,o=o||n.slice();for(var x=y?Array.isArray(y)?y:[y]:n,w=0;w<x.length;w++){var j=x[w];o.includes(j)||o.push(j);for(var O=this.state[j]||[],H=0;H<O.length;H++)if(O[H][0]===v&&O[H][1]===d){O.splice(H,1);break}}}}for(var L=0;L<c.length;L++){for(var C=c[L],I=C[0],D=C[1],R=C[2],S=!0,W=0;W<a.messages.length;W++){var q=a.messages[W],z=q[0],T=q[1],K=q[2];if(I===z&&D===T&&u(R)===u(K)){S=!1;break}}if(S){s=!0,o=o||n.slice();for(var P=R?Array.isArray(R)?R:[R]:n,V=0;V<P.length;V++){var _=P[V];o.includes(_)||o.push(_),(this.state[_]||(this.state[_]=[])).push([I,D])}}}a.messages=c,s&&o.forEach(function(r){return i.notify(r,!0)})}function i(r,n,t){var e;return function(){for(var o=[],i=arguments.length;i--;)o[i]=arguments[i];e||(e=setTimeout(function(){n.apply(t,o),e=null},r))}}function s(r,n,t,e){var o={};return function(){for(var i=[],s=arguments.length;s--;)i[s]=arguments[s];o[i[e]]||(o[i[e]]=setTimeout(function(){n.apply(t,i),o[i[e]]=null},r))}}e.prototype.reset=function(){this.disposing=!0,this.disposers.slice().forEach(function(r){return r.cancel()}),this.state={},this.hooks={},this.patternHooks=[],this.groupHooks={},this.checks=[],this.fns=[],this.many=[],this.disposing=!1,this.watchers.forEach(function(r){return r.reset()})},e.prototype.check=function(r,n,e,s){var a=this,c=Array.isArray(r)?r.slice():[r],u=c.concat(Array.isArray(n)?n:"string"==typeof n?[n]:[]);"function"==typeof n&&(s=e,e=n,n=[]);var f=[c,n,e,s&&s.group&&(Array.isArray(s.group)?s.group:[s.group])];this.fns.push(f);var h=this.ractive.observe(u.join(" "),i(this.debounce,function(){var r=this;f.disposed||o.call(this,e,c,u.map(function(n){return r.ractive.get(n)}))},this),{init:!s||!1!==s.init}),p={cancel:function(){t(a,p),f.disposed=!0;var r=a.fns.indexOf(f);~r&&a.fns.splice(r,1),h.cancel()}};return this.disposers.push(p),p},e.prototype.checkList=function(r,n,e){var a=this,c={},u=0,f=function(t,e,s){if(Array.isArray(t)&&t.length!==u){if(u>t.length)for(var f=t.length;f<u;f++)c[f]&&(c[f].forEach(function(r){var n=r[0];r[1].cancel(),n.forEach(function(r){a.clear(r,!0),a.notify(r,!0,!0)});var t=a.fns.findIndex(function(r){return r[0]===n});~t&&a.fns.splice(t,1)}),delete c[f]);else for(var h=function(t){var e=r+"."+t,s=[],u={check:function(r,n,t,c){var u=(Array.isArray(r)?r.slice():[r]).map(function(r){return"."===r[0]?e+r:r}),f=u.concat((Array.isArray(n)?n:"string"==typeof n?[n]:[]).map(function(r){return"."===r[0]?e+r:r}));"function"==typeof n&&(c=t,t=n,n=[]),s.push([u,a.ractive.observe(f.join(" "),i(a.debounce,function(){var r=this;o.call(this,t,u,f.map(function(n){return r.ractive.get(n)}),e)},a),{init:!c||!1!==c.init})]),a.fns.push([u,n,t,c&&c.group&&(Array.isArray(c.group)?c.group:[c.group])]),u.prefix=e},checkList:function(r,n,t){s.push([[],a.checkList("."===r[0]?e+r:r,n,t)])},checkDefer:function(r,n,t){s.push([[],a.checkDefer("."===r[0]?e+r:r,n,t)])},checkCondition:function(r,n,t,o,i){s.push([[],a.checkCondition("."===r[0]?e+r:r,n,t,o,i)])}};n(e,u,t),c[t]=s},p=u;p<t.length;p++)h(p);u=t.length}},h=this.ractive.observe(r,s(this.debounce,f,this,2),{init:!e||!1!==e.init}),p=r.split(/\s+/),l=[p,function(){p.forEach(function(r){var n=a.ractive.get(r);if(Array.isArray(n))for(var t=0;t<n.length;t++)f(n[t])})}];this.many.push(l);var v={cancel:function(){t(a,v),Object.keys(c).forEach(function(r){c[r]&&c[r].forEach(function(r){var n=r[0];r[1].cancel();var t=a.fns.findIndex(function(r){return r[0]===n});~t&&a.fns.splice(t,1)})});for(var r=a.many.length;r--;)a.many[r][1]===f&&a.many.splice(r,1);h.cancel()}};return this.disposers.push(v),v},e.prototype.checkDefer=function(r,n,t){return this.checkCondition(r,function(r){return null!=r},n,t)},e.prototype.checkCondition=function(r,n,e,a,c){var u=this;"function"==typeof n&&(c=a,a=e,e=n,n=[]),"string"==typeof n&&(n=[n]);var f=[r].concat(n),h={},p=function(r,t,s,c){var f=!~n.indexOf(s);!f||s in h||(h[s]=void 0);for(var p=f?[s]:Object.keys(h),l=function(r){var t=p[r],s=e.apply(u.ractive,[t].concat(n).map(function(r){return u.ractive.get(r)}));if(!s&&h[t])h[t].forEach(function(r){var n=r[0];r[1].cancel(),n.forEach(function(r){u.clear(r,!0),u.notify(r,!0,!0)});var t=u.fns.findIndex(function(r){return r[0]===n});~t&&u.fns.splice(t,1)}),h[t]=void 0;else if(s&&!h[t]){var f=[],l={check:function(r,n,e,s){var a=(Array.isArray(r)?r.slice():[r]).map(function(r){return"."===r[0]?t+r:r}),c=a.concat((Array.isArray(n)?n:"string"==typeof n?[n]:[]).map(function(r){return"."===r[0]?t+r:r}));"function"==typeof n&&(s=e,e=n,n=[]),f.push([a,u.ractive.observe(c.join(" "),i(u.debounce,function(){var r=this;o.call(this,e,a,c.map(function(n){return r.ractive.get(n)}),t)},u),{init:!s||!1!==s.init})]),u.fns.push([a,n,e,s&&s.group&&(Array.isArray(s.group)?s.group:[s.group])]),a.prefix=t},checkList:function(r,n,e){f.push([[],u.checkList("."===r[0]?t+r:r,n,e)])},checkDefer:function(r,n,e){f.push([[],u.checkDefer("."===r[0]?t+r:r,n,e)])},checkCondition:function(r,n,e,o,i){f.push([[],u.checkCondition("."===r[0]?t+r:r,n,e,o,i)])}};a(t,l,c),h[t]=f}},v=0;v<p.length;v++)l(v)},l=this.ractive.observe(f.join(" "),s(this.debounce,p,this,2),{init:!c||!1!==c.init}),v=r.split(/\s+/),d=[v,function(){v.forEach(function(r){var n=u.ractive.get(r);n&&p(0,0,r)})}];this.many.push(d);var y={cancel:function(){t(u,y),Object.keys(h).forEach(function(r){h[r]&&h[r].forEach(function(r){var n=r[0];r[1].cancel();var t=u.fns.findIndex(function(r){return r[0]===n});~t&&u.fns.splice(t,1)})});for(var r=u.many.length;r--;)u.many[r][1]===p&&u.many.splice(r,1);l.cancel()}};return this.disposers.push(y),y},e.prototype.refresh=function(r,n){var t=this;void 0===n&&(n=!0);var e=Array.isArray(r)?r:[r];e.forEach(function(r){if(r.test)for(var n=0;n<t.many.length;n++){var e=t.many[n],o=e[0],i=e[1];o.find(function(n){return r.test(n)})&&i()}else for(var s=0;s<t.many.length;s++){var a=t.many[s],c=a[0],u=a[1];c.includes(r)&&u()}}),e.forEach(function(r){r.test?t.fns.forEach(function(n){var e=n[0],i=n[1],s=n[2];return e.find(function(n){return r.test(n)})&&o.call(t,s,e,e.concat(i).map(function(r){return t.ractive.get(r)}),e.prefix)}):t.fns.forEach(function(n){var e=n[0],i=n[1],s=n[2];return e.includes(r)&&o.call(t,s,e,e.concat(i).map(function(r){return t.ractive.get(r)}),e.prefix)})})},e.prototype.notify=function(r,t,e){var o=this;if(t){var i=n.splitKeypath(r);for(i.pop();i.length;){var s=n.joinKeys.apply(n,i),a=this.hooks[s];a&&a.forEach(function(r){return r()}),i.pop()}}if(this.hooks[r]&&this.hooks[r].forEach(function(r){return r()}),e){var c=r+".";Object.keys(this.hooks).forEach(function(r){r.startsWith(c)&&o.hooks[r].forEach(function(r){return r()})})}for(var u=this.patternHooks,f=0;f<u.length;f++)u[f][0].test(r)&&u[f][1]();for(var h=[],p=0;p<this.fns.length;p++){var l=this.fns[p],v=l[0],d=l[3];d&&Array.isArray(v)&&v.includes(r)&&d.forEach(function(r){return!h.includes(r)&&h.push(r)})}for(var y=0;y<h.length;y++){(this.groupHooks[h[y]]||[]).forEach(function(r){return r()})}},e.prototype.clear=function(r,n){var t=this;if(delete this.state[r],n){var e=r+".";Object.keys(this.state).forEach(function(r){r.startsWith(e)&&delete t.state[r]})}this.notify(r,!0,n)},e.prototype.level=function(r,n){void 0===n&&(n=!0),r&&r.group&&"function"!=typeof r.group&&(r=f(this,r.group)),"boolean"==typeof r?(n=r,r=/.*/):void 0===r&&(r=/.*/);for(var t=Array.isArray(r)?r:[r],e="none",o=0;o<t.length;o++){var i=t[o];if("string"==typeof i)for(var s=this.state[i]||[],a=0;a<s.length;a++){var c=s[a][0];if("error"===c)return"error";"warn"===c?e="warn":"info"===c&&"warn"!==e&&(e="warn")}if(n||i.test)for(var u=this.state,h=Object.keys(u),p=i+".",l=0;l<h.length;l++){var v=h[l];if(i.test?i.test(v):v.startsWith(p))for(var d=u[v],y=0;y<d.length;y++){var g=d[y][0];if("error"===g)return"error";"warn"===g?e="warn":"info"===g&&"warn"!==e&&(e="info")}}}return e},e.prototype.messages=function(r,n){var t=this;r.group&&"function"!=typeof r.group&&(r=f(this,r.group));var e=[];return(Array.isArray(r)?r:[r]).forEach(function(r){if("string"==typeof r){var o=t.state[r]||[];e.push.apply(e,o)}if(n||r.test){var i=t.state,s=Object.keys(i),a=r+".";s.forEach(function(n){(r.test?r.test(n):n.startsWith(a))&&e.push.apply(e,i[n])})}}),e},e.prototype.hook=function(r,n,t){var e=this;r&&r.group&&"function"!=typeof r.group?(Array.isArray(r.group)?r.group:[r.group]).forEach(function(r){return(e.groupHooks[r]||(e.groupHooks[r]=[])).push(n)}):("function"==typeof r&&(t=n,n=r,r=/.*/),(Array.isArray(r)?r:[r]).forEach(function(r){"string"==typeof r?(e.hooks[r]||(e.hooks[r]=[])).push(n):r.test&&e.patternHooks.push([r,n])}));var o={cancel:function(){return e.unhook(r,n,o)}};return this.disposers.push(o),t&&!0===t.lazy||n(),o},e.prototype.unhook=function(r,n,e){var o=this;(e&&t(this,e),r&&r.group&&"function"!=typeof r.group)?(Array.isArray(r.group)?r.group:[r.group]).forEach(function(r){var t=o.groupHooks[r]||[],e=t.indexOf(n);~e&&t.splice(e,1)}):("function"==typeof r&&(n=r,r=/.*/),(Array.isArray(r)?r:[r]).forEach(function(r){if("string"==typeof r){var t=o.hooks[r]||[],e=t.indexOf(n);~e&&t.splice(e,1)}else if(r.test){var i=o.patternHooks.findIndex(function(t){return t[0].toString()===r.toString()&&t[1]===n});~i&&o.patternHooks.splice(i,1)}}))},e.prototype.register=function(r){this.watchers.push(r)},e.prototype.unregister=function(r){var n=this.watchers.indexOf(r);~n&&this.watchers.splice(n,1)},e.prototype.decorator=function(r){void 0===r&&(r={});var t=this;return function(o){for(var i=[],s=arguments.length-1;s-- >0;)i[s]=arguments[s+1];var u,f,p=this.getLocalContext(),l=p.resolve();function v(n){var t=n.join(",");return f!==t&&(f=t,u=r.regex?n.map(function(r){return"string"==typeof r?new RegExp(r):r}):r.group?{group:n}:n.map(function(r){return p.resolve(r)}),!0)}v(i);var d,y,g=r.levels||e.defaults.levels,k=o.style.position;if(r.indicator&&!k&&(o.style.position="relative"),r.indicator&&(h||(n.addCSS("validation-decorator","\n span.valid-indicator {\n display: none;\n position: absolute;\n top: 0.25em;\n right: 0.5em;\n width: 1em;\n height: 1em;\n border-radius: 1em;\n z-index: 19;\n }\n span.valid-indicator:after {\n color: #fff;\n width: 100%;\n display: block;\n font-weight: bold;\n text-align: center;\n line-height: 1.1em;\n font-size: 1.1em;\n }\n .none > span.valid-indicator {\n display: flex;\n background-color: #16ab39;\n }\n .error > span.valid-indicator {\n display: flex;\n background-color: #ca3c3c;\n }\n .warn > span.valid-indicator {\n display: flex;\n background-color: #f79e0b;\n }\n .info > span.valid-indicator {\n display: flex;\n background-color: #1f5b93;\n }\n "),h=!0),(d=document.createElement("span")).setAttribute("class","valid-indicator"),o.appendChild(d)),r.tab&&!r.regex){var m,b=o.querySelector("input,select,textarea");if(b)m=function(r){b.removeEventListener("blur",m),b.removeEventListener("input",m),y=null,"blur"===r.type&&(t.refresh(u),A())},y=[b,m],b.addEventListener("blur",m),b.addEventListener("input",m)}function A(){if(!y){var n=t.level(u,!0);c(o,g,g[a[n]]),r.indicator&&("none"!==n?d.setAttribute("title",function(r){if(1===r.length)return r[0][1].join("\n");return r.map(function(r){return r[0]+":\n"+r[1].join("\n")}).join("\n\n")}(function(r){var n=[],t=r.filter(function(r){return"error"===r[0]});t.length&&n.push(["Errors",t.map(function(r){return r[1]})]);(t=r.filter(function(r){return"warn"===r[0]})).length&&n.push(["Warnings",t.map(function(r){return r[1]})]);(t=r.filter(function(r){return"info"===r[0]||"none"===r[0]})).length&&n.push(["Info",t.map(function(r){return r[1]})]);return n}(t.messages(u,!0)))):d.setAttribute("title",""))}}t.hook(u,A),r.tab||r.regex||setTimeout(A,t.debounce||500);var E={update:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=u;v(r)&&(t.unhook(e,A),t.hook(u,A),A())},teardown:function(){t.unhook(u,A),c(o,g),o.style.position=k,d&&d.remove(),y&&y[0].removeEventListener("blur",y[1]),t.unregister(E)},reset:function(){t.hook(u,A),A()}};return r.regex?E.update=function(){for(var n=[],e=arguments.length;e--;)n[e]=arguments[e];var o=p.resolve();t.unhook(u,A),u=r.regex?n.map(function(r){return"string"==typeof r?new RegExp(r):r}):n.map(function(r){return p.resolve(r)}),t.hook(u,A),l=o,A()}:r.group||(E.shuffled=function(){var n=p.resolve();n!==l&&(t.unhook(u,A),u=r.regex?i.map(function(r){return"string"==typeof r?new RegExp(r):r}):i.map(function(r){return p.resolve(r)}),t.hook(u,A),l=n,A())}),t.register(E),E}},e.defaults={levels:["","info","warn","error"]};var a={none:0,info:1,warn:2,error:3};function c(r,n,t){var e=r.classList;n.forEach(function(r){r&&t!==r&&e.contains(r)&&e.remove(r)}),t&&!e.contains(t)&&e.add(t)}function u(r){return"string"==typeof r?r:Array.isArray(r)?r.join(","):void 0}function f(r,n){for(var t=Array.isArray(n)?n:[n],e=[],o=0;o<t.length;o++)for(var i=r.fns,s=0;s<i.length;s++){var a=i[s][0];if(Array.isArray(a)&&i[s][3]&&i[s][3].includes(t[o]))for(var c=0;c<a.length;c++)e.includes(a[c])||e.push(a[c])}return e}var h=!1;var p="should probably";r.Validator=e,r.required=function(r,n){return void 0===n&&(n="error"),function(t){if(!t)return[[n,r+" "+("error"!==n?"should probably be provided":"is required")]]}},r.lt=function(r,n,t){return void 0===t&&(t="error"),function(e){if(e>=n)return[[t,r+" "+("error"!==t?p:"must")+" be at most "+(n-1)]]}},r.lte=function(r,n,t){return void 0===t&&(t="error"),function(e){if(e>n)return[[t,r+" "+("error"!==t?p:"must")+" be at most "+n]]}},r.gt=function(r,n,t){return void 0===t&&(t="error"),function(e){if(e<=n)return[[t,r+" "+("error"!==t?p:"must")+" be at least "+(n+1)]]}},r.gte=function(r,n,t){return void 0===t&&(t="error"),function(e){if(e<=n)return[[t,r+" "+("error"!==t?p:"must")+" be at least "+n]]}},r.between=function(r,n,t,e){return void 0===e&&(e="error"),function(o){if(o<n||o>t)return[[e,r+" "+("error"!==e?p:"must")+" be between "+n+" and "+t]]}},Object.defineProperty(r,"__esModule",{value:!0})}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2979923