@keysdown/form-wrapper 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/form-wrapper.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var m=Object.defineProperty;var F=(s,t,e)=>t in s?m(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var a=(s,t,e)=>F(s,typeof t!="symbol"?t+"":t,e);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=s=>typeof s=="string"?s.split("|"):s,b=s=>{var t,e;return{validation:{rules:(t=s.validation)!=null&&t.rules?p(s.validation.rules):[],messages:((e=s.validation)==null?void 0:e.messages)||{}},value:s.value||null}};class u{constructor(){a(this,"collection",{})}all(){return this.collection}first(t){const e=this.get(t);if(e){const r=Array.isArray(e)?e[0]:e;return String(r)}return null}any(){return Object.keys(this.collection).length>0}fill(t){return this.collection=t,this}push(t,e){return this.collection={...this.collection,[t]:e},this}has(t){return this.collection.hasOwnProperty(t)}get(t,e=null){return this.has(t)?this.collection[t]:e}unset(t){return this.has(t)&&delete this.collection[t],this}clear(){return this.collection={},this}}class j extends u{}class
|
|
1
|
+
"use strict";var m=Object.defineProperty;var F=(s,t,e)=>t in s?m(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var a=(s,t,e)=>F(s,typeof t!="symbol"?t+"":t,e);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=s=>typeof s=="string"?s.split("|"):s,b=s=>{var t,e;return{validation:{rules:(t=s.validation)!=null&&t.rules?p(s.validation.rules):[],messages:((e=s.validation)==null?void 0:e.messages)||{}},value:s.value||null}};class u{constructor(){a(this,"collection",{})}all(){return this.collection}first(t){const e=this.get(t);if(e){const r=Array.isArray(e)?e[0]:e;if(r)return String(r)}return null}any(){return Object.keys(this.collection).length>0}fill(t){return this.collection=t,this}push(t,e){return this.collection={...this.collection,[t]:e},this}has(t){return this.collection.hasOwnProperty(t)}get(t,e=null){return this.has(t)?this.collection[t]:e}unset(t){return this.has(t)&&delete this.collection[t],this}clear(){return this.collection={},this}}class j extends u{}class f extends u{}class y extends u{push(t,e){const r=this.get(t)||[];return this.collection={...this.collection,[t]:[...r,e]},this}get(t){return super.get(t,[])}}class w{constructor(){a(this,"errors",new y);a(this,"messages",new j);a(this,"rules",new f)}}const O=s=>new Promise((t,e)=>{s==null&&e(),String(s).replace(/\s/g,"").length>0?t(s):e()}),c={required:O},P=s=>s!==null&&typeof s=="object"&&!Array.isArray(s),h=(s,t,e=null)=>{const r=t||new FormData;return Object.keys(s).forEach(i=>{const n=s[i];if(i=e?`${e}[${i}]`:i,!([void 0,null].indexOf(n)>-1)){if(P(n)&&!(n instanceof File)||Array.isArray(n)){h(n,r,i);return}r.append(i,n)}}),r};class d{constructor(t){a(this,"awaiting",!1);a(this,"originalValues",{});a(this,"validation",new w);this.addFields(t)}addField(t,e){if(e!==null&&typeof e=="object"&&"value"in e){const r=b(e);this[t]=r.value,this.originalValues[t]=r.value,this.validation.messages.push(t,r.validation.messages),this.validation.rules.push(t,r.validation.rules)}else this[t]=e,this.originalValues[t]=e;return this}addFields(t){return Object.keys(t).forEach(e=>{this.addField(e,t[e])}),this}get errors(){return this.validation.errors}fill(t,e=!1){return Object.keys(t).forEach(r=>{let i=t[r];e&&(this.originalValues[r]=i),this[r]=i}),this}get messages(){return this.validation.messages}removeField(t){return delete this[t],delete this.originalValues[t],this.validation.messages.unset(t),this.validation.rules.unset(t),this}removeFields(t){return t.forEach(e=>{this.removeField(e)}),this}reset(){return this.validation.errors.clear(),Object.keys(this.originalValues).forEach(t=>{this[t]=this.originalValues[t]}),this}get rules(){return this.validation.rules}setAwaiting(t=!0){return this.awaiting=t,this}validate(t=null){return t?this.validateField(t):this.validateForm()}validateField(t){this.validation.errors.unset(t);const e=this.validation.rules.get(t);if(e&&e.length>0){const r=e.map(i=>{const n=i.split(":"),l=n[0],g=n.length===2?n[1].split(","):[];return l in c?c[l](this[t],g).catch(v=>{const o=this.validation.messages.get(t);return o&&l in o&&this.validation.errors.push(t,o[l]),Promise.reject(v)}):Promise.reject(new Error(`There is no validation rule called "${i}"`))});return Promise.all(r).then(()=>{})}return Promise.resolve()}validateForm(){const t=Object.keys(this.originalValues).map(e=>this.validateField(e));return Promise.all(t).then(()=>Promise.resolve(this)).catch(()=>Promise.reject(this))}values(){const t={};return Object.keys(this.originalValues).forEach(e=>{t[e]=this[e]}),t}valuesAsFormData(){return h(this.values())}}const V=s=>new d(s);exports.createForm=V;exports.default=d;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var FormWrapper=function(n){"use strict";var P=Object.defineProperty;var V=(n,l,u)=>l in n?P(n,l,{enumerable:!0,configurable:!0,writable:!0,value:u}):n[l]=u;var o=(n,l,u)=>V(n,typeof l!="symbol"?l+"":l,u);const l=s=>typeof s=="string"?s.split("|"):s,u=s=>{var t,e;return{validation:{rules:(t=s.validation)!=null&&t.rules?l(s.validation.rules):[],messages:((e=s.validation)==null?void 0:e.messages)||{}},value:s.value||null}};class h{constructor(){o(this,"collection",{})}all(){return this.collection}first(t){const e=this.get(t);if(e){const r=Array.isArray(e)?e[0]:e;return String(r)}return null}any(){return Object.keys(this.collection).length>0}fill(t){return this.collection=t,this}push(t,e){return this.collection={...this.collection,[t]:e},this}has(t){return this.collection.hasOwnProperty(t)}get(t,e=null){return this.has(t)?this.collection[t]:e}unset(t){return this.has(t)&&delete this.collection[t],this}clear(){return this.collection={},this}}class F extends h{}class p extends h{}class b extends h{push(t,e){const r=this.get(t)||[];return this.collection={...this.collection,[t]:[...r,e]},this}get(t){return super.get(t,[])}}class
|
|
1
|
+
var FormWrapper=function(n){"use strict";var P=Object.defineProperty;var V=(n,l,u)=>l in n?P(n,l,{enumerable:!0,configurable:!0,writable:!0,value:u}):n[l]=u;var o=(n,l,u)=>V(n,typeof l!="symbol"?l+"":l,u);const l=s=>typeof s=="string"?s.split("|"):s,u=s=>{var t,e;return{validation:{rules:(t=s.validation)!=null&&t.rules?l(s.validation.rules):[],messages:((e=s.validation)==null?void 0:e.messages)||{}},value:s.value||null}};class h{constructor(){o(this,"collection",{})}all(){return this.collection}first(t){const e=this.get(t);if(e){const r=Array.isArray(e)?e[0]:e;if(r)return String(r)}return null}any(){return Object.keys(this.collection).length>0}fill(t){return this.collection=t,this}push(t,e){return this.collection={...this.collection,[t]:e},this}has(t){return this.collection.hasOwnProperty(t)}get(t,e=null){return this.has(t)?this.collection[t]:e}unset(t){return this.has(t)&&delete this.collection[t],this}clear(){return this.collection={},this}}class F extends h{}class p extends h{}class b extends h{push(t,e){const r=this.get(t)||[];return this.collection={...this.collection,[t]:[...r,e]},this}get(t){return super.get(t,[])}}class f{constructor(){o(this,"errors",new b);o(this,"messages",new F);o(this,"rules",new p)}}const g={required:s=>new Promise((t,e)=>{s==null&&e(),String(s).replace(/\s/g,"").length>0?t(s):e()})},j=s=>s!==null&&typeof s=="object"&&!Array.isArray(s),v=(s,t,e=null)=>{const r=t||new FormData;return Object.keys(s).forEach(i=>{const a=s[i];if(i=e?`${e}[${i}]`:i,!([void 0,null].indexOf(a)>-1)){if(j(a)&&!(a instanceof File)||Array.isArray(a)){v(a,r,i);return}r.append(i,a)}}),r};class m{constructor(t){o(this,"awaiting",!1);o(this,"originalValues",{});o(this,"validation",new f);this.addFields(t)}addField(t,e){if(e!==null&&typeof e=="object"&&"value"in e){const r=u(e);this[t]=r.value,this.originalValues[t]=r.value,this.validation.messages.push(t,r.validation.messages),this.validation.rules.push(t,r.validation.rules)}else this[t]=e,this.originalValues[t]=e;return this}addFields(t){return Object.keys(t).forEach(e=>{this.addField(e,t[e])}),this}get errors(){return this.validation.errors}fill(t,e=!1){return Object.keys(t).forEach(r=>{let i=t[r];e&&(this.originalValues[r]=i),this[r]=i}),this}get messages(){return this.validation.messages}removeField(t){return delete this[t],delete this.originalValues[t],this.validation.messages.unset(t),this.validation.rules.unset(t),this}removeFields(t){return t.forEach(e=>{this.removeField(e)}),this}reset(){return this.validation.errors.clear(),Object.keys(this.originalValues).forEach(t=>{this[t]=this.originalValues[t]}),this}get rules(){return this.validation.rules}setAwaiting(t=!0){return this.awaiting=t,this}validate(t=null){return t?this.validateField(t):this.validateForm()}validateField(t){this.validation.errors.unset(t);const e=this.validation.rules.get(t);if(e&&e.length>0){const r=e.map(i=>{const a=i.split(":"),c=a[0],w=a.length===2?a[1].split(","):[];return c in g?g[c](this[t],w).catch(O=>{const d=this.validation.messages.get(t);return d&&c in d&&this.validation.errors.push(t,d[c]),Promise.reject(O)}):Promise.reject(new Error(`There is no validation rule called "${i}"`))});return Promise.all(r).then(()=>{})}return Promise.resolve()}validateForm(){const t=Object.keys(this.originalValues).map(e=>this.validateField(e));return Promise.all(t).then(()=>Promise.resolve(this)).catch(()=>Promise.reject(this))}values(){const t={};return Object.keys(this.originalValues).forEach(e=>{t[e]=this[e]}),t}valuesAsFormData(){return v(this.values())}}const y=s=>new m(s);return n.createForm=y,n.default=m,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),n}({});
|
package/dist/form-wrapper.js
CHANGED
|
@@ -22,7 +22,8 @@ class h {
|
|
|
22
22
|
const s = this.get(t);
|
|
23
23
|
if (s) {
|
|
24
24
|
const r = Array.isArray(s) ? s[0] : s;
|
|
25
|
-
|
|
25
|
+
if (r)
|
|
26
|
+
return String(r);
|
|
26
27
|
}
|
|
27
28
|
return null;
|
|
28
29
|
}
|
|
@@ -55,7 +56,7 @@ class j extends h {
|
|
|
55
56
|
}
|
|
56
57
|
class b extends h {
|
|
57
58
|
}
|
|
58
|
-
class
|
|
59
|
+
class f extends h {
|
|
59
60
|
push(t, s) {
|
|
60
61
|
const r = this.get(t) || [];
|
|
61
62
|
return this.collection = {
|
|
@@ -67,17 +68,17 @@ class w extends h {
|
|
|
67
68
|
return super.get(t, []);
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
|
-
class
|
|
71
|
+
class w {
|
|
71
72
|
constructor() {
|
|
72
|
-
a(this, "errors", new
|
|
73
|
+
a(this, "errors", new f());
|
|
73
74
|
a(this, "messages", new j());
|
|
74
75
|
a(this, "rules", new b());
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
|
-
const
|
|
78
|
+
const y = (e) => new Promise((t, s) => {
|
|
78
79
|
e == null && s(), String(e).replace(/\s/g, "").length > 0 ? t(e) : s();
|
|
79
80
|
}), c = {
|
|
80
|
-
required:
|
|
81
|
+
required: y
|
|
81
82
|
}, V = (e) => e !== null && typeof e == "object" && !Array.isArray(e), u = (e, t, s = null) => {
|
|
82
83
|
const r = t || new FormData();
|
|
83
84
|
return Object.keys(e).forEach((i) => {
|
|
@@ -95,7 +96,7 @@ class O {
|
|
|
95
96
|
constructor(t) {
|
|
96
97
|
a(this, "awaiting", !1);
|
|
97
98
|
a(this, "originalValues", {});
|
|
98
|
-
a(this, "validation", new
|
|
99
|
+
a(this, "validation", new w());
|
|
99
100
|
this.addFields(t);
|
|
100
101
|
}
|
|
101
102
|
addField(t, s) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(r,n){typeof exports=="object"&&typeof module<"u"?n(exports):typeof define=="function"&&define.amd?define(["exports"],n):(r=typeof globalThis<"u"?globalThis:r||self,n(r.FormWrapper={}))})(this,function(r){"use strict";var P=Object.defineProperty;var V=(r,n,u)=>n in r?P(r,n,{enumerable:!0,configurable:!0,writable:!0,value:u}):r[n]=u;var o=(r,n,u)=>V(r,typeof n!="symbol"?n+"":n,u);const n=s=>typeof s=="string"?s.split("|"):s,u=s=>{var t,e;return{validation:{rules:(t=s.validation)!=null&&t.rules?n(s.validation.rules):[],messages:((e=s.validation)==null?void 0:e.messages)||{}},value:s.value||null}};class c{constructor(){o(this,"collection",{})}all(){return this.collection}first(t){const e=this.get(t);if(e){const i=Array.isArray(e)?e[0]:e;return String(i)}return null}any(){return Object.keys(this.collection).length>0}fill(t){return this.collection=t,this}push(t,e){return this.collection={...this.collection,[t]:e},this}has(t){return this.collection.hasOwnProperty(t)}get(t,e=null){return this.has(t)?this.collection[t]:e}unset(t){return this.has(t)&&delete this.collection[t],this}clear(){return this.collection={},this}}class p extends c{}class f extends c{}class F extends c{push(t,e){const i=this.get(t)||[];return this.collection={...this.collection,[t]:[...i,e]},this}get(t){return super.get(t,[])}}class b{constructor(){o(this,"errors",new F);o(this,"messages",new p);o(this,"rules",new f)}}const g={required:s=>new Promise((t,e)=>{s==null&&e(),String(s).replace(/\s/g,"").length>0?t(s):e()})},j=s=>s!==null&&typeof s=="object"&&!Array.isArray(s),v=(s,t,e=null)=>{const i=t||new FormData;return Object.keys(s).forEach(a=>{const l=s[a];if(a=e?`${e}[${a}]`:a,!([void 0,null].indexOf(l)>-1)){if(j(l)&&!(l instanceof File)||Array.isArray(l)){v(l,i,a);return}i.append(a,l)}}),i};class m{constructor(t){o(this,"awaiting",!1);o(this,"originalValues",{});o(this,"validation",new b);this.addFields(t)}addField(t,e){if(e!==null&&typeof e=="object"&&"value"in e){const i=u(e);this[t]=i.value,this.originalValues[t]=i.value,this.validation.messages.push(t,i.validation.messages),this.validation.rules.push(t,i.validation.rules)}else this[t]=e,this.originalValues[t]=e;return this}addFields(t){return Object.keys(t).forEach(e=>{this.addField(e,t[e])}),this}get errors(){return this.validation.errors}fill(t,e=!1){return Object.keys(t).forEach(i=>{let a=t[i];e&&(this.originalValues[i]=a),this[i]=a}),this}get messages(){return this.validation.messages}removeField(t){return delete this[t],delete this.originalValues[t],this.validation.messages.unset(t),this.validation.rules.unset(t),this}removeFields(t){return t.forEach(e=>{this.removeField(e)}),this}reset(){return this.validation.errors.clear(),Object.keys(this.originalValues).forEach(t=>{this[t]=this.originalValues[t]}),this}get rules(){return this.validation.rules}setAwaiting(t=!0){return this.awaiting=t,this}validate(t=null){return t?this.validateField(t):this.validateForm()}validateField(t){this.validation.errors.unset(t);const e=this.validation.rules.get(t);if(e&&e.length>0){const i=e.map(a=>{const l=a.split(":"),h=l[0],w=l.length===2?l[1].split(","):[];return h in g?g[h](this[t],w).catch(O=>{const d=this.validation.messages.get(t);return d&&h in d&&this.validation.errors.push(t,d[h]),Promise.reject(O)}):Promise.reject(new Error(`There is no validation rule called "${a}"`))});return Promise.all(i).then(()=>{})}return Promise.resolve()}validateForm(){const t=Object.keys(this.originalValues).map(e=>this.validateField(e));return Promise.all(t).then(()=>Promise.resolve(this)).catch(()=>Promise.reject(this))}values(){const t={};return Object.keys(this.originalValues).forEach(e=>{t[e]=this[e]}),t}valuesAsFormData(){return v(this.values())}}const y=s=>new m(s);r.createForm=y,r.default=m,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
1
|
+
(function(r,n){typeof exports=="object"&&typeof module<"u"?n(exports):typeof define=="function"&&define.amd?define(["exports"],n):(r=typeof globalThis<"u"?globalThis:r||self,n(r.FormWrapper={}))})(this,function(r){"use strict";var P=Object.defineProperty;var V=(r,n,u)=>n in r?P(r,n,{enumerable:!0,configurable:!0,writable:!0,value:u}):r[n]=u;var o=(r,n,u)=>V(r,typeof n!="symbol"?n+"":n,u);const n=s=>typeof s=="string"?s.split("|"):s,u=s=>{var t,e;return{validation:{rules:(t=s.validation)!=null&&t.rules?n(s.validation.rules):[],messages:((e=s.validation)==null?void 0:e.messages)||{}},value:s.value||null}};class c{constructor(){o(this,"collection",{})}all(){return this.collection}first(t){const e=this.get(t);if(e){const i=Array.isArray(e)?e[0]:e;if(i)return String(i)}return null}any(){return Object.keys(this.collection).length>0}fill(t){return this.collection=t,this}push(t,e){return this.collection={...this.collection,[t]:e},this}has(t){return this.collection.hasOwnProperty(t)}get(t,e=null){return this.has(t)?this.collection[t]:e}unset(t){return this.has(t)&&delete this.collection[t],this}clear(){return this.collection={},this}}class p extends c{}class f extends c{}class F extends c{push(t,e){const i=this.get(t)||[];return this.collection={...this.collection,[t]:[...i,e]},this}get(t){return super.get(t,[])}}class b{constructor(){o(this,"errors",new F);o(this,"messages",new p);o(this,"rules",new f)}}const g={required:s=>new Promise((t,e)=>{s==null&&e(),String(s).replace(/\s/g,"").length>0?t(s):e()})},j=s=>s!==null&&typeof s=="object"&&!Array.isArray(s),v=(s,t,e=null)=>{const i=t||new FormData;return Object.keys(s).forEach(a=>{const l=s[a];if(a=e?`${e}[${a}]`:a,!([void 0,null].indexOf(l)>-1)){if(j(l)&&!(l instanceof File)||Array.isArray(l)){v(l,i,a);return}i.append(a,l)}}),i};class m{constructor(t){o(this,"awaiting",!1);o(this,"originalValues",{});o(this,"validation",new b);this.addFields(t)}addField(t,e){if(e!==null&&typeof e=="object"&&"value"in e){const i=u(e);this[t]=i.value,this.originalValues[t]=i.value,this.validation.messages.push(t,i.validation.messages),this.validation.rules.push(t,i.validation.rules)}else this[t]=e,this.originalValues[t]=e;return this}addFields(t){return Object.keys(t).forEach(e=>{this.addField(e,t[e])}),this}get errors(){return this.validation.errors}fill(t,e=!1){return Object.keys(t).forEach(i=>{let a=t[i];e&&(this.originalValues[i]=a),this[i]=a}),this}get messages(){return this.validation.messages}removeField(t){return delete this[t],delete this.originalValues[t],this.validation.messages.unset(t),this.validation.rules.unset(t),this}removeFields(t){return t.forEach(e=>{this.removeField(e)}),this}reset(){return this.validation.errors.clear(),Object.keys(this.originalValues).forEach(t=>{this[t]=this.originalValues[t]}),this}get rules(){return this.validation.rules}setAwaiting(t=!0){return this.awaiting=t,this}validate(t=null){return t?this.validateField(t):this.validateForm()}validateField(t){this.validation.errors.unset(t);const e=this.validation.rules.get(t);if(e&&e.length>0){const i=e.map(a=>{const l=a.split(":"),h=l[0],w=l.length===2?l[1].split(","):[];return h in g?g[h](this[t],w).catch(O=>{const d=this.validation.messages.get(t);return d&&h in d&&this.validation.errors.push(t,d[h]),Promise.reject(O)}):Promise.reject(new Error(`There is no validation rule called "${a}"`))});return Promise.all(i).then(()=>{})}return Promise.resolve()}validateForm(){const t=Object.keys(this.originalValues).map(e=>this.validateField(e));return Promise.all(t).then(()=>Promise.resolve(this)).catch(()=>Promise.reject(this))}values(){const t={};return Object.keys(this.originalValues).forEach(e=>{t[e]=this[e]}),t}valuesAsFormData(){return v(this.values())}}const y=s=>new m(s);r.createForm=y,r.default=m,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|