@abgov/ui-components-common 1.2.1 → 1.2.2-alpha.2

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 CHANGED
@@ -1 +1 @@
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;
1
+ "use strict";var M=Object.defineProperty;var y=r=>{throw TypeError(r)};var S=(r,t,e)=>t in r?M(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var l=(r,t,e)=>S(r,typeof t!="symbol"?t+"":t,e),N=(r,t,e)=>t.has(r)||y("Cannot "+e);var g=(r,t,e)=>t.has(r)?y("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(r):t.set(r,e);var V=(r,t,e)=>(N(r,t,"access private method"),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class E{constructor(t){l(this,"validators");this.validators=t||{}}add(t,...e){this.validators[t]=e}validate(t){const e={};return Object.entries(this.validators).forEach(([a,i])=>{const n=i.map(s=>s(t[a])).find(s=>!!s);n&&(e[a]=n)}),e}}function w(){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 _(){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(r){const t=new RegExp(/^\+?[\d-() ]{10,18}$/);return h(t,r||"Invalid phone number")}function $(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 x(){return r=>{if(!r)return"";const t="121212121".split("").map(i=>parseInt(i)),e=r.replace(/\D/g,"");return e.length!==9?"SIN must contain 9 numbers":e.split("").map(i=>parseInt(i)).map((i,n)=>{const s=i*t[n];return s<10?s:`${s}`.split("").map(o=>parseInt(o)).reduce((o,u)=>o+u,0)}).reduce((i,n)=>i+n,0)%10===0?"":"Invalid SIN"}}function I(){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 C({invalidMsg:r,minMsg:t,maxMsg:e,min:a,max:i}={}){return n=>{let s=new Date(-1);return`${n||""}`.length===0?"":(typeof n=="string"&&(s=new Date(n)),typeof n=="number"&&(s=new Date(n)),n.toDateString&&(s=n),s.getDate()===-1?r||"Invalid date":a&&s<a?t||`Must be after ${a}`:i&&s>i?e||`Must be before ${i}`:"")}}function m({invalidTypeMsg:r,minMsg:t,maxMsg:e,min:a=-Number.MAX_VALUE,max:i=Number.MAX_VALUE}={}){return n=>{let s=Number.MAX_VALUE;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}`:"")}}function L({invalidTypeMsg:r,minMsg:t,maxMsg:e,min:a=-Number.MAX_VALUE,max:i=Number.MAX_VALUE}){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`:""}var f,T,A;class q{constructor(t){g(this,f);l(this,"state");l(this,"_formData");l(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){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)}updateListState(t){const e=t.detail;Array.isArray(e.data)&&(this.state=e.data)}updateObjectState(t){var a,i;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:{...((i=this.state)==null?void 0:i.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[i,n]of Object.entries(a))e[i]=n.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}d(this._formRef,"external::continue",{next:t})}validate(t,e,a,i){var b;const{el:n,state:s,cancelled:o}=t.detail,u=(b=s==null?void 0:s[e])==null?void 0:b.value;if(window.scrollTo({top:0,behavior:"smooth"}),o)return[!0,u];for(const v of a){const p=v(u);if(V(this,f,A).call(this,n,e,p,i),p)return[!1,""]}return[!0,u]}validateGroup(t,e,a,i){let n=0;for(const s of e){const[o]=this.validate(t,s,i,{grouped:!0});o&&n++}return n>=a}edit(t){d(this._formRef,"external::alter:state",{index:t,operation:"edit"})}remove(t){d(this._formRef,"external::alter:state",{index:t,operation:"remove"})}clean(t){return t.history.reduce((e,a)=>(e[a]=t.form[a],e),{})}}f=new WeakSet,T=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}}))},A=function(t,e,a,i){t.dispatchEvent(new CustomEvent("msg",{composed:!0,detail:{action:"external::set:error",data:{name:e,msg:a,grouped:i==null?void 0:i.grouped}}}))};function U(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 d(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=E;exports.PublicFormController=q;exports.SINValidator=x;exports.birthDayValidator=w;exports.birthMonthValidator=_;exports.birthYearValidator=D;exports.dateValidator=C;exports.dispatch=U;exports.emailValidator=$;exports.lengthValidator=L;exports.numericValidator=m;exports.phoneNumberValidator=R;exports.postalCodeValidator=I;exports.regexValidator=h;exports.relay=d;exports.requiredValidator=c;
package/index.js CHANGED
@@ -1,14 +1,14 @@
1
- var v = Object.defineProperty;
2
- var p = (r) => {
1
+ var M = Object.defineProperty;
2
+ var y = (r) => {
3
3
  throw TypeError(r);
4
4
  };
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
- 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) => (S(r, t, "access private method"), e);
9
- class N {
5
+ var S = (r, t, e) => t in r ? M(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
6
+ var l = (r, t, e) => S(r, typeof t != "symbol" ? t + "" : t, e), E = (r, t, e) => t.has(r) || y("Cannot " + e);
7
+ var g = (r, t, e) => t.has(r) ? y("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(r) : t.set(r, e);
8
+ var A = (r, t, e) => (E(r, t, "access private method"), e);
9
+ class _ {
10
10
  constructor(t) {
11
- u(this, "validators");
11
+ l(this, "validators");
12
12
  this.validators = t || {};
13
13
  }
14
14
  add(t, ...e) {
@@ -16,13 +16,13 @@ class N {
16
16
  }
17
17
  validate(t) {
18
18
  const e = {};
19
- return Object.entries(this.validators).forEach(([a, i]) => {
20
- const n = i.map((s) => s(t[a])).find((s) => !!s);
21
- n && (e[a] = n);
19
+ return Object.entries(this.validators).forEach(([a, n]) => {
20
+ const i = n.map((s) => s(t[a])).find((s) => !!s);
21
+ i && (e[a] = i);
22
22
  }), e;
23
23
  }
24
24
  }
25
- function _() {
25
+ function D() {
26
26
  return [
27
27
  c("Day is required"),
28
28
  m({
@@ -33,7 +33,7 @@ function _() {
33
33
  })
34
34
  ];
35
35
  }
36
- function D() {
36
+ function R() {
37
37
  return [
38
38
  c("Month is required"),
39
39
  m({
@@ -44,7 +44,7 @@ function D() {
44
44
  })
45
45
  ];
46
46
  }
47
- function R() {
47
+ function $() {
48
48
  const r = (/* @__PURE__ */ new Date()).getFullYear();
49
49
  return [
50
50
  c("Year is required"),
@@ -59,27 +59,27 @@ function R() {
59
59
  function c(r) {
60
60
  return (t) => (r = r || "Required", typeof t == "number" && !isNaN(t) || t ? "" : r);
61
61
  }
62
- function $(r) {
62
+ function x(r) {
63
63
  const t = new RegExp(/^\+?[\d-() ]{10,18}$/);
64
64
  return h(t, r || "Invalid phone number");
65
65
  }
66
- function x(r) {
66
+ function I(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 I() {
72
+ function L() {
73
73
  return (r) => {
74
74
  if (!r) return "";
75
- const t = "121212121".split("").map((i) => parseInt(i)), e = r.replace(/\D/g, "");
76
- return e.length !== 9 ? "SIN must contain 9 numbers" : e.split("").map((i) => parseInt(i)).map((i, n) => {
77
- const s = i * t[n];
78
- return s < 10 ? s : `${s}`.split("").map((o) => parseInt(o)).reduce((o, l) => o + l, 0);
79
- }).reduce((i, n) => i + n, 0) % 10 === 0 ? "" : "Invalid SIN";
75
+ const t = "121212121".split("").map((n) => parseInt(n)), e = r.replace(/\D/g, "");
76
+ return e.length !== 9 ? "SIN must contain 9 numbers" : e.split("").map((n) => parseInt(n)).map((n, i) => {
77
+ const s = n * t[i];
78
+ return s < 10 ? s : `${s}`.split("").map((o) => parseInt(o)).reduce((o, u) => o + u, 0);
79
+ }).reduce((n, i) => n + i, 0) % 10 === 0 ? "" : "Invalid SIN";
80
80
  };
81
81
  }
82
- function L() {
82
+ function C() {
83
83
  return h(
84
84
  /^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ -]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,
85
85
  "Invalid postal code"
@@ -88,16 +88,16 @@ function L() {
88
88
  function h(r, t) {
89
89
  return (e) => !e || e.match(r) ? "" : t;
90
90
  }
91
- function C({
91
+ function U({
92
92
  invalidMsg: r,
93
93
  minMsg: t,
94
94
  maxMsg: e,
95
95
  min: a,
96
- max: i
96
+ max: n
97
97
  } = {}) {
98
- return (n) => {
98
+ return (i) => {
99
99
  let s = /* @__PURE__ */ new Date(-1);
100
- return `${n || ""}`.length === 0 ? "" : (typeof n == "string" && (s = new Date(n)), typeof n == "number" && (s = new Date(n)), n.toDateString && (s = n), s.getDate() === -1 ? r || "Invalid date" : a && s < a ? t || `Must be after ${a}` : i && s > i ? e || `Must be before ${i}` : "");
100
+ 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}` : "");
101
101
  };
102
102
  }
103
103
  function m({
@@ -105,29 +105,29 @@ function m({
105
105
  minMsg: t,
106
106
  maxMsg: e,
107
107
  min: a = -Number.MAX_VALUE,
108
- max: i = Number.MAX_VALUE
108
+ max: n = Number.MAX_VALUE
109
109
  } = {}) {
110
- return (n) => {
110
+ return (i) => {
111
111
  let s = Number.MAX_VALUE;
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}` : "");
112
+ 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}` : "");
113
113
  };
114
114
  }
115
- function U({
115
+ function q({
116
116
  invalidTypeMsg: r,
117
117
  minMsg: t,
118
118
  maxMsg: e,
119
119
  min: a = -Number.MAX_VALUE,
120
- max: i = Number.MAX_VALUE
120
+ max: n = Number.MAX_VALUE
121
121
  }) {
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` : "";
122
+ 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` : "";
123
123
  }
124
- var f, E, A;
125
- class q {
124
+ var f, w, v;
125
+ class T {
126
126
  constructor(t) {
127
- y(this, f);
128
- u(this, "state");
129
- u(this, "_formData");
130
- u(this, "_formRef");
127
+ g(this, f);
128
+ l(this, "state");
129
+ l(this, "_formData");
130
+ l(this, "_formRef");
131
131
  this.type = t;
132
132
  }
133
133
  // Obtain reference to the form element
@@ -156,7 +156,7 @@ class q {
156
156
  Array.isArray(e.data) && (this.state = e.data);
157
157
  }
158
158
  updateObjectState(t) {
159
- var a, i;
159
+ var a, n;
160
160
  if (Array.isArray(this.state))
161
161
  return;
162
162
  const e = t.detail;
@@ -166,7 +166,7 @@ class q {
166
166
  } : this.state = {
167
167
  ...this.state,
168
168
  ...e.data,
169
- form: { ...((i = this.state) == null ? void 0 : i.form) || {}, ...e.data.form },
169
+ form: { ...((n = this.state) == null ? void 0 : n.form) || {}, ...e.data.form },
170
170
  history: e.data.history
171
171
  };
172
172
  }
@@ -179,8 +179,8 @@ class q {
179
179
  return e.data.type === "details" && ((a = e.data) == null ? void 0 : a.fieldsets) || {};
180
180
  }).reduce(
181
181
  (e, a) => {
182
- for (const [i, n] of Object.entries(a))
183
- e[i] = n.value;
182
+ for (const [n, i] of Object.entries(a))
183
+ e[n] = i.value;
184
184
  return e;
185
185
  },
186
186
  {}
@@ -226,17 +226,35 @@ class q {
226
226
  d(this._formRef, "external::continue", { next: t });
227
227
  }
228
228
  // Public method to perform validation and send the appropriate messages to the form elements
229
- validate(t, e, a) {
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];
229
+ validate(t, e, a, n) {
230
+ var b;
231
+ const { el: i, state: s, cancelled: o } = t.detail, u = (b = s == null ? void 0 : s[e]) == null ? void 0 : b.value;
232
+ if (window.scrollTo({ top: 0, behavior: "smooth" }), o)
233
+ return [!0, u];
234
234
  for (const V of a) {
235
- const b = V(o);
236
- if (g(this, f, A).call(this, i, t, b), b)
235
+ const p = V(u);
236
+ if (A(this, f, v).call(this, i, e, p, n), p)
237
237
  return [!1, ""];
238
238
  }
239
- return [!0, o];
239
+ return [!0, u];
240
+ }
241
+ /**
242
+ * Validates a group of fields ensuring that at least `minPassCount` of the items within the group
243
+ * passes. This is useful in the scenario when n number fields are required out of n+m number of fields.
244
+ *
245
+ * @param {string[]} fields - An array of field names to be validated.
246
+ * @param {Event} e - The event object associated with the validation trigger.
247
+ * @param minPassCount - The minimum number of fields that are required to pass to return true.
248
+ * @param {FieldValidator[]} validators - An array of validator functions to apply to the fields.
249
+ * @return {boolean} - Returns true if at least one field in the group is valid; otherwise, false.
250
+ */
251
+ validateGroup(t, e, a, n) {
252
+ let i = 0;
253
+ for (const s of e) {
254
+ const [o] = this.validate(t, s, n, { grouped: !0 });
255
+ o && i++;
256
+ }
257
+ return i >= a;
240
258
  }
241
259
  edit(t) {
242
260
  d(this._formRef, "external::alter:state", { index: t, operation: "edit" });
@@ -249,7 +267,7 @@ class q {
249
267
  return t.history.reduce((e, a) => (e[a] = t.form[a], e), {});
250
268
  }
251
269
  }
252
- f = new WeakSet(), E = function(t) {
270
+ f = new WeakSet(), w = function(t) {
253
271
  var e;
254
272
  Array.isArray(t.data) && (Array.isArray(this.state) || (this.state = {
255
273
  ...this.state,
@@ -259,7 +277,7 @@ f = new WeakSet(), E = function(t) {
259
277
  }
260
278
  }));
261
279
  }, // Private method to dispatch the error message to the form element
262
- A = function(t, e, a) {
280
+ v = function(t, e, a, n) {
263
281
  t.dispatchEvent(
264
282
  new CustomEvent("msg", {
265
283
  composed: !0,
@@ -267,13 +285,14 @@ A = function(t, e, a) {
267
285
  action: "external::set:error",
268
286
  data: {
269
287
  name: e,
270
- msg: a
288
+ msg: a,
289
+ grouped: n == null ? void 0 : n.grouped
271
290
  }
272
291
  }
273
292
  })
274
293
  );
275
294
  };
276
- function T(r, t, e, a) {
295
+ function Y(r, t, e, a) {
277
296
  if (!r) {
278
297
  console.error("dispatch element is null");
279
298
  return;
@@ -303,19 +322,19 @@ function d(r, t, e, a) {
303
322
  );
304
323
  }
305
324
  export {
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,
325
+ _ as FormValidator,
326
+ T as PublicFormController,
327
+ L as SINValidator,
328
+ D as birthDayValidator,
329
+ R as birthMonthValidator,
330
+ $ as birthYearValidator,
331
+ U as dateValidator,
332
+ Y as dispatch,
333
+ I as emailValidator,
334
+ q as lengthValidator,
316
335
  m as numericValidator,
317
- $ as phoneNumberValidator,
318
- L as postalCodeValidator,
336
+ x as phoneNumberValidator,
337
+ C as postalCodeValidator,
319
338
  h as regexValidator,
320
339
  d as relay,
321
340
  c as requiredValidator
package/lib/common.d.ts CHANGED
@@ -240,6 +240,7 @@ export type GoabTextTextElement = "span" | "div" | "p";
240
240
  export type GoabTextHeadingSize = "heading-xl" | "heading-l" | "heading-m" | "heading-s" | "heading-xs";
241
241
  export type GoabTextBodySize = "body-l" | "body-m" | "body-s" | "body-xs";
242
242
  export type GoabTextSize = GoabTextHeadingSize | GoabTextBodySize;
243
+ export type GoabTextColor = "primary" | "secondary";
243
244
  export type GoabFielsetOnContinueDetail = {
244
245
  el: HTMLElement;
245
246
  state: Record<string, string>;
@@ -38,7 +38,20 @@ export declare class PublicFormController<T> {
38
38
  getStateList(): Record<string, string>[];
39
39
  getStateValue(group: string, key: string): string;
40
40
  continueTo(next: T | undefined): void;
41
- validate(field: string, e: Event, validators: FieldValidator[]): [boolean, string];
41
+ validate(e: Event, field: string, validators: FieldValidator[], options?: {
42
+ grouped: boolean;
43
+ }): [boolean, string];
44
+ /**
45
+ * Validates a group of fields ensuring that at least `minPassCount` of the items within the group
46
+ * passes. This is useful in the scenario when n number fields are required out of n+m number of fields.
47
+ *
48
+ * @param {string[]} fields - An array of field names to be validated.
49
+ * @param {Event} e - The event object associated with the validation trigger.
50
+ * @param minPassCount - The minimum number of fields that are required to pass to return true.
51
+ * @param {FieldValidator[]} validators - An array of validator functions to apply to the fields.
52
+ * @return {boolean} - Returns true if at least one field in the group is valid; otherwise, false.
53
+ */
54
+ validateGroup(e: Event, fields: string[], minPassCount: number, validators: FieldValidator[]): boolean;
42
55
  edit(index: number): void;
43
56
  remove(index: number): void;
44
57
  clean(data: AppState<T>): Record<string, unknown>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/ui-components-common",
3
- "version": "1.2.1",
3
+ "version": "1.2.2-alpha.2",
4
4
  "bugs": {
5
5
  "url": "https://github.com/GovAlta/ui-components/issues"
6
6
  },