@abgov/ui-components-common 1.2.0 → 1.2.1-alpha.1
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/index.cjs +1 -1
- package/index.js +47 -45
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var v=Object.defineProperty;var p=r=>{throw TypeError(r)};var M=(r,t,e)=>t in r?v(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var u=(r,t,e)=>M(r,typeof t!="symbol"?t+"":t,e),S=(r,t,e)=>t.has(r)||p("Cannot "+e);var y=(r,t,e)=>t.has(r)?p("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(r):t.set(r,e);var g=(r,t,e)=>(S(r,t,"access private method"),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class N{constructor(t){u(this,"validators");this.validators=t||{}}add(t,...e){this.validators[t]=e}validate(t){const e={};return Object.entries(this.validators).forEach(([a,n])=>{const i=n.map(s=>s(t[a])).find(s=>!!s);i&&(e[a]=i)}),e}}function E(){return[c("Day is required"),m({min:1,max:31,minMsg:"Day must be between 1 and 31",maxMsg:"Day must be between 1 and 31"})]}function w(){return[c("Month is required"),m({min:0,max:11,minMsg:"Month must be between Jan and Dec",maxMsg:"Month must be between Jan and Dec"})]}function D(){const r=new Date().getFullYear();return[c("Year is required"),m({min:1900,max:r,minMsg:"Year must be greater than 1900",maxMsg:`Year must be less than ${r}`})]}function c(r){return t=>(r=r||"Required",typeof t=="number"&&!isNaN(t)||t?"":r)}function _(r){const t=new RegExp(/^\+?[\d-() ]{10,18}$/);return h(t,r||"Invalid phone number")}function R(r){const t=new RegExp(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/);return h(t,r||"Invalid email address")}function $(){return r=>{if(!r)return"";const t="121212121".split("").map(n=>parseInt(n)),e=r.replace(/\D/g,"");return e.length!==9?"SIN must contain 9 numbers":e.split("").map(n=>parseInt(n)).map((n,i)=>{const s=n*t[i];return s<10?s:`${s}`.split("").map(o=>parseInt(o)).reduce((o,f)=>o+f,0)}).reduce((n,i)=>n+i,0)%10===0?"":"Invalid SIN"}}function x(){return h(/^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ -]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,"Invalid postal code")}function h(r,t){return e=>!e||e.match(r)?"":t}function I({invalidMsg:r,minMsg:t,maxMsg:e,min:a,max:n}={}){return i=>{let s=new Date(-1);return`${i||""}`.length===0?"":(typeof i=="string"&&(s=new Date(i)),typeof i=="number"&&(s=new Date(i)),i.toDateString&&(s=i),s.getDate()===-1?r||"Invalid date":a&&s<a?t||`Must be after ${a}`:n&&s>n?e||`Must be before ${n}`:"")}}function m({invalidTypeMsg:r,minMsg:t,maxMsg:e,min:a=-Number.MAX_VALUE,max:n=Number.MAX_VALUE}={}){return i=>{let s=Number.MAX_VALUE;return`${i??""}`.length===0?"":(typeof i=="string"&&(s=parseFloat(i)),typeof i=="number"&&(s=i),isNaN(s)?r||"Must be a numeric value":s>n?e||`Must be less than or equal to ${n}`:s<a?t||`Must be greater than or equal to ${a}`:"")}}function C({invalidTypeMsg:r,minMsg:t,maxMsg:e,min:a=-Number.MAX_VALUE,max:n=Number.MAX_VALUE}){return i=>`${i||""}`.length===0?"":typeof i!="string"?r||"Invalid type":i.length>n?e||`Must be less than ${n} characters`:i.length<a?t||`Must be greater than ${a} characters`:""}var d,q,V;class L{constructor(t){y(this,d);u(this,"state");u(this,"_formData");u(this,"_formRef");this.type=t}init(t){if(this._formRef){console.warn("init: form element has already been set");return}this._formRef=t.detail.el,this.state={uuid:crypto.randomUUID(),form:{},history:[],editting:"",status:"not-started"}}initList(t){this._formRef=t.detail.el,this.state=[]}initState(t,e){l(this._formRef,"external::init:state",t),typeof t=="string"?this.state=JSON.parse(t):Array.isArray(t)||(this.state=t),e&&setTimeout(e,200)}updateListState(t){const e=t.detail;Array.isArray(e.data)&&(this.state=e.data)}updateObjectState(t){var a,n;if(Array.isArray(this.state))return;const e=t.detail;e.type==="list"?this.state={...this.state,form:{...((a=this.state)==null?void 0:a.form)||{},[e.id]:e.data}}:this.state={...this.state,...e.data,form:{...((n=this.state)==null?void 0:n.form)||{},...e.data.form},history:e.data.history}}getStateList(){return this.state?Array.isArray(this.state)?this.state.length===0?[]:this.state.map(t=>Object.values(t.form).filter(e=>{var a;return((a=e==null?void 0:e.data)==null?void 0:a.type)==="details"}).map(e=>{var a;return e.data.type==="details"&&((a=e.data)==null?void 0:a.fieldsets)||{}}).reduce((e,a)=>{for(const[n,i]of Object.entries(a))e[n]=i.value;return e},{})):(console.warn("Utils:getStateList: unable to update the state of a non-multi form type",this.state),[]):[]}getStateValue(t,e){if(Array.isArray(this.state))return console.error("getStateValue: unable to update the state of a multi form type"),"";if(!this.state)return console.error("getStateValue: state has not yet been set"),"";const a=this.state.form[t].data;return a.type!=="details"?"":a.fieldsets[e].value}continueTo(t){if(!t){console.error("continueTo [name] is undefined");return}l(this._formRef,"external::continue",{next:t})}validate(t,e,a){var f;const{el:n,state:i,cancelled:s}=e.detail,o=(f=i==null?void 0:i[t])==null?void 0:f.value;if(window.scrollTo({top:0,behavior:"smooth"}),s)return[!0,o];for(const A of a){const b=A(o);if(g(this,d,V).call(this,n,t,b),b)return[!1,""]}return[!0,o]}edit(t){l(this._formRef,"external::alter:state",{index:t,operation:"edit"})}remove(t){l(this._formRef,"external::alter:state",{index:t,operation:"remove"})}clean(t){return t.history.reduce((e,a)=>(e[a]=t.form[a],e),{})}}d=new WeakSet,q=function(t){var e;Array.isArray(t.data)&&(Array.isArray(this.state)||(this.state={...this.state,form:{...((e=this.state)==null?void 0:e.form)||{},[t.id]:t.data}}))},V=function(t,e,a){t.dispatchEvent(new CustomEvent("msg",{composed:!0,detail:{action:"external::set:error",data:{name:e,msg:a}}}))};function T(r,t,e,a){if(!r){console.error("dispatch element is null");return}r.dispatchEvent(new CustomEvent(t,{composed:!0,bubbles:a==null?void 0:a.bubbles,detail:e}))}function l(r,t,e,a){if(!r){console.error("dispatch element is null");return}r.dispatchEvent(new CustomEvent("msg",{composed:!0,bubbles:a==null?void 0:a.bubbles,detail:{action:t,data:e}}))}exports.FormValidator=N;exports.PublicFormController=L;exports.SINValidator=$;exports.birthDayValidator=E;exports.birthMonthValidator=w;exports.birthYearValidator=D;exports.dateValidator=I;exports.dispatch=T;exports.emailValidator=R;exports.lengthValidator=C;exports.numericValidator=m;exports.phoneNumberValidator=_;exports.postalCodeValidator=x;exports.regexValidator=h;exports.relay=l;exports.requiredValidator=c;
|
package/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var
|
|
1
|
+
var v = Object.defineProperty;
|
|
2
2
|
var p = (r) => {
|
|
3
3
|
throw TypeError(r);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var u = (r, t, e) =>
|
|
5
|
+
var M = (r, t, e) => t in r ? v(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
6
|
+
var u = (r, t, e) => M(r, typeof t != "symbol" ? t + "" : t, e), S = (r, t, e) => t.has(r) || p("Cannot " + e);
|
|
7
7
|
var y = (r, t, e) => t.has(r) ? p("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(r) : t.set(r, e);
|
|
8
|
-
var g = (r, t, e) => (
|
|
9
|
-
class
|
|
8
|
+
var g = (r, t, e) => (S(r, t, "access private method"), e);
|
|
9
|
+
class N {
|
|
10
10
|
constructor(t) {
|
|
11
11
|
u(this, "validators");
|
|
12
12
|
this.validators = t || {};
|
|
@@ -22,7 +22,7 @@ class w {
|
|
|
22
22
|
}), e;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function _() {
|
|
26
26
|
return [
|
|
27
27
|
c("Day is required"),
|
|
28
28
|
m({
|
|
@@ -33,7 +33,7 @@ function N() {
|
|
|
33
33
|
})
|
|
34
34
|
];
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function D() {
|
|
37
37
|
return [
|
|
38
38
|
c("Month is required"),
|
|
39
39
|
m({
|
|
@@ -44,7 +44,7 @@ function _() {
|
|
|
44
44
|
})
|
|
45
45
|
];
|
|
46
46
|
}
|
|
47
|
-
function
|
|
47
|
+
function R() {
|
|
48
48
|
const r = (/* @__PURE__ */ new Date()).getFullYear();
|
|
49
49
|
return [
|
|
50
50
|
c("Year is required"),
|
|
@@ -59,27 +59,27 @@ function D() {
|
|
|
59
59
|
function c(r) {
|
|
60
60
|
return (t) => (r = r || "Required", typeof t == "number" && !isNaN(t) || t ? "" : r);
|
|
61
61
|
}
|
|
62
|
-
function
|
|
62
|
+
function $(r) {
|
|
63
63
|
const t = new RegExp(/^\+?[\d-() ]{10,18}$/);
|
|
64
64
|
return h(t, r || "Invalid phone number");
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function x(r) {
|
|
67
67
|
const t = new RegExp(
|
|
68
68
|
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
|
69
69
|
);
|
|
70
70
|
return h(t, r || "Invalid email address");
|
|
71
71
|
}
|
|
72
|
-
function
|
|
72
|
+
function I() {
|
|
73
73
|
return (r) => {
|
|
74
74
|
if (!r) return "";
|
|
75
75
|
const t = "121212121".split("").map((i) => parseInt(i)), e = r.replace(/\D/g, "");
|
|
76
76
|
return e.length !== 9 ? "SIN must contain 9 numbers" : e.split("").map((i) => parseInt(i)).map((i, n) => {
|
|
77
77
|
const s = i * t[n];
|
|
78
|
-
return s < 10 ? s : `${s}`.split("").map((o) => parseInt(o)).reduce((o,
|
|
78
|
+
return s < 10 ? s : `${s}`.split("").map((o) => parseInt(o)).reduce((o, l) => o + l, 0);
|
|
79
79
|
}).reduce((i, n) => i + n, 0) % 10 === 0 ? "" : "Invalid SIN";
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
|
-
function
|
|
82
|
+
function L() {
|
|
83
83
|
return h(
|
|
84
84
|
/^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ -]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,
|
|
85
85
|
"Invalid postal code"
|
|
@@ -88,7 +88,7 @@ function I() {
|
|
|
88
88
|
function h(r, t) {
|
|
89
89
|
return (e) => !e || e.match(r) ? "" : t;
|
|
90
90
|
}
|
|
91
|
-
function
|
|
91
|
+
function C({
|
|
92
92
|
invalidMsg: r,
|
|
93
93
|
minMsg: t,
|
|
94
94
|
maxMsg: e,
|
|
@@ -112,7 +112,7 @@ function m({
|
|
|
112
112
|
return `${n ?? ""}`.length === 0 ? "" : (typeof n == "string" && (s = parseFloat(n)), typeof n == "number" && (s = n), isNaN(s) ? r || "Must be a numeric value" : s > i ? e || `Must be less than or equal to ${i}` : s < a ? t || `Must be greater than or equal to ${a}` : "");
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
|
-
function
|
|
115
|
+
function U({
|
|
116
116
|
invalidTypeMsg: r,
|
|
117
117
|
minMsg: t,
|
|
118
118
|
maxMsg: e,
|
|
@@ -121,10 +121,10 @@ function C({
|
|
|
121
121
|
}) {
|
|
122
122
|
return (n) => `${n || ""}`.length === 0 ? "" : typeof n != "string" ? r || "Invalid type" : n.length > i ? e || `Must be less than ${i} characters` : n.length < a ? t || `Must be greater than ${a} characters` : "";
|
|
123
123
|
}
|
|
124
|
-
var
|
|
125
|
-
class
|
|
124
|
+
var f, E, A;
|
|
125
|
+
class q {
|
|
126
126
|
constructor(t) {
|
|
127
|
-
y(this,
|
|
127
|
+
y(this, f);
|
|
128
128
|
u(this, "state");
|
|
129
129
|
u(this, "_formData");
|
|
130
130
|
u(this, "_formRef");
|
|
@@ -149,7 +149,7 @@ class U {
|
|
|
149
149
|
}
|
|
150
150
|
// Public method to allow for the initialization of the state
|
|
151
151
|
initState(t, e) {
|
|
152
|
-
|
|
152
|
+
d(this._formRef, "external::init:state", t), typeof t == "string" ? this.state = JSON.parse(t) : Array.isArray(t) || (this.state = t), e && setTimeout(e, 200);
|
|
153
153
|
}
|
|
154
154
|
updateListState(t) {
|
|
155
155
|
const e = t.detail;
|
|
@@ -165,6 +165,7 @@ class U {
|
|
|
165
165
|
form: { ...((a = this.state) == null ? void 0 : a.form) || {}, [e.id]: e.data }
|
|
166
166
|
} : this.state = {
|
|
167
167
|
...this.state,
|
|
168
|
+
...e.data,
|
|
168
169
|
form: { ...((i = this.state) == null ? void 0 : i.form) || {}, ...e.data.form },
|
|
169
170
|
history: e.data.history
|
|
170
171
|
};
|
|
@@ -222,32 +223,33 @@ class U {
|
|
|
222
223
|
console.error("continueTo [name] is undefined");
|
|
223
224
|
return;
|
|
224
225
|
}
|
|
225
|
-
|
|
226
|
+
d(this._formRef, "external::continue", { next: t });
|
|
226
227
|
}
|
|
227
228
|
// Public method to perform validation and send the appropriate messages to the form elements
|
|
228
229
|
validate(t, e, a) {
|
|
229
|
-
var
|
|
230
|
-
const { el: i, state: n } = e.detail,
|
|
231
|
-
window.scrollTo({ top: 0, behavior: "smooth" })
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
230
|
+
var l;
|
|
231
|
+
const { el: i, state: n, cancelled: s } = e.detail, o = (l = n == null ? void 0 : n[t]) == null ? void 0 : l.value;
|
|
232
|
+
if (window.scrollTo({ top: 0, behavior: "smooth" }), s)
|
|
233
|
+
return [!0, o];
|
|
234
|
+
for (const V of a) {
|
|
235
|
+
const b = V(o);
|
|
236
|
+
if (g(this, f, A).call(this, i, t, b), b)
|
|
235
237
|
return [!1, ""];
|
|
236
238
|
}
|
|
237
|
-
return [!0,
|
|
239
|
+
return [!0, o];
|
|
238
240
|
}
|
|
239
241
|
edit(t) {
|
|
240
|
-
|
|
242
|
+
d(this._formRef, "external::alter:state", { index: t, operation: "edit" });
|
|
241
243
|
}
|
|
242
244
|
remove(t) {
|
|
243
|
-
|
|
245
|
+
d(this._formRef, "external::alter:state", { index: t, operation: "remove" });
|
|
244
246
|
}
|
|
245
247
|
// removes any data collected that doesn't correspond with the final history path
|
|
246
248
|
clean(t) {
|
|
247
249
|
return t.history.reduce((e, a) => (e[a] = t.form[a], e), {});
|
|
248
250
|
}
|
|
249
251
|
}
|
|
250
|
-
|
|
252
|
+
f = new WeakSet(), E = function(t) {
|
|
251
253
|
var e;
|
|
252
254
|
Array.isArray(t.data) && (Array.isArray(this.state) || (this.state = {
|
|
253
255
|
...this.state,
|
|
@@ -271,7 +273,7 @@ A = function(t, e, a) {
|
|
|
271
273
|
})
|
|
272
274
|
);
|
|
273
275
|
};
|
|
274
|
-
function
|
|
276
|
+
function T(r, t, e, a) {
|
|
275
277
|
if (!r) {
|
|
276
278
|
console.error("dispatch element is null");
|
|
277
279
|
return;
|
|
@@ -284,7 +286,7 @@ function q(r, t, e, a) {
|
|
|
284
286
|
})
|
|
285
287
|
);
|
|
286
288
|
}
|
|
287
|
-
function
|
|
289
|
+
function d(r, t, e, a) {
|
|
288
290
|
if (!r) {
|
|
289
291
|
console.error("dispatch element is null");
|
|
290
292
|
return;
|
|
@@ -301,20 +303,20 @@ function f(r, t, e, a) {
|
|
|
301
303
|
);
|
|
302
304
|
}
|
|
303
305
|
export {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
306
|
+
N as FormValidator,
|
|
307
|
+
q as PublicFormController,
|
|
308
|
+
I as SINValidator,
|
|
309
|
+
_ as birthDayValidator,
|
|
310
|
+
D as birthMonthValidator,
|
|
311
|
+
R as birthYearValidator,
|
|
312
|
+
C as dateValidator,
|
|
313
|
+
T as dispatch,
|
|
314
|
+
x as emailValidator,
|
|
315
|
+
U as lengthValidator,
|
|
314
316
|
m as numericValidator,
|
|
315
|
-
|
|
316
|
-
|
|
317
|
+
$ as phoneNumberValidator,
|
|
318
|
+
L as postalCodeValidator,
|
|
317
319
|
h as regexValidator,
|
|
318
|
-
|
|
320
|
+
d as relay,
|
|
319
321
|
c as requiredValidator
|
|
320
322
|
};
|